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 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22 ***************************************************************************/
27 #include "replacements.h"
38 /* note that this is not marked as static as it must be available from outside jtag.c for those
39 that implement the jtag_xxx() minidriver layer
41 int jtag_error
=ERROR_OK
;
44 char* tap_state_strings
[16] =
47 "sds", "cd", "sd", "e1d", "pd", "e2d", "ud",
49 "sis", "ci", "si", "e1i", "pi", "e2i", "ui"
52 typedef struct cmd_queue_page_s
56 struct cmd_queue_page_s
*next
;
59 #define CMD_QUEUE_PAGE_SIZE (1024 * 1024)
60 static cmd_queue_page_t
*cmd_queue_pages
= NULL
;
62 /* tap_move[i][j]: tap movement command to go from state i to state j
70 * SD->SD and SI->SI have to be caught in interface specific code
74 /* TLR RTI SD PD SI PI */
75 {0x7f, 0x00, 0x17, 0x0a, 0x1b, 0x16}, /* TLR */
76 {0x7f, 0x00, 0x25, 0x05, 0x2b, 0x0b}, /* RTI */
77 {0x7f, 0x31, 0x00, 0x01, 0x0f, 0x2f}, /* SD */
78 {0x7f, 0x30, 0x20, 0x17, 0x1e, 0x2f}, /* PD */
79 {0x7f, 0x31, 0x07, 0x17, 0x00, 0x01}, /* SI */
80 {0x7f, 0x30, 0x1c, 0x17, 0x20, 0x2f} /* PI */
83 int tap_move_map
[16] = {
84 0, -1, -1, 2, -1, 3, -1, -1,
85 1, -1, -1, 4, -1, 5, -1, -1
88 tap_transition_t tap_transitions
[16] =
90 {TAP_TLR
, TAP_RTI
}, /* TLR */
91 {TAP_SIS
, TAP_CD
}, /* SDS */
92 {TAP_E1D
, TAP_SD
}, /* CD */
93 {TAP_E1D
, TAP_SD
}, /* SD */
94 {TAP_UD
, TAP_PD
}, /* E1D */
95 {TAP_E2D
, TAP_PD
}, /* PD */
96 {TAP_UD
, TAP_SD
}, /* E2D */
97 {TAP_SDS
, TAP_RTI
}, /* UD */
98 {TAP_SDS
, TAP_RTI
}, /* RTI */
99 {TAP_TLR
, TAP_CI
}, /* SIS */
100 {TAP_E1I
, TAP_SI
}, /* CI */
101 {TAP_E1I
, TAP_SI
}, /* SI */
102 {TAP_UI
, TAP_PI
}, /* E1I */
103 {TAP_E2I
, TAP_PI
}, /* PI */
104 {TAP_UI
, TAP_SI
}, /* E2I */
105 {TAP_SDS
, TAP_RTI
} /* UI */
108 char* jtag_event_strings
[] =
110 "JTAG controller reset (TLR or TRST)"
113 /* kludge!!!! these are just global variables that the
114 * interface use internally. They really belong
115 * inside the drivers, but we don't want to break
116 * linking the drivers!!!!
118 enum tap_state end_state
= TAP_TLR
;
119 enum tap_state cur_state
= TAP_TLR
;
123 jtag_command_t
*jtag_command_queue
= NULL
;
124 jtag_command_t
**last_comand_pointer
= &jtag_command_queue
;
125 static jtag_tap_t
*jtag_all_taps
= NULL
;
127 enum reset_types jtag_reset_config
= RESET_NONE
;
128 enum tap_state cmd_queue_end_state
= TAP_TLR
;
129 enum tap_state cmd_queue_cur_state
= TAP_TLR
;
131 int jtag_verify_capture_ir
= 1;
133 /* how long the OpenOCD should wait before attempting JTAG communication after reset lines deasserted (in ms) */
134 int jtag_nsrst_delay
= 0; /* default to no nSRST delay */
135 int jtag_ntrst_delay
= 0; /* default to no nTRST delay */
137 /* maximum number of JTAG devices expected in the chain
139 #define JTAG_MAX_CHAIN_SIZE 20
141 /* callbacks to inform high-level handlers about JTAG state changes */
142 jtag_event_callback_t
*jtag_event_callbacks
;
145 static int speed_khz
= 0;
146 /* flag if the kHz speed was defined */
147 static int hasKHz
= 0;
149 /* jtag interfaces (parport, FTDI-USB, TI-USB, ...)
152 #if BUILD_ECOSBOARD == 1
153 extern jtag_interface_t zy1000_interface
;
156 #if BUILD_PARPORT == 1
157 extern jtag_interface_t parport_interface
;
161 extern jtag_interface_t dummy_interface
;
164 #if BUILD_FT2232_FTD2XX == 1
165 extern jtag_interface_t ft2232_interface
;
168 #if BUILD_FT2232_LIBFTDI == 1
169 extern jtag_interface_t ft2232_interface
;
172 #if BUILD_AMTJTAGACCEL == 1
173 extern jtag_interface_t amt_jtagaccel_interface
;
176 #if BUILD_EP93XX == 1
177 extern jtag_interface_t ep93xx_interface
;
180 #if BUILD_AT91RM9200 == 1
181 extern jtag_interface_t at91rm9200_interface
;
184 #if BUILD_GW16012 == 1
185 extern jtag_interface_t gw16012_interface
;
188 #if BUILD_PRESTO_LIBFTDI == 1 || BUILD_PRESTO_FTD2XX == 1
189 extern jtag_interface_t presto_interface
;
192 #if BUILD_USBPROG == 1
193 extern jtag_interface_t usbprog_interface
;
197 extern jtag_interface_t jlink_interface
;
200 jtag_interface_t
*jtag_interfaces
[] = {
201 #if BUILD_ECOSBOARD == 1
204 #if BUILD_PARPORT == 1
210 #if BUILD_FT2232_FTD2XX == 1
213 #if BUILD_FT2232_LIBFTDI == 1
216 #if BUILD_AMTJTAGACCEL == 1
217 &amt_jtagaccel_interface
,
219 #if BUILD_EP93XX == 1
222 #if BUILD_AT91RM9200 == 1
223 &at91rm9200_interface
,
225 #if BUILD_GW16012 == 1
228 #if BUILD_PRESTO_LIBFTDI == 1 || BUILD_PRESTO_FTD2XX == 1
231 #if BUILD_USBPROG == 1
240 jtag_interface_t
*jtag
= NULL
;
243 jtag_interface_t
*jtag_interface
= NULL
;
248 /* forward declarations */
249 void jtag_add_pathmove(int num_states
, enum tap_state
*path
);
250 void jtag_add_runtest(int num_cycles
, enum tap_state endstate
);
251 void jtag_add_end_state(enum tap_state endstate
);
252 void jtag_add_sleep(u32 us
);
253 int jtag_execute_queue(void);
257 int handle_interface_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
258 int handle_jtag_speed_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
259 int handle_jtag_khz_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
260 int handle_jtag_device_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
261 int handle_reset_config_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
262 int handle_jtag_nsrst_delay_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
263 int handle_jtag_ntrst_delay_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
265 int handle_scan_chain_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
267 int handle_endstate_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
268 int handle_jtag_reset_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
269 int handle_runtest_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
270 int handle_irscan_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
271 int Jim_Command_drscan(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
);
273 int handle_verify_ircapture_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
276 jtag_tap_t
*jtag_AllTaps(void)
278 return jtag_all_taps
;
282 jtag_NumTotalTaps(void)
297 jtag_NumEnabledTaps(void)
314 jtag_NextEnabledTap( jtag_tap_t
*p
)
317 // start at the head of list
320 // start *after* this one
333 jtag_tap_t
*jtag_TapByString( const char *s
)
341 if( 0 == strcmp( t
->dotted_name
, s
) ){
347 // backup plan is by number
349 /* ok - is "s" a number? */
351 n
= strtol( s
, &cp
, 0 );
352 if( (s
!= cp
) && (*cp
== 0) ){
354 t
= jtag_TapByAbsPosition(n
);
361 jtag_TapByJimObj( Jim_Interp
*interp
, Jim_Obj
*o
)
366 cp
= Jim_GetString( o
, NULL
);
371 t
= jtag_TapByString( cp
);
374 Jim_SetResult_sprintf(interp
,"Tap: %s is unknown", cp
);
379 /* returns a pointer to the n-th device in the scan chain */
381 jtag_TapByAbsPosition( int n
)
389 while( t
&& (n
> 0)) {
397 int jtag_register_event_callback(int (*callback
)(enum jtag_event event
, void *priv
), void *priv
)
399 jtag_event_callback_t
**callbacks_p
= &jtag_event_callbacks
;
401 if (callback
== NULL
)
403 return ERROR_INVALID_ARGUMENTS
;
408 while ((*callbacks_p
)->next
)
409 callbacks_p
= &((*callbacks_p
)->next
);
410 callbacks_p
= &((*callbacks_p
)->next
);
413 (*callbacks_p
) = malloc(sizeof(jtag_event_callback_t
));
414 (*callbacks_p
)->callback
= callback
;
415 (*callbacks_p
)->priv
= priv
;
416 (*callbacks_p
)->next
= NULL
;
421 int jtag_unregister_event_callback(int (*callback
)(enum jtag_event event
, void *priv
))
423 jtag_event_callback_t
**callbacks_p
= &jtag_event_callbacks
;
425 if (callback
== NULL
)
427 return ERROR_INVALID_ARGUMENTS
;
432 jtag_event_callback_t
**next
= &((*callbacks_p
)->next
);
433 if ((*callbacks_p
)->callback
== callback
)
436 *callbacks_p
= *next
;
444 int jtag_call_event_callbacks(enum jtag_event event
)
446 jtag_event_callback_t
*callback
= jtag_event_callbacks
;
448 LOG_DEBUG("jtag event: %s", jtag_event_strings
[event
]);
452 callback
->callback(event
, callback
->priv
);
453 callback
= callback
->next
;
459 /* returns a pointer to the pointer of the last command in queue
460 * this may be a pointer to the root pointer (jtag_command_queue)
461 * or to the next member of the last but one command
463 jtag_command_t
** jtag_get_last_command_p(void)
465 /* jtag_command_t *cmd = jtag_command_queue;
471 return &jtag_command_queue;
475 return last_comand_pointer
;
479 void* cmd_queue_alloc(size_t size
)
481 cmd_queue_page_t
**p_page
= &cmd_queue_pages
;
487 while ((*p_page
)->next
)
488 p_page
= &((*p_page
)->next
);
489 if (CMD_QUEUE_PAGE_SIZE
- (*p_page
)->used
< size
)
490 p_page
= &((*p_page
)->next
);
495 *p_page
= malloc(sizeof(cmd_queue_page_t
));
497 (*p_page
)->address
= malloc(CMD_QUEUE_PAGE_SIZE
);
498 (*p_page
)->next
= NULL
;
501 offset
= (*p_page
)->used
;
502 (*p_page
)->used
+= size
;
504 t
=(u8
*)((*p_page
)->address
);
508 void cmd_queue_free(void)
510 cmd_queue_page_t
*page
= cmd_queue_pages
;
514 cmd_queue_page_t
*last
= page
;
520 cmd_queue_pages
= NULL
;
523 static void jtag_prelude1(void)
527 LOG_WARNING("JTAG command queued, while TRST is low (TAP in reset)");
528 jtag_error
=ERROR_JTAG_TRST_ASSERTED
;
532 if (cmd_queue_end_state
== TAP_TLR
)
533 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
536 static void jtag_prelude(enum tap_state state
)
541 jtag_add_end_state(state
);
543 cmd_queue_cur_state
= cmd_queue_end_state
;
546 void jtag_add_ir_scan(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
552 retval
=interface_jtag_add_ir_scan(num_fields
, fields
, cmd_queue_end_state
);
553 if (retval
!=ERROR_OK
)
557 int MINIDRIVER(interface_jtag_add_ir_scan
)(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
559 jtag_command_t
**last_cmd
;
567 last_cmd
= jtag_get_last_command_p();
569 /* allocate memory for a new list member */
570 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
571 (*last_cmd
)->next
= NULL
;
572 last_comand_pointer
= &((*last_cmd
)->next
);
573 (*last_cmd
)->type
= JTAG_SCAN
;
575 /* allocate memory for ir scan command */
576 (*last_cmd
)->cmd
.scan
= cmd_queue_alloc(sizeof(scan_command_t
));
577 (*last_cmd
)->cmd
.scan
->ir_scan
= 1;
578 x
= jtag_NumEnabledTaps();
579 (*last_cmd
)->cmd
.scan
->num_fields
= x
; /* one field per device */
580 (*last_cmd
)->cmd
.scan
->fields
= cmd_queue_alloc(x
* sizeof(scan_field_t
));
581 (*last_cmd
)->cmd
.scan
->end_state
= state
;
588 // do this here so it is not forgotten
589 tap
= jtag_NextEnabledTap(tap
);
594 scan_size
= tap
->ir_length
;
595 (*last_cmd
)->cmd
.scan
->fields
[nth_tap
].tap
= tap
;
596 (*last_cmd
)->cmd
.scan
->fields
[nth_tap
].num_bits
= scan_size
;
597 (*last_cmd
)->cmd
.scan
->fields
[nth_tap
].in_value
= NULL
;
598 (*last_cmd
)->cmd
.scan
->fields
[nth_tap
].in_handler
= NULL
; /* disable verification by default */
600 /* search the list */
601 for (j
= 0; j
< num_fields
; j
++)
603 if (tap
== fields
[j
].tap
)
606 (*last_cmd
)->cmd
.scan
->fields
[nth_tap
].out_value
= buf_cpy(fields
[j
].out_value
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
607 (*last_cmd
)->cmd
.scan
->fields
[nth_tap
].out_mask
= buf_cpy(fields
[j
].out_mask
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
609 if (jtag_verify_capture_ir
)
611 if (fields
[j
].in_handler
==NULL
)
613 jtag_set_check_value((*last_cmd
)->cmd
.scan
->fields
+nth_tap
, tap
->expected
, tap
->expected_mask
, NULL
);
616 (*last_cmd
)->cmd
.scan
->fields
[nth_tap
].in_handler
= fields
[j
].in_handler
;
617 (*last_cmd
)->cmd
.scan
->fields
[nth_tap
].in_handler_priv
= fields
[j
].in_handler_priv
;
618 (*last_cmd
)->cmd
.scan
->fields
[nth_tap
].in_check_value
= tap
->expected
;
619 (*last_cmd
)->cmd
.scan
->fields
[nth_tap
].in_check_mask
= tap
->expected_mask
;
630 /* if a tap isn't listed, set it to BYPASS */
631 (*last_cmd
)->cmd
.scan
->fields
[nth_tap
].out_value
= buf_set_ones(cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
632 (*last_cmd
)->cmd
.scan
->fields
[nth_tap
].out_mask
= NULL
;
637 /* update device information */
638 buf_cpy((*last_cmd
)->cmd
.scan
->fields
[nth_tap
].out_value
, tap
->cur_instr
, scan_size
);
644 void jtag_add_plain_ir_scan(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
650 retval
=interface_jtag_add_plain_ir_scan(num_fields
, fields
, cmd_queue_end_state
);
651 if (retval
!=ERROR_OK
)
655 int MINIDRIVER(interface_jtag_add_plain_ir_scan
)(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
658 jtag_command_t
**last_cmd
;
660 last_cmd
= jtag_get_last_command_p();
662 /* allocate memory for a new list member */
663 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
664 (*last_cmd
)->next
= NULL
;
665 last_comand_pointer
= &((*last_cmd
)->next
);
666 (*last_cmd
)->type
= JTAG_SCAN
;
668 /* allocate memory for ir scan command */
669 (*last_cmd
)->cmd
.scan
= cmd_queue_alloc(sizeof(scan_command_t
));
670 (*last_cmd
)->cmd
.scan
->ir_scan
= 1;
671 (*last_cmd
)->cmd
.scan
->num_fields
= num_fields
;
672 (*last_cmd
)->cmd
.scan
->fields
= cmd_queue_alloc(num_fields
* sizeof(scan_field_t
));
673 (*last_cmd
)->cmd
.scan
->end_state
= state
;
675 for( i
= 0 ; i
< num_fields
; i
++ ){
676 int num_bits
= fields
[i
].num_bits
;
677 int num_bytes
= CEIL(fields
[i
].num_bits
, 8);
678 (*last_cmd
)->cmd
.scan
->fields
[i
].tap
= fields
[i
].tap
;
679 (*last_cmd
)->cmd
.scan
->fields
[i
].num_bits
= num_bits
;
680 (*last_cmd
)->cmd
.scan
->fields
[i
].out_value
= buf_cpy(fields
[i
].out_value
, cmd_queue_alloc(num_bytes
), num_bits
);
681 (*last_cmd
)->cmd
.scan
->fields
[i
].out_mask
= buf_cpy(fields
[i
].out_mask
, cmd_queue_alloc(num_bytes
), num_bits
);
682 (*last_cmd
)->cmd
.scan
->fields
[i
].in_value
= fields
[i
].in_value
;
683 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_value
= fields
[i
].in_check_value
;
684 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_mask
= fields
[i
].in_check_mask
;
685 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler
= NULL
;
686 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler_priv
= NULL
;
691 void jtag_add_dr_scan(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
697 retval
=interface_jtag_add_dr_scan(num_fields
, fields
, cmd_queue_end_state
);
698 if (retval
!=ERROR_OK
)
702 int MINIDRIVER(interface_jtag_add_dr_scan
)(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
706 int bypass_devices
= 0;
710 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
713 /* count devices in bypass */
717 tap
= jtag_NextEnabledTap(tap
);
726 /* allocate memory for a new list member */
727 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
728 last_comand_pointer
= &((*last_cmd
)->next
);
729 (*last_cmd
)->next
= NULL
;
730 (*last_cmd
)->type
= JTAG_SCAN
;
732 /* allocate memory for dr scan command */
733 (*last_cmd
)->cmd
.scan
= cmd_queue_alloc(sizeof(scan_command_t
));
734 (*last_cmd
)->cmd
.scan
->ir_scan
= 0;
735 (*last_cmd
)->cmd
.scan
->num_fields
= num_fields
+ bypass_devices
;
736 (*last_cmd
)->cmd
.scan
->fields
= cmd_queue_alloc((num_fields
+ bypass_devices
) * sizeof(scan_field_t
));
737 (*last_cmd
)->cmd
.scan
->end_state
= state
;
743 tap
= jtag_NextEnabledTap(tap
);
748 (*last_cmd
)->cmd
.scan
->fields
[field_count
].tap
= tap
;
750 for (j
= 0; j
< num_fields
; j
++)
752 if (tap
== fields
[j
].tap
)
755 scan_size
= fields
[j
].num_bits
;
756 (*last_cmd
)->cmd
.scan
->fields
[field_count
].num_bits
= scan_size
;
757 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_value
= buf_cpy(fields
[j
].out_value
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
758 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_mask
= buf_cpy(fields
[j
].out_mask
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
759 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_value
= fields
[j
].in_value
;
760 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_check_value
= fields
[j
].in_check_value
;
761 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_check_mask
= fields
[j
].in_check_mask
;
762 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_handler
= fields
[j
].in_handler
;
763 (*last_cmd
)->cmd
.scan
->fields
[field_count
++].in_handler_priv
= fields
[j
].in_handler_priv
;
768 #ifdef _DEBUG_JTAG_IO_
769 /* if a device isn't listed, the BYPASS register should be selected */
772 LOG_ERROR("BUG: no scan data for a device not in BYPASS");
776 /* program the scan field to 1 bit length, and ignore it's value */
777 (*last_cmd
)->cmd
.scan
->fields
[field_count
].num_bits
= 1;
778 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_value
= NULL
;
779 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_mask
= NULL
;
780 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_value
= NULL
;
781 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_check_value
= NULL
;
782 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_check_mask
= NULL
;
783 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_handler
= NULL
;
784 (*last_cmd
)->cmd
.scan
->fields
[field_count
++].in_handler_priv
= NULL
;
788 #ifdef _DEBUG_JTAG_IO_
789 /* if a device is listed, the BYPASS register must not be selected */
792 LOG_ERROR("BUG: scan data for a device in BYPASS");
801 void MINIDRIVER(interface_jtag_add_dr_out
)(jtag_tap_t
*target_tap
,
805 enum tap_state end_state
)
810 int bypass_devices
= 0;
812 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
815 /* count devices in bypass */
819 tap
= jtag_NextEnabledTap(tap
);
828 /* allocate memory for a new list member */
829 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
830 last_comand_pointer
= &((*last_cmd
)->next
);
831 (*last_cmd
)->next
= NULL
;
832 (*last_cmd
)->type
= JTAG_SCAN
;
834 /* allocate memory for dr scan command */
835 (*last_cmd
)->cmd
.scan
= cmd_queue_alloc(sizeof(scan_command_t
));
836 (*last_cmd
)->cmd
.scan
->ir_scan
= 0;
837 (*last_cmd
)->cmd
.scan
->num_fields
= num_fields
+ bypass_devices
;
838 (*last_cmd
)->cmd
.scan
->fields
= cmd_queue_alloc((num_fields
+ bypass_devices
) * sizeof(scan_field_t
));
839 (*last_cmd
)->cmd
.scan
->end_state
= end_state
;
844 tap
= jtag_NextEnabledTap(tap
);
849 (*last_cmd
)->cmd
.scan
->fields
[field_count
].tap
= tap
;
851 if (tap
== target_tap
)
854 #ifdef _DEBUG_JTAG_IO_
855 /* if a device is listed, the BYPASS register must not be selected */
858 LOG_ERROR("BUG: scan data for a device in BYPASS");
862 for (j
= 0; j
< num_fields
; j
++)
865 scan_size
= num_bits
[j
];
866 buf_set_u32(out_value
, 0, scan_size
, value
[j
]);
867 (*last_cmd
)->cmd
.scan
->fields
[field_count
].num_bits
= scan_size
;
868 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_value
= buf_cpy(out_value
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
869 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_mask
= NULL
;
870 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_value
= NULL
;
871 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_check_value
= NULL
;
872 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_check_mask
= NULL
;
873 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_handler
= NULL
;
874 (*last_cmd
)->cmd
.scan
->fields
[field_count
++].in_handler_priv
= NULL
;
878 #ifdef _DEBUG_JTAG_IO_
879 /* if a device isn't listed, the BYPASS register should be selected */
882 LOG_ERROR("BUG: no scan data for a device not in BYPASS");
886 /* program the scan field to 1 bit length, and ignore it's value */
887 (*last_cmd
)->cmd
.scan
->fields
[field_count
].num_bits
= 1;
888 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_value
= NULL
;
889 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_mask
= NULL
;
890 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_value
= NULL
;
891 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_check_value
= NULL
;
892 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_check_mask
= NULL
;
893 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_handler
= NULL
;
894 (*last_cmd
)->cmd
.scan
->fields
[field_count
++].in_handler_priv
= NULL
;
899 void jtag_add_plain_dr_scan(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
905 retval
=interface_jtag_add_plain_dr_scan(num_fields
, fields
, cmd_queue_end_state
);
906 if (retval
!=ERROR_OK
)
910 int MINIDRIVER(interface_jtag_add_plain_dr_scan
)(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
913 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
915 /* allocate memory for a new list member */
916 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
917 last_comand_pointer
= &((*last_cmd
)->next
);
918 (*last_cmd
)->next
= NULL
;
919 (*last_cmd
)->type
= JTAG_SCAN
;
921 /* allocate memory for scan command */
922 (*last_cmd
)->cmd
.scan
= cmd_queue_alloc(sizeof(scan_command_t
));
923 (*last_cmd
)->cmd
.scan
->ir_scan
= 0;
924 (*last_cmd
)->cmd
.scan
->num_fields
= num_fields
;
925 (*last_cmd
)->cmd
.scan
->fields
= cmd_queue_alloc(num_fields
* sizeof(scan_field_t
));
926 (*last_cmd
)->cmd
.scan
->end_state
= state
;
928 for (i
= 0; i
< num_fields
; i
++)
930 int num_bits
= fields
[i
].num_bits
;
931 int num_bytes
= CEIL(fields
[i
].num_bits
, 8);
932 (*last_cmd
)->cmd
.scan
->fields
[i
].tap
= fields
[i
].tap
;
933 (*last_cmd
)->cmd
.scan
->fields
[i
].num_bits
= num_bits
;
934 (*last_cmd
)->cmd
.scan
->fields
[i
].out_value
= buf_cpy(fields
[i
].out_value
, cmd_queue_alloc(num_bytes
), num_bits
);
935 (*last_cmd
)->cmd
.scan
->fields
[i
].out_mask
= buf_cpy(fields
[i
].out_mask
, cmd_queue_alloc(num_bytes
), num_bits
);
936 (*last_cmd
)->cmd
.scan
->fields
[i
].in_value
= fields
[i
].in_value
;
937 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_value
= fields
[i
].in_check_value
;
938 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_mask
= fields
[i
].in_check_mask
;
939 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler
= fields
[i
].in_handler
;
940 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler_priv
= fields
[i
].in_handler_priv
;
946 void jtag_add_tlr(void)
948 jtag_prelude(TAP_TLR
);
951 retval
=interface_jtag_add_tlr();
952 if (retval
!=ERROR_OK
)
956 int MINIDRIVER(interface_jtag_add_tlr
)()
958 enum tap_state state
= TAP_TLR
;
959 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
961 /* allocate memory for a new list member */
962 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
963 last_comand_pointer
= &((*last_cmd
)->next
);
964 (*last_cmd
)->next
= NULL
;
965 (*last_cmd
)->type
= JTAG_STATEMOVE
;
967 (*last_cmd
)->cmd
.statemove
= cmd_queue_alloc(sizeof(statemove_command_t
));
968 (*last_cmd
)->cmd
.statemove
->end_state
= state
;
974 void jtag_add_pathmove(int num_states
, enum tap_state
*path
)
976 enum tap_state cur_state
=cmd_queue_cur_state
;
980 /* the last state has to be a stable state */
981 if (tap_move_map
[path
[num_states
- 1]] == -1)
983 LOG_ERROR("BUG: TAP path doesn't finish in a stable state");
987 for (i
=0; i
<num_states
; i
++)
989 if (path
[i
] == TAP_TLR
)
991 LOG_ERROR("BUG: TAP_TLR is not a valid state for pathmove sequences");
994 if ((tap_transitions
[cur_state
].low
!= path
[i
])&&
995 (tap_transitions
[cur_state
].high
!= path
[i
]))
997 LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_strings
[cur_state
], tap_state_strings
[path
[i
]]);
1000 cur_state
= path
[i
];
1006 retval
=interface_jtag_add_pathmove(num_states
, path
);
1007 cmd_queue_cur_state
= path
[num_states
- 1];
1008 if (retval
!=ERROR_OK
)
1012 int MINIDRIVER(interface_jtag_add_pathmove
)(int num_states
, enum tap_state
*path
)
1014 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
1017 /* allocate memory for a new list member */
1018 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
1019 last_comand_pointer
= &((*last_cmd
)->next
);
1020 (*last_cmd
)->next
= NULL
;
1021 (*last_cmd
)->type
= JTAG_PATHMOVE
;
1023 (*last_cmd
)->cmd
.pathmove
= cmd_queue_alloc(sizeof(pathmove_command_t
));
1024 (*last_cmd
)->cmd
.pathmove
->num_states
= num_states
;
1025 (*last_cmd
)->cmd
.pathmove
->path
= cmd_queue_alloc(sizeof(enum tap_state
) * num_states
);
1027 for (i
= 0; i
< num_states
; i
++)
1028 (*last_cmd
)->cmd
.pathmove
->path
[i
] = path
[i
];
1033 int MINIDRIVER(interface_jtag_add_runtest
)(int num_cycles
, enum tap_state state
)
1035 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
1037 /* allocate memory for a new list member */
1038 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
1039 (*last_cmd
)->next
= NULL
;
1040 last_comand_pointer
= &((*last_cmd
)->next
);
1041 (*last_cmd
)->type
= JTAG_RUNTEST
;
1043 (*last_cmd
)->cmd
.runtest
= cmd_queue_alloc(sizeof(runtest_command_t
));
1044 (*last_cmd
)->cmd
.runtest
->num_cycles
= num_cycles
;
1045 (*last_cmd
)->cmd
.runtest
->end_state
= state
;
1050 void jtag_add_runtest(int num_cycles
, enum tap_state state
)
1054 jtag_prelude(state
);
1056 /* executed by sw or hw fifo */
1057 retval
=interface_jtag_add_runtest(num_cycles
, cmd_queue_end_state
);
1058 if (retval
!=ERROR_OK
)
1062 void jtag_add_reset(int req_tlr_or_trst
, int req_srst
)
1064 int trst_with_tlr
= 0;
1067 /* FIX!!! there are *many* different cases here. A better
1068 * approach is needed for legal combinations of transitions...
1070 if ((jtag_reset_config
& RESET_HAS_SRST
)&&
1071 (jtag_reset_config
& RESET_HAS_TRST
)&&
1072 ((jtag_reset_config
& RESET_SRST_PULLS_TRST
)==0))
1074 if (((req_tlr_or_trst
&&!jtag_trst
)||
1075 (!req_tlr_or_trst
&&jtag_trst
))&&
1076 ((req_srst
&&!jtag_srst
)||
1077 (!req_srst
&&jtag_srst
)))
1079 /* FIX!!! srst_pulls_trst allows 1,1 => 0,0 transition.... */
1080 //LOG_ERROR("BUG: transition of req_tlr_or_trst and req_srst in the same jtag_add_reset() call is undefined");
1084 /* Make sure that jtag_reset_config allows the requested reset */
1085 /* if SRST pulls TRST, we can't fulfill srst == 1 with trst == 0 */
1086 if (((jtag_reset_config
& RESET_SRST_PULLS_TRST
) && (req_srst
== 1)) && (!req_tlr_or_trst
))
1088 LOG_ERROR("BUG: requested reset would assert trst");
1089 jtag_error
=ERROR_FAIL
;
1093 /* if TRST pulls SRST, we reset with TAP T-L-R */
1094 if (((jtag_reset_config
& RESET_TRST_PULLS_SRST
) && (req_tlr_or_trst
)) && (req_srst
== 0))
1099 if (req_srst
&& !(jtag_reset_config
& RESET_HAS_SRST
))
1101 LOG_ERROR("BUG: requested SRST assertion, but the current configuration doesn't support this");
1102 jtag_error
=ERROR_FAIL
;
1106 if (req_tlr_or_trst
)
1108 if (!trst_with_tlr
&& (jtag_reset_config
& RESET_HAS_TRST
))
1120 jtag_srst
= req_srst
;
1122 retval
= interface_jtag_add_reset(jtag_trst
, jtag_srst
);
1123 if (retval
!=ERROR_OK
)
1131 LOG_DEBUG("SRST line asserted");
1135 LOG_DEBUG("SRST line released");
1136 if (jtag_nsrst_delay
)
1137 jtag_add_sleep(jtag_nsrst_delay
* 1000);
1142 LOG_DEBUG("JTAG reset with TLR instead of TRST");
1143 jtag_add_end_state(TAP_TLR
);
1145 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
1151 /* we just asserted nTRST, so we're now in Test-Logic-Reset,
1152 * and inform possible listeners about this
1154 LOG_DEBUG("TRST line asserted");
1155 cmd_queue_cur_state
= TAP_TLR
;
1156 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
1160 if (jtag_ntrst_delay
)
1161 jtag_add_sleep(jtag_ntrst_delay
* 1000);
1165 int MINIDRIVER(interface_jtag_add_reset
)(int req_trst
, int req_srst
)
1167 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
1169 /* allocate memory for a new list member */
1170 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
1171 (*last_cmd
)->next
= NULL
;
1172 last_comand_pointer
= &((*last_cmd
)->next
);
1173 (*last_cmd
)->type
= JTAG_RESET
;
1175 (*last_cmd
)->cmd
.reset
= cmd_queue_alloc(sizeof(reset_command_t
));
1176 (*last_cmd
)->cmd
.reset
->trst
= req_trst
;
1177 (*last_cmd
)->cmd
.reset
->srst
= req_srst
;
1182 void jtag_add_end_state(enum tap_state state
)
1184 cmd_queue_end_state
= state
;
1185 if ((cmd_queue_end_state
== TAP_SD
)||(cmd_queue_end_state
== TAP_SI
))
1187 LOG_ERROR("BUG: TAP_SD/SI can't be end state. Calling code should use a larger scan field");
1191 int MINIDRIVER(interface_jtag_add_sleep
)(u32 us
)
1193 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
1195 /* allocate memory for a new list member */
1196 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
1197 (*last_cmd
)->next
= NULL
;
1198 last_comand_pointer
= &((*last_cmd
)->next
);
1199 (*last_cmd
)->type
= JTAG_SLEEP
;
1201 (*last_cmd
)->cmd
.sleep
= cmd_queue_alloc(sizeof(sleep_command_t
));
1202 (*last_cmd
)->cmd
.sleep
->us
= us
;
1207 void jtag_add_sleep(u32 us
)
1209 keep_alive(); /* we might be running on a very slow JTAG clk */
1210 int retval
=interface_jtag_add_sleep(us
);
1211 if (retval
!=ERROR_OK
)
1216 int jtag_scan_size(scan_command_t
*cmd
)
1221 /* count bits in scan command */
1222 for (i
= 0; i
< cmd
->num_fields
; i
++)
1224 bit_count
+= cmd
->fields
[i
].num_bits
;
1230 int jtag_build_buffer(scan_command_t
*cmd
, u8
**buffer
)
1235 bit_count
= jtag_scan_size(cmd
);
1236 *buffer
= malloc(CEIL(bit_count
, 8));
1240 for (i
= 0; i
< cmd
->num_fields
; i
++)
1242 if (cmd
->fields
[i
].out_value
)
1244 #ifdef _DEBUG_JTAG_IO_
1245 char* char_buf
= buf_to_str(cmd
->fields
[i
].out_value
, (cmd
->fields
[i
].num_bits
> 64) ? 64 : cmd
->fields
[i
].num_bits
, 16);
1247 buf_set_buf(cmd
->fields
[i
].out_value
, 0, *buffer
, bit_count
, cmd
->fields
[i
].num_bits
);
1248 #ifdef _DEBUG_JTAG_IO_
1249 LOG_DEBUG("fields[%i].out_value: 0x%s", i
, char_buf
);
1254 bit_count
+= cmd
->fields
[i
].num_bits
;
1260 int jtag_read_buffer(u8
*buffer
, scan_command_t
*cmd
)
1266 /* we return ERROR_OK, unless a check fails, or a handler reports a problem */
1269 for (i
= 0; i
< cmd
->num_fields
; i
++)
1271 /* if neither in_value nor in_handler
1272 * are specified we don't have to examine this field
1274 if (cmd
->fields
[i
].in_value
|| cmd
->fields
[i
].in_handler
)
1276 int num_bits
= cmd
->fields
[i
].num_bits
;
1277 u8
*captured
= buf_set_buf(buffer
, bit_count
, malloc(CEIL(num_bits
, 8)), 0, num_bits
);
1279 #ifdef _DEBUG_JTAG_IO_
1282 char_buf
= buf_to_str(captured
, (num_bits
> 64) ? 64 : num_bits
, 16);
1283 LOG_DEBUG("fields[%i].in_value: 0x%s", i
, char_buf
);
1287 if (cmd
->fields
[i
].in_value
)
1289 buf_cpy(captured
, cmd
->fields
[i
].in_value
, num_bits
);
1291 if (cmd
->fields
[i
].in_handler
)
1293 if (cmd
->fields
[i
].in_handler(cmd
->fields
[i
].in_value
, cmd
->fields
[i
].in_handler_priv
, cmd
->fields
+i
) != ERROR_OK
)
1295 LOG_WARNING("in_handler reported a failed check");
1296 retval
= ERROR_JTAG_QUEUE_FAILED
;
1301 /* no in_value specified, but a handler takes care of the scanned data */
1302 if (cmd
->fields
[i
].in_handler
&& (!cmd
->fields
[i
].in_value
))
1304 if (cmd
->fields
[i
].in_handler(captured
, cmd
->fields
[i
].in_handler_priv
, cmd
->fields
+i
) != ERROR_OK
)
1306 /* We're going to call the error:handler later, but if the in_handler
1307 * reported an error we report this failure upstream
1309 LOG_WARNING("in_handler reported a failed check");
1310 retval
= ERROR_JTAG_QUEUE_FAILED
;
1316 bit_count
+= cmd
->fields
[i
].num_bits
;
1322 int jtag_check_value(u8
*captured
, void *priv
, scan_field_t
*field
)
1324 int retval
= ERROR_OK
;
1325 int num_bits
= field
->num_bits
;
1327 int compare_failed
= 0;
1329 if (field
->in_check_mask
)
1330 compare_failed
= buf_cmp_mask(captured
, field
->in_check_value
, field
->in_check_mask
, num_bits
);
1332 compare_failed
= buf_cmp(captured
, field
->in_check_value
, num_bits
);
1334 if (compare_failed
){
1335 /* An error handler could have caught the failing check
1336 * only report a problem when there wasn't a handler, or if the handler
1337 * acknowledged the error
1339 LOG_WARNING("TAP %s:",
1340 (field
->tap
== NULL
) ? "(unknown)" : field
->tap
->dotted_name
);
1343 char *captured_char
= buf_to_str(captured
, (num_bits
> 64) ? 64 : num_bits
, 16);
1344 char *in_check_value_char
= buf_to_str(field
->in_check_value
, (num_bits
> 64) ? 64 : num_bits
, 16);
1346 if (field
->in_check_mask
)
1348 char *in_check_mask_char
;
1349 in_check_mask_char
= buf_to_str(field
->in_check_mask
, (num_bits
> 64) ? 64 : num_bits
, 16);
1350 LOG_WARNING("value captured during scan didn't pass the requested check:");
1351 LOG_WARNING("captured: 0x%s check_value: 0x%s check_mask: 0x%s",
1352 captured_char
, in_check_value_char
, in_check_mask_char
);
1353 free(in_check_mask_char
);
1357 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
);
1360 free(captured_char
);
1361 free(in_check_value_char
);
1363 retval
= ERROR_JTAG_QUEUE_FAILED
;
1371 set up checking of this field using the in_handler. The values passed in must be valid until
1372 after jtag_execute() has completed.
1374 void jtag_set_check_value(scan_field_t
*field
, u8
*value
, u8
*mask
, error_handler_t
*in_error_handler
)
1377 field
->in_handler
= jtag_check_value
;
1379 field
->in_handler
= NULL
; /* No check, e.g. embeddedice uses value==NULL to indicate no check */
1380 field
->in_handler_priv
= NULL
;
1381 field
->in_check_value
= value
;
1382 field
->in_check_mask
= mask
;
1385 enum scan_type
jtag_scan_type(scan_command_t
*cmd
)
1390 for (i
= 0; i
< cmd
->num_fields
; i
++)
1392 if (cmd
->fields
[i
].in_value
|| cmd
->fields
[i
].in_handler
)
1394 if (cmd
->fields
[i
].out_value
)
1401 int MINIDRIVER(interface_jtag_execute_queue
)(void)
1407 LOG_ERROR("No JTAG interface configured yet. Issue 'init' command in startup scripts before communicating with targets.");
1411 retval
= jtag
->execute_queue();
1415 jtag_command_queue
= NULL
;
1416 last_comand_pointer
= &jtag_command_queue
;
1421 int jtag_execute_queue(void)
1423 int retval
=interface_jtag_execute_queue();
1424 if (retval
==ERROR_OK
)
1428 jtag_error
=ERROR_OK
;
1432 int jtag_reset_callback(enum jtag_event event
, void *priv
)
1434 jtag_tap_t
*tap
= priv
;
1438 if (event
== JTAG_TRST_ASSERTED
)
1440 buf_set_ones(tap
->cur_instr
, tap
->ir_length
);
1447 void jtag_sleep(u32 us
)
1449 alive_sleep(us
/1000);
1452 /* Try to examine chain layout according to IEEE 1149.1 §12
1454 int jtag_examine_chain(void)
1458 u8 idcode_buffer
[JTAG_MAX_CHAIN_SIZE
* 4];
1461 int device_count
= 0;
1462 u8 zero_check
= 0x0;
1463 u8 one_check
= 0xff;
1466 field
.num_bits
= sizeof(idcode_buffer
) * 8;
1467 field
.out_value
= idcode_buffer
;
1468 field
.out_mask
= NULL
;
1469 field
.in_value
= idcode_buffer
;
1470 field
.in_check_value
= NULL
;
1471 field
.in_check_mask
= NULL
;
1472 field
.in_handler
= NULL
;
1473 field
.in_handler_priv
= NULL
;
1475 for (i
= 0; i
< JTAG_MAX_CHAIN_SIZE
; i
++)
1477 buf_set_u32(idcode_buffer
, i
* 32, 32, 0x000000FF);
1480 jtag_add_plain_dr_scan(1, &field
, TAP_TLR
);
1481 jtag_execute_queue();
1483 for (i
= 0; i
< JTAG_MAX_CHAIN_SIZE
* 4; i
++)
1485 zero_check
|= idcode_buffer
[i
];
1486 one_check
&= idcode_buffer
[i
];
1489 /* if there wasn't a single non-zero bit or if all bits were one, the scan isn't valid */
1490 if ((zero_check
== 0x00) || (one_check
== 0xff))
1492 LOG_ERROR("JTAG communication failure, check connection, JTAG interface, target power etc.");
1493 return ERROR_JTAG_INIT_FAILED
;
1496 // point at the 1st tap
1497 tap
= jtag_NextEnabledTap(NULL
);
1499 LOG_ERROR("JTAG: No taps enabled?");
1500 return ERROR_JTAG_INIT_FAILED
;
1503 for (bit_count
= 0; bit_count
< (JTAG_MAX_CHAIN_SIZE
* 32) - 31;)
1505 u32 idcode
= buf_get_u32(idcode_buffer
, bit_count
, 32);
1506 if ((idcode
& 1) == 0)
1508 /* LSB must not be 0, this indicates a device in bypass */
1509 LOG_WARNING("Tap/Device does not have IDCODE");
1520 if (idcode
== 0x000000FF)
1523 /* End of chain (invalid manufacturer ID)
1525 * The JTAG examine is the very first thing that happens
1527 * A single JTAG device requires only 64 bits to be read back correctly.
1529 * The code below adds a check that the rest of the data scanned (640 bits)
1530 * are all as expected. This helps diagnose/catch problems with the JTAG chain
1532 * earlier and gives more helpful/explicit error messages.
1534 for (bit_count
+= 32; bit_count
< (JTAG_MAX_CHAIN_SIZE
* 32) - 31;bit_count
+= 32)
1536 idcode
= buf_get_u32(idcode_buffer
, bit_count
, 32);
1537 if (unexpected
||(idcode
!= 0x000000FF))
1539 LOG_WARNING("Unexpected idcode after end of chain! %d 0x%08x", bit_count
, idcode
);
1547 #define EXTRACT_MFG(X) (((X) & 0xffe) >> 1)
1548 manufacturer
= EXTRACT_MFG(idcode
);
1549 #define EXTRACT_PART(X) (((X) & 0xffff000) >> 12)
1550 part
= EXTRACT_PART(idcode
);
1551 #define EXTRACT_VER(X) (((X) & 0xf0000000) >> 28)
1552 version
= EXTRACT_VER(idcode
);
1554 LOG_INFO("JTAG tap: %s tap/device found: 0x%8.8x (Manufacturer: 0x%3.3x, Part: 0x%4.4x, Version: 0x%1.1x)",
1555 ((tap
!= NULL
) ? (tap
->dotted_name
) : "(not-named)"),
1556 idcode
, manufacturer
, part
, version
);
1562 tap
->idcode
= idcode
;
1563 if( tap
->expected_id
){
1564 if( tap
->idcode
!= tap
->expected_id
){
1565 LOG_ERROR("ERROR: Tap: %s - Expected id: 0x%08x, Got: 0x%08x",
1569 LOG_ERROR("ERROR: expected: mfg: 0x%3.3x, part: 0x%4.4x, ver: 0x%1.1x",
1570 EXTRACT_MFG( tap
->expected_id
),
1571 EXTRACT_PART( tap
->expected_id
),
1572 EXTRACT_VER( tap
->expected_id
) );
1573 LOG_ERROR("ERROR: got: mfg: 0x%3.3x, part: 0x%4.4x, ver: 0x%1.1x",
1574 EXTRACT_MFG( tap
->idcode
),
1575 EXTRACT_PART( tap
->idcode
),
1576 EXTRACT_VER( tap
->idcode
) );
1578 LOG_INFO("JTAG Tap/device matched");
1582 LOG_INFO("JTAG TAP ID: 0x%08x - Unknown - please report (A) chipname and (B) idcode to the openocd project",
1586 tap
= jtag_NextEnabledTap(tap
);
1591 /* see if number of discovered devices matches configuration */
1592 if (device_count
!= jtag_NumEnabledTaps())
1594 LOG_ERROR("number of discovered devices in JTAG chain (%i) doesn't match (enabled) configuration (%i), total taps: %d",
1595 device_count
, jtag_NumEnabledTaps(), jtag_NumTotalTaps());
1596 LOG_ERROR("check the config file and ensure proper JTAG communication (connections, speed, ...)");
1597 return ERROR_JTAG_INIT_FAILED
;
1603 int jtag_validate_chain(void)
1606 int total_ir_length
= 0;
1612 total_ir_length
= 0;
1614 tap
= jtag_NextEnabledTap(tap
);
1618 total_ir_length
+= tap
->ir_length
;
1621 total_ir_length
+= 2;
1622 ir_test
= malloc(CEIL(total_ir_length
, 8));
1623 buf_set_ones(ir_test
, total_ir_length
);
1626 field
.num_bits
= total_ir_length
;
1627 field
.out_value
= ir_test
;
1628 field
.out_mask
= NULL
;
1629 field
.in_value
= ir_test
;
1630 field
.in_check_value
= NULL
;
1631 field
.in_check_mask
= NULL
;
1632 field
.in_handler
= NULL
;
1633 field
.in_handler_priv
= NULL
;
1635 jtag_add_plain_ir_scan(1, &field
, TAP_TLR
);
1636 jtag_execute_queue();
1641 tap
= jtag_NextEnabledTap(tap
);
1647 if (buf_get_u32(ir_test
, chain_pos
, 2) != 0x1)
1649 char *cbuf
= buf_to_str(ir_test
, total_ir_length
, 16);
1650 LOG_ERROR("Error validating JTAG scan chain, IR mismatch, scan returned 0x%s", cbuf
);
1653 return ERROR_JTAG_INIT_FAILED
;
1655 chain_pos
+= tap
->ir_length
;
1658 if (buf_get_u32(ir_test
, chain_pos
, 2) != 0x3)
1660 char *cbuf
= buf_to_str(ir_test
, total_ir_length
, 16);
1661 LOG_ERROR("Error validating JTAG scan chain, IR mismatch, scan returned 0x%s", cbuf
);
1664 return ERROR_JTAG_INIT_FAILED
;
1674 jim_newtap_cmd( Jim_GetOptInfo
*goi
)
1684 const Jim_Nvp opts
[] = {
1685 #define NTAP_OPT_IRLEN 0
1686 { .name
= "-irlen" , .value
= NTAP_OPT_IRLEN
},
1687 #define NTAP_OPT_IRMASK 1
1688 { .name
= "-irmask" , .value
= NTAP_OPT_IRMASK
},
1689 #define NTAP_OPT_IRCAPTURE 2
1690 { .name
= "-ircapture" , .value
= NTAP_OPT_IRCAPTURE
},
1691 #define NTAP_OPT_ENABLED 3
1692 { .name
= "-enable" , .value
= NTAP_OPT_ENABLED
},
1693 #define NTAP_OPT_DISABLED 4
1694 { .name
= "-disable" , .value
= NTAP_OPT_DISABLED
},
1695 #define NTAP_OPT_EXPECTED_ID 5
1696 { .name
= "-expected-id" , .value
= NTAP_OPT_EXPECTED_ID
},
1697 { .name
= NULL
, .value
= -1 },
1701 pTap
= malloc( sizeof(jtag_tap_t
) );
1702 memset( pTap
, 0, sizeof(*pTap
) );
1704 Jim_SetResult_sprintf( goi
->interp
, "no memory");
1708 // we expect CHIP + TAP + OPTIONS
1710 if( goi
->argc
< 3 ){
1711 Jim_SetResult_sprintf(goi
->interp
, "Missing CHIP TAP OPTIONS ....");
1714 Jim_GetOpt_String( goi
, &cp
, NULL
);
1715 pTap
->chip
= strdup(cp
);
1717 Jim_GetOpt_String( goi
, &cp
, NULL
);
1718 pTap
->tapname
= strdup(cp
);
1720 // name + dot + name + null
1721 x
= strlen(pTap
->chip
) + 1 + strlen(pTap
->tapname
) + 1;
1723 sprintf( cp
, "%s.%s", pTap
->chip
, pTap
->tapname
);
1724 pTap
->dotted_name
= cp
;
1726 LOG_DEBUG("Creating New Tap, Chip: %s, Tap: %s, Dotted: %s, %d params",
1727 pTap
->chip
, pTap
->tapname
, pTap
->dotted_name
, goi
->argc
);
1730 // default is enabled
1733 // deal with options
1734 #define NTREQ_IRLEN 1
1735 #define NTREQ_IRCAPTURE 2
1736 #define NTREQ_IRMASK 4
1738 // clear them as we find them
1739 reqbits
= (NTREQ_IRLEN
| NTREQ_IRCAPTURE
| NTREQ_IRMASK
);
1742 e
= Jim_GetOpt_Nvp( goi
, opts
, &n
);
1744 Jim_GetOpt_NvpUnknown( goi
, opts
, 0 );
1747 LOG_DEBUG("Processing option: %s", n
->name
);
1749 case NTAP_OPT_ENABLED
:
1752 case NTAP_OPT_DISABLED
:
1755 case NTAP_OPT_EXPECTED_ID
:
1756 e
= Jim_GetOpt_Wide( goi
, &w
);
1757 pTap
->expected_id
= w
;
1759 case NTAP_OPT_IRLEN
:
1760 case NTAP_OPT_IRMASK
:
1761 case NTAP_OPT_IRCAPTURE
:
1762 e
= Jim_GetOpt_Wide( goi
, &w
);
1764 Jim_SetResult_sprintf( goi
->interp
, "option: %s bad parameter", n
->name
);
1767 if( (w
< 0) || (w
> 0xffff) ){
1769 Jim_SetResult_sprintf( goi
->interp
, "option: %s - wacky value: %d (0x%x)",
1770 n
->name
, (int)(w
), (int)(w
));
1774 case NTAP_OPT_IRLEN
:
1775 pTap
->ir_length
= w
;
1776 reqbits
&= (~(NTREQ_IRLEN
));
1778 case NTAP_OPT_IRMASK
:
1779 pTap
->ir_capture_mask
= w
;
1780 reqbits
&= (~(NTREQ_IRMASK
));
1782 case NTAP_OPT_IRCAPTURE
:
1783 pTap
->ir_capture_value
= w
;
1784 reqbits
&= (~(NTREQ_IRCAPTURE
));
1787 } // switch(n->value)
1788 } // while( goi->argc )
1790 // Did we get all the options?
1793 Jim_SetResult_sprintf( goi
->interp
,
1794 "newtap: %s missing required parameters",
1796 // fixme: Tell user what is missing :-(
1797 // no memory leaks pelase
1798 free(((void *)(pTap
->chip
)));
1799 free(((void *)(pTap
->tapname
)));
1800 free(((void *)(pTap
->dotted_name
)));
1801 free(((void *)(pTap
)));
1805 pTap
->expected
= malloc( pTap
->ir_length
);
1806 pTap
->expected_mask
= malloc( pTap
->ir_length
);
1807 pTap
->cur_instr
= malloc( pTap
->ir_length
);
1809 buf_set_u32( pTap
->expected
,
1812 pTap
->ir_capture_value
);
1813 buf_set_u32( pTap
->expected_mask
,
1816 pTap
->ir_capture_mask
);
1817 buf_set_ones( pTap
->cur_instr
,
1823 jtag_register_event_callback(jtag_reset_callback
, pTap
);
1825 ppTap
= &(jtag_all_taps
);
1826 while( (*ppTap
) != NULL
){
1827 ppTap
= &((*ppTap
)->next_tap
);
1831 static int n_taps
= 0;
1832 pTap
->abs_chain_position
= n_taps
++;
1834 LOG_DEBUG( "Created Tap: %s @ abs position %d, irlen %d, capture: 0x%x mask: 0x%x",
1835 (*ppTap
)->dotted_name
,
1836 (*ppTap
)->abs_chain_position
,
1837 (*ppTap
)->ir_length
,
1838 (*ppTap
)->ir_capture_value
,
1839 (*ppTap
)->ir_capture_mask
);
1847 jim_jtag_command( Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
1852 struct command_context_s
*context
;
1856 JTAG_CMD_INIT_RESET
,
1859 JTAG_CMD_TAPDISABLE
,
1860 JTAG_CMD_TAPISENABLED
1863 const Jim_Nvp jtag_cmds
[] = {
1864 { .name
= "interface" , .value
= JTAG_CMD_INTERFACE
},
1865 { .name
= "arp_init-reset", .value
= JTAG_CMD_INIT_RESET
},
1866 { .name
= "newtap" , .value
= JTAG_CMD_NEWTAP
},
1867 { .name
= "tapisenabled" , .value
= JTAG_CMD_TAPISENABLED
},
1868 { .name
= "tapenable" , .value
= JTAG_CMD_TAPENABLE
},
1869 { .name
= "tapdisable" , .value
= JTAG_CMD_TAPDISABLE
},
1871 { .name
= NULL
, .value
= -1 },
1874 context
= Jim_GetAssocData(interp
, "context");
1875 // go past the command
1876 Jim_GetOpt_Setup( &goi
, interp
, argc
-1, argv
+1 );
1878 e
= Jim_GetOpt_Nvp( &goi
, jtag_cmds
, &n
);
1880 Jim_GetOpt_NvpUnknown( &goi
, jtag_cmds
, 0 );
1883 Jim_SetEmptyResult( goi
.interp
);
1885 case JTAG_CMD_INTERFACE
:
1886 // return the name of the interface
1887 // TCL code might need to know the exact type...
1888 // FUTURE: we allow this as a means to "set" the interface.
1889 if( goi
.argc
!= 0 ){
1890 Jim_WrongNumArgs( goi
.interp
, 1, goi
.argv
-1, "(no params)");
1893 Jim_SetResultString( goi
.interp
, jtag_interface
->name
, -1 );
1895 case JTAG_CMD_INIT_RESET
:
1896 if( goi
.argc
!= 0 ){
1897 Jim_WrongNumArgs( goi
.interp
, 1, goi
.argv
-1, "(no params)");
1900 e
= jtag_init_reset(context
);
1901 if( e
!= ERROR_OK
){
1902 Jim_SetResult_sprintf( goi
.interp
, "error: %d", e
);
1906 case JTAG_CMD_NEWTAP
:
1907 return jim_newtap_cmd( &goi
);
1909 case JTAG_CMD_TAPISENABLED
:
1910 case JTAG_CMD_TAPENABLE
:
1911 case JTAG_CMD_TAPDISABLE
:
1912 if( goi
.argc
!= 1 ){
1913 Jim_SetResultString( goi
.interp
, "Too many parameters",-1 );
1919 t
= jtag_TapByJimObj( goi
.interp
, goi
.argv
[0] );
1924 case JTAG_CMD_TAPISENABLED
:
1927 case JTAG_CMD_TAPENABLE
:
1931 case JTAG_CMD_TAPDISABLE
:
1936 Jim_SetResult( goi
.interp
, Jim_NewIntObj( goi
.interp
, e
) );
1945 int jtag_register_commands(struct command_context_s
*cmd_ctx
)
1947 register_jim( cmd_ctx
, "jtag", jim_jtag_command
, "perform jtag tap actions");
1949 register_command(cmd_ctx
, NULL
, "interface", handle_interface_command
,
1950 COMMAND_CONFIG
, "try to configure interface");
1951 register_command(cmd_ctx
, NULL
, "jtag_speed", handle_jtag_speed_command
,
1952 COMMAND_ANY
, "set jtag speed (if supported)");
1953 register_command(cmd_ctx
, NULL
, "jtag_khz", handle_jtag_khz_command
,
1954 COMMAND_ANY
, "same as jtag_speed, except it takes maximum khz as arguments. 0 KHz = RTCK.");
1955 register_command(cmd_ctx
, NULL
, "jtag_device", handle_jtag_device_command
,
1956 COMMAND_CONFIG
, "jtag_device <ir_length> <ir_expected> <ir_mask>");
1957 register_command(cmd_ctx
, NULL
, "reset_config", handle_reset_config_command
,
1958 COMMAND_CONFIG
, NULL
);
1959 register_command(cmd_ctx
, NULL
, "jtag_nsrst_delay", handle_jtag_nsrst_delay_command
,
1960 COMMAND_ANY
, "jtag_nsrst_delay <ms> - delay after deasserting srst in ms");
1961 register_command(cmd_ctx
, NULL
, "jtag_ntrst_delay", handle_jtag_ntrst_delay_command
,
1962 COMMAND_ANY
, "jtag_ntrst_delay <ms> - delay after deasserting trst in ms");
1964 register_command(cmd_ctx
, NULL
, "scan_chain", handle_scan_chain_command
,
1965 COMMAND_EXEC
, "print current scan chain configuration");
1967 register_command(cmd_ctx
, NULL
, "endstate", handle_endstate_command
,
1968 COMMAND_EXEC
, "finish JTAG operations in <tap_state>");
1969 register_command(cmd_ctx
, NULL
, "jtag_reset", handle_jtag_reset_command
,
1970 COMMAND_EXEC
, "toggle reset lines <trst> <srst>");
1971 register_command(cmd_ctx
, NULL
, "runtest", handle_runtest_command
,
1972 COMMAND_EXEC
, "move to Run-Test/Idle, and execute <num_cycles>");
1973 register_command(cmd_ctx
, NULL
, "irscan", handle_irscan_command
,
1974 COMMAND_EXEC
, "execute IR scan <device> <instr> [dev2] [instr2] ...");
1975 register_jim(cmd_ctx
, "drscan", Jim_Command_drscan
, "execute DR scan <device> <num_bits> <value> <num_bits1> <value2> ...");
1977 register_command(cmd_ctx
, NULL
, "verify_ircapture", handle_verify_ircapture_command
,
1978 COMMAND_ANY
, "verify value captured during Capture-IR <enable|disable>");
1982 int jtag_interface_init(struct command_context_s
*cmd_ctx
)
1987 if (!jtag_interface
)
1989 /* nothing was previously specified by "interface" command */
1990 LOG_ERROR("JTAG interface has to be specified, see \"interface\" command");
1991 return ERROR_JTAG_INVALID_INTERFACE
;
1995 jtag_interface
->khz(speed_khz
, &jtag_speed
);
1999 if (jtag_interface
->init() != ERROR_OK
)
2000 return ERROR_JTAG_INIT_FAILED
;
2004 jtag
= jtag_interface
;
2008 static int jtag_init_inner(struct command_context_s
*cmd_ctx
)
2013 LOG_DEBUG("Init JTAG chain");
2016 tap
= jtag_NextEnabledTap(NULL
);
2018 LOG_ERROR("There are no enabled taps?");
2019 return ERROR_JTAG_INIT_FAILED
;
2023 if ((retval
=jtag_execute_queue())!=ERROR_OK
)
2026 /* examine chain first, as this could discover the real chain layout */
2027 if (jtag_examine_chain() != ERROR_OK
)
2029 LOG_ERROR("trying to validate configured JTAG chain anyway...");
2032 if (jtag_validate_chain() != ERROR_OK
)
2034 LOG_ERROR("Could not validate JTAG chain, continuing anyway...");
2040 int jtag_init_reset(struct command_context_s
*cmd_ctx
)
2044 if ((retval
=jtag_interface_init(cmd_ctx
)) != ERROR_OK
)
2047 LOG_DEBUG("Trying to bring the JTAG controller to life by asserting TRST / TLR");
2049 /* Reset can happen after a power cycle.
2051 * Ideally we would only assert TRST or run TLR before the target reset.
2053 * However w/srst_pulls_trst, trst is asserted together with the target
2054 * reset whether we want it or not.
2056 * NB! Some targets have JTAG circuitry disabled until a
2057 * trst & srst has been asserted.
2059 * NB! here we assume nsrst/ntrst delay are sufficient!
2061 * NB! order matters!!!! srst *can* disconnect JTAG circuitry
2064 jtag_add_reset(1, 0); /* TLR or TRST */
2065 if (jtag_reset_config
& RESET_HAS_SRST
)
2067 jtag_add_reset(1, 1);
2068 if ((jtag_reset_config
& RESET_SRST_PULLS_TRST
)==0)
2069 jtag_add_reset(0, 1);
2071 jtag_add_reset(0, 0);
2072 if ((retval
= jtag_execute_queue()) != ERROR_OK
)
2075 /* Check that we can communication on the JTAG chain + eventually we want to
2076 * be able to perform enumeration only after OpenOCD has started
2077 * telnet and GDB server
2079 * That would allow users to more easily perform any magic they need to before
2082 return jtag_init_inner(cmd_ctx
);
2085 int jtag_init(struct command_context_s
*cmd_ctx
)
2088 if ((retval
=jtag_interface_init(cmd_ctx
)) != ERROR_OK
)
2090 if (jtag_init_inner(cmd_ctx
)==ERROR_OK
)
2094 return jtag_init_reset(cmd_ctx
);
2097 static int default_khz(int khz
, int *jtag_speed
)
2099 LOG_ERROR("Translation from khz to jtag_speed not implemented");
2103 static int default_speed_div(int speed
, int *khz
)
2105 LOG_ERROR("Translation from jtag_speed to khz not implemented");
2109 static int default_power_dropout(int *dropout
)
2111 *dropout
=0; /* by default we can't detect power dropout */
2115 static int default_srst_asserted(int *srst_asserted
)
2117 *srst_asserted
=0; /* by default we can't detect srst asserted */
2121 int handle_interface_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2126 /* check whether the interface is already configured */
2129 LOG_WARNING("Interface already configured, ignoring");
2133 /* interface name is a mandatory argument */
2134 if (argc
< 1 || args
[0][0] == '\0')
2136 return ERROR_COMMAND_SYNTAX_ERROR
;
2139 for (i
=0; jtag_interfaces
[i
]; i
++)
2141 if (strcmp(args
[0], jtag_interfaces
[i
]->name
) == 0)
2143 if ((retval
= jtag_interfaces
[i
]->register_commands(cmd_ctx
)) != ERROR_OK
)
2148 jtag_interface
= jtag_interfaces
[i
];
2150 if (jtag_interface
->khz
== NULL
)
2152 jtag_interface
->khz
= default_khz
;
2154 if (jtag_interface
->speed_div
== NULL
)
2156 jtag_interface
->speed_div
= default_speed_div
;
2158 if (jtag_interface
->power_dropout
== NULL
)
2160 jtag_interface
->power_dropout
= default_power_dropout
;
2162 if (jtag_interface
->srst_asserted
== NULL
)
2164 jtag_interface
->srst_asserted
= default_srst_asserted
;
2171 /* no valid interface was found (i.e. the configuration option,
2172 * didn't match one of the compiled-in interfaces
2174 LOG_ERROR("No valid jtag interface found (%s)", args
[0]);
2175 LOG_ERROR("compiled-in jtag interfaces:");
2176 for (i
= 0; jtag_interfaces
[i
]; i
++)
2178 LOG_ERROR("%i: %s", i
, jtag_interfaces
[i
]->name
);
2181 return ERROR_JTAG_INVALID_INTERFACE
;
2184 int handle_jtag_device_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2188 Jim_Obj
*newargs
[ 10 ];
2192 // argv[-1] = command
2193 // argv[ 0] = ir length
2194 // argv[ 1] = ir capture
2195 // argv[ 2] = ir mask
2196 // argv[ 3] = not actually used by anything but in the docs
2199 command_print( cmd_ctx
, "OLD DEPRECATED SYNTAX: Please use the NEW syntax");
2202 command_print( cmd_ctx
, "OLD SYNTAX: DEPRECATED - translating to new syntax");
2203 command_print( cmd_ctx
, "jtag newtap CHIP TAP -irlen %s -ircapture %s -irvalue %s",
2207 command_print( cmd_ctx
, "Example: STM32 has 2 taps, the cortexM3(len4) + boundryscan(len5)");
2208 command_print( cmd_ctx
, "jtag newtap stm32 cortexm3 ....., thus creating the tap: \"stm32.cortexm3\"");
2209 command_print( cmd_ctx
, "jtag newtap stm32 boundry ....., and the tap: \"stm32.boundery\"");
2210 command_print( cmd_ctx
, "And then refer to the taps by the dotted name.");
2214 newargs
[0] = Jim_NewStringObj( interp
, "jtag", -1 );
2215 newargs
[1] = Jim_NewStringObj( interp
, "newtap", -1 );
2216 sprintf( buf
, "chip%d", jtag_NumTotalTaps() );
2217 newargs
[2] = Jim_NewStringObj( interp
, buf
, -1 );
2218 sprintf( buf
, "tap%d", jtag_NumTotalTaps() );
2219 newargs
[3] = Jim_NewStringObj( interp
, buf
, -1 );
2220 newargs
[4] = Jim_NewStringObj( interp
, "-irlen", -1 );
2221 newargs
[5] = Jim_NewStringObj( interp
, args
[0], -1 );
2222 newargs
[6] = Jim_NewStringObj( interp
, "-ircapture", -1 );
2223 newargs
[7] = Jim_NewStringObj( interp
, args
[1], -1 );
2224 newargs
[8] = Jim_NewStringObj( interp
, "-irmask", -1 );
2225 newargs
[9] = Jim_NewStringObj( interp
, args
[2], -1 );
2227 command_print( cmd_ctx
, "NEW COMMAND:");
2228 sprintf( buf
, "%s %s %s %s %s %s %s %s %s %s",
2229 Jim_GetString( newargs
[0], NULL
),
2230 Jim_GetString( newargs
[1], NULL
),
2231 Jim_GetString( newargs
[2], NULL
),
2232 Jim_GetString( newargs
[3], NULL
),
2233 Jim_GetString( newargs
[4], NULL
),
2234 Jim_GetString( newargs
[5], NULL
),
2235 Jim_GetString( newargs
[6], NULL
),
2236 Jim_GetString( newargs
[7], NULL
),
2237 Jim_GetString( newargs
[8], NULL
),
2238 Jim_GetString( newargs
[9], NULL
) );
2242 e
= jim_jtag_command( interp
, 10, newargs
);
2244 command_print( cmd_ctx
, "%s", Jim_GetString( Jim_GetResult(interp
), NULL
) );
2250 int handle_scan_chain_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2254 tap
= jtag_all_taps
;
2255 command_print(cmd_ctx
, " TapName | Enabled | IdCode Expected IrLen IrCap IrMask Instr ");
2256 command_print(cmd_ctx
, "---|--------------------|---------|------------|------------|------|------|------|---------");
2259 u32 expected
, expected_mask
, cur_instr
;
2260 expected
= buf_get_u32(tap
->expected
, 0, tap
->ir_length
);
2261 expected_mask
= buf_get_u32(tap
->expected_mask
, 0, tap
->ir_length
);
2262 cur_instr
= buf_get_u32(tap
->cur_instr
, 0, tap
->ir_length
);
2263 command_print(cmd_ctx
,
2264 "%2d | %-18s | %c | 0x%08x | 0x%08x | 0x%02x | 0x%02x | 0x%02x | 0x%02x",
2265 tap
->abs_chain_position
,
2267 tap
->enabled
? 'Y' : 'n',
2274 tap
= tap
->next_tap
;
2280 int handle_reset_config_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2283 return ERROR_COMMAND_SYNTAX_ERROR
;
2287 if (strcmp(args
[0], "none") == 0)
2288 jtag_reset_config
= RESET_NONE
;
2289 else if (strcmp(args
[0], "trst_only") == 0)
2290 jtag_reset_config
= RESET_HAS_TRST
;
2291 else if (strcmp(args
[0], "srst_only") == 0)
2292 jtag_reset_config
= RESET_HAS_SRST
;
2293 else if (strcmp(args
[0], "trst_and_srst") == 0)
2294 jtag_reset_config
= RESET_TRST_AND_SRST
;
2297 LOG_ERROR("(1) invalid reset_config argument (%s), defaulting to none", args
[0]);
2298 jtag_reset_config
= RESET_NONE
;
2299 return ERROR_INVALID_ARGUMENTS
;
2305 if (strcmp(args
[1], "separate") == 0)
2307 /* seperate reset lines - default */
2310 if (strcmp(args
[1], "srst_pulls_trst") == 0)
2311 jtag_reset_config
|= RESET_SRST_PULLS_TRST
;
2312 else if (strcmp(args
[1], "trst_pulls_srst") == 0)
2313 jtag_reset_config
|= RESET_TRST_PULLS_SRST
;
2314 else if (strcmp(args
[1], "combined") == 0)
2315 jtag_reset_config
|= RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
;
2318 LOG_ERROR("(2) invalid reset_config argument (%s), defaulting to none", args
[1]);
2319 jtag_reset_config
= RESET_NONE
;
2320 return ERROR_INVALID_ARGUMENTS
;
2327 if (strcmp(args
[2], "trst_open_drain") == 0)
2328 jtag_reset_config
|= RESET_TRST_OPEN_DRAIN
;
2329 else if (strcmp(args
[2], "trst_push_pull") == 0)
2330 jtag_reset_config
&= ~RESET_TRST_OPEN_DRAIN
;
2333 LOG_ERROR("(3) invalid reset_config argument (%s) defaulting to none", args
[2] );
2334 jtag_reset_config
= RESET_NONE
;
2335 return ERROR_INVALID_ARGUMENTS
;
2341 if (strcmp(args
[3], "srst_push_pull") == 0)
2342 jtag_reset_config
|= RESET_SRST_PUSH_PULL
;
2343 else if (strcmp(args
[3], "srst_open_drain") == 0)
2344 jtag_reset_config
&= ~RESET_SRST_PUSH_PULL
;
2347 LOG_ERROR("(4) invalid reset_config argument (%s), defaulting to none", args
[3]);
2348 jtag_reset_config
= RESET_NONE
;
2349 return ERROR_INVALID_ARGUMENTS
;
2356 int handle_jtag_nsrst_delay_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2360 LOG_ERROR("jtag_nsrst_delay <ms> command takes one required argument");
2365 jtag_nsrst_delay
= strtoul(args
[0], NULL
, 0);
2371 int handle_jtag_ntrst_delay_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2375 LOG_ERROR("jtag_ntrst_delay <ms> command takes one required argument");
2380 jtag_ntrst_delay
= strtoul(args
[0], NULL
, 0);
2386 int handle_jtag_speed_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2388 int retval
=ERROR_OK
;
2392 LOG_DEBUG("handle jtag speed");
2395 cur_speed
= jtag_speed
= strtoul(args
[0], NULL
, 0);
2397 /* this command can be called during CONFIG,
2398 * in which case jtag isn't initialized */
2401 retval
=jtag
->speed(cur_speed
);
2403 } else if (argc
== 0)
2407 return ERROR_COMMAND_SYNTAX_ERROR
;
2409 command_print(cmd_ctx
, "jtag_speed: %d", jtag_speed
);
2414 int handle_jtag_khz_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2416 int retval
=ERROR_OK
;
2417 LOG_DEBUG("handle jtag khz");
2421 speed_khz
= strtoul(args
[0], NULL
, 0);
2425 LOG_DEBUG("have interface set up");
2427 if ((retval
=jtag
->khz(speed_khz
, &speed_div1
))!=ERROR_OK
)
2433 cur_speed
= jtag_speed
= speed_div1
;
2435 retval
=jtag
->speed(cur_speed
);
2444 return ERROR_COMMAND_SYNTAX_ERROR
;
2449 if ((retval
=jtag
->speed_div(jtag_speed
, &speed_khz
))!=ERROR_OK
)
2455 command_print(cmd_ctx
, "RCLK - adaptive");
2458 command_print(cmd_ctx
, "%d kHz", speed_khz
);
2464 int handle_endstate_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2466 enum tap_state state
;
2470 return ERROR_COMMAND_SYNTAX_ERROR
;
2474 for (state
= 0; state
< 16; state
++)
2476 if (strcmp(args
[0], tap_state_strings
[state
]) == 0)
2478 jtag_add_end_state(state
);
2479 jtag_execute_queue();
2483 command_print(cmd_ctx
, "current endstate: %s", tap_state_strings
[cmd_queue_end_state
]);
2488 int handle_jtag_reset_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2495 return ERROR_COMMAND_SYNTAX_ERROR
;
2498 if (args
[0][0] == '1')
2500 else if (args
[0][0] == '0')
2504 return ERROR_COMMAND_SYNTAX_ERROR
;
2507 if (args
[1][0] == '1')
2509 else if (args
[1][0] == '0')
2513 return ERROR_COMMAND_SYNTAX_ERROR
;
2516 if (jtag_interface_init(cmd_ctx
) != ERROR_OK
)
2517 return ERROR_JTAG_INIT_FAILED
;
2519 jtag_add_reset(trst
, srst
);
2520 jtag_execute_queue();
2525 int handle_runtest_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2529 return ERROR_COMMAND_SYNTAX_ERROR
;
2532 jtag_add_runtest(strtol(args
[0], NULL
, 0), -1);
2533 jtag_execute_queue();
2539 int handle_irscan_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2542 scan_field_t
*fields
;
2545 if ((argc
< 2) || (argc
% 2))
2547 return ERROR_COMMAND_SYNTAX_ERROR
;
2550 fields
= malloc(sizeof(scan_field_t
) * argc
/ 2);
2552 for (i
= 0; i
< argc
/ 2; i
++)
2554 tap
= jtag_TapByString( args
[i
*2] );
2557 command_print( cmd_ctx
, "Tap: %s unknown", args
[i
*2] );
2560 int field_size
= tap
->ir_length
;
2561 fields
[i
].tap
= tap
;
2562 fields
[i
].out_value
= malloc(CEIL(field_size
, 8));
2563 buf_set_u32(fields
[i
].out_value
, 0, field_size
, strtoul(args
[i
*2+1], NULL
, 0));
2564 fields
[i
].out_mask
= NULL
;
2565 fields
[i
].in_value
= NULL
;
2566 fields
[i
].in_check_mask
= NULL
;
2567 fields
[i
].in_handler
= NULL
;
2568 fields
[i
].in_handler_priv
= NULL
;
2571 jtag_add_ir_scan(argc
/ 2, fields
, -1);
2572 jtag_execute_queue();
2574 for (i
= 0; i
< argc
/ 2; i
++)
2575 free(fields
[i
].out_value
);
2582 int Jim_Command_drscan(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *args
)
2585 scan_field_t
*fields
;
2587 int field_count
= 0;
2592 * args[2] = num_bits
2593 * args[3] = hex string
2594 * ... repeat num bits and hex string ...
2596 if ((argc
< 4) || ((argc
% 2)!=0))
2598 Jim_WrongNumArgs(interp
, 1, args
, "wrong arguments");
2602 for (i
= 2; i
< argc
; i
+=2)
2606 e
= Jim_GetLong(interp
, args
[i
], &bits
);
2611 tap
= jtag_TapByJimObj( interp
, args
[1] );
2616 num_fields
=(argc
-2)/2;
2617 fields
= malloc(sizeof(scan_field_t
) * num_fields
);
2618 for (i
= 2; i
< argc
; i
+=2)
2624 Jim_GetLong(interp
, args
[i
], &bits
);
2625 str
= Jim_GetString(args
[i
+1], &len
);
2628 fields
[field_count
].tap
= tap
;
2629 fields
[field_count
].num_bits
= bits
;
2630 fields
[field_count
].out_value
= malloc(CEIL(bits
, 8));
2631 str_to_buf(str
, len
, fields
[field_count
].out_value
, bits
, 0);
2632 fields
[field_count
].out_mask
= NULL
;
2633 fields
[field_count
].in_value
= fields
[field_count
].out_value
;
2634 fields
[field_count
].in_check_mask
= NULL
;
2635 fields
[field_count
].in_check_value
= NULL
;
2636 fields
[field_count
].in_handler
= NULL
;
2637 fields
[field_count
++].in_handler_priv
= NULL
;
2640 jtag_add_dr_scan(num_fields
, fields
, -1);
2641 retval
= jtag_execute_queue();
2642 if (retval
!= ERROR_OK
)
2644 Jim_SetResultString(interp
, "drscan: jtag execute failed",-1);
2649 Jim_Obj
*list
= Jim_NewListObj(interp
, NULL
, 0);
2650 for (i
= 2; i
< argc
; i
+=2)
2655 Jim_GetLong(interp
, args
[i
], &bits
);
2656 str
= buf_to_str(fields
[field_count
].in_value
, bits
, 16);
2657 free(fields
[field_count
].out_value
);
2659 Jim_ListAppendElement(interp
, list
, Jim_NewStringObj(interp
, str
, strlen(str
)));
2664 Jim_SetResult(interp
, list
);
2671 int handle_verify_ircapture_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2675 if (strcmp(args
[0], "enable") == 0)
2677 jtag_verify_capture_ir
= 1;
2679 else if (strcmp(args
[0], "disable") == 0)
2681 jtag_verify_capture_ir
= 0;
2684 return ERROR_COMMAND_SYNTAX_ERROR
;
2686 } else if (argc
!= 0)
2688 return ERROR_COMMAND_SYNTAX_ERROR
;
2691 command_print(cmd_ctx
, "verify Capture-IR is %s", (jtag_verify_capture_ir
) ? "enabled": "disabled");
2697 int jtag_power_dropout(int *dropout
)
2699 return jtag
->power_dropout(dropout
);
2702 int jtag_srst_asserted(int *srst_asserted
)
2704 return jtag
->srst_asserted(srst_asserted
);
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)