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 struct jtag_interface_s
*jtag
;
174 extern jtag_interface_t
*jtag_interface
;
177 static int handle_interface_list_command(struct command_context_s
*cmd_ctx
,
178 char *cmd
, char **args
, int argc
);
179 static int handle_interface_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
180 static int handle_jtag_speed_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
181 static int handle_jtag_khz_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
182 static int handle_jtag_device_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
183 static int handle_reset_config_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
184 static int handle_jtag_nsrst_delay_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
185 static int handle_jtag_ntrst_delay_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
187 static int handle_scan_chain_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
189 static int handle_jtag_reset_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
190 static int handle_runtest_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
191 static int handle_irscan_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
192 static int Jim_Command_drscan(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) */
300 extern void jtag_tap_init(jtag_tap_t
*tap
);
301 extern void jtag_tap_free(jtag_tap_t
*tap
);
303 static int jim_newtap_cmd( Jim_GetOptInfo
*goi
)
312 const Jim_Nvp opts
[] = {
313 #define NTAP_OPT_IRLEN 0
314 { .name
= "-irlen" , .value
= NTAP_OPT_IRLEN
},
315 #define NTAP_OPT_IRMASK 1
316 { .name
= "-irmask" , .value
= NTAP_OPT_IRMASK
},
317 #define NTAP_OPT_IRCAPTURE 2
318 { .name
= "-ircapture" , .value
= NTAP_OPT_IRCAPTURE
},
319 #define NTAP_OPT_ENABLED 3
320 { .name
= "-enable" , .value
= NTAP_OPT_ENABLED
},
321 #define NTAP_OPT_DISABLED 4
322 { .name
= "-disable" , .value
= NTAP_OPT_DISABLED
},
323 #define NTAP_OPT_EXPECTED_ID 5
324 { .name
= "-expected-id" , .value
= NTAP_OPT_EXPECTED_ID
},
325 { .name
= NULL
, .value
= -1 },
328 pTap
= malloc( sizeof(jtag_tap_t
) );
329 memset( pTap
, 0, sizeof(*pTap
) );
331 Jim_SetResult_sprintf( goi
->interp
, "no memory");
335 * we expect CHIP + TAP + OPTIONS
338 Jim_SetResult_sprintf(goi
->interp
, "Missing CHIP TAP OPTIONS ....");
341 Jim_GetOpt_String( goi
, &cp
, NULL
);
342 pTap
->chip
= strdup(cp
);
344 Jim_GetOpt_String( goi
, &cp
, NULL
);
345 pTap
->tapname
= strdup(cp
);
347 /* name + dot + name + null */
348 x
= strlen(pTap
->chip
) + 1 + strlen(pTap
->tapname
) + 1;
350 sprintf( cp
, "%s.%s", pTap
->chip
, pTap
->tapname
);
351 pTap
->dotted_name
= cp
;
353 LOG_DEBUG("Creating New Tap, Chip: %s, Tap: %s, Dotted: %s, %d params",
354 pTap
->chip
, pTap
->tapname
, pTap
->dotted_name
, goi
->argc
);
356 /* default is enabled */
359 /* deal with options */
360 #define NTREQ_IRLEN 1
361 #define NTREQ_IRCAPTURE 2
362 #define NTREQ_IRMASK 4
364 /* clear them as we find them */
365 reqbits
= (NTREQ_IRLEN
| NTREQ_IRCAPTURE
| NTREQ_IRMASK
);
368 e
= Jim_GetOpt_Nvp( goi
, opts
, &n
);
370 Jim_GetOpt_NvpUnknown( goi
, opts
, 0 );
373 LOG_DEBUG("Processing option: %s", n
->name
);
375 case NTAP_OPT_ENABLED
:
378 case NTAP_OPT_DISABLED
:
381 case NTAP_OPT_EXPECTED_ID
:
383 u32
*new_expected_ids
;
385 e
= Jim_GetOpt_Wide( goi
, &w
);
387 Jim_SetResult_sprintf(goi
->interp
, "option: %s bad parameter", n
->name
);
391 new_expected_ids
= malloc(sizeof(u32
) * (pTap
->expected_ids_cnt
+ 1));
392 if (new_expected_ids
== NULL
) {
393 Jim_SetResult_sprintf( goi
->interp
, "no memory");
397 memcpy(new_expected_ids
, pTap
->expected_ids
, sizeof(u32
) * pTap
->expected_ids_cnt
);
399 new_expected_ids
[pTap
->expected_ids_cnt
] = w
;
401 free(pTap
->expected_ids
);
402 pTap
->expected_ids
= new_expected_ids
;
403 pTap
->expected_ids_cnt
++;
407 case NTAP_OPT_IRMASK
:
408 case NTAP_OPT_IRCAPTURE
:
409 e
= Jim_GetOpt_Wide( goi
, &w
);
411 Jim_SetResult_sprintf( goi
->interp
, "option: %s bad parameter", n
->name
);
414 if( (w
< 0) || (w
> 0xffff) ){
416 Jim_SetResult_sprintf( goi
->interp
, "option: %s - wacky value: %d (0x%x)",
417 n
->name
, (int)(w
), (int)(w
));
423 reqbits
&= (~(NTREQ_IRLEN
));
425 case NTAP_OPT_IRMASK
:
426 pTap
->ir_capture_mask
= w
;
427 reqbits
&= (~(NTREQ_IRMASK
));
429 case NTAP_OPT_IRCAPTURE
:
430 pTap
->ir_capture_value
= w
;
431 reqbits
&= (~(NTREQ_IRCAPTURE
));
434 } /* switch(n->value) */
435 } /* while( goi->argc ) */
437 /* Did all the required option bits get cleared? */
444 Jim_SetResult_sprintf(goi
->interp
,
445 "newtap: %s missing required parameters",
451 static void jtag_tap_handle_event( jtag_tap_t
* tap
, enum jtag_tap_event e
)
453 jtag_tap_event_action_t
* jteap
;
456 jteap
= tap
->event_action
;
460 if (jteap
->event
== e
) {
462 LOG_DEBUG( "JTAG tap: %s event: %d (%s) action: %s\n",
465 Jim_Nvp_value2name_simple(nvp_jtag_tap_event
, e
)->name
,
466 Jim_GetString(jteap
->body
, NULL
) );
467 if (Jim_EvalObj(interp
, jteap
->body
) != JIM_OK
) {
468 Jim_PrintErrorMessage(interp
);
476 LOG_DEBUG( "event %d %s - no action",
478 Jim_Nvp_value2name_simple( nvp_jtag_tap_event
, e
)->name
);
483 static int jim_jtag_command( Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
489 struct command_context_s
*context
;
497 JTAG_CMD_TAPISENABLED
,
502 const Jim_Nvp jtag_cmds
[] = {
503 { .name
= "interface" , .value
= JTAG_CMD_INTERFACE
},
504 { .name
= "arp_init-reset", .value
= JTAG_CMD_INIT_RESET
},
505 { .name
= "newtap" , .value
= JTAG_CMD_NEWTAP
},
506 { .name
= "tapisenabled" , .value
= JTAG_CMD_TAPISENABLED
},
507 { .name
= "tapenable" , .value
= JTAG_CMD_TAPENABLE
},
508 { .name
= "tapdisable" , .value
= JTAG_CMD_TAPDISABLE
},
509 { .name
= "configure" , .value
= JTAG_CMD_CONFIGURE
},
510 { .name
= "cget" , .value
= JTAG_CMD_CGET
},
512 { .name
= NULL
, .value
= -1 },
515 context
= Jim_GetAssocData(interp
, "context");
516 /* go past the command */
517 Jim_GetOpt_Setup( &goi
, interp
, argc
-1, argv
+1 );
519 e
= Jim_GetOpt_Nvp( &goi
, jtag_cmds
, &n
);
521 Jim_GetOpt_NvpUnknown( &goi
, jtag_cmds
, 0 );
524 Jim_SetEmptyResult( goi
.interp
);
526 case JTAG_CMD_INTERFACE
:
527 /* return the name of the interface */
528 /* TCL code might need to know the exact type... */
529 /* FUTURE: we allow this as a means to "set" the interface. */
531 Jim_WrongNumArgs( goi
.interp
, 1, goi
.argv
-1, "(no params)");
534 Jim_SetResultString( goi
.interp
, jtag_interface
->name
, -1 );
536 case JTAG_CMD_INIT_RESET
:
538 Jim_WrongNumArgs( goi
.interp
, 1, goi
.argv
-1, "(no params)");
541 e
= jtag_init_reset(context
);
543 Jim_SetResult_sprintf( goi
.interp
, "error: %d", e
);
547 case JTAG_CMD_NEWTAP
:
548 return jim_newtap_cmd( &goi
);
550 case JTAG_CMD_TAPISENABLED
:
551 case JTAG_CMD_TAPENABLE
:
552 case JTAG_CMD_TAPDISABLE
:
554 Jim_SetResultString( goi
.interp
, "Too many parameters",-1 );
560 t
= jtag_tap_by_jim_obj( goi
.interp
, goi
.argv
[0] );
565 case JTAG_CMD_TAPISENABLED
:
568 case JTAG_CMD_TAPENABLE
:
569 jtag_tap_handle_event( t
, JTAG_TAP_EVENT_ENABLE
);
573 case JTAG_CMD_TAPDISABLE
:
574 jtag_tap_handle_event( t
, JTAG_TAP_EVENT_DISABLE
);
579 Jim_SetResult( goi
.interp
, Jim_NewIntObj( goi
.interp
, e
) );
586 Jim_WrongNumArgs( goi
.interp
, 0, NULL
, "?tap-name? -option ...");
593 Jim_GetOpt_Obj(&goi
, &o
);
594 t
= jtag_tap_by_jim_obj( goi
.interp
, o
);
600 return jtag_tap_configure_cmd( &goi
, t
);
604 case JTAG_CMD_CONFIGURE
:
606 Jim_WrongNumArgs( goi
.interp
, 0, NULL
, "?tap-name? -option ?VALUE? ...");
613 Jim_GetOpt_Obj(&goi
, &o
);
614 t
= jtag_tap_by_jim_obj( goi
.interp
, o
);
620 return jtag_tap_configure_cmd( &goi
, t
);
627 int jtag_register_commands(struct command_context_s
*cmd_ctx
)
629 register_jim( cmd_ctx
, "jtag", jim_jtag_command
, "perform jtag tap actions");
631 register_command(cmd_ctx
, NULL
, "interface", handle_interface_command
,
632 COMMAND_CONFIG
, "try to configure interface");
633 register_command(cmd_ctx
, NULL
,
634 "interface_list", &handle_interface_list_command
,
635 COMMAND_ANY
, "list all built-in interfaces");
636 register_command(cmd_ctx
, NULL
, "jtag_speed", handle_jtag_speed_command
,
637 COMMAND_ANY
, "(DEPRECATED) set jtag speed (if supported)");
638 register_command(cmd_ctx
, NULL
, "jtag_khz", handle_jtag_khz_command
,
639 COMMAND_ANY
, "set maximum jtag speed (if supported); "
640 "parameter is maximum khz, or 0 for adaptive clocking (RTCK).");
641 register_command(cmd_ctx
, NULL
, "jtag_device", handle_jtag_device_command
,
642 COMMAND_CONFIG
, "(DEPRECATED) jtag_device <ir_length> <ir_expected> <ir_mask>");
643 register_command(cmd_ctx
, NULL
, "reset_config", handle_reset_config_command
,
645 "[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]");
646 register_command(cmd_ctx
, NULL
, "jtag_nsrst_delay", handle_jtag_nsrst_delay_command
,
647 COMMAND_ANY
, "jtag_nsrst_delay <ms> - delay after deasserting srst in ms");
648 register_command(cmd_ctx
, NULL
, "jtag_ntrst_delay", handle_jtag_ntrst_delay_command
,
649 COMMAND_ANY
, "jtag_ntrst_delay <ms> - delay after deasserting trst in ms");
651 register_command(cmd_ctx
, NULL
, "scan_chain", handle_scan_chain_command
,
652 COMMAND_EXEC
, "print current scan chain configuration");
654 register_command(cmd_ctx
, NULL
, "jtag_reset", handle_jtag_reset_command
,
655 COMMAND_EXEC
, "toggle reset lines <trst> <srst>");
656 register_command(cmd_ctx
, NULL
, "runtest", handle_runtest_command
,
657 COMMAND_EXEC
, "move to Run-Test/Idle, and execute <num_cycles>");
658 register_command(cmd_ctx
, NULL
, "irscan", handle_irscan_command
,
659 COMMAND_EXEC
, "execute IR scan <device> <instr> [dev2] [instr2] ...");
660 register_jim(cmd_ctx
, "drscan", Jim_Command_drscan
, "execute DR scan <device> <num_bits> <value> <num_bits1> <value2> ...");
661 register_jim(cmd_ctx
, "flush_count", Jim_Command_flush_count
, "returns number of times the JTAG queue has been flushed");
663 register_command(cmd_ctx
, NULL
, "verify_ircapture", handle_verify_ircapture_command
,
664 COMMAND_ANY
, "verify value captured during Capture-IR <enable|disable>");
665 register_command(cmd_ctx
, NULL
, "verify_jtag", handle_verify_jtag_command
,
666 COMMAND_ANY
, "verify value capture <enable|disable>");
667 register_command(cmd_ctx
, NULL
, "tms_sequence", handle_tms_sequence_command
,
668 COMMAND_ANY
, "choose short(default) or long tms_sequence <short|long>");
672 static int default_khz(int khz
, int *jtag_speed
)
674 LOG_ERROR("Translation from khz to jtag_speed not implemented");
678 static int default_speed_div(int speed
, int *khz
)
680 LOG_ERROR("Translation from jtag_speed to khz not implemented");
684 static int default_power_dropout(int *dropout
)
686 *dropout
=0; /* by default we can't detect power dropout */
690 static int default_srst_asserted(int *srst_asserted
)
692 *srst_asserted
=0; /* by default we can't detect srst asserted */
696 static int handle_interface_command(struct command_context_s
*cmd_ctx
,
697 char *cmd
, char **args
, int argc
)
699 /* check whether the interface is already configured */
702 LOG_WARNING("Interface already configured, ignoring");
706 /* interface name is a mandatory argument */
707 if (argc
!= 1 || args
[0][0] == '\0')
708 return ERROR_COMMAND_SYNTAX_ERROR
;
710 for (unsigned i
= 0; NULL
!= jtag_interfaces
[i
]; i
++)
712 if (strcmp(args
[0], jtag_interfaces
[i
]->name
) != 0)
715 int retval
= jtag_interfaces
[i
]->register_commands(cmd_ctx
);
716 if (ERROR_OK
!= retval
)
719 jtag_interface
= jtag_interfaces
[i
];
721 if (jtag_interface
->khz
== NULL
)
722 jtag_interface
->khz
= default_khz
;
723 if (jtag_interface
->speed_div
== NULL
)
724 jtag_interface
->speed_div
= default_speed_div
;
725 if (jtag_interface
->power_dropout
== NULL
)
726 jtag_interface
->power_dropout
= default_power_dropout
;
727 if (jtag_interface
->srst_asserted
== NULL
)
728 jtag_interface
->srst_asserted
= default_srst_asserted
;
733 /* no valid interface was found (i.e. the configuration option,
734 * didn't match one of the compiled-in interfaces
736 LOG_ERROR("The specified JTAG interface was not found (%s)", args
[0]);
737 handle_interface_list_command(cmd_ctx
, cmd
, args
, argc
);
738 return ERROR_JTAG_INVALID_INTERFACE
;
741 static int handle_interface_list_command(struct command_context_s
*cmd_ctx
,
742 char *cmd
, char **args
, int argc
)
744 if (strcmp(cmd
, "interface_list") == 0 && argc
> 0)
745 return ERROR_COMMAND_SYNTAX_ERROR
;
747 command_print(cmd_ctx
, "The following JTAG interfaces are available:");
748 for (unsigned i
= 0; NULL
!= jtag_interfaces
[i
]; i
++)
750 const char *name
= jtag_interfaces
[i
]->name
;
751 command_print(cmd_ctx
, "%u: %s", i
+ 1, name
);
757 static int handle_jtag_device_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
761 Jim_Obj
*newargs
[ 10 ];
765 * argv[ 0] = ir length
766 * argv[ 1] = ir capture
768 * argv[ 3] = not actually used by anything but in the docs
772 command_print( cmd_ctx
, "OLD DEPRECATED SYNTAX: Please use the NEW syntax");
775 command_print( cmd_ctx
, "OLD SYNTAX: DEPRECATED - translating to new syntax");
776 command_print( cmd_ctx
, "jtag newtap CHIP TAP -irlen %s -ircapture %s -irvalue %s",
780 command_print( cmd_ctx
, "Example: STM32 has 2 taps, the cortexM3(len4) + boundaryscan(len5)");
781 command_print( cmd_ctx
, "jtag newtap stm32 cortexm3 ....., thus creating the tap: \"stm32.cortexm3\"");
782 command_print( cmd_ctx
, "jtag newtap stm32 boundary ....., and the tap: \"stm32.boundary\"");
783 command_print( cmd_ctx
, "And then refer to the taps by the dotted name.");
785 newargs
[0] = Jim_NewStringObj( interp
, "jtag", -1 );
786 newargs
[1] = Jim_NewStringObj( interp
, "newtap", -1 );
787 sprintf( buf
, "chip%d", jtag_tap_count() );
788 newargs
[2] = Jim_NewStringObj( interp
, buf
, -1 );
789 sprintf( buf
, "tap%d", jtag_tap_count() );
790 newargs
[3] = Jim_NewStringObj( interp
, buf
, -1 );
791 newargs
[4] = Jim_NewStringObj( interp
, "-irlen", -1 );
792 newargs
[5] = Jim_NewStringObj( interp
, args
[0], -1 );
793 newargs
[6] = Jim_NewStringObj( interp
, "-ircapture", -1 );
794 newargs
[7] = Jim_NewStringObj( interp
, args
[1], -1 );
795 newargs
[8] = Jim_NewStringObj( interp
, "-irmask", -1 );
796 newargs
[9] = Jim_NewStringObj( interp
, args
[2], -1 );
798 command_print( cmd_ctx
, "NEW COMMAND:");
799 sprintf( buf
, "%s %s %s %s %s %s %s %s %s %s",
800 Jim_GetString( newargs
[0], NULL
),
801 Jim_GetString( newargs
[1], NULL
),
802 Jim_GetString( newargs
[2], NULL
),
803 Jim_GetString( newargs
[3], NULL
),
804 Jim_GetString( newargs
[4], NULL
),
805 Jim_GetString( newargs
[5], NULL
),
806 Jim_GetString( newargs
[6], NULL
),
807 Jim_GetString( newargs
[7], NULL
),
808 Jim_GetString( newargs
[8], NULL
),
809 Jim_GetString( newargs
[9], NULL
) );
811 e
= jim_jtag_command( interp
, 10, newargs
);
813 command_print( cmd_ctx
, "%s", Jim_GetString( Jim_GetResult(interp
), NULL
) );
818 static int handle_scan_chain_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
822 tap
= jtag_all_taps();
823 command_print(cmd_ctx
, " TapName | Enabled | IdCode Expected IrLen IrCap IrMask Instr ");
824 command_print(cmd_ctx
, "---|--------------------|---------|------------|------------|------|------|------|---------");
827 u32 expected
, expected_mask
, cur_instr
, ii
;
828 expected
= buf_get_u32(tap
->expected
, 0, tap
->ir_length
);
829 expected_mask
= buf_get_u32(tap
->expected_mask
, 0, tap
->ir_length
);
830 cur_instr
= buf_get_u32(tap
->cur_instr
, 0, tap
->ir_length
);
832 command_print(cmd_ctx
,
833 "%2d | %-18s | %c | 0x%08x | 0x%08x | 0x%02x | 0x%02x | 0x%02x | 0x%02x",
834 tap
->abs_chain_position
,
836 tap
->enabled
? 'Y' : 'n',
838 (tap
->expected_ids_cnt
> 0 ? tap
->expected_ids
[0] : 0),
844 for (ii
= 1; ii
< tap
->expected_ids_cnt
; ii
++) {
845 command_print(cmd_ctx
, " | | | | 0x%08x | | | | ",
846 tap
->expected_ids
[ii
]);
855 static int handle_reset_config_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
861 return ERROR_COMMAND_SYNTAX_ERROR
;
863 /* Original versions cared about the order of these tokens:
864 * reset_config signals [combination [trst_type [srst_type]]]
865 * They also clobbered the previous configuration even on error.
867 * Here we don't care about the order, and only change values
868 * which have been explicitly specified.
870 for (; argc
; argc
--, args
++) {
875 m
= RESET_HAS_TRST
| RESET_HAS_SRST
;
876 if (strcmp(*args
, "none") == 0)
878 else if (strcmp(*args
, "trst_only") == 0)
879 tmp
= RESET_HAS_TRST
;
880 else if (strcmp(*args
, "srst_only") == 0)
881 tmp
= RESET_HAS_SRST
;
882 else if (strcmp(*args
, "trst_and_srst") == 0)
883 tmp
= RESET_HAS_TRST
| RESET_HAS_SRST
;
887 LOG_ERROR("extra reset_config %s spec (%s)",
889 return ERROR_INVALID_ARGUMENTS
;
894 /* combination (options for broken wiring) */
895 m
= RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
;
896 if (strcmp(*args
, "separate") == 0)
897 /* separate reset lines - default */;
898 else if (strcmp(*args
, "srst_pulls_trst") == 0)
899 tmp
|= RESET_SRST_PULLS_TRST
;
900 else if (strcmp(*args
, "trst_pulls_srst") == 0)
901 tmp
|= RESET_TRST_PULLS_SRST
;
902 else if (strcmp(*args
, "combined") == 0)
903 tmp
|= RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
;
907 LOG_ERROR("extra reset_config %s spec (%s)",
908 "combination", *args
);
909 return ERROR_INVALID_ARGUMENTS
;
914 /* trst_type (NOP without HAS_TRST) */
915 m
= RESET_TRST_OPEN_DRAIN
;
916 if (strcmp(*args
, "trst_open_drain") == 0)
917 tmp
|= RESET_TRST_OPEN_DRAIN
;
918 else if (strcmp(*args
, "trst_push_pull") == 0)
919 /* push/pull from adapter - default */;
923 LOG_ERROR("extra reset_config %s spec (%s)",
925 return ERROR_INVALID_ARGUMENTS
;
930 /* srst_type (NOP without HAS_SRST) */
931 m
|= RESET_SRST_PUSH_PULL
;
932 if (strcmp(*args
, "srst_push_pull") == 0)
933 tmp
|= RESET_SRST_PUSH_PULL
;
934 else if (strcmp(*args
, "srst_open_drain") == 0)
935 /* open drain from adapter - default */;
939 LOG_ERROR("extra reset_config %s spec (%s)",
941 return ERROR_INVALID_ARGUMENTS
;
946 /* caller provided nonsense; fail */
947 LOG_ERROR("unknown reset_config flag (%s)", *args
);
948 return ERROR_INVALID_ARGUMENTS
;
951 /* Remember the bits which were specified (mask)
952 * and their new values (new_cfg).
958 /* clear previous values of those bits, save new values */
959 enum reset_types old_cfg
= jtag_get_reset_config();
962 jtag_set_reset_config(new_cfg
);
967 static int handle_jtag_nsrst_delay_command(struct command_context_s
*cmd_ctx
,
968 char *cmd
, char **args
, int argc
)
971 return ERROR_COMMAND_SYNTAX_ERROR
;
973 jtag_set_nsrst_delay(strtoul(args
[0], NULL
, 0));
974 command_print(cmd_ctx
, "jtag_nsrst_delay: %u", jtag_get_nsrst_delay());
978 static int handle_jtag_ntrst_delay_command(struct command_context_s
*cmd_ctx
,
979 char *cmd
, char **args
, int argc
)
982 return ERROR_COMMAND_SYNTAX_ERROR
;
984 jtag_set_ntrst_delay(strtoul(args
[0], NULL
, 0));
985 command_print(cmd_ctx
, "jtag_ntrst_delay: %u", jtag_get_ntrst_delay());
989 static int handle_jtag_speed_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
991 int retval
= ERROR_OK
;
994 return ERROR_COMMAND_SYNTAX_ERROR
;
997 LOG_DEBUG("handle jtag speed");
1000 cur_speed
= strtoul(args
[0], NULL
, 0);
1001 retval
= jtag_set_speed(cur_speed
);
1004 command_print(cmd_ctx
, "jtag_speed: %d", jtag_get_speed());
1009 static int handle_jtag_khz_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1012 return ERROR_COMMAND_SYNTAX_ERROR
;
1014 int retval
= ERROR_OK
;
1018 LOG_DEBUG("handle jtag khz");
1020 jtag_set_speed_khz(strtoul(args
[0], NULL
, 0));
1023 LOG_DEBUG("have interface set up");
1025 retval
= jtag
->khz(jtag_get_speed_khz(), &speed_div1
);
1026 if (ERROR_OK
!= retval
)
1028 jtag_set_speed_khz(0);
1031 cur_speed
= speed_div1
;
1033 retval
= jtag_set_speed(cur_speed
);
1036 cur_speed
= jtag_get_speed_khz();
1039 retval
= jtag
->speed_div(jtag_get_speed(), &cur_speed
);
1040 if (ERROR_OK
!= retval
)
1045 command_print(cmd_ctx
, "%d kHz", cur_speed
);
1047 command_print(cmd_ctx
, "RCLK - adaptive");
1052 static int handle_jtag_reset_command(struct command_context_s
*cmd_ctx
,
1053 char *cmd
, char **args
, int argc
)
1056 return ERROR_COMMAND_SYNTAX_ERROR
;
1059 if (args
[0][0] == '1')
1061 else if (args
[0][0] == '0')
1064 return ERROR_COMMAND_SYNTAX_ERROR
;
1067 if (args
[1][0] == '1')
1069 else if (args
[1][0] == '0')
1072 return ERROR_COMMAND_SYNTAX_ERROR
;
1074 if (jtag_interface_init(cmd_ctx
) != ERROR_OK
)
1075 return ERROR_JTAG_INIT_FAILED
;
1077 jtag_add_reset(trst
, srst
);
1078 jtag_execute_queue();
1083 static int handle_runtest_command(struct command_context_s
*cmd_ctx
,
1084 char *cmd
, char **args
, int argc
)
1087 return ERROR_COMMAND_SYNTAX_ERROR
;
1089 jtag_add_runtest(strtol(args
[0], NULL
, 0), jtag_get_end_state());
1090 jtag_execute_queue();
1096 * For "irscan" or "drscan" commands, the "end" (really, "next") state
1097 * should be stable ... and *NOT* a shift state, otherwise free-running
1098 * jtag clocks could change the values latched by the update state.
1100 static bool scan_is_safe(tap_state_t state
)
1115 static int handle_irscan_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1118 scan_field_t
*fields
;
1120 tap_state_t endstate
;
1122 if ((argc
< 2) || (argc
% 2))
1124 return ERROR_COMMAND_SYNTAX_ERROR
;
1127 /* optional "-endstate" "statename" at the end of the arguments,
1128 * so that e.g. IRPAUSE can let us load the data register before
1129 * entering RUN/IDLE to execute the instruction we load here.
1131 endstate
= TAP_IDLE
;
1134 /* have at least one pair of numbers. */
1135 /* is last pair the magic text? */
1136 if( 0 == strcmp( "-endstate", args
[ argc
- 2 ] ) ){
1139 cpA
= args
[ argc
-1 ];
1140 for( endstate
= 0 ; endstate
< TAP_NUM_STATES
; endstate
++ ){
1141 cpS
= tap_state_name( endstate
);
1142 if( 0 == strcmp( cpA
, cpS
) ){
1146 if( endstate
>= TAP_NUM_STATES
){
1147 return ERROR_COMMAND_SYNTAX_ERROR
;
1149 if (!scan_is_safe(endstate
))
1150 LOG_WARNING("irscan with unsafe "
1151 "endstate \"%s\"", cpA
);
1152 /* found - remove the last 2 args */
1158 int num_fields
= argc
/ 2;
1160 fields
= malloc(sizeof(scan_field_t
) * num_fields
);
1162 for (i
= 0; i
< num_fields
; i
++)
1164 tap
= jtag_tap_by_string( args
[i
*2] );
1167 command_print( cmd_ctx
, "Tap: %s unknown", args
[i
*2] );
1170 int field_size
= tap
->ir_length
;
1171 fields
[i
].tap
= tap
;
1172 fields
[i
].num_bits
= field_size
;
1173 fields
[i
].out_value
= malloc(CEIL(field_size
, 8));
1174 buf_set_u32(fields
[i
].out_value
, 0, field_size
, strtoul(args
[i
*2+1], NULL
, 0));
1175 fields
[i
].in_value
= NULL
;
1178 /* did we have an endstate? */
1179 jtag_add_ir_scan(num_fields
, fields
, endstate
);
1181 int retval
=jtag_execute_queue();
1183 for (i
= 0; i
< num_fields
; i
++)
1184 free(fields
[i
].out_value
);
1191 static int Jim_Command_drscan(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *args
)
1194 scan_field_t
*fields
;
1196 int field_count
= 0;
1199 tap_state_t endstate
;
1202 * args[2] = num_bits
1203 * args[3] = hex string
1204 * ... repeat num bits and hex string ...
1207 * args[N-2] = "-endstate"
1208 * args[N-1] = statename
1210 if ((argc
< 4) || ((argc
% 2)!=0))
1212 Jim_WrongNumArgs(interp
, 1, args
, "wrong arguments");
1216 endstate
= TAP_IDLE
;
1218 /* validate arguments as numbers */
1220 for (i
= 2; i
< argc
; i
+=2)
1225 e
= Jim_GetLong(interp
, args
[i
], &bits
);
1226 /* If valid - try next arg */
1231 /* Not valid.. are we at the end? */
1232 if ( ((i
+2) != argc
) ){
1233 /* nope, then error */
1237 /* it could be: "-endstate FOO"
1238 * e.g. DRPAUSE so we can issue more instructions
1239 * before entering RUN/IDLE and executing them.
1242 /* get arg as a string. */
1243 cp
= Jim_GetString( args
[i
], NULL
);
1244 /* is it the magic? */
1245 if( 0 == strcmp( "-endstate", cp
) ){
1246 /* is the statename valid? */
1247 cp
= Jim_GetString( args
[i
+1], NULL
);
1249 /* see if it is a valid state name */
1250 endstate
= tap_state_by_name(cp
);
1252 /* update the error message */
1253 Jim_SetResult_sprintf(interp
,"endstate: %s invalid", cp
);
1255 if (!scan_is_safe(endstate
))
1256 LOG_WARNING("drscan with unsafe "
1257 "endstate \"%s\"", cp
);
1259 /* valid - so clear the error */
1261 /* and remove the last 2 args */
1266 /* Still an error? */
1268 return e
; /* too bad */
1270 } /* validate args */
1272 tap
= jtag_tap_by_jim_obj( interp
, args
[1] );
1277 num_fields
=(argc
-2)/2;
1278 fields
= malloc(sizeof(scan_field_t
) * num_fields
);
1279 for (i
= 2; i
< argc
; i
+=2)
1285 Jim_GetLong(interp
, args
[i
], &bits
);
1286 str
= Jim_GetString(args
[i
+1], &len
);
1288 fields
[field_count
].tap
= tap
;
1289 fields
[field_count
].num_bits
= bits
;
1290 fields
[field_count
].out_value
= malloc(CEIL(bits
, 8));
1291 str_to_buf(str
, len
, fields
[field_count
].out_value
, bits
, 0);
1292 fields
[field_count
].in_value
= fields
[field_count
].out_value
;
1296 jtag_add_dr_scan(num_fields
, fields
, endstate
);
1298 retval
= jtag_execute_queue();
1299 if (retval
!= ERROR_OK
)
1301 Jim_SetResultString(interp
, "drscan: jtag execute failed",-1);
1306 Jim_Obj
*list
= Jim_NewListObj(interp
, NULL
, 0);
1307 for (i
= 2; i
< argc
; i
+=2)
1312 Jim_GetLong(interp
, args
[i
], &bits
);
1313 str
= buf_to_str(fields
[field_count
].in_value
, bits
, 16);
1314 free(fields
[field_count
].out_value
);
1316 Jim_ListAppendElement(interp
, list
, Jim_NewStringObj(interp
, str
, strlen(str
)));
1321 Jim_SetResult(interp
, list
);
1329 static int Jim_Command_flush_count(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *args
)
1331 Jim_SetResult(interp
, Jim_NewIntObj(interp
, jtag_get_flush_queue_count()));
1337 static int handle_verify_ircapture_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1340 return ERROR_COMMAND_SYNTAX_ERROR
;
1344 if (strcmp(args
[0], "enable") == 0)
1345 jtag_set_verify_capture_ir(true);
1346 else if (strcmp(args
[0], "disable") == 0)
1347 jtag_set_verify_capture_ir(false);
1349 return ERROR_COMMAND_SYNTAX_ERROR
;
1352 const char *status
= jtag_will_verify_capture_ir() ? "enabled": "disabled";
1353 command_print(cmd_ctx
, "verify Capture-IR is %s", status
);
1358 static int handle_verify_jtag_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1361 return ERROR_COMMAND_SYNTAX_ERROR
;
1365 if (strcmp(args
[0], "enable") == 0)
1366 jtag_set_verify(true);
1367 else if (strcmp(args
[0], "disable") == 0)
1368 jtag_set_verify(false);
1370 return ERROR_COMMAND_SYNTAX_ERROR
;
1373 const char *status
= jtag_will_verify() ? "enabled": "disabled";
1374 command_print(cmd_ctx
, "verify jtag capture is %s", status
);
1379 static int handle_tms_sequence_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1382 return ERROR_COMMAND_SYNTAX_ERROR
;
1387 if (strcmp(args
[0], "short") == 0)
1388 use_new_table
= true;
1389 else if (strcmp(args
[0], "long") == 0)
1390 use_new_table
= false;
1392 return ERROR_COMMAND_SYNTAX_ERROR
;
1394 tap_use_new_tms_table(use_new_table
);
1397 command_print(cmd_ctx
, "tms sequence is %s",
1398 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)