have "reg" command print cache names too
[openocd.git] / src / target / target.c
index 8bb9371f903bca836e16a17021668ac79dc8a21e..eb93fb7b83dc24756d6bf7ca6b10e552dd98ed32 100644 (file)
@@ -601,11 +601,24 @@ int target_read_memory(struct target_s *target,
        return target->type->read_memory(target, address, size, count, buffer);
 }
 
+int target_read_phys_memory(struct target_s *target,
+               uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer)
+{
+       return target->type->read_phys_memory(target, address, size, count, buffer);
+}
+
 int target_write_memory(struct target_s *target,
                uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer)
 {
        return target->type->write_memory(target, address, size, count, buffer);
 }
+
+int target_write_phys_memory(struct target_s *target,
+               uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer)
+{
+       return target->type->write_phys_memory(target, address, size, count, buffer);
+}
+
 int target_bulk_write_memory(struct target_s *target,
                uint32_t address, uint32_t count, uint8_t *buffer)
 {
@@ -698,7 +711,17 @@ int target_init(struct command_context_s *cmd_ctx)
                {
                        target->type->virt2phys = default_virt2phys;
                }
-               target->type->virt2phys = default_virt2phys;
+
+               if (target->type->read_phys_memory == NULL)
+               {
+                       target->type->read_phys_memory = target->type->read_memory;
+               }
+
+               if (target->type->write_phys_memory == NULL)
+               {
+                       target->type->write_phys_memory = target->type->write_memory;
+               }
+
                /* a non-invasive way(in terms of patches) to add some code that
                 * runs before the type->write/read_memory implementation
                 */
@@ -1532,13 +1555,13 @@ int target_register_user_commands(struct command_context_s *cmd_ctx)
        register_command(cmd_ctx,  NULL, "reset", handle_reset_command, COMMAND_EXEC, "reset target [run | halt | init] - default is run");
        register_command(cmd_ctx,  NULL, "soft_reset_halt", handle_soft_reset_halt_command, COMMAND_EXEC, "halt the target and do a soft reset");
 
-       register_command(cmd_ctx,  NULL, "mdw", handle_md_command, COMMAND_EXEC, "display memory words <addr> [count]");
-       register_command(cmd_ctx,  NULL, "mdh", handle_md_command, COMMAND_EXEC, "display memory half-words <addr> [count]");
-       register_command(cmd_ctx,  NULL, "mdb", handle_md_command, COMMAND_EXEC, "display memory bytes <addr> [count]");
+       register_command(cmd_ctx,  NULL, "mdw", handle_md_command, COMMAND_EXEC, "display memory words [phys] <addr> [count]");
+       register_command(cmd_ctx,  NULL, "mdh", handle_md_command, COMMAND_EXEC, "display memory half-words [phys] <addr> [count]");
+       register_command(cmd_ctx,  NULL, "mdb", handle_md_command, COMMAND_EXEC, "display memory bytes [phys] <addr> [count]");
 
-       register_command(cmd_ctx,  NULL, "mww", handle_mw_command, COMMAND_EXEC, "write memory word <addr> <value> [count]");
-       register_command(cmd_ctx,  NULL, "mwh", handle_mw_command, COMMAND_EXEC, "write memory half-word <addr> <value> [count]");
-       register_command(cmd_ctx,  NULL, "mwb", handle_mw_command, COMMAND_EXEC, "write memory byte <addr> <value> [count]");
+       register_command(cmd_ctx,  NULL, "mww", handle_mw_command, COMMAND_EXEC, "write memory word [phys]  <addr> <value> [count]");
+       register_command(cmd_ctx,  NULL, "mwh", handle_mw_command, COMMAND_EXEC, "write memory half-word [phys]  <addr> <value> [count]");
+       register_command(cmd_ctx,  NULL, "mwb", handle_mw_command, COMMAND_EXEC, "write memory byte [phys] <addr> <value> [count]");
 
        register_command(cmd_ctx,  NULL, "bp",
                        handle_bp_command, COMMAND_EXEC,
@@ -1800,6 +1823,8 @@ static int handle_reg_command(struct command_context_s *cmd_ctx, char *cmd, char
                {
                        int i;
 
+                       command_print(cmd_ctx, "===== %s", cache->name);
+
                        for (i = 0, reg = cache->reg_list;
                                        i < cache->num_regs;
                                        i++, reg++, count++)
@@ -2184,6 +2209,22 @@ static int handle_md_command(struct command_context_s *cmd_ctx, char *cmd, char
        default: return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
+       bool physical=strcmp(args[0], "phys")==0;
+       int (*fn)(struct target_s *target,
+                       uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer);
+       if (physical)
+       {
+               argc--;
+               args++;
+               fn=target_read_phys_memory;
+       } else
+       {
+               fn=target_read_memory;
+       }
+       if ((argc < 1) || (argc > 2))
+       {
+               return ERROR_COMMAND_SYNTAX_ERROR;
+       }
        uint32_t address;
        int retval = parse_u32(args[0], &address);
        if (ERROR_OK != retval)
@@ -2200,8 +2241,7 @@ static int handle_md_command(struct command_context_s *cmd_ctx, char *cmd, char
        uint8_t *buffer = calloc(count, size);
 
        target_t *target = get_current_target(cmd_ctx);
-       retval = target_read_memory(target,
-                               address, size, count, buffer);
+       retval = fn(target, address, size, count, buffer);
        if (ERROR_OK == retval)
                handle_md_output(cmd_ctx, target, address, size, count, buffer);
 
@@ -2212,7 +2252,23 @@ static int handle_md_command(struct command_context_s *cmd_ctx, char *cmd, char
 
 static int handle_mw_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
 {
-        if ((argc < 2) || (argc > 3))
+       if (argc < 2)
+       {
+               return ERROR_COMMAND_SYNTAX_ERROR;
+       }
+       bool physical=strcmp(args[0], "phys")==0;
+       int (*fn)(struct target_s *target,
+                       uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer);
+       if (physical)
+       {
+               argc--;
+               args++;
+               fn=target_write_phys_memory;
+       } else
+       {
+               fn=target_write_memory;
+       }
+       if ((argc < 2) || (argc > 3))
                return ERROR_COMMAND_SYNTAX_ERROR;
 
        uint32_t address;
@@ -2255,7 +2311,7 @@ static int handle_mw_command(struct command_context_s *cmd_ctx, char *cmd, char
        }
        for (unsigned i = 0; i < count; i++)
        {
-               retval = target_write_memory(target,
+               retval = fn(target,
                                address + i * wordsize, wordsize, 1, value_buf);
                if (ERROR_OK != retval)
                        return retval;
@@ -3452,6 +3508,10 @@ void target_all_handle_event(enum target_event e)
        }
 }
 
+
+/* FIX? should we propagate errors here rather than printing them
+ * and continuing?
+ */
 void target_handle_event(target_t *target, enum target_event e)
 {
        target_event_action_t *teap;
@@ -4093,11 +4153,11 @@ static int tcl_target_func(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
 
                /* do the assert */
                if (n->value == NVP_ASSERT) {
-                       target->type->assert_reset(target);
+                       e = target->type->assert_reset(target);
                } else {
-                       target->type->deassert_reset(target);
+                       e = target->type->deassert_reset(target);
                }
-               return JIM_OK;
+               return (e == ERROR_OK) ? JIM_OK : JIM_ERR;
        case TS_CMD_HALT:
                if (goi.argc) {
                        Jim_WrongNumArgs(goi.interp, 0, argv, "halt [no parameters]");
@@ -4105,8 +4165,8 @@ static int tcl_target_func(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                }
                if (!target->tap->enabled)
                        goto err_tap_disabled;
-               target->type->halt(target);
-               return JIM_OK;
+               e = target->type->halt(target);
+               return (e == ERROR_OK) ? JIM_OK : JIM_ERR;
        case TS_CMD_WAITSTATE:
                /* params:  <name>  statename timeoutmsecs */
                if (goi.argc != 2) {

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)