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

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)