jtag/hla, jtag/stlink: switch to command 'adapter serial'
[openocd.git] / src / jtag / drivers / stlink_usb.c
index 87e6ddc20f3066aef72b93407acd71aa04c72527..4c0e025fc5f9522097caf039d469f10de9a930b6 100644 (file)
@@ -38,6 +38,7 @@
 #include <helper/bits.h>
 #include <helper/system.h>
 #include <helper/time_support.h>
+#include <jtag/adapter.h>
 #include <jtag/interface.h>
 #include <jtag/hla/hla_layout.h>
 #include <jtag/hla/hla_transport.h>
@@ -3363,7 +3364,7 @@ static int stlink_usb_usb_open(void *handle, struct hl_interface_param_s *param)
          in order to become operational.
         */
        do {
-               if (jtag_libusb_open(param->vid, param->pid, param->serial,
+               if (jtag_libusb_open(param->vid, param->pid, adapter_get_required_serial(),
                                &h->usb_backend_priv.fd, stlink_usb_get_alternate_serial) != ERROR_OK) {
                        LOG_ERROR("open failed");
                        return ERROR_FAIL;
@@ -3574,7 +3575,8 @@ static int stlink_tcp_open(void *handle, struct hl_interface_param_s *param)
        char serial[STLINK_TCP_SERIAL_SIZE + 1] = {0};
        uint8_t stlink_used;
        bool stlink_id_matched = false;
-       bool stlink_serial_matched = (!param->serial);
+       const char *adapter_serial = adapter_get_required_serial();
+       bool stlink_serial_matched = !adapter_serial;
 
        for (uint32_t stlink_id = 0; stlink_id < connected_stlinks; stlink_id++) {
                /* get the stlink info */
@@ -3604,27 +3606,28 @@ static int stlink_tcp_open(void *handle, struct hl_interface_param_s *param)
                        continue;
 
                /* check the serial if specified */
-               if (param->serial) {
+               if (adapter_serial) {
                        /* ST-Link server fixes the buggy serial returned by old ST-Link DFU
                         * for further details refer to stlink_usb_get_alternate_serial
                         * so if the user passes the buggy serial, we need to fix it before
                         * comparing with the serial returned by ST-Link server */
-                       if (strlen(param->serial) == STLINK_SERIAL_LEN / 2) {
+                       if (strlen(adapter_serial) == STLINK_SERIAL_LEN / 2) {
                                char fixed_serial[STLINK_SERIAL_LEN + 1];
 
                                for (unsigned int i = 0; i < STLINK_SERIAL_LEN; i += 2)
-                                       sprintf(fixed_serial + i, "%02X", param->serial[i / 2]);
+                                       sprintf(fixed_serial + i, "%02X", adapter_serial[i / 2]);
 
                                fixed_serial[STLINK_SERIAL_LEN] = '\0';
 
                                stlink_serial_matched = strcmp(fixed_serial, serial) == 0;
-                       } else
-                               stlink_serial_matched = strcmp(param->serial, serial) == 0;
+                       } else {
+                               stlink_serial_matched = strcmp(adapter_serial, serial) == 0;
+                       }
                }
 
                if (!stlink_serial_matched)
                        LOG_DEBUG("Device serial number '%s' doesn't match requested serial '%s'",
-                                       serial, param->serial);
+                                       serial, adapter_serial);
                else /* exit the search loop if there is match */
                        break;
        }
@@ -3693,7 +3696,7 @@ static int stlink_open(struct hl_interface_param_s *param, enum stlink_mode mode
        for (unsigned i = 0; param->vid[i]; i++) {
                LOG_DEBUG("transport: %d vid: 0x%04x pid: 0x%04x serial: %s",
                          h->st_mode, param->vid[i], param->pid[i],
-                         param->serial ? param->serial : "");
+                         adapter_get_required_serial() ? adapter_get_required_serial() : "");
        }
 
        if (param->use_stlink_tcp)
@@ -4916,25 +4919,6 @@ static int stlink_dap_trace_read(uint8_t *buf, size_t *size)
        return stlink_usb_trace_read(stlink_dap_handle, buf, size);
 }
 
-/** */
-COMMAND_HANDLER(stlink_dap_serial_command)
-{
-       LOG_DEBUG("stlink_dap_serial_command");
-
-       if (CMD_ARGC != 1) {
-               LOG_ERROR("Expected exactly one argument for \"st-link serial <serial-number>\".");
-               return ERROR_COMMAND_SYNTAX_ERROR;
-       }
-
-       if (stlink_dap_param.serial) {
-               LOG_WARNING("Command \"st-link serial\" already used. Replacing previous value");
-               free((void *)stlink_dap_param.serial);
-       }
-
-       stlink_dap_param.serial = strdup(CMD_ARGV[0]);
-       return ERROR_OK;
-}
-
 /** */
 COMMAND_HANDLER(stlink_dap_vid_pid)
 {
@@ -5025,13 +5009,6 @@ COMMAND_HANDLER(stlink_dap_cmd_command)
 
 /** */
 static const struct command_registration stlink_dap_subcommand_handlers[] = {
-       {
-               .name = "serial",
-               .handler = stlink_dap_serial_command,
-               .mode = COMMAND_CONFIG,
-               .help = "set the serial number of the adapter",
-               .usage = "<serial_number>",
-       },
        {
                .name = "vid_pid",
                .handler = stlink_dap_vid_pid,
@@ -5112,9 +5089,6 @@ static int stlink_dap_quit(void)
 {
        LOG_DEBUG("stlink_dap_quit()");
 
-       free((void *)stlink_dap_param.serial);
-       stlink_dap_param.serial = NULL;
-
        return stlink_close(stlink_dap_handle);
 }
 

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)