36 #define XCOMPLETE 0x00
44 #define XSETSDRMASKS 0x0A
64 #define XWAITSTATE 0x18
87 #define XSV_RESET 0x00
89 #define XSV_DRSELECT 0x02
90 #define XSV_DRCAPTURE 0x03
91 #define XSV_DRSHIFT 0x04
92 #define XSV_DREXIT1 0x05
93 #define XSV_DRPAUSE 0x06
94 #define XSV_DREXIT2 0x07
95 #define XSV_DRUPDATE 0x08
96 #define XSV_IRSELECT 0x09
97 #define XSV_IRCAPTURE 0x0A
98 #define XSV_IRSHIFT 0x0B
99 #define XSV_IREXIT1 0x0C
100 #define XSV_IRPAUSE 0x0D
101 #define XSV_IREXIT2 0x0E
102 #define XSV_IRUPDATE 0x0F
108 #define XTRST_ABSENT 3
110 #define XSTATE_MAX_PATH 12
119 switch (xsvf_state) {
169 LOG_ERROR(
"UNKNOWN XSVF STATE 0x%02X", xsvf_state);
180 for (num_bytes = (num_bits + 7) / 8; num_bytes > 0; num_bytes--) {
182 if (read(fd, buf + num_bytes - 1, 1) < 0)
191 uint8_t *dr_out_buf =
NULL;
192 uint8_t *dr_in_buf =
NULL;
193 uint8_t *dr_in_mask =
NULL;
205 long file_offset = 0;
214 int tdo_mismatch = 0;
218 bool collecting_path =
false;
220 unsigned pathlen = 0;
225 int runtest_requires_tck = 0;
239 if (strcmp(
CMD_ARGV[0],
"plain") != 0) {
247 xsvf_fd = open(filename, O_RDONLY);
256 runtest_requires_tck = 1;
264 LOG_WARNING(
"XSVF support in OpenOCD is limited. Consider using SVF instead");
265 LOG_USER(
"xsvf processing file: \"%s\"", filename);
267 while (read(
xsvf_fd, &opcode, 1) > 0) {
269 file_offset = lseek(
xsvf_fd, 0, SEEK_CUR) - 1;
274 if (collecting_path) {
289 if (read(
xsvf_fd, &uc, 1) < 0) {
295 path[pathlen++] = mystate;
330 collecting_path =
false;
339 LOG_ERROR(
"XSVF: pathmove error %d", result);
367 uint8_t xruntest_buf[4];
369 if (read(
xsvf_fd, xruntest_buf, 4) < 0) {
375 LOG_DEBUG(
"XRUNTEST %d 0x%08X", xruntest, xruntest);
383 if (read(
xsvf_fd, &myrepeat, 1) < 0)
394 uint8_t xsdrsize_buf[4];
396 if (read(
xsvf_fd, xsdrsize_buf, 4) < 0) {
408 dr_out_buf = malloc((xsdrsize + 7) / 8);
409 dr_in_buf = malloc((xsdrsize + 7) / 8);
410 dr_in_mask = malloc((xsdrsize + 7) / 8);
421 const char *op_name = (opcode ==
XSDR ?
"XSDR" :
"XSDRTDO");
441 for (attempt = 0; attempt < limit; ++attempt) {
469 LOG_USER(
"%s mismatch, xsdrsize=%d retry=%d",
511 if (runtest_requires_tck)
568 if (read(
xsvf_fd, &uc, 1) < 0) {
603 collecting_path =
true;
611 if (read(
xsvf_fd, &uc, 1) < 0) {
622 LOG_ERROR(
"illegial XENDIR argument: 0x%02X", uc);
632 if (read(
xsvf_fd, &uc, 1) < 0) {
643 LOG_ERROR(
"illegial XENDDR argument: 0x%02X", uc);
654 uint8_t short_buf[2];
659 if (opcode ==
XSIR) {
661 if (read(
xsvf_fd, short_buf, 1) < 0) {
665 bitcount = short_buf[0];
668 if (read(
xsvf_fd, short_buf, 2) < 0) {
676 ir_buf = malloc((bitcount + 7) / 8);
695 if (runtest_requires_tck)
717 unsigned int ndx = 0;
721 if (read(
xsvf_fd, &uc, 1) < 0) {
726 if (ndx <
sizeof(comment)-1)
731 comment[
sizeof(comment)-1] = 0;
745 uint8_t delay_buf[4];
751 if (read(
xsvf_fd, &wait_local, 1) < 0
753 || read(
xsvf_fd, delay_buf, 4) < 0) {
765 if (runtest_requires_tck && wait_state ==
TAP_IDLE)
787 uint8_t clock_buf[4];
788 uint8_t usecs_buf[4];
796 if (read(
xsvf_fd, &wait_local, 1) < 0
798 || read(
xsvf_fd, clock_buf, 4) < 0
799 || read(
xsvf_fd, usecs_buf, 4) < 0) {
810 LOG_DEBUG(
"XWAITSTATE %s %s clocks:%i usecs:%i",
821 LOG_ERROR(
"illegal XWAITSTATE wait_state: \"%s\"",
846 uint8_t count_buf[4];
848 if (read(
xsvf_fd, count_buf, 4) < 0) {
864 uint8_t clock_buf[4];
865 uint8_t usecs_buf[4];
868 || read(
xsvf_fd, clock_buf, 4) < 0
869 || read(
xsvf_fd, usecs_buf, 4) < 0) {
880 loop_state), loop_clocks, loop_usecs);
889 int limit = loop_count;
904 for (attempt = 0; attempt < limit; ++attempt) {
919 if (attempt > 0 && verbose)
978 LOG_ERROR(
"unknown xsvf command (0x%02X)", uc);
982 if (do_abort || unsupported || tdo_mismatch) {
983 LOG_DEBUG(
"xsvf failed, setting taps to reasonable state");
998 "TDO mismatch, somewhere near offset %lu in xsvf file, aborting",
1007 "unsupported xsvf command (0x%02X) at offset %jd, aborting",
1031 .handler = handle_xsvf_command,
1033 .help =
"Runs a XSVF file. If 'virt2' is given, xruntest "
1034 "counts are interpreted as TCK cycles rather than "
1035 "as microseconds. Without the 'quiet' option, all "
1036 "comments, retries, and mismatches will be reported.",
1037 .usage =
"(tapname|'plain') filename ['virt2'] ['quiet']",
void command_print(struct command_invocation *cmd, 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 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.
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.
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_check_value_mask(struct scan_field *field, uint8_t *value, uint8_t *mask)
Execute jtag queue and check value with an optional mask.
void jtag_add_ir_scan(struct jtag_tap *active, struct scan_field *in_fields, tap_state_t state)
Generate an IR SCAN with a list of scan fields with one entry for each enabled TAP.
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,...
void jtag_add_dr_scan(struct jtag_tap *active, int in_num_fields, const struct scan_field *in_fields, tap_state_t state)
Generate a DR SCAN using the fields passed to the function.
The JTAG interface can be implemented with a software or hardware fifo.
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
#define LOG_USER(expr ...)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_DEBUG(expr ...)
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.
bool svf_tap_state_is_stable(tap_state_t state)
svf_tap_state_is_stable() returns true for stable non-SHIFT states
int svf_add_statemove(tap_state_t state_to)
svf_add_statemove() moves from the current state to goal_state.
#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.
static uint32_t be_to_h_u32(const uint8_t *buf)
static uint16_t be_to_h_u16(const uint8_t *buf)
static int xsvf_read_buffer(int num_bits, int fd, uint8_t *buf)
int xsvf_register_commands(struct command_context *cmd_ctx)
COMMAND_HANDLER(handle_xsvf_command)
static tap_state_t xsvf_to_tap(int xsvf_state)
static const struct command_registration xsvf_command_handlers[]