drivers: call adapter_get_required_serial() in jtag_libusb_open() 63/6663/4
authorAntonio Borneo <borneo.antonio@gmail.com>
Tue, 19 Oct 2021 11:09:25 +0000 (13:09 +0200)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sun, 28 Nov 2021 11:01:32 +0000 (11:01 +0000)
Now that adapter serial is handled independently from the adapter
drivers, move inside jtag_libusb_open() the call to
adapter_get_required_serial(), so every adapter that uses libusb
will automagically get USB serial support.

Extend the documentation to list the adapters involved.

Change-Id: I75b3482d38f8ed3418329f3106c5e8b689fd460b
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6663
Tested-by: jenkins
15 files changed:
doc/openocd.texi
src/jtag/aice/aice_usb.c
src/jtag/drivers/arm-jtag-ew.c
src/jtag/drivers/ft232r.c
src/jtag/drivers/kitprog.c
src/jtag/drivers/libusb_helper.c
src/jtag/drivers/libusb_helper.h
src/jtag/drivers/opendous.c
src/jtag/drivers/openjtag.c
src/jtag/drivers/osbdm.c
src/jtag/drivers/rlink.c
src/jtag/drivers/stlink_usb.c
src/jtag/drivers/ti_icdi_usb.c
src/jtag/drivers/usb_blaster/ublast2_access_libusb.c
src/jtag/drivers/usbprog.c

index 19ec31b34326abfc5decb2822220771ed94a642f..33732818768db010736f20196ba2b5eceda44885 100644 (file)
@@ -2371,7 +2371,8 @@ This command is only available if your libusb1 is at least version 1.0.16.
 Specifies the @var{serial_string} of the adapter to use.
 If this command is not specified, serial strings are not checked.
 Only the following adapter drivers use the serial string from this command:
-cmsis_dap, ft232r, ftdi, hla, jlink, kitprog, presto, st-link, vsllink, xds110.
+aice (aice_usb), arm-jtag-ew, cmsis_dap, ft232r, ftdi, hla (stlink, ti-icdi), jlink, kitprog, opendus,
+openjtag, osbdm, presto, rlink, st-link, usb_blaster (ublast2), usbprog, vsllink, xds110.
 @end deffn
 
 @section Interface Drivers
index a943bb8b0427265b4d9e2b1b11778915ed0fe073..5d586763c4390307756b3cc2c1c7f040bc802a58 100644 (file)
@@ -2085,7 +2085,7 @@ static int aice_usb_open(struct aice_port_param_s *param)
        const uint16_t pids[] = { param->pid, 0 };
        struct libusb_device_handle *devh;
 
-       if (jtag_libusb_open(vids, pids, NULL, &devh, NULL) != ERROR_OK)
+       if (jtag_libusb_open(vids, pids, &devh, NULL) != ERROR_OK)
                return ERROR_FAIL;
 
        /* BE ***VERY CAREFUL*** ABOUT MAKING CHANGES IN THIS
@@ -2109,7 +2109,7 @@ static int aice_usb_open(struct aice_port_param_s *param)
        /* reopen jlink after usb_reset
         * on win32 this may take a second or two to re-enumerate */
        int retval;
