From 815e09bb1b0c76923aa91a383d21edb8c1c65879 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Sat, 18 Apr 2020 16:18:55 +0200 Subject: [PATCH 1/8] cl-utils: Add more arguments --- src/platforms/pc/cl_utils.c | 15 ++++++++++++--- src/platforms/pc/cl_utils.h | 2 ++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/platforms/pc/cl_utils.c b/src/platforms/pc/cl_utils.c index f65c24cb..ece6e6b9 100644 --- a/src/platforms/pc/cl_utils.c +++ b/src/platforms/pc/cl_utils.c @@ -120,12 +120,13 @@ static void cl_help(char **argv, BMP_CL_OPTIONS_t *opt) printf("\t-h\t\t: This help.\n"); printf("\t-v[1|2]\t\t: Increasing verbosity\n"); printf("\t-d \"path\"\t: Use serial device at \"path\"\n"); + printf("\t-P \t: Use device found as "); printf("\t-s \"string\"\t: Use dongle with (partial) " "serial number \"string\"\n"); printf("\t-c \"string\"\t: Use ftdi dongle with type \"string\"\n"); - printf("\t-C\t\t: Connect under reset\n"); printf("\t-n\t\t: Exit immediate if no device found\n"); printf("\tRun mode related options:\n"); + printf("\t-C\t\t: Connect under reset\n"); printf("\t-t\t\t: Scan SWD, with no target found scan jtag and exit\n"); printf("\t-E\t\t: Erase flash until flash end or for given size\n"); printf("\t-V\t\t: Verify flash against binary file\n"); @@ -149,7 +150,7 @@ void cl_init(BMP_CL_OPTIONS_t *opt, int argc, char **argv) opt->opt_target_dev = 1; opt->opt_flash_start = 0x08000000; opt->opt_flash_size = 16 * 1024 *1024; - while((c = getopt(argc, argv, "Ehv::d:s:c:CnN:tVta:S:jprR")) != -1) { + while((c = getopt(argc, argv, "Ehv::d:s:I:c:CnN:tVta:S:jpP:rR")) != -1) { switch(c) { case 'c': if (optarg) @@ -181,6 +182,10 @@ void cl_init(BMP_CL_OPTIONS_t *opt, int argc, char **argv) if (optarg) opt->opt_serial = optarg; break; + case 'I': + if (optarg) + opt->opt_ident_string = optarg; + break; case 'E': opt->opt_mode = BMP_MODE_FLASH_ERASE; break; @@ -207,6 +212,10 @@ void cl_init(BMP_CL_OPTIONS_t *opt, int argc, char **argv) if (optarg) opt->opt_target_dev = strtol(optarg, NULL, 0); break; + case 'P': + if (optarg) + opt->opt_position = atoi(optarg); + break; case 'S': if (optarg) { char *endptr; @@ -398,7 +407,7 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) } if (read_file != -1) close(read_file); - printf("Read/Verifed succeeded for %d bytes\n", bytes_read); + printf("Read/Verified succeeded for %d bytes\n", bytes_read); } free_map: if (map.size) diff --git a/src/platforms/pc/cl_utils.h b/src/platforms/pc/cl_utils.h index 6e89656d..f25bd3ff 100644 --- a/src/platforms/pc/cl_utils.h +++ b/src/platforms/pc/cl_utils.h @@ -43,6 +43,8 @@ typedef struct BMP_CL_OPTIONS_s { char *opt_flash_file; char *opt_device; char *opt_serial; + char *opt_ident_string; + int opt_position; char *opt_cable; int opt_debuglevel; int opt_target_dev; From c5d0902d4ce98b0c18bd3d57e030e9c4f934ae1b Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Wed, 22 Apr 2020 18:18:22 +0200 Subject: [PATCH 2/8] cl_utils: Fix memory leak. --- src/platforms/pc/cl_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/pc/cl_utils.c b/src/platforms/pc/cl_utils.c index ece6e6b9..2a73c64e 100644 --- a/src/platforms/pc/cl_utils.c +++ b/src/platforms/pc/cl_utils.c @@ -354,7 +354,7 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) target_reset(t); } else { #define WORKSIZE 1024 - uint8_t *data = malloc(WORKSIZE); + uint8_t *data = alloca(WORKSIZE); if (!data) { printf("Can not malloc memory for flash read/verify operation\n"); return res; From 8db979798c28fca6b6abbc79886c1550609caf54 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Sat, 25 Apr 2020 14:02:33 +0200 Subject: [PATCH 3/8] cl_utils.c: Report read/write speed. --- src/platforms/pc/cl_utils.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/platforms/pc/cl_utils.c b/src/platforms/pc/cl_utils.c index 2a73c64e..114fd9e2 100644 --- a/src/platforms/pc/cl_utils.c +++ b/src/platforms/pc/cl_utils.c @@ -332,6 +332,7 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) } else if (opt->opt_mode == BMP_MODE_FLASH_WRITE) { DEBUG("Erase %zu bytes at 0x%08" PRIx32 "\n", map.size, opt->opt_flash_start); + uint32_t start_time = platform_time_ms(); unsigned int erased = target_flash_erase(t, opt->opt_flash_start, map.size); if (erased) { @@ -352,6 +353,9 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) } target_flash_done(t); target_reset(t); + uint32_t end_time = platform_time_ms(); + printf("Flash Write succeeded for %d bytes, %8.3f kiB/s\n", + (int)map.size, (((map.size * 1.0)/(end_time - start_time)))); } else { #define WORKSIZE 1024 uint8_t *data = alloca(WORKSIZE); @@ -368,6 +372,7 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) map.size; int bytes_read = 0; void *flash = map.data; + uint32_t start_time = platform_time_ms(); while (size) { int worksize = (size > WORKSIZE) ? WORKSIZE : size; int n_read = target_mem_read(t, data, flash_src, worksize); @@ -405,9 +410,11 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) if (size <= 0) res = 0; } + uint32_t end_time = platform_time_ms(); if (read_file != -1) close(read_file); - printf("Read/Verified succeeded for %d bytes\n", bytes_read); + printf("Read/Verified succeeded for %d bytes, %8.3f kiB/s\n", + bytes_read, (((bytes_read * 1.0)/(end_time - start_time)))); } free_map: if (map.size) From b5182e09d015029f8fce83a0e787355540a406c1 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Sat, 25 Apr 2020 13:15:31 +0200 Subject: [PATCH 4/8] cl_utils: When reading from flash to file, truncate the file. --- src/platforms/pc/cl_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/pc/cl_utils.c b/src/platforms/pc/cl_utils.c index 114fd9e2..57af8d30 100644 --- a/src/platforms/pc/cl_utils.c +++ b/src/platforms/pc/cl_utils.c @@ -306,7 +306,7 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) } } else if (opt->opt_mode == BMP_MODE_FLASH_READ) { /* Open as binary */ - read_file = open(opt->opt_flash_file, O_CREAT | O_RDWR | O_BINARY, + read_file = open(opt->opt_flash_file, O_TRUNC | O_CREAT | O_RDWR | O_BINARY, S_IRUSR | S_IWUSR); if (read_file == -1) { printf("Error opening flashfile %s for read: %s\n", From 7956fbc3612e81b21d330e702a9e86401d1b6099 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Wed, 29 Apr 2020 15:24:54 +0200 Subject: [PATCH 5/8] cl-utils: Print memory map when test is specified. --- src/platforms/pc/cl_utils.c | 40 +++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/platforms/pc/cl_utils.c b/src/platforms/pc/cl_utils.c index 57af8d30..45f6373d 100644 --- a/src/platforms/pc/cl_utils.c +++ b/src/platforms/pc/cl_utils.c @@ -285,8 +285,6 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) } else { target_foreach(display_target, NULL); } - if (opt->opt_mode == BMP_MODE_TEST) - return 0; if (opt->opt_target_dev > num_targets) { DEBUG("Given target nummer %d not available\n", opt->opt_target_dev); return res; @@ -296,6 +294,44 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) DEBUG("Can not attach to target %d\n", opt->opt_target_dev); goto target_detach; } + if (opt->opt_mode == BMP_MODE_TEST) { + char map [1024], *p = map; + if (target_mem_map(t, map, sizeof(map))) { + while (*p && (*p == '<')) { + unsigned int start, size; + char *res; + int match; + match = strncmp(p, "", strlen("")); + if (!match) { + p += strlen(""); + continue; + } + match = strncmp(p, "" + "%x", + &start, &size, &blocksize)) + printf("Flash Start: 0x%08x, length %#9x, blocksize %#8x\n", + start, size, blocksize); + res = strstr(p, ""); + p = res + strlen(""); + continue; + } + match = strncmp(p, ""); + p = res + strlen("/>"); + continue; + } + break; + } + } + goto target_detach; + } int read_file = -1; if ((opt->opt_mode == BMP_MODE_FLASH_WRITE) || (opt->opt_mode == BMP_MODE_FLASH_VERIFY)) { From 60f39f55b48ced7af35c15abcf6861e2b3e5ba31 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Sun, 26 Apr 2020 18:12:20 +0200 Subject: [PATCH 6/8] MSP432: Warn when hardware version not supported. --- src/target/msp432.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/target/msp432.c b/src/target/msp432.c index 79cf2412..4c29fd21 100644 --- a/src/target/msp432.c +++ b/src/target/msp432.c @@ -184,8 +184,10 @@ bool msp432_probe(target *t) return false; /* Check for the right HW revision: at least C, as no flash support for B */ - if (target_mem_read32(t, HWREV_ADDR) < HWREV_MIN_VALUE) + if (target_mem_read32(t, HWREV_ADDR) < HWREV_MIN_VALUE) { + DEBUG("MSP432 Version not handled\n"); return false; + } /* If we got till this point, we are most probably looking at a real TLV */ /* Device Information structure. Now check for the correct device */ From 966ac4036d67630b4c03c413df7355f420db8e39 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Sat, 25 Apr 2020 13:44:41 +0200 Subject: [PATCH 7/8] target.c: Check for valid flash structure. --- src/target/target.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/target/target.c b/src/target/target.c index 520c629b..765a401d 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -256,6 +256,8 @@ int target_flash_write(target *t, int ret = 0; while (len) { struct target_flash *f = flash_for_addr(t, dest); + if (!f) + return 1; size_t tmptarget = MIN(dest + len, f->start + f->length); size_t tmplen = tmptarget - dest; ret |= target_flash_write_buffered(f, dest, src, tmplen); From f3790b90e5ecf44525dc05f05a4e72f74baea411 Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Fri, 17 Apr 2020 17:43:09 +0200 Subject: [PATCH 8/8] command.c: Simplify usage of serial_no serial number string. --- src/command.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/command.c b/src/command.c index 372b8e95..12a5e4ad 100644 --- a/src/command.c +++ b/src/command.c @@ -357,11 +357,7 @@ static bool cmd_target_power(target *t, int argc, const char **argv) #ifdef PLATFORM_HAS_TRACESWO static bool cmd_traceswo(target *t, int argc, const char **argv) { -#if defined(STM32L0) || defined(STM32F3) || defined(STM32F4) - extern char serial_no[13]; -#else - extern char serial_no[9]; -#endif + extern char *serial_no; (void)t; #if TRACESWO_PROTOCOL == 2 uint32_t baudrate = SWO_DEFAULT_BAUD;