1 /***************************************************************************
2 * Copyright (C) 2005 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
5 * Copyright (C) 2007-2010 Øyvind Harboe *
6 * oyvind.harboe@zylin.com *
8 * Copyright (C) 2009 SoftPLC Corporation *
12 * Copyright (C) 2009 Zachary T Welch *
13 * zw@superlucidity.net *
15 * This program is free software; you can redistribute it and/or modify *
16 * it under the terms of the GNU General Public License as published by *
17 * the Free Software Foundation; either version 2 of the License, or *
18 * (at your option) any later version. *
20 * This program is distributed in the hope that it will be useful, *
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
23 * GNU General Public License for more details. *
25 * You should have received a copy of the GNU General Public License *
26 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
27 ***************************************************************************/
35 #include "minidriver.h"
36 #include "interface.h"
37 #include "interfaces.h"
44 #include <helper/time_support.h>
45 #include "transport/transport.h"
49 * Holds support for accessing JTAG-specific mechanisms from TCl scripts.
52 static const Jim_Nvp nvp_jtag_tap_event
[] = {
53 { .value
= JTAG_TRST_ASSERTED
, .name
= "post-reset" },
54 { .value
= JTAG_TAP_EVENT_SETUP
, .name
= "setup" },
55 { .value
= JTAG_TAP_EVENT_ENABLE
, .name
= "tap-enable" },
56 { .value
= JTAG_TAP_EVENT_DISABLE
, .name
= "tap-disable" },
58 { .name
= NULL
, .value
= -1 }
61 struct jtag_tap
*jtag_tap_by_jim_obj(Jim_Interp
*interp
, Jim_Obj
*o
)
63 const char *cp
= Jim_GetString(o
, NULL
);
64 struct jtag_tap
*t
= cp
? jtag_tap_by_string(cp
) : NULL
;
68 Jim_SetResultFormatted(interp
, "Tap '%s' could not be found", cp
);
72 static bool scan_is_safe(tap_state_t state
)
85 static int Jim_Command_drscan(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *args
)
88 struct scan_field
*fields
;
97 * args[3] = hex string
98 * ... repeat num bits and hex string ...
101 * args[N-2] = "-endstate"
102 * args[N-1] = statename
104 if ((argc
< 4) || ((argc
% 2) != 0)) {
105 Jim_WrongNumArgs(interp
, 1, args
, "wrong arguments");
111 /* validate arguments as numbers */
113 for (i
= 2; i
< argc
; i
+= 2) {
117 e
= Jim_GetLong(interp
, args
[i
], &bits
);
118 /* If valid - try next arg */
122 /* Not valid.. are we at the end? */
123 if (((i
+ 2) != argc
)) {
124 /* nope, then error */
128 /* it could be: "-endstate FOO"
129 * e.g. DRPAUSE so we can issue more instructions
130 * before entering RUN/IDLE and executing them.
133 /* get arg as a string. */
134 cp
= Jim_GetString(args
[i
], NULL
);
135 /* is it the magic? */
136 if (0 == strcmp("-endstate", cp
)) {
137 /* is the statename valid? */
138 cp
= Jim_GetString(args
[i
+ 1], NULL
);
140 /* see if it is a valid state name */
141 endstate
= tap_state_by_name(cp
);
143 /* update the error message */
144 Jim_SetResultFormatted(interp
, "endstate: %s invalid", cp
);
146 if (!scan_is_safe(endstate
))
147 LOG_WARNING("drscan with unsafe "
148 "endstate \"%s\"", cp
);
150 /* valid - so clear the error */
152 /* and remove the last 2 args */
157 /* Still an error? */
159 return e
; /* too bad */
160 } /* validate args */
164 tap
= jtag_tap_by_jim_obj(interp
, args
[1]);
168 num_fields
= (argc
-2)/2;
169 if (num_fields
<= 0) {
170 Jim_SetResultString(interp
, "drscan: no scan fields supplied", -1);
173 fields
= malloc(sizeof(struct scan_field
) * num_fields
);
174 for (i
= 2; i
< argc
; i
+= 2) {
179 Jim_GetLong(interp
, args
[i
], &bits
);
180 str
= Jim_GetString(args
[i
+ 1], &len
);
182 fields
[field_count
].num_bits
= bits
;
183 void *t
= malloc(DIV_ROUND_UP(bits
, 8));
184 fields
[field_count
].out_value
= t
;
185 str_to_buf(str
, len
, t
, bits
, 0);
186 fields
[field_count
].in_value
= t
;
190 jtag_add_dr_scan(tap
, num_fields
, fields
, endstate
);
192 retval
= jtag_execute_queue();
193 if (retval
!= ERROR_OK
) {
194 Jim_SetResultString(interp
, "drscan: jtag execute failed", -1);
196 for (i
= 0; i
< field_count
; i
++)
197 free(fields
[i
].in_value
);
204 Jim_Obj
*list
= Jim_NewListObj(interp
, NULL
, 0);
205 for (i
= 2; i
< argc
; i
+= 2) {
209 Jim_GetLong(interp
, args
[i
], &bits
);
210 str
= buf_to_hex_str(fields
[field_count
].in_value
, bits
);
211 free(fields
[field_count
].in_value
);
213 Jim_ListAppendElement(interp
, list
, Jim_NewStringObj(interp
, str
, strlen(str
)));
218 Jim_SetResult(interp
, list
);
226 static int Jim_Command_pathmove(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *args
)
228 tap_state_t states
[8];
230 if ((argc
< 2) || ((size_t)argc
> (ARRAY_SIZE(states
) + 1))) {
231 Jim_WrongNumArgs(interp
, 1, args
, "wrong arguments");
236 for (i
= 0; i
< argc
-1; i
++) {
238 cp
= Jim_GetString(args
[i
+ 1], NULL
);
239 states
[i
] = tap_state_by_name(cp
);
241 /* update the error message */
242 Jim_SetResultFormatted(interp
, "endstate: %s invalid", cp
);
247 if ((jtag_add_statemove(states
[0]) != ERROR_OK
) || (jtag_execute_queue() != ERROR_OK
)) {
248 Jim_SetResultString(interp
, "pathmove: jtag execute failed", -1);
252 jtag_add_pathmove(argc
- 2, states
+ 1);
254 if (jtag_execute_queue() != ERROR_OK
) {
255 Jim_SetResultString(interp
, "pathmove: failed", -1);
263 static int Jim_Command_flush_count(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *args
)
265 Jim_SetResult(interp
, Jim_NewIntObj(interp
, jtag_get_flush_queue_count()));
270 /* REVISIT Just what about these should "move" ... ?
271 * These registrations, into the main JTAG table?
273 * There's a minor compatibility issue, these all show up twice;
274 * that's not desirable:
275 * - jtag drscan ... NOT DOCUMENTED!
278 * The "irscan" command (for example) doesn't show twice.
280 static const struct command_registration jtag_command_handlers_to_move
[] = {
283 .mode
= COMMAND_EXEC
,
284 .jim_handler
= Jim_Command_drscan
,
285 .help
= "Execute Data Register (DR) scan for one TAP. "
286 "Other TAPs must be in BYPASS mode.",
287 .usage
= "tap_name [num_bits value]* ['-endstate' state_name]",
290 .name
= "flush_count",
291 .mode
= COMMAND_EXEC
,
292 .jim_handler
= Jim_Command_flush_count
,
293 .help
= "Returns the number of times the JTAG queue "
298 .mode
= COMMAND_EXEC
,
299 .jim_handler
= Jim_Command_pathmove
,
300 .usage
= "start_state state1 [state2 [state3 ...]]",
301 .help
= "Move JTAG state machine from current state "
302 "(start_state) to state1, then state2, state3, etc.",
304 COMMAND_REGISTRATION_DONE
308 enum jtag_tap_cfg_param
{
313 static Jim_Nvp nvp_config_opts
[] = {
314 { .name
= "-event", .value
= JCFG_EVENT
},
315 { .name
= "-idcode", .value
= JCFG_IDCODE
},
317 { .name
= NULL
, .value
= -1 }
320 static int jtag_tap_configure_event(Jim_GetOptInfo
*goi
, struct jtag_tap
*tap
)
322 if (goi
->argc
== 0) {
323 Jim_WrongNumArgs(goi
->interp
, goi
->argc
, goi
->argv
, "-event <event-name> ...");
328 int e
= Jim_GetOpt_Nvp(goi
, nvp_jtag_tap_event
, &n
);
330 Jim_GetOpt_NvpUnknown(goi
, nvp_jtag_tap_event
, 1);
334 if (goi
->isconfigure
) {
335 if (goi
->argc
!= 1) {
336 Jim_WrongNumArgs(goi
->interp
,
339 "-event <event-name> <event-body>");
343 if (goi
->argc
!= 0) {
344 Jim_WrongNumArgs(goi
->interp
, goi
->argc
, goi
->argv
, "-event <event-name>");
349 struct jtag_tap_event_action
*jteap
= tap
->event_action
;
350 /* replace existing event body */
353 if (jteap
->event
== (enum jtag_event
)n
->value
) {
360 Jim_SetEmptyResult(goi
->interp
);
362 if (goi
->isconfigure
) {
364 jteap
= calloc(1, sizeof(*jteap
));
365 else if (NULL
!= jteap
->body
)
366 Jim_DecrRefCount(goi
->interp
, jteap
->body
);
368 jteap
->interp
= goi
->interp
;
369 jteap
->event
= n
->value
;
372 Jim_GetOpt_Obj(goi
, &o
);
373 jteap
->body
= Jim_DuplicateObj(goi
->interp
, o
);
374 Jim_IncrRefCount(jteap
->body
);
377 /* add to head of event list */
378 jteap
->next
= tap
->event_action
;
379 tap
->event_action
= jteap
;
382 jteap
->interp
= goi
->interp
;
383 Jim_SetResult(goi
->interp
,
384 Jim_DuplicateObj(goi
->interp
, jteap
->body
));
389 static int jtag_tap_configure_cmd(Jim_GetOptInfo
*goi
, struct jtag_tap
*tap
)
391 /* parse config or cget options */
392 while (goi
->argc
> 0) {
393 Jim_SetEmptyResult(goi
->interp
);
396 int e
= Jim_GetOpt_Nvp(goi
, nvp_config_opts
, &n
);
398 Jim_GetOpt_NvpUnknown(goi
, nvp_config_opts
, 0);
404 e
= jtag_tap_configure_event(goi
, tap
);
409 if (goi
->isconfigure
) {
410 Jim_SetResultFormatted(goi
->interp
,
411 "not settable: %s", n
->name
);
414 if (goi
->argc
!= 0) {
415 Jim_WrongNumArgs(goi
->interp
,
416 goi
->argc
, goi
->argv
,
421 Jim_SetResult(goi
->interp
, Jim_NewIntObj(goi
->interp
, tap
->idcode
));
424 Jim_SetResultFormatted(goi
->interp
, "unknown value: %s", n
->name
);
432 static int is_bad_irval(int ir_length
, jim_wide w
)
442 static int jim_newtap_expected_id(Jim_Nvp
*n
, Jim_GetOptInfo
*goi
,
443 struct jtag_tap
*pTap
)
446 int e
= Jim_GetOpt_Wide(goi
, &w
);
448 Jim_SetResultFormatted(goi
->interp
, "option: %s bad parameter", n
->name
);
452 uint32_t *p
= realloc(pTap
->expected_ids
,
453 (pTap
->expected_ids_cnt
+ 1) * sizeof(uint32_t));
455 Jim_SetResultFormatted(goi
->interp
, "no memory");
459 pTap
->expected_ids
= p
;
460 pTap
->expected_ids
[pTap
->expected_ids_cnt
++] = w
;
465 #define NTAP_OPT_IRLEN 0
466 #define NTAP_OPT_IRMASK 1
467 #define NTAP_OPT_IRCAPTURE 2
468 #define NTAP_OPT_ENABLED 3
469 #define NTAP_OPT_DISABLED 4
470 #define NTAP_OPT_EXPECTED_ID 5
471 #define NTAP_OPT_VERSION 6
473 static int jim_newtap_ir_param(Jim_Nvp
*n
, Jim_GetOptInfo
*goi
,
474 struct jtag_tap
*pTap
)
477 int e
= Jim_GetOpt_Wide(goi
, &w
);
479 Jim_SetResultFormatted(goi
->interp
,
480 "option: %s bad parameter", n
->name
);
485 if (w
> (jim_wide
) (8 * sizeof(pTap
->ir_capture_value
))) {
486 LOG_WARNING("%s: huge IR length %d",
487 pTap
->dotted_name
, (int) w
);
491 case NTAP_OPT_IRMASK
:
492 if (is_bad_irval(pTap
->ir_length
, w
)) {
493 LOG_ERROR("%s: IR mask %x too big",
499 LOG_WARNING("%s: nonstandard IR mask", pTap
->dotted_name
);
500 pTap
->ir_capture_mask
= w
;
502 case NTAP_OPT_IRCAPTURE
:
503 if (is_bad_irval(pTap
->ir_length
, w
)) {
504 LOG_ERROR("%s: IR capture %x too big",
505 pTap
->dotted_name
, (int) w
);
509 LOG_WARNING("%s: nonstandard IR value",
511 pTap
->ir_capture_value
= w
;
519 static int jim_newtap_cmd(Jim_GetOptInfo
*goi
)
521 struct jtag_tap
*pTap
;
526 const Jim_Nvp opts
[] = {
527 { .name
= "-irlen", .value
= NTAP_OPT_IRLEN
},
528 { .name
= "-irmask", .value
= NTAP_OPT_IRMASK
},
529 { .name
= "-ircapture", .value
= NTAP_OPT_IRCAPTURE
},
530 { .name
= "-enable", .value
= NTAP_OPT_ENABLED
},
531 { .name
= "-disable", .value
= NTAP_OPT_DISABLED
},
532 { .name
= "-expected-id", .value
= NTAP_OPT_EXPECTED_ID
},
533 { .name
= "-ignore-version", .value
= NTAP_OPT_VERSION
},
534 { .name
= NULL
, .value
= -1 },
537 pTap
= calloc(1, sizeof(struct jtag_tap
));
539 Jim_SetResultFormatted(goi
->interp
, "no memory");
544 * we expect CHIP + TAP + OPTIONS
547 Jim_SetResultFormatted(goi
->interp
, "Missing CHIP TAP OPTIONS ....");
553 Jim_GetOpt_String(goi
, &tmp
, NULL
);
554 pTap
->chip
= strdup(tmp
);
556 Jim_GetOpt_String(goi
, &tmp
, NULL
);
557 pTap
->tapname
= strdup(tmp
);
559 /* name + dot + name + null */
560 x
= strlen(pTap
->chip
) + 1 + strlen(pTap
->tapname
) + 1;
562 sprintf(cp
, "%s.%s", pTap
->chip
, pTap
->tapname
);
563 pTap
->dotted_name
= cp
;
565 LOG_DEBUG("Creating New Tap, Chip: %s, Tap: %s, Dotted: %s, %d params",
566 pTap
->chip
, pTap
->tapname
, pTap
->dotted_name
, goi
->argc
);
568 if (!transport_is_jtag()) {
569 /* SWD doesn't require any JTAG tap parameters */
570 pTap
->enabled
= true;
575 /* IEEE specifies that the two LSBs of an IR scan are 01, so make
576 * that the default. The "-ircapture" and "-irmask" options are only
577 * needed to cope with nonstandard TAPs, or to specify more bits.
579 pTap
->ir_capture_mask
= 0x03;
580 pTap
->ir_capture_value
= 0x01;
583 e
= Jim_GetOpt_Nvp(goi
, opts
, &n
);
585 Jim_GetOpt_NvpUnknown(goi
, opts
, 0);
590 LOG_DEBUG("Processing option: %s", n
->name
);
592 case NTAP_OPT_ENABLED
:
593 pTap
->disabled_after_reset
= false;
595 case NTAP_OPT_DISABLED
:
596 pTap
->disabled_after_reset
= true;
598 case NTAP_OPT_EXPECTED_ID
:
599 e
= jim_newtap_expected_id(n
, goi
, pTap
);
607 case NTAP_OPT_IRMASK
:
608 case NTAP_OPT_IRCAPTURE
:
609 e
= jim_newtap_ir_param(n
, goi
, pTap
);
616 case NTAP_OPT_VERSION
:
617 pTap
->ignore_version
= true;
619 } /* switch (n->value) */
620 } /* while (goi->argc) */
622 /* default is enabled-after-reset */
623 pTap
->enabled
= !pTap
->disabled_after_reset
;
625 /* Did all the required option bits get cleared? */
626 if (pTap
->ir_length
!= 0) {
631 Jim_SetResultFormatted(goi
->interp
,
632 "newtap: %s missing IR length",
638 static void jtag_tap_handle_event(struct jtag_tap
*tap
, enum jtag_event e
)
640 struct jtag_tap_event_action
*jteap
;
643 for (jteap
= tap
->event_action
; jteap
!= NULL
; jteap
= jteap
->next
) {
644 if (jteap
->event
!= e
)
647 Jim_Nvp
*nvp
= Jim_Nvp_value2name_simple(nvp_jtag_tap_event
, e
);
648 LOG_DEBUG("JTAG tap: %s event: %d (%s)\n\taction: %s",
649 tap
->dotted_name
, e
, nvp
->name
,
650 Jim_GetString(jteap
->body
, NULL
));
652 retval
= Jim_EvalObj(jteap
->interp
, jteap
->body
);
653 if (retval
== JIM_RETURN
)
654 retval
= jteap
->interp
->returnCode
;
656 if (retval
!= JIM_OK
) {
657 Jim_MakeErrorMessage(jteap
->interp
);
658 LOG_USER("%s", Jim_GetString(Jim_GetResult(jteap
->interp
), NULL
));
663 case JTAG_TAP_EVENT_ENABLE
:
664 case JTAG_TAP_EVENT_DISABLE
:
665 /* NOTE: we currently assume the handlers
666 * can't fail. Right here is where we should
667 * really be verifying the scan chains ...
669 tap
->enabled
= (e
== JTAG_TAP_EVENT_ENABLE
);
670 LOG_INFO("JTAG tap: %s %s", tap
->dotted_name
,
671 tap
->enabled
? "enabled" : "disabled");
679 static int jim_jtag_arp_init(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
682 Jim_GetOpt_Setup(&goi
, interp
, argc
-1, argv
+ 1);
684 Jim_WrongNumArgs(goi
.interp
, 1, goi
.argv
-1, "(no params)");
687 struct command_context
*context
= current_command_context(interp
);
688 int e
= jtag_init_inner(context
);
690 Jim_Obj
*eObj
= Jim_NewIntObj(goi
.interp
, e
);
691 Jim_IncrRefCount(eObj
);
692 Jim_SetResultFormatted(goi
.interp
, "error: %#s", eObj
);
693 Jim_DecrRefCount(goi
.interp
, eObj
);
699 static int jim_jtag_arp_init_reset(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
703 Jim_GetOpt_Setup(&goi
, interp
, argc
-1, argv
+ 1);
705 Jim_WrongNumArgs(goi
.interp
, 1, goi
.argv
-1, "(no params)");
708 struct command_context
*context
= current_command_context(interp
);
709 if (transport_is_jtag())
710 e
= jtag_init_reset(context
);
711 else if (transport_is_swd())
712 e
= swd_init_reset(context
);
715 Jim_Obj
*eObj
= Jim_NewIntObj(goi
.interp
, e
);
716 Jim_IncrRefCount(eObj
);
717 Jim_SetResultFormatted(goi
.interp
, "error: %#s", eObj
);
718 Jim_DecrRefCount(goi
.interp
, eObj
);
724 int jim_jtag_newtap(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
727 Jim_GetOpt_Setup(&goi
, interp
, argc
-1, argv
+ 1);
728 return jim_newtap_cmd(&goi
);
731 static bool jtag_tap_enable(struct jtag_tap
*t
)
735 jtag_tap_handle_event(t
, JTAG_TAP_EVENT_ENABLE
);
739 /* FIXME add JTAG sanity checks, w/o TLR
740 * - scan chain length grew by one (this)
741 * - IDs and IR lengths are as expected
743 jtag_call_event_callbacks(JTAG_TAP_EVENT_ENABLE
);
746 static bool jtag_tap_disable(struct jtag_tap
*t
)
750 jtag_tap_handle_event(t
, JTAG_TAP_EVENT_DISABLE
);
754 /* FIXME add JTAG sanity checks, w/o TLR
755 * - scan chain length shrank by one (this)
756 * - IDs and IR lengths are as expected
758 jtag_call_event_callbacks(JTAG_TAP_EVENT_DISABLE
);
762 int jim_jtag_tap_enabler(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
764 struct command
*c
= jim_to_command(interp
);
765 const char *cmd_name
= c
->name
;
767 Jim_GetOpt_Setup(&goi
, interp
, argc
-1, argv
+ 1);
769 Jim_SetResultFormatted(goi
.interp
, "usage: %s <name>", cmd_name
);
775 t
= jtag_tap_by_jim_obj(goi
.interp
, goi
.argv
[0]);
779 if (strcasecmp(cmd_name
, "tapisenabled") == 0) {
780 /* do nothing, just return the value */
781 } else if (strcasecmp(cmd_name
, "tapenable") == 0) {
782 if (!jtag_tap_enable(t
)) {
783 LOG_WARNING("failed to enable tap %s", t
->dotted_name
);
786 } else if (strcasecmp(cmd_name
, "tapdisable") == 0) {
787 if (!jtag_tap_disable(t
)) {
788 LOG_WARNING("failed to disable tap %s", t
->dotted_name
);
792 LOG_ERROR("command '%s' unknown", cmd_name
);
796 Jim_SetResult(goi
.interp
, Jim_NewIntObj(goi
.interp
, e
));
800 int jim_jtag_configure(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
802 struct command
*c
= jim_to_command(interp
);
803 const char *cmd_name
= c
->name
;
805 Jim_GetOpt_Setup(&goi
, interp
, argc
-1, argv
+ 1);
806 goi
.isconfigure
= !strcmp(cmd_name
, "configure");
807 if (goi
.argc
< 2 + goi
.isconfigure
) {
808 Jim_WrongNumArgs(goi
.interp
, 0, NULL
,
809 "<tap_name> <attribute> ...");
816 Jim_GetOpt_Obj(&goi
, &o
);
817 t
= jtag_tap_by_jim_obj(goi
.interp
, o
);
821 return jtag_tap_configure_cmd(&goi
, t
);
824 static int jim_jtag_names(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
827 Jim_GetOpt_Setup(&goi
, interp
, argc
-1, argv
+ 1);
829 Jim_WrongNumArgs(goi
.interp
, 1, goi
.argv
, "Too many parameters");
832 Jim_SetResult(goi
.interp
, Jim_NewListObj(goi
.interp
, NULL
, 0));
833 struct jtag_tap
*tap
;
835 for (tap
= jtag_all_taps(); tap
; tap
= tap
->next_tap
) {
836 Jim_ListAppendElement(goi
.interp
,
837 Jim_GetResult(goi
.interp
),
838 Jim_NewStringObj(goi
.interp
,
839 tap
->dotted_name
, -1));
844 COMMAND_HANDLER(handle_jtag_init_command
)
847 return ERROR_COMMAND_SYNTAX_ERROR
;
849 static bool jtag_initialized
;
850 if (jtag_initialized
) {
851 LOG_INFO("'jtag init' has already been called");
854 jtag_initialized
= true;
856 LOG_DEBUG("Initializing jtag devices...");
857 return jtag_init(CMD_CTX
);
860 static const struct command_registration jtag_subcommand_handlers
[] = {
864 .handler
= handle_jtag_init_command
,
865 .help
= "initialize jtag scan chain",
871 .jim_handler
= jim_jtag_arp_init
,
872 .help
= "Validates JTAG scan chain against the list of "
873 "declared TAPs using just the four standard JTAG "
877 .name
= "arp_init-reset",
879 .jim_handler
= jim_jtag_arp_init_reset
,
880 .help
= "Uses TRST and SRST to try resetting everything on "
881 "the JTAG scan chain, then performs 'jtag arp_init'."
885 .mode
= COMMAND_CONFIG
,
886 .jim_handler
= jim_jtag_newtap
,
887 .help
= "Create a new TAP instance named basename.tap_type, "
888 "and appends it to the scan chain.",
889 .usage
= "basename tap_type '-irlen' count "
890 "['-enable'|'-disable'] "
891 "['-expected_id' number] "
892 "['-ignore-version'] "
893 "['-ircapture' number] "
897 .name
= "tapisenabled",
898 .mode
= COMMAND_EXEC
,
899 .jim_handler
= jim_jtag_tap_enabler
,
900 .help
= "Returns a Tcl boolean (0/1) indicating whether "
901 "the TAP is enabled (1) or not (0).",
906 .mode
= COMMAND_EXEC
,
907 .jim_handler
= jim_jtag_tap_enabler
,
908 .help
= "Try to enable the specified TAP using the "
909 "'tap-enable' TAP event.",
913 .name
= "tapdisable",
914 .mode
= COMMAND_EXEC
,
915 .jim_handler
= jim_jtag_tap_enabler
,
916 .help
= "Try to disable the specified TAP using the "
917 "'tap-disable' TAP event.",
923 .jim_handler
= jim_jtag_configure
,
924 .help
= "Provide a Tcl handler for the specified "
926 .usage
= "tap_name '-event' event_name handler",
930 .mode
= COMMAND_EXEC
,
931 .jim_handler
= jim_jtag_configure
,
932 .help
= "Return any Tcl handler for the specified "
934 .usage
= "tap_name '-event' event_name",
939 .jim_handler
= jim_jtag_names
,
940 .help
= "Returns list of all JTAG tap names.",
943 .chain
= jtag_command_handlers_to_move
,
945 COMMAND_REGISTRATION_DONE
948 void jtag_notify_event(enum jtag_event event
)
950 struct jtag_tap
*tap
;
952 for (tap
= jtag_all_taps(); tap
; tap
= tap
->next_tap
)
953 jtag_tap_handle_event(tap
, event
);
957 COMMAND_HANDLER(handle_scan_chain_command
)
959 struct jtag_tap
*tap
;
960 char expected_id
[12];
962 tap
= jtag_all_taps();
964 " TapName Enabled IdCode Expected IrLen IrCap IrMask");
966 "-- ------------------- -------- ---------- ---------- ----- ----- ------");
969 uint32_t expected
, expected_mask
, ii
;
971 snprintf(expected_id
, sizeof(expected_id
), "0x%08x",
972 (unsigned)((tap
->expected_ids_cnt
> 0)
973 ? tap
->expected_ids
[0]
975 if (tap
->ignore_version
)
976 expected_id
[2] = '*';
978 expected
= buf_get_u32(tap
->expected
, 0, tap
->ir_length
);
979 expected_mask
= buf_get_u32(tap
->expected_mask
, 0, tap
->ir_length
);
982 "%2d %-18s %c 0x%08x %s %5d 0x%02x 0x%02x",
983 tap
->abs_chain_position
,
985 tap
->enabled
? 'Y' : 'n',
986 (unsigned int)(tap
->idcode
),
988 (unsigned int)(tap
->ir_length
),
989 (unsigned int)(expected
),
990 (unsigned int)(expected_mask
));
992 for (ii
= 1; ii
< tap
->expected_ids_cnt
; ii
++) {
993 snprintf(expected_id
, sizeof(expected_id
), "0x%08x",
994 (unsigned) tap
->expected_ids
[ii
]);
995 if (tap
->ignore_version
)
996 expected_id
[2] = '*';
1003 tap
= tap
->next_tap
;
1009 COMMAND_HANDLER(handle_jtag_ntrst_delay_command
)
1012 return ERROR_COMMAND_SYNTAX_ERROR
;
1013 if (CMD_ARGC
== 1) {
1015 COMMAND_PARSE_NUMBER(uint
, CMD_ARGV
[0], delay
);
1017 jtag_set_ntrst_delay(delay
);
1019 command_print(CMD
, "jtag_ntrst_delay: %u", jtag_get_ntrst_delay());
1023 COMMAND_HANDLER(handle_jtag_ntrst_assert_width_command
)
1026 return ERROR_COMMAND_SYNTAX_ERROR
;
1027 if (CMD_ARGC
== 1) {
1029 COMMAND_PARSE_NUMBER(uint
, CMD_ARGV
[0], delay
);
1031 jtag_set_ntrst_assert_width(delay
);
1033 command_print(CMD
, "jtag_ntrst_assert_width: %u", jtag_get_ntrst_assert_width());
1037 COMMAND_HANDLER(handle_jtag_rclk_command
)
1040 return ERROR_COMMAND_SYNTAX_ERROR
;
1042 int retval
= ERROR_OK
;
1043 if (CMD_ARGC
== 1) {
1045 COMMAND_PARSE_NUMBER(uint
, CMD_ARGV
[0], khz
);
1047 retval
= jtag_config_rclk(khz
);
1048 if (ERROR_OK
!= retval
)
1052 int cur_khz
= jtag_get_speed_khz();
1053 retval
= jtag_get_speed_readable(&cur_khz
);
1054 if (ERROR_OK
!= retval
)
1058 command_print(CMD
, "RCLK not supported - fallback to %d kHz", cur_khz
);
1060 command_print(CMD
, "RCLK - adaptive");
1065 COMMAND_HANDLER(handle_runtest_command
)
1068 return ERROR_COMMAND_SYNTAX_ERROR
;
1070 unsigned num_clocks
;
1071 COMMAND_PARSE_NUMBER(uint
, CMD_ARGV
[0], num_clocks
);
1073 jtag_add_runtest(num_clocks
, TAP_IDLE
);
1074 return jtag_execute_queue();
1078 * For "irscan" or "drscan" commands, the "end" (really, "next") state
1079 * should be stable ... and *NOT* a shift state, otherwise free-running
1080 * jtag clocks could change the values latched by the update state.
1081 * Not surprisingly, this is the same constraint as SVF; the "irscan"
1082 * and "drscan" commands are a write-only subset of what SVF provides.
1085 COMMAND_HANDLER(handle_irscan_command
)
1088 struct scan_field
*fields
;
1089 struct jtag_tap
*tap
= NULL
;
1090 tap_state_t endstate
;
1092 if ((CMD_ARGC
< 2) || (CMD_ARGC
% 2))
1093 return ERROR_COMMAND_SYNTAX_ERROR
;
1095 /* optional "-endstate" "statename" at the end of the arguments,
1096 * so that e.g. IRPAUSE can let us load the data register before
1097 * entering RUN/IDLE to execute the instruction we load here.
1099 endstate
= TAP_IDLE
;
1101 if (CMD_ARGC
>= 4) {
1102 /* have at least one pair of numbers.
1103 * is last pair the magic text? */
1104 if (strcmp("-endstate", CMD_ARGV
[CMD_ARGC
- 2]) == 0) {
1105 endstate
= tap_state_by_name(CMD_ARGV
[CMD_ARGC
- 1]);
1106 if (endstate
== TAP_INVALID
)
1107 return ERROR_COMMAND_SYNTAX_ERROR
;
1108 if (!scan_is_safe(endstate
))
1109 LOG_WARNING("unstable irscan endstate \"%s\"",
1110 CMD_ARGV
[CMD_ARGC
- 1]);
1115 int num_fields
= CMD_ARGC
/ 2;
1116 if (num_fields
> 1) {
1117 /* we really should be looking at plain_ir_scan if we want
1118 * anything more fancy.
1120 LOG_ERROR("Specify a single value for tap");
1121 return ERROR_COMMAND_SYNTAX_ERROR
;
1124 fields
= calloc(num_fields
, sizeof(*fields
));
1127 for (i
= 0; i
< num_fields
; i
++) {
1128 tap
= jtag_tap_by_string(CMD_ARGV
[i
*2]);
1131 command_print(CMD
, "Tap: %s unknown", CMD_ARGV
[i
*2]);
1136 retval
= parse_u64(CMD_ARGV
[i
* 2 + 1], &value
);
1137 if (ERROR_OK
!= retval
)
1140 int field_size
= tap
->ir_length
;
1141 fields
[i
].num_bits
= field_size
;
1142 uint8_t *v
= calloc(1, DIV_ROUND_UP(field_size
, 8));
1144 LOG_ERROR("Out of memory");
1148 buf_set_u64(v
, 0, field_size
, value
);
1149 fields
[i
].out_value
= v
;
1150 fields
[i
].in_value
= NULL
;
1153 /* did we have an endstate? */
1154 jtag_add_ir_scan(tap
, fields
, endstate
);
1156 retval
= jtag_execute_queue();
1159 for (i
= 0; i
< num_fields
; i
++)
1160 free((void *)fields
[i
].out_value
);
1167 COMMAND_HANDLER(handle_verify_ircapture_command
)
1170 return ERROR_COMMAND_SYNTAX_ERROR
;
1172 if (CMD_ARGC
== 1) {
1174 COMMAND_PARSE_ENABLE(CMD_ARGV
[0], enable
);
1175 jtag_set_verify_capture_ir(enable
);
1178 const char *status
= jtag_will_verify_capture_ir() ? "enabled" : "disabled";
1179 command_print(CMD
, "verify Capture-IR is %s", status
);
1184 COMMAND_HANDLER(handle_verify_jtag_command
)
1187 return ERROR_COMMAND_SYNTAX_ERROR
;
1189 if (CMD_ARGC
== 1) {
1191 COMMAND_PARSE_ENABLE(CMD_ARGV
[0], enable
);
1192 jtag_set_verify(enable
);
1195 const char *status
= jtag_will_verify() ? "enabled" : "disabled";
1196 command_print(CMD
, "verify jtag capture is %s", status
);
1201 COMMAND_HANDLER(handle_tms_sequence_command
)
1204 return ERROR_COMMAND_SYNTAX_ERROR
;
1206 if (CMD_ARGC
== 1) {
1208 if (strcmp(CMD_ARGV
[0], "short") == 0)
1209 use_new_table
= true;
1210 else if (strcmp(CMD_ARGV
[0], "long") == 0)
1211 use_new_table
= false;
1213 return ERROR_COMMAND_SYNTAX_ERROR
;
1215 tap_use_new_tms_table(use_new_table
);
1218 command_print(CMD
, "tms sequence is %s",
1219 tap_uses_new_tms_table() ? "short" : "long");
1224 COMMAND_HANDLER(handle_jtag_flush_queue_sleep
)
1227 return ERROR_COMMAND_SYNTAX_ERROR
;
1230 COMMAND_PARSE_NUMBER(int, CMD_ARGV
[0], sleep_ms
);
1232 jtag_set_flush_queue_sleep(sleep_ms
);
1237 COMMAND_HANDLER(handle_wait_srst_deassert
)
1240 return ERROR_COMMAND_SYNTAX_ERROR
;
1243 COMMAND_PARSE_NUMBER(int, CMD_ARGV
[0], timeout_ms
);
1244 if ((timeout_ms
<= 0) || (timeout_ms
> 100000)) {
1245 LOG_ERROR("Timeout must be an integer between 0 and 100000");
1249 LOG_USER("Waiting for srst assert + deassert for at most %dms", timeout_ms
);
1251 int64_t then
= timeval_ms();
1252 while (jtag_srst_asserted(&asserted_yet
) == ERROR_OK
) {
1253 if ((timeval_ms() - then
) > timeout_ms
) {
1254 LOG_ERROR("Timed out");
1260 while (jtag_srst_asserted(&asserted_yet
) == ERROR_OK
) {
1261 if ((timeval_ms() - then
) > timeout_ms
) {
1262 LOG_ERROR("Timed out");
1272 static const struct command_registration jtag_command_handlers
[] = {
1275 .name
= "jtag_flush_queue_sleep",
1276 .handler
= handle_jtag_flush_queue_sleep
,
1277 .mode
= COMMAND_ANY
,
1278 .help
= "For debug purposes(simulate long delays of interface) "
1279 "to test performance or change in behavior. Default 0ms.",
1280 .usage
= "[sleep in ms]",
1283 .name
= "jtag_rclk",
1284 .handler
= handle_jtag_rclk_command
,
1285 .mode
= COMMAND_ANY
,
1286 .help
= "With an argument, change to to use adaptive clocking "
1287 "if possible; else to use the fallback speed. "
1288 "With or without argument, display current setting.",
1289 .usage
= "[fallback_speed_khz]",
1292 .name
= "jtag_ntrst_delay",
1293 .handler
= handle_jtag_ntrst_delay_command
,
1294 .mode
= COMMAND_ANY
,
1295 .help
= "delay after deasserting trst in ms",
1296 .usage
= "[milliseconds]",
1299 .name
= "jtag_ntrst_assert_width",
1300 .handler
= handle_jtag_ntrst_assert_width_command
,
1301 .mode
= COMMAND_ANY
,
1302 .help
= "delay after asserting trst in ms",
1303 .usage
= "[milliseconds]",
1306 .name
= "scan_chain",
1307 .handler
= handle_scan_chain_command
,
1308 .mode
= COMMAND_ANY
,
1309 .help
= "print current scan chain configuration",
1314 .handler
= handle_runtest_command
,
1315 .mode
= COMMAND_EXEC
,
1316 .help
= "Move to Run-Test/Idle, and issue TCK for num_cycles.",
1317 .usage
= "num_cycles"
1321 .handler
= handle_irscan_command
,
1322 .mode
= COMMAND_EXEC
,
1323 .help
= "Execute Instruction Register (IR) scan. The "
1324 "specified opcodes are put into each TAP's IR, "
1325 "and other TAPs are put in BYPASS.",
1326 .usage
= "[tap_name instruction]* ['-endstate' state_name]",
1329 .name
= "verify_ircapture",
1330 .handler
= handle_verify_ircapture_command
,
1331 .mode
= COMMAND_ANY
,
1332 .help
= "Display or assign flag controlling whether to "
1333 "verify values captured during Capture-IR.",
1334 .usage
= "['enable'|'disable']",
1337 .name
= "verify_jtag",
1338 .handler
= handle_verify_jtag_command
,
1339 .mode
= COMMAND_ANY
,
1340 .help
= "Display or assign flag controlling whether to "
1341 "verify values captured during IR and DR scans.",
1342 .usage
= "['enable'|'disable']",
1345 .name
= "tms_sequence",
1346 .handler
= handle_tms_sequence_command
,
1347 .mode
= COMMAND_ANY
,
1348 .help
= "Display or change what style TMS sequences to use "
1349 "for JTAG state transitions: short (default) or "
1350 "long. Only for working around JTAG bugs.",
1351 /* Specifically for working around DRIVER bugs... */
1352 .usage
= "['short'|'long']",
1355 .name
= "wait_srst_deassert",
1356 .handler
= handle_wait_srst_deassert
,
1357 .mode
= COMMAND_ANY
,
1358 .help
= "Wait for an SRST deassert. "
1359 "Useful for cases where you need something to happen within ms "
1360 "of an srst deassert. Timeout in ms ",
1365 .mode
= COMMAND_ANY
,
1366 .help
= "perform jtag tap actions",
1369 .chain
= jtag_subcommand_handlers
,
1372 .chain
= jtag_command_handlers_to_move
,
1374 COMMAND_REGISTRATION_DONE
1377 int jtag_register_commands(struct command_context
*cmd_ctx
)
1379 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)