OpenOCD
svf.c File Reference
Include dependency graph for svf.c:

Go to the source code of this file.

Data Structures

struct  svf_check_tdo_para
 
struct  svf_para
 
struct  svf_statemove
 
struct  svf_xxr_para
 

Macros

#define MIN_CHUNK   16 /* Buffer is increased by this size each time as required */
 
#define SVF_BUF_LOG(_lvl, _buf, _nbits, _desc)    svf_hexbuf_print(LOG_LVL_##_lvl, __FILE__, __LINE__, __func__, _buf, _nbits, _desc)
 
#define SVF_CHECK_TDO_PARA_SIZE   1024
 
#define SVF_MAX_ADDCYCLES   255
 
#define SVF_MAX_BUFFER_SIZE_TO_COMMIT   (1024 * 1024)
 
#define SVF_MAX_NUM_OF_OPTIONS   8
 
#define SVF_MIN_NUM_OF_OPTIONS   1
 
#define SVFP_CMD_INC_CNT   1024
 
#define XXR_MASK   (1 << 2)
 
#define XXR_SMASK   (1 << 3)
 
#define XXR_TDI   (1 << 0)
 
#define XXR_TDO   (1 << 1)
 

Enumerations

enum  svf_cmd_param {
  OPT_ADDCYCLES , OPT_IGNORE_ERROR , OPT_NIL , OPT_NORESET ,
  OPT_PROGRESS , OPT_QUIET , OPT_TAP , DEPRECATED_OPT_IGNORE_ERROR ,
  DEPRECATED_OPT_NIL , DEPRECATED_OPT_PROGRESS , DEPRECATED_OPT_QUIET
}
 
enum  svf_command {
  ENDDR , ENDIR , FREQUENCY , HDR ,
  HIR , PIO , PIOMAP , RUNTEST ,
  SDR , SIR , STATE , TDR ,
  TIR , TRST
}
 
enum  trst_mode { TRST_ON , TRST_OFF , TRST_Z , TRST_ABSENT }
 

Functions

 COMMAND_HANDLER (handle_svf_command)
 
static int svf_add_check_para (uint8_t enabled, int buffer_offset, int bit_len)
 
int svf_add_statemove (tap_state_t state_to)
 svf_add_statemove() moves from the current state to goal_state. More...
 
static int svf_adjust_array_length (uint8_t **arr, int orig_bit_len, int new_bit_len)
 
static int svf_check_tdo (void)
 
static int svf_copy_hexstring_to_binary (char *str, uint8_t **bin, int orig_bit_len, int bit_len)
 
static int svf_execute_tap (void)
 
static int svf_find_string_in_array (char *str, char **strs, int num_of_element)
 
static void svf_free_xxd_para (struct svf_xxr_para *para)
 
static int svf_getline (char **lineptr, size_t *n, FILE *stream)
 
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_parse_cmd_string (char *str, int len, char **argus, int *num_of_argu)
 
static int svf_read_command_from_file (FILE *fd)
 
static int svf_realloc_buffers (size_t len)
 
int svf_register_commands (struct command_context *cmd_ctx)
 
static int svf_run_command (struct command_context *cmd_ctx, char *cmd_str)
 
static int svf_set_padding (struct svf_xxr_para *para, int len, unsigned char tdi)
 
bool svf_tap_state_is_stable (tap_state_t state)
 svf_tap_state_is_stable() returns true for stable non-SHIFT states More...
 

Variables

static int svf_addcycles
 
static int svf_buffer_index
 
static int svf_buffer_size
 
static struct svf_check_tdo_parasvf_check_tdo_para
 
static int svf_check_tdo_para_index
 
static const struct nvp svf_cmd_opts []
 
static char * svf_command_buffer
 
static size_t svf_command_buffer_size
 
static const struct command_registration svf_command_handlers []
 
static const char * svf_command_name [14]
 
static FILE * svf_fd
 
static int svf_ignore_error
 
static int svf_last_printed_percentage = -1
 
static int svf_line_number
 
static uint8_t * svf_mask_buffer
 
static int svf_nil
 
static bool svf_noreset
 
static struct svf_para svf_para
 
static const struct svf_para svf_para_init
 
static int svf_percentage
 
static int svf_progress_enabled
 
static int svf_quiet
 
static char * svf_read_line
 
static size_t svf_read_line_size
 
static const struct svf_statemove svf_statemoves []
 
static int svf_tap_is_specified
 
static uint8_t * svf_tdi_buffer
 
static uint8_t * svf_tdo_buffer
 
static long svf_total_lines
 
static const char * svf_trst_mode_name [4]
 

Macro Definition Documentation

◆ MIN_CHUNK

#define MIN_CHUNK   16 /* Buffer is increased by this size each time as required */

