+// SPDX-License-Identifier: GPL-2.0-or-later
+
/***************************************************************************
* Copyright (C) 2009 by Simon Qian *
* SimonQian@SimonQian.com *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
/* The specification for SVF is available here:
#include "svf.h"
#include "helper/system.h"
#include <helper/time_support.h>
+#include <helper/nvp.h>
+#include <stdbool.h>
/* SVF command */
enum svf_command {
#define XXR_TDO (1 << 1)
#define XXR_MASK (1 << 2)
#define XXR_SMASK (1 << 3)
+
+#define SVF_MAX_ADDCYCLES 255
+
struct svf_xxr_para {
int len;
int data_mask;
static int svf_quiet;
static int svf_nil;
static int svf_ignore_error;
+static bool svf_noreset;
+static int svf_addcycles;
/* Targeting particular tap */
static int svf_tap_is_specified;
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
-#define SVF_MAX_NUM_OF_OPTIONS 5
+#define SVF_MAX_NUM_OF_OPTIONS 8
int command_num = 0;
int ret = ERROR_OK;
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))
svf_nil = 0;
svf_progress_enabled = 0;
svf_ignore_error = 0;
+ svf_noreset = false;
+ svf_addcycles = 0;
+
for (unsigned int i = 0; i < CMD_ARGC; i++) {
- if (strcmp(CMD_ARGV[i], "-tap") == 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_COMMAND_ARGUMENT_INVALID;
+ }
+ i++;
+ 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]);
- return ERROR_FAIL;
+ if (svf_fd)
+ fclose(svf_fd);
+ svf_fd = NULL;
+ 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 {
+ break;
+
+ case OPT_NORESET:
+ svf_noreset = true;
+ 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;
}
}
memcpy(&svf_para, &svf_para_init, sizeof(svf_para));
- if (!svf_nil) {
+ if (!svf_nil && !svf_noreset) {
/* TAP_RESET */
jtag_add_tlr();
}
}
/* HDR %d TDI (0) */
- if (svf_set_padding(&svf_para.hdr_para, header_dr_len, 0) != ERROR_OK) {
- LOG_ERROR("failed to set data header");
- return ERROR_FAIL;
+ ret = svf_set_padding(&svf_para.hdr_para, header_dr_len, 0);
+ if (ret != ERROR_OK) {
+ command_print(CMD, "failed to set data header");
+ goto free_all;
}
/* HIR %d TDI (0xFF) */
- if (svf_set_padding(&svf_para.hir_para, header_ir_len, 0xFF) != ERROR_OK) {
- LOG_ERROR("failed to set instruction header");
- return ERROR_FAIL;
+ ret = svf_set_padding(&svf_para.hir_para, header_ir_len, 0xFF);
+ if (ret != ERROR_OK) {
+ command_print(CMD, "failed to set instruction header");
+ goto free_all;
}
/* TDR %d TDI (0) */
- if (svf_set_padding(&svf_para.tdr_para, trailer_dr_len, 0) != ERROR_OK) {
- LOG_ERROR("failed to set data trailer");
- return ERROR_FAIL;
+ ret = svf_set_padding(&svf_para.tdr_para, trailer_dr_len, 0);
+ if (ret != ERROR_OK) {
+ command_print(CMD, "failed to set data trailer");
+ goto free_all;
}
/* TIR %d TDI (0xFF) */
- if (svf_set_padding(&svf_para.tir_para, trailer_ir_len, 0xFF) != ERROR_OK) {
- LOG_ERROR("failed to set instruction trailer");
- return ERROR_FAIL;
+ ret = svf_set_padding(&svf_para.tir_para, trailer_ir_len, 0xFF);
+ if (ret != ERROR_OK) {
+ command_print(CMD, "failed to set instruction trailer");
+ goto free_all;
}
}
free_all:
fclose(svf_fd);
- svf_fd = 0;
+ svf_fd = NULL;
/* free buffers */
free(svf_command_buffer);
svf_para.dr_end_state);
}
+ if (svf_addcycles)
+ jtag_add_clocks(svf_addcycles);
+
svf_buffer_index += (i + 7) >> 3;
} else if (command == SIR) {
/* check buffer size first, reallocate if necessary */
.handler = handle_svf_command,
.mode = COMMAND_EXEC,
.help = "Runs a SVF file.",
- .usage = "[-tap device.tap] <file> [quiet] [nil] [progress] [ignore_error]",
+ .usage = "[-tap device.tap] [-quiet] [-nil] [-progress] [-ignore_error] [-noreset] [-addcycles numcycles] file",
},
COMMAND_REGISTRATION_DONE
};