1 /***************************************************************************
2 * Copyright (C) 2005 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
24 #include "replacements.h"
30 #include "interpreter.h"
36 char* tap_state_strings
[16] =
39 "sds", "cd", "sd", "e1d", "pd", "e2d", "ud",
41 "sis", "ci", "si", "e1i", "pi", "e2i", "ui"
44 typedef struct cmd_queue_page_s
48 struct cmd_queue_page_s
*next
;
51 #define CMD_QUEUE_PAGE_SIZE (1024 * 1024)
52 static cmd_queue_page_t
*cmd_queue_pages
= NULL
;
54 /* tap_move[i][j]: tap movement command to go from state i to state j
62 * SD->SD and SI->SI have to be caught in interface specific code
66 /* TLR RTI SD PD SI PI */
67 {0x7f, 0x00, 0x17, 0x0a, 0x1b, 0x16}, /* TLR */
68 {0x7f, 0x00, 0x25, 0x05, 0x2b, 0x0b}, /* RTI */
69 {0x7f, 0x31, 0x00, 0x01, 0x0f, 0x2f}, /* SD */
70 {0x7f, 0x30, 0x20, 0x17, 0x1e, 0x2f}, /* PD */
71 {0x7f, 0x31, 0x07, 0x17, 0x00, 0x01}, /* SI */
72 {0x7f, 0x30, 0x1c, 0x17, 0x20, 0x2f} /* PI */
75 int tap_move_map
[16] = {
76 0, -1, -1, 2, -1, 3, -1, -1,
77 1, -1, -1, 4, -1, 5, -1, -1
80 tap_transition_t tap_transitions
[16] =
82 {TAP_TLR
, TAP_RTI
}, /* TLR */
83 {TAP_SIS
, TAP_CD
}, /* SDS */
84 {TAP_E1D
, TAP_SD
}, /* CD */
85 {TAP_E1D
, TAP_SD
}, /* SD */
86 {TAP_UD
, TAP_PD
}, /* E1D */
87 {TAP_E2D
, TAP_PD
}, /* PD */
88 {TAP_UD
, TAP_SD
}, /* E2D */
89 {TAP_SDS
, TAP_RTI
}, /* UD */
90 {TAP_SDS
, TAP_RTI
}, /* RTI */
91 {TAP_TLR
, TAP_CI
}, /* SIS */
92 {TAP_E1I
, TAP_SI
}, /* CI */
93 {TAP_E1I
, TAP_SI
}, /* SI */
94 {TAP_UI
, TAP_PI
}, /* E1I */
95 {TAP_E2I
, TAP_PI
}, /* PI */
96 {TAP_UI
, TAP_SI
}, /* E2I */
97 {TAP_SDS
, TAP_RTI
} /* UI */
100 char* jtag_event_strings
[] =
108 enum tap_state end_state
= TAP_TLR
;
109 enum tap_state cur_state
= TAP_TLR
;
113 jtag_command_t
*jtag_command_queue
= NULL
;
114 jtag_command_t
**last_comand_pointer
= &jtag_command_queue
;
115 jtag_device_t
*jtag_devices
= NULL
;
116 int jtag_num_devices
= 0;
117 int jtag_ir_scan_size
= 0;
118 enum reset_types jtag_reset_config
= RESET_NONE
;
119 enum tap_state cmd_queue_end_state
= TAP_TLR
;
120 enum tap_state cmd_queue_cur_state
= TAP_TLR
;
122 int jtag_verify_capture_ir
= 1;
124 /* how long the OpenOCD should wait before attempting JTAG communication after reset lines deasserted (in ms) */
125 int jtag_nsrst_delay
= 0; /* default to no nSRST delay */
126 int jtag_ntrst_delay
= 0; /* default to no nTRST delay */
128 /* maximum number of JTAG devices expected in the chain
130 #define JTAG_MAX_CHAIN_SIZE 20
132 /* callbacks to inform high-level handlers about JTAG state changes */
133 jtag_event_callback_t
*jtag_event_callbacks
;
135 /* jtag interfaces (parport, FTDI-USB, TI-USB, ...)
137 #if BUILD_PARPORT == 1
138 extern jtag_interface_t parport_interface
;
141 #if BUILD_FT2232_FTD2XX == 1
142 extern jtag_interface_t ft2232_interface
;
145 #if BUILD_FT2232_LIBFTDI == 1
146 extern jtag_interface_t ft2232_interface
;
149 #if BUILD_AMTJTAGACCEL == 1
150 extern jtag_interface_t amt_jtagaccel_interface
;
153 #if BUILD_EP93XX == 1
154 extern jtag_interface_t ep93xx_interface
;
157 #if BUILD_AT91RM9200 == 1
158 extern jtag_interface_t at91rm9200_interface
;
161 #if BUILD_GW16012 == 1
162 extern jtag_interface_t gw16012_interface
;
165 #if BUILD_PRESTO_LIBFTDI == 1 || BUILD_PRESTO_FTD2XX == 1
166 extern jtag_interface_t presto_interface
;
169 #if BUILD_USBPROG == 1
170 extern jtag_interface_t usbprog_interface
;
173 jtag_interface_t
*jtag_interfaces
[] = {
174 #if BUILD_PARPORT == 1
177 #if BUILD_FT2232_FTD2XX == 1
180 #if BUILD_FT2232_LIBFTDI == 1
183 #if BUILD_AMTJTAGACCEL == 1
184 &amt_jtagaccel_interface
,
186 #if BUILD_EP93XX == 1
189 #if BUILD_AT91RM9200 == 1
190 &at91rm9200_interface
,
192 #if BUILD_GW16012 == 1
195 #if BUILD_PRESTO_LIBFTDI == 1 || BUILD_PRESTO_FTD2XX == 1
198 #if BUILD_USBPROG == 1
204 jtag_interface_t
*jtag
= NULL
;
207 char* jtag_interface
= NULL
;
211 /* forward declarations */
212 int jtag_add_statemove(enum tap_state endstate
);
213 int jtag_add_pathmove(int num_states
, enum tap_state
*path
);
214 int jtag_add_runtest(int num_cycles
, enum tap_state endstate
);
215 int jtag_add_reset(int trst
, int srst
);
216 int jtag_add_end_state(enum tap_state endstate
);
217 int jtag_add_sleep(u32 us
);
218 int jtag_execute_queue(void);
219 int jtag_cancel_queue(void);
222 int handle_interface_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
223 int handle_jtag_speed_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
224 int handle_jtag_device_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
225 int handle_reset_config_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
226 int handle_jtag_nsrst_delay_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
227 int handle_jtag_ntrst_delay_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
229 int handle_scan_chain_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
231 int handle_endstate_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
232 int handle_jtag_reset_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
233 int handle_runtest_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
234 int handle_statemove_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
235 int handle_irscan_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
236 int handle_drscan_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
238 int handle_verify_ircapture_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
240 int jtag_register_event_callback(int (*callback
)(enum jtag_event event
, void *priv
), void *priv
)
242 jtag_event_callback_t
**callbacks_p
= &jtag_event_callbacks
;
244 if (callback
== NULL
)
246 return ERROR_INVALID_ARGUMENTS
;
251 while ((*callbacks_p
)->next
)
252 callbacks_p
= &((*callbacks_p
)->next
);
253 callbacks_p
= &((*callbacks_p
)->next
);
256 (*callbacks_p
) = malloc(sizeof(jtag_event_callback_t
));
257 (*callbacks_p
)->callback
= callback
;
258 (*callbacks_p
)->priv
= priv
;
259 (*callbacks_p
)->next
= NULL
;
264 int jtag_unregister_event_callback(int (*callback
)(enum jtag_event event
, void *priv
))
266 jtag_event_callback_t
**callbacks_p
= &jtag_event_callbacks
;
268 if (callback
== NULL
)
270 return ERROR_INVALID_ARGUMENTS
;
275 jtag_event_callback_t
**next
= &((*callbacks_p
)->next
);
276 if ((*callbacks_p
)->callback
== callback
)
279 *callbacks_p
= *next
;
287 int jtag_call_event_callbacks(enum jtag_event event
)
289 jtag_event_callback_t
*callback
= jtag_event_callbacks
;
291 DEBUG("jtag event: %s", jtag_event_strings
[event
]);
295 callback
->callback(event
, callback
->priv
);
296 callback
= callback
->next
;
302 /* returns a pointer to the pointer of the last command in queue
303 * this may be a pointer to the root pointer (jtag_command_queue)
304 * or to the next member of the last but one command
306 jtag_command_t
** jtag_get_last_command_p(void)
308 /* jtag_command_t *cmd = jtag_command_queue;
314 return &jtag_command_queue;
318 return last_comand_pointer
;
321 /* returns a pointer to the n-th device in the scan chain */
322 jtag_device_t
* jtag_get_device(int num
)
324 jtag_device_t
*device
= jtag_devices
;
331 device
= device
->next
;
335 ERROR("jtag device number %d not defined", num
);
339 void* cmd_queue_alloc(size_t size
)
341 cmd_queue_page_t
**p_page
= &cmd_queue_pages
;
346 while ((*p_page
)->next
)
347 p_page
= &((*p_page
)->next
);
348 if (CMD_QUEUE_PAGE_SIZE
- (*p_page
)->used
< size
)
349 p_page
= &((*p_page
)->next
);
354 *p_page
= malloc(sizeof(cmd_queue_page_t
));
356 (*p_page
)->address
= malloc(CMD_QUEUE_PAGE_SIZE
);
357 (*p_page
)->next
= NULL
;
360 offset
= (*p_page
)->used
;
361 (*p_page
)->used
+= size
;
363 u8
*t
=(u8
*)((*p_page
)->address
);
367 void cmd_queue_free()
369 cmd_queue_page_t
*page
= cmd_queue_pages
;
373 cmd_queue_page_t
*last
= page
;
379 cmd_queue_pages
= NULL
;
382 int jtag_add_ir_scan(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
384 jtag_command_t
**last_cmd
;
385 jtag_device_t
*device
;
391 WARNING("JTAG command queued, while TRST is low (TAP in reset)");
392 return ERROR_JTAG_TRST_ASSERTED
;
395 last_cmd
= jtag_get_last_command_p();
397 /* allocate memory for a new list member */
398 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
399 (*last_cmd
)->next
= NULL
;
400 last_comand_pointer
= &((*last_cmd
)->next
);
401 (*last_cmd
)->type
= JTAG_SCAN
;
403 /* allocate memory for ir scan command */
404 (*last_cmd
)->cmd
.scan
= cmd_queue_alloc(sizeof(scan_command_t
));
405 (*last_cmd
)->cmd
.scan
->ir_scan
= 1;
406 (*last_cmd
)->cmd
.scan
->num_fields
= jtag_num_devices
; /* one field per device */
407 (*last_cmd
)->cmd
.scan
->fields
= cmd_queue_alloc(jtag_num_devices
* sizeof(scan_field_t
));
408 (*last_cmd
)->cmd
.scan
->end_state
= state
;
411 cmd_queue_end_state
= state
;
413 if (cmd_queue_cur_state
== TAP_TLR
&& cmd_queue_end_state
!= TAP_TLR
)
414 jtag_call_event_callbacks(JTAG_TRST_RELEASED
);
416 if (cmd_queue_end_state
== TAP_TLR
)
417 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
419 cmd_queue_cur_state
= cmd_queue_end_state
;
421 for (i
= 0; i
< jtag_num_devices
; i
++)
424 device
= jtag_get_device(i
);
425 scan_size
= device
->ir_length
;
426 (*last_cmd
)->cmd
.scan
->fields
[i
].device
= i
;
427 (*last_cmd
)->cmd
.scan
->fields
[i
].num_bits
= scan_size
;
428 (*last_cmd
)->cmd
.scan
->fields
[i
].in_value
= NULL
;
429 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler
= NULL
; /* disable verification by default */
431 /* search the list */
432 for (j
= 0; j
< num_fields
; j
++)
434 if (i
== fields
[j
].device
)
437 (*last_cmd
)->cmd
.scan
->fields
[i
].out_value
= buf_cpy(fields
[j
].out_value
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
438 (*last_cmd
)->cmd
.scan
->fields
[i
].out_mask
= buf_cpy(fields
[j
].out_mask
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
440 if (jtag_verify_capture_ir
)
442 if (fields
[j
].in_handler
==NULL
)
444 jtag_set_check_value((*last_cmd
)->cmd
.scan
->fields
+i
, device
->expected
, device
->expected_mask
, NULL
);
447 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler
= fields
[j
].in_handler
;
448 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler_priv
= fields
[j
].in_handler_priv
;
449 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_value
= device
->expected
;
450 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_mask
= device
->expected_mask
;
461 /* if a device isn't listed, set it to BYPASS */
462 (*last_cmd
)->cmd
.scan
->fields
[i
].out_value
= buf_set_ones(cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
463 (*last_cmd
)->cmd
.scan
->fields
[i
].out_mask
= NULL
;
468 /* update device information */
469 buf_cpy((*last_cmd
)->cmd
.scan
->fields
[i
].out_value
, jtag_get_device(i
)->cur_instr
, scan_size
);
475 int jtag_add_plain_ir_scan(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
477 jtag_command_t
**last_cmd
;
482 WARNING("JTAG command queued, while TRST is low (TAP in reset)");
483 return ERROR_JTAG_TRST_ASSERTED
;
486 last_cmd
= jtag_get_last_command_p();
488 /* allocate memory for a new list member */
489 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
490 (*last_cmd
)->next
= NULL
;
491 last_comand_pointer
= &((*last_cmd
)->next
);
492 (*last_cmd
)->type
= JTAG_SCAN
;
494 /* allocate memory for ir scan command */
495 (*last_cmd
)->cmd
.scan
= cmd_queue_alloc(sizeof(scan_command_t
));
496 (*last_cmd
)->cmd
.scan
->ir_scan
= 1;
497 (*last_cmd
)->cmd
.scan
->num_fields
= num_fields
;
498 (*last_cmd
)->cmd
.scan
->fields
= cmd_queue_alloc(num_fields
* sizeof(scan_field_t
));
499 (*last_cmd
)->cmd
.scan
->end_state
= state
;
502 cmd_queue_end_state
= state
;
504 if (cmd_queue_cur_state
== TAP_TLR
&& cmd_queue_end_state
!= TAP_TLR
)
505 jtag_call_event_callbacks(JTAG_TRST_RELEASED
);
507 if (cmd_queue_end_state
== TAP_TLR
)
508 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
510 cmd_queue_cur_state
= cmd_queue_end_state
;
512 for (i
= 0; i
< num_fields
; i
++)
514 int num_bits
= fields
[i
].num_bits
;
515 int num_bytes
= CEIL(fields
[i
].num_bits
, 8);
516 (*last_cmd
)->cmd
.scan
->fields
[i
].device
= fields
[i
].device
;
517 (*last_cmd
)->cmd
.scan
->fields
[i
].num_bits
= num_bits
;
518 (*last_cmd
)->cmd
.scan
->fields
[i
].out_value
= buf_cpy(fields
[i
].out_value
, cmd_queue_alloc(num_bytes
), num_bits
);
519 (*last_cmd
)->cmd
.scan
->fields
[i
].out_mask
= buf_cpy(fields
[i
].out_mask
, cmd_queue_alloc(num_bytes
), num_bits
);
520 (*last_cmd
)->cmd
.scan
->fields
[i
].in_value
= fields
[i
].in_value
;
521 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_value
= fields
[i
].in_check_value
;
522 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_mask
= fields
[i
].in_check_mask
;
523 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler
= NULL
;
524 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler_priv
= NULL
;
529 int jtag_add_dr_scan(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
532 int bypass_devices
= 0;
534 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
535 jtag_device_t
*device
= jtag_devices
;
540 WARNING("JTAG command queued, while TRST is low (TAP in reset)");
541 return ERROR_JTAG_TRST_ASSERTED
;
544 /* count devices in bypass */
549 device
= device
->next
;
552 /* allocate memory for a new list member */
553 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
554 last_comand_pointer
= &((*last_cmd
)->next
);
555 (*last_cmd
)->next
= NULL
;
556 (*last_cmd
)->type
= JTAG_SCAN
;
558 /* allocate memory for dr scan command */
559 (*last_cmd
)->cmd
.scan
= cmd_queue_alloc(sizeof(scan_command_t
));
560 (*last_cmd
)->cmd
.scan
->ir_scan
= 0;
561 (*last_cmd
)->cmd
.scan
->num_fields
= num_fields
+ bypass_devices
;
562 (*last_cmd
)->cmd
.scan
->fields
= cmd_queue_alloc((num_fields
+ bypass_devices
) * sizeof(scan_field_t
));
563 (*last_cmd
)->cmd
.scan
->end_state
= state
;
566 cmd_queue_end_state
= state
;
568 if (cmd_queue_cur_state
== TAP_TLR
&& cmd_queue_end_state
!= TAP_TLR
)
569 jtag_call_event_callbacks(JTAG_TRST_RELEASED
);
571 if (cmd_queue_end_state
== TAP_TLR
)
572 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
574 cmd_queue_cur_state
= cmd_queue_end_state
;
576 for (i
= 0; i
< jtag_num_devices
; i
++)
579 (*last_cmd
)->cmd
.scan
->fields
[field_count
].device
= i
;
581 for (j
= 0; j
< num_fields
; j
++)
583 if (i
== fields
[j
].device
)
586 scan_size
= fields
[j
].num_bits
;
587 (*last_cmd
)->cmd
.scan
->fields
[field_count
].num_bits
= scan_size
;
588 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_value
= buf_cpy(fields
[j
].out_value
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
589 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_mask
= buf_cpy(fields
[j
].out_mask
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
590 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_value
= fields
[j
].in_value
;
591 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_check_value
= fields
[j
].in_check_value
;
592 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_check_mask
= fields
[j
].in_check_mask
;
593 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_handler
= fields
[j
].in_handler
;
594 (*last_cmd
)->cmd
.scan
->fields
[field_count
++].in_handler_priv
= fields
[j
].in_handler_priv
;
599 /* if a device isn't listed, the BYPASS register should be selected */
600 if (!jtag_get_device(i
)->bypass
)
602 ERROR("BUG: no scan data for a device not in BYPASS");
606 /* program the scan field to 1 bit length, and ignore it's value */
607 (*last_cmd
)->cmd
.scan
->fields
[field_count
].num_bits
= 1;
608 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_value
= NULL
;
609 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_mask
= NULL
;
610 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_value
= NULL
;
611 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_check_value
= NULL
;
612 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_check_mask
= NULL
;
613 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_handler
= NULL
;
614 (*last_cmd
)->cmd
.scan
->fields
[field_count
++].in_handler_priv
= NULL
;
618 /* if a device is listed, the BYPASS register must not be selected */
619 if (jtag_get_device(i
)->bypass
)
621 WARNING("scan data for a device in BYPASS");
629 int jtag_add_plain_dr_scan(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
632 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
636 WARNING("JTAG command queued, while TRST is low (TAP in reset)");
637 return ERROR_JTAG_TRST_ASSERTED
;
640 /* allocate memory for a new list member */
641 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
642 last_comand_pointer
= &((*last_cmd
)->next
);
643 (*last_cmd
)->next
= NULL
;
644 (*last_cmd
)->type
= JTAG_SCAN
;
646 /* allocate memory for scan command */
647 (*last_cmd
)->cmd
.scan
= cmd_queue_alloc(sizeof(scan_command_t
));
648 (*last_cmd
)->cmd
.scan
->ir_scan
= 0;
649 (*last_cmd
)->cmd
.scan
->num_fields
= num_fields
;
650 (*last_cmd
)->cmd
.scan
->fields
= cmd_queue_alloc(num_fields
* sizeof(scan_field_t
));
651 (*last_cmd
)->cmd
.scan
->end_state
= state
;
654 cmd_queue_end_state
= state
;
656 if (cmd_queue_cur_state
== TAP_TLR
&& cmd_queue_end_state
!= TAP_TLR
)
657 jtag_call_event_callbacks(JTAG_TRST_RELEASED
);
659 if (cmd_queue_end_state
== TAP_TLR
)
660 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
662 cmd_queue_cur_state
= cmd_queue_end_state
;
664 for (i
= 0; i
< num_fields
; i
++)
666 int num_bits
= fields
[i
].num_bits
;
667 int num_bytes
= CEIL(fields
[i
].num_bits
, 8);
668 (*last_cmd
)->cmd
.scan
->fields
[i
].device
= fields
[i
].device
;
669 (*last_cmd
)->cmd
.scan
->fields
[i
].num_bits
= num_bits
;
670 (*last_cmd
)->cmd
.scan
->fields
[i
].out_value
= buf_cpy(fields
[i
].out_value
, cmd_queue_alloc(num_bytes
), num_bits
);
671 (*last_cmd
)->cmd
.scan
->fields
[i
].out_mask
= buf_cpy(fields
[i
].out_mask
, cmd_queue_alloc(num_bytes
), num_bits
);
672 (*last_cmd
)->cmd
.scan
->fields
[i
].in_value
= fields
[i
].in_value
;
673 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_value
= fields
[i
].in_check_value
;
674 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_mask
= fields
[i
].in_check_mask
;
675 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler
= fields
[i
].in_handler
;
676 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler_priv
= fields
[i
].in_handler_priv
;
681 int jtag_add_statemove(enum tap_state state
)
683 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
687 WARNING("JTAG command queued, while TRST is low (TAP in reset)");
688 return ERROR_JTAG_TRST_ASSERTED
;
691 /* allocate memory for a new list member */
692 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
693 last_comand_pointer
= &((*last_cmd
)->next
);
694 (*last_cmd
)->next
= NULL
;
695 (*last_cmd
)->type
= JTAG_STATEMOVE
;
697 (*last_cmd
)->cmd
.statemove
= cmd_queue_alloc(sizeof(statemove_command_t
));
698 (*last_cmd
)->cmd
.statemove
->end_state
= state
;
701 cmd_queue_end_state
= state
;
703 if (cmd_queue_cur_state
== TAP_TLR
&& cmd_queue_end_state
!= TAP_TLR
)
704 jtag_call_event_callbacks(JTAG_TRST_RELEASED
);
706 if (cmd_queue_end_state
== TAP_TLR
)
707 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
709 cmd_queue_cur_state
= cmd_queue_end_state
;
714 int jtag_add_pathmove(int num_states
, enum tap_state
*path
)
716 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
721 WARNING("JTAG command queued, while TRST is low (TAP in reset)");
722 return ERROR_JTAG_TRST_ASSERTED
;
725 /* the last state has to be a stable state */
726 if (tap_move_map
[path
[num_states
- 1]] == -1)
728 ERROR("TAP path doesn't finish in a stable state");
729 return ERROR_JTAG_NOT_IMPLEMENTED
;
732 /* allocate memory for a new list member */
733 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
734 last_comand_pointer
= &((*last_cmd
)->next
);
735 (*last_cmd
)->next
= NULL
;
736 (*last_cmd
)->type
= JTAG_PATHMOVE
;
738 (*last_cmd
)->cmd
.pathmove
= cmd_queue_alloc(sizeof(pathmove_command_t
));
739 (*last_cmd
)->cmd
.pathmove
->num_states
= num_states
;
740 (*last_cmd
)->cmd
.pathmove
->path
= cmd_queue_alloc(sizeof(enum tap_state
) * num_states
);
742 for (i
= 0; i
< num_states
; i
++)
743 (*last_cmd
)->cmd
.pathmove
->path
[i
] = path
[i
];
745 if (cmd_queue_cur_state
== TAP_TLR
&& cmd_queue_end_state
!= TAP_TLR
)
746 jtag_call_event_callbacks(JTAG_TRST_RELEASED
);
748 if (cmd_queue_end_state
== TAP_TLR
)
749 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
751 cmd_queue_cur_state
= path
[num_states
- 1];
756 int jtag_add_runtest(int num_cycles
, enum tap_state state
)
758 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
762 WARNING("JTAG command queued, while TRST is low (TAP in reset)");
763 return ERROR_JTAG_TRST_ASSERTED
;
766 /* allocate memory for a new list member */
767 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
768 (*last_cmd
)->next
= NULL
;
769 last_comand_pointer
= &((*last_cmd
)->next
);
770 (*last_cmd
)->type
= JTAG_RUNTEST
;
772 (*last_cmd
)->cmd
.runtest
= cmd_queue_alloc(sizeof(runtest_command_t
));
773 (*last_cmd
)->cmd
.runtest
->num_cycles
= num_cycles
;
774 (*last_cmd
)->cmd
.runtest
->end_state
= state
;
777 cmd_queue_end_state
= state
;
779 if (cmd_queue_cur_state
== TAP_TLR
&& cmd_queue_end_state
!= TAP_TLR
)
780 jtag_call_event_callbacks(JTAG_TRST_RELEASED
);
782 if (cmd_queue_end_state
== TAP_TLR
)
783 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
785 cmd_queue_cur_state
= cmd_queue_end_state
;
790 int jtag_add_reset(int req_trst
, int req_srst
)
792 int trst_with_tms
= 0;
794 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
797 req_trst
= jtag_trst
;
800 req_srst
= jtag_srst
;
802 /* Make sure that jtag_reset_config allows the requested reset */
803 /* if SRST pulls TRST, we can't fulfill srst == 1 with trst == 0 */
804 if (((jtag_reset_config
& RESET_SRST_PULLS_TRST
) && (req_srst
== 1)) && (req_trst
== 0))
805 return ERROR_JTAG_RESET_WOULD_ASSERT_TRST
;
807 /* if TRST pulls SRST, we reset with TAP T-L-R */
808 if (((jtag_reset_config
& RESET_TRST_PULLS_SRST
) && (req_trst
== 1)) && (req_srst
== 0))
814 if (req_srst
&& !(jtag_reset_config
& RESET_HAS_SRST
))
816 ERROR("requested nSRST assertion, but the current configuration doesn't support this");
817 return ERROR_JTAG_RESET_CANT_SRST
;
820 if (req_trst
&& !(jtag_reset_config
& RESET_HAS_TRST
))
826 /* allocate memory for a new list member */
827 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
828 (*last_cmd
)->next
= NULL
;
829 last_comand_pointer
= &((*last_cmd
)->next
);
830 (*last_cmd
)->type
= JTAG_RESET
;
832 (*last_cmd
)->cmd
.reset
= cmd_queue_alloc(sizeof(reset_command_t
));
833 (*last_cmd
)->cmd
.reset
->trst
= req_trst
;
834 (*last_cmd
)->cmd
.reset
->srst
= req_srst
;
836 jtag_trst
= req_trst
;
837 jtag_srst
= req_srst
;
841 jtag_call_event_callbacks(JTAG_SRST_ASSERTED
);
845 jtag_call_event_callbacks(JTAG_SRST_RELEASED
);
846 if (jtag_nsrst_delay
)
847 jtag_add_sleep(jtag_nsrst_delay
* 1000);
852 last_cmd
= &((*last_cmd
)->next
);
854 /* allocate memory for a new list member */
855 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
856 (*last_cmd
)->next
= NULL
;
857 last_comand_pointer
= &((*last_cmd
)->next
);
858 (*last_cmd
)->type
= JTAG_STATEMOVE
;
860 (*last_cmd
)->cmd
.statemove
= cmd_queue_alloc(sizeof(statemove_command_t
));
861 (*last_cmd
)->cmd
.statemove
->end_state
= TAP_TLR
;
863 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
864 cmd_queue_cur_state
= TAP_TLR
;
865 cmd_queue_end_state
= TAP_TLR
;
873 /* we just asserted nTRST, so we're now in Test-Logic-Reset,
874 * and inform possible listeners about this
876 cmd_queue_cur_state
= TAP_TLR
;
877 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
881 /* the nTRST line got deasserted, so we're still in Test-Logic-Reset,
882 * but we might want to add a delay to give the TAP time to settle
884 if (jtag_ntrst_delay
)
885 jtag_add_sleep(jtag_ntrst_delay
* 1000);
892 int jtag_add_end_state(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_cmd
)->next
= NULL
;
899 last_comand_pointer
= &((*last_cmd
)->next
);
900 (*last_cmd
)->type
= JTAG_END_STATE
;
902 (*last_cmd
)->cmd
.end_state
= cmd_queue_alloc(sizeof(end_state_command_t
));
903 (*last_cmd
)->cmd
.end_state
->end_state
= state
;
906 cmd_queue_end_state
= state
;
911 int jtag_add_sleep(u32 us
)
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_cmd
)->next
= NULL
;
918 last_comand_pointer
= &((*last_cmd
)->next
);
919 (*last_cmd
)->type
= JTAG_SLEEP
;
921 (*last_cmd
)->cmd
.sleep
= cmd_queue_alloc(sizeof(sleep_command_t
));
922 (*last_cmd
)->cmd
.sleep
->us
= us
;
927 int jtag_scan_size(scan_command_t
*cmd
)
932 /* count bits in scan command */
933 for (i
= 0; i
< cmd
->num_fields
; i
++)
935 bit_count
+= cmd
->fields
[i
].num_bits
;
941 int jtag_build_buffer(scan_command_t
*cmd
, u8
**buffer
)
946 bit_count
= jtag_scan_size(cmd
);
947 *buffer
= malloc(CEIL(bit_count
, 8));
951 for (i
= 0; i
< cmd
->num_fields
; i
++)
953 if (cmd
->fields
[i
].out_value
)
955 #ifdef _DEBUG_JTAG_IO_
956 char* char_buf
= buf_to_str(cmd
->fields
[i
].out_value
, (cmd
->fields
[i
].num_bits
> 64) ? 64 : cmd
->fields
[i
].num_bits
, 16);
958 buf_set_buf(cmd
->fields
[i
].out_value
, 0, *buffer
, bit_count
, cmd
->fields
[i
].num_bits
);
959 #ifdef _DEBUG_JTAG_IO_
960 DEBUG("fields[%i].out_value: 0x%s", i
, char_buf
);
965 bit_count
+= cmd
->fields
[i
].num_bits
;
972 int jtag_read_buffer(u8
*buffer
, scan_command_t
*cmd
)
978 /* we return ERROR_OK, unless a check fails, or a handler reports a problem */
981 for (i
= 0; i
< cmd
->num_fields
; i
++)
983 /* if neither in_value nor in_handler
984 * are specified we don't have to examine this field
986 if (cmd
->fields
[i
].in_value
|| cmd
->fields
[i
].in_handler
)
988 int num_bits
= cmd
->fields
[i
].num_bits
;
989 u8
*captured
= buf_set_buf(buffer
, bit_count
, malloc(CEIL(num_bits
, 8)), 0, num_bits
);
991 #ifdef _DEBUG_JTAG_IO_
994 char_buf
= buf_to_str(captured
, (num_bits
> 64) ? 64 : num_bits
, 16);
995 DEBUG("fields[%i].in_value: 0x%s", i
, char_buf
);
999 if (cmd
->fields
[i
].in_value
)
1001 buf_cpy(captured
, cmd
->fields
[i
].in_value
, num_bits
);
1003 if (cmd
->fields
[i
].in_handler
)
1005 if (cmd
->fields
[i
].in_handler(cmd
->fields
[i
].in_value
, cmd
->fields
[i
].in_handler_priv
, cmd
->fields
+i
) != ERROR_OK
)
1007 WARNING("in_handler reported a failed check");
1008 retval
= ERROR_JTAG_QUEUE_FAILED
;
1013 /* no in_value specified, but a handler takes care of the scanned data */
1014 if (cmd
->fields
[i
].in_handler
&& (!cmd
->fields
[i
].in_value
))
1016 if (cmd
->fields
[i
].in_handler(captured
, cmd
->fields
[i
].in_handler_priv
, cmd
->fields
+i
) != ERROR_OK
)
1018 /* We're going to call the error:handler later, but if the in_handler
1019 * reported an error we report this failure upstream
1021 WARNING("in_handler reported a failed check");
1022 retval
= ERROR_JTAG_QUEUE_FAILED
;
1028 bit_count
+= cmd
->fields
[i
].num_bits
;
1034 int jtag_check_value(u8
*captured
, void *priv
, scan_field_t
*field
)
1036 int retval
= ERROR_OK
;
1037 int num_bits
= field
->num_bits
;
1039 int compare_failed
= 0;
1041 if (field
->in_check_mask
)
1042 compare_failed
= buf_cmp_mask(captured
, field
->in_check_value
, field
->in_check_mask
, num_bits
);
1044 compare_failed
= buf_cmp(captured
, field
->in_check_value
, num_bits
);
1048 /* An error handler could have caught the failing check
1049 * only report a problem when there wasn't a handler, or if the handler
1050 * acknowledged the error
1054 char *captured_char
= buf_to_str(captured
, (num_bits
> 64) ? 64 : num_bits
, 16);
1055 char *in_check_value_char
= buf_to_str(field
->in_check_value
, (num_bits
> 64) ? 64 : num_bits
, 16);
1057 if (field
->in_check_mask
)
1059 char *in_check_mask_char
;
1060 in_check_mask_char
= buf_to_str(field
->in_check_mask
, (num_bits
> 64) ? 64 : num_bits
, 16);
1061 WARNING("value captured during scan didn't pass the requested check: captured: 0x%s check_value: 0x%s check_mask: 0x%s", captured_char
, in_check_value_char
, in_check_mask_char
);
1062 free(in_check_mask_char
);
1066 WARNING("value captured during scan didn't pass the requested check: captured: 0x%s check_value: 0x%s", captured_char
, in_check_value_char
);
1069 free(captured_char
);
1070 free(in_check_value_char
);
1072 retval
= ERROR_JTAG_QUEUE_FAILED
;
1080 set up checking of this field using the in_handler. The values passed in must be valid until
1081 after jtag_execute() has completed.
1083 void jtag_set_check_value(scan_field_t
*field
, u8
*value
, u8
*mask
, error_handler_t
*in_error_handler
)
1086 field
->in_handler
= jtag_check_value
;
1088 field
->in_handler
= NULL
; /* No check, e.g. embeddedice uses value==NULL to indicate no check */
1089 field
->in_handler_priv
= NULL
; /* this will be filled in at the invocation site to point to the field duplicate */
1090 field
->in_check_value
= value
;
1091 field
->in_check_mask
= mask
;
1094 enum scan_type
jtag_scan_type(scan_command_t
*cmd
)
1099 for (i
= 0; i
< cmd
->num_fields
; i
++)
1101 if (cmd
->fields
[i
].in_value
|| cmd
->fields
[i
].in_handler
)
1103 if (cmd
->fields
[i
].out_value
)
1110 int jtag_execute_queue(void)
1114 retval
= jtag
->execute_queue();
1118 jtag_command_queue
= NULL
;
1119 last_comand_pointer
= &jtag_command_queue
;
1124 int jtag_reset_callback(enum jtag_event event
, void *priv
)
1126 jtag_device_t
*device
= priv
;
1130 if (event
== JTAG_TRST_ASSERTED
)
1132 buf_set_ones(device
->cur_instr
, device
->ir_length
);
1139 void jtag_sleep(u32 us
)
1144 /* Try to examine chain layout according to IEEE 1149.1 §12
1146 int jtag_examine_chain()
1148 jtag_device_t
*device
= jtag_devices
;
1150 u8 idcode_buffer
[JTAG_MAX_CHAIN_SIZE
* 4];
1153 int device_count
= 0;
1154 u8 zero_check
= 0x0;
1155 u8 one_check
= 0xff;
1158 field
.num_bits
= sizeof(idcode_buffer
) * 8;
1159 field
.out_value
= idcode_buffer
;
1160 field
.out_mask
= NULL
;
1161 field
.in_value
= idcode_buffer
;
1162 field
.in_check_value
= NULL
;
1163 field
.in_check_mask
= NULL
;
1164 field
.in_handler
= NULL
;
1165 field
.in_handler_priv
= NULL
;
1167 for (i
= 0; i
< JTAG_MAX_CHAIN_SIZE
; i
++)
1169 buf_set_u32(idcode_buffer
, i
* 32, 32, 0x000000FF);
1172 jtag_add_plain_dr_scan(1, &field
, TAP_TLR
);
1173 jtag_execute_queue();
1175 for (i
= 0; i
< JTAG_MAX_CHAIN_SIZE
* 4; i
++)
1177 zero_check
|= idcode_buffer
[i
];
1178 one_check
&= idcode_buffer
[i
];
1181 /* if there wasn't a single non-zero bit or if all bits were one, the scan isn't valid */
1182 if ((zero_check
== 0x00) || (one_check
== 0xff))
1184 ERROR("JTAG communication failure, check connection, JTAG interface, target power etc.");
1185 return ERROR_JTAG_INIT_FAILED
;
1188 for (bit_count
= 0; bit_count
< (JTAG_MAX_CHAIN_SIZE
* 32) - 31;)
1190 u32 idcode
= buf_get_u32(idcode_buffer
, bit_count
, 32);
1191 if ((idcode
& 1) == 0)
1193 /* LSB must not be 0, this indicates a device in bypass */
1204 if (idcode
== 0x000000FF)
1206 /* End of chain (invalid manufacturer ID) */
1212 device
->idcode
= idcode
;
1213 device
= device
->next
;
1217 manufacturer
= (idcode
& 0xffe) >> 1;
1218 part
= (idcode
& 0xffff000) >> 12;
1219 version
= (idcode
& 0xf0000000) >> 28;
1221 INFO("JTAG device found: 0x%8.8x (Manufacturer: 0x%3.3x, Part: 0x%4.4x, Version: 0x%1.1x)",
1222 idcode
, manufacturer
, part
, version
);
1228 /* see if number of discovered devices matches configuration */
1229 if (device_count
!= jtag_num_devices
)
1231 ERROR("number of discovered devices in JTAG chain (%i) doesn't match configuration (%i)",
1232 device_count
, jtag_num_devices
);
1233 ERROR("check the config file and ensure proper JTAG communication (connections, speed, ...)");
1234 return ERROR_JTAG_INIT_FAILED
;
1240 int jtag_validate_chain()
1242 jtag_device_t
*device
= jtag_devices
;
1243 int total_ir_length
= 0;
1250 total_ir_length
+= device
->ir_length
;
1251 device
= device
->next
;
1254 total_ir_length
+= 2;
1255 ir_test
= malloc(CEIL(total_ir_length
, 8));
1256 buf_set_ones(ir_test
, total_ir_length
);
1259 field
.num_bits
= total_ir_length
;
1260 field
.out_value
= ir_test
;
1261 field
.out_mask
= NULL
;
1262 field
.in_value
= ir_test
;
1263 field
.in_check_value
= NULL
;
1264 field
.in_check_mask
= NULL
;
1265 field
.in_handler
= NULL
;
1266 field
.in_handler_priv
= NULL
;
1268 jtag_add_plain_ir_scan(1, &field
, TAP_TLR
);
1269 jtag_execute_queue();
1271 device
= jtag_devices
;
1274 if (buf_get_u32(ir_test
, chain_pos
, 2) != 0x1)
1276 char *cbuf
= buf_to_str(ir_test
, total_ir_length
, 16);
1277 ERROR("Error validating JTAG scan chain, IR mismatch, scan returned 0x%s", cbuf
);
1280 return ERROR_JTAG_INIT_FAILED
;
1282 chain_pos
+= device
->ir_length
;
1283 device
= device
->next
;
1286 if (buf_get_u32(ir_test
, chain_pos
, 2) != 0x3)
1288 char *cbuf
= buf_to_str(ir_test
, total_ir_length
, 16);
1289 ERROR("Error validating JTAG scan chain, IR mismatch, scan returned 0x%s", cbuf
);
1292 return ERROR_JTAG_INIT_FAILED
;
1300 int jtag_register_commands(struct command_context_s
*cmd_ctx
)
1302 register_command(cmd_ctx
, NULL
, "interface", handle_interface_command
,
1303 COMMAND_CONFIG
, NULL
);
1304 register_command(cmd_ctx
, NULL
, "jtag_speed", handle_jtag_speed_command
,
1305 COMMAND_ANY
, "set jtag speed (if supported) <speed>");
1306 register_command(cmd_ctx
, NULL
, "jtag_device", handle_jtag_device_command
,
1307 COMMAND_CONFIG
, "jtag_device <ir_length> <ir_expected> <ir_mask>");
1308 register_command(cmd_ctx
, NULL
, "reset_config", handle_reset_config_command
,
1309 COMMAND_CONFIG
, NULL
);
1310 register_command(cmd_ctx
, NULL
, "jtag_nsrst_delay", handle_jtag_nsrst_delay_command
,
1311 COMMAND_CONFIG
, NULL
);
1312 register_command(cmd_ctx
, NULL
, "jtag_ntrst_delay", handle_jtag_ntrst_delay_command
,
1313 COMMAND_CONFIG
, NULL
);
1315 register_command(cmd_ctx
, NULL
, "scan_chain", handle_scan_chain_command
,
1316 COMMAND_EXEC
, "print current scan chain configuration");
1318 register_command(cmd_ctx
, NULL
, "endstate", handle_endstate_command
,
1319 COMMAND_EXEC
, "finish JTAG operations in <tap_state>");
1320 register_command(cmd_ctx
, NULL
, "jtag_reset", handle_jtag_reset_command
,
1321 COMMAND_EXEC
, "toggle reset lines <trst> <srst>");
1322 register_command(cmd_ctx
, NULL
, "runtest", handle_runtest_command
,
1323 COMMAND_EXEC
, "move to Run-Test/Idle, and execute <num_cycles>");
1324 register_command(cmd_ctx
, NULL
, "statemove", handle_statemove_command
,
1325 COMMAND_EXEC
, "move to current endstate or [tap_state]");
1326 register_command(cmd_ctx
, NULL
, "irscan", handle_irscan_command
,
1327 COMMAND_EXEC
, "execute IR scan <device> <instr> [dev2] [instr2] ...");
1328 register_command(cmd_ctx
, NULL
, "drscan", handle_drscan_command
,
1329 COMMAND_EXEC
, "execute DR scan <device> <var> [dev2] [var2] ...");
1331 register_command(cmd_ctx
, NULL
, "verify_ircapture", handle_verify_ircapture_command
,
1332 COMMAND_ANY
, "verify value captured during Capture-IR <enable|disable>");
1336 int jtag_init(struct command_context_s
*cmd_ctx
)
1338 int i
, validate_tries
= 0;
1342 if (jtag_speed
== -1)
1345 if (jtag_interface
&& (jtag_interface
[0] != 0))
1346 /* configuration var 'jtag_interface' is set, and not empty */
1347 for (i
= 0; jtag_interfaces
[i
]; i
++)
1349 if (strcmp(jtag_interface
, jtag_interfaces
[i
]->name
) == 0)
1351 jtag_device_t
*device
;
1352 device
= jtag_devices
;
1354 if (jtag_interfaces
[i
]->init() != ERROR_OK
)
1355 return ERROR_JTAG_INIT_FAILED
;
1356 jtag
= jtag_interfaces
[i
];
1358 jtag_ir_scan_size
= 0;
1359 jtag_num_devices
= 0;
1360 while (device
!= NULL
)
1362 jtag_ir_scan_size
+= device
->ir_length
;
1364 device
= device
->next
;
1367 jtag_add_statemove(TAP_TLR
);
1368 jtag_execute_queue();
1370 /* examine chain first, as this could discover the real chain layout */
1371 if (jtag_examine_chain() != ERROR_OK
)
1373 ERROR("trying to validate configured JTAG chain anyway...");
1376 while (jtag_validate_chain() != ERROR_OK
)
1379 if (validate_tries
> 5)
1381 ERROR("Could not validate JTAG chain, exit");
1383 return ERROR_JTAG_INVALID_INTERFACE
;
1392 /* no valid interface was found (i.e. the configuration option,
1393 * didn't match one of the compiled-in interfaces
1395 ERROR("No valid jtag interface found (%s)", jtag_interface
);
1396 ERROR("compiled-in jtag interfaces:");
1397 for (i
= 0; jtag_interfaces
[i
]; i
++)
1399 ERROR("%i: %s", i
, jtag_interfaces
[i
]->name
);
1403 return ERROR_JTAG_INVALID_INTERFACE
;
1406 int handle_interface_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1410 /* only if the configuration var isn't overwritten from cmdline */
1411 if (!jtag_interface
)
1413 if (args
[0] && (args
[0][0] != 0))
1415 for (i
=0; jtag_interfaces
[i
]; i
++)
1417 if (strcmp(args
[0], jtag_interfaces
[i
]->name
) == 0)
1419 if (jtag_interfaces
[i
]->register_commands(cmd_ctx
) != ERROR_OK
)
1422 jtag_interface
= jtag_interfaces
[i
]->name
;
1429 /* remember the requested interface name, so we can complain about it later */
1430 jtag_interface
= strdup(args
[0]);
1431 DEBUG("'interface' command didn't specify a valid interface");
1437 int handle_jtag_device_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1439 jtag_device_t
**last_device_p
= &jtag_devices
;
1443 while ((*last_device_p
)->next
)
1444 last_device_p
= &((*last_device_p
)->next
);
1445 last_device_p
= &((*last_device_p
)->next
);
1451 *last_device_p
= malloc(sizeof(jtag_device_t
));
1452 (*last_device_p
)->ir_length
= strtoul(args
[0], NULL
, 0);
1454 (*last_device_p
)->expected
= malloc((*last_device_p
)->ir_length
);
1455 buf_set_u32((*last_device_p
)->expected
, 0, (*last_device_p
)->ir_length
, strtoul(args
[1], NULL
, 0));
1456 (*last_device_p
)->expected_mask
= malloc((*last_device_p
)->ir_length
);
1457 buf_set_u32((*last_device_p
)->expected_mask
, 0, (*last_device_p
)->ir_length
, strtoul(args
[2], NULL
, 0));
1459 (*last_device_p
)->cur_instr
= malloc((*last_device_p
)->ir_length
);
1460 (*last_device_p
)->bypass
= 1;
1461 buf_set_ones((*last_device_p
)->cur_instr
, (*last_device_p
)->ir_length
);
1463 (*last_device_p
)->next
= NULL
;
1465 jtag_register_event_callback(jtag_reset_callback
, (*last_device_p
));
1472 int handle_scan_chain_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1474 jtag_device_t
*device
= jtag_devices
;
1475 int device_count
= 0;
1479 u32 expected
, expected_mask
, cur_instr
;
1480 expected
= buf_get_u32(device
->expected
, 0, device
->ir_length
);
1481 expected_mask
= buf_get_u32(device
->expected_mask
, 0, device
->ir_length
);
1482 cur_instr
= buf_get_u32(device
->cur_instr
, 0, device
->ir_length
);
1483 command_print(cmd_ctx
, "%i: idcode: 0x%8.8x ir length %i, ir capture 0x%x, ir mask 0x%x, current instruction 0x%x", device_count
, device
->idcode
, device
->ir_length
, expected
, expected_mask
, cur_instr
);
1484 device
= device
->next
;
1491 int handle_reset_config_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1495 if (strcmp(args
[0], "none") == 0)
1496 jtag_reset_config
= RESET_NONE
;
1497 else if (strcmp(args
[0], "trst_only") == 0)
1498 jtag_reset_config
= RESET_HAS_TRST
;
1499 else if (strcmp(args
[0], "srst_only") == 0)
1500 jtag_reset_config
= RESET_HAS_SRST
;
1501 else if (strcmp(args
[0], "trst_and_srst") == 0)
1502 jtag_reset_config
= RESET_TRST_AND_SRST
;
1505 ERROR("invalid reset_config argument, defaulting to none");
1506 jtag_reset_config
= RESET_NONE
;
1507 return ERROR_INVALID_ARGUMENTS
;
1513 if (strcmp(args
[1], "srst_pulls_trst") == 0)
1514 jtag_reset_config
|= RESET_SRST_PULLS_TRST
;
1515 else if (strcmp(args
[1], "trst_pulls_srst") == 0)
1516 jtag_reset_config
|= RESET_TRST_PULLS_SRST
;
1517 else if (strcmp(args
[1], "combined") == 0)
1518 jtag_reset_config
|= RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
;
1519 else if (strcmp(args
[1], "separate") == 0)
1520 jtag_reset_config
&= ~(RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
);
1523 ERROR("invalid reset_config argument, defaulting to none");
1524 jtag_reset_config
= RESET_NONE
;
1525 return ERROR_INVALID_ARGUMENTS
;
1531 if (strcmp(args
[2], "trst_open_drain") == 0)
1532 jtag_reset_config
|= RESET_TRST_OPEN_DRAIN
;
1533 else if (strcmp(args
[2], "trst_push_pull") == 0)
1534 jtag_reset_config
&= ~RESET_TRST_OPEN_DRAIN
;
1537 ERROR("invalid reset_config argument, defaulting to none");
1538 jtag_reset_config
= RESET_NONE
;
1539 return ERROR_INVALID_ARGUMENTS
;
1545 if (strcmp(args
[3], "srst_push_pull") == 0)
1546 jtag_reset_config
|= RESET_SRST_PUSH_PULL
;
1547 else if (strcmp(args
[3], "srst_open_drain") == 0)
1548 jtag_reset_config
&= ~RESET_SRST_PUSH_PULL
;
1551 ERROR("invalid reset_config argument, defaulting to none");
1552 jtag_reset_config
= RESET_NONE
;
1553 return ERROR_INVALID_ARGUMENTS
;
1560 int handle_jtag_nsrst_delay_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1564 ERROR("jtag_nsrst_delay <ms> command takes one required argument");
1569 jtag_nsrst_delay
= strtoul(args
[0], NULL
, 0);
1575 int handle_jtag_ntrst_delay_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1579 ERROR("jtag_ntrst_delay <ms> command takes one required argument");
1584 jtag_ntrst_delay
= strtoul(args
[0], NULL
, 0);
1590 int handle_jtag_speed_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1593 command_print(cmd_ctx
, "jtag_speed: %i", jtag_speed
);
1597 /* this command can be called during CONFIG,
1598 * in which case jtag isn't initialized */
1600 jtag
->speed(strtoul(args
[0], NULL
, 0));
1602 jtag_speed
= strtoul(args
[0], NULL
, 0);
1608 int handle_endstate_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1610 enum tap_state state
;
1614 return ERROR_COMMAND_SYNTAX_ERROR
;
1618 for (state
= 0; state
< 16; state
++)
1620 if (strcmp(args
[0], tap_state_strings
[state
]) == 0)
1622 jtag_add_end_state(state
);
1623 jtag_execute_queue();
1627 command_print(cmd_ctx
, "current endstate: %s", tap_state_strings
[end_state
]);
1632 int handle_jtag_reset_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1640 return ERROR_COMMAND_SYNTAX_ERROR
;
1644 if (args
[0][0] == '1')
1646 else if (args
[0][0] == '0')
1650 return ERROR_COMMAND_SYNTAX_ERROR
;
1653 if (args
[1][0] == '1')
1655 else if (args
[1][0] == '0')
1659 return ERROR_COMMAND_SYNTAX_ERROR
;
1662 if ((retval
= jtag_add_reset(trst
, srst
)) != ERROR_OK
)
1666 case ERROR_JTAG_RESET_WOULD_ASSERT_TRST
:
1667 command_print(cmd_ctx
, "requested reset would assert trst\nif this is acceptable, use jtag_reset 1 %c", args
[1][0]);
1669 case ERROR_JTAG_RESET_CANT_SRST
:
1670 command_print(cmd_ctx
, "can't assert srst because the current reset_config doesn't support it");
1673 command_print(cmd_ctx
, "unknown error");
1676 jtag_execute_queue();
1681 int handle_runtest_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1685 return ERROR_COMMAND_SYNTAX_ERROR
;
1688 jtag_add_runtest(strtol(args
[0], NULL
, 0), -1);
1689 jtag_execute_queue();
1695 int handle_statemove_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1697 enum tap_state state
;
1702 for (state
= 0; state
< 16; state
++)
1704 if (strcmp(args
[0], tap_state_strings
[state
]) == 0)
1711 jtag_add_statemove(state
);
1712 jtag_execute_queue();
1718 int handle_irscan_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1721 scan_field_t
*fields
;
1723 if ((argc
< 2) || (argc
% 2))
1725 return ERROR_COMMAND_SYNTAX_ERROR
;
1728 fields
= malloc(sizeof(scan_field_t
) * argc
/ 2);
1730 for (i
= 0; i
< argc
/ 2; i
++)
1732 int device
= strtoul(args
[i
*2], NULL
, 0);
1733 int field_size
= jtag_get_device(device
)->ir_length
;
1734 fields
[i
].device
= device
;
1735 fields
[i
].out_value
= malloc(CEIL(field_size
, 8));
1736 buf_set_u32(fields
[i
].out_value
, 0, field_size
, strtoul(args
[i
*2+1], NULL
, 0));
1737 fields
[i
].out_mask
= NULL
;
1738 fields
[i
].in_value
= NULL
;
1739 fields
[i
].in_check_mask
= NULL
;
1740 fields
[i
].in_handler
= NULL
;
1741 fields
[i
].in_handler_priv
= NULL
;
1744 jtag_add_ir_scan(argc
/ 2, fields
, -1);
1745 jtag_execute_queue();
1747 for (i
= 0; i
< argc
/ 2; i
++)
1748 free(fields
[i
].out_value
);
1755 int handle_drscan_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1757 scan_field_t
*fields
;
1759 int field_count
= 0;
1763 if ((argc
< 2) || (argc
% 2))
1765 return ERROR_COMMAND_SYNTAX_ERROR
;
1768 for (i
= 0; i
< argc
; i
+=2)
1770 var
= get_var_by_namenum(args
[i
+1]);
1773 num_fields
+= var
->num_fields
;
1777 command_print(cmd_ctx
, "variable %s doesn't exist", args
[i
+1]);
1782 fields
= malloc(sizeof(scan_field_t
) * num_fields
);
1784 for (i
= 0; i
< argc
; i
+=2)
1786 var
= get_var_by_namenum(args
[i
+1]);
1788 for (j
= 0; j
< var
->num_fields
; j
++)
1790 fields
[field_count
].device
= strtol(args
[i
], NULL
, 0);
1791 fields
[field_count
].num_bits
= var
->fields
[j
].num_bits
;
1792 fields
[field_count
].out_value
= malloc(CEIL(var
->fields
[j
].num_bits
, 8));
1793 buf_set_u32(fields
[field_count
].out_value
, 0, var
->fields
[j
].num_bits
, var
->fields
[j
].value
);
1794 fields
[field_count
].out_mask
= NULL
;
1795 fields
[field_count
].in_value
= fields
[field_count
].out_value
;
1796 fields
[field_count
].in_check_mask
= NULL
;
1797 fields
[field_count
].in_check_value
= NULL
;
1798 fields
[field_count
].in_handler
= field_le_to_host
;
1799 fields
[field_count
++].in_handler_priv
= &(var
->fields
[j
]);
1803 jtag_add_dr_scan(num_fields
, fields
, -1);
1804 jtag_execute_queue();
1806 for (i
= 0; i
< argc
/ 2; i
++)
1807 free(fields
[i
].out_value
);
1814 int handle_verify_ircapture_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1818 if (strcmp(args
[0], "enable") == 0)
1820 jtag_verify_capture_ir
= 1;
1822 else if (strcmp(args
[0], "disable") == 0)
1824 jtag_verify_capture_ir
= 0;
1827 return ERROR_COMMAND_SYNTAX_ERROR
;
1829 } else if (argc
!= 0)
1831 return ERROR_COMMAND_SYNTAX_ERROR
;
1834 command_print(cmd_ctx
, "verify Capture-IR is %s", (jtag_verify_capture_ir
) ? "enabled": "disabled");
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)