◆ SVF_BUF_LOG

#define SVF_BUF_LOG (   _lvl,
  _buf,
  _nbits,
  _desc 
)     svf_hexbuf_print(LOG_LVL_##_lvl, __FILE__, __LINE__, __func__, _buf, _nbits, _desc)

Definition at line 245 of file svf.c.

◆ SVF_CHECK_TDO_PARA_SIZE

#define SVF_CHECK_TDO_PARA_SIZE   1024

Definition at line 204 of file svf.c.

◆ SVF_MAX_ADDCYCLES

#define SVF_MAX_ADDCYCLES   255

Definition at line 145 of file svf.c.

◆ SVF_MAX_BUFFER_SIZE_TO_COMMIT

#define SVF_MAX_BUFFER_SIZE_TO_COMMIT   (1024 * 1024)

Definition at line 222 of file svf.c.

◆ SVF_MAX_NUM_OF_OPTIONS

#define SVF_MAX_NUM_OF_OPTIONS   8

◆ SVF_MIN_NUM_OF_OPTIONS

#define SVF_MIN_NUM_OF_OPTIONS   1

◆ SVFP_CMD_INC_CNT

#define SVFP_CMD_INC_CNT   1024

Definition at line 691 of file svf.c.

◆ XXR_MASK

#define XXR_MASK   (1 << 2)

Definition at line 142 of file svf.c.

◆ XXR_SMASK

#define XXR_SMASK   (1 << 3)

Definition at line 143 of file svf.c.

◆ XXR_TDI

#define XXR_TDI   (1 << 0)

Definition at line 140 of file svf.c.

◆ XXR_TDO

#define XXR_TDO   (1 << 1)

Definition at line 141 of file svf.c.

Enumeration Type Documentation

◆ svf_cmd_param

Enumerator
OPT_ADDCYCLES 
OPT_IGNORE_ERROR 
OPT_NIL 
OPT_NORESET 
OPT_PROGRESS 
OPT_QUIET 
OPT_TAP 
DEPRECATED_OPT_IGNORE_ERROR 
DEPRECATED_OPT_NIL 
DEPRECATED_OPT_PROGRESS 
DEPRECATED_OPT_QUIET 

Definition at line 350 of file svf.c.

◆ svf_command

Enumerator
ENDDR 
ENDIR 
FREQUENCY 
HDR 
HIR 
PIO 
PIOMAP 
RUNTEST 
SDR 
SIR 
STATE 
TDR 
TIR 
TRST 

Definition at line 29 of file svf.c.

◆ trst_mode

enum trst_mode
Enumerator
TRST_ON 
TRST_OFF 
TRST_Z 
TRST_ABSENT 

Definition at line 63 of file svf.c.

Function Documentation

◆ COMMAND_HANDLER()

◆ svf_add_check_para()

static int svf_add_check_para ( uint8_t  enabled,
int  buffer_offset,
int  bit_len 
)
static

◆ svf_add_statemove()

int svf_add_statemove ( tap_state_t  goal_state)

svf_add_statemove() moves from the current state to goal_state.

Parameters
goal_stateThe final TAP state.
Returns
ERROR_OK on success, or an error code on failure.

The current and goal states must satisfy svf_tap_state_is_stable(). State transition paths used by this routine are those given in the SVF specification for single-argument STATE commands (and also used for various other state transitions).

Definition at line 316 of file svf.c.

References ARRAY_SIZE, cmd_queue_cur_state, ERROR_FAIL, ERROR_OK, jtag_add_pathmove(), jtag_add_tlr(), LOG_ERROR, svf_nil, svf_statemoves, TAP_RESET, tap_state_name(), and svf_statemove::to.

Referenced by COMMAND_HANDLER().

◆ svf_adjust_array_length()

static int svf_adjust_array_length ( uint8_t **  arr,
int  orig_bit_len,
int  new_bit_len 
)
static

Definition at line 836 of file svf.c.

References ERROR_FAIL, ERROR_OK, and LOG_ERROR.

Referenced by svf_copy_hexstring_to_binary(), and svf_set_padding().

◆ svf_check_tdo()

◆ svf_copy_hexstring_to_binary()

static int svf_copy_hexstring_to_binary ( char *  str,
uint8_t **  bin,
int  orig_bit_len,
int  bit_len 
)
static

Definition at line 864 of file svf.c.

References ERROR_FAIL, ERROR_OK, LOG_ERROR, and svf_adjust_array_length().

◆ svf_execute_tap()

static int svf_execute_tap ( void  )
static

Definition at line 970 of file svf.c.

References ERROR_FAIL, ERROR_OK, jtag_execute_queue(), svf_buffer_index, svf_check_tdo(), and svf_nil.

Referenced by svf_realloc_buffers().

◆ svf_find_string_in_array()

static int svf_find_string_in_array ( char *  str,
char **  strs,
int  num_of_element 
)
static

Definition at line 825 of file svf.c.

◆ svf_free_xxd_para()

static void svf_free_xxd_para ( struct svf_xxr_para para)
static

Definition at line 299 of file svf.c.

References svf_xxr_para::mask, NULL, svf_xxr_para::smask, svf_xxr_para::tdi, and svf_xxr_para::tdo.

Referenced by COMMAND_HANDLER().

◆ svf_getline()

static int svf_getline ( char **  lineptr,
size_t *  n,
FILE *  stream 
)
static

Definition at line 661 of file svf.c.

References MIN_CHUNK.

Referenced by COMMAND_HANDLER(), and svf_read_command_from_file().

◆ svf_hexbuf_print()

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

Definition at line 248 of file svf.c.

References svf_check_tdo_para::bit_len, DIV_ROUND_UP, and log_printf_lf().

◆ svf_parse_cmd_string()

static int svf_parse_cmd_string ( char *  str,
int  len,
char **  argus,
int *  num_of_argu 
)
static

Definition at line 781 of file svf.c.

References ERROR_FAIL, ERROR_OK, and LOG_ERROR.

◆ svf_read_command_from_file()

static int svf_read_command_from_file ( FILE *  fd)
static

◆ svf_realloc_buffers()

static int svf_realloc_buffers ( size_t  len)
static

◆ svf_register_commands()

int svf_register_commands ( struct command_context cmd_ctx)

Definition at line 1643 of file svf.c.

References NULL, register_commands(), and svf_command_handlers.

Referenced by jtag_select().

◆ svf_run_command()

static int svf_run_command ( struct command_context cmd_ctx,
char *  cmd_str 
)
static

Definition at line 982 of file svf.c.

Referenced by COMMAND_HANDLER().

◆ svf_set_padding()

static int svf_set_padding ( struct svf_xxr_para para,
int  len,
unsigned char  tdi 
)
static

◆ svf_tap_state_is_stable()

bool svf_tap_state_is_stable ( tap_state_t  state)

svf_tap_state_is_stable() returns true for stable non-SHIFT states

Parameters
stateThe TAP state in question
Returns
true iff the state is stable and not a SHIFT state.

Definition at line 819 of file svf.c.

References state, TAP_DRPAUSE, TAP_IDLE, TAP_IRPAUSE, and TAP_RESET.

Referenced by COMMAND_HANDLER().

Variable Documentation

◆ svf_addcycles

int svf_addcycles
static

Definition at line 229 of file svf.c.

Referenced by COMMAND_HANDLER().

◆ svf_buffer_index

int svf_buffer_index
static

Definition at line 224 of file svf.c.

Referenced by COMMAND_HANDLER(), and svf_execute_tap().

◆ svf_buffer_size

int svf_buffer_size
static

Definition at line 224 of file svf.c.

Referenced by COMMAND_HANDLER(), and svf_realloc_buffers().

◆ svf_check_tdo_para

Definition at line 205 of file svf.c.

◆ svf_check_tdo_para_index

int svf_check_tdo_para_index
static

Definition at line 206 of file svf.c.

Referenced by COMMAND_HANDLER(), svf_add_check_para(), and svf_check_tdo().

◆ svf_cmd_opts

const struct nvp svf_cmd_opts[]
static
Initial value:
= {
{ .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 },
{ .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 }
}
@ DEPRECATED_OPT_IGNORE_ERROR
Definition: svf.c:359
@ OPT_TAP
Definition: svf.c:357
@ DEPRECATED_OPT_QUIET
Definition: svf.c:362
@ OPT_QUIET
Definition: svf.c:356
@ OPT_IGNORE_ERROR
Definition: svf.c:352
@ OPT_NIL
Definition: svf.c:353
@ OPT_PROGRESS
Definition: svf.c:355
@ OPT_ADDCYCLES
Definition: svf.c:351
@ DEPRECATED_OPT_PROGRESS
Definition: svf.c:361
@ OPT_NORESET
Definition: svf.c:354
@ DEPRECATED_OPT_NIL
Definition: svf.c:360
#define NULL
Definition: usb.h:16

Definition at line 316 of file svf.c.

Referenced by COMMAND_HANDLER().

◆ svf_command_buffer

char* svf_command_buffer
static

Definition at line 217 of file svf.c.

Referenced by COMMAND_HANDLER(), and svf_read_command_from_file().

◆ svf_command_buffer_size

size_t svf_command_buffer_size
static

Definition at line 218 of file svf.c.

Referenced by COMMAND_HANDLER(), and svf_read_command_from_file().

◆ svf_command_handlers

const struct command_registration svf_command_handlers[]
static
Initial value:
= {
{
.name = "svf",
.handler = handle_svf_command,
.mode = COMMAND_EXEC,
.help = "Runs a SVF file.",
.usage = "[-tap device.tap] [-quiet] [-nil] [-progress] [-ignore_error] [-noreset] [-addcycles numcycles] file",
},
}
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:253
@ COMMAND_EXEC
Definition: command.h:40

Definition at line 982 of file svf.c.

Referenced by svf_register_commands().

◆ svf_command_name

const char* svf_command_name[14]
static
Initial value:
= {
"ENDDR",
"ENDIR",
"FREQUENCY",
"HDR",
"HIR",
"PIO",
"PIOMAP",
"RUNTEST",
"SDR",
"SIR",
"STATE",
"TDR",
"TIR",
"TRST"
}

Definition at line 46 of file svf.c.

◆ svf_fd

FILE* svf_fd
static

Definition at line 214 of file svf.c.

Referenced by COMMAND_HANDLER(), and svf_read_command_from_file().

◆ svf_ignore_error

int svf_ignore_error
static

Definition at line 227 of file svf.c.

Referenced by COMMAND_HANDLER(), and svf_check_tdo().

◆ svf_last_printed_percentage

int svf_last_printed_percentage = -1
static

Definition at line 239 of file svf.c.

Referenced by COMMAND_HANDLER().

◆ svf_line_number

int svf_line_number
static

Definition at line 219 of file svf.c.

Referenced by COMMAND_HANDLER(), svf_add_check_para(), and svf_read_command_from_file().

◆ svf_mask_buffer

uint8_t * svf_mask_buffer
static

Definition at line 223 of file svf.c.

Referenced by COMMAND_HANDLER(), svf_check_tdo(), and svf_realloc_buffers().

◆ svf_nil

int svf_nil
static

Definition at line 226 of file svf.c.

Referenced by COMMAND_HANDLER(), svf_add_statemove(), and svf_execute_tap().

◆ svf_noreset

bool svf_noreset
static

Definition at line 228 of file svf.c.

Referenced by COMMAND_HANDLER().

◆ svf_para

struct svf_para svf_para
static

Definition at line 70 of file svf.c.

◆ svf_para_init

const struct svf_para svf_para_init
static
Initial value:
= {
{0, 0, NULL, NULL, NULL, NULL},
{0, 0, NULL, NULL, NULL, NULL},
{0, 0, NULL, NULL, NULL, NULL},
{0, 0, NULL, NULL, NULL, NULL},
{0, 0, NULL, NULL, NULL, NULL},
{0, 0, NULL, NULL, NULL, NULL},
}
@ TAP_IDLE
Definition: jtag.h:53
@ TRST_Z
Definition: svf.c:66

Definition at line 70 of file svf.c.

Referenced by COMMAND_HANDLER().

◆ svf_percentage

int svf_percentage
static

Definition at line 238 of file svf.c.

Referenced by COMMAND_HANDLER().

◆ svf_progress_enabled

int svf_progress_enabled
static

Definition at line 236 of file svf.c.

Referenced by COMMAND_HANDLER().

◆ svf_quiet

int svf_quiet
static

Definition at line 225 of file svf.c.

Referenced by COMMAND_HANDLER().

◆ svf_read_line

char* svf_read_line
static

Definition at line 215 of file svf.c.

Referenced by COMMAND_HANDLER(), and svf_read_command_from_file().

◆ svf_read_line_size

size_t svf_read_line_size
static

Definition at line 216 of file svf.c.

Referenced by svf_read_command_from_file().

◆ svf_statemoves

const struct svf_statemove svf_statemoves[]
static

Definition at line 70 of file svf.c.

Referenced by svf_add_statemove().

◆ svf_tap_is_specified

int svf_tap_is_specified
static

Definition at line 232 of file svf.c.

Referenced by COMMAND_HANDLER().

◆ svf_tdi_buffer

uint8_t* svf_tdi_buffer
static

Definition at line 223 of file svf.c.

Referenced by COMMAND_HANDLER(), svf_check_tdo(), and svf_realloc_buffers().

◆ svf_tdo_buffer

uint8_t * svf_tdo_buffer
static

Definition at line 223 of file svf.c.

Referenced by COMMAND_HANDLER(), svf_check_tdo(), and svf_realloc_buffers().

◆ svf_total_lines

long svf_total_lines
static

Definition at line 237 of file svf.c.

Referenced by COMMAND_HANDLER().

◆ svf_trst_mode_name

const char* svf_trst_mode_name[4]
static
Initial value:
= {
"ON",
"OFF",
"Z",
"ABSENT"
}

Definition at line 70 of file svf.c.