This is an automated email from Gerrit. "Bernhard Rosenkränzer <b...@baylibre.com>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8290
-- gerrit commit b54eda6eb8119852e900b467ec3a9eb03d53d2f3 Author: Bernhard Rosenkränzer <b...@baylibre.com> Date: Sun May 19 23:27:32 2024 +0200 target: Add -no-autoincr option to mdX, mwX and {read,write}_memory This is the third in a series of 4 patches replacing https://review.openocd.org/c/openocd/+/8259 Change-Id: I9a543b87ae568a8a014dbf4f17e504dccfa46e0a Signed-off-by: Bernhard Rosenkränzer <b...@baylibre.com> Cc: Antonio Borneo <borneo.anto...@gmail.com> diff --git a/doc/openocd.texi b/doc/openocd.texi index 55e6e76808..2eccabedc7 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -9152,11 +9152,12 @@ get_reg @{pc sp@} @end example @end deffn -@deffn {Command} {write_memory} address width data ['phys'] +@deffn {Command} {write_memory} [-no-autoincr] address width data ['phys'] This function provides an efficient way to write to the target memory from a Tcl script. @itemize +@item @option{-no-autoincr} if specified, the address is not auto-incremented after writing the contents. @item @var{address} ... target memory address @item @var{width} ... memory access bit size, can be 8, 16, 32 or 64 @item @var{data} ... Tcl list with the elements to write @@ -9171,12 +9172,13 @@ write_memory 0x20000000 32 @{0xdeadbeef 0x00230500@} @end example @end deffn -@deffn {Command} {read_memory} address width count ['phys'] +@deffn {Command} {read_memory} [-no-autoincr] address width count ['phys'] This function provides an efficient way to read the target memory from a Tcl script. A Tcl list containing the requested memory elements is returned by this function. @itemize +@item @option{-no-autoincr} if specified, the address is not auto-incremented after reading the contents. @item @var{address} ... target memory address @item @var{width} ... memory access bit size, can be 8, 16, 32 or 64 @item @var{count} ... number of elements to read @@ -9326,10 +9328,10 @@ Please use their TARGET object siblings to avoid making assumptions about what TAP is the current target, or about MMU configuration. @end enumerate -@deffn {Command} {mdd} [phys] addr [count] -@deffnx {Command} {mdw} [phys] addr [count] -@deffnx {Command} {mdh} [phys] addr [count] -@deffnx {Command} {mdb} [phys] addr [count] +@deffn {Command} {mdd} [-no-autoincr] [phys] addr [count] +@deffnx {Command} {mdw} [-no-autoincr] [phys] addr [count] +@deffnx {Command} {mdh} [-no-autoincr] [phys] addr [count] +@deffnx {Command} {mdb} [-no-autoincr] [phys] addr [count] Display contents of address @var{addr}, as 64-bit doublewords (@command{mdd}), 32-bit words (@command{mdw}), 16-bit halfwords (@command{mdh}), @@ -9341,12 +9343,14 @@ Otherwise, or if the optional @var{phys} flag is specified, If @var{count} is specified, displays that many units. (If you want to process the data instead of displaying it, see the @code{read_memory} primitives.) +If @option{-no-autoincr} is specified, the address is not +auto-incremented after reading the contents. @end deffn -@deffn {Command} {mwd} [phys] addr doubleword [count] -@deffnx {Command} {mww} [phys] addr word [count] -@deffnx {Command} {mwh} [phys] addr halfword [count] -@deffnx {Command} {mwb} [phys] addr byte [count] +@deffn {Command} {mwd} [-no-autoincr] [phys] addr doubleword [count] +@deffnx {Command} {mww} [-no-autoincr] [phys] addr word [count] +@deffnx {Command} {mwh} [-no-autoincr] [phys] addr halfword [count] +@deffnx {Command} {mwb} [-no-autoincr] [phys] addr byte [count] Writes the specified @var{doubleword} (64 bits), @var{word} (32 bits), @var{halfword} (16 bits), or @var{byte} (8-bit) value, at the specified address @var{addr}. @@ -9355,6 +9359,8 @@ When the current target has an MMU which is present and active, Otherwise, or if the optional @var{phys} flag is specified, @var{addr} is interpreted as a physical address. If @var{count} is specified, fills that many units of consecutive address. +If @option{-no-autoincr} is specified, the address is not +auto-incremented after writing the contents. @end deffn @anchor{imageaccess} diff --git a/src/target/target.c b/src/target/target.c index c4ae6a216e..ffddc013d9 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -3497,6 +3497,12 @@ COMMAND_HANDLER(handle_md_command) if (CMD_ARGC < 1) return ERROR_COMMAND_SYNTAX_ERROR; + bool autoincr = strcmp(CMD_ARGV[0], "-no-autoincr"); + if (!autoincr) { + CMD_ARGC--; + CMD_ARGV++; + } + unsigned size = 0; switch (CMD_NAME[2]) { case 'd': @@ -3521,9 +3527,16 @@ COMMAND_HANDLER(handle_md_command) if (physical) { CMD_ARGC--; CMD_ARGV++; - fn = target_read_phys_memory; - } else - fn = target_read_memory; + if (autoincr) + fn = target_read_phys_memory; + else + fn = target_read_phys_memory_no_addrincr; + } else { + if (autoincr) + fn = target_read_memory; + else + fn = target_read_memory_no_addrincr; + } if ((CMD_ARGC < 1) || (CMD_ARGC > 2)) return ERROR_COMMAND_SYNTAX_ERROR; @@ -3618,14 +3631,28 @@ COMMAND_HANDLER(handle_mw_command) { if (CMD_ARGC < 2) return ERROR_COMMAND_SYNTAX_ERROR; + + bool autoincr = strcmp(CMD_ARGV[0], "-no-autoincr"); + if (!autoincr) { + CMD_ARGC--; + CMD_ARGV++; + } + bool physical = strcmp(CMD_ARGV[0], "phys") == 0; target_write_fn fn; if (physical) { CMD_ARGC--; CMD_ARGV++; - fn = target_write_phys_memory; - } else - fn = target_write_memory; + if (autoincr) + fn = target_write_phys_memory; + else + fn = target_write_phys_memory_no_addrincr; + } else { + if (autoincr) + fn = target_write_memory; + else + fn = target_write_memory_no_addrincr; + } if ((CMD_ARGC < 2) || (CMD_ARGC > 3)) return ERROR_COMMAND_SYNTAX_ERROR; @@ -4488,12 +4515,19 @@ COMMAND_HANDLER(handle_profile_command) COMMAND_HANDLER(handle_target_read_memory) { /* + * optional flag: -no-autoincr * CMD_ARGV[0] = memory address * CMD_ARGV[1] = desired element width in bits * CMD_ARGV[2] = number of elements to read * CMD_ARGV[3] = optional "phys" */ + bool autoincr = strcmp(CMD_ARGV[0], "-no-autoincr"); + if (!autoincr) { + CMD_ARGC--; + CMD_ARGV++; + } + if (CMD_ARGC < 3 || CMD_ARGC > 4) return ERROR_COMMAND_SYNTAX_ERROR; @@ -4560,10 +4594,17 @@ COMMAND_HANDLER(handle_target_read_memory) int retval; - if (is_phys) - retval = target_read_phys_memory(target, addr, width, chunk_len, buffer); - else - retval = target_read_memory(target, addr, width, chunk_len, buffer); + if (autoincr) { + if (is_phys) + retval = target_read_phys_memory(target, addr, width, chunk_len, buffer); + else + retval = target_read_memory(target, addr, width, chunk_len, buffer); + } else { + if (is_phys) + retval = target_read_phys_memory_no_addrincr(target, addr, width, chunk_len, buffer); + else + retval = target_read_memory_no_addrincr(target, addr, width, chunk_len, buffer); + } if (retval != ERROR_OK) { LOG_DEBUG("read_memory: read at " TARGET_ADDR_FMT " with width=%u and count=%zu failed", @@ -4612,13 +4653,23 @@ static int target_jim_write_memory(Jim_Interp *interp, int argc, Jim_Obj * const *argv) { /* + * optional flag: -no-autoincr * argv[1] = memory address * argv[2] = desired element width in bits * argv[3] = list of data to write * argv[4] = optional "phys" */ - if (argc < 4 || argc > 5) { + if (argc < 1) { + Jim_WrongNumArgs(interp, 1, argv, "address width data ['phys']"); + return JIM_ERR; + } + + const char *firstarg = Jim_GetString(argv[1], NULL); + bool autoincr = strcmp(firstarg, "-no-autoincr"); + int flags = autoincr ? 0 : 1; + + if (argc < (4 + flags) || argc > (5 + flags)) { Jim_WrongNumArgs(interp, 1, argv, "address width data ['phys']"); return JIM_ERR; } @@ -4626,7 +4677,7 @@ static int target_jim_write_memory(Jim_Interp *interp, int argc, /* Arg 1: Memory address. */ int e; jim_wide wide_addr; - e = Jim_GetWide(interp, argv[1], &wide_addr); + e = Jim_GetWide(interp, argv[flags + 1], &wide_addr); if (e != JIM_OK) return e; @@ -4635,19 +4686,19 @@ static int target_jim_write_memory(Jim_Interp *interp, int argc, /* Arg 2: Bit width of one element. */ long l; - e = Jim_GetLong(interp, argv[2], &l); + e = Jim_GetLong(interp, argv[flags + 2], &l); if (e != JIM_OK) return e; const unsigned int width_bits = l; - size_t count = Jim_ListLength(interp, argv[3]); + size_t count = Jim_ListLength(interp, argv[flags + 3]); /* Arg 4: Optional 'phys'. */ bool is_phys = false; if (argc > 4) { - const char *phys = Jim_GetString(argv[4], NULL); + const char *phys = Jim_GetString(argv[flags + 4], NULL); if (strcmp(phys, "phys")) { Jim_SetResultFormatted(interp, "invalid argument '%s', must be 'phys'", phys); @@ -4725,10 +4776,17 @@ static int target_jim_write_memory(Jim_Interp *interp, int argc, int retval; - if (is_phys) - retval = target_write_phys_memory(target, addr, width, chunk_len, buffer); - else - retval = target_write_memory(target, addr, width, chunk_len, buffer); + if (autoincr) { + if (is_phys) + retval = target_write_phys_memory(target, addr, width, chunk_len, buffer); + else + retval = target_write_memory(target, addr, width, chunk_len, buffer); + } else { + if (is_phys) + retval = target_write_phys_memory_no_addrincr(target, addr, width, chunk_len, buffer); + else + retval = target_write_memory_no_addrincr(target, addr, width, chunk_len, buffer); + } if (retval != ERROR_OK) { LOG_ERROR("write_memory: write at " TARGET_ADDR_FMT " with width=%u and count=%zu failed", --