cl_utils: Use start of flash in memory map as default flash start.

This commit is contained in:
Uwe Bonnes 2020-05-26 12:24:53 +02:00
parent 425002a38f
commit aabd07738e
1 changed files with 40 additions and 33 deletions

View File

@ -143,7 +143,7 @@ static void cl_help(char **argv, BMP_CL_OPTIONS_t *opt)
DEBUG_WARN("Flash operation modifiers options:\n"); DEBUG_WARN("Flash operation modifiers options:\n");
DEBUG_WARN("\tDefault action with given file is to write to flash\n"); DEBUG_WARN("\tDefault action with given file is to write to flash\n");
DEBUG_WARN("\t-a <addr>\t: Start flash operation at flash address <addr>\n" DEBUG_WARN("\t-a <addr>\t: Start flash operation at flash address <addr>\n"
"\t\t\t Default start is 0x08000000\n"); "\t\t\t Default start is start of flash in memory map\n");
DEBUG_WARN("\t-S <num>\t: Read <num> bytes. Default is until read fails.\n"); DEBUG_WARN("\t-S <num>\t: Read <num> bytes. Default is until read fails.\n");
DEBUG_WARN("\t <file>\t\t: Use (binary) file <file> for flash operation\n"); DEBUG_WARN("\t <file>\t\t: Use (binary) file <file> for flash operation\n");
exit(0); exit(0);
@ -153,7 +153,6 @@ void cl_init(BMP_CL_OPTIONS_t *opt, int argc, char **argv)
{ {
int c; int c;
opt->opt_target_dev = 1; opt->opt_target_dev = 1;
opt->opt_flash_start = 0x08000000;
opt->opt_flash_size = 16 * 1024 *1024; opt->opt_flash_size = 16 * 1024 *1024;
while((c = getopt(argc, argv, "Ehv:d:s:I:c:CnltVta:S:jpP:rR")) != -1) { while((c = getopt(argc, argv, "Ehv:d:s:I:c:CnltVta:S:jpP:rR")) != -1) {
switch(c) { switch(c) {
@ -301,9 +300,10 @@ int cl_execute(BMP_CL_OPTIONS_t *opt)
DEBUG_WARN("Can not attach to target %d\n", opt->opt_target_dev); DEBUG_WARN("Can not attach to target %d\n", opt->opt_target_dev);
goto target_detach; goto target_detach;
} }
if (opt->opt_mode == BMP_MODE_TEST) { /* Always scan memory map to find lowest flash */
char map [1024], *p = map; char memory_map [1024], *p = memory_map;
if (target_mem_map(t, map, sizeof(map))) { uint32_t flash_start = 0xffffffff;
if (target_mem_map(t, memory_map, sizeof(memory_map))) {
while (*p && (*p == '<')) { while (*p && (*p == '<')) {
unsigned int start, size; unsigned int start, size;
char *res; char *res;
@ -318,9 +318,13 @@ int cl_execute(BMP_CL_OPTIONS_t *opt)
unsigned int blocksize; unsigned int blocksize;
if (sscanf(p, "<memory type=\"flash\" start=\"%x\" length=\"%x\">" if (sscanf(p, "<memory type=\"flash\" start=\"%x\" length=\"%x\">"
"<property name=\"blocksize\">%x</property></memory>", "<property name=\"blocksize\">%x</property></memory>",
&start, &size, &blocksize)) &start, &size, &blocksize)) {
if (opt->opt_mode == BMP_MODE_TEST)
DEBUG_INFO("Flash Start: 0x%08x, length %#9x, " DEBUG_INFO("Flash Start: 0x%08x, length %#9x, "
"blocksize %#8x\n", start, size, blocksize); "blocksize %#8x\n", start, size, blocksize);
if (start < flash_start)
flash_start = start;
}
res = strstr(p, "</memory>"); res = strstr(p, "</memory>");
p = res + strlen("</memory>"); p = res + strlen("</memory>");
continue; continue;
@ -329,6 +333,7 @@ int cl_execute(BMP_CL_OPTIONS_t *opt)
if (!match) { if (!match) {
if (sscanf(p, "<memory type=\"ram\" start=\"%x\" length=\"%x\"/", if (sscanf(p, "<memory type=\"ram\" start=\"%x\" length=\"%x\"/",
&start, &size)) &start, &size))
if (opt->opt_mode == BMP_MODE_TEST)
DEBUG_INFO("Ram Start: 0x%08x, length %#9x\n", DEBUG_INFO("Ram Start: 0x%08x, length %#9x\n",
start, size); start, size);
res = strstr(p, "/>"); res = strstr(p, "/>");
@ -338,8 +343,10 @@ int cl_execute(BMP_CL_OPTIONS_t *opt)
break; break;
} }
} }
if (opt->opt_flash_start < flash_start)
opt->opt_flash_start = flash_start;
if (opt->opt_mode == BMP_MODE_TEST)
goto target_detach; goto target_detach;
}
int read_file = -1; int read_file = -1;
if ((opt->opt_mode == BMP_MODE_FLASH_WRITE) || if ((opt->opt_mode == BMP_MODE_FLASH_WRITE) ||
(opt->opt_mode == BMP_MODE_FLASH_VERIFY)) { (opt->opt_mode == BMP_MODE_FLASH_VERIFY)) {