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 COMMAND_HELPER(handle_jtag_command_drscan_fields
, struct scan_field
*fields
)
77 unsigned int field_count
= 0;
78 for (unsigned int i
= 1; i
< CMD_ARGC
; i
+= 2) {
80 COMMAND_PARSE_NUMBER(uint
, CMD_ARGV
[i
], bits
);
81 fields
[field_count
].num_bits
= bits
;
83 void *t
= malloc(DIV_ROUND_UP(bits
, 8));
85 LOG_ERROR("Out of memory");
88 fields
[field_count
].out_value
= t
;
89 str_to_buf(CMD_ARGV
[i
+ 1], strlen(CMD_ARGV
[i
+ 1]), t
, bits
, 0);
90 fields
[field_count
].in_value
= t
;
97 COMMAND_HANDLER(handle_jtag_command_drscan
)
100 * CMD_ARGV[0] = device
101 * CMD_ARGV[1] = num_bits
102 * CMD_ARGV[2] = hex string
103 * ... repeat num bits and hex string ...
106 * CMD_ARGV[CMD_ARGC-2] = "-endstate"
107 * CMD_ARGV[CMD_ARGC-1] = statename
110 if (CMD_ARGC
< 3 || (CMD_ARGC
% 2) != 1)
111 return ERROR_COMMAND_SYNTAX_ERROR
;
113 struct jtag_tap
*tap
= jtag_tap_by_string(CMD_ARGV
[0]);
115 command_print(CMD
, "Tap '%s' could not be found", CMD_ARGV
[0]);
116 return ERROR_COMMAND_ARGUMENT_INVALID
;
120 command_print(CMD
, "Can't execute as the selected tap is in BYPASS");
124 tap_state_t endstate
= TAP_IDLE
;
125 if (CMD_ARGC
> 3 && !strcmp("-endstate", CMD_ARGV
[CMD_ARGC
- 2])) {
126 const char *state_name
= CMD_ARGV
[CMD_ARGC
- 1];
127 endstate
= tap_state_by_name(state_name
);
129 command_print(CMD
, "endstate: %s invalid", state_name
);
130 return ERROR_COMMAND_ARGUMENT_INVALID
;
133 if (!scan_is_safe(endstate
))
134 LOG_WARNING("drscan with unsafe endstate \"%s\"", state_name
);
139 unsigned int num_fields
= (CMD_ARGC
- 1) / 2;
140 struct scan_field
*fields
= calloc(num_fields
, sizeof(struct scan_field
));
142 LOG_ERROR("Out of memory");
146 int retval
= CALL_COMMAND_HANDLER(handle_jtag_command_drscan_fields
, fields
);
147 if (retval
!= ERROR_OK
)
150 jtag_add_dr_scan(tap
, num_fields
, fields
, endstate
);
152 retval
= jtag_execute_queue();
153 if (retval
!= ERROR_OK
) {
154 command_print(CMD
, "drscan: jtag execute failed");
158 for (unsigned int i
= 0; i
< num_fields
; i
++) {
159 char *str
= buf_to_hex_str(fields
[i
].in_value
, fields
[i
].num_bits
);
160 command_print(CMD
, "%s", str
);
165 for (unsigned int i
= 0; i
< num_fields
; i
++)
166 free(fields
[i
].in_value
);
172 COMMAND_HANDLER(handle_jtag_command_pathmove
)
174 tap_state_t states
[8];
176 if (CMD_ARGC
< 1 || CMD_ARGC
> ARRAY_SIZE(states
))
177 return ERROR_COMMAND_SYNTAX_ERROR
;
179 for (unsigned int i
= 0; i
< CMD_ARGC
; i
++) {
180 states
[i
] = tap_state_by_name(CMD_ARGV
[i
]);
182 command_print(CMD
, "endstate: %s invalid", CMD_ARGV
[i
]);
183 return ERROR_COMMAND_ARGUMENT_INVALID
;
187 int retval
= jtag_add_statemove(states
[0]);
188 if (retval
== ERROR_OK
)
189 retval
= jtag_execute_queue();
190 if (retval
!= ERROR_OK
) {
191 command_print(CMD
, "pathmove: jtag execute failed");
195 jtag_add_pathmove(CMD_ARGC
- 1, states
+ 1);
196 retval
= jtag_execute_queue();
197 if (retval
!= ERROR_OK
) {
198 command_print(CMD
, "pathmove: failed");
205 COMMAND_HANDLER(handle_jtag_flush_count
)
208 return ERROR_COMMAND_SYNTAX_ERROR
;
210 int count
= jtag_get_flush_queue_count();
211 command_print_sameline(CMD
, "%d", count
);
216 /* REVISIT Just what about these should "move" ... ?
217 * These registrations, into the main JTAG table?
219 * There's a minor compatibility issue, these all show up twice;
220 * that's not desirable:
221 * - jtag drscan ... NOT DOCUMENTED!
224 * The "irscan" command (for example) doesn't show twice.
226 static const struct command_registration jtag_command_handlers_to_move
[] = {
229 .mode
= COMMAND_EXEC
,
230 .handler
= handle_jtag_command_drscan
,
231 .help
= "Execute Data Register (DR) scan for one TAP. "
232 "Other TAPs must be in BYPASS mode.",
233 .usage
= "tap_name (num_bits value)+ ['-endstate' state_name]",
236 .name
= "flush_count",
237 .mode
= COMMAND_EXEC
,
238 .handler
= handle_jtag_flush_count
,
239 .help
= "Returns the number of times the JTAG queue "
245 .mode
= COMMAND_EXEC
,
246 .handler
= handle_jtag_command_pathmove
,
247 .usage
= "start_state state1 [state2 [state3 ...]]",
248 .help
= "Move JTAG state machine from current state "
249 "(start_state) to state1, then state2, state3, etc.",
251 COMMAND_REGISTRATION_DONE
255 enum jtag_tap_cfg_param
{
260 static struct jim_nvp nvp_config_opts
[] = {
261 { .name
= "-event", .value
= JCFG_EVENT
},
262 { .name
= "-idcode", .value
= JCFG_IDCODE
},
264 { .name
= NULL
, .value
= -1 }
267 static int jtag_tap_configure_event(struct jim_getopt_info
*goi
, struct jtag_tap
*tap
)
269 if (goi
->argc
== 0) {
270 Jim_WrongNumArgs(goi
->interp
, goi
->argc
, goi
->argv
, "-event <event-name> ...");
275 int e
= jim_getopt_nvp(goi
, nvp_jtag_tap_event
, &n
);
277 jim_getopt_nvp_unknown(goi
, nvp_jtag_tap_event
, 1);
281 if (goi
->isconfigure
) {
282 if (goi
->argc
!= 1) {
283 Jim_WrongNumArgs(goi
->interp
,
286 "-event <event-name> <event-body>");
290 if (goi
->argc
!= 0) {
291 Jim_WrongNumArgs(goi
->interp
, goi
->argc
, goi
->argv
, "-event <event-name>");
296 struct jtag_tap_event_action
*jteap
= tap
->event_action
;
297 /* replace existing event body */
300 if (jteap
->event
== (enum jtag_event
)n
->value
) {
307 Jim_SetEmptyResult(goi
->interp
);
309 if (goi
->isconfigure
) {
311 jteap
= calloc(1, sizeof(*jteap
));
312 else if (jteap
->body
)
313 Jim_DecrRefCount(goi
->interp
, jteap
->body
);
315 jteap
->interp
= goi
->interp
;
316 jteap
->event
= n
->value
;
319 jim_getopt_obj(goi
, &o
);
320 jteap
->body
= Jim_DuplicateObj(goi
->interp
, o
);
321 Jim_IncrRefCount(jteap
->body
);
324 /* add to head of event list */
325 jteap
->next
= tap
->event_action
;
326 tap
->event_action
= jteap
;
329 jteap
->interp
= goi
->interp
;
330 Jim_SetResult(goi
->interp
,
331 Jim_DuplicateObj(goi
->interp
, jteap
->body
));
336 static int jtag_tap_configure_cmd(struct jim_getopt_info
*goi
, struct jtag_tap
*tap
)
338 /* parse config or cget options */
339 while (goi
->argc
> 0) {
340 Jim_SetEmptyResult(goi
->interp
);
343 int e
= jim_getopt_nvp(goi
, nvp_config_opts
, &n
);
345 jim_getopt_nvp_unknown(goi
, nvp_config_opts
, 0);
351 e
= jtag_tap_configure_event(goi
, tap
);
356 if (goi
->isconfigure
) {
357 Jim_SetResultFormatted(goi
->interp
,
358 "not settable: %s", n
->name
);
361 if (goi
->argc
!= 0) {
362 Jim_WrongNumArgs(goi
->interp
,
363 goi
->argc
, goi
->argv
,
368 Jim_SetResult(goi
->interp
, Jim_NewIntObj(goi
->interp
, tap
->idcode
));
371 Jim_SetResultFormatted(goi
->interp
, "unknown value: %s", n
->name
);
379 static int is_bad_irval(int ir_length
, jim_wide w
)
389 static int jim_newtap_expected_id(struct jim_nvp
*n
, struct jim_getopt_info
*goi
,
390 struct jtag_tap
*tap
)
393 int e
= jim_getopt_wide(goi
, &w
);
395 Jim_SetResultFormatted(goi
->interp
, "option: %s bad parameter", n
->name
);
399 uint32_t *p
= realloc(tap
->expected_ids
,
400 (tap
->expected_ids_cnt
+ 1) * sizeof(uint32_t));
402 Jim_SetResultFormatted(goi
->interp
, "no memory");
406 tap
->expected_ids
= p
;
407 tap
->expected_ids
[tap
->expected_ids_cnt
++] = w
;
412 #define NTAP_OPT_IRLEN 0
413 #define NTAP_OPT_IRMASK 1
414 #define NTAP_OPT_IRCAPTURE 2
415 #define NTAP_OPT_ENABLED 3
416 #define NTAP_OPT_DISABLED 4
417 #define NTAP_OPT_EXPECTED_ID 5
418 #define NTAP_OPT_VERSION 6
419 #define NTAP_OPT_BYPASS 7
421 static int jim_newtap_ir_param(struct jim_nvp
*n
, struct jim_getopt_info
*goi
,
422 struct jtag_tap
*tap
)
425 int e
= jim_getopt_wide(goi
, &w
);
427 Jim_SetResultFormatted(goi
->interp
,
428 "option: %s bad parameter", n
->name
);
433 if (w
> (jim_wide
) (8 * sizeof(tap
->ir_capture_value
))) {
434 LOG_WARNING("%s: huge IR length %d",
435 tap
->dotted_name
, (int) w
);
439 case NTAP_OPT_IRMASK
:
440 if (is_bad_irval(tap
->ir_length
, w
)) {
441 LOG_ERROR("%s: IR mask %x too big",
447 LOG_WARNING("%s: nonstandard IR mask", tap
->dotted_name
);
448 tap
->ir_capture_mask
= w
;
450 case NTAP_OPT_IRCAPTURE
:
451 if (is_bad_irval(tap
->ir_length
, w
)) {
452 LOG_ERROR("%s: IR capture %x too big",
453 tap
->dotted_name
, (int) w
);
457 LOG_WARNING("%s: nonstandard IR value",
459 tap
->ir_capture_value
= w
;
467 static int jim_newtap_cmd(struct jim_getopt_info
*goi
)
469 struct jtag_tap
*tap
;
474 const struct jim_nvp opts
[] = {
475 { .name
= "-irlen", .value
= NTAP_OPT_IRLEN
},
476 { .name
= "-irmask", .value
= NTAP_OPT_IRMASK
},
477 { .name
= "-ircapture", .value
= NTAP_OPT_IRCAPTURE
},
478 { .name
= "-enable", .value
= NTAP_OPT_ENABLED
},
479 { .name
= "-disable", .value
= NTAP_OPT_DISABLED
},
480 { .name
= "-expected-id", .value
= NTAP_OPT_EXPECTED_ID
},
481 { .name
= "-ignore-version", .value
= NTAP_OPT_VERSION
},
482 { .name
= "-ignore-bypass", .value
= NTAP_OPT_BYPASS
},
483 { .name
= NULL
, .value
= -1 },
486 tap
= calloc(1, sizeof(struct jtag_tap
));
488 Jim_SetResultFormatted(goi
->interp
, "no memory");
493 * we expect CHIP + TAP + OPTIONS
496 Jim_SetResultFormatted(goi
->interp
, "Missing CHIP TAP OPTIONS ....");
502 jim_getopt_string(goi
, &tmp
, NULL
);
503 tap
->chip
= strdup(tmp
);
505 jim_getopt_string(goi
, &tmp
, NULL
);
506 tap
->tapname
= strdup(tmp
);
508 /* name + dot + name + null */
509 x
= strlen(tap
->chip
) + 1 + strlen(tap
->tapname
) + 1;
511 sprintf(cp
, "%s.%s", tap
->chip
, tap
->tapname
);
512 tap
->dotted_name
= cp
;
514 LOG_DEBUG("Creating New Tap, Chip: %s, Tap: %s, Dotted: %s, %d params",
515 tap
->chip
, tap
->tapname
, tap
->dotted_name
, goi
->argc
);
517 /* IEEE specifies that the two LSBs of an IR scan are 01, so make
518 * that the default. The "-ircapture" and "-irmask" options are only
519 * needed to cope with nonstandard TAPs, or to specify more bits.
521 tap
->ir_capture_mask
= 0x03;
522 tap
->ir_capture_value
= 0x01;
525 e
= jim_getopt_nvp(goi
, opts
, &n
);
527 jim_getopt_nvp_unknown(goi
, opts
, 0);
532 LOG_DEBUG("Processing option: %s", n
->name
);
534 case NTAP_OPT_ENABLED
:
535 tap
->disabled_after_reset
= false;
537 case NTAP_OPT_DISABLED
:
538 tap
->disabled_after_reset
= true;
540 case NTAP_OPT_EXPECTED_ID
:
541 e
= jim_newtap_expected_id(n
, goi
, tap
);
549 case NTAP_OPT_IRMASK
:
550 case NTAP_OPT_IRCAPTURE
:
551 e
= jim_newtap_ir_param(n
, goi
, tap
);
558 case NTAP_OPT_VERSION
:
559 tap
->ignore_version
= true;
561 case NTAP_OPT_BYPASS
:
562 tap
->ignore_bypass
= true;
564 } /* switch (n->value) */
565 } /* while (goi->argc) */
567 /* default is enabled-after-reset */
568 tap
->enabled
= !tap
->disabled_after_reset
;
570 /* Did all the required option bits get cleared? */
571 if (!transport_is_jtag() || tap
->ir_length
!= 0) {
576 Jim_SetResultFormatted(goi
->interp
,
577 "newtap: %s missing IR length",
583 static void jtag_tap_handle_event(struct jtag_tap
*tap
, enum jtag_event e
)
585 struct jtag_tap_event_action
*jteap
;
588 for (jteap
= tap
->event_action
; jteap
; jteap
= jteap
->next
) {
589 if (jteap
->event
!= e
)
592 struct jim_nvp
*nvp
= jim_nvp_value2name_simple(nvp_jtag_tap_event
, e
);
593 LOG_DEBUG("JTAG tap: %s event: %d (%s)\n\taction: %s",
594 tap
->dotted_name
, e
, nvp
->name
,
595 Jim_GetString(jteap
->body
, NULL
));
597 retval
= Jim_EvalObj(jteap
->interp
, jteap
->body
);
598 if (retval
== JIM_RETURN
)
599 retval
= jteap
->interp
->returnCode
;
601 if (retval
!= JIM_OK
) {
602 Jim_MakeErrorMessage(jteap
->interp
);
603 LOG_USER("%s", Jim_GetString(Jim_GetResult(jteap
->interp
), NULL
));
608 case JTAG_TAP_EVENT_ENABLE
:
609 case JTAG_TAP_EVENT_DISABLE
:
610 /* NOTE: we currently assume the handlers
611 * can't fail. Right here is where we should
612 * really be verifying the scan chains ...
614 tap
->enabled
= (e
== JTAG_TAP_EVENT_ENABLE
);
615 LOG_INFO("JTAG tap: %s %s", tap
->dotted_name
,
616 tap
->enabled
? "enabled" : "disabled");
624 COMMAND_HANDLER(handle_jtag_arp_init
)
627 return ERROR_COMMAND_SYNTAX_ERROR
;
629 return jtag_init_inner(CMD_CTX
);
632 COMMAND_HANDLER(handle_jtag_arp_init_reset
)
635 return ERROR_COMMAND_SYNTAX_ERROR
;
637 if (transport_is_jtag())
638 return jtag_init_reset(CMD_CTX
);
640 if (transport_is_swd())
641 return swd_init_reset(CMD_CTX
);
646 int jim_jtag_newtap(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
648 struct jim_getopt_info goi
;
649 jim_getopt_setup(&goi
, interp
, argc
-1, argv
+ 1);
650 return jim_newtap_cmd(&goi
);
653 static bool jtag_tap_enable(struct jtag_tap
*t
)
657 jtag_tap_handle_event(t
, JTAG_TAP_EVENT_ENABLE
);
661 /* FIXME add JTAG sanity checks, w/o TLR
662 * - scan chain length grew by one (this)
663 * - IDs and IR lengths are as expected
665 jtag_call_event_callbacks(JTAG_TAP_EVENT_ENABLE
);
668 static bool jtag_tap_disable(struct jtag_tap
*t
)
672 jtag_tap_handle_event(t
, JTAG_TAP_EVENT_DISABLE
);
676 /* FIXME add JTAG sanity checks, w/o TLR
677 * - scan chain length shrank by one (this)
678 * - IDs and IR lengths are as expected
680 jtag_call_event_callbacks(JTAG_TAP_EVENT_DISABLE
);
684 int jim_jtag_tap_enabler(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
686 struct command
*c
= jim_to_command(interp
);
687 const char *cmd_name
= c
->name
;
688 struct jim_getopt_info goi
;
689 jim_getopt_setup(&goi
, interp
, argc
-1, argv
+ 1);
691 Jim_SetResultFormatted(goi
.interp
, "usage: %s <name>", cmd_name
);
697 t
= jtag_tap_by_jim_obj(goi
.interp
, goi
.argv
[0]);
701 if (strcasecmp(cmd_name
, "tapisenabled") == 0) {
702 /* do nothing, just return the value */
703 } else if (strcasecmp(cmd_name
, "tapenable") == 0) {
704 if (!jtag_tap_enable(t
)) {
705 LOG_WARNING("failed to enable tap %s", t
->dotted_name
);
708 } else if (strcasecmp(cmd_name
, "tapdisable") == 0) {
709 if (!jtag_tap_disable(t
)) {
710 LOG_WARNING("failed to disable tap %s", t
->dotted_name
);
714 LOG_ERROR("command '%s' unknown", cmd_name
);
718 Jim_SetResult(goi
.interp
, Jim_NewIntObj(goi
.interp
, e
));
722 int jim_jtag_configure(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
724 struct command
*c
= jim_to_command(interp
);
725 const char *cmd_name
= c
->name
;
726 struct jim_getopt_info goi
;
727 jim_getopt_setup(&goi
, interp
, argc
-1, argv
+ 1);
728 goi
.isconfigure
= !strcmp(cmd_name
, "configure");
729 if (goi
.argc
< 2 + goi
.isconfigure
) {
730 Jim_WrongNumArgs(goi
.interp
, 0, NULL
,
731 "<tap_name> <attribute> ...");
738 jim_getopt_obj(&goi
, &o
);
739 t
= jtag_tap_by_jim_obj(goi
.interp
, o
);
743 return jtag_tap_configure_cmd(&goi
, t
);
746 COMMAND_HANDLER(handle_jtag_names
)
749 return ERROR_COMMAND_SYNTAX_ERROR
;
751 for (struct jtag_tap
*tap
= jtag_all_taps(); tap
; tap
= tap
->next_tap
)
752 command_print(CMD
, "%s", tap
->dotted_name
);
757 COMMAND_HANDLER(handle_jtag_init_command
)
760 return ERROR_COMMAND_SYNTAX_ERROR
;
762 static bool jtag_initialized
;
763 if (jtag_initialized
) {
764 LOG_INFO("'jtag init' has already been called");
767 jtag_initialized
= true;
769 LOG_DEBUG("Initializing jtag devices...");
770 return jtag_init(CMD_CTX
);
773 static const struct command_registration jtag_subcommand_handlers
[] = {
777 .handler
= handle_jtag_init_command
,
778 .help
= "initialize jtag scan chain",
784 .handler
= handle_jtag_arp_init
,
785 .help
= "Validates JTAG scan chain against the list of "
786 "declared TAPs using just the four standard JTAG "
791 .name
= "arp_init-reset",
793 .handler
= handle_jtag_arp_init_reset
,
794 .help
= "Uses TRST and SRST to try resetting everything on "
795 "the JTAG scan chain, then performs 'jtag arp_init'.",
800 .mode
= COMMAND_CONFIG
,
801 .jim_handler
= jim_jtag_newtap
,
802 .help
= "Create a new TAP instance named basename.tap_type, "
803 "and appends it to the scan chain.",
804 .usage
= "basename tap_type '-irlen' count "
805 "['-enable'|'-disable'] "
806 "['-expected_id' number] "
807 "['-ignore-version'] "
808 "['-ignore-bypass'] "
809 "['-ircapture' number] "
813 .name
= "tapisenabled",
814 .mode
= COMMAND_EXEC
,
815 .jim_handler
= jim_jtag_tap_enabler
,
816 .help
= "Returns a Tcl boolean (0/1) indicating whether "
817 "the TAP is enabled (1) or not (0).",
822 .mode
= COMMAND_EXEC
,
823 .jim_handler
= jim_jtag_tap_enabler
,
824 .help
= "Try to enable the specified TAP using the "
825 "'tap-enable' TAP event.",
829 .name
= "tapdisable",
830 .mode
= COMMAND_EXEC
,
831 .jim_handler
= jim_jtag_tap_enabler
,
832 .help
= "Try to disable the specified TAP using the "
833 "'tap-disable' TAP event.",
839 .jim_handler
= jim_jtag_configure
,
840 .help
= "Provide a Tcl handler for the specified "
842 .usage
= "tap_name '-event' event_name handler",
846 .mode
= COMMAND_EXEC
,
847 .jim_handler
= jim_jtag_configure
,
848 .help
= "Return any Tcl handler for the specified "
850 .usage
= "tap_name '-event' event_name",
855 .handler
= handle_jtag_names
,
856 .help
= "Returns list of all JTAG tap names.",
860 .chain
= jtag_command_handlers_to_move
,
862 COMMAND_REGISTRATION_DONE
865 void jtag_notify_event(enum jtag_event event
)
867 struct jtag_tap
*tap
;
869 for (tap
= jtag_all_taps(); tap
; tap
= tap
->next_tap
)
870 jtag_tap_handle_event(tap
, event
);
874 COMMAND_HANDLER(handle_scan_chain_command
)
876 struct jtag_tap
*tap
;
877 char expected_id
[12];
879 tap
= jtag_all_taps();
881 " TapName Enabled IdCode Expected IrLen IrCap IrMask");
883 "-- ------------------- -------- ---------- ---------- ----- ----- ------");
886 uint32_t expected
, expected_mask
, ii
;
888 snprintf(expected_id
, sizeof(expected_id
), "0x%08x",
889 (unsigned)((tap
->expected_ids_cnt
> 0)
890 ? tap
->expected_ids
[0]
892 if (tap
->ignore_version
)
893 expected_id
[2] = '*';
895 expected
= buf_get_u32(tap
->expected
, 0, tap
->ir_length
);
896 expected_mask
= buf_get_u32(tap
->expected_mask
, 0, tap
->ir_length
);
899 "%2d %-18s %c 0x%08x %s %5d 0x%02x 0x%02x",
900 tap
->abs_chain_position
,
902 tap
->enabled
? 'Y' : 'n',
903 (unsigned int)(tap
->idcode
),
905 (unsigned int)(tap
->ir_length
),
906 (unsigned int)(expected
),
907 (unsigned int)(expected_mask
));
909 for (ii
= 1; ii
< tap
->expected_ids_cnt
; ii
++) {
910 snprintf(expected_id
, sizeof(expected_id
), "0x%08x",
911 (unsigned) tap
->expected_ids
[ii
]);
912 if (tap
->ignore_version
)
913 expected_id
[2] = '*';
926 COMMAND_HANDLER(handle_jtag_ntrst_delay_command
)
929 return ERROR_COMMAND_SYNTAX_ERROR
;
932 COMMAND_PARSE_NUMBER(uint
, CMD_ARGV
[0], delay
);
934 jtag_set_ntrst_delay(delay
);
936 command_print(CMD
, "jtag_ntrst_delay: %u", jtag_get_ntrst_delay());
940 COMMAND_HANDLER(handle_jtag_ntrst_assert_width_command
)
943 return ERROR_COMMAND_SYNTAX_ERROR
;
946 COMMAND_PARSE_NUMBER(uint
, CMD_ARGV
[0], delay
);
948 jtag_set_ntrst_assert_width(delay
);
950 command_print(CMD
, "jtag_ntrst_assert_width: %u", jtag_get_ntrst_assert_width());
954 COMMAND_HANDLER(handle_jtag_rclk_command
)
957 return ERROR_COMMAND_SYNTAX_ERROR
;
959 int retval
= ERROR_OK
;
962 COMMAND_PARSE_NUMBER(uint
, CMD_ARGV
[0], khz
);
964 retval
= adapter_config_rclk(khz
);
965 if (retval
!= ERROR_OK
)
969 int cur_khz
= adapter_get_speed_khz();
970 retval
= adapter_get_speed_readable(&cur_khz
);
971 if (retval
!= ERROR_OK
)
975 command_print(CMD
, "RCLK not supported - fallback to %d kHz", cur_khz
);
977 command_print(CMD
, "RCLK - adaptive");
982 COMMAND_HANDLER(handle_runtest_command
)
985 return ERROR_COMMAND_SYNTAX_ERROR
;
988 COMMAND_PARSE_NUMBER(uint
, CMD_ARGV
[0], num_clocks
);
990 jtag_add_runtest(num_clocks
, TAP_IDLE
);
991 return jtag_execute_queue();
995 * For "irscan" or "drscan" commands, the "end" (really, "next") state
996 * should be stable ... and *NOT* a shift state, otherwise free-running
997 * jtag clocks could change the values latched by the update state.
998 * Not surprisingly, this is the same constraint as SVF; the "irscan"
999 * and "drscan" commands are a write-only subset of what SVF provides.
1002 COMMAND_HANDLER(handle_irscan_command
)
1005 struct scan_field
*fields
;
1006 struct jtag_tap
*tap
= NULL
;
1007 tap_state_t endstate
;
1009 if ((CMD_ARGC
< 2) || (CMD_ARGC
% 2))
1010 return ERROR_COMMAND_SYNTAX_ERROR
;
1012 /* optional "-endstate" "statename" at the end of the arguments,
1013 * so that e.g. IRPAUSE can let us load the data register before
1014 * entering RUN/IDLE to execute the instruction we load here.
1016 endstate
= TAP_IDLE
;
1018 if (CMD_ARGC
>= 4) {
1019 /* have at least one pair of numbers.
1020 * is last pair the magic text? */
1021 if (strcmp("-endstate", CMD_ARGV
[CMD_ARGC
- 2]) == 0) {
1022 endstate
= tap_state_by_name(CMD_ARGV
[CMD_ARGC
- 1]);
1023 if (endstate
== TAP_INVALID
)
1024 return ERROR_COMMAND_SYNTAX_ERROR
;
1025 if (!scan_is_safe(endstate
))
1026 LOG_WARNING("unstable irscan endstate \"%s\"",
1027 CMD_ARGV
[CMD_ARGC
- 1]);
1032 int num_fields
= CMD_ARGC
/ 2;
1033 if (num_fields
> 1) {
1034 /* we really should be looking at plain_ir_scan if we want
1035 * anything more fancy.
1037 LOG_ERROR("Specify a single value for tap");
1038 return ERROR_COMMAND_SYNTAX_ERROR
;
1041 fields
= calloc(num_fields
, sizeof(*fields
));
1044 for (i
= 0; i
< num_fields
; i
++) {
1045 tap
= jtag_tap_by_string(CMD_ARGV
[i
*2]);
1048 command_print(CMD
, "Tap: %s unknown", CMD_ARGV
[i
*2]);
1053 retval
= parse_u64(CMD_ARGV
[i
* 2 + 1], &value
);
1054 if (retval
!= ERROR_OK
)
1057 int field_size
= tap
->ir_length
;
1058 fields
[i
].num_bits
= field_size
;
1059 uint8_t *v
= calloc(1, DIV_ROUND_UP(field_size
, 8));
1061 LOG_ERROR("Out of memory");
1065 buf_set_u64(v
, 0, field_size
, value
);
1066 fields
[i
].out_value
= v
;
1067 fields
[i
].in_value
= NULL
;
1070 /* did we have an endstate? */
1071 jtag_add_ir_scan(tap
, fields
, endstate
);
1073 retval
= jtag_execute_queue();
1076 for (i
= 0; i
< num_fields
; i
++)
1077 free((void *)fields
[i
].out_value
);
1084 COMMAND_HANDLER(handle_verify_ircapture_command
)
1087 return ERROR_COMMAND_SYNTAX_ERROR
;
1089 if (CMD_ARGC
== 1) {
1091 COMMAND_PARSE_ENABLE(CMD_ARGV
[0], enable
);
1092 jtag_set_verify_capture_ir(enable
);
1095 const char *status
= jtag_will_verify_capture_ir() ? "enabled" : "disabled";
1096 command_print(CMD
, "verify Capture-IR is %s", status
);
1101 COMMAND_HANDLER(handle_verify_jtag_command
)
1104 return ERROR_COMMAND_SYNTAX_ERROR
;
1106 if (CMD_ARGC
== 1) {
1108 COMMAND_PARSE_ENABLE(CMD_ARGV
[0], enable
);
1109 jtag_set_verify(enable
);
1112 const char *status
= jtag_will_verify() ? "enabled" : "disabled";
1113 command_print(CMD
, "verify jtag capture is %s", status
);
1118 COMMAND_HANDLER(handle_tms_sequence_command
)
1121 return ERROR_COMMAND_SYNTAX_ERROR
;
1123 if (CMD_ARGC
== 1) {
1125 if (strcmp(CMD_ARGV
[0], "short") == 0)
1126 use_new_table
= true;
1127 else if (strcmp(CMD_ARGV
[0], "long") == 0)
1128 use_new_table
= false;
1130 return ERROR_COMMAND_SYNTAX_ERROR
;
1132 tap_use_new_tms_table(use_new_table
);
1135 command_print(CMD
, "tms sequence is %s",
1136 tap_uses_new_tms_table() ? "short" : "long");
1141 COMMAND_HANDLER(handle_jtag_flush_queue_sleep
)
1144 return ERROR_COMMAND_SYNTAX_ERROR
;
1147 COMMAND_PARSE_NUMBER(int, CMD_ARGV
[0], sleep_ms
);
1149 jtag_set_flush_queue_sleep(sleep_ms
);
1154 COMMAND_HANDLER(handle_wait_srst_deassert
)
1157 return ERROR_COMMAND_SYNTAX_ERROR
;
1160 COMMAND_PARSE_NUMBER(int, CMD_ARGV
[0], timeout_ms
);
1161 if ((timeout_ms
<= 0) || (timeout_ms
> 100000)) {
1162 LOG_ERROR("Timeout must be an integer between 0 and 100000");
1166 LOG_USER("Waiting for srst assert + deassert for at most %dms", timeout_ms
);
1168 int64_t then
= timeval_ms();
1169 while (jtag_srst_asserted(&asserted_yet
) == ERROR_OK
) {
1170 if ((timeval_ms() - then
) > timeout_ms
) {
1171 LOG_ERROR("Timed out");
1177 while (jtag_srst_asserted(&asserted_yet
) == ERROR_OK
) {
1178 if ((timeval_ms() - then
) > timeout_ms
) {
1179 LOG_ERROR("Timed out");
1189 static const struct command_registration jtag_command_handlers
[] = {
1192 .name
= "jtag_flush_queue_sleep",
1193 .handler
= handle_jtag_flush_queue_sleep
,
1194 .mode
= COMMAND_ANY
,
1195 .help
= "For debug purposes(simulate long delays of interface) "
1196 "to test performance or change in behavior. Default 0ms.",
1197 .usage
= "[sleep in ms]",
1200 .name
= "jtag_rclk",
1201 .handler
= handle_jtag_rclk_command
,
1202 .mode
= COMMAND_ANY
,
1203 .help
= "With an argument, change to to use adaptive clocking "
1204 "if possible; else to use the fallback speed. "
1205 "With or without argument, display current setting.",
1206 .usage
= "[fallback_speed_khz]",
1209 .name
= "jtag_ntrst_delay",
1210 .handler
= handle_jtag_ntrst_delay_command
,
1211 .mode
= COMMAND_ANY
,
1212 .help
= "delay after deasserting trst in ms",
1213 .usage
= "[milliseconds]",
1216 .name
= "jtag_ntrst_assert_width",
1217 .handler
= handle_jtag_ntrst_assert_width_command
,
1218 .mode
= COMMAND_ANY
,
1219 .help
= "delay after asserting trst in ms",
1220 .usage
= "[milliseconds]",
1223 .name
= "scan_chain",
1224 .handler
= handle_scan_chain_command
,
1225 .mode
= COMMAND_ANY
,
1226 .help
= "print current scan chain configuration",
1231 .handler
= handle_runtest_command
,
1232 .mode
= COMMAND_EXEC
,
1233 .help
= "Move to Run-Test/Idle, and issue TCK for num_cycles.",
1234 .usage
= "num_cycles"
1238 .handler
= handle_irscan_command
,
1239 .mode
= COMMAND_EXEC
,
1240 .help
= "Execute Instruction Register (IR) scan. The "
1241 "specified opcodes are put into each TAP's IR, "
1242 "and other TAPs are put in BYPASS.",
1243 .usage
= "[tap_name instruction]* ['-endstate' state_name]",
1246 .name
= "verify_ircapture",
1247 .handler
= handle_verify_ircapture_command
,
1248 .mode
= COMMAND_ANY
,
1249 .help
= "Display or assign flag controlling whether to "
1250 "verify values captured during Capture-IR.",
1251 .usage
= "['enable'|'disable']",
1254 .name
= "verify_jtag",
1255 .handler
= handle_verify_jtag_command
,
1256 .mode
= COMMAND_ANY
,
1257 .help
= "Display or assign flag controlling whether to "
1258 "verify values captured during IR and DR scans.",
1259 .usage
= "['enable'|'disable']",
1262 .name
= "tms_sequence",
1263 .handler
= handle_tms_sequence_command
,
1264 .mode
= COMMAND_ANY
,
1265 .help
= "Display or change what style TMS sequences to use "
1266 "for JTAG state transitions: short (default) or "
1267 "long. Only for working around JTAG bugs.",
1268 /* Specifically for working around DRIVER bugs... */
1269 .usage
= "['short'|'long']",
1272 .name
= "wait_srst_deassert",
1273 .handler
= handle_wait_srst_deassert
,
1274 .mode
= COMMAND_ANY
,
1275 .help
= "Wait for an SRST deassert. "
1276 "Useful for cases where you need something to happen within ms "
1277 "of an srst deassert. Timeout in ms",
1282 .mode
= COMMAND_ANY
,
1283 .help
= "perform jtag tap actions",
1286 .chain
= jtag_subcommand_handlers
,
1289 .chain
= jtag_command_handlers_to_move
,
1291 COMMAND_REGISTRATION_DONE
1294 int jtag_register_commands(struct command_context
*cmd_ctx
)
1296 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)