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
64 /* TLR RTI SD PD SI PI */
65 {0x7f, 0x00, 0x17, 0x0a, 0x1b, 0x16}, /* TLR */
66 {0x7f, 0x00, 0x25, 0x05, 0x2b, 0x0b}, /* RTI */
67 {0x7f, 0x31, 0x00, 0x01, 0x0f, 0x2f}, /* SD */
68 {0x7f, 0x30, 0x20, 0x17, 0x1e, 0x2f}, /* PD */
69 {0x7f, 0x31, 0x07, 0x17, 0x00, 0x01}, /* SI */
70 {0x7f, 0x30, 0x1c, 0x17, 0x20, 0x2f} /* PI */
73 int tap_move_map
[16] = {
74 0, -1, -1, 2, -1, 3, -1, -1,
75 1, -1, -1, 4, -1, 5, -1, -1
78 tap_transition_t tap_transitions
[16] =
80 {TAP_TLR
, TAP_RTI
}, /* TLR */
81 {TAP_SIS
, TAP_CD
}, /* SDS */
82 {TAP_E1D
, TAP_SD
}, /* CD */
83 {TAP_E1D
, TAP_SD
}, /* SD */
84 {TAP_UD
, TAP_PD
}, /* E1D */
85 {TAP_E2D
, TAP_PD
}, /* PD */
86 {TAP_UD
, TAP_SD
}, /* E2D */
87 {TAP_SDS
, TAP_RTI
}, /* UD */
88 {TAP_SDS
, TAP_RTI
}, /* RTI */
89 {TAP_TLR
, TAP_CI
}, /* SIS */
90 {TAP_E1I
, TAP_SI
}, /* CI */
91 {TAP_E1I
, TAP_SI
}, /* SI */
92 {TAP_UI
, TAP_PI
}, /* E1I */
93 {TAP_E2I
, TAP_PI
}, /* PI */
94 {TAP_UI
, TAP_SI
}, /* E2I */
95 {TAP_SDS
, TAP_RTI
} /* UI */
98 enum tap_state end_state
= TAP_TLR
;
99 enum tap_state cur_state
= TAP_TLR
;
103 jtag_command_t
*jtag_command_queue
= NULL
;
104 jtag_command_t
**last_comand_pointer
= &jtag_command_queue
;
105 jtag_device_t
*jtag_devices
= NULL
;
106 int jtag_num_devices
= 0;
107 int jtag_ir_scan_size
= 0;
108 enum reset_types jtag_reset_config
= RESET_NONE
;
109 enum tap_state cmd_queue_end_state
= TAP_TLR
;
110 enum tap_state cmd_queue_cur_state
= TAP_TLR
;
112 int jtag_verify_capture_ir
= 1;
114 /* callbacks to inform high-level handlers about JTAG state changes */
115 jtag_event_callback_t
*jtag_event_callbacks
;
117 /* jtag interfaces (parport, FTDI-USB, TI-USB, ...)
119 #if BUILD_PARPORT == 1
120 extern jtag_interface_t parport_interface
;
123 #if BUILD_FTDI2232 == 1
124 extern jtag_interface_t ftdi2232_interface
;
127 #if BUILD_FTD2XX == 1
128 extern jtag_interface_t ftd2xx_interface
;
131 #if BUILD_AMTJTAGACCEL == 1
132 extern jtag_interface_t amt_jtagaccel_interface
;
135 #if BUILD_EP93XX == 1
136 extern jtag_interface_t ep93xx_interface
;
139 jtag_interface_t
*jtag_interfaces
[] = {
140 #if BUILD_PARPORT == 1
143 #if BUILD_FTDI2232 == 1
146 #if BUILD_FTD2XX == 1
149 #if BUILD_AMTJTAGACCEL == 1
150 &amt_jtagaccel_interface
,
152 #if BUILD_EP93XX == 1
158 jtag_interface_t
*jtag
= NULL
;
161 char* jtag_interface
= NULL
;
164 /* forward declarations */
167 int handle_interface_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
168 int handle_jtag_speed_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
169 int handle_jtag_device_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
170 int handle_reset_config_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
172 int handle_scan_chain_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
174 int handle_endstate_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
175 int handle_jtag_reset_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
176 int handle_runtest_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
177 int handle_statemove_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
178 int handle_irscan_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
179 int handle_drscan_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
181 int handle_verify_ircapture_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
183 int jtag_register_event_callback(int (*callback
)(enum jtag_event event
, void *priv
), void *priv
)
185 jtag_event_callback_t
**callbacks_p
= &jtag_event_callbacks
;
187 if (callback
== NULL
)
189 return ERROR_INVALID_ARGUMENTS
;
194 while ((*callbacks_p
)->next
)
195 callbacks_p
= &((*callbacks_p
)->next
);
196 callbacks_p
= &((*callbacks_p
)->next
);
199 (*callbacks_p
) = malloc(sizeof(jtag_event_callback_t
));
200 (*callbacks_p
)->callback
= callback
;
201 (*callbacks_p
)->priv
= priv
;
202 (*callbacks_p
)->next
= NULL
;
207 int jtag_unregister_event_callback(int (*callback
)(enum jtag_event event
, void *priv
))
209 jtag_event_callback_t
**callbacks_p
= &jtag_event_callbacks
;
211 if (callback
== NULL
)
213 return ERROR_INVALID_ARGUMENTS
;
218 jtag_event_callback_t
**next
= &((*callbacks_p
)->next
);
219 if ((*callbacks_p
)->callback
== callback
)
222 *callbacks_p
= *next
;
230 int jtag_call_event_callbacks(enum jtag_event event
)
232 jtag_event_callback_t
*callback
= jtag_event_callbacks
;
234 DEBUG("jtag event: %i", event
);
238 callback
->callback(event
, callback
->priv
);
239 callback
= callback
->next
;
245 /* returns a pointer to the pointer of the last command in queue
246 * this may be a pointer to the root pointer (jtag_command_queue)
247 * or to the next member of the last but one command
249 jtag_command_t
** jtag_get_last_command_p(void)
251 /* jtag_command_t *cmd = jtag_command_queue;
257 return &jtag_command_queue;
261 return last_comand_pointer
;
264 /* returns a pointer to the n-th device in the scan chain */
265 jtag_device_t
* jtag_get_device(int num
)
267 jtag_device_t
*device
= jtag_devices
;
274 device
= device
->next
;
281 void* cmd_queue_alloc(size_t size
)
283 cmd_queue_page_t
**p_page
= &cmd_queue_pages
;
288 while ((*p_page
)->next
)
289 p_page
= &((*p_page
)->next
);
290 if (CMD_QUEUE_PAGE_SIZE
- (*p_page
)->used
< size
)
291 p_page
= &((*p_page
)->next
);
296 *p_page
= malloc(sizeof(cmd_queue_page_t
));
298 (*p_page
)->address
= malloc(CMD_QUEUE_PAGE_SIZE
);
299 (*p_page
)->next
= NULL
;
302 offset
= (*p_page
)->used
;
303 (*p_page
)->used
+= size
;
305 return ((*p_page
)->address
) + offset
;
308 void cmd_queue_free()
310 cmd_queue_page_t
*page
= cmd_queue_pages
;
314 cmd_queue_page_t
*last
= page
;
320 cmd_queue_pages
= NULL
;
323 int jtag_add_ir_scan(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
325 jtag_command_t
**last_cmd
;
326 jtag_device_t
*device
;
329 /* int changed = 0; */
333 WARNING("JTAG command queued, while TRST is low (TAP in reset)");
334 return ERROR_JTAG_TRST_ASSERTED
;
338 for (i=0; i<num_fields; i++)
340 device = jtag_get_device(fields[i].device);
343 if (buf_cmp(device->cur_instr, fields[i].out_value, device->ir_length))
348 ERROR("inexistant device specified for ir scan");
349 return ERROR_INVALID_ARGUMENTS;
357 last_cmd
= jtag_get_last_command_p();
359 /* allocate memory for a new list member */
360 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
361 (*last_cmd
)->next
= NULL
;
362 last_comand_pointer
= &((*last_cmd
)->next
);
363 (*last_cmd
)->type
= JTAG_SCAN
;
365 /* allocate memory for ir scan command */
366 (*last_cmd
)->cmd
.scan
= cmd_queue_alloc(sizeof(scan_command_t
));
367 (*last_cmd
)->cmd
.scan
->ir_scan
= 1;
368 (*last_cmd
)->cmd
.scan
->num_fields
= jtag_num_devices
; /* one field per device */
369 (*last_cmd
)->cmd
.scan
->fields
= cmd_queue_alloc(jtag_num_devices
* sizeof(scan_field_t
));
370 (*last_cmd
)->cmd
.scan
->end_state
= state
;
373 cmd_queue_end_state
= state
;
375 if (cmd_queue_cur_state
== TAP_TLR
&& cmd_queue_end_state
!= TAP_TLR
)
376 jtag_call_event_callbacks(JTAG_TRST_RELEASED
);
378 if (cmd_queue_end_state
== TAP_TLR
)
379 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
381 cmd_queue_cur_state
= cmd_queue_end_state
;
383 for (i
=0; i
< jtag_num_devices
; i
++)
386 device
= jtag_get_device(i
);
387 scan_size
= device
->ir_length
;
388 (*last_cmd
)->cmd
.scan
->fields
[i
].device
= i
;
389 (*last_cmd
)->cmd
.scan
->fields
[i
].num_bits
= scan_size
;
390 (*last_cmd
)->cmd
.scan
->fields
[i
].in_value
= NULL
;
391 if (jtag_verify_capture_ir
)
393 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_value
= buf_cpy(device
->expected
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
394 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_mask
= buf_cpy(device
->expected_mask
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
398 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_value
= NULL
;
399 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_mask
= NULL
;
401 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler
= NULL
;
402 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler_priv
= NULL
;
404 /* search the list */
405 for (j
=0; j
< num_fields
; j
++)
407 if (i
== fields
[j
].device
)
410 (*last_cmd
)->cmd
.scan
->fields
[i
].out_value
= buf_cpy(fields
[j
].out_value
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
411 (*last_cmd
)->cmd
.scan
->fields
[i
].out_mask
= buf_cpy(fields
[j
].out_mask
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
420 /* if a device isn't listed, set it to BYPASS */
421 (*last_cmd
)->cmd
.scan
->fields
[i
].out_value
= buf_set_ones(cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
422 (*last_cmd
)->cmd
.scan
->fields
[i
].out_mask
= NULL
;
427 /* update device information */
428 buf_cpy((*last_cmd
)->cmd
.scan
->fields
[i
].out_value
, jtag_get_device(i
)->cur_instr
, scan_size
);
434 int jtag_add_plain_ir_scan(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
436 jtag_command_t
**last_cmd
;
441 WARNING("JTAG command queued, while TRST is low (TAP in reset)");
442 return ERROR_JTAG_TRST_ASSERTED
;
445 last_cmd
= jtag_get_last_command_p();
447 /* allocate memory for a new list member */
448 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
449 (*last_cmd
)->next
= NULL
;
450 last_comand_pointer
= &((*last_cmd
)->next
);
451 (*last_cmd
)->type
= JTAG_SCAN
;
453 /* allocate memory for ir scan command */
454 (*last_cmd
)->cmd
.scan
= cmd_queue_alloc(sizeof(scan_command_t
));
455 (*last_cmd
)->cmd
.scan
->ir_scan
= 1;
456 (*last_cmd
)->cmd
.scan
->num_fields
= num_fields
;
457 (*last_cmd
)->cmd
.scan
->fields
= cmd_queue_alloc(num_fields
* sizeof(scan_field_t
));
458 (*last_cmd
)->cmd
.scan
->end_state
= state
;
461 cmd_queue_end_state
= state
;
463 if (cmd_queue_cur_state
== TAP_TLR
&& cmd_queue_end_state
!= TAP_TLR
)
464 jtag_call_event_callbacks(JTAG_TRST_RELEASED
);
466 if (cmd_queue_end_state
== TAP_TLR
)
467 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
469 cmd_queue_cur_state
= cmd_queue_end_state
;
471 for (i
= 0; i
< num_fields
; i
++)
473 int num_bits
= fields
[i
].num_bits
;
474 int num_bytes
= CEIL(fields
[i
].num_bits
, 8);
475 (*last_cmd
)->cmd
.scan
->fields
[i
].device
= fields
[i
].device
;
476 (*last_cmd
)->cmd
.scan
->fields
[i
].num_bits
= num_bits
;
477 (*last_cmd
)->cmd
.scan
->fields
[i
].out_value
= buf_cpy(fields
[i
].out_value
, cmd_queue_alloc(num_bytes
), num_bits
);
478 (*last_cmd
)->cmd
.scan
->fields
[i
].out_mask
= buf_cpy(fields
[i
].out_mask
, cmd_queue_alloc(num_bytes
), num_bits
);
479 (*last_cmd
)->cmd
.scan
->fields
[i
].in_value
= fields
[i
].in_value
;
480 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_value
= buf_cpy(fields
[i
].in_check_value
, cmd_queue_alloc(num_bytes
), num_bits
);
481 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_mask
= buf_cpy(fields
[i
].in_check_mask
, cmd_queue_alloc(num_bytes
), num_bits
);
482 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler
= NULL
;
483 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler_priv
= NULL
;
488 int jtag_add_dr_scan(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
491 int bypass_devices
= 0;
493 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
494 jtag_device_t
*device
= jtag_devices
;
499 WARNING("JTAG command queued, while TRST is low (TAP in reset)");
500 return ERROR_JTAG_TRST_ASSERTED
;
503 /* count devices in bypass */
508 device
= device
->next
;
511 /* allocate memory for a new list member */
512 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
513 last_comand_pointer
= &((*last_cmd
)->next
);
514 (*last_cmd
)->next
= NULL
;
515 (*last_cmd
)->type
= JTAG_SCAN
;
517 /* allocate memory for dr scan command */
518 (*last_cmd
)->cmd
.scan
= cmd_queue_alloc(sizeof(scan_command_t
));
519 (*last_cmd
)->cmd
.scan
->ir_scan
= 0;
520 (*last_cmd
)->cmd
.scan
->num_fields
= num_fields
+ bypass_devices
;
521 (*last_cmd
)->cmd
.scan
->fields
= cmd_queue_alloc((num_fields
+ bypass_devices
) * sizeof(scan_field_t
));
522 (*last_cmd
)->cmd
.scan
->end_state
= state
;
525 cmd_queue_end_state
= state
;
527 if (cmd_queue_cur_state
== TAP_TLR
&& cmd_queue_end_state
!= TAP_TLR
)
528 jtag_call_event_callbacks(JTAG_TRST_RELEASED
);
530 if (cmd_queue_end_state
== TAP_TLR
)
531 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
533 cmd_queue_cur_state
= cmd_queue_end_state
;
535 for (i
=0; i
< jtag_num_devices
; i
++)
538 (*last_cmd
)->cmd
.scan
->fields
[field_count
].device
= i
;
540 for (j
=0; j
< num_fields
; j
++)
542 if (i
== fields
[j
].device
)
545 scan_size
= fields
[j
].num_bits
;
546 (*last_cmd
)->cmd
.scan
->fields
[field_count
].num_bits
= scan_size
;
547 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_value
= buf_cpy(fields
[j
].out_value
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
548 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_mask
= buf_cpy(fields
[j
].out_mask
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
549 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_value
= fields
[j
].in_value
;
550 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_check_value
= buf_cpy(fields
[j
].in_check_value
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
551 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_check_mask
= buf_cpy(fields
[j
].in_check_mask
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
552 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_handler
= fields
[j
].in_handler
;
553 (*last_cmd
)->cmd
.scan
->fields
[field_count
++].in_handler_priv
= fields
[j
].in_handler_priv
;
558 /* if a device isn't listed, the BYPASS register should be selected */
559 if (!jtag_get_device(i
)->bypass
)
561 ERROR("BUG: no scan data for a device not in BYPASS");
565 /* program the scan field to 1 bit length, and ignore it's value */
566 (*last_cmd
)->cmd
.scan
->fields
[field_count
].num_bits
= 1;
567 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_value
= NULL
;
568 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_mask
= NULL
;
569 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_value
= NULL
;
570 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_check_value
= NULL
;
571 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_check_mask
= NULL
;
572 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_handler
= NULL
;
573 (*last_cmd
)->cmd
.scan
->fields
[field_count
++].in_handler_priv
= NULL
;
577 /* if a device is listed, the BYPASS register must not be selected */
578 if (jtag_get_device(i
)->bypass
)
580 ERROR("BUG: scan data for a device in BYPASS");
588 int jtag_add_plain_dr_scan(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
591 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
595 WARNING("JTAG command queued, while TRST is low (TAP in reset)");
596 return ERROR_JTAG_TRST_ASSERTED
;
599 /* allocate memory for a new list member */
600 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
601 last_comand_pointer
= &((*last_cmd
)->next
);
602 (*last_cmd
)->next
= NULL
;
603 (*last_cmd
)->type
= JTAG_SCAN
;
605 /* allocate memory for scan command */
606 (*last_cmd
)->cmd
.scan
= cmd_queue_alloc(sizeof(scan_command_t
));
607 (*last_cmd
)->cmd
.scan
->ir_scan
= 0;
608 (*last_cmd
)->cmd
.scan
->num_fields
= num_fields
;
609 (*last_cmd
)->cmd
.scan
->fields
= cmd_queue_alloc(num_fields
* sizeof(scan_field_t
));
610 (*last_cmd
)->cmd
.scan
->end_state
= state
;
613 cmd_queue_end_state
= state
;
615 if (cmd_queue_cur_state
== TAP_TLR
&& cmd_queue_end_state
!= TAP_TLR
)
616 jtag_call_event_callbacks(JTAG_TRST_RELEASED
);
618 if (cmd_queue_end_state
== TAP_TLR
)
619 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
621 cmd_queue_cur_state
= cmd_queue_end_state
;
623 for (i
= 0; i
< num_fields
; i
++)
625 int num_bits
= fields
[i
].num_bits
;
626 int num_bytes
= CEIL(fields
[i
].num_bits
, 8);
627 (*last_cmd
)->cmd
.scan
->fields
[i
].device
= fields
[i
].device
;
628 (*last_cmd
)->cmd
.scan
->fields
[i
].num_bits
= num_bits
;
629 (*last_cmd
)->cmd
.scan
->fields
[i
].out_value
= buf_cpy(fields
[i
].out_value
, cmd_queue_alloc(num_bytes
), num_bits
);
630 (*last_cmd
)->cmd
.scan
->fields
[i
].out_mask
= buf_cpy(fields
[i
].out_mask
, cmd_queue_alloc(num_bytes
), num_bits
);
631 (*last_cmd
)->cmd
.scan
->fields
[i
].in_value
= fields
[i
].in_value
;
632 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_value
= buf_cpy(fields
[i
].in_check_value
, cmd_queue_alloc(num_bytes
), num_bits
);
633 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_mask
= buf_cpy(fields
[i
].in_check_mask
, cmd_queue_alloc(num_bytes
), num_bits
);
634 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler
= fields
[i
].in_handler
;
635 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler_priv
= fields
[i
].in_handler_priv
;
640 int jtag_add_statemove(enum tap_state state
)
642 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
646 WARNING("JTAG command queued, while TRST is low (TAP in reset)");
647 return ERROR_JTAG_TRST_ASSERTED
;
650 /* allocate memory for a new list member */
651 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
652 last_comand_pointer
= &((*last_cmd
)->next
);
653 (*last_cmd
)->next
= NULL
;
654 (*last_cmd
)->type
= JTAG_STATEMOVE
;
656 (*last_cmd
)->cmd
.statemove
= cmd_queue_alloc(sizeof(statemove_command_t
));
657 (*last_cmd
)->cmd
.statemove
->end_state
= state
;
660 cmd_queue_end_state
= state
;
662 if (cmd_queue_cur_state
== TAP_TLR
&& cmd_queue_end_state
!= TAP_TLR
)
663 jtag_call_event_callbacks(JTAG_TRST_RELEASED
);
665 if (cmd_queue_end_state
== TAP_TLR
)
666 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
668 cmd_queue_cur_state
= cmd_queue_end_state
;
673 int jtag_add_pathmove(int num_states
, enum tap_state
*path
)
675 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
680 WARNING("JTAG command queued, while TRST is low (TAP in reset)");
681 return ERROR_JTAG_TRST_ASSERTED
;
684 /* the last state has to be a stable state */
685 if (tap_move_map
[path
[num_states
- 1]] == -1)
687 ERROR("TAP path doesn't finish in a stable state");
688 return ERROR_JTAG_NOT_IMPLEMENTED
;
691 if (jtag
->support_statemove
)
693 /* allocate memory for a new list member */
694 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
695 last_comand_pointer
= &((*last_cmd
)->next
);
696 (*last_cmd
)->next
= NULL
;
697 (*last_cmd
)->type
= JTAG_RUNTEST
;
699 (*last_cmd
)->cmd
.pathmove
= cmd_queue_alloc(sizeof(pathmove_command_t
));
700 (*last_cmd
)->cmd
.pathmove
->num_states
= num_states
;
701 (*last_cmd
)->cmd
.pathmove
->path
= cmd_queue_alloc(sizeof(enum tap_state
) * num_states
);
703 for (i
= 0; i
< num_states
; i
++)
704 (*last_cmd
)->cmd
.pathmove
->path
[i
] = path
[i
];
708 /* validate the desired path, and see if it fits a default path */
713 for (i
= 0; i
< num_states
; i
++)
715 for (j
= i
; j
< num_states
; j
++)
717 if (tap_move_map
[path
[j
]] != -1)
724 if (begin
- end
<= 7) /* a default path spans no more than 7 states */
726 jtag_add_statemove(path
[end
]);
730 ERROR("encountered a TAP path that can't be fulfilled by default paths");
731 return ERROR_JTAG_NOT_IMPLEMENTED
;
738 if (cmd_queue_cur_state
== TAP_TLR
&& cmd_queue_end_state
!= TAP_TLR
)
739 jtag_call_event_callbacks(JTAG_TRST_RELEASED
);
741 if (cmd_queue_end_state
== TAP_TLR
)
742 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
744 cmd_queue_cur_state
= path
[num_states
- 1];
749 int jtag_add_runtest(int num_cycles
, enum tap_state state
)
751 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
755 WARNING("JTAG command queued, while TRST is low (TAP in reset)");
756 return ERROR_JTAG_TRST_ASSERTED
;
759 /* allocate memory for a new list member */
760 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
761 (*last_cmd
)->next
= NULL
;
762 last_comand_pointer
= &((*last_cmd
)->next
);
763 (*last_cmd
)->type
= JTAG_RUNTEST
;
765 (*last_cmd
)->cmd
.runtest
= cmd_queue_alloc(sizeof(runtest_command_t
));
766 (*last_cmd
)->cmd
.runtest
->num_cycles
= num_cycles
;
767 (*last_cmd
)->cmd
.runtest
->end_state
= state
;
770 cmd_queue_end_state
= state
;
772 if (cmd_queue_cur_state
== TAP_TLR
&& cmd_queue_end_state
!= TAP_TLR
)
773 jtag_call_event_callbacks(JTAG_TRST_RELEASED
);
775 if (cmd_queue_end_state
== TAP_TLR
)
776 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
778 cmd_queue_cur_state
= cmd_queue_end_state
;
783 int jtag_add_reset(int req_trst
, int req_srst
)
785 int trst_with_tms
= 0;
787 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
790 req_trst
= jtag_trst
;
793 req_srst
= jtag_srst
;
795 /* Make sure that jtag_reset_config allows the requested reset */
796 /* if SRST pulls TRST, we can't fulfill srst == 1 with trst == 0 */
797 if (((jtag_reset_config
& RESET_SRST_PULLS_TRST
) && (req_srst
== 1)) && (req_trst
== 0))
798 return ERROR_JTAG_RESET_WOULD_ASSERT_TRST
;
800 /* if TRST pulls SRST, we reset with TAP T-L-R */
801 if (((jtag_reset_config
& RESET_TRST_PULLS_SRST
) && (req_trst
== 1)) && (req_srst
== 0))
807 if (req_srst
&& !(jtag_reset_config
& RESET_HAS_SRST
))
808 return ERROR_JTAG_RESET_CANT_SRST
;
810 if (req_trst
&& !(jtag_reset_config
& RESET_HAS_TRST
))
816 /* allocate memory for a new list member */
817 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
818 (*last_cmd
)->next
= NULL
;
819 last_comand_pointer
= &((*last_cmd
)->next
);
820 (*last_cmd
)->type
= JTAG_RESET
;
822 (*last_cmd
)->cmd
.reset
= cmd_queue_alloc(sizeof(reset_command_t
));
823 (*last_cmd
)->cmd
.reset
->trst
= req_trst
;
824 (*last_cmd
)->cmd
.reset
->srst
= req_srst
;
826 jtag_trst
= req_trst
;
827 jtag_srst
= req_srst
;
830 jtag_call_event_callbacks(JTAG_SRST_ASSERTED
);
832 jtag_call_event_callbacks(JTAG_SRST_RELEASED
);
836 last_cmd
= &((*last_cmd
)->next
);
838 /* allocate memory for a new list member */
839 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
840 (*last_cmd
)->next
= NULL
;
841 last_comand_pointer
= &((*last_cmd
)->next
);
842 (*last_cmd
)->type
= JTAG_STATEMOVE
;
844 (*last_cmd
)->cmd
.statemove
= cmd_queue_alloc(sizeof(statemove_command_t
));
845 (*last_cmd
)->cmd
.statemove
->end_state
= TAP_TLR
;
847 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
848 cmd_queue_cur_state
= TAP_TLR
;
849 cmd_queue_end_state
= TAP_TLR
;
857 cmd_queue_cur_state
= TAP_TLR
;
858 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
865 int jtag_add_end_state(enum tap_state state
)
867 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
869 /* allocate memory for a new list member */
870 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
871 (*last_cmd
)->next
= NULL
;
872 last_comand_pointer
= &((*last_cmd
)->next
);
873 (*last_cmd
)->type
= JTAG_END_STATE
;
875 (*last_cmd
)->cmd
.end_state
= cmd_queue_alloc(sizeof(end_state_command_t
));
876 (*last_cmd
)->cmd
.end_state
->end_state
= state
;
879 cmd_queue_end_state
= state
;
884 int jtag_add_sleep(u32 us
)
886 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
888 /* allocate memory for a new list member */
889 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
890 (*last_cmd
)->next
= NULL
;
891 last_comand_pointer
= &((*last_cmd
)->next
);
892 (*last_cmd
)->type
= JTAG_SLEEP
;
894 (*last_cmd
)->cmd
.sleep
= cmd_queue_alloc(sizeof(sleep_command_t
));
895 (*last_cmd
)->cmd
.sleep
->us
= us
;
900 int jtag_scan_size(scan_command_t
*cmd
)
905 /* count bits in scan command */
906 for (i
=0; i
<cmd
->num_fields
; i
++)
908 bit_count
+= cmd
->fields
[i
].num_bits
;
914 int jtag_build_buffer(scan_command_t
*cmd
, u8
**buffer
)
919 bit_count
= jtag_scan_size(cmd
);
920 *buffer
= malloc(CEIL(bit_count
, 8));
924 for (i
= 0; i
< cmd
->num_fields
; i
++)
926 if (cmd
->fields
[i
].out_value
)
928 char* char_buf
= buf_to_char(cmd
->fields
[i
].out_value
, cmd
->fields
[i
].num_bits
);
929 buf_set_buf(cmd
->fields
[i
].out_value
, 0, *buffer
, bit_count
, cmd
->fields
[i
].num_bits
);
930 #ifdef _DEBUG_JTAG_IO_
931 DEBUG("fields[%i].out_value: %s", i
, char_buf
);
936 bit_count
+= cmd
->fields
[i
].num_bits
;
943 int jtag_read_buffer(u8
*buffer
, scan_command_t
*cmd
)
947 int retval
= ERROR_OK
;
949 for (i
=0; i
< cmd
->num_fields
; i
++)
951 /* if neither in_value nor in_check_value are specified we don't have to examine this field */
952 if (cmd
->fields
[i
].in_value
|| cmd
->fields
[i
].in_check_value
)
954 int num_bits
= cmd
->fields
[i
].num_bits
;
956 if (cmd
->fields
[i
].in_value
)
959 buf_set_buf(buffer
, bit_count
, cmd
->fields
[i
].in_value
, 0, num_bits
);
960 char_buf
= buf_to_char(cmd
->fields
[i
].in_value
, num_bits
);
961 #ifdef _DEBUG_JTAG_IO_
962 DEBUG("fields[%i].in_value: %s", i
, char_buf
);
965 if (cmd
->fields
[i
].in_handler
)
967 if (cmd
->fields
[i
].in_handler(cmd
->fields
[i
].in_value
, cmd
->fields
[i
].in_handler_priv
) != ERROR_OK
)
969 /* TODO: error reporting */
970 WARNING("in_handler reported a failed check");
971 retval
= ERROR_JTAG_QUEUE_FAILED
;
976 if (cmd
->fields
[i
].in_check_value
)
978 u8
*captured
= buf_set_buf(buffer
, bit_count
, malloc(CEIL(num_bits
, 8)), 0, num_bits
);
979 if ((cmd
->fields
[i
].in_check_mask
&& buf_cmp_mask(captured
, cmd
->fields
[i
].in_check_value
, cmd
->fields
[i
].in_check_mask
, num_bits
))
980 || (!cmd
->fields
[i
].in_check_mask
&& buf_cmp(captured
, cmd
->fields
[i
].in_check_mask
, num_bits
)))
982 char *captured_char
= buf_to_char(captured
, num_bits
);
983 char *in_check_value_char
= buf_to_char(cmd
->fields
[i
].in_check_value
, num_bits
);
984 char *in_check_mask_char
= buf_to_char(cmd
->fields
[i
].in_check_mask
, num_bits
);
985 /* TODO: error reporting */
986 WARNING("value captured during scan didn't pass the requested check: captured: %s check_value: %s check_mask: %s", captured_char
, in_check_value_char
, in_check_mask_char
);
987 retval
= ERROR_JTAG_QUEUE_FAILED
;
989 free(in_check_value_char
);
990 free(in_check_mask_char
);
995 bit_count
+= cmd
->fields
[i
].num_bits
;
1001 enum scan_type
jtag_scan_type(scan_command_t
*cmd
)
1006 for (i
=0; i
< cmd
->num_fields
; i
++)
1008 if (cmd
->fields
[i
].in_check_value
|| cmd
->fields
[i
].in_value
)
1010 if (cmd
->fields
[i
].out_value
)
1017 int jtag_execute_queue(void)
1021 retval
= jtag
->execute_queue();
1025 jtag_command_queue
= NULL
;
1026 last_comand_pointer
= &jtag_command_queue
;
1031 int jtag_cancel_queue(void)
1034 jtag_command_queue
= NULL
;
1035 last_comand_pointer
= &jtag_command_queue
;
1040 int jtag_reset_callback(enum jtag_event event
, void *priv
)
1042 jtag_device_t
*device
= priv
;
1046 if (event
== JTAG_TRST_ASSERTED
)
1048 buf_set_ones(device
->cur_instr
, device
->ir_length
);
1055 void jtag_sleep(u32 us
)
1060 int jtag_validate_chain()
1062 jtag_device_t
*device
= jtag_devices
;
1063 int total_ir_length
= 0;
1070 total_ir_length
+= device
->ir_length
;
1071 device
= device
->next
;
1074 total_ir_length
+= 2;
1075 ir_test
= malloc(CEIL(total_ir_length
, 8));
1076 buf_set_ones(ir_test
, total_ir_length
);
1079 field
.num_bits
= total_ir_length
;
1080 field
.out_value
= ir_test
;
1081 field
.out_mask
= NULL
;
1082 field
.in_value
= ir_test
;
1083 field
.in_check_value
= NULL
;
1084 field
.in_check_mask
= NULL
;
1085 field
.in_handler
= NULL
;
1086 field
.in_handler_priv
= NULL
;
1088 jtag_add_plain_ir_scan(1, &field
, TAP_TLR
);
1089 jtag_execute_queue();
1091 device
= jtag_devices
;
1094 if (buf_get_u32(ir_test
, chain_pos
, 2) != 0x1)
1096 ERROR("Error validating JTAG scan chain, IR mismatch");
1099 chain_pos
+= device
->ir_length
;
1100 device
= device
->next
;
1103 if (buf_get_u32(ir_test
, chain_pos
, 2) != 0x3)
1105 ERROR("Error validating JTAG scan chain, IR mismatch");
1114 int jtag_register_commands(struct command_context_s
*cmd_ctx
)
1116 register_command(cmd_ctx
, NULL
, "interface", handle_interface_command
,
1117 COMMAND_CONFIG
, NULL
);
1118 register_command(cmd_ctx
, NULL
, "jtag_speed", handle_jtag_speed_command
,
1119 COMMAND_ANY
, "set jtag speed (if supported) <speed>");
1120 register_command(cmd_ctx
, NULL
, "jtag_device", handle_jtag_device_command
,
1121 COMMAND_CONFIG
, NULL
);
1122 register_command(cmd_ctx
, NULL
, "reset_config", handle_reset_config_command
,
1123 COMMAND_CONFIG
, NULL
);
1125 register_command(cmd_ctx
, NULL
, "scan_chain", handle_scan_chain_command
,
1126 COMMAND_EXEC
, "print current scan chain configuration");
1128 register_command(cmd_ctx
, NULL
, "endstate", handle_endstate_command
,
1129 COMMAND_EXEC
, "finish JTAG operations in <tap_state>");
1130 register_command(cmd_ctx
, NULL
, "jtag_reset", handle_jtag_reset_command
,
1131 COMMAND_EXEC
, "toggle reset lines <trst> <srst>");
1132 register_command(cmd_ctx
, NULL
, "runtest", handle_runtest_command
,
1133 COMMAND_EXEC
, "move to Run-Test/Idle, and execute <num_cycles>");
1134 register_command(cmd_ctx
, NULL
, "statemove", handle_statemove_command
,
1135 COMMAND_EXEC
, "move to current endstate or [tap_state]");
1136 register_command(cmd_ctx
, NULL
, "irscan", handle_irscan_command
,
1137 COMMAND_EXEC
, "execute IR scan <device> <instr> [dev2] [instr2] ...");
1138 register_command(cmd_ctx
, NULL
, "drscan", handle_drscan_command
,
1139 COMMAND_EXEC
, "execute DR scan <device> <var> [dev2] [var2] ...");
1141 register_command(cmd_ctx
, NULL
, "verify_ircapture", handle_verify_ircapture_command
,
1142 COMMAND_ANY
, "verify value captured during Capture-IR <enable|disable>");
1146 int jtag_init(struct command_context_s
*cmd_ctx
)
1152 if (jtag_speed
== -1)
1155 if (jtag_interface
&& (jtag_interface
[0] != 0))
1156 /* configuration var 'jtag_interface' is set, and not empty */
1157 for (i
= 0; jtag_interfaces
[i
]; i
++)
1159 if (strcmp(jtag_interface
, jtag_interfaces
[i
]->name
) == 0)
1161 jtag_device_t
*device
;
1162 device
= jtag_devices
;
1164 if (jtag_interfaces
[i
]->init() != ERROR_OK
)
1165 return ERROR_JTAG_INIT_FAILED
;
1166 jtag
= jtag_interfaces
[i
];
1168 jtag_ir_scan_size
= 0;
1169 jtag_num_devices
= 0;
1170 while (device
!= NULL
)
1172 jtag_ir_scan_size
+= device
->ir_length
;
1174 device
= device
->next
;
1177 jtag_add_statemove(TAP_TLR
);
1178 jtag_execute_queue();
1180 jtag_validate_chain();
1186 /* no valid interface was found (i.e. the configuration option,
1187 * didn't match one of the compiled-in interfaces
1189 ERROR("No valid jtag interface found (%s)", jtag_interface
);
1191 return ERROR_JTAG_INVALID_INTERFACE
;
1194 int handle_interface_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1198 /* only if the configuration var isn't overwritten from cmdline */
1199 if (!jtag_interface
)
1201 if (args
[0] && (args
[0][0] != 0))
1203 for (i
=0; jtag_interfaces
[i
]; i
++)
1205 if (strcmp(args
[0], jtag_interfaces
[i
]->name
) == 0)
1207 if (jtag_interfaces
[i
]->register_commands(cmd_ctx
) != ERROR_OK
)
1210 jtag_interface
= jtag_interfaces
[i
]->name
;
1217 /* remember the requested interface name, so we can complain about it later */
1218 jtag_interface
= strdup(args
[0]);
1219 DEBUG("'interface' command didn't specify a valid interface");
1225 int handle_jtag_device_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1227 jtag_device_t
**last_device_p
= &jtag_devices
;
1231 while ((*last_device_p
)->next
)
1232 last_device_p
= &((*last_device_p
)->next
);
1233 last_device_p
= &((*last_device_p
)->next
);
1239 *last_device_p
= malloc(sizeof(jtag_device_t
));
1240 (*last_device_p
)->ir_length
= strtoul(args
[0], NULL
, 0);
1242 (*last_device_p
)->expected
= malloc((*last_device_p
)->ir_length
);
1243 buf_set_u32((*last_device_p
)->expected
, 0, (*last_device_p
)->ir_length
, strtoul(args
[1], NULL
, 0));
1244 (*last_device_p
)->expected_mask
= malloc((*last_device_p
)->ir_length
);
1245 buf_set_u32((*last_device_p
)->expected_mask
, 0, (*last_device_p
)->ir_length
, strtoul(args
[2], NULL
, 0));
1247 (*last_device_p
)->cur_instr
= malloc((*last_device_p
)->ir_length
);
1248 (*last_device_p
)->bypass
= 1;
1249 buf_set_ones((*last_device_p
)->cur_instr
, (*last_device_p
)->ir_length
);
1251 (*last_device_p
)->next
= NULL
;
1253 jtag_register_event_callback(jtag_reset_callback
, (*last_device_p
));
1260 int handle_scan_chain_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1262 jtag_device_t
*device
= jtag_devices
;
1263 int device_count
= 0;
1267 u32 expected
, expected_mask
, cur_instr
;
1268 expected
= buf_get_u32(device
->expected
, 0, device
->ir_length
);
1269 expected_mask
= buf_get_u32(device
->expected_mask
, 0, device
->ir_length
);
1270 cur_instr
= buf_get_u32(device
->cur_instr
, 0, device
->ir_length
);
1271 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
);
1272 device
= device
->next
;
1279 int handle_reset_config_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1283 if (strcmp(args
[0], "none") == 0)
1284 jtag_reset_config
= RESET_NONE
;
1285 else if (strcmp(args
[0], "trst_only") == 0)
1286 jtag_reset_config
= RESET_HAS_TRST
;
1287 else if (strcmp(args
[0], "srst_only") == 0)
1288 jtag_reset_config
= RESET_HAS_SRST
;
1289 else if (strcmp(args
[0], "trst_and_srst") == 0)
1290 jtag_reset_config
= RESET_TRST_AND_SRST
;
1293 ERROR("invalid reset_config argument");
1300 if (strcmp(args
[1], "srst_pulls_trst") == 0)
1301 jtag_reset_config
|= RESET_SRST_PULLS_TRST
;
1302 else if (strcmp(args
[1], "trst_pulls_srst") == 0)
1303 jtag_reset_config
|= RESET_TRST_PULLS_SRST
;
1304 else if (strcmp(args
[1], "combined") == 0)
1305 jtag_reset_config
|= RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
;
1306 else if (strcmp(args
[1], "separate") == 0)
1307 jtag_reset_config
&= ~(RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
);
1310 ERROR("invalid reset_config argument");
1317 if (strcmp(args
[2], "trst_open_drain") == 0)
1318 jtag_reset_config
|= RESET_TRST_OPEN_DRAIN
;
1319 else if (strcmp(args
[2], "trst_push_pull") == 0)
1320 jtag_reset_config
&= ~RESET_TRST_OPEN_DRAIN
;
1323 ERROR("invalid reset_config argument");
1330 if (strcmp(args
[3], "srst_push_pull") == 0)
1331 jtag_reset_config
|= RESET_SRST_PUSH_PULL
;
1332 else if (strcmp(args
[3], "srst_open_drain") == 0)
1333 jtag_reset_config
&= ~RESET_SRST_PUSH_PULL
;
1336 ERROR("invalid reset_config argument");
1344 int handle_jtag_speed_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1347 command_print(cmd_ctx
, "jtag_speed: %i", jtag_speed
);
1351 /* this command can be called during CONFIG,
1352 * in which case jtag isn't initialized */
1354 jtag
->speed(strtoul(args
[0], NULL
, 0));
1356 jtag_speed
= strtoul(args
[0], NULL
, 0);
1362 int handle_endstate_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1364 enum tap_state state
;
1368 command_print(cmd_ctx
, "usage: endstate <tap_state>");
1372 for (state
= 0; state
< 16; state
++)
1374 if (strcmp(args
[0], tap_state_strings
[state
]) == 0)
1376 jtag_add_end_state(state
);
1377 jtag_execute_queue();
1384 int handle_jtag_reset_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1388 char *usage
= "usage: jtag_reset <trst> <srst>";
1393 command_print(cmd_ctx
, usage
);
1397 if (args
[0][0] == '1')
1399 else if (args
[0][0] == '0')
1403 command_print(cmd_ctx
, usage
);
1407 if (args
[1][0] == '1')
1409 else if (args
[1][0] == '0')
1413 command_print(cmd_ctx
, usage
);
1417 if ((retval
= jtag_add_reset(trst
, srst
)) != ERROR_OK
)
1421 case ERROR_JTAG_RESET_WOULD_ASSERT_TRST
:
1422 command_print(cmd_ctx
, "requested reset would assert trst\nif this is acceptable, use jtag_reset 1 %c", args
[1][0]);
1424 case ERROR_JTAG_RESET_CANT_SRST
:
1425 command_print(cmd_ctx
, "can't assert srst because the current reset_config doesn't support it");
1428 command_print(cmd_ctx
, "unknown error");
1431 jtag_execute_queue();
1436 int handle_runtest_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1440 command_print(cmd_ctx
, "usage: runtest <num_cycles>");
1444 jtag_add_runtest(strtol(args
[0], NULL
, 0), -1);
1445 jtag_execute_queue();
1451 int handle_statemove_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1453 enum tap_state state
;
1458 for (state
= 0; state
< 16; state
++)
1460 if (strcmp(args
[0], tap_state_strings
[state
]) == 0)
1467 jtag_add_statemove(state
);
1468 jtag_execute_queue();
1474 int handle_irscan_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1477 scan_field_t
*fields
;
1479 if ((argc
< 2) || (argc
% 2))
1481 command_print(cmd_ctx
, "usage: irscan <device> <instr> [dev2] [instr2] ...");
1485 fields
= malloc(sizeof(scan_field_t
) * argc
/ 2);
1487 for (i
= 0; i
< argc
/ 2; i
++)
1489 int device
= strtoul(args
[i
*2], NULL
, 0);
1490 int field_size
= jtag_get_device(device
)->ir_length
;
1491 fields
[i
].device
= device
;
1492 fields
[i
].out_value
= malloc(CEIL(field_size
, 8));
1493 buf_set_u32(fields
[i
].out_value
, 0, field_size
, strtoul(args
[i
*2+1], NULL
, 0));
1494 fields
[i
].out_mask
= NULL
;
1495 fields
[i
].in_value
= NULL
;
1496 fields
[i
].in_check_mask
= NULL
;
1497 fields
[i
].in_handler
= NULL
;
1498 fields
[i
].in_handler_priv
= NULL
;
1501 jtag_add_ir_scan(argc
/ 2, fields
, -1);
1502 jtag_execute_queue();
1504 for (i
= 0; i
< argc
/ 2; i
++)
1505 free(fields
[i
].out_value
);
1512 int handle_drscan_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1514 scan_field_t
*fields
;
1516 int field_count
= 0;
1520 if ((argc
< 2) || (argc
% 2))
1522 command_print(cmd_ctx
, "usage: drscan <device> <var> [dev2] [var2]");
1526 for (i
= 0; i
< argc
; i
+=2)
1528 var
= get_var_by_namenum(args
[i
+1]);
1531 num_fields
+= var
->num_fields
;
1535 command_print(cmd_ctx
, "variable %s doesn't exist", args
[i
+1]);
1540 fields
= malloc(sizeof(scan_field_t
) * num_fields
);
1542 for (i
= 0; i
< argc
; i
+=2)
1544 var
= get_var_by_namenum(args
[i
+1]);
1546 for (j
= 0; j
< var
->num_fields
; j
++)
1548 fields
[field_count
].device
= strtol(args
[i
], NULL
, 0);
1549 fields
[field_count
].num_bits
= var
->fields
[j
].num_bits
;
1550 fields
[field_count
].out_value
= malloc(CEIL(var
->fields
[j
].num_bits
, 8));
1551 buf_set_u32(fields
[field_count
].out_value
, 0, var
->fields
[j
].num_bits
, var
->fields
[j
].value
);
1552 fields
[field_count
].out_mask
= NULL
;
1553 fields
[field_count
].in_value
= fields
[field_count
].out_value
;
1554 fields
[field_count
].in_check_mask
= NULL
;
1555 fields
[field_count
].in_check_value
= NULL
;
1556 fields
[field_count
].in_handler
= field_le_to_host
;
1557 fields
[field_count
++].in_handler_priv
= &(var
->fields
[j
]);
1561 jtag_add_dr_scan(num_fields
, fields
, -1);
1562 jtag_execute_queue();
1564 for (i
= 0; i
< argc
/ 2; i
++)
1565 free(fields
[i
].out_value
);
1572 int handle_verify_ircapture_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1576 command_print(cmd_ctx
, "verify Capture-IR is %s", (jtag_verify_capture_ir
) ? "enabled": "disabled");
1580 if (strcmp(args
[0], "enable") == 0)
1582 jtag_verify_capture_ir
= 1;
1584 else if (strcmp(args
[0], "disable") == 0)
1586 jtag_verify_capture_ir
= 0;
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)