jlink: add usb location support 96/4596/10
authorOleksij Rempel <o.rempel@pengutronix.de>
Wed, 4 Jul 2018 14:40:58 +0000 (16:40 +0200)
committerTomas Vanek <vanekt@fbl.cz>
Fri, 31 May 2019 07:49:38 +0000 (08:49 +0100)
this patch needs latest extended libjaylink version

Change-Id: Ib688ba18740717ccce7863e08c09425975b5f153
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Signed-off-by: Marc Schink <openocd-dev@marcschink.de>
Reviewed-on: http://openocd.zylin.com/4596
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
src/jtag/drivers/jlink.c

index cc04953cd690d15fec1b6b3c0f9841f4111ad969..8ce7c0d22fda8a39e24961da5706292654160164 100644 (file)
@@ -38,6 +38,7 @@
 #include <jtag/interface.h>
 #include <jtag/swd.h>
 #include <jtag/commands.h>
+#include <jtag/drivers/jtag_usb_common.h>
 
 #include <libjaylink/libjaylink.h>
 
@@ -50,6 +51,7 @@ static uint8_t caps[JAYLINK_DEV_EXT_CAPS_SIZE];
 
 static uint32_t serial_number;
 static bool use_serial_number;
+static bool use_usb_location;
 static enum jaylink_usb_address usb_address;
 static bool use_usb_address;
 static enum jaylink_target_interface iface = JAYLINK_TIF_JTAG;
@@ -534,6 +536,31 @@ static int jaylink_log_handler(const struct jaylink_context *ctx,
        return 0;
 }
 
+static bool jlink_usb_location_equal(struct jaylink_device *dev)
+{
+       int retval;
+       uint8_t bus;
+       uint8_t *ports;
+       size_t num_ports;
+       bool equal = false;
+
+       retval = jaylink_device_get_usb_bus_ports(dev, &bus, &ports, &num_ports);
+
+       if (retval == JAYLINK_ERR_NOT_SUPPORTED) {
+               return false;
+       } else if (retval != JAYLINK_OK) {
+               LOG_WARNING("jaylink_device_get_usb_bus_ports() failed: %s.",
+                       jaylink_strerror(retval));
+               return false;
+       }
+
+       equal = jtag_usb_location_equal(bus, ports,     num_ports);
+       free(ports);
+
+       return equal;
+}
+
+
 static int jlink_init(void)
 {
        int ret;
@@ -595,7 +622,9 @@ static int jlink_init(void)
                return ERROR_JTAG_INIT_FAILED;
        }
 
-       if (!use_serial_number && !use_usb_address && num_devices > 1) {
+       use_usb_location = (jtag_usb_get_location() != NULL);
+
+       if (!use_serial_number && !use_usb_address && !use_usb_location && num_devices > 1) {
                LOG_ERROR("Multiple devices found, specify the desired device.");
                jaylink_free_devices(devs, true);
                jaylink_exit(jayctx);
@@ -605,8 +634,10 @@ static int jlink_init(void)
        found_device = false;
 
        for (i = 0; devs[i]; i++) {
+               struct jaylink_device *dev = devs[i];
+
                if (use_serial_number) {
-                       ret = jaylink_device_get_serial_number(devs[i], &tmp);
+                       ret = jaylink_device_get_serial_number(dev, &tmp);
 
                        if (ret == JAYLINK_ERR_NOT_AVAILABLE) {
                                continue;
@@ -621,7 +652,7 @@ static int jlink_init(void)
                }
 
                if (use_usb_address) {
-                       ret = jaylink_device_get_usb_address(devs[i], &address);
+                       ret = jaylink_device_get_usb_address(dev, &address);
 
                        if (ret == JAYLINK_ERR_NOT_SUPPORTED) {
                                continue;
@@ -635,7 +666,10 @@ static int jlink_init(void)
                                continue;
                }
 
-               ret = jaylink_open(devs[i], &devh);
+               if (use_usb_location && !jlink_usb_location_equal(dev))
+                       continue;
+
+               ret = jaylink_open(dev, &devh);
 
                if (ret == JAYLINK_OK) {
                        found_device = true;

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)