jlink: add support for Jlink-OB (0x0105) devices 31/2031/3
authorAndrey Yurovsky <yurovsky@gmail.com>
Sat, 8 Mar 2014 01:16:52 +0000 (17:16 -0800)
committerPaul Fertser <fercerpav@gmail.com>
Sat, 29 Mar 2014 07:12:42 +0000 (07:12 +0000)
The JLink-OB (onboard) devices work the same way as the normal JLink
except that their PID is 0x0105 (and that's the only one we know of so
far) and their endpoint addresses are different due to there being a
CDC-ACM interface as well.  These JLink-OB devices show up on a lot of
vendors' development kits as an integrated debugger.

This change simply checks whether the adapter we opened has a JLink-OB
PID and, if it does, uses the JLink-OB endpoints rather than the
default.  To do this, we add a new routine, jtag_libusb_get_pid() to the
libusb adapter layer, it in turn just calls
libusb_get_device_descriptor(), which previously had no wrapper.

Also, checkpatch.pl doesn't like the VID/PID macros as defined so I
moved them to the array itself.  This should have no effect on the code.

This change adds the 0102 through 0104 PIDs to openocd.rules as well as this
new 0105 PID.

Tested on an Atmel SAM4S Xplained board which has a JLink-OB, also
regression tested by using a 0x0101 PID normal JLink adapter.

Signed-off-by: Andrey Yurovsky <yurovsky@gmail.com>
Change-Id: I121d30e57729cda3adb66e2a5dc72e1fcb7ef8b1
Reviewed-on: http://openocd.zylin.com/2031
Tested-by: jenkins
Reviewed-by: Xiaofan <xiaofanc@gmail.com>
Reviewed-by: Paul Fertser <fercerpav@gmail.com>
contrib/99-openocd.rules
src/jtag/drivers/jlink.c
src/jtag/drivers/libusb0_common.c
src/jtag/drivers/libusb0_common.h
src/jtag/drivers/libusb1_common.c
src/jtag/drivers/libusb1_common.h

index 44ab9cc87259ad7f1a48053324c0b32f3a8888a5..b5a5e68bd948745af184c33bcc9844c02b69e4b8 100644 (file)
@@ -77,6 +77,12 @@ ATTRS{idVendor}=="0fbb", ATTRS{idProduct}=="1000", MODE="664", GROUP="plugdev"
 
 # IAR J-Link USB
 ATTRS{idVendor}=="1366", ATTRS{idProduct}=="0101", MODE="664", GROUP="plugdev"
+ATTRS{idVendor}=="1366", ATTRS{idProduct}=="0102", MODE="664", GROUP="plugdev"
+ATTRS{idVendor}=="1366", ATTRS{idProduct}=="0103", MODE="664", GROUP="plugdev"
+ATTRS{idVendor}=="1366", ATTRS{idProduct}=="0104", MODE="664", GROUP="plugdev"
+
+# J-Link-OB (onboard)
+ATTRS{idVendor}=="1366", ATTRS{idProduct}=="0105", MODE="664", GROUP="plugdev"
 
 # Raisonance RLink
 ATTRS{idVendor}=="138e", ATTRS{idProduct}=="9000", MODE="664", GROUP="plugdev"
index 728a05b87b4590c4df6beda9a633b46c73a86ccd..029db38c93e79e67abfbecc93a165e673001bb73 100644 (file)
  * pid = ( usb_address > 0x4) ? 0x0101 : (0x101 + usb_address)
  */
 
-#define VID 0x1366, 0x1366, 0x1366, 0x1366
-#define PID 0x0101, 0x0102, 0x0103, 0x0104
+#define JLINK_OB_PID  0x0105
 
 #define JLINK_WRITE_ENDPOINT   0x02
 #define JLINK_READ_ENDPOINT            0x81
 
+#define JLINK_OB_WRITE_ENDPOINT        0x06
+#define JLINK_OB_READ_ENDPOINT 0x85
+
 static unsigned int jlink_write_ep = JLINK_WRITE_ENDPOINT;
 static unsigned int jlink_read_ep = JLINK_READ_ENDPOINT;
 static unsigned int jlink_hw_jtag_version = 2;
