svf: make command 'svf' syntax consistent 34/7534/2
authorAntonio Borneo <borneo.antonio@gmail.com>
Fri, 10 Mar 2023 10:41:54 +0000 (11:41 +0100)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sat, 25 Mar 2023 18:09:06 +0000 (18:09 +0000)
The command 'svf' is the only command in OpenOCD that accepts
options in both forms 'option' and '-option'.

Deprecate the option format without the leading '-'.
Update the documentation and fix the on-line help.
While there:
- switch to use the new nvp.h helper;
- return ERROR_COMMAND_ARGUMENT_INVALID on invalid command args;
- fix some minor coding style rule.

Change-Id: I5b944403d92a3fa1e12d5faafc1d2a139bc16a7d
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7534
Tested-by: jenkins
doc/openocd.texi
src/svf/svf.c

index 0de101b6da142ca41351059d2df0e19ec99914bc..26a59e6a72ba91818699b851fcaeb959b12a1f6e 100644 (file)
@@ -11432,8 +11432,8 @@ way to represent JTAG test patterns in text files.
 In a debug session using JTAG for its transport protocol,
 OpenOCD supports running such test files.
 
-@deffn {Command} {svf} @file{filename} [@option{-tap @var{tapname}}] [@option{[-]quiet}] @
-                     [@option{[-]nil}] [@option{[-]progress}] [@option{[-]ignore_error}] @
+@deffn {Command} {svf} @file{filename} [@option{-tap @var{tapname}}] [@option{-quiet}] @
+                     [@option{-nil}] [@option{-progress}] [@option{-ignore_error}] @
                      [@option{-noreset}] [@option{-addcycles @var{cyclecount}}]
 This issues a JTAG reset (Test-Logic-Reset) and then
 runs the SVF script from @file{filename}.
@@ -11447,11 +11447,11 @@ Command options:
 specified by the SVF file with HIR, TIR, HDR and TDR commands;
 instead, calculate them automatically according to the current JTAG
 chain configuration, targeting @var{tapname};
-@item @option{[-]quiet} do not log every command before execution;
-@item @option{[-]nil} ``dry run'', i.e., do not perform any operations
+@item @option{-quiet} do not log every command before execution;
+@item @option{-nil} ``dry run'', i.e., do not perform any operations
 on the real interface;
-@item @option{[-]progress} enable progress indication;
-@item @option{[-]ignore_error} continue execution despite TDO check
+@item @option{-progress} enable progress indication;
+@item @option{-ignore_error} continue execution despite TDO check
 errors.
 @item @option{-noreset} omit JTAG reset (Test-Logic-Reset) before executing
 content of the SVF file;
index 2a133128045da6aa970443e1b9f02f328bfc71eb..dd3d5175c37d4ff468790dcc564d538e58e91e4c 100644 (file)
@@ -22,6 +22,7 @@
 #include "svf.h"
 #include "helper/system.h"
 #include <helper/time_support.h>
+#include <helper/nvp.h>
 #include <stdbool.h>
 
 /* SVF command */
@@ -346,6 +347,37 @@ int svf_add_statemove(tap_state_t state_to)
        return ERROR_FAIL;
 }
 
