jtag/drivers: Extension of jtag_libusb_open 38/7938/3
authorEasyDevKits <info@easydevkits.com>
Sat, 14 Oct 2023 19:48:56 +0000 (21:48 +0200)
committerAntonio Borneo <borneo.antonio@gmail.com>
Wed, 25 Oct 2023 01:35:16 +0000 (01:35 +0000)
In jtag_libusb_open I've added a parameter for delivering the device
description for which this function should search and adjusted all
callers of this function. A new driver for WCH CH347 JTAG chips
will use this new parameter.
See also: https://review.openocd.org/c/openocd/+/7937

Change-Id: I85e1d7b1f7912ba5e223f0f26323ff3b7600e17d
Signed-off-by: EasyDevKits <info@easydevkits.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7938
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
15 files changed:
src/jtag/drivers/angie.c
src/jtag/drivers/arm-jtag-ew.c
src/jtag/drivers/esp_usb_jtag.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 9cc086599c31b29a1abec24f164a595120970898..b6bde5b3b91aad2ea77abe0ff8788234c5ee4d89 100644 (file)
@@ -257,7 +257,7 @@ static int angie_usb_open(struct angie *device)
        const uint16_t vids[] = {ANGIE_VID, ANGIE_VID, ANGIE_VID, ANGIE_VID, 0};
        const uint16_t pids[] = {ANGIE_PID, ANGIE_PID_2, ANGIE_PID_3, ANGIE_PID_4, 0};
 
-       int ret = jtag_libusb_open(vids, pids, &usb_device_handle, NULL);
+       int ret = jtag_libusb_open(vids, pids, NULL, &usb_device_handle, NULL);
 
        if (ret != ERROR_OK)
                return ret;
index a372720849db3809a0b66dca8908dbfc8d0473f5..eada67f45ccdbd6d3ec0483c1b0970726a288846 100644 (file)
@@ -677,7 +677,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, &dev, NULL) != ERROR_OK)
+       if (jtag_libusb_open(vids, pids, NULL, &dev, NULL) != ERROR_OK)
                return NULL;
 
        struct armjtagew *result = malloc(sizeof(struct armjtagew));
index 2ed0f58fd1e5e73b9687e4d42b7751340678d781..95040595439e6d8feef01a76aeef8841a8db1f14 100644 (file)
@@ -487,7 +487,7 @@ static int esp_usb_jtag_init(void)
        bitq_interface->in_rdy = esp_usb_jtag_in_rdy;
        bitq_interface->in = esp_usb_jtag_in;
 
-       int r = jtag_libusb_open(vids, pids, &priv->usb_device, NULL);
+       int r = jtag_libusb_open(vids, pids, NULL, &priv->usb_device, NULL);
        if (r != ERROR_OK) {
                LOG_ERROR("esp_usb_jtag: could not find or open device!");
                goto out;
index c2ec78ad8888df9f1c2ca25abb547b474b84005e..2d9d9ef34d029843b3b66db73749d9b194c0980d 100644 (file)
@@ -246,7 +246,7 @@ static int ft232r_init(void)
 {
        uint16_t avids[] = {ft232r_vid, 0};
        uint16_t apids[] = {ft232r_pid, 0};
-       if (jtag_libusb_open(avids, apids, &adapter, NULL)) {
+       if (jtag_libusb_open(avids, apids, NULL, &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);
index b953218b855c63710333eb73157a013a5f775286..e126a9c22b67bc2d5fbc32e00d50c1e95936800e 100644 (file)
@@ -275,7 +275,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, &kitprog_handle->usb_handle, NULL) != ERROR_OK) {
+       if (jtag_libusb_open(vids, pids, NULL, &kitprog_handle->usb_handle, NULL) != ERROR_OK) {
                LOG_ERROR("Failed to open or find the device");
                return ERROR_FAIL;
        }
index c77fe78c28ea3b9f4c141be1238449c2a0d87776..9d788ee3944b906e7a8a26f0fd7679157ee4b017 100644 (file)
@@ -146,12 +146,13 @@ static bool jtag_libusb_match_serial(struct libusb_device_handle *device,
 }
 
 int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[],
-               struct libusb_device_handle **out,
+               const char *product, struct libusb_device_handle **out,
                adapter_get_alternate_serial_fn adapter_get_alternate_serial)
 {
        int cnt, idx, err_code;
        int retval = ERROR_FAIL;
        bool serial_mismatch = false;
+       bool product_mismatch = false;
        struct libusb_device_handle *libusb_handle = NULL;
        const char *serial = adapter_get_required_serial();
 
@@ -188,10 +189,18 @@ int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[],
                        continue;
                }
 
+               if (product &&
+                               !string_descriptor_equal(libusb_handle, dev_desc.iProduct, product)) {
+                       product_mismatch = true;
+                       libusb_close(libusb_handle);
+                       continue;
+               }
+
                /* Success. */
                *out = libusb_handle;
                retval = ERROR_OK;
                serial_mismatch = false;
+               product_mismatch = false;
                break;
        }
        if (cnt >= 0)
@@ -200,6 +209,9 @@ int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[],
        if (serial_mismatch)
                LOG_INFO("No device matches the serial string");
 
+       if (product_mismatch)
+               LOG_INFO("No device matches the product string");
+
        if (retval != ERROR_OK)
                libusb_exit(jtag_libusb_context);
 
index 75f133519a50f689ce4f325cb90aa2392c64b494..09309b40c2717b6bd8996693a6a47d44865761f3 100644 (file)
@@ -33,7 +33,7 @@ typedef char * (*adapter_get_alternate_serial_fn)(struct libusb_device_handle *d
 bool jtag_libusb_match_ids(struct libusb_device_descriptor *dev_desc,
                const uint16_t vids[], const uint16_t pids[]);
 int jtag_libusb_open(const uint16_t vids[], const uint16_t pids[],
-               struct libusb_device_handle **out,
+               const char *product, struct libusb_device_handle **out,
                adapter_get_alternate_serial_fn adapter_get_alternate_serial);
 void jtag_libusb_close(struct libusb_device_handle *dev);
 int jtag_libusb_control_transfer(struct libusb_device_handle *dev,
index 2e1d648147bc011df341d531f27a202d220f56eb..4d9fd998a7bc165bf02b6c5cac01dcce0066e9b8 100644 (file)
@@ -695,7 +695,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, &devh, NULL) != ERROR_OK)
+       if (jtag_libusb_open(opendous_probe->VID, opendous_probe->PID, NULL, &devh, NULL) != ERROR_OK)
                return NULL;
 
        jtag_libusb_set_configuration(devh, 0);
index fe3a8ff7f9ac042a7b243963708dd22a4f85f225..dca27b0a6444f756e9f6c69309d0e3c2759d338e 100644 (file)
@@ -438,7 +438,7 @@ static int openjtag_init_cy7c65215(void)
        int ret;
 
        usbh = NULL;
-       ret = jtag_libusb_open(cy7c65215_vids, cy7c65215_pids, &usbh, NULL);
+       ret = jtag_libusb_open(cy7c65215_vids, cy7c65215_pids, NULL, &usbh, NULL);
        if (ret != ERROR_OK) {
                LOG_ERROR("unable to open cy7c65215 device");
                goto err;
index d8fe7135e72bced3958391fb12bef70d95b2ddd3..84f2fd66a0d48d301851fb8de716665f33947047 100644 (file)
@@ -363,7 +363,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, &osbdm->devh, NULL) != ERROR_OK)
+       if (jtag_libusb_open(osbdm_vid, osbdm_pid, NULL, &osbdm->devh, NULL) != ERROR_OK)
                return ERROR_FAIL;
 
        if (libusb_claim_interface(osbdm->devh, 0) != ERROR_OK)
