This is an automated email from Gerrit.

Tomas Vanek ([email protected]) just uploaded a new patch set to Gerrit, which you 
can find at http://openocd.zylin.com/4776

-- gerrit

commit fc5b7e9b8f94b287f4d5f69cba4e29f996e2fb1e
Author: Tomas Vanek <[email protected]>
Date:   Thu Nov 22 19:05:04 2018 +0100

    flash/nor: add flash mdw/h/b commands
    
    Some flash banks are not mapped in the target memory
    (e.g. SPI flash, some special pages).
    
    Add flash version of mdw/h/b which reads data using
    the flash driver.
    
    While on it:
    - drop conditional compile for parsing fillw address
    - remove copy of handle_md_output from src/target/dsp563xx.c
    
    Change-Id: I66910e0a69cf523fe5ca1ed6ce7b9e8e176aef4a
    Signed-off-by: Tomas Vanek <[email protected]>

diff --git a/doc/openocd.texi b/doc/openocd.texi
index e7d0c67..293ba00 100644
--- a/doc/openocd.texi
+++ b/doc/openocd.texi
@@ -4923,6 +4923,19 @@ each block, and the specified length must stay within 
that bank.
 @end deffn
 @comment no current checks for errors if fill blocks touch multiple banks!
 
+@deffn Command {flash mdw} addr [count]
+@deffnx Command {flash mdh} addr [count]
+@deffnx Command {flash mdb} addr [count]
+Display contents of address @var{addr}, as
+32-bit words (@command{mdw}), 16-bit halfwords (@command{mdh}),
+or 8-bit bytes (@command{mdb}).
+If @var{count} is specified, displays that many units.
+Reads from flash using the flash driver, thefore it enables reading
+from a bank not mapped in target address space.
+The flash bank to use is inferred from the @var{address} of
+each block, and the specified length must stay within that bank.
+@end deffn
+
 @deffn Command {flash write_bank} num filename [offset]
 Write the binary @file{filename} to flash bank @var{num},
 starting at @var{offset} bytes from the beginning of the bank. If @var{offset}
diff --git a/src/flash/nor/tcl.c b/src/flash/nor/tcl.c
index 95ca819..a77f3dc 100644
--- a/src/flash/nor/tcl.c
+++ b/src/flash/nor/tcl.c
@@ -476,11 +476,7 @@ COMMAND_HANDLER(handle_flash_fill_command)
        if (CMD_ARGC != 3)
                return ERROR_COMMAND_SYNTAX_ERROR;
 
-#if BUILD_TARGET64
-       COMMAND_PARSE_NUMBER(u64, CMD_ARGV[0], address);
-#else
-       COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], address);
-#endif
+       COMMAND_PARSE_ADDRESS(CMD_ARGV[0], address);
        COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], pattern);
        COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], count);
 
@@ -607,6 +603,65 @@ done:
        return retval;
 }
 
