138 #define XXR_TDI             (1 << 0) 
  139 #define XXR_TDO             (1 << 1) 
  140 #define XXR_MASK            (1 << 2) 
  141 #define XXR_SMASK           (1 << 3) 
  199 #define SVF_CHECK_TDO_PARA_SIZE 1024 
  215 static int svf_getline(
char **lineptr, 
size_t *n, FILE *stream);
 
  217 #define SVF_MAX_BUFFER_SIZE_TO_COMMIT   (1024 * 1024) 
  238 #define SVF_BUF_LOG(_lvl, _buf, _nbits, _desc)                          \ 
  239     svf_hexbuf_print(LOG_LVL_##_lvl,  __FILE__, __LINE__, __func__, _buf, _nbits, _desc) 
  242                              const char *
function, 
const uint8_t *buf,
 
  250     char *prbuf = malloc((byte_len * 2) + 2 + 1);
 
  255     uint8_t msb = buf[byte_len - 1] & (msbits ? (1 << msbits) - 1 : 0xff);
 
  256     len = sprintf(prbuf, msbits <= 4 ? 
"0x%01"PRIx8 : 
"0x%02"PRIx8, msb);
 
  257     for (j = byte_len - 2; j >= 0; j--)
 
  258         len += sprintf(prbuf + len, 
"%02"PRIx8, buf[j]);
 
  260     log_printf_lf(dbg_lvl, file, line, 
function, 
"%8s = %s", desc ? desc : 
" ", prbuf);
 
  345 #define SVF_MIN_NUM_OF_OPTIONS 1 
  346 #define SVF_MAX_NUM_OF_OPTIONS 5 
  349     int64_t time_measure_ms;
 
  350     int time_measure_s, time_measure_m;
 
  366     for (
unsigned int i = 0; i < 
CMD_ARGC; i++) {
 
  367         if (strcmp(
CMD_ARGV[i], 
"-tap") == 0) {
 
  375                 "quiet") == 0) || (strcmp(
CMD_ARGV[i], 
"-quiet") == 0))
 
  377         else if ((strcmp(
CMD_ARGV[i], 
"nil") == 0) || (strcmp(
CMD_ARGV[i], 
"-nil") == 0))
 
  380                   "progress") == 0) || (strcmp(
CMD_ARGV[i], 
"-progress") == 0))
 
  383                   "ignore_error") == 0) || (strcmp(
CMD_ARGV[i], 
"-ignore_error") == 0))
 
  434         int header_ir_len = 0, header_dr_len = 0, trailer_ir_len = 0, trailer_dr_len = 0;
 
  459             LOG_ERROR(
"failed to set instruction header");
 
  471             LOG_ERROR(
"failed to set instruction trailer");
 
  516     time_measure_ms = 
timeval_ms() - time_measure_ms;
 
  517     time_measure_s = time_measure_ms / 1000;
 
  518     time_measure_ms %= 1000;
 
  519     time_measure_m = time_measure_s / 60;
 
  520     time_measure_s %= 60;
 
  521     if (time_measure_ms < 1000)
 
  523             "\r\nTime used: %dm%ds%" PRId64 
