1 // SPDX-License-Identifier: GPL-2.0-or-later
3 /***************************************************************************
4 * Copyright (C) 2005 by Dominic Rath *
5 * Dominic.Rath@gmx.de *
7 * Copyright (C) 2007-2010 Øyvind Harboe *
8 * oyvind.harboe@zylin.com *
10 * Copyright (C) 2009 SoftPLC Corporation *
11 * http://softplc.com *
14 * Copyright (C) 2009 Zachary T Welch *
15 * zw@superlucidity.net *
16 ***************************************************************************/
25 #include "minidriver.h"
26 #include "interface.h"
27 #include "interfaces.h"
34 #include <helper/time_support.h>
35 #include "transport/transport.h"
39 * Holds support for accessing JTAG-specific mechanisms from TCl scripts.
42 static const struct jim_nvp nvp_jtag_tap_event
[] = {
43 { .value
= JTAG_TRST_ASSERTED
, .name
= "post-reset" },
44 { .value
= JTAG_TAP_EVENT_SETUP
, .name
= "setup" },
45 { .value
= JTAG_TAP_EVENT_ENABLE
, .name
= "tap-enable" },
46 { .value
= JTAG_TAP_EVENT_DISABLE
, .name
= "tap-disable" },
48 { .name
= NULL
, .value
= -1 }
51 struct jtag_tap
*jtag_tap_by_jim_obj(Jim_Interp
*interp
, Jim_Obj
*o
)
53 const char *cp
= Jim_GetString(o
, NULL
);
54 struct jtag_tap
*t
= cp
? jtag_tap_by_string(cp
) : NULL
;
58 Jim_SetResultFormatted(interp
, "Tap '%s' could not be found", cp
);
62 static bool scan_is_safe(tap_state_t state
)
75 static int jim_command_drscan(Jim_Interp
*interp
, int argc
, Jim_Obj
* const *args
)
78 struct scan_field
*fields
;
87 * args[3] = hex string
88 * ... repeat num bits and hex string ...
91 * args[N-2] = "-endstate"
92 * args[N-1] = statename
94 if ((argc
< 4) || ((argc
% 2) != 0)) {
95 Jim_WrongNumArgs(interp
, 1, args
, "wrong arguments");
101 /* validate arguments as numbers */
103 for (i
= 2; i
< argc
; i
+= 2) {
107 e
= Jim_GetLong(interp
, args
[i
], &bits
);
108 /* If valid - try next arg */
112 /* Not valid.. are we at the end? */
113 if (((i
+ 2) != argc
)) {
114 /* nope, then error */
118 /* it could be: "-endstate FOO"
119 * e.g. DRPAUSE so we can issue more instructions
120 * before entering RUN/IDLE and executing them.
123 /* get arg as a string. */
124 cp
= Jim_GetString(args
[i
], NULL
);
125 /* is it the magic? */
126 if (strcmp("-endstate", cp
) == 0) {
127 /* is the statename valid? */
128 cp
= Jim_GetString(args
[i
+ 1], NULL
);
130 /* see if it is a valid state name */
131 endstate
= tap_state_by_name(cp
);
133 /* update the error message */
134 Jim_SetResultFormatted(interp
, "endstate: %s invalid", cp
);
136 if (!scan_is_safe(endstate
))
137 LOG_WARNING("drscan with unsafe "
138 "endstate \"%s\"", cp
);
140 /* valid - so clear the error */
142 /* and remove the last 2 args */
147 /* Still an error? */
149 return e
; /* too bad */
150 } /* validate args */
154 tap
= jtag_tap_by_jim_obj(interp
, args
[1]);
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
);
172 fields
[field_count
].num_bits
= bits
;
173 void *t
= malloc(DIV_ROUND_UP(bits
, 8));
174 fields
[field_count
].out_value
= t
;
175 str_to_buf(str
, len
, t
, bits
, 0);
176 fields
[field_count
].in_value
= t
;
180 jtag_add_dr_scan(tap
, num_fields
, fields
, endstate
);
182 retval
= jtag_execute_queue();
183 if (retval
!= ERROR_OK
) {
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
);
200 str
= buf_to_hex_str(fields
[field_count
].in_value
, bits
);
201 free(fields
[field_count
].in_value
);
203 Jim_ListAppendElement(interp
, list
, Jim_NewStringObj(interp
, str
, strlen(str
)));
208 Jim_SetResult(interp
, list
);
216 static int jim_command_pathmove(Jim_Interp
*interp
, int argc
, Jim_Obj
* const *args
)
218 tap_state_t states
[8];
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
);
229 states
[i
] = tap_state_by_name(cp
);
231 /* update the error message */
232 Jim_SetResultFormatted(interp
, "endstate: %s invalid", cp
);
237 if ((jtag_add_statemove(states
[0]) != ERROR_OK
) || (jtag_execute_queue() != ERROR_OK
)) {
238 Jim_SetResultString(interp
, "pathmove: jtag execute failed", -1);
242 jtag_add_pathmove(argc
- 2, states
+ 1);
244 if (jtag_execute_queue() != ERROR_OK
) {
245 Jim_SetResultString(interp
, "pathmove: failed", -1);
253 static int jim_command_flush_count(Jim_Interp
*interp
, int argc
, Jim_Obj
* const *args
)
255 Jim_SetResult(interp
, Jim_NewIntObj(interp
, jtag_get_flush_queue_count()));
260 /* REVISIT Just what about these should "move" ... ?
261 * These registrations, into the main JTAG table?
263 * There's a minor compatibility issue, these all show up twice;
264 * that's not desirable:
265 * - jtag drscan ... NOT DOCUMENTED!
268 * The "irscan" command (for example) doesn't show twice.
270 static const struct command_registration jtag_command_handlers_to_move
[] = {
273 .mode
= COMMAND_EXEC
,
274 .jim_handler
= jim_command_drscan
,
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",
281 .mode
= COMMAND_EXEC
,
282 .jim_handler
= jim_command_flush_count
,
283 .help
= "Returns the number of times the JTAG queue "
288 .mode
= COMMAND_EXEC
,
289 .jim_handler
= jim_command_pathmove
,
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.",
294 COMMAND_REGISTRATION_DONE
298 enum jtag_tap_cfg_param
{
303 static struct jim_nvp nvp_config_opts
[] = {
304 { .name
= "-event", .value
= JCFG_EVENT
},
305 { .name
= "-idcode", .value
= JCFG_IDCODE
},
307 { .name
= NULL
, .value
= -1 }
310 static int jtag_tap_configure_event(struct jim_getopt_info
*goi
, struct jtag_tap
*tap
)
312 if (goi
->argc
== 0) {
313 Jim_WrongNumArgs(goi
->interp
, goi
->argc
, goi
->argv
, "-event <event-name> ...");
318 int e
= jim_getopt_nvp(goi
, nvp_jtag_tap_event
, &n
);
320 jim_getopt_nvp_unknown(goi
, nvp_jtag_tap_event
, 1);
324 if (goi
->isconfigure
) {
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>");
339 struct jtag_tap_event_action
*jteap
= tap
->event_action
;
340 /* replace existing event body */
343 if (jteap
->event
== (enum jtag_event
)n
->value
) {
350 Jim_SetEmptyResult(goi
->interp
);
352 if (goi
->isconfigure
) {
354 jteap
= calloc(1, sizeof(*jteap
));
355 else if (jteap
->body
)
356 Jim_DecrRefCount(goi
->interp
, jteap
->body
);
358 jteap
->interp
= goi
->interp
;
359 jteap
->event
= n
->value
;
362 jim_getopt_obj(goi
, &o
);
363 jteap
->body
= Jim_DuplicateObj(goi
->interp
, o
);
364 Jim_IncrRefCount(jteap
->body
);
367 /* add to head of event list */
368 jteap
->next
= tap
->event_action
;
369 tap
->event_action
= jteap
;
372 jteap
->interp
= goi
->interp
;
373 Jim_SetResult(goi
->interp
,
374 Jim_DuplicateObj(goi
->interp
, jteap
->body
));
379 static int jtag_tap_configure_cmd(struct jim_getopt_info
*goi
, struct jtag_tap
*tap
)
381 /* parse config or cget options */
382 while (goi
->argc
> 0) {
383 Jim_SetEmptyResult(goi
->interp
);
386 int e
= jim_getopt_nvp(goi
, nvp_config_opts
, &n
);
388 jim_getopt_nvp_unknown(goi
, nvp_config_opts
, 0);
394 e
= jtag_tap_configure_event(goi
, tap
);
399 if (goi
->isconfigure
) {
400 Jim_SetResultFormatted(goi
->interp
,
401 "not settable: %s", n
->name
);
404 if (goi
->argc
!= 0) {
405 Jim_WrongNumArgs(goi
->interp
,
406 goi
->argc
, goi
->argv
,
411 Jim_SetResult(goi
->interp
, Jim_NewIntObj(goi
->interp
, tap
->idcode
));
414 Jim_SetResultFormatted(goi
->interp
, "unknown value: %s", n
->name
);
422 static int is_bad_irval(int ir_length
, jim_wide w
)
432 static int jim_newtap_expected_id(struct jim_nvp
*n
, struct jim_getopt_info
*goi
,
433 struct jtag_tap
*tap
)
436 int e
= jim_getopt_wide(goi
, &w
);
438 Jim_SetResultFormatted(goi
->interp
, "option: %s bad parameter", n
->name
);
442 uint32_t *p
= realloc(tap
->expected_ids
,
443 (tap
->expected_ids_cnt
+ 1) * sizeof(uint32_t));
445 Jim_SetResultFormatted(goi
->interp
, "no memory");
449 tap
->expected_ids
= p
;
450 tap
->expected_ids
[tap
->expected_ids_cnt
++] = w
;
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
464 static int jim_newtap_ir_param(struct jim_nvp
*n
, struct jim_getopt_info
*goi
,
465 struct jtag_tap
*tap
)
468 int e
= jim_getopt_wide(goi
, &w
);
470 Jim_SetResultFormatted(goi
->interp
,
471 "option: %s bad parameter", n
->name
);
476 if (w
> (jim_wide
) (8 * sizeof(tap
->ir_capture_value
))) {
477 LOG_WARNING("%s: huge IR length %d",
478 tap
->dotted_name
, (int) w
);
482 case NTAP_OPT_IRMASK
:
483 if (is_bad_irval(tap
->ir_length
, w
)) {
484 LOG_ERROR("%s: IR mask %x too big",
490 LOG_WARNING("%s: nonstandard IR mask", tap
->dotted_name
);
491 tap
->ir_capture_mask
= w
;
493 case NTAP_OPT_IRCAPTURE
:
494 if (is_bad_irval(tap
->ir_length
, w
)) {
495 LOG_ERROR("%s: IR capture %x too big",
496 tap
->dotted_name
, (int) w
);
500 LOG_WARNING("%s: nonstandard IR value",
502 tap
->ir_capture_value
= w
;
510 static int jim_newtap_cmd(struct jim_getopt_info
*goi
)
512 struct jtag_tap
*tap
;
517 const struct jim_nvp opts
[] = {
518 { .name
= "-irlen", .value
= NTAP_OPT_IRLEN
},
519 { .name
= "-irmask", .value
= NTAP_OPT_IRMASK
},
520 { .name
= "-ircapture", .value
= NTAP_OPT_IRCAPTURE
},
521 { .name
= "-enable", .value
= NTAP_OPT_ENABLED
},
522 { .name
= "-disable", .value
= NTAP_OPT_DISABLED
},
523 { .name
= "-expected-id", .value
= NTAP_OPT_EXPECTED_ID
},
524 { .name
= "-ignore-version", .value
= NTAP_OPT_VERSION
},
525 { .name
= "-ignore-bypass", .value
= NTAP_OPT_BYPASS
},
526 { .name
= NULL
, .value
= -1 },
529 tap
= calloc(1, sizeof(struct jtag_tap
));
531 Jim_SetResultFormatted(goi
->interp
, "no memory");
536 * we expect CHIP + TAP + OPTIONS
539 Jim_SetResultFormatted(goi
->interp
, "Missing CHIP TAP OPTIONS ....");
545 jim_getopt_string(goi
, &tmp
, NULL
);
546 tap
->chip
= strdup(tmp
);
548 jim_getopt_string(goi
, &tmp
, NULL
);
549 tap
->tapname
= strdup(tmp
);
551 /* name + dot + name + null */
552 x
= strlen(tap
->chip
) + 1 + strlen(tap
->tapname
) + 1;
554 sprintf(cp
, "%s.%s", tap
->chip
, tap
->tapname
);
555 tap
->dotted_name
= cp
;
557 LOG_DEBUG("Creating New Tap, Chip: %s, Tap: %s, Dotted: %s, %d params",
558 tap
->chip
, tap
->tapname
, tap
->dotted_name
, goi
->argc
);
560 /* IEEE specifies that the two LSBs of an IR scan are 01, so make
561 * that the default. The "-ircapture" and "-irmask" options are only
562 * needed to cope with nonstandard TAPs, or to specify more bits.
564 tap
->ir_capture_mask
= 0x03;
565 tap
->ir_capture_value
= 0x01;
568 e
= jim_getopt_nvp(goi
, opts
, &n
);
570 jim_getopt_nvp_unknown(goi
, opts
, 0);
575 LOG_DEBUG("Processing option: %s", n
->name
);
577 case NTAP_OPT_ENABLED
:
578 tap
->disabled_after_reset
= false;
580 case NTAP_OPT_DISABLED
:
581 tap
->disabled_after_reset
= true;
583 case NTAP_OPT_EXPECTED_ID
:
584 e
= jim_newtap_expected_id(n
, goi
, tap
);
592 case NTAP_OPT_IRMASK
:
593 case NTAP_OPT_IRCAPTURE
:
594 e
= jim_newtap_ir_param(n
, goi
, tap
);
601 case NTAP_OPT_VERSION
:
602 tap
->ignore_version
= true;
604 case NTAP_OPT_BYPASS
:
605 tap
->ignore_bypass
= true;
607 } /* switch (n->value) */
608 } /* while (goi->argc) */
610 /* default is enabled-after-reset */
611 tap
->enabled
= !tap
->disabled_after_reset
;
613 /* Did all the required option bits get cleared? */
614 if (!transport_is_jtag() || tap
->ir_length
!= 0) {
619 Jim_SetResultFormatted(goi
->interp
,
620 "newtap: %s missing IR length",
626 static void jtag_tap_handle_event(struct jtag_tap
*tap
, enum jtag_event e
)
628 struct jtag_tap_event_action
*jteap
;
631 for (jteap
= tap
->event_action
; jteap
; jteap
= jteap
->next
) {
632 if (jteap
->event
!= e
)
635 struct jim_nvp
*nvp
= jim_nvp_value2name_simple(nvp_jtag_tap_event
, e
);
636 LOG_DEBUG("JTAG tap: %s event: %d (%s)\n\taction: %s",
637 tap
->dotted_name
, e
, nvp
->name
,
638 Jim_GetString(jteap
->body
, NULL
));
640 retval
= Jim_EvalObj(jteap
->interp
, jteap
->body
);
641 if (retval
== JIM_RETURN
)
642 retval
= jteap
->interp
->returnCode
;
644 if (retval
!= JIM_OK
) {
645 Jim_MakeErrorMessage(jteap
->interp
);
646 LOG_USER("%s", Jim_GetString(Jim_GetResult(jteap
->interp
), NULL
));
651 case JTAG_TAP_EVENT_ENABLE
:
652 case JTAG_TAP_EVENT_DISABLE
:
653 /* NOTE: we currently assume the handlers
654 * can't fail. Right here is where we should
655 * really be verifying the scan chains ...
657 tap
->enabled
= (e
== JTAG_TAP_EVENT_ENABLE
);
658 LOG_INFO("JTAG tap: %s %s", tap
->dotted_name
,
659 tap
->enabled
? "enabled" : "disabled");
667 static int jim_jtag_arp_init(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
669 struct jim_getopt_info goi
;
670 jim_getopt_setup(&goi
, interp
, argc
-1, argv
+ 1);
672 Jim_WrongNumArgs(goi
.interp
, 1, goi
.argv
-1, "(no params)");
675 struct command_context
*context
= current_command_context(interp
);
676 int e
= jtag_init_inner(context
);
678 Jim_Obj
*obj
= Jim_NewIntObj(goi
.interp
, e
);
679 Jim_SetResultFormatted(goi
.interp
, "error: %#s", obj
);
685 static int jim_jtag_arp_init_reset(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
688 struct jim_getopt_info goi
;
689 jim_getopt_setup(&goi
, interp
, argc
-1, argv
+ 1);
691 Jim_WrongNumArgs(goi
.interp
, 1, goi
.argv
-1, "(no params)");
694 struct command_context
*context
= current_command_context(interp
);
695 if (transport_is_jtag())
696 e
= jtag_init_reset(context
);
697 else if (transport_is_swd())
698 e
= swd_init_reset(context
);
701 Jim_Obj
*obj
= Jim_NewIntObj(goi
.interp
, e
);
702 Jim_SetResultFormatted(goi
.interp
, "error: %#s", obj
);
708 int jim_jtag_newtap(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
710 struct jim_getopt_info goi
;
711 jim_getopt_setup(&goi
, interp
, argc
-1, argv
+ 1);
712 return jim_newtap_cmd(&goi
);
715 static bool jtag_tap_enable(struct jtag_tap
*t
)
719 jtag_tap_handle_event(t
, JTAG_TAP_EVENT_ENABLE
);
723 /* FIXME add JTAG sanity checks, w/o TLR
724 * - scan chain length grew by one (this)
725 * - IDs and IR lengths are as expected
727 jtag_call_event_callbacks(JTAG_TAP_EVENT_ENABLE
);
730 static bool jtag_tap_disable(struct jtag_tap
*t
)
734 jtag_tap_handle_event(t
, JTAG_TAP_EVENT_DISABLE
);
738 /* FIXME add JTAG sanity checks, w/o TLR
739 * - scan chain length shrank by one (this)
740 * - IDs and IR lengths are as expected
742 jtag_call_event_callbacks(JTAG_TAP_EVENT_DISABLE
);
746 int jim_jtag_tap_enabler(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
748 struct command
*c
= jim_to_command(interp
);
749 const char *cmd_name
= c
->name
;
750 struct jim_getopt_info goi
;
751 jim_getopt_setup(&goi
, interp
, argc
-1, argv
+ 1);
753 Jim_SetResultFormatted(goi
.interp
, "usage: %s <name>", cmd_name
);
759 t
= jtag_tap_by_jim_obj(goi
.interp
, goi
.argv
[0]);
763 if (strcasecmp(cmd_name
, "tapisenabled") == 0) {
764 /* do nothing, just return the value */
765 } else if (strcasecmp(cmd_name
, "tapenable") == 0) {
766 if (!jtag_tap_enable(t
)) {
767 LOG_WARNING("failed to enable tap %s", t
->dotted_name
);
770 } else if (strcasecmp(cmd_name
, "tapdisable") == 0) {
771 if (!jtag_tap_disable(t
)) {
772 LOG_WARNING("failed to disable tap %s", t
->dotted_name
);
776 LOG_ERROR("command '%s' unknown", cmd_name
);
780 Jim_SetResult(goi
.interp
, Jim_NewIntObj(goi
.interp
, e
));
784 int jim_jtag_configure(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
786 struct command
*c
= jim_to_command(interp
);
787 const char *cmd_name
= c
->name
;
788 struct jim_getopt_info goi
;
789 jim_getopt_setup(&goi
, interp
, argc
-1, argv
+ 1);
790 goi
.isconfigure
= !strcmp(cmd_name
, "configure");
791 if (goi
.argc
< 2 + goi
.isconfigure
) {
792 Jim_WrongNumArgs(goi
.interp
, 0, NULL
,
793 "<tap_name> <attribute> ...");
800 jim_getopt_obj(&goi
, &o
);
801 t
= jtag_tap_by_jim_obj(goi
.interp
, o
);
805 return jtag_tap_configure_cmd(&goi
, t
);
808 static int jim_jtag_names(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
810 struct jim_getopt_info goi
;
811 jim_getopt_setup(&goi
, interp
, argc
-1, argv
+ 1);
813 Jim_WrongNumArgs(goi
.interp
, 1, goi
.argv
, "Too many parameters");
816 Jim_SetResult(goi
.interp
, Jim_NewListObj(goi
.interp
, NULL
, 0));
817 struct jtag_tap
*tap
;
819 for (tap
= jtag_all_taps(); tap
; tap
= tap
->next_tap
) {
820 Jim_ListAppendElement(goi
.interp
,
821 Jim_GetResult(goi
.interp
),
822 Jim_NewStringObj(goi
.interp
,
823 tap
->dotted_name
, -1));
828 COMMAND_HANDLER(handle_jtag_init_command
)
831 return ERROR_COMMAND_SYNTAX_ERROR
;
833 static bool jtag_initialized
;
834 if (jtag_initialized
) {
835 LOG_INFO("'jtag init' has already been called");
838 jtag_initialized
= true;
840 LOG_DEBUG("Initializing jtag devices...");
841 return jtag_init(CMD_CTX
);
844 static const struct command_registration jtag_subcommand_handlers
[] = {
848 .handler
= handle_jtag_init_command
,
849 .help
= "initialize jtag scan chain",
855 .jim_handler
= jim_jtag_arp_init
,
856 .help
= "Validates JTAG scan chain against the list of "
857 "declared TAPs using just the four standard JTAG "
861 .name
= "arp_init-reset",
863 .jim_handler
= jim_jtag_arp_init_reset
,
864 .help
= "Uses TRST and SRST to try resetting everything on "
865 "the JTAG scan chain, then performs 'jtag arp_init'."
869 .mode
= COMMAND_CONFIG
,
870 .jim_handler
= jim_jtag_newtap
,
871 .help
= "Create a new TAP instance named basename.tap_type, "
872 "and appends it to the scan chain.",
873 .usage
= "basename tap_type '-irlen' count "
874 "['-enable'|'-disable'] "
875 "['-expected_id' number] "
876 "['-ignore-version'] "
877 "['-ignore-bypass'] "
878 "['-ircapture' number] "
882 .name
= "tapisenabled",
883 .mode
= COMMAND_EXEC
,
884 .jim_handler
= jim_jtag_tap_enabler
,
885 .help
= "Returns a Tcl boolean (0/1) indicating whether "
886 "the TAP is enabled (1) or not (0).",
891 .mode
= COMMAND_EXEC
,
892 .jim_handler
= jim_jtag_tap_enabler
,
893 .help
= "Try to enable the specified TAP using the "
894 "'tap-enable' TAP event.",
898 .name
= "tapdisable",
899 .mode
= COMMAND_EXEC
,
900 .jim_handler
= jim_jtag_tap_enabler
,
901 .help
= "Try to disable the specified TAP using the "
902 "'tap-disable' TAP event.",
908 .jim_handler
= jim_jtag_configure
,
909 .help
= "Provide a Tcl handler for the specified "
911 .usage
= "tap_name '-event' event_name handler",
915 .mode
= COMMAND_EXEC
,
916 .jim_handler
= jim_jtag_configure
,
917 .help
= "Return any Tcl handler for the specified "
919 .usage
= "tap_name '-event' event_name",
924 .jim_handler
= jim_jtag_names
,
925 .help
= "Returns list of all JTAG tap names.",
928 .chain
= jtag_command_handlers_to_move
,
930 COMMAND_REGISTRATION_DONE
933 void jtag_notify_event(enum jtag_event event
)
935 struct jtag_tap
*tap
;
937 for (tap
= jtag_all_taps(); tap
; tap
= tap
->next_tap
)
938 jtag_tap_handle_event(tap
, event
);
942 COMMAND_HANDLER(handle_scan_chain_command
)
944 struct jtag_tap
*tap
;
945 char expected_id
[12];
947 tap
= jtag_all_taps();
949 " TapName Enabled IdCode Expected IrLen IrCap IrMask");
951 "-- ------------------- -------- ---------- ---------- ----- ----- ------");
954 uint32_t expected
, expected_mask
, ii
;
956 snprintf(expected_id
, sizeof(expected_id
), "0x%08x",
957 (unsigned)((tap
->expected_ids_cnt
> 0)
958 ? tap
->expected_ids
[0]
960 if (tap
->ignore_version
)
961 expected_id
[2] = '*';
963 expected
= buf_get_u32(tap
->expected
, 0, tap
->ir_length
);
964 expected_mask
= buf_get_u32(tap
->expected_mask
, 0, tap
->ir_length
);
967 "%2d %-18s %c 0x%08x %s %5d 0x%02x 0x%02x",
968 tap
->abs_chain_position
,
970 tap
->enabled
? 'Y' : 'n',
971 (unsigned int)(tap
->idcode
),
973 (unsigned int)(tap
->ir_length
),
974 (unsigned int)(expected
),
975 (unsigned int)(expected_mask
));
977 for (ii
= 1; ii
< tap
->expected_ids_cnt
; ii
++) {
978 snprintf(expected_id
, sizeof(expected_id
), "0x%08x",
979 (unsigned) tap
->expected_ids
[ii
]);
980 if (tap
->ignore_version
)
981 expected_id
[2] = '*';
994 COMMAND_HANDLER(handle_jtag_ntrst_delay_command
)
997 return ERROR_COMMAND_SYNTAX_ERROR
;
1000 COMMAND_PARSE_NUMBER(uint
, CMD_ARGV
[0], delay
);
1002 jtag_set_ntrst_delay(delay
);
1004 command_print(CMD
, "jtag_ntrst_delay: %u", jtag_get_ntrst_delay());
1008 COMMAND_HANDLER(handle_jtag_ntrst_assert_width_command
)
1011 return ERROR_COMMAND_SYNTAX_ERROR
;
1012 if (CMD_ARGC
== 1) {
1014 COMMAND_PARSE_NUMBER(uint
, CMD_ARGV
[0], delay
);
1016 jtag_set_ntrst_assert_width(delay
);
1018 command_print(CMD
, "jtag_ntrst_assert_width: %u", jtag_get_ntrst_assert_width());
1022 COMMAND_HANDLER(handle_jtag_rclk_command
)
1025 return ERROR_COMMAND_SYNTAX_ERROR
;
1027 int retval
= ERROR_OK
;
1028 if (CMD_ARGC
== 1) {
1030 COMMAND_PARSE_NUMBER(uint
, CMD_ARGV
[0], khz
);
1032 retval
= adapter_config_rclk(khz
);
1033 if (retval
!= ERROR_OK
)
1037 int cur_khz
= adapter_get_speed_khz();
1038 retval
= adapter_get_speed_readable(&cur_khz
);
1039 if (retval
!= ERROR_OK
)
1043 command_print(CMD
, "RCLK not supported - fallback to %d kHz", cur_khz
);
1045 command_print(CMD
, "RCLK - adaptive");
1050 COMMAND_HANDLER(handle_runtest_command
)
1053 return ERROR_COMMAND_SYNTAX_ERROR
;
1055 unsigned num_clocks
;
1056 COMMAND_PARSE_NUMBER(uint
, CMD_ARGV
[0], num_clocks
);
1058 jtag_add_runtest(num_clocks
, TAP_IDLE
);
1059 return jtag_execute_queue();
1063 * For "irscan" or "drscan" commands, the "end" (really, "next") state
1064 * should be stable ... and *NOT* a shift state, otherwise free-running
1065 * jtag clocks could change the values latched by the update state.
1066 * Not surprisingly, this is the same constraint as SVF; the "irscan"
1067 * and "drscan" commands are a write-only subset of what SVF provides.
1070 COMMAND_HANDLER(handle_irscan_command
)
1073 struct scan_field
*fields
;
1074 struct jtag_tap
*tap
= NULL
;
1075 tap_state_t endstate
;
1077 if ((CMD_ARGC
< 2) || (CMD_ARGC
% 2))
1078 return ERROR_COMMAND_SYNTAX_ERROR
;
1080 /* optional "-endstate" "statename" at the end of the arguments,
1081 * so that e.g. IRPAUSE can let us load the data register before
1082 * entering RUN/IDLE to execute the instruction we load here.
1084 endstate
= TAP_IDLE
;
1086 if (CMD_ARGC
>= 4) {
1087 /* have at least one pair of numbers.
1088 * is last pair the magic text? */
1089 if (strcmp("-endstate", CMD_ARGV
[CMD_ARGC
- 2]) == 0) {
1090 endstate
= tap_state_by_name(CMD_ARGV
[CMD_ARGC
- 1]);
1091 if (endstate
== TAP_INVALID
)
1092 return ERROR_COMMAND_SYNTAX_ERROR
;
1093 if (!scan_is_safe(endstate
))
1094 LOG_WARNING("unstable irscan endstate \"%s\"",
1095 CMD_ARGV
[CMD_ARGC
- 1]);
1100 int num_fields
= CMD_ARGC
/ 2;
1101 if (num_fields
> 1) {
1102 /* we really should be looking at plain_ir_scan if we want
1103 * anything more fancy.
1105 LOG_ERROR("Specify a single value for tap");
1106 return ERROR_COMMAND_SYNTAX_ERROR
;
1109 fields
= calloc(num_fields
, sizeof(*fields
));
1112 for (i
= 0; i
< num_fields
; i
++) {
1113 tap
= jtag_tap_by_string(CMD_ARGV
[i
*2]);
1116 command_print(CMD
, "Tap: %s unknown", CMD_ARGV
[i
*2]);
1121 retval
= parse_u64(CMD_ARGV
[i
* 2 + 1], &value
);
1122 if (retval
!= ERROR_OK
)
1125 int field_size
= tap
->ir_length
;
1126 fields
[i
].num_bits
= field_size
;
1127 uint8_t *v
= calloc(1, DIV_ROUND_UP(field_size
, 8));
1129 LOG_ERROR("Out of memory");
1133 buf_set_u64(v
, 0, field_size
, value
);
1134 fields
[i
].out_value
= v
;
1135 fields
[i
].in_value
= NULL
;
1138 /* did we have an endstate? */
1139 jtag_add_ir_scan(tap
, fields
, endstate
);
1141 retval
= jtag_execute_queue();
1144 for (i
= 0; i
< num_fields
; i
++)
1145 free((void *)fields
[i
].out_value
);
1152 COMMAND_HANDLER(handle_verify_ircapture_command
)
1155 return ERROR_COMMAND_SYNTAX_ERROR
;
1157 if (CMD_ARGC
== 1) {
1159 COMMAND_PARSE_ENABLE(CMD_ARGV
[0], enable
);
1160 jtag_set_verify_capture_ir(enable
);
1163 const char *status
= jtag_will_verify_capture_ir() ? "enabled" : "disabled";
1164 command_print(CMD
, "verify Capture-IR is %s", status
);
1169 COMMAND_HANDLER(handle_verify_jtag_command
)
1172 return ERROR_COMMAND_SYNTAX_ERROR
;
1174 if (CMD_ARGC
== 1) {
1176 COMMAND_PARSE_ENABLE(CMD_ARGV
[0], enable
);
1177 jtag_set_verify(enable
);
1180 const char *status
= jtag_will_verify() ? "enabled" : "disabled";
1181 command_print(CMD
, "verify jtag capture is %s", status
);
1186 COMMAND_HANDLER(handle_tms_sequence_command
)
1189 return ERROR_COMMAND_SYNTAX_ERROR
;
1191 if (CMD_ARGC
== 1) {
1193 if (strcmp(CMD_ARGV
[0], "short") == 0)
1194 use_new_table
= true;
1195 else if (strcmp(CMD_ARGV
[0], "long") == 0)
1196 use_new_table
= false;
1198 return ERROR_COMMAND_SYNTAX_ERROR
;
1200 tap_use_new_tms_table(use_new_table
);
1203 command_print(CMD
, "tms sequence is %s",
1204 tap_uses_new_tms_table() ? "short" : "long");
1209 COMMAND_HANDLER(handle_jtag_flush_queue_sleep
)
1212 return ERROR_COMMAND_SYNTAX_ERROR
;
1215 COMMAND_PARSE_NUMBER(int, CMD_ARGV
[0], sleep_ms
);
1217 jtag_set_flush_queue_sleep(sleep_ms
);
1222 COMMAND_HANDLER(handle_wait_srst_deassert
)
1225 return ERROR_COMMAND_SYNTAX_ERROR
;
1228 COMMAND_PARSE_NUMBER(int, CMD_ARGV
[0], timeout_ms
);
1229 if ((timeout_ms
<= 0) || (timeout_ms
> 100000)) {
1230 LOG_ERROR("Timeout must be an integer between 0 and 100000");
1234 LOG_USER("Waiting for srst assert + deassert for at most %dms", timeout_ms
);
1236 int64_t then
= timeval_ms();
1237 while (jtag_srst_asserted(&asserted_yet
) == ERROR_OK
) {
1238 if ((timeval_ms() - then
) > timeout_ms
) {
1239 LOG_ERROR("Timed out");
1245 while (jtag_srst_asserted(&asserted_yet
) == ERROR_OK
) {
1246 if ((timeval_ms() - then
) > timeout_ms
) {
1247 LOG_ERROR("Timed out");
1257 static const struct command_registration jtag_command_handlers
[] = {
1260 .name
= "jtag_flush_queue_sleep",
1261 .handler
= handle_jtag_flush_queue_sleep
,
1262 .mode
= COMMAND_ANY
,
1263 .help
= "For debug purposes(simulate long delays of interface) "
1264 "to test performance or change in behavior. Default 0ms.",
1265 .usage
= "[sleep in ms]",
1268 .name
= "jtag_rclk",
1269 .handler
= handle_jtag_rclk_command
,
1270 .mode
= COMMAND_ANY
,
1271 .help
= "With an argument, change to to use adaptive clocking "
1272 "if possible; else to use the fallback speed. "
1273 "With or without argument, display current setting.",
1274 .usage
= "[fallback_speed_khz]",
1277 .name
= "jtag_ntrst_delay",
1278 .handler
= handle_jtag_ntrst_delay_command
,
1279 .mode
= COMMAND_ANY
,
1280 .help
= "delay after deasserting trst in ms",
1281 .usage
= "[milliseconds]",
1284 .name
= "jtag_ntrst_assert_width",
1285 .handler
= handle_jtag_ntrst_assert_width_command
,
1286 .mode
= COMMAND_ANY
,
1287 .help
= "delay after asserting trst in ms",
1288 .usage
= "[milliseconds]",
1291 .name
= "scan_chain",
1292 .handler
= handle_scan_chain_command
,
1293 .mode
= COMMAND_ANY
,
1294 .help
= "print current scan chain configuration",
1299 .handler
= handle_runtest_command
,
1300 .mode
= COMMAND_EXEC
,
1301 .help
= "Move to Run-Test/Idle, and issue TCK for num_cycles.",
1302 .usage
= "num_cycles"
1306 .handler
= handle_irscan_command
,
1307 .mode
= COMMAND_EXEC
,
1308 .help
= "Execute Instruction Register (IR) scan. The "
1309 "specified opcodes are put into each TAP's IR, "
1310 "and other TAPs are put in BYPASS.",
1311 .usage
= "[tap_name instruction]* ['-endstate' state_name]",
1314 .name
= "verify_ircapture",
1315 .handler
= handle_verify_ircapture_command
,
1316 .mode
= COMMAND_ANY
,
1317 .help
= "Display or assign flag controlling whether to "
1318 "verify values captured during Capture-IR.",
1319 .usage
= "['enable'|'disable']",
1322 .name
= "verify_jtag",
1323 .handler
= handle_verify_jtag_command
,
1324 .mode
= COMMAND_ANY
,
1325 .help
= "Display or assign flag controlling whether to "
1326 "verify values captured during IR and DR scans.",
1327 .usage
= "['enable'|'disable']",
1330 .name
= "tms_sequence",
1331 .handler
= handle_tms_sequence_command
,
1332 .mode
= COMMAND_ANY
,
1333 .help
= "Display or change what style TMS sequences to use "
1334 "for JTAG state transitions: short (default) or "
1335 "long. Only for working around JTAG bugs.",
1336 /* Specifically for working around DRIVER bugs... */
1337 .usage
= "['short'|'long']",
1340 .name
= "wait_srst_deassert",
1341 .handler
= handle_wait_srst_deassert
,
1342 .mode
= COMMAND_ANY
,
1343 .help
= "Wait for an SRST deassert. "
1344 "Useful for cases where you need something to happen within ms "
1345 "of an srst deassert. Timeout in ms",
1350 .mode
= COMMAND_ANY
,
1351 .help
= "perform jtag tap actions",
1354 .chain
= jtag_subcommand_handlers
,
1357 .chain
= jtag_command_handlers_to_move
,
1359 COMMAND_REGISTRATION_DONE
1362 int jtag_register_commands(struct command_context
*cmd_ctx
)
1364 return register_commands(cmd_ctx
, NULL
, jtag_command_handlers
);
Linking to existing account procedure
If you already have an account and want to add another login method
you
MUST first sign in with your existing account and
then change URL to read
https://review.openocd.org/login/?link
to get to this page again but this time it'll work for linking. Thank you.
SSH host keys fingerprints
1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=.. |
|+o.. . |
|*.o . . |
|+B . . . |
|Bo. = o S |
|Oo.+ + = |
|oB=.* = . o |
| =+=.+ + E |
|. .=o . o |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)