target: rewrite command 'arp_examine' as COMMAND_HANDLER 60/7560/3
authorAntonio Borneo <borneo.antonio@gmail.com>
Mon, 27 Mar 2023 09:38:35 +0000 (11:38 +0200)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sat, 27 May 2023 06:40:16 +0000 (06:40 +0000)
Change-Id: I8f227b219ca39f198e1e39847ddd36bb9880a328
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7560
Tested-by: jenkins
src/target/target.c

index fee9583ae964e98fc1ae3e0f0b0ad0aeac290846..785d7651ac1e233c317cd238aeff27983751a55b 100644 (file)
@@ -5639,49 +5639,40 @@ static int jim_target_tap_disabled(Jim_Interp *interp)
        return JIM_ERR;
 }
 
-static int jim_target_examine(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
+COMMAND_HANDLER(handle_target_examine)
 {
        bool allow_defer = false;
 
-       struct jim_getopt_info goi;
-       jim_getopt_setup(&goi, interp, argc - 1, argv + 1);
-       if (goi.argc > 1) {
-               const char *cmd_name = Jim_GetString(argv[0], NULL);
-               Jim_SetResultFormatted(goi.interp,
-                               "usage: %s ['allow-defer']", cmd_name);
-               return JIM_ERR;
-       }
-       if (goi.argc > 0 &&
-           strcmp(Jim_GetString(argv[1], NULL), "allow-defer") == 0) {
-               /* consume it */
-               Jim_Obj *obj;
-               int e = jim_getopt_obj(&goi, &obj);
-               if (e != JIM_OK)
-                       return e;
+       if (CMD_ARGC > 1)
+               return ERROR_COMMAND_SYNTAX_ERROR;
+
+       if (CMD_ARGC == 1) {
+               if (strcmp(CMD_ARGV[0], "allow-defer"))
+                       return ERROR_COMMAND_ARGUMENT_INVALID;
                allow_defer = true;
        }
 
-       struct command_context *cmd_ctx = current_command_context(interp);
-       assert(cmd_ctx);
-       struct target *target = get_current_target(cmd_ctx);
-       if (!target->tap->enabled)
-               return jim_target_tap_disabled(interp);
+       struct target *target = get_current_target(CMD_CTX);
+       if (!target->tap->enabled) {
+               command_print(CMD, "[TAP is disabled]");
+               return ERROR_FAIL;
+       }
 
        if (allow_defer && target->defer_examine) {
                LOG_INFO("Deferring arp_examine of %s", target_name(target));
                LOG_INFO("Use arp_examine command to examine it manually!");
-               return JIM_OK;
+               return ERROR_OK;
        }
 
-       int e = target->type->examine(target);
-       if (e != ERROR_OK) {
+       int retval = target->type->examine(target);
+       if (retval != ERROR_OK) {
                target_reset_examined(target);
-               return JIM_ERR;
+               return retval;
        }
 
        target_set_examined(target);
 
-       return JIM_OK;
+       return ERROR_OK;
 }
 
 COMMAND_HANDLER(handle_target_was_examined)
@@ -6019,7 +6010,7 @@ static const struct command_registration target_instance_command_handlers[] = {
        {
                .name = "arp_examine",
                .mode = COMMAND_EXEC,
-               .jim_handler = jim_target_examine,
+               .handler = handle_target_examine,
                .help = "used internally for reset processing",
                .usage = "['allow-defer']",
        },

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)