48 { .name =
NULL, .value = -1 }
53 const char *cp = Jim_GetString(o,
NULL);
58 Jim_SetResultFormatted(interp,
"Tap '%s' could not be found", cp);
94 if ((argc < 4) || ((argc % 2) != 0)) {
95 Jim_WrongNumArgs(interp, 1, args,
"wrong arguments");
103 for (i = 2; i < argc; i += 2) {
107 e = Jim_GetLong(interp, args[i], &
bits);
113 if (((i + 2) != argc)) {
124 cp = Jim_GetString(args[i],
NULL);
126 if (strcmp(
"-endstate", cp) == 0) {
128 cp = Jim_GetString(args[i + 1],
NULL);
134 Jim_SetResultFormatted(interp,
"endstate: %s invalid", cp);
138 "endstate \"%s\"", cp);
158 num_fields = (argc-2)/2;
159 if (num_fields <= 0) {
160 Jim_SetResultString(interp,
"drscan: no scan fields supplied", -1);
163 fields = malloc(
sizeof(
struct scan_field) * num_fields);
164 for (i = 2; i < argc; i += 2) {
169 Jim_GetLong(interp, args[i], &
bits);
170 str = Jim_GetString(args[i + 1], &len);
184 Jim_SetResultString(interp,
"drscan: jtag execute failed", -1);
186 for (i = 0; i < field_count; i++)
187 free(fields[i].in_value);
194 Jim_Obj *list = Jim_NewListObj(interp,
NULL, 0);
195 for (i = 2; i < argc; i += 2) {
199 Jim_GetLong(interp, args[i], &
bits);
201 free(fields[field_count].in_value);
203 Jim_ListAppendElement(interp, list, Jim_NewStringObj(interp, str, strlen(str)));
208 Jim_SetResult(interp, list);
220 if ((argc < 2) || ((
size_t)argc > (
ARRAY_SIZE(states) + 1))) {
221 Jim_WrongNumArgs(interp, 1, args,
"wrong arguments");
226 for (i = 0; i < argc-1; i++) {
228 cp = Jim_GetString(args[i + 1],
NULL);
232 Jim_SetResultFormatted(interp,
"endstate: %s invalid", cp);
238 Jim_SetResultString(interp,
"pathmove: jtag execute failed", -1);
245 Jim_SetResultString(interp,
"pathmove: failed", -1);
275 .help =
"Execute Data Register (DR) scan for one TAP. "
276 "Other TAPs must be in BYPASS mode.",
277 .usage =
"tap_name [num_bits value]* ['-endstate' state_name]",
280 .name =
"flush_count",
283 .help =
"Returns the number of times the JTAG queue "
290 .usage =
"start_state state1 [state2 [state3 ...]]",
291 .help =
"Move JTAG state machine from current state "
292 "(start_state) to state1, then state2, state3, etc.",
307 { .name =
NULL, .value = -1 }
312 if (goi->
argc == 0) {
313 Jim_WrongNumArgs(goi->
interp, goi->
argc, goi->
argv,
"-event <event-name> ...");
325 if (goi->
argc != 1) {
326 Jim_WrongNumArgs(goi->
interp,
329 "-event <event-name> <event-body>");
333 if (goi->
argc != 0) {
334 Jim_WrongNumArgs(goi->
interp, goi->
argc, goi->
argv,
"-event <event-name>");
350 Jim_SetEmptyResult(goi->
interp);
354 jteap = calloc(1,
sizeof(*jteap));
355 else if (jteap->
body)
363 jteap->
body = Jim_DuplicateObj(goi->
interp, o);
364 Jim_IncrRefCount(jteap->
body);
373 Jim_SetResult(goi->
interp,
382 while (goi->
argc > 0) {
383 Jim_SetEmptyResult(goi->
interp);
400 Jim_SetResultFormatted(goi->
interp,
401 "not settable: %s", n->
name);
404 if (goi->
argc != 0) {
405 Jim_WrongNumArgs(goi->
interp,
414 Jim_SetResultFormatted(goi->
interp,
"unknown value: %s", n->
name);
438 Jim_SetResultFormatted(goi->
interp,
"option: %s bad parameter", n->
name);
445 Jim_SetResultFormatted(goi->
interp,
"no memory");
455 #define NTAP_OPT_IRLEN 0
456 #define NTAP_OPT_IRMASK 1
457 #define NTAP_OPT_IRCAPTURE 2
458 #define NTAP_OPT_ENABLED 3
459 #define NTAP_OPT_DISABLED 4
460 #define NTAP_OPT_EXPECTED_ID 5
461 #define NTAP_OPT_VERSION 6
462 #define NTAP_OPT_BYPASS 7
470 Jim_SetResultFormatted(goi->
interp,
471 "option: %s bad parameter", n->
name);
517 const struct jim_nvp opts[] = {
526 { .name =
NULL, .value = -1 },
529 tap = calloc(1,
sizeof(
struct jtag_tap));
531 Jim_SetResultFormatted(goi->
interp,
"no memory");
539 Jim_SetResultFormatted(goi->
interp,
"Missing CHIP TAP OPTIONS ....");
546 tap->
chip = strdup(tmp);
552 x = strlen(tap->
chip) + 1 + strlen(tap->
tapname) + 1;
557 LOG_DEBUG(
"Creating New Tap, Chip: %s, Tap: %s, Dotted: %s, %d params",
626 Jim_SetResultFormatted(goi->
interp,
627 "newtap: %s missing IR length",
639 if (jteap->
event != e)
643 LOG_DEBUG(
"JTAG tap: %s event: %d (%s)\n\taction: %s",
647 retval = Jim_EvalObj(jteap->
interp, jteap->
body);
648 if (retval == JIM_RETURN)
649 retval = jteap->
interp->returnCode;
651 if (retval != JIM_OK) {
652 Jim_MakeErrorMessage(jteap->
interp);
666 tap->
enabled ?
"enabled" :
"disabled");
679 Jim_WrongNumArgs(goi.
interp, 1, goi.
argv-1,
"(no params)");
685 Jim_Obj *obj = Jim_NewIntObj(goi.
interp, e);
686 Jim_SetResultFormatted(goi.
interp,
"error: %#s", obj);
698 Jim_WrongNumArgs(goi.
interp, 1, goi.
argv-1,
"(no params)");
708 Jim_Obj *obj = Jim_NewIntObj(goi.
interp, e);
709 Jim_SetResultFormatted(goi.
interp,
"error: %#s", obj);
756 const char *cmd_name = c->
name;
760 Jim_SetResultFormatted(goi.
interp,
"usage: %s <name>", cmd_name);
770 if (strcasecmp(cmd_name,
"tapisenabled") == 0) {
772 }
else if (strcasecmp(cmd_name,
"tapenable") == 0) {
777 }
else if (strcasecmp(cmd_name,
"tapdisable") == 0) {
783 LOG_ERROR(
"command '%s' unknown", cmd_name);
787 Jim_SetResult(goi.
interp, Jim_NewIntObj(goi.
interp, e));
794 const char *cmd_name = c->
name;
800 "<tap_name> <attribute> ...");
820 Jim_WrongNumArgs(goi.
interp, 1, goi.
argv,
"Too many parameters");
827 Jim_ListAppendElement(goi.
interp,
828 Jim_GetResult(goi.
interp),
829 Jim_NewStringObj(goi.
interp,
840 static bool jtag_initialized;
841 if (jtag_initialized) {
842 LOG_INFO(
"'jtag init' has already been called");
845 jtag_initialized =
true;
847 LOG_DEBUG(
"Initializing jtag devices...");
855 .handler = handle_jtag_init_command,
856 .help =
"initialize jtag scan chain",
863 .help =
"Validates JTAG scan chain against the list of "
864 "declared TAPs using just the four standard JTAG "
868 .name =
"arp_init-reset",
871 .help =
"Uses TRST and SRST to try resetting everything on "
872 "the JTAG scan chain, then performs 'jtag arp_init'."
878 .help =
"Create a new TAP instance named basename.tap_type, "
879 "and appends it to the scan chain.",
880 .usage =
"basename tap_type '-irlen' count "
881 "['-enable'|'-disable'] "
882 "['-expected_id' number] "
883 "['-ignore-version'] "
884 "['-ignore-bypass'] "
885 "['-ircapture' number] "
889 .name =
"tapisenabled",
892 .help =
"Returns a Tcl boolean (0/1) indicating whether "
893 "the TAP is enabled (1) or not (0).",
900 .help =
"Try to enable the specified TAP using the "
901 "'tap-enable' TAP event.",
905 .name =
"tapdisable",
908 .help =
"Try to disable the specified TAP using the "
909 "'tap-disable' TAP event.",
916 .help =
"Provide a Tcl handler for the specified "
918 .usage =
"tap_name '-event' event_name handler",
924 .help =
"Return any Tcl handler for the specified "
926 .usage =
"tap_name '-event' event_name",
932 .help =
"Returns list of all JTAG tap names.",
952 char expected_id[12];
956 " TapName Enabled IdCode Expected IrLen IrCap IrMask");
958 "-- ------------------- -------- ---------- ---------- ----- ----- ------");
963 snprintf(expected_id,
sizeof(expected_id),
"0x%08x",
968 expected_id[2] =
'*';
974 "%2d %-18s %c 0x%08x %s %5d 0x%02x 0x%02x",
978 (
unsigned int)(tap->
idcode),
985 snprintf(expected_id,
sizeof(expected_id),
"0x%08x",
988 expected_id[2] =
'*';
1062 unsigned num_clocks;
1108 if (num_fields > 1) {
1112 LOG_ERROR(
"Specify a single value for tap");
1116 fields = calloc(num_fields,
sizeof(*fields));
1119 for (i = 0; i < num_fields; i++) {
1128 retval = parse_u64(
CMD_ARGV[i * 2 + 1], &value);
1151 for (i = 0; i < num_fields; i++)
1152 free((
void *)fields[i].out_value);
1200 if (strcmp(
CMD_ARGV[0],
"short") == 0)
1201 use_new_table =
true;
1202 else if (strcmp(
CMD_ARGV[0],
"long") == 0)
1203 use_new_table =
false;
1236 if ((timeout_ms <= 0) || (timeout_ms > 100000)) {
1237 LOG_ERROR(
"Timeout must be an integer between 0 and 100000");
1241 LOG_USER(
"Waiting for srst assert + deassert for at most %dms", timeout_ms);
1267 .
name =
"jtag_flush_queue_sleep",
1268 .handler = handle_jtag_flush_queue_sleep,
1270 .help =
"For debug purposes(simulate long delays of interface) "
1271 "to test performance or change in behavior. Default 0ms.",
1272 .usage =
"[sleep in ms]",
1275 .name =
"jtag_rclk",
1276 .handler = handle_jtag_rclk_command,
1278 .help =
"With an argument, change to to use adaptive clocking "
1279 "if possible; else to use the fallback speed. "
1280 "With or without argument, display current setting.",
1281 .usage =
"[fallback_speed_khz]",
1284 .name =
"jtag_ntrst_delay",
1285 .handler = handle_jtag_ntrst_delay_command,
1287 .help =
"delay after deasserting trst in ms",
1288 .usage =
"[milliseconds]",
1291 .name =
"jtag_ntrst_assert_width",
1292 .handler = handle_jtag_ntrst_assert_width_command,
1294 .help =
"delay after asserting trst in ms",
1295 .usage =
"[milliseconds]",
1298 .name =
"scan_chain",
1299 .handler = handle_scan_chain_command,
1301 .help =
"print current scan chain configuration",
1306 .handler = handle_runtest_command,
1308 .help =
"Move to Run-Test/Idle, and issue TCK for num_cycles.",
1309 .usage =
"num_cycles"
1313 .handler = handle_irscan_command,
1315 .help =
"Execute Instruction Register (IR) scan. The "
1316 "specified opcodes are put into each TAP's IR, "
1317 "and other TAPs are put in BYPASS.",
1318 .usage =
"[tap_name instruction]* ['-endstate' state_name]",
1321 .name =
"verify_ircapture",
1322 .handler = handle_verify_ircapture_command,
1324 .help =
"Display or assign flag controlling whether to "
1325 "verify values captured during Capture-IR.",
1326 .usage =
"['enable'|'disable']",
1329 .name =
"verify_jtag",
1330 .handler = handle_verify_jtag_command,
1332 .help =
"Display or assign flag controlling whether to "
1333 "verify values captured during IR and DR scans.",
1334 .usage =
"['enable'|'disable']",
1337 .name =
"tms_sequence",
1338 .handler = handle_tms_sequence_command,
1340 .help =
"Display or change what style TMS sequences to use "
1341 "for JTAG state transitions: short (default) or "
1342 "long. Only for working around JTAG bugs.",
1344 .usage =
"['short'|'long']",
1347 .name =
"wait_srst_deassert",
1348 .handler = handle_wait_srst_deassert,
1350 .help =
"Wait for an SRST deassert. "
1351 "Useful for cases where you need something to happen within ms "
1352 "of an srst deassert. Timeout in ms",
1358 .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.
struct command_context * current_command_context(Jim_Interp *interp)
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_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...
static struct command * jim_to_command(Jim_Interp *interp)
#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,...
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...
int jim_getopt_wide(struct jim_getopt_info *goi, jim_wide *puthere)
Remove argv[0] as wide.
int jim_getopt_setup(struct jim_getopt_info *p, Jim_Interp *interp, int argc, Jim_Obj *const *argv)
GetOpt - how to.
int jim_getopt_string(struct jim_getopt_info *goi, const char **puthere, int *len)
Remove argv[0] as string.
int jim_getopt_nvp(struct jim_getopt_info *goi, const struct jim_nvp *nvp, struct jim_nvp **puthere)
Remove argv[0] as NVP.
void jim_getopt_nvp_unknown(struct jim_getopt_info *goi, const struct jim_nvp *nvptable, int hadprefix)
Create an appropriate error message for an NVP.
int jim_getopt_obj(struct jim_getopt_info *goi, Jim_Obj **puthere)
Remove argv[0] from the list.
struct jim_nvp * jim_nvp_value2name_simple(const struct jim_nvp *p, int value)
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_tap_free(struct jtag_tap *tap)
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 int jtag_tap_configure_cmd(struct jim_getopt_info *goi, struct jtag_tap *tap)
static const struct command_registration jtag_command_handlers_to_move[]
int jim_jtag_tap_enabler(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
static void jtag_tap_handle_event(struct jtag_tap *tap, enum jtag_event e)
int jim_jtag_configure(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
static int jim_command_flush_count(Jim_Interp *interp, int argc, Jim_Obj *const *args)
#define NTAP_OPT_DISABLED
static const struct jim_nvp nvp_jtag_tap_event[]
static int is_bad_irval(int ir_length, jim_wide w)
static int jim_jtag_names(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
static struct jim_nvp nvp_config_opts[]
static bool jtag_tap_disable(struct jtag_tap *t)
static int jtag_tap_configure_event(struct jim_getopt_info *goi, struct jtag_tap *tap)
static int jim_newtap_ir_param(struct jim_nvp *n, struct jim_getopt_info *goi, struct jtag_tap *tap)
static int jim_newtap_cmd(struct jim_getopt_info *goi)
static int jim_jtag_arp_init(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
#define NTAP_OPT_EXPECTED_ID
#define NTAP_OPT_IRCAPTURE
COMMAND_HANDLER(handle_jtag_init_command)
static int jim_command_pathmove(Jim_Interp *interp, int argc, Jim_Obj *const *args)
static int jim_command_drscan(Jim_Interp *interp, int argc, Jim_Obj *const *args)
static bool scan_is_safe(tap_state_t state)
static int jim_newtap_expected_id(struct jim_nvp *n, struct jim_getopt_info *goi, struct jtag_tap *tap)
static const struct command_registration jtag_subcommand_handlers[]
static bool jtag_tap_enable(struct jtag_tap *t)
int jim_jtag_newtap(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
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)
static int jim_jtag_arp_init_reset(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
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_INFO(expr ...)
#define LOG_DEBUG(expr ...)
const struct command_registration * chain
If non-NULL, the commands in chain will be registered in the same context and scope of this registrat...
A TCL -ish GetOpt like code.
Name Value Pairs, aka: NVP.
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
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?
uint32_t * expected_ids
Array of expected identification codes.
struct jtag_tap * next_tap
uint32_t idcode
device identification code
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.