-       while ((retval = jtag_libusb_open(vids, pids, NULL, &devh, NULL)) != ERROR_OK) {
+       while ((retval = jtag_libusb_open(vids, pids, &devh, NULL)) != ERROR_OK) {
                usleep(1000);
                timeout--;
                if (!timeout)
index 5b5a9669e518246a26744985654e165450151ae3..703378940b60ac76ee8cdb33dc106048198e7ed9 100644 (file)
@@ -688,7 +688,7 @@ static struct armjtagew *armjtagew_usb_open(void)
        const uint16_t pids[] = { USB_PID, 0 };
        struct libusb_device_handle *dev;
 
-       if (jtag_libusb_open(vids, pids, NULL, &dev, NULL) != ERROR_OK)
+       if (jtag_libusb_open(vids, pids, &dev, NULL) != ERROR_OK)
                return NULL;
 
        struct armjtagew *result = malloc(sizeof(struct armjtagew));
index fc3cdbae29918798403ab59c42b2fe96b26986e9..c930d8c4c18feb101511e250f487fe3c151fa4da 100644 (file)
@@ -257,8 +257,8 @@ static int ft232r_init(void)
 {
        uint16_t avids[] = {ft232r_vid, 0};
        uint16_t apids[] = {ft232r_pid, 0};
-       const char *ft232r_serial_desc = adapter_get_required_serial();
-       if (jtag_libusb_open(avids, apids, ft232r_serial_desc, &adapter, NULL)) {
+       if (jtag_libusb_open(avids, apids, &adapter, NULL)) {
+               const char *ft232r_serial_desc = adapter_get_required_serial();
                LOG_ERROR("ft232r not found: vid=%04x, pid=%04x, serial=%s\n",
                        ft232r_vid, ft232r_pid, (!ft232r_serial_desc) ? "[any]" : ft232r_serial_desc);
                return ERROR_JTAG_INIT_FAILED;
index 0c5ccc6a7ee8fbb0237cbdc37dd2102bacd40523..5e2168eea50e227a75282234c26bc7929da80a49 100644 (file)
@@ -39,7 +39,6 @@
 
 #include <hidapi.h>
 
-#include <jtag/adapter.h>
 #include <jtag/interface.h>
 #include <jtag/swd.h>
 #include <jtag/commands.h>
@@ -271,8 +270,7 @@ static int kitprog_usb_open(void)
        const uint16_t vids[] = { VID, 0 };
        const uint16_t pids[] = { PID, 0 };
 
-       if (jtag_libusb_open(vids, pids, adapter_get_required_serial(),
-                       &kitprog_handle->usb_handle, NULL) != ERROR_OK) {
+       if (jtag_libusb_open(vids, pids, &kitprog_handle->usb_handle, NULL) != ERROR_OK) {
                LOG_ERROR("Failed to open or find the device");
                return ERROR_FAIL;
        }
index b8f1124e3b70ee4a6dd7239c0e152f6c051b155b..fc961cb915d39661d8e278e4201d0dd48462ea63 100644 (file)
@@ -157,7 +157,6 @@ static bool jtag_libusb_match_serial(struct libusb_device_handle *device,
 }
 
 int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[],
-               const char *serial,
                struct libusb_device_handle **out,
                adapter_get_alternate_serial_fn adapter_get_alternate_serial)
 {
@@ -165,6 +164,7 @@ int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[],
        int retval = ERROR_FAIL;
        bool serial_mismatch = false;
        struct libusb_device_handle *libusb_handle = NULL;
+       const char *serial = adapter_get_required_serial();
 
        if (libusb_init(&jtag_libusb_context) < 0)
                return ERROR_FAIL;
index 6087128d24a854acee3f5582c864793166091d0d..2ddb246b3d2f6ad47ec3202842d6e88271d5a4a8 100644 (file)
@@ -28,7 +28,6 @@ typedef char * (*adapter_get_alternate_serial_fn)(struct libusb_device_handle *d
                struct libusb_device_descriptor *dev_desc);
 
 int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[],
-               const char *serial,
                struct libusb_device_handle **out,
                adapter_get_alternate_serial_fn adapter_get_alternate_serial);
 void jtag_libusb_close(struct libusb_device_handle *dev);
index 6881959c33761a348ae410b8fcf71e0e14a8d1b0..ae21cf2b9b498e9f9e4fb39f663e72d507170828 100644 (file)
@@ -706,7 +706,7 @@ struct opendous_jtag *opendous_usb_open(void)
        struct opendous_jtag *result;
 
        struct libusb_device_handle *devh;
-       if (jtag_libusb_open(opendous_probe->VID, opendous_probe->PID, NULL, &devh, NULL) != ERROR_OK)
+       if (jtag_libusb_open(opendous_probe->VID, opendous_probe->PID, &devh, NULL) != ERROR_OK)
                return NULL;
 
        jtag_libusb_set_configuration(devh, 0);
index 7340119a1418714d16c7bdaaea8c8139a6090f9e..771b6e6f3ecd522ac913602135995adf9356e8cd 100644 (file)
@@ -449,7 +449,7 @@ static int openjtag_init_cy7c65215(void)
        int ret;
 
        usbh = NULL;
-       ret = jtag_libusb_open(cy7c65215_vids, cy7c65215_pids, NULL, &usbh, NULL);
+       ret = jtag_libusb_open(cy7c65215_vids, cy7c65215_pids, &usbh, NULL);
        if (ret != ERROR_OK) {
                LOG_ERROR("unable to open cy7c65215 device");
                goto err;
index 5c43d32445115914f1a63edce78f5d40790529ec..f7665eb12b6edc9d629af999f443b7ab4915f48d 100644 (file)
@@ -374,7 +374,7 @@ static int osbdm_flush(struct osbdm *osbdm, struct queue *queue)
 static int osbdm_open(struct osbdm *osbdm)
 {
        (void)memset(osbdm, 0, sizeof(*osbdm));
-       if (jtag_libusb_open(osbdm_vid, osbdm_pid, NULL, &osbdm->devh, NULL) != ERROR_OK)
+       if (jtag_libusb_open(osbdm_vid, osbdm_pid, &osbdm->devh, NULL) != ERROR_OK)
                return ERROR_FAIL;
 
        if (libusb_claim_interface(osbdm->devh, 0) != ERROR_OK)
index f75a38b5d22f02c36814edf8e1cfe0bb483dd057..73be3c57e624a6c43e966ad45e61e9ad390a8c7a 100644 (file)
@@ -1461,7 +1461,7 @@ static int rlink_init(void)
 
        const uint16_t vids[] = { USB_IDVENDOR, 0 };
        const uint16_t pids[] = { USB_IDPRODUCT, 0 };
-       if (jtag_libusb_open(vids, pids, NULL, &hdev, NULL) != ERROR_OK)
+       if (jtag_libusb_open(vids, pids, &hdev, NULL) != ERROR_OK)
                return ERROR_FAIL;
 
        struct libusb_device_descriptor descriptor;
index 4c0e025fc5f9522097caf039d469f10de9a930b6..2f61bf946266133b4afbdf76751ea6a038db8561 100644 (file)
@@ -3364,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, adapter_get_required_serial(),
+               if (jtag_libusb_open(param->vid, param->pid,
                                &h->usb_backend_priv.fd, stlink_usb_get_alternate_serial) != ERROR_OK) {
                        LOG_ERROR("open failed");
                        return ERROR_FAIL;
index a359dd17dceb6d7e40535675a155e24c22cca19f..c94a1102f25a1df227c393eb7191cf2efd328ed5 100644 (file)
@@ -686,7 +686,7 @@ static int icdi_usb_open(struct hl_interface_param_s *param, void **fd)
 
        /* TI (Stellaris) ICDI provides its serial number in the USB descriptor;
           no need to provide a callback here. */
-       jtag_libusb_open(param->vid, param->pid, adapter_get_required_serial(), &h->usb_dev, NULL);
+       jtag_libusb_open(param->vid, param->pid, &h->usb_dev, NULL);
 
        if (!h->usb_dev) {
                LOG_ERROR("open failed");
index d55bf85cd9e2e7e28bd00b81a0bd7c28c308f247..21f9ae72baaf16789b292b7b8887724092e7be5c 100644 (file)
@@ -210,7 +210,7 @@ static int ublast2_libusb_init(struct ublast_lowlevel *low)
        bool renumeration = false;
        int ret;
 
-       if (jtag_libusb_open(vids, pids, NULL, &temp, NULL) == ERROR_OK) {
+       if (jtag_libusb_open(vids, pids, &temp, NULL) == ERROR_OK) {
                LOG_INFO("Altera USB-Blaster II (uninitialized) found");
                LOG_INFO("Loading firmware...");
                ret = load_usb_blaster_firmware(temp, low);
@@ -224,15 +224,13 @@ static int ublast2_libusb_init(struct ublast_lowlevel *low)
        const uint16_t pids_renum[] = { low->ublast_pid, 0 };
 
        if (renumeration == false) {
-               if (jtag_libusb_open(vids_renum, pids_renum, NULL,
-                               &low->libusb_dev, NULL) != ERROR_OK) {
+               if (jtag_libusb_open(vids_renum, pids_renum, &low->libusb_dev, NULL) != ERROR_OK) {
                        LOG_ERROR("Altera USB-Blaster II not found");
                        return ERROR_FAIL;
                }
        } else {
                int retry = 10;
-               while (jtag_libusb_open(vids_renum, pids_renum, NULL,
-                               &low->libusb_dev, NULL) != ERROR_OK && retry--) {
+               while (jtag_libusb_open(vids_renum, pids_renum, &low->libusb_dev, NULL) != ERROR_OK && retry--) {
                        usleep(1000000);
                        LOG_INFO("Waiting for reenumerate...");
                }
index 44db61ec095d0c29bbb6c23b66c76393b75d2cbe..a2ebdbc86a771fb84445032df194e3828359acd5 100644 (file)
@@ -354,7 +354,7 @@ struct usbprog_jtag *usbprog_jtag_open(void)
        const uint16_t pids[] = { PID, 0 };
        struct libusb_device_handle *dev;
 
-       if (jtag_libusb_open(vids, pids, NULL, &dev, NULL) != ERROR_OK)
+       if (jtag_libusb_open(vids, pids, &dev, NULL) != ERROR_OK)
                return NULL;
 
        struct usbprog_jtag *tmp = malloc(sizeof(struct usbprog_jtag));

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)