aboutsummaryrefslogtreecommitdiff
path: root/src/svf
diff options
context:
space:
mode:
authorAntonio Borneo <borneo.antonio@gmail.com>2023-03-10 11:41:54 +0100
committerAntonio Borneo <borneo.antonio@gmail.com>2023-03-25 18:09:06 +0000
commit5f6ceebbba3a34fc4bfcf56e963739dd2e9cf056 (patch)
treef3d755bbcb469478e63c7f26e885750ca1488d0d /src/svf
parentf8631c3650c0e3a3c3e16726f1ca3748d163cc69 (diff)
downloadriscv-openocd-5f6ceebbba3a34fc4bfcf56e963739dd2e9cf056.zip
riscv-openocd-5f6ceebbba3a34fc4bfcf56e963739dd2e9cf056.tar.gz
riscv-openocd-5f6ceebbba3a34fc4bfcf56e963739dd2e9cf056.tar.bz2
svf: make command 'svf' syntax consistent
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
Diffstat (limited to 'src/svf')
-rw-r--r--src/svf/svf.c95
1 files changed, 77 insertions, 18 deletions
diff --git a/src/svf/svf.c b/src/svf/svf.c
index 2a13312..dd3d517 100644
--- a/src/svf/svf.c
+++ b/src/svf/svf.c
@@ -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
};