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

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)