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

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)