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 bool space_found =
true, in_bracket =
false;
784 int pos = 0, num = 0;
802 if (!in_bracket && isspace((
int)str[pos])) {
805 }
else if (space_found) {
806 argus[num++] = &str[pos];
831 for (i = 0; i < num_of_element; i++) {
832 if (!strcmp(str, strs[i]))
840 int new_byte_len = (new_bit_len + 7) >> 3;
842 if ((!*arr) || (((orig_bit_len + 7) >> 3) < ((new_bit_len + 7) >> 3))) {
844 *arr = calloc(1, new_byte_len);
857 memset(para->
tdi, tdi, (len + 7) >> 3);
868 int i, str_len = strlen(str), str_hbyte_len = (bit_len + 3) >> 2;
872 LOG_ERROR(
"fail to adjust length of array");
877 for (i = 0; i < str_hbyte_len; i++) {
879 while (str_len > 0) {
889 if ((ch >=
'0') && (ch <=
'9')) {
892 }
else if ((ch >=
'A') && (ch <=
'F')) {
907 (*bin)[i / 2] |= ch << 4;
916 while (str_len > 0 && ((str[str_len - 1] ==
'0')
917 || isspace((
int) str[str_len - 1])))
921 if (str_len > 0 || (ch & ~((2 << ((bit_len - 1) % 4)) - 1)) != 0) {
931 int i, len, index_var;
959 LOG_ERROR(
"toooooo many operation undone");
987 uint8_t **pbuffer_tmp;
991 if (num_of_argu > 10 || (num_of_argu % 2)) {
992 LOG_ERROR(
"invalid parameter of %s", argus[0]);
995 i_tmp = xxr_para_tmp->
len;
996 xxr_para_tmp->
len = atoi(argus[1]);
999 if (i_tmp < xxr_para_tmp->len) {
1000 free(xxr_para_tmp->
tdi);
1002 free(xxr_para_tmp->
tdo);
1004 free(xxr_para_tmp->
mask);
1006 free(xxr_para_tmp->
smask);
1012 for (i = 2; i < num_of_argu; i += 2) {
1013 if ((strlen(argus[i + 1]) < 3) || (argus[i + 1][0] !=
'(') ||
1014 argus[i + 1][strlen(argus[i + 1]) - 1] !=
')') {
1018 argus[i + 1][strlen(argus[i + 1]) - 1] =
'\0';
1020 if (!strcmp(argus[i],
"TDI")) {
1022 pbuffer_tmp = &xxr_para_tmp->
tdi;
1024 }
else if (!strcmp(argus[i],
"TDO")) {
1026 pbuffer_tmp = &xxr_para_tmp->
tdo;
1028 }
else if (!strcmp(argus[i],
"MASK")) {
1030 pbuffer_tmp = &xxr_para_tmp->
mask;
1032 }
else if (!strcmp(argus[i],
"SMASK")) {
1034 pbuffer_tmp = &xxr_para_tmp->
smask;
1037 LOG_ERROR(
"unknown parameter: %s", argus[i]);
1054 LOG_ERROR(
"fail to adjust length of array");
1061 if (!xxr_para_tmp->
tdo) {
1064 LOG_ERROR(
"fail to adjust length of array");
1068 if (!xxr_para_tmp->
mask) {
1071 LOG_ERROR(
"fail to adjust length of array");
1075 memset(xxr_para_tmp->
mask, 0, (xxr_para_tmp->
len + 7) >> 3);
1272 int num_of_argu = 0, i, retval;
1283 int padding_command_skipped = 0;
1297 if (num_of_argu != 2) {
1298 LOG_ERROR(
"invalid parameter of %s", argus[0]);
1315 LOG_ERROR(
"%s: %s is not a stable state",
1316 argus[0], argus[1]);
1321 if (num_of_argu != 1 && num_of_argu != 3) {
1322 LOG_ERROR(
"invalid parameter of %s", argus[0]);
1325 if (num_of_argu == 1) {
1329 if (strcmp(argus[2],
"HZ")) {
1330 LOG_ERROR(
"HZ not found in FREQUENCY command");
1347 padding_command_skipped = 1;
1356 padding_command_skipped = 1;
1365 padding_command_skipped = 1;
1374 padding_command_skipped = 1;
1393 LOG_ERROR(
"PIO and PIOMAP are not supported");
1400 if (num_of_argu < 3 || num_of_argu > 11) {
1401 LOG_ERROR(
"invalid parameter of %s", argus[0]);
1428 if (((i + 2) <= num_of_argu) && strcmp(argus[i + 1],
"SEC")) {
1429 if (!strcmp(argus[i + 1],
"TCK")) {
1431 run_count = atoi(argus[i]);
1432 LOG_DEBUG(
"\trun_count@TCK = %d", run_count);
1434 LOG_ERROR(
"%s not supported for clock", argus[i + 1]);
1440 if (((i + 2) <= num_of_argu) && !strcmp(argus[i + 1],
"SEC")) {
1441 min_time = atof(argus[i]);
1442 LOG_DEBUG(
"\tmin_time = %fs", min_time);
1446 if (((i + 3) <= num_of_argu) &&
1447 !strcmp(argus[i],
"MAXIMUM") && !strcmp(argus[i + 2],
"SEC")) {
1449 max_time = atof(argus[i + 1]);
1450 LOG_DEBUG(
"\tmax_time = %fs", max_time);
1454 if (((i + 2) <= num_of_argu) && !strcmp(argus[i],
"ENDSTATE")) {
1468 if (i == num_of_argu) {
1471 uint32_t min_usec = 1000000 * min_time;
1478 if (run_count > 0) {
1503 LOG_ERROR(
"fail to parse parameter of RUNTEST, %d out of %d is parsed",
1511 if (num_of_argu < 2) {
1512 LOG_ERROR(
"invalid parameter of %s", argus[0]);
1515 if (num_of_argu > 2) {
1517 path = malloc((num_of_argu - 1) *
sizeof(
enum tap_state));
1524 for (i = 0; i < num_of_argu; i++, i_tmp++) {
1527 LOG_ERROR(
"%s: %s is not a valid state", argus[0], argus[i_tmp]);
1540 num_of_argu -= i + 1;
1544 if (num_of_argu > 0) {
1553 LOG_ERROR(
"%s: %s is not a stable state",
1567 LOG_DEBUG(
"\tmove to %s by svf_add_statemove",
1572 LOG_ERROR(
"%s: %s is not a stable state",
1580 if (num_of_argu != 2) {
1581 LOG_ERROR(
"invalid parameter of %s", argus[0]);
1603 LOG_ERROR(
"unknown TRST mode: %s", argus[1]);
1609 LOG_ERROR(
"can not accept TRST command if trst_mode is ABSENT");
1614 LOG_ERROR(
"invalid svf command: %s", argus[0]);
1619 if (padding_command_skipped)
1620 LOG_USER(
"(Above Padding command skipped, as per -tap argument)");
1651 .handler = handle_svf_command,
1653 .help =
"Runs a SVF file.",
1654 .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(enum tap_state state)
Function tap_state_name Returns a string suitable for display representing the JTAG tap_state.
enum tap_state tap_state_by_name(const char *name)
Provides user-friendly name lookup of TAP states.
void jtag_add_plain_dr_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits, enum tap_state state)
Scan out the bits in ir scan mode.
struct jtag_tap * jtag_tap_by_string(const char *s)
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_runtest(unsigned int num_cycles, enum tap_state state)
Goes to TAP_IDLE (if we're not already there), cycle precisely num_cycles in the TAP_IDLE state,...
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
void jtag_add_pathmove(unsigned int num_states, const enum tap_state *path)
Application code must assume that interfaces will implement transitions between states with different...
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)
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)
enum tap_state cmd_queue_cur_state
The current TAP state of the pending JTAG command queue.
void jtag_add_plain_ir_scan(int num_bits, const uint8_t *out_bits, uint8_t *in_bits, enum tap_state state)
Scan out the bits in ir scan mode.
The JTAG interface can be implemented with a software or hardware fifo.
tap_state
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
enum tap_state runtest_run_state
enum tap_state ir_end_state
struct svf_xxr_para sdr_para
enum tap_state dr_end_state
struct svf_xxr_para hdr_para
enum tap_state runtest_end_state
struct svf_xxr_para hir_para
struct svf_xxr_para tdr_para
static size_t svf_read_line_size
static int svf_realloc_buffers(size_t len)
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
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
int svf_add_statemove(enum tap_state state_to)
svf_add_statemove() moves from the current state to goal_state.
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)
bool svf_tap_state_is_stable(enum tap_state state)
svf_tap_state_is_stable() returns true for stable non-SHIFT states
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_xxr_common(char **argus, int num_of_argu, char command, struct svf_xxr_para *xxr_para_tmp)
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.