+COMMAND_HANDLER(handle_flash_md_command)
+{
+       int retval;
+
+       if (CMD_ARGC < 1 || CMD_ARGC > 2)
+               return ERROR_COMMAND_SYNTAX_ERROR;
+
+       target_addr_t address;
+       COMMAND_PARSE_ADDRESS(CMD_ARGV[0], address);
+
+       uint32_t count = 1;
+       if (CMD_ARGC == 2)
+               COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], count);
+
+       unsigned int wordsize;
+       switch (CMD_NAME[2]) {
+               case 'w':
+                       wordsize = 4;
+                       break;
+               case 'h':
+                       wordsize = 2;
+                       break;
+               case 'b':
+                       wordsize = 1;
+                       break;
+               default:
+                       return ERROR_COMMAND_SYNTAX_ERROR;
+       }
+
+       if (count == 0)
+               return ERROR_OK;
+
+       struct target *target = get_current_target(CMD_CTX);
+       struct flash_bank *bank;
+       retval = get_flash_bank_by_addr(target, address, true, &bank);
+       if (retval != ERROR_OK)
+               return retval;
+
+       uint32_t offset = address - bank->base;
+       uint32_t sizebytes = count * wordsize;
+       if (offset + sizebytes > bank->size) {
+               LOG_ERROR("Cannot cross flash bank borders");
+               return ERROR_FAIL;
+       }
+
+       uint8_t *buffer = calloc(count, wordsize);
+       if (buffer == NULL)
+               return ERROR_FAIL;
+
+       retval = flash_driver_read(bank, buffer, offset, sizebytes);
+       if (retval == ERROR_OK)
+               handle_md_output(CMD_CTX, target, offset, wordsize, count, 
buffer);
+
+       free(buffer);
+
+       return retval;
+}
+
+
 COMMAND_HANDLER(handle_flash_write_bank_command)
 {
        uint32_t offset;
@@ -1021,6 +1076,27 @@ static const struct command_registration 
flash_exec_command_handlers[] = {
                        "word address.  (No autoerase.)",
        },
        {
+               .name = "mdb",
+               .handler = handle_flash_md_command,
+               .mode = COMMAND_EXEC,
+               .usage = "address [count]",
+               .help = "Display bytes from flash.",
+       },
+       {
+               .name = "mdh",
+               .handler = handle_flash_md_command,
+               .mode = COMMAND_EXEC,
+               .usage = "address [count]",
+               .help = "Display half-words from flash.",
+       },
+       {
+               .name = "mdw",
+               .handler = handle_flash_md_command,
+               .mode = COMMAND_EXEC,
+               .usage = "address [count]",
+               .help = "Display words from flash.",
+       },
+       {
                .name = "write_bank",
                .handler = handle_flash_write_bank_command,
                .mode = COMMAND_EXEC,
diff --git a/src/target/dsp563xx.c b/src/target/dsp563xx.c
index 1d728df..6757d10 100644
--- a/src/target/dsp563xx.c
+++ b/src/target/dsp563xx.c
@@ -1870,67 +1870,6 @@ static int dsp563xx_remove_watchpoint(struct target 
*target, struct watchpoint *
        return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
 }
 
-static void handle_md_output(struct command_context *cmd_ctx,
-       struct target *target,
-       uint32_t address,
-       unsigned size,
-       unsigned count,
-       const uint8_t *buffer)
-{
-       const unsigned line_bytecnt = 32;
-       unsigned line_modulo = line_bytecnt / size;
-
-       char output[line_bytecnt * 4 + 1];
-       unsigned output_len = 0;
-
-       const char *value_fmt;
-       switch (size) {
-               case 4:
-                       value_fmt = "%8.8x ";
-                       break;
-               case 2:
-                       value_fmt = "%4.4x ";
-                       break;
-               case 1:
-                       value_fmt = "%2.2x ";
-                       break;
-               default:
-                       /* "can't happen", caller checked */
-                       LOG_ERROR("invalid memory read size: %u", size);
-                       return;
-       }
-
-       for (unsigned i = 0; i < count; i++) {
-               if (i % line_modulo == 0)
-                       output_len += snprintf(output + output_len,
-                                       sizeof(output) - output_len,
-                                       "0x%8.8x: ",
-                                       (unsigned) (address + i));
-
-               uint32_t value = 0;
-               const uint8_t *value_ptr = buffer + i * size;
-               switch (size) {
-                       case 4:
-                               value = target_buffer_get_u32(target, 
value_ptr);
-                               break;
-                       case 2:
-                               value = target_buffer_get_u16(target, 
value_ptr);
-                               break;
-                       case 1:
-                               value = *value_ptr;
-               }
-               output_len += snprintf(output + output_len,
-                               sizeof(output) - output_len,
-                               value_fmt,
-                               value);
-
-               if ((i % line_modulo == line_modulo - 1) || (i == count - 1)) {
-                       command_print(cmd_ctx, "%s", output);
-                       output_len = 0;
-               }
-       }
-}
-
 static int dsp563xx_add_custom_watchpoint(struct target *target, uint32_t 
address, uint32_t memType,
                enum watchpoint_rw rw, enum watchpoint_condition cond)
 {
diff --git a/src/target/target.c b/src/target/target.c
index 74b332d..70150a0 100644
--- a/src/target/target.c
+++ b/src/target/target.c
@@ -3104,7 +3104,7 @@ COMMAND_HANDLER(handle_step_command)
        return target->type->step(target, current_pc, addr, 1);
 }
 
-static void handle_md_output(struct command_context *cmd_ctx,
+void handle_md_output(struct command_context *cmd_ctx,
                struct target *target, target_addr_t address, unsigned size,
                unsigned count, const uint8_t *buffer)
 {
diff --git a/src/target/target.h b/src/target/target.h
index fb9d714..477ff44 100644
--- a/src/target/target.h
+++ b/src/target/target.h
@@ -714,6 +714,10 @@ int target_arch_state(struct target *target);
 
 void target_handle_event(struct target *t, enum target_event e);
 
+void handle_md_output(struct command_context *cmd_ctx,
+       struct target *target, target_addr_t address, unsigned size,
+       unsigned count, const uint8_t *buffer);
+
 #define ERROR_TARGET_INVALID   (-300)
 #define ERROR_TARGET_INIT_FAILED (-301)
 #define ERROR_TARGET_TIMEOUT   (-302)

-- 


_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to