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"
42 static const Jim_Nvp nvp_jtag_tap_event
[] = {
43 { .value
= JTAG_TAP_EVENT_ENABLE
, .name
= "tap-enable" },
44 { .value
= JTAG_TAP_EVENT_DISABLE
, .name
= "tap-disable" },
46 { .name
= NULL
, .value
= -1 }
49 /* jtag interfaces (parport, FTDI-USB, TI-USB, ...)
52 #if BUILD_ECOSBOARD == 1
53 extern jtag_interface_t zy1000_interface
;
54 #elif defined(BUILD_MINIDRIVER_DUMMY)
55 extern jtag_interface_t minidummy_interface
;
56 #else // standard drivers
57 #if BUILD_PARPORT == 1
58 extern jtag_interface_t parport_interface
;
62 extern jtag_interface_t dummy_interface
;
65 #if BUILD_FT2232_FTD2XX == 1
66 extern jtag_interface_t ft2232_interface
;
69 #if BUILD_FT2232_LIBFTDI == 1
70 extern jtag_interface_t ft2232_interface
;
73 #if BUILD_AMTJTAGACCEL == 1
74 extern jtag_interface_t amt_jtagaccel_interface
;
78 extern jtag_interface_t ep93xx_interface
;
81 #if BUILD_AT91RM9200 == 1
82 extern jtag_interface_t at91rm9200_interface
;
85 #if BUILD_GW16012 == 1
86 extern jtag_interface_t gw16012_interface
;
89 #if BUILD_PRESTO_LIBFTDI == 1 || BUILD_PRESTO_FTD2XX == 1
90 extern jtag_interface_t presto_interface
;
93 #if BUILD_USBPROG == 1
94 extern jtag_interface_t usbprog_interface
;
98 extern jtag_interface_t jlink_interface
;
101 #if BUILD_VSLLINK == 1
102 extern jtag_interface_t vsllink_interface
;
106 extern jtag_interface_t rlink_interface
;
109 #if BUILD_ARMJTAGEW == 1
110 extern jtag_interface_t armjtagew_interface
;
112 #endif // standard drivers
115 * The list of built-in JTAG interfaces, containing entries for those
116 * drivers that were enabled by the @c configure script.
118 * The list should be defined to contain either one minidriver interface
119 * or some number of standard driver interfaces, never both.
121 jtag_interface_t
*jtag_interfaces
[] = {
122 #if BUILD_ECOSBOARD == 1
124 #elif defined(BUILD_MINIDRIVER_DUMMY)
125 &minidummy_interface
,
126 #else // standard drivers
127 #if BUILD_PARPORT == 1
133 #if BUILD_FT2232_FTD2XX == 1
136 #if BUILD_FT2232_LIBFTDI == 1
139 #if BUILD_AMTJTAGACCEL == 1
140 &amt_jtagaccel_interface
,
142 #if BUILD_EP93XX == 1
145 #if BUILD_AT91RM9200 == 1
146 &at91rm9200_interface
,
148 #if BUILD_GW16012 == 1
151 #if BUILD_PRESTO_LIBFTDI == 1 || BUILD_PRESTO_FTD2XX == 1
154 #if BUILD_USBPROG == 1
160 #if BUILD_VSLLINK == 1
166 #if BUILD_ARMJTAGEW == 1
167 &armjtagew_interface
,
169 #endif // standard drivers
173 extern jtag_interface_t
*jtag_interface
;
176 static int handle_interface_list_command(struct command_context_s
*cmd_ctx
,
177 char *cmd
, char **args
, int argc
);
178 static int handle_interface_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
179 static int handle_jtag_speed_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
180 static int handle_jtag_khz_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
181 static int handle_jtag_device_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
182 static int handle_reset_config_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
183 static int handle_jtag_nsrst_delay_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
184 static int handle_jtag_ntrst_delay_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
186 static int handle_scan_chain_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
188 static int handle_jtag_reset_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
189 static int handle_runtest_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
190 static int handle_irscan_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
191 static int Jim_Command_drscan(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
);
192 static int Jim_Command_pathmove(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
);
193 static int Jim_Command_flush_count(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *args
);
195 static int handle_verify_ircapture_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
196 static int handle_verify_jtag_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
197 static int handle_tms_sequence_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
199 extern int jtag_examine_chain(void);
200 extern int jtag_validate_chain(void);
202 enum jtag_tap_cfg_param
{
206 static Jim_Nvp nvp_config_opts
[] = {
207 { .name
= "-event", .value
= JCFG_EVENT
},
209 { .name
= NULL
, .value
= -1 }
212 static int jtag_tap_configure_cmd( Jim_GetOptInfo
*goi
, jtag_tap_t
* tap
)
218 /* parse config or cget options */
219 while (goi
->argc
> 0) {
220 Jim_SetEmptyResult (goi
->interp
);
222 e
= Jim_GetOpt_Nvp(goi
, nvp_config_opts
, &n
);
224 Jim_GetOpt_NvpUnknown(goi
, nvp_config_opts
, 0);
230 if (goi
->argc
== 0) {
231 Jim_WrongNumArgs( goi
->interp
, goi
->argc
, goi
->argv
, "-event ?event-name? ..." );
235 e
= Jim_GetOpt_Nvp( goi
, nvp_jtag_tap_event
, &n
);
237 Jim_GetOpt_NvpUnknown(goi
, nvp_jtag_tap_event
, 1);
241 if (goi
->isconfigure
) {
242 if (goi
->argc
!= 1) {
243 Jim_WrongNumArgs(goi
->interp
, goi
->argc
, goi
->argv
, "-event ?event-name? ?EVENT-BODY?");
247 if (goi
->argc
!= 0) {
248 Jim_WrongNumArgs(goi
->interp
, goi
->argc
, goi
->argv
, "-event ?event-name?");
254 jtag_tap_event_action_t
*jteap
;
256 jteap
= tap
->event_action
;
257 /* replace existing? */
259 if (jteap
->event
== (enum jtag_tap_event
)n
->value
) {
265 if (goi
->isconfigure
) {
268 jteap
= calloc(1, sizeof (*jteap
));
270 jteap
->event
= n
->value
;
271 Jim_GetOpt_Obj( goi
, &o
);
273 Jim_DecrRefCount(interp
, jteap
->body
);
275 jteap
->body
= Jim_DuplicateObj(goi
->interp
, o
);
276 Jim_IncrRefCount(jteap
->body
);
278 /* add to head of event list */
279 jteap
->next
= tap
->event_action
;
280 tap
->event_action
= jteap
;
281 Jim_SetEmptyResult(goi
->interp
);
285 Jim_SetEmptyResult(goi
->interp
);
287 Jim_SetResult(goi
->interp
, Jim_DuplicateObj(goi
->interp
, jteap
->body
));
294 } /* while (goi->argc) */
299 static int is_bad_irval(int ir_length
, jim_wide w
)
309 static int jim_newtap_cmd( Jim_GetOptInfo
*goi
)
318 const Jim_Nvp opts
[] = {
319 #define NTAP_OPT_IRLEN 0
320 { .name
= "-irlen" , .value
= NTAP_OPT_IRLEN
},
321 #define NTAP_OPT_IRMASK 1
322 { .name
= "-irmask" , .value
= NTAP_OPT_IRMASK
},
323 #define NTAP_OPT_IRCAPTURE 2
324 { .name
= "-ircapture" , .value
= NTAP_OPT_IRCAPTURE
},
325 #define NTAP_OPT_ENABLED 3
326 { .name
= "-enable" , .value
= NTAP_OPT_ENABLED
},
327 #define NTAP_OPT_DISABLED 4
328 { .name
= "-disable" , .value
= NTAP_OPT_DISABLED
},
329 #define NTAP_OPT_EXPECTED_ID 5
330 { .name
= "-expected-id" , .value
= NTAP_OPT_EXPECTED_ID
},
331 { .name
= NULL
, .value
= -1 },
334 pTap
= calloc(1, sizeof(jtag_tap_t
));
336 Jim_SetResult_sprintf(goi
->interp
, "no memory");
341 * we expect CHIP + TAP + OPTIONS
344 Jim_SetResult_sprintf(goi
->interp
, "Missing CHIP TAP OPTIONS ....");
347 Jim_GetOpt_String( goi
, &cp
, NULL
);
348 pTap
->chip
= strdup(cp
);
350 Jim_GetOpt_String( goi
, &cp
, NULL
);
351 pTap
->tapname
= strdup(cp
);
353 /* name + dot + name + null */
354 x
= strlen(pTap
->chip
) + 1 + strlen(pTap
->tapname
) + 1;
356 sprintf( cp
, "%s.%s", pTap
->chip
, pTap
->tapname
);
357 pTap
->dotted_name
= cp
;
359 LOG_DEBUG("Creating New Tap, Chip: %s, Tap: %s, Dotted: %s, %d params",
360 pTap
->chip
, pTap
->tapname
, pTap
->dotted_name
, goi
->argc
);
362 /* deal with options */
363 #define NTREQ_IRLEN 1
364 #define NTREQ_IRCAPTURE 2
365 #define NTREQ_IRMASK 4
367 /* clear them as we find them */
368 reqbits
= (NTREQ_IRLEN
| NTREQ_IRCAPTURE
| NTREQ_IRMASK
);
371 e
= Jim_GetOpt_Nvp( goi
, opts
, &n
);
373 Jim_GetOpt_NvpUnknown( goi
, opts
, 0 );
376 LOG_DEBUG("Processing option: %s", n
->name
);
378 case NTAP_OPT_ENABLED
:
379 pTap
->disabled_after_reset
= false;
381 case NTAP_OPT_DISABLED
:
382 pTap
->disabled_after_reset
= true;
384 case NTAP_OPT_EXPECTED_ID
:
386 u32
*new_expected_ids
;
388 e
= Jim_GetOpt_Wide( goi
, &w
);
390 Jim_SetResult_sprintf(goi
->interp
, "option: %s bad parameter", n
->name
);
394 new_expected_ids
= malloc(sizeof(u32
) * (pTap
->expected_ids_cnt
+ 1));
395 if (new_expected_ids
== NULL
) {
396 Jim_SetResult_sprintf( goi
->interp
, "no memory");
400 memcpy(new_expected_ids
, pTap
->expected_ids
, sizeof(u32
) * pTap
->expected_ids_cnt
);
402 new_expected_ids
[pTap
->expected_ids_cnt
] = w
;
404 free(pTap
->expected_ids
);
405 pTap
->expected_ids
= new_expected_ids
;
406 pTap
->expected_ids_cnt
++;
410 case NTAP_OPT_IRMASK
:
411 case NTAP_OPT_IRCAPTURE
:
412 e
= Jim_GetOpt_Wide( goi
, &w
);
414 Jim_SetResult_sprintf( goi
->interp
, "option: %s bad parameter", n
->name
);
419 if (w
> (jim_wide
) (8 * sizeof(pTap
->ir_capture_value
)))
420 LOG_WARNING("huge IR length %d", (int) w
);
422 reqbits
&= (~(NTREQ_IRLEN
));
424 case NTAP_OPT_IRMASK
:
425 if (is_bad_irval(pTap
->ir_length
, w
)) {
426 LOG_ERROR("IR mask %x too big",
430 pTap
->ir_capture_mask
= w
;
431 reqbits
&= (~(NTREQ_IRMASK
));
433 case NTAP_OPT_IRCAPTURE
:
434 if (is_bad_irval(pTap
->ir_length
, w
)) {
435 LOG_ERROR("IR capture %x too big",
439 pTap
->ir_capture_value
= w
;
440 reqbits
&= (~(NTREQ_IRCAPTURE
));
443 } /* switch(n->value) */
444 } /* while( goi->argc ) */
446 /* default is enabled-after-reset */
447 pTap
->enabled
= !pTap
->disabled_after_reset
;
449 /* Did all the required option bits get cleared? */
456 Jim_SetResult_sprintf(goi
->interp
,
457 "newtap: %s missing required parameters",
463 static void jtag_tap_handle_event( jtag_tap_t
* tap
, enum jtag_tap_event e
)
465 jtag_tap_event_action_t
* jteap
;
468 jteap
= tap
->event_action
;
472 if (jteap
->event
== e
) {
474 LOG_DEBUG( "JTAG tap: %s event: %d (%s) action: %s\n",
477 Jim_Nvp_value2name_simple(nvp_jtag_tap_event
, e
)->name
,
478 Jim_GetString(jteap
->body
, NULL
) );
479 if (Jim_EvalObj(interp
, jteap
->body
) != JIM_OK
) {
480 Jim_PrintErrorMessage(interp
);
482 /* NOTE: we currently assume the handlers
483 * can't fail. That presumes later code
484 * will be verifying the scan chains ...
486 tap
->enabled
= (e
== JTAG_TAP_EVENT_ENABLE
);
494 LOG_DEBUG( "event %d %s - no action",
496 Jim_Nvp_value2name_simple( nvp_jtag_tap_event
, e
)->name
);
501 static int jim_jtag_command( Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
507 struct command_context_s
*context
;
515 JTAG_CMD_TAPISENABLED
,
520 const Jim_Nvp jtag_cmds
[] = {
521 { .name
= "interface" , .value
= JTAG_CMD_INTERFACE
},
522 { .name
= "arp_init-reset", .value
= JTAG_CMD_INIT_RESET
},
523 { .name
= "newtap" , .value
= JTAG_CMD_NEWTAP
},
524 { .name
= "tapisenabled" , .value
= JTAG_CMD_TAPISENABLED
},
525 { .name
= "tapenable" , .value
= JTAG_CMD_TAPENABLE
},
526 { .name
= "tapdisable" , .value
= JTAG_CMD_TAPDISABLE
},
527 { .name
= "configure" , .value
= JTAG_CMD_CONFIGURE
},
528 { .name
= "cget" , .value
= JTAG_CMD_CGET
},
530 { .name
= NULL
, .value
= -1 },
533 context
= Jim_GetAssocData(interp
, "context");
534 /* go past the command */
535 Jim_GetOpt_Setup( &goi
, interp
, argc
-1, argv
+1 );
537 e
= Jim_GetOpt_Nvp( &goi
, jtag_cmds
, &n
);
539 Jim_GetOpt_NvpUnknown( &goi
, jtag_cmds
, 0 );
542 Jim_SetEmptyResult( goi
.interp
);
544 case JTAG_CMD_INTERFACE
:
545 /* return the name of the interface */
546 /* TCL code might need to know the exact type... */
547 /* FUTURE: we allow this as a means to "set" the interface. */
549 Jim_WrongNumArgs( goi
.interp
, 1, goi
.argv
-1, "(no params)");
552 Jim_SetResultString( goi
.interp
, jtag_interface
->name
, -1 );
554 case JTAG_CMD_INIT_RESET
:
556 Jim_WrongNumArgs( goi
.interp
, 1, goi
.argv
-1, "(no params)");
559 e
= jtag_init_reset(context
);
561 Jim_SetResult_sprintf( goi
.interp
, "error: %d", e
);
565 case JTAG_CMD_NEWTAP
:
566 return jim_newtap_cmd( &goi
);
568 case JTAG_CMD_TAPISENABLED
:
569 case JTAG_CMD_TAPENABLE
:
570 case JTAG_CMD_TAPDISABLE
:
572 Jim_SetResultString( goi
.interp
, "Too many parameters",-1 );
579 t
= jtag_tap_by_jim_obj(goi
.interp
, goi
.argv
[0]);
584 case JTAG_CMD_TAPISENABLED
:
586 case JTAG_CMD_TAPENABLE
:
589 jtag_tap_handle_event(t
, JTAG_TAP_EVENT_ENABLE
);
593 /* FIXME add JTAG sanity checks, w/o TLR
594 * - scan chain length grew by one (this)
595 * - IDs and IR lengths are as expected
598 case JTAG_CMD_TAPDISABLE
:
601 jtag_tap_handle_event(t
, JTAG_TAP_EVENT_DISABLE
);
605 /* FIXME add JTAG sanity checks, w/o TLR
606 * - scan chain length shrank by one (this)
607 * - IDs and IR lengths are as expected
612 Jim_SetResult(goi
.interp
, Jim_NewIntObj(goi
.interp
, e
));
619 Jim_WrongNumArgs( goi
.interp
, 0, NULL
, "?tap-name? -option ...");
626 Jim_GetOpt_Obj(&goi
, &o
);
627 t
= jtag_tap_by_jim_obj( goi
.interp
, o
);
633 return jtag_tap_configure_cmd( &goi
, t
);
637 case JTAG_CMD_CONFIGURE
:
639 Jim_WrongNumArgs( goi
.interp
, 0, NULL
, "?tap-name? -option ?VALUE? ...");
646 Jim_GetOpt_Obj(&goi
, &o
);
647 t
= jtag_tap_by_jim_obj( goi
.interp
, o
);
653 return jtag_tap_configure_cmd( &goi
, t
);
660 int jtag_register_commands(struct command_context_s
*cmd_ctx
)
662 register_jim( cmd_ctx
, "jtag", jim_jtag_command
, "perform jtag tap actions");
664 register_command(cmd_ctx
, NULL
, "interface", handle_interface_command
,
665 COMMAND_CONFIG
, "try to configure interface");
666 register_command(cmd_ctx
, NULL
,
667 "interface_list", &handle_interface_list_command
,
668 COMMAND_ANY
, "list all built-in interfaces");
669 register_command(cmd_ctx
, NULL
, "jtag_speed", handle_jtag_speed_command
,
670 COMMAND_ANY
, "(DEPRECATED) set jtag speed (if supported)");
671 register_command(cmd_ctx
, NULL
, "jtag_khz", handle_jtag_khz_command
,
672 COMMAND_ANY
, "set maximum jtag speed (if supported); "
673 "parameter is maximum khz, or 0 for adaptive clocking (RTCK).");
674 register_command(cmd_ctx
, NULL
, "jtag_device", handle_jtag_device_command
,
675 COMMAND_CONFIG
, "(DEPRECATED) jtag_device <ir_length> <ir_expected> <ir_mask>");
676 register_command(cmd_ctx
, NULL
, "reset_config", handle_reset_config_command
,
678 "[none/trst_only/srst_only/trst_and_srst] [srst_pulls_trst/trst_pulls_srst] [combined/separate] [trst_push_pull/trst_open_drain] [srst_push_pull/srst_open_drain]");
679 register_command(cmd_ctx
, NULL
, "jtag_nsrst_delay", handle_jtag_nsrst_delay_command
,
680 COMMAND_ANY
, "jtag_nsrst_delay <ms> - delay after deasserting srst in ms");
681 register_command(cmd_ctx
, NULL
, "jtag_ntrst_delay", handle_jtag_ntrst_delay_command
,
682 COMMAND_ANY
, "jtag_ntrst_delay <ms> - delay after deasserting trst in ms");
684 register_command(cmd_ctx
, NULL
, "scan_chain", handle_scan_chain_command
,
685 COMMAND_EXEC
, "print current scan chain configuration");
687 register_command(cmd_ctx
, NULL
, "jtag_reset", handle_jtag_reset_command
,
688 COMMAND_EXEC
, "toggle reset lines <trst> <srst>");
689 register_command(cmd_ctx
, NULL
, "runtest", handle_runtest_command
,
690 COMMAND_EXEC
, "move to Run-Test/Idle, and execute <num_cycles>");
691 register_command(cmd_ctx
, NULL
, "irscan", handle_irscan_command
,
692 COMMAND_EXEC
, "execute IR scan <device> <instr> [dev2] [instr2] ...");
693 register_jim(cmd_ctx
, "drscan", Jim_Command_drscan
, "execute DR scan <device> <num_bits> <value> <num_bits1> <value2> ...");
694 register_jim(cmd_ctx
, "flush_count", Jim_Command_flush_count
, "returns number of times the JTAG queue has been flushed");
695 register_jim(cmd_ctx
, "pathmove", Jim_Command_pathmove
, "move JTAG to state1 then to state2, state3, etc. <state1>,<state2>,<stat3>...");
697 register_command(cmd_ctx
, NULL
, "verify_ircapture", handle_verify_ircapture_command
,
698 COMMAND_ANY
, "verify value captured during Capture-IR <enable|disable>");
699 register_command(cmd_ctx
, NULL
, "verify_jtag", handle_verify_jtag_command
,
700 COMMAND_ANY
, "verify value capture <enable|disable>");
701 register_command(cmd_ctx
, NULL
, "tms_sequence", handle_tms_sequence_command
,
702 COMMAND_ANY
, "choose short(default) or long tms_sequence <short|long>");
706 static int default_khz(int khz
, int *jtag_speed
)
708 LOG_ERROR("Translation from khz to jtag_speed not implemented");
712 static int default_speed_div(int speed
, int *khz
)
714 LOG_ERROR("Translation from jtag_speed to khz not implemented");
718 static int default_power_dropout(int *dropout
)
720 *dropout
=0; /* by default we can't detect power dropout */
724 static int default_srst_asserted(int *srst_asserted
)
726 *srst_asserted
=0; /* by default we can't detect srst asserted */
730 static int handle_interface_command(struct command_context_s
*cmd_ctx
,
731 char *cmd
, char **args
, int argc
)
733 /* check whether the interface is already configured */
736 LOG_WARNING("Interface already configured, ignoring");
740 /* interface name is a mandatory argument */
741 if (argc
!= 1 || args
[0][0] == '\0')
742 return ERROR_COMMAND_SYNTAX_ERROR
;
744 for (unsigned i
= 0; NULL
!= jtag_interfaces
[i
]; i
++)
746 if (strcmp(args
[0], jtag_interfaces
[i
]->name
) != 0)
749 int retval
= jtag_interfaces
[i
]->register_commands(cmd_ctx
);
750 if (ERROR_OK
!= retval
)
753 jtag_interface
= jtag_interfaces
[i
];
755 if (jtag_interface
->khz
== NULL
)
756 jtag_interface
->khz
= default_khz
;
757 if (jtag_interface
->speed_div
== NULL
)
758 jtag_interface
->speed_div
= default_speed_div
;
759 if (jtag_interface
->power_dropout
== NULL
)
760 jtag_interface
->power_dropout
= default_power_dropout
;
761 if (jtag_interface
->srst_asserted
== NULL
)
762 jtag_interface
->srst_asserted
= default_srst_asserted
;
767 /* no valid interface was found (i.e. the configuration option,
768 * didn't match one of the compiled-in interfaces
770 LOG_ERROR("The specified JTAG interface was not found (%s)", args
[0]);
771 handle_interface_list_command(cmd_ctx
, cmd
, args
, argc
);
772 return ERROR_JTAG_INVALID_INTERFACE
;
775 static int handle_interface_list_command(struct command_context_s
*cmd_ctx
,
776 char *cmd
, char **args
, int argc
)
778 if (strcmp(cmd
, "interface_list") == 0 && argc
> 0)
779 return ERROR_COMMAND_SYNTAX_ERROR
;
781 command_print(cmd_ctx
, "The following JTAG interfaces are available:");
782 for (unsigned i
= 0; NULL
!= jtag_interfaces
[i
]; i
++)
784 const char *name
= jtag_interfaces
[i
]->name
;
785 command_print(cmd_ctx
, "%u: %s", i
+ 1, name
);
791 static int handle_jtag_device_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
795 Jim_Obj
*newargs
[ 10 ];
799 * argv[ 0] = ir length
800 * argv[ 1] = ir capture
802 * argv[ 3] = not actually used by anything but in the docs
806 command_print( cmd_ctx
, "OLD DEPRECATED SYNTAX: Please use the NEW syntax");
809 command_print( cmd_ctx
, "OLD SYNTAX: DEPRECATED - translating to new syntax");
810 command_print( cmd_ctx
, "jtag newtap CHIP TAP -irlen %s -ircapture %s -irvalue %s",
814 command_print( cmd_ctx
, "Example: STM32 has 2 taps, the cortexM3(len4) + boundaryscan(len5)");
815 command_print( cmd_ctx
, "jtag newtap stm32 cortexm3 ....., thus creating the tap: \"stm32.cortexm3\"");
816 command_print( cmd_ctx
, "jtag newtap stm32 boundary ....., and the tap: \"stm32.boundary\"");
817 command_print( cmd_ctx
, "And then refer to the taps by the dotted name.");
819 newargs
[0] = Jim_NewStringObj( interp
, "jtag", -1 );
820 newargs
[1] = Jim_NewStringObj( interp
, "newtap", -1 );
821 sprintf( buf
, "chip%d", jtag_tap_count() );
822 newargs
[2] = Jim_NewStringObj( interp
, buf
, -1 );
823 sprintf( buf
, "tap%d", jtag_tap_count() );
824 newargs
[3] = Jim_NewStringObj( interp
, buf
, -1 );
825 newargs
[4] = Jim_NewStringObj( interp
, "-irlen", -1 );
826 newargs
[5] = Jim_NewStringObj( interp
, args
[0], -1 );
827 newargs
[6] = Jim_NewStringObj( interp
, "-ircapture", -1 );
828 newargs
[7] = Jim_NewStringObj( interp
, args
[1], -1 );
829 newargs
[8] = Jim_NewStringObj( interp
, "-irmask", -1 );
830 newargs
[9] = Jim_NewStringObj( interp
, args
[2], -1 );
832 command_print( cmd_ctx
, "NEW COMMAND:");
833 sprintf( buf
, "%s %s %s %s %s %s %s %s %s %s",
834 Jim_GetString( newargs
[0], NULL
),
835 Jim_GetString( newargs
[1], NULL
),
836 Jim_GetString( newargs
[2], NULL
),
837 Jim_GetString( newargs
[3], NULL
),
838 Jim_GetString( newargs
[4], NULL
),
839 Jim_GetString( newargs
[5], NULL
),
840 Jim_GetString( newargs
[6], NULL
),
841 Jim_GetString( newargs
[7], NULL
),
842 Jim_GetString( newargs
[8], NULL
),
843 Jim_GetString( newargs
[9], NULL
) );
845 e
= jim_jtag_command( interp
, 10, newargs
);
847 command_print( cmd_ctx
, "%s", Jim_GetString( Jim_GetResult(interp
), NULL
) );
852 static int handle_scan_chain_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
856 tap
= jtag_all_taps();
857 command_print(cmd_ctx
, " TapName | Enabled | IdCode Expected IrLen IrCap IrMask Instr ");
858 command_print(cmd_ctx
, "---|--------------------|---------|------------|------------|------|------|------|---------");
861 u32 expected
, expected_mask
, cur_instr
, ii
;
862 expected
= buf_get_u32(tap
->expected
, 0, tap
->ir_length
);
863 expected_mask
= buf_get_u32(tap
->expected_mask
, 0, tap
->ir_length
);
864 cur_instr
= buf_get_u32(tap
->cur_instr
, 0, tap
->ir_length
);
866 command_print(cmd_ctx
,
867 "%2d | %-18s | %c | 0x%08x | 0x%08x | 0x%02x | 0x%02x | 0x%02x | 0x%02x",
868 tap
->abs_chain_position
,
870 tap
->enabled
? 'Y' : 'n',
872 (tap
->expected_ids_cnt
> 0 ? tap
->expected_ids
[0] : 0),
878 for (ii
= 1; ii
< tap
->expected_ids_cnt
; ii
++) {
879 command_print(cmd_ctx
, " | | | | 0x%08x | | | | ",
880 tap
->expected_ids
[ii
]);
889 static int handle_reset_config_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
895 return ERROR_COMMAND_SYNTAX_ERROR
;
897 /* Original versions cared about the order of these tokens:
898 * reset_config signals [combination [trst_type [srst_type]]]
899 * They also clobbered the previous configuration even on error.
901 * Here we don't care about the order, and only change values
902 * which have been explicitly specified.
904 for (; argc
; argc
--, args
++) {
909 m
= RESET_HAS_TRST
| RESET_HAS_SRST
;
910 if (strcmp(*args
, "none") == 0)
912 else if (strcmp(*args
, "trst_only") == 0)
913 tmp
= RESET_HAS_TRST
;
914 else if (strcmp(*args
, "srst_only") == 0)
915 tmp
= RESET_HAS_SRST
;
916 else if (strcmp(*args
, "trst_and_srst") == 0)
917 tmp
= RESET_HAS_TRST
| RESET_HAS_SRST
;
921 LOG_ERROR("extra reset_config %s spec (%s)",
923 return ERROR_INVALID_ARGUMENTS
;
928 /* combination (options for broken wiring) */
929 m
= RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
;
930 if (strcmp(*args
, "separate") == 0)
931 /* separate reset lines - default */;
932 else if (strcmp(*args
, "srst_pulls_trst") == 0)
933 tmp
|= RESET_SRST_PULLS_TRST
;
934 else if (strcmp(*args
, "trst_pulls_srst") == 0)
935 tmp
|= RESET_TRST_PULLS_SRST
;
936 else if (strcmp(*args
, "combined") == 0)
937 tmp
|= RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
;
941 LOG_ERROR("extra reset_config %s spec (%s)",
942 "combination", *args
);
943 return ERROR_INVALID_ARGUMENTS
;
948 /* trst_type (NOP without HAS_TRST) */
949 m
= RESET_TRST_OPEN_DRAIN
;
950 if (strcmp(*args
, "trst_open_drain") == 0)
951 tmp
|= RESET_TRST_OPEN_DRAIN
;
952 else if (strcmp(*args
, "trst_push_pull") == 0)
953 /* push/pull from adapter - default */;
957 LOG_ERROR("extra reset_config %s spec (%s)",
959 return ERROR_INVALID_ARGUMENTS
;
964 /* srst_type (NOP without HAS_SRST) */
965 m
|= RESET_SRST_PUSH_PULL
;
966 if (strcmp(*args
, "srst_push_pull") == 0)
967 tmp
|= RESET_SRST_PUSH_PULL
;
968 else if (strcmp(*args
, "srst_open_drain") == 0)
969 /* open drain from adapter - default */;
973 LOG_ERROR("extra reset_config %s spec (%s)",
975 return ERROR_INVALID_ARGUMENTS
;
980 /* caller provided nonsense; fail */
981 LOG_ERROR("unknown reset_config flag (%s)", *args
);
982 return ERROR_INVALID_ARGUMENTS
;
985 /* Remember the bits which were specified (mask)
986 * and their new values (new_cfg).
992 /* clear previous values of those bits, save new values */
993 enum reset_types old_cfg
= jtag_get_reset_config();
996 jtag_set_reset_config(new_cfg
);
1001 static int handle_jtag_nsrst_delay_command(struct command_context_s
*cmd_ctx
,
1002 char *cmd
, char **args
, int argc
)
1005 return ERROR_COMMAND_SYNTAX_ERROR
;
1009 int retval
= parse_uint(args
[0], &delay
);
1010 if (ERROR_OK
!= retval
)
1012 jtag_set_nsrst_delay(delay
);
1014 command_print(cmd_ctx
, "jtag_nsrst_delay: %u", jtag_get_nsrst_delay());
1018 static int handle_jtag_ntrst_delay_command(struct command_context_s
*cmd_ctx
,
1019 char *cmd
, char **args
, int argc
)
1022 return ERROR_COMMAND_SYNTAX_ERROR
;
1026 int retval
= parse_uint(args
[0], &delay
);
1027 if (ERROR_OK
!= retval
)
1029 jtag_set_ntrst_delay(delay
);
1031 command_print(cmd_ctx
, "jtag_ntrst_delay: %u", jtag_get_ntrst_delay());
1035 static int handle_jtag_speed_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1037 int retval
= ERROR_OK
;
1040 return ERROR_COMMAND_SYNTAX_ERROR
;
1043 LOG_DEBUG("handle jtag speed");
1045 unsigned cur_speed
= 0;
1046 int retval
= parse_uint(args
[0], &cur_speed
);
1047 if (ERROR_OK
!= retval
)
1049 retval
= jtag_set_speed(cur_speed
);
1052 command_print(cmd_ctx
, "jtag_speed: %d", jtag_get_speed());
1057 static int handle_jtag_khz_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1060 return ERROR_COMMAND_SYNTAX_ERROR
;
1062 int retval
= ERROR_OK
;
1066 int retval
= parse_uint(args
[0], &khz
);
1067 if (ERROR_OK
!= retval
)
1069 retval
= jtag_config_khz(khz
);
1070 if (ERROR_OK
!= retval
)
1074 int cur_speed
= jtag_get_speed_khz();
1075 retval
= jtag_get_speed_readable(&cur_speed
);
1076 if (ERROR_OK
!= retval
)
1080 command_print(cmd_ctx
, "%d kHz", cur_speed
);
1082 command_print(cmd_ctx
, "RCLK - adaptive");
1087 static int handle_jtag_reset_command(struct command_context_s
*cmd_ctx
,
1088 char *cmd
, char **args
, int argc
)
1091 return ERROR_COMMAND_SYNTAX_ERROR
;
1094 if (args
[0][0] == '1')
1096 else if (args
[0][0] == '0')
1099 return ERROR_COMMAND_SYNTAX_ERROR
;
1102 if (args
[1][0] == '1')
1104 else if (args
[1][0] == '0')
1107 return ERROR_COMMAND_SYNTAX_ERROR
;
1109 if (jtag_interface_init(cmd_ctx
) != ERROR_OK
)
1110 return ERROR_JTAG_INIT_FAILED
;
1112 jtag_add_reset(trst
, srst
);
1113 jtag_execute_queue();
1118 static int handle_runtest_command(struct command_context_s
*cmd_ctx
,
1119 char *cmd
, char **args
, int argc
)
1122 return ERROR_COMMAND_SYNTAX_ERROR
;
1124 unsigned num_clocks
;
1125 int retval
= parse_uint(args
[0], &num_clocks
);
1126 if (ERROR_OK
!= retval
)
1129 jtag_add_runtest(num_clocks
, jtag_get_end_state());
1130 jtag_execute_queue();
1136 * For "irscan" or "drscan" commands, the "end" (really, "next") state
1137 * should be stable ... and *NOT* a shift state, otherwise free-running
1138 * jtag clocks could change the values latched by the update state.
1140 static bool scan_is_safe(tap_state_t state
)
1155 static int handle_irscan_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1158 scan_field_t
*fields
;
1160 tap_state_t endstate
;
1162 if ((argc
< 2) || (argc
% 2))
1164 return ERROR_COMMAND_SYNTAX_ERROR
;
1167 /* optional "-endstate" "statename" at the end of the arguments,
1168 * so that e.g. IRPAUSE can let us load the data register before
1169 * entering RUN/IDLE to execute the instruction we load here.
1171 endstate
= TAP_IDLE
;
1174 /* have at least one pair of numbers. */
1175 /* is last pair the magic text? */
1176 if( 0 == strcmp( "-endstate", args
[ argc
- 2 ] ) ){
1179 cpA
= args
[ argc
-1 ];
1180 for( endstate
= 0 ; endstate
< TAP_NUM_STATES
; endstate
++ ){
1181 cpS
= tap_state_name( endstate
);
1182 if( 0 == strcmp( cpA
, cpS
) ){
1186 if( endstate
>= TAP_NUM_STATES
){
1187 return ERROR_COMMAND_SYNTAX_ERROR
;
1189 if (!scan_is_safe(endstate
))
1190 LOG_WARNING("irscan with unsafe "
1191 "endstate \"%s\"", cpA
);
1192 /* found - remove the last 2 args */
1198 int num_fields
= argc
/ 2;
1199 size_t fields_len
= sizeof(scan_field_t
) * num_fields
;
1200 fields
= malloc(fields_len
);
1201 memset(fields
, 0, fields_len
);
1204 for (i
= 0; i
< num_fields
; i
++)
1206 tap
= jtag_tap_by_string( args
[i
*2] );
1209 command_print( cmd_ctx
, "Tap: %s unknown", args
[i
*2] );
1212 int field_size
= tap
->ir_length
;
1213 fields
[i
].tap
= tap
;
1214 fields
[i
].num_bits
= field_size
;
1215 fields
[i
].out_value
= malloc(CEIL(field_size
, 8));
1218 retval
= parse_u32(args
[i
* 2 + 1], &value
);
1219 if (ERROR_OK
!= retval
)
1221 buf_set_u32(fields
[i
].out_value
, 0, field_size
, value
);
1222 fields
[i
].in_value
= NULL
;
1225 /* did we have an endstate? */
1226 jtag_add_ir_scan(num_fields
, fields
, endstate
);
1228 retval
= jtag_execute_queue();
1231 for (i
= 0; i
< num_fields
; i
++)
1233 if (NULL
!= fields
[i
].out_value
)
1234 free(fields
[i
].out_value
);
1242 static int Jim_Command_drscan(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *args
)
1245 scan_field_t
*fields
;
1247 int field_count
= 0;
1250 tap_state_t endstate
;
1253 * args[2] = num_bits
1254 * args[3] = hex string
1255 * ... repeat num bits and hex string ...
1258 * args[N-2] = "-endstate"
1259 * args[N-1] = statename
1261 if ((argc
< 4) || ((argc
% 2)!=0))
1263 Jim_WrongNumArgs(interp
, 1, args
, "wrong arguments");
1267 endstate
= TAP_IDLE
;
1269 script_debug(interp
, "drscan", argc
, args
);
1271 /* validate arguments as numbers */
1273 for (i
= 2; i
< argc
; i
+=2)
1278 e
= Jim_GetLong(interp
, args
[i
], &bits
);
1279 /* If valid - try next arg */
1284 /* Not valid.. are we at the end? */
1285 if ( ((i
+2) != argc
) ){
1286 /* nope, then error */
1290 /* it could be: "-endstate FOO"
1291 * e.g. DRPAUSE so we can issue more instructions
1292 * before entering RUN/IDLE and executing them.
1295 /* get arg as a string. */
1296 cp
= Jim_GetString( args
[i
], NULL
);
1297 /* is it the magic? */
1298 if( 0 == strcmp( "-endstate", cp
) ){
1299 /* is the statename valid? */
1300 cp
= Jim_GetString( args
[i
+1], NULL
);
1302 /* see if it is a valid state name */
1303 endstate
= tap_state_by_name(cp
);
1305 /* update the error message */
1306 Jim_SetResult_sprintf(interp
,"endstate: %s invalid", cp
);
1308 if (!scan_is_safe(endstate
))
1309 LOG_WARNING("drscan with unsafe "
1310 "endstate \"%s\"", cp
);
1312 /* valid - so clear the error */
1314 /* and remove the last 2 args */
1319 /* Still an error? */
1321 return e
; /* too bad */
1323 } /* validate args */
1325 tap
= jtag_tap_by_jim_obj( interp
, args
[1] );
1330 num_fields
=(argc
-2)/2;
1331 fields
= malloc(sizeof(scan_field_t
) * num_fields
);
1332 for (i
= 2; i
< argc
; i
+=2)
1338 Jim_GetLong(interp
, args
[i
], &bits
);
1339 str
= Jim_GetString(args
[i
+1], &len
);
1341 fields
[field_count
].tap
= tap
;
1342 fields
[field_count
].num_bits
= bits
;
1343 fields
[field_count
].out_value
= malloc(CEIL(bits
, 8));
1344 str_to_buf(str
, len
, fields
[field_count
].out_value
, bits
, 0);
1345 fields
[field_count
].in_value
= fields
[field_count
].out_value
;
1349 jtag_add_dr_scan(num_fields
, fields
, endstate
);
1351 retval
= jtag_execute_queue();
1352 if (retval
!= ERROR_OK
)
1354 Jim_SetResultString(interp
, "drscan: jtag execute failed",-1);
1359 Jim_Obj
*list
= Jim_NewListObj(interp
, NULL
, 0);
1360 for (i
= 2; i
< argc
; i
+=2)
1365 Jim_GetLong(interp
, args
[i
], &bits
);
1366 str
= buf_to_str(fields
[field_count
].in_value
, bits
, 16);
1367 free(fields
[field_count
].out_value
);
1369 Jim_ListAppendElement(interp
, list
, Jim_NewStringObj(interp
, str
, strlen(str
)));
1374 Jim_SetResult(interp
, list
);
1382 static int Jim_Command_pathmove(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *args
)
1384 tap_state_t states
[8];
1386 if ((argc
< 2) || ((size_t)argc
> (sizeof(states
)/sizeof(*states
)+1)))
1388 Jim_WrongNumArgs(interp
, 1, args
, "wrong arguments");
1392 script_debug(interp
, "pathmove", argc
, args
);
1395 for (i
=0; i
<argc
-1; i
++)
1398 cp
= Jim_GetString( args
[i
+1], NULL
);
1399 states
[i
] = tap_state_by_name(cp
);
1402 /* update the error message */
1403 Jim_SetResult_sprintf(interp
,"endstate: %s invalid", cp
);
1408 if ((jtag_add_statemove(states
[0]) != ERROR_OK
) || ( jtag_execute_queue()!= ERROR_OK
))
1410 Jim_SetResultString(interp
, "pathmove: jtag execute failed",-1);
1414 jtag_add_pathmove(argc
-2, states
+1);
1416 if (jtag_execute_queue()!= ERROR_OK
)
1418 Jim_SetResultString(interp
, "pathmove: failed",-1);
1426 static int Jim_Command_flush_count(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *args
)
1428 script_debug(interp
, "flush_count", argc
, args
);
1430 Jim_SetResult(interp
, Jim_NewIntObj(interp
, jtag_get_flush_queue_count()));
1436 static int handle_verify_ircapture_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1439 return ERROR_COMMAND_SYNTAX_ERROR
;
1443 if (strcmp(args
[0], "enable") == 0)
1444 jtag_set_verify_capture_ir(true);
1445 else if (strcmp(args
[0], "disable") == 0)
1446 jtag_set_verify_capture_ir(false);
1448 return ERROR_COMMAND_SYNTAX_ERROR
;
1451 const char *status
= jtag_will_verify_capture_ir() ? "enabled": "disabled";
1452 command_print(cmd_ctx
, "verify Capture-IR is %s", status
);
1457 static int handle_verify_jtag_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1460 return ERROR_COMMAND_SYNTAX_ERROR
;
1464 if (strcmp(args
[0], "enable") == 0)
1465 jtag_set_verify(true);
1466 else if (strcmp(args
[0], "disable") == 0)
1467 jtag_set_verify(false);
1469 return ERROR_COMMAND_SYNTAX_ERROR
;
1472 const char *status
= jtag_will_verify() ? "enabled": "disabled";
1473 command_print(cmd_ctx
, "verify jtag capture is %s", status
);
1478 static int handle_tms_sequence_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1481 return ERROR_COMMAND_SYNTAX_ERROR
;
1486 if (strcmp(args
[0], "short") == 0)
1487 use_new_table
= true;
1488 else if (strcmp(args
[0], "long") == 0)
1489 use_new_table
= false;
1491 return ERROR_COMMAND_SYNTAX_ERROR
;
1493 tap_use_new_tms_table(use_new_table
);
1496 command_print(cmd_ctx
, "tms sequence is %s",
1497 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)