Do not assert trst in srst_only case even if srst_pulls_trst.
[openocd.git] / src / jtag / jtag.c
1 /***************************************************************************
2 * Copyright (C) 2005 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
4 * *
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. *
9 * *
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. *
14 * *
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 ***************************************************************************/
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include "replacements.h"
25
26 #include "jtag.h"
27
28 #include "command.h"
29 #include "log.h"
30 #include "interpreter.h"
31
32 #include "stdlib.h"
33 #include "string.h"
34 #include <unistd.h>
35
36
37 /* note that this is not marked as static as it must be available from outside jtag.c for those
38 that implement the jtag_xxx() minidriver layer
39 */
40 int jtag_error=ERROR_OK;
41
42
43 char* tap_state_strings[16] =
44 {
45 "tlr",
46 "sds", "cd", "sd", "e1d", "pd", "e2d", "ud",
47 "rti",
48 "sis", "ci", "si", "e1i", "pi", "e2i", "ui"
49 };
50
51 typedef struct cmd_queue_page_s
52 {
53 void *address;
54 size_t used;
55 struct cmd_queue_page_s *next;
56 } cmd_queue_page_t;
57
58 #define CMD_QUEUE_PAGE_SIZE (1024 * 1024)
59 static cmd_queue_page_t *cmd_queue_pages = NULL;
60
61 /* tap_move[i][j]: tap movement command to go from state i to state j
62 * 0: Test-Logic-Reset
63 * 1: Run-Test/Idle
64 * 2: Shift-DR
65 * 3: Pause-DR
66 * 4: Shift-IR
67 * 5: Pause-IR
68 *
69 * SD->SD and SI->SI have to be caught in interface specific code
70 */
71 u8 tap_move[6][6] =
72 {
73 /* TLR RTI SD PD SI PI */
74 {0x7f, 0x00, 0x17, 0x0a, 0x1b, 0x16}, /* TLR */
75 {0x7f, 0x00, 0x25, 0x05, 0x2b, 0x0b}, /* RTI */
76 {0x7f, 0x31, 0x00, 0x01, 0x0f, 0x2f}, /* SD */
77 {0x7f, 0x30, 0x20, 0x17, 0x1e, 0x2f}, /* PD */
78 {0x7f, 0x31, 0x07, 0x17, 0x00, 0x01}, /* SI */
79 {0x7f, 0x30, 0x1c, 0x17, 0x20, 0x2f} /* PI */
80 };
81
82 int tap_move_map[16] = {
83 0, -1, -1, 2, -1, 3, -1, -1,
84 1, -1, -1, 4, -1, 5, -1, -1
85 };
86
87 tap_transition_t tap_transitions[16] =
88 {
89 {TAP_TLR, TAP_RTI}, /* TLR */
90 {TAP_SIS, TAP_CD}, /* SDS */
91 {TAP_E1D, TAP_SD}, /* CD */
92 {TAP_E1D, TAP_SD}, /* SD */
93 {TAP_UD, TAP_PD}, /* E1D */
94 {TAP_E2D, TAP_PD}, /* PD */
95 {TAP_UD, TAP_SD}, /* E2D */
96 {TAP_SDS, TAP_RTI}, /* UD */
97 {TAP_SDS, TAP_RTI}, /* RTI */
98 {TAP_TLR, TAP_CI}, /* SIS */
99 {TAP_E1I, TAP_SI}, /* CI */
100 {TAP_E1I, TAP_SI}, /* SI */
101 {TAP_UI, TAP_PI}, /* E1I */
102 {TAP_E2I, TAP_PI}, /* PI */
103 {TAP_UI, TAP_SI}, /* E2I */
104 {TAP_SDS, TAP_RTI} /* UI */
105 };
106
107 char* jtag_event_strings[] =
108 {
109 "JTAG controller reset(tms or TRST)"
110 };
111
112 enum tap_state end_state = TAP_TLR;
113 enum tap_state cur_state = TAP_TLR;
114 int jtag_trst = 0;
115 int jtag_srst = 0;
116
117 jtag_command_t *jtag_command_queue = NULL;
118 jtag_command_t **last_comand_pointer = &jtag_command_queue;
119 jtag_device_t *jtag_devices = NULL;
120 int jtag_num_devices = 0;
121 int jtag_ir_scan_size = 0;
122 enum reset_types jtag_reset_config = RESET_NONE;
123 enum tap_state cmd_queue_end_state = TAP_TLR;
124 enum tap_state cmd_queue_cur_state = TAP_TLR;
125
126 int jtag_verify_capture_ir = 1;
127
128 /* how long the OpenOCD should wait before attempting JTAG communication after reset lines deasserted (in ms) */
129 int jtag_nsrst_delay = 0; /* default to no nSRST delay */
130 int jtag_ntrst_delay = 0; /* default to no nTRST delay */
131
132 /* maximum number of JTAG devices expected in the chain
133 */
134 #define JTAG_MAX_CHAIN_SIZE 20
135
136 /* callbacks to inform high-level handlers about JTAG state changes */
137 jtag_event_callback_t *jtag_event_callbacks;
138
139 /* jtag interfaces (parport, FTDI-USB, TI-USB, ...)
140 */
141
142 #if BUILD_ECOSBOARD == 1
143 extern jtag_interface_t eCosBoard_interface;
144 #endif
145
146 #if BUILD_PARPORT == 1
147 extern jtag_interface_t parport_interface;
148 #endif
149
150 #if BUILD_FT2232_FTD2XX == 1
151 extern jtag_interface_t ft2232_interface;
152 #endif
153
154 #if BUILD_FT2232_LIBFTDI == 1
155 extern jtag_interface_t ft2232_interface;
156 #endif
157
158 #if BUILD_AMTJTAGACCEL == 1
159 extern jtag_interface_t amt_jtagaccel_interface;
160 #endif
161
162 #if BUILD_EP93XX == 1
163 extern jtag_interface_t ep93xx_interface;
164 #endif
165
166 #if BUILD_AT91RM9200 == 1
167 extern jtag_interface_t at91rm9200_interface;
168 #endif
169
170 #if BUILD_GW16012 == 1
171 extern jtag_interface_t gw16012_interface;
172 #endif
173
174 #if BUILD_PRESTO_LIBFTDI == 1 || BUILD_PRESTO_FTD2XX == 1
175 extern jtag_interface_t presto_interface;
176 #endif
177
178 #if BUILD_USBPROG == 1
179 extern jtag_interface_t usbprog_interface;
180 #endif
181
182 jtag_interface_t *jtag_interfaces[] = {
183 #if BUILD_ECOSBOARD == 1
184 &eCosBoard_interface,
185 #endif
186 #if BUILD_PARPORT == 1
187 &parport_interface,
188 #endif
189 #if BUILD_FT2232_FTD2XX == 1
190 &ft2232_interface,
191 #endif
192 #if BUILD_FT2232_LIBFTDI == 1
193 &ft2232_interface,
194 #endif
195 #if BUILD_AMTJTAGACCEL == 1
196 &amt_jtagaccel_interface,
197 #endif
198 #if BUILD_EP93XX == 1
199 &ep93xx_interface,
200 #endif
201 #if BUILD_AT91RM9200 == 1
202 &at91rm9200_interface,
203 #endif
204 #if BUILD_GW16012 == 1
205 &gw16012_interface,
206 #endif
207 #if BUILD_PRESTO_LIBFTDI == 1 || BUILD_PRESTO_FTD2XX == 1
208 &presto_interface,
209 #endif
210 #if BUILD_USBPROG == 1
211 &usbprog_interface,
212 #endif
213 NULL,
214 };
215
216 jtag_interface_t *jtag = NULL;
217
218 /* configuration */
219 jtag_interface_t *jtag_interface = NULL;
220 int jtag_speed = 0;
221 int jtag_speed_post_reset = 0;
222
223
224 /* forward declarations */
225 void jtag_add_pathmove(int num_states, enum tap_state *path);
226 void jtag_add_runtest(int num_cycles, enum tap_state endstate);
227 void jtag_add_end_state(enum tap_state endstate);
228 void jtag_add_sleep(u32 us);
229 int jtag_execute_queue(void);
230 int jtag_cancel_queue(void);
231
232 /* jtag commands */
233 int handle_interface_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
234 int handle_jtag_speed_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
235 int handle_jtag_khz_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
236 int handle_jtag_device_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
237 int handle_reset_config_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
238 int handle_jtag_nsrst_delay_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
239 int handle_jtag_ntrst_delay_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
240
241 int handle_scan_chain_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
242
243 int handle_endstate_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
244 int handle_jtag_reset_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
245 int handle_runtest_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
246 int handle_irscan_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
247 int handle_drscan_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
248
249 int handle_verify_ircapture_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
250
251 int jtag_register_event_callback(int (*callback)(enum jtag_event event, void *priv), void *priv)
252 {
253 jtag_event_callback_t **callbacks_p = &jtag_event_callbacks;
254
255 if (callback == NULL)
256 {
257 return ERROR_INVALID_ARGUMENTS;
258 }
259
260 if (*callbacks_p)
261 {
262 while ((*callbacks_p)->next)
263 callbacks_p = &((*callbacks_p)->next);
264 callbacks_p = &((*callbacks_p)->next);
265 }
266
267 (*callbacks_p) = malloc(sizeof(jtag_event_callback_t));
268 (*callbacks_p)->callback = callback;
269 (*callbacks_p)->priv = priv;
270 (*callbacks_p)->next = NULL;
271
272 return ERROR_OK;
273 }
274
275 int jtag_unregister_event_callback(int (*callback)(enum jtag_event event, void *priv))
276 {
277 jtag_event_callback_t **callbacks_p = &jtag_event_callbacks;
278
279 if (callback == NULL)
280 {
281 return ERROR_INVALID_ARGUMENTS;
282 }
283
284 while (*callbacks_p)
285 {
286 jtag_event_callback_t **next = &((*callbacks_p)->next);
287 if ((*callbacks_p)->callback == callback)
288 {
289 free(*callbacks_p);
290 *callbacks_p = *next;
291 }
292 callbacks_p = next;
293 }
294
295 return ERROR_OK;
296 }
297
298 int jtag_call_event_callbacks(enum jtag_event event)
299 {
300 jtag_event_callback_t *callback = jtag_event_callbacks;
301
302 LOG_DEBUG("jtag event: %s", jtag_event_strings[event]);
303
304 while (callback)
305 {
306 callback->callback(event, callback->priv);
307 callback = callback->next;
308 }
309
310 return ERROR_OK;
311 }
312
313 /* returns a pointer to the pointer of the last command in queue
314 * this may be a pointer to the root pointer (jtag_command_queue)
315 * or to the next member of the last but one command
316 */
317 jtag_command_t** jtag_get_last_command_p(void)
318 {
319 /* jtag_command_t *cmd = jtag_command_queue;
320
321 if (cmd)
322 while (cmd->next)
323 cmd = cmd->next;
324 else
325 return &jtag_command_queue;
326
327 return &cmd->next;*/
328
329 return last_comand_pointer;
330 }
331
332 /* returns a pointer to the n-th device in the scan chain */
333 jtag_device_t* jtag_get_device(int num)
334 {
335 jtag_device_t *device = jtag_devices;
336 int i = 0;
337
338 while (device)
339 {
340 if (num == i)
341 return device;
342 device = device->next;
343 i++;
344 }
345
346 LOG_ERROR("jtag device number %d not defined", num);
347 exit(-1);
348 }
349
350 void* cmd_queue_alloc(size_t size)
351 {
352 cmd_queue_page_t **p_page = &cmd_queue_pages;
353 int offset;
354
355 if (*p_page)
356 {
357 while ((*p_page)->next)
358 p_page = &((*p_page)->next);
359 if (CMD_QUEUE_PAGE_SIZE - (*p_page)->used < size)
360 p_page = &((*p_page)->next);
361 }
362
363 if (!*p_page)
364 {
365 *p_page = malloc(sizeof(cmd_queue_page_t));
366 (*p_page)->used = 0;
367 (*p_page)->address = malloc(CMD_QUEUE_PAGE_SIZE);
368 (*p_page)->next = NULL;
369 }
370
371 offset = (*p_page)->used;
372 (*p_page)->used += size;
373
374 u8 *t=(u8 *)((*p_page)->address);
375 return t + offset;
376 }
377
378 void cmd_queue_free()
379 {
380 cmd_queue_page_t *page = cmd_queue_pages;
381
382 while (page)
383 {
384 cmd_queue_page_t *last = page;
385 free(page->address);
386 page = page->next;
387 free(last);
388 }
389
390 cmd_queue_pages = NULL;
391 }
392
393 static void jtag_prelude1()
394 {
395 if (jtag_trst == 1)
396 {
397 LOG_WARNING("JTAG command queued, while TRST is low (TAP in reset)");
398 jtag_error=ERROR_JTAG_TRST_ASSERTED;
399 return;
400 }
401
402 if (cmd_queue_end_state == TAP_TLR)
403 jtag_call_event_callbacks(JTAG_TRST_ASSERTED);
404 }
405
406 static void jtag_prelude(enum tap_state state)
407 {
408 jtag_prelude1();
409
410 if (state != -1)
411 jtag_add_end_state(state);
412
413 cmd_queue_cur_state = cmd_queue_end_state;
414 }
415
416 void jtag_add_ir_scan(int num_fields, scan_field_t *fields, enum tap_state state)
417 {
418 jtag_prelude(state);
419
420 int retval=interface_jtag_add_ir_scan(num_fields, fields, cmd_queue_end_state);
421 if (retval!=ERROR_OK)
422 jtag_error=retval;
423 }
424
425 int MINIDRIVER(interface_jtag_add_ir_scan)(int num_fields, scan_field_t *fields, enum tap_state state)
426 {
427 jtag_command_t **last_cmd;
428 jtag_device_t *device;
429 int i, j;
430 int scan_size = 0;
431
432
433 last_cmd = jtag_get_last_command_p();
434
435 /* allocate memory for a new list member */
436 *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
437 (*last_cmd)->next = NULL;
438 last_comand_pointer = &((*last_cmd)->next);
439 (*last_cmd)->type = JTAG_SCAN;
440
441 /* allocate memory for ir scan command */
442 (*last_cmd)->cmd.scan = cmd_queue_alloc(sizeof(scan_command_t));
443 (*last_cmd)->cmd.scan->ir_scan = 1;
444 (*last_cmd)->cmd.scan->num_fields = jtag_num_devices; /* one field per device */
445 (*last_cmd)->cmd.scan->fields = cmd_queue_alloc(jtag_num_devices * sizeof(scan_field_t));
446 (*last_cmd)->cmd.scan->end_state = state;
447
448 for (i = 0; i < jtag_num_devices; i++)
449 {
450 int found = 0;
451 device = jtag_get_device(i);
452 scan_size = device->ir_length;
453 (*last_cmd)->cmd.scan->fields[i].device = i;
454 (*last_cmd)->cmd.scan->fields[i].num_bits = scan_size;
455 (*last_cmd)->cmd.scan->fields[i].in_value = NULL;
456 (*last_cmd)->cmd.scan->fields[i].in_handler = NULL; /* disable verification by default */
457
458 /* search the list */
459 for (j = 0; j < num_fields; j++)
460 {
461 if (i == fields[j].device)
462 {
463 found = 1;
464 (*last_cmd)->cmd.scan->fields[i].out_value = buf_cpy(fields[j].out_value, cmd_queue_alloc(CEIL(scan_size, 8)), scan_size);
465 (*last_cmd)->cmd.scan->fields[i].out_mask = buf_cpy(fields[j].out_mask, cmd_queue_alloc(CEIL(scan_size, 8)), scan_size);
466
467 if (jtag_verify_capture_ir)
468 {
469 if (fields[j].in_handler==NULL)
470 {
471 jtag_set_check_value((*last_cmd)->cmd.scan->fields+i, device->expected, device->expected_mask, NULL);
472 } else
473 {
474 (*last_cmd)->cmd.scan->fields[i].in_handler = fields[j].in_handler;
475 (*last_cmd)->cmd.scan->fields[i].in_handler_priv = fields[j].in_handler_priv;
476 (*last_cmd)->cmd.scan->fields[i].in_check_value = device->expected;
477 (*last_cmd)->cmd.scan->fields[i].in_check_mask = device->expected_mask;
478 }
479 }
480
481 device->bypass = 0;
482 break;
483 }
484 }
485
486 if (!found)
487 {
488 /* if a device isn't listed, set it to BYPASS */
489 (*last_cmd)->cmd.scan->fields[i].out_value = buf_set_ones(cmd_queue_alloc(CEIL(scan_size, 8)), scan_size);
490 (*last_cmd)->cmd.scan->fields[i].out_mask = NULL;
491 device->bypass = 1;
492
493 }
494
495 /* update device information */
496 buf_cpy((*last_cmd)->cmd.scan->fields[i].out_value, jtag_get_device(i)->cur_instr, scan_size);
497 }
498
499 return ERROR_OK;
500 }
501
502 void jtag_add_plain_ir_scan(int num_fields, scan_field_t *fields, enum tap_state state)
503 {
504 jtag_prelude(state);
505
506 int retval=interface_jtag_add_plain_ir_scan(num_fields, fields, cmd_queue_end_state);
507 if (retval!=ERROR_OK)
508 jtag_error=retval;
509 }
510
511 int MINIDRIVER(interface_jtag_add_plain_ir_scan)(int num_fields, scan_field_t *fields, enum tap_state state)
512 {
513 int i;
514 jtag_command_t **last_cmd;
515
516 last_cmd = jtag_get_last_command_p();
517
518 /* allocate memory for a new list member */
519 *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
520 (*last_cmd)->next = NULL;
521 last_comand_pointer = &((*last_cmd)->next);
522 (*last_cmd)->type = JTAG_SCAN;
523
524 /* allocate memory for ir scan command */
525 (*last_cmd)->cmd.scan = cmd_queue_alloc(sizeof(scan_command_t));
526 (*last_cmd)->cmd.scan->ir_scan = 1;
527 (*last_cmd)->cmd.scan->num_fields = num_fields;
528 (*last_cmd)->cmd.scan->fields = cmd_queue_alloc(num_fields * sizeof(scan_field_t));
529 (*last_cmd)->cmd.scan->end_state = state;
530
531 for (i = 0; i < num_fields; i++)
532 {
533 int num_bits = fields[i].num_bits;
534 int num_bytes = CEIL(fields[i].num_bits, 8);
535 (*last_cmd)->cmd.scan->fields[i].device = fields[i].device;
536 (*last_cmd)->cmd.scan->fields[i].num_bits = num_bits;
537 (*last_cmd)->cmd.scan->fields[i].out_value = buf_cpy(fields[i].out_value, cmd_queue_alloc(num_bytes), num_bits);
538 (*last_cmd)->cmd.scan->fields[i].out_mask = buf_cpy(fields[i].out_mask, cmd_queue_alloc(num_bytes), num_bits);
539 (*last_cmd)->cmd.scan->fields[i].in_value = fields[i].in_value;
540 (*last_cmd)->cmd.scan->fields[i].in_check_value = fields[i].in_check_value;
541 (*last_cmd)->cmd.scan->fields[i].in_check_mask = fields[i].in_check_mask;
542 (*last_cmd)->cmd.scan->fields[i].in_handler = NULL;
543 (*last_cmd)->cmd.scan->fields[i].in_handler_priv = NULL;
544 }
545 return ERROR_OK;
546 }
547
548 void jtag_add_dr_scan(int num_fields, scan_field_t *fields, enum tap_state state)
549 {
550 jtag_prelude(state);
551
552 int retval=interface_jtag_add_dr_scan(num_fields, fields, cmd_queue_end_state);
553 if (retval!=ERROR_OK)
554 jtag_error=retval;
555 }
556
557 int MINIDRIVER(interface_jtag_add_dr_scan)(int num_fields, scan_field_t *fields, enum tap_state state)
558 {
559 int i, j;
560 int bypass_devices = 0;
561 int field_count = 0;
562 int scan_size;
563
564 jtag_command_t **last_cmd = jtag_get_last_command_p();
565 jtag_device_t *device = jtag_devices;
566
567 /* count devices in bypass */
568 while (device)
569 {
570 if (device->bypass)
571 bypass_devices++;
572 device = device->next;
573 }
574
575 /* allocate memory for a new list member */
576 *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
577 last_comand_pointer = &((*last_cmd)->next);
578 (*last_cmd)->next = NULL;
579 (*last_cmd)->type = JTAG_SCAN;
580
581 /* allocate memory for dr scan command */
582 (*last_cmd)->cmd.scan = cmd_queue_alloc(sizeof(scan_command_t));
583 (*last_cmd)->cmd.scan->ir_scan = 0;
584 (*last_cmd)->cmd.scan->num_fields = num_fields + bypass_devices;
585 (*last_cmd)->cmd.scan->fields = cmd_queue_alloc((num_fields + bypass_devices) * sizeof(scan_field_t));
586 (*last_cmd)->cmd.scan->end_state = state;
587
588 for (i = 0; i < jtag_num_devices; i++)
589 {
590 int found = 0;
591 (*last_cmd)->cmd.scan->fields[field_count].device = i;
592
593 for (j = 0; j < num_fields; j++)
594 {
595 if (i == fields[j].device)
596 {
597 found = 1;
598 scan_size = fields[j].num_bits;
599 (*last_cmd)->cmd.scan->fields[field_count].num_bits = scan_size;
600 (*last_cmd)->cmd.scan->fields[field_count].out_value = buf_cpy(fields[j].out_value, cmd_queue_alloc(CEIL(scan_size, 8)), scan_size);
601 (*last_cmd)->cmd.scan->fields[field_count].out_mask = buf_cpy(fields[j].out_mask, cmd_queue_alloc(CEIL(scan_size, 8)), scan_size);
602 (*last_cmd)->cmd.scan->fields[field_count].in_value = fields[j].in_value;
603 (*last_cmd)->cmd.scan->fields[field_count].in_check_value = fields[j].in_check_value;
604 (*last_cmd)->cmd.scan->fields[field_count].in_check_mask = fields[j].in_check_mask;
605 (*last_cmd)->cmd.scan->fields[field_count].in_handler = fields[j].in_handler;
606 (*last_cmd)->cmd.scan->fields[field_count++].in_handler_priv = fields[j].in_handler_priv;
607 }
608 }
609 if (!found)
610 {
611 #ifdef _DEBUG_JTAG_IO_
612 /* if a device isn't listed, the BYPASS register should be selected */
613 if (!jtag_get_device(i)->bypass)
614 {
615 LOG_ERROR("BUG: no scan data for a device not in BYPASS");
616 exit(-1);
617 }
618 #endif
619 /* program the scan field to 1 bit length, and ignore it's value */
620 (*last_cmd)->cmd.scan->fields[field_count].num_bits = 1;
621 (*last_cmd)->cmd.scan->fields[field_count].out_value = NULL;
622 (*last_cmd)->cmd.scan->fields[field_count].out_mask = NULL;
623 (*last_cmd)->cmd.scan->fields[field_count].in_value = NULL;
624 (*last_cmd)->cmd.scan->fields[field_count].in_check_value = NULL;
625 (*last_cmd)->cmd.scan->fields[field_count].in_check_mask = NULL;
626 (*last_cmd)->cmd.scan->fields[field_count].in_handler = NULL;
627 (*last_cmd)->cmd.scan->fields[field_count++].in_handler_priv = NULL;
628 }
629 else
630 {
631 #ifdef _DEBUG_JTAG_IO_
632 /* if a device is listed, the BYPASS register must not be selected */
633 if (jtag_get_device(i)->bypass)
634 {
635 LOG_ERROR("BUG: scan data for a device in BYPASS");
636 exit(-1);
637 }
638 #endif
639 }
640 }
641 return ERROR_OK;
642 }
643
644 void MINIDRIVER(interface_jtag_add_dr_out)(int device_num,
645 int num_fields,
646 int *num_bits,
647 u32 *value,
648 enum tap_state end_state)
649 {
650 int i;
651 int field_count = 0;
652 int scan_size;
653 int bypass_devices = 0;
654
655 jtag_command_t **last_cmd = jtag_get_last_command_p();
656 jtag_device_t *device = jtag_devices;
657 /* count devices in bypass */
658 while (device)
659 {
660 if (device->bypass)
661 bypass_devices++;
662 device = device->next;
663 }
664
665 /* allocate memory for a new list member */
666 *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
667 last_comand_pointer = &((*last_cmd)->next);
668 (*last_cmd)->next = NULL;
669 (*last_cmd)->type = JTAG_SCAN;
670
671 /* allocate memory for dr scan command */
672 (*last_cmd)->cmd.scan = cmd_queue_alloc(sizeof(scan_command_t));
673 (*last_cmd)->cmd.scan->ir_scan = 0;
674 (*last_cmd)->cmd.scan->num_fields = num_fields + bypass_devices;
675 (*last_cmd)->cmd.scan->fields = cmd_queue_alloc((num_fields + bypass_devices) * sizeof(scan_field_t));
676 (*last_cmd)->cmd.scan->end_state = end_state;
677
678 for (i = 0; i < jtag_num_devices; i++)
679 {
680 (*last_cmd)->cmd.scan->fields[field_count].device = i;
681
682 if (i == device_num)
683 {
684 int j;
685 #ifdef _DEBUG_JTAG_IO_
686 /* if a device is listed, the BYPASS register must not be selected */
687 if (jtag_get_device(i)->bypass)
688 {
689 LOG_ERROR("BUG: scan data for a device in BYPASS");
690 exit(-1);
691 }
692 #endif
693 for (j = 0; j < num_fields; j++)
694 {
695 u8 out_value[4];
696 scan_size = num_bits[j];
697 buf_set_u32(out_value, 0, scan_size, value[j]);
698 (*last_cmd)->cmd.scan->fields[field_count].num_bits = scan_size;
699 (*last_cmd)->cmd.scan->fields[field_count].out_value = buf_cpy(out_value, cmd_queue_alloc(CEIL(scan_size, 8)), scan_size);
700 (*last_cmd)->cmd.scan->fields[field_count].out_mask = NULL;
701 (*last_cmd)->cmd.scan->fields[field_count].in_value = NULL;
702 (*last_cmd)->cmd.scan->fields[field_count].in_check_value = NULL;
703 (*last_cmd)->cmd.scan->fields[field_count].in_check_mask = NULL;
704 (*last_cmd)->cmd.scan->fields[field_count].in_handler = NULL;
705 (*last_cmd)->cmd.scan->fields[field_count++].in_handler_priv = NULL;
706 }
707 } else
708 {
709 #ifdef _DEBUG_JTAG_IO_
710 /* if a device isn't listed, the BYPASS register should be selected */
711 if (!jtag_get_device(i)->bypass)
712 {
713 LOG_ERROR("BUG: no scan data for a device not in BYPASS");
714 exit(-1);
715 }
716 #endif
717 /* program the scan field to 1 bit length, and ignore it's value */
718 (*last_cmd)->cmd.scan->fields[field_count].num_bits = 1;
719 (*last_cmd)->cmd.scan->fields[field_count].out_value = NULL;
720 (*last_cmd)->cmd.scan->fields[field_count].out_mask = NULL;
721 (*last_cmd)->cmd.scan->fields[field_count].in_value = NULL;
722 (*last_cmd)->cmd.scan->fields[field_count].in_check_value = NULL;
723 (*last_cmd)->cmd.scan->fields[field_count].in_check_mask = NULL;
724 (*last_cmd)->cmd.scan->fields[field_count].in_handler = NULL;
725 (*last_cmd)->cmd.scan->fields[field_count++].in_handler_priv = NULL;
726 }
727 }
728 }
729
730
731
732
733 void jtag_add_plain_dr_scan(int num_fields, scan_field_t *fields, enum tap_state state)
734 {
735 jtag_prelude(state);
736
737 int retval=interface_jtag_add_plain_dr_scan(num_fields, fields, cmd_queue_end_state);
738 if (retval!=ERROR_OK)
739 jtag_error=retval;
740 }
741
742 int MINIDRIVER(interface_jtag_add_plain_dr_scan)(int num_fields, scan_field_t *fields, enum tap_state state)
743 {
744 int i;
745 jtag_command_t **last_cmd = jtag_get_last_command_p();
746
747 /* allocate memory for a new list member */
748 *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
749 last_comand_pointer = &((*last_cmd)->next);
750 (*last_cmd)->next = NULL;
751 (*last_cmd)->type = JTAG_SCAN;
752
753 /* allocate memory for scan command */
754 (*last_cmd)->cmd.scan = cmd_queue_alloc(sizeof(scan_command_t));
755 (*last_cmd)->cmd.scan->ir_scan = 0;
756 (*last_cmd)->cmd.scan->num_fields = num_fields;
757 (*last_cmd)->cmd.scan->fields = cmd_queue_alloc(num_fields * sizeof(scan_field_t));
758 (*last_cmd)->cmd.scan->end_state = state;
759
760 for (i = 0; i < num_fields; i++)
761 {
762 int num_bits = fields[i].num_bits;
763 int num_bytes = CEIL(fields[i].num_bits, 8);
764 (*last_cmd)->cmd.scan->fields[i].device = fields[i].device;
765 (*last_cmd)->cmd.scan->fields[i].num_bits = num_bits;
766 (*last_cmd)->cmd.scan->fields[i].out_value = buf_cpy(fields[i].out_value, cmd_queue_alloc(num_bytes), num_bits);
767 (*last_cmd)->cmd.scan->fields[i].out_mask = buf_cpy(fields[i].out_mask, cmd_queue_alloc(num_bytes), num_bits);
768 (*last_cmd)->cmd.scan->fields[i].in_value = fields[i].in_value;
769 (*last_cmd)->cmd.scan->fields[i].in_check_value = fields[i].in_check_value;
770 (*last_cmd)->cmd.scan->fields[i].in_check_mask = fields[i].in_check_mask;
771 (*last_cmd)->cmd.scan->fields[i].in_handler = fields[i].in_handler;
772 (*last_cmd)->cmd.scan->fields[i].in_handler_priv = fields[i].in_handler_priv;
773 }
774
775 return ERROR_OK;
776 }
777
778 void jtag_add_tms()
779 {
780 jtag_prelude(TAP_TLR);
781
782 int retval;
783 retval=interface_jtag_add_tms();
784 if (retval!=ERROR_OK)
785 jtag_error=retval;
786 }
787
788 int MINIDRIVER(interface_jtag_add_tms)()
789 {
790 enum tap_state state = TAP_TLR;
791 jtag_command_t **last_cmd = jtag_get_last_command_p();
792
793 /* allocate memory for a new list member */
794 *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
795 last_comand_pointer = &((*last_cmd)->next);
796 (*last_cmd)->next = NULL;
797 (*last_cmd)->type = JTAG_STATEMOVE;
798
799 (*last_cmd)->cmd.statemove = cmd_queue_alloc(sizeof(statemove_command_t));
800 (*last_cmd)->cmd.statemove->end_state = state;
801
802
803 return ERROR_OK;
804 }
805
806 void jtag_add_pathmove(int num_states, enum tap_state *path)
807 {
808 /* the last state has to be a stable state */
809 if (tap_move_map[path[num_states - 1]] == -1)
810 {
811 LOG_ERROR("BUG: TAP path doesn't finish in a stable state");
812 exit(-1);
813 }
814
815 enum tap_state cur_state=cmd_queue_cur_state;
816 int i;
817 for (i=0; i<num_states; i++)
818 {
819 if ((tap_transitions[cur_state].low != path[i])&&
820 (tap_transitions[cur_state].high != path[i]))
821 {
822 LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", tap_state_strings[cur_state], tap_state_strings[path[i]]);
823 exit(-1);
824 }
825 cur_state = path[i];
826 }
827
828 jtag_prelude1();
829
830 cmd_queue_cur_state = path[num_states - 1];
831
832 int retval=interface_jtag_add_pathmove(num_states, path);
833 if (retval!=ERROR_OK)
834 jtag_error=retval;
835 }
836
837
838 int MINIDRIVER(interface_jtag_add_pathmove)(int num_states, enum tap_state *path)
839 {
840 jtag_command_t **last_cmd = jtag_get_last_command_p();
841 int i;
842
843 /* allocate memory for a new list member */
844 *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
845 last_comand_pointer = &((*last_cmd)->next);
846 (*last_cmd)->next = NULL;
847 (*last_cmd)->type = JTAG_PATHMOVE;
848
849 (*last_cmd)->cmd.pathmove = cmd_queue_alloc(sizeof(pathmove_command_t));
850 (*last_cmd)->cmd.pathmove->num_states = num_states;
851 (*last_cmd)->cmd.pathmove->path = cmd_queue_alloc(sizeof(enum tap_state) * num_states);
852
853 for (i = 0; i < num_states; i++)
854 (*last_cmd)->cmd.pathmove->path[i] = path[i];
855
856 return ERROR_OK;
857 }
858
859 int MINIDRIVER(interface_jtag_add_runtest)(int num_cycles, enum tap_state state)
860 {
861 jtag_command_t **last_cmd = jtag_get_last_command_p();
862
863 /* allocate memory for a new list member */
864 *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
865 (*last_cmd)->next = NULL;
866 last_comand_pointer = &((*last_cmd)->next);
867 (*last_cmd)->type = JTAG_RUNTEST;
868
869 (*last_cmd)->cmd.runtest = cmd_queue_alloc(sizeof(runtest_command_t));
870 (*last_cmd)->cmd.runtest->num_cycles = num_cycles;
871 (*last_cmd)->cmd.runtest->end_state = state;
872
873 return ERROR_OK;
874 }
875
876 void jtag_add_runtest(int num_cycles, enum tap_state state)
877 {
878 jtag_prelude(state);
879
880 /* executed by sw or hw fifo */
881 int retval=interface_jtag_add_runtest(num_cycles, cmd_queue_end_state);
882 if (retval!=ERROR_OK)
883 jtag_error=retval;
884 }
885
886 void jtag_add_reset(int req_tms_or_trst, int req_srst)
887 {
888 int trst_with_tms = 0;
889 int retval;
890
891 /* Make sure that jtag_reset_config allows the requested reset */
892 /* if SRST pulls TRST, we can't fulfill srst == 1 with trst == 0 */
893 if (((jtag_reset_config & RESET_SRST_PULLS_TRST) && (req_srst == 1)) && (!req_tms_or_trst))
894 {
895 LOG_ERROR("BUG: requested reset would assert trst");
896 jtag_error=ERROR_FAIL;
897 return;
898 }
899
900 /* if TRST pulls SRST, we reset with TAP T-L-R */
901 if (((jtag_reset_config & RESET_TRST_PULLS_SRST) && (req_tms_or_trst)) && (req_srst == 0))
902 {
903 trst_with_tms = 1;
904 }
905
906 if (req_srst && !(jtag_reset_config & RESET_HAS_SRST))
907 {
908 LOG_ERROR("BUG: requested SRST assertion, but the current configuration doesn't support this");
909 jtag_error=ERROR_FAIL;
910 return;
911 }
912
913 if (req_tms_or_trst)
914 {
915 if (!trst_with_tms && (jtag_reset_config & RESET_HAS_TRST))
916 {
917 jtag_trst = 1;
918 } else
919 {
920 trst_with_tms = 1;
921 }
922 } else
923 {
924 jtag_trst = 0;
925 }
926
927 jtag_srst = req_srst;
928
929 retval = interface_jtag_add_reset(jtag_trst, jtag_srst);
930 if (retval!=ERROR_OK)
931 {
932 jtag_error=retval;
933 return;
934 }
935
936 if (jtag_srst)
937 {
938 LOG_DEBUG("SRST line asserted");
939 }
940 else
941 {
942 LOG_DEBUG("SRST line released");
943 if (jtag_nsrst_delay)
944 jtag_add_sleep(jtag_nsrst_delay * 1000);
945 }
946
947 if (trst_with_tms)
948 {
949 LOG_DEBUG("JTAG reset with tms instead of TRST");
950 jtag_add_end_state(TAP_TLR);
951 jtag_add_tms();
952 jtag_call_event_callbacks(JTAG_TRST_ASSERTED);
953 return;
954 }
955
956 if (jtag_trst)
957 {
958 /* we just asserted nTRST, so we're now in Test-Logic-Reset,
959 * and inform possible listeners about this
960 */
961 LOG_DEBUG("TRST line asserted");
962 cmd_queue_cur_state = TAP_TLR;
963 jtag_call_event_callbacks(JTAG_TRST_ASSERTED);
964 }
965 else
966 {
967 if (jtag_ntrst_delay)
968 jtag_add_sleep(jtag_ntrst_delay * 1000);
969 }
970 }
971
972 int MINIDRIVER(interface_jtag_add_reset)(int req_trst, int req_srst)
973 {
974 jtag_command_t **last_cmd = jtag_get_last_command_p();
975
976 /* allocate memory for a new list member */
977 *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
978 (*last_cmd)->next = NULL;
979 last_comand_pointer = &((*last_cmd)->next);
980 (*last_cmd)->type = JTAG_RESET;
981
982 (*last_cmd)->cmd.reset = cmd_queue_alloc(sizeof(reset_command_t));
983 (*last_cmd)->cmd.reset->trst = req_trst;
984 (*last_cmd)->cmd.reset->srst = req_srst;
985
986
987 return ERROR_OK;
988 }
989
990 void jtag_add_end_state(enum tap_state state)
991 {
992 cmd_queue_end_state = state;
993 if ((cmd_queue_end_state == TAP_SD)||(cmd_queue_end_state == TAP_SD))
994 {
995 LOG_ERROR("BUG: TAP_SD/SI can't be end state. Calling code should use a larger scan field");
996 }
997 }
998
999 int MINIDRIVER(interface_jtag_add_sleep)(u32 us)
1000 {
1001 jtag_command_t **last_cmd = jtag_get_last_command_p();
1002
1003 /* allocate memory for a new list member */
1004 *last_cmd = cmd_queue_alloc(sizeof(jtag_command_t));
1005 (*last_cmd)->next = NULL;
1006 last_comand_pointer = &((*last_cmd)->next);
1007 (*last_cmd)->type = JTAG_SLEEP;
1008
1009 (*last_cmd)->cmd.sleep = cmd_queue_alloc(sizeof(sleep_command_t));
1010 (*last_cmd)->cmd.sleep->us = us;
1011
1012 return ERROR_OK;
1013 }
1014
1015 void jtag_add_sleep(u32 us)
1016 {
1017 int retval=interface_jtag_add_sleep(us);
1018 if (retval!=ERROR_OK)
1019 jtag_error=retval;
1020 return;
1021 }
1022
1023 int jtag_scan_size(scan_command_t *cmd)
1024 {
1025 int bit_count = 0;
1026 int i;
1027
1028 /* count bits in scan command */
1029 for (i = 0; i < cmd->num_fields; i++)
1030 {
1031 bit_count += cmd->fields[i].num_bits;
1032 }
1033
1034 return bit_count;
1035 }
1036
1037 int jtag_build_buffer(scan_command_t *cmd, u8 **buffer)
1038 {
1039 int bit_count = 0;
1040 int i;
1041
1042 bit_count = jtag_scan_size(cmd);
1043 *buffer = malloc(CEIL(bit_count, 8));
1044
1045 bit_count = 0;
1046
1047 for (i = 0; i < cmd->num_fields; i++)
1048 {
1049 if (cmd->fields[i].out_value)
1050 {
1051 #ifdef _DEBUG_JTAG_IO_
1052 char* char_buf = buf_to_str(cmd->fields[i].out_value, (cmd->fields[i].num_bits > 64) ? 64 : cmd->fields[i].num_bits, 16);
1053 #endif
1054 buf_set_buf(cmd->fields[i].out_value, 0, *buffer, bit_count, cmd->fields[i].num_bits);
1055 #ifdef _DEBUG_JTAG_IO_
1056 LOG_DEBUG("fields[%i].out_value: 0x%s", i, char_buf);
1057 free(char_buf);
1058 #endif
1059 }
1060
1061 bit_count += cmd->fields[i].num_bits;
1062 }
1063
1064 return bit_count;
1065
1066 }
1067
1068 int jtag_read_buffer(u8 *buffer, scan_command_t *cmd)
1069 {
1070 int i;
1071 int bit_count = 0;
1072 int retval;
1073
1074 /* we return ERROR_OK, unless a check fails, or a handler reports a problem */
1075 retval = ERROR_OK;
1076
1077 for (i = 0; i < cmd->num_fields; i++)
1078 {
1079 /* if neither in_value nor in_handler
1080 * are specified we don't have to examine this field
1081 */
1082 if (cmd->fields[i].in_value || cmd->fields[i].in_handler)
1083 {
1084 int num_bits = cmd->fields[i].num_bits;
1085 u8 *captured = buf_set_buf(buffer, bit_count, malloc(CEIL(num_bits, 8)), 0, num_bits);
1086
1087 #ifdef _DEBUG_JTAG_IO_
1088 char *char_buf;
1089
1090 char_buf = buf_to_str(captured, (num_bits > 64) ? 64 : num_bits, 16);
1091 LOG_DEBUG("fields[%i].in_value: 0x%s", i, char_buf);
1092 free(char_buf);
1093 #endif
1094
1095 if (cmd->fields[i].in_value)
1096 {
1097 buf_cpy(captured, cmd->fields[i].in_value, num_bits);
1098
1099 if (cmd->fields[i].in_handler)
1100 {
1101 if (cmd->fields[i].in_handler(cmd->fields[i].in_value, cmd->fields[i].in_handler_priv, cmd->fields+i) != ERROR_OK)
1102 {
1103 LOG_WARNING("in_handler reported a failed check");
1104 retval = ERROR_JTAG_QUEUE_FAILED;
1105 }
1106 }
1107 }
1108
1109 /* no in_value specified, but a handler takes care of the scanned data */
1110 if (cmd->fields[i].in_handler && (!cmd->fields[i].in_value))
1111 {
1112 if (cmd->fields[i].in_handler(captured, cmd->fields[i].in_handler_priv, cmd->fields+i) != ERROR_OK)
1113 {
1114 /* We're going to call the error:handler later, but if the in_handler
1115 * reported an error we report this failure upstream
1116 */
1117 LOG_WARNING("in_handler reported a failed check");
1118 retval = ERROR_JTAG_QUEUE_FAILED;
1119 }
1120 }
1121
1122 free(captured);
1123 }
1124 bit_count += cmd->fields[i].num_bits;
1125 }
1126
1127 return retval;
1128 }
1129
1130 int jtag_check_value(u8 *captured, void *priv, scan_field_t *field)
1131 {
1132 int retval = ERROR_OK;
1133 int num_bits = field->num_bits;
1134
1135 int compare_failed = 0;
1136
1137 if (field->in_check_mask)
1138 compare_failed = buf_cmp_mask(captured, field->in_check_value, field->in_check_mask, num_bits);
1139 else
1140 compare_failed = buf_cmp(captured, field->in_check_value, num_bits);
1141
1142 if (compare_failed)
1143 {
1144 /* An error handler could have caught the failing check
1145 * only report a problem when there wasn't a handler, or if the handler
1146 * acknowledged the error
1147 */
1148 if (compare_failed)
1149 {
1150 char *captured_char = buf_to_str(captured, (num_bits > 64) ? 64 : num_bits, 16);
1151 char *in_check_value_char = buf_to_str(field->in_check_value, (num_bits > 64) ? 64 : num_bits, 16);
1152
1153 if (field->in_check_mask)
1154 {
1155 char *in_check_mask_char;
1156 in_check_mask_char = buf_to_str(field->in_check_mask, (num_bits > 64) ? 64 : num_bits, 16);
1157 LOG_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);
1158 free(in_check_mask_char);
1159 }
1160 else
1161 {
1162 LOG_WARNING("value captured during scan didn't pass the requested check: captured: 0x%s check_value: 0x%s", captured_char, in_check_value_char);
1163 }
1164
1165 free(captured_char);
1166 free(in_check_value_char);
1167
1168 retval = ERROR_JTAG_QUEUE_FAILED;
1169 }
1170
1171 }
1172 return retval;
1173 }
1174
1175 /*
1176 set up checking of this field using the in_handler. The values passed in must be valid until
1177 after jtag_execute() has completed.
1178 */
1179 void jtag_set_check_value(scan_field_t *field, u8 *value, u8 *mask, error_handler_t *in_error_handler)
1180 {
1181 if (value)
1182 field->in_handler = jtag_check_value;
1183 else
1184 field->in_handler = NULL; /* No check, e.g. embeddedice uses value==NULL to indicate no check */
1185 field->in_handler_priv = NULL; /* this will be filled in at the invocation site to point to the field duplicate */
1186 field->in_check_value = value;
1187 field->in_check_mask = mask;
1188 }
1189
1190 enum scan_type jtag_scan_type(scan_command_t *cmd)
1191 {
1192 int i;
1193 int type = 0;
1194
1195 for (i = 0; i < cmd->num_fields; i++)
1196 {
1197 if (cmd->fields[i].in_value || cmd->fields[i].in_handler)
1198 type |= SCAN_IN;
1199 if (cmd->fields[i].out_value)
1200 type |= SCAN_OUT;
1201 }
1202
1203 return type;
1204 }
1205
1206 int MINIDRIVER(interface_jtag_execute_queue)(void)
1207 {
1208 int retval;
1209
1210 retval = jtag->execute_queue();
1211
1212 cmd_queue_free();
1213
1214 jtag_command_queue = NULL;
1215 last_comand_pointer = &jtag_command_queue;
1216
1217 return retval;
1218 }
1219
1220 int jtag_execute_queue(void)
1221 {
1222 int retval=interface_jtag_execute_queue();
1223 if (retval==ERROR_OK)
1224 {
1225 retval=jtag_error;
1226 }
1227 jtag_error=ERROR_OK;
1228 return retval;
1229 }
1230
1231 int jtag_reset_callback(enum jtag_event event, void *priv)
1232 {
1233 jtag_device_t *device = priv;
1234
1235 LOG_DEBUG("-");
1236
1237 if (event == JTAG_TRST_ASSERTED)
1238 {
1239 buf_set_ones(device->cur_instr, device->ir_length);
1240 device->bypass = 1;
1241 }
1242
1243 return ERROR_OK;
1244 }
1245
1246 void jtag_sleep(u32 us)
1247 {
1248 usleep(us);
1249 }
1250
1251 /* Try to examine chain layout according to IEEE 1149.1 §12
1252 */
1253 int jtag_examine_chain()
1254 {
1255 jtag_device_t *device = jtag_devices;
1256 scan_field_t field;
1257 u8 idcode_buffer[JTAG_MAX_CHAIN_SIZE * 4];
1258 int i;
1259 int bit_count;
1260 int device_count = 0;
1261 u8 zero_check = 0x0;
1262 u8 one_check = 0xff;
1263
1264 field.device = 0;
1265 field.num_bits = sizeof(idcode_buffer) * 8;
1266 field.out_value = idcode_buffer;
1267 field.out_mask = NULL;
1268 field.in_value = idcode_buffer;
1269 field.in_check_value = NULL;
1270 field.in_check_mask = NULL;
1271 field.in_handler = NULL;
1272 field.in_handler_priv = NULL;
1273
1274 for (i = 0; i < JTAG_MAX_CHAIN_SIZE; i++)
1275 {
1276 buf_set_u32(idcode_buffer, i * 32, 32, 0x000000FF);
1277 }
1278
1279 jtag_add_plain_dr_scan(1, &field, TAP_TLR);
1280 jtag_execute_queue();
1281
1282 for (i = 0; i < JTAG_MAX_CHAIN_SIZE * 4; i++)
1283 {
1284 zero_check |= idcode_buffer[i];
1285 one_check &= idcode_buffer[i];
1286 }
1287
1288 /* if there wasn't a single non-zero bit or if all bits were one, the scan isn't valid */
1289 if ((zero_check == 0x00) || (one_check == 0xff))
1290 {
1291 LOG_ERROR("JTAG communication failure, check connection, JTAG interface, target power etc.");
1292 return ERROR_JTAG_INIT_FAILED;
1293 }
1294
1295 for (bit_count = 0; bit_count < (JTAG_MAX_CHAIN_SIZE * 32) - 31;)
1296 {
1297 u32 idcode = buf_get_u32(idcode_buffer, bit_count, 32);
1298 if ((idcode & 1) == 0)
1299 {
1300 /* LSB must not be 0, this indicates a device in bypass */
1301 device_count++;
1302
1303 bit_count += 1;
1304 }
1305 else
1306 {
1307 u32 manufacturer;
1308 u32 part;
1309 u32 version;
1310
1311 if (idcode == 0x000000FF)
1312 {
1313 /* End of chain (invalid manufacturer ID) */
1314 break;
1315 }
1316
1317 if (device)
1318 {
1319 device->idcode = idcode;
1320 device = device->next;
1321 }
1322 device_count++;
1323
1324 manufacturer = (idcode & 0xffe) >> 1;
1325 part = (idcode & 0xffff000) >> 12;
1326 version = (idcode & 0xf0000000) >> 28;
1327
1328 LOG_INFO("JTAG device found: 0x%8.8x (Manufacturer: 0x%3.3x, Part: 0x%4.4x, Version: 0x%1.1x)",
1329 idcode, manufacturer, part, version);
1330
1331 bit_count += 32;
1332 }
1333 }
1334
1335 /* see if number of discovered devices matches configuration */
1336 if (device_count != jtag_num_devices)
1337 {
1338 LOG_ERROR("number of discovered devices in JTAG chain (%i) doesn't match configuration (%i)",
1339 device_count, jtag_num_devices);
1340 LOG_ERROR("check the config file and ensure proper JTAG communication (connections, speed, ...)");
1341 return ERROR_JTAG_INIT_FAILED;
1342 }
1343
1344 return ERROR_OK;
1345 }
1346
1347 int jtag_validate_chain()
1348 {
1349 jtag_device_t *device = jtag_devices;
1350 int total_ir_length = 0;
1351 u8 *ir_test = NULL;
1352 scan_field_t field;
1353 int chain_pos = 0;
1354
1355 while (device)
1356 {
1357 total_ir_length += device->ir_length;
1358 device = device->next;
1359 }
1360
1361 total_ir_length += 2;
1362 ir_test = malloc(CEIL(total_ir_length, 8));
1363 buf_set_ones(ir_test, total_ir_length);
1364
1365 field.device = 0;
1366 field.num_bits = total_ir_length;
1367 field.out_value = ir_test;
1368 field.out_mask = NULL;
1369 field.in_value = ir_test;
1370 field.in_check_value = NULL;
1371 field.in_check_mask = NULL;
1372 field.in_handler = NULL;
1373 field.in_handler_priv = NULL;
1374
1375 jtag_add_plain_ir_scan(1, &field, TAP_TLR);
1376 jtag_execute_queue();
1377
1378 device = jtag_devices;
1379 while (device)
1380 {
1381 if (buf_get_u32(ir_test, chain_pos, 2) != 0x1)
1382 {
1383 char *cbuf = buf_to_str(ir_test, total_ir_length, 16);
1384 LOG_ERROR("Error validating JTAG scan chain, IR mismatch, scan returned 0x%s", cbuf);
1385 free(cbuf);
1386 free(ir_test);
1387 return ERROR_JTAG_INIT_FAILED;
1388 }
1389 chain_pos += device->ir_length;
1390 device = device->next;
1391 }
1392
1393 if (buf_get_u32(ir_test, chain_pos, 2) != 0x3)
1394 {
1395 char *cbuf = buf_to_str(ir_test, total_ir_length, 16);
1396 LOG_ERROR("Error validating JTAG scan chain, IR mismatch, scan returned 0x%s", cbuf);
1397 free(cbuf);
1398 free(ir_test);
1399 return ERROR_JTAG_INIT_FAILED;
1400 }
1401
1402 free(ir_test);
1403
1404 return ERROR_OK;
1405 }
1406
1407 int jtag_register_commands(struct command_context_s *cmd_ctx)
1408 {
1409 register_command(cmd_ctx, NULL, "interface", handle_interface_command,
1410 COMMAND_CONFIG, NULL);
1411 register_command(cmd_ctx, NULL, "jtag_speed", handle_jtag_speed_command,
1412 COMMAND_ANY, "set jtag speed (if supported) <reset speed> [<post reset speed, default value is reset speed>]");
1413 register_command(cmd_ctx, NULL, "jtag_khz", handle_jtag_khz_command,
1414 COMMAND_ANY, "same as jtag_speed, except it takes maximum khz as arguments. 0 KHz = RTCK.");
1415 register_command(cmd_ctx, NULL, "jtag_device", handle_jtag_device_command,
1416 COMMAND_CONFIG, "jtag_device <ir_length> <ir_expected> <ir_mask>");
1417 register_command(cmd_ctx, NULL, "reset_config", handle_reset_config_command,
1418 COMMAND_CONFIG, NULL);
1419 register_command(cmd_ctx, NULL, "jtag_nsrst_delay", handle_jtag_nsrst_delay_command,
1420 COMMAND_CONFIG, NULL);
1421 register_command(cmd_ctx, NULL, "jtag_ntrst_delay", handle_jtag_ntrst_delay_command,
1422 COMMAND_CONFIG, NULL);
1423
1424 register_command(cmd_ctx, NULL, "scan_chain", handle_scan_chain_command,
1425 COMMAND_EXEC, "print current scan chain configuration");
1426
1427 register_command(cmd_ctx, NULL, "endstate", handle_endstate_command,
1428 COMMAND_EXEC, "finish JTAG operations in <tap_state>");
1429 register_command(cmd_ctx, NULL, "jtag_reset", handle_jtag_reset_command,
1430 COMMAND_EXEC, "toggle reset lines <trst> <srst>");
1431 register_command(cmd_ctx, NULL, "runtest", handle_runtest_command,
1432 COMMAND_EXEC, "move to Run-Test/Idle, and execute <num_cycles>");
1433 register_command(cmd_ctx, NULL, "irscan", handle_irscan_command,
1434 COMMAND_EXEC, "execute IR scan <device> <instr> [dev2] [instr2] ...");
1435 register_command(cmd_ctx, NULL, "drscan", handle_drscan_command,
1436 COMMAND_EXEC, "execute DR scan <device> <var> [dev2] [var2] ...");
1437
1438 register_command(cmd_ctx, NULL, "verify_ircapture", handle_verify_ircapture_command,
1439 COMMAND_ANY, "verify value captured during Capture-IR <enable|disable>");
1440 return ERROR_OK;
1441 }
1442
1443 int jtag_interface_init(struct command_context_s *cmd_ctx)
1444 {
1445 if (!jtag_interface)
1446 {
1447 /* nothing was previously specified by "interface" command */
1448 LOG_ERROR("JTAG interface has to be specified, see \"interface\" command");
1449 return ERROR_JTAG_INVALID_INTERFACE;
1450 }
1451
1452 if (jtag_interface->init() != ERROR_OK)
1453 return ERROR_JTAG_INIT_FAILED;
1454
1455 jtag = jtag_interface;
1456 return ERROR_OK;
1457 }
1458
1459 int jtag_init(struct command_context_s *cmd_ctx)
1460 {
1461 int validate_tries = 0;
1462 jtag_device_t *device;
1463
1464 LOG_DEBUG("-");
1465
1466 if (!jtag && jtag_interface_init(cmd_ctx) != ERROR_OK)
1467 return ERROR_JTAG_INIT_FAILED;
1468
1469 device = jtag_devices;
1470 jtag_ir_scan_size = 0;
1471 jtag_num_devices = 0;
1472 while (device != NULL)
1473 {
1474 jtag_ir_scan_size += device->ir_length;
1475 jtag_num_devices++;
1476 device = device->next;
1477 }
1478
1479 jtag_add_tms();
1480 jtag_execute_queue();
1481
1482 /* examine chain first, as this could discover the real chain layout */
1483 if (jtag_examine_chain() != ERROR_OK)
1484 {
1485 LOG_ERROR("trying to validate configured JTAG chain anyway...");
1486 }
1487
1488 while (jtag_validate_chain() != ERROR_OK)
1489 {
1490 validate_tries++;
1491 if (validate_tries > 5)
1492 {
1493 LOG_ERROR("Could not validate JTAG chain, exit");
1494 return ERROR_JTAG_INVALID_INTERFACE;
1495 }
1496 usleep(10000);
1497 }
1498
1499 return ERROR_OK;
1500 }
1501
1502
1503 static int default_khz(int khz, int *jtag_speed)
1504 {
1505 LOG_ERROR("Translation from khz to jtag_speed not implemented");
1506 return ERROR_FAIL;
1507 }
1508
1509 int handle_interface_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
1510 {
1511 int i;
1512
1513 /* check whether the interface is already configured */
1514 if (jtag_interface)
1515 {
1516 LOG_WARNING("Interface already configured, ignoring");
1517 return ERROR_OK;
1518 }
1519
1520 /* interface name is a mandatory argument */
1521 if (argc < 1 || args[0][0] == '\0')
1522 {
1523 return ERROR_COMMAND_SYNTAX_ERROR;
1524 }
1525
1526 for (i=0; jtag_interfaces[i]; i++)
1527 {
1528 if (strcmp(args[0], jtag_interfaces[i]->name) == 0)
1529 {
1530 if (jtag_interfaces[i]->register_commands(cmd_ctx) != ERROR_OK)
1531 exit(-1);
1532
1533 jtag_interface = jtag_interfaces[i];
1534
1535 if (jtag_interface->khz == NULL)
1536 {
1537 jtag_interface->khz = default_khz;
1538 }
1539 return ERROR_OK;
1540 }
1541 }
1542
1543 /* no valid interface was found (i.e. the configuration option,
1544 * didn't match one of the compiled-in interfaces
1545 */
1546 LOG_ERROR("No valid jtag interface found (%s)", args[0]);
1547 LOG_ERROR("compiled-in jtag interfaces:");
1548 for (i = 0; jtag_interfaces[i]; i++)
1549 {
1550 LOG_ERROR("%i: %s", i, jtag_interfaces[i]->name);
1551 }
1552
1553 return ERROR_JTAG_INVALID_INTERFACE;
1554 }
1555
1556 int handle_jtag_device_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
1557 {
1558 jtag_device_t **last_device_p = &jtag_devices;
1559
1560 if (*last_device_p)
1561 {
1562 while ((*last_device_p)->next)
1563 last_device_p = &((*last_device_p)->next);
1564 last_device_p = &((*last_device_p)->next);
1565 }
1566
1567 if (argc < 3)
1568 return ERROR_OK;
1569
1570 *last_device_p = malloc(sizeof(jtag_device_t));
1571 (*last_device_p)->ir_length = strtoul(args[0], NULL, 0);
1572
1573 (*last_device_p)->expected = malloc((*last_device_p)->ir_length);
1574 buf_set_u32((*last_device_p)->expected, 0, (*last_device_p)->ir_length, strtoul(args[1], NULL, 0));
1575 (*last_device_p)->expected_mask = malloc((*last_device_p)->ir_length);
1576 buf_set_u32((*last_device_p)->expected_mask, 0, (*last_device_p)->ir_length, strtoul(args[2], NULL, 0));
1577
1578 (*last_device_p)->cur_instr = malloc((*last_device_p)->ir_length);
1579 (*last_device_p)->bypass = 1;
1580 buf_set_ones((*last_device_p)->cur_instr, (*last_device_p)->ir_length);
1581
1582 (*last_device_p)->next = NULL;
1583
1584 jtag_register_event_callback(jtag_reset_callback, (*last_device_p));
1585
1586 jtag_num_devices++;
1587
1588 return ERROR_OK;
1589 }
1590
1591 int handle_scan_chain_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
1592 {
1593 jtag_device_t *device = jtag_devices;
1594 int device_count = 0;
1595
1596 while (device)
1597 {
1598 u32 expected, expected_mask, cur_instr;
1599 expected = buf_get_u32(device->expected, 0, device->ir_length);
1600 expected_mask = buf_get_u32(device->expected_mask, 0, device->ir_length);
1601 cur_instr = buf_get_u32(device->cur_instr, 0, device->ir_length);
1602 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);
1603 device = device->next;
1604 device_count++;
1605 }
1606
1607 return ERROR_OK;
1608 }
1609
1610 int handle_reset_config_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
1611 {
1612 if (argc < 1)
1613 return ERROR_COMMAND_SYNTAX_ERROR;
1614
1615 if (argc >= 1)
1616 {
1617 if (strcmp(args[0], "none") == 0)
1618 jtag_reset_config = RESET_NONE;
1619 else if (strcmp(args[0], "trst_only") == 0)
1620 jtag_reset_config = RESET_HAS_TRST;
1621 else if (strcmp(args[0], "srst_only") == 0)
1622 jtag_reset_config = RESET_HAS_SRST;
1623 else if (strcmp(args[0], "trst_and_srst") == 0)
1624 jtag_reset_config = RESET_TRST_AND_SRST;
1625 else
1626 {
1627 LOG_ERROR("invalid reset_config argument, defaulting to none");
1628 jtag_reset_config = RESET_NONE;
1629 return ERROR_INVALID_ARGUMENTS;
1630 }
1631 }
1632
1633 if (argc >= 2)
1634 {
1635 if (strcmp(args[1], "separate") == 0)
1636 {
1637 /* seperate reset lines - default */
1638 } else
1639 {
1640 if (strcmp(args[1], "srst_pulls_trst") == 0)
1641 jtag_reset_config |= RESET_SRST_PULLS_TRST;
1642 else if (strcmp(args[1], "trst_pulls_srst") == 0)
1643 jtag_reset_config |= RESET_TRST_PULLS_SRST;
1644 else if (strcmp(args[1], "combined") == 0)
1645 jtag_reset_config |= RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST;
1646 else
1647 {
1648 LOG_ERROR("invalid reset_config argument, defaulting to none");
1649 jtag_reset_config = RESET_NONE;
1650 return ERROR_INVALID_ARGUMENTS;
1651 }
1652 }
1653 }
1654
1655 if (argc >= 3)
1656 {
1657 if (strcmp(args[2], "trst_open_drain") == 0)
1658 jtag_reset_config |= RESET_TRST_OPEN_DRAIN;
1659 else if (strcmp(args[2], "trst_push_pull") == 0)
1660 jtag_reset_config &= ~RESET_TRST_OPEN_DRAIN;
1661 else
1662 {
1663 LOG_ERROR("invalid reset_config argument, defaulting to none");
1664 jtag_reset_config = RESET_NONE;
1665 return ERROR_INVALID_ARGUMENTS;
1666 }
1667 }
1668
1669 if (argc >= 4)
1670 {
1671 if (strcmp(args[3], "srst_push_pull") == 0)
1672 jtag_reset_config |= RESET_SRST_PUSH_PULL;
1673 else if (strcmp(args[3], "srst_open_drain") == 0)
1674 jtag_reset_config &= ~RESET_SRST_PUSH_PULL;
1675 else
1676 {
1677 LOG_ERROR("invalid reset_config argument, defaulting to none");
1678 jtag_reset_config = RESET_NONE;
1679 return ERROR_INVALID_ARGUMENTS;
1680 }
1681 }
1682
1683 return ERROR_OK;
1684 }
1685
1686 int handle_jtag_nsrst_delay_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
1687 {
1688 if (argc < 1)
1689 {
1690 LOG_ERROR("jtag_nsrst_delay <ms> command takes one required argument");
1691 exit(-1);
1692 }
1693 else
1694 {
1695 jtag_nsrst_delay = strtoul(args[0], NULL, 0);
1696 }
1697
1698 return ERROR_OK;
1699 }
1700
1701 int handle_jtag_ntrst_delay_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
1702 {
1703 if (argc < 1)
1704 {
1705 LOG_ERROR("jtag_ntrst_delay <ms> command takes one required argument");
1706 exit(-1);
1707 }
1708 else
1709 {
1710 jtag_ntrst_delay = strtoul(args[0], NULL, 0);
1711 }
1712
1713 return ERROR_OK;
1714 }
1715
1716 int handle_jtag_speed_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
1717 {
1718 int cur_speed = 0;
1719 if ((argc<1) || (argc>2))
1720 return ERROR_COMMAND_SYNTAX_ERROR;
1721
1722 if (argc >= 1)
1723 cur_speed = jtag_speed = jtag_speed_post_reset = strtoul(args[0], NULL, 0);
1724 if (argc == 2)
1725 cur_speed = jtag_speed_post_reset = strtoul(args[1], NULL, 0);
1726
1727 /* this command can be called during CONFIG,
1728 * in which case jtag isn't initialized */
1729 if (jtag)
1730 jtag->speed(cur_speed);
1731
1732 return ERROR_OK;
1733 }
1734
1735 int handle_jtag_khz_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
1736 {
1737 int cur_speed = 0;
1738 int speed1, speed2;
1739 if ((argc<1) || (argc>2))
1740 return ERROR_COMMAND_SYNTAX_ERROR;
1741
1742 if (jtag == NULL)
1743 {
1744 LOG_ERROR("Interface not selected yet");
1745 return ERROR_COMMAND_SYNTAX_ERROR;
1746 }
1747
1748 if (argc >= 1)
1749 speed1 = strtoul(args[0], NULL, 0);
1750 if (argc == 2)
1751 speed2 = strtoul(args[1], NULL, 0);
1752
1753 if (jtag->khz(speed1, &speed1)!=ERROR_OK)
1754 return ERROR_OK;
1755
1756 if (jtag->khz(speed2, &speed2)!=ERROR_OK)
1757 return ERROR_OK;
1758
1759 if (argc >= 1)
1760 cur_speed = jtag_speed = jtag_speed_post_reset = speed1;
1761
1762 if (argc == 2)
1763 cur_speed = jtag_speed_post_reset = speed2;
1764
1765 jtag->speed(cur_speed);
1766
1767 return ERROR_OK;
1768 }
1769
1770
1771 int handle_endstate_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
1772 {
1773 enum tap_state state;
1774
1775 if (argc < 1)
1776 {
1777 return ERROR_COMMAND_SYNTAX_ERROR;
1778 }
1779 else
1780 {
1781 for (state = 0; state < 16; state++)
1782 {
1783 if (strcmp(args[0], tap_state_strings[state]) == 0)
1784 {
1785 jtag_add_end_state(state);
1786 jtag_execute_queue();
1787 }
1788 }
1789 }
1790 command_print(cmd_ctx, "current endstate: %s", tap_state_strings[end_state]);
1791
1792 return ERROR_OK;
1793 }
1794
1795 int handle_jtag_reset_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
1796 {
1797 int trst = -1;
1798 int srst = -1;
1799
1800 if (argc < 2)
1801 {
1802 return ERROR_COMMAND_SYNTAX_ERROR;
1803 }
1804
1805 if (args[0][0] == '1')
1806 trst = 1;
1807 else if (args[0][0] == '0')
1808 trst = 0;
1809 else
1810 {
1811 return ERROR_COMMAND_SYNTAX_ERROR;
1812 }
1813
1814 if (args[1][0] == '1')
1815 srst = 1;
1816 else if (args[1][0] == '0')
1817 srst = 0;
1818 else
1819 {
1820 return ERROR_COMMAND_SYNTAX_ERROR;
1821 }
1822
1823 if (!jtag && jtag_interface_init(cmd_ctx) != ERROR_OK)
1824 return ERROR_JTAG_INIT_FAILED;
1825
1826 jtag_add_reset(trst, srst);
1827 jtag_execute_queue();
1828
1829 return ERROR_OK;
1830 }
1831
1832 int handle_runtest_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
1833 {
1834 if (argc < 1)
1835 {
1836 return ERROR_COMMAND_SYNTAX_ERROR;
1837 }
1838
1839 jtag_add_runtest(strtol(args[0], NULL, 0), -1);
1840 jtag_execute_queue();
1841
1842 return ERROR_OK;
1843
1844 }
1845
1846
1847 int handle_irscan_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
1848 {
1849 int i;
1850 scan_field_t *fields;
1851
1852 if ((argc < 2) || (argc % 2))
1853 {
1854 return ERROR_COMMAND_SYNTAX_ERROR;
1855 }
1856
1857 fields = malloc(sizeof(scan_field_t) * argc / 2);
1858
1859 for (i = 0; i < argc / 2; i++)
1860 {
1861 int device = strtoul(args[i*2], NULL, 0);
1862 int field_size = jtag_get_device(device)->ir_length;
1863 fields[i].device = device;
1864 fields[i].out_value = malloc(CEIL(field_size, 8));
1865 buf_set_u32(fields[i].out_value, 0, field_size, strtoul(args[i*2+1], NULL, 0));
1866 fields[i].out_mask = NULL;
1867 fields[i].in_value = NULL;
1868 fields[i].in_check_mask = NULL;
1869 fields[i].in_handler = NULL;
1870 fields[i].in_handler_priv = NULL;
1871 }
1872
1873 jtag_add_ir_scan(argc / 2, fields, -1);
1874 jtag_execute_queue();
1875
1876 for (i = 0; i < argc / 2; i++)
1877 free(fields[i].out_value);
1878
1879 free (fields);
1880
1881 return ERROR_OK;
1882 }
1883
1884 int handle_drscan_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
1885 {
1886 scan_field_t *fields;
1887 int num_fields = 0;
1888 int field_count = 0;
1889 var_t *var;
1890 int i, j;
1891
1892 if ((argc < 2) || (argc % 2))
1893 {
1894 return ERROR_COMMAND_SYNTAX_ERROR;
1895 }
1896
1897 for (i = 0; i < argc; i+=2)
1898 {
1899 var = get_var_by_namenum(args[i+1]);
1900 if (var)
1901 {
1902 num_fields += var->num_fields;
1903 }
1904 else
1905 {
1906 command_print(cmd_ctx, "variable %s doesn't exist", args[i+1]);
1907 return ERROR_OK;
1908 }
1909 }
1910
1911 fields = malloc(sizeof(scan_field_t) * num_fields);
1912
1913 for (i = 0; i < argc; i+=2)
1914 {
1915 var = get_var_by_namenum(args[i+1]);
1916
1917 for (j = 0; j < var->num_fields; j++)
1918 {
1919 fields[field_count].device = strtol(args[i], NULL, 0);
1920 fields[field_count].num_bits = var->fields[j].num_bits;
1921 fields[field_count].out_value = malloc(CEIL(var->fields[j].num_bits, 8));
1922 buf_set_u32(fields[field_count].out_value, 0, var->fields[j].num_bits, var->fields[j].value);
1923 fields[field_count].out_mask = NULL;
1924 fields[field_count].in_value = fields[field_count].out_value;
1925 fields[field_count].in_check_mask = NULL;
1926 fields[field_count].in_check_value = NULL;
1927 fields[field_count].in_handler = field_le_to_host;
1928 fields[field_count++].in_handler_priv = &(var->fields[j]);
1929 }
1930 }
1931
1932 jtag_add_dr_scan(num_fields, fields, -1);
1933 jtag_execute_queue();
1934
1935 for (i = 0; i < argc / 2; i++)
1936 free(fields[i].out_value);
1937
1938 free(fields);
1939
1940 return ERROR_OK;
1941 }
1942
1943 int handle_verify_ircapture_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
1944 {
1945 if (argc == 1)
1946 {
1947 if (strcmp(args[0], "enable") == 0)
1948 {
1949 jtag_verify_capture_ir = 1;
1950 }
1951 else if (strcmp(args[0], "disable") == 0)
1952 {
1953 jtag_verify_capture_ir = 0;
1954 } else
1955 {
1956 return ERROR_COMMAND_SYNTAX_ERROR;
1957 }
1958 } else if (argc != 0)
1959 {
1960 return ERROR_COMMAND_SYNTAX_ERROR;
1961 }
1962
1963 command_print(cmd_ctx, "verify Capture-IR is %s", (jtag_verify_capture_ir) ? "enabled": "disabled");
1964
1965 return ERROR_OK;
1966 }

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)