@@ -246,8 +248,8 @@ static enum tap_state jlink_last_state = TAP_RESET;
 static struct jlink *jlink_handle;
 
 /* pid could be specified at runtime */
-static uint16_t vids[] = { VID, 0 };
-static uint16_t pids[] = { PID, 0 };
+static uint16_t vids[] = { 0x1366, 0x1366, 0x1366, 0x1366, 0x1366, 0 };
+static uint16_t pids[] = { 0x0101, 0x0102, 0x0103, 0x0104, 0x0105, 0 };
 
 static uint32_t jlink_caps;
 static uint32_t jlink_hw_type;
@@ -1517,6 +1519,15 @@ static struct jlink *jlink_usb_open()
        usb_set_altinterface(result->usb_handle, 0);
 #endif
 
+       /* Use the OB endpoints if the JLink we matched is a Jlink-OB adapter */
+       uint16_t matched_pid;
+       if (jtag_libusb_get_pid(udev, &matched_pid) == ERROR_OK) {
+               if (matched_pid == JLINK_OB_PID) {
+                       jlink_read_ep = JLINK_OB_WRITE_ENDPOINT;
+                       jlink_write_ep = JLINK_OB_READ_ENDPOINT;
+               }
+       }
+
        jtag_libusb_get_endpoints(udev, &jlink_read_ep, &jlink_write_ep);
 
        struct jlink *result = malloc(sizeof(struct jlink));
index 32111195a9e220a1d9dd26aaad1b367cf8f31ca1..4b3bde1ec0a6c67d36c4d3f9704e8e2e755191ca 100644 (file)
@@ -122,3 +122,16 @@ int jtag_libusb_get_endpoints(struct jtag_libusb_device *udev,
 
        return 0;
 }
+
+int jtag_libusb_get_pid(struct jtag_libusb_device *dev, uint16_t *pid)
+{
+       struct libusb_device_descriptor dev_desc;
+
+       if (libusb_get_device_descriptor(dev, &dev_desc) == 0) {
+               *pid = dev_desc.idProduct;
+
+               return 0;
+       }
+
+       return -ENODEV;
+}
index bea743dcf5c5d9e59fcbb5300b49e513552a62e0..db247ad850d31d873561124ebeee59e051376a00 100644 (file)
@@ -68,5 +68,6 @@ int jtag_libusb_set_configuration(jtag_libusb_device_handle *devh,
 int jtag_libusb_get_endpoints(struct jtag_libusb_device *udev,
                unsigned int *usb_read_ep,
                unsigned int *usb_write_ep);
+int jtag_libusb_get_pid(struct jtag_libusb_device *dev, uint16_t *pid);
 
 #endif /* JTAG_USB_COMMON_H */
index c4478cb9b1ac99b863b91df87b2e9d017699a73c..81e8ca888728b8b5bc202dbb4924baaa27a35baa 100644 (file)
@@ -166,3 +166,16 @@ int jtag_libusb_get_endpoints(struct jtag_libusb_device *udev,
 
        return 0;
 }
+
+int jtag_libusb_get_pid(struct jtag_libusb_device *dev, uint16_t *pid)
+{
+       struct libusb_device_descriptor dev_desc;
+
+       if (libusb_get_device_descriptor(dev, &dev_desc) == 0) {
+               *pid = dev_desc.idProduct;
+
+               return 0;
+       }
+
+       return -ENODEV;
+}
index 0e653d845400d3b9c997713ad830a8e280f0259b..e33b83ad844c5b986e398875b3c5dbfbf503e572 100644 (file)
@@ -62,5 +62,6 @@ int jtag_libusb_set_configuration(jtag_libusb_device_handle *devh,
 int jtag_libusb_get_endpoints(struct jtag_libusb_device *udev,
                unsigned int *usb_read_ep,
                unsigned int *usb_write_ep);
+int jtag_libusb_get_pid(struct jtag_libusb_device *dev, uint16_t *pid);
 
 #endif /* JTAG_USB_COMMON_H */

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)