fix array2mem/mem2array when used as a "method" on a target.
[openocd.git] / src / target / target.c
index 68fad2fe89194c8f1d12e4bd9f30da2ae3ab6fab..3ec28284e6da22a93662c51d2a1b891ee02e7786 100644 (file)
@@ -1285,8 +1285,8 @@ int target_register_user_commands(struct command_context_s *cmd_ctx)
 
        /* script procedures */
        register_command(cmd_ctx, NULL, "profile", handle_profile_command, COMMAND_EXEC, "profiling samples the CPU PC");
-       register_jim(cmd_ctx, "ocd_mem2array", jim_mem2array, "read memory and return as a TCL array for script processing");
-       register_jim(cmd_ctx, "ocd_array2mem", jim_array2mem, "convert a TCL array to memory locations and write the values");
+       register_jim(cmd_ctx, "ocd_mem2array", jim_mem2array, "read memory and return as a TCL array for script processing <ARRAYNAME> <WIDTH=32/16/8> <ADDRESS> <COUNT>");
+       register_jim(cmd_ctx, "ocd_array2mem", jim_array2mem, "convert a TCL array to memory locations and write the values  <ARRAYNAME> <WIDTH=32/16/8> <ADDRESS> <COUNT>");
 
        register_command(cmd_ctx, NULL, "fast_load_image", handle_fast_load_image_command, COMMAND_ANY,
                        "same args as load_image, image stored in memory - mainly for profiling purposes");
@@ -2115,12 +2115,6 @@ static int handle_dump_image_command(struct command_context_s *cmd_ctx, char *cm
        address = strtoul(args[1], NULL, 0);
        size = strtoul(args[2], NULL, 0);
 
-       if ((address & 3) || (size & 3))
-       {
-               command_print(cmd_ctx, "only 32-bit aligned address and size are supported");
-               return ERROR_OK;
-       }
-
        if (fileio_open(&fileio, args[0], FILEIO_WRITE, FILEIO_BINARY) != ERROR_OK)
        {
                return ERROR_OK;
@@ -2133,7 +2127,7 @@ static int handle_dump_image_command(struct command_context_s *cmd_ctx, char *cm
                u32 size_written;
                u32 this_run_size = (size > 560) ? 560 : size;
 
-               retval = target->type->read_memory(target, address, 4, this_run_size / 4, buffer);
+               retval = target_read_buffer(target, address, this_run_size, buffer);
                if (retval != ERROR_OK)
                {
                        break;
@@ -2158,10 +2152,10 @@ static int handle_dump_image_command(struct command_context_s *cmd_ctx, char *cm
        if (retval==ERROR_OK)
        {
                command_print(cmd_ctx, "dumped %"PRIi64" byte in %s", fileio.size, duration_text);
+               free(duration_text);
        }
-       free(duration_text);
 
-       return ERROR_OK;
+       return retval;
 }
 
 static int handle_verify_image_command_internal(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc, int verify)
@@ -2727,7 +2721,7 @@ static int jim_mem2array(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                return JIM_ERR;
        }
 
-       return  target_mem2array(interp, target, argc,argv);
+       return  target_mem2array(interp, target, argc-1, argv+1);
 }
 
 static int target_mem2array(Jim_Interp *interp, target_t *target, int argc, Jim_Obj *const *argv)
@@ -2748,25 +2742,25 @@ static int target_mem2array(Jim_Interp *interp, target_t *target, int argc, Jim_
         * argv[3] = memory address
         * argv[4] = count of times to read
         */
-       if (argc != 5) {
+       if (argc != 4) {
                Jim_WrongNumArgs(interp, 1, argv, "varname width addr nelems");
                return JIM_ERR;
        }
-       varname = Jim_GetString(argv[1], &len);
+       varname = Jim_GetString(argv[0], &len);
        /* given "foo" get space for worse case "foo(%d)" .. add 20 */
 
-       e = Jim_GetLong(interp, argv[2], &l);
+       e = Jim_GetLong(interp, argv[1], &l);
        width = l;
        if (e != JIM_OK) {
                return e;
        }
 
-       e = Jim_GetLong(interp, argv[3], &l);
+       e = Jim_GetLong(interp, argv[2], &l);
        addr = l;
        if (e != JIM_OK) {
                return e;
        }
-       e = Jim_GetLong(interp, argv[4], &l);
+       e = Jim_GetLong(interp, argv[3], &l);
        len = l;
        if (e != JIM_OK) {
                return e;
@@ -2909,7 +2903,7 @@ static int jim_array2mem(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                return JIM_ERR;
        }
 
-       return target_array2mem( interp,target, argc, argv );
+       return target_array2mem( interp,target, argc-1, argv+1 );
 }
 
 static int target_array2mem(Jim_Interp *interp, target_t *target, int argc, Jim_Obj *const *argv)
@@ -2930,25 +2924,25 @@ static int target_array2mem(Jim_Interp *interp, target_t *target, int argc, Jim_
         * argv[3] = memory address
         * argv[4] = count to write
         */
-       if (argc != 5) {
+       if (argc != 4) {
                Jim_WrongNumArgs(interp, 1, argv, "varname width addr nelems");
                return JIM_ERR;
        }
-       varname = Jim_GetString(argv[1], &len);
+       varname = Jim_GetString(argv[0], &len);
        /* given "foo" get space for worse case "foo(%d)" .. add 20 */
 
-       e = Jim_GetLong(interp, argv[2], &l);
+       e = Jim_GetLong(interp, argv[1], &l);
        width = l;
        if (e != JIM_OK) {
                return e;
        }
 
-       e = Jim_GetLong(interp, argv[3], &l);
+       e = Jim_GetLong(interp, argv[2], &l);
        addr = l;
        if (e != JIM_OK) {
                return e;
        }
-       e = Jim_GetLong(interp, argv[4], &l);
+       e = Jim_GetLong(interp, argv[3], &l);
        len = l;
        if (e != JIM_OK) {
                return e;

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)