+enum svf_cmd_param {
+       OPT_ADDCYCLES,
+       OPT_IGNORE_ERROR,
+       OPT_NIL,
+       OPT_NORESET,
+       OPT_PROGRESS,
+       OPT_QUIET,
+       OPT_TAP,
+       /* DEPRECATED */
+       DEPRECATED_OPT_IGNORE_ERROR,
+       DEPRECATED_OPT_NIL,
+       DEPRECATED_OPT_PROGRESS,
+       DEPRECATED_OPT_QUIET,
+};
+
+static const struct nvp svf_cmd_opts[] = {
+       { .name = "-addcycles",    .value = OPT_ADDCYCLES },
+       { .name = "-ignore_error", .value = OPT_IGNORE_ERROR },
+       { .name = "-nil",          .value = OPT_NIL },
+       { .name = "-noreset",      .value = OPT_NORESET },
+       { .name = "-progress",     .value = OPT_PROGRESS },
+       { .name = "-quiet",        .value = OPT_QUIET },
+       { .name = "-tap",          .value = OPT_TAP },
+       /* DEPRECATED */
+       { .name = "ignore_error",  .value = DEPRECATED_OPT_IGNORE_ERROR },
+       { .name = "nil",           .value = DEPRECATED_OPT_NIL },
+       { .name = "progress",      .value = DEPRECATED_OPT_PROGRESS },
+       { .name = "quiet",         .value = DEPRECATED_OPT_QUIET },
+       { .name = NULL,            .value = -1 }
+};
+
 COMMAND_HANDLER(handle_svf_command)
 {
 #define SVF_MIN_NUM_OF_OPTIONS 1
@@ -355,10 +387,11 @@ COMMAND_HANDLER(handle_svf_command)
        int64_t time_measure_ms;
        int time_measure_s, time_measure_m;
 
-       /* use NULL to indicate a "plain" svf file which accounts for
+       /*
+        * use NULL to indicate a "plain" svf file which accounts for
         * any additional devices in the scan chain, otherwise the device
         * that should be affected
-       */
+        */
        struct jtag_tap *tap = NULL;
 
        if ((CMD_ARGC < SVF_MIN_NUM_OF_OPTIONS) || (CMD_ARGC > SVF_MAX_NUM_OF_OPTIONS))
@@ -373,48 +406,74 @@ COMMAND_HANDLER(handle_svf_command)
        svf_addcycles = 0;
 
        for (unsigned int i = 0; i < CMD_ARGC; i++) {
-               if (strcmp(CMD_ARGV[i], "-addcycles") == 0) {
+               const struct nvp *n = nvp_name2value(svf_cmd_opts, CMD_ARGV[i]);
+               switch (n->value) {
+               case OPT_ADDCYCLES:
                        svf_addcycles = atoi(CMD_ARGV[i + 1]);
                        if (svf_addcycles > SVF_MAX_ADDCYCLES) {
                                command_print(CMD, "addcycles: %s out of range", CMD_ARGV[i + 1]);
                                if (svf_fd)
                                        fclose(svf_fd);
                                svf_fd = NULL;
-                               return ERROR_FAIL;
+                               return ERROR_COMMAND_ARGUMENT_INVALID;
                        }
                        i++;
-               } else if (strcmp(CMD_ARGV[i], "-tap") == 0) {
+                       break;
+
+               case OPT_TAP:
                        tap = jtag_tap_by_string(CMD_ARGV[i+1]);
                        if (!tap) {
                                command_print(CMD, "Tap: %s unknown", CMD_ARGV[i+1]);
                                if (svf_fd)
                                        fclose(svf_fd);
                                svf_fd = NULL;
-                               return ERROR_FAIL;
+                               return ERROR_COMMAND_ARGUMENT_INVALID;
                        }
                        i++;
-               } else if ((strcmp(CMD_ARGV[i],
-                               "quiet") == 0) || (strcmp(CMD_ARGV[i], "-quiet") == 0))
+                       break;
+
+               case DEPRECATED_OPT_QUIET:
+                       LOG_INFO("DEPRECATED flag '%s'; use '-%s'", CMD_ARGV[i], CMD_ARGV[i]);
+                       /* fallthrough */
+               case OPT_QUIET:
                        svf_quiet = 1;
-               else if ((strcmp(CMD_ARGV[i], "nil") == 0) || (strcmp(CMD_ARGV[i], "-nil") == 0))
+                       break;
+
+               case DEPRECATED_OPT_NIL:
+                       LOG_INFO("DEPRECATED flag '%s'; use '-%s'", CMD_ARGV[i], CMD_ARGV[i]);
+                       /* fallthrough */
+               case OPT_NIL:
                        svf_nil = 1;
-               else if ((strcmp(CMD_ARGV[i],
-                                 "progress") == 0) || (strcmp(CMD_ARGV[i], "-progress") == 0))
+                       break;
+
+               case DEPRECATED_OPT_PROGRESS:
+                       LOG_INFO("DEPRECATED flag '%s'; use '-%s'", CMD_ARGV[i], CMD_ARGV[i]);
+                       /* fallthrough */
+               case OPT_PROGRESS:
                        svf_progress_enabled = 1;
-               else if ((strcmp(CMD_ARGV[i],
-                                 "ignore_error") == 0) || (strcmp(CMD_ARGV[i], "-ignore_error") == 0))
+                       break;
+
+               case DEPRECATED_OPT_IGNORE_ERROR:
+                       LOG_INFO("DEPRECATED flag '%s'; use '-%s'", CMD_ARGV[i], CMD_ARGV[i]);
+                       /* fallthrough */
+               case OPT_IGNORE_ERROR:
                        svf_ignore_error = 1;
-               else if (strcmp(CMD_ARGV[i], "-noreset") == 0)
+                       break;
+
+               case OPT_NORESET:
                        svf_noreset = true;
-               else {
+                       break;
+
+               default:
                        svf_fd = fopen(CMD_ARGV[i], "r");
                        if (!svf_fd) {
                                int err = errno;
                                command_print(CMD, "open(\"%s\"): %s", CMD_ARGV[i], strerror(err));
                                /* no need to free anything now */
                                return ERROR_COMMAND_SYNTAX_ERROR;
-                       } else
-                               LOG_USER("svf processing file: \"%s\"", CMD_ARGV[i]);
+                       }
+                       LOG_USER("svf processing file: \"%s\"", CMD_ARGV[i]);
+                       break;
                }
        }
 
@@ -1576,7 +1635,7 @@ static const struct command_registration svf_command_handlers[] = {
                .handler = handle_svf_command,
                .mode = COMMAND_EXEC,
                .help = "Runs a SVF file.",
-               .usage = "[-tap device.tap] <file> [quiet] [nil] [progress] [ignore_error] [-noreset] [-addcycles numcycles]",
+               .usage = "[-tap device.tap] [-quiet] [-nil] [-progress] [-ignore_error] [-noreset] [-addcycles numcycles] file",
        },
        COMMAND_REGISTRATION_DONE
 };

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)