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) {
136 LOG_WARNING(
"drscan with unsafe endstate \"%s\"", state_name);
141 unsigned int num_fields = (
CMD_ARGC - 1) / 2;
160 for (
unsigned int i = 0; i < num_fields; i++) {
167 for (
unsigned int i = 0; i < num_fields; i++)
178 if (CMD_ARGC < 1 || CMD_ARGC >
ARRAY_SIZE(states))
181 for (
unsigned int i = 0; i <
CMD_ARGC; i++) {
232 .handler = handle_jtag_command_drscan,
233 .help =
"Execute Data Register (DR) scan for one TAP. "
234 "Other TAPs must be in BYPASS mode.",
235 .usage =
"tap_name (num_bits value)+ ['-endstate' state_name]",
238 .name =
"flush_count",
240 .handler = handle_jtag_flush_count,
241 .help =
"Returns the number of times the JTAG queue "
248 .handler = handle_jtag_command_pathmove,
249 .usage =
"start_state state1 [state2 [state3 ...]]",
250 .help =
"Move JTAG state machine from current state "
251 "(start_state) to state1, then state2, state3, etc.",
266 { .name =
NULL, .value = -1 }
270 const struct nvp *event, Jim_Obj *body)
281 jteap = calloc(1,
sizeof(*jteap));
291 Jim_DecrRefCount(cmd_ctx->
interp, jteap->
body);
297 Jim_IncrRefCount(jteap->
body);
304 bool is_configure = !strcmp(
CMD_NAME,
"configure");
306 if (
CMD_ARGC < (is_configure ? 3 : 2))
314 for (
unsigned int i = 1; i <
CMD_ARGC; i++) {
318 if (i + (is_configure ? 2 : 1) >=
CMD_ARGC) {
320 is_configure ?
" <event-body>" :
"");
345 i += is_configure ? 2 : 1;
362 #define NTAP_OPT_IRLEN 0
363 #define NTAP_OPT_IRMASK 1
364 #define NTAP_OPT_IRCAPTURE 2
365 #define NTAP_OPT_ENABLED 3
366 #define NTAP_OPT_DISABLED 4
367 #define NTAP_OPT_EXPECTED_ID 5
368 #define NTAP_OPT_VERSION 6
369 #define NTAP_OPT_BYPASS 7
370 #define NTAP_OPT_IRBYPASS 8
382 { .name =
NULL, .value = -1 },
401 LOG_DEBUG(
"Creating New Tap, Chip: %s, Tap: %s, Dotted: %s, %d params",
539 if (jteap->
event != e)
543 LOG_DEBUG(
"JTAG tap: %s event: %d (%s)\n\taction: %s",
547 retval = Jim_EvalObj(jteap->
interp, jteap->
body);
548 if (retval == JIM_RETURN)
549 retval = jteap->
interp->returnCode;
551 if (retval != JIM_OK) {
552 Jim_MakeErrorMessage(jteap->
interp);
566 tap->
enabled ?
"enabled" :
"disabled");
638 if (strcmp(
CMD_NAME,
"tapisenabled") == 0) {
640 }
else if (strcmp(
CMD_NAME,
"tapenable") == 0) {
645 }
else if (strcmp(
CMD_NAME,
"tapdisable") == 0) {
675 static bool jtag_initialized;
676 if (jtag_initialized) {
677 LOG_INFO(
"'jtag init' has already been called");
680 jtag_initialized =
true;
682 LOG_DEBUG(
"Initializing jtag devices...");
690 .handler = handle_jtag_init_command,
691 .help =
"initialize jtag scan chain",
697 .handler = handle_jtag_arp_init,
698 .help =
"Validates JTAG scan chain against the list of "
699 "declared TAPs using just the four standard JTAG "
704 .name =
"arp_init-reset",
706 .handler = handle_jtag_arp_init_reset,
707 .help =
"Uses TRST and SRST to try resetting everything on "
708 "the JTAG scan chain, then performs 'jtag arp_init'.",
714 .handler = handle_jtag_newtap,
715 .help =
"Create a new TAP instance named basename.tap_type, "
716 "and appends it to the scan chain.",
717 .usage =
"basename tap_type '-irlen' count "
718 "['-enable'|'-disable'] "
719 "['-expected_id' number] "
720 "['-ignore-version'] "
721 "['-ignore-bypass'] "
722 "['-ircapture' number] "
723 "['-ir-bypass' number] "
727 .name =
"tapisenabled",
729 .handler = handle_jtag_tap_enabler,
730 .help =
"Returns a Tcl boolean (0/1) indicating whether "
731 "the TAP is enabled (1) or not (0).",
737 .handler = handle_jtag_tap_enabler,
738 .help =
"Try to enable the specified TAP using the "
739 "'tap-enable' TAP event.",
743 .name =
"tapdisable",
745 .handler = handle_jtag_tap_enabler,
746 .help =
"Try to disable the specified TAP using the "
747 "'tap-disable' TAP event.",
753 .handler = handle_jtag_configure,
754 .help =
"Provide a Tcl handler for the specified "
756 .usage =
"tap_name '-event' event_name handler",
761 .handler = handle_jtag_configure,
762 .help =
"Return any Tcl handler for the specified "
764 .usage =
"tap_name '-event' event_name",
769 .handler = handle_jtag_names,
770 .help =
"Returns list of all JTAG tap names.",
791 char expected_id[12];
795 " TapName Enabled IdCode Expected IrLen IrCap IrMask");
797 "-- ------------------- -------- ---------- ---------- ----- ----- ------");
802 snprintf(expected_id,
sizeof(expected_id),
"0x%08x",
807 expected_id[2] =
'*';
813 "%2d %-18s %c 0x%08x %s %5d 0x%02x 0x%02x",
817 (
unsigned int)(tap->
idcode),
824 snprintf(expected_id,
sizeof(expected_id),
"0x%08x",
827 expected_id[2] =
'*';
947 if (num_fields > 1) {
951 LOG_ERROR(
"Specify a single value for tap");
955 fields = calloc(num_fields,
sizeof(*fields));
958 for (i = 0; i < num_fields; i++) {
967 retval = parse_u64(
CMD_ARGV[i * 2 + 1], &value);
990 for (i = 0; i < num_fields; i++)
991 free((
void *)fields[i].out_value);
1039 if (strcmp(
CMD_ARGV[0],
"short") == 0)
1040 use_new_table =
true;
1041 else if (strcmp(
CMD_ARGV[0],
"long") == 0)
1042 use_new_table =
false;
1075 if ((timeout_ms <= 0) || (timeout_ms > 100000)) {
1076 LOG_ERROR(
"Timeout must be an integer between 0 and 100000");
1080 LOG_USER(
"Waiting for srst assert + deassert for at most %dms", timeout_ms);
1106 .
name =
"jtag_flush_queue_sleep",
1107 .handler = handle_jtag_flush_queue_sleep,
1109 .help =
"For debug purposes(simulate long delays of interface) "
1110 "to test performance or change in behavior. Default 0ms.",
1111 .usage =
"[sleep in ms]",
1114 .name =
"jtag_rclk",
1115 .handler = handle_jtag_rclk_command,
1117 .help =
"With an argument, change to to use adaptive clocking "
1118 "if possible; else to use the fallback speed. "
1119 "With or without argument, display current setting.",
1120 .usage =
"[fallback_speed_khz]",
1123 .name =
"jtag_ntrst_delay",
1124 .handler = handle_jtag_ntrst_delay_command,
1126 .help =
"delay after deasserting trst in ms",
1127 .usage =
"[milliseconds]",
1130 .name =
"jtag_ntrst_assert_width",
1131 .handler = handle_jtag_ntrst_assert_width_command,
1133 .help =
"delay after asserting trst in ms",
1134 .usage =
"[milliseconds]",
1137 .name =
"scan_chain",
1138 .handler = handle_scan_chain_command,
1140 .help =
"print current scan chain configuration",
1145 .handler = handle_runtest_command,
1147 .help =
"Move to Run-Test/Idle, and issue TCK for num_cycles.",
1148 .usage =
"num_cycles"
1152 .handler = handle_irscan_command,
1154 .help =
"Execute Instruction Register (IR) scan. The "
1155 "specified opcodes are put into each TAP's IR, "
1156 "and other TAPs are put in BYPASS.",
1157 .usage =
"[tap_name instruction]* ['-endstate' state_name]",
1160 .name =
"verify_ircapture",
1161 .handler = handle_verify_ircapture_command,
1163 .help =
"Display or assign flag controlling whether to "
1164 "verify values captured during Capture-IR.",
1165 .usage =
"['enable'|'disable']",
1168 .name =
"verify_jtag",
1169 .handler = handle_verify_jtag_command,
1171 .help =
"Display or assign flag controlling whether to "
1172 "verify values captured during IR and DR scans.",
1173 .usage =
"['enable'|'disable']",
1176 .name =
"tms_sequence",
1177 .handler = handle_tms_sequence_command,
1179 .help =
"Display or change what style TMS sequences to use "
1180 "for JTAG state transitions: short (default) or "
1181 "long. Only for working around JTAG bugs.",
1183 .usage =
"['short'|'long']",
1186 .name =
"wait_srst_deassert",
1187 .handler = handle_wait_srst_deassert,
1189 .help =
"Wait for an SRST deassert. "
1190 "Useful for cases where you need something to happen within ms "
1191 "of an srst deassert. Timeout in ms",
1197 .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 buf_len)
int str_to_buf(const char *str, unsigned str_len, void *_buf, unsigned buf_len, unsigned radix)
static void buf_set_u64(uint8_t *_buffer, unsigned first, unsigned num, uint64_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
static uint32_t buf_get_u32(const uint8_t *_buffer, unsigned first, unsigned num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 32-bit word.
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_set_ntrst_assert_width(unsigned delay)
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_set_ntrst_delay(unsigned delay)
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.
unsigned jtag_get_ntrst_delay(void)
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_get_flush_queue_count(void)
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)
unsigned jtag_get_ntrst_assert_width(void)
void jtag_set_verify_capture_ir(bool enable)
Enable or disable verification of IR scan checking.
bool jtag_will_verify_capture_ir(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_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_tap_init(struct jtag_tap *tap)
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
int ir_length
size of instruction register
uint8_t * expected
Capture-IR expected value.
uint8_t expected_ids_cnt
Number of expected identification codes.
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.
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.
#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.