50 { .name =
NULL, .value = -1 }
55 const char *cp = Jim_GetString(o,
NULL);
60 Jim_SetResultFormatted(interp,
"Tap '%s' could not be found", cp);
79 unsigned int field_count = 0;
80 for (
unsigned int i = 1; i <
CMD_ARGC; i += 2) {
139 LOG_WARNING(
"drscan with unsafe endstate \"%s\"", state_name);
144 unsigned int num_fields = (
CMD_ARGC - 1) / 2;
163 for (
unsigned int i = 0; i < num_fields; i++) {
170 for (
unsigned int i = 0; i < num_fields; i++)
181 if (CMD_ARGC < 1 || CMD_ARGC >
ARRAY_SIZE(states))
184 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
235 .handler = handle_jtag_command_drscan,
236 .help =
"Execute Data Register (DR) scan for one TAP. "
237 "Other TAPs must be in BYPASS mode.",
238 .usage =
"tap_name (num_bits value)+ ['-endstate' state_name]",
241 .name =
"flush_count",
243 .handler = handle_jtag_flush_count,
244 .help =
"Returns the number of times the JTAG queue "
251 .handler = handle_jtag_command_pathmove,
252 .usage =
"start_state state1 [state2 [state3 ...]]",
253 .help =
"Move JTAG state machine from current state "
254 "(start_state) to state1, then state2, state3, etc.",
269 { .name =
NULL, .value = -1 }
273 const struct nvp *event, Jim_Obj *body)
284 jteap = calloc(1,
sizeof(*jteap));
294 Jim_DecrRefCount(cmd_ctx->
interp, jteap->
body);
300 Jim_IncrRefCount(jteap->
body);
307 bool is_configure = !strcmp(
CMD_NAME,
"configure");
309 if (
CMD_ARGC < (is_configure ? 3 : 2))
317 for (
unsigned int i = 1; i <
CMD_ARGC; i++) {
321 if (i + (is_configure ? 2 : 1) >=
CMD_ARGC) {
323 is_configure ?
" <event-body>" :
"");
348 i += is_configure ? 2 : 1;
365 #define NTAP_OPT_IRLEN 0
366 #define NTAP_OPT_IRMASK 1
367 #define NTAP_OPT_IRCAPTURE 2
368 #define NTAP_OPT_ENABLED 3
369 #define NTAP_OPT_DISABLED 4
370 #define NTAP_OPT_EXPECTED_ID 5
371 #define NTAP_OPT_VERSION 6
372 #define NTAP_OPT_BYPASS 7
373 #define NTAP_OPT_IRBYPASS 8
385 { .name =
NULL, .value = -1 },
404 LOG_DEBUG(
"Creating New Tap, Chip: %s, Tap: %s, Dotted: %s, %d params",
542 if (jteap->
event != e)
546 LOG_DEBUG(
"JTAG tap: %s event: %d (%s)\n\taction: %s",
550 retval = Jim_EvalObj(jteap->
interp, jteap->
body);
551 if (retval == JIM_RETURN)
552 retval = jteap->
interp->returnCode;
554 if (retval != JIM_OK) {
555 Jim_MakeErrorMessage(jteap->
interp);
569 tap->
enabled ?
"enabled" :
"disabled");
641 if (strcmp(
CMD_NAME,
"tapisenabled") == 0) {
643 }
else if (strcmp(
CMD_NAME,
"tapenable") == 0) {
648 }
else if (strcmp(
CMD_NAME,
"tapdisable") == 0) {
678 static bool jtag_initialized;
679 if (jtag_initialized) {
680 LOG_INFO(
"'jtag init' has already been called");
683 jtag_initialized =
true;
685 LOG_DEBUG(
"Initializing jtag devices...");
693 .handler = handle_jtag_init_command,
694 .help =
"initialize jtag scan chain",
700 .handler = handle_jtag_arp_init,
701 .help =
"Validates JTAG scan chain against the list of "
702 "declared TAPs using just the four standard JTAG "
707 .name =
"arp_init-reset",
709 .handler = handle_jtag_arp_init_reset,
710 .help =
"Uses TRST and SRST to try resetting everything on "
711 "the JTAG scan chain, then performs 'jtag arp_init'.",
717 .handler = handle_jtag_newtap,
718 .help =
"Create a new TAP instance named basename.tap_type, "
719 "and appends it to the scan chain.",
720 .usage =
"basename tap_type '-irlen' count "
721 "['-enable'|'-disable'] "
722 "['-expected_id' number] "
723 "['-ignore-version'] "
724 "['-ignore-bypass'] "
725 "['-ircapture' number] "
726 "['-ir-bypass' number] "
730 .name =
"tapisenabled",
732 .handler = handle_jtag_tap_enabler,
733 .help =
"Returns a Tcl boolean (0/1) indicating whether "
734 "the TAP is enabled (1) or not (0).",
740 .handler = handle_jtag_tap_enabler,
741 .help =
"Try to enable the specified TAP using the "
742 "'tap-enable' TAP event.",
746 .name =
"tapdisable",
748 .handler = handle_jtag_tap_enabler,
749 .help =
"Try to disable the specified TAP using the "
750 "'tap-disable' TAP event.",
756 .handler = handle_jtag_configure,
757 .help =
"Provide a Tcl handler for the specified "
759 .usage =
"tap_name '-event' event_name handler",
764 .handler = handle_jtag_configure,
765 .help =
"Return any Tcl handler for the specified "
766 "TAP event or the value of the IDCODE found in hardware.",
767 .usage =
"tap_name '-event' event_name | "
768 "tap_name '-idcode'",
773 .handler = handle_jtag_names,
774 .help =
"Returns list of all JTAG tap names.",
795 char expected_id[12];
799 " TapName Enabled IdCode Expected IrLen IrCap IrMask");
801 "-- ------------------- -------- ---------- ---------- ----- ----- ------");
806 snprintf(expected_id,
sizeof(expected_id),
"0x%08" PRIx32,
809 expected_id[2] =
'*';
815 "%2u %-18s %c 0x%08x %s %5u 0x%02x 0x%02x",
819 (
unsigned int)(tap->
idcode),
826 snprintf(expected_id,
sizeof(expected_id),
"0x%08" PRIx32, tap->
expected_ids[ii]);
828 expected_id[2] =
'*';
876 unsigned int khz = 0;
902 unsigned int num_clocks;
948 if (num_fields > 1) {
952 LOG_ERROR(
"Specify a single value for tap");
956 fields = calloc(num_fields,
sizeof(*fields));
959 for (i = 0; i < num_fields; i++) {
968 retval = parse_u64(
CMD_ARGV[i * 2 + 1], &value);
972 unsigned int field_size = tap->
ir_length;
991 for (i = 0; i < num_fields; i++)
992 free((
void *)fields[i].out_value);
1040 if (strcmp(
CMD_ARGV[0],
"short") == 0)
1041 use_new_table =
true;
1042 else if (strcmp(
CMD_ARGV[0],
"long") == 0)
1043 use_new_table =
false;
1076 if ((timeout_ms <= 0) || (timeout_ms > 100000)) {
1077 LOG_ERROR(
"Timeout must be an integer between 0 and 100000");
1081 LOG_USER(
"Waiting for srst assert + deassert for at most %dms", timeout_ms);
1107 .
name =
"jtag_flush_queue_sleep",
1108 .handler = handle_jtag_flush_queue_sleep,
1110 .help =
"For debug purposes(simulate long delays of interface) "
1111 "to test performance or change in behavior. Default 0ms.",
1112 .usage =
"[sleep in ms]",
1115 .name =
"jtag_rclk",
1116 .handler = handle_jtag_rclk_command,
1118 .help =
"With an argument, change to to use adaptive clocking "
1119 "if possible; else to use the fallback speed. "
1120 "With or without argument, display current setting.",
1121 .usage =
"[fallback_speed_khz]",
1124 .name =
"jtag_ntrst_delay",
1125 .handler = handle_jtag_ntrst_delay_command,
1127 .help =
"delay after deasserting trst in ms",
1128 .usage =
"[milliseconds]",
1131 .name =
"jtag_ntrst_assert_width",
1132 .handler = handle_jtag_ntrst_assert_width_command,
1134 .help =
"delay after asserting trst in ms",
1135 .usage =
"[milliseconds]",
1138 .name =
"scan_chain",
1139 .handler = handle_scan_chain_command,
1141 .help =
"print current scan chain configuration",
1146 .handler = handle_runtest_command,
1148 .help =
"Move to Run-Test/Idle, and issue TCK for num_cycles.",
1149 .usage =
"num_cycles"
1153 .handler = handle_irscan_command,
1155 .help =
"Execute Instruction Register (IR) scan. The "
1156 "specified opcodes are put into each TAP's IR, "
1157 "and other TAPs are put in BYPASS.",
1158 .usage =
"[tap_name instruction]* ['-endstate' state_name]",
1161 .name =
"verify_ircapture",
1162 .handler = handle_verify_ircapture_command,
1164 .help =
"Display or assign flag controlling whether to "
1165 "verify values captured during Capture-IR.",
1166 .usage =
"['enable'|'disable']",
1169 .name =
"verify_jtag",
1170 .handler = handle_verify_jtag_command,
1172 .help =
"Display or assign flag controlling whether to "
1173 "verify values captured during IR and DR scans.",
1174 .usage =
"['enable'|'disable']",
1177 .name =
"tms_sequence",
1178 .handler = handle_tms_sequence_command,
1180 .help =
"Display or change what style TMS sequences to use "
1181 "for JTAG state transitions: short (default) or "
1182 "long. Only for working around JTAG bugs.",
1184 .usage =
"['short'|'long']",
1187 .name =
"wait_srst_deassert",
1188 .handler = handle_wait_srst_deassert,
1190 .help =
"Wait for an SRST deassert. "
1191 "Useful for cases where you need something to happen within ms "
1192 "of an srst deassert. Timeout in ms",
1198 .help =
"perform jtag tap actions",
int adapter_config_rclk(unsigned int fallback_speed_khz)
Attempt to enable RTCK/RCLK.
unsigned int adapter_get_speed_khz(void)
Retrieves the clock speed of the adapter in kHz.
int adapter_get_speed_readable(int *khz)
Given a speed setting, use the interface speed_div callback to adjust the setting.
bool transport_is_swd(void)
Returns true if the current debug session is using SWD as its transport.
char * buf_to_hex_str(const void *_buf, unsigned int buf_len)
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
static void buf_set_u64(uint8_t *_buffer, unsigned int first, unsigned int num, uint64_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
void command_print_sameline(struct command_invocation *cmd, const char *format,...)
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 CALL_COMMAND_HANDLER(name, extra ...)
Use this to macro to call a command helper (or a nested handler).
#define CMD_NAME
Use this macro to access the name of the command being handled, rather than accessing the variable di...
#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_JIMTCL_ARGV
Use this macro to access the jimtcl arguments for the command being handled, rather than accessing th...
#define COMMAND_PARSE_ENABLE(in, out)
parses an enable/disable command argument
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
#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,...
void tap_use_new_tms_table(bool use_new)
Allow switching between old and new TMS tables.
bool tap_uses_new_tms_table(void)
tap_state_t tap_state_by_name(const char *name)
Provides user-friendly name lookup of TAP states.
Exports the list of JTAG interface drivers, along with routines for loading and unloading them dynami...
struct jtag_tap * jtag_tap_by_string(const char *s)
int jtag_init_inner(struct command_context *cmd_ctx)
void jtag_add_runtest(unsigned 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_pathmove(unsigned int num_states, const tap_state_t *path)
Application code must assume that interfaces will implement transitions between states with different...
unsigned int jtag_get_ntrst_assert_width(void)
int jtag_init(struct command_context *cmd_ctx)
Initialize JTAG chain using only a RESET reset.
int jtag_srst_asserted(int *srst_asserted)
bool transport_is_jtag(void)
Returns true if the current debug session is using JTAG as its transport.
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
void jtag_set_flush_queue_sleep(int ms)
Set ms to sleep after jtag_execute_queue() flushes queue.
struct jtag_tap * jtag_all_taps(void)
int jtag_add_statemove(tap_state_t goal_state)
jtag_add_statemove() moves from the current state to goal_state.
int swd_init_reset(struct command_context *cmd_ctx)
int jtag_init_reset(struct command_context *cmd_ctx)
reset, then initialize JTAG chain
bool jtag_will_verify(void)
int jtag_call_event_callbacks(enum jtag_event event)
void jtag_set_ntrst_delay(unsigned int delay)
void jtag_set_verify_capture_ir(bool enable)
Enable or disable verification of IR scan checking.
unsigned int jtag_get_ntrst_delay(void)
bool jtag_will_verify_capture_ir(void)
unsigned int jtag_get_flush_queue_count(void)
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_tap_init(struct jtag_tap *tap)
void jtag_set_ntrst_assert_width(unsigned int delay)
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.
void jtag_set_verify(bool enable)
Enable or disable data scan verification checking.
int jtag_register_commands(struct command_context *cmd_ctx)
static const struct command_registration jtag_command_handlers_to_move[]
static void jtag_tap_handle_event(struct jtag_tap *tap, enum jtag_event e)
#define NTAP_OPT_DISABLED
static const struct nvp jtag_newtap_opts[]
static COMMAND_HELPER(handle_jtag_command_drscan_fields, struct scan_field *fields)
static bool jtag_tap_disable(struct jtag_tap *t)
static int jtag_tap_set_event(struct command_context *cmd_ctx, struct jtag_tap *tap, const struct nvp *event, Jim_Obj *body)
__COMMAND_HANDLER(handle_jtag_configure)
#define NTAP_OPT_EXPECTED_ID
#define NTAP_OPT_IRCAPTURE
static struct nvp nvp_config_opts[]
static const struct nvp nvp_jtag_tap_event[]
static bool scan_is_safe(tap_state_t state)
#define NTAP_OPT_IRBYPASS
COMMAND_HANDLER(handle_jtag_command_drscan)
static const struct command_registration jtag_subcommand_handlers[]
static bool jtag_tap_enable(struct jtag_tap *t)
static const struct command_registration jtag_command_handlers[]
void jtag_notify_event(enum jtag_event event)
Report Tcl event to all TAPs.
struct jtag_tap * jtag_tap_by_jim_obj(Jim_Interp *interp, Jim_Obj *o)
The JTAG interface can be implemented with a software or hardware fifo.
enum tap_state tap_state_t
Defines JTAG Test Access Port states.
char * alloc_printf(const char *format,...)
#define LOG_USER(expr ...)
#define LOG_WARNING(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
void nvp_unknown_command_print(struct command_invocation *cmd, const struct nvp *nvp, const char *param_name, const char *param_value)
const struct nvp * nvp_name2value(const struct nvp *p, const char *name)
const struct nvp * nvp_value2name(const struct nvp *p, int value)
uint8_t bits[QN908X_FLASH_MAX_BLOCKS *QN908X_FLASH_PAGES_PER_BLOCK/8]
char id[RTT_CB_MAX_ID_LENGTH]
Control block identifier.
const struct command_registration * chain
If non-NULL, the commands in chain will be registered in the same context and scope of this registrat...
struct jtag_tap_event_action * next
enum jtag_event event
The event for which this action will be triggered.
Jim_Obj * body
Contains a script to 'eval' when the event is triggered.
Jim_Interp * interp
The interpreter to use for evaluating the body.
uint32_t ir_capture_value
bool bypass
Bypass register selected.
uint8_t * expected_mask
Capture-IR expected mask.
bool ignore_version
Flag saying whether to ignore version field in expected_ids[].
bool disabled_after_reset
Is this TAP disabled after JTAG reset?
struct jtag_tap_event_action * event_action
unsigned int ir_length
size of instruction register
uint8_t * expected
Capture-IR expected value.
uint8_t expected_ids_cnt
Number of expected identification codes.
unsigned int abs_chain_position
bool ignore_bypass
Flag saying whether to ignore the bypass bit in the code.
bool enabled
Is this TAP currently enabled?
uint64_t ir_bypass_value
Bypass instruction value.
uint32_t * expected_ids
Array of expected identification codes.
struct jtag_tap * next_tap
uint32_t idcode
device identification code
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.
#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.