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
;
102 #if BUILD_PARPORT == 1
103 extern jtag_interface_t parport_interface
;
107 extern jtag_interface_t dummy_interface
;
110 #if BUILD_FT2232_FTD2XX == 1
111 extern jtag_interface_t ft2232_interface
;
114 #if BUILD_FT2232_LIBFTDI == 1
115 extern jtag_interface_t ft2232_interface
;
118 #if BUILD_AMTJTAGACCEL == 1
119 extern jtag_interface_t amt_jtagaccel_interface
;
122 #if BUILD_EP93XX == 1
123 extern jtag_interface_t ep93xx_interface
;
126 #if BUILD_AT91RM9200 == 1
127 extern jtag_interface_t at91rm9200_interface
;
130 #if BUILD_GW16012 == 1
131 extern jtag_interface_t gw16012_interface
;
134 #if BUILD_PRESTO_LIBFTDI == 1 || BUILD_PRESTO_FTD2XX == 1
135 extern jtag_interface_t presto_interface
;
138 #if BUILD_USBPROG == 1
139 extern jtag_interface_t usbprog_interface
;
143 extern jtag_interface_t jlink_interface
;
146 #if BUILD_VSLLINK == 1
147 extern jtag_interface_t vsllink_interface
;
151 extern jtag_interface_t rlink_interface
;
154 #if BUILD_ARMJTAGEW == 1
155 extern jtag_interface_t armjtagew_interface
;
158 jtag_interface_t
*jtag_interfaces
[] = {
159 #if BUILD_ECOSBOARD == 1
162 #if BUILD_PARPORT == 1
168 #if BUILD_FT2232_FTD2XX == 1
171 #if BUILD_FT2232_LIBFTDI == 1
174 #if BUILD_AMTJTAGACCEL == 1
175 &amt_jtagaccel_interface
,
177 #if BUILD_EP93XX == 1
180 #if BUILD_AT91RM9200 == 1
181 &at91rm9200_interface
,
183 #if BUILD_GW16012 == 1
186 #if BUILD_PRESTO_LIBFTDI == 1 || BUILD_PRESTO_FTD2XX == 1
189 #if BUILD_USBPROG == 1
195 #if BUILD_VSLLINK == 1
201 #if BUILD_ARMJTAGEW == 1
202 &armjtagew_interface
,
207 struct jtag_interface_s
*jtag
= NULL
;
210 static jtag_interface_t
*jtag_interface
= NULL
;
214 static int handle_interface_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
215 static int handle_jtag_speed_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
216 static int handle_jtag_khz_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
217 static int handle_jtag_device_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
218 static int handle_reset_config_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
219 static int handle_jtag_nsrst_delay_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
220 static int handle_jtag_ntrst_delay_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
222 static int handle_scan_chain_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
224 static int handle_endstate_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
225 static int handle_jtag_reset_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
226 static int handle_runtest_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
227 static int handle_irscan_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
228 static int Jim_Command_drscan(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
);
229 static int Jim_Command_flush_count(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *args
);
231 static int handle_verify_ircapture_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
232 static int handle_verify_jtag_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
233 static int handle_tms_sequence_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
235 jtag_tap_t
*jtag_all_taps(void)
237 return __jtag_all_taps
;
240 int jtag_tap_count(void)
242 return jtag_num_taps
;
245 int jtag_tap_count_enabled(void)
261 /// Append a new TAP to the chain of all taps.
262 static void jtag_tap_add(struct jtag_tap_s
*t
)
264 t
->abs_chain_position
= jtag_num_taps
++;
266 jtag_tap_t
**tap
= &__jtag_all_taps
;
268 tap
= &(*tap
)->next_tap
;
272 jtag_tap_t
*jtag_tap_by_string( const char *s
)
280 if( 0 == strcmp( t
->dotted_name
, s
) ){
286 /* backup plan is by number */
288 /* ok - is "s" a number? */
290 n
= strtol( s
, &cp
, 0 );
291 if( (s
!= cp
) && (*cp
== 0) ){
293 t
= jtag_tap_by_abs_position(n
);
299 jtag_tap_t
* jtag_tap_by_jim_obj( Jim_Interp
*interp
, Jim_Obj
*o
)
304 cp
= Jim_GetString( o
, NULL
);
309 t
= jtag_tap_by_string( cp
);
312 Jim_SetResult_sprintf(interp
,"Tap: %s is unknown", cp
);
317 /* returns a pointer to the n-th device in the scan chain */
318 jtag_tap_t
* jtag_tap_by_abs_position( int n
)
326 while( t
&& (n
> 0)) {
333 const char *jtag_tap_name(const jtag_tap_t
*tap
)
335 return (tap
== NULL
) ? "(unknown)" : tap
->dotted_name
;
339 int jtag_register_event_callback(int (*callback
)(enum jtag_event event
, void *priv
), void *priv
)
341 jtag_event_callback_t
**callbacks_p
= &jtag_event_callbacks
;
343 if (callback
== NULL
)
345 return ERROR_INVALID_ARGUMENTS
;
350 while ((*callbacks_p
)->next
)
351 callbacks_p
= &((*callbacks_p
)->next
);
352 callbacks_p
= &((*callbacks_p
)->next
);
355 (*callbacks_p
) = malloc(sizeof(jtag_event_callback_t
));
356 (*callbacks_p
)->callback
= callback
;
357 (*callbacks_p
)->priv
= priv
;
358 (*callbacks_p
)->next
= NULL
;
363 int jtag_unregister_event_callback(int (*callback
)(enum jtag_event event
, void *priv
))
365 jtag_event_callback_t
**callbacks_p
= &jtag_event_callbacks
;
367 if (callback
== NULL
)
369 return ERROR_INVALID_ARGUMENTS
;
374 jtag_event_callback_t
**next
= &((*callbacks_p
)->next
);
375 if ((*callbacks_p
)->callback
== callback
)
378 *callbacks_p
= *next
;
386 int jtag_call_event_callbacks(enum jtag_event event
)
388 jtag_event_callback_t
*callback
= jtag_event_callbacks
;
390 LOG_DEBUG("jtag event: %s", jtag_event_strings
[event
]);
394 callback
->callback(event
, callback
->priv
);
395 callback
= callback
->next
;
401 static void jtag_checks(void)
403 assert(jtag_trst
== 0);
406 static void jtag_prelude(tap_state_t state
)
410 assert(state
!=TAP_INVALID
);
412 cmd_queue_cur_state
= state
;
415 void jtag_alloc_in_value32(scan_field_t
*field
)
417 interface_jtag_alloc_in_value32(field
);
420 void jtag_add_ir_scan_noverify(int in_num_fields
, const scan_field_t
*in_fields
, tap_state_t state
)
425 retval
=interface_jtag_add_ir_scan(in_num_fields
, in_fields
, state
);
426 if (retval
!=ERROR_OK
)
433 * Generate an IR SCAN with a list of scan fields with one entry for each enabled TAP.
435 * If the input field list contains an instruction value for a TAP then that is used
436 * otherwise the TAP is set to bypass.
438 * TAPs for which no fields are passed are marked as bypassed for subsequent DR SCANs.
441 void jtag_add_ir_scan(int in_num_fields
, scan_field_t
*in_fields
, tap_state_t state
)
443 if (jtag_verify
&&jtag_verify_capture_ir
)
445 /* 8 x 32 bit id's is enough for all invocations */
447 for (int j
= 0; j
< in_num_fields
; j
++)
449 /* if we are to run a verification of the ir scan, we need to get the input back.
450 * We may have to allocate space if the caller didn't ask for the input back.
452 in_fields
[j
].check_value
=in_fields
[j
].tap
->expected
;
453 in_fields
[j
].check_mask
=in_fields
[j
].tap
->expected_mask
;
455 jtag_add_scan_check(jtag_add_ir_scan_noverify
, in_num_fields
, in_fields
, state
);
458 jtag_add_ir_scan_noverify(in_num_fields
, in_fields
, state
);
463 * Duplicate the scan fields passed into the function into an IR SCAN command
465 * This function assumes that the caller handles extra fields for bypassed TAPs
468 void jtag_add_plain_ir_scan(int in_num_fields
, const scan_field_t
*in_fields
, tap_state_t state
)
474 retval
=interface_jtag_add_plain_ir_scan(in_num_fields
, in_fields
, state
);
475 if (retval
!=ERROR_OK
)
479 void jtag_add_callback(jtag_callback1_t f
, u8
*in
)
481 interface_jtag_add_callback(f
, in
);
484 void jtag_add_callback4(jtag_callback_t f
, u8
*in
,
485 jtag_callback_data_t data1
, jtag_callback_data_t data2
,
486 jtag_callback_data_t data3
)
488 interface_jtag_add_callback4(f
, in
, data1
, data2
, data3
);
491 int jtag_check_value_inner(u8
*captured
, u8
*in_check_value
, u8
*in_check_mask
, int num_bits
);
493 static int jtag_check_value_mask_callback(u8
*in
, jtag_callback_data_t data1
, jtag_callback_data_t data2
, jtag_callback_data_t data3
)
495 return jtag_check_value_inner(in
, (u8
*)data1
, (u8
*)data2
, (int)data3
);
498 static void jtag_add_scan_check(void (*jtag_add_scan
)(int in_num_fields
, const scan_field_t
*in_fields
, tap_state_t state
),
499 int in_num_fields
, scan_field_t
*in_fields
, tap_state_t state
)
501 for (int i
= 0; i
< in_num_fields
; i
++)
503 struct scan_field_s
*field
= &in_fields
[i
];
504 field
->allocated
= 0;
506 if (field
->check_value
|| field
->in_value
)
508 interface_jtag_add_scan_check_alloc(field
);
512 jtag_add_scan(in_num_fields
, in_fields
, state
);
514 for (int i
= 0; i
< in_num_fields
; i
++)
516 if ((in_fields
[i
].check_value
!= NULL
) && (in_fields
[i
].in_value
!= NULL
))
518 /* this is synchronous for a minidriver */
519 jtag_add_callback4(jtag_check_value_mask_callback
, in_fields
[i
].in_value
,
520 (jtag_callback_data_t
)in_fields
[i
].check_value
,
521 (jtag_callback_data_t
)in_fields
[i
].check_mask
,
522 (jtag_callback_data_t
)in_fields
[i
].num_bits
);
524 if (in_fields
[i
].allocated
)
526 free(in_fields
[i
].in_value
);
528 if (in_fields
[i
].modified
)
530 in_fields
[i
].in_value
= NULL
;
535 void jtag_add_dr_scan_check(int in_num_fields
, scan_field_t
*in_fields
, tap_state_t state
)
539 jtag_add_scan_check(jtag_add_dr_scan
, in_num_fields
, in_fields
, state
);
542 jtag_add_dr_scan(in_num_fields
, in_fields
, state
);
548 * Generate a DR SCAN using the fields passed to the function
550 * For not bypassed TAPs the function checks in_fields and uses fields specified there.
551 * For bypassed TAPs the function generates a dummy 1bit field.
553 * The bypass status of TAPs is set by jtag_add_ir_scan().
556 void jtag_add_dr_scan(int in_num_fields
, const scan_field_t
*in_fields
, tap_state_t state
)
562 retval
=interface_jtag_add_dr_scan(in_num_fields
, in_fields
, state
);
563 if (retval
!=ERROR_OK
)
570 * Duplicate the scan fields passed into the function into a DR SCAN command
572 * This function assumes that the caller handles extra fields for bypassed TAPs
575 void jtag_add_plain_dr_scan(int in_num_fields
, const scan_field_t
*in_fields
, tap_state_t state
)
581 retval
=interface_jtag_add_plain_dr_scan(in_num_fields
, in_fields
, state
);
582 if (retval
!=ERROR_OK
)
586 void jtag_add_dr_out(jtag_tap_t
* tap
,
587 int num_fields
, const int* num_bits
, const u32
* value
,
588 tap_state_t end_state
)
590 assert(end_state
!= TAP_INVALID
);
592 cmd_queue_cur_state
= end_state
;
594 interface_jtag_add_dr_out(tap
,
595 num_fields
, num_bits
, value
,
599 void jtag_add_tlr(void)
601 jtag_prelude(TAP_RESET
);
604 retval
=interface_jtag_add_tlr();
605 if (retval
!=ERROR_OK
)
608 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
611 void jtag_add_pathmove(int num_states
, const tap_state_t
*path
)
613 tap_state_t cur_state
= cmd_queue_cur_state
;
617 /* the last state has to be a stable state */
618 if (!tap_is_state_stable(path
[num_states
- 1]))
620 LOG_ERROR("BUG: TAP path doesn't finish in a stable state");
624 for (i
=0; i
<num_states
; i
++)
626 if (path
[i
] == TAP_RESET
)
628 LOG_ERROR("BUG: TAP_RESET is not a valid state for pathmove sequences");
632 if ( tap_state_transition(cur_state
, true) != path
[i
]
633 && tap_state_transition(cur_state
, false) != path
[i
])
635 LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_name(cur_state
), tap_state_name(path
[i
]));
643 retval
= interface_jtag_add_pathmove(num_states
, path
);
644 cmd_queue_cur_state
= path
[num_states
- 1];
645 if (retval
!=ERROR_OK
)
649 void jtag_add_runtest(int num_cycles
, tap_state_t state
)
655 /* executed by sw or hw fifo */
656 retval
=interface_jtag_add_runtest(num_cycles
, state
);
657 if (retval
!=ERROR_OK
)
662 void jtag_add_clocks( int num_cycles
)
666 if( !tap_is_state_stable(cmd_queue_cur_state
) )
668 LOG_ERROR( "jtag_add_clocks() was called with TAP in non-stable state \"%s\"",
669 tap_state_name(cmd_queue_cur_state
) );
670 jtag_error
= ERROR_JTAG_NOT_STABLE_STATE
;
678 retval
= interface_jtag_add_clocks(num_cycles
);
679 if (retval
!= ERROR_OK
)
684 void jtag_add_reset(int req_tlr_or_trst
, int req_srst
)
686 int trst_with_tlr
= 0;
689 /* FIX!!! there are *many* different cases here. A better
690 * approach is needed for legal combinations of transitions...
692 if ((jtag_reset_config
& RESET_HAS_SRST
)&&
693 (jtag_reset_config
& RESET_HAS_TRST
)&&
694 ((jtag_reset_config
& RESET_SRST_PULLS_TRST
)==0))
696 if (((req_tlr_or_trst
&&!jtag_trst
)||
697 (!req_tlr_or_trst
&&jtag_trst
))&&
698 ((req_srst
&&!jtag_srst
)||
699 (!req_srst
&&jtag_srst
)))
701 /* FIX!!! srst_pulls_trst allows 1,1 => 0,0 transition.... */
702 //LOG_ERROR("BUG: transition of req_tlr_or_trst and req_srst in the same jtag_add_reset() call is undefined");
706 /* Make sure that jtag_reset_config allows the requested reset */
707 /* if SRST pulls TRST, we can't fulfill srst == 1 with trst == 0 */
708 if (((jtag_reset_config
& RESET_SRST_PULLS_TRST
) && (req_srst
== 1)) && (!req_tlr_or_trst
))
710 LOG_ERROR("BUG: requested reset would assert trst");
711 jtag_error
=ERROR_FAIL
;
715 /* if TRST pulls SRST, we reset with TAP T-L-R */
716 if (((jtag_reset_config
& RESET_TRST_PULLS_SRST
) && (req_tlr_or_trst
)) && (req_srst
== 0))
721 if (req_srst
&& !(jtag_reset_config
& RESET_HAS_SRST
))
723 LOG_ERROR("BUG: requested SRST assertion, but the current configuration doesn't support this");
724 jtag_error
=ERROR_FAIL
;
730 if (!trst_with_tlr
&& (jtag_reset_config
& RESET_HAS_TRST
))
742 jtag_srst
= req_srst
;
744 retval
= interface_jtag_add_reset(jtag_trst
, jtag_srst
);
745 if (retval
!=ERROR_OK
)
750 jtag_execute_queue();
754 LOG_DEBUG("SRST line asserted");
758 LOG_DEBUG("SRST line released");
759 if (jtag_nsrst_delay
)
760 jtag_add_sleep(jtag_nsrst_delay
* 1000);
765 LOG_DEBUG("JTAG reset with RESET instead of TRST");
766 jtag_set_end_state(TAP_RESET
);
773 /* we just asserted nTRST, so we're now in Test-Logic-Reset,
774 * and inform possible listeners about this
776 LOG_DEBUG("TRST line asserted");
777 tap_set_state(TAP_RESET
);
778 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
782 if (jtag_ntrst_delay
)
783 jtag_add_sleep(jtag_ntrst_delay
* 1000);
787 tap_state_t
jtag_set_end_state(tap_state_t state
)
789 if ((state
== TAP_DRSHIFT
)||(state
== TAP_IRSHIFT
))
791 LOG_ERROR("BUG: TAP_DRSHIFT/IRSHIFT can't be end state. Calling code should use a larger scan field");
794 if (state
!=TAP_INVALID
)
795 cmd_queue_end_state
= state
;
796 return cmd_queue_end_state
;
799 tap_state_t
jtag_get_end_state(void)
801 return cmd_queue_end_state
;
804 void jtag_add_sleep(u32 us
)
806 keep_alive(); /* we might be running on a very slow JTAG clk */
807 int retval
=interface_jtag_add_sleep(us
);
808 if (retval
!=ERROR_OK
)
813 int jtag_check_value_inner(u8
*captured
, u8
*in_check_value
, u8
*in_check_mask
, int num_bits
)
815 int retval
= ERROR_OK
;
817 int compare_failed
= 0;
820 compare_failed
= buf_cmp_mask(captured
, in_check_value
, in_check_mask
, num_bits
);
822 compare_failed
= buf_cmp(captured
, in_check_value
, num_bits
);
825 /* An error handler could have caught the failing check
826 * only report a problem when there wasn't a handler, or if the handler
827 * acknowledged the error
830 LOG_WARNING("TAP %s:",
831 jtag_tap_name(field->tap));
835 char *captured_char
= buf_to_str(captured
, (num_bits
> DEBUG_JTAG_IOZ
) ? DEBUG_JTAG_IOZ
: num_bits
, 16);
836 char *in_check_value_char
= buf_to_str(in_check_value
, (num_bits
> DEBUG_JTAG_IOZ
) ? DEBUG_JTAG_IOZ
: num_bits
, 16);
840 char *in_check_mask_char
;
841 in_check_mask_char
= buf_to_str(in_check_mask
, (num_bits
> DEBUG_JTAG_IOZ
) ? DEBUG_JTAG_IOZ
: num_bits
, 16);
842 LOG_WARNING("value captured during scan didn't pass the requested check:");
843 LOG_WARNING("captured: 0x%s check_value: 0x%s check_mask: 0x%s",
844 captured_char
, in_check_value_char
, in_check_mask_char
);
845 free(in_check_mask_char
);
849 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
);
853 free(in_check_value_char
);
855 retval
= ERROR_JTAG_QUEUE_FAILED
;
862 void jtag_check_value_mask(scan_field_t
*field
, u8
*value
, u8
*mask
)
864 assert(field
->in_value
!= NULL
);
868 /* no checking to do */
872 jtag_execute_queue_noclear();
874 int retval
=jtag_check_value_inner(field
->in_value
, value
, mask
, field
->num_bits
);
875 jtag_set_error(retval
);
880 int default_interface_jtag_execute_queue(void)
884 LOG_ERROR("No JTAG interface configured yet. "
885 "Issue 'init' command in startup scripts "
886 "before communicating with targets.");
890 return jtag
->execute_queue();
893 void jtag_execute_queue_noclear(void)
895 /* each flush can take as much as 1-2ms on high bandwidth low latency interfaces.
896 * E.g. a JTAG over TCP/IP or USB....
898 jtag_flush_queue_count
++;
900 int retval
=interface_jtag_execute_queue();
901 /* we keep the first error */
902 if ((jtag_error
==ERROR_OK
)&&(retval
!=ERROR_OK
))
908 int jtag_get_flush_queue_count(void)
910 return jtag_flush_queue_count
;
913 int jtag_execute_queue(void)
916 jtag_execute_queue_noclear();
922 static int jtag_reset_callback(enum jtag_event event
, void *priv
)
924 jtag_tap_t
*tap
= priv
;
928 if (event
== JTAG_TRST_ASSERTED
)
930 buf_set_ones(tap
->cur_instr
, tap
->ir_length
);
937 void jtag_sleep(u32 us
)
939 alive_sleep(us
/1000);
942 /// maximum number of JTAG devices expected in the chain
943 #define JTAG_MAX_CHAIN_SIZE 20
945 #define EXTRACT_MFG(X) (((X) & 0xffe) >> 1)
946 #define EXTRACT_PART(X) (((X) & 0xffff000) >> 12)
947 #define EXTRACT_VER(X) (((X) & 0xf0000000) >> 28)
949 static int jtag_examine_chain_execute(u8
*idcode_buffer
, unsigned num_idcode
)
951 scan_field_t field
= {
953 .num_bits
= num_idcode
* 32,
954 .out_value
= idcode_buffer
,
955 .in_value
= idcode_buffer
,
958 // initialize to the end of chain ID value
959 for (unsigned i
= 0; i
< JTAG_MAX_CHAIN_SIZE
; i
++)
960 buf_set_u32(idcode_buffer
, i
* 32, 32, 0x000000FF);
962 jtag_add_plain_dr_scan(1, &field
, TAP_RESET
);
963 return jtag_execute_queue();
966 static bool jtag_examine_chain_check(u8
*idcodes
, unsigned count
)
971 for (unsigned i
= 0; i
< count
* 4; i
++)
973 zero_check
|= idcodes
[i
];
974 one_check
&= idcodes
[i
];
977 /* if there wasn't a single non-zero bit or if all bits were one,
978 * the scan is not valid */
979 if (zero_check
== 0x00 || one_check
== 0xff)
981 LOG_ERROR("JTAG communication failure: check connection, "
982 "JTAG interface, target power etc.");
988 static void jtag_examine_chain_display(enum log_levels level
, const char *msg
,
989 const char *name
, u32 idcode
)
991 log_printf_lf(level
, __FILE__
, __LINE__
, __FUNCTION__
,
992 "JTAG tap: %s %16.16s: 0x%08x "
993 "(mfg: 0x%3.3x, part: 0x%4.4x, ver: 0x%1.1x)",
995 EXTRACT_MFG(idcode
), EXTRACT_PART(idcode
), EXTRACT_VER(idcode
) );
999 * This helper checks that remaining bits in the examined chain data are
1000 * all as expected, but a single JTAG device requires only 64 bits to be
1001 * read back correctly. This can help identify and diagnose problems
1002 * with the JTAG chain earlier, gives more helpful/explicit error messages.
1004 static void jtag_examine_chain_end(u8
*idcodes
, unsigned count
, unsigned max
)
1006 bool triggered
= false;
1007 for ( ; count
< max
- 31; count
+= 32)
1009 u32 idcode
= buf_get_u32(idcodes
, count
, 32);
1010 // do not trigger the warning if the data looks good
1011 if (!triggered
&& (idcode
== 0x000000FF || idcode
== 0xFFFFFFFF))
1013 LOG_WARNING("Unexpected idcode after end of chain: %d 0x%08x",
1019 /* Try to examine chain layout according to IEEE 1149.1 §12
1021 static int jtag_examine_chain(void)
1024 u8 idcode_buffer
[JTAG_MAX_CHAIN_SIZE
* 4];
1026 int device_count
= 0;
1028 jtag_examine_chain_execute(idcode_buffer
, JTAG_MAX_CHAIN_SIZE
);
1030 if (!jtag_examine_chain_check(idcode_buffer
, JTAG_MAX_CHAIN_SIZE
))
1031 return ERROR_JTAG_INIT_FAILED
;
1033 /* point at the 1st tap */
1034 tap
= jtag_tap_next_enabled(NULL
);
1036 LOG_ERROR("JTAG: No taps enabled?");
1037 return ERROR_JTAG_INIT_FAILED
;
1040 for (bit_count
= 0; bit_count
< (JTAG_MAX_CHAIN_SIZE
* 32) - 31;)
1042 u32 idcode
= buf_get_u32(idcode_buffer
, bit_count
, 32);
1043 if ((idcode
& 1) == 0)
1045 /* LSB must not be 0, this indicates a device in bypass */
1046 LOG_WARNING("Tap/Device does not have IDCODE");
1054 * End of chain (invalid manufacturer ID) some devices, such
1055 * as AVR will output all 1's instead of TDI input value at
1058 if ((idcode
== 0x000000FF)||(idcode
== 0xFFFFFFFF))
1060 jtag_examine_chain_end(idcode_buffer
,
1061 bit_count
+ 32, JTAG_MAX_CHAIN_SIZE
* 32);
1065 jtag_examine_chain_display(LOG_LVL_INFO
, "tap/device found",
1066 tap
? tap
->dotted_name
: "(not-named)",
1075 tap
->idcode
= idcode
;
1077 if (0 == tap
->expected_ids_cnt
)
1079 // @todo Enable LOG_INFO to ask for reports about unknown TAP IDs.
1081 LOG_INFO("Uknown JTAG TAP ID: 0x%08x", tap
->idcode
)
1082 LOG_INFO("Please report the chip name and reported ID code to the openocd project");
1084 tap
= jtag_tap_next_enabled(tap
);
1087 /* Loop over the expected identification codes and test for a match */
1089 for (ii
= 0; ii
< tap
->expected_ids_cnt
; ii
++) {
1090 if (tap
->idcode
== tap
->expected_ids
[ii
]) {
1095 /* If none of the expected ids matched, log an error */
1096 if (ii
!= tap
->expected_ids_cnt
)
1098 LOG_INFO("JTAG Tap/device matched");
1099 tap
= jtag_tap_next_enabled(tap
);
1102 jtag_examine_chain_display(LOG_LVL_ERROR
, "got",
1103 tap
->dotted_name
, tap
->idcode
);
1104 for (ii
= 0; ii
< tap
->expected_ids_cnt
; ii
++) {
1106 snprintf(msg
, 20, "expected %hhu of %hhu",
1107 ii
+ 1, tap
->expected_ids_cnt
);
1108 jtag_examine_chain_display(LOG_LVL_ERROR
, msg
,
1109 tap
->dotted_name
, tap
->expected_ids
[ii
]);
1111 return ERROR_JTAG_INIT_FAILED
;
1114 /* see if number of discovered devices matches configuration */
1115 if (device_count
!= jtag_tap_count_enabled())
1117 LOG_ERROR("number of discovered devices in JTAG chain (%i) doesn't match (enabled) configuration (%i), total taps: %d",
1118 device_count
, jtag_tap_count_enabled(), jtag_tap_count());
1119 LOG_ERROR("check the config file and ensure proper JTAG communication (connections, speed, ...)");
1120 return ERROR_JTAG_INIT_FAILED
;
1126 static int jtag_validate_chain(void)
1129 int total_ir_length
= 0;
1135 total_ir_length
= 0;
1137 tap
= jtag_tap_next_enabled(tap
);
1141 total_ir_length
+= tap
->ir_length
;
1144 total_ir_length
+= 2;
1145 ir_test
= malloc(CEIL(total_ir_length
, 8));
1146 buf_set_ones(ir_test
, total_ir_length
);
1149 field
.num_bits
= total_ir_length
;
1150 field
.out_value
= ir_test
;
1151 field
.in_value
= ir_test
;
1154 jtag_add_plain_ir_scan(1, &field
, TAP_RESET
);
1155 jtag_execute_queue();
1161 tap
= jtag_tap_next_enabled(tap
);
1166 val
= buf_get_u32(ir_test
, chain_pos
, 2);
1169 char *cbuf
= buf_to_str(ir_test
, total_ir_length
, 16);
1170 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
);
1173 return ERROR_JTAG_INIT_FAILED
;
1175 chain_pos
+= tap
->ir_length
;
1178 val
= buf_get_u32(ir_test
, chain_pos
, 2);
1181 char *cbuf
= buf_to_str(ir_test
, total_ir_length
, 16);
1182 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
);
1185 return ERROR_JTAG_INIT_FAILED
;
1193 enum jtag_tap_cfg_param
{
1197 static Jim_Nvp nvp_config_opts
[] = {
1198 { .name
= "-event", .value
= JCFG_EVENT
},
1200 { .name
= NULL
, .value
= -1 }
1203 static int jtag_tap_configure_cmd( Jim_GetOptInfo
*goi
, jtag_tap_t
* tap
)
1209 /* parse config or cget options */
1210 while (goi
->argc
> 0) {
1211 Jim_SetEmptyResult (goi
->interp
);
1213 e
= Jim_GetOpt_Nvp(goi
, nvp_config_opts
, &n
);
1215 Jim_GetOpt_NvpUnknown(goi
, nvp_config_opts
, 0);
1221 if (goi
->argc
== 0) {
1222 Jim_WrongNumArgs( goi
->interp
, goi
->argc
, goi
->argv
, "-event ?event-name? ..." );
1226 e
= Jim_GetOpt_Nvp( goi
, nvp_jtag_tap_event
, &n
);
1228 Jim_GetOpt_NvpUnknown(goi
, nvp_jtag_tap_event
, 1);
1232 if (goi
->isconfigure
) {
1233 if (goi
->argc
!= 1) {
1234 Jim_WrongNumArgs(goi
->interp
, goi
->argc
, goi
->argv
, "-event ?event-name? ?EVENT-BODY?");
1238 if (goi
->argc
!= 0) {
1239 Jim_WrongNumArgs(goi
->interp
, goi
->argc
, goi
->argv
, "-event ?event-name?");
1245 jtag_tap_event_action_t
*jteap
;
1247 jteap
= tap
->event_action
;
1248 /* replace existing? */
1250 if (jteap
->event
== (enum jtag_tap_event
)n
->value
) {
1253 jteap
= jteap
->next
;
1256 if (goi
->isconfigure
) {
1257 if (jteap
== NULL
) {
1259 jteap
= calloc(1, sizeof (*jteap
));
1261 jteap
->event
= n
->value
;
1262 Jim_GetOpt_Obj( goi
, &o
);
1264 Jim_DecrRefCount(interp
, jteap
->body
);
1266 jteap
->body
= Jim_DuplicateObj(goi
->interp
, o
);
1267 Jim_IncrRefCount(jteap
->body
);
1269 /* add to head of event list */
1270 jteap
->next
= tap
->event_action
;
1271 tap
->event_action
= jteap
;
1272 Jim_SetEmptyResult(goi
->interp
);
1275 if (jteap
== NULL
) {
1276 Jim_SetEmptyResult(goi
->interp
);
1278 Jim_SetResult(goi
->interp
, Jim_DuplicateObj(goi
->interp
, jteap
->body
));
1285 } /* while (goi->argc) */
1291 static void jtag_tap_init(jtag_tap_t
*tap
)
1293 assert(0 != tap
->ir_length
);
1295 tap
->expected
= malloc(tap
->ir_length
);
1296 tap
->expected_mask
= malloc(tap
->ir_length
);
1297 tap
->cur_instr
= malloc(tap
->ir_length
);
1299 buf_set_u32(tap
->expected
, 0, tap
->ir_length
, tap
->ir_capture_value
);
1300 buf_set_u32(tap
->expected_mask
, 0, tap
->ir_length
, tap
->ir_capture_mask
);
1301 buf_set_ones(tap
->cur_instr
, tap
->ir_length
);
1303 // place TAP in bypass mode
1305 // register the reset callback for the TAP
1306 jtag_register_event_callback(&jtag_reset_callback
, tap
);
1308 LOG_DEBUG("Created Tap: %s @ abs position %d, "
1309 "irlen %d, capture: 0x%x mask: 0x%x", tap
->dotted_name
,
1310 tap
->abs_chain_position
, tap
->ir_length
,
1311 tap
->ir_capture_value
, tap
->ir_capture_mask
);
1315 static void jtag_tap_free(jtag_tap_t
*tap
)
1317 /// @todo is anything missing? no memory leaks please
1318 free((void *)tap
->expected_ids
);
1319 free((void *)tap
->chip
);
1320 free((void *)tap
->tapname
);
1321 free((void *)tap
->dotted_name
);
1325 static int jim_newtap_cmd( Jim_GetOptInfo
*goi
)
1334 const Jim_Nvp opts
[] = {
1335 #define NTAP_OPT_IRLEN 0
1336 { .name
= "-irlen" , .value
= NTAP_OPT_IRLEN
},
1337 #define NTAP_OPT_IRMASK 1
1338 { .name
= "-irmask" , .value
= NTAP_OPT_IRMASK
},
1339 #define NTAP_OPT_IRCAPTURE 2
1340 { .name
= "-ircapture" , .value
= NTAP_OPT_IRCAPTURE
},
1341 #define NTAP_OPT_ENABLED 3
1342 { .name
= "-enable" , .value
= NTAP_OPT_ENABLED
},
1343 #define NTAP_OPT_DISABLED 4
1344 { .name
= "-disable" , .value
= NTAP_OPT_DISABLED
},
1345 #define NTAP_OPT_EXPECTED_ID 5
1346 { .name
= "-expected-id" , .value
= NTAP_OPT_EXPECTED_ID
},
1347 { .name
= NULL
, .value
= -1 },
1350 pTap
= malloc( sizeof(jtag_tap_t
) );
1351 memset( pTap
, 0, sizeof(*pTap
) );
1353 Jim_SetResult_sprintf( goi
->interp
, "no memory");
1357 * we expect CHIP + TAP + OPTIONS
1359 if( goi
->argc
< 3 ){
1360 Jim_SetResult_sprintf(goi
->interp
, "Missing CHIP TAP OPTIONS ....");
1363 Jim_GetOpt_String( goi
, &cp
, NULL
);
1364 pTap
->chip
= strdup(cp
);
1366 Jim_GetOpt_String( goi
, &cp
, NULL
);
1367 pTap
->tapname
= strdup(cp
);
1369 /* name + dot + name + null */
1370 x
= strlen(pTap
->chip
) + 1 + strlen(pTap
->tapname
) + 1;
1372 sprintf( cp
, "%s.%s", pTap
->chip
, pTap
->tapname
);
1373 pTap
->dotted_name
= cp
;
1375 LOG_DEBUG("Creating New Tap, Chip: %s, Tap: %s, Dotted: %s, %d params",
1376 pTap
->chip
, pTap
->tapname
, pTap
->dotted_name
, goi
->argc
);
1378 /* default is enabled */
1381 /* deal with options */
1382 #define NTREQ_IRLEN 1
1383 #define NTREQ_IRCAPTURE 2
1384 #define NTREQ_IRMASK 4
1386 /* clear them as we find them */
1387 reqbits
= (NTREQ_IRLEN
| NTREQ_IRCAPTURE
| NTREQ_IRMASK
);
1390 e
= Jim_GetOpt_Nvp( goi
, opts
, &n
);
1392 Jim_GetOpt_NvpUnknown( goi
, opts
, 0 );
1395 LOG_DEBUG("Processing option: %s", n
->name
);
1397 case NTAP_OPT_ENABLED
:
1400 case NTAP_OPT_DISABLED
:
1403 case NTAP_OPT_EXPECTED_ID
:
1405 u32
*new_expected_ids
;
1407 e
= Jim_GetOpt_Wide( goi
, &w
);
1409 Jim_SetResult_sprintf(goi
->interp
, "option: %s bad parameter", n
->name
);
1413 new_expected_ids
= malloc(sizeof(u32
) * (pTap
->expected_ids_cnt
+ 1));
1414 if (new_expected_ids
== NULL
) {
1415 Jim_SetResult_sprintf( goi
->interp
, "no memory");
1419 memcpy(new_expected_ids
, pTap
->expected_ids
, sizeof(u32
) * pTap
->expected_ids_cnt
);
1421 new_expected_ids
[pTap
->expected_ids_cnt
] = w
;
1423 free(pTap
->expected_ids
);
1424 pTap
->expected_ids
= new_expected_ids
;
1425 pTap
->expected_ids_cnt
++;
1428 case NTAP_OPT_IRLEN
:
1429 case NTAP_OPT_IRMASK
:
1430 case NTAP_OPT_IRCAPTURE
:
1431 e
= Jim_GetOpt_Wide( goi
, &w
);
1433 Jim_SetResult_sprintf( goi
->interp
, "option: %s bad parameter", n
->name
);
1436 if( (w
< 0) || (w
> 0xffff) ){
1438 Jim_SetResult_sprintf( goi
->interp
, "option: %s - wacky value: %d (0x%x)",
1439 n
->name
, (int)(w
), (int)(w
));
1443 case NTAP_OPT_IRLEN
:
1444 pTap
->ir_length
= w
;
1445 reqbits
&= (~(NTREQ_IRLEN
));
1447 case NTAP_OPT_IRMASK
:
1448 pTap
->ir_capture_mask
= w
;
1449 reqbits
&= (~(NTREQ_IRMASK
));
1451 case NTAP_OPT_IRCAPTURE
:
1452 pTap
->ir_capture_value
= w
;
1453 reqbits
&= (~(NTREQ_IRCAPTURE
));
1456 } /* switch(n->value) */
1457 } /* while( goi->argc ) */
1459 /* Did all the required option bits get cleared? */
1462 jtag_tap_init(pTap
);
1466 Jim_SetResult_sprintf(goi
->interp
,
1467 "newtap: %s missing required parameters",
1469 jtag_tap_free(pTap
);
1473 static int jim_jtag_command( Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
1479 struct command_context_s
*context
;
1483 JTAG_CMD_INIT_RESET
,
1486 JTAG_CMD_TAPDISABLE
,
1487 JTAG_CMD_TAPISENABLED
,
1492 const Jim_Nvp jtag_cmds
[] = {
1493 { .name
= "interface" , .value
= JTAG_CMD_INTERFACE
},
1494 { .name
= "arp_init-reset", .value
= JTAG_CMD_INIT_RESET
},
1495 { .name
= "newtap" , .value
= JTAG_CMD_NEWTAP
},
1496 { .name
= "tapisenabled" , .value
= JTAG_CMD_TAPISENABLED
},
1497 { .name
= "tapenable" , .value
= JTAG_CMD_TAPENABLE
},
1498 { .name
= "tapdisable" , .value
= JTAG_CMD_TAPDISABLE
},
1499 { .name
= "configure" , .value
= JTAG_CMD_CONFIGURE
},
1500 { .name
= "cget" , .value
= JTAG_CMD_CGET
},
1502 { .name
= NULL
, .value
= -1 },
1505 context
= Jim_GetAssocData(interp
, "context");
1506 /* go past the command */
1507 Jim_GetOpt_Setup( &goi
, interp
, argc
-1, argv
+1 );
1509 e
= Jim_GetOpt_Nvp( &goi
, jtag_cmds
, &n
);
1511 Jim_GetOpt_NvpUnknown( &goi
, jtag_cmds
, 0 );
1514 Jim_SetEmptyResult( goi
.interp
);
1516 case JTAG_CMD_INTERFACE
:
1517 /* return the name of the interface */
1518 /* TCL code might need to know the exact type... */
1519 /* FUTURE: we allow this as a means to "set" the interface. */
1520 if( goi
.argc
!= 0 ){
1521 Jim_WrongNumArgs( goi
.interp
, 1, goi
.argv
-1, "(no params)");
1524 Jim_SetResultString( goi
.interp
, jtag_interface
->name
, -1 );
1526 case JTAG_CMD_INIT_RESET
:
1527 if( goi
.argc
!= 0 ){
1528 Jim_WrongNumArgs( goi
.interp
, 1, goi
.argv
-1, "(no params)");
1531 e
= jtag_init_reset(context
);
1532 if( e
!= ERROR_OK
){
1533 Jim_SetResult_sprintf( goi
.interp
, "error: %d", e
);
1537 case JTAG_CMD_NEWTAP
:
1538 return jim_newtap_cmd( &goi
);
1540 case JTAG_CMD_TAPISENABLED
:
1541 case JTAG_CMD_TAPENABLE
:
1542 case JTAG_CMD_TAPDISABLE
:
1543 if( goi
.argc
!= 1 ){
1544 Jim_SetResultString( goi
.interp
, "Too many parameters",-1 );
1550 t
= jtag_tap_by_jim_obj( goi
.interp
, goi
.argv
[0] );
1555 case JTAG_CMD_TAPISENABLED
:
1558 case JTAG_CMD_TAPENABLE
:
1559 jtag_tap_handle_event( t
, JTAG_TAP_EVENT_ENABLE
);
1563 case JTAG_CMD_TAPDISABLE
:
1564 jtag_tap_handle_event( t
, JTAG_TAP_EVENT_DISABLE
);
1569 Jim_SetResult( goi
.interp
, Jim_NewIntObj( goi
.interp
, e
) );
1576 Jim_WrongNumArgs( goi
.interp
, 0, NULL
, "?tap-name? -option ...");
1583 Jim_GetOpt_Obj(&goi
, &o
);
1584 t
= jtag_tap_by_jim_obj( goi
.interp
, o
);
1589 goi
.isconfigure
= 0;
1590 return jtag_tap_configure_cmd( &goi
, t
);
1594 case JTAG_CMD_CONFIGURE
:
1596 Jim_WrongNumArgs( goi
.interp
, 0, NULL
, "?tap-name? -option ?VALUE? ...");
1603 Jim_GetOpt_Obj(&goi
, &o
);
1604 t
= jtag_tap_by_jim_obj( goi
.interp
, o
);
1609 goi
.isconfigure
= 1;
1610 return jtag_tap_configure_cmd( &goi
, t
);
1617 int jtag_register_commands(struct command_context_s
*cmd_ctx
)
1619 register_jim( cmd_ctx
, "jtag", jim_jtag_command
, "perform jtag tap actions");
1621 register_command(cmd_ctx
, NULL
, "interface", handle_interface_command
,
1622 COMMAND_CONFIG
, "try to configure interface");
1623 register_command(cmd_ctx
, NULL
, "jtag_speed", handle_jtag_speed_command
,
1624 COMMAND_ANY
, "(DEPRECATED) set jtag speed (if supported)");
1625 register_command(cmd_ctx
, NULL
, "jtag_khz", handle_jtag_khz_command
,
1626 COMMAND_ANY
, "set maximum jtag speed (if supported); "
1627 "parameter is maximum khz, or 0 for adaptive clocking (RTCK).");
1628 register_command(cmd_ctx
, NULL
, "jtag_device", handle_jtag_device_command
,
1629 COMMAND_CONFIG
, "(DEPRECATED) jtag_device <ir_length> <ir_expected> <ir_mask>");
1630 register_command(cmd_ctx
, NULL
, "reset_config", handle_reset_config_command
,
1632 "[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]");
1633 register_command(cmd_ctx
, NULL
, "jtag_nsrst_delay", handle_jtag_nsrst_delay_command
,
1634 COMMAND_ANY
, "jtag_nsrst_delay <ms> - delay after deasserting srst in ms");
1635 register_command(cmd_ctx
, NULL
, "jtag_ntrst_delay", handle_jtag_ntrst_delay_command
,
1636 COMMAND_ANY
, "jtag_ntrst_delay <ms> - delay after deasserting trst in ms");
1638 register_command(cmd_ctx
, NULL
, "scan_chain", handle_scan_chain_command
,
1639 COMMAND_EXEC
, "print current scan chain configuration");
1641 register_command(cmd_ctx
, NULL
, "endstate", handle_endstate_command
,
1642 COMMAND_EXEC
, "finish JTAG operations in <tap_state>");
1643 register_command(cmd_ctx
, NULL
, "jtag_reset", handle_jtag_reset_command
,
1644 COMMAND_EXEC
, "toggle reset lines <trst> <srst>");
1645 register_command(cmd_ctx
, NULL
, "runtest", handle_runtest_command
,
1646 COMMAND_EXEC
, "move to Run-Test/Idle, and execute <num_cycles>");
1647 register_command(cmd_ctx
, NULL
, "irscan", handle_irscan_command
,
1648 COMMAND_EXEC
, "execute IR scan <device> <instr> [dev2] [instr2] ...");
1649 register_jim(cmd_ctx
, "drscan", Jim_Command_drscan
, "execute DR scan <device> <num_bits> <value> <num_bits1> <value2> ...");
1650 register_jim(cmd_ctx
, "flush_count", Jim_Command_flush_count
, "returns number of times the JTAG queue has been flushed");
1652 register_command(cmd_ctx
, NULL
, "verify_ircapture", handle_verify_ircapture_command
,
1653 COMMAND_ANY
, "verify value captured during Capture-IR <enable|disable>");
1654 register_command(cmd_ctx
, NULL
, "verify_jtag", handle_verify_jtag_command
,
1655 COMMAND_ANY
, "verify value capture <enable|disable>");
1656 register_command(cmd_ctx
, NULL
, "tms_sequence", handle_tms_sequence_command
,
1657 COMMAND_ANY
, "choose short(default) or long tms_sequence <short|long>");
1661 int jtag_interface_init(struct command_context_s
*cmd_ctx
)
1666 if (!jtag_interface
)
1668 /* nothing was previously specified by "interface" command */
1669 LOG_ERROR("JTAG interface has to be specified, see \"interface\" command");
1670 return ERROR_JTAG_INVALID_INTERFACE
;
1674 jtag_interface
->khz(jtag_get_speed_khz(), &jtag_speed
);
1678 if (jtag_interface
->init() != ERROR_OK
)
1679 return ERROR_JTAG_INIT_FAILED
;
1681 jtag
= jtag_interface
;
1685 static int jtag_init_inner(struct command_context_s
*cmd_ctx
)
1690 LOG_DEBUG("Init JTAG chain");
1692 tap
= jtag_tap_next_enabled(NULL
);
1694 LOG_ERROR("There are no enabled taps?");
1695 return ERROR_JTAG_INIT_FAILED
;
1699 if ((retval
=jtag_execute_queue())!=ERROR_OK
)
1702 /* examine chain first, as this could discover the real chain layout */
1703 if (jtag_examine_chain() != ERROR_OK
)
1705 LOG_ERROR("trying to validate configured JTAG chain anyway...");
1708 if (jtag_validate_chain() != ERROR_OK
)
1710 LOG_WARNING("Could not validate JTAG chain, continuing anyway...");
1716 int jtag_interface_quit(void)
1718 if (!jtag
|| !jtag
->quit
)
1721 // close the JTAG interface
1722 int result
= jtag
->quit();
1723 if (ERROR_OK
!= result
)
1724 LOG_ERROR("failed: %d", result
);
1730 int jtag_init_reset(struct command_context_s
*cmd_ctx
)
1734 if ((retval
=jtag_interface_init(cmd_ctx
)) != ERROR_OK
)
1737 LOG_DEBUG("Trying to bring the JTAG controller to life by asserting TRST / RESET");
1739 /* Reset can happen after a power cycle.
1741 * Ideally we would only assert TRST or run RESET before the target reset.
1743 * However w/srst_pulls_trst, trst is asserted together with the target
1744 * reset whether we want it or not.
1746 * NB! Some targets have JTAG circuitry disabled until a
1747 * trst & srst has been asserted.
1749 * NB! here we assume nsrst/ntrst delay are sufficient!
1751 * NB! order matters!!!! srst *can* disconnect JTAG circuitry
1754 jtag_add_reset(1, 0); /* RESET or TRST */
1755 if (jtag_reset_config
& RESET_HAS_SRST
)
1757 jtag_add_reset(1, 1);
1758 if ((jtag_reset_config
& RESET_SRST_PULLS_TRST
)==0)
1759 jtag_add_reset(0, 1);
1761 jtag_add_reset(0, 0);
1762 if ((retval
= jtag_execute_queue()) != ERROR_OK
)
1765 /* Check that we can communication on the JTAG chain + eventually we want to
1766 * be able to perform enumeration only after OpenOCD has started
1767 * telnet and GDB server
1769 * That would allow users to more easily perform any magic they need to before
1772 return jtag_init_inner(cmd_ctx
);
1775 int jtag_init(struct command_context_s
*cmd_ctx
)
1778 if ((retval
=jtag_interface_init(cmd_ctx
)) != ERROR_OK
)
1780 if (jtag_init_inner(cmd_ctx
)==ERROR_OK
)
1784 return jtag_init_reset(cmd_ctx
);
1787 void jtag_set_speed_khz(unsigned khz
)
1791 unsigned jtag_get_speed_khz(void)
1796 static int default_khz(int khz
, int *jtag_speed
)
1798 LOG_ERROR("Translation from khz to jtag_speed not implemented");
1802 static int default_speed_div(int speed
, int *khz
)
1804 LOG_ERROR("Translation from jtag_speed to khz not implemented");
1808 static int default_power_dropout(int *dropout
)
1810 *dropout
=0; /* by default we can't detect power dropout */
1814 static int default_srst_asserted(int *srst_asserted
)
1816 *srst_asserted
=0; /* by default we can't detect srst asserted */
1820 static int handle_interface_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1825 /* check whether the interface is already configured */
1828 LOG_WARNING("Interface already configured, ignoring");
1832 /* interface name is a mandatory argument */
1833 if (argc
< 1 || args
[0][0] == '\0')
1835 return ERROR_COMMAND_SYNTAX_ERROR
;
1838 for (i
=0; jtag_interfaces
[i
]; i
++)
1840 if (strcmp(args
[0], jtag_interfaces
[i
]->name
) == 0)
1842 if ((retval
= jtag_interfaces
[i
]->register_commands(cmd_ctx
)) != ERROR_OK
)
1847 jtag_interface
= jtag_interfaces
[i
];
1849 if (jtag_interface
->khz
== NULL
)
1851 jtag_interface
->khz
= default_khz
;
1853 if (jtag_interface
->speed_div
== NULL
)
1855 jtag_interface
->speed_div
= default_speed_div
;
1857 if (jtag_interface
->power_dropout
== NULL
)
1859 jtag_interface
->power_dropout
= default_power_dropout
;
1861 if (jtag_interface
->srst_asserted
== NULL
)
1863 jtag_interface
->srst_asserted
= default_srst_asserted
;
1870 /* no valid interface was found (i.e. the configuration option,
1871 * didn't match one of the compiled-in interfaces
1873 LOG_ERROR("No valid jtag interface found (%s)", args
[0]);
1874 LOG_ERROR("compiled-in jtag interfaces:");
1875 for (i
= 0; jtag_interfaces
[i
]; i
++)
1877 LOG_ERROR("%i: %s", i
, jtag_interfaces
[i
]->name
);
1880 return ERROR_JTAG_INVALID_INTERFACE
;
1883 static int handle_jtag_device_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1887 Jim_Obj
*newargs
[ 10 ];
1890 * argv[-1] = command
1891 * argv[ 0] = ir length
1892 * argv[ 1] = ir capture
1893 * argv[ 2] = ir mask
1894 * argv[ 3] = not actually used by anything but in the docs
1898 command_print( cmd_ctx
, "OLD DEPRECATED SYNTAX: Please use the NEW syntax");
1901 command_print( cmd_ctx
, "OLD SYNTAX: DEPRECATED - translating to new syntax");
1902 command_print( cmd_ctx
, "jtag newtap CHIP TAP -irlen %s -ircapture %s -irvalue %s",
1906 command_print( cmd_ctx
, "Example: STM32 has 2 taps, the cortexM3(len4) + boundaryscan(len5)");
1907 command_print( cmd_ctx
, "jtag newtap stm32 cortexm3 ....., thus creating the tap: \"stm32.cortexm3\"");
1908 command_print( cmd_ctx
, "jtag newtap stm32 boundary ....., and the tap: \"stm32.boundary\"");
1909 command_print( cmd_ctx
, "And then refer to the taps by the dotted name.");
1911 newargs
[0] = Jim_NewStringObj( interp
, "jtag", -1 );
1912 newargs
[1] = Jim_NewStringObj( interp
, "newtap", -1 );
1913 sprintf( buf
, "chip%d", jtag_tap_count() );
1914 newargs
[2] = Jim_NewStringObj( interp
, buf
, -1 );
1915 sprintf( buf
, "tap%d", jtag_tap_count() );
1916 newargs
[3] = Jim_NewStringObj( interp
, buf
, -1 );
1917 newargs
[4] = Jim_NewStringObj( interp
, "-irlen", -1 );
1918 newargs
[5] = Jim_NewStringObj( interp
, args
[0], -1 );
1919 newargs
[6] = Jim_NewStringObj( interp
, "-ircapture", -1 );
1920 newargs
[7] = Jim_NewStringObj( interp
, args
[1], -1 );
1921 newargs
[8] = Jim_NewStringObj( interp
, "-irmask", -1 );
1922 newargs
[9] = Jim_NewStringObj( interp
, args
[2], -1 );
1924 command_print( cmd_ctx
, "NEW COMMAND:");
1925 sprintf( buf
, "%s %s %s %s %s %s %s %s %s %s",
1926 Jim_GetString( newargs
[0], NULL
),
1927 Jim_GetString( newargs
[1], NULL
),
1928 Jim_GetString( newargs
[2], NULL
),
1929 Jim_GetString( newargs
[3], NULL
),
1930 Jim_GetString( newargs
[4], NULL
),
1931 Jim_GetString( newargs
[5], NULL
),
1932 Jim_GetString( newargs
[6], NULL
),
1933 Jim_GetString( newargs
[7], NULL
),
1934 Jim_GetString( newargs
[8], NULL
),
1935 Jim_GetString( newargs
[9], NULL
) );
1937 e
= jim_jtag_command( interp
, 10, newargs
);
1939 command_print( cmd_ctx
, "%s", Jim_GetString( Jim_GetResult(interp
), NULL
) );
1944 static int handle_scan_chain_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1948 tap
= jtag_all_taps();
1949 command_print(cmd_ctx
, " TapName | Enabled | IdCode Expected IrLen IrCap IrMask Instr ");
1950 command_print(cmd_ctx
, "---|--------------------|---------|------------|------------|------|------|------|---------");
1953 u32 expected
, expected_mask
, cur_instr
, ii
;
1954 expected
= buf_get_u32(tap
->expected
, 0, tap
->ir_length
);
1955 expected_mask
= buf_get_u32(tap
->expected_mask
, 0, tap
->ir_length
);
1956 cur_instr
= buf_get_u32(tap
->cur_instr
, 0, tap
->ir_length
);
1958 command_print(cmd_ctx
,
1959 "%2d | %-18s | %c | 0x%08x | 0x%08x | 0x%02x | 0x%02x | 0x%02x | 0x%02x",
1960 tap
->abs_chain_position
,
1962 tap
->enabled
? 'Y' : 'n',
1964 (tap
->expected_ids_cnt
> 0 ? tap
->expected_ids
[0] : 0),
1970 for (ii
= 1; ii
< tap
->expected_ids_cnt
; ii
++) {
1971 command_print(cmd_ctx
, " | | | | 0x%08x | | | | ",
1972 tap
->expected_ids
[ii
]);
1975 tap
= tap
->next_tap
;
1981 static int handle_reset_config_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1987 return ERROR_COMMAND_SYNTAX_ERROR
;
1989 /* Original versions cared about the order of these tokens:
1990 * reset_config signals [combination [trst_type [srst_type]]]
1991 * They also clobbered the previous configuration even on error.
1993 * Here we don't care about the order, and only change values
1994 * which have been explicitly specified.
1996 for (; argc
; argc
--, args
++) {
2001 m
= RESET_HAS_TRST
| RESET_HAS_SRST
;
2002 if (strcmp(*args
, "none") == 0)
2004 else if (strcmp(*args
, "trst_only") == 0)
2005 tmp
= RESET_HAS_TRST
;
2006 else if (strcmp(*args
, "srst_only") == 0)
2007 tmp
= RESET_HAS_SRST
;
2008 else if (strcmp(*args
, "trst_and_srst") == 0)
2009 tmp
= RESET_HAS_TRST
| RESET_HAS_SRST
;
2013 LOG_ERROR("extra reset_config %s spec (%s)",
2015 return ERROR_INVALID_ARGUMENTS
;
2020 /* combination (options for broken wiring) */
2021 m
= RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
;
2022 if (strcmp(*args
, "separate") == 0)
2023 /* separate reset lines - default */;
2024 else if (strcmp(*args
, "srst_pulls_trst") == 0)
2025 tmp
|= RESET_SRST_PULLS_TRST
;
2026 else if (strcmp(*args
, "trst_pulls_srst") == 0)
2027 tmp
|= RESET_TRST_PULLS_SRST
;
2028 else if (strcmp(*args
, "combined") == 0)
2029 tmp
|= RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
;
2033 LOG_ERROR("extra reset_config %s spec (%s)",
2034 "combination", *args
);
2035 return ERROR_INVALID_ARGUMENTS
;
2040 /* trst_type (NOP without HAS_TRST) */
2041 m
= RESET_TRST_OPEN_DRAIN
;
2042 if (strcmp(*args
, "trst_open_drain") == 0)
2043 tmp
|= RESET_TRST_OPEN_DRAIN
;
2044 else if (strcmp(*args
, "trst_push_pull") == 0)
2045 /* push/pull from adapter - default */;
2049 LOG_ERROR("extra reset_config %s spec (%s)",
2050 "trst_type", *args
);
2051 return ERROR_INVALID_ARGUMENTS
;
2056 /* srst_type (NOP without HAS_SRST) */
2057 m
|= RESET_SRST_PUSH_PULL
;
2058 if (strcmp(*args
, "srst_push_pull") == 0)
2059 tmp
|= RESET_SRST_PUSH_PULL
;
2060 else if (strcmp(*args
, "srst_open_drain") == 0)
2061 /* open drain from adapter - default */;
2065 LOG_ERROR("extra reset_config %s spec (%s)",
2066 "srst_type", *args
);
2067 return ERROR_INVALID_ARGUMENTS
;
2072 /* caller provided nonsense; fail */
2073 LOG_ERROR("unknown reset_config flag (%s)", *args
);
2074 return ERROR_INVALID_ARGUMENTS
;
2077 /* Remember the bits which were specified (mask)
2078 * and their new values (new_cfg).
2084 /* clear previous values of those bits, save new values */
2085 jtag_reset_config
&= ~mask
;
2086 jtag_reset_config
|= new_cfg
;
2091 static int handle_jtag_nsrst_delay_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2095 LOG_ERROR("jtag_nsrst_delay <ms> command takes one required argument");
2100 jtag_set_nsrst_delay(strtoul(args
[0], NULL
, 0));
2106 static int handle_jtag_ntrst_delay_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2110 LOG_ERROR("jtag_ntrst_delay <ms> command takes one required argument");
2115 jtag_set_ntrst_delay(strtoul(args
[0], NULL
, 0));
2122 static int handle_jtag_speed_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2124 int retval
=ERROR_OK
;
2128 LOG_DEBUG("handle jtag speed");
2131 cur_speed
= jtag_speed
= strtoul(args
[0], NULL
, 0);
2133 /* this command can be called during CONFIG,
2134 * in which case jtag isn't initialized */
2137 retval
=jtag
->speed(cur_speed
);
2139 } else if (argc
== 0)
2143 return ERROR_COMMAND_SYNTAX_ERROR
;
2145 command_print(cmd_ctx
, "jtag_speed: %d", jtag_speed
);
2150 static int handle_jtag_khz_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2152 int retval
=ERROR_OK
;
2153 LOG_DEBUG("handle jtag khz");
2158 jtag_set_speed_khz(strtoul(args
[0], NULL
, 0));
2161 LOG_DEBUG("have interface set up");
2163 if ((retval
=jtag
->khz(jtag_get_speed_khz(), &speed_div1
))!=ERROR_OK
)
2165 jtag_set_speed_khz(0);
2169 cur_speed
= jtag_speed
= speed_div1
;
2171 retval
=jtag
->speed(cur_speed
);
2180 return ERROR_COMMAND_SYNTAX_ERROR
;
2182 cur_speed
= jtag_get_speed_khz();
2186 if ((retval
=jtag
->speed_div(jtag_speed
, &cur_speed
))!=ERROR_OK
)
2191 command_print(cmd_ctx
, "%d kHz", cur_speed
);
2193 command_print(cmd_ctx
, "RCLK - adaptive");
2198 static int handle_endstate_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2201 return ERROR_COMMAND_SYNTAX_ERROR
;
2203 tap_state_t state
= tap_state_by_name(args
[0]);
2206 command_print( cmd_ctx
, "Invalid state name: %s\n", args
[0] );
2207 return ERROR_COMMAND_SYNTAX_ERROR
;
2209 jtag_set_end_state(state
);
2210 jtag_execute_queue();
2212 command_print(cmd_ctx
, "current endstate: %s",
2213 tap_state_name(cmd_queue_end_state
));
2218 static int handle_jtag_reset_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2225 return ERROR_COMMAND_SYNTAX_ERROR
;
2228 if (args
[0][0] == '1')
2230 else if (args
[0][0] == '0')
2234 return ERROR_COMMAND_SYNTAX_ERROR
;
2237 if (args
[1][0] == '1')
2239 else if (args
[1][0] == '0')
2243 return ERROR_COMMAND_SYNTAX_ERROR
;
2246 if (jtag_interface_init(cmd_ctx
) != ERROR_OK
)
2247 return ERROR_JTAG_INIT_FAILED
;
2249 jtag_add_reset(trst
, srst
);
2250 jtag_execute_queue();
2255 static int handle_runtest_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2259 return ERROR_COMMAND_SYNTAX_ERROR
;
2262 jtag_add_runtest(strtol(args
[0], NULL
, 0), jtag_get_end_state());
2263 jtag_execute_queue();
2270 * For "irscan" or "drscan" commands, the "end" (really, "next") state
2271 * should be stable ... and *NOT* a shift state, otherwise free-running
2272 * jtag clocks could change the values latched by the update state.
2274 static bool scan_is_safe(tap_state_t state
)
2289 static int handle_irscan_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2292 scan_field_t
*fields
;
2294 tap_state_t endstate
;
2296 if ((argc
< 2) || (argc
% 2))
2298 return ERROR_COMMAND_SYNTAX_ERROR
;
2301 /* optional "-endstate" "statename" at the end of the arguments,
2302 * so that e.g. IRPAUSE can let us load the data register before
2303 * entering RUN/IDLE to execute the instruction we load here.
2305 endstate
= TAP_IDLE
;
2308 /* have at least one pair of numbers. */
2309 /* is last pair the magic text? */
2310 if( 0 == strcmp( "-endstate", args
[ argc
- 2 ] ) ){
2313 cpA
= args
[ argc
-1 ];
2314 for( endstate
= 0 ; endstate
< TAP_NUM_STATES
; endstate
++ ){
2315 cpS
= tap_state_name( endstate
);
2316 if( 0 == strcmp( cpA
, cpS
) ){
2320 if( endstate
>= TAP_NUM_STATES
){
2321 return ERROR_COMMAND_SYNTAX_ERROR
;
2323 if (!scan_is_safe(endstate
))
2324 LOG_WARNING("irscan with unsafe "
2325 "endstate \"%s\"", cpA
);
2326 /* found - remove the last 2 args */
2332 int num_fields
= argc
/ 2;
2334 fields
= malloc(sizeof(scan_field_t
) * num_fields
);
2336 for (i
= 0; i
< num_fields
; i
++)
2338 tap
= jtag_tap_by_string( args
[i
*2] );
2341 command_print( cmd_ctx
, "Tap: %s unknown", args
[i
*2] );
2344 int field_size
= tap
->ir_length
;
2345 fields
[i
].tap
= tap
;
2346 fields
[i
].num_bits
= field_size
;
2347 fields
[i
].out_value
= malloc(CEIL(field_size
, 8));
2348 buf_set_u32(fields
[i
].out_value
, 0, field_size
, strtoul(args
[i
*2+1], NULL
, 0));
2349 fields
[i
].in_value
= NULL
;
2352 /* did we have an endstate? */
2353 jtag_add_ir_scan(num_fields
, fields
, endstate
);
2355 int retval
=jtag_execute_queue();
2357 for (i
= 0; i
< num_fields
; i
++)
2358 free(fields
[i
].out_value
);
2365 static int Jim_Command_drscan(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *args
)
2368 scan_field_t
*fields
;
2370 int field_count
= 0;
2373 tap_state_t endstate
;
2376 * args[2] = num_bits
2377 * args[3] = hex string
2378 * ... repeat num bits and hex string ...
2381 * args[N-2] = "-endstate"
2382 * args[N-1] = statename
2384 if ((argc
< 4) || ((argc
% 2)!=0))
2386 Jim_WrongNumArgs(interp
, 1, args
, "wrong arguments");
2390 endstate
= TAP_IDLE
;
2392 /* validate arguments as numbers */
2394 for (i
= 2; i
< argc
; i
+=2)
2399 e
= Jim_GetLong(interp
, args
[i
], &bits
);
2400 /* If valid - try next arg */
2405 /* Not valid.. are we at the end? */
2406 if ( ((i
+2) != argc
) ){
2407 /* nope, then error */
2411 /* it could be: "-endstate FOO"
2412 * e.g. DRPAUSE so we can issue more instructions
2413 * before entering RUN/IDLE and executing them.
2416 /* get arg as a string. */
2417 cp
= Jim_GetString( args
[i
], NULL
);
2418 /* is it the magic? */
2419 if( 0 == strcmp( "-endstate", cp
) ){
2420 /* is the statename valid? */
2421 cp
= Jim_GetString( args
[i
+1], NULL
);
2423 /* see if it is a valid state name */
2424 endstate
= tap_state_by_name(cp
);
2426 /* update the error message */
2427 Jim_SetResult_sprintf(interp
,"endstate: %s invalid", cp
);
2429 if (!scan_is_safe(endstate
))
2430 LOG_WARNING("drscan with unsafe "
2431 "endstate \"%s\"", cp
);
2433 /* valid - so clear the error */
2435 /* and remove the last 2 args */
2440 /* Still an error? */
2442 return e
; /* too bad */
2444 } /* validate args */
2446 tap
= jtag_tap_by_jim_obj( interp
, args
[1] );
2451 num_fields
=(argc
-2)/2;
2452 fields
= malloc(sizeof(scan_field_t
) * num_fields
);
2453 for (i
= 2; i
< argc
; i
+=2)
2459 Jim_GetLong(interp
, args
[i
], &bits
);
2460 str
= Jim_GetString(args
[i
+1], &len
);
2462 fields
[field_count
].tap
= tap
;
2463 fields
[field_count
].num_bits
= bits
;
2464 fields
[field_count
].out_value
= malloc(CEIL(bits
, 8));
2465 str_to_buf(str
, len
, fields
[field_count
].out_value
, bits
, 0);
2466 fields
[field_count
].in_value
= fields
[field_count
].out_value
;
2470 jtag_add_dr_scan(num_fields
, fields
, endstate
);
2472 retval
= jtag_execute_queue();
2473 if (retval
!= ERROR_OK
)
2475 Jim_SetResultString(interp
, "drscan: jtag execute failed",-1);
2480 Jim_Obj
*list
= Jim_NewListObj(interp
, NULL
, 0);
2481 for (i
= 2; i
< argc
; i
+=2)
2486 Jim_GetLong(interp
, args
[i
], &bits
);
2487 str
= buf_to_str(fields
[field_count
].in_value
, bits
, 16);
2488 free(fields
[field_count
].out_value
);
2490 Jim_ListAppendElement(interp
, list
, Jim_NewStringObj(interp
, str
, strlen(str
)));
2495 Jim_SetResult(interp
, list
);
2503 static int Jim_Command_flush_count(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *args
)
2505 Jim_SetResult(interp
, Jim_NewIntObj(interp
, jtag_get_flush_queue_count()));
2511 static int handle_verify_ircapture_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2515 if (strcmp(args
[0], "enable") == 0)
2517 jtag_verify_capture_ir
= 1;
2519 else if (strcmp(args
[0], "disable") == 0)
2521 jtag_verify_capture_ir
= 0;
2524 return ERROR_COMMAND_SYNTAX_ERROR
;
2526 } else if (argc
!= 0)
2528 return ERROR_COMMAND_SYNTAX_ERROR
;
2531 command_print(cmd_ctx
, "verify Capture-IR is %s", (jtag_verify_capture_ir
) ? "enabled": "disabled");
2536 void jtag_set_verify(bool enable
)
2538 jtag_verify
= enable
;
2541 bool jtag_will_verify()
2546 static int handle_verify_jtag_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2549 return ERROR_COMMAND_SYNTAX_ERROR
;
2553 if (strcmp(args
[0], "enable") == 0)
2554 jtag_set_verify(true);
2555 else if (strcmp(args
[0], "disable") == 0)
2556 jtag_set_verify(false);
2558 return ERROR_COMMAND_SYNTAX_ERROR
;
2561 const char *status
= jtag_will_verify() ? "enabled": "disabled";
2562 command_print(cmd_ctx
, "verify jtag capture is %s", status
);
2568 int jtag_power_dropout(int *dropout
)
2570 return jtag
->power_dropout(dropout
);
2573 int jtag_srst_asserted(int *srst_asserted
)
2575 return jtag
->srst_asserted(srst_asserted
);
2578 void jtag_tap_handle_event( jtag_tap_t
* tap
, enum jtag_tap_event e
)
2580 jtag_tap_event_action_t
* jteap
;
2583 jteap
= tap
->event_action
;
2587 if (jteap
->event
== e
) {
2589 LOG_DEBUG( "JTAG tap: %s event: %d (%s) action: %s\n",
2592 Jim_Nvp_value2name_simple(nvp_jtag_tap_event
, e
)->name
,
2593 Jim_GetString(jteap
->body
, NULL
) );
2594 if (Jim_EvalObj(interp
, jteap
->body
) != JIM_OK
) {
2595 Jim_PrintErrorMessage(interp
);
2599 jteap
= jteap
->next
;
2603 LOG_DEBUG( "event %d %s - no action",
2605 Jim_Nvp_value2name_simple( nvp_jtag_tap_event
, e
)->name
);
2609 static int handle_tms_sequence_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2612 return ERROR_COMMAND_SYNTAX_ERROR
;
2617 if (strcmp(args
[0], "short") == 0)
2618 use_new_table
= true;
2619 else if (strcmp(args
[0], "long") == 0)
2620 use_new_table
= false;
2622 return ERROR_COMMAND_SYNTAX_ERROR
;
2624 tap_use_new_tms_table(use_new_table
);
2627 command_print(cmd_ctx
, "tms sequence is %s",
2628 tap_uses_new_tms_table() ? "short": "long");
2634 * Function jtag_add_statemove
2635 * moves from the current state to the goal \a state. This needs
2636 * to be handled according to the xsvf spec, see the XSTATE command
2639 int jtag_add_statemove(tap_state_t goal_state
)
2641 int retval
= ERROR_OK
;
2643 tap_state_t moves
[8];
2644 tap_state_t cur_state
= cmd_queue_cur_state
;
2649 LOG_DEBUG( "cur_state=%s goal_state=%s",
2650 tap_state_name(cur_state
),
2651 tap_state_name(goal_state
) );
2654 /* From the XSVF spec, pertaining to XSTATE:
2656 For special states known as stable states (Test-Logic-Reset,
2657 Run-Test/Idle, Pause-DR, Pause- IR), an XSVF interpreter follows
2658 predefined TAP state paths when the starting state is a stable state and
2659 when the XSTATE specifies a new stable state (see the STATE command in
2660 the [Ref 5] for the TAP state paths between stable states). For
2661 non-stable states, XSTATE should specify a state that is only one TAP
2662 state transition distance from the current TAP state to avoid undefined
2663 TAP state paths. A sequence of multiple XSTATE commands can be issued to
2664 transition the TAP through a specific state path.
2667 if (goal_state
==cur_state
)
2668 ; /* nothing to do */
2670 else if( goal_state
==TAP_RESET
)
2675 else if( tap_is_state_stable(cur_state
) && tap_is_state_stable(goal_state
) )
2677 /* note: unless tms_bits holds a path that agrees with [Ref 5] in above
2678 spec, then this code is not fully conformant to the xsvf spec. This
2679 puts a burden on tap_get_tms_path() function from the xsvf spec.
2680 If in doubt, you should confirm that that burden is being met.
2683 tms_bits
= tap_get_tms_path(cur_state
, goal_state
);
2684 tms_count
= tap_get_tms_path_len(cur_state
, goal_state
);
2686 assert( (unsigned) tms_count
< DIM(moves
) );
2688 for (i
=0; i
<tms_count
; i
++, tms_bits
>>=1)
2690 bool bit
= tms_bits
& 1;
2692 cur_state
= tap_state_transition(cur_state
, bit
);
2693 moves
[i
] = cur_state
;
2696 jtag_add_pathmove(tms_count
, moves
);
2699 /* else state must be immediately reachable in one clock cycle, and does not
2700 need to be a stable state.
2702 else if( tap_state_transition(cur_state
, true) == goal_state
2703 || tap_state_transition(cur_state
, false) == goal_state
)
2705 /* move a single state */
2706 moves
[0] = goal_state
;
2707 jtag_add_pathmove( 1, moves
);
2712 retval
= ERROR_FAIL
;
2718 void jtag_set_nsrst_delay(unsigned delay
)
2720 jtag_nsrst_delay
= delay
;
2722 void jtag_set_ntrst_delay(unsigned delay
)
2724 jtag_ntrst_delay
= 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)