1 /***************************************************************************
2 * Copyright (C) 2005 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
5 * Copyright (C) 2007,2008 Ø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, write to the *
27 * Free Software Foundation, Inc., *
28 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
29 ***************************************************************************/
35 #include "minidriver.h"
36 #include "interface.h"
37 #include "interfaces.h"
43 static const Jim_Nvp nvp_jtag_tap_event
[] = {
44 { .value
= JTAG_TRST_ASSERTED
, .name
= "post-reset" },
45 { .value
= JTAG_TAP_EVENT_SETUP
, .name
= "setup" },
46 { .value
= JTAG_TAP_EVENT_ENABLE
, .name
= "tap-enable" },
47 { .value
= JTAG_TAP_EVENT_DISABLE
, .name
= "tap-disable" },
49 { .name
= NULL
, .value
= -1 }
52 extern jtag_interface_t
*jtag_interface
;
55 static int handle_interface_list_command(struct command_context_s
*cmd_ctx
,
56 char *cmd
, char **args
, int argc
);
57 static int handle_interface_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
58 static int handle_jtag_khz_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
59 static int handle_jtag_rclk_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
60 static int handle_reset_config_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
61 static int handle_jtag_nsrst_delay_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
62 static int handle_jtag_ntrst_delay_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
63 static int handle_jtag_nsrst_assert_width_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
64 static int handle_jtag_ntrst_assert_width_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
66 static int handle_scan_chain_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
68 static int handle_jtag_reset_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
69 static int handle_runtest_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
70 static int handle_irscan_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
71 static int Jim_Command_drscan(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
);
72 static int Jim_Command_pathmove(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
);
73 static int Jim_Command_flush_count(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *args
);
75 static int handle_verify_ircapture_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
76 static int handle_verify_jtag_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
77 static int handle_tms_sequence_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
80 enum jtag_tap_cfg_param
{
84 static Jim_Nvp nvp_config_opts
[] = {
85 { .name
= "-event", .value
= JCFG_EVENT
},
87 { .name
= NULL
, .value
= -1 }
90 static int jtag_tap_configure_cmd(Jim_GetOptInfo
*goi
, jtag_tap_t
* tap
)
96 /* parse config or cget options */
97 while (goi
->argc
> 0) {
98 Jim_SetEmptyResult (goi
->interp
);
100 e
= Jim_GetOpt_Nvp(goi
, nvp_config_opts
, &n
);
102 Jim_GetOpt_NvpUnknown(goi
, nvp_config_opts
, 0);
108 if (goi
->argc
== 0) {
109 Jim_WrongNumArgs(goi
->interp
, goi
->argc
, goi
->argv
, "-event ?event-name? ...");
113 e
= Jim_GetOpt_Nvp(goi
, nvp_jtag_tap_event
, &n
);
115 Jim_GetOpt_NvpUnknown(goi
, nvp_jtag_tap_event
, 1);
119 if (goi
->isconfigure
) {
120 if (goi
->argc
!= 1) {
121 Jim_WrongNumArgs(goi
->interp
, goi
->argc
, goi
->argv
, "-event ?event-name? ?EVENT-BODY?");
125 if (goi
->argc
!= 0) {
126 Jim_WrongNumArgs(goi
->interp
, goi
->argc
, goi
->argv
, "-event ?event-name?");
132 jtag_tap_event_action_t
*jteap
;
134 jteap
= tap
->event_action
;
135 /* replace existing? */
137 if (jteap
->event
== (enum jtag_event
)n
->value
) {
143 if (goi
->isconfigure
) {
147 jteap
= calloc(1, sizeof (*jteap
));
150 jteap
->event
= n
->value
;
151 Jim_GetOpt_Obj(goi
, &o
);
153 Jim_DecrRefCount(interp
, jteap
->body
);
155 jteap
->body
= Jim_DuplicateObj(goi
->interp
, o
);
156 Jim_IncrRefCount(jteap
->body
);
160 /* add to head of event list */
161 jteap
->next
= tap
->event_action
;
162 tap
->event_action
= jteap
;
164 Jim_SetEmptyResult(goi
->interp
);
168 Jim_SetEmptyResult(goi
->interp
);
170 Jim_SetResult(goi
->interp
, Jim_DuplicateObj(goi
->interp
, jteap
->body
));
177 } /* while (goi->argc) */
182 static int is_bad_irval(int ir_length
, jim_wide w
)
192 static int jim_newtap_cmd(Jim_GetOptInfo
*goi
)
200 const Jim_Nvp opts
[] = {
201 #define NTAP_OPT_IRLEN 0
202 { .name
= "-irlen" , .value
= NTAP_OPT_IRLEN
},
203 #define NTAP_OPT_IRMASK 1
204 { .name
= "-irmask" , .value
= NTAP_OPT_IRMASK
},
205 #define NTAP_OPT_IRCAPTURE 2
206 { .name
= "-ircapture" , .value
= NTAP_OPT_IRCAPTURE
},
207 #define NTAP_OPT_ENABLED 3
208 { .name
= "-enable" , .value
= NTAP_OPT_ENABLED
},
209 #define NTAP_OPT_DISABLED 4
210 { .name
= "-disable" , .value
= NTAP_OPT_DISABLED
},
211 #define NTAP_OPT_EXPECTED_ID 5
212 { .name
= "-expected-id" , .value
= NTAP_OPT_EXPECTED_ID
},
213 { .name
= NULL
, .value
= -1 },
216 pTap
= calloc(1, sizeof(jtag_tap_t
));
218 Jim_SetResult_sprintf(goi
->interp
, "no memory");
223 * we expect CHIP + TAP + OPTIONS
226 Jim_SetResult_sprintf(goi
->interp
, "Missing CHIP TAP OPTIONS ....");
230 Jim_GetOpt_String(goi
, &cp
, NULL
);
231 pTap
->chip
= strdup(cp
);
233 Jim_GetOpt_String(goi
, &cp
, NULL
);
234 pTap
->tapname
= strdup(cp
);
236 /* name + dot + name + null */
237 x
= strlen(pTap
->chip
) + 1 + strlen(pTap
->tapname
) + 1;
239 sprintf(cp
, "%s.%s", pTap
->chip
, pTap
->tapname
);
240 pTap
->dotted_name
= cp
;
242 LOG_DEBUG("Creating New Tap, Chip: %s, Tap: %s, Dotted: %s, %d params",
243 pTap
->chip
, pTap
->tapname
, pTap
->dotted_name
, goi
->argc
);
245 /* IEEE specifies that the two LSBs of an IR scan are 01, so make
246 * that the default. The "-irlen" and "-irmask" options are only
247 * needed to cope with nonstandard TAPs, or to specify more bits.
249 pTap
->ir_capture_mask
= 0x03;
250 pTap
->ir_capture_value
= 0x01;
253 e
= Jim_GetOpt_Nvp(goi
, opts
, &n
);
255 Jim_GetOpt_NvpUnknown(goi
, opts
, 0);
256 free((void *)pTap
->dotted_name
);
260 LOG_DEBUG("Processing option: %s", n
->name
);
262 case NTAP_OPT_ENABLED
:
263 pTap
->disabled_after_reset
= false;
265 case NTAP_OPT_DISABLED
:
266 pTap
->disabled_after_reset
= true;
268 case NTAP_OPT_EXPECTED_ID
:
270 uint32_t *new_expected_ids
;
272 e
= Jim_GetOpt_Wide(goi
, &w
);
274 Jim_SetResult_sprintf(goi
->interp
, "option: %s bad parameter", n
->name
);
275 free((void *)pTap
->dotted_name
);
280 new_expected_ids
= malloc(sizeof(uint32_t) * (pTap
->expected_ids_cnt
+ 1));
281 if (new_expected_ids
== NULL
) {
282 Jim_SetResult_sprintf(goi
->interp
, "no memory");
283 free((void *)pTap
->dotted_name
);
288 memcpy(new_expected_ids
, pTap
->expected_ids
, sizeof(uint32_t) * pTap
->expected_ids_cnt
);
290 new_expected_ids
[pTap
->expected_ids_cnt
] = w
;
292 free(pTap
->expected_ids
);
293 pTap
->expected_ids
= new_expected_ids
;
294 pTap
->expected_ids_cnt
++;
298 case NTAP_OPT_IRMASK
:
299 case NTAP_OPT_IRCAPTURE
:
300 e
= Jim_GetOpt_Wide(goi
, &w
);
302 Jim_SetResult_sprintf(goi
->interp
, "option: %s bad parameter", n
->name
);
303 free((void *)pTap
->dotted_name
);
309 if (w
> (jim_wide
) (8 * sizeof(pTap
->ir_capture_value
)))
310 LOG_WARNING("%s: huge IR length %d",
315 case NTAP_OPT_IRMASK
:
316 if (is_bad_irval(pTap
->ir_length
, w
)) {
317 LOG_ERROR("%s: IR mask %x too big",
320 free((void *)pTap
->dotted_name
);
325 LOG_WARNING("%s: nonstandard IR mask",
327 pTap
->ir_capture_mask
= w
;
329 case NTAP_OPT_IRCAPTURE
:
330 if (is_bad_irval(pTap
->ir_length
, w
)) {
331 LOG_ERROR("%s: IR capture %x too big",
334 free((void *)pTap
->dotted_name
);
339 LOG_WARNING("%s: nonstandard IR value",
341 pTap
->ir_capture_value
= w
;
344 } /* switch (n->value) */
345 } /* while (goi->argc) */
347 /* default is enabled-after-reset */
348 pTap
->enabled
= !pTap
->disabled_after_reset
;
350 /* Did all the required option bits get cleared? */
351 if (pTap
->ir_length
!= 0)
357 Jim_SetResult_sprintf(goi
->interp
,
358 "newtap: %s missing IR length",
364 static void jtag_tap_handle_event(jtag_tap_t
*tap
, enum jtag_event e
)
366 jtag_tap_event_action_t
* jteap
;
368 for (jteap
= tap
->event_action
; jteap
!= NULL
; jteap
= jteap
->next
) {
369 if (jteap
->event
== e
) {
370 LOG_DEBUG("JTAG tap: %s event: %d (%s)\n\taction: %s",
373 Jim_Nvp_value2name_simple(nvp_jtag_tap_event
, e
)->name
,
374 Jim_GetString(jteap
->body
, NULL
));
375 if (Jim_EvalObj(interp
, jteap
->body
) != JIM_OK
) {
376 Jim_PrintErrorMessage(interp
);
378 case JTAG_TAP_EVENT_ENABLE
:
379 case JTAG_TAP_EVENT_DISABLE
:
380 /* NOTE: we currently assume the handlers
381 * can't fail. Right here is where we should
382 * really be verifying the scan chains ...
384 tap
->enabled
= (e
== JTAG_TAP_EVENT_ENABLE
);
385 LOG_INFO("JTAG tap: %s %s", tap
->dotted_name
,
386 tap
->enabled
? "enabled" : "disabled");
396 static int jim_jtag_command(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
402 struct command_context_s
*context
;
411 JTAG_CMD_TAPISENABLED
,
417 const Jim_Nvp jtag_cmds
[] = {
418 { .name
= "interface" , .value
= JTAG_CMD_INTERFACE
},
419 { .name
= "arp_init" , .value
= JTAG_CMD_INIT
},
420 { .name
= "arp_init-reset", .value
= JTAG_CMD_INIT_RESET
},
421 { .name
= "newtap" , .value
= JTAG_CMD_NEWTAP
},
422 { .name
= "tapisenabled" , .value
= JTAG_CMD_TAPISENABLED
},
423 { .name
= "tapenable" , .value
= JTAG_CMD_TAPENABLE
},
424 { .name
= "tapdisable" , .value
= JTAG_CMD_TAPDISABLE
},
425 { .name
= "configure" , .value
= JTAG_CMD_CONFIGURE
},
426 { .name
= "cget" , .value
= JTAG_CMD_CGET
},
427 { .name
= "names" , .value
= JTAG_CMD_NAMES
},
429 { .name
= NULL
, .value
= -1 },
432 context
= Jim_GetAssocData(interp
, "context");
433 /* go past the command */
434 Jim_GetOpt_Setup(&goi
, interp
, argc
-1, argv
+ 1);
436 e
= Jim_GetOpt_Nvp(&goi
, jtag_cmds
, &n
);
438 Jim_GetOpt_NvpUnknown(&goi
, jtag_cmds
, 0);
441 Jim_SetEmptyResult(goi
.interp
);
443 case JTAG_CMD_INTERFACE
:
444 /* return the name of the interface */
445 /* TCL code might need to know the exact type... */
446 /* FUTURE: we allow this as a means to "set" the interface. */
448 Jim_WrongNumArgs(goi
.interp
, 1, goi
.argv
-1, "(no params)");
451 Jim_SetResultString(goi
.interp
, jtag_interface
->name
, -1);
455 Jim_WrongNumArgs(goi
.interp
, 1, goi
.argv
-1, "(no params)");
458 e
= jtag_init_inner(context
);
460 Jim_SetResult_sprintf(goi
.interp
, "error: %d", e
);
464 case JTAG_CMD_INIT_RESET
:
466 Jim_WrongNumArgs(goi
.interp
, 1, goi
.argv
-1, "(no params)");
469 e
= jtag_init_reset(context
);
471 Jim_SetResult_sprintf(goi
.interp
, "error: %d", e
);
475 case JTAG_CMD_NEWTAP
:
476 return jim_newtap_cmd(&goi
);
478 case JTAG_CMD_TAPISENABLED
:
479 case JTAG_CMD_TAPENABLE
:
480 case JTAG_CMD_TAPDISABLE
:
482 Jim_SetResultString(goi
.interp
, "Too many parameters",-1);
489 t
= jtag_tap_by_jim_obj(goi
.interp
, goi
.argv
[0]);
494 case JTAG_CMD_TAPISENABLED
:
496 case JTAG_CMD_TAPENABLE
:
499 jtag_tap_handle_event(t
, JTAG_TAP_EVENT_ENABLE
);
503 /* FIXME add JTAG sanity checks, w/o TLR
504 * - scan chain length grew by one (this)
505 * - IDs and IR lengths are as expected
508 jtag_call_event_callbacks(JTAG_TAP_EVENT_ENABLE
);
510 case JTAG_CMD_TAPDISABLE
:
513 jtag_tap_handle_event(t
, JTAG_TAP_EVENT_DISABLE
);
517 /* FIXME add JTAG sanity checks, w/o TLR
518 * - scan chain length shrank by one (this)
519 * - IDs and IR lengths are as expected
522 jtag_call_event_callbacks(JTAG_TAP_EVENT_DISABLE
);
526 Jim_SetResult(goi
.interp
, Jim_NewIntObj(goi
.interp
, e
));
533 Jim_WrongNumArgs(goi
.interp
, 0, NULL
,
534 "cget tap_name queryparm");
541 Jim_GetOpt_Obj(&goi
, &o
);
542 t
= jtag_tap_by_jim_obj(goi
.interp
, o
);
548 return jtag_tap_configure_cmd(&goi
, t
);
552 case JTAG_CMD_CONFIGURE
:
554 Jim_WrongNumArgs(goi
.interp
, 0, NULL
,
555 "configure tap_name attribute value ...");
562 Jim_GetOpt_Obj(&goi
, &o
);
563 t
= jtag_tap_by_jim_obj(goi
.interp
, o
);
569 return jtag_tap_configure_cmd(&goi
, t
);
575 Jim_WrongNumArgs(goi
.interp
, 1, goi
.argv
, "Too many parameters");
578 Jim_SetResult(goi
.interp
, Jim_NewListObj(goi
.interp
, NULL
, 0));
582 for (tap
= jtag_all_taps(); tap
; tap
= tap
->next_tap
) {
583 Jim_ListAppendElement(goi
.interp
,
584 Jim_GetResult(goi
.interp
),
585 Jim_NewStringObj(goi
.interp
,
586 tap
->dotted_name
, -1));
598 void jtag_notify_event(enum jtag_event event
)
602 for (tap
= jtag_all_taps(); tap
; tap
= tap
->next_tap
)
603 jtag_tap_handle_event(tap
, event
);
607 int jtag_register_commands(struct command_context_s
*cmd_ctx
)
609 register_jim(cmd_ctx
, "jtag", jim_jtag_command
, "perform jtag tap actions");
611 register_command(cmd_ctx
, NULL
, "interface", handle_interface_command
,
612 COMMAND_CONFIG
, "try to configure interface");
613 register_command(cmd_ctx
, NULL
,
614 "interface_list", &handle_interface_list_command
,
615 COMMAND_ANY
, "list all built-in interfaces");
616 register_command(cmd_ctx
, NULL
, "jtag_khz", handle_jtag_khz_command
,
617 COMMAND_ANY
, "set maximum jtag speed (if supported); "
618 "parameter is maximum khz, or 0 for adaptive clocking (RTCK).");
619 register_command(cmd_ctx
, NULL
, "jtag_rclk", handle_jtag_rclk_command
,
620 COMMAND_ANY
, "fallback_speed_khz - set JTAG speed to RCLK or use fallback speed");
621 register_command(cmd_ctx
, NULL
, "reset_config", handle_reset_config_command
,
624 "[none|trst_only|srst_only|trst_and_srst] "
625 "[srst_pulls_trst|trst_pulls_srst|combined|separate] "
626 "[srst_gates_jtag|srst_nogate] "
627 "[trst_push_pull|trst_open_drain] "
628 "[srst_push_pull|srst_open_drain]");
629 register_command(cmd_ctx
, NULL
, "jtag_nsrst_delay", handle_jtag_nsrst_delay_command
,
630 COMMAND_ANY
, "jtag_nsrst_delay <ms> - delay after deasserting srst in ms");
631 register_command(cmd_ctx
, NULL
, "jtag_ntrst_delay", handle_jtag_ntrst_delay_command
,
632 COMMAND_ANY
, "jtag_ntrst_delay <ms> - delay after deasserting trst in ms");
633 register_command(cmd_ctx
, NULL
, "jtag_nsrst_assert_width", handle_jtag_nsrst_assert_width_command
,
634 COMMAND_ANY
, "jtag_nsrst_assert_width <ms> - delay after asserting srst in ms");
635 register_command(cmd_ctx
, NULL
, "jtag_ntrst_assert_width", handle_jtag_ntrst_assert_width_command
,
636 COMMAND_ANY
, "jtag_ntrst_assert_width <ms> - delay after asserting trst in ms");
638 register_command(cmd_ctx
, NULL
, "scan_chain", handle_scan_chain_command
,
639 COMMAND_EXEC
, "print current scan chain configuration");
641 register_command(cmd_ctx
, NULL
, "jtag_reset", handle_jtag_reset_command
,
642 COMMAND_EXEC
, "toggle reset lines <trst> <srst>");
643 register_command(cmd_ctx
, NULL
, "runtest", handle_runtest_command
,
644 COMMAND_EXEC
, "move to Run-Test/Idle, and execute <num_cycles>");
645 register_command(cmd_ctx
, NULL
, "irscan", handle_irscan_command
,
646 COMMAND_EXEC
, "execute IR scan <device> <instr> [dev2] [instr2] ...");
647 register_jim(cmd_ctx
, "drscan", Jim_Command_drscan
, "execute DR scan <device> <num_bits> <value> <num_bits1> <value2> ...");
648 register_jim(cmd_ctx
, "flush_count", Jim_Command_flush_count
, "returns number of times the JTAG queue has been flushed");
649 register_jim(cmd_ctx
, "pathmove", Jim_Command_pathmove
, "move JTAG to state1 then to state2, state3, etc. <state1>,<state2>,<stat3>...");
651 register_command(cmd_ctx
, NULL
, "verify_ircapture", handle_verify_ircapture_command
,
652 COMMAND_ANY
, "verify value captured during Capture-IR <enable | disable>");
653 register_command(cmd_ctx
, NULL
, "verify_jtag", handle_verify_jtag_command
,
654 COMMAND_ANY
, "verify value capture <enable | disable>");
655 register_command(cmd_ctx
, NULL
, "tms_sequence", handle_tms_sequence_command
,
656 COMMAND_ANY
, "choose short(default) or long tms_sequence <short | long>");
660 static int default_khz(int khz
, int *jtag_speed
)
662 LOG_ERROR("Translation from khz to jtag_speed not implemented");
666 static int default_speed_div(int speed
, int *khz
)
668 LOG_ERROR("Translation from jtag_speed to khz not implemented");
672 static int default_power_dropout(int *dropout
)
674 *dropout
= 0; /* by default we can't detect power dropout */
678 static int default_srst_asserted(int *srst_asserted
)
680 *srst_asserted
= 0; /* by default we can't detect srst asserted */
684 static int handle_interface_command(struct command_context_s
*cmd_ctx
,
685 char *cmd
, char **args
, int argc
)
687 /* check whether the interface is already configured */
690 LOG_WARNING("Interface already configured, ignoring");
694 /* interface name is a mandatory argument */
695 if (argc
!= 1 || args
[0][0] == '\0')
696 return ERROR_COMMAND_SYNTAX_ERROR
;
698 for (unsigned i
= 0; NULL
!= jtag_interfaces
[i
]; i
++)
700 if (strcmp(args
[0], jtag_interfaces
[i
]->name
) != 0)
703 int retval
= jtag_interfaces
[i
]->register_commands(cmd_ctx
);
704 if (ERROR_OK
!= retval
)
707 jtag_interface
= jtag_interfaces
[i
];
709 if (jtag_interface
->khz
== NULL
)
710 jtag_interface
->khz
= default_khz
;
711 if (jtag_interface
->speed_div
== NULL
)
712 jtag_interface
->speed_div
= default_speed_div
;
713 if (jtag_interface
->power_dropout
== NULL
)
714 jtag_interface
->power_dropout
= default_power_dropout
;
715 if (jtag_interface
->srst_asserted
== NULL
)
716 jtag_interface
->srst_asserted
= default_srst_asserted
;
721 /* no valid interface was found (i.e. the configuration option,
722 * didn't match one of the compiled-in interfaces
724 LOG_ERROR("The specified JTAG interface was not found (%s)", args
[0]);
725 handle_interface_list_command(cmd_ctx
, cmd
, args
, argc
);
726 return ERROR_JTAG_INVALID_INTERFACE
;
729 static int handle_interface_list_command(struct command_context_s
*cmd_ctx
,
730 char *cmd
, char **args
, int argc
)
732 if (strcmp(cmd
, "interface_list") == 0 && argc
> 0)
733 return ERROR_COMMAND_SYNTAX_ERROR
;
735 command_print(cmd_ctx
, "The following JTAG interfaces are available:");
736 for (unsigned i
= 0; NULL
!= jtag_interfaces
[i
]; i
++)
738 const char *name
= jtag_interfaces
[i
]->name
;
739 command_print(cmd_ctx
, "%u: %s", i
+ 1, name
);
745 static int handle_scan_chain_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
749 tap
= jtag_all_taps();
750 command_print(cmd_ctx
, " TapName | Enabled | IdCode Expected IrLen IrCap IrMask Instr ");
751 command_print(cmd_ctx
, "---|--------------------|---------|------------|------------|------|------|------|---------");
754 uint32_t expected
, expected_mask
, cur_instr
, ii
;
755 expected
= buf_get_u32(tap
->expected
, 0, tap
->ir_length
);
756 expected_mask
= buf_get_u32(tap
->expected_mask
, 0, tap
->ir_length
);
757 cur_instr
= buf_get_u32(tap
->cur_instr
, 0, tap
->ir_length
);
759 command_print(cmd_ctx
,
760 "%2d | %-18s | %c | 0x%08x | 0x%08x | 0x%02x | 0x%02x | 0x%02x | 0x%02x",
761 tap
->abs_chain_position
,
763 tap
->enabled
? 'Y' : 'n',
764 (unsigned int)(tap
->idcode
),
765 (unsigned int)(tap
->expected_ids_cnt
> 0 ? tap
->expected_ids
[0] : 0),
766 (unsigned int)(tap
->ir_length
),
767 (unsigned int)(expected
),
768 (unsigned int)(expected_mask
),
769 (unsigned int)(cur_instr
));
771 for (ii
= 1; ii
< tap
->expected_ids_cnt
; ii
++) {
772 command_print(cmd_ctx
, " | | | | 0x%08x | | | | ",
773 (unsigned int)(tap
->expected_ids
[ii
]));
782 static int handle_reset_config_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
787 /* Original versions cared about the order of these tokens:
788 * reset_config signals [combination [trst_type [srst_type]]]
789 * They also clobbered the previous configuration even on error.
791 * Here we don't care about the order, and only change values
792 * which have been explicitly specified.
794 for (; argc
; argc
--, args
++) {
799 m
= RESET_SRST_NO_GATING
;
800 if (strcmp(*args
, "srst_gates_jtag") == 0)
801 /* default: don't use JTAG while SRST asserted */;
802 else if (strcmp(*args
, "srst_nogate") == 0)
803 tmp
= RESET_SRST_NO_GATING
;
807 LOG_ERROR("extra reset_config %s spec (%s)",
809 return ERROR_INVALID_ARGUMENTS
;
815 m
= RESET_HAS_TRST
| RESET_HAS_SRST
;
816 if (strcmp(*args
, "none") == 0)
818 else if (strcmp(*args
, "trst_only") == 0)
819 tmp
= RESET_HAS_TRST
;
820 else if (strcmp(*args
, "srst_only") == 0)
821 tmp
= RESET_HAS_SRST
;
822 else if (strcmp(*args
, "trst_and_srst") == 0)
823 tmp
= RESET_HAS_TRST
| RESET_HAS_SRST
;
827 LOG_ERROR("extra reset_config %s spec (%s)",
829 return ERROR_INVALID_ARGUMENTS
;
834 /* combination (options for broken wiring) */
835 m
= RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
;
836 if (strcmp(*args
, "separate") == 0)
837 /* separate reset lines - default */;
838 else if (strcmp(*args
, "srst_pulls_trst") == 0)
839 tmp
|= RESET_SRST_PULLS_TRST
;
840 else if (strcmp(*args
, "trst_pulls_srst") == 0)
841 tmp
|= RESET_TRST_PULLS_SRST
;
842 else if (strcmp(*args
, "combined") == 0)
843 tmp
|= RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
;
847 LOG_ERROR("extra reset_config %s spec (%s)",
848 "combination", *args
);
849 return ERROR_INVALID_ARGUMENTS
;
854 /* trst_type (NOP without HAS_TRST) */
855 m
= RESET_TRST_OPEN_DRAIN
;
856 if (strcmp(*args
, "trst_open_drain") == 0)
857 tmp
|= RESET_TRST_OPEN_DRAIN
;
858 else if (strcmp(*args
, "trst_push_pull") == 0)
859 /* push/pull from adapter - default */;
863 LOG_ERROR("extra reset_config %s spec (%s)",
865 return ERROR_INVALID_ARGUMENTS
;
870 /* srst_type (NOP without HAS_SRST) */
871 m
|= RESET_SRST_PUSH_PULL
;
872 if (strcmp(*args
, "srst_push_pull") == 0)
873 tmp
|= RESET_SRST_PUSH_PULL
;
874 else if (strcmp(*args
, "srst_open_drain") == 0)
875 /* open drain from adapter - default */;
879 LOG_ERROR("extra reset_config %s spec (%s)",
881 return ERROR_INVALID_ARGUMENTS
;
886 /* caller provided nonsense; fail */
887 LOG_ERROR("unknown reset_config flag (%s)", *args
);
888 return ERROR_INVALID_ARGUMENTS
;
891 /* Remember the bits which were specified (mask)
892 * and their new values (new_cfg).
898 /* clear previous values of those bits, save new values */
900 int old_cfg
= jtag_get_reset_config();
904 jtag_set_reset_config(new_cfg
);
906 new_cfg
= jtag_get_reset_config();
910 * Display the (now-)current reset mode
914 /* minimal JTAG has neither SRST nor TRST (so that's the default) */
915 switch (new_cfg
& (RESET_HAS_TRST
| RESET_HAS_SRST
)) {
917 modes
[0] = "srst_only";
920 modes
[0] = "trst_only";
922 case RESET_TRST_AND_SRST
:
923 modes
[0] = "trst_and_srst";
930 /* normally SRST and TRST are decoupled; but bugs happen ... */
931 switch (new_cfg
& (RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
)) {
932 case RESET_SRST_PULLS_TRST
:
933 modes
[1] = "srst_pulls_trst";
935 case RESET_TRST_PULLS_SRST
:
936 modes
[1] = "trst_pulls_srst";
938 case RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
:
939 modes
[1] = "combined";
942 modes
[1] = "separate";
946 /* TRST-less connectors include Altera, Xilinx, and minimal JTAG */
947 if (new_cfg
& RESET_HAS_TRST
) {
948 if (new_cfg
& RESET_TRST_OPEN_DRAIN
)
949 modes
[3] = " trst_open_drain";
951 modes
[3] = " trst_push_pull";
955 /* SRST-less connectors include TI-14, Xilinx, and minimal JTAG */
956 if (new_cfg
& RESET_HAS_SRST
) {
957 if (new_cfg
& RESET_SRST_NO_GATING
)
958 modes
[2] = " srst_nogate";
960 modes
[2] = " srst_gates_jtag";
962 if (new_cfg
& RESET_SRST_PUSH_PULL
)
963 modes
[4] = " srst_push_pull";
965 modes
[4] = " srst_open_drain";
971 command_print(cmd_ctx
, "%s %s%s%s%s",
973 modes
[2], modes
[3], modes
[4]);
978 static int handle_jtag_nsrst_delay_command(struct command_context_s
*cmd_ctx
,
979 char *cmd
, char **args
, int argc
)
982 return ERROR_COMMAND_SYNTAX_ERROR
;
986 COMMAND_PARSE_NUMBER(uint
, args
[0], delay
);
988 jtag_set_nsrst_delay(delay
);
990 command_print(cmd_ctx
, "jtag_nsrst_delay: %u", jtag_get_nsrst_delay());
994 static int handle_jtag_ntrst_delay_command(struct command_context_s
*cmd_ctx
,
995 char *cmd
, char **args
, int argc
)
998 return ERROR_COMMAND_SYNTAX_ERROR
;
1002 COMMAND_PARSE_NUMBER(uint
, args
[0], delay
);
1004 jtag_set_ntrst_delay(delay
);
1006 command_print(cmd_ctx
, "jtag_ntrst_delay: %u", jtag_get_ntrst_delay());
1010 static int handle_jtag_nsrst_assert_width_command(struct command_context_s
*cmd_ctx
,
1011 char *cmd
, char **args
, int argc
)
1014 return ERROR_COMMAND_SYNTAX_ERROR
;
1018 COMMAND_PARSE_NUMBER(uint
, args
[0], delay
);
1020 jtag_set_nsrst_assert_width(delay
);
1022 command_print(cmd_ctx
, "jtag_nsrst_assert_width: %u", jtag_get_nsrst_assert_width());
1026 static int handle_jtag_ntrst_assert_width_command(struct command_context_s
*cmd_ctx
,
1027 char *cmd
, char **args
, int argc
)
1030 return ERROR_COMMAND_SYNTAX_ERROR
;
1034 COMMAND_PARSE_NUMBER(uint
, args
[0], delay
);
1036 jtag_set_ntrst_assert_width(delay
);
1038 command_print(cmd_ctx
, "jtag_ntrst_assert_width: %u", jtag_get_ntrst_assert_width());
1042 static int handle_jtag_khz_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1045 return ERROR_COMMAND_SYNTAX_ERROR
;
1047 int retval
= ERROR_OK
;
1051 COMMAND_PARSE_NUMBER(uint
, args
[0], khz
);
1053 retval
= jtag_config_khz(khz
);
1054 if (ERROR_OK
!= retval
)
1058 int cur_speed
= jtag_get_speed_khz();
1059 retval
= jtag_get_speed_readable(&cur_speed
);
1060 if (ERROR_OK
!= retval
)
1064 command_print(cmd_ctx
, "%d kHz", cur_speed
);
1066 command_print(cmd_ctx
, "RCLK - adaptive");
1071 static int handle_jtag_rclk_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1074 return ERROR_COMMAND_SYNTAX_ERROR
;
1076 int retval
= ERROR_OK
;
1080 COMMAND_PARSE_NUMBER(uint
, args
[0], khz
);
1082 retval
= jtag_config_rclk(khz
);
1083 if (ERROR_OK
!= retval
)
1087 int cur_khz
= jtag_get_speed_khz();
1088 retval
= jtag_get_speed_readable(&cur_khz
);
1089 if (ERROR_OK
!= retval
)
1093 command_print(cmd_ctx
, "RCLK not supported - fallback to %d kHz", cur_khz
);
1095 command_print(cmd_ctx
, "RCLK - adaptive");
1100 static int handle_jtag_reset_command(struct command_context_s
*cmd_ctx
,
1101 char *cmd
, char **args
, int argc
)
1104 return ERROR_COMMAND_SYNTAX_ERROR
;
1107 if (args
[0][0] == '1')
1109 else if (args
[0][0] == '0')
1112 return ERROR_COMMAND_SYNTAX_ERROR
;
1115 if (args
[1][0] == '1')
1117 else if (args
[1][0] == '0')
1120 return ERROR_COMMAND_SYNTAX_ERROR
;
1122 if (jtag_interface_init(cmd_ctx
) != ERROR_OK
)
1123 return ERROR_JTAG_INIT_FAILED
;
1125 jtag_add_reset(trst
, srst
);
1126 return jtag_execute_queue();
1129 static int handle_runtest_command(struct command_context_s
*cmd_ctx
,
1130 char *cmd
, char **args
, int argc
)
1133 return ERROR_COMMAND_SYNTAX_ERROR
;
1135 unsigned num_clocks
;
1136 COMMAND_PARSE_NUMBER(uint
, args
[0], num_clocks
);
1138 jtag_add_runtest(num_clocks
, TAP_IDLE
);
1139 return jtag_execute_queue();
1143 * For "irscan" or "drscan" commands, the "end" (really, "next") state
1144 * should be stable ... and *NOT* a shift state, otherwise free-running
1145 * jtag clocks could change the values latched by the update state.
1146 * Not surprisingly, this is the same constraint as SVF; the "irscan"
1147 * and "drscan" commands are a write-only subset of what SVF provides.
1149 static bool scan_is_safe(tap_state_t state
)
1164 static int handle_irscan_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1167 scan_field_t
*fields
;
1169 tap_state_t endstate
;
1171 if ((argc
< 2) || (argc
% 2))
1173 return ERROR_COMMAND_SYNTAX_ERROR
;
1176 /* optional "-endstate" "statename" at the end of the arguments,
1177 * so that e.g. IRPAUSE can let us load the data register before
1178 * entering RUN/IDLE to execute the instruction we load here.
1180 endstate
= TAP_IDLE
;
1183 /* have at least one pair of numbers. */
1184 /* is last pair the magic text? */
1185 if (strcmp("-endstate", args
[argc
- 2]) == 0) {
1186 endstate
= tap_state_by_name(args
[argc
- 1]);
1187 if (endstate
== TAP_INVALID
)
1188 return ERROR_COMMAND_SYNTAX_ERROR
;
1189 if (!scan_is_safe(endstate
))
1190 LOG_WARNING("unstable irscan endstate \"%s\"",
1196 int num_fields
= argc
/ 2;
1197 size_t fields_len
= sizeof(scan_field_t
) * num_fields
;
1198 fields
= malloc(fields_len
);
1199 memset(fields
, 0, fields_len
);
1202 for (i
= 0; i
< num_fields
; i
++)
1204 tap
= jtag_tap_by_string(args
[i
*2]);
1208 for (j
= 0; j
< i
; j
++)
1209 free(fields
[j
].out_value
);
1211 command_print(cmd_ctx
, "Tap: %s unknown", args
[i
*2]);
1215 int field_size
= tap
->ir_length
;
1216 fields
[i
].tap
= tap
;
1217 fields
[i
].num_bits
= field_size
;
1218 fields
[i
].out_value
= malloc(CEIL(field_size
, 8));
1221 retval
= parse_u32(args
[i
* 2 + 1], &value
);
1222 if (ERROR_OK
!= retval
)
1224 buf_set_u32(fields
[i
].out_value
, 0, field_size
, value
);
1225 fields
[i
].in_value
= NULL
;
1228 /* did we have an endstate? */
1229 jtag_add_ir_scan(num_fields
, fields
, endstate
);
1231 retval
= jtag_execute_queue();
1234 for (i
= 0; i
< num_fields
; i
++)
1236 if (NULL
!= fields
[i
].out_value
)
1237 free(fields
[i
].out_value
);
1245 static int Jim_Command_drscan(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *args
)
1248 scan_field_t
*fields
;
1250 int field_count
= 0;
1253 tap_state_t endstate
;
1256 * args[2] = num_bits
1257 * args[3] = hex string
1258 * ... repeat num bits and hex string ...
1261 * args[N-2] = "-endstate"
1262 * args[N-1] = statename
1264 if ((argc
< 4) || ((argc
% 2) != 0))
1266 Jim_WrongNumArgs(interp
, 1, args
, "wrong arguments");
1270 endstate
= TAP_IDLE
;
1272 script_debug(interp
, "drscan", argc
, args
);
1274 /* validate arguments as numbers */
1276 for (i
= 2; i
< argc
; i
+= 2)
1281 e
= Jim_GetLong(interp
, args
[i
], &bits
);
1282 /* If valid - try next arg */
1287 /* Not valid.. are we at the end? */
1288 if (((i
+ 2) != argc
)) {
1289 /* nope, then error */
1293 /* it could be: "-endstate FOO"
1294 * e.g. DRPAUSE so we can issue more instructions
1295 * before entering RUN/IDLE and executing them.
1298 /* get arg as a string. */
1299 cp
= Jim_GetString(args
[i
], NULL
);
1300 /* is it the magic? */
1301 if (0 == strcmp("-endstate", cp
)) {
1302 /* is the statename valid? */
1303 cp
= Jim_GetString(args
[i
+ 1], NULL
);
1305 /* see if it is a valid state name */
1306 endstate
= tap_state_by_name(cp
);
1308 /* update the error message */
1309 Jim_SetResult_sprintf(interp
,"endstate: %s invalid", cp
);
1311 if (!scan_is_safe(endstate
))
1312 LOG_WARNING("drscan with unsafe "
1313 "endstate \"%s\"", cp
);
1315 /* valid - so clear the error */
1317 /* and remove the last 2 args */
1322 /* Still an error? */
1324 return e
; /* too bad */
1326 } /* validate args */
1328 tap
= jtag_tap_by_jim_obj(interp
, args
[1]);
1333 num_fields
= (argc
-2)/2;
1334 fields
= malloc(sizeof(scan_field_t
) * num_fields
);
1335 for (i
= 2; i
< argc
; i
+= 2)
1341 Jim_GetLong(interp
, args
[i
], &bits
);
1342 str
= Jim_GetString(args
[i
+ 1], &len
);
1344 fields
[field_count
].tap
= tap
;
1345 fields
[field_count
].num_bits
= bits
;
1346 fields
[field_count
].out_value
= malloc(CEIL(bits
, 8));
1347 str_to_buf(str
, len
, fields
[field_count
].out_value
, bits
, 0);
1348 fields
[field_count
].in_value
= fields
[field_count
].out_value
;
1352 jtag_add_dr_scan(num_fields
, fields
, endstate
);
1354 retval
= jtag_execute_queue();
1355 if (retval
!= ERROR_OK
)
1357 Jim_SetResultString(interp
, "drscan: jtag execute failed",-1);
1362 Jim_Obj
*list
= Jim_NewListObj(interp
, NULL
, 0);
1363 for (i
= 2; i
< argc
; i
+= 2)
1368 Jim_GetLong(interp
, args
[i
], &bits
);
1369 str
= buf_to_str(fields
[field_count
].in_value
, bits
, 16);
1370 free(fields
[field_count
].out_value
);
1372 Jim_ListAppendElement(interp
, list
, Jim_NewStringObj(interp
, str
, strlen(str
)));
1377 Jim_SetResult(interp
, list
);
1385 static int Jim_Command_pathmove(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *args
)
1387 tap_state_t states
[8];
1389 if ((argc
< 2) || ((size_t)argc
> (sizeof(states
)/sizeof(*states
) + 1)))
1391 Jim_WrongNumArgs(interp
, 1, args
, "wrong arguments");
1395 script_debug(interp
, "pathmove", argc
, args
);
1398 for (i
= 0; i
< argc
-1; i
++)
1401 cp
= Jim_GetString(args
[i
+ 1], NULL
);
1402 states
[i
] = tap_state_by_name(cp
);
1405 /* update the error message */
1406 Jim_SetResult_sprintf(interp
,"endstate: %s invalid", cp
);
1411 if ((jtag_add_statemove(states
[0]) != ERROR_OK
) || (jtag_execute_queue()!= ERROR_OK
))
1413 Jim_SetResultString(interp
, "pathmove: jtag execute failed",-1);
1417 jtag_add_pathmove(argc
-2, states
+ 1);
1419 if (jtag_execute_queue()!= ERROR_OK
)
1421 Jim_SetResultString(interp
, "pathmove: failed",-1);
1429 static int Jim_Command_flush_count(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *args
)
1431 script_debug(interp
, "flush_count", argc
, args
);
1433 Jim_SetResult(interp
, Jim_NewIntObj(interp
, jtag_get_flush_queue_count()));
1439 static int handle_verify_ircapture_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1442 return ERROR_COMMAND_SYNTAX_ERROR
;
1446 if (strcmp(args
[0], "enable") == 0)
1447 jtag_set_verify_capture_ir(true);
1448 else if (strcmp(args
[0], "disable") == 0)
1449 jtag_set_verify_capture_ir(false);
1451 return ERROR_COMMAND_SYNTAX_ERROR
;
1454 const char *status
= jtag_will_verify_capture_ir() ? "enabled": "disabled";
1455 command_print(cmd_ctx
, "verify Capture-IR is %s", status
);
1460 static int handle_verify_jtag_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1463 return ERROR_COMMAND_SYNTAX_ERROR
;
1467 if (strcmp(args
[0], "enable") == 0)
1468 jtag_set_verify(true);
1469 else if (strcmp(args
[0], "disable") == 0)
1470 jtag_set_verify(false);
1472 return ERROR_COMMAND_SYNTAX_ERROR
;
1475 const char *status
= jtag_will_verify() ? "enabled": "disabled";
1476 command_print(cmd_ctx
, "verify jtag capture is %s", status
);
1481 static int handle_tms_sequence_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1484 return ERROR_COMMAND_SYNTAX_ERROR
;
1489 if (strcmp(args
[0], "short") == 0)
1490 use_new_table
= true;
1491 else if (strcmp(args
[0], "long") == 0)
1492 use_new_table
= false;
1494 return ERROR_COMMAND_SYNTAX_ERROR
;
1496 tap_use_new_tms_table(use_new_table
);
1499 command_print(cmd_ctx
, "tms sequence is %s",
1500 tap_uses_new_tms_table() ? "short": "long");
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)