jtag/adapter: add command 'adapter serial' 47/6647/3
authorAntonio Borneo <borneo.antonio@gmail.com>
Thu, 7 Oct 2021 17:27:31 +0000 (19:27 +0200)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sun, 28 Nov 2021 10:49:51 +0000 (10:49 +0000)
Several adapter define their own command to specify the USB serial
number or serial string to be used during USB search.

Define a general command 'adapter serial' to be proposed as
replacement of the driver specific ones.
No driver is changed so far to use it.

Change-Id: I7631687a4163ccc63a9bdf3ad1fcb300fc483d3a
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6647
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Tested-by: jenkins
doc/openocd.texi
src/jtag/adapter.c
src/jtag/adapter.h

index 0ab4b36acb54c4665695ec58b345c7d00c0be758..286943643798e9a8017a0d9e7476be39ac851dea 100644 (file)
@@ -2367,6 +2367,14 @@ The USB bus topology can be queried with the command @emph{lsusb -t} or @emph{dm
 This command is only available if your libusb1 is at least version 1.0.16.
 @end deffn
 
+@deffn {Config Command} {adapter serial} serial_string
+Specifies the @var{serial_string} of the adapter to use.
+If this command is not specified, serial strings are not checked.
+No adapter uses this command, so far.
+The following adapters have their own command to specify the serial string:
+cmsis_dap, ft232r, ftdi, hla, jlink, kitprog, presto, st-link, vsllink, xds110.
+@end deffn
+
 @section Interface Drivers
 
 Each of the interface drivers listed here must be explicitly
index 65874590dd9674f072571830e657435e6509ba4b..14452d42f271979e7e5113f76c1652bb82c0f351 100644 (file)
@@ -42,6 +42,7 @@ enum adapter_clk_mode {
 static struct {
        bool adapter_initialized;
        char *usb_location;
+       char *serial;
        enum adapter_clk_mode clock_mode;
        int speed_khz;
        int rclk_fallback_speed_khz;
@@ -120,6 +121,7 @@ int adapter_quit(void)
                        LOG_ERROR("failed: %d", result);
        }
 
+       free(adapter_config.serial);
        free(adapter_config.usb_location);
 
        struct jtag_tap *t = jtag_all_taps();
@@ -223,6 +225,11 @@ int adapter_get_speed_readable(int *khz)
        return adapter_driver->speed_div(speed_var, khz);
 }
 
+const char *adapter_get_required_serial(void)
+{
+       return adapter_config.serial;
+}
+
 /*
  * 1 char: bus
  * 2 * 7 chars: max 7 ports
@@ -659,6 +666,16 @@ COMMAND_HANDLER(handle_adapter_speed_command)
        return retval;
 }
 
+COMMAND_HANDLER(handle_adapter_serial_command)
+{
+       if (CMD_ARGC != 1)
+               return ERROR_COMMAND_SYNTAX_ERROR;
+
+       free(adapter_config.serial);
+       adapter_config.serial = strdup(CMD_ARGV[0]);
+       return ERROR_OK;
+}
+
 COMMAND_HANDLER(handle_adapter_reset_de_assert)
 {
        enum values {
@@ -806,6 +823,13 @@ static const struct command_registration adapter_command_handlers[] = {
                        "With or without argument, display current setting.",
                .usage = "[khz]",
        },
+       {
+               .name = "serial",
+               .handler = handle_adapter_serial_command,
+               .mode = COMMAND_CONFIG,
+               .help = "Set the serial number of the adapter",
+               .usage = "serial_string",
+       },
        {
                .name = "list",
                .handler = handle_adapter_list_command,
index 8b73c0c9ef188755b0dbe2a62819184dcafc03b7..300769c22965023bfd1164d710128c3057c7f693 100644 (file)
@@ -55,4 +55,7 @@ int adapter_config_rclk(unsigned int fallback_speed_khz);
 /** Retrieves the clock speed of the adapter in kHz. */
 unsigned int adapter_get_speed_khz(void);
 
+/** Retrieves the serial number set with command 'adapter serial' */
+const char *adapter_get_required_serial(void);
+
 #endif /* OPENOCD_JTAG_ADAPTER_H */

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)