"ms ",
 
  563                   "svf file programmed %s for %d commands with %d errors",
 
  581         *lineptr = malloc(*n);
 
  586     (*lineptr)[0] = fgetc(stream);
 
  587     while ((*lineptr)[i] != 
'\n') {
 
  588         (*lineptr)[++i] = fgetc(stream);
 
  595             *lineptr = realloc(*lineptr, *n);
 
  601     return sizeof(*lineptr);
 
  604 #define SVFP_CMD_INC_CNT 1024 
  610     int cmd_ok = 0, slash = 0;
 
  616     while (!cmd_ok && (ch != 0)) {
 
  696     int pos = 0, num = 0, space_found = 1, in_bracket = 0;
 
  712                 if (!in_bracket && isspace((
int) str[pos])) {
 
  715                 } 
else if (space_found) {
 
  716                     argus[num++] = &str[pos];
 
  742     for (i = 0; i < num_of_element; i++) {
 
  743         if (!strcmp(str, strs[i]))
 
  751     int new_byte_len = (new_bit_len + 7) >> 3;
 
  753     if ((!*arr) || (((orig_bit_len + 7) >> 3) < ((new_bit_len + 7) >> 3))) {
 
  755         *arr = calloc(1, new_byte_len);
 
  768     memset(para->
tdi, tdi, (len + 7) >> 3);
 
  779     int i, str_len = strlen(str), str_hbyte_len = (bit_len + 3) >> 2;
 
  783         LOG_ERROR(
"fail to adjust length of array");
 
  788     for (i = 0; i < str_hbyte_len; i++) {
 
  790         while (str_len > 0) {
 
  800                 if ((ch >= 
'0') && (ch <= 
'9')) {
 
  803                 } 
else if ((ch >= 
'A') && (ch <= 
'F')) {
 
  818             (*bin)[i / 2] |= ch << 4;
 
  827     while (str_len > 0 && ((str[str_len - 1] == 
'0')
 
  828             || isspace((
int) str[str_len - 1])))
 
  832     if (str_len > 0 || (ch & ~((2 << ((bit_len - 1) % 4)) - 1)) != 0) {
 
  842     int i, len, index_var;
 
  870         LOG_ERROR(
"toooooo many operation undone");
 
  898     int num_of_argu = 0, i;
 
  908     uint8_t **pbuffer_tmp;
 
  913     int padding_command_skipped = 0;
 
  927             if (num_of_argu != 2) {
 
  928                 LOG_ERROR(
"invalid parameter of %s", argus[0]);
 
  945                 LOG_ERROR(
"%s: %s is not a stable state",
 
  951             if ((num_of_argu != 1) && (num_of_argu != 3)) {
 
  952                 LOG_ERROR(
"invalid parameter of %s", argus[0]);
 
  955             if (num_of_argu == 1) {
 
  959                 if (strcmp(argus[2], 
"HZ")) {
 
  960                     LOG_ERROR(
"HZ not found in FREQUENCY command");
 
  977                 padding_command_skipped = 1;
 
  984                 padding_command_skipped = 1;
 
  991                 padding_command_skipped = 1;
 
  998                 padding_command_skipped = 1;
 
 1011             if ((num_of_argu > 10) || (num_of_argu % 2)) {
 
 1012                 LOG_ERROR(
"invalid parameter of %s", argus[0]);
 
 1015             i_tmp = xxr_para_tmp->
len;
 
 1016             xxr_para_tmp->
len = atoi(argus[1]);
 
 1019             if (i_tmp < xxr_para_tmp->len) {
 
 1020                 free(xxr_para_tmp->
tdi);
 
 1022                 free(xxr_para_tmp->
tdo);
 
 1024                 free(xxr_para_tmp->
mask);
 
 1026                 free(xxr_para_tmp->
smask);
 
 1032             for (i = 2; i < num_of_argu; i += 2) {
 
 1033                 if ((strlen(argus[i + 1]) < 3) || (argus[i + 1][0] != 
'(') ||
 
 1034                 (argus[i + 1][strlen(argus[i + 1]) - 1] != 
')')) {
 
 1038                 argus[i + 1][strlen(argus[i + 1]) - 1] = 
'\0';
 
 1040                 if (!strcmp(argus[i], 
"TDI")) {
 
 1042                     pbuffer_tmp = &xxr_para_tmp->
tdi;
 
 1044                 } 
else if (!strcmp(argus[i], 
"TDO")) {
 
 1046                     pbuffer_tmp = &xxr_para_tmp->
tdo;
 
 1048                 } 
else if (!strcmp(argus[i], 
"MASK")) {
 
 1050                     pbuffer_tmp = &xxr_para_tmp->
mask;
 
 1052                 } 
else if (!strcmp(argus[i], 
"SMASK")) {
 
 1054                     pbuffer_tmp = &xxr_para_tmp->
smask;
 
 1057                     LOG_ERROR(
"unknown parameter: %s", argus[i]);
 
 1062                     xxr_para_tmp->
len)) {
 
 1075                     xxr_para_tmp->
len)) {
 
 1076                     LOG_ERROR(
"fail to adjust length of array");
 
 1083                 if (!xxr_para_tmp->
tdo) {
 
 1086                         xxr_para_tmp->
len)) {
 
 1087                         LOG_ERROR(
"fail to adjust length of array");
 
 1091                 if (!xxr_para_tmp->
mask) {
 
 1094                         xxr_para_tmp->
len)) {
 
 1095                         LOG_ERROR(
"fail to adjust length of array");
 
 1099                 memset(xxr_para_tmp->
mask, 0, (xxr_para_tmp->
len + 7) >> 3);
 
 1287             LOG_ERROR(
"PIO and PIOMAP are not supported");
 
 1294             if ((num_of_argu < 3) || (num_of_argu > 11)) {
 
 1295                 LOG_ERROR(
"invalid parameter of %s", argus[0]);
 
 1322             if (((i + 2) <= num_of_argu) && strcmp(argus[i + 1], 
"SEC")) {
 
 1323                 if (!strcmp(argus[i + 1], 
"TCK")) {
 
 1325                     run_count = atoi(argus[i]);
 
 1326                     LOG_DEBUG(
"\trun_count@TCK = %d", run_count);
 
 1328                     LOG_ERROR(
"%s not supported for clock", argus[i + 1]);
 
 1334             if (((i + 2) <= num_of_argu) && !strcmp(argus[i + 1], 
"SEC")) {
 
 1335                 min_time = atof(argus[i]);
 
 1336                 LOG_DEBUG(
"\tmin_time = %fs", min_time);
 
 1340             if (((i + 3) <= num_of_argu) &&
 
 1341             !strcmp(argus[i], 
"MAXIMUM") && !strcmp(argus[i + 2], 
"SEC")) {
 
 1343                 max_time = atof(argus[i + 1]);
 
 1344                 LOG_DEBUG(
"\tmax_time = %fs", max_time);
 
 1348             if (((i + 2) <= num_of_argu) && !strcmp(argus[i], 
"ENDSTATE")) {
 
 1362             if (i == num_of_argu) {
 
 1365                 uint32_t min_usec = 1000000 * min_time;
 
 1372                 if (run_count > 0) {
 
 1397                 LOG_ERROR(
"fail to parse parameter of RUNTEST, %d out of %d is parsed",
 
 1405             if (num_of_argu < 2) {
 
 1406                 LOG_ERROR(
"invalid parameter of %s", argus[0]);
 
 1409             if (num_of_argu > 2) {
 
 1411                 path = malloc((num_of_argu - 1) * 
sizeof(
tap_state_t));
 
 1418                 for (i = 0; i < num_of_argu; i++, i_tmp++) {
 
 1421                         LOG_ERROR(
"%s: %s is not a valid state", argus[0], argus[i_tmp]);
 
 1434                         num_of_argu -= i + 1;
 
 1438                 if (num_of_argu > 0) {
 
 1447                         LOG_ERROR(
"%s: %s is not a stable state",
 
 1461                     LOG_DEBUG(
"\tmove to %s by svf_add_statemove",
 
 1466                     LOG_ERROR(
"%s: %s is not a stable state",
 
 1474             if (num_of_argu != 2) {
 
 1475                 LOG_ERROR(
"invalid parameter of %s", argus[0]);
 
 1497                     LOG_ERROR(
"unknown TRST mode: %s", argus[1]);
 
 1503                 LOG_ERROR(
"can not accept TRST command if trst_mode is ABSENT");
 
 1508             LOG_ERROR(
"invalid svf command: %s", argus[0]);
 
 1513         if (padding_command_skipped)
 
 1514             LOG_USER(
"(Above Padding command skipped, as per -tap argument)");
 
 1545         .handler = handle_svf_command,
 
 1547         .help = 
"Runs a SVF file.",
 
 1548         .usage = 
"[-tap device.tap] <file> [quiet] [nil] [progress] [ignore_error]",
 
bool buf_cmp_mask(const void *_buf1, const void *_buf2, const void *_mask, unsigned size)
 
void * buf_set_ones(void *_buf, unsigned size)
Set the contents of buf with count bits, all set to 1.
 
void * buf_set_buf(const void *_src, unsigned src_start, void *_dst, unsigned dst_start, unsigned len)
 
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.
 
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_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_pathmove(int num_states, const tap_state_t *path)
Application code must assume that interfaces will implement transitions between states with different...
 
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.
 
void jtag_add_clocks(int num_cycles)
Function jtag_add_clocks first checks that the state in which the clocks are to be issued is stable,...
 
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
 
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)
 
void jtag_add_runtest(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,...
 
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 line, const char *function, const char *format,...)
 
#define LOG_USER(expr ...)
 
#define LOG_USER_N(expr ...)
 
#define LOG_ERROR(expr ...)
 
#define LOG_DEBUG(expr ...)
 
int ir_length
size of instruction register
 
bool enabled
Is this TAP currently enabled?
 
struct jtag_tap * next_tap
 
This structure defines a single scan field in the scan.
 
int num_bits
The number of bits this field specifies.
 
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.
 
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]
 
static const struct command_registration svf_command_handlers[]
 
static int svf_line_number
 
static void svf_hexbuf_print(int dbg_lvl, const char *file, unsigned line, const char *function, const uint8_t *buf, int bit_len, const char *desc)
 
static void svf_free_xxd_para(struct svf_xxr_para *para)
 
static int svf_read_command_from_file(FILE *fd)
 
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.