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_tap_t
*jtag_TapByString( const char *s
)
322 if( 0 == strcmp( t
->dotted_name
, s
) ){
328 // backup plan is by number
330 /* ok - is "s" a number? */
332 n
= strtol( s
, &cp
, 0 );
333 if( (s
!= cp
) && (*cp
== 0) ){
335 t
= jtag_TapByAbsPosition(n
);
342 jtag_TapByJimObj( Jim_Interp
*interp
, Jim_Obj
*o
)
347 cp
= Jim_GetString( o
, NULL
);
352 t
= jtag_TapByString( cp
);
355 Jim_SetResult_sprintf(interp
,"Tap: %s is unknown", cp
);
360 /* returns a pointer to the n-th device in the scan chain */
362 jtag_TapByAbsPosition( int n
)
370 while( t
&& (n
> 0)) {
378 int jtag_register_event_callback(int (*callback
)(enum jtag_event event
, void *priv
), void *priv
)
380 jtag_event_callback_t
**callbacks_p
= &jtag_event_callbacks
;
382 if (callback
== NULL
)
384 return ERROR_INVALID_ARGUMENTS
;
389 while ((*callbacks_p
)->next
)
390 callbacks_p
= &((*callbacks_p
)->next
);
391 callbacks_p
= &((*callbacks_p
)->next
);
394 (*callbacks_p
) = malloc(sizeof(jtag_event_callback_t
));
395 (*callbacks_p
)->callback
= callback
;
396 (*callbacks_p
)->priv
= priv
;
397 (*callbacks_p
)->next
= NULL
;
402 int jtag_unregister_event_callback(int (*callback
)(enum jtag_event event
, void *priv
))
404 jtag_event_callback_t
**callbacks_p
= &jtag_event_callbacks
;
406 if (callback
== NULL
)
408 return ERROR_INVALID_ARGUMENTS
;
413 jtag_event_callback_t
**next
= &((*callbacks_p
)->next
);
414 if ((*callbacks_p
)->callback
== callback
)
417 *callbacks_p
= *next
;
425 int jtag_call_event_callbacks(enum jtag_event event
)
427 jtag_event_callback_t
*callback
= jtag_event_callbacks
;
429 LOG_DEBUG("jtag event: %s", jtag_event_strings
[event
]);
433 callback
->callback(event
, callback
->priv
);
434 callback
= callback
->next
;
440 /* returns a pointer to the pointer of the last command in queue
441 * this may be a pointer to the root pointer (jtag_command_queue)
442 * or to the next member of the last but one command
444 jtag_command_t
** jtag_get_last_command_p(void)
446 /* jtag_command_t *cmd = jtag_command_queue;
452 return &jtag_command_queue;
456 return last_comand_pointer
;
460 void* cmd_queue_alloc(size_t size
)
462 cmd_queue_page_t
**p_page
= &cmd_queue_pages
;
468 while ((*p_page
)->next
)
469 p_page
= &((*p_page
)->next
);
470 if (CMD_QUEUE_PAGE_SIZE
- (*p_page
)->used
< size
)
471 p_page
= &((*p_page
)->next
);
476 *p_page
= malloc(sizeof(cmd_queue_page_t
));
478 (*p_page
)->address
= malloc(CMD_QUEUE_PAGE_SIZE
);
479 (*p_page
)->next
= NULL
;
482 offset
= (*p_page
)->used
;
483 (*p_page
)->used
+= size
;
485 t
=(u8
*)((*p_page
)->address
);
489 void cmd_queue_free(void)
491 cmd_queue_page_t
*page
= cmd_queue_pages
;
495 cmd_queue_page_t
*last
= page
;
501 cmd_queue_pages
= NULL
;
504 static void jtag_prelude1(void)
508 LOG_WARNING("JTAG command queued, while TRST is low (TAP in reset)");
509 jtag_error
=ERROR_JTAG_TRST_ASSERTED
;
513 if (cmd_queue_end_state
== TAP_TLR
)
514 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
517 static void jtag_prelude(enum tap_state state
)
522 jtag_add_end_state(state
);
524 cmd_queue_cur_state
= cmd_queue_end_state
;
527 void jtag_add_ir_scan(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
533 retval
=interface_jtag_add_ir_scan(num_fields
, fields
, cmd_queue_end_state
);
534 if (retval
!=ERROR_OK
)
538 int MINIDRIVER(interface_jtag_add_ir_scan
)(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
540 jtag_command_t
**last_cmd
;
548 last_cmd
= jtag_get_last_command_p();
550 /* allocate memory for a new list member */
551 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
552 (*last_cmd
)->next
= NULL
;
553 last_comand_pointer
= &((*last_cmd
)->next
);
554 (*last_cmd
)->type
= JTAG_SCAN
;
556 /* allocate memory for ir scan command */
557 (*last_cmd
)->cmd
.scan
= cmd_queue_alloc(sizeof(scan_command_t
));
558 (*last_cmd
)->cmd
.scan
->ir_scan
= 1;
559 x
= jtag_NumEnabledTaps();
560 (*last_cmd
)->cmd
.scan
->num_fields
= x
; /* one field per device */
561 (*last_cmd
)->cmd
.scan
->fields
= cmd_queue_alloc(x
* sizeof(scan_field_t
));
562 (*last_cmd
)->cmd
.scan
->end_state
= state
;
569 // do this here so it is not forgotten
570 tap
= jtag_NextEnabledTap(tap
);
575 scan_size
= tap
->ir_length
;
576 (*last_cmd
)->cmd
.scan
->fields
[nth_tap
].tap
= tap
;
577 (*last_cmd
)->cmd
.scan
->fields
[nth_tap
].num_bits
= scan_size
;
578 (*last_cmd
)->cmd
.scan
->fields
[nth_tap
].in_value
= NULL
;
579 (*last_cmd
)->cmd
.scan
->fields
[nth_tap
].in_handler
= NULL
; /* disable verification by default */
581 /* search the list */
582 for (j
= 0; j
< num_fields
; j
++)
584 if (tap
== fields
[j
].tap
)
587 (*last_cmd
)->cmd
.scan
->fields
[nth_tap
].out_value
= buf_cpy(fields
[j
].out_value
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
588 (*last_cmd
)->cmd
.scan
->fields
[nth_tap
].out_mask
= buf_cpy(fields
[j
].out_mask
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
590 if (jtag_verify_capture_ir
)
592 if (fields
[j
].in_handler
==NULL
)
594 jtag_set_check_value((*last_cmd
)->cmd
.scan
->fields
+nth_tap
, tap
->expected
, tap
->expected_mask
, NULL
);
597 (*last_cmd
)->cmd
.scan
->fields
[nth_tap
].in_handler
= fields
[j
].in_handler
;
598 (*last_cmd
)->cmd
.scan
->fields
[nth_tap
].in_handler_priv
= fields
[j
].in_handler_priv
;
599 (*last_cmd
)->cmd
.scan
->fields
[nth_tap
].in_check_value
= tap
->expected
;
600 (*last_cmd
)->cmd
.scan
->fields
[nth_tap
].in_check_mask
= tap
->expected_mask
;
611 /* if a tap isn't listed, set it to BYPASS */
612 (*last_cmd
)->cmd
.scan
->fields
[nth_tap
].out_value
= buf_set_ones(cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
613 (*last_cmd
)->cmd
.scan
->fields
[nth_tap
].out_mask
= NULL
;
618 /* update device information */
619 buf_cpy((*last_cmd
)->cmd
.scan
->fields
[nth_tap
].out_value
, tap
->cur_instr
, scan_size
);
625 void jtag_add_plain_ir_scan(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
631 retval
=interface_jtag_add_plain_ir_scan(num_fields
, fields
, cmd_queue_end_state
);
632 if (retval
!=ERROR_OK
)
636 int MINIDRIVER(interface_jtag_add_plain_ir_scan
)(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
639 jtag_command_t
**last_cmd
;
641 last_cmd
= jtag_get_last_command_p();
643 /* allocate memory for a new list member */
644 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
645 (*last_cmd
)->next
= NULL
;
646 last_comand_pointer
= &((*last_cmd
)->next
);
647 (*last_cmd
)->type
= JTAG_SCAN
;
649 /* allocate memory for ir scan command */
650 (*last_cmd
)->cmd
.scan
= cmd_queue_alloc(sizeof(scan_command_t
));
651 (*last_cmd
)->cmd
.scan
->ir_scan
= 1;
652 (*last_cmd
)->cmd
.scan
->num_fields
= num_fields
;
653 (*last_cmd
)->cmd
.scan
->fields
= cmd_queue_alloc(num_fields
* sizeof(scan_field_t
));
654 (*last_cmd
)->cmd
.scan
->end_state
= state
;
656 for( i
= 0 ; i
< num_fields
; i
++ ){
657 int num_bits
= fields
[i
].num_bits
;
658 int num_bytes
= CEIL(fields
[i
].num_bits
, 8);
659 (*last_cmd
)->cmd
.scan
->fields
[i
].tap
= fields
[i
].tap
;
660 (*last_cmd
)->cmd
.scan
->fields
[i
].num_bits
= num_bits
;
661 (*last_cmd
)->cmd
.scan
->fields
[i
].out_value
= buf_cpy(fields
[i
].out_value
, cmd_queue_alloc(num_bytes
), num_bits
);
662 (*last_cmd
)->cmd
.scan
->fields
[i
].out_mask
= buf_cpy(fields
[i
].out_mask
, cmd_queue_alloc(num_bytes
), num_bits
);
663 (*last_cmd
)->cmd
.scan
->fields
[i
].in_value
= fields
[i
].in_value
;
664 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_value
= fields
[i
].in_check_value
;
665 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_mask
= fields
[i
].in_check_mask
;
666 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler
= NULL
;
667 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler_priv
= NULL
;
672 void jtag_add_dr_scan(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
678 retval
=interface_jtag_add_dr_scan(num_fields
, fields
, cmd_queue_end_state
);
679 if (retval
!=ERROR_OK
)
683 int MINIDRIVER(interface_jtag_add_dr_scan
)(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
687 int bypass_devices
= 0;
691 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
694 /* count devices in bypass */
698 tap
= jtag_NextEnabledTap(tap
);
707 /* allocate memory for a new list member */
708 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
709 last_comand_pointer
= &((*last_cmd
)->next
);
710 (*last_cmd
)->next
= NULL
;
711 (*last_cmd
)->type
= JTAG_SCAN
;
713 /* allocate memory for dr scan command */
714 (*last_cmd
)->cmd
.scan
= cmd_queue_alloc(sizeof(scan_command_t
));
715 (*last_cmd
)->cmd
.scan
->ir_scan
= 0;
716 (*last_cmd
)->cmd
.scan
->num_fields
= num_fields
+ bypass_devices
;
717 (*last_cmd
)->cmd
.scan
->fields
= cmd_queue_alloc((num_fields
+ bypass_devices
) * sizeof(scan_field_t
));
718 (*last_cmd
)->cmd
.scan
->end_state
= state
;
724 tap
= jtag_NextEnabledTap(tap
);
729 (*last_cmd
)->cmd
.scan
->fields
[field_count
].tap
= tap
;
731 for (j
= 0; j
< num_fields
; j
++)
733 if (tap
== fields
[j
].tap
)
736 scan_size
= fields
[j
].num_bits
;
737 (*last_cmd
)->cmd
.scan
->fields
[field_count
].num_bits
= scan_size
;
738 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_value
= buf_cpy(fields
[j
].out_value
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
739 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_mask
= buf_cpy(fields
[j
].out_mask
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
740 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_value
= fields
[j
].in_value
;
741 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_check_value
= fields
[j
].in_check_value
;
742 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_check_mask
= fields
[j
].in_check_mask
;
743 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_handler
= fields
[j
].in_handler
;
744 (*last_cmd
)->cmd
.scan
->fields
[field_count
++].in_handler_priv
= fields
[j
].in_handler_priv
;
749 #ifdef _DEBUG_JTAG_IO_
750 /* if a device isn't listed, the BYPASS register should be selected */
753 LOG_ERROR("BUG: no scan data for a device not in BYPASS");
757 /* program the scan field to 1 bit length, and ignore it's value */
758 (*last_cmd
)->cmd
.scan
->fields
[field_count
].num_bits
= 1;
759 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_value
= NULL
;
760 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_mask
= NULL
;
761 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_value
= NULL
;
762 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_check_value
= NULL
;
763 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_check_mask
= NULL
;
764 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_handler
= NULL
;
765 (*last_cmd
)->cmd
.scan
->fields
[field_count
++].in_handler_priv
= NULL
;
769 #ifdef _DEBUG_JTAG_IO_
770 /* if a device is listed, the BYPASS register must not be selected */
773 LOG_ERROR("BUG: scan data for a device in BYPASS");
782 void MINIDRIVER(interface_jtag_add_dr_out
)(jtag_tap_t
*target_tap
,
786 enum tap_state end_state
)
791 int bypass_devices
= 0;
793 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
796 /* count devices in bypass */
800 tap
= jtag_NextEnabledTap(tap
);
809 /* allocate memory for a new list member */
810 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
811 last_comand_pointer
= &((*last_cmd
)->next
);
812 (*last_cmd
)->next
= NULL
;
813 (*last_cmd
)->type
= JTAG_SCAN
;
815 /* allocate memory for dr scan command */
816 (*last_cmd
)->cmd
.scan
= cmd_queue_alloc(sizeof(scan_command_t
));
817 (*last_cmd
)->cmd
.scan
->ir_scan
= 0;
818 (*last_cmd
)->cmd
.scan
->num_fields
= num_fields
+ bypass_devices
;
819 (*last_cmd
)->cmd
.scan
->fields
= cmd_queue_alloc((num_fields
+ bypass_devices
) * sizeof(scan_field_t
));
820 (*last_cmd
)->cmd
.scan
->end_state
= end_state
;
825 tap
= jtag_NextEnabledTap(tap
);
830 (*last_cmd
)->cmd
.scan
->fields
[field_count
].tap
= tap
;
832 if (tap
== target_tap
)
835 #ifdef _DEBUG_JTAG_IO_
836 /* if a device is listed, the BYPASS register must not be selected */
839 LOG_ERROR("BUG: scan data for a device in BYPASS");
843 for (j
= 0; j
< num_fields
; j
++)
846 scan_size
= num_bits
[j
];
847 buf_set_u32(out_value
, 0, scan_size
, value
[j
]);
848 (*last_cmd
)->cmd
.scan
->fields
[field_count
].num_bits
= scan_size
;
849 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_value
= buf_cpy(out_value
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
850 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_mask
= NULL
;
851 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_value
= NULL
;
852 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_check_value
= NULL
;
853 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_check_mask
= NULL
;
854 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_handler
= NULL
;
855 (*last_cmd
)->cmd
.scan
->fields
[field_count
++].in_handler_priv
= NULL
;
859 #ifdef _DEBUG_JTAG_IO_
860 /* if a device isn't listed, the BYPASS register should be selected */
863 LOG_ERROR("BUG: no scan data for a device not in BYPASS");
867 /* program the scan field to 1 bit length, and ignore it's value */
868 (*last_cmd
)->cmd
.scan
->fields
[field_count
].num_bits
= 1;
869 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_value
= NULL
;
870 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_mask
= NULL
;
871 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_value
= NULL
;
872 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_check_value
= NULL
;
873 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_check_mask
= NULL
;
874 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_handler
= NULL
;
875 (*last_cmd
)->cmd
.scan
->fields
[field_count
++].in_handler_priv
= NULL
;
880 void jtag_add_plain_dr_scan(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
886 retval
=interface_jtag_add_plain_dr_scan(num_fields
, fields
, cmd_queue_end_state
);
887 if (retval
!=ERROR_OK
)
891 int MINIDRIVER(interface_jtag_add_plain_dr_scan
)(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
894 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
896 /* allocate memory for a new list member */
897 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
898 last_comand_pointer
= &((*last_cmd
)->next
);
899 (*last_cmd
)->next
= NULL
;
900 (*last_cmd
)->type
= JTAG_SCAN
;
902 /* allocate memory for scan command */
903 (*last_cmd
)->cmd
.scan
= cmd_queue_alloc(sizeof(scan_command_t
));
904 (*last_cmd
)->cmd
.scan
->ir_scan
= 0;
905 (*last_cmd
)->cmd
.scan
->num_fields
= num_fields
;
906 (*last_cmd
)->cmd
.scan
->fields
= cmd_queue_alloc(num_fields
* sizeof(scan_field_t
));
907 (*last_cmd
)->cmd
.scan
->end_state
= state
;
909 for (i
= 0; i
< num_fields
; i
++)
911 int num_bits
= fields
[i
].num_bits
;
912 int num_bytes
= CEIL(fields
[i
].num_bits
, 8);
913 (*last_cmd
)->cmd
.scan
->fields
[i
].tap
= fields
[i
].tap
;
914 (*last_cmd
)->cmd
.scan
->fields
[i
].num_bits
= num_bits
;
915 (*last_cmd
)->cmd
.scan
->fields
[i
].out_value
= buf_cpy(fields
[i
].out_value
, cmd_queue_alloc(num_bytes
), num_bits
);
916 (*last_cmd
)->cmd
.scan
->fields
[i
].out_mask
= buf_cpy(fields
[i
].out_mask
, cmd_queue_alloc(num_bytes
), num_bits
);
917 (*last_cmd
)->cmd
.scan
->fields
[i
].in_value
= fields
[i
].in_value
;
918 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_value
= fields
[i
].in_check_value
;
919 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_mask
= fields
[i
].in_check_mask
;
920 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler
= fields
[i
].in_handler
;
921 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler_priv
= fields
[i
].in_handler_priv
;
927 void jtag_add_tlr(void)
929 jtag_prelude(TAP_TLR
);
932 retval
=interface_jtag_add_tlr();
933 if (retval
!=ERROR_OK
)
937 int MINIDRIVER(interface_jtag_add_tlr
)()
939 enum tap_state state
= TAP_TLR
;
940 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
942 /* allocate memory for a new list member */
943 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
944 last_comand_pointer
= &((*last_cmd
)->next
);
945 (*last_cmd
)->next
= NULL
;
946 (*last_cmd
)->type
= JTAG_STATEMOVE
;
948 (*last_cmd
)->cmd
.statemove
= cmd_queue_alloc(sizeof(statemove_command_t
));
949 (*last_cmd
)->cmd
.statemove
->end_state
= state
;
955 void jtag_add_pathmove(int num_states
, enum tap_state
*path
)
957 enum tap_state cur_state
=cmd_queue_cur_state
;
961 /* the last state has to be a stable state */
962 if (tap_move_map
[path
[num_states
- 1]] == -1)
964 LOG_ERROR("BUG: TAP path doesn't finish in a stable state");
968 for (i
=0; i
<num_states
; i
++)
970 if (path
[i
] == TAP_TLR
)
972 LOG_ERROR("BUG: TAP_TLR is not a valid state for pathmove sequences");
975 if ((tap_transitions
[cur_state
].low
!= path
[i
])&&
976 (tap_transitions
[cur_state
].high
!= path
[i
]))
978 LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_strings
[cur_state
], tap_state_strings
[path
[i
]]);
987 retval
=interface_jtag_add_pathmove(num_states
, path
);
988 cmd_queue_cur_state
= path
[num_states
- 1];
989 if (retval
!=ERROR_OK
)
993 int MINIDRIVER(interface_jtag_add_pathmove
)(int num_states
, enum tap_state
*path
)
995 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
998 /* allocate memory for a new list member */
999 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
1000 last_comand_pointer
= &((*last_cmd
)->next
);
1001 (*last_cmd
)->next
= NULL
;
1002 (*last_cmd
)->type
= JTAG_PATHMOVE
;
1004 (*last_cmd
)->cmd
.pathmove
= cmd_queue_alloc(sizeof(pathmove_command_t
));
1005 (*last_cmd
)->cmd
.pathmove
->num_states
= num_states
;
1006 (*last_cmd
)->cmd
.pathmove
->path
= cmd_queue_alloc(sizeof(enum tap_state
) * num_states
);
1008 for (i
= 0; i
< num_states
; i
++)
1009 (*last_cmd
)->cmd
.pathmove
->path
[i
] = path
[i
];
1014 int MINIDRIVER(interface_jtag_add_runtest
)(int num_cycles
, enum tap_state state
)
1016 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
1018 /* allocate memory for a new list member */
1019 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
1020 (*last_cmd
)->next
= NULL
;
1021 last_comand_pointer
= &((*last_cmd
)->next
);
1022 (*last_cmd
)->type
= JTAG_RUNTEST
;
1024 (*last_cmd
)->cmd
.runtest
= cmd_queue_alloc(sizeof(runtest_command_t
));
1025 (*last_cmd
)->cmd
.runtest
->num_cycles
= num_cycles
;
1026 (*last_cmd
)->cmd
.runtest
->end_state
= state
;
1031 void jtag_add_runtest(int num_cycles
, enum tap_state state
)
1035 jtag_prelude(state
);
1037 /* executed by sw or hw fifo */
1038 retval
=interface_jtag_add_runtest(num_cycles
, cmd_queue_end_state
);
1039 if (retval
!=ERROR_OK
)
1043 void jtag_add_reset(int req_tlr_or_trst
, int req_srst
)
1045 int trst_with_tlr
= 0;
1048 /* FIX!!! there are *many* different cases here. A better
1049 * approach is needed for legal combinations of transitions...
1051 if ((jtag_reset_config
& RESET_HAS_SRST
)&&
1052 (jtag_reset_config
& RESET_HAS_TRST
)&&
1053 ((jtag_reset_config
& RESET_SRST_PULLS_TRST
)==0))
1055 if (((req_tlr_or_trst
&&!jtag_trst
)||
1056 (!req_tlr_or_trst
&&jtag_trst
))&&
1057 ((req_srst
&&!jtag_srst
)||
1058 (!req_srst
&&jtag_srst
)))
1060 /* FIX!!! srst_pulls_trst allows 1,1 => 0,0 transition.... */
1061 //LOG_ERROR("BUG: transition of req_tlr_or_trst and req_srst in the same jtag_add_reset() call is undefined");
1065 /* Make sure that jtag_reset_config allows the requested reset */
1066 /* if SRST pulls TRST, we can't fulfill srst == 1 with trst == 0 */
1067 if (((jtag_reset_config
& RESET_SRST_PULLS_TRST
) && (req_srst
== 1)) && (!req_tlr_or_trst
))
1069 LOG_ERROR("BUG: requested reset would assert trst");
1070 jtag_error
=ERROR_FAIL
;
1074 /* if TRST pulls SRST, we reset with TAP T-L-R */
1075 if (((jtag_reset_config
& RESET_TRST_PULLS_SRST
) && (req_tlr_or_trst
)) && (req_srst
== 0))
1080 if (req_srst
&& !(jtag_reset_config
& RESET_HAS_SRST
))
1082 LOG_ERROR("BUG: requested SRST assertion, but the current configuration doesn't support this");
1083 jtag_error
=ERROR_FAIL
;
1087 if (req_tlr_or_trst
)
1089 if (!trst_with_tlr
&& (jtag_reset_config
& RESET_HAS_TRST
))
1101 jtag_srst
= req_srst
;
1103 retval
= interface_jtag_add_reset(jtag_trst
, jtag_srst
);
1104 if (retval
!=ERROR_OK
)
1112 LOG_DEBUG("SRST line asserted");
1116 LOG_DEBUG("SRST line released");
1117 if (jtag_nsrst_delay
)
1118 jtag_add_sleep(jtag_nsrst_delay
* 1000);
1123 LOG_DEBUG("JTAG reset with TLR instead of TRST");
1124 jtag_add_end_state(TAP_TLR
);
1126 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
1132 /* we just asserted nTRST, so we're now in Test-Logic-Reset,
1133 * and inform possible listeners about this
1135 LOG_DEBUG("TRST line asserted");
1136 cmd_queue_cur_state
= TAP_TLR
;
1137 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
1141 if (jtag_ntrst_delay
)
1142 jtag_add_sleep(jtag_ntrst_delay
* 1000);
1146 int MINIDRIVER(interface_jtag_add_reset
)(int req_trst
, int req_srst
)
1148 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
1150 /* allocate memory for a new list member */
1151 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
1152 (*last_cmd
)->next
= NULL
;
1153 last_comand_pointer
= &((*last_cmd
)->next
);
1154 (*last_cmd
)->type
= JTAG_RESET
;
1156 (*last_cmd
)->cmd
.reset
= cmd_queue_alloc(sizeof(reset_command_t
));
1157 (*last_cmd
)->cmd
.reset
->trst
= req_trst
;
1158 (*last_cmd
)->cmd
.reset
->srst
= req_srst
;
1163 void jtag_add_end_state(enum tap_state state
)
1165 cmd_queue_end_state
= state
;
1166 if ((cmd_queue_end_state
== TAP_SD
)||(cmd_queue_end_state
== TAP_SI
))
1168 LOG_ERROR("BUG: TAP_SD/SI can't be end state. Calling code should use a larger scan field");
1172 int MINIDRIVER(interface_jtag_add_sleep
)(u32 us
)
1174 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
1176 /* allocate memory for a new list member */
1177 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
1178 (*last_cmd
)->next
= NULL
;
1179 last_comand_pointer
= &((*last_cmd
)->next
);
1180 (*last_cmd
)->type
= JTAG_SLEEP
;
1182 (*last_cmd
)->cmd
.sleep
= cmd_queue_alloc(sizeof(sleep_command_t
));
1183 (*last_cmd
)->cmd
.sleep
->us
= us
;
1188 void jtag_add_sleep(u32 us
)
1190 keep_alive(); /* we might be running on a very slow JTAG clk */
1191 int retval
=interface_jtag_add_sleep(us
);
1192 if (retval
!=ERROR_OK
)
1197 int jtag_scan_size(scan_command_t
*cmd
)
1202 /* count bits in scan command */
1203 for (i
= 0; i
< cmd
->num_fields
; i
++)
1205 bit_count
+= cmd
->fields
[i
].num_bits
;
1211 int jtag_build_buffer(scan_command_t
*cmd
, u8
**buffer
)
1216 bit_count
= jtag_scan_size(cmd
);
1217 *buffer
= malloc(CEIL(bit_count
, 8));
1221 for (i
= 0; i
< cmd
->num_fields
; i
++)
1223 if (cmd
->fields
[i
].out_value
)
1225 #ifdef _DEBUG_JTAG_IO_
1226 char* char_buf
= buf_to_str(cmd
->fields
[i
].out_value
, (cmd
->fields
[i
].num_bits
> 64) ? 64 : cmd
->fields
[i
].num_bits
, 16);
1228 buf_set_buf(cmd
->fields
[i
].out_value
, 0, *buffer
, bit_count
, cmd
->fields
[i
].num_bits
);
1229 #ifdef _DEBUG_JTAG_IO_
1230 LOG_DEBUG("fields[%i].out_value: 0x%s", i
, char_buf
);
1235 bit_count
+= cmd
->fields
[i
].num_bits
;
1241 int jtag_read_buffer(u8
*buffer
, scan_command_t
*cmd
)
1247 /* we return ERROR_OK, unless a check fails, or a handler reports a problem */
1250 for (i
= 0; i
< cmd
->num_fields
; i
++)
1252 /* if neither in_value nor in_handler
1253 * are specified we don't have to examine this field
1255 if (cmd
->fields
[i
].in_value
|| cmd
->fields
[i
].in_handler
)
1257 int num_bits
= cmd
->fields
[i
].num_bits
;
1258 u8
*captured
= buf_set_buf(buffer
, bit_count
, malloc(CEIL(num_bits
, 8)), 0, num_bits
);
1260 #ifdef _DEBUG_JTAG_IO_
1263 char_buf
= buf_to_str(captured
, (num_bits
> 64) ? 64 : num_bits
, 16);
1264 LOG_DEBUG("fields[%i].in_value: 0x%s", i
, char_buf
);
1268 if (cmd
->fields
[i
].in_value
)
1270 buf_cpy(captured
, cmd
->fields
[i
].in_value
, num_bits
);
1272 if (cmd
->fields
[i
].in_handler
)
1274 if (cmd
->fields
[i
].in_handler(cmd
->fields
[i
].in_value
, cmd
->fields
[i
].in_handler_priv
, cmd
->fields
+i
) != ERROR_OK
)
1276 LOG_WARNING("in_handler reported a failed check");
1277 retval
= ERROR_JTAG_QUEUE_FAILED
;
1282 /* no in_value specified, but a handler takes care of the scanned data */
1283 if (cmd
->fields
[i
].in_handler
&& (!cmd
->fields
[i
].in_value
))
1285 if (cmd
->fields
[i
].in_handler(captured
, cmd
->fields
[i
].in_handler_priv
, cmd
->fields
+i
) != ERROR_OK
)
1287 /* We're going to call the error:handler later, but if the in_handler
1288 * reported an error we report this failure upstream
1290 LOG_WARNING("in_handler reported a failed check");
1291 retval
= ERROR_JTAG_QUEUE_FAILED
;
1297 bit_count
+= cmd
->fields
[i
].num_bits
;
1303 int jtag_check_value(u8
*captured
, void *priv
, scan_field_t
*field
)
1305 int retval
= ERROR_OK
;
1306 int num_bits
= field
->num_bits
;
1308 int compare_failed
= 0;
1310 if (field
->in_check_mask
)
1311 compare_failed
= buf_cmp_mask(captured
, field
->in_check_value
, field
->in_check_mask
, num_bits
);
1313 compare_failed
= buf_cmp(captured
, field
->in_check_value
, num_bits
);
1315 if (compare_failed
){
1316 /* An error handler could have caught the failing check
1317 * only report a problem when there wasn't a handler, or if the handler
1318 * acknowledged the error
1320 LOG_WARNING("TAP %s:",
1321 (field
->tap
== NULL
) ? "(unknown)" : field
->tap
->dotted_name
);
1324 char *captured_char
= buf_to_str(captured
, (num_bits
> 64) ? 64 : num_bits
, 16);
1325 char *in_check_value_char
= buf_to_str(field
->in_check_value
, (num_bits
> 64) ? 64 : num_bits
, 16);
1327 if (field
->in_check_mask
)
1329 char *in_check_mask_char
;
1330 in_check_mask_char
= buf_to_str(field
->in_check_mask
, (num_bits
> 64) ? 64 : num_bits
, 16);
1331 LOG_WARNING("value captured during scan didn't pass the requested check:");
1332 LOG_WARNING("captured: 0x%s check_value: 0x%s check_mask: 0x%s",
1333 captured_char
, in_check_value_char
, in_check_mask_char
);
1334 free(in_check_mask_char
);
1338 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
);
1341 free(captured_char
);
1342 free(in_check_value_char
);
1344 retval
= ERROR_JTAG_QUEUE_FAILED
;
1352 set up checking of this field using the in_handler. The values passed in must be valid until
1353 after jtag_execute() has completed.
1355 void jtag_set_check_value(scan_field_t
*field
, u8
*value
, u8
*mask
, error_handler_t
*in_error_handler
)
1358 field
->in_handler
= jtag_check_value
;
1360 field
->in_handler
= NULL
; /* No check, e.g. embeddedice uses value==NULL to indicate no check */
1361 field
->in_handler_priv
= NULL
;
1362 field
->in_check_value
= value
;
1363 field
->in_check_mask
= mask
;
1366 enum scan_type
jtag_scan_type(scan_command_t
*cmd
)
1371 for (i
= 0; i
< cmd
->num_fields
; i
++)
1373 if (cmd
->fields
[i
].in_value
|| cmd
->fields
[i
].in_handler
)
1375 if (cmd
->fields
[i
].out_value
)
1382 int MINIDRIVER(interface_jtag_execute_queue
)(void)
1388 LOG_ERROR("No JTAG interface configured yet. Issue 'init' command in startup scripts before communicating with targets.");
1392 retval
= jtag
->execute_queue();
1396 jtag_command_queue
= NULL
;
1397 last_comand_pointer
= &jtag_command_queue
;
1402 int jtag_execute_queue(void)
1404 int retval
=interface_jtag_execute_queue();
1405 if (retval
==ERROR_OK
)
1409 jtag_error
=ERROR_OK
;
1413 int jtag_reset_callback(enum jtag_event event
, void *priv
)
1415 jtag_tap_t
*tap
= priv
;
1419 if (event
== JTAG_TRST_ASSERTED
)
1421 buf_set_ones(tap
->cur_instr
, tap
->ir_length
);
1428 void jtag_sleep(u32 us
)
1430 alive_sleep(us
/1000);
1433 /* Try to examine chain layout according to IEEE 1149.1 §12
1435 int jtag_examine_chain(void)
1439 u8 idcode_buffer
[JTAG_MAX_CHAIN_SIZE
* 4];
1442 int device_count
= 0;
1443 u8 zero_check
= 0x0;
1444 u8 one_check
= 0xff;
1447 field
.num_bits
= sizeof(idcode_buffer
) * 8;
1448 field
.out_value
= idcode_buffer
;
1449 field
.out_mask
= NULL
;
1450 field
.in_value
= idcode_buffer
;
1451 field
.in_check_value
= NULL
;
1452 field
.in_check_mask
= NULL
;
1453 field
.in_handler
= NULL
;
1454 field
.in_handler_priv
= NULL
;
1456 for (i
= 0; i
< JTAG_MAX_CHAIN_SIZE
; i
++)
1458 buf_set_u32(idcode_buffer
, i
* 32, 32, 0x000000FF);
1461 jtag_add_plain_dr_scan(1, &field
, TAP_TLR
);
1462 jtag_execute_queue();
1464 for (i
= 0; i
< JTAG_MAX_CHAIN_SIZE
* 4; i
++)
1466 zero_check
|= idcode_buffer
[i
];
1467 one_check
&= idcode_buffer
[i
];
1470 /* if there wasn't a single non-zero bit or if all bits were one, the scan isn't valid */
1471 if ((zero_check
== 0x00) || (one_check
== 0xff))
1473 LOG_ERROR("JTAG communication failure, check connection, JTAG interface, target power etc.");
1474 return ERROR_JTAG_INIT_FAILED
;
1477 // point at the 1st tap
1478 tap
= jtag_NextEnabledTap(NULL
);
1480 LOG_ERROR("JTAG: No taps enabled?");
1481 return ERROR_JTAG_INIT_FAILED
;
1484 for (bit_count
= 0; bit_count
< (JTAG_MAX_CHAIN_SIZE
* 32) - 31;)
1486 u32 idcode
= buf_get_u32(idcode_buffer
, bit_count
, 32);
1487 if ((idcode
& 1) == 0)
1489 /* LSB must not be 0, this indicates a device in bypass */
1490 LOG_WARNING("Tap/Device does not have IDCODE");
1501 if (idcode
== 0x000000FF)
1504 /* End of chain (invalid manufacturer ID)
1506 * The JTAG examine is the very first thing that happens
1508 * A single JTAG device requires only 64 bits to be read back correctly.
1510 * The code below adds a check that the rest of the data scanned (640 bits)
1511 * are all as expected. This helps diagnose/catch problems with the JTAG chain
1513 * earlier and gives more helpful/explicit error messages.
1515 for (bit_count
+= 32; bit_count
< (JTAG_MAX_CHAIN_SIZE
* 32) - 31;bit_count
+= 32)
1517 idcode
= buf_get_u32(idcode_buffer
, bit_count
, 32);
1518 if (unexpected
||(idcode
!= 0x000000FF))
1520 LOG_WARNING("Unexpected idcode after end of chain! %d 0x%08x", bit_count
, idcode
);
1528 #define EXTRACT_MFG(X) (((X) & 0xffe) >> 1)
1529 manufacturer
= EXTRACT_MFG(idcode
);
1530 #define EXTRACT_PART(X) (((X) & 0xffff000) >> 12)
1531 part
= EXTRACT_PART(idcode
);
1532 #define EXTRACT_VER(X) (((X) & 0xf0000000) >> 28)
1533 version
= EXTRACT_VER(idcode
);
1535 LOG_INFO("JTAG tap: %s tap/device found: 0x%8.8x (Manufacturer: 0x%3.3x, Part: 0x%4.4x, Version: 0x%1.1x)",
1536 ((tap
!= NULL
) ? (tap
->dotted_name
) : "(not-named)"),
1537 idcode
, manufacturer
, part
, version
);
1543 tap
->idcode
= idcode
;
1544 if( tap
->expected_id
){
1545 if( tap
->idcode
!= tap
->expected_id
){
1546 LOG_ERROR("ERROR: Tap: %s - Expected id: 0x%08x, Got: 0x%08x",
1550 LOG_ERROR("ERROR: expected: mfg: 0x%3.3x, part: 0x%4.4x, ver: 0x%1.1x",
1551 EXTRACT_MFG( tap
->expected_id
),
1552 EXTRACT_PART( tap
->expected_id
),
1553 EXTRACT_VER( tap
->expected_id
) );
1554 LOG_ERROR("ERROR: got: mfg: 0x%3.3x, part: 0x%4.4x, ver: 0x%1.1x",
1555 EXTRACT_MFG( tap
->idcode
),
1556 EXTRACT_PART( tap
->idcode
),
1557 EXTRACT_VER( tap
->idcode
) );
1559 LOG_INFO("JTAG Tap/device matched");
1563 LOG_INFO("JTAG TAP ID: 0x%08x - Unknown - please report (A) chipname and (B) idcode to the openocd project",
1567 tap
= jtag_NextEnabledTap(tap
);
1572 /* see if number of discovered devices matches configuration */
1573 if (device_count
!= jtag_NumEnabledTaps())
1575 LOG_ERROR("number of discovered devices in JTAG chain (%i) doesn't match (enabled) configuration (%i), total taps: %d",
1576 device_count
, jtag_NumEnabledTaps(), jtag_NumTotalTaps());
1577 LOG_ERROR("check the config file and ensure proper JTAG communication (connections, speed, ...)");
1578 return ERROR_JTAG_INIT_FAILED
;
1584 int jtag_validate_chain(void)
1587 int total_ir_length
= 0;
1593 total_ir_length
= 0;
1595 tap
= jtag_NextEnabledTap(tap
);
1599 total_ir_length
+= tap
->ir_length
;
1602 total_ir_length
+= 2;
1603 ir_test
= malloc(CEIL(total_ir_length
, 8));
1604 buf_set_ones(ir_test
, total_ir_length
);
1607 field
.num_bits
= total_ir_length
;
1608 field
.out_value
= ir_test
;
1609 field
.out_mask
= NULL
;
1610 field
.in_value
= ir_test
;
1611 field
.in_check_value
= NULL
;
1612 field
.in_check_mask
= NULL
;
1613 field
.in_handler
= NULL
;
1614 field
.in_handler_priv
= NULL
;
1616 jtag_add_plain_ir_scan(1, &field
, TAP_TLR
);
1617 jtag_execute_queue();
1622 tap
= jtag_NextEnabledTap(tap
);
1628 if (buf_get_u32(ir_test
, chain_pos
, 2) != 0x1)
1630 char *cbuf
= buf_to_str(ir_test
, total_ir_length
, 16);
1631 LOG_ERROR("Error validating JTAG scan chain, IR mismatch, scan returned 0x%s", cbuf
);
1634 return ERROR_JTAG_INIT_FAILED
;
1636 chain_pos
+= tap
->ir_length
;
1639 if (buf_get_u32(ir_test
, chain_pos
, 2) != 0x3)
1641 char *cbuf
= buf_to_str(ir_test
, total_ir_length
, 16);
1642 LOG_ERROR("Error validating JTAG scan chain, IR mismatch, scan returned 0x%s", cbuf
);
1645 return ERROR_JTAG_INIT_FAILED
;
1655 jim_newtap_cmd( Jim_GetOptInfo
*goi
)
1665 const Jim_Nvp opts
[] = {
1666 #define NTAP_OPT_IRLEN 0
1667 { .name
= "-irlen" , .value
= NTAP_OPT_IRLEN
},
1668 #define NTAP_OPT_IRMASK 1
1669 { .name
= "-irmask" , .value
= NTAP_OPT_IRMASK
},
1670 #define NTAP_OPT_IRCAPTURE 2
1671 { .name
= "-ircapture" , .value
= NTAP_OPT_IRCAPTURE
},
1672 #define NTAP_OPT_ENABLED 3
1673 { .name
= "-enable" , .value
= NTAP_OPT_ENABLED
},
1674 #define NTAP_OPT_DISABLED 4
1675 { .name
= "-disable" , .value
= NTAP_OPT_DISABLED
},
1676 #define NTAP_OPT_EXPECTED_ID 5
1677 { .name
= "-expected-id" , .value
= NTAP_OPT_EXPECTED_ID
},
1678 { .name
= NULL
, .value
= -1 },
1682 pTap
= malloc( sizeof(jtag_tap_t
) );
1683 memset( pTap
, 0, sizeof(*pTap
) );
1685 Jim_SetResult_sprintf( goi
->interp
, "no memory");
1689 // we expect CHIP + TAP + OPTIONS
1691 if( goi
->argc
< 3 ){
1692 Jim_SetResult_sprintf(goi
->interp
, "Missing CHIP TAP OPTIONS ....");
1695 Jim_GetOpt_String( goi
, &cp
, NULL
);
1696 pTap
->chip
= strdup(cp
);
1698 Jim_GetOpt_String( goi
, &cp
, NULL
);
1699 pTap
->tapname
= strdup(cp
);
1701 // name + dot + name + null
1702 x
= strlen(pTap
->chip
) + 1 + strlen(pTap
->tapname
) + 1;
1704 sprintf( cp
, "%s.%s", pTap
->chip
, pTap
->tapname
);
1705 pTap
->dotted_name
= cp
;
1707 LOG_DEBUG("Creating New Tap, Chip: %s, Tap: %s, Dotted: %s, %d params",
1708 pTap
->chip
, pTap
->tapname
, pTap
->dotted_name
, goi
->argc
);
1711 // default is enabled
1714 // deal with options
1715 #define NTREQ_IRLEN 1
1716 #define NTREQ_IRCAPTURE 2
1717 #define NTREQ_IRMASK 4
1719 // clear them as we find them
1720 reqbits
= (NTREQ_IRLEN
| NTREQ_IRCAPTURE
| NTREQ_IRMASK
);
1723 e
= Jim_GetOpt_Nvp( goi
, opts
, &n
);
1725 Jim_GetOpt_NvpUnknown( goi
, opts
, 0 );
1728 LOG_DEBUG("Processing option: %s", n
->name
);
1730 case NTAP_OPT_ENABLED
:
1733 case NTAP_OPT_DISABLED
:
1736 case NTAP_OPT_EXPECTED_ID
:
1737 e
= Jim_GetOpt_Wide( goi
, &w
);
1738 pTap
->expected_id
= w
;
1740 case NTAP_OPT_IRLEN
:
1741 case NTAP_OPT_IRMASK
:
1742 case NTAP_OPT_IRCAPTURE
:
1743 e
= Jim_GetOpt_Wide( goi
, &w
);
1745 Jim_SetResult_sprintf( goi
->interp
, "option: %s bad parameter", n
->name
);
1748 if( (w
< 0) || (w
> 0xffff) ){
1750 Jim_SetResult_sprintf( goi
->interp
, "option: %s - wacky value: %d (0x%x)",
1751 n
->name
, (int)(w
), (int)(w
));
1755 case NTAP_OPT_IRLEN
:
1756 pTap
->ir_length
= w
;
1757 reqbits
&= (~(NTREQ_IRLEN
));
1759 case NTAP_OPT_IRMASK
:
1760 pTap
->ir_capture_mask
= w
;
1761 reqbits
&= (~(NTREQ_IRMASK
));
1763 case NTAP_OPT_IRCAPTURE
:
1764 pTap
->ir_capture_value
= w
;
1765 reqbits
&= (~(NTREQ_IRCAPTURE
));
1768 } // switch(n->value)
1769 } // while( goi->argc )
1771 // Did we get all the options?
1774 Jim_SetResult_sprintf( goi
->interp
,
1775 "newtap: %s missing required parameters",
1777 // fixme: Tell user what is missing :-(
1778 // no memory leaks pelase
1779 free(((void *)(pTap
->chip
)));
1780 free(((void *)(pTap
->tapname
)));
1781 free(((void *)(pTap
->dotted_name
)));
1782 free(((void *)(pTap
)));
1786 pTap
->expected
= malloc( pTap
->ir_length
);
1787 pTap
->expected_mask
= malloc( pTap
->ir_length
);
1788 pTap
->cur_instr
= malloc( pTap
->ir_length
);
1790 buf_set_u32( pTap
->expected
,
1793 pTap
->ir_capture_value
);
1794 buf_set_u32( pTap
->expected_mask
,
1797 pTap
->ir_capture_mask
);
1798 buf_set_ones( pTap
->cur_instr
,
1804 jtag_register_event_callback(jtag_reset_callback
, pTap
);
1806 ppTap
= &(jtag_all_taps
);
1807 while( (*ppTap
) != NULL
){
1808 ppTap
= &((*ppTap
)->next_tap
);
1812 static int n_taps
= 0;
1813 pTap
->abs_chain_position
= n_taps
++;
1815 LOG_DEBUG( "Created Tap: %s @ abs position %d, irlen %d, capture: 0x%x mask: 0x%x",
1816 (*ppTap
)->dotted_name
,
1817 (*ppTap
)->abs_chain_position
,
1818 (*ppTap
)->ir_length
,
1819 (*ppTap
)->ir_capture_value
,
1820 (*ppTap
)->ir_capture_mask
);
1828 jim_jtag_command( Jim_Interp
*interp
, int argc
, Jim_Obj
*const *argv
)
1833 struct command_context_s
*context
;
1837 JTAG_CMD_INIT_RESET
,
1840 JTAG_CMD_TAPDISABLE
,
1841 JTAG_CMD_TAPISENABLED
1844 const Jim_Nvp jtag_cmds
[] = {
1845 { .name
= "interface" , .value
= JTAG_CMD_INTERFACE
},
1846 { .name
= "arp_init-reset", .value
= JTAG_CMD_INIT_RESET
},
1847 { .name
= "newtap" , .value
= JTAG_CMD_NEWTAP
},
1848 { .name
= "tapisenabled" , .value
= JTAG_CMD_TAPISENABLED
},
1849 { .name
= "tapenable" , .value
= JTAG_CMD_TAPENABLE
},
1850 { .name
= "tapdisable" , .value
= JTAG_CMD_TAPDISABLE
},
1852 { .name
= NULL
, .value
= -1 },
1855 context
= Jim_GetAssocData(interp
, "context");
1856 // go past the command
1857 Jim_GetOpt_Setup( &goi
, interp
, argc
-1, argv
+1 );
1859 e
= Jim_GetOpt_Nvp( &goi
, jtag_cmds
, &n
);
1861 Jim_GetOpt_NvpUnknown( &goi
, jtag_cmds
, 0 );
1864 Jim_SetEmptyResult( goi
.interp
);
1866 case JTAG_CMD_INTERFACE
:
1867 // return the name of the interface
1868 // TCL code might need to know the exact type...
1869 // FUTURE: we allow this as a means to "set" the interface.
1870 if( goi
.argc
!= 0 ){
1871 Jim_WrongNumArgs( goi
.interp
, 1, goi
.argv
-1, "(no params)");
1874 Jim_SetResultString( goi
.interp
, jtag_interface
->name
, -1 );
1876 case JTAG_CMD_INIT_RESET
:
1877 if( goi
.argc
!= 0 ){
1878 Jim_WrongNumArgs( goi
.interp
, 1, goi
.argv
-1, "(no params)");
1881 e
= jtag_init_reset(context
);
1882 if( e
!= ERROR_OK
){
1883 Jim_SetResult_sprintf( goi
.interp
, "error: %d", e
);
1887 case JTAG_CMD_NEWTAP
:
1888 return jim_newtap_cmd( &goi
);
1890 case JTAG_CMD_TAPISENABLED
:
1891 case JTAG_CMD_TAPENABLE
:
1892 case JTAG_CMD_TAPDISABLE
:
1893 if( goi
.argc
!= 1 ){
1894 Jim_SetResultString( goi
.interp
, "Too many parameters",-1 );
1900 t
= jtag_TapByJimObj( goi
.interp
, goi
.argv
[0] );
1905 case JTAG_CMD_TAPISENABLED
:
1908 case JTAG_CMD_TAPENABLE
:
1912 case JTAG_CMD_TAPDISABLE
:
1917 Jim_SetResult( goi
.interp
, Jim_NewIntObj( goi
.interp
, e
) );
1926 int jtag_register_commands(struct command_context_s
*cmd_ctx
)
1928 register_jim( cmd_ctx
, "jtag", jim_jtag_command
, "perform jtag tap actions");
1930 register_command(cmd_ctx
, NULL
, "interface", handle_interface_command
,
1931 COMMAND_CONFIG
, "try to configure interface");
1932 register_command(cmd_ctx
, NULL
, "jtag_speed", handle_jtag_speed_command
,
1933 COMMAND_ANY
, "set jtag speed (if supported)");
1934 register_command(cmd_ctx
, NULL
, "jtag_khz", handle_jtag_khz_command
,
1935 COMMAND_ANY
, "same as jtag_speed, except it takes maximum khz as arguments. 0 KHz = RTCK.");
1936 register_command(cmd_ctx
, NULL
, "jtag_device", handle_jtag_device_command
,
1937 COMMAND_CONFIG
, "jtag_device <ir_length> <ir_expected> <ir_mask>");
1938 register_command(cmd_ctx
, NULL
, "reset_config", handle_reset_config_command
,
1939 COMMAND_CONFIG
, NULL
);
1940 register_command(cmd_ctx
, NULL
, "jtag_nsrst_delay", handle_jtag_nsrst_delay_command
,
1941 COMMAND_ANY
, "jtag_nsrst_delay <ms> - delay after deasserting srst in ms");
1942 register_command(cmd_ctx
, NULL
, "jtag_ntrst_delay", handle_jtag_ntrst_delay_command
,
1943 COMMAND_ANY
, "jtag_ntrst_delay <ms> - delay after deasserting trst in ms");
1945 register_command(cmd_ctx
, NULL
, "scan_chain", handle_scan_chain_command
,
1946 COMMAND_EXEC
, "print current scan chain configuration");
1948 register_command(cmd_ctx
, NULL
, "endstate", handle_endstate_command
,
1949 COMMAND_EXEC
, "finish JTAG operations in <tap_state>");
1950 register_command(cmd_ctx
, NULL
, "jtag_reset", handle_jtag_reset_command
,
1951 COMMAND_EXEC
, "toggle reset lines <trst> <srst>");
1952 register_command(cmd_ctx
, NULL
, "runtest", handle_runtest_command
,
1953 COMMAND_EXEC
, "move to Run-Test/Idle, and execute <num_cycles>");
1954 register_command(cmd_ctx
, NULL
, "irscan", handle_irscan_command
,
1955 COMMAND_EXEC
, "execute IR scan <device> <instr> [dev2] [instr2] ...");
1956 register_jim(cmd_ctx
, "drscan", Jim_Command_drscan
, "execute DR scan <device> <num_bits> <value> <num_bits1> <value2> ...");
1958 register_command(cmd_ctx
, NULL
, "verify_ircapture", handle_verify_ircapture_command
,
1959 COMMAND_ANY
, "verify value captured during Capture-IR <enable|disable>");
1963 int jtag_interface_init(struct command_context_s
*cmd_ctx
)
1968 if (!jtag_interface
)
1970 /* nothing was previously specified by "interface" command */
1971 LOG_ERROR("JTAG interface has to be specified, see \"interface\" command");
1972 return ERROR_JTAG_INVALID_INTERFACE
;
1976 jtag_interface
->khz(speed_khz
, &jtag_speed
);
1980 if (jtag_interface
->init() != ERROR_OK
)
1981 return ERROR_JTAG_INIT_FAILED
;
1985 jtag
= jtag_interface
;
1989 static int jtag_init_inner(struct command_context_s
*cmd_ctx
)
1994 LOG_DEBUG("Init JTAG chain");
1997 tap
= jtag_NextEnabledTap(NULL
);
1999 LOG_ERROR("There are no enabled taps?");
2000 return ERROR_JTAG_INIT_FAILED
;
2004 if ((retval
=jtag_execute_queue())!=ERROR_OK
)
2007 /* examine chain first, as this could discover the real chain layout */
2008 if (jtag_examine_chain() != ERROR_OK
)
2010 LOG_ERROR("trying to validate configured JTAG chain anyway...");
2013 if (jtag_validate_chain() != ERROR_OK
)
2015 LOG_ERROR("Could not validate JTAG chain, continuing anyway...");
2021 int jtag_init_reset(struct command_context_s
*cmd_ctx
)
2025 if ((retval
=jtag_interface_init(cmd_ctx
)) != ERROR_OK
)
2028 LOG_DEBUG("Trying to bring the JTAG controller to life by asserting TRST / TLR");
2030 /* Reset can happen after a power cycle.
2032 * Ideally we would only assert TRST or run TLR before the target reset.
2034 * However w/srst_pulls_trst, trst is asserted together with the target
2035 * reset whether we want it or not.
2037 * NB! Some targets have JTAG circuitry disabled until a
2038 * trst & srst has been asserted.
2040 * NB! here we assume nsrst/ntrst delay are sufficient!
2042 * NB! order matters!!!! srst *can* disconnect JTAG circuitry
2045 jtag_add_reset(1, 0); /* TLR or TRST */
2046 if (jtag_reset_config
& RESET_HAS_SRST
)
2048 jtag_add_reset(1, 1);
2049 if ((jtag_reset_config
& RESET_SRST_PULLS_TRST
)==0)
2050 jtag_add_reset(0, 1);
2052 jtag_add_reset(0, 0);
2053 if ((retval
= jtag_execute_queue()) != ERROR_OK
)
2056 /* Check that we can communication on the JTAG chain + eventually we want to
2057 * be able to perform enumeration only after OpenOCD has started
2058 * telnet and GDB server
2060 * That would allow users to more easily perform any magic they need to before
2063 return jtag_init_inner(cmd_ctx
);
2066 int jtag_init(struct command_context_s
*cmd_ctx
)
2069 if ((retval
=jtag_interface_init(cmd_ctx
)) != ERROR_OK
)
2071 if (jtag_init_inner(cmd_ctx
)==ERROR_OK
)
2075 return jtag_init_reset(cmd_ctx
);
2078 static int default_khz(int khz
, int *jtag_speed
)
2080 LOG_ERROR("Translation from khz to jtag_speed not implemented");
2084 static int default_speed_div(int speed
, int *khz
)
2086 LOG_ERROR("Translation from jtag_speed to khz not implemented");
2090 static int default_power_dropout(int *dropout
)
2092 *dropout
=0; /* by default we can't detect power dropout */
2096 static int default_srst_asserted(int *srst_asserted
)
2098 *srst_asserted
=0; /* by default we can't detect srst asserted */
2102 int handle_interface_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2107 /* check whether the interface is already configured */
2110 LOG_WARNING("Interface already configured, ignoring");
2114 /* interface name is a mandatory argument */
2115 if (argc
< 1 || args
[0][0] == '\0')
2117 return ERROR_COMMAND_SYNTAX_ERROR
;
2120 for (i
=0; jtag_interfaces
[i
]; i
++)
2122 if (strcmp(args
[0], jtag_interfaces
[i
]->name
) == 0)
2124 if ((retval
= jtag_interfaces
[i
]->register_commands(cmd_ctx
)) != ERROR_OK
)
2129 jtag_interface
= jtag_interfaces
[i
];
2131 if (jtag_interface
->khz
== NULL
)
2133 jtag_interface
->khz
= default_khz
;
2135 if (jtag_interface
->speed_div
== NULL
)
2137 jtag_interface
->speed_div
= default_speed_div
;
2139 if (jtag_interface
->power_dropout
== NULL
)
2141 jtag_interface
->power_dropout
= default_power_dropout
;
2143 if (jtag_interface
->srst_asserted
== NULL
)
2145 jtag_interface
->srst_asserted
= default_srst_asserted
;
2152 /* no valid interface was found (i.e. the configuration option,
2153 * didn't match one of the compiled-in interfaces
2155 LOG_ERROR("No valid jtag interface found (%s)", args
[0]);
2156 LOG_ERROR("compiled-in jtag interfaces:");
2157 for (i
= 0; jtag_interfaces
[i
]; i
++)
2159 LOG_ERROR("%i: %s", i
, jtag_interfaces
[i
]->name
);
2162 return ERROR_JTAG_INVALID_INTERFACE
;
2165 int handle_jtag_device_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2169 Jim_Obj
*newargs
[ 10 ];
2173 // argv[-1] = command
2174 // argv[ 0] = ir length
2175 // argv[ 1] = ir capture
2176 // argv[ 2] = ir mask
2177 // argv[ 3] = not actually used by anything but in the docs
2180 command_print( cmd_ctx
, "OLD DEPRECATED SYNTAX: Please use the NEW syntax");
2183 command_print( cmd_ctx
, "OLD SYNTAX: DEPRECATED - translating to new syntax");
2184 command_print( cmd_ctx
, "jtag newtap CHIP TAP -irlen %s -ircapture %s -irvalue %s",
2188 command_print( cmd_ctx
, "Example: STM32 has 2 taps, the cortexM3(len4) + boundryscan(len5)");
2189 command_print( cmd_ctx
, "jtag newtap stm32 cortexm3 ....., thus creating the tap: \"stm32.cortexm3\"");
2190 command_print( cmd_ctx
, "jtag newtap stm32 boundry ....., and the tap: \"stm32.boundery\"");
2191 command_print( cmd_ctx
, "And then refer to the taps by the dotted name.");
2195 newargs
[0] = Jim_NewStringObj( interp
, "jtag", -1 );
2196 newargs
[1] = Jim_NewStringObj( interp
, "newtap", -1 );
2197 sprintf( buf
, "chip%d", jtag_NumTotalTaps() );
2198 newargs
[2] = Jim_NewStringObj( interp
, buf
, -1 );
2199 sprintf( buf
, "tap%d", jtag_NumTotalTaps() );
2200 newargs
[3] = Jim_NewStringObj( interp
, buf
, -1 );
2201 newargs
[4] = Jim_NewStringObj( interp
, "-irlen", -1 );
2202 newargs
[5] = Jim_NewStringObj( interp
, args
[0], -1 );
2203 newargs
[6] = Jim_NewStringObj( interp
, "-ircapture", -1 );
2204 newargs
[7] = Jim_NewStringObj( interp
, args
[1], -1 );
2205 newargs
[8] = Jim_NewStringObj( interp
, "-irmask", -1 );
2206 newargs
[9] = Jim_NewStringObj( interp
, args
[2], -1 );
2208 command_print( cmd_ctx
, "NEW COMMAND:");
2209 sprintf( buf
, "%s %s %s %s %s %s %s %s %s %s",
2210 Jim_GetString( newargs
[0], NULL
),
2211 Jim_GetString( newargs
[1], NULL
),
2212 Jim_GetString( newargs
[2], NULL
),
2213 Jim_GetString( newargs
[3], NULL
),
2214 Jim_GetString( newargs
[4], NULL
),
2215 Jim_GetString( newargs
[5], NULL
),
2216 Jim_GetString( newargs
[6], NULL
),
2217 Jim_GetString( newargs
[7], NULL
),
2218 Jim_GetString( newargs
[8], NULL
),
2219 Jim_GetString( newargs
[9], NULL
) );
2223 e
= jim_jtag_command( interp
, 10, newargs
);
2225 command_print( cmd_ctx
, "%s", Jim_GetString( Jim_GetResult(interp
), NULL
) );
2231 int handle_scan_chain_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2235 tap
= jtag_all_taps
;
2236 command_print(cmd_ctx
, " TapName | Enabled | IdCode Expected IrLen IrCap IrMask Instr ");
2237 command_print(cmd_ctx
, "---|--------------------|---------|------------|------------|------|------|------|---------");
2240 u32 expected
, expected_mask
, cur_instr
;
2241 expected
= buf_get_u32(tap
->expected
, 0, tap
->ir_length
);
2242 expected_mask
= buf_get_u32(tap
->expected_mask
, 0, tap
->ir_length
);
2243 cur_instr
= buf_get_u32(tap
->cur_instr
, 0, tap
->ir_length
);
2244 command_print(cmd_ctx
,
2245 "%2d | %-18s | %c | 0x%08x | 0x%08x | 0x%02x | 0x%02x | 0x%02x | 0x%02x",
2246 tap
->abs_chain_position
,
2248 tap
->enabled
? 'Y' : 'n',
2255 tap
= tap
->next_tap
;
2261 int handle_reset_config_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2264 return ERROR_COMMAND_SYNTAX_ERROR
;
2268 if (strcmp(args
[0], "none") == 0)
2269 jtag_reset_config
= RESET_NONE
;
2270 else if (strcmp(args
[0], "trst_only") == 0)
2271 jtag_reset_config
= RESET_HAS_TRST
;
2272 else if (strcmp(args
[0], "srst_only") == 0)
2273 jtag_reset_config
= RESET_HAS_SRST
;
2274 else if (strcmp(args
[0], "trst_and_srst") == 0)
2275 jtag_reset_config
= RESET_TRST_AND_SRST
;
2278 LOG_ERROR("(1) invalid reset_config argument (%s), defaulting to none", args
[0]);
2279 jtag_reset_config
= RESET_NONE
;
2280 return ERROR_INVALID_ARGUMENTS
;
2286 if (strcmp(args
[1], "separate") == 0)
2288 /* seperate reset lines - default */
2291 if (strcmp(args
[1], "srst_pulls_trst") == 0)
2292 jtag_reset_config
|= RESET_SRST_PULLS_TRST
;
2293 else if (strcmp(args
[1], "trst_pulls_srst") == 0)
2294 jtag_reset_config
|= RESET_TRST_PULLS_SRST
;
2295 else if (strcmp(args
[1], "combined") == 0)
2296 jtag_reset_config
|= RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
;
2299 LOG_ERROR("(2) invalid reset_config argument (%s), defaulting to none", args
[1]);
2300 jtag_reset_config
= RESET_NONE
;
2301 return ERROR_INVALID_ARGUMENTS
;
2308 if (strcmp(args
[2], "trst_open_drain") == 0)
2309 jtag_reset_config
|= RESET_TRST_OPEN_DRAIN
;
2310 else if (strcmp(args
[2], "trst_push_pull") == 0)
2311 jtag_reset_config
&= ~RESET_TRST_OPEN_DRAIN
;
2314 LOG_ERROR("(3) invalid reset_config argument (%s) defaulting to none", args
[2] );
2315 jtag_reset_config
= RESET_NONE
;
2316 return ERROR_INVALID_ARGUMENTS
;
2322 if (strcmp(args
[3], "srst_push_pull") == 0)
2323 jtag_reset_config
|= RESET_SRST_PUSH_PULL
;
2324 else if (strcmp(args
[3], "srst_open_drain") == 0)
2325 jtag_reset_config
&= ~RESET_SRST_PUSH_PULL
;
2328 LOG_ERROR("(4) invalid reset_config argument (%s), defaulting to none", args
[3]);
2329 jtag_reset_config
= RESET_NONE
;
2330 return ERROR_INVALID_ARGUMENTS
;
2337 int handle_jtag_nsrst_delay_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2341 LOG_ERROR("jtag_nsrst_delay <ms> command takes one required argument");
2346 jtag_nsrst_delay
= strtoul(args
[0], NULL
, 0);
2352 int handle_jtag_ntrst_delay_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2356 LOG_ERROR("jtag_ntrst_delay <ms> command takes one required argument");
2361 jtag_ntrst_delay
= strtoul(args
[0], NULL
, 0);
2367 int handle_jtag_speed_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2369 int retval
=ERROR_OK
;
2373 LOG_DEBUG("handle jtag speed");
2376 cur_speed
= jtag_speed
= strtoul(args
[0], NULL
, 0);
2378 /* this command can be called during CONFIG,
2379 * in which case jtag isn't initialized */
2382 retval
=jtag
->speed(cur_speed
);
2384 } else if (argc
== 0)
2388 return ERROR_COMMAND_SYNTAX_ERROR
;
2390 command_print(cmd_ctx
, "jtag_speed: %d", jtag_speed
);
2395 int handle_jtag_khz_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2397 int retval
=ERROR_OK
;
2398 LOG_DEBUG("handle jtag khz");
2402 speed_khz
= strtoul(args
[0], NULL
, 0);
2406 LOG_DEBUG("have interface set up");
2408 if ((retval
=jtag
->khz(speed_khz
, &speed_div1
))!=ERROR_OK
)
2414 cur_speed
= jtag_speed
= speed_div1
;
2416 retval
=jtag
->speed(cur_speed
);
2425 return ERROR_COMMAND_SYNTAX_ERROR
;
2430 if ((retval
=jtag
->speed_div(jtag_speed
, &speed_khz
))!=ERROR_OK
)
2436 command_print(cmd_ctx
, "RCLK - adaptive");
2439 command_print(cmd_ctx
, "%d kHz", speed_khz
);
2445 int handle_endstate_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2447 enum tap_state state
;
2451 return ERROR_COMMAND_SYNTAX_ERROR
;
2455 for (state
= 0; state
< 16; state
++)
2457 if (strcmp(args
[0], tap_state_strings
[state
]) == 0)
2459 jtag_add_end_state(state
);
2460 jtag_execute_queue();
2464 command_print(cmd_ctx
, "current endstate: %s", tap_state_strings
[cmd_queue_end_state
]);
2469 int handle_jtag_reset_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2476 return ERROR_COMMAND_SYNTAX_ERROR
;
2479 if (args
[0][0] == '1')
2481 else if (args
[0][0] == '0')
2485 return ERROR_COMMAND_SYNTAX_ERROR
;
2488 if (args
[1][0] == '1')
2490 else if (args
[1][0] == '0')
2494 return ERROR_COMMAND_SYNTAX_ERROR
;
2497 if (jtag_interface_init(cmd_ctx
) != ERROR_OK
)
2498 return ERROR_JTAG_INIT_FAILED
;
2500 jtag_add_reset(trst
, srst
);
2501 jtag_execute_queue();
2506 int handle_runtest_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2510 return ERROR_COMMAND_SYNTAX_ERROR
;
2513 jtag_add_runtest(strtol(args
[0], NULL
, 0), -1);
2514 jtag_execute_queue();
2520 int handle_irscan_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2523 scan_field_t
*fields
;
2526 if ((argc
< 2) || (argc
% 2))
2528 return ERROR_COMMAND_SYNTAX_ERROR
;
2531 fields
= malloc(sizeof(scan_field_t
) * argc
/ 2);
2533 for (i
= 0; i
< argc
/ 2; i
++)
2535 tap
= jtag_TapByString( args
[i
*2] );
2538 command_print( cmd_ctx
, "Tap: %s unknown", args
[i
*2] );
2541 int field_size
= tap
->ir_length
;
2542 fields
[i
].tap
= tap
;
2543 fields
[i
].out_value
= malloc(CEIL(field_size
, 8));
2544 buf_set_u32(fields
[i
].out_value
, 0, field_size
, strtoul(args
[i
*2+1], NULL
, 0));
2545 fields
[i
].out_mask
= NULL
;
2546 fields
[i
].in_value
= NULL
;
2547 fields
[i
].in_check_mask
= NULL
;
2548 fields
[i
].in_handler
= NULL
;
2549 fields
[i
].in_handler_priv
= NULL
;
2552 jtag_add_ir_scan(argc
/ 2, fields
, -1);
2553 jtag_execute_queue();
2555 for (i
= 0; i
< argc
/ 2; i
++)
2556 free(fields
[i
].out_value
);
2563 int Jim_Command_drscan(Jim_Interp
*interp
, int argc
, Jim_Obj
*const *args
)
2566 scan_field_t
*fields
;
2568 int field_count
= 0;
2573 * args[2] = num_bits
2574 * args[3] = hex string
2575 * ... repeat num bits and hex string ...
2577 if ((argc
< 4) || ((argc
% 2)!=0))
2579 Jim_WrongNumArgs(interp
, 1, args
, "wrong arguments");
2583 for (i
= 2; i
< argc
; i
+=2)
2587 e
= Jim_GetLong(interp
, args
[i
], &bits
);
2592 tap
= jtag_TapByJimObj( interp
, args
[1] );
2597 num_fields
=(argc
-2)/2;
2598 fields
= malloc(sizeof(scan_field_t
) * num_fields
);
2599 for (i
= 2; i
< argc
; i
+=2)
2605 Jim_GetLong(interp
, args
[i
], &bits
);
2606 str
= Jim_GetString(args
[i
+1], &len
);
2609 fields
[field_count
].tap
= tap
;
2610 fields
[field_count
].num_bits
= bits
;
2611 fields
[field_count
].out_value
= malloc(CEIL(bits
, 8));
2612 str_to_buf(str
, len
, fields
[field_count
].out_value
, bits
, 0);
2613 fields
[field_count
].out_mask
= NULL
;
2614 fields
[field_count
].in_value
= fields
[field_count
].out_value
;
2615 fields
[field_count
].in_check_mask
= NULL
;
2616 fields
[field_count
].in_check_value
= NULL
;
2617 fields
[field_count
].in_handler
= NULL
;
2618 fields
[field_count
++].in_handler_priv
= NULL
;
2621 jtag_add_dr_scan(num_fields
, fields
, -1);
2622 retval
= jtag_execute_queue();
2623 if (retval
!= ERROR_OK
)
2625 Jim_SetResultString(interp
, "drscan: jtag execute failed",-1);
2630 Jim_Obj
*list
= Jim_NewListObj(interp
, NULL
, 0);
2631 for (i
= 2; i
< argc
; i
+=2)
2636 Jim_GetLong(interp
, args
[i
], &bits
);
2637 str
= buf_to_str(fields
[field_count
].in_value
, bits
, 16);
2638 free(fields
[field_count
].out_value
);
2640 Jim_ListAppendElement(interp
, list
, Jim_NewStringObj(interp
, str
, strlen(str
)));
2645 Jim_SetResult(interp
, list
);
2652 int handle_verify_ircapture_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
2656 if (strcmp(args
[0], "enable") == 0)
2658 jtag_verify_capture_ir
= 1;
2660 else if (strcmp(args
[0], "disable") == 0)
2662 jtag_verify_capture_ir
= 0;
2665 return ERROR_COMMAND_SYNTAX_ERROR
;
2667 } else if (argc
!= 0)
2669 return ERROR_COMMAND_SYNTAX_ERROR
;
2672 command_print(cmd_ctx
, "verify Capture-IR is %s", (jtag_verify_capture_ir
) ? "enabled": "disabled");
2678 int jtag_power_dropout(int *dropout
)
2680 return jtag
->power_dropout(dropout
);
2683 int jtag_srst_asserted(int *srst_asserted
)
2685 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)