add jim_handler to command_registration
[openocd.git] / src / target / target.c
index 6f48808fafdf5a80f1795e5829040ae7b3b94c2d..4a9095a6764d8565bdbbcccf6b3ff83ee1894234 100644 (file)
@@ -777,12 +777,14 @@ int target_init(struct command_context *cmd_ctx)
                        target->type->mcr = default_mcr;
                } else
                {
-                       /* FIX! multiple targets will generally register global commands
-                        * multiple times. Only register this one if *one* of the
-                        * targets need the command. Hmm... make it a command on the
-                        * Jim Tcl target object?
-                        */
-                       register_jim(cmd_ctx, "mcr", jim_mcrmrc, "write coprocessor <cpnum> <op1> <op2> <CRn> <CRm> <value>");
+                       const struct command_registration mcr_cmd = {
+                               .name = "mcr",
+                               .mode = COMMAND_EXEC,
+                               .jim_handler = &jim_mcrmrc,
+                               .help = "write coprocessor",
+                               .usage = "<cpnum> <op1> <op2> <CRn> <CRm> <value>",
+                       };
+                       register_command(cmd_ctx, NULL, &mcr_cmd);
                }
 
                if (target->type->mrc == NULL)
@@ -790,7 +792,13 @@ int target_init(struct command_context *cmd_ctx)
                        target->type->mrc = default_mrc;
                } else
                {
-                       register_jim(cmd_ctx, "mrc", jim_mcrmrc, "read coprocessor <cpnum> <op1> <op2> <CRn> <CRm>");
+                       const struct command_registration mrc_cmd = {
+                               .name = "mrc",
+                               .jim_handler = &jim_mcrmrc,
+                               .help = "read coprocessor",
+                               .usage = "<cpnum> <op1> <op2> <CRn> <CRm>",
+                       };
+                       register_command(cmd_ctx, NULL, &mrc_cmd);
                }
 
 
@@ -4353,9 +4361,14 @@ static int target_create(Jim_GetOptInfo *goi)
        if (!target->variant)
                target->variant = strdup("");
 
+       cp = Jim_GetString(new_cmd, NULL);
+       target->cmd_name = strdup(cp);
+
        /* create the target specific commands */
-       if (target->type->register_commands) {
-               (*(target->type->register_commands))(cmd_ctx);
+       if (target->type->commands) {
+               e = register_commands(cmd_ctx, NULL, target->type->commands);
+               if (ERROR_OK != e)
+                       LOG_ERROR("unable to register '%s' commands", cp);
        }
        if (target->type->target_create) {
                (*(target->type->target_create))(target, goi->interp);
@@ -4371,18 +4384,15 @@ static int target_create(Jim_GetOptInfo *goi)
                *tpp = target;
        }
 
-       cp = Jim_GetString(new_cmd, NULL);
-       target->cmd_name = strdup(cp);
-
        /* now - create the new target name command */
-       e = Jim_CreateCommand(goi->interp,
-                                                  /* name */
-                                                  cp,
-                                                  tcl_target_func, /* C function */
-                                                  target, /* private data */
-                                                  NULL); /* no del proc */
-
-       return e;
+       const struct command_registration target_command = {
+               .name = cp,
+               .jim_handler = &tcl_target_func,
+               .jim_handler_data = target,
+               .help = "target command group",
+       };
+       struct command *c = register_command(cmd_ctx, NULL, &target_command);
+       return (NULL != c) ? ERROR_OK : ERROR_FAIL;
 }
 
 static int jim_target(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
@@ -4771,12 +4781,17 @@ static const struct command_registration target_command_handlers[] = {
                        "or list targets (no parameters)",
                .usage = "[<new_current_target>]",
        },
+       {
+               .name = "target",
+               .mode = COMMAND_CONFIG,
+               .jim_handler = &jim_target,
+               .help = "configure target",
+       },
        COMMAND_REGISTRATION_DONE
 };
 
 int target_register_commands(struct command_context *cmd_ctx)
 {
-       register_jim(cmd_ctx, "target", jim_target, "configure target");
        return register_commands(cmd_ctx, NULL, target_command_handlers);
 }
 
@@ -4965,6 +4980,22 @@ static const struct command_registration target_exec_command_handlers[] = {
                .mode = COMMAND_EXEC,
                .usage = "<file> [offset] [type]",
        },
+       {
+               .name = "ocd_mem2array",
+               .mode = COMMAND_EXEC,
+               .jim_handler = &jim_mem2array,
+               .help = "read memory and return as a TCL array "
+                       "for script processing",
+               .usage = "<arrayname> <width=32|16|8> <address> <count>",
+       },
+       {
+               .name = "ocd_array2mem",
+               .mode = COMMAND_EXEC,
+               .jim_handler = &jim_array2mem,
+               .help = "convert a TCL array to memory locations "
+                       "and write the values",
+               .usage = "<arrayname> <width=32|16|8> <address> <count>",
+       },
        COMMAND_REGISTRATION_DONE
 };
 int target_register_user_commands(struct command_context *cmd_ctx)
@@ -4976,13 +5007,6 @@ int target_register_user_commands(struct command_context *cmd_ctx)
        if ((retval = trace_register_commands(cmd_ctx)) != ERROR_OK)
                return retval;
 
-       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>");
 
        return register_commands(cmd_ctx, NULL, target_exec_command_handlers);
 }

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)