index 65f7494bd9cf956d519dae1906938a12ece66dfa..a28e76e013db2f04fb4d8253b674f1fe4a689cb0 100644 (file)
@@ -1448,7 +1448,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, &hdev, NULL) != ERROR_OK)
+       if (jtag_libusb_open(vids, pids, NULL, &hdev, NULL) != ERROR_OK)
                return ERROR_FAIL;
 
        struct libusb_device_descriptor descriptor;
index c5326a206aa031ca07093404baf07308f69fa1be..b14fbf1f38ec5c87c6ab13a8f676bca58284e5af 100644 (file)
@@ -3406,7 +3406,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,
+               if (jtag_libusb_open(param->vid, param->pid, NULL,
                                &h->usb_backend_priv.fd, stlink_usb_get_alternate_serial) != ERROR_OK) {
                        LOG_ERROR("open failed");
                        return ERROR_FAIL;
index 3e36218738ec8d574961c12fecea453d97af2035..4260e2d39db23ca3501765c074979185190ce1f7 100644 (file)
@@ -675,7 +675,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, &h->usb_dev, NULL);
+       jtag_libusb_open(param->vid, param->pid, NULL, &h->usb_dev, NULL);
 
        if (!h->usb_dev) {
                LOG_ERROR("open failed");
index f5e0026a7ba31092c23e26b5b34407e9d27fd544..de0d2d8472d1aae57580dbc81e61414949eab8f8 100644 (file)
@@ -202,7 +202,7 @@ static int ublast2_libusb_init(struct ublast_lowlevel *low)
        bool renumeration = false;
        int ret;
 
-       if (jtag_libusb_open(vids, pids, &temp, NULL) == ERROR_OK) {
+       if (jtag_libusb_open(vids, pids, NULL, &temp, NULL) == ERROR_OK) {
                LOG_INFO("Altera USB-Blaster II (uninitialized) found");
                LOG_INFO("Loading firmware...");
                ret = load_usb_blaster_firmware(temp, low);
@@ -216,13 +216,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, &low->libusb_dev, NULL) != ERROR_OK) {
+               if (jtag_libusb_open(vids_renum, pids_renum, NULL, &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, &low->libusb_dev, NULL) != ERROR_OK && retry--) {
+               while (jtag_libusb_open(vids_renum, pids_renum, NULL, &low->libusb_dev, NULL) != ERROR_OK && retry--) {
                        usleep(1000000);
                        LOG_INFO("Waiting for reenumerate...");
                }
index 5d41656b4f563719a0787e1ef9297ed5fceecb33..aa655ed7e607290b04424b7bdccad4f94de0260c 100644 (file)
@@ -341,7 +341,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, &dev, NULL) != ERROR_OK)
+       if (jtag_libusb_open(vids, pids, NULL, &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)