140 #define XXR_TDI (1 << 0)
141 #define XXR_TDO (1 << 1)
142 #define XXR_MASK (1 << 2)
143 #define XXR_SMASK (1 << 3)
145 #define SVF_MAX_ADDCYCLES 255
204 #define SVF_CHECK_TDO_PARA_SIZE 1024
220 static int svf_getline(
char **lineptr,
size_t *n, FILE *stream);
222 #define SVF_MAX_BUFFER_SIZE_TO_COMMIT (1024 * 1024)
245 #define SVF_BUF_LOG(_lvl, _buf, _nbits, _desc) \
246 svf_hexbuf_print(LOG_LVL_##_lvl, __FILE__, __LINE__, __func__, _buf, _nbits, _desc)
249 const char *
function,
const uint8_t *buf,
257 char *prbuf = malloc((byte_len * 2) + 2 + 1);
262 uint8_t msb = buf[byte_len - 1] & (msbits ? (1 << msbits) - 1 : 0xff);
263 len = sprintf(prbuf, msbits <= 4 ?
"0x%01"PRIx8 :
"0x%02"PRIx8, msb);
264 for (j = byte_len - 2; j >= 0; j--)
265 len += sprintf(prbuf + len,
"%02"PRIx8, buf[j]);
267 log_printf_lf(dbg_lvl, file, line,
function,
"%8s = %s", desc ? desc :
" ", prbuf);
319 unsigned int index_var;
368 { .name =
"-nil", .value =
OPT_NIL },
371 { .name =
"-quiet", .value =
OPT_QUIET },
372 { .name =
"-tap", .value =
OPT_TAP },
378 { .name =
NULL, .value = -1 }
383 #define SVF_MIN_NUM_OF_OPTIONS 1
384 #define SVF_MAX_NUM_OF_OPTIONS 8
387 int64_t time_measure_ms;
388 int time_measure_s, time_measure_m;
408 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
517 int header_ir_len = 0, header_dr_len = 0, trailer_ir_len = 0, trailer_dr_len = 0;
603 time_measure_ms =
timeval_ms() - time_measure_ms;
604 time_measure_s = time_measure_ms / 1000;
605 time_measure_ms %= 1000;
606 time_measure_m = time_measure_s / 60;
607 time_measure_s %= 60;
608 if (time_measure_ms < 1000)
610 "\r\nTime used: %dm%ds%" PRId64
"ms ",
650 "svf file programmed %s for %d commands with %d errors",
668 *lineptr = malloc(*n);
673 (*lineptr)[0] = fgetc(stream);
674 while ((*lineptr)[i] !=
'\n') {
675 (*lineptr)[++i] = fgetc(stream);
682 *lineptr = realloc(*lineptr, *n);
688 return sizeof(*lineptr);
691 #define SVFP_CMD_INC_CNT 1024
697 int cmd_ok = 0, slash = 0;
703 while (!cmd_ok && (ch != 0)) {
783 int pos = 0, num = 0, space_found = 1, in_bracket = 0;
799 if (!in_bracket && isspace((
int) str[pos])) {
802 }
else if (space_found) {
803 argus[num++] = &str[pos];
829 for (i = 0; i < num_of_element; i++) {
830 if (!strcmp(str, strs[i]))
838 int new_byte_len = (new_bit_len + 7) >> 3;
840 if ((!*arr) || (((orig_bit_len + 7) >> 3) < ((new_bit_len + 7) >> 3))) {
842 *arr = calloc(1, new_byte_len);
855 memset(para->
tdi, tdi, (len + 7) >> 3);
866 int i, str_len = strlen(str), str_hbyte_len = (bit_len + 3) >> 2;
870 LOG_ERROR(
"fail to adjust length of array");
875 for (i = 0; i < str_hbyte_len; i++) {
877 while (str_len > 0) {
887 if ((ch >=
'0') && (ch <=
'9')) {
890 }
else if ((ch >=
'A') && (ch <=
'F')) {
905 (*bin)[i / 2] |= ch << 4;
914 while (str_len > 0 && ((str[str_len - 1] ==
'0')
915 || isspace((
int) str[str_len - 1])))
919 if (str_len > 0 || (ch & ~((2 << ((bit_len - 1) % 4)) - 1)) != 0) {
929 int i, len, index_var;
957 LOG_ERROR(
"toooooo many operation undone");
985 int num_of_argu = 0, i;
995 uint8_t **pbuffer_tmp;
1000 int padding_command_skipped = 0;
1014 if (num_of_argu != 2) {
1015 LOG_ERROR(
"invalid parameter of %s", argus[0]);
1032 LOG_ERROR(
"%s: %s is not a stable state",
1033 argus[0], argus[1]);
1038 if ((num_of_argu != 1) && (num_of_argu != 3)) {
1039 LOG_ERROR(
"invalid parameter of %s", argus[0]);
1042 if (num_of_argu == 1) {
1046 if (strcmp(argus[2],
"HZ")) {
1047 LOG_ERROR(
"HZ not found in FREQUENCY command");
1064 padding_command_skipped = 1;
1071 padding_command_skipped = 1;
1078 padding_command_skipped = 1;
1085 padding_command_skipped = 1;
1098 if ((num_of_argu > 10) || (num_of_argu % 2)) {
1099 LOG_ERROR(
"invalid parameter of %s", argus[0]);
1102 i_tmp = xxr_para_tmp->
len;
1103 xxr_para_tmp->
len = atoi(argus[1]);
1106 if (i_tmp < xxr_para_tmp->len) {
1107 free(xxr_para_tmp->
tdi);
1109 free(xxr_para_tmp->
tdo);
1111 free(xxr_para_tmp->
mask);
1113 free(xxr_para_tmp->
smask);
1119 for (i = 2; i < num_of_argu; i += 2) {
1120 if ((strlen(argus[i + 1]) < 3) || (argus[i + 1][0] !=
'(') ||
1121 (argus[i + 1][strlen(argus[i + 1]) - 1] !=
')')) {
1125 argus[i + 1][strlen(argus[i + 1]) - 1] =
'\0';
1127 if (!strcmp(argus[i],
"TDI")) {
1129 pbuffer_tmp = &xxr_para_tmp->
tdi;
1131 }
else if (!strcmp(argus[i],
"TDO")) {
1133 pbuffer_tmp = &xxr_para_tmp->
tdo;
1135 }
else if (!strcmp(argus[i],
"MASK")) {
1137 pbuffer_tmp = &xxr_para_tmp->
mask;
1139 }
else if (!strcmp(argus[i],
"SMASK")) {
1141 pbuffer_tmp = &xxr_para_tmp->
smask;
1144 LOG_ERROR(
"unknown parameter: %s", argus[i]);
1149 xxr_para_tmp->
len)) {
1162 xxr_para_tmp->
len)) {
1163 LOG_ERROR(
"fail to adjust length of array");
1170 if (!xxr_para_tmp->
tdo) {
1173 xxr_para_tmp->
len)) {
1174 LOG_ERROR(
"fail to adjust length of array");
1178 if (!xxr_para_tmp->
mask) {
1181 xxr_para_tmp->
len)) {
1182 LOG_ERROR(
"fail to adjust length of array");
1186 memset(xxr_para_tmp->
mask, 0, (xxr_para_tmp->
len + 7) >> 3);
1377 LOG_ERROR(
"PIO and PIOMAP are not supported");
1384 if ((num_of_argu < 3) || (num_of_argu > 11)) {
1385 LOG_ERROR(
"invalid parameter of %s", argus[0]);
1412 if (((i + 2) <= num_of_argu) && strcmp(argus[i + 1],
"SEC")) {
1413 if (!strcmp(argus[i + 1],
"TCK")) {
1415 run_count = atoi(argus[i]);
1416 LOG_DEBUG(
"\trun_count@TCK = %d", run_count);
1418 LOG_ERROR(
"%s not supported for clock", argus[i + 1]);
1424 if (((i + 2) <= num_of_argu) && !strcmp(argus[i + 1],
"SEC")) {
1425 min_time = atof(argus[i]);
1426 LOG_DEBUG(
"\tmin_time = %fs", min_time);
1430 if (((i + 3) <= num_of_argu) &&
1431 !strcmp(argus[i],
"MAXIMUM") && !strcmp(argus[i + 2],
"SEC")) {
1433 max_time = atof(argus[i + 1]);
1434 LOG_DEBUG(
"\tmax_time = %fs", max_time);
1438 if (((i + 2) <= num_of_argu) && !strcmp(argus[i],
"ENDSTATE")) {
1452 if (i == num_of_argu) {
1455 uint32_t min_usec = 1000000 * min_time;
1462 if (run_count > 0) {
1487 LOG_ERROR(
"fail to parse parameter of RUNTEST, %d out of %d is parsed",
1495 if (num_of_argu < 2) {
1496 LOG_ERROR(
"invalid parameter of %s", argus[0]);
1499 if (num_of_argu > 2) {
1501 path = malloc((num_of_argu - 1) *
sizeof(
tap_state_t));
1508 for (i = 0; i < num_of_argu; i++, i_tmp++) {
1511 LOG_ERROR(
"%s: %s is not a valid state", argus[0], argus[i_tmp]);
1524 num_of_argu -= i + 1;
1528 if (num_of_argu > 0) {
1537 LOG_ERROR(
"%s: %s is not a stable state",
1551 LOG_DEBUG(
"\tmove to %s by svf_add_statemove",
1556 LOG_ERROR(
"%s: %s is not a stable state",
1564 if (num_of_argu != 2) {
1565 LOG_ERROR(
"invalid parameter of %s", argus[0]);
1587 LOG_ERROR(
"unknown TRST mode: %s", argus[1]);
1593 LOG_ERROR(
"can not accept TRST command if trst_mode is ABSENT");
1598 LOG_ERROR(
"invalid svf command: %s", argus[0]);
1603 if (padding_command_skipped)
1604 LOG_USER(
"(Above Padding command skipped, as per -tap argument)");
1635 .handler = handle_svf_command,
1637 .help =
"Runs a SVF file.",
1638 .usage =
"[-tap device.tap] [-quiet] [-nil] [-progress] [-ignore_error] [-noreset] [-addcycles numcycles] file",
void * buf_set_buf(const void *_src, unsigned int src_start, void *_dst, unsigned int dst_start, unsigned int len)
void * buf_set_ones(void *_buf, unsigned int size)
Set the contents of buf with count bits, all set to 1.
bool buf_eq_mask(const void *_buf1, const void *_buf2, const void *_mask, unsigned int size)
void command_print(struct command_invocation *cmd, const char *format,...)
int command_run_linef(struct command_context *context, const char *format,...)
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define ERROR_COMMAND_SYNTAX_ERROR
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
#define CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
#define ERROR_COMMAND_ARGUMENT_INVALID
static int register_commands(struct command_context *cmd_ctx, const char *cmd_prefix, const struct command_registration *cmds)
Register one or more commands in the specified context, as children of parent (or top-level commends,...
const char * tap_state_name(tap_state_t state)
Function tap_state_name Returns a string suitable for display representing the JTAG tap_state.
tap_state_t tap_state_by_name(const char *name)
Provides user-friendly name lookup of TAP states.
struct jtag_tap * jtag_tap_by_string(const char *s)
void jtag_add_runtest(unsigned int num_cycles, tap_state_t state)
Goes to TAP_IDLE (if we're not already there), cycle precisely num_cycles in the TAP_IDLE state,...
void jtag_add_pathmove(unsigned int num_states, const tap_state_t *path)
Application code must assume that interfaces will implement transitions between states with different...
void jtag_add_plain_dr_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits, tap_state_t state)
Scan out the bits in ir scan mode.
void jtag_add_reset(int req_tlr_or_trst, int req_srst)
A reset of the TAP state machine can be requested.
void jtag_add_plain_ir_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits, tap_state_t state)
Scan out the bits in ir scan mode.
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
void jtag_add_clocks(unsigned int num_cycles)
Function jtag_add_clocks first checks that the state in which the clocks are to be issued is stable,...
struct jtag_tap * jtag_all_taps(void)
tap_state_t cmd_queue_cur_state
The current TAP state of the pending JTAG command queue.
void jtag_add_tlr(void)
Run a TAP_RESET reset where the end state is TAP_RESET, regardless of the start state.
void jtag_add_sleep(uint32_t us)
The JTAG interface can be implemented with a software or hardware fifo.
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
void log_printf_lf(enum log_levels level, const char *file, unsigned int line, const char *function, const char *format,...)
#define LOG_USER(expr ...)
#define LOG_USER_N(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
const struct nvp * nvp_name2value(const struct nvp *p, const char *name)
unsigned int ir_length
size of instruction register
unsigned int abs_chain_position
bool enabled
Is this TAP currently enabled?
struct jtag_tap * next_tap
Name Value Pairs, aka: NVP.
This structure defines a single scan field in the scan.
uint8_t * in_value
A pointer to a 32-bit memory location for data scanned out.
const uint8_t * out_value
A pointer to value to be scanned into the device.
unsigned int num_bits
The number of bits this field specifies.
struct svf_xxr_para sir_para
struct svf_xxr_para tir_para
tap_state_t runtest_run_state
struct svf_xxr_para sdr_para
struct svf_xxr_para hdr_para
struct svf_xxr_para hir_para
struct svf_xxr_para tdr_para
tap_state_t runtest_end_state
static size_t svf_read_line_size
static int svf_realloc_buffers(size_t len)
bool svf_tap_state_is_stable(tap_state_t state)
svf_tap_state_is_stable() returns true for stable non-SHIFT states
static long svf_total_lines
static int svf_check_tdo_para_index
static const struct svf_para svf_para_init
static int svf_getline(char **lineptr, size_t *n, FILE *stream)
static int svf_set_padding(struct svf_xxr_para *para, int len, unsigned char tdi)
static int svf_adjust_array_length(uint8_t **arr, int orig_bit_len, int new_bit_len)
static size_t svf_command_buffer_size
#define SVF_CHECK_TDO_PARA_SIZE
static uint8_t * svf_tdi_buffer
static int svf_tap_is_specified
#define SVF_MAX_BUFFER_SIZE_TO_COMMIT
COMMAND_HANDLER(handle_svf_command)
static uint8_t * svf_tdo_buffer
static int svf_copy_hexstring_to_binary(char *str, uint8_t **bin, int orig_bit_len, int bit_len)
static int svf_check_tdo(void)
#define SVF_MAX_NUM_OF_OPTIONS
int svf_add_statemove(tap_state_t state_to)
svf_add_statemove() moves from the current state to goal_state.
static const struct svf_statemove svf_statemoves[]
int svf_register_commands(struct command_context *cmd_ctx)
static int svf_percentage
#define SVF_MIN_NUM_OF_OPTIONS
static int svf_execute_tap(void)
static char * svf_read_line
static int svf_buffer_index
static const char * svf_command_name[14]
static struct svf_check_tdo_para * svf_check_tdo_para
static int svf_run_command(struct command_context *cmd_ctx, char *cmd_str)
static int svf_last_printed_percentage
static int svf_parse_cmd_string(char *str, int len, char **argus, int *num_of_argu)
static const char * svf_trst_mode_name[4]
#define SVF_MAX_ADDCYCLES
static const struct command_registration svf_command_handlers[]
static const struct nvp svf_cmd_opts[]
static int svf_line_number
@ DEPRECATED_OPT_IGNORE_ERROR
@ DEPRECATED_OPT_PROGRESS
static void svf_free_xxd_para(struct svf_xxr_para *para)
static int svf_read_command_from_file(FILE *fd)
static void svf_hexbuf_print(int dbg_lvl, const char *file, unsigned int line, const char *function, const uint8_t *buf, int bit_len, const char *desc)
static int svf_add_check_para(uint8_t enabled, int buffer_offset, int bit_len)
static char * svf_command_buffer
#define SVF_BUF_LOG(_lvl, _buf, _nbits, _desc)
static int svf_find_string_in_array(char *str, char **strs, int num_of_element)
static int svf_ignore_error
static int svf_progress_enabled
static int svf_buffer_size
static uint8_t * svf_mask_buffer
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.