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 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
17 * This program is distributed in the hope that it will be useful, *
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20 * GNU General Public License for more details. *
22 * You should have received a copy of the GNU General Public License *
23 * along with this program; if not, write to the *
24 * Free Software Foundation, Inc., *
25 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
26 ***************************************************************************/
32 #include "minidriver.h"
33 #include "interface.h"
40 /// The number of JTAG queue flushes (for profiling and debugging purposes).
41 static int jtag_flush_queue_count
;
43 static void jtag_add_scan_check(void (*jtag_add_scan
)(int in_num_fields
, const scan_field_t
*in_fields
, tap_state_t state
),
44 int in_num_fields
, scan_field_t
*in_fields
, tap_state_t state
);
46 /* note that this is not marked as static as it must be available from outside jtag.c for those
47 that implement the jtag_xxx() minidriver layer
49 int jtag_error
=ERROR_OK
;
51 char* jtag_event_strings
[] =
53 "JTAG controller reset (RESET or TRST)"
56 const Jim_Nvp nvp_jtag_tap_event
[] = {
57 { .value
= JTAG_TAP_EVENT_ENABLE
, .name
= "tap-enable" },
58 { .value
= JTAG_TAP_EVENT_DISABLE
, .name
= "tap-disable" },
60 { .name
= NULL
, .value
= -1 }
67 * List all TAPs that have been created.
69 static jtag_tap_t
*__jtag_all_taps
= NULL
;
71 * The number of TAPs in the __jtag_all_taps list, used to track the
72 * assigned chain position to new TAPs
74 static int jtag_num_taps
= 0;
76 enum reset_types jtag_reset_config
= RESET_NONE
;
77 tap_state_t cmd_queue_end_state
= TAP_RESET
;
78 tap_state_t cmd_queue_cur_state
= TAP_RESET
;
80 int jtag_verify_capture_ir
= 1;
83 /* how long the OpenOCD should wait before attempting JTAG communication after reset lines deasserted (in ms) */
84 static int jtag_nsrst_delay
= 0; /* default to no nSRST delay */
85 static int jtag_ntrst_delay
= 0; /* default to no nTRST delay */
87 /* callbacks to inform high-level handlers about JTAG state changes */
88 jtag_event_callback_t
*jtag_event_callbacks
;
91 static int speed_khz
= 0;
92 /* flag if the kHz speed was defined */
93 static bool hasKHz
= false;
95 /* jtag interfaces (parport, FTDI-USB, TI-USB, ...)
98 #if BUILD_ECOSBOARD == 1
99 extern jtag_interface_t zy1000_interface
;
100 #elif defined(BUILD_MINIDRIVER_DUMMY)
101 extern jtag_interface_t minidummy_interface
;
102 #else // standard drivers
103 #if BUILD_PARPORT == 1
104 extern jtag_interface_t parport_interface
;
108 extern jtag_interface_t dummy_interface
;
111 #if BUILD_FT2232_FTD2XX == 1
112 extern jtag_interface_t ft2232_interface
;
115 #if BUILD_FT2232_LIBFTDI == 1
116 extern jtag_interface_t ft2232_interface
;
119 #if BUILD_AMTJTAGACCEL == 1
120 extern jtag_interface_t amt_jtagaccel_interface
;
123 #if BUILD_EP93XX == 1
124 extern jtag_interface_t ep93xx_interface
;
127 #if BUILD_AT91RM9200 == 1
128 extern jtag_interface_t at91rm9200_interface
;
131 #if BUILD_GW16012 == 1
132 extern jtag_interface_t gw16012_interface
;
135 #if BUILD_PRESTO_LIBFTDI == 1 || BUILD_PRESTO_FTD2XX == 1
136 extern jtag_interface_t presto_interface
;
139 #if BUILD_USBPROG == 1
140 extern jtag_interface_t usbprog_interface
;
144 extern jtag_interface_t jlink_interface
;
147 #if BUILD_VSLLINK == 1
148 extern jtag_interface_t vsllink_interface
;
152 extern jtag_interface_t rlink_interface
;
155 #if BUILD_ARMJTAGEW == 1
156 extern jtag_interface_t armjtagew_interface
;
158 #endif // standard drivers
161 * The list of built-in JTAG interfaces, containing entries for those
162 * drivers that were enabled by the @c configure script.
164 * The list should be defined to contain either one minidriver interface
165 * or some number of standard driver interfaces, never both.
167 jtag_interface_t
*jtag_interfaces
[] = {
168 #if BUILD_ECOSBOARD == 1
170 #elif defined(BUILD_MINIDRIVER_DUMMY)
171 &minidummy_interface
,
172 #else // standard drivers
173 #if BUILD_PARPORT == 1
179 #if BUILD_FT2232_FTD2XX == 1
182 #if BUILD_FT2232_LIBFTDI == 1
185 #if BUILD_AMTJTAGACCEL == 1
186 &amt_jtagaccel_interface
,
188 #if BUILD_EP93XX == 1
191 #if BUILD_AT91RM9200 == 1
192 &at91rm9200_interface
,
194 #if BUILD_GW16012 == 1
197 #if BUILD_PRESTO_LIBFTDI == 1 || BUILD_PRESTO_FTD2XX == 1
200 #if BUILD_USBPROG == 1
206 #if BUILD_VSLLINK == 1
212 #if BUILD_ARMJTAGEW == 1
213 &armjtagew_interface
,
215 #endif // standard drivers
219 struct jtag_interface_s
*jtag
= NULL
;
222 static jtag_interface_t
*jtag_interface
= NULL
;
226 static int handle_interface_list_command(struct command_context_s
*cmd_ctx
,
227 char *cmd
, char **args
, int argc
);
228 static int handle_interface_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
229 static int handle_jtag_speed_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
230 static int handle_jtag_khz_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
231 static int handle_jtag_device_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
232 static int handle_reset_config_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
233 static int handle_jtag_nsrst_delay_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
234 static int handle_jtag_ntrst_delay_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
236 static int handle_scan_chain_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
238 static int handle_jtag_reset_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
239 static int handle_runtest_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
240 static int handle_irscan_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
241 static int Jim_Command_drscan(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
);
242 static int Jim_Command_flush_count(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *args
);
244 static int handle_verify_ircapture_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
245 static int handle_verify_jtag_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
246 static int handle_tms_sequence_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
248 jtag_tap_t
*jtag_all_taps(void)
250 return __jtag_all_taps
;
253 int jtag_tap_count(void)
255 return jtag_num_taps
;
258 unsigned jtag_tap_count_enabled(void)
274 /// Append a new TAP to the chain of all taps.
275 static void jtag_tap_add(struct jtag_tap_s
*t
)
277 t
->abs_chain_position
= jtag_num_taps
++;
279 jtag_tap_t
**tap
= &__jtag_all_taps
;
281 tap
= &(*tap
)->next_tap
;
285 jtag_tap_t
*jtag_tap_by_string( const char *s
)
293 if( 0 == strcmp( t
->dotted_name
, s
) ){
299 /* backup plan is by number */
301 /* ok - is "s" a number? */
303 n
= strtol( s
, &cp
, 0 );
304 if( (s
!= cp
) && (*cp
== 0) ){
306 t
= jtag_tap_by_abs_position(n
);
312 jtag_tap_t
* jtag_tap_by_jim_obj( Jim_Interp
*interp
, Jim_Obj
*o
)
317 cp
= Jim_GetString( o
, NULL
);
322 t
= jtag_tap_by_string( cp
);
325 Jim_SetResult_sprintf(interp
,"Tap: %s is unknown", cp
);
330 /* returns a pointer to the n-th device in the scan chain */
331 jtag_tap_t
* jtag_tap_by_abs_position( int n
)
339 while( t
&& (n
> 0)) {
346 const char *jtag_tap_name(const jtag_tap_t
*tap
)
348 return (tap
== NULL
) ? "(unknown)" : tap
->dotted_name
;
352 int jtag_register_event_callback(int (*callback
)(enum jtag_event event
, void *priv
), void *priv
)
354 jtag_event_callback_t
**callbacks_p
= &jtag_event_callbacks
;
356 if (callback
== NULL
)
358 return ERROR_INVALID_ARGUMENTS
;
363 while ((*callbacks_p
)->next
)
364 callbacks_p
= &((*callbacks_p
)->next
);
365 callbacks_p
= &((*callbacks_p
)->next
);
368 (*callbacks_p
) = malloc(sizeof(jtag_event_callback_t
));
369 (*callbacks_p
)->callback
= callback
;
370 (*callbacks_p
)->priv
= priv
;
371 (*callbacks_p
)->next
= NULL
;
376 int jtag_unregister_event_callback(int (*callback
)(enum jtag_event event
, void *priv
))
378 jtag_event_callback_t
**callbacks_p
= &jtag_event_callbacks
;
380 if (callback
== NULL
)
382 return ERROR_INVALID_ARGUMENTS
;
387 jtag_event_callback_t
**next
= &((*callbacks_p
)->next
);
388 if ((*callbacks_p
)->callback
== callback
)
391 *callbacks_p
= *next
;
399 int jtag_call_event_callbacks(enum jtag_event event
)
401 jtag_event_callback_t
*callback
= jtag_event_callbacks
;
403 LOG_DEBUG("jtag event: %s", jtag_event_strings
[event
]);
407 callback
->callback(event
, callback
->priv
);
408 callback
= callback
->next
;
414 static void jtag_checks(void)
416 assert(jtag_trst
== 0);
419 static void jtag_prelude(tap_state_t state
)
423 assert(state
!=TAP_INVALID
);
425 cmd_queue_cur_state
= state
;
428 void jtag_alloc_in_value32(scan_field_t
*field
)
430 interface_jtag_alloc_in_value32(field
);
433 void jtag_add_ir_scan_noverify(int in_count
, const scan_field_t
*in_fields
,
438 int retval
= interface_jtag_add_ir_scan(in_count
, in_fields
, state
);
439 jtag_set_error(retval
);
444 * Generate an IR SCAN with a list of scan fields with one entry for each enabled TAP.
446 * If the input field list contains an instruction value for a TAP then that is used
447 * otherwise the TAP is set to bypass.
449 * TAPs for which no fields are passed are marked as bypassed for subsequent DR SCANs.
452 void jtag_add_ir_scan(int in_num_fields
, scan_field_t
*in_fields
, tap_state_t state
)
454 if (jtag_verify
&&jtag_verify_capture_ir
)
456 /* 8 x 32 bit id's is enough for all invocations */
458 for (int j
= 0; j
< in_num_fields
; j
++)
460 /* if we are to run a verification of the ir scan, we need to get the input back.
461 * We may have to allocate space if the caller didn't ask for the input back.
463 in_fields
[j
].check_value
=in_fields
[j
].tap
->expected
;
464 in_fields
[j
].check_mask
=in_fields
[j
].tap
->expected_mask
;
466 jtag_add_scan_check(jtag_add_ir_scan_noverify
, in_num_fields
, in_fields
, state
);
469 jtag_add_ir_scan_noverify(in_num_fields
, in_fields
, state
);
474 * Duplicate the scan fields passed into the function into an IR SCAN command
476 * This function assumes that the caller handles extra fields for bypassed TAPs
479 void jtag_add_plain_ir_scan(int in_num_fields
, const scan_field_t
*in_fields
,
484 int retval
= interface_jtag_add_plain_ir_scan(
485 in_num_fields
, in_fields
, state
);
486 jtag_set_error(retval
);
489 void jtag_add_callback(jtag_callback1_t f
, u8
*in
)
491 interface_jtag_add_callback(f
, in
);
494 void jtag_add_callback4(jtag_callback_t f
, u8
*in
,
495 jtag_callback_data_t data1
, jtag_callback_data_t data2
,
496 jtag_callback_data_t data3
)
498 interface_jtag_add_callback4(f
, in
, data1
, data2
, data3
);
501 int jtag_check_value_inner(u8
*captured
, u8
*in_check_value
, u8
*in_check_mask
, int num_bits
);
503 static int jtag_check_value_mask_callback(u8
*in
, jtag_callback_data_t data1
, jtag_callback_data_t data2
, jtag_callback_data_t data3
)
505 return jtag_check_value_inner(in
, (u8
*)data1
, (u8
*)data2
, (int)data3
);
508 static void jtag_add_scan_check(void (*jtag_add_scan
)(int in_num_fields
, const scan_field_t
*in_fields
, tap_state_t state
),
509 int in_num_fields
, scan_field_t
*in_fields
, tap_state_t state
)
511 for (int i
= 0; i
< in_num_fields
; i
++)
513 struct scan_field_s
*field
= &in_fields
[i
];
514 field
->allocated
= 0;
516 if (field
->check_value
|| field
->in_value
)
518 interface_jtag_add_scan_check_alloc(field
);
522 jtag_add_scan(in_num_fields
, in_fields
, state
);
524 for (int i
= 0; i
< in_num_fields
; i
++)
526 if ((in_fields
[i
].check_value
!= NULL
) && (in_fields
[i
].in_value
!= NULL
))
528 /* this is synchronous for a minidriver */
529 jtag_add_callback4(jtag_check_value_mask_callback
, in_fields
[i
].in_value
,
530 (jtag_callback_data_t
)in_fields
[i
].check_value
,
531 (jtag_callback_data_t
)in_fields
[i
].check_mask
,
532 (jtag_callback_data_t
)in_fields
[i
].num_bits
);
534 if (in_fields
[i
].allocated
)
536 free(in_fields
[i
].in_value
);
538 if (in_fields
[i
].modified
)
540 in_fields
[i
].in_value
= NULL
;
545 void jtag_add_dr_scan_check(int in_num_fields
, scan_field_t
*in_fields
, tap_state_t state
)
549 jtag_add_scan_check(jtag_add_dr_scan
, in_num_fields
, in_fields
, state
);
552 jtag_add_dr_scan(in_num_fields
, in_fields
, state
);
558 * Generate a DR SCAN using the fields passed to the function.
559 * For connected TAPs, the function checks in_fields and uses fields
560 * specified there. For bypassed TAPs, the function generates a dummy
561 * 1-bit field. The bypass status of TAPs is set by jtag_add_ir_scan().
563 void jtag_add_dr_scan(int in_num_fields
, const scan_field_t
*in_fields
,
569 retval
= interface_jtag_add_dr_scan(in_num_fields
, in_fields
, state
);
570 jtag_set_error(retval
);
574 * Duplicate the scan fields passed into the function into a DR SCAN
575 * command. Unlike jtag_add_dr_scan(), this function assumes that the
576 * caller handles extra fields for bypassed TAPs.
578 void jtag_add_plain_dr_scan(int in_num_fields
, const scan_field_t
*in_fields
,
584 retval
= interface_jtag_add_plain_dr_scan(in_num_fields
, in_fields
, state
);
585 jtag_set_error(retval
);
588 void jtag_add_dr_out(jtag_tap_t
* tap
,
589 int num_fields
, const int* num_bits
, const u32
* value
,
590 tap_state_t end_state
)
592 assert(end_state
!= TAP_INVALID
);
594 cmd_queue_cur_state
= end_state
;
596 interface_jtag_add_dr_out(tap
,
597 num_fields
, num_bits
, value
,
601 void jtag_add_tlr(void)
603 jtag_prelude(TAP_RESET
);
604 jtag_set_error(interface_jtag_add_tlr());
605 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
608 void jtag_add_pathmove(int num_states
, const tap_state_t
*path
)
610 tap_state_t cur_state
= cmd_queue_cur_state
;
612 /* the last state has to be a stable state */
613 if (!tap_is_state_stable(path
[num_states
- 1]))
615 LOG_ERROR("BUG: TAP path doesn't finish in a stable state");
619 for (int i
= 0; i
< num_states
; i
++)
621 if (path
[i
] == TAP_RESET
)
623 LOG_ERROR("BUG: TAP_RESET is not a valid state for pathmove sequences");
627 if ( tap_state_transition(cur_state
, true) != path
[i
]
628 && tap_state_transition(cur_state
, false) != path
[i
])
630 LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition",
631 tap_state_name(cur_state
), tap_state_name(path
[i
]));
639 jtag_set_error(interface_jtag_add_pathmove(num_states
, path
));
640 cmd_queue_cur_state
= path
[num_states
- 1];
643 void jtag_add_runtest(int num_cycles
, tap_state_t state
)
646 jtag_set_error(interface_jtag_add_runtest(num_cycles
, state
));
650 void jtag_add_clocks(int num_cycles
)
652 if (!tap_is_state_stable(cmd_queue_cur_state
))
654 LOG_ERROR("jtag_add_clocks() called with TAP in unstable state \"%s\"",
655 tap_state_name(cmd_queue_cur_state
));
656 jtag_set_error(ERROR_JTAG_NOT_STABLE_STATE
);
663 jtag_set_error(interface_jtag_add_clocks(num_cycles
));
667 void jtag_add_reset(int req_tlr_or_trst
, int req_srst
)
669 int trst_with_tlr
= 0;
671 /* FIX!!! there are *many* different cases here. A better
672 * approach is needed for legal combinations of transitions...
674 if ((jtag_reset_config
& RESET_HAS_SRST
)&&
675 (jtag_reset_config
& RESET_HAS_TRST
)&&
676 ((jtag_reset_config
& RESET_SRST_PULLS_TRST
)==0))
678 if (((req_tlr_or_trst
&&!jtag_trst
)||
679 (!req_tlr_or_trst
&&jtag_trst
))&&
680 ((req_srst
&&!jtag_srst
)||
681 (!req_srst
&&jtag_srst
)))
683 /* FIX!!! srst_pulls_trst allows 1,1 => 0,0 transition.... */
684 //LOG_ERROR("BUG: transition of req_tlr_or_trst and req_srst in the same jtag_add_reset() call is undefined");
688 /* Make sure that jtag_reset_config allows the requested reset */
689 /* if SRST pulls TRST, we can't fulfill srst == 1 with trst == 0 */
690 if (((jtag_reset_config
& RESET_SRST_PULLS_TRST
) && (req_srst
== 1)) && (!req_tlr_or_trst
))
692 LOG_ERROR("BUG: requested reset would assert trst");
693 jtag_set_error(ERROR_FAIL
);
697 /* if TRST pulls SRST, we reset with TAP T-L-R */
698 if (((jtag_reset_config
& RESET_TRST_PULLS_SRST
) && (req_tlr_or_trst
)) && (req_srst
== 0))
703 if (req_srst
&& !(jtag_reset_config
& RESET_HAS_SRST
))
705 LOG_ERROR("BUG: requested SRST assertion, but the current configuration doesn't support this");
706 jtag_set_error(ERROR_FAIL
);
712 if (!trst_with_tlr
&& (jtag_reset_config
& RESET_HAS_TRST
))
724 jtag_srst
= req_srst
;
726 int retval
= interface_jtag_add_reset(jtag_trst
, jtag_srst
);
727 if (retval
!= ERROR_OK
)
729 jtag_set_error(retval
);
732 jtag_execute_queue();
736 LOG_DEBUG("SRST line asserted");
740 LOG_DEBUG("SRST line released");
741 if (jtag_nsrst_delay
)
742 jtag_add_sleep(jtag_nsrst_delay
* 1000);
747 LOG_DEBUG("JTAG reset with RESET instead of TRST");
748 jtag_set_end_state(TAP_RESET
);
755 /* we just asserted nTRST, so we're now in Test-Logic-Reset,
756 * and inform possible listeners about this
758 LOG_DEBUG("TRST line asserted");
759 tap_set_state(TAP_RESET
);
760 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
764 if (jtag_ntrst_delay
)
765 jtag_add_sleep(jtag_ntrst_delay
* 1000);
769 tap_state_t
jtag_set_end_state(tap_state_t state
)
771 if ((state
== TAP_DRSHIFT
)||(state
== TAP_IRSHIFT
))
773 LOG_ERROR("BUG: TAP_DRSHIFT/IRSHIFT can't be end state. Calling code should use a larger scan field");
776 if (state
!=TAP_INVALID
)
777 cmd_queue_end_state
= state
;
778 return cmd_queue_end_state
;
781 tap_state_t
jtag_get_end_state(void)
783 return cmd_queue_end_state
;
786 void jtag_add_sleep(u32 us
)
788 /// @todo Here, keep_alive() appears to be a layering violation!!!
790 jtag_set_error(interface_jtag_add_sleep(us
));
793 int jtag_check_value_inner(u8
*captured
, u8
*in_check_value
, u8
*in_check_mask
, int num_bits
)
795 int retval
= ERROR_OK
;
797 int compare_failed
= 0;
800 compare_failed
= buf_cmp_mask(captured
, in_check_value
, in_check_mask
, num_bits
);
802 compare_failed
= buf_cmp(captured
, in_check_value
, num_bits
);
805 /* An error handler could have caught the failing check
806 * only report a problem when there wasn't a handler, or if the handler
807 * acknowledged the error
810 LOG_WARNING("TAP %s:",
811 jtag_tap_name(field->tap));
815 char *captured_char
= buf_to_str(captured
, (num_bits
> DEBUG_JTAG_IOZ
) ? DEBUG_JTAG_IOZ
: num_bits
, 16);
816 char *in_check_value_char
= buf_to_str(in_check_value
, (num_bits
> DEBUG_JTAG_IOZ
) ? DEBUG_JTAG_IOZ
: num_bits
, 16);
820 char *in_check_mask_char
;
821 in_check_mask_char
= buf_to_str(in_check_mask
, (num_bits
> DEBUG_JTAG_IOZ
) ? DEBUG_JTAG_IOZ
: num_bits
, 16);
822 LOG_WARNING("value captured during scan didn't pass the requested check:");
823 LOG_WARNING("captured: 0x%s check_value: 0x%s check_mask: 0x%s",
824 captured_char
, in_check_value_char
, in_check_mask_char
);
825 free(in_check_mask_char
);
829 LOG_WARNING("value captured during scan didn't pass the requested check: captured: 0x%s check_value: 0x%s", captured_char
, in_check_value_char
);
833 free(in_check_value_char
);
835 retval
= ERROR_JTAG_QUEUE_FAILED
;
842 void jtag_check_value_mask(scan_field_t
*field
, u8
*value
, u8
*mask
)
844 assert(field
->in_value
!= NULL
);
848 /* no checking to do */
852 jtag_execute_queue_noclear();
854 int retval
=jtag_check_value_inner(field
->in_value
, value
, mask
, field
->num_bits
);
855 jtag_set_error(retval
);
860 int default_interface_jtag_execute_queue(void)
864 LOG_ERROR("No JTAG interface configured yet. "
865 "Issue 'init' command in startup scripts "
866 "before communicating with targets.");
870 return jtag
->execute_queue();
873 void jtag_execute_queue_noclear(void)
875 jtag_flush_queue_count
++;
876 jtag_set_error(interface_jtag_execute_queue());
879 int jtag_get_flush_queue_count(void)
881 return jtag_flush_queue_count
;
884 int jtag_execute_queue(void)
886 jtag_execute_queue_noclear();
887 return jtag_error_clear();
890 static int jtag_reset_callback(enum jtag_event event
, void *priv
)
892 jtag_tap_t
*tap
= priv
;
896 if (event
== JTAG_TRST_ASSERTED
)
898 buf_set_ones(tap
->cur_instr
, tap
->ir_length
);
905 void jtag_sleep(u32 us
)
907 alive_sleep(us
/1000);
910 /// maximum number of JTAG devices expected in the chain
911 #define JTAG_MAX_CHAIN_SIZE 20
913 #define EXTRACT_MFG(X) (((X) & 0xffe) >> 1)
914 #define EXTRACT_PART(X) (((X) & 0xffff000) >> 12)
915 #define EXTRACT_VER(X) (((X) & 0xf0000000) >> 28)
917 static int jtag_examine_chain_execute(u8
*idcode_buffer
, unsigned num_idcode
)
919 scan_field_t field
= {
921 .num_bits
= num_idcode
* 32,
922 .out_value
= idcode_buffer
,
923 .in_value
= idcode_buffer
,
926 // initialize to the end of chain ID value
927 for (unsigned i
= 0; i
< JTAG_MAX_CHAIN_SIZE
; i
++)
928 buf_set_u32(idcode_buffer
, i
* 32, 32, 0x000000FF);
930 jtag_add_plain_dr_scan(1, &field
, TAP_RESET
);
931 return jtag_execute_queue();
934 static bool jtag_examine_chain_check(u8
*idcodes
, unsigned count
)
939 for (unsigned i
= 0; i
< count
* 4; i
++)
941 zero_check
|= idcodes
[i
];
942 one_check
&= idcodes
[i
];
945 /* if there wasn't a single non-zero bit or if all bits were one,
946 * the scan is not valid */
947 if (zero_check
== 0x00 || one_check
== 0xff)
949 LOG_ERROR("JTAG communication failure: check connection, "
950 "JTAG interface, target power etc.");
956 static void jtag_examine_chain_display(enum log_levels level
, const char *msg
,
957 const char *name
, u32 idcode
)
959 log_printf_lf(level
, __FILE__
, __LINE__
, __FUNCTION__
,
960 "JTAG tap: %s %16.16s: 0x%08x "
961 "(mfg: 0x%3.3x, part: 0x%4.4x, ver: 0x%1.1x)",
963 EXTRACT_MFG(idcode
), EXTRACT_PART(idcode
), EXTRACT_VER(idcode
) );
966 static bool jtag_idcode_is_final(u32 idcode
)
968 return idcode
== 0x000000FF || idcode
== 0xFFFFFFFF;
972 * This helper checks that remaining bits in the examined chain data are
973 * all as expected, but a single JTAG device requires only 64 bits to be
974 * read back correctly. This can help identify and diagnose problems
975 * with the JTAG chain earlier, gives more helpful/explicit error messages.
977 static void jtag_examine_chain_end(u8
*idcodes
, unsigned count
, unsigned max
)
979 bool triggered
= false;
980 for ( ; count
< max
- 31; count
+= 32)
982 u32 idcode
= buf_get_u32(idcodes
, count
, 32);
983 // do not trigger the warning if the data looks good
984 if (!triggered
&& jtag_idcode_is_final(idcode
))
986 LOG_WARNING("Unexpected idcode after end of chain: %d 0x%08x",
992 static bool jtag_examine_chain_match_tap(const struct jtag_tap_s
*tap
)
994 if (0 == tap
->expected_ids_cnt
)
996 /// @todo Enable LOG_INFO to ask for reports about unknown TAP IDs.
998 LOG_INFO("Uknown JTAG TAP ID: 0x%08x", tap
->idcode
)
999 LOG_INFO("Please report the chip name and reported ID code to the openocd project");
1004 /* Loop over the expected identification codes and test for a match */
1006 for (ii
= 0; ii
< tap
->expected_ids_cnt
; ii
++)
1008 if (tap
->idcode
== tap
->expected_ids
[ii
])
1012 /* If none of the expected ids matched, log an error */
1013 if (ii
!= tap
->expected_ids_cnt
)
1015 LOG_INFO("JTAG Tap/device matched");
1018 jtag_examine_chain_display(LOG_LVL_ERROR
, "got",
1019 tap
->dotted_name
, tap
->idcode
);
1020 for (ii
= 0; ii
< tap
->expected_ids_cnt
; ii
++)
1023 snprintf(msg
, sizeof(msg
), "expected %hhu of %hhu",
1024 ii
+ 1, tap
->expected_ids_cnt
);
1025 jtag_examine_chain_display(LOG_LVL_ERROR
, msg
,
1026 tap
->dotted_name
, tap
->expected_ids
[ii
]);
1031 /* Try to examine chain layout according to IEEE 1149.1 §12
1033 static int jtag_examine_chain(void)
1035 u8 idcode_buffer
[JTAG_MAX_CHAIN_SIZE
* 4];
1036 unsigned device_count
= 0;
1038 jtag_examine_chain_execute(idcode_buffer
, JTAG_MAX_CHAIN_SIZE
);
1040 if (!jtag_examine_chain_check(idcode_buffer
, JTAG_MAX_CHAIN_SIZE
))
1041 return ERROR_JTAG_INIT_FAILED
;
1043 /* point at the 1st tap */
1044 jtag_tap_t
*tap
= jtag_tap_next_enabled(NULL
);
1047 LOG_ERROR("JTAG: No taps enabled?");
1048 return ERROR_JTAG_INIT_FAILED
;
1051 for (unsigned bit_count
= 0; bit_count
< (JTAG_MAX_CHAIN_SIZE
* 32) - 31;)
1053 u32 idcode
= buf_get_u32(idcode_buffer
, bit_count
, 32);
1054 if ((idcode
& 1) == 0)
1056 /* LSB must not be 0, this indicates a device in bypass */
1057 LOG_WARNING("Tap/Device does not have IDCODE");
1065 * End of chain (invalid manufacturer ID) some devices, such
1066 * as AVR will output all 1's instead of TDI input value at
1069 if (jtag_idcode_is_final(idcode
))
1071 jtag_examine_chain_end(idcode_buffer
,
1072 bit_count
+ 32, JTAG_MAX_CHAIN_SIZE
* 32);
1076 jtag_examine_chain_display(LOG_LVL_INFO
, "tap/device found",
1077 tap
? tap
->dotted_name
: "(not-named)",
1086 tap
->idcode
= idcode
;
1088 // ensure the TAP ID does matches what was expected
1089 if (!jtag_examine_chain_match_tap(tap
))
1090 return ERROR_JTAG_INIT_FAILED
;
1092 tap
= jtag_tap_next_enabled(tap
);
1095 /* see if number of discovered devices matches configuration */
1096 if (device_count
!= jtag_tap_count_enabled())
1098 LOG_ERROR("number of discovered devices in JTAG chain (%i) "
1099 "does not match (enabled) configuration (%i), total taps: %d",
1100 device_count
, jtag_tap_count_enabled(), jtag_tap_count());
1101 LOG_ERROR("check the config file and ensure proper JTAG communication"
1102 " (connections, speed, ...)");
1103 return ERROR_JTAG_INIT_FAILED
;
1109 static int jtag_validate_chain(void)
1112 int total_ir_length
= 0;
1118 total_ir_length
= 0;
1120 tap
= jtag_tap_next_enabled(tap
);
1124 total_ir_length
+= tap
->ir_length
;
1127 total_ir_length
+= 2;
1128 ir_test
= malloc(CEIL(total_ir_length
, 8));
1129 buf_set_ones(ir_test
, total_ir_length
);
1132 field
.num_bits
= total_ir_length
;
1133 field
.out_value
= ir_test
;
1134 field
.in_value
= ir_test
;
1137 jtag_add_plain_ir_scan(1, &field
, TAP_RESET
);
1138 jtag_execute_queue();
1144 tap
= jtag_tap_next_enabled(tap
);
1149 val
= buf_get_u32(ir_test
, chain_pos
, 2);
1152 char *cbuf
= buf_to_str(ir_test
, total_ir_length
, 16);
1153 LOG_ERROR("Could not validate JTAG scan chain, IR mismatch, scan returned 0x%s. tap=%s pos=%d expected 0x1 got %0x", cbuf
, jtag_tap_name(tap
), chain_pos
, val
);
1156 return ERROR_JTAG_INIT_FAILED
;
1158 chain_pos
+= tap
->ir_length
;
1161 val
= buf_get_u32(ir_test
, chain_pos
, 2);
1164 char *cbuf
= buf_to_str(ir_test
, total_ir_length
, 16);
1165 LOG_ERROR("Could not validate end of JTAG scan chain, IR mismatch, scan returned 0x%s. pos=%d expected 0x3 got %0x", cbuf
, chain_pos
, val
);
1168 return ERROR_JTAG_INIT_FAILED
;
1176 enum jtag_tap_cfg_param
{
1180 static Jim_Nvp nvp_config_opts
[] = {
1181 { .name
= "-event", .value
= JCFG_EVENT
},
1183 { .name
= NULL
, .value
= -1 }
1186 static int jtag_tap_configure_cmd( Jim_GetOptInfo
*goi
, jtag_tap_t
* tap
)
1192 /* parse config or cget options */
1193 while (goi
->argc
> 0) {
1194 Jim_SetEmptyResult (goi
->interp
);
1196 e
= Jim_GetOpt_Nvp(goi
, nvp_config_opts
, &n
);
1198 Jim_GetOpt_NvpUnknown(goi
, nvp_config_opts
, 0);
1204 if (goi
->argc
== 0) {
1205 Jim_WrongNumArgs( goi
->interp
, goi
->argc
, goi
->argv
, "-event ?event-name? ..." );
1209 e
= Jim_GetOpt_Nvp( goi
, nvp_jtag_tap_event
, &n
);
1211 Jim_GetOpt_NvpUnknown(goi
, nvp_jtag_tap_event
, 1);
1215 if (goi
->isconfigure
) {
1216 if (goi
->argc
!= 1) {
1217 Jim_WrongNumArgs(goi
->interp
, goi
->argc
, goi
->argv
, "-event ?event-name? ?EVENT-BODY?");
1221 if (goi
->argc
!= 0) {
1222 Jim_WrongNumArgs(goi
->interp
, goi
->argc
, goi
->argv
, "-event ?event-name?");
1228 jtag_tap_event_action_t
*jteap
;
1230 jteap
= tap
->event_action
;
1231 /* replace existing? */
1233 if (jteap
->event
== (enum jtag_tap_event
)n
->value
) {
1236 jteap
= jteap
->next
;
1239 if (goi
->isconfigure
) {
1240 if (jteap
== NULL
) {
1242 jteap
= calloc(1, sizeof (*jteap
));
1244 jteap
->event
= n
->value
;
1245 Jim_GetOpt_Obj( goi
, &o
);
1247 Jim_DecrRefCount(interp
, jteap
->body
);
1249 jteap
->body
= Jim_DuplicateObj(goi
->interp
, o
);
1250 Jim_IncrRefCount(jteap
->body
);
1252 /* add to head of event list */
1253 jteap
->next
= tap
->event_action
;
1254 tap
->event_action
= jteap
;
1255 Jim_SetEmptyResult(goi
->interp
);
1258 if (jteap
== NULL
) {
1259 Jim_SetEmptyResult(goi
->interp
);
1261 Jim_SetResult(goi
->interp
, Jim_DuplicateObj(goi
->interp
, jteap
->body
));
1268 } /* while (goi->argc) */
1274 static void jtag_tap_init(jtag_tap_t
*tap
)
1276 assert(0 != tap
->ir_length
);
1278 tap
->expected
= malloc(tap
->ir_length
);
1279 tap
->expected_mask
= malloc(tap
->ir_length
);
1280 tap
->cur_instr
= malloc(tap
->ir_length
);
1282 buf_set_u32(tap
->expected
, 0, tap
->ir_length
, tap
->ir_capture_value
);
1283 buf_set_u32(tap
->expected_mask
, 0, tap
->ir_length
, tap
->ir_capture_mask
);
1284 buf_set_ones(tap
->cur_instr
, tap
->ir_length
);
1286 // place TAP in bypass mode
1288 // register the reset callback for the TAP
1289 jtag_register_event_callback(&jtag_reset_callback
, tap
);
1291 LOG_DEBUG("Created Tap: %s @ abs position %d, "
1292 "irlen %d, capture: 0x%x mask: 0x%x", tap
->dotted_name
,
1293 tap
->abs_chain_position
, tap
->ir_length
,
1294 tap
->ir_capture_value
, tap
->ir_capture_mask
);
1298 static void jtag_tap_free(jtag_tap_t
*tap
)
1300 /// @todo is anything missing? no memory leaks please
1301 free((void *)tap
->expected_ids
);
1302 free((void *)tap
->chip
);
1303 free((void *)tap
->tapname
);
1304 free((void *)tap
->dotted_name
);
1308 static int jim_newtap_cmd( Jim_GetOptInfo
*goi
)
1317 const Jim_Nvp opts
[] = {
1318 #define NTAP_OPT_IRLEN 0
1319 { .name
= "-irlen" , .value
= NTAP_OPT_IRLEN
},
1320 #define NTAP_OPT_IRMASK 1
1321 { .name
= "-irmask" , .value
= NTAP_OPT_IRMASK
},
1322 #define NTAP_OPT_IRCAPTURE 2
1323 { .name
= "-ircapture" , .value
= NTAP_OPT_IRCAPTURE
},
1324 #define NTAP_OPT_ENABLED 3
1325 { .name
= "-enable" , .value
= NTAP_OPT_ENABLED
},
1326 #define NTAP_OPT_DISABLED 4
1327 { .name
= "-disable" , .value
= NTAP_OPT_DISABLED
},
1328 #define NTAP_OPT_EXPECTED_ID 5
1329 { .name
= "-expected-id" , .value
= NTAP_OPT_EXPECTED_ID
},
1330 { .name
= NULL
, .value
= -1 },
1333 pTap
= malloc( sizeof(jtag_tap_t
) );
1334 memset( pTap
, 0, sizeof(*pTap
) );
1336 Jim_SetResult_sprintf( goi
->interp
, "no memory");
1340 * we expect CHIP + TAP + OPTIONS
1342 if( goi
->argc
< 3 ){
1343 Jim_SetResult_sprintf(goi
->interp
, "Missing CHIP TAP OPTIONS ....");
1346 Jim_GetOpt_String( goi
, &cp
, NULL
);
1347 pTap
->chip
= strdup(cp
);
1349 Jim_GetOpt_String( goi
, &cp
, NULL
);
1350 pTap
->tapname
= strdup(cp
);
1352 /* name + dot + name + null */
1353 x
= strlen(pTap
->chip
) + 1 + strlen(pTap
->tapname
) + 1;
1355 sprintf( cp
, "%s.%s", pTap
->chip
, pTap
->tapname
);
1356 pTap
->dotted_name
= cp
;
1358 LOG_DEBUG("Creating New Tap, Chip: %s, Tap: %s, Dotted: %s, %d params",
1359 pTap
->chip
, pTap
->tapname
, pTap
->dotted_name
, goi
->argc
);
1361 /* default is enabled */
1364 /* deal with options */
1365 #define NTREQ_IRLEN 1
1366 #define NTREQ_IRCAPTURE 2
1367 #define NTREQ_IRMASK 4
1369 /* clear them as we find them */
1370 reqbits
= (NTREQ_IRLEN
| NTREQ_IRCAPTURE
| NTREQ_IRMASK
);
1373 e
= Jim_GetOpt_Nvp( goi
, opts
, &n
);
1375 Jim_GetOpt_NvpUnknown( goi
, opts
, 0 );
1378 LOG_DEBUG("Processing option: %s", n
->name
);
1380 case NTAP_OPT_ENABLED
:
1383 case NTAP_OPT_DISABLED
:
1386 case NTAP_OPT_EXPECTED_ID
:
1388 u32
*new_expected_ids
;
1390 e
= Jim_GetOpt_Wide( goi
, &w
);
1392 Jim_SetResult_sprintf(goi
->interp
, "option: %s bad parameter", n
->name
);
1396 new_expected_ids
= malloc(sizeof(u32
) * (pTap
->expected_ids_cnt
+ 1));
1397 if (new_expected_ids
== NULL
) {
1398 Jim_SetResult_sprintf( goi
->interp
, "no memory");
1402 memcpy(new_expected_ids
, pTap
->expected_ids
, sizeof(u32
) * pTap
->expected_ids_cnt
);
1404 new_expected_ids
[pTap
->expected_ids_cnt
] = w
;
1406 free(pTap
->expected_ids
);
1407 pTap
->expected_ids
= new_expected_ids
;
1408 pTap
->expected_ids_cnt
++;
1411 case NTAP_OPT_IRLEN
:
1412 case NTAP_OPT_IRMASK
:
1413 case NTAP_OPT_IRCAPTURE
:
1414 e
= Jim_GetOpt_Wide( goi
, &w
);
1416 Jim_SetResult_sprintf( goi
->interp
, "option: %s bad parameter", n
->name
);
1419 if( (w
< 0) || (w
> 0xffff) ){
1421 Jim_SetResult_sprintf( goi
->interp
, "option: %s - wacky value: %d (0x%x)",
1422 n
->name
, (int)(w
), (int)(w
));
1426 case NTAP_OPT_IRLEN
:
1427 pTap
->ir_length
= w
;
1428 reqbits
&= (~(NTREQ_IRLEN
));
1430 case NTAP_OPT_IRMASK
:
1431 pTap
->ir_capture_mask
= w
;
1432 reqbits
&= (~(NTREQ_IRMASK
));
1434 case NTAP_OPT_IRCAPTURE
:
1435 pTap
->ir_capture_value
= w
;
1436 reqbits
&= (~(NTREQ_IRCAPTURE
));
1439 } /* switch(n->value) */
1440 } /* while( goi->argc ) */
1442 /* Did all the required option bits get cleared? */
1445 jtag_tap_init(pTap
);
1449 Jim_SetResult_sprintf(goi
->interp
,
1450 "newtap: %s missing required parameters",
1452 jtag_tap_free(pTap
);
1456 static int jim_jtag_command( Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
1462 struct command_context_s
*context
;
1466 JTAG_CMD_INIT_RESET
,
1469 JTAG_CMD_TAPDISABLE
,
1470 JTAG_CMD_TAPISENABLED
,
1475 const Jim_Nvp jtag_cmds
[] = {
1476 { .name
= "interface" , .value
= JTAG_CMD_INTERFACE
},
1477 { .name
= "arp_init-reset", .value
= JTAG_CMD_INIT_RESET
},
1478 { .name
= "newtap" , .value
= JTAG_CMD_NEWTAP
},
1479 { .name
= "tapisenabled" , .value
= JTAG_CMD_TAPISENABLED
},
1480 { .name
= "tapenable" , .value
= JTAG_CMD_TAPENABLE
},
1481 { .name
= "tapdisable" , .value
= JTAG_CMD_TAPDISABLE
},
1482 { .name
= "configure" , .value
= JTAG_CMD_CONFIGURE
},
1483 { .name
= "cget" , .value
= JTAG_CMD_CGET
},
1485 { .name
= NULL
, .value
= -1 },
1488 context
= Jim_GetAssocData(interp
, "context");
1489 /* go past the command */
1490 Jim_GetOpt_Setup( &goi
, interp
, argc
-1, argv
+1 );
1492 e
= Jim_GetOpt_Nvp( &goi
, jtag_cmds
, &n
);
1494 Jim_GetOpt_NvpUnknown( &goi
, jtag_cmds
, 0 );
1497 Jim_SetEmptyResult( goi
.interp
);
1499 case JTAG_CMD_INTERFACE
:
1500 /* return the name of the interface */
1501 /* TCL code might need to know the exact type... */
1502 /* FUTURE: we allow this as a means to "set" the interface. */
1503 if( goi
.argc
!= 0 ){
1504 Jim_WrongNumArgs( goi
.interp
, 1, goi
.argv
-1, "(no params)");
1507 Jim_SetResultString( goi
.interp
, jtag_interface
->name
, -1 );
1509 case JTAG_CMD_INIT_RESET
:
1510 if( goi
.argc
!= 0 ){
1511 Jim_WrongNumArgs( goi
.interp
, 1, goi
.argv
-1, "(no params)");
1514 e
= jtag_init_reset(context
);
1515 if( e
!= ERROR_OK
){
1516 Jim_SetResult_sprintf( goi
.interp
, "error: %d", e
);
1520 case JTAG_CMD_NEWTAP
:
1521 return jim_newtap_cmd( &goi
);
1523 case JTAG_CMD_TAPISENABLED
:
1524 case JTAG_CMD_TAPENABLE
:
1525 case JTAG_CMD_TAPDISABLE
:
1526 if( goi
.argc
!= 1 ){
1527 Jim_SetResultString( goi
.interp
, "Too many parameters",-1 );
1533 t
= jtag_tap_by_jim_obj( goi
.interp
, goi
.argv
[0] );
1538 case JTAG_CMD_TAPISENABLED
:
1541 case JTAG_CMD_TAPENABLE
:
1542 jtag_tap_handle_event( t
, JTAG_TAP_EVENT_ENABLE
);
1546 case JTAG_CMD_TAPDISABLE
:
1547 jtag_tap_handle_event( t
, JTAG_TAP_EVENT_DISABLE
);
1552 Jim_SetResult( goi
.interp
, Jim_NewIntObj( goi
.interp
, e
) );
1559 Jim_WrongNumArgs( goi
.interp
, 0, NULL
, "?tap-name? -option ...");
1566 Jim_GetOpt_Obj(&goi
, &o
);
1567 t
= jtag_tap_by_jim_obj( goi
.interp
, o
);
1572 goi
.isconfigure
= 0;
1573 return jtag_tap_configure_cmd( &goi
, t
);
1577 case JTAG_CMD_CONFIGURE
:
1579 Jim_WrongNumArgs( goi
.interp
, 0, NULL
, "?tap-name? -option ?VALUE? ...");
1586 Jim_GetOpt_Obj(&goi
, &o
);
1587 t
= jtag_tap_by_jim_obj( goi
.interp
, o
);
1592 goi
.isconfigure
= 1;
1593 return jtag_tap_configure_cmd( &goi
, t
);
1600 int jtag_register_commands(struct command_context_s
*cmd_ctx
)
1602 register_jim( cmd_ctx
, "jtag", jim_jtag_command
, "perform jtag tap actions");
1604 register_command(cmd_ctx
, NULL
, "interface", handle_interface_command
,
1605 COMMAND_CONFIG
, "try to configure interface");
1606 register_command(cmd_ctx
, NULL
,
1607 "interface_list", &handle_interface_list_command
,
1608 COMMAND_ANY
, "list all built-in interfaces");
1609 register_command(cmd_ctx
, NULL
, "jtag_speed", handle_jtag_speed_command
,
1610 COMMAND_ANY
, "(DEPRECATED) set jtag speed (if supported)");
1611 register_command(cmd_ctx
, NULL
, "jtag_khz", handle_jtag_khz_command
,
1612 COMMAND_ANY
, "set maximum jtag speed (if supported); "
1613 "parameter is maximum khz, or 0 for adaptive clocking (RTCK).");
1614 register_command(cmd_ctx
, NULL
, "jtag_device", handle_jtag_device_command
,
1615 COMMAND_CONFIG
, "(DEPRECATED) jtag_device <ir_length> <ir_expected> <ir_mask>");
1616 register_command(cmd_ctx
, NULL
, "reset_config", handle_reset_config_command
,
1618 "[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]");
1619 register_command(cmd_ctx
, NULL
, "jtag_nsrst_delay", handle_jtag_nsrst_delay_command
,
1620 COMMAND_ANY
, "jtag_nsrst_delay <ms> - delay after deasserting srst in ms");
1621 register_command(cmd_ctx
, NULL
, "jtag_ntrst_delay", handle_jtag_ntrst_delay_command
,
1622 COMMAND_ANY
, "jtag_ntrst_delay <ms> - delay after deasserting trst in ms");
1624 register_command(cmd_ctx
, NULL
, "scan_chain", handle_scan_chain_command
,
1625 COMMAND_EXEC
, "print current scan chain configuration");
1627 register_command(cmd_ctx
, NULL
, "jtag_reset", handle_jtag_reset_command
,
1628 COMMAND_EXEC
, "toggle reset lines <trst> <srst>");
1629 register_command(cmd_ctx
, NULL
, "runtest", handle_runtest_command
,
1630 COMMAND_EXEC
, "move to Run-Test/Idle, and execute <num_cycles>");
1631 register_command(cmd_ctx
, NULL
, "irscan", handle_irscan_command
,
1632 COMMAND_EXEC
, "execute IR scan <device> <instr> [dev2] [instr2] ...");
1633 register_jim(cmd_ctx
, "drscan", Jim_Command_drscan
, "execute DR scan <device> <num_bits> <value> <num_bits1> <value2> ...");
1634 register_jim(cmd_ctx
, "flush_count", Jim_Command_flush_count
, "returns number of times the JTAG queue has been flushed");
1636 register_command(cmd_ctx
, NULL
, "verify_ircapture", handle_verify_ircapture_command
,
1637 COMMAND_ANY
, "verify value captured during Capture-IR <enable|disable>");
1638 register_command(cmd_ctx
, NULL
, "verify_jtag", handle_verify_jtag_command
,
1639 COMMAND_ANY
, "verify value capture <enable|disable>");
1640 register_command(cmd_ctx
, NULL
, "tms_sequence", handle_tms_sequence_command
,
1641 COMMAND_ANY
, "choose short(default) or long tms_sequence <short|long>");
1645 int jtag_interface_init(struct command_context_s
*cmd_ctx
)
1650 if (!jtag_interface
)
1652 /* nothing was previously specified by "interface" command */
1653 LOG_ERROR("JTAG interface has to be specified, see \"interface\" command");
1654 return ERROR_JTAG_INVALID_INTERFACE
;
1658 jtag_interface
->khz(jtag_get_speed_khz(), &jtag_speed
);
1662 if (jtag_interface
->init() != ERROR_OK
)
1663 return ERROR_JTAG_INIT_FAILED
;
1665 jtag
= jtag_interface
;
1669 static int jtag_init_inner(struct command_context_s
*cmd_ctx
)
1674 LOG_DEBUG("Init JTAG chain");
1676 tap
= jtag_tap_next_enabled(NULL
);
1678 LOG_ERROR("There are no enabled taps?");
1679 return ERROR_JTAG_INIT_FAILED
;
1683 if ((retval
=jtag_execute_queue())!=ERROR_OK
)
1686 /* examine chain first, as this could discover the real chain layout */
1687 if (jtag_examine_chain() != ERROR_OK
)
1689 LOG_ERROR("trying to validate configured JTAG chain anyway...");
1692 if (jtag_validate_chain() != ERROR_OK
)
1694 LOG_WARNING("Could not validate JTAG chain, continuing anyway...");
1700 int jtag_interface_quit(void)
1702 if (!jtag
|| !jtag
->quit
)
1705 // close the JTAG interface
1706 int result
= jtag
->quit();
1707 if (ERROR_OK
!= result
)
1708 LOG_ERROR("failed: %d", result
);
1714 int jtag_init_reset(struct command_context_s
*cmd_ctx
)
1718 if ((retval
=jtag_interface_init(cmd_ctx
)) != ERROR_OK
)
1721 LOG_DEBUG("Trying to bring the JTAG controller to life by asserting TRST / RESET");
1723 /* Reset can happen after a power cycle.
1725 * Ideally we would only assert TRST or run RESET before the target reset.
1727 * However w/srst_pulls_trst, trst is asserted together with the target
1728 * reset whether we want it or not.
1730 * NB! Some targets have JTAG circuitry disabled until a
1731 * trst & srst has been asserted.
1733 * NB! here we assume nsrst/ntrst delay are sufficient!
1735 * NB! order matters!!!! srst *can* disconnect JTAG circuitry
1738 jtag_add_reset(1, 0); /* RESET or TRST */
1739 if (jtag_reset_config
& RESET_HAS_SRST
)
1741 jtag_add_reset(1, 1);
1742 if ((jtag_reset_config
& RESET_SRST_PULLS_TRST
)==0)
1743 jtag_add_reset(0, 1);
1745 jtag_add_reset(0, 0);
1746 if ((retval
= jtag_execute_queue()) != ERROR_OK
)
1749 /* Check that we can communication on the JTAG chain + eventually we want to
1750 * be able to perform enumeration only after OpenOCD has started
1751 * telnet and GDB server
1753 * That would allow users to more easily perform any magic they need to before
1756 return jtag_init_inner(cmd_ctx
);
1759 int jtag_init(struct command_context_s
*cmd_ctx
)
1762 if ((retval
=jtag_interface_init(cmd_ctx
)) != ERROR_OK
)
1764 if (jtag_init_inner(cmd_ctx
)==ERROR_OK
)
1768 return jtag_init_reset(cmd_ctx
);
1771 void jtag_set_speed_khz(unsigned khz
)
1775 unsigned jtag_get_speed_khz(void)
1780 static int default_khz(int khz
, int *jtag_speed
)
1782 LOG_ERROR("Translation from khz to jtag_speed not implemented");
1786 static int default_speed_div(int speed
, int *khz
)
1788 LOG_ERROR("Translation from jtag_speed to khz not implemented");
1792 static int default_power_dropout(int *dropout
)
1794 *dropout
=0; /* by default we can't detect power dropout */
1798 static int default_srst_asserted(int *srst_asserted
)
1800 *srst_asserted
=0; /* by default we can't detect srst asserted */
1804 static int handle_interface_command(struct command_context_s
*cmd_ctx
,
1805 char *cmd
, char **args
, int argc
)
1807 /* check whether the interface is already configured */
1810 LOG_WARNING("Interface already configured, ignoring");
1814 /* interface name is a mandatory argument */
1815 if (argc
!= 1 || args
[0][0] == '\0')
1816 return ERROR_COMMAND_SYNTAX_ERROR
;
1818 for (unsigned i
= 0; NULL
!= jtag_interfaces
[i
]; i
++)
1820 if (strcmp(args
[0], jtag_interfaces
[i
]->name
) != 0)
1823 int retval
= jtag_interfaces
[i
]->register_commands(cmd_ctx
);
1824 if (ERROR_OK
!= retval
)
1827 jtag_interface
= jtag_interfaces
[i
];
1829 if (jtag_interface
->khz
== NULL
)
1830 jtag_interface
->khz
= default_khz
;
1831 if (jtag_interface
->speed_div
== NULL
)
1832 jtag_interface
->speed_div
= default_speed_div
;
1833 if (jtag_interface
->power_dropout
== NULL
)
1834 jtag_interface
->power_dropout
= default_power_dropout
;
1835 if (jtag_interface
->srst_asserted
== NULL
)
1836 jtag_interface
->srst_asserted
= default_srst_asserted
;
1841 /* no valid interface was found (i.e. the configuration option,
1842 * didn't match one of the compiled-in interfaces
1844 LOG_ERROR("The specified JTAG interface was not found (%s)", args
[0]);
1845 handle_interface_list_command(cmd_ctx
, cmd
, args
, argc
);
1846 return ERROR_JTAG_INVALID_INTERFACE
;
1849 static int handle_interface_list_command(struct command_context_s
*cmd_ctx
,
1850 char *cmd
, char **args
, int argc
)
1852 if (strcmp(cmd
, "interface_list") == 0 && argc
> 0)
1853 return ERROR_COMMAND_SYNTAX_ERROR
;
1855 command_print(cmd_ctx
, "The following JTAG interfaces are available:");
1856 for (unsigned i
= 0; NULL
!= jtag_interfaces
[i
]; i
++)
1858 const char *name
= jtag_interfaces
[i
]->name
;
1859 command_print(cmd_ctx
, "%u: %s", i
+ 1, name
);
1865 static int handle_jtag_device_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1869 Jim_Obj
*newargs
[ 10 ];
1872 * argv[-1] = command
1873 * argv[ 0] = ir length
1874 * argv[ 1] = ir capture
1875 * argv[ 2] = ir mask
1876 * argv[ 3] = not actually used by anything but in the docs
1880 command_print( cmd_ctx
, "OLD DEPRECATED SYNTAX: Please use the NEW syntax");
1883 command_print( cmd_ctx
, "OLD SYNTAX: DEPRECATED - translating to new syntax");
1884 command_print( cmd_ctx
, "jtag newtap CHIP TAP -irlen %s -ircapture %s -irvalue %s",
1888 command_print( cmd_ctx
, "Example: STM32 has 2 taps, the cortexM3(len4) + boundaryscan(len5)");
1889 command_print( cmd_ctx
, "jtag newtap stm32 cortexm3 ....., thus creating the tap: \"stm32.cortexm3\"");
1890 command_print( cmd_ctx
, "jtag newtap stm32 boundary ....., and the tap: \"stm32.boundary\"");
1891 command_print( cmd_ctx
, "And then refer to the taps by the dotted name.");
1893 newargs
[0] = Jim_NewStringObj( interp
, "jtag", -1 );
1894 newargs
[1] = Jim_NewStringObj( interp
, "newtap", -1 );
1895 sprintf( buf
, "chip%d", jtag_tap_count() );
1896 newargs
[2] = Jim_NewStringObj( interp
, buf
, -1 );
1897 sprintf( buf
, "tap%d", jtag_tap_count() );
1898 newargs
[3] = Jim_NewStringObj( interp
, buf
, -1 );
1899 newargs
[4] = Jim_NewStringObj( interp
, "-irlen", -1 );
1900 newargs
[5] = Jim_NewStringObj( interp
, args
[0], -1 );
1901 newargs
[6] = Jim_NewStringObj( interp
, "-ircapture", -1 );
1902 newargs
[7] = Jim_NewStringObj( interp
, args
[1], -1 );
1903 newargs
[8] = Jim_NewStringObj( interp
, "-irmask", -1 );
1904 newargs
[9] = Jim_NewStringObj( interp
, args
[2], -1 );
1906 command_print( cmd_ctx
, "NEW COMMAND:");
1907 sprintf( buf
, "%s %s %s %s %s %s %s %s %s %s",
1908 Jim_GetString( newargs
[0], NULL
),
1909 Jim_GetString( newargs
[1], NULL
),
1910 Jim_GetString( newargs
[2], NULL
),
1911 Jim_GetString( newargs
[3], NULL
),
1912 Jim_GetString( newargs
[4], NULL
),
1913 Jim_GetString( newargs
[5], NULL
),
1914 Jim_GetString( newargs
[6], NULL
),
1915 Jim_GetString( newargs
[7], NULL
),
1916 Jim_GetString( newargs
[8], NULL
),
1917 Jim_GetString( newargs
[9], NULL
) );
1919 e
= jim_jtag_command( interp
, 10, newargs
);
1921 command_print( cmd_ctx
, "%s", Jim_GetString( Jim_GetResult(interp
), NULL
) );
1926 static int handle_scan_chain_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1930 tap
= jtag_all_taps();
1931 command_print(cmd_ctx
, " TapName | Enabled | IdCode Expected IrLen IrCap IrMask Instr ");
1932 command_print(cmd_ctx
, "---|--------------------|---------|------------|------------|------|------|------|---------");
1935 u32 expected
, expected_mask
, cur_instr
, ii
;
1936 expected
= buf_get_u32(tap
->expected
, 0, tap
->ir_length
);
1937 expected_mask
= buf_get_u32(tap
->expected_mask
, 0, tap
->ir_length
);
1938 cur_instr
= buf_get_u32(tap
->cur_instr
, 0, tap
->ir_length
);
1940 command_print(cmd_ctx
,
1941 "%2d | %-18s | %c | 0x%08x | 0x%08x | 0x%02x | 0x%02x | 0x%02x | 0x%02x",
1942 tap
->abs_chain_position
,
1944 tap
->enabled
? 'Y' : 'n',
1946 (tap
->expected_ids_cnt
> 0 ? tap
->expected_ids
[0] : 0),
1952 for (ii
= 1; ii
< tap
->expected_ids_cnt
; ii
++) {
1953 command_print(cmd_ctx
, " | | | | 0x%08x | | | | ",
1954 tap
->expected_ids
[ii
]);
1957 tap
= tap
->next_tap
;
1963 static int handle_reset_config_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1969 return ERROR_COMMAND_SYNTAX_ERROR
;
1971 /* Original versions cared about the order of these tokens:
1972 * reset_config signals [combination [trst_type [srst_type]]]
1973 * They also clobbered the previous configuration even on error.
1975 * Here we don't care about the order, and only change values
1976 * which have been explicitly specified.
1978 for (; argc
; argc
--, args
++) {
1983 m
= RESET_HAS_TRST
| RESET_HAS_SRST
;
1984 if (strcmp(*args
, "none") == 0)
1986 else if (strcmp(*args
, "trst_only") == 0)
1987 tmp
= RESET_HAS_TRST
;
1988 else if (strcmp(*args
, "srst_only") == 0)
1989 tmp
= RESET_HAS_SRST
;
1990 else if (strcmp(*args
, "trst_and_srst") == 0)
1991 tmp
= RESET_HAS_TRST
| RESET_HAS_SRST
;
1995 LOG_ERROR("extra reset_config %s spec (%s)",
1997 return ERROR_INVALID_ARGUMENTS
;
2002 /* combination (options for broken wiring) */
2003 m
= RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
;
2004 if (strcmp(*args
, "separate") == 0)
2005 /* separate reset lines - default */;
2006 else if (strcmp(*args
, "srst_pulls_trst") == 0)
2007 tmp
|= RESET_SRST_PULLS_TRST
;
2008 else if (strcmp(*args
, "trst_pulls_srst") == 0)
2009 tmp
|= RESET_TRST_PULLS_SRST
;
2010 else if (strcmp(*args
, "combined") == 0)
2011 tmp
|= RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
;
2015 LOG_ERROR("extra reset_config %s spec (%s)",
2016 "combination", *args
);
2017 return ERROR_INVALID_ARGUMENTS
;
2022 /* trst_type (NOP without HAS_TRST) */
2023 m
= RESET_TRST_OPEN_DRAIN
;
2024 if (strcmp(*args
, "trst_open_drain") == 0)
2025 tmp
|= RESET_TRST_OPEN_DRAIN
;
2026 else if (strcmp(*args
, "trst_push_pull") == 0)
2027 /* push/pull from adapter - default */;
2031 LOG_ERROR("extra reset_config %s spec (%s)",
2032 "trst_type", *args
);
2033 return ERROR_INVALID_ARGUMENTS
;
2038 /* srst_type (NOP without HAS_SRST) */
2039 m
|= RESET_SRST_PUSH_PULL
;
2040 if (strcmp(*args
, "srst_push_pull") == 0)
2041 tmp
|= RESET_SRST_PUSH_PULL
;
2042 else if (strcmp(*args
, "srst_open_drain") == 0)
2043 /* open drain from adapter - default */;
2047 LOG_ERROR("extra reset_config %s spec (%s)",
2048 "srst_type", *args
);
2049 return ERROR_INVALID_ARGUMENTS
;
2054 /* caller provided nonsense; fail */
2055 LOG_ERROR("unknown reset_config flag (%s)", *args
);
2056 return ERROR_INVALID_ARGUMENTS
;
2059 /* Remember the bits which were specified (mask)
2060 * and their new values (new_cfg).
2066 /* clear previous values of those bits, save new values */
2067 jtag_reset_config
&= ~mask
;
2068 jtag_reset_config
|= new_cfg
;
2073 static int handle_jtag_nsrst_delay_command(struct command_context_s
*cmd_ctx
,
2074 char *cmd
, char **args
, int argc
)
2077 return ERROR_COMMAND_SYNTAX_ERROR
;
2079 jtag_set_nsrst_delay(strtoul(args
[0], NULL
, 0));
2080 command_print(cmd_ctx
, "jtag_nsrst_delay: %u", jtag_get_nsrst_delay());
2084 static int handle_jtag_ntrst_delay_command(struct command_context_s
*cmd_ctx
,
2085 char *cmd
, char **args
, int argc
)
2088 return ERROR_COMMAND_SYNTAX_ERROR
;
2090 jtag_set_ntrst_delay(strtoul(args
[0], NULL
, 0));
2091 command_print(cmd_ctx
, "jtag_ntrst_delay: %u", jtag_get_ntrst_delay());
2095 static int handle_jtag_speed_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2097 int retval
= ERROR_OK
;
2100 return ERROR_COMMAND_SYNTAX_ERROR
;
2103 LOG_DEBUG("handle jtag speed");
2106 cur_speed
= jtag_speed
= strtoul(args
[0], NULL
, 0);
2108 /* this command can be called during CONFIG,
2109 * in which case jtag isn't initialized */
2111 retval
= jtag
->speed(cur_speed
);
2113 command_print(cmd_ctx
, "jtag_speed: %d", jtag_speed
);
2118 static int handle_jtag_khz_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2121 return ERROR_COMMAND_SYNTAX_ERROR
;
2123 int retval
= ERROR_OK
;
2127 LOG_DEBUG("handle jtag khz");
2129 jtag_set_speed_khz(strtoul(args
[0], NULL
, 0));
2132 LOG_DEBUG("have interface set up");
2134 retval
= jtag
->khz(jtag_get_speed_khz(), &speed_div1
);
2135 if (ERROR_OK
!= retval
)
2137 jtag_set_speed_khz(0);
2140 cur_speed
= jtag_speed
= speed_div1
;
2142 retval
= jtag
->speed(cur_speed
);
2148 cur_speed
= jtag_get_speed_khz();
2151 retval
= jtag
->speed_div(jtag_speed
, &cur_speed
);
2152 if (ERROR_OK
!= retval
)
2157 command_print(cmd_ctx
, "%d kHz", cur_speed
);
2159 command_print(cmd_ctx
, "RCLK - adaptive");
2164 static int handle_jtag_reset_command(struct command_context_s
*cmd_ctx
,
2165 char *cmd
, char **args
, int argc
)
2168 return ERROR_COMMAND_SYNTAX_ERROR
;
2171 if (args
[0][0] == '1')
2173 else if (args
[0][0] == '0')
2176 return ERROR_COMMAND_SYNTAX_ERROR
;
2179 if (args
[1][0] == '1')
2181 else if (args
[1][0] == '0')
2184 return ERROR_COMMAND_SYNTAX_ERROR
;
2186 if (jtag_interface_init(cmd_ctx
) != ERROR_OK
)
2187 return ERROR_JTAG_INIT_FAILED
;
2189 jtag_add_reset(trst
, srst
);
2190 jtag_execute_queue();
2195 static int handle_runtest_command(struct command_context_s
*cmd_ctx
,
2196 char *cmd
, char **args
, int argc
)
2199 return ERROR_COMMAND_SYNTAX_ERROR
;
2201 jtag_add_runtest(strtol(args
[0], NULL
, 0), jtag_get_end_state());
2202 jtag_execute_queue();
2208 * For "irscan" or "drscan" commands, the "end" (really, "next") state
2209 * should be stable ... and *NOT* a shift state, otherwise free-running
2210 * jtag clocks could change the values latched by the update state.
2212 static bool scan_is_safe(tap_state_t state
)
2227 static int handle_irscan_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2230 scan_field_t
*fields
;
2232 tap_state_t endstate
;
2234 if ((argc
< 2) || (argc
% 2))
2236 return ERROR_COMMAND_SYNTAX_ERROR
;
2239 /* optional "-endstate" "statename" at the end of the arguments,
2240 * so that e.g. IRPAUSE can let us load the data register before
2241 * entering RUN/IDLE to execute the instruction we load here.
2243 endstate
= TAP_IDLE
;
2246 /* have at least one pair of numbers. */
2247 /* is last pair the magic text? */
2248 if( 0 == strcmp( "-endstate", args
[ argc
- 2 ] ) ){
2251 cpA
= args
[ argc
-1 ];
2252 for( endstate
= 0 ; endstate
< TAP_NUM_STATES
; endstate
++ ){
2253 cpS
= tap_state_name( endstate
);
2254 if( 0 == strcmp( cpA
, cpS
) ){
2258 if( endstate
>= TAP_NUM_STATES
){
2259 return ERROR_COMMAND_SYNTAX_ERROR
;
2261 if (!scan_is_safe(endstate
))
2262 LOG_WARNING("irscan with unsafe "
2263 "endstate \"%s\"", cpA
);
2264 /* found - remove the last 2 args */
2270 int num_fields
= argc
/ 2;
2272 fields
= malloc(sizeof(scan_field_t
) * num_fields
);
2274 for (i
= 0; i
< num_fields
; i
++)
2276 tap
= jtag_tap_by_string( args
[i
*2] );
2279 command_print( cmd_ctx
, "Tap: %s unknown", args
[i
*2] );
2282 int field_size
= tap
->ir_length
;
2283 fields
[i
].tap
= tap
;
2284 fields
[i
].num_bits
= field_size
;
2285 fields
[i
].out_value
= malloc(CEIL(field_size
, 8));
2286 buf_set_u32(fields
[i
].out_value
, 0, field_size
, strtoul(args
[i
*2+1], NULL
, 0));
2287 fields
[i
].in_value
= NULL
;
2290 /* did we have an endstate? */
2291 jtag_add_ir_scan(num_fields
, fields
, endstate
);
2293 int retval
=jtag_execute_queue();
2295 for (i
= 0; i
< num_fields
; i
++)
2296 free(fields
[i
].out_value
);
2303 static int Jim_Command_drscan(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *args
)
2306 scan_field_t
*fields
;
2308 int field_count
= 0;
2311 tap_state_t endstate
;
2314 * args[2] = num_bits
2315 * args[3] = hex string
2316 * ... repeat num bits and hex string ...
2319 * args[N-2] = "-endstate"
2320 * args[N-1] = statename
2322 if ((argc
< 4) || ((argc
% 2)!=0))
2324 Jim_WrongNumArgs(interp
, 1, args
, "wrong arguments");
2328 endstate
= TAP_IDLE
;
2330 /* validate arguments as numbers */
2332 for (i
= 2; i
< argc
; i
+=2)
2337 e
= Jim_GetLong(interp
, args
[i
], &bits
);
2338 /* If valid - try next arg */
2343 /* Not valid.. are we at the end? */
2344 if ( ((i
+2) != argc
) ){
2345 /* nope, then error */
2349 /* it could be: "-endstate FOO"
2350 * e.g. DRPAUSE so we can issue more instructions
2351 * before entering RUN/IDLE and executing them.
2354 /* get arg as a string. */
2355 cp
= Jim_GetString( args
[i
], NULL
);
2356 /* is it the magic? */
2357 if( 0 == strcmp( "-endstate", cp
) ){
2358 /* is the statename valid? */
2359 cp
= Jim_GetString( args
[i
+1], NULL
);
2361 /* see if it is a valid state name */
2362 endstate
= tap_state_by_name(cp
);
2364 /* update the error message */
2365 Jim_SetResult_sprintf(interp
,"endstate: %s invalid", cp
);
2367 if (!scan_is_safe(endstate
))
2368 LOG_WARNING("drscan with unsafe "
2369 "endstate \"%s\"", cp
);
2371 /* valid - so clear the error */
2373 /* and remove the last 2 args */
2378 /* Still an error? */
2380 return e
; /* too bad */
2382 } /* validate args */
2384 tap
= jtag_tap_by_jim_obj( interp
, args
[1] );
2389 num_fields
=(argc
-2)/2;
2390 fields
= malloc(sizeof(scan_field_t
) * num_fields
);
2391 for (i
= 2; i
< argc
; i
+=2)
2397 Jim_GetLong(interp
, args
[i
], &bits
);
2398 str
= Jim_GetString(args
[i
+1], &len
);
2400 fields
[field_count
].tap
= tap
;
2401 fields
[field_count
].num_bits
= bits
;
2402 fields
[field_count
].out_value
= malloc(CEIL(bits
, 8));
2403 str_to_buf(str
, len
, fields
[field_count
].out_value
, bits
, 0);
2404 fields
[field_count
].in_value
= fields
[field_count
].out_value
;
2408 jtag_add_dr_scan(num_fields
, fields
, endstate
);
2410 retval
= jtag_execute_queue();
2411 if (retval
!= ERROR_OK
)
2413 Jim_SetResultString(interp
, "drscan: jtag execute failed",-1);
2418 Jim_Obj
*list
= Jim_NewListObj(interp
, NULL
, 0);
2419 for (i
= 2; i
< argc
; i
+=2)
2424 Jim_GetLong(interp
, args
[i
], &bits
);
2425 str
= buf_to_str(fields
[field_count
].in_value
, bits
, 16);
2426 free(fields
[field_count
].out_value
);
2428 Jim_ListAppendElement(interp
, list
, Jim_NewStringObj(interp
, str
, strlen(str
)));
2433 Jim_SetResult(interp
, list
);
2441 static int Jim_Command_flush_count(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *args
)
2443 Jim_SetResult(interp
, Jim_NewIntObj(interp
, jtag_get_flush_queue_count()));
2449 static int handle_verify_ircapture_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2453 if (strcmp(args
[0], "enable") == 0)
2455 jtag_verify_capture_ir
= 1;
2457 else if (strcmp(args
[0], "disable") == 0)
2459 jtag_verify_capture_ir
= 0;
2462 return ERROR_COMMAND_SYNTAX_ERROR
;
2464 } else if (argc
!= 0)
2466 return ERROR_COMMAND_SYNTAX_ERROR
;
2469 command_print(cmd_ctx
, "verify Capture-IR is %s", (jtag_verify_capture_ir
) ? "enabled": "disabled");
2474 void jtag_set_verify(bool enable
)
2476 jtag_verify
= enable
;
2479 bool jtag_will_verify()
2484 static int handle_verify_jtag_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2487 return ERROR_COMMAND_SYNTAX_ERROR
;
2491 if (strcmp(args
[0], "enable") == 0)
2492 jtag_set_verify(true);
2493 else if (strcmp(args
[0], "disable") == 0)
2494 jtag_set_verify(false);
2496 return ERROR_COMMAND_SYNTAX_ERROR
;
2499 const char *status
= jtag_will_verify() ? "enabled": "disabled";
2500 command_print(cmd_ctx
, "verify jtag capture is %s", status
);
2506 int jtag_power_dropout(int *dropout
)
2508 return jtag
->power_dropout(dropout
);
2511 int jtag_srst_asserted(int *srst_asserted
)
2513 return jtag
->srst_asserted(srst_asserted
);
2516 void jtag_tap_handle_event( jtag_tap_t
* tap
, enum jtag_tap_event e
)
2518 jtag_tap_event_action_t
* jteap
;
2521 jteap
= tap
->event_action
;
2525 if (jteap
->event
== e
) {
2527 LOG_DEBUG( "JTAG tap: %s event: %d (%s) action: %s\n",
2530 Jim_Nvp_value2name_simple(nvp_jtag_tap_event
, e
)->name
,
2531 Jim_GetString(jteap
->body
, NULL
) );
2532 if (Jim_EvalObj(interp
, jteap
->body
) != JIM_OK
) {
2533 Jim_PrintErrorMessage(interp
);
2537 jteap
= jteap
->next
;
2541 LOG_DEBUG( "event %d %s - no action",
2543 Jim_Nvp_value2name_simple( nvp_jtag_tap_event
, e
)->name
);
2547 static int handle_tms_sequence_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2550 return ERROR_COMMAND_SYNTAX_ERROR
;
2555 if (strcmp(args
[0], "short") == 0)
2556 use_new_table
= true;
2557 else if (strcmp(args
[0], "long") == 0)
2558 use_new_table
= false;
2560 return ERROR_COMMAND_SYNTAX_ERROR
;
2562 tap_use_new_tms_table(use_new_table
);
2565 command_print(cmd_ctx
, "tms sequence is %s",
2566 tap_uses_new_tms_table() ? "short": "long");
2572 * Moves from the current state to the goal \a state. This needs
2573 * to be handled according to the xsvf spec, see the XSTATE command
2576 * From the XSVF spec, pertaining to XSTATE:
2578 * For special states known as stable states (Test-Logic-Reset,
2579 * Run-Test/Idle, Pause-DR, Pause- IR), an XSVF interpreter follows
2580 * predefined TAP state paths when the starting state is a stable state
2581 * and when the XSTATE specifies a new stable state. See the STATE
2582 * command in the [Ref 5] for the TAP state paths between stable
2585 * For non-stable states, XSTATE should specify a state that is only one
2586 * TAP state transition distance from the current TAP state to avoid
2587 * undefined TAP state paths. A sequence of multiple XSTATE commands can
2588 * be issued to transition the TAP through a specific state path.
2590 * @note Unless @a tms_bits holds a path that agrees with [Ref 5] in *
2591 * above spec, then this code is not fully conformant to the xsvf spec.
2592 * This puts a burden on tap_get_tms_path() function from the xsvf spec.
2593 * If in doubt, you should confirm that that burden is being met.
2595 * Otherwise, state must be immediately reachable in one clock cycle,
2596 * and does not need to be a stable state.
2598 int jtag_add_statemove(tap_state_t goal_state
)
2600 int retval
= ERROR_OK
;
2602 tap_state_t moves
[8];
2603 tap_state_t cur_state
= cmd_queue_cur_state
;
2608 LOG_DEBUG( "cur_state=%s goal_state=%s",
2609 tap_state_name(cur_state
),
2610 tap_state_name(goal_state
) );
2613 if (goal_state
==cur_state
)
2614 ; /* nothing to do */
2615 else if( goal_state
==TAP_RESET
)
2619 else if( tap_is_state_stable(cur_state
) && tap_is_state_stable(goal_state
) )
2621 tms_bits
= tap_get_tms_path(cur_state
, goal_state
);
2622 tms_count
= tap_get_tms_path_len(cur_state
, goal_state
);
2624 assert( (unsigned) tms_count
< DIM(moves
) );
2626 for (i
=0; i
<tms_count
; i
++, tms_bits
>>=1)
2628 bool bit
= tms_bits
& 1;
2630 cur_state
= tap_state_transition(cur_state
, bit
);
2631 moves
[i
] = cur_state
;
2634 jtag_add_pathmove(tms_count
, moves
);
2636 else if( tap_state_transition(cur_state
, true) == goal_state
2637 || tap_state_transition(cur_state
, false) == goal_state
)
2639 /* move a single state */
2640 moves
[0] = goal_state
;
2641 jtag_add_pathmove( 1, moves
);
2646 retval
= ERROR_FAIL
;
2652 void jtag_set_nsrst_delay(unsigned delay
)
2654 jtag_nsrst_delay
= delay
;
2656 unsigned jtag_get_nsrst_delay(void)
2658 return jtag_nsrst_delay
;
2660 void jtag_set_ntrst_delay(unsigned delay
)
2662 jtag_ntrst_delay
= delay
;
2664 unsigned jtag_get_ntrst_delay(void)
2666 return jtag_ntrst_delay
;
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)