Simplify jtag_add_pathmove:
[openocd.git] / src / jtag / jtag.c
1 /***************************************************************************
2 * Copyright (C) 2005 by Dominic Rath *
3 * Dominic.Rath@gmx.de *
4 * *
5 * Copyright (C) 2007,2008 Øyvind Harboe *
6 * oyvind.harboe@zylin.com *
7 * *
8 * Copyright (C) 2009 SoftPLC Corporation *
9 * http://softplc.com *
10 * dick@softplc.com *
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 * This program is distributed in the hope that it will be useful, *
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20 * GNU General Public License for more details. *
21 * *
22 * You should have received a copy of the GNU General Public License *
23 * along with this program; if not, write to the *
24 * Free Software Foundation, Inc., *
25 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
26 ***************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include "jtag.h"
32 #include "minidriver.h"
33 #include "interface.h"
34
35 #ifdef HAVE_STRINGS_H
36 #include <strings.h>
37 #endif
38
39
40 /// The number of JTAG queue flushes (for profiling and debugging purposes).
41 static int jtag_flush_queue_count;
42
43 static void jtag_add_scan_check(void (*jtag_add_scan)(int in_num_fields, const scan_field_t *in_fields, tap_state_t state),
44 int in_num_fields, scan_field_t *in_fields, tap_state_t state);
45
46 /* note that this is not marked as static as it must be available from outside jtag.c for those
47 that implement the jtag_xxx() minidriver layer
48 */
49 int jtag_error=ERROR_OK;
50
51 char* jtag_event_strings[] =
52 {
53 "JTAG controller reset (RESET or TRST)"
54 };
55
56 const Jim_Nvp nvp_jtag_tap_event[] = {
57 { .value = JTAG_TAP_EVENT_ENABLE, .name = "tap-enable" },
58 { .value = JTAG_TAP_EVENT_DISABLE, .name = "tap-disable" },
59
60 { .name = NULL, .value = -1 }
61 };
62
63 int jtag_trst = 0;
64 int jtag_srst = 0;
65
66 /**
67 * List all TAPs that have been created.
68 */
69 static jtag_tap_t *__jtag_all_taps = NULL;
70 /**
71 * The number of TAPs in the __jtag_all_taps list, used to track the
72 * assigned chain position to new TAPs
73 */
74 static int jtag_num_taps = 0;
75
76 enum reset_types jtag_reset_config = RESET_NONE;
77 tap_state_t cmd_queue_end_state = TAP_RESET;
78 tap_state_t cmd_queue_cur_state = TAP_RESET;
79
80 int jtag_verify_capture_ir = 1;
81 int jtag_verify = 1;
82
83 /* how long the OpenOCD should wait before attempting JTAG communication after reset lines deasserted (in ms) */
84 static int jtag_nsrst_delay = 0; /* default to no nSRST delay */
85 static int jtag_ntrst_delay = 0; /* default to no nTRST delay */
86
87 /* callbacks to inform high-level handlers about JTAG state changes */
88 jtag_event_callback_t *jtag_event_callbacks;
89
90 /* speed in kHz*/
91 static int speed_khz = 0;
92 /* flag if the kHz speed was defined */
93 static bool hasKHz = false;
94
95 /* jtag interfaces (parport, FTDI-USB, TI-USB, ...)
96 */
97
98 #if BUILD_ECOSBOARD == 1
99 extern jtag_interface_t zy1000_interface;
100 #elif defined(BUILD_MINIDRIVER_DUMMY)
101 extern jtag_interface_t minidummy_interface;
102 #else // standard drivers
103 #if BUILD_PARPORT == 1
104 extern jtag_interface_t parport_interface;
105 #endif
106
107 #if BUILD_DUMMY == 1
108 extern jtag_interface_t dummy_interface;
109 #endif
110
111 #if BUILD_FT2232_FTD2XX == 1
112 extern jtag_interface_t ft2232_interface;
113 #endif
114
115 #if BUILD_FT2232_LIBFTDI == 1
116 extern jtag_interface_t ft2232_interface;
117 #endif
118
119 #if BUILD_AMTJTAGACCEL == 1
120 extern jtag_interface_t amt_jtagaccel_interface;
121 #endif
122
123 #if BUILD_EP93XX == 1
124 extern jtag_interface_t ep93xx_interface;
125 #endif
126
127 #if BUILD_AT91RM9200 == 1
128 extern jtag_interface_t at91rm9200_interface;
129 #endif
130
131 #if BUILD_GW16012 == 1
132 extern jtag_interface_t gw16012_interface;
133 #endif
134
135 #if BUILD_PRESTO_LIBFTDI == 1 || BUILD_PRESTO_FTD2XX == 1
136 extern jtag_interface_t presto_interface;
137 #endif
138
139 #if BUILD_USBPROG == 1
140 extern jtag_interface_t usbprog_interface;
141 #endif
142
143 #if BUILD_JLINK == 1
144 extern jtag_interface_t jlink_interface;
145 #endif
146
147 #if BUILD_VSLLINK == 1
148 extern jtag_interface_t vsllink_interface;
149 #endif
150
151 #if BUILD_RLINK == 1
152 extern jtag_interface_t rlink_interface;
153 #endif
154
155 #if BUILD_ARMJTAGEW == 1
156 extern jtag_interface_t armjtagew_interface;
157 #endif
158 #endif // standard drivers
159
160 /**
161 * The list of built-in JTAG interfaces, containing entries for those
162 * drivers that were enabled by the @c configure script.
163 *
164 * The list should be defined to contain either one minidriver interface
165 * or some number of standard driver interfaces, never both.
166 */
167 jtag_interface_t *jtag_interfaces[] = {
168 #if BUILD_ECOSBOARD == 1
169 &zy1000_interface,
170 #elif defined(BUILD_MINIDRIVER_DUMMY)
171 &minidummy_interface,
172 #else // standard drivers
173 #if BUILD_PARPORT == 1
174 &parport_interface,
175 #endif
176 #if BUILD_DUMMY == 1
177 &dummy_interface,
178 #endif
179 #if BUILD_FT2232_FTD2XX == 1
180 &ft2232_interface,
181 #endif
182 #if BUILD_FT2232_LIBFTDI == 1
183 &ft2232_interface,
184 #endif
185 #if BUILD_AMTJTAGACCEL == 1
186 &amt_jtagaccel_interface,
187 #endif
188 #if BUILD_EP93XX == 1
189 &ep93xx_interface,
190 #endif
191 #if BUILD_AT91RM9200 == 1
192 &at91rm9200_interface,
193 #endif
194 #if BUILD_GW16012 == 1
195 &gw16012_interface,
196 #endif
197 #if BUILD_PRESTO_LIBFTDI == 1 || BUILD_PRESTO_FTD2XX == 1
198 &presto_interface,
199 #endif
200 #if BUILD_USBPROG == 1
201 &usbprog_interface,
202 #endif
203 #if BUILD_JLINK == 1
204 &jlink_interface,
205 #endif
206 #if BUILD_VSLLINK == 1
207 &vsllink_interface,
208 #endif
209 #if BUILD_RLINK == 1
210 &rlink_interface,
211 #endif
212 #if BUILD_ARMJTAGEW == 1
213 &armjtagew_interface,
214 #endif
215 #endif // standard drivers
216 NULL,
217 };
218
219 struct jtag_interface_s *jtag = NULL;
220
221 /* configuration */
222 static jtag_interface_t *jtag_interface = NULL;
223 int jtag_speed = 0;
224
225 /* jtag commands */
226 static int handle_interface_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
227 static int handle_jtag_speed_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
228 static int handle_jtag_khz_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
229 static int handle_jtag_device_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
230 static int handle_reset_config_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
231 static int handle_jtag_nsrst_delay_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
232 static int handle_jtag_ntrst_delay_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
233
234 static int handle_scan_chain_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
235
236 static int handle_jtag_reset_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
237 static int handle_runtest_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
238 static int handle_irscan_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
239 static int Jim_Command_drscan(Jim_Interp *interp, int argc, Jim_Obj *const *argv);
240 static int Jim_Command_flush_count(Jim_Interp *interp, int argc, Jim_Obj *const *args);
241
242 static int handle_verify_ircapture_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
243 static int handle_verify_jtag_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
244 static int handle_tms_sequence_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
245
246 jtag_tap_t *jtag_all_taps(void)
247 {
248 return __jtag_all_taps;
249 };
250
251 int jtag_tap_count(void)
252 {
253 return jtag_num_taps;
254 }
255
256 unsigned jtag_tap_count_enabled(void)
257 {
258 jtag_tap_t *t;
259 unsigned n;
260
261 n = 0;
262 t = jtag_all_taps();
263 while(t){
264 if( t->enabled ){
265 n++;
266 }
267 t = t->next_tap;
268 }
269 return n;
270 }
271
272 /// Append a new TAP to the chain of all taps.
273 static void jtag_tap_add(struct jtag_tap_s *t)
274 {
275 t->abs_chain_position = jtag_num_taps++;
276
277 jtag_tap_t **tap = &__jtag_all_taps;
278 while(*tap != NULL)
279 tap = &(*tap)->next_tap;
280 *tap = t;
281 }
282
283 jtag_tap_t *jtag_tap_by_string( const char *s )
284 {
285 jtag_tap_t *t;
286 char *cp;
287
288 t = jtag_all_taps();
289 /* try name first */
290 while(t){
291 if( 0 == strcmp( t->dotted_name, s ) ){
292 break;
293 } else {
294 t = t->next_tap;
295 }
296 }
297 /* backup plan is by number */
298 if( t == NULL ){
299 /* ok - is "s" a number? */
300 int n;
301 n = strtol( s, &cp, 0 );
302 if( (s != cp) && (*cp == 0) ){
303 /* Then it is... */
304 t = jtag_tap_by_abs_position(n);
305 }
306 }
307 return t;
308 }
309
310 jtag_tap_t * jtag_tap_by_jim_obj( Jim_Interp *interp, Jim_Obj *o )
311 {
312 jtag_tap_t *t;
313 const char *cp;
314
315 cp = Jim_GetString( o, NULL );
316 if(cp == NULL){
317 cp = "(unknown)";
318 t = NULL;
319 } else {
320 t = jtag_tap_by_string( cp );
321 }
322 if( t == NULL ){
323 Jim_SetResult_sprintf(interp,"Tap: %s is unknown", cp );
324 }
325 return t;
326 }
327
328 /* returns a pointer to the n-th device in the scan chain */
329 jtag_tap_t * jtag_tap_by_abs_position( int n )
330 {
331 int orig_n;
332 jtag_tap_t *t;
333
334 orig_n = n;
335 t = jtag_all_taps();
336
337 while( t && (n > 0)) {
338 n--;
339 t = t->next_tap;
340 }
341 return t;
342 }
343
344 const char *jtag_tap_name(const jtag_tap_t *tap)
345 {
346 return (tap == NULL) ? "(unknown)" : tap->dotted_name;
347 }
348
349
350 int jtag_register_event_callback(int (*callback)(enum jtag_event event, void *priv), void *priv)
351 {
352 jtag_event_callback_t **callbacks_p = &jtag_event_callbacks;
353
354 if (callback == NULL)
355 {
356 return ERROR_INVALID_ARGUMENTS;
357 }
358
359 if (*callbacks_p)
360 {
361 while ((*callbacks_p)->next)
362 callbacks_p = &((*callbacks_p)->next);
363 callbacks_p = &((*callbacks_p)->next);
364 }
365
366 (*callbacks_p) = malloc(sizeof(jtag_event_callback_t));
367 (*callbacks_p)->callback = callback;
368 (*callbacks_p)->priv = priv;
369 (*callbacks_p)->next = NULL;
370
371 return ERROR_OK;
372 }
373
374 int jtag_unregister_event_callback(int (*callback)(enum jtag_event event, void *priv))
375 {
376 jtag_event_callback_t **callbacks_p = &jtag_event_callbacks;
377
378 if (callback == NULL)
379 {
380 return ERROR_INVALID_ARGUMENTS;
381 }
382
383 while (*callbacks_p)
384 {
385 jtag_event_callback_t **next = &((*callbacks_p)->next);
386 if ((*callbacks_p)->callback == callback)
387 {
388 free(*callbacks_p);
389 *callbacks_p = *next;
390 }
391 callbacks_p = next;
392 }
393
394 return ERROR_OK;
395 }
396
397 int jtag_call_event_callbacks(enum jtag_event event)
398 {
399 jtag_event_callback_t *callback = jtag_event_callbacks;
400
401 LOG_DEBUG("jtag event: %s", jtag_event_strings[event]);
402
403 while (callback)
404 {
405 callback->callback(event, callback->priv);
406 callback = callback->next;
407 }
408
409 return ERROR_OK;
410 }
411
412 static void jtag_checks(void)
413 {
414 assert(jtag_trst == 0);
415 }
416
417 static void jtag_prelude(tap_state_t state)
418 {
419 jtag_checks();
420
421 assert(state!=TAP_INVALID);
422
423 cmd_queue_cur_state = state;
424 }
425
426 void jtag_alloc_in_value32(scan_field_t *field)
427 {
428 interface_jtag_alloc_in_value32(field);
429 }
430
431 void jtag_add_ir_scan_noverify(int in_count, const scan_field_t *in_fields,
432 tap_state_t state)
433 {
434 jtag_prelude(state);
435
436 int retval = interface_jtag_add_ir_scan(in_count, in_fields, state);
437 jtag_set_error(retval);
438 }
439
440
441 /**
442 * Generate an IR SCAN with a list of scan fields with one entry for each enabled TAP.
443 *
444 * If the input field list contains an instruction value for a TAP then that is used
445 * otherwise the TAP is set to bypass.
446 *
447 * TAPs for which no fields are passed are marked as bypassed for subsequent DR SCANs.
448 *
449 */
450 void jtag_add_ir_scan(int in_num_fields, scan_field_t *in_fields, tap_state_t state)
451 {
452 if (jtag_verify&&jtag_verify_capture_ir)
453 {
454 /* 8 x 32 bit id's is enough for all invocations */
455
456 for (int j = 0; j < in_num_fields; j++)
457 {
458 /* if we are to run a verification of the ir scan, we need to get the input back.
459 * We may have to allocate space if the caller didn't ask for the input back.
460 */
461 in_fields[j].check_value=in_fields[j].tap->expected;
462 in_fields[j].check_mask=in_fields[j].tap->expected_mask;
463 }
464 jtag_add_scan_check(jtag_add_ir_scan_noverify, in_num_fields, in_fields, state);
465 } else
466 {
467 jtag_add_ir_scan_noverify(in_num_fields, in_fields, state);
468 }
469 }
470
471 /**
472 * Duplicate the scan fields passed into the function into an IR SCAN command
473 *
474 * This function assumes that the caller handles extra fields for bypassed TAPs
475 *
476 */
477 void jtag_add_plain_ir_scan(int in_num_fields, const scan_field_t *in_fields,
478 tap_state_t state)
479 {
480 jtag_prelude(state);
481
482 int retval = interface_jtag_add_plain_ir_scan(
483 in_num_fields, in_fields, state);
484 jtag_set_error(retval);
485 }
486
487 void jtag_add_callback(jtag_callback1_t f, u8 *in)
488 {
489 interface_jtag_add_callback(f, in);
490 }
491
492 void jtag_add_callback4(jtag_callback_t f, u8 *in,
493 jtag_callback_data_t data1, jtag_callback_data_t data2,
494 jtag_callback_data_t data3)
495 {
496 interface_jtag_add_callback4(f, in, data1, data2, data3);
497 }
498
499 int jtag_check_value_inner(u8 *captured, u8 *in_check_value, u8 *in_check_mask, int num_bits);
500
501 static int jtag_check_value_mask_callback(u8 *in, jtag_callback_data_t data1, jtag_callback_data_t data2, jtag_callback_data_t data3)
502 {
503 return jtag_check_value_inner(in, (u8 *)data1, (u8 *)data2, (int)data3);
504 }
505
506 static void jtag_add_scan_check(void (*jtag_add_scan)(int in_num_fields, const scan_field_t *in_fields, tap_state_t state),
507 int in_num_fields, scan_field_t *in_fields, tap_state_t state)
508 {
509 for (int i = 0; i < in_num_fields; i++)
510 {
511 struct scan_field_s *field = &in_fields[i];
512 field->allocated = 0;
513 field->modified = 0;
514 if (field->check_value || field->in_value)
515 continue;
516 interface_jtag_add_scan_check_alloc(field);
517 field->modified = 1;
518 }
519
520 jtag_add_scan(in_num_fields, in_fields, state);
521
522 for (int i = 0; i < in_num_fields; i++)
523 {
524 if ((in_fields[i].check_value != NULL) && (in_fields[i].in_value != NULL))
525 {
526 /* this is synchronous for a minidriver */
527 jtag_add_callback4(jtag_check_value_mask_callback, in_fields[i].in_value,
528 (jtag_callback_data_t)in_fields[i].check_value,
529 (jtag_callback_data_t)in_fields[i].check_mask,
530 (jtag_callback_data_t)in_fields[i].num_bits);
531 }
532 if (in_fields[i].allocated)
533 {
534 free(in_fields[i].in_value);
535 }
536 if (in_fields[i].modified)
537 {
538 in_fields[i].in_value = NULL;
539 }
540 }
541 }
542
543 void jtag_add_dr_scan_check(int in_num_fields, scan_field_t *in_fields, tap_state_t state)
544 {
545 if (jtag_verify)
546 {
547 jtag_add_scan_check(jtag_add_dr_scan, in_num_fields, in_fields, state);
548 } else
549 {
550 jtag_add_dr_scan(in_num_fields, in_fields, state);
551 }
552 }
553
554
555 /**
556 * Generate a DR SCAN using the fields passed to the function.
557 * For connected TAPs, the function checks in_fields and uses fields
558 * specified there. For bypassed TAPs, the function generates a dummy
559 * 1-bit field. The bypass status of TAPs is set by jtag_add_ir_scan().
560 */
561 void jtag_add_dr_scan(int in_num_fields, const scan_field_t *in_fields,
562 tap_state_t state)
563 {
564 jtag_prelude(state);
565
566 int retval;
567 retval = interface_jtag_add_dr_scan(in_num_fields, in_fields, state);
568 jtag_set_error(retval);
569 }
570
571 /**
572 * Duplicate the scan fields passed into the function into a DR SCAN
573 * command. Unlike jtag_add_dr_scan(), this function assumes that the
574 * caller handles extra fields for bypassed TAPs.
575 */
576 void jtag_add_plain_dr_scan(int in_num_fields, const scan_field_t *in_fields,
577 tap_state_t state)
578 {
579 jtag_prelude(state);
580
581 int retval;
582 retval = interface_jtag_add_plain_dr_scan(in_num_fields, in_fields, state);
583 jtag_set_error(retval);
584 }
585
586 void jtag_add_dr_out(jtag_tap_t* tap,
587 int num_fields, const int* num_bits, const u32* value,
588 tap_state_t end_state)
589 {
590 assert(end_state != TAP_INVALID);
591
592 cmd_queue_cur_state = end_state;
593
594 interface_jtag_add_dr_out(tap,
595 num_fields, num_bits, value,
596 end_state);
597 }
598
599 void jtag_add_tlr(void)
600 {
601 jtag_prelude(TAP_RESET);
602 jtag_set_error(interface_jtag_add_tlr());
603 jtag_call_event_callbacks(JTAG_TRST_ASSERTED);
604 }
605
606 void jtag_add_pathmove(int num_states, const tap_state_t *path)
607 {
608 tap_state_t cur_state = cmd_queue_cur_state;
609
610 /* the last state has to be a stable state */
611 if (!tap_is_state_stable(path[num_states - 1]))
612 {
613 LOG_ERROR("BUG: TAP path doesn't finish in a stable state");
614 exit(-1);
615 }
616
617 for (int i = 0; i < num_states; i++)
618 {
619 if (path[i] == TAP_RESET)
620 {
621 LOG_ERROR("BUG: TAP_RESET is not a valid state for pathmove sequences");
622 exit(-1);
623 }
624
625 if ( tap_state_transition(cur_state, true) != path[i]
626 && tap_state_transition(cur_state, false) != path[i])
627 {
628 LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition",
629 tap_state_name(cur_state), tap_state_name(path[i]));
630 exit(-1);
631 }
632 cur_state = path[i];
633 }
634
635 jtag_checks();
636
637 jtag_set_error(interface_jtag_add_pathmove(num_states, path));
638 cmd_queue_cur_state = path[num_states - 1];
639 }
640
641 void jtag_add_runtest(int num_cycles, tap_state_t state)
642 {
643 int retval;
644
645 jtag_prelude(state);
646
647 /* executed by sw or hw fifo */
648 retval=interface_jtag_add_runtest(num_cycles, state);
649 if (retval!=ERROR_OK)
650 jtag_error=retval;
651 }
652
653
654 void jtag_add_clocks( int num_cycles )
655 {
656 int retval;
657
658 if( !tap_is_state_stable(cmd_queue_cur_state) )
659 {
660 LOG_ERROR( "jtag_add_clocks() was called with TAP in non-stable state \"%s\"",
661 tap_state_name(cmd_queue_cur_state) );
662 jtag_error = ERROR_JTAG_NOT_STABLE_STATE;
663 return;
664 }
665
666 if( num_cycles > 0 )
667 {
668 jtag_checks();
669
670 retval = interface_jtag_add_clocks(num_cycles);
671 if (retval != ERROR_OK)
672 jtag_error=retval;
673 }
674 }
675
676 void jtag_add_reset(int req_tlr_or_trst, int req_srst)
677 {
678 int trst_with_tlr = 0;
679 int retval;
680
681 /* FIX!!! there are *many* different cases here. A better
682 * approach is needed for legal combinations of transitions...
683 */
684 if ((jtag_reset_config & RESET_HAS_SRST)&&
685 (jtag_reset_config & RESET_HAS_TRST)&&
686 ((jtag_reset_config & RESET_SRST_PULLS_TRST)==0))
687 {
688 if (((req_tlr_or_trst&&!jtag_trst)||
689 (!req_tlr_or_trst&&jtag_trst))&&
690 ((req_srst&&!jtag_srst)||
691 (!req_srst&&jtag_srst)))
692 {
693 /* FIX!!! srst_pulls_trst allows 1,1 => 0,0 transition.... */
694 //LOG_ERROR("BUG: transition of req_tlr_or_trst and req_srst in the same jtag_add_reset() call is undefined");
695 }
696 }
697
698 /* Make sure that jtag_reset_config allows the requested reset */
699 /* if SRST pulls TRST, we can't fulfill srst == 1 with trst == 0 */
700 if (((jtag_reset_config & RESET_SRST_PULLS_TRST) && (req_srst == 1)) && (!req_tlr_or_trst))
701 {
702 LOG_ERROR("BUG: requested reset would assert trst");
703 jtag_error=ERROR_FAIL;
704 return;
705 }
706
707 /* if TRST pulls SRST, we reset with TAP T-L-R */
708 if (((jtag_reset_config & RESET_TRST_PULLS_SRST) && (req_tlr_or_trst)) && (req_srst == 0))
709 {
710 trst_with_tlr = 1;
711 }
712
713 if (req_srst && !(jtag_reset_config & RESET_HAS_SRST))
714 {
715 LOG_ERROR("BUG: requested SRST assertion, but the current configuration doesn't support this");
716 jtag_error=ERROR_FAIL;
717 return;
718 }
719
720 if (req_tlr_or_trst)
721 {
722 if (!trst_with_tlr && (jtag_reset_config & RESET_HAS_TRST))
723 {
724 jtag_trst = 1;
725 } else
726 {
727 trst_with_tlr = 1;
728 }
729 } else
730 {
731 jtag_trst = 0;
732 }
733
734 jtag_srst = req_srst;
735
736 retval = interface_jtag_add_reset(jtag_trst, jtag_srst);
737 if (retval!=ERROR_OK)
738 {
739 jtag_error=retval;
740 return;
741 }
742 jtag_execute_queue();
743
744 if (jtag_srst)
745 {
746 LOG_DEBUG("SRST line asserted");
747 }
748 else
749 {
750 LOG_DEBUG("SRST line released");
751 if (jtag_nsrst_delay)
752 jtag_add_sleep(jtag_nsrst_delay * 1000);
753 }
754
755 if (trst_with_tlr)
756 {
757 LOG_DEBUG("JTAG reset with RESET instead of TRST");
758 jtag_set_end_state(TAP_RESET);
759 jtag_add_tlr();
760 return;
761 }
762
763 if (jtag_trst)
764 {
765 /* we just asserted nTRST, so we're now in Test-Logic-Reset,
766 * and inform possible listeners about this
767 */
768 LOG_DEBUG("TRST line asserted");
769 tap_set_state(TAP_RESET);
770 jtag_call_event_callbacks(JTAG_TRST_ASSERTED);
771 }
772 else
773 {
774 if (jtag_ntrst_delay)
775 jtag_add_sleep(jtag_ntrst_delay * 1000);
776 }
777 }
778
779 tap_state_t jtag_set_end_state(tap_state_t state)
780 {
781 if ((state == TAP_DRSHIFT)||(state == TAP_IRSHIFT))
782 {
783 LOG_ERROR("BUG: TAP_DRSHIFT/IRSHIFT can't be end state. Calling code should use a larger scan field");
784 }
785
786 if (state!=TAP_INVALID)
787 cmd_queue_end_state = state;
788 return cmd_queue_end_state;
789 }
790
791 tap_state_t jtag_get_end_state(void)
792 {
793 return cmd_queue_end_state;
794 }
795
796 void jtag_add_sleep(u32 us)
797 {
798 keep_alive(); /* we might be running on a very slow JTAG clk */
799 int retval=interface_jtag_add_sleep(us);
800 if (retval!=ERROR_OK)
801 jtag_error=retval;
802 return;
803 }
804
805 int jtag_check_value_inner(u8 *captured, u8 *in_check_value, u8 *in_check_mask, int num_bits)
806 {
807 int retval = ERROR_OK;
808
809 int compare_failed = 0;
810
811 if (in_check_mask)
812 compare_failed = buf_cmp_mask(captured, in_check_value, in_check_mask, num_bits);
813 else
814 compare_failed = buf_cmp(captured, in_check_value, num_bits);
815
816 if (compare_failed){
817 /* An error handler could have caught the failing check
818 * only report a problem when there wasn't a handler, or if the handler
819 * acknowledged the error
820 */
821 /*
822 LOG_WARNING("TAP %s:",
823 jtag_tap_name(field->tap));
824 */
825 if (compare_failed)
826 {
827 char *captured_char = buf_to_str(captured, (num_bits > DEBUG_JTAG_IOZ) ? DEBUG_JTAG_IOZ : num_bits, 16);
828 char *in_check_value_char = buf_to_str(in_check_value, (num_bits > DEBUG_JTAG_IOZ) ? DEBUG_JTAG_IOZ : num_bits, 16);
829
830 if (in_check_mask)
831 {
832 char *in_check_mask_char;
833 in_check_mask_char = buf_to_str(in_check_mask, (num_bits > DEBUG_JTAG_IOZ) ? DEBUG_JTAG_IOZ : num_bits, 16);
834 LOG_WARNING("value captured during scan didn't pass the requested check:");
835 LOG_WARNING("captured: 0x%s check_value: 0x%s check_mask: 0x%s",
836 captured_char, in_check_value_char, in_check_mask_char);
837 free(in_check_mask_char);
838 }
839 else
840 {
841 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);
842 }
843
844 free(captured_char);
845 free(in_check_value_char);
846
847 retval = ERROR_JTAG_QUEUE_FAILED;
848 }
849
850 }
851 return retval;
852 }
853
854 void jtag_check_value_mask(scan_field_t *field, u8 *value, u8 *mask)
855 {
856 assert(field->in_value != NULL);
857
858 if (value==NULL)
859 {
860 /* no checking to do */
861 return;
862 }
863
864 jtag_execute_queue_noclear();
865
866 int retval=jtag_check_value_inner(field->in_value, value, mask, field->num_bits);
867 jtag_set_error(retval);
868 }
869
870
871
872 int default_interface_jtag_execute_queue(void)
873 {
874 if (NULL == jtag)
875 {
876 LOG_ERROR("No JTAG interface configured yet. "
877 "Issue 'init' command in startup scripts "
878 "before communicating with targets.");
879 return ERROR_FAIL;
880 }
881
882 return jtag->execute_queue();
883 }
884
885 void jtag_execute_queue_noclear(void)
886 {
887 jtag_flush_queue_count++;
888 jtag_set_error(interface_jtag_execute_queue());
889 }
890
891 int jtag_get_flush_queue_count(void)
892 {
893 return jtag_flush_queue_count;
894 }
895
896 int jtag_execute_queue(void)
897 {
898 jtag_execute_queue_noclear();
899 return jtag_error_clear();
900 }
901
902 static int jtag_reset_callback(enum jtag_event event, void *priv)
903 {
904 jtag_tap_t *tap = priv;
905
906 LOG_DEBUG("-");
907
908 if (event == JTAG_TRST_ASSERTED)
909 {
910 buf_set_ones(tap->cur_instr, tap->ir_length);
911 tap->bypass = 1;
912 }
913
914 return ERROR_OK;
915 }
916
917 void jtag_sleep(u32 us)
918 {
919 alive_sleep(us/1000);
920 }
921
922 /// maximum number of JTAG devices expected in the chain
923 #define JTAG_MAX_CHAIN_SIZE 20
924
925 #define EXTRACT_MFG(X) (((X) & 0xffe) >> 1)
926 #define EXTRACT_PART(X) (((X) & 0xffff000) >> 12)
927 #define EXTRACT_VER(X) (((X) & 0xf0000000) >> 28)
928
929 static int jtag_examine_chain_execute(u8 *idcode_buffer, unsigned num_idcode)
930 {
931 scan_field_t field = {
932 .tap = NULL,
933 .num_bits = num_idcode * 32,
934 .out_value = idcode_buffer,
935 .in_value = idcode_buffer,
936 };
937
938 // initialize to the end of chain ID value
939 for (unsigned i = 0; i < JTAG_MAX_CHAIN_SIZE; i++)
940 buf_set_u32(idcode_buffer, i * 32, 32, 0x000000FF);
941
942 jtag_add_plain_dr_scan(1, &field, TAP_RESET);
943 return jtag_execute_queue();
944 }
945
946 static bool jtag_examine_chain_check(u8 *idcodes, unsigned count)
947 {
948 u8 zero_check = 0x0;
949 u8 one_check = 0xff;
950
951 for (unsigned i = 0; i < count * 4; i++)
952 {
953 zero_check |= idcodes[i];
954 one_check &= idcodes[i];
955 }
956
957 /* if there wasn't a single non-zero bit or if all bits were one,
958 * the scan is not valid */
959 if (zero_check == 0x00 || one_check == 0xff)
960 {
961 LOG_ERROR("JTAG communication failure: check connection, "
962 "JTAG interface, target power etc.");
963 return false;
964 }
965 return true;
966 }
967
968 static void jtag_examine_chain_display(enum log_levels level, const char *msg,
969 const char *name, u32 idcode)
970 {
971 log_printf_lf(level, __FILE__, __LINE__, __FUNCTION__,
972 "JTAG tap: %s %16.16s: 0x%08x "
973 "(mfg: 0x%3.3x, part: 0x%4.4x, ver: 0x%1.1x)",
974 name, msg, idcode,
975 EXTRACT_MFG(idcode), EXTRACT_PART(idcode), EXTRACT_VER(idcode) );
976 }
977
978 static bool jtag_idcode_is_final(u32 idcode)
979 {
980 return idcode == 0x000000FF || idcode == 0xFFFFFFFF;
981 }
982
983 /**
984 * This helper checks that remaining bits in the examined chain data are
985 * all as expected, but a single JTAG device requires only 64 bits to be
986 * read back correctly. This can help identify and diagnose problems
987 * with the JTAG chain earlier, gives more helpful/explicit error messages.
988 */
989 static void jtag_examine_chain_end(u8 *idcodes, unsigned count, unsigned max)
990 {
991 bool triggered = false;
992 for ( ; count < max - 31; count += 32)
993 {
994 u32 idcode = buf_get_u32(idcodes, count, 32);
995 // do not trigger the warning if the data looks good
996 if (!triggered && jtag_idcode_is_final(idcode))
997 continue;
998 LOG_WARNING("Unexpected idcode after end of chain: %d 0x%08x",
999 count, idcode);
1000 triggered = true;
1001 }
1002 }
1003
1004 static bool jtag_examine_chain_match_tap(const struct jtag_tap_s *tap)
1005 {
1006 if (0 == tap->expected_ids_cnt)
1007 {
1008 /// @todo Enable LOG_INFO to ask for reports about unknown TAP IDs.
1009 #if 0
1010 LOG_INFO("Uknown JTAG TAP ID: 0x%08x", tap->idcode)
1011 LOG_INFO("Please report the chip name and reported ID code to the openocd project");
1012 #endif
1013 return true;
1014 }
1015
1016 /* Loop over the expected identification codes and test for a match */
1017 u8 ii;
1018 for (ii = 0; ii < tap->expected_ids_cnt; ii++)
1019 {
1020 if (tap->idcode == tap->expected_ids[ii])
1021 break;
1022 }
1023
1024 /* If none of the expected ids matched, log an error */
1025 if (ii != tap->expected_ids_cnt)
1026 {
1027 LOG_INFO("JTAG Tap/device matched");
1028 return true;
1029 }
1030 jtag_examine_chain_display(LOG_LVL_ERROR, "got",
1031 tap->dotted_name, tap->idcode);
1032 for (ii = 0; ii < tap->expected_ids_cnt; ii++)
1033 {
1034 char msg[32];
1035 snprintf(msg, sizeof(msg), "expected %hhu of %hhu",
1036 ii + 1, tap->expected_ids_cnt);
1037 jtag_examine_chain_display(LOG_LVL_ERROR, msg,
1038 tap->dotted_name, tap->expected_ids[ii]);
1039 }
1040 return false;
1041 }
1042
1043 /* Try to examine chain layout according to IEEE 1149.1 §12
1044 */
1045 static int jtag_examine_chain(void)
1046 {
1047 u8 idcode_buffer[JTAG_MAX_CHAIN_SIZE * 4];
1048 unsigned device_count = 0;
1049
1050 jtag_examine_chain_execute(idcode_buffer, JTAG_MAX_CHAIN_SIZE);
1051
1052 if (!jtag_examine_chain_check(idcode_buffer, JTAG_MAX_CHAIN_SIZE))
1053 return ERROR_JTAG_INIT_FAILED;
1054
1055 /* point at the 1st tap */
1056 jtag_tap_t *tap = jtag_tap_next_enabled(NULL);
1057 if (tap == NULL)
1058 {
1059 LOG_ERROR("JTAG: No taps enabled?");
1060 return ERROR_JTAG_INIT_FAILED;
1061 }
1062
1063 for (unsigned bit_count = 0; bit_count < (JTAG_MAX_CHAIN_SIZE * 32) - 31;)
1064 {
1065 u32 idcode = buf_get_u32(idcode_buffer, bit_count, 32);
1066 if ((idcode & 1) == 0)
1067 {
1068 /* LSB must not be 0, this indicates a device in bypass */
1069 LOG_WARNING("Tap/Device does not have IDCODE");
1070 idcode = 0;
1071
1072 bit_count += 1;
1073 }
1074 else
1075 {
1076 /*
1077 * End of chain (invalid manufacturer ID) some devices, such
1078 * as AVR will output all 1's instead of TDI input value at
1079 * end of chain.
1080 */
1081 if (jtag_idcode_is_final(idcode))
1082 {
1083 jtag_examine_chain_end(idcode_buffer,
1084 bit_count + 32, JTAG_MAX_CHAIN_SIZE * 32);
1085 break;
1086 }
1087
1088 jtag_examine_chain_display(LOG_LVL_INFO, "tap/device found",
1089 tap ? tap->dotted_name : "(not-named)",
1090 idcode);
1091
1092 bit_count += 32;
1093 }
1094 device_count++;
1095 if (!tap)
1096 continue;
1097
1098 tap->idcode = idcode;
1099
1100 // ensure the TAP ID does matches what was expected
1101 if (!jtag_examine_chain_match_tap(tap))
1102 return ERROR_JTAG_INIT_FAILED;
1103
1104 tap = jtag_tap_next_enabled(tap);
1105 }
1106
1107 /* see if number of discovered devices matches configuration */
1108 if (device_count != jtag_tap_count_enabled())
1109 {
1110 LOG_ERROR("number of discovered devices in JTAG chain (%i) "
1111 "does not match (enabled) configuration (%i), total taps: %d",
1112 device_count, jtag_tap_count_enabled(), jtag_tap_count());
1113 LOG_ERROR("check the config file and ensure proper JTAG communication"
1114 " (connections, speed, ...)");
1115 return ERROR_JTAG_INIT_FAILED;
1116 }
1117
1118 return ERROR_OK;
1119 }
1120
1121 static int jtag_validate_chain(void)
1122 {
1123 jtag_tap_t *tap;
1124 int total_ir_length = 0;
1125 u8 *ir_test = NULL;
1126 scan_field_t field;
1127 int chain_pos = 0;
1128
1129 tap = NULL;
1130 total_ir_length = 0;
1131 for(;;){
1132 tap = jtag_tap_next_enabled(tap);
1133 if( tap == NULL ){
1134 break;
1135 }
1136 total_ir_length += tap->ir_length;
1137 }
1138
1139 total_ir_length += 2;
1140 ir_test = malloc(CEIL(total_ir_length, 8));
1141 buf_set_ones(ir_test, total_ir_length);
1142
1143 field.tap = NULL;
1144 field.num_bits = total_ir_length;
1145 field.out_value = ir_test;
1146 field.in_value = ir_test;
1147
1148
1149 jtag_add_plain_ir_scan(1, &field, TAP_RESET);
1150 jtag_execute_queue();
1151
1152 tap = NULL;
1153 chain_pos = 0;
1154 int val;
1155 for(;;){
1156 tap = jtag_tap_next_enabled(tap);
1157 if( tap == NULL ){
1158 break;
1159 }
1160
1161 val = buf_get_u32(ir_test, chain_pos, 2);
1162 if (val != 0x1)
1163 {
1164 char *cbuf = buf_to_str(ir_test, total_ir_length, 16);
1165 LOG_ERROR("Could not validate JTAG scan chain, IR mismatch, scan returned 0x%s. tap=%s pos=%d expected 0x1 got %0x", cbuf, jtag_tap_name(tap), chain_pos, val);
1166 free(cbuf);
1167 free(ir_test);
1168 return ERROR_JTAG_INIT_FAILED;
1169 }
1170 chain_pos += tap->ir_length;
1171 }
1172
1173 val = buf_get_u32(ir_test, chain_pos, 2);
1174 if (val != 0x3)
1175 {
1176 char *cbuf = buf_to_str(ir_test, total_ir_length, 16);
1177 LOG_ERROR("Could not validate end of JTAG scan chain, IR mismatch, scan returned 0x%s. pos=%d expected 0x3 got %0x", cbuf, chain_pos, val);
1178 free(cbuf);
1179 free(ir_test);
1180 return ERROR_JTAG_INIT_FAILED;
1181 }
1182
1183 free(ir_test);
1184
1185 return ERROR_OK;
1186 }
1187
1188 enum jtag_tap_cfg_param {
1189 JCFG_EVENT
1190 };
1191
1192 static Jim_Nvp nvp_config_opts[] = {
1193 { .name = "-event", .value = JCFG_EVENT },
1194
1195 { .name = NULL, .value = -1 }
1196 };
1197
1198 static int jtag_tap_configure_cmd( Jim_GetOptInfo *goi, jtag_tap_t * tap)
1199 {
1200 Jim_Nvp *n;
1201 Jim_Obj *o;
1202 int e;
1203
1204 /* parse config or cget options */
1205 while (goi->argc > 0) {
1206 Jim_SetEmptyResult (goi->interp);
1207
1208 e = Jim_GetOpt_Nvp(goi, nvp_config_opts, &n);
1209 if (e != JIM_OK) {
1210 Jim_GetOpt_NvpUnknown(goi, nvp_config_opts, 0);
1211 return e;
1212 }
1213
1214 switch (n->value) {
1215 case JCFG_EVENT:
1216 if (goi->argc == 0) {
1217 Jim_WrongNumArgs( goi->interp, goi->argc, goi->argv, "-event ?event-name? ..." );
1218 return JIM_ERR;
1219 }
1220
1221 e = Jim_GetOpt_Nvp( goi, nvp_jtag_tap_event, &n );
1222 if (e != JIM_OK) {
1223 Jim_GetOpt_NvpUnknown(goi, nvp_jtag_tap_event, 1);
1224 return e;
1225 }
1226
1227 if (goi->isconfigure) {
1228 if (goi->argc != 1) {
1229 Jim_WrongNumArgs(goi->interp, goi->argc, goi->argv, "-event ?event-name? ?EVENT-BODY?");
1230 return JIM_ERR;
1231 }
1232 } else {
1233 if (goi->argc != 0) {
1234 Jim_WrongNumArgs(goi->interp, goi->argc, goi->argv, "-event ?event-name?");
1235 return JIM_ERR;
1236 }
1237 }
1238
1239 {
1240 jtag_tap_event_action_t *jteap;
1241
1242 jteap = tap->event_action;
1243 /* replace existing? */
1244 while (jteap) {
1245 if (jteap->event == (enum jtag_tap_event)n->value) {
1246 break;
1247 }
1248 jteap = jteap->next;
1249 }
1250
1251 if (goi->isconfigure) {
1252 if (jteap == NULL) {
1253 /* create new */
1254 jteap = calloc(1, sizeof (*jteap));
1255 }
1256 jteap->event = n->value;
1257 Jim_GetOpt_Obj( goi, &o);
1258 if (jteap->body) {
1259 Jim_DecrRefCount(interp, jteap->body);
1260 }
1261 jteap->body = Jim_DuplicateObj(goi->interp, o);
1262 Jim_IncrRefCount(jteap->body);
1263
1264 /* add to head of event list */
1265 jteap->next = tap->event_action;
1266 tap->event_action = jteap;
1267 Jim_SetEmptyResult(goi->interp);
1268 } else {
1269 /* get */
1270 if (jteap == NULL) {
1271 Jim_SetEmptyResult(goi->interp);
1272 } else {
1273 Jim_SetResult(goi->interp, Jim_DuplicateObj(goi->interp, jteap->body));
1274 }
1275 }
1276 }
1277 /* loop for more */
1278 break;
1279 }
1280 } /* while (goi->argc) */
1281
1282 return JIM_OK;
1283 }
1284
1285
1286 static void jtag_tap_init(jtag_tap_t *tap)
1287 {
1288 assert(0 != tap->ir_length);
1289
1290 tap->expected = malloc(tap->ir_length);
1291 tap->expected_mask = malloc(tap->ir_length);
1292 tap->cur_instr = malloc(tap->ir_length);
1293
1294 buf_set_u32(tap->expected, 0, tap->ir_length, tap->ir_capture_value);
1295 buf_set_u32(tap->expected_mask, 0, tap->ir_length, tap->ir_capture_mask);
1296 buf_set_ones(tap->cur_instr, tap->ir_length);
1297
1298 // place TAP in bypass mode
1299 tap->bypass = 1;
1300 // register the reset callback for the TAP
1301 jtag_register_event_callback(&jtag_reset_callback, tap);
1302
1303 LOG_DEBUG("Created Tap: %s @ abs position %d, "
1304 "irlen %d, capture: 0x%x mask: 0x%x", tap->dotted_name,
1305 tap->abs_chain_position, tap->ir_length,
1306 tap->ir_capture_value, tap->ir_capture_mask);
1307 jtag_tap_add(tap);
1308 }
1309
1310 static void jtag_tap_free(jtag_tap_t *tap)
1311 {
1312 /// @todo is anything missing? no memory leaks please
1313 free((void *)tap->expected_ids);
1314 free((void *)tap->chip);
1315 free((void *)tap->tapname);
1316 free((void *)tap->dotted_name);
1317 free(tap);
1318 }
1319
1320 static int jim_newtap_cmd( Jim_GetOptInfo *goi )
1321 {
1322 jtag_tap_t *pTap;
1323 jim_wide w;
1324 int x;
1325 int e;
1326 int reqbits;
1327 Jim_Nvp *n;
1328 char *cp;
1329 const Jim_Nvp opts[] = {
1330 #define NTAP_OPT_IRLEN 0
1331 { .name = "-irlen" , .value = NTAP_OPT_IRLEN },
1332 #define NTAP_OPT_IRMASK 1
1333 { .name = "-irmask" , .value = NTAP_OPT_IRMASK },
1334 #define NTAP_OPT_IRCAPTURE 2
1335 { .name = "-ircapture" , .value = NTAP_OPT_IRCAPTURE },
1336 #define NTAP_OPT_ENABLED 3
1337 { .name = "-enable" , .value = NTAP_OPT_ENABLED },
1338 #define NTAP_OPT_DISABLED 4
1339 { .name = "-disable" , .value = NTAP_OPT_DISABLED },
1340 #define NTAP_OPT_EXPECTED_ID 5
1341 { .name = "-expected-id" , .value = NTAP_OPT_EXPECTED_ID },
1342 { .name = NULL , .value = -1 },
1343 };
1344
1345 pTap = malloc( sizeof(jtag_tap_t) );
1346 memset( pTap, 0, sizeof(*pTap) );
1347 if( !pTap ){
1348 Jim_SetResult_sprintf( goi->interp, "no memory");
1349 return JIM_ERR;
1350 }
1351 /*
1352 * we expect CHIP + TAP + OPTIONS
1353 * */
1354 if( goi->argc < 3 ){
1355 Jim_SetResult_sprintf(goi->interp, "Missing CHIP TAP OPTIONS ....");
1356 return JIM_ERR;
1357 }
1358 Jim_GetOpt_String( goi, &cp, NULL );
1359 pTap->chip = strdup(cp);
1360
1361 Jim_GetOpt_String( goi, &cp, NULL );
1362 pTap->tapname = strdup(cp);
1363
1364 /* name + dot + name + null */
1365 x = strlen(pTap->chip) + 1 + strlen(pTap->tapname) + 1;
1366 cp = malloc( x );
1367 sprintf( cp, "%s.%s", pTap->chip, pTap->tapname );
1368 pTap->dotted_name = cp;
1369
1370 LOG_DEBUG("Creating New Tap, Chip: %s, Tap: %s, Dotted: %s, %d params",
1371 pTap->chip, pTap->tapname, pTap->dotted_name, goi->argc);
1372
1373 /* default is enabled */
1374 pTap->enabled = 1;
1375
1376 /* deal with options */
1377 #define NTREQ_IRLEN 1
1378 #define NTREQ_IRCAPTURE 2
1379 #define NTREQ_IRMASK 4
1380
1381 /* clear them as we find them */
1382 reqbits = (NTREQ_IRLEN | NTREQ_IRCAPTURE | NTREQ_IRMASK);
1383
1384 while( goi->argc ){
1385 e = Jim_GetOpt_Nvp( goi, opts, &n );
1386 if( e != JIM_OK ){
1387 Jim_GetOpt_NvpUnknown( goi, opts, 0 );
1388 return e;
1389 }
1390 LOG_DEBUG("Processing option: %s", n->name );
1391 switch( n->value ){
1392 case NTAP_OPT_ENABLED:
1393 pTap->enabled = 1;
1394 break;
1395 case NTAP_OPT_DISABLED:
1396 pTap->enabled = 0;
1397 break;
1398 case NTAP_OPT_EXPECTED_ID:
1399 {
1400 u32 *new_expected_ids;
1401
1402 e = Jim_GetOpt_Wide( goi, &w );
1403 if( e != JIM_OK) {
1404 Jim_SetResult_sprintf(goi->interp, "option: %s bad parameter", n->name);
1405 return e;
1406 }
1407
1408 new_expected_ids = malloc(sizeof(u32) * (pTap->expected_ids_cnt + 1));
1409 if (new_expected_ids == NULL) {
1410 Jim_SetResult_sprintf( goi->interp, "no memory");
1411 return JIM_ERR;
1412 }
1413
1414 memcpy(new_expected_ids, pTap->expected_ids, sizeof(u32) * pTap->expected_ids_cnt);
1415
1416 new_expected_ids[pTap->expected_ids_cnt] = w;
1417
1418 free(pTap->expected_ids);
1419 pTap->expected_ids = new_expected_ids;
1420 pTap->expected_ids_cnt++;
1421 break;
1422 }
1423 case NTAP_OPT_IRLEN:
1424 case NTAP_OPT_IRMASK:
1425 case NTAP_OPT_IRCAPTURE:
1426 e = Jim_GetOpt_Wide( goi, &w );
1427 if( e != JIM_OK ){
1428 Jim_SetResult_sprintf( goi->interp, "option: %s bad parameter", n->name );
1429 return e;
1430 }
1431 if( (w < 0) || (w > 0xffff) ){
1432 /* wacky value */
1433 Jim_SetResult_sprintf( goi->interp, "option: %s - wacky value: %d (0x%x)",
1434 n->name, (int)(w), (int)(w));
1435 return JIM_ERR;
1436 }
1437 switch(n->value){
1438 case NTAP_OPT_IRLEN:
1439 pTap->ir_length = w;
1440 reqbits &= (~(NTREQ_IRLEN));
1441 break;
1442 case NTAP_OPT_IRMASK:
1443 pTap->ir_capture_mask = w;
1444 reqbits &= (~(NTREQ_IRMASK));
1445 break;
1446 case NTAP_OPT_IRCAPTURE:
1447 pTap->ir_capture_value = w;
1448 reqbits &= (~(NTREQ_IRCAPTURE));
1449 break;
1450 }
1451 } /* switch(n->value) */
1452 } /* while( goi->argc ) */
1453
1454 /* Did all the required option bits get cleared? */
1455 if (0 == reqbits)
1456 {
1457 jtag_tap_init(pTap);
1458 return ERROR_OK;
1459 }
1460
1461 Jim_SetResult_sprintf(goi->interp,
1462 "newtap: %s missing required parameters",
1463 pTap->dotted_name);
1464 jtag_tap_free(pTap);
1465 return JIM_ERR;
1466 }
1467
1468 static int jim_jtag_command( Jim_Interp *interp, int argc, Jim_Obj *const *argv )
1469 {
1470 Jim_GetOptInfo goi;
1471 int e;
1472 Jim_Nvp *n;
1473 Jim_Obj *o;
1474 struct command_context_s *context;
1475
1476 enum {
1477 JTAG_CMD_INTERFACE,
1478 JTAG_CMD_INIT_RESET,
1479 JTAG_CMD_NEWTAP,
1480 JTAG_CMD_TAPENABLE,
1481 JTAG_CMD_TAPDISABLE,
1482 JTAG_CMD_TAPISENABLED,
1483 JTAG_CMD_CONFIGURE,
1484 JTAG_CMD_CGET
1485 };
1486
1487 const Jim_Nvp jtag_cmds[] = {
1488 { .name = "interface" , .value = JTAG_CMD_INTERFACE },
1489 { .name = "arp_init-reset", .value = JTAG_CMD_INIT_RESET },
1490 { .name = "newtap" , .value = JTAG_CMD_NEWTAP },
1491 { .name = "tapisenabled" , .value = JTAG_CMD_TAPISENABLED },
1492 { .name = "tapenable" , .value = JTAG_CMD_TAPENABLE },
1493 { .name = "tapdisable" , .value = JTAG_CMD_TAPDISABLE },
1494 { .name = "configure" , .value = JTAG_CMD_CONFIGURE },
1495 { .name = "cget" , .value = JTAG_CMD_CGET },
1496
1497 { .name = NULL, .value = -1 },
1498 };
1499
1500 context = Jim_GetAssocData(interp, "context");
1501 /* go past the command */
1502 Jim_GetOpt_Setup( &goi, interp, argc-1, argv+1 );
1503
1504 e = Jim_GetOpt_Nvp( &goi, jtag_cmds, &n );
1505 if( e != JIM_OK ){
1506 Jim_GetOpt_NvpUnknown( &goi, jtag_cmds, 0 );
1507 return e;
1508 }
1509 Jim_SetEmptyResult( goi.interp );
1510 switch( n->value ){
1511 case JTAG_CMD_INTERFACE:
1512 /* return the name of the interface */
1513 /* TCL code might need to know the exact type... */
1514 /* FUTURE: we allow this as a means to "set" the interface. */
1515 if( goi.argc != 0 ){
1516 Jim_WrongNumArgs( goi.interp, 1, goi.argv-1, "(no params)");
1517 return JIM_ERR;
1518 }
1519 Jim_SetResultString( goi.interp, jtag_interface->name, -1 );
1520 return JIM_OK;
1521 case JTAG_CMD_INIT_RESET:
1522 if( goi.argc != 0 ){
1523 Jim_WrongNumArgs( goi.interp, 1, goi.argv-1, "(no params)");
1524 return JIM_ERR;
1525 }
1526 e = jtag_init_reset(context);
1527 if( e != ERROR_OK ){
1528 Jim_SetResult_sprintf( goi.interp, "error: %d", e);
1529 return JIM_ERR;
1530 }
1531 return JIM_OK;
1532 case JTAG_CMD_NEWTAP:
1533 return jim_newtap_cmd( &goi );
1534 break;
1535 case JTAG_CMD_TAPISENABLED:
1536 case JTAG_CMD_TAPENABLE:
1537 case JTAG_CMD_TAPDISABLE:
1538 if( goi.argc != 1 ){
1539 Jim_SetResultString( goi.interp, "Too many parameters",-1 );
1540 return JIM_ERR;
1541 }
1542
1543 {
1544 jtag_tap_t *t;
1545 t = jtag_tap_by_jim_obj( goi.interp, goi.argv[0] );
1546 if( t == NULL ){
1547 return JIM_ERR;
1548 }
1549 switch( n->value ){
1550 case JTAG_CMD_TAPISENABLED:
1551 e = t->enabled;
1552 break;
1553 case JTAG_CMD_TAPENABLE:
1554 jtag_tap_handle_event( t, JTAG_TAP_EVENT_ENABLE);
1555 e = 1;
1556 t->enabled = e;
1557 break;
1558 case JTAG_CMD_TAPDISABLE:
1559 jtag_tap_handle_event( t, JTAG_TAP_EVENT_DISABLE);
1560 e = 0;
1561 t->enabled = e;
1562 break;
1563 }
1564 Jim_SetResult( goi.interp, Jim_NewIntObj( goi.interp, e ) );
1565 return JIM_OK;
1566 }
1567 break;
1568
1569 case JTAG_CMD_CGET:
1570 if( goi.argc < 2 ){
1571 Jim_WrongNumArgs( goi.interp, 0, NULL, "?tap-name? -option ...");
1572 return JIM_ERR;
1573 }
1574
1575 {
1576 jtag_tap_t *t;
1577
1578 Jim_GetOpt_Obj(&goi, &o);
1579 t = jtag_tap_by_jim_obj( goi.interp, o );
1580 if( t == NULL ){
1581 return JIM_ERR;
1582 }
1583
1584 goi.isconfigure = 0;
1585 return jtag_tap_configure_cmd( &goi, t);
1586 }
1587 break;
1588
1589 case JTAG_CMD_CONFIGURE:
1590 if( goi.argc < 3 ){
1591 Jim_WrongNumArgs( goi.interp, 0, NULL, "?tap-name? -option ?VALUE? ...");
1592 return JIM_ERR;
1593 }
1594
1595 {
1596 jtag_tap_t *t;
1597
1598 Jim_GetOpt_Obj(&goi, &o);
1599 t = jtag_tap_by_jim_obj( goi.interp, o );
1600 if( t == NULL ){
1601 return JIM_ERR;
1602 }
1603
1604 goi.isconfigure = 1;
1605 return jtag_tap_configure_cmd( &goi, t);
1606 }
1607 }
1608
1609 return JIM_ERR;
1610 }
1611
1612 int jtag_register_commands(struct command_context_s *cmd_ctx)
1613 {
1614 register_jim( cmd_ctx, "jtag", jim_jtag_command, "perform jtag tap actions");
1615
1616 register_command(cmd_ctx, NULL, "interface", handle_interface_command,
1617 COMMAND_CONFIG, "try to configure interface");
1618 register_command(cmd_ctx, NULL, "jtag_speed", handle_jtag_speed_command,
1619 COMMAND_ANY, "(DEPRECATED) set jtag speed (if supported)");
1620 register_command(cmd_ctx, NULL, "jtag_khz", handle_jtag_khz_command,
1621 COMMAND_ANY, "set maximum jtag speed (if supported); "
1622 "parameter is maximum khz, or 0 for adaptive clocking (RTCK).");
1623 register_command(cmd_ctx, NULL, "jtag_device", handle_jtag_device_command,
1624 COMMAND_CONFIG, "(DEPRECATED) jtag_device <ir_length> <ir_expected> <ir_mask>");
1625 register_command(cmd_ctx, NULL, "reset_config", handle_reset_config_command,
1626 COMMAND_ANY,
1627 "[none/trst_only/srst_only/trst_and_srst] [srst_pulls_trst/trst_pulls_srst] [combined/separate] [trst_push_pull/trst_open_drain] [srst_push_pull/srst_open_drain]");
1628 register_command(cmd_ctx, NULL, "jtag_nsrst_delay", handle_jtag_nsrst_delay_command,
1629 COMMAND_ANY, "jtag_nsrst_delay <ms> - delay after deasserting srst in ms");
1630 register_command(cmd_ctx, NULL, "jtag_ntrst_delay", handle_jtag_ntrst_delay_command,
1631 COMMAND_ANY, "jtag_ntrst_delay <ms> - delay after deasserting trst in ms");
1632
1633 register_command(cmd_ctx, NULL, "scan_chain", handle_scan_chain_command,
1634 COMMAND_EXEC, "print current scan chain configuration");
1635
1636 register_command(cmd_ctx, NULL, "jtag_reset", handle_jtag_reset_command,
1637 COMMAND_EXEC, "toggle reset lines <trst> <srst>");
1638 register_command(cmd_ctx, NULL, "runtest", handle_runtest_command,
1639 COMMAND_EXEC, "move to Run-Test/Idle, and execute <num_cycles>");
1640 register_command(cmd_ctx, NULL, "irscan", handle_irscan_command,
1641 COMMAND_EXEC, "execute IR scan <device> <instr> [dev2] [instr2] ...");
1642 register_jim(cmd_ctx, "drscan", Jim_Command_drscan, "execute DR scan <device> <num_bits> <value> <num_bits1> <value2> ...");
1643 register_jim(cmd_ctx, "flush_count", Jim_Command_flush_count, "returns number of times the JTAG queue has been flushed");
1644
1645 register_command(cmd_ctx, NULL, "verify_ircapture", handle_verify_ircapture_command,
1646 COMMAND_ANY, "verify value captured during Capture-IR <enable|disable>");
1647 register_command(cmd_ctx, NULL, "verify_jtag", handle_verify_jtag_command,
1648 COMMAND_ANY, "verify value capture <enable|disable>");
1649 register_command(cmd_ctx, NULL, "tms_sequence", handle_tms_sequence_command,
1650 COMMAND_ANY, "choose short(default) or long tms_sequence <short|long>");
1651 return ERROR_OK;
1652 }
1653
1654 int jtag_interface_init(struct command_context_s *cmd_ctx)
1655 {
1656 if (jtag)
1657 return ERROR_OK;
1658
1659 if (!jtag_interface)
1660 {
1661 /* nothing was previously specified by "interface" command */
1662 LOG_ERROR("JTAG interface has to be specified, see \"interface\" command");
1663 return ERROR_JTAG_INVALID_INTERFACE;
1664 }
1665 if(hasKHz)
1666 {
1667 jtag_interface->khz(jtag_get_speed_khz(), &jtag_speed);
1668 hasKHz = false;
1669 }
1670
1671 if (jtag_interface->init() != ERROR_OK)
1672 return ERROR_JTAG_INIT_FAILED;
1673
1674 jtag = jtag_interface;
1675 return ERROR_OK;
1676 }
1677
1678 static int jtag_init_inner(struct command_context_s *cmd_ctx)
1679 {
1680 jtag_tap_t *tap;
1681 int retval;
1682
1683 LOG_DEBUG("Init JTAG chain");
1684
1685 tap = jtag_tap_next_enabled(NULL);
1686 if( tap == NULL ){
1687 LOG_ERROR("There are no enabled taps?");
1688 return ERROR_JTAG_INIT_FAILED;
1689 }
1690
1691 jtag_add_tlr();
1692 if ((retval=jtag_execute_queue())!=ERROR_OK)
1693 return retval;
1694
1695 /* examine chain first, as this could discover the real chain layout */
1696 if (jtag_examine_chain() != ERROR_OK)
1697 {
1698 LOG_ERROR("trying to validate configured JTAG chain anyway...");
1699 }
1700
1701 if (jtag_validate_chain() != ERROR_OK)
1702 {
1703 LOG_WARNING("Could not validate JTAG chain, continuing anyway...");
1704 }
1705
1706 return ERROR_OK;
1707 }
1708
1709 int jtag_interface_quit(void)
1710 {
1711 if (!jtag || !jtag->quit)
1712 return ERROR_OK;
1713
1714 // close the JTAG interface
1715 int result = jtag->quit();
1716 if (ERROR_OK != result)
1717 LOG_ERROR("failed: %d", result);
1718
1719 return ERROR_OK;
1720 }
1721
1722
1723 int jtag_init_reset(struct command_context_s *cmd_ctx)
1724 {
1725 int retval;
1726
1727 if ((retval=jtag_interface_init(cmd_ctx)) != ERROR_OK)
1728 return retval;
1729
1730 LOG_DEBUG("Trying to bring the JTAG controller to life by asserting TRST / RESET");
1731
1732 /* Reset can happen after a power cycle.
1733 *
1734 * Ideally we would only assert TRST or run RESET before the target reset.
1735 *
1736 * However w/srst_pulls_trst, trst is asserted together with the target
1737 * reset whether we want it or not.
1738 *
1739 * NB! Some targets have JTAG circuitry disabled until a
1740 * trst & srst has been asserted.
1741 *
1742 * NB! here we assume nsrst/ntrst delay are sufficient!
1743 *
1744 * NB! order matters!!!! srst *can* disconnect JTAG circuitry
1745 *
1746 */
1747 jtag_add_reset(1, 0); /* RESET or TRST */
1748 if (jtag_reset_config & RESET_HAS_SRST)
1749 {
1750 jtag_add_reset(1, 1);
1751 if ((jtag_reset_config & RESET_SRST_PULLS_TRST)==0)
1752 jtag_add_reset(0, 1);
1753 }
1754 jtag_add_reset(0, 0);
1755 if ((retval = jtag_execute_queue()) != ERROR_OK)
1756 return retval;
1757
1758 /* Check that we can communication on the JTAG chain + eventually we want to
1759 * be able to perform enumeration only after OpenOCD has started
1760 * telnet and GDB server
1761 *
1762 * That would allow users to more easily perform any magic they need to before
1763 * reset happens.
1764 */
1765 return jtag_init_inner(cmd_ctx);
1766 }
1767
1768 int jtag_init(struct command_context_s *cmd_ctx)
1769 {
1770 int retval;
1771 if ((retval=jtag_interface_init(cmd_ctx)) != ERROR_OK)
1772 return retval;
1773 if (jtag_init_inner(cmd_ctx)==ERROR_OK)
1774 {
1775 return ERROR_OK;
1776 }
1777 return jtag_init_reset(cmd_ctx);
1778 }
1779
1780 void jtag_set_speed_khz(unsigned khz)
1781 {
1782 speed_khz = khz;
1783 }
1784 unsigned jtag_get_speed_khz(void)
1785 {
1786 return speed_khz;
1787 }
1788
1789 static int default_khz(int khz, int *jtag_speed)
1790 {
1791 LOG_ERROR("Translation from khz to jtag_speed not implemented");
1792 return ERROR_FAIL;
1793 }
1794
1795 static int default_speed_div(int speed, int *khz)
1796 {
1797 LOG_ERROR("Translation from jtag_speed to khz not implemented");
1798 return ERROR_FAIL;
1799 }
1800
1801 static int default_power_dropout(int *dropout)
1802 {
1803 *dropout=0; /* by default we can't detect power dropout */
1804 return ERROR_OK;
1805 }
1806
1807 static int default_srst_asserted(int *srst_asserted)
1808 {
1809 *srst_asserted=0; /* by default we can't detect srst asserted */
1810 return ERROR_OK;
1811 }
1812
1813 static int handle_interface_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
1814 {
1815 int i;
1816 int retval;
1817
1818 /* check whether the interface is already configured */
1819 if (jtag_interface)
1820 {
1821 LOG_WARNING("Interface already configured, ignoring");
1822 return ERROR_OK;
1823 }
1824
1825 /* interface name is a mandatory argument */
1826 if (argc < 1 || args[0][0] == '\0')
1827 {
1828 return ERROR_COMMAND_SYNTAX_ERROR;
1829 }
1830
1831 for (i=0; jtag_interfaces[i]; i++)
1832 {
1833 if (strcmp(args[0], jtag_interfaces[i]->name) == 0)
1834 {
1835 if ((retval = jtag_interfaces[i]->register_commands(cmd_ctx)) != ERROR_OK)
1836 {
1837 return retval;
1838 }
1839
1840 jtag_interface = jtag_interfaces[i];
1841
1842 if (jtag_interface->khz == NULL)
1843 {
1844 jtag_interface->khz = default_khz;
1845 }
1846 if (jtag_interface->speed_div == NULL)
1847 {
1848 jtag_interface->speed_div = default_speed_div;
1849 }
1850 if (jtag_interface->power_dropout == NULL)
1851 {
1852 jtag_interface->power_dropout = default_power_dropout;
1853 }
1854 if (jtag_interface->srst_asserted == NULL)
1855 {
1856 jtag_interface->srst_asserted = default_srst_asserted;
1857 }
1858
1859 return ERROR_OK;
1860 }
1861 }
1862
1863 /* no valid interface was found (i.e. the configuration option,
1864 * didn't match one of the compiled-in interfaces
1865 */
1866 LOG_ERROR("No valid jtag interface found (%s)", args[0]);
1867 LOG_ERROR("compiled-in jtag interfaces:");
1868 for (i = 0; jtag_interfaces[i]; i++)
1869 {
1870 LOG_ERROR("%i: %s", i, jtag_interfaces[i]->name);
1871 }
1872
1873 return ERROR_JTAG_INVALID_INTERFACE;
1874 }
1875
1876 static int handle_jtag_device_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
1877 {
1878 int e;
1879 char buf[1024];
1880 Jim_Obj *newargs[ 10 ];
1881 /*
1882 * CONVERT SYNTAX
1883 * argv[-1] = command
1884 * argv[ 0] = ir length
1885 * argv[ 1] = ir capture
1886 * argv[ 2] = ir mask
1887 * argv[ 3] = not actually used by anything but in the docs
1888 */
1889
1890 if( argc < 4 ){
1891 command_print( cmd_ctx, "OLD DEPRECATED SYNTAX: Please use the NEW syntax");
1892 return ERROR_OK;
1893 }
1894 command_print( cmd_ctx, "OLD SYNTAX: DEPRECATED - translating to new syntax");
1895 command_print( cmd_ctx, "jtag newtap CHIP TAP -irlen %s -ircapture %s -irvalue %s",
1896 args[0],
1897 args[1],
1898 args[2] );
1899 command_print( cmd_ctx, "Example: STM32 has 2 taps, the cortexM3(len4) + boundaryscan(len5)");
1900 command_print( cmd_ctx, "jtag newtap stm32 cortexm3 ....., thus creating the tap: \"stm32.cortexm3\"");
1901 command_print( cmd_ctx, "jtag newtap stm32 boundary ....., and the tap: \"stm32.boundary\"");
1902 command_print( cmd_ctx, "And then refer to the taps by the dotted name.");
1903
1904 newargs[0] = Jim_NewStringObj( interp, "jtag", -1 );
1905 newargs[1] = Jim_NewStringObj( interp, "newtap", -1 );
1906 sprintf( buf, "chip%d", jtag_tap_count() );
1907 newargs[2] = Jim_NewStringObj( interp, buf, -1 );
1908 sprintf( buf, "tap%d", jtag_tap_count() );
1909 newargs[3] = Jim_NewStringObj( interp, buf, -1 );
1910 newargs[4] = Jim_NewStringObj( interp, "-irlen", -1 );
1911 newargs[5] = Jim_NewStringObj( interp, args[0], -1 );
1912 newargs[6] = Jim_NewStringObj( interp, "-ircapture", -1 );
1913 newargs[7] = Jim_NewStringObj( interp, args[1], -1 );
1914 newargs[8] = Jim_NewStringObj( interp, "-irmask", -1 );
1915 newargs[9] = Jim_NewStringObj( interp, args[2], -1 );
1916
1917 command_print( cmd_ctx, "NEW COMMAND:");
1918 sprintf( buf, "%s %s %s %s %s %s %s %s %s %s",
1919 Jim_GetString( newargs[0], NULL ),
1920 Jim_GetString( newargs[1], NULL ),
1921 Jim_GetString( newargs[2], NULL ),
1922 Jim_GetString( newargs[3], NULL ),
1923 Jim_GetString( newargs[4], NULL ),
1924 Jim_GetString( newargs[5], NULL ),
1925 Jim_GetString( newargs[6], NULL ),
1926 Jim_GetString( newargs[7], NULL ),
1927 Jim_GetString( newargs[8], NULL ),
1928 Jim_GetString( newargs[9], NULL ) );
1929
1930 e = jim_jtag_command( interp, 10, newargs );
1931 if( e != JIM_OK ){
1932 command_print( cmd_ctx, "%s", Jim_GetString( Jim_GetResult(interp), NULL ) );
1933 }
1934 return e;
1935 }
1936
1937 static int handle_scan_chain_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
1938 {
1939 jtag_tap_t *tap;
1940
1941 tap = jtag_all_taps();
1942 command_print(cmd_ctx, " TapName | Enabled | IdCode Expected IrLen IrCap IrMask Instr ");
1943 command_print(cmd_ctx, "---|--------------------|---------|------------|------------|------|------|------|---------");
1944
1945 while( tap ){
1946 u32 expected, expected_mask, cur_instr, ii;
1947 expected = buf_get_u32(tap->expected, 0, tap->ir_length);
1948 expected_mask = buf_get_u32(tap->expected_mask, 0, tap->ir_length);
1949 cur_instr = buf_get_u32(tap->cur_instr, 0, tap->ir_length);
1950
1951 command_print(cmd_ctx,
1952 "%2d | %-18s | %c | 0x%08x | 0x%08x | 0x%02x | 0x%02x | 0x%02x | 0x%02x",
1953 tap->abs_chain_position,
1954 tap->dotted_name,
1955 tap->enabled ? 'Y' : 'n',
1956 tap->idcode,
1957 (tap->expected_ids_cnt > 0 ? tap->expected_ids[0] : 0),
1958 tap->ir_length,
1959 expected,
1960 expected_mask,
1961 cur_instr);
1962
1963 for (ii = 1; ii < tap->expected_ids_cnt; ii++) {
1964 command_print(cmd_ctx, " | | | | 0x%08x | | | | ",
1965 tap->expected_ids[ii]);
1966 }
1967
1968 tap = tap->next_tap;
1969 }
1970
1971 return ERROR_OK;
1972 }
1973
1974 static int handle_reset_config_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
1975 {
1976 int new_cfg = 0;
1977 int mask = 0;
1978
1979 if (argc < 1)
1980 return ERROR_COMMAND_SYNTAX_ERROR;
1981
1982 /* Original versions cared about the order of these tokens:
1983 * reset_config signals [combination [trst_type [srst_type]]]
1984 * They also clobbered the previous configuration even on error.
1985 *
1986 * Here we don't care about the order, and only change values
1987 * which have been explicitly specified.
1988 */
1989 for (; argc; argc--, args++) {
1990 int tmp = 0;
1991 int m;
1992
1993 /* signals */
1994 m = RESET_HAS_TRST | RESET_HAS_SRST;
1995 if (strcmp(*args, "none") == 0)
1996 tmp = RESET_NONE;
1997 else if (strcmp(*args, "trst_only") == 0)
1998 tmp = RESET_HAS_TRST;
1999 else if (strcmp(*args, "srst_only") == 0)
2000 tmp = RESET_HAS_SRST;
2001 else if (strcmp(*args, "trst_and_srst") == 0)
2002 tmp = RESET_HAS_TRST | RESET_HAS_SRST;
2003 else
2004 m = 0;
2005 if (mask & m) {
2006 LOG_ERROR("extra reset_config %s spec (%s)",
2007 "signal", *args);
2008 return ERROR_INVALID_ARGUMENTS;
2009 }
2010 if (m)
2011 goto next;
2012
2013 /* combination (options for broken wiring) */
2014 m = RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST;
2015 if (strcmp(*args, "separate") == 0)
2016 /* separate reset lines - default */;
2017 else if (strcmp(*args, "srst_pulls_trst") == 0)
2018 tmp |= RESET_SRST_PULLS_TRST;
2019 else if (strcmp(*args, "trst_pulls_srst") == 0)
2020 tmp |= RESET_TRST_PULLS_SRST;
2021 else if (strcmp(*args, "combined") == 0)
2022 tmp |= RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST;
2023 else
2024 m = 0;
2025 if (mask & m) {
2026 LOG_ERROR("extra reset_config %s spec (%s)",
2027 "combination", *args);
2028 return ERROR_INVALID_ARGUMENTS;
2029 }
2030 if (m)
2031 goto next;
2032
2033 /* trst_type (NOP without HAS_TRST) */
2034 m = RESET_TRST_OPEN_DRAIN;
2035 if (strcmp(*args, "trst_open_drain") == 0)
2036 tmp |= RESET_TRST_OPEN_DRAIN;
2037 else if (strcmp(*args, "trst_push_pull") == 0)
2038 /* push/pull from adapter - default */;
2039 else
2040 m = 0;
2041 if (mask & m) {
2042 LOG_ERROR("extra reset_config %s spec (%s)",
2043 "trst_type", *args);
2044 return ERROR_INVALID_ARGUMENTS;
2045 }
2046 if (m)
2047 goto next;
2048
2049 /* srst_type (NOP without HAS_SRST) */
2050 m |= RESET_SRST_PUSH_PULL;
2051 if (strcmp(*args, "srst_push_pull") == 0)
2052 tmp |= RESET_SRST_PUSH_PULL;
2053 else if (strcmp(*args, "srst_open_drain") == 0)
2054 /* open drain from adapter - default */;
2055 else
2056 m = 0;
2057 if (mask & m) {
2058 LOG_ERROR("extra reset_config %s spec (%s)",
2059 "srst_type", *args);
2060 return ERROR_INVALID_ARGUMENTS;
2061 }
2062 if (m)
2063 goto next;
2064
2065 /* caller provided nonsense; fail */
2066 LOG_ERROR("unknown reset_config flag (%s)", *args);
2067 return ERROR_INVALID_ARGUMENTS;
2068
2069 next:
2070 /* Remember the bits which were specified (mask)
2071 * and their new values (new_cfg).
2072 */
2073 mask |= m;
2074 new_cfg |= tmp;
2075 }
2076
2077 /* clear previous values of those bits, save new values */
2078 jtag_reset_config &= ~mask;
2079 jtag_reset_config |= new_cfg;
2080
2081 return ERROR_OK;
2082 }
2083
2084 static int handle_jtag_nsrst_delay_command(struct command_context_s *cmd_ctx,
2085 char *cmd, char **args, int argc)
2086 {
2087 if (argc > 1)
2088 return ERROR_COMMAND_SYNTAX_ERROR;
2089 if (argc == 1)
2090 jtag_set_nsrst_delay(strtoul(args[0], NULL, 0));
2091 command_print(cmd_ctx, "jtag_nsrst_delay: %u", jtag_get_nsrst_delay());
2092 return ERROR_OK;
2093 }
2094
2095 static int handle_jtag_ntrst_delay_command(struct command_context_s *cmd_ctx,
2096 char *cmd, char **args, int argc)
2097 {
2098 if (argc > 1)
2099 return ERROR_COMMAND_SYNTAX_ERROR;
2100 if (argc == 1)
2101 jtag_set_ntrst_delay(strtoul(args[0], NULL, 0));
2102 command_print(cmd_ctx, "jtag_ntrst_delay: %u", jtag_get_ntrst_delay());
2103 return ERROR_OK;
2104 }
2105
2106 static int handle_jtag_speed_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
2107 {
2108 int retval = ERROR_OK;
2109
2110 if (argc > 1)
2111 return ERROR_COMMAND_SYNTAX_ERROR;
2112 if (argc == 1)
2113 {
2114 LOG_DEBUG("handle jtag speed");
2115
2116 int cur_speed = 0;
2117 cur_speed = jtag_speed = strtoul(args[0], NULL, 0);
2118
2119 /* this command can be called during CONFIG,
2120 * in which case jtag isn't initialized */
2121 if (jtag)
2122 retval = jtag->speed(cur_speed);
2123 }
2124 command_print(cmd_ctx, "jtag_speed: %d", jtag_speed);
2125
2126 return retval;
2127 }
2128
2129 static int handle_jtag_khz_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
2130 {
2131 if (argc > 1)
2132 return ERROR_COMMAND_SYNTAX_ERROR;
2133
2134 int retval = ERROR_OK;
2135 int cur_speed = 0;
2136 if (argc == 1)
2137 {
2138 LOG_DEBUG("handle jtag khz");
2139
2140 jtag_set_speed_khz(strtoul(args[0], NULL, 0));
2141 if (jtag != NULL)
2142 {
2143 LOG_DEBUG("have interface set up");
2144 int speed_div1;
2145 retval = jtag->khz(jtag_get_speed_khz(), &speed_div1);
2146 if (ERROR_OK != retval)
2147 {
2148 jtag_set_speed_khz(0);
2149 return retval;
2150 }
2151 cur_speed = jtag_speed = speed_div1;
2152
2153 retval = jtag->speed(cur_speed);
2154 }
2155 else
2156 hasKHz = true;
2157 }
2158
2159 cur_speed = jtag_get_speed_khz();
2160 if (jtag != NULL)
2161 {
2162 retval = jtag->speed_div(jtag_speed, &cur_speed);
2163 if (ERROR_OK != retval)
2164 return retval;
2165 }
2166
2167 if (cur_speed)
2168 command_print(cmd_ctx, "%d kHz", cur_speed);
2169 else
2170 command_print(cmd_ctx, "RCLK - adaptive");
2171 return retval;
2172
2173 }
2174
2175 static int handle_jtag_reset_command(struct command_context_s *cmd_ctx,
2176 char *cmd, char **args, int argc)
2177 {
2178 if (argc != 2)
2179 return ERROR_COMMAND_SYNTAX_ERROR;
2180
2181 int trst = -1;
2182 if (args[0][0] == '1')
2183 trst = 1;
2184 else if (args[0][0] == '0')
2185 trst = 0;
2186 else
2187 return ERROR_COMMAND_SYNTAX_ERROR;
2188
2189 int srst = -1;
2190 if (args[1][0] == '1')
2191 srst = 1;
2192 else if (args[1][0] == '0')
2193 srst = 0;
2194 else
2195 return ERROR_COMMAND_SYNTAX_ERROR;
2196
2197 if (jtag_interface_init(cmd_ctx) != ERROR_OK)
2198 return ERROR_JTAG_INIT_FAILED;
2199
2200 jtag_add_reset(trst, srst);
2201 jtag_execute_queue();
2202
2203 return ERROR_OK;
2204 }
2205
2206 static int handle_runtest_command(struct command_context_s *cmd_ctx,
2207 char *cmd, char **args, int argc)
2208 {
2209 if (argc != 1)
2210 return ERROR_COMMAND_SYNTAX_ERROR;
2211
2212 jtag_add_runtest(strtol(args[0], NULL, 0), jtag_get_end_state());
2213 jtag_execute_queue();
2214
2215 return ERROR_OK;
2216 }
2217
2218 /*
2219 * For "irscan" or "drscan" commands, the "end" (really, "next") state
2220 * should be stable ... and *NOT* a shift state, otherwise free-running
2221 * jtag clocks could change the values latched by the update state.
2222 */
2223 static bool scan_is_safe(tap_state_t state)
2224 {
2225 switch (state)
2226 {
2227 case TAP_RESET:
2228 case TAP_IDLE:
2229 case TAP_DRPAUSE:
2230 case TAP_IRPAUSE:
2231 return true;
2232 default:
2233 return false;
2234 }
2235 }
2236
2237
2238 static int handle_irscan_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
2239 {
2240 int i;
2241 scan_field_t *fields;
2242 jtag_tap_t *tap;
2243 tap_state_t endstate;
2244
2245 if ((argc < 2) || (argc % 2))
2246 {
2247 return ERROR_COMMAND_SYNTAX_ERROR;
2248 }
2249
2250 /* optional "-endstate" "statename" at the end of the arguments,
2251 * so that e.g. IRPAUSE can let us load the data register before
2252 * entering RUN/IDLE to execute the instruction we load here.
2253 */
2254 endstate = TAP_IDLE;
2255
2256 if( argc >= 4 ){
2257 /* have at least one pair of numbers. */
2258 /* is last pair the magic text? */
2259 if( 0 == strcmp( "-endstate", args[ argc - 2 ] ) ){
2260 const char *cpA;
2261 const char *cpS;
2262 cpA = args[ argc-1 ];
2263 for( endstate = 0 ; endstate < TAP_NUM_STATES ; endstate++ ){
2264 cpS = tap_state_name( endstate );
2265 if( 0 == strcmp( cpA, cpS ) ){
2266 break;
2267 }
2268 }
2269 if( endstate >= TAP_NUM_STATES ){
2270 return ERROR_COMMAND_SYNTAX_ERROR;
2271 } else {
2272 if (!scan_is_safe(endstate))
2273 LOG_WARNING("irscan with unsafe "
2274 "endstate \"%s\"", cpA);
2275 /* found - remove the last 2 args */
2276 argc -= 2;
2277 }
2278 }
2279 }
2280
2281 int num_fields = argc / 2;
2282
2283 fields = malloc(sizeof(scan_field_t) * num_fields);
2284
2285 for (i = 0; i < num_fields; i++)
2286 {
2287 tap = jtag_tap_by_string( args[i*2] );
2288 if (tap==NULL)
2289 {
2290 command_print( cmd_ctx, "Tap: %s unknown", args[i*2] );
2291 return ERROR_FAIL;
2292 }
2293 int field_size = tap->ir_length;
2294 fields[i].tap = tap;
2295 fields[i].num_bits = field_size;
2296 fields[i].out_value = malloc(CEIL(field_size, 8));
2297 buf_set_u32(fields[i].out_value, 0, field_size, strtoul(args[i*2+1], NULL, 0));
2298 fields[i].in_value = NULL;
2299 }
2300
2301 /* did we have an endstate? */
2302 jtag_add_ir_scan(num_fields, fields, endstate);
2303
2304 int retval=jtag_execute_queue();
2305
2306 for (i = 0; i < num_fields; i++)
2307 free(fields[i].out_value);
2308
2309 free (fields);
2310
2311 return retval;
2312 }
2313
2314 static int Jim_Command_drscan(Jim_Interp *interp, int argc, Jim_Obj *const *args)
2315 {
2316 int retval;
2317 scan_field_t *fields;
2318 int num_fields;
2319 int field_count = 0;
2320 int i, e;
2321 jtag_tap_t *tap;
2322 tap_state_t endstate;
2323
2324 /* args[1] = device
2325 * args[2] = num_bits
2326 * args[3] = hex string
2327 * ... repeat num bits and hex string ...
2328 *
2329 * .. optionally:
2330 * args[N-2] = "-endstate"
2331 * args[N-1] = statename
2332 */
2333 if ((argc < 4) || ((argc % 2)!=0))
2334 {
2335 Jim_WrongNumArgs(interp, 1, args, "wrong arguments");
2336 return JIM_ERR;
2337 }
2338
2339 endstate = TAP_IDLE;
2340
2341 /* validate arguments as numbers */
2342 e = JIM_OK;
2343 for (i = 2; i < argc; i+=2)
2344 {
2345 long bits;
2346 const char *cp;
2347
2348 e = Jim_GetLong(interp, args[i], &bits);
2349 /* If valid - try next arg */
2350 if( e == JIM_OK ){
2351 continue;
2352 }
2353
2354 /* Not valid.. are we at the end? */
2355 if ( ((i+2) != argc) ){
2356 /* nope, then error */
2357 return e;
2358 }
2359
2360 /* it could be: "-endstate FOO"
2361 * e.g. DRPAUSE so we can issue more instructions
2362 * before entering RUN/IDLE and executing them.
2363 */
2364
2365 /* get arg as a string. */
2366 cp = Jim_GetString( args[i], NULL );
2367 /* is it the magic? */
2368 if( 0 == strcmp( "-endstate", cp ) ){
2369 /* is the statename valid? */
2370 cp = Jim_GetString( args[i+1], NULL );
2371
2372 /* see if it is a valid state name */
2373 endstate = tap_state_by_name(cp);
2374 if( endstate < 0 ){
2375 /* update the error message */
2376 Jim_SetResult_sprintf(interp,"endstate: %s invalid", cp );
2377 } else {
2378 if (!scan_is_safe(endstate))
2379 LOG_WARNING("drscan with unsafe "
2380 "endstate \"%s\"", cp);
2381
2382 /* valid - so clear the error */
2383 e = JIM_OK;
2384 /* and remove the last 2 args */
2385 argc -= 2;
2386 }
2387 }
2388
2389 /* Still an error? */
2390 if( e != JIM_OK ){
2391 return e; /* too bad */
2392 }
2393 } /* validate args */
2394
2395 tap = jtag_tap_by_jim_obj( interp, args[1] );
2396 if( tap == NULL ){
2397 return JIM_ERR;
2398 }
2399
2400 num_fields=(argc-2)/2;
2401 fields = malloc(sizeof(scan_field_t) * num_fields);
2402 for (i = 2; i < argc; i+=2)
2403 {
2404 long bits;
2405 int len;
2406 const char *str;
2407
2408 Jim_GetLong(interp, args[i], &bits);
2409 str = Jim_GetString(args[i+1], &len);
2410
2411 fields[field_count].tap = tap;
2412 fields[field_count].num_bits = bits;
2413 fields[field_count].out_value = malloc(CEIL(bits, 8));
2414 str_to_buf(str, len, fields[field_count].out_value, bits, 0);
2415 fields[field_count].in_value = fields[field_count].out_value;
2416 field_count++;
2417 }
2418
2419 jtag_add_dr_scan(num_fields, fields, endstate);
2420
2421 retval = jtag_execute_queue();
2422 if (retval != ERROR_OK)
2423 {
2424 Jim_SetResultString(interp, "drscan: jtag execute failed",-1);
2425 return JIM_ERR;
2426 }
2427
2428 field_count=0;
2429 Jim_Obj *list = Jim_NewListObj(interp, NULL, 0);
2430 for (i = 2; i < argc; i+=2)
2431 {
2432 long bits;
2433 char *str;
2434
2435 Jim_GetLong(interp, args[i], &bits);
2436 str = buf_to_str(fields[field_count].in_value, bits, 16);
2437 free(fields[field_count].out_value);
2438
2439 Jim_ListAppendElement(interp, list, Jim_NewStringObj(interp, str, strlen(str)));
2440 free(str);
2441 field_count++;
2442 }
2443
2444 Jim_SetResult(interp, list);
2445
2446 free(fields);
2447
2448 return JIM_OK;
2449 }
2450
2451
2452 static int Jim_Command_flush_count(Jim_Interp *interp, int argc, Jim_Obj *const *args)
2453 {
2454 Jim_SetResult(interp, Jim_NewIntObj(interp, jtag_get_flush_queue_count()));
2455
2456 return JIM_OK;
2457 }
2458
2459
2460 static int handle_verify_ircapture_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
2461 {
2462 if (argc == 1)
2463 {
2464 if (strcmp(args[0], "enable") == 0)
2465 {
2466 jtag_verify_capture_ir = 1;
2467 }
2468 else if (strcmp(args[0], "disable") == 0)
2469 {
2470 jtag_verify_capture_ir = 0;
2471 } else
2472 {
2473 return ERROR_COMMAND_SYNTAX_ERROR;
2474 }
2475 } else if (argc != 0)
2476 {
2477 return ERROR_COMMAND_SYNTAX_ERROR;
2478 }
2479
2480 command_print(cmd_ctx, "verify Capture-IR is %s", (jtag_verify_capture_ir) ? "enabled": "disabled");
2481
2482 return ERROR_OK;
2483 }
2484
2485 void jtag_set_verify(bool enable)
2486 {
2487 jtag_verify = enable;
2488 }
2489
2490 bool jtag_will_verify()
2491 {
2492 return jtag_verify;
2493 }
2494
2495 static int handle_verify_jtag_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
2496 {
2497 if (argc > 1)
2498 return ERROR_COMMAND_SYNTAX_ERROR;
2499
2500 if (argc == 1)
2501 {
2502 if (strcmp(args[0], "enable") == 0)
2503 jtag_set_verify(true);
2504 else if (strcmp(args[0], "disable") == 0)
2505 jtag_set_verify(false);
2506 else
2507 return ERROR_COMMAND_SYNTAX_ERROR;
2508 }
2509
2510 const char *status = jtag_will_verify() ? "enabled": "disabled";
2511 command_print(cmd_ctx, "verify jtag capture is %s", status);
2512
2513 return ERROR_OK;
2514 }
2515
2516
2517 int jtag_power_dropout(int *dropout)
2518 {
2519 return jtag->power_dropout(dropout);
2520 }
2521
2522 int jtag_srst_asserted(int *srst_asserted)
2523 {
2524 return jtag->srst_asserted(srst_asserted);
2525 }
2526
2527 void jtag_tap_handle_event( jtag_tap_t * tap, enum jtag_tap_event e)
2528 {
2529 jtag_tap_event_action_t * jteap;
2530 int done;
2531
2532 jteap = tap->event_action;
2533
2534 done = 0;
2535 while (jteap) {
2536 if (jteap->event == e) {
2537 done = 1;
2538 LOG_DEBUG( "JTAG tap: %s event: %d (%s) action: %s\n",
2539 tap->dotted_name,
2540 e,
2541 Jim_Nvp_value2name_simple(nvp_jtag_tap_event, e)->name,
2542 Jim_GetString(jteap->body, NULL) );
2543 if (Jim_EvalObj(interp, jteap->body) != JIM_OK) {
2544 Jim_PrintErrorMessage(interp);
2545 }
2546 }
2547
2548 jteap = jteap->next;
2549 }
2550
2551 if (!done) {
2552 LOG_DEBUG( "event %d %s - no action",
2553 e,
2554 Jim_Nvp_value2name_simple( nvp_jtag_tap_event, e)->name);
2555 }
2556 }
2557
2558 static int handle_tms_sequence_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
2559 {
2560 if (argc > 1)
2561 return ERROR_COMMAND_SYNTAX_ERROR;
2562
2563 if (argc == 1)
2564 {
2565 bool use_new_table;
2566 if (strcmp(args[0], "short") == 0)
2567 use_new_table = true;
2568 else if (strcmp(args[0], "long") == 0)
2569 use_new_table = false;
2570 else
2571 return ERROR_COMMAND_SYNTAX_ERROR;
2572
2573 tap_use_new_tms_table(use_new_table);
2574 }
2575
2576 command_print(cmd_ctx, "tms sequence is %s",
2577 tap_uses_new_tms_table() ? "short": "long");
2578
2579 return ERROR_OK;
2580 }
2581
2582 /**
2583 * Function jtag_add_statemove
2584 * moves from the current state to the goal \a state. This needs
2585 * to be handled according to the xsvf spec, see the XSTATE command
2586 * description.
2587 */
2588 int jtag_add_statemove(tap_state_t goal_state)
2589 {
2590 int retval = ERROR_OK;
2591
2592 tap_state_t moves[8];
2593 tap_state_t cur_state = cmd_queue_cur_state;
2594 int i;
2595 int tms_bits;
2596 int tms_count;
2597
2598 LOG_DEBUG( "cur_state=%s goal_state=%s",
2599 tap_state_name(cur_state),
2600 tap_state_name(goal_state) );
2601
2602
2603 /* From the XSVF spec, pertaining to XSTATE:
2604
2605 For special states known as stable states (Test-Logic-Reset,
2606 Run-Test/Idle, Pause-DR, Pause- IR), an XSVF interpreter follows
2607 predefined TAP state paths when the starting state is a stable state and
2608 when the XSTATE specifies a new stable state (see the STATE command in
2609 the [Ref 5] for the TAP state paths between stable states). For
2610 non-stable states, XSTATE should specify a state that is only one TAP
2611 state transition distance from the current TAP state to avoid undefined
2612 TAP state paths. A sequence of multiple XSTATE commands can be issued to
2613 transition the TAP through a specific state path.
2614 */
2615
2616 if (goal_state==cur_state )
2617 ; /* nothing to do */
2618
2619 else if( goal_state==TAP_RESET )
2620 {
2621 jtag_add_tlr();
2622 }
2623
2624 else if( tap_is_state_stable(cur_state) && tap_is_state_stable(goal_state) )
2625 {
2626 /* note: unless tms_bits holds a path that agrees with [Ref 5] in above
2627 spec, then this code is not fully conformant to the xsvf spec. This
2628 puts a burden on tap_get_tms_path() function from the xsvf spec.
2629 If in doubt, you should confirm that that burden is being met.
2630 */
2631
2632 tms_bits = tap_get_tms_path(cur_state, goal_state);
2633 tms_count = tap_get_tms_path_len(cur_state, goal_state);
2634
2635 assert( (unsigned) tms_count < DIM(moves) );
2636
2637 for (i=0; i<tms_count; i++, tms_bits>>=1)
2638 {
2639 bool bit = tms_bits & 1;
2640
2641 cur_state = tap_state_transition(cur_state, bit);
2642 moves[i] = cur_state;
2643 }
2644
2645 jtag_add_pathmove(tms_count, moves);
2646 }
2647
2648 /* else state must be immediately reachable in one clock cycle, and does not
2649 need to be a stable state.
2650 */
2651 else if( tap_state_transition(cur_state, true) == goal_state
2652 || tap_state_transition(cur_state, false) == goal_state )
2653 {
2654 /* move a single state */
2655 moves[0] = goal_state;
2656 jtag_add_pathmove( 1, moves );
2657 }
2658
2659 else
2660 {
2661 retval = ERROR_FAIL;
2662 }
2663
2664 return retval;
2665 }
2666
2667 void jtag_set_nsrst_delay(unsigned delay)
2668 {
2669 jtag_nsrst_delay = delay;
2670 }
2671 unsigned jtag_get_nsrst_delay(void)
2672 {
2673 return jtag_nsrst_delay;
2674 }
2675 void jtag_set_ntrst_delay(unsigned delay)
2676 {
2677 jtag_ntrst_delay = delay;
2678 }
2679 unsigned jtag_get_ntrst_delay(void)
2680 {
2681 return jtag_ntrst_delay;
2682 }

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)