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 ***************************************************************************/
25 #include "interpreter.h"
31 char* tap_state_strings
[16] =
34 "sds", "cd", "sd", "e1d", "pd", "e2d", "ud",
36 "sis", "ci", "si", "e1i", "pi", "e2i", "ui"
39 typedef struct cmd_queue_page_s
43 struct cmd_queue_page_s
*next
;
46 #define CMD_QUEUE_PAGE_SIZE (1024 * 1024)
47 static cmd_queue_page_t
*cmd_queue_pages
= NULL
;
49 /* tap_move[i][j]: tap movement command to go from state i to state j
59 /* TLR RTI SD PD SI PI */
60 {0x7f, 0x00, 0x17, 0x0a, 0x1b, 0x16}, /* TLR */
61 {0x7f, 0x00, 0x25, 0x05, 0x2b, 0x0b}, /* RTI */
62 {0x7f, 0x31, 0x00, 0x01, 0x0f, 0x2f}, /* SD */
63 {0x7f, 0x30, 0x20, 0x17, 0x1e, 0x2f}, /* PD */
64 {0x7f, 0x31, 0x07, 0x17, 0x00, 0x01}, /* SI */
65 {0x7f, 0x30, 0x1c, 0x17, 0x20, 0x2f} /* PI */
68 int tap_move_map
[16] = {
69 0, -1, -1, 2, -1, 3, -1, -1,
70 1, -1, -1, 4, -1, 5, -1, -1
73 tap_transition_t tap_transitions
[16] =
75 {TAP_TLR
, TAP_RTI
}, /* TLR */
76 {TAP_SIS
, TAP_CD
}, /* SDS */
77 {TAP_E1D
, TAP_SD
}, /* CD */
78 {TAP_E1D
, TAP_SD
}, /* SD */
79 {TAP_UD
, TAP_PD
}, /* E1D */
80 {TAP_E2D
, TAP_PD
}, /* PD */
81 {TAP_UD
, TAP_SD
}, /* E2D */
82 {TAP_SDS
, TAP_RTI
}, /* UD */
83 {TAP_SDS
, TAP_RTI
}, /* RTI */
84 {TAP_TLR
, TAP_CI
}, /* SIS */
85 {TAP_E1I
, TAP_SI
}, /* CI */
86 {TAP_E1I
, TAP_SI
}, /* SI */
87 {TAP_UI
, TAP_PI
}, /* E1I */
88 {TAP_E2I
, TAP_PI
}, /* PI */
89 {TAP_UI
, TAP_SI
}, /* E2I */
90 {TAP_SDS
, TAP_RTI
} /* UI */
93 enum tap_state end_state
= TAP_TLR
;
94 enum tap_state cur_state
= TAP_TLR
;
98 jtag_command_t
*jtag_command_queue
= NULL
;
99 jtag_command_t
**last_comand_pointer
= &jtag_command_queue
;
100 jtag_device_t
*jtag_devices
= NULL
;
101 int jtag_num_devices
= 0;
102 int jtag_ir_scan_size
= 0;
103 enum reset_types jtag_reset_config
= RESET_NONE
;
104 enum tap_state cmd_queue_end_state
= TAP_TLR
;
105 enum tap_state cmd_queue_cur_state
= TAP_TLR
;
107 int jtag_verify_capture_ir
= 1;
109 /* callbacks to inform high-level handlers about JTAG state changes */
110 jtag_event_callback_t
*jtag_event_callbacks
;
112 /* jtag interfaces (parport, FTDI-USB, TI-USB, ...)
114 #if BUILD_PARPORT == 1
115 extern jtag_interface_t parport_interface
;
118 #if BUILD_FTDI2232 == 1
119 extern jtag_interface_t ftdi2232_interface
;
122 #if BUILD_FTD2XX == 1
123 extern jtag_interface_t ftd2xx_interface
;
126 #if BUILD_AMTJTAGACCEL == 1
127 extern jtag_interface_t amt_jtagaccel_interface
;
130 #if BUILD_EP93XX == 1
131 extern jtag_interface_t ep93xx_interface
;
134 jtag_interface_t
*jtag_interfaces
[] = {
135 #if BUILD_PARPORT == 1
138 #if BUILD_FTDI2232 == 1
141 #if BUILD_FTD2XX == 1
144 #if BUILD_AMTJTAGACCEL == 1
145 &amt_jtagaccel_interface
,
147 #if BUILD_EP93XX == 1
153 jtag_interface_t
*jtag
= NULL
;
156 char* jtag_interface
= NULL
;
159 /* forward declarations */
162 int handle_interface_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
163 int handle_jtag_speed_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
164 int handle_jtag_device_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
165 int handle_reset_config_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
167 int handle_scan_chain_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
169 int handle_endstate_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
170 int handle_jtag_reset_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
171 int handle_runtest_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
172 int handle_statemove_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
173 int handle_irscan_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
174 int handle_drscan_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
176 int handle_verify_ircapture_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
);
178 int jtag_register_event_callback(int (*callback
)(enum jtag_event event
, void *priv
), void *priv
)
180 jtag_event_callback_t
**callbacks_p
= &jtag_event_callbacks
;
182 if (callback
== NULL
)
184 return ERROR_INVALID_ARGUMENTS
;
189 while ((*callbacks_p
)->next
)
190 callbacks_p
= &((*callbacks_p
)->next
);
191 callbacks_p
= &((*callbacks_p
)->next
);
194 (*callbacks_p
) = malloc(sizeof(jtag_event_callback_t
));
195 (*callbacks_p
)->callback
= callback
;
196 (*callbacks_p
)->priv
= priv
;
197 (*callbacks_p
)->next
= NULL
;
202 int jtag_unregister_event_callback(int (*callback
)(enum jtag_event event
, void *priv
))
204 jtag_event_callback_t
**callbacks_p
= &jtag_event_callbacks
;
206 if (callback
== NULL
)
208 return ERROR_INVALID_ARGUMENTS
;
213 jtag_event_callback_t
**next
= &((*callbacks_p
)->next
);
214 if ((*callbacks_p
)->callback
== callback
)
217 *callbacks_p
= *next
;
225 int jtag_call_event_callbacks(enum jtag_event event
)
227 jtag_event_callback_t
*callback
= jtag_event_callbacks
;
229 DEBUG("jtag event: %i", event
);
233 callback
->callback(event
, callback
->priv
);
234 callback
= callback
->next
;
240 /* returns a pointer to the pointer of the last command in queue
241 * this may be a pointer to the root pointer (jtag_command_queue)
242 * or to the next member of the last but one command
244 jtag_command_t
** jtag_get_last_command_p(void)
246 /* jtag_command_t *cmd = jtag_command_queue;
252 return &jtag_command_queue;
256 return last_comand_pointer
;
259 /* returns a pointer to the n-th device in the scan chain */
260 jtag_device_t
* jtag_get_device(int num
)
262 jtag_device_t
*device
= jtag_devices
;
269 device
= device
->next
;
276 void* cmd_queue_alloc(size_t size
)
278 cmd_queue_page_t
**p_page
= &cmd_queue_pages
;
283 while ((*p_page
)->next
)
284 p_page
= &((*p_page
)->next
);
285 if (CMD_QUEUE_PAGE_SIZE
- (*p_page
)->used
< size
)
286 p_page
= &((*p_page
)->next
);
291 *p_page
= malloc(sizeof(cmd_queue_page_t
));
293 (*p_page
)->address
= malloc(CMD_QUEUE_PAGE_SIZE
);
294 (*p_page
)->next
= NULL
;
297 offset
= (*p_page
)->used
;
298 (*p_page
)->used
+= size
;
300 return ((*p_page
)->address
) + offset
;
303 void cmd_queue_free()
305 cmd_queue_page_t
*page
= cmd_queue_pages
;
309 cmd_queue_page_t
*last
= page
;
315 cmd_queue_pages
= NULL
;
318 int jtag_add_ir_scan(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
320 jtag_command_t
**last_cmd
;
321 jtag_device_t
*device
;
324 /* int changed = 0; */
328 WARNING("JTAG command queued, while TRST is low (TAP in reset)");
329 return ERROR_JTAG_TRST_ASSERTED
;
333 for (i=0; i<num_fields; i++)
335 device = jtag_get_device(fields[i].device);
338 if (buf_cmp(device->cur_instr, fields[i].out_value, device->ir_length))
343 ERROR("inexistant device specified for ir scan");
344 return ERROR_INVALID_ARGUMENTS;
352 last_cmd
= jtag_get_last_command_p();
354 /* allocate memory for a new list member */
355 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
356 (*last_cmd
)->next
= NULL
;
357 last_comand_pointer
= &((*last_cmd
)->next
);
358 (*last_cmd
)->type
= JTAG_SCAN
;
360 /* allocate memory for ir scan command */
361 (*last_cmd
)->cmd
.scan
= cmd_queue_alloc(sizeof(scan_command_t
));
362 (*last_cmd
)->cmd
.scan
->ir_scan
= 1;
363 (*last_cmd
)->cmd
.scan
->num_fields
= jtag_num_devices
; /* one field per device */
364 (*last_cmd
)->cmd
.scan
->fields
= cmd_queue_alloc(jtag_num_devices
* sizeof(scan_field_t
));
365 (*last_cmd
)->cmd
.scan
->end_state
= state
;
368 cmd_queue_end_state
= state
;
370 if (cmd_queue_cur_state
== TAP_TLR
&& cmd_queue_end_state
!= TAP_TLR
)
371 jtag_call_event_callbacks(JTAG_TRST_RELEASED
);
373 if (cmd_queue_end_state
== TAP_TLR
)
374 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
376 cmd_queue_cur_state
= cmd_queue_end_state
;
378 for (i
=0; i
< jtag_num_devices
; i
++)
381 device
= jtag_get_device(i
);
382 scan_size
= device
->ir_length
;
383 (*last_cmd
)->cmd
.scan
->fields
[i
].device
= i
;
384 (*last_cmd
)->cmd
.scan
->fields
[i
].num_bits
= scan_size
;
385 (*last_cmd
)->cmd
.scan
->fields
[i
].in_value
= NULL
;
386 if (jtag_verify_capture_ir
)
388 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_value
= buf_cpy(device
->expected
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
389 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_mask
= buf_cpy(device
->expected_mask
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
393 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_value
= NULL
;
394 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_mask
= NULL
;
396 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler
= NULL
;
397 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler_priv
= NULL
;
399 /* search the list */
400 for (j
=0; j
< num_fields
; j
++)
402 if (i
== fields
[j
].device
)
405 (*last_cmd
)->cmd
.scan
->fields
[i
].out_value
= buf_cpy(fields
[j
].out_value
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
406 (*last_cmd
)->cmd
.scan
->fields
[i
].out_mask
= buf_cpy(fields
[j
].out_mask
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
415 /* if a device isn't listed, set it to BYPASS */
416 (*last_cmd
)->cmd
.scan
->fields
[i
].out_value
= buf_set_ones(cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
417 (*last_cmd
)->cmd
.scan
->fields
[i
].out_mask
= NULL
;
422 /* update device information */
423 buf_cpy((*last_cmd
)->cmd
.scan
->fields
[i
].out_value
, jtag_get_device(i
)->cur_instr
, scan_size
);
429 int jtag_add_plain_ir_scan(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
431 jtag_command_t
**last_cmd
;
436 WARNING("JTAG command queued, while TRST is low (TAP in reset)");
437 return ERROR_JTAG_TRST_ASSERTED
;
440 last_cmd
= jtag_get_last_command_p();
442 /* allocate memory for a new list member */
443 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
444 (*last_cmd
)->next
= NULL
;
445 last_comand_pointer
= &((*last_cmd
)->next
);
446 (*last_cmd
)->type
= JTAG_SCAN
;
448 /* allocate memory for ir scan command */
449 (*last_cmd
)->cmd
.scan
= cmd_queue_alloc(sizeof(scan_command_t
));
450 (*last_cmd
)->cmd
.scan
->ir_scan
= 1;
451 (*last_cmd
)->cmd
.scan
->num_fields
= num_fields
;
452 (*last_cmd
)->cmd
.scan
->fields
= cmd_queue_alloc(num_fields
* sizeof(scan_field_t
));
453 (*last_cmd
)->cmd
.scan
->end_state
= state
;
456 cmd_queue_end_state
= state
;
458 if (cmd_queue_cur_state
== TAP_TLR
&& cmd_queue_end_state
!= TAP_TLR
)
459 jtag_call_event_callbacks(JTAG_TRST_RELEASED
);
461 if (cmd_queue_end_state
== TAP_TLR
)
462 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
464 cmd_queue_cur_state
= cmd_queue_end_state
;
466 for (i
= 0; i
< num_fields
; i
++)
468 int num_bits
= fields
[i
].num_bits
;
469 int num_bytes
= CEIL(fields
[i
].num_bits
, 8);
470 (*last_cmd
)->cmd
.scan
->fields
[i
].device
= fields
[i
].device
;
471 (*last_cmd
)->cmd
.scan
->fields
[i
].num_bits
= num_bits
;
472 (*last_cmd
)->cmd
.scan
->fields
[i
].out_value
= buf_cpy(fields
[i
].out_value
, cmd_queue_alloc(num_bytes
), num_bits
);
473 (*last_cmd
)->cmd
.scan
->fields
[i
].out_mask
= buf_cpy(fields
[i
].out_mask
, cmd_queue_alloc(num_bytes
), num_bits
);
474 (*last_cmd
)->cmd
.scan
->fields
[i
].in_value
= fields
[i
].in_value
;
475 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_value
= buf_cpy(fields
[i
].in_check_value
, cmd_queue_alloc(num_bytes
), num_bits
);
476 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_mask
= buf_cpy(fields
[i
].in_check_mask
, cmd_queue_alloc(num_bytes
), num_bits
);
477 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler
= NULL
;
478 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler_priv
= NULL
;
483 int jtag_add_dr_scan(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
486 int bypass_devices
= 0;
488 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
489 jtag_device_t
*device
= jtag_devices
;
494 WARNING("JTAG command queued, while TRST is low (TAP in reset)");
495 return ERROR_JTAG_TRST_ASSERTED
;
498 /* count devices in bypass */
503 device
= device
->next
;
506 /* allocate memory for a new list member */
507 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
508 last_comand_pointer
= &((*last_cmd
)->next
);
509 (*last_cmd
)->next
= NULL
;
510 (*last_cmd
)->type
= JTAG_SCAN
;
512 /* allocate memory for dr scan command */
513 (*last_cmd
)->cmd
.scan
= cmd_queue_alloc(sizeof(scan_command_t
));
514 (*last_cmd
)->cmd
.scan
->ir_scan
= 0;
515 (*last_cmd
)->cmd
.scan
->num_fields
= num_fields
+ bypass_devices
;
516 (*last_cmd
)->cmd
.scan
->fields
= cmd_queue_alloc((num_fields
+ bypass_devices
) * sizeof(scan_field_t
));
517 (*last_cmd
)->cmd
.scan
->end_state
= state
;
520 cmd_queue_end_state
= state
;
522 if (cmd_queue_cur_state
== TAP_TLR
&& cmd_queue_end_state
!= TAP_TLR
)
523 jtag_call_event_callbacks(JTAG_TRST_RELEASED
);
525 if (cmd_queue_end_state
== TAP_TLR
)
526 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
528 cmd_queue_cur_state
= cmd_queue_end_state
;
530 for (i
=0; i
< jtag_num_devices
; i
++)
533 (*last_cmd
)->cmd
.scan
->fields
[field_count
].device
= i
;
535 for (j
=0; j
< num_fields
; j
++)
537 if (i
== fields
[j
].device
)
540 scan_size
= fields
[j
].num_bits
;
541 (*last_cmd
)->cmd
.scan
->fields
[field_count
].num_bits
= scan_size
;
542 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_value
= buf_cpy(fields
[j
].out_value
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
543 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_mask
= buf_cpy(fields
[j
].out_mask
, cmd_queue_alloc(CEIL(scan_size
, 8)), scan_size
);
544 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_value
= fields
[j
].in_value
;
545 (*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
);
546 (*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
);
547 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_handler
= fields
[j
].in_handler
;
548 (*last_cmd
)->cmd
.scan
->fields
[field_count
++].in_handler_priv
= fields
[j
].in_handler_priv
;
553 /* if a device isn't listed, the BYPASS register should be selected */
554 if (!jtag_get_device(i
)->bypass
)
556 ERROR("BUG: no scan data for a device not in BYPASS");
560 /* program the scan field to 1 bit length, and ignore it's value */
561 (*last_cmd
)->cmd
.scan
->fields
[field_count
].num_bits
= 1;
562 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_value
= NULL
;
563 (*last_cmd
)->cmd
.scan
->fields
[field_count
].out_mask
= NULL
;
564 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_value
= NULL
;
565 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_check_value
= NULL
;
566 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_check_mask
= NULL
;
567 (*last_cmd
)->cmd
.scan
->fields
[field_count
].in_handler
= NULL
;
568 (*last_cmd
)->cmd
.scan
->fields
[field_count
++].in_handler_priv
= NULL
;
572 /* if a device is listed, the BYPASS register must not be selected */
573 if (jtag_get_device(i
)->bypass
)
575 ERROR("BUG: scan data for a device in BYPASS");
583 int jtag_add_plain_dr_scan(int num_fields
, scan_field_t
*fields
, enum tap_state state
)
586 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
590 WARNING("JTAG command queued, while TRST is low (TAP in reset)");
591 return ERROR_JTAG_TRST_ASSERTED
;
594 /* allocate memory for a new list member */
595 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
596 last_comand_pointer
= &((*last_cmd
)->next
);
597 (*last_cmd
)->next
= NULL
;
598 (*last_cmd
)->type
= JTAG_SCAN
;
600 /* allocate memory for scan command */
601 (*last_cmd
)->cmd
.scan
= cmd_queue_alloc(sizeof(scan_command_t
));
602 (*last_cmd
)->cmd
.scan
->ir_scan
= 0;
603 (*last_cmd
)->cmd
.scan
->num_fields
= num_fields
;
604 (*last_cmd
)->cmd
.scan
->fields
= cmd_queue_alloc(num_fields
* sizeof(scan_field_t
));
605 (*last_cmd
)->cmd
.scan
->end_state
= state
;
608 cmd_queue_end_state
= state
;
610 if (cmd_queue_cur_state
== TAP_TLR
&& cmd_queue_end_state
!= TAP_TLR
)
611 jtag_call_event_callbacks(JTAG_TRST_RELEASED
);
613 if (cmd_queue_end_state
== TAP_TLR
)
614 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
616 cmd_queue_cur_state
= cmd_queue_end_state
;
618 for (i
= 0; i
< num_fields
; i
++)
620 int num_bits
= fields
[i
].num_bits
;
621 int num_bytes
= CEIL(fields
[i
].num_bits
, 8);
622 (*last_cmd
)->cmd
.scan
->fields
[i
].device
= fields
[i
].device
;
623 (*last_cmd
)->cmd
.scan
->fields
[i
].num_bits
= num_bits
;
624 (*last_cmd
)->cmd
.scan
->fields
[i
].out_value
= buf_cpy(fields
[i
].out_value
, cmd_queue_alloc(num_bytes
), num_bits
);
625 (*last_cmd
)->cmd
.scan
->fields
[i
].out_mask
= buf_cpy(fields
[i
].out_mask
, cmd_queue_alloc(num_bytes
), num_bits
);
626 (*last_cmd
)->cmd
.scan
->fields
[i
].in_value
= fields
[i
].in_value
;
627 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_value
= buf_cpy(fields
[i
].in_check_value
, cmd_queue_alloc(num_bytes
), num_bits
);
628 (*last_cmd
)->cmd
.scan
->fields
[i
].in_check_mask
= buf_cpy(fields
[i
].in_check_mask
, cmd_queue_alloc(num_bytes
), num_bits
);
629 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler
= fields
[i
].in_handler
;
630 (*last_cmd
)->cmd
.scan
->fields
[i
].in_handler_priv
= fields
[i
].in_handler_priv
;
635 int jtag_add_statemove(enum tap_state state
)
637 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
641 WARNING("JTAG command queued, while TRST is low (TAP in reset)");
642 return ERROR_JTAG_TRST_ASSERTED
;
645 /* allocate memory for a new list member */
646 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
647 last_comand_pointer
= &((*last_cmd
)->next
);
648 (*last_cmd
)->next
= NULL
;
649 (*last_cmd
)->type
= JTAG_STATEMOVE
;
651 (*last_cmd
)->cmd
.statemove
= cmd_queue_alloc(sizeof(statemove_command_t
));
652 (*last_cmd
)->cmd
.statemove
->end_state
= state
;
655 cmd_queue_end_state
= state
;
657 if (cmd_queue_cur_state
== TAP_TLR
&& cmd_queue_end_state
!= TAP_TLR
)
658 jtag_call_event_callbacks(JTAG_TRST_RELEASED
);
660 if (cmd_queue_end_state
== TAP_TLR
)
661 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
663 cmd_queue_cur_state
= cmd_queue_end_state
;
668 int jtag_add_pathmove(int num_states
, enum tap_state
*path
)
670 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
675 WARNING("JTAG command queued, while TRST is low (TAP in reset)");
676 return ERROR_JTAG_TRST_ASSERTED
;
679 /* the last state has to be a stable state */
680 if (tap_move_map
[path
[num_states
- 1]] == -1)
682 ERROR("TAP path doesn't finish in a stable state");
683 return ERROR_JTAG_NOT_IMPLEMENTED
;
686 if (jtag
->support_statemove
)
688 /* allocate memory for a new list member */
689 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
690 last_comand_pointer
= &((*last_cmd
)->next
);
691 (*last_cmd
)->next
= NULL
;
692 (*last_cmd
)->type
= JTAG_RUNTEST
;
694 (*last_cmd
)->cmd
.pathmove
= cmd_queue_alloc(sizeof(pathmove_command_t
));
695 (*last_cmd
)->cmd
.pathmove
->num_states
= num_states
;
696 (*last_cmd
)->cmd
.pathmove
->path
= cmd_queue_alloc(sizeof(enum tap_state
) * num_states
);
698 for (i
= 0; i
< num_states
; i
++)
699 (*last_cmd
)->cmd
.pathmove
->path
[i
] = path
[i
];
703 /* validate the desired path, and see if it fits a default path */
708 for (i
= 0; i
< num_states
; i
++)
710 for (j
= i
; j
< num_states
; j
++)
712 if (tap_move_map
[path
[j
]] != -1)
719 if (begin
- end
<= 7) /* a default path spans no more than 7 states */
721 jtag_add_statemove(path
[end
]);
725 ERROR("encountered a TAP path that can't be fulfilled by default paths");
726 return ERROR_JTAG_NOT_IMPLEMENTED
;
733 if (cmd_queue_cur_state
== TAP_TLR
&& cmd_queue_end_state
!= TAP_TLR
)
734 jtag_call_event_callbacks(JTAG_TRST_RELEASED
);
736 if (cmd_queue_end_state
== TAP_TLR
)
737 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
739 cmd_queue_cur_state
= path
[num_states
- 1];
744 int jtag_add_runtest(int num_cycles
, enum tap_state state
)
746 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
750 WARNING("JTAG command queued, while TRST is low (TAP in reset)");
751 return ERROR_JTAG_TRST_ASSERTED
;
754 /* allocate memory for a new list member */
755 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
756 (*last_cmd
)->next
= NULL
;
757 last_comand_pointer
= &((*last_cmd
)->next
);
758 (*last_cmd
)->type
= JTAG_RUNTEST
;
760 (*last_cmd
)->cmd
.runtest
= cmd_queue_alloc(sizeof(runtest_command_t
));
761 (*last_cmd
)->cmd
.runtest
->num_cycles
= num_cycles
;
762 (*last_cmd
)->cmd
.runtest
->end_state
= state
;
765 cmd_queue_end_state
= state
;
767 if (cmd_queue_cur_state
== TAP_TLR
&& cmd_queue_end_state
!= TAP_TLR
)
768 jtag_call_event_callbacks(JTAG_TRST_RELEASED
);
770 if (cmd_queue_end_state
== TAP_TLR
)
771 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
773 cmd_queue_cur_state
= cmd_queue_end_state
;
778 int jtag_add_reset(int req_trst
, int req_srst
)
780 int trst_with_tms
= 0;
782 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
785 req_trst
= jtag_trst
;
788 req_srst
= jtag_srst
;
790 /* Make sure that jtag_reset_config allows the requested reset */
791 /* if SRST pulls TRST, we can't fulfill srst == 1 with trst == 0 */
792 if (((jtag_reset_config
& RESET_SRST_PULLS_TRST
) && (req_srst
== 1)) && (req_trst
== 0))
793 return ERROR_JTAG_RESET_WOULD_ASSERT_TRST
;
795 /* if TRST pulls SRST, we reset with TAP T-L-R */
796 if (((jtag_reset_config
& RESET_TRST_PULLS_SRST
) && (req_trst
== 1)) && (req_srst
== 0))
802 if (req_srst
&& !(jtag_reset_config
& RESET_HAS_SRST
))
803 return ERROR_JTAG_RESET_CANT_SRST
;
805 if (req_trst
&& !(jtag_reset_config
& RESET_HAS_TRST
))
811 /* allocate memory for a new list member */
812 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
813 (*last_cmd
)->next
= NULL
;
814 last_comand_pointer
= &((*last_cmd
)->next
);
815 (*last_cmd
)->type
= JTAG_RESET
;
817 (*last_cmd
)->cmd
.reset
= cmd_queue_alloc(sizeof(reset_command_t
));
818 (*last_cmd
)->cmd
.reset
->trst
= req_trst
;
819 (*last_cmd
)->cmd
.reset
->srst
= req_srst
;
821 jtag_trst
= req_trst
;
822 jtag_srst
= req_srst
;
825 jtag_call_event_callbacks(JTAG_SRST_ASSERTED
);
827 jtag_call_event_callbacks(JTAG_SRST_RELEASED
);
831 last_cmd
= &((*last_cmd
)->next
);
833 /* allocate memory for a new list member */
834 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
835 (*last_cmd
)->next
= NULL
;
836 last_comand_pointer
= &((*last_cmd
)->next
);
837 (*last_cmd
)->type
= JTAG_STATEMOVE
;
839 (*last_cmd
)->cmd
.statemove
= cmd_queue_alloc(sizeof(statemove_command_t
));
840 (*last_cmd
)->cmd
.statemove
->end_state
= TAP_TLR
;
842 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
843 cmd_queue_cur_state
= TAP_TLR
;
844 cmd_queue_end_state
= TAP_TLR
;
852 cmd_queue_cur_state
= TAP_TLR
;
853 jtag_call_event_callbacks(JTAG_TRST_ASSERTED
);
860 int jtag_add_end_state(enum tap_state state
)
862 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
864 /* allocate memory for a new list member */
865 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
866 (*last_cmd
)->next
= NULL
;
867 last_comand_pointer
= &((*last_cmd
)->next
);
868 (*last_cmd
)->type
= JTAG_END_STATE
;
870 (*last_cmd
)->cmd
.end_state
= cmd_queue_alloc(sizeof(end_state_command_t
));
871 (*last_cmd
)->cmd
.end_state
->end_state
= state
;
874 cmd_queue_end_state
= state
;
879 int jtag_add_sleep(u32 us
)
881 jtag_command_t
**last_cmd
= jtag_get_last_command_p();
883 /* allocate memory for a new list member */
884 *last_cmd
= cmd_queue_alloc(sizeof(jtag_command_t
));
885 (*last_cmd
)->next
= NULL
;
886 last_comand_pointer
= &((*last_cmd
)->next
);
887 (*last_cmd
)->type
= JTAG_SLEEP
;
889 (*last_cmd
)->cmd
.sleep
= cmd_queue_alloc(sizeof(sleep_command_t
));
890 (*last_cmd
)->cmd
.sleep
->us
= us
;
895 int jtag_scan_size(scan_command_t
*cmd
)
900 /* count bits in scan command */
901 for (i
=0; i
<cmd
->num_fields
; i
++)
903 bit_count
+= cmd
->fields
[i
].num_bits
;
909 int jtag_build_buffer(scan_command_t
*cmd
, u8
**buffer
)
914 bit_count
= jtag_scan_size(cmd
);
915 *buffer
= malloc(CEIL(bit_count
, 8));
919 for (i
= 0; i
< cmd
->num_fields
; i
++)
921 if (cmd
->fields
[i
].out_value
)
923 char* char_buf
= buf_to_char(cmd
->fields
[i
].out_value
, cmd
->fields
[i
].num_bits
);
924 buf_set_buf(cmd
->fields
[i
].out_value
, 0, *buffer
, bit_count
, cmd
->fields
[i
].num_bits
);
925 #ifdef _DEBUG_JTAG_IO_
926 DEBUG("fields[%i].out_value: %s", i
, char_buf
);
931 bit_count
+= cmd
->fields
[i
].num_bits
;
938 int jtag_read_buffer(u8
*buffer
, scan_command_t
*cmd
)
942 int retval
= ERROR_OK
;
944 for (i
=0; i
< cmd
->num_fields
; i
++)
946 /* if neither in_value nor in_check_value are specified we don't have to examine this field */
947 if (cmd
->fields
[i
].in_value
|| cmd
->fields
[i
].in_check_value
)
949 int num_bits
= cmd
->fields
[i
].num_bits
;
951 if (cmd
->fields
[i
].in_value
)
954 buf_set_buf(buffer
, bit_count
, cmd
->fields
[i
].in_value
, 0, num_bits
);
955 char_buf
= buf_to_char(cmd
->fields
[i
].in_value
, num_bits
);
956 #ifdef _DEBUG_JTAG_IO_
957 DEBUG("fields[%i].in_value: %s", i
, char_buf
);
960 if (cmd
->fields
[i
].in_handler
)
962 if (cmd
->fields
[i
].in_handler(cmd
->fields
[i
].in_value
, cmd
->fields
[i
].in_handler_priv
) != ERROR_OK
)
964 /* TODO: error reporting */
965 WARNING("in_handler reported a failed check");
966 retval
= ERROR_JTAG_QUEUE_FAILED
;
971 if (cmd
->fields
[i
].in_check_value
)
973 u8
*captured
= buf_set_buf(buffer
, bit_count
, malloc(CEIL(num_bits
, 8)), 0, num_bits
);
974 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
))
975 || (!cmd
->fields
[i
].in_check_mask
&& buf_cmp(captured
, cmd
->fields
[i
].in_check_mask
, num_bits
)))
977 char *captured_char
= buf_to_char(captured
, num_bits
);
978 char *in_check_value_char
= buf_to_char(cmd
->fields
[i
].in_check_value
, num_bits
);
979 char *in_check_mask_char
= buf_to_char(cmd
->fields
[i
].in_check_mask
, num_bits
);
980 /* TODO: error reporting */
981 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
);
982 retval
= ERROR_JTAG_QUEUE_FAILED
;
984 free(in_check_value_char
);
985 free(in_check_mask_char
);
990 bit_count
+= cmd
->fields
[i
].num_bits
;
996 enum scan_type
jtag_scan_type(scan_command_t
*cmd
)
1001 for (i
=0; i
< cmd
->num_fields
; i
++)
1003 if (cmd
->fields
[i
].in_check_value
|| cmd
->fields
[i
].in_value
)
1005 if (cmd
->fields
[i
].out_value
)
1012 int jtag_execute_queue(void)
1016 retval
= jtag
->execute_queue();
1020 jtag_command_queue
= NULL
;
1021 last_comand_pointer
= &jtag_command_queue
;
1026 int jtag_cancel_queue(void)
1029 jtag_command_queue
= NULL
;
1030 last_comand_pointer
= &jtag_command_queue
;
1035 int jtag_reset_callback(enum jtag_event event
, void *priv
)
1037 jtag_device_t
*device
= priv
;
1041 if (event
== JTAG_TRST_ASSERTED
)
1043 buf_set_ones(device
->cur_instr
, device
->ir_length
);
1050 void jtag_sleep(u32 us
)
1055 int jtag_validate_chain()
1057 jtag_device_t
*device
= jtag_devices
;
1058 int total_ir_length
= 0;
1065 total_ir_length
+= device
->ir_length
;
1066 device
= device
->next
;
1069 total_ir_length
+= 2;
1070 ir_test
= malloc(CEIL(total_ir_length
, 8));
1071 buf_set_ones(ir_test
, total_ir_length
);
1074 field
.num_bits
= total_ir_length
;
1075 field
.out_value
= ir_test
;
1076 field
.out_mask
= NULL
;
1077 field
.in_value
= ir_test
;
1078 field
.in_check_value
= NULL
;
1079 field
.in_check_mask
= NULL
;
1080 field
.in_handler
= NULL
;
1081 field
.in_handler_priv
= NULL
;
1083 jtag_add_plain_ir_scan(1, &field
, TAP_TLR
);
1084 jtag_execute_queue();
1086 device
= jtag_devices
;
1089 if (buf_get_u32(ir_test
, chain_pos
, 2) != 0x1)
1091 ERROR("Error validating JTAG scan chain, IR mismatch");
1094 chain_pos
+= device
->ir_length
;
1095 device
= device
->next
;
1098 if (buf_get_u32(ir_test
, chain_pos
, 2) != 0x3)
1100 ERROR("Error validating JTAG scan chain, IR mismatch");
1109 int jtag_register_commands(struct command_context_s
*cmd_ctx
)
1111 register_command(cmd_ctx
, NULL
, "interface", handle_interface_command
,
1112 COMMAND_CONFIG
, NULL
);
1113 register_command(cmd_ctx
, NULL
, "jtag_speed", handle_jtag_speed_command
,
1114 COMMAND_ANY
, "set jtag speed (if supported) <speed>");
1115 register_command(cmd_ctx
, NULL
, "jtag_device", handle_jtag_device_command
,
1116 COMMAND_CONFIG
, NULL
);
1117 register_command(cmd_ctx
, NULL
, "reset_config", handle_reset_config_command
,
1118 COMMAND_CONFIG
, NULL
);
1120 register_command(cmd_ctx
, NULL
, "scan_chain", handle_scan_chain_command
,
1121 COMMAND_EXEC
, "print current scan chain configuration");
1123 register_command(cmd_ctx
, NULL
, "endstate", handle_endstate_command
,
1124 COMMAND_EXEC
, "finish JTAG operations in <tap_state>");
1125 register_command(cmd_ctx
, NULL
, "jtag_reset", handle_jtag_reset_command
,
1126 COMMAND_EXEC
, "toggle reset lines <trst> <srst>");
1127 register_command(cmd_ctx
, NULL
, "runtest", handle_runtest_command
,
1128 COMMAND_EXEC
, "move to Run-Test/Idle, and execute <num_cycles>");
1129 register_command(cmd_ctx
, NULL
, "statemove", handle_statemove_command
,
1130 COMMAND_EXEC
, "move to current endstate or [tap_state]");
1131 register_command(cmd_ctx
, NULL
, "irscan", handle_irscan_command
,
1132 COMMAND_EXEC
, "execute IR scan <device> <instr> [dev2] [instr2] ...");
1133 register_command(cmd_ctx
, NULL
, "drscan", handle_drscan_command
,
1134 COMMAND_EXEC
, "execute DR scan <device> <var> [dev2] [var2] ...");
1136 register_command(cmd_ctx
, NULL
, "verify_ircapture", handle_verify_ircapture_command
,
1137 COMMAND_ANY
, "verify value captured during Capture-IR <enable|disable>");
1141 int jtag_init(struct command_context_s
*cmd_ctx
)
1147 if (jtag_speed
== -1)
1150 if (jtag_interface
&& (jtag_interface
[0] != 0))
1151 /* configuration var 'jtag_interface' is set, and not empty */
1152 for (i
= 0; jtag_interfaces
[i
]; i
++)
1154 if (strcmp(jtag_interface
, jtag_interfaces
[i
]->name
) == 0)
1156 jtag_device_t
*device
;
1157 device
= jtag_devices
;
1159 if (jtag_interfaces
[i
]->init() != ERROR_OK
)
1160 return ERROR_JTAG_INIT_FAILED
;
1161 jtag
= jtag_interfaces
[i
];
1163 jtag_ir_scan_size
= 0;
1164 jtag_num_devices
= 0;
1165 while (device
!= NULL
)
1167 jtag_ir_scan_size
+= device
->ir_length
;
1169 device
= device
->next
;
1172 jtag_add_statemove(TAP_TLR
);
1173 jtag_execute_queue();
1175 jtag_validate_chain();
1181 /* no valid interface was found (i.e. the configuration option,
1182 * didn't match one of the compiled-in interfaces
1184 ERROR("No valid jtag interface found (%s)", jtag_interface
);
1186 return ERROR_JTAG_INVALID_INTERFACE
;
1189 int handle_interface_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1193 /* only if the configuration var isn't overwritten from cmdline */
1194 if (!jtag_interface
)
1196 if (args
[0] && (args
[0][0] != 0))
1198 for (i
=0; jtag_interfaces
[i
]; i
++)
1200 if (strcmp(args
[0], jtag_interfaces
[i
]->name
) == 0)
1202 if (jtag_interfaces
[i
]->register_commands(cmd_ctx
) != ERROR_OK
)
1205 jtag_interface
= jtag_interfaces
[i
]->name
;
1212 /* remember the requested interface name, so we can complain about it later */
1213 jtag_interface
= strdup(args
[0]);
1214 DEBUG("'interface' command didn't specify a valid interface");
1220 int handle_jtag_device_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1222 jtag_device_t
**last_device_p
= &jtag_devices
;
1226 while ((*last_device_p
)->next
)
1227 last_device_p
= &((*last_device_p
)->next
);
1228 last_device_p
= &((*last_device_p
)->next
);
1234 *last_device_p
= malloc(sizeof(jtag_device_t
));
1235 (*last_device_p
)->ir_length
= strtoul(args
[0], NULL
, 0);
1237 (*last_device_p
)->expected
= malloc((*last_device_p
)->ir_length
);
1238 buf_set_u32((*last_device_p
)->expected
, 0, (*last_device_p
)->ir_length
, strtoul(args
[1], NULL
, 0));
1239 (*last_device_p
)->expected_mask
= malloc((*last_device_p
)->ir_length
);
1240 buf_set_u32((*last_device_p
)->expected_mask
, 0, (*last_device_p
)->ir_length
, strtoul(args
[2], NULL
, 0));
1242 (*last_device_p
)->cur_instr
= malloc((*last_device_p
)->ir_length
);
1243 (*last_device_p
)->bypass
= 1;
1244 buf_set_ones((*last_device_p
)->cur_instr
, (*last_device_p
)->ir_length
);
1246 (*last_device_p
)->next
= NULL
;
1248 jtag_register_event_callback(jtag_reset_callback
, (*last_device_p
));
1255 int handle_scan_chain_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1257 jtag_device_t
*device
= jtag_devices
;
1258 int device_count
= 0;
1262 u32 expected
, expected_mask
, cur_instr
;
1263 expected
= buf_get_u32(device
->expected
, 0, device
->ir_length
);
1264 expected_mask
= buf_get_u32(device
->expected_mask
, 0, device
->ir_length
);
1265 cur_instr
= buf_get_u32(device
->cur_instr
, 0, device
->ir_length
);
1266 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
);
1267 device
= device
->next
;
1274 int handle_reset_config_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1278 if (strcmp(args
[0], "none") == 0)
1279 jtag_reset_config
= RESET_NONE
;
1280 else if (strcmp(args
[0], "trst_only") == 0)
1281 jtag_reset_config
= RESET_HAS_TRST
;
1282 else if (strcmp(args
[0], "srst_only") == 0)
1283 jtag_reset_config
= RESET_HAS_SRST
;
1284 else if (strcmp(args
[0], "trst_and_srst") == 0)
1285 jtag_reset_config
= RESET_TRST_AND_SRST
;
1288 ERROR("invalid reset_config argument");
1295 if (strcmp(args
[1], "srst_pulls_trst") == 0)
1296 jtag_reset_config
|= RESET_SRST_PULLS_TRST
;
1297 else if (strcmp(args
[1], "trst_pulls_srst") == 0)
1298 jtag_reset_config
|= RESET_TRST_PULLS_SRST
;
1299 else if (strcmp(args
[1], "combined") == 0)
1300 jtag_reset_config
|= RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
;
1301 else if (strcmp(args
[1], "separate") == 0)
1302 jtag_reset_config
&= ~(RESET_SRST_PULLS_TRST
| RESET_TRST_PULLS_SRST
);
1305 ERROR("invalid reset_config argument");
1312 if (strcmp(args
[2], "trst_open_drain") == 0)
1313 jtag_reset_config
|= RESET_TRST_OPEN_DRAIN
;
1314 else if (strcmp(args
[2], "trst_push_pull") == 0)
1315 jtag_reset_config
&= ~RESET_TRST_OPEN_DRAIN
;
1318 ERROR("invalid reset_config argument");
1325 if (strcmp(args
[3], "srst_push_pull") == 0)
1326 jtag_reset_config
|= RESET_SRST_PUSH_PULL
;
1327 else if (strcmp(args
[3], "srst_open_drain") == 0)
1328 jtag_reset_config
&= ~RESET_SRST_PUSH_PULL
;
1331 ERROR("invalid reset_config argument");
1339 int handle_jtag_speed_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1342 command_print(cmd_ctx
, "jtag_speed: %i", jtag_speed
);
1346 /* this command can be called during CONFIG,
1347 * in which case jtag isn't initialized */
1349 jtag
->speed(strtoul(args
[0], NULL
, 0));
1351 jtag_speed
= strtoul(args
[0], NULL
, 0);
1357 int handle_endstate_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1359 enum tap_state state
;
1363 command_print(cmd_ctx
, "usage: endstate <tap_state>");
1367 for (state
= 0; state
< 16; state
++)
1369 if (strcmp(args
[0], tap_state_strings
[state
]) == 0)
1371 jtag_add_end_state(state
);
1372 jtag_execute_queue();
1379 int handle_jtag_reset_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1383 char *usage
= "usage: jtag_reset <trst> <srst>";
1388 command_print(cmd_ctx
, usage
);
1392 if (args
[0][0] == '1')
1394 else if (args
[0][0] == '0')
1398 command_print(cmd_ctx
, usage
);
1402 if (args
[1][0] == '1')
1404 else if (args
[1][0] == '0')
1408 command_print(cmd_ctx
, usage
);
1412 if ((retval
= jtag_add_reset(trst
, srst
)) != ERROR_OK
)
1416 case ERROR_JTAG_RESET_WOULD_ASSERT_TRST
:
1417 command_print(cmd_ctx
, "requested reset would assert trst\nif this is acceptable, use jtag_reset 1 %c", args
[1][0]);
1419 case ERROR_JTAG_RESET_CANT_SRST
:
1420 command_print(cmd_ctx
, "can't assert srst because the current reset_config doesn't support it");
1423 command_print(cmd_ctx
, "unknown error");
1426 jtag_execute_queue();
1431 int handle_runtest_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1435 command_print(cmd_ctx
, "usage: runtest <num_cycles>");
1439 jtag_add_runtest(strtol(args
[0], NULL
, 0), -1);
1440 jtag_execute_queue();
1446 int handle_statemove_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1448 enum tap_state state
;
1453 for (state
= 0; state
< 16; state
++)
1455 if (strcmp(args
[0], tap_state_strings
[state
]) == 0)
1462 jtag_add_statemove(state
);
1463 jtag_execute_queue();
1469 int handle_irscan_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1472 scan_field_t
*fields
;
1474 if ((argc
< 2) || (argc
% 2))
1476 command_print(cmd_ctx
, "usage: irscan <device> <instr> [dev2] [instr2] ...");
1480 fields
= malloc(sizeof(scan_field_t
) * argc
/ 2);
1482 for (i
= 0; i
< argc
/ 2; i
++)
1484 int device
= strtoul(args
[i
*2], NULL
, 0);
1485 int field_size
= jtag_get_device(device
)->ir_length
;
1486 fields
[i
].device
= device
;
1487 fields
[i
].out_value
= malloc(CEIL(field_size
, 8));
1488 buf_set_u32(fields
[i
].out_value
, 0, field_size
, strtoul(args
[i
*2+1], NULL
, 0));
1489 fields
[i
].out_mask
= NULL
;
1490 fields
[i
].in_value
= NULL
;
1491 fields
[i
].in_check_mask
= NULL
;
1492 fields
[i
].in_handler
= NULL
;
1493 fields
[i
].in_handler_priv
= NULL
;
1496 jtag_add_ir_scan(argc
/ 2, fields
, -1);
1497 jtag_execute_queue();
1499 for (i
= 0; i
< argc
/ 2; i
++)
1500 free(fields
[i
].out_value
);
1507 int handle_drscan_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1509 scan_field_t
*fields
;
1511 int field_count
= 0;
1515 if ((argc
< 2) || (argc
% 2))
1517 command_print(cmd_ctx
, "usage: drscan <device> <var> [dev2] [var2]");
1521 for (i
= 0; i
< argc
; i
+=2)
1523 var
= get_var_by_namenum(args
[i
+1]);
1526 num_fields
+= var
->num_fields
;
1530 command_print(cmd_ctx
, "variable %s doesn't exist", args
[i
+1]);
1535 fields
= malloc(sizeof(scan_field_t
) * num_fields
);
1537 for (i
= 0; i
< argc
; i
+=2)
1539 var
= get_var_by_namenum(args
[i
+1]);
1541 for (j
= 0; j
< var
->num_fields
; j
++)
1543 fields
[field_count
].device
= strtol(args
[i
], NULL
, 0);
1544 fields
[field_count
].num_bits
= var
->fields
[j
].num_bits
;
1545 fields
[field_count
].out_value
= malloc(CEIL(var
->fields
[j
].num_bits
, 8));
1546 buf_set_u32(fields
[field_count
].out_value
, 0, var
->fields
[j
].num_bits
, var
->fields
[j
].value
);
1547 fields
[field_count
].out_mask
= NULL
;
1548 fields
[field_count
].in_value
= fields
[field_count
].out_value
;
1549 fields
[field_count
].in_check_mask
= NULL
;
1550 fields
[field_count
].in_check_value
= NULL
;
1551 fields
[field_count
].in_handler
= field_le_to_host
;
1552 fields
[field_count
++].in_handler_priv
= &(var
->fields
[j
]);
1556 jtag_add_dr_scan(num_fields
, fields
, -1);
1557 jtag_execute_queue();
1559 for (i
= 0; i
< argc
/ 2; i
++)
1560 free(fields
[i
].out_value
);
1567 int handle_verify_ircapture_command(struct command_context_s
*cmd_ctx
, char *cmd
, char **args
, int argc
)
1571 command_print(cmd_ctx
, "verify Capture-IR is %s", (jtag_verify_capture_ir
) ? "enabled": "disabled");
1575 if (strcmp(args
[0], "enable") == 0)
1577 jtag_verify_capture_ir
= 1;
1579 else if (strcmp(args
[0], "disable") == 0)
1581 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)