c30019c17539c4584493af125c486265841d2864
[openocd.git] / src / jtag / adapter.c
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * Copyright (C) 2005 by Dominic Rath <Dominic.Rath@gmx.de>
4 * Copyright (C) 2007-2010 Øyvind Harboe <oyvind.harboe@zylin.com>
5 * Copyright (C) 2009 SoftPLC Corporation, http://softplc.com, Dick Hollenbeck <dick@softplc.com>
6 * Copyright (C) 2009 Zachary T Welch <zw@superlucidity.net>
7 * Copyright (C) 2018 Pengutronix, Oleksij Rempel <kernel@pengutronix.de>
8 */
9
10 #ifdef HAVE_CONFIG_H
11 #include "config.h"
12 #endif
13
14 #include "adapter.h"
15 #include "jtag.h"
16 #include "minidriver.h"
17 #include "interface.h"
18 #include "interfaces.h"
19 #include <transport/transport.h>
20
21 #ifdef HAVE_STRINGS_H
22 #include <strings.h>
23 #endif
24
25 /**
26 * @file
27 * Holds support for configuring debug adapters from TCl scripts.
28 */
29
30 struct adapter_driver *adapter_driver;
31 const char * const jtag_only[] = { "jtag", NULL };
32
33 enum adapter_clk_mode {
34 CLOCK_MODE_UNSELECTED = 0,
35 CLOCK_MODE_KHZ,
36 CLOCK_MODE_RCLK
37 };
38
39 /**
40 * Adapter configuration
41 */
42 static struct {
43 bool adapter_initialized;
44 char *usb_location;
45 enum adapter_clk_mode clock_mode;
46 int speed_khz;
47 int rclk_fallback_speed_khz;
48 } adapter_config;
49
50 bool is_adapter_initialized(void)
51 {
52 return adapter_config.adapter_initialized;
53 }
54
55 /**
56 * Do low-level setup like initializing registers, output signals,
57 * and clocking.
58 */
59 int adapter_init(struct command_context *cmd_ctx)
60 {
61 if (is_adapter_initialized())
62 return ERROR_OK;
63
64 if (!adapter_driver) {
65 /* nothing was previously specified by "adapter driver" command */
66 LOG_ERROR("Debug Adapter has to be specified, "
67 "see \"adapter driver\" command");
68 return ERROR_JTAG_INVALID_INTERFACE;
69 }
70
71 int retval;
72 retval = adapter_driver->init();
73 if (retval != ERROR_OK)
74 return retval;
75 adapter_config.adapter_initialized = true;
76
77 if (!adapter_driver->speed) {
78 LOG_INFO("This adapter doesn't support configurable speed");
79 return ERROR_OK;
80 }
81
82 if (adapter_config.clock_mode == CLOCK_MODE_UNSELECTED) {
83 LOG_ERROR("An adapter speed is not selected in the init script."
84 " Insert a call to \"adapter speed\" or \"jtag_rclk\" to proceed.");
85 return ERROR_JTAG_INIT_FAILED;
86 }
87
88 int requested_khz = adapter_get_speed_khz();
89 int actual_khz = requested_khz;
90 int speed_var = 0;
91 retval = adapter_get_speed(&speed_var);
92 if (retval != ERROR_OK)
93 return retval;
94 retval = adapter_driver->speed(speed_var);
95 if (retval != ERROR_OK)
96 return retval;
97 retval = adapter_get_speed_readable(&actual_khz);
98 if (retval != ERROR_OK)
99 LOG_INFO("adapter-specific clock speed value %d", speed_var);
100 else if (actual_khz) {
101 /* Adaptive clocking -- JTAG-specific */
102 if ((adapter_config.clock_mode == CLOCK_MODE_RCLK)
103 || ((adapter_config.clock_mode == CLOCK_MODE_KHZ) && !requested_khz)) {
104 LOG_INFO("RCLK (adaptive clock speed) not supported - fallback to %d kHz"
105 , actual_khz);
106 } else
107 LOG_INFO("clock speed %d kHz", actual_khz);
108 } else
109 LOG_INFO("RCLK (adaptive clock speed)");
110
111 return ERROR_OK;
112 }
113
114 int adapter_quit(void)
115 {
116 if (is_adapter_initialized() && adapter_driver->quit) {
117 /* close the JTAG interface */
118 int result = adapter_driver->quit();
119 if (result != ERROR_OK)
120 LOG_ERROR("failed: %d", result);
121 }
122
123 free(adapter_config.usb_location);
124
125 struct jtag_tap *t = jtag_all_taps();
126 while (t) {
127 struct jtag_tap *n = t->next_tap;
128 jtag_tap_free(t);
129 t = n;
130 }
131
132 return ERROR_OK;
133 }
134
135 unsigned int adapter_get_speed_khz(void)
136 {
137 return adapter_config.speed_khz;
138 }
139
140 static int adapter_khz_to_speed(unsigned int khz, int *speed)
141 {
142 LOG_DEBUG("convert khz to adapter specific speed value");
143 adapter_config.speed_khz = khz;
144 if (!is_adapter_initialized())
145 return ERROR_OK;
146 LOG_DEBUG("have adapter set up");
147 if (!adapter_driver->khz) {
148 LOG_ERROR("Translation from khz to adapter speed not implemented");
149 return ERROR_FAIL;
150 }
151 int speed_div1;
152 int retval = adapter_driver->khz(adapter_get_speed_khz(), &speed_div1);
153 if (retval != ERROR_OK)
154 return retval;
155 *speed = speed_div1;
156 return ERROR_OK;
157 }
158
159 static int adapter_rclk_to_speed(unsigned int fallback_speed_khz, int *speed)
160 {
161 int retval = adapter_khz_to_speed(0, speed);
162 if ((retval != ERROR_OK) && fallback_speed_khz) {
163 LOG_DEBUG("trying fallback speed...");
164 retval = adapter_khz_to_speed(fallback_speed_khz, speed);
165 }
166 return retval;
167 }
168
169 static int adapter_set_speed(int speed)
170 {
171 /* this command can be called during CONFIG,
172 * in which case adapter isn't initialized */
173 return is_adapter_initialized() ? adapter_driver->speed(speed) : ERROR_OK;
174 }
175
176 int adapter_config_khz(unsigned int khz)
177 {
178 LOG_DEBUG("handle adapter khz");
179 adapter_config.clock_mode = CLOCK_MODE_KHZ;
180 int speed = 0;
181 int retval = adapter_khz_to_speed(khz, &speed);
182 return (retval != ERROR_OK) ? retval : adapter_set_speed(speed);
183 }
184
185 int adapter_config_rclk(unsigned int fallback_speed_khz)
186 {
187 LOG_DEBUG("handle adapter rclk");
188 adapter_config.clock_mode = CLOCK_MODE_RCLK;
189 adapter_config.rclk_fallback_speed_khz = fallback_speed_khz;
190 int speed = 0;
191 int retval = adapter_rclk_to_speed(fallback_speed_khz, &speed);
192 return (retval != ERROR_OK) ? retval : adapter_set_speed(speed);
193 }
194
195 int adapter_get_speed(int *speed)
196 {
197 switch (adapter_config.clock_mode) {
198 case CLOCK_MODE_KHZ:
199 adapter_khz_to_speed(adapter_get_speed_khz(), speed);
200 break;
201 case CLOCK_MODE_RCLK:
202 adapter_rclk_to_speed(adapter_config.rclk_fallback_speed_khz, speed);
203 break;
204 default:
205 LOG_ERROR("BUG: unknown adapter clock mode");
206 return ERROR_FAIL;
207 }
208 return ERROR_OK;
209 }
210
211 int adapter_get_speed_readable(int *khz)
212 {
213 int speed_var = 0;
214 int retval = adapter_get_speed(&speed_var);
215 if (retval != ERROR_OK)
216 return retval;
217 if (!is_adapter_initialized())
218 return ERROR_OK;
219 if (!adapter_driver->speed_div) {
220 LOG_ERROR("Translation from adapter speed to khz not implemented");
221 return ERROR_FAIL;
222 }
223 return adapter_driver->speed_div(speed_var, khz);
224 }
225
226 /*
227 * 1 char: bus
228 * 2 * 7 chars: max 7 ports
229 * 1 char: test for overflow
230 * ------
231 * 16 chars
232 */
233 #define USB_MAX_LOCATION_LENGTH 16
234
235 #ifdef HAVE_LIBUSB_GET_PORT_NUMBERS
236 static void adapter_usb_set_location(const char *location)
237 {
238 if (strnlen(location, USB_MAX_LOCATION_LENGTH) == USB_MAX_LOCATION_LENGTH)
239 LOG_WARNING("usb location string is too long!!");
240
241 free(adapter_config.usb_location);
242
243 adapter_config.usb_location = strndup(location, USB_MAX_LOCATION_LENGTH);
244 }
245 #endif /* HAVE_LIBUSB_GET_PORT_NUMBERS */
246
247 const char *adapter_usb_get_location(void)
248 {
249 return adapter_config.usb_location;
250 }
251
252 bool adapter_usb_location_equal(uint8_t dev_bus, uint8_t *port_path, size_t path_len)
253 {
254 size_t path_step, string_length;
255 char *ptr, *loc;
256 bool equal = false;
257
258 if (!adapter_usb_get_location())
259 return equal;
260
261 /* strtok need non const char */
262 loc = strndup(adapter_usb_get_location(), USB_MAX_LOCATION_LENGTH);
263 string_length = strnlen(loc, USB_MAX_LOCATION_LENGTH);
264
265 ptr = strtok(loc, "-");
266 if (!ptr) {
267 LOG_WARNING("no '-' in usb path\n");
268 goto done;
269 }
270
271 string_length -= strnlen(ptr, string_length);
272 /* check bus mismatch */
273 if (atoi(ptr) != dev_bus)
274 goto done;
275
276 path_step = 0;
277 while (path_step < path_len) {
278 ptr = strtok(NULL, ".");
279
280 /* no more tokens in path */
281 if (!ptr)
282 break;
283
284 /* path mismatch at some step */
285 if (path_step < path_len && atoi(ptr) != port_path[path_step])
286 break;
287
288 path_step++;
289 string_length -= strnlen(ptr, string_length) + 1;
290 };
291
292 /* walked the full path, all elements match */
293 if (path_step == path_len && !string_length)
294 equal = true;
295
296 done:
297 free(loc);
298 return equal;
299 }
300
301 static int jim_adapter_name(Jim_Interp *interp, int argc, Jim_Obj * const *argv)
302 {
303 struct jim_getopt_info goi;
304 jim_getopt_setup(&goi, interp, argc-1, argv + 1);
305
306 /* return the name of the interface */
307 /* TCL code might need to know the exact type... */
308 /* FUTURE: we allow this as a means to "set" the interface. */
309 if (goi.argc != 0) {
310 Jim_WrongNumArgs(goi.interp, 1, goi.argv-1, "(no params)");
311 return JIM_ERR;
312 }
313 const char *name = adapter_driver ? adapter_driver->name : NULL;
314 Jim_SetResultString(goi.interp, name ? name : "undefined", -1);
315 return JIM_OK;
316 }
317
318 COMMAND_HANDLER(adapter_transports_command)
319 {
320 char **transports;
321 int retval;
322
323 retval = CALL_COMMAND_HANDLER(transport_list_parse, &transports);
324 if (retval != ERROR_OK)
325 return retval;
326
327 retval = allow_transports(CMD_CTX, (const char **)transports);
328
329 if (retval != ERROR_OK) {
330 for (unsigned i = 0; transports[i]; i++)
331 free(transports[i]);
332 free(transports);
333 }
334 return retval;
335 }
336
337 COMMAND_HANDLER(handle_adapter_list_command)
338 {
339 if (strcmp(CMD_NAME, "list") == 0 && CMD_ARGC > 0)
340 return ERROR_COMMAND_SYNTAX_ERROR;
341
342 command_print(CMD, "The following debug adapters are available:");
343 for (unsigned i = 0; adapter_drivers[i]; i++) {
344 const char *name = adapter_drivers[i]->name;
345 command_print(CMD, "%u: %s", i + 1, name);
346 }
347
348 return ERROR_OK;
349 }
350
351 COMMAND_HANDLER(handle_adapter_driver_command)
352 {
353 int retval;
354
355 /* check whether the interface is already configured */
356 if (adapter_driver) {
357 LOG_WARNING("Interface already configured, ignoring");
358 return ERROR_OK;
359 }
360
361 /* interface name is a mandatory argument */
362 if (CMD_ARGC != 1 || CMD_ARGV[0][0] == '\0')
363 return ERROR_COMMAND_SYNTAX_ERROR;
364
365 for (unsigned i = 0; adapter_drivers[i]; i++) {
366 if (strcmp(CMD_ARGV[0], adapter_drivers[i]->name) != 0)
367 continue;
368
369 if (adapter_drivers[i]->commands) {
370 retval = register_commands(CMD_CTX, NULL,
371 adapter_drivers[i]->commands);
372 if (retval != ERROR_OK)
373 return retval;
374 }
375
376 adapter_driver = adapter_drivers[i];
377
378 return allow_transports(CMD_CTX, adapter_driver->transports);
379 }
380
381 /* no valid interface was found (i.e. the configuration option,
382 * didn't match one of the compiled-in interfaces
383 */
384 LOG_ERROR("The specified debug interface was not found (%s)",
385 CMD_ARGV[0]);
386 CALL_COMMAND_HANDLER(handle_adapter_list_command);
387 return ERROR_JTAG_INVALID_INTERFACE;
388 }
389
390 COMMAND_HANDLER(handle_reset_config_command)
391 {
392 int new_cfg = 0;
393 int mask = 0;
394
395 /* Original versions cared about the order of these tokens:
396 * reset_config signals [combination [trst_type [srst_type]]]
397 * They also clobbered the previous configuration even on error.
398 *
399 * Here we don't care about the order, and only change values
400 * which have been explicitly specified.
401 */
402 for (; CMD_ARGC; CMD_ARGC--, CMD_ARGV++) {
403 int tmp = 0;
404 int m;
405
406 /* gating */
407 m = RESET_SRST_NO_GATING;
408 if (strcmp(*CMD_ARGV, "srst_gates_jtag") == 0)
409 /* default: don't use JTAG while SRST asserted */;
410 else if (strcmp(*CMD_ARGV, "srst_nogate") == 0)
411 tmp = RESET_SRST_NO_GATING;
412 else
413 m = 0;
414 if (mask & m) {
415 LOG_ERROR("extra reset_config %s spec (%s)",
416 "gating", *CMD_ARGV);
417 return ERROR_COMMAND_SYNTAX_ERROR;
418 }
419 if (m)
420 goto next;
421
422 /* signals */
423 m = RESET_HAS_TRST | RESET_HAS_SRST;
424 if (strcmp(*CMD_ARGV, "none") == 0)
425 tmp = RESET_NONE;
426 else if (strcmp(*CMD_ARGV, "trst_only") == 0)
427 tmp = RESET_HAS_TRST;
428 else if (strcmp(*CMD_ARGV, "srst_only") == 0)
429 tmp = RESET_HAS_SRST;
430 else if (strcmp(*CMD_ARGV, "trst_and_srst") == 0)
431 tmp = RESET_HAS_TRST | RESET_HAS_SRST;
432 else
433 m = 0;
434 if (mask & m) {
435 LOG_ERROR("extra reset_config %s spec (%s)",
436 "signal", *CMD_ARGV);
437 return ERROR_COMMAND_SYNTAX_ERROR;
438 }
439 if (m)
440 goto next;
441
442 /* combination (options for broken wiring) */
443 m = RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST;
444 if (strcmp(*CMD_ARGV, "separate") == 0)
445 /* separate reset lines - default */;
446 else if (strcmp(*CMD_ARGV, "srst_pulls_trst") == 0)
447 tmp |= RESET_SRST_PULLS_TRST;
448 else if (strcmp(*CMD_ARGV, "trst_pulls_srst") == 0)
449 tmp |= RESET_TRST_PULLS_SRST;
450 else if (strcmp(*CMD_ARGV, "combined") == 0)
451 tmp |= RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST;
452 else
453 m = 0;
454 if (mask & m) {
455 LOG_ERROR("extra reset_config %s spec (%s)",
456 "combination", *CMD_ARGV);
457 return ERROR_COMMAND_SYNTAX_ERROR;
458 }
459 if (m)
460 goto next;
461
462 /* trst_type (NOP without HAS_TRST) */
463 m = RESET_TRST_OPEN_DRAIN;
464 if (strcmp(*CMD_ARGV, "trst_open_drain") == 0)
465 tmp |= RESET_TRST_OPEN_DRAIN;
466 else if (strcmp(*CMD_ARGV, "trst_push_pull") == 0)
467 /* push/pull from adapter - default */;
468 else
469 m = 0;
470 if (mask & m) {
471 LOG_ERROR("extra reset_config %s spec (%s)",
472 "trst_type", *CMD_ARGV);
473 return ERROR_COMMAND_SYNTAX_ERROR;
474 }
475 if (m)
476 goto next;
477
478 /* srst_type (NOP without HAS_SRST) */
479 m = RESET_SRST_PUSH_PULL;
480 if (strcmp(*CMD_ARGV, "srst_push_pull") == 0)
481 tmp |= RESET_SRST_PUSH_PULL;
482 else if (strcmp(*CMD_ARGV, "srst_open_drain") == 0)
483 /* open drain from adapter - default */;
484 else
485 m = 0;
486 if (mask & m) {
487 LOG_ERROR("extra reset_config %s spec (%s)",
488 "srst_type", *CMD_ARGV);
489 return ERROR_COMMAND_SYNTAX_ERROR;
490 }
491 if (m)
492 goto next;
493
494 /* connect_type - only valid when srst_nogate */
495 m = RESET_CNCT_UNDER_SRST;
496 if (strcmp(*CMD_ARGV, "connect_assert_srst") == 0)
497 tmp |= RESET_CNCT_UNDER_SRST;
498 else if (strcmp(*CMD_ARGV, "connect_deassert_srst") == 0)
499 /* connect normally - default */;
500 else
501 m = 0;
502 if (mask & m) {
503 LOG_ERROR("extra reset_config %s spec (%s)",
504 "connect_type", *CMD_ARGV);
505 return ERROR_COMMAND_SYNTAX_ERROR;
506 }
507 if (m)
508 goto next;
509
510 /* caller provided nonsense; fail */
511 LOG_ERROR("unknown reset_config flag (%s)", *CMD_ARGV);
512 return ERROR_COMMAND_SYNTAX_ERROR;
513
514 next:
515 /* Remember the bits which were specified (mask)
516 * and their new values (new_cfg).
517 */
518 mask |= m;
519 new_cfg |= tmp;
520 }
521
522 /* clear previous values of those bits, save new values */
523 if (mask) {
524 int old_cfg = jtag_get_reset_config();
525
526 old_cfg &= ~mask;
527 new_cfg |= old_cfg;
528 jtag_set_reset_config(new_cfg);
529 } else
530 new_cfg = jtag_get_reset_config();
531
532 /*
533 * Display the (now-)current reset mode
534 */
535 char *modes[6];
536
537 /* minimal JTAG has neither SRST nor TRST (so that's the default) */
538 switch (new_cfg & (RESET_HAS_TRST | RESET_HAS_SRST)) {
539 case RESET_HAS_SRST:
540 modes[0] = "srst_only";
541 break;
542 case RESET_HAS_TRST:
543 modes[0] = "trst_only";
544 break;
545 case RESET_TRST_AND_SRST:
546 modes[0] = "trst_and_srst";
547 break;
548 default:
549 modes[0] = "none";
550 break;
551 }
552
553 /* normally SRST and TRST are decoupled; but bugs happen ... */
554 switch (new_cfg & (RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST)) {
555 case RESET_SRST_PULLS_TRST:
556 modes[1] = "srst_pulls_trst";
557 break;
558 case RESET_TRST_PULLS_SRST:
559 modes[1] = "trst_pulls_srst";
560 break;
561 case RESET_SRST_PULLS_TRST | RESET_TRST_PULLS_SRST:
562 modes[1] = "combined";
563 break;
564 default:
565 modes[1] = "separate";
566 break;
567 }
568
569 /* TRST-less connectors include Altera, Xilinx, and minimal JTAG */
570 if (new_cfg & RESET_HAS_TRST) {
571 if (new_cfg & RESET_TRST_OPEN_DRAIN)
572 modes[3] = " trst_open_drain";
573 else
574 modes[3] = " trst_push_pull";
575 } else
576 modes[3] = "";
577
578 /* SRST-less connectors include TI-14, Xilinx, and minimal JTAG */
579 if (new_cfg & RESET_HAS_SRST) {
580 if (new_cfg & RESET_SRST_NO_GATING)
581 modes[2] = " srst_nogate";
582 else
583 modes[2] = " srst_gates_jtag";
584
585 if (new_cfg & RESET_SRST_PUSH_PULL)
586 modes[4] = " srst_push_pull";
587 else
588 modes[4] = " srst_open_drain";
589
590 if (new_cfg & RESET_CNCT_UNDER_SRST)
591 modes[5] = " connect_assert_srst";
592 else
593 modes[5] = " connect_deassert_srst";
594 } else {
595 modes[2] = "";
596 modes[4] = "";
597 modes[5] = "";
598 }
599
600 command_print(CMD, "%s %s%s%s%s%s",
601 modes[0], modes[1],
602 modes[2], modes[3], modes[4], modes[5]);
603
604 return ERROR_OK;
605 }
606
607 COMMAND_HANDLER(handle_adapter_srst_delay_command)
608 {
609 if (CMD_ARGC > 1)
610 return ERROR_COMMAND_SYNTAX_ERROR;
611 if (CMD_ARGC == 1) {
612 unsigned delay;
613 COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], delay);
614
615 jtag_set_nsrst_delay(delay);
616 }
617 command_print(CMD, "adapter srst delay: %u", jtag_get_nsrst_delay());
618 return ERROR_OK;
619 }
620
621 COMMAND_HANDLER(handle_adapter_srst_pulse_width_command)
622 {
623 if (CMD_ARGC > 1)
624 return ERROR_COMMAND_SYNTAX_ERROR;
625 if (CMD_ARGC == 1) {
626 unsigned width;
627 COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], width);
628
629 jtag_set_nsrst_assert_width(width);
630 }
631 command_print(CMD, "adapter srst pulse_width: %u", jtag_get_nsrst_assert_width());
632 return ERROR_OK;
633 }
634
635 COMMAND_HANDLER(handle_adapter_speed_command)
636 {
637 if (CMD_ARGC > 1)
638 return ERROR_COMMAND_SYNTAX_ERROR;
639
640 int retval = ERROR_OK;
641 if (CMD_ARGC == 1) {
642 unsigned khz = 0;
643 COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], khz);
644
645 retval = adapter_config_khz(khz);
646 if (retval != ERROR_OK)
647 return retval;
648 }
649
650 int cur_speed = adapter_get_speed_khz();
651 retval = adapter_get_speed_readable(&cur_speed);
652 if (retval != ERROR_OK)
653 return retval;
654
655 if (cur_speed)
656 command_print(CMD, "adapter speed: %d kHz", cur_speed);
657 else
658 command_print(CMD, "adapter speed: RCLK - adaptive");
659
660 return retval;
661 }
662
663 COMMAND_HANDLER(handle_adapter_reset_de_assert)
664 {
665 enum values {
666 VALUE_UNDEFINED = -1,
667 VALUE_DEASSERT = 0,
668 VALUE_ASSERT = 1,
669 };
670 enum values value;
671 enum values srst = VALUE_UNDEFINED;
672 enum values trst = VALUE_UNDEFINED;
673 enum reset_types jtag_reset_config = jtag_get_reset_config();
674 char *signal;
675
676 if (CMD_ARGC == 0) {
677 if (transport_is_jtag()) {
678 if (jtag_reset_config & RESET_HAS_TRST)
679 signal = jtag_get_trst() ? "asserted" : "deasserted";
680 else
681 signal = "not present";
682 command_print(CMD, "trst %s", signal);
683 }
684
685 if (jtag_reset_config & RESET_HAS_SRST)
686 signal = jtag_get_srst() ? "asserted" : "deasserted";
687 else
688 signal = "not present";
689 command_print(CMD, "srst %s", signal);
690
691 return ERROR_OK;
692 }
693
694 if (CMD_ARGC != 1 && CMD_ARGC != 3)
695 return ERROR_COMMAND_SYNTAX_ERROR;
696
697 value = (strcmp(CMD_NAME, "assert") == 0) ? VALUE_ASSERT : VALUE_DEASSERT;
698 if (strcmp(CMD_ARGV[0], "srst") == 0)
699 srst = value;
700 else if (strcmp(CMD_ARGV[0], "trst") == 0)
701 trst = value;
702 else
703 return ERROR_COMMAND_SYNTAX_ERROR;
704
705 if (CMD_ARGC == 3) {
706 if (strcmp(CMD_ARGV[1], "assert") == 0)
707 value = VALUE_ASSERT;
708 else if (strcmp(CMD_ARGV[1], "deassert") == 0)
709 value = VALUE_DEASSERT;
710 else
711 return ERROR_COMMAND_SYNTAX_ERROR;
712
713 if (strcmp(CMD_ARGV[2], "srst") == 0 && srst == VALUE_UNDEFINED)
714 srst = value;
715 else if (strcmp(CMD_ARGV[2], "trst") == 0 && trst == VALUE_UNDEFINED)
716 trst = value;
717 else
718 return ERROR_COMMAND_SYNTAX_ERROR;
719 }
720
721 if (trst == VALUE_UNDEFINED) {
722 if (transport_is_jtag())
723 trst = jtag_get_trst() ? VALUE_ASSERT : VALUE_DEASSERT;
724 else
725 trst = VALUE_DEASSERT; /* unused, safe value */
726 }
727
728 if (srst == VALUE_UNDEFINED) {
729 if (jtag_reset_config & RESET_HAS_SRST)
730 srst = jtag_get_srst() ? VALUE_ASSERT : VALUE_DEASSERT;
731 else
732 srst = VALUE_DEASSERT; /* unused, safe value */
733 }
734
735 if (trst == VALUE_ASSERT && !transport_is_jtag()) {
736 LOG_ERROR("transport has no trst signal");
737 return ERROR_FAIL;
738 }
739
740 if (srst == VALUE_ASSERT && !(jtag_reset_config & RESET_HAS_SRST)) {
741 LOG_ERROR("adapter has no srst signal");
742 return ERROR_FAIL;
743 }
744
745 return adapter_resets((trst == VALUE_DEASSERT) ? TRST_DEASSERT : TRST_ASSERT,
746 (srst == VALUE_DEASSERT) ? SRST_DEASSERT : SRST_ASSERT);
747 }
748
749 #ifdef HAVE_LIBUSB_GET_PORT_NUMBERS
750 COMMAND_HANDLER(handle_usb_location_command)
751 {
752 if (CMD_ARGC == 1)
753 adapter_usb_set_location(CMD_ARGV[0]);
754
755 command_print(CMD, "adapter usb location: %s", adapter_usb_get_location());
756
757 return ERROR_OK;
758 }
759 #endif /* HAVE_LIBUSB_GET_PORT_NUMBERS */
760
761 static const struct command_registration adapter_usb_command_handlers[] = {
762 #ifdef HAVE_LIBUSB_GET_PORT_NUMBERS
763 {
764 .name = "location",
765 .handler = &handle_usb_location_command,
766 .mode = COMMAND_CONFIG,
767 .help = "display or set the USB bus location of the USB device",
768 .usage = "[<bus>-port[.port]...]",
769 },
770 #endif /* HAVE_LIBUSB_GET_PORT_NUMBERS */
771 COMMAND_REGISTRATION_DONE
772 };
773
774 static const struct command_registration adapter_srst_command_handlers[] = {
775 {
776 .name = "delay",
777 .handler = handle_adapter_srst_delay_command,
778 .mode = COMMAND_ANY,
779 .help = "delay after deasserting SRST in ms",
780 .usage = "[milliseconds]",
781 },
782 {
783 .name = "pulse_width",
784 .handler = handle_adapter_srst_pulse_width_command,
785 .mode = COMMAND_ANY,
786 .help = "SRST assertion pulse width in ms",
787 .usage = "[milliseconds]",
788 },
789 COMMAND_REGISTRATION_DONE
790 };
791
792 static const struct command_registration adapter_command_handlers[] = {
793 {
794 .name = "driver",
795 .handler = handle_adapter_driver_command,
796 .mode = COMMAND_CONFIG,
797 .help = "Select a debug adapter driver",
798 .usage = "driver_name",
799 },
800 {
801 .name = "speed",
802 .handler = handle_adapter_speed_command,
803 .mode = COMMAND_ANY,
804 .help = "With an argument, change to the specified maximum "
805 "jtag speed. For JTAG, 0 KHz signifies adaptive "
806 "clocking. "
807 "With or without argument, display current setting.",
808 .usage = "[khz]",
809 },
810 {
811 .name = "list",
812 .handler = handle_adapter_list_command,
813 .mode = COMMAND_ANY,
814 .help = "List all built-in debug adapter drivers",
815 .usage = "",
816 },
817 {
818 .name = "name",
819 .mode = COMMAND_ANY,
820 .jim_handler = jim_adapter_name,
821 .help = "Returns the name of the currently "
822 "selected adapter (driver)",
823 },
824 {
825 .name = "srst",
826 .mode = COMMAND_ANY,
827 .help = "srst adapter command group",
828 .usage = "",
829 .chain = adapter_srst_command_handlers,
830 },
831 {
832 .name = "transports",
833 .handler = adapter_transports_command,
834 .mode = COMMAND_CONFIG,
835 .help = "Declare transports the adapter supports.",
836 .usage = "transport ...",
837 },
838 {
839 .name = "usb",
840 .mode = COMMAND_ANY,
841 .help = "usb adapter command group",
842 .usage = "",
843 .chain = adapter_usb_command_handlers,
844 },
845 {
846 .name = "assert",
847 .handler = handle_adapter_reset_de_assert,
848 .mode = COMMAND_EXEC,
849 .help = "Controls SRST and TRST lines.",
850 .usage = "|deassert [srst|trst [assert|deassert srst|trst]]",
851 },
852 {
853 .name = "deassert",
854 .handler = handle_adapter_reset_de_assert,
855 .mode = COMMAND_EXEC,
856 .help = "Controls SRST and TRST lines.",
857 .usage = "|assert [srst|trst [deassert|assert srst|trst]]",
858 },
859 COMMAND_REGISTRATION_DONE
860 };
861
862 static const struct command_registration interface_command_handlers[] = {
863 {
864 .name = "adapter",
865 .mode = COMMAND_ANY,
866 .help = "adapter command group",
867 .usage = "",
868 .chain = adapter_command_handlers,
869 },
870 {
871 .name = "reset_config",
872 .handler = handle_reset_config_command,
873 .mode = COMMAND_ANY,
874 .help = "configure adapter reset behavior",
875 .usage = "[none|trst_only|srst_only|trst_and_srst] "
876 "[srst_pulls_trst|trst_pulls_srst|combined|separate] "
877 "[srst_gates_jtag|srst_nogate] "
878 "[trst_push_pull|trst_open_drain] "
879 "[srst_push_pull|srst_open_drain] "
880 "[connect_deassert_srst|connect_assert_srst]",
881 },
882 COMMAND_REGISTRATION_DONE
883 };
884
885 /**
886 * Register the commands which deal with arbitrary debug adapter drivers.
887 *
888 * @todo Remove internal assumptions that all debug adapters use JTAG for
889 * transport. Various types and data structures are not named generically.
890 */
891 int adapter_register_commands(struct command_context *ctx)
892 {
893 return register_commands(ctx, NULL, interface_command_handlers);
894 }

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)