From da50873d5ebe558ee545c1a00f31df9e23f45456 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 4 Jan 2025 18:41:41 +0100 Subject: [PATCH] adapter: list supported transports beside adapter name Modify the command 'adapter list' to output the list of transports supported by each adapter driver. Drop the line number, as there is no real interest on it. Format the output as a TCL dictionary indexed by the adapter name and containing the transports in a TCL list. E.g: dummy { jtag } ftdi { jtag swd } This format is easily handled by TCL scripts, e.g.: dict get [adapter list] ftdi Document the command output. Change-Id: I69f73b71da2f1756866a63bc2c0ba33459a29063 Signed-off-by: Antonio Borneo Reviewed-on: https://review.openocd.org/c/openocd/+/8691 Tested-by: jenkins --- doc/openocd.texi | 11 +++++++++++ src/jtag/adapter.c | 14 +++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/doc/openocd.texi b/doc/openocd.texi index 32a2895ec..d85812824 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -2414,6 +2414,17 @@ target. @deffn {Command} {adapter list} List the debug adapter drivers that have been built into the running copy of OpenOCD. + +The output is formatted as a Tcl dictionary indexed by the adapter name +and containing the transports in a Tcl list. +@example +dummy @{ jtag @} +ftdi @{ jtag swd @} +@end example +This format is easily handled by Tcl scripts: +@example +dict get [adapter list] ftdi +@end example @end deffn @anchor{adapter gpio} diff --git a/src/jtag/adapter.c b/src/jtag/adapter.c index 0bdfe7b13..694721746 100644 --- a/src/jtag/adapter.c +++ b/src/jtag/adapter.c @@ -393,9 +393,21 @@ COMMAND_HANDLER(handle_adapter_name) COMMAND_HANDLER(dump_adapter_driver_list) { + int max_len = 0; + for (unsigned int i = 0; adapter_drivers[i]; i++) { + int len = strlen(adapter_drivers[i]->name); + if (max_len < len) + max_len = len; + } + for (unsigned int i = 0; adapter_drivers[i]; i++) { const char *name = adapter_drivers[i]->name; - command_print(CMD, "%u: %s", i + 1, name); + const char * const *transports = adapter_drivers[i]->transports; + + command_print_sameline(CMD, "%-*s {", max_len, name); + for (unsigned int j = 0; transports[j]; j++) + command_print_sameline(CMD, " %s", transports[j]); + command_print(CMD, " }"); } return ERROR_OK;