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_BUFFER_SIZE_TO_COMMIT   (1024 * 1024)
 
#define SVF_MAX_NUM_OF_OPTIONS   5
 
#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_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 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_buffer_index
 
static int svf_buffer_size
 
static struct svf_check_tdo_parasvf_check_tdo_para
 
static int svf_check_tdo_para_index
 
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 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 238 of file svf.c.

◆ SVF_CHECK_TDO_PARA_SIZE

#define SVF_CHECK_TDO_PARA_SIZE   1024

Definition at line 199 of file svf.c.

◆ SVF_MAX_BUFFER_SIZE_TO_COMMIT

#define SVF_MAX_BUFFER_SIZE_TO_COMMIT   (1024 * 1024)

Definition at line 217 of file svf.c.

◆ SVF_MAX_NUM_OF_OPTIONS

#define SVF_MAX_NUM_OF_OPTIONS   5

◆ 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 604 of file svf.c.

◆ XXR_MASK

#define XXR_MASK   (1 << 2)

Definition at line 140 of file svf.c.

◆ XXR_SMASK

#define XXR_SMASK   (1 << 3)

Definition at line 141 of file svf.c.

◆ XXR_TDI

#define XXR_TDI   (1 << 0)

Definition at line 138 of file svf.c.

◆ XXR_TDO

#define XXR_TDO   (1 << 1)

Definition at line 139 of file svf.c.

Enumeration Type Documentation

◆ svf_command

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

Definition at line 27 of file svf.c.

◆ trst_mode

enum trst_mode
Enumerator
TRST_ON 
TRST_OFF 
TRST_Z 
TRST_ABSENT 

Definition at line 61 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 309 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 749 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 777 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 883 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 738 of file svf.c.

◆ svf_free_xxd_para()

static void svf_free_xxd_para ( struct svf_xxr_para para)
static

Definition at line 292 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 574 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  line,
const char *  function,
const uint8_t *  buf,
int  bit_len,
const char *  desc 
)
static

Definition at line 241 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 694 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 1553 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 895 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 732 of file svf.c.

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

Referenced by COMMAND_HANDLER().

Variable Documentation

◆ svf_buffer_index

int svf_buffer_index
static

Definition at line 219 of file svf.c.

Referenced by COMMAND_HANDLER(), and svf_execute_tap().

◆ svf_buffer_size

int svf_buffer_size
static

Definition at line 219 of file svf.c.

Referenced by COMMAND_HANDLER(), and svf_realloc_buffers().

◆ svf_check_tdo_para

Definition at line 200 of file svf.c.

◆ svf_check_tdo_para_index

int svf_check_tdo_para_index
static

Definition at line 201 of file svf.c.

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

◆ svf_command_buffer

char* svf_command_buffer
static

Definition at line 212 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 213 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] <file> [quiet] [nil] [progress] [ignore_error]",
},
}
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:247
@ COMMAND_EXEC
Definition: command.h:40

Definition at line 895 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 44 of file svf.c.

◆ svf_fd

FILE* svf_fd
static

Definition at line 209 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 222 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 232 of file svf.c.

Referenced by COMMAND_HANDLER().

◆ svf_line_number

int svf_line_number
static

Definition at line 214 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 218 of file svf.c.

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

◆ svf_nil

int svf_nil
static

Definition at line 221 of file svf.c.

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

◆ svf_para

struct svf_para svf_para
static

Definition at line 68 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:52
@ TRST_Z
Definition: svf.c:64
#define NULL
Definition: usb.h:16

Definition at line 68 of file svf.c.

Referenced by COMMAND_HANDLER().

◆ svf_percentage

int svf_percentage
static

Definition at line 231 of file svf.c.

Referenced by COMMAND_HANDLER().

◆ svf_progress_enabled

int svf_progress_enabled
static

Definition at line 229 of file svf.c.

Referenced by COMMAND_HANDLER().

◆ svf_quiet

int svf_quiet
static

Definition at line 220 of file svf.c.

Referenced by COMMAND_HANDLER().

◆ svf_read_line

char* svf_read_line
static

Definition at line 210 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 211 of file svf.c.

Referenced by svf_read_command_from_file().

◆ svf_statemoves

const struct svf_statemove svf_statemoves[]
static

Definition at line 68 of file svf.c.

Referenced by svf_add_statemove().

◆ svf_tap_is_specified

int svf_tap_is_specified
static

Definition at line 225 of file svf.c.

Referenced by COMMAND_HANDLER().

◆ svf_tdi_buffer

uint8_t* svf_tdi_buffer
static

Definition at line 218 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 218 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 230 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 68 of file svf.c.