diff --git a/src/platforms/pc/cl_utils.c b/src/platforms/pc/cl_utils.c index df13c12..bca5acd 100644 --- a/src/platforms/pc/cl_utils.c +++ b/src/platforms/pc/cl_utils.c @@ -160,7 +160,9 @@ static void cl_help(char **argv) DEBUG_WARN("\t-e\t\t: Assume \"resistor SWD connection\" on FTDI: TDI\n" "\t\t\t connected to TMS, TDO to TDI with eventual resistor\n"); DEBUG_WARN("\t-E\t\t: Erase flash until flash end or for given size\n"); - DEBUG_WARN("\t-V\t\t: Verify flash against binary file\n"); + DEBUG_WARN("\t-w\t\t: Write binary file to target flash (default).\n"); + DEBUG_WARN("\t-V\t\t: Verify flash against binary file. Can be combined\n" + "\t\t\t with -w to verify right after programming.\n"); DEBUG_WARN("\t-r\t\t: Read flash and write to binary file\n"); DEBUG_WARN("\t-p\t\t: Supplies power to the target (where applicable)\n"); DEBUG_WARN("\t-R\t\t: Reset device\n"); @@ -184,7 +186,7 @@ void cl_init(BMP_CL_OPTIONS_t *opt, int argc, char **argv) opt->opt_flash_size = 16 * 1024 *1024; opt->opt_flash_start = 0xffffffff; opt->opt_max_swj_frequency = 4000000; - while((c = getopt(argc, argv, "eEhHv:d:f:s:I:c:Cln:m:M:tVtTa:S:jpP:rR")) != -1) { + while((c = getopt(argc, argv, "eEhHv:d:f:s:I:c:Cln:m:M:wVtTa:S:jpP:rR")) != -1) { switch(c) { case 'c': if (optarg) @@ -251,8 +253,17 @@ void cl_init(BMP_CL_OPTIONS_t *opt, int argc, char **argv) case 'T': opt->opt_mode = BMP_MODE_SWJ_TEST; break; + case 'w': + if (opt->opt_mode == BMP_MODE_FLASH_VERIFY) + opt->opt_mode = BMP_MODE_FLASH_WRITE_VERIFY; + else + opt->opt_mode = BMP_MODE_FLASH_WRITE; + break; case 'V': - opt->opt_mode = BMP_MODE_FLASH_VERIFY; + if (opt->opt_mode == BMP_MODE_FLASH_WRITE) + opt->opt_mode = BMP_MODE_FLASH_WRITE_VERIFY; + else + opt->opt_mode = BMP_MODE_FLASH_VERIFY; break; case 'r': opt->opt_mode = BMP_MODE_FLASH_READ; @@ -422,7 +433,8 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) goto target_detach; int read_file = -1; if ((opt->opt_mode == BMP_MODE_FLASH_WRITE) || - (opt->opt_mode == BMP_MODE_FLASH_VERIFY)) { + (opt->opt_mode == BMP_MODE_FLASH_VERIFY) || + (opt->opt_mode == BMP_MODE_FLASH_WRITE_VERIFY)) { int mmap_res = bmp_mmap(opt->opt_flash_file, &map); if (mmap_res) { DEBUG_WARN("Can not map file: %s. Aborting!\n", strerror(errno)); @@ -453,7 +465,8 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) goto free_map; } target_reset(t); - } else if (opt->opt_mode == BMP_MODE_FLASH_WRITE) { + } else if ((opt->opt_mode == BMP_MODE_FLASH_WRITE) || + (opt->opt_mode == BMP_MODE_FLASH_WRITE_VERIFY)) { DEBUG_INFO("Erase %zu bytes at 0x%08" PRIx32 "\n", map.size, opt->opt_flash_start); uint32_t start_time = platform_time_ms(); @@ -476,11 +489,17 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) } } target_flash_done(t); - target_reset(t); uint32_t end_time = platform_time_ms(); DEBUG_WARN("Flash Write succeeded for %d bytes, %8.3f kiB/s\n", (int)map.size, (((map.size * 1.0)/(end_time - start_time)))); - } else { + if (opt->opt_mode != BMP_MODE_FLASH_WRITE_VERIFY) { + target_reset(t); + goto free_map; + } + } + if ((opt->opt_mode == BMP_MODE_FLASH_READ) || + (opt->opt_mode == BMP_MODE_FLASH_VERIFY) || + (opt->opt_mode == BMP_MODE_FLASH_WRITE_VERIFY)) { #define WORKSIZE 1024 uint8_t *data = alloca(WORKSIZE); if (!data) { @@ -514,7 +533,8 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) } else { bytes_read += worksize; } - if (opt->opt_mode == BMP_MODE_FLASH_VERIFY) { + if ((opt->opt_mode == BMP_MODE_FLASH_VERIFY) || + (opt->opt_mode == BMP_MODE_FLASH_WRITE_VERIFY)) { int difference = memcmp(data, flash, worksize); if (difference){ DEBUG_WARN("Verify failed at flash region 0x%08" @@ -538,11 +558,11 @@ int cl_execute(BMP_CL_OPTIONS_t *opt) uint32_t end_time = platform_time_ms(); if (read_file != -1) close(read_file); - if ((opt->opt_mode == BMP_MODE_FLASH_VERIFY) || - (opt->opt_mode == BMP_MODE_FLASH_READ)) - DEBUG_WARN("Read/Verify succeeded for %d bytes, %8.3f kiB/s\n", - bytes_read, - (((bytes_read * 1.0)/(end_time - start_time)))); + DEBUG_WARN("Read/Verify succeeded for %d bytes, %8.3f kiB/s\n", + bytes_read, + (((bytes_read * 1.0)/(end_time - start_time)))); + if (opt->opt_mode == BMP_MODE_FLASH_WRITE_VERIFY) + target_reset(t); } free_map: if (map.size) diff --git a/src/platforms/pc/cl_utils.h b/src/platforms/pc/cl_utils.h index e002cda..4a0c1e2 100644 --- a/src/platforms/pc/cl_utils.h +++ b/src/platforms/pc/cl_utils.h @@ -32,6 +32,7 @@ enum bmp_cl_mode { BMP_MODE_RESET, BMP_MODE_FLASH_ERASE, BMP_MODE_FLASH_WRITE, + BMP_MODE_FLASH_WRITE_VERIFY, BMP_MODE_FLASH_READ, BMP_MODE_FLASH_VERIFY, BMP_MODE_SWJ_TEST,