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 unsigned 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 unsigned jtag_tap_count(void)
255 return jtag_num_taps
;
258 unsigned jtag_tap_count_enabled(void)
260 jtag_tap_t
*t
= jtag_all_taps();
271 /// Append a new TAP to the chain of all taps.
272 void jtag_tap_add(struct jtag_tap_s
*t
)
274 t
->abs_chain_position
= jtag_num_taps
++;
276 jtag_tap_t
**tap
= &__jtag_all_taps
;
278 tap
= &(*tap
)->next_tap
;
282 jtag_tap_t
*jtag_tap_by_string(const char *s
)
284 /* try by name first */
285 jtag_tap_t
*t
= jtag_all_taps();
288 if (0 == strcmp(t
->dotted_name
, s
))
293 /* no tap found by name, so try to parse the name as a number */
295 unsigned n
= strtoul(s
, &cp
, 0);
296 if ((s
== cp
) || (*cp
!= 0))
299 return jtag_tap_by_position(n
);
302 jtag_tap_t
*jtag_tap_by_jim_obj(Jim_Interp
*interp
, Jim_Obj
*o
)
304 const char *cp
= Jim_GetString(o
, NULL
);
305 jtag_tap_t
*t
= cp
? jtag_tap_by_string(cp
) : NULL
;
309 Jim_SetResult_sprintf(interp
, "Tap '%s' could not be found", cp
);
313 /* returns a pointer to the n-th device in the scan chain */
314 jtag_tap_t
*jtag_tap_by_position(unsigned n
)
316 jtag_tap_t
*t
= jtag_all_taps();
324 const char *jtag_tap_name(const jtag_tap_t
*tap
)
326 return (tap
== NULL
) ? "(unknown)" : tap
->dotted_name
;
330 int jtag_register_event_callback(int (*callback
)(enum jtag_event event
, void *priv
), void *priv
)
332 jtag_event_callback_t
**callbacks_p
= &jtag_event_callbacks
;
334 if (callback
== NULL
)
336 return ERROR_INVALID_ARGUMENTS
;
341 while ((*callbacks_p
)->next
)
342 callbacks_p
= &((*callbacks_p
)->next
);
343 callbacks_p
= &((*callbacks_p
)->next
);
346 (*callbacks_p
) = malloc(sizeof(jtag_event_callback_t
));
347 (*callbacks_p
)->callback
= callback
;
348 (*callbacks_p
)->priv
= priv
;
349 (*callbacks_p
)->next
= NULL
;
354 int jtag_unregister_event_callback(int (*callback
)(enum jtag_event event
, void *priv
))
356 jtag_event_callback_t
**callbacks_p
= &jtag_event_callbacks
;
358 if (callback
== NULL
)
360 return ERROR_INVALID_ARGUMENTS
;
365 jtag_event_callback_t
**next
= &((*callbacks_p
)->next
);
366 if ((*callbacks_p
)->callback
== callback
)
369 *callbacks_p
= *next
;
377 int jtag_call_event_callbacks(enum jtag_event event
)
379 jtag_event_callback_t
*callback
= jtag_event_callbacks
;
381 LOG_DEBUG("jtag event: %s", jtag_event_strings
[event
]);
385 callback
->callback(event
, callback
->priv
);
386 callback
= callback
->next
;
392 static void jtag_checks(void)
394 assert(jtag_trst
== 0);
397 static void jtag_prelude(tap_state_t state
)
401 assert(state
!=TAP_INVALID
);
403 cmd_queue_cur_state
= state
;
406 void jtag_alloc_in_value32(scan_field_t
*field
)
408 interface_jtag_alloc_in_value32(field
);
411 void jtag_add_ir_scan_noverify(int in_count
, const scan_field_t
*in_fields
,
416 int retval
= interface_jtag_add_ir_scan(in_count
, in_fields
, state
);
417 jtag_set_error(retval
);
421 void jtag_add_ir_scan(int in_num_fields
, scan_field_t
*in_fields
, tap_state_t state
)
423 if (jtag_verify
&&jtag_verify_capture_ir
)
425 /* 8 x 32 bit id's is enough for all invocations */
427 for (int j
= 0; j
< in_num_fields
; j
++)
429 /* if we are to run a verification of the ir scan, we need to get the input back.
430 * We may have to allocate space if the caller didn't ask for the input back.
432 in_fields
[j
].check_value
=in_fields
[j
].tap
->expected
;
433 in_fields
[j
].check_mask
=in_fields
[j
].tap
->expected_mask
;
435 jtag_add_scan_check(jtag_add_ir_scan_noverify
, in_num_fields
, in_fields
, state
);
438 jtag_add_ir_scan_noverify(in_num_fields
, in_fields
, state
);
442 void jtag_add_plain_ir_scan(int in_num_fields
, const scan_field_t
*in_fields
,
447 int retval
= interface_jtag_add_plain_ir_scan(
448 in_num_fields
, in_fields
, state
);
449 jtag_set_error(retval
);
452 void jtag_add_callback(jtag_callback1_t f
, u8
*in
)
454 interface_jtag_add_callback(f
, in
);
457 void jtag_add_callback4(jtag_callback_t f
, u8
*in
,
458 jtag_callback_data_t data1
, jtag_callback_data_t data2
,
459 jtag_callback_data_t data3
)
461 interface_jtag_add_callback4(f
, in
, data1
, data2
, data3
);
464 int jtag_check_value_inner(u8
*captured
, u8
*in_check_value
, u8
*in_check_mask
, int num_bits
);
466 static int jtag_check_value_mask_callback(u8
*in
, jtag_callback_data_t data1
, jtag_callback_data_t data2
, jtag_callback_data_t data3
)
468 return jtag_check_value_inner(in
, (u8
*)data1
, (u8
*)data2
, (int)data3
);
471 static void jtag_add_scan_check(void (*jtag_add_scan
)(int in_num_fields
, const scan_field_t
*in_fields
, tap_state_t state
),
472 int in_num_fields
, scan_field_t
*in_fields
, tap_state_t state
)
474 for (int i
= 0; i
< in_num_fields
; i
++)
476 struct scan_field_s
*field
= &in_fields
[i
];
477 field
->allocated
= 0;
479 if (field
->check_value
|| field
->in_value
)
481 interface_jtag_add_scan_check_alloc(field
);
485 jtag_add_scan(in_num_fields
, in_fields
, state
);
487 for (int i
= 0; i
< in_num_fields
; i
++)
489 if ((in_fields
[i
].check_value
!= NULL
) && (in_fields
[i
].in_value
!= NULL
))
491 /* this is synchronous for a minidriver */
492 jtag_add_callback4(jtag_check_value_mask_callback
, in_fields
[i
].in_value
,
493 (jtag_callback_data_t
)in_fields
[i
].check_value
,
494 (jtag_callback_data_t
)in_fields
[i
].check_mask
,
495 (jtag_callback_data_t
)in_fields
[i
].num_bits
);
497 if (in_fields
[i
].allocated
)
499 free(in_fields
[i
].in_value
);
501 if (in_fields
[i
].modified
)
503 in_fields
[i
].in_value
= NULL
;
508 void jtag_add_dr_scan_check(int in_num_fields
, scan_field_t
*in_fields
, tap_state_t state
)
512 jtag_add_scan_check(jtag_add_dr_scan
, in_num_fields
, in_fields
, state
);
515 jtag_add_dr_scan(in_num_fields
, in_fields
, state
);
520 void jtag_add_dr_scan(int in_num_fields
, const scan_field_t
*in_fields
,
526 retval
= interface_jtag_add_dr_scan(in_num_fields
, in_fields
, state
);
527 jtag_set_error(retval
);
530 void jtag_add_plain_dr_scan(int in_num_fields
, const scan_field_t
*in_fields
,
536 retval
= interface_jtag_add_plain_dr_scan(in_num_fields
, in_fields
, state
);
537 jtag_set_error(retval
);
540 void jtag_add_dr_out(jtag_tap_t
* tap
,
541 int num_fields
, const int* num_bits
, const u32
* value
,
542 tap_state_t end_state
)
544 assert(end_state
!= TAP_INVALID
);
546 cmd_queue_cur_state
= end_state
;
548 interface_jtag_add_dr_out(tap
,
549 num_fields
, num_bits
, value
,
553 void jtag_add_tlr(void)
555 jtag_prelude(TAP_RESET
);
556 jtag_set_error(interface_jtag_add_tlr());
557 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
560 void jtag_add_pathmove(int num_states
, const tap_state_t
*path
)
562 tap_state_t cur_state
= cmd_queue_cur_state
;
564 /* the last state has to be a stable state */
565 if (!tap_is_state_stable(path
[num_states
- 1]))
567 LOG_ERROR("BUG: TAP path doesn't finish in a stable state");
568 jtag_set_error(ERROR_JTAG_NOT_STABLE_STATE
);
572 for (int i
= 0; i
< num_states
; i
++)
574 if (path
[i
] == TAP_RESET
)
576 LOG_ERROR("BUG: TAP_RESET is not a valid state for pathmove sequences");
577 jtag_set_error(ERROR_JTAG_STATE_INVALID
);
581 if ( tap_state_transition(cur_state
, true) != path
[i
]
582 && tap_state_transition(cur_state
, false) != path
[i
])
584 LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition",
585 tap_state_name(cur_state
), tap_state_name(path
[i
]));
586 jtag_set_error(ERROR_JTAG_TRANSITION_INVALID
);
594 jtag_set_error(interface_jtag_add_pathmove(num_states
, path
));
595 cmd_queue_cur_state
= path
[num_states
- 1];
598 void jtag_add_runtest(int num_cycles
, tap_state_t state
)
601 jtag_set_error(interface_jtag_add_runtest(num_cycles
, state
));
605 void jtag_add_clocks(int num_cycles
)
607 if (!tap_is_state_stable(cmd_queue_cur_state
))
609 LOG_ERROR("jtag_add_clocks() called with TAP in unstable state \"%s\"",
610 tap_state_name(cmd_queue_cur_state
));
611 jtag_set_error(ERROR_JTAG_NOT_STABLE_STATE
);
618 jtag_set_error(interface_jtag_add_clocks(num_cycles
));
622 void jtag_add_reset(int req_tlr_or_trst
, int req_srst
)
624 int trst_with_tlr
= 0;
626 /* FIX!!! there are *many* different cases here. A better
627 * approach is needed for legal combinations of transitions...
629 if ((jtag_reset_config
& RESET_HAS_SRST
)&&
630 (jtag_reset_config
& RESET_HAS_TRST
)&&
631 ((jtag_reset_config
& RESET_SRST_PULLS_TRST
)==0))
633 if (((req_tlr_or_trst
&&!jtag_trst
)||
634 (!req_tlr_or_trst
&&jtag_trst
))&&
635 ((req_srst
&&!jtag_srst
)||
636 (!req_srst
&&jtag_srst
)))
638 /* FIX!!! srst_pulls_trst allows 1,1 => 0,0 transition.... */
639 //LOG_ERROR("BUG: transition of req_tlr_or_trst and req_srst in the same jtag_add_reset() call is undefined");
643 /* Make sure that jtag_reset_config allows the requested reset */
644 /* if SRST pulls TRST, we can't fulfill srst == 1 with trst == 0 */
645 if (((jtag_reset_config
& RESET_SRST_PULLS_TRST
) && (req_srst
== 1)) && (!req_tlr_or_trst
))
647 LOG_ERROR("BUG: requested reset would assert trst");
648 jtag_set_error(ERROR_FAIL
);
652 /* if TRST pulls SRST, we reset with TAP T-L-R */
653 if (((jtag_reset_config
& RESET_TRST_PULLS_SRST
) && (req_tlr_or_trst
)) && (req_srst
== 0))
658 if (req_srst
&& !(jtag_reset_config
& RESET_HAS_SRST
))
660 LOG_ERROR("BUG: requested SRST assertion, but the current configuration doesn't support this");
661 jtag_set_error(ERROR_FAIL
);
667 if (!trst_with_tlr
&& (jtag_reset_config
& RESET_HAS_TRST
))
679 jtag_srst
= req_srst
;
681 int retval
= interface_jtag_add_reset(jtag_trst
, jtag_srst
);
682 if (retval
!= ERROR_OK
)
684 jtag_set_error(retval
);
687 jtag_execute_queue();
691 LOG_DEBUG("SRST line asserted");
695 LOG_DEBUG("SRST line released");
696 if (jtag_nsrst_delay
)
697 jtag_add_sleep(jtag_nsrst_delay
* 1000);
702 LOG_DEBUG("JTAG reset with RESET instead of TRST");
703 jtag_set_end_state(TAP_RESET
);
710 /* we just asserted nTRST, so we're now in Test-Logic-Reset,
711 * and inform possible listeners about this
713 LOG_DEBUG("TRST line asserted");
714 tap_set_state(TAP_RESET
);
715 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
719 if (jtag_ntrst_delay
)
720 jtag_add_sleep(jtag_ntrst_delay
* 1000);
724 tap_state_t
jtag_set_end_state(tap_state_t state
)
726 if ((state
== TAP_DRSHIFT
)||(state
== TAP_IRSHIFT
))
728 LOG_ERROR("BUG: TAP_DRSHIFT/IRSHIFT can't be end state. Calling code should use a larger scan field");
731 if (state
!=TAP_INVALID
)
732 cmd_queue_end_state
= state
;
733 return cmd_queue_end_state
;
736 tap_state_t
jtag_get_end_state(void)
738 return cmd_queue_end_state
;
741 void jtag_add_sleep(u32 us
)
743 /// @todo Here, keep_alive() appears to be a layering violation!!!
745 jtag_set_error(interface_jtag_add_sleep(us
));
748 int jtag_check_value_inner(u8
*captured
, u8
*in_check_value
, u8
*in_check_mask
, int num_bits
)
750 int retval
= ERROR_OK
;
752 int compare_failed
= 0;
755 compare_failed
= buf_cmp_mask(captured
, in_check_value
, in_check_mask
, num_bits
);
757 compare_failed
= buf_cmp(captured
, in_check_value
, num_bits
);
760 /* An error handler could have caught the failing check
761 * only report a problem when there wasn't a handler, or if the handler
762 * acknowledged the error
765 LOG_WARNING("TAP %s:",
766 jtag_tap_name(field->tap));
770 char *captured_char
= buf_to_str(captured
, (num_bits
> DEBUG_JTAG_IOZ
) ? DEBUG_JTAG_IOZ
: num_bits
, 16);
771 char *in_check_value_char
= buf_to_str(in_check_value
, (num_bits
> DEBUG_JTAG_IOZ
) ? DEBUG_JTAG_IOZ
: num_bits
, 16);
775 char *in_check_mask_char
;
776 in_check_mask_char
= buf_to_str(in_check_mask
, (num_bits
> DEBUG_JTAG_IOZ
) ? DEBUG_JTAG_IOZ
: num_bits
, 16);
777 LOG_WARNING("value captured during scan didn't pass the requested check:");
778 LOG_WARNING("captured: 0x%s check_value: 0x%s check_mask: 0x%s",
779 captured_char
, in_check_value_char
, in_check_mask_char
);
780 free(in_check_mask_char
);
784 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
);
788 free(in_check_value_char
);
790 retval
= ERROR_JTAG_QUEUE_FAILED
;
797 void jtag_check_value_mask(scan_field_t
*field
, u8
*value
, u8
*mask
)
799 assert(field
->in_value
!= NULL
);
803 /* no checking to do */
807 jtag_execute_queue_noclear();
809 int retval
=jtag_check_value_inner(field
->in_value
, value
, mask
, field
->num_bits
);
810 jtag_set_error(retval
);
815 int default_interface_jtag_execute_queue(void)
819 LOG_ERROR("No JTAG interface configured yet. "
820 "Issue 'init' command in startup scripts "
821 "before communicating with targets.");
825 return jtag
->execute_queue();
828 void jtag_execute_queue_noclear(void)
830 jtag_flush_queue_count
++;
831 jtag_set_error(interface_jtag_execute_queue());
834 int jtag_get_flush_queue_count(void)
836 return jtag_flush_queue_count
;
839 int jtag_execute_queue(void)
841 jtag_execute_queue_noclear();
842 return jtag_error_clear();
845 static int jtag_reset_callback(enum jtag_event event
, void *priv
)
847 jtag_tap_t
*tap
= priv
;
851 if (event
== JTAG_TRST_ASSERTED
)
853 buf_set_ones(tap
->cur_instr
, tap
->ir_length
);
860 void jtag_sleep(u32 us
)
862 alive_sleep(us
/1000);
865 /// maximum number of JTAG devices expected in the chain
866 #define JTAG_MAX_CHAIN_SIZE 20
868 #define EXTRACT_MFG(X) (((X) & 0xffe) >> 1)
869 #define EXTRACT_PART(X) (((X) & 0xffff000) >> 12)
870 #define EXTRACT_VER(X) (((X) & 0xf0000000) >> 28)
872 static int jtag_examine_chain_execute(u8
*idcode_buffer
, unsigned num_idcode
)
874 scan_field_t field
= {
876 .num_bits
= num_idcode
* 32,
877 .out_value
= idcode_buffer
,
878 .in_value
= idcode_buffer
,
881 // initialize to the end of chain ID value
882 for (unsigned i
= 0; i
< JTAG_MAX_CHAIN_SIZE
; i
++)
883 buf_set_u32(idcode_buffer
, i
* 32, 32, 0x000000FF);
885 jtag_add_plain_dr_scan(1, &field
, TAP_RESET
);
886 return jtag_execute_queue();
889 static bool jtag_examine_chain_check(u8
*idcodes
, unsigned count
)
894 for (unsigned i
= 0; i
< count
* 4; i
++)
896 zero_check
|= idcodes
[i
];
897 one_check
&= idcodes
[i
];
900 /* if there wasn't a single non-zero bit or if all bits were one,
901 * the scan is not valid */
902 if (zero_check
== 0x00 || one_check
== 0xff)
904 LOG_ERROR("JTAG communication failure: check connection, "
905 "JTAG interface, target power etc.");
911 static void jtag_examine_chain_display(enum log_levels level
, const char *msg
,
912 const char *name
, u32 idcode
)
914 log_printf_lf(level
, __FILE__
, __LINE__
, __FUNCTION__
,
915 "JTAG tap: %s %16.16s: 0x%08x "
916 "(mfg: 0x%3.3x, part: 0x%4.4x, ver: 0x%1.1x)",
918 EXTRACT_MFG(idcode
), EXTRACT_PART(idcode
), EXTRACT_VER(idcode
) );
921 static bool jtag_idcode_is_final(u32 idcode
)
923 return idcode
== 0x000000FF || idcode
== 0xFFFFFFFF;
927 * This helper checks that remaining bits in the examined chain data are
928 * all as expected, but a single JTAG device requires only 64 bits to be
929 * read back correctly. This can help identify and diagnose problems
930 * with the JTAG chain earlier, gives more helpful/explicit error messages.
932 static void jtag_examine_chain_end(u8
*idcodes
, unsigned count
, unsigned max
)
934 bool triggered
= false;
935 for ( ; count
< max
- 31; count
+= 32)
937 u32 idcode
= buf_get_u32(idcodes
, count
, 32);
938 // do not trigger the warning if the data looks good
939 if (!triggered
&& jtag_idcode_is_final(idcode
))
941 LOG_WARNING("Unexpected idcode after end of chain: %d 0x%08x",
947 static bool jtag_examine_chain_match_tap(const struct jtag_tap_s
*tap
)
949 if (0 == tap
->expected_ids_cnt
)
951 /// @todo Enable LOG_INFO to ask for reports about unknown TAP IDs.
953 LOG_INFO("Uknown JTAG TAP ID: 0x%08x", tap
->idcode
)
954 LOG_INFO("Please report the chip name and reported ID code to the openocd project");
959 /* Loop over the expected identification codes and test for a match */
961 for (ii
= 0; ii
< tap
->expected_ids_cnt
; ii
++)
963 if (tap
->idcode
== tap
->expected_ids
[ii
])
967 /* If none of the expected ids matched, log an error */
968 if (ii
!= tap
->expected_ids_cnt
)
970 LOG_INFO("JTAG Tap/device matched");
973 jtag_examine_chain_display(LOG_LVL_ERROR
, "got",
974 tap
->dotted_name
, tap
->idcode
);
975 for (ii
= 0; ii
< tap
->expected_ids_cnt
; ii
++)
978 snprintf(msg
, sizeof(msg
), "expected %hhu of %hhu",
979 ii
+ 1, tap
->expected_ids_cnt
);
980 jtag_examine_chain_display(LOG_LVL_ERROR
, msg
,
981 tap
->dotted_name
, tap
->expected_ids
[ii
]);
986 /* Try to examine chain layout according to IEEE 1149.1 §12
988 static int jtag_examine_chain(void)
990 u8 idcode_buffer
[JTAG_MAX_CHAIN_SIZE
* 4];
991 unsigned device_count
= 0;
993 jtag_examine_chain_execute(idcode_buffer
, JTAG_MAX_CHAIN_SIZE
);
995 if (!jtag_examine_chain_check(idcode_buffer
, JTAG_MAX_CHAIN_SIZE
))
996 return ERROR_JTAG_INIT_FAILED
;
998 /* point at the 1st tap */
999 jtag_tap_t
*tap
= jtag_tap_next_enabled(NULL
);
1002 LOG_ERROR("JTAG: No taps enabled?");
1003 return ERROR_JTAG_INIT_FAILED
;
1006 for (unsigned bit_count
= 0; bit_count
< (JTAG_MAX_CHAIN_SIZE
* 32) - 31;)
1008 u32 idcode
= buf_get_u32(idcode_buffer
, bit_count
, 32);
1009 if ((idcode
& 1) == 0)
1011 /* LSB must not be 0, this indicates a device in bypass */
1012 LOG_WARNING("Tap/Device does not have IDCODE");
1020 * End of chain (invalid manufacturer ID) some devices, such
1021 * as AVR will output all 1's instead of TDI input value at
1024 if (jtag_idcode_is_final(idcode
))
1026 jtag_examine_chain_end(idcode_buffer
,
1027 bit_count
+ 32, JTAG_MAX_CHAIN_SIZE
* 32);
1031 jtag_examine_chain_display(LOG_LVL_INFO
, "tap/device found",
1032 tap
? tap
->dotted_name
: "(not-named)",
1041 tap
->idcode
= idcode
;
1043 // ensure the TAP ID does matches what was expected
1044 if (!jtag_examine_chain_match_tap(tap
))
1045 return ERROR_JTAG_INIT_FAILED
;
1047 tap
= jtag_tap_next_enabled(tap
);
1050 /* see if number of discovered devices matches configuration */
1051 if (device_count
!= jtag_tap_count_enabled())
1053 LOG_ERROR("number of discovered devices in JTAG chain (%i) "
1054 "does not match (enabled) configuration (%i), total taps: %d",
1055 device_count
, jtag_tap_count_enabled(), jtag_tap_count());
1056 LOG_ERROR("check the config file and ensure proper JTAG communication"
1057 " (connections, speed, ...)");
1058 return ERROR_JTAG_INIT_FAILED
;
1064 static int jtag_validate_chain(void)
1067 int total_ir_length
= 0;
1073 total_ir_length
= 0;
1075 tap
= jtag_tap_next_enabled(tap
);
1079 total_ir_length
+= tap
->ir_length
;
1082 total_ir_length
+= 2;
1083 ir_test
= malloc(CEIL(total_ir_length
, 8));
1084 buf_set_ones(ir_test
, total_ir_length
);
1087 field
.num_bits
= total_ir_length
;
1088 field
.out_value
= ir_test
;
1089 field
.in_value
= ir_test
;
1092 jtag_add_plain_ir_scan(1, &field
, TAP_RESET
);
1093 jtag_execute_queue();
1099 tap
= jtag_tap_next_enabled(tap
);
1104 val
= buf_get_u32(ir_test
, chain_pos
, 2);
1107 char *cbuf
= buf_to_str(ir_test
, total_ir_length
, 16);
1108 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
);
1111 return ERROR_JTAG_INIT_FAILED
;
1113 chain_pos
+= tap
->ir_length
;
1116 val
= buf_get_u32(ir_test
, chain_pos
, 2);
1119 char *cbuf
= buf_to_str(ir_test
, total_ir_length
, 16);
1120 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
);
1123 return ERROR_JTAG_INIT_FAILED
;
1131 enum jtag_tap_cfg_param
{
1135 static Jim_Nvp nvp_config_opts
[] = {
1136 { .name
= "-event", .value
= JCFG_EVENT
},
1138 { .name
= NULL
, .value
= -1 }
1141 static int jtag_tap_configure_cmd( Jim_GetOptInfo
*goi
, jtag_tap_t
* tap
)
1147 /* parse config or cget options */
1148 while (goi
->argc
> 0) {
1149 Jim_SetEmptyResult (goi
->interp
);
1151 e
= Jim_GetOpt_Nvp(goi
, nvp_config_opts
, &n
);
1153 Jim_GetOpt_NvpUnknown(goi
, nvp_config_opts
, 0);
1159 if (goi
->argc
== 0) {
1160 Jim_WrongNumArgs( goi
->interp
, goi
->argc
, goi
->argv
, "-event ?event-name? ..." );
1164 e
= Jim_GetOpt_Nvp( goi
, nvp_jtag_tap_event
, &n
);
1166 Jim_GetOpt_NvpUnknown(goi
, nvp_jtag_tap_event
, 1);
1170 if (goi
->isconfigure
) {
1171 if (goi
->argc
!= 1) {
1172 Jim_WrongNumArgs(goi
->interp
, goi
->argc
, goi
->argv
, "-event ?event-name? ?EVENT-BODY?");
1176 if (goi
->argc
!= 0) {
1177 Jim_WrongNumArgs(goi
->interp
, goi
->argc
, goi
->argv
, "-event ?event-name?");
1183 jtag_tap_event_action_t
*jteap
;
1185 jteap
= tap
->event_action
;
1186 /* replace existing? */
1188 if (jteap
->event
== (enum jtag_tap_event
)n
->value
) {
1191 jteap
= jteap
->next
;
1194 if (goi
->isconfigure
) {
1195 if (jteap
== NULL
) {
1197 jteap
= calloc(1, sizeof (*jteap
));
1199 jteap
->event
= n
->value
;
1200 Jim_GetOpt_Obj( goi
, &o
);
1202 Jim_DecrRefCount(interp
, jteap
->body
);
1204 jteap
->body
= Jim_DuplicateObj(goi
->interp
, o
);
1205 Jim_IncrRefCount(jteap
->body
);
1207 /* add to head of event list */
1208 jteap
->next
= tap
->event_action
;
1209 tap
->event_action
= jteap
;
1210 Jim_SetEmptyResult(goi
->interp
);
1213 if (jteap
== NULL
) {
1214 Jim_SetEmptyResult(goi
->interp
);
1216 Jim_SetResult(goi
->interp
, Jim_DuplicateObj(goi
->interp
, jteap
->body
));
1223 } /* while (goi->argc) */
1229 static void jtag_tap_init(jtag_tap_t
*tap
)
1231 assert(0 != tap
->ir_length
);
1233 tap
->expected
= malloc(tap
->ir_length
);
1234 tap
->expected_mask
= malloc(tap
->ir_length
);
1235 tap
->cur_instr
= malloc(tap
->ir_length
);
1237 buf_set_u32(tap
->expected
, 0, tap
->ir_length
, tap
->ir_capture_value
);
1238 buf_set_u32(tap
->expected_mask
, 0, tap
->ir_length
, tap
->ir_capture_mask
);
1239 buf_set_ones(tap
->cur_instr
, tap
->ir_length
);
1241 // place TAP in bypass mode
1243 // register the reset callback for the TAP
1244 jtag_register_event_callback(&jtag_reset_callback
, tap
);
1246 LOG_DEBUG("Created Tap: %s @ abs position %d, "
1247 "irlen %d, capture: 0x%x mask: 0x%x", tap
->dotted_name
,
1248 tap
->abs_chain_position
, tap
->ir_length
,
1249 tap
->ir_capture_value
, tap
->ir_capture_mask
);
1253 static void jtag_tap_free(jtag_tap_t
*tap
)
1255 /// @todo is anything missing? no memory leaks please
1256 free((void *)tap
->expected_ids
);
1257 free((void *)tap
->chip
);
1258 free((void *)tap
->tapname
);
1259 free((void *)tap
->dotted_name
);
1263 static int jim_newtap_cmd( Jim_GetOptInfo
*goi
)
1272 const Jim_Nvp opts
[] = {
1273 #define NTAP_OPT_IRLEN 0
1274 { .name
= "-irlen" , .value
= NTAP_OPT_IRLEN
},
1275 #define NTAP_OPT_IRMASK 1
1276 { .name
= "-irmask" , .value
= NTAP_OPT_IRMASK
},
1277 #define NTAP_OPT_IRCAPTURE 2
1278 { .name
= "-ircapture" , .value
= NTAP_OPT_IRCAPTURE
},
1279 #define NTAP_OPT_ENABLED 3
1280 { .name
= "-enable" , .value
= NTAP_OPT_ENABLED
},
1281 #define NTAP_OPT_DISABLED 4
1282 { .name
= "-disable" , .value
= NTAP_OPT_DISABLED
},
1283 #define NTAP_OPT_EXPECTED_ID 5
1284 { .name
= "-expected-id" , .value
= NTAP_OPT_EXPECTED_ID
},
1285 { .name
= NULL
, .value
= -1 },
1288 pTap
= malloc( sizeof(jtag_tap_t
) );
1289 memset( pTap
, 0, sizeof(*pTap
) );
1291 Jim_SetResult_sprintf( goi
->interp
, "no memory");
1295 * we expect CHIP + TAP + OPTIONS
1297 if( goi
->argc
< 3 ){
1298 Jim_SetResult_sprintf(goi
->interp
, "Missing CHIP TAP OPTIONS ....");
1301 Jim_GetOpt_String( goi
, &cp
, NULL
);
1302 pTap
->chip
= strdup(cp
);
1304 Jim_GetOpt_String( goi
, &cp
, NULL
);
1305 pTap
->tapname
= strdup(cp
);
1307 /* name + dot + name + null */
1308 x
= strlen(pTap
->chip
) + 1 + strlen(pTap
->tapname
) + 1;
1310 sprintf( cp
, "%s.%s", pTap
->chip
, pTap
->tapname
);
1311 pTap
->dotted_name
= cp
;
1313 LOG_DEBUG("Creating New Tap, Chip: %s, Tap: %s, Dotted: %s, %d params",
1314 pTap
->chip
, pTap
->tapname
, pTap
->dotted_name
, goi
->argc
);
1316 /* default is enabled */
1319 /* deal with options */
1320 #define NTREQ_IRLEN 1
1321 #define NTREQ_IRCAPTURE 2
1322 #define NTREQ_IRMASK 4
1324 /* clear them as we find them */
1325 reqbits
= (NTREQ_IRLEN
| NTREQ_IRCAPTURE
| NTREQ_IRMASK
);
1328 e
= Jim_GetOpt_Nvp( goi
, opts
, &n
);
1330 Jim_GetOpt_NvpUnknown( goi
, opts
, 0 );
1333 LOG_DEBUG("Processing option: %s", n
->name
);
1335 case NTAP_OPT_ENABLED
:
1338 case NTAP_OPT_DISABLED
:
1341 case NTAP_OPT_EXPECTED_ID
:
1343 u32
*new_expected_ids
;
1345 e
= Jim_GetOpt_Wide( goi
, &w
);
1347 Jim_SetResult_sprintf(goi
->interp
, "option: %s bad parameter", n
->name
);
1351 new_expected_ids
= malloc(sizeof(u32
) * (pTap
->expected_ids_cnt
+ 1));
1352 if (new_expected_ids
== NULL
) {
1353 Jim_SetResult_sprintf( goi
->interp
, "no memory");
1357 memcpy(new_expected_ids
, pTap
->expected_ids
, sizeof(u32
) * pTap
->expected_ids_cnt
);
1359 new_expected_ids
[pTap
->expected_ids_cnt
] = w
;
1361 free(pTap
->expected_ids
);
1362 pTap
->expected_ids
= new_expected_ids
;
1363 pTap
->expected_ids_cnt
++;
1366 case NTAP_OPT_IRLEN
:
1367 case NTAP_OPT_IRMASK
:
1368 case NTAP_OPT_IRCAPTURE
:
1369 e
= Jim_GetOpt_Wide( goi
, &w
);
1371 Jim_SetResult_sprintf( goi
->interp
, "option: %s bad parameter", n
->name
);
1374 if( (w
< 0) || (w
> 0xffff) ){
1376 Jim_SetResult_sprintf( goi
->interp
, "option: %s - wacky value: %d (0x%x)",
1377 n
->name
, (int)(w
), (int)(w
));
1381 case NTAP_OPT_IRLEN
:
1382 pTap
->ir_length
= w
;
1383 reqbits
&= (~(NTREQ_IRLEN
));
1385 case NTAP_OPT_IRMASK
:
1386 pTap
->ir_capture_mask
= w
;
1387 reqbits
&= (~(NTREQ_IRMASK
));
1389 case NTAP_OPT_IRCAPTURE
:
1390 pTap
->ir_capture_value
= w
;
1391 reqbits
&= (~(NTREQ_IRCAPTURE
));
1394 } /* switch(n->value) */
1395 } /* while( goi->argc ) */
1397 /* Did all the required option bits get cleared? */
1400 jtag_tap_init(pTap
);
1404 Jim_SetResult_sprintf(goi
->interp
,
1405 "newtap: %s missing required parameters",
1407 jtag_tap_free(pTap
);
1411 static int jim_jtag_command( Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
1417 struct command_context_s
*context
;
1421 JTAG_CMD_INIT_RESET
,
1424 JTAG_CMD_TAPDISABLE
,
1425 JTAG_CMD_TAPISENABLED
,
1430 const Jim_Nvp jtag_cmds
[] = {
1431 { .name
= "interface" , .value
= JTAG_CMD_INTERFACE
},
1432 { .name
= "arp_init-reset", .value
= JTAG_CMD_INIT_RESET
},
1433 { .name
= "newtap" , .value
= JTAG_CMD_NEWTAP
},
1434 { .name
= "tapisenabled" , .value
= JTAG_CMD_TAPISENABLED
},
1435 { .name
= "tapenable" , .value
= JTAG_CMD_TAPENABLE
},
1436 { .name
= "tapdisable" , .value
= JTAG_CMD_TAPDISABLE
},
1437 { .name
= "configure" , .value
= JTAG_CMD_CONFIGURE
},
1438 { .name
= "cget" , .value
= JTAG_CMD_CGET
},
1440 { .name
= NULL
, .value
= -1 },
1443 context
= Jim_GetAssocData(interp
, "context");
1444 /* go past the command */
1445 Jim_GetOpt_Setup( &goi
, interp
, argc
-1, argv
+1 );
1447 e
= Jim_GetOpt_Nvp( &goi
, jtag_cmds
, &n
);
1449 Jim_GetOpt_NvpUnknown( &goi
, jtag_cmds
, 0 );
1452 Jim_SetEmptyResult( goi
.interp
);
1454 case JTAG_CMD_INTERFACE
:
1455 /* return the name of the interface */
1456 /* TCL code might need to know the exact type... */
1457 /* FUTURE: we allow this as a means to "set" the interface. */
1458 if( goi
.argc
!= 0 ){
1459 Jim_WrongNumArgs( goi
.interp
, 1, goi
.argv
-1, "(no params)");
1462 Jim_SetResultString( goi
.interp
, jtag_interface
->name
, -1 );
1464 case JTAG_CMD_INIT_RESET
:
1465 if( goi
.argc
!= 0 ){
1466 Jim_WrongNumArgs( goi
.interp
, 1, goi
.argv
-1, "(no params)");
1469 e
= jtag_init_reset(context
);
1470 if( e
!= ERROR_OK
){
1471 Jim_SetResult_sprintf( goi
.interp
, "error: %d", e
);
1475 case JTAG_CMD_NEWTAP
:
1476 return jim_newtap_cmd( &goi
);
1478 case JTAG_CMD_TAPISENABLED
:
1479 case JTAG_CMD_TAPENABLE
:
1480 case JTAG_CMD_TAPDISABLE
:
1481 if( goi
.argc
!= 1 ){
1482 Jim_SetResultString( goi
.interp
, "Too many parameters",-1 );
1488 t
= jtag_tap_by_jim_obj( goi
.interp
, goi
.argv
[0] );
1493 case JTAG_CMD_TAPISENABLED
:
1496 case JTAG_CMD_TAPENABLE
:
1497 jtag_tap_handle_event( t
, JTAG_TAP_EVENT_ENABLE
);
1501 case JTAG_CMD_TAPDISABLE
:
1502 jtag_tap_handle_event( t
, JTAG_TAP_EVENT_DISABLE
);
1507 Jim_SetResult( goi
.interp
, Jim_NewIntObj( goi
.interp
, e
) );
1514 Jim_WrongNumArgs( goi
.interp
, 0, NULL
, "?tap-name? -option ...");
1521 Jim_GetOpt_Obj(&goi
, &o
);
1522 t
= jtag_tap_by_jim_obj( goi
.interp
, o
);
1527 goi
.isconfigure
= 0;
1528 return jtag_tap_configure_cmd( &goi
, t
);
1532 case JTAG_CMD_CONFIGURE
:
1534 Jim_WrongNumArgs( goi
.interp
, 0, NULL
, "?tap-name? -option ?VALUE? ...");
1541 Jim_GetOpt_Obj(&goi
, &o
);
1542 t
= jtag_tap_by_jim_obj( goi
.interp
, o
);
1547 goi
.isconfigure
= 1;
1548 return jtag_tap_configure_cmd( &goi
, t
);
1555 int jtag_register_commands(struct command_context_s
*cmd_ctx
)
1557 register_jim( cmd_ctx
, "jtag", jim_jtag_command
, "perform jtag tap actions");
1559 register_command(cmd_ctx
, NULL
, "interface", handle_interface_command
,
1560 COMMAND_CONFIG
, "try to configure interface");
1561 register_command(cmd_ctx
, NULL
,
1562 "interface_list", &handle_interface_list_command
,
1563 COMMAND_ANY
, "list all built-in interfaces");
1564 register_command(cmd_ctx
, NULL
, "jtag_speed", handle_jtag_speed_command
,
1565 COMMAND_ANY
, "(DEPRECATED) set jtag speed (if supported)");
1566 register_command(cmd_ctx
, NULL
, "jtag_khz", handle_jtag_khz_command
,
1567 COMMAND_ANY
, "set maximum jtag speed (if supported); "
1568 "parameter is maximum khz, or 0 for adaptive clocking (RTCK).");
1569 register_command(cmd_ctx
, NULL
, "jtag_device", handle_jtag_device_command
,
1570 COMMAND_CONFIG
, "(DEPRECATED) jtag_device <ir_length> <ir_expected> <ir_mask>");
1571 register_command(cmd_ctx
, NULL
, "reset_config", handle_reset_config_command
,
1573 "[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]");
1574 register_command(cmd_ctx
, NULL
, "jtag_nsrst_delay", handle_jtag_nsrst_delay_command
,
1575 COMMAND_ANY
, "jtag_nsrst_delay <ms> - delay after deasserting srst in ms");
1576 register_command(cmd_ctx
, NULL
, "jtag_ntrst_delay", handle_jtag_ntrst_delay_command
,
1577 COMMAND_ANY
, "jtag_ntrst_delay <ms> - delay after deasserting trst in ms");
1579 register_command(cmd_ctx
, NULL
, "scan_chain", handle_scan_chain_command
,
1580 COMMAND_EXEC
, "print current scan chain configuration");
1582 register_command(cmd_ctx
, NULL
, "jtag_reset", handle_jtag_reset_command
,
1583 COMMAND_EXEC
, "toggle reset lines <trst> <srst>");
1584 register_command(cmd_ctx
, NULL
, "runtest", handle_runtest_command
,
1585 COMMAND_EXEC
, "move to Run-Test/Idle, and execute <num_cycles>");
1586 register_command(cmd_ctx
, NULL
, "irscan", handle_irscan_command
,
1587 COMMAND_EXEC
, "execute IR scan <device> <instr> [dev2] [instr2] ...");
1588 register_jim(cmd_ctx
, "drscan", Jim_Command_drscan
, "execute DR scan <device> <num_bits> <value> <num_bits1> <value2> ...");
1589 register_jim(cmd_ctx
, "flush_count", Jim_Command_flush_count
, "returns number of times the JTAG queue has been flushed");
1591 register_command(cmd_ctx
, NULL
, "verify_ircapture", handle_verify_ircapture_command
,
1592 COMMAND_ANY
, "verify value captured during Capture-IR <enable|disable>");
1593 register_command(cmd_ctx
, NULL
, "verify_jtag", handle_verify_jtag_command
,
1594 COMMAND_ANY
, "verify value capture <enable|disable>");
1595 register_command(cmd_ctx
, NULL
, "tms_sequence", handle_tms_sequence_command
,
1596 COMMAND_ANY
, "choose short(default) or long tms_sequence <short|long>");
1600 int jtag_interface_init(struct command_context_s
*cmd_ctx
)
1605 if (!jtag_interface
)
1607 /* nothing was previously specified by "interface" command */
1608 LOG_ERROR("JTAG interface has to be specified, see \"interface\" command");
1609 return ERROR_JTAG_INVALID_INTERFACE
;
1613 jtag_interface
->khz(jtag_get_speed_khz(), &jtag_speed
);
1617 if (jtag_interface
->init() != ERROR_OK
)
1618 return ERROR_JTAG_INIT_FAILED
;
1620 jtag
= jtag_interface
;
1624 static int jtag_init_inner(struct command_context_s
*cmd_ctx
)
1629 LOG_DEBUG("Init JTAG chain");
1631 tap
= jtag_tap_next_enabled(NULL
);
1633 LOG_ERROR("There are no enabled taps?");
1634 return ERROR_JTAG_INIT_FAILED
;
1638 if ((retval
=jtag_execute_queue())!=ERROR_OK
)
1641 /* examine chain first, as this could discover the real chain layout */
1642 if (jtag_examine_chain() != ERROR_OK
)
1644 LOG_ERROR("trying to validate configured JTAG chain anyway...");
1647 if (jtag_validate_chain() != ERROR_OK
)
1649 LOG_WARNING("Could not validate JTAG chain, continuing anyway...");
1655 int jtag_interface_quit(void)
1657 if (!jtag
|| !jtag
->quit
)
1660 // close the JTAG interface
1661 int result
= jtag
->quit();
1662 if (ERROR_OK
!= result
)
1663 LOG_ERROR("failed: %d", result
);
1669 int jtag_init_reset(struct command_context_s
*cmd_ctx
)
1673 if ((retval
=jtag_interface_init(cmd_ctx
)) != ERROR_OK
)
1676 LOG_DEBUG("Trying to bring the JTAG controller to life by asserting TRST / RESET");
1678 /* Reset can happen after a power cycle.
1680 * Ideally we would only assert TRST or run RESET before the target reset.
1682 * However w/srst_pulls_trst, trst is asserted together with the target
1683 * reset whether we want it or not.
1685 * NB! Some targets have JTAG circuitry disabled until a
1686 * trst & srst has been asserted.
1688 * NB! here we assume nsrst/ntrst delay are sufficient!
1690 * NB! order matters!!!! srst *can* disconnect JTAG circuitry
1693 jtag_add_reset(1, 0); /* RESET or TRST */
1694 if (jtag_reset_config
& RESET_HAS_SRST
)
1696 jtag_add_reset(1, 1);
1697 if ((jtag_reset_config
& RESET_SRST_PULLS_TRST
)==0)
1698 jtag_add_reset(0, 1);
1700 jtag_add_reset(0, 0);
1701 if ((retval
= jtag_execute_queue()) != ERROR_OK
)
1704 /* Check that we can communication on the JTAG chain + eventually we want to
1705 * be able to perform enumeration only after OpenOCD has started
1706 * telnet and GDB server
1708 * That would allow users to more easily perform any magic they need to before
1711 return jtag_init_inner(cmd_ctx
);
1714 int jtag_init(struct command_context_s
*cmd_ctx
)
1717 if ((retval
=jtag_interface_init(cmd_ctx
)) != ERROR_OK
)
1719 if (jtag_init_inner(cmd_ctx
)==ERROR_OK
)
1723 return jtag_init_reset(cmd_ctx
);
1726 void jtag_set_speed_khz(unsigned khz
)
1730 unsigned jtag_get_speed_khz(void)
1735 static int default_khz(int khz
, int *jtag_speed
)
1737 LOG_ERROR("Translation from khz to jtag_speed not implemented");
1741 static int default_speed_div(int speed
, int *khz
)
1743 LOG_ERROR("Translation from jtag_speed to khz not implemented");
1747 static int default_power_dropout(int *dropout
)
1749 *dropout
=0; /* by default we can't detect power dropout */
1753 static int default_srst_asserted(int *srst_asserted
)
1755 *srst_asserted
=0; /* by default we can't detect srst asserted */
1759 static int handle_interface_command(struct command_context_s
*cmd_ctx
,
1760 char *cmd
, char **args
, int argc
)
1762 /* check whether the interface is already configured */
1765 LOG_WARNING("Interface already configured, ignoring");
1769 /* interface name is a mandatory argument */
1770 if (argc
!= 1 || args
[0][0] == '\0')
1771 return ERROR_COMMAND_SYNTAX_ERROR
;
1773 for (unsigned i
= 0; NULL
!= jtag_interfaces
[i
]; i
++)
1775 if (strcmp(args
[0], jtag_interfaces
[i
]->name
) != 0)
1778 int retval
= jtag_interfaces
[i
]->register_commands(cmd_ctx
);
1779 if (ERROR_OK
!= retval
)
1782 jtag_interface
= jtag_interfaces
[i
];
1784 if (jtag_interface
->khz
== NULL
)
1785 jtag_interface
->khz
= default_khz
;
1786 if (jtag_interface
->speed_div
== NULL
)
1787 jtag_interface
->speed_div
= default_speed_div
;
1788 if (jtag_interface
->power_dropout
== NULL
)
1789 jtag_interface
->power_dropout
= default_power_dropout
;
1790 if (jtag_interface
->srst_asserted
== NULL
)
1791 jtag_interface
->srst_asserted
= default_srst_asserted
;
1796 /* no valid interface was found (i.e. the configuration option,
1797 * didn't match one of the compiled-in interfaces
1799 LOG_ERROR("The specified JTAG interface was not found (%s)", args
[0]);
1800 handle_interface_list_command(cmd_ctx
, cmd
, args
, argc
);
1801 return ERROR_JTAG_INVALID_INTERFACE
;
1804 static int handle_interface_list_command(struct command_context_s
*cmd_ctx
,
1805 char *cmd
, char **args
, int argc
)
1807 if (strcmp(cmd
, "interface_list") == 0 && argc
> 0)
1808 return ERROR_COMMAND_SYNTAX_ERROR
;
1810 command_print(cmd_ctx
, "The following JTAG interfaces are available:");
1811 for (unsigned i
= 0; NULL
!= jtag_interfaces
[i
]; i
++)
1813 const char *name
= jtag_interfaces
[i
]->name
;
1814 command_print(cmd_ctx
, "%u: %s", i
+ 1, name
);
1820 static int handle_jtag_device_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1824 Jim_Obj
*newargs
[ 10 ];
1827 * argv[-1] = command
1828 * argv[ 0] = ir length
1829 * argv[ 1] = ir capture
1830 * argv[ 2] = ir mask
1831 * argv[ 3] = not actually used by anything but in the docs
1835 command_print( cmd_ctx
, "OLD DEPRECATED SYNTAX: Please use the NEW syntax");
1838 command_print( cmd_ctx
, "OLD SYNTAX: DEPRECATED - translating to new syntax");
1839 command_print( cmd_ctx
, "jtag newtap CHIP TAP -irlen %s -ircapture %s -irvalue %s",
1843 command_print( cmd_ctx
, "Example: STM32 has 2 taps, the cortexM3(len4) + boundaryscan(len5)");
1844 command_print( cmd_ctx
, "jtag newtap stm32 cortexm3 ....., thus creating the tap: \"stm32.cortexm3\"");
1845 command_print( cmd_ctx
, "jtag newtap stm32 boundary ....., and the tap: \"stm32.boundary\"");
1846 command_print( cmd_ctx
, "And then refer to the taps by the dotted name.");
1848 newargs
[0] = Jim_NewStringObj( interp
, "jtag", -1 );
1849 newargs
[1] = Jim_NewStringObj( interp
, "newtap", -1 );
1850 sprintf( buf
, "chip%d", jtag_tap_count() );
1851 newargs
[2] = Jim_NewStringObj( interp
, buf
, -1 );
1852 sprintf( buf
, "tap%d", jtag_tap_count() );
1853 newargs
[3] = Jim_NewStringObj( interp
, buf
, -1 );
1854 newargs
[4] = Jim_NewStringObj( interp
, "-irlen", -1 );
1855 newargs
[5] = Jim_NewStringObj( interp
, args
[0], -1 );
1856 newargs
[6] = Jim_NewStringObj( interp
, "-ircapture", -1 );
1857 newargs
[7] = Jim_NewStringObj( interp
, args
[1], -1 );
1858 newargs
[8] = Jim_NewStringObj( interp
, "-irmask", -1 );
1859 newargs
[9] = Jim_NewStringObj( interp
, args
[2], -1 );
1861 command_print( cmd_ctx
, "NEW COMMAND:");
1862 sprintf( buf
, "%s %s %s %s %s %s %s %s %s %s",
1863 Jim_GetString( newargs
[0], NULL
),
1864 Jim_GetString( newargs
[1], NULL
),
1865 Jim_GetString( newargs
[2], NULL
),
1866 Jim_GetString( newargs
[3], NULL
),
1867 Jim_GetString( newargs
[4], NULL
),
1868 Jim_GetString( newargs
[5], NULL
),
1869 Jim_GetString( newargs
[6], NULL
),
1870 Jim_GetString( newargs
[7], NULL
),
1871 Jim_GetString( newargs
[8], NULL
),
1872 Jim_GetString( newargs
[9], NULL
) );
1874 e
= jim_jtag_command( interp
, 10, newargs
);
1876 command_print( cmd_ctx
, "%s", Jim_GetString( Jim_GetResult(interp
), NULL
) );
1881 static int handle_scan_chain_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1885 tap
= jtag_all_taps();
1886 command_print(cmd_ctx
, " TapName | Enabled | IdCode Expected IrLen IrCap IrMask Instr ");
1887 command_print(cmd_ctx
, "---|--------------------|---------|------------|------------|------|------|------|---------");
1890 u32 expected
, expected_mask
, cur_instr
, ii
;
1891 expected
= buf_get_u32(tap
->expected
, 0, tap
->ir_length
);
1892 expected_mask
= buf_get_u32(tap
->expected_mask
, 0, tap
->ir_length
);
1893 cur_instr
= buf_get_u32(tap
->cur_instr
, 0, tap
->ir_length
);
1895 command_print(cmd_ctx
,
1896 "%2d | %-18s | %c | 0x%08x | 0x%08x | 0x%02x | 0x%02x | 0x%02x | 0x%02x",
1897 tap
->abs_chain_position
,
1899 tap
->enabled
? 'Y' : 'n',
1901 (tap
->expected_ids_cnt
> 0 ? tap
->expected_ids
[0] : 0),
1907 for (ii
= 1; ii
< tap
->expected_ids_cnt
; ii
++) {
1908 command_print(cmd_ctx
, " | | | | 0x%08x | | | | ",
1909 tap
->expected_ids
[ii
]);
1912 tap
= tap
->next_tap
;
1918 static int handle_reset_config_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1924 return ERROR_COMMAND_SYNTAX_ERROR
;
1926 /* Original versions cared about the order of these tokens:
1927 * reset_config signals [combination [trst_type [srst_type]]]
1928 * They also clobbered the previous configuration even on error.
1930 * Here we don't care about the order, and only change values
1931 * which have been explicitly specified.
1933 for (; argc
; argc
--, args
++) {
1938 m
= RESET_HAS_TRST
| RESET_HAS_SRST
;
1939 if (strcmp(*args
, "none") == 0)
1941 else if (strcmp(*args
, "trst_only") == 0)
1942 tmp
= RESET_HAS_TRST
;
1943 else if (strcmp(*args
, "srst_only") == 0)
1944 tmp
= RESET_HAS_SRST
;
1945 else if (strcmp(*args
, "trst_and_srst") == 0)
1946 tmp
= RESET_HAS_TRST
| RESET_HAS_SRST
;
1950 LOG_ERROR("extra reset_config %s spec (%s)",
1952 return ERROR_INVALID_ARGUMENTS
;
1957 /* combination (options for broken wiring) */
1958 m
= RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
;
1959 if (strcmp(*args
, "separate") == 0)
1960 /* separate reset lines - default */;
1961 else if (strcmp(*args
, "srst_pulls_trst") == 0)
1962 tmp
|= RESET_SRST_PULLS_TRST
;
1963 else if (strcmp(*args
, "trst_pulls_srst") == 0)
1964 tmp
|= RESET_TRST_PULLS_SRST
;
1965 else if (strcmp(*args
, "combined") == 0)
1966 tmp
|= RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
;
1970 LOG_ERROR("extra reset_config %s spec (%s)",
1971 "combination", *args
);
1972 return ERROR_INVALID_ARGUMENTS
;
1977 /* trst_type (NOP without HAS_TRST) */
1978 m
= RESET_TRST_OPEN_DRAIN
;
1979 if (strcmp(*args
, "trst_open_drain") == 0)
1980 tmp
|= RESET_TRST_OPEN_DRAIN
;
1981 else if (strcmp(*args
, "trst_push_pull") == 0)
1982 /* push/pull from adapter - default */;
1986 LOG_ERROR("extra reset_config %s spec (%s)",
1987 "trst_type", *args
);
1988 return ERROR_INVALID_ARGUMENTS
;
1993 /* srst_type (NOP without HAS_SRST) */
1994 m
|= RESET_SRST_PUSH_PULL
;
1995 if (strcmp(*args
, "srst_push_pull") == 0)
1996 tmp
|= RESET_SRST_PUSH_PULL
;
1997 else if (strcmp(*args
, "srst_open_drain") == 0)
1998 /* open drain from adapter - default */;
2002 LOG_ERROR("extra reset_config %s spec (%s)",
2003 "srst_type", *args
);
2004 return ERROR_INVALID_ARGUMENTS
;
2009 /* caller provided nonsense; fail */
2010 LOG_ERROR("unknown reset_config flag (%s)", *args
);
2011 return ERROR_INVALID_ARGUMENTS
;
2014 /* Remember the bits which were specified (mask)
2015 * and their new values (new_cfg).
2021 /* clear previous values of those bits, save new values */
2022 jtag_reset_config
&= ~mask
;
2023 jtag_reset_config
|= new_cfg
;
2028 static int handle_jtag_nsrst_delay_command(struct command_context_s
*cmd_ctx
,
2029 char *cmd
, char **args
, int argc
)
2032 return ERROR_COMMAND_SYNTAX_ERROR
;
2034 jtag_set_nsrst_delay(strtoul(args
[0], NULL
, 0));
2035 command_print(cmd_ctx
, "jtag_nsrst_delay: %u", jtag_get_nsrst_delay());
2039 static int handle_jtag_ntrst_delay_command(struct command_context_s
*cmd_ctx
,
2040 char *cmd
, char **args
, int argc
)
2043 return ERROR_COMMAND_SYNTAX_ERROR
;
2045 jtag_set_ntrst_delay(strtoul(args
[0], NULL
, 0));
2046 command_print(cmd_ctx
, "jtag_ntrst_delay: %u", jtag_get_ntrst_delay());
2050 static int handle_jtag_speed_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2052 int retval
= ERROR_OK
;
2055 return ERROR_COMMAND_SYNTAX_ERROR
;
2058 LOG_DEBUG("handle jtag speed");
2061 cur_speed
= jtag_speed
= strtoul(args
[0], NULL
, 0);
2063 /* this command can be called during CONFIG,
2064 * in which case jtag isn't initialized */
2066 retval
= jtag
->speed(cur_speed
);
2068 command_print(cmd_ctx
, "jtag_speed: %d", jtag_speed
);
2073 static int handle_jtag_khz_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2076 return ERROR_COMMAND_SYNTAX_ERROR
;
2078 int retval
= ERROR_OK
;
2082 LOG_DEBUG("handle jtag khz");
2084 jtag_set_speed_khz(strtoul(args
[0], NULL
, 0));
2087 LOG_DEBUG("have interface set up");
2089 retval
= jtag
->khz(jtag_get_speed_khz(), &speed_div1
);
2090 if (ERROR_OK
!= retval
)
2092 jtag_set_speed_khz(0);
2095 cur_speed
= jtag_speed
= speed_div1
;
2097 retval
= jtag
->speed(cur_speed
);
2103 cur_speed
= jtag_get_speed_khz();
2106 retval
= jtag
->speed_div(jtag_speed
, &cur_speed
);
2107 if (ERROR_OK
!= retval
)
2112 command_print(cmd_ctx
, "%d kHz", cur_speed
);
2114 command_print(cmd_ctx
, "RCLK - adaptive");
2119 static int handle_jtag_reset_command(struct command_context_s
*cmd_ctx
,
2120 char *cmd
, char **args
, int argc
)
2123 return ERROR_COMMAND_SYNTAX_ERROR
;
2126 if (args
[0][0] == '1')
2128 else if (args
[0][0] == '0')
2131 return ERROR_COMMAND_SYNTAX_ERROR
;
2134 if (args
[1][0] == '1')
2136 else if (args
[1][0] == '0')
2139 return ERROR_COMMAND_SYNTAX_ERROR
;
2141 if (jtag_interface_init(cmd_ctx
) != ERROR_OK
)
2142 return ERROR_JTAG_INIT_FAILED
;
2144 jtag_add_reset(trst
, srst
);
2145 jtag_execute_queue();
2150 static int handle_runtest_command(struct command_context_s
*cmd_ctx
,
2151 char *cmd
, char **args
, int argc
)
2154 return ERROR_COMMAND_SYNTAX_ERROR
;
2156 jtag_add_runtest(strtol(args
[0], NULL
, 0), jtag_get_end_state());
2157 jtag_execute_queue();
2163 * For "irscan" or "drscan" commands, the "end" (really, "next") state
2164 * should be stable ... and *NOT* a shift state, otherwise free-running
2165 * jtag clocks could change the values latched by the update state.
2167 static bool scan_is_safe(tap_state_t state
)
2182 static int handle_irscan_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2185 scan_field_t
*fields
;
2187 tap_state_t endstate
;
2189 if ((argc
< 2) || (argc
% 2))
2191 return ERROR_COMMAND_SYNTAX_ERROR
;
2194 /* optional "-endstate" "statename" at the end of the arguments,
2195 * so that e.g. IRPAUSE can let us load the data register before
2196 * entering RUN/IDLE to execute the instruction we load here.
2198 endstate
= TAP_IDLE
;
2201 /* have at least one pair of numbers. */
2202 /* is last pair the magic text? */
2203 if( 0 == strcmp( "-endstate", args
[ argc
- 2 ] ) ){
2206 cpA
= args
[ argc
-1 ];
2207 for( endstate
= 0 ; endstate
< TAP_NUM_STATES
; endstate
++ ){
2208 cpS
= tap_state_name( endstate
);
2209 if( 0 == strcmp( cpA
, cpS
) ){
2213 if( endstate
>= TAP_NUM_STATES
){
2214 return ERROR_COMMAND_SYNTAX_ERROR
;
2216 if (!scan_is_safe(endstate
))
2217 LOG_WARNING("irscan with unsafe "
2218 "endstate \"%s\"", cpA
);
2219 /* found - remove the last 2 args */
2225 int num_fields
= argc
/ 2;
2227 fields
= malloc(sizeof(scan_field_t
) * num_fields
);
2229 for (i
= 0; i
< num_fields
; i
++)
2231 tap
= jtag_tap_by_string( args
[i
*2] );
2234 command_print( cmd_ctx
, "Tap: %s unknown", args
[i
*2] );
2237 int field_size
= tap
->ir_length
;
2238 fields
[i
].tap
= tap
;
2239 fields
[i
].num_bits
= field_size
;
2240 fields
[i
].out_value
= malloc(CEIL(field_size
, 8));
2241 buf_set_u32(fields
[i
].out_value
, 0, field_size
, strtoul(args
[i
*2+1], NULL
, 0));
2242 fields
[i
].in_value
= NULL
;
2245 /* did we have an endstate? */
2246 jtag_add_ir_scan(num_fields
, fields
, endstate
);
2248 int retval
=jtag_execute_queue();
2250 for (i
= 0; i
< num_fields
; i
++)
2251 free(fields
[i
].out_value
);
2258 static int Jim_Command_drscan(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *args
)
2261 scan_field_t
*fields
;
2263 int field_count
= 0;
2266 tap_state_t endstate
;
2269 * args[2] = num_bits
2270 * args[3] = hex string
2271 * ... repeat num bits and hex string ...
2274 * args[N-2] = "-endstate"
2275 * args[N-1] = statename
2277 if ((argc
< 4) || ((argc
% 2)!=0))
2279 Jim_WrongNumArgs(interp
, 1, args
, "wrong arguments");
2283 endstate
= TAP_IDLE
;
2285 /* validate arguments as numbers */
2287 for (i
= 2; i
< argc
; i
+=2)
2292 e
= Jim_GetLong(interp
, args
[i
], &bits
);
2293 /* If valid - try next arg */
2298 /* Not valid.. are we at the end? */
2299 if ( ((i
+2) != argc
) ){
2300 /* nope, then error */
2304 /* it could be: "-endstate FOO"
2305 * e.g. DRPAUSE so we can issue more instructions
2306 * before entering RUN/IDLE and executing them.
2309 /* get arg as a string. */
2310 cp
= Jim_GetString( args
[i
], NULL
);
2311 /* is it the magic? */
2312 if( 0 == strcmp( "-endstate", cp
) ){
2313 /* is the statename valid? */
2314 cp
= Jim_GetString( args
[i
+1], NULL
);
2316 /* see if it is a valid state name */
2317 endstate
= tap_state_by_name(cp
);
2319 /* update the error message */
2320 Jim_SetResult_sprintf(interp
,"endstate: %s invalid", cp
);
2322 if (!scan_is_safe(endstate
))
2323 LOG_WARNING("drscan with unsafe "
2324 "endstate \"%s\"", cp
);
2326 /* valid - so clear the error */
2328 /* and remove the last 2 args */
2333 /* Still an error? */
2335 return e
; /* too bad */
2337 } /* validate args */
2339 tap
= jtag_tap_by_jim_obj( interp
, args
[1] );
2344 num_fields
=(argc
-2)/2;
2345 fields
= malloc(sizeof(scan_field_t
) * num_fields
);
2346 for (i
= 2; i
< argc
; i
+=2)
2352 Jim_GetLong(interp
, args
[i
], &bits
);
2353 str
= Jim_GetString(args
[i
+1], &len
);
2355 fields
[field_count
].tap
= tap
;
2356 fields
[field_count
].num_bits
= bits
;
2357 fields
[field_count
].out_value
= malloc(CEIL(bits
, 8));
2358 str_to_buf(str
, len
, fields
[field_count
].out_value
, bits
, 0);
2359 fields
[field_count
].in_value
= fields
[field_count
].out_value
;
2363 jtag_add_dr_scan(num_fields
, fields
, endstate
);
2365 retval
= jtag_execute_queue();
2366 if (retval
!= ERROR_OK
)
2368 Jim_SetResultString(interp
, "drscan: jtag execute failed",-1);
2373 Jim_Obj
*list
= Jim_NewListObj(interp
, NULL
, 0);
2374 for (i
= 2; i
< argc
; i
+=2)
2379 Jim_GetLong(interp
, args
[i
], &bits
);
2380 str
= buf_to_str(fields
[field_count
].in_value
, bits
, 16);
2381 free(fields
[field_count
].out_value
);
2383 Jim_ListAppendElement(interp
, list
, Jim_NewStringObj(interp
, str
, strlen(str
)));
2388 Jim_SetResult(interp
, list
);
2396 static int Jim_Command_flush_count(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *args
)
2398 Jim_SetResult(interp
, Jim_NewIntObj(interp
, jtag_get_flush_queue_count()));
2404 static int handle_verify_ircapture_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2408 if (strcmp(args
[0], "enable") == 0)
2410 jtag_verify_capture_ir
= 1;
2412 else if (strcmp(args
[0], "disable") == 0)
2414 jtag_verify_capture_ir
= 0;
2417 return ERROR_COMMAND_SYNTAX_ERROR
;
2419 } else if (argc
!= 0)
2421 return ERROR_COMMAND_SYNTAX_ERROR
;
2424 command_print(cmd_ctx
, "verify Capture-IR is %s", (jtag_verify_capture_ir
) ? "enabled": "disabled");
2429 void jtag_set_verify(bool enable
)
2431 jtag_verify
= enable
;
2434 bool jtag_will_verify()
2439 static int handle_verify_jtag_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2442 return ERROR_COMMAND_SYNTAX_ERROR
;
2446 if (strcmp(args
[0], "enable") == 0)
2447 jtag_set_verify(true);
2448 else if (strcmp(args
[0], "disable") == 0)
2449 jtag_set_verify(false);
2451 return ERROR_COMMAND_SYNTAX_ERROR
;
2454 const char *status
= jtag_will_verify() ? "enabled": "disabled";
2455 command_print(cmd_ctx
, "verify jtag capture is %s", status
);
2461 int jtag_power_dropout(int *dropout
)
2463 return jtag
->power_dropout(dropout
);
2466 int jtag_srst_asserted(int *srst_asserted
)
2468 return jtag
->srst_asserted(srst_asserted
);
2471 void jtag_tap_handle_event( jtag_tap_t
* tap
, enum jtag_tap_event e
)
2473 jtag_tap_event_action_t
* jteap
;
2476 jteap
= tap
->event_action
;
2480 if (jteap
->event
== e
) {
2482 LOG_DEBUG( "JTAG tap: %s event: %d (%s) action: %s\n",
2485 Jim_Nvp_value2name_simple(nvp_jtag_tap_event
, e
)->name
,
2486 Jim_GetString(jteap
->body
, NULL
) );
2487 if (Jim_EvalObj(interp
, jteap
->body
) != JIM_OK
) {
2488 Jim_PrintErrorMessage(interp
);
2492 jteap
= jteap
->next
;
2496 LOG_DEBUG( "event %d %s - no action",
2498 Jim_Nvp_value2name_simple( nvp_jtag_tap_event
, e
)->name
);
2502 static int handle_tms_sequence_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2505 return ERROR_COMMAND_SYNTAX_ERROR
;
2510 if (strcmp(args
[0], "short") == 0)
2511 use_new_table
= true;
2512 else if (strcmp(args
[0], "long") == 0)
2513 use_new_table
= false;
2515 return ERROR_COMMAND_SYNTAX_ERROR
;
2517 tap_use_new_tms_table(use_new_table
);
2520 command_print(cmd_ctx
, "tms sequence is %s",
2521 tap_uses_new_tms_table() ? "short": "long");
2527 * Moves from the current state to the goal \a state. This needs
2528 * to be handled according to the xsvf spec, see the XSTATE command
2531 * From the XSVF spec, pertaining to XSTATE:
2533 * For special states known as stable states (Test-Logic-Reset,
2534 * Run-Test/Idle, Pause-DR, Pause- IR), an XSVF interpreter follows
2535 * predefined TAP state paths when the starting state is a stable state
2536 * and when the XSTATE specifies a new stable state. See the STATE
2537 * command in the [Ref 5] for the TAP state paths between stable
2540 * For non-stable states, XSTATE should specify a state that is only one
2541 * TAP state transition distance from the current TAP state to avoid
2542 * undefined TAP state paths. A sequence of multiple XSTATE commands can
2543 * be issued to transition the TAP through a specific state path.
2545 * @note Unless @a tms_bits holds a path that agrees with [Ref 5] in *
2546 * above spec, then this code is not fully conformant to the xsvf spec.
2547 * This puts a burden on tap_get_tms_path() function from the xsvf spec.
2548 * If in doubt, you should confirm that that burden is being met.
2550 * Otherwise, state must be immediately reachable in one clock cycle,
2551 * and does not need to be a stable state.
2553 int jtag_add_statemove(tap_state_t goal_state
)
2555 tap_state_t cur_state
= cmd_queue_cur_state
;
2557 LOG_DEBUG( "cur_state=%s goal_state=%s",
2558 tap_state_name(cur_state
),
2559 tap_state_name(goal_state
) );
2562 if (goal_state
==cur_state
)
2563 ; /* nothing to do */
2564 else if( goal_state
==TAP_RESET
)
2568 else if( tap_is_state_stable(cur_state
) && tap_is_state_stable(goal_state
) )
2570 unsigned tms_bits
= tap_get_tms_path(cur_state
, goal_state
);
2571 unsigned tms_count
= tap_get_tms_path_len(cur_state
, goal_state
);
2572 tap_state_t moves
[8];
2573 assert(tms_count
< DIM(moves
));
2575 for (unsigned i
= 0; i
< tms_count
; i
++, tms_bits
>>= 1)
2577 bool bit
= tms_bits
& 1;
2579 cur_state
= tap_state_transition(cur_state
, bit
);
2580 moves
[i
] = cur_state
;
2583 jtag_add_pathmove(tms_count
, moves
);
2585 else if( tap_state_transition(cur_state
, true) == goal_state
2586 || tap_state_transition(cur_state
, false) == goal_state
)
2588 jtag_add_pathmove(1, &goal_state
);
2597 void jtag_set_nsrst_delay(unsigned delay
)
2599 jtag_nsrst_delay
= delay
;
2601 unsigned jtag_get_nsrst_delay(void)
2603 return jtag_nsrst_delay
;
2605 void jtag_set_ntrst_delay(unsigned delay
)
2607 jtag_ntrst_delay
= delay
;
2609 unsigned jtag_get_ntrst_delay(void)
2611 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)