drivers/ftdi: prevent misleading error msg when more vid/pids configured 29/7529/2
authorTomas Vanek <vanekt@fbl.cz>
Mon, 6 Mar 2023 14:37:43 +0000 (15:37 +0100)
committerTomas Vanek <vanekt@fbl.cz>
Sat, 18 Mar 2023 17:33:48 +0000 (17:33 +0000)
The driver tries to open mpsse engine for each vid pid
pair in sequence. If more vid/pid pairs are configured and
the USB device does not correspond to the first pair,
the driver shows 'unable to open ftdi device ...' error.

Match vid pid with the whole list as used in jtag_libusb_open()
instead of multiple mpsse_open() in for loop over vid/pid pairs.

Change-Id: I8ef55205be221c727607fe25b81ae21de0d96f02
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/7529
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Wolfram Sang <wsa@kernel.org>
src/jtag/drivers/ftdi.c
src/jtag/drivers/mpsse.c

index 3097d41296118058e8dc7a88013afa1f74fcfab8..6356a4929b11a34074f35b386c826136726b00d7 100644 (file)
@@ -658,13 +658,8 @@ static int ftdi_initialize(void)
                return ERROR_JTAG_INIT_FAILED;
        }
 
-       for (int i = 0; ftdi_vid[i] || ftdi_pid[i]; i++) {
-               mpsse_ctx = mpsse_open(&ftdi_vid[i], &ftdi_pid[i], ftdi_device_desc,
+       mpsse_ctx = mpsse_open(ftdi_vid, ftdi_pid, ftdi_device_desc,
                                adapter_get_required_serial(), adapter_usb_get_location(), ftdi_channel);
-               if (mpsse_ctx)
-                       break;
-       }
-
        if (!mpsse_ctx)
                return ERROR_JTAG_INIT_FAILED;
 
index 18aeb38a480b79c1a873ac9e8de748e41e114199..9f2fdde9fb77fe50810ab5e796df5bcb97692024 100644 (file)
@@ -13,6 +13,7 @@
 #include "helper/log.h"
 #include "helper/replacements.h"
 #include "helper/time_support.h"
+#include "libusb_helper.h"
 #include <libusb.h>
 
 /* Compatibility define for older libusb-1.0 */
@@ -148,7 +149,7 @@ static bool device_location_equal(struct libusb_device *device, const char *loca
  * Set any field to 0 as a wildcard. If the device is found true is returned, with ctx containing
  * the already opened handle. ctx->interface must be set to the desired interface (channel) number
  * prior to calling this function. */
-static bool open_matching_device(struct mpsse_ctx *ctx, const uint16_t *vid, const uint16_t *pid,
+static bool open_matching_device(struct mpsse_ctx *ctx, const uint16_t vids[], const uint16_t pids[],
        const char *product, const char *serial, const char *location)
 {
        struct libusb_device **list;
@@ -169,9 +170,7 @@ static bool open_matching_device(struct mpsse_ctx *ctx, const uint16_t *vid, con
                        continue;
                }
 
-               if (vid && *vid != desc.idVendor)
-                       continue;
-               if (pid && *pid != desc.idProduct)
+               if (!jtag_libusb_match_ids(&desc, vids, pids))
                        continue;
 
                err = libusb_open(device, &ctx->usb_dev);
@@ -203,7 +202,7 @@ static bool open_matching_device(struct mpsse_ctx *ctx, const uint16_t *vid, con
        libusb_free_device_list(list, 1);
 
        if (!found) {
-               LOG_ERROR("no device found");
+               /* The caller reports detailed error desc */
                return false;
        }
 
@@ -307,7 +306,7 @@ error:
        return false;
 }
 
-struct mpsse_ctx *mpsse_open(const uint16_t *vid, const uint16_t *pid, const char *description,
+struct mpsse_ctx *mpsse_open(const uint16_t vids[], const uint16_t pids[], const char *description,
        const char *serial, const char *location, int channel)
 {
        struct mpsse_ctx *ctx = calloc(1, sizeof(*ctx));
@@ -343,14 +342,9 @@ struct mpsse_ctx *mpsse_open(const uint16_t *vid, const uint16_t *pid, const cha
                goto error;
        }
 
-       if (!open_matching_device(ctx, vid, pid, description, serial, location)) {
-               /* Four hex digits plus terminating zero each */
-               char vidstr[5];
-               char pidstr[5];
-               LOG_ERROR("unable to open ftdi device with vid %s, pid %s, description '%s', "
+       if (!open_matching_device(ctx, vids, pids, description, serial, location)) {
+               LOG_ERROR("unable to open ftdi device with description '%s', "
                                "serial '%s' at bus location '%s'",
-                               vid ? sprintf(vidstr, "%04x", *vid), vidstr : "*",
-                               pid ? sprintf(pidstr, "%04x", *pid), pidstr : "*",
                                description ? description : "*",
                                serial ? serial : "*",
                                location ? location : "*");

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)