From: OpenOCD-Gerrit <ope...@us...> - 2020-07-13 23:40:52
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via 68611efcdf50327ebeccc8f2533380dc4d9fbf40 (commit) via 97b710131693bdcfdc112e4c183d8e65bd909e94 (commit) via e466f389a9f0e824d62c5ed6092507a2812427b7 (commit) from 3a5f84f8187ce5b473f0eaafa0d68d1ab23ec0cd (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 68611efcdf50327ebeccc8f2533380dc4d9fbf40 Author: Antonio Borneo <bor...@gm...> Date: Mon Jun 29 23:58:09 2020 +0200 cmsis-dap: fix USB interface for NXP LPC-Link2 The adapter NXP LPC-Link2 is a USB composite device that provides five interfaces; among three of them that are of HID class, only one is cmsis-dap. Accordingly to ticket 255, OpenOCD code is not opening the right HID interface; then it fails to communicate with the cmsis-dap while checking the adapter's info. Unfortunately, hidapi does not provide any support for reading the string descriptor of the interface, otherwise it would have been trivial to look for the right cmsis-dap interface. In fact the cmsis-dap specification reports: The CMSIS-DAP Firmware can be also part of a USB composite device. If this case, the HID Interface String must contain the sub-string CMSIS-DAP. This requirement is satisfied by the USB device descriptor of the LPC-Link2 reported below, but cannot be used. Add a quirk to let OpenOCD only accept interface number zero on a LPC-Link2 device. Bus 001 Device 050: ID 1fc9:0090 NXP Semiconductors Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.00 bDeviceClass 239 Miscellaneous Device bDeviceSubClass 2 bDeviceProtocol 1 Interface Association bMaxPacketSize0 64 idVendor 0x1fc9 NXP Semiconductors idProduct 0x0090 bcdDevice 1.00 iManufacturer 1 NXP Semiconductors iProduct 2 LPC-LINK2 CMSIS-DAP V5.224 iSerial 3 I3F4AABA bNumConfigurations 1 Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 0x00ab bNumInterfaces 5 bConfigurationValue 1 iConfiguration 0 bmAttributes 0x80 (Bus Powered) MaxPower 500mA Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 0 bAlternateSetting 0 bNumEndpoints 2 bInterfaceClass 3 Human Interface Device bInterfaceSubClass 0 bInterfaceProtocol 0 iInterface 4 LPC-LINK2 CMSIS-DAP V5.224 HID Device Descriptor: bLength 9 bDescriptorType 33 bcdHID 1.00 bCountryCode 0 Not supported bNumDescriptors 1 bDescriptorType 34 Report wDescriptorLength 35 Report Descriptors: ** UNAVAILABLE ** Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0400 1x 1024 bytes bInterval 4 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x01 EP 1 OUT bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0400 1x 1024 bytes bInterval 4 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 4 bAlternateSetting 0 bNumEndpoints 2 bInterfaceClass 3 Human Interface Device bInterfaceSubClass 0 bInterfaceProtocol 0 iInterface 7 LPC-LINK2 DATA PORT HID Device Descriptor: bLength 9 bDescriptorType 33 bcdHID 1.00 bCountryCode 0 Not supported bNumDescriptors 1 bDescriptorType 34 Report wDescriptorLength 35 Report Descriptors: ** UNAVAILABLE ** Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x84 EP 4 IN bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0400 1x 1024 bytes bInterval 1 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x04 EP 4 OUT bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0400 1x 1024 bytes bInterval 1 Interface Association: bLength 8 bDescriptorType 11 bFirstInterface 1 bInterfaceCount 2 bFunctionClass 2 Communications bFunctionSubClass 2 Abstract (modem) bFunctionProtocol 0 iFunction 5 VCOM Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 0 bNumEndpoints 1 bInterfaceClass 2 Communications bInterfaceSubClass 2 Abstract (modem) bInterfaceProtocol 0 iInterface 5 VCOM CDC Header: bcdCDC 1.10 CDC Call Management: bmCapabilities 0x01 call management bDataInterface 2 CDC ACM: bmCapabilities 0x02 line coding and serial state CDC Union: bMasterInterface 1 bSlaveInterface 2 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x83 EP 3 IN bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0010 1x 16 bytes bInterval 4 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 2 bAlternateSetting 0 bNumEndpoints 2 bInterfaceClass 10 CDC Data bInterfaceSubClass 0 bInterfaceProtocol 0 iInterface 5 VCOM Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x02 EP 2 OUT bmAttributes 2 Transfer Type Bulk Synch Type None Usage Type Data wMaxPacketSize 0x0200 1x 512 bytes bInterval 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x82 EP 2 IN bmAttributes 2 Transfer Type Bulk Synch Type None Usage Type Data wMaxPacketSize 0x0200 1x 512 bytes bInterval 0 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 3 bAlternateSetting 0 bNumEndpoints 2 bInterfaceClass 3 Human Interface Device bInterfaceSubClass 0 bInterfaceProtocol 0 iInterface 6 LPCSIO HID Device Descriptor: bLength 9 bDescriptorType 33 bcdHID 1.11 bCountryCode 0 Not supported bNumDescriptors 1 bDescriptorType 34 Report wDescriptorLength 33 Report Descriptors: ** UNAVAILABLE ** Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x85 EP 5 IN bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0040 1x 64 bytes bInterval 2 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x05 EP 5 OUT bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0040 1x 64 bytes bInterval 2 Device Qualifier (for other device speed): bLength 10 bDescriptorType 6 bcdUSB 2.00 bDeviceClass 0 bDeviceSubClass 0 bDeviceProtocol 0 bMaxPacketSize0 64 bNumConfigurations 1 Device Status: 0x0000 (Bus Powered) Change-Id: Ib3d46f87743a2d35a266842cb356035d898d466e Signed-off-by: Antonio Borneo <bor...@gm...> Suggested-by: Masatoshi Tateishi <tat...@gm...> Reported-by: Donald Bailey <do...@us...> Fixes: https://sourceforge.net/p/openocd/tickets/255/ Reviewed-on: http://openocd.zylin.com/5732 Tested-by: jenkins diff --git a/src/jtag/drivers/cmsis_dap_usb.c b/src/jtag/drivers/cmsis_dap_usb.c index 891583680..d87d0c9a5 100644 --- a/src/jtag/drivers/cmsis_dap_usb.c +++ b/src/jtag/drivers/cmsis_dap_usb.c @@ -270,6 +270,10 @@ static int cmsis_dap_usb_open(void) found = true; } + /* LPC-LINK2 has cmsis-dap on interface 0 and other HID functions on other interfaces */ + if (cur_dev->vendor_id == 0x1fc9 && cur_dev->product_id == 0x0090 && cur_dev->interface_number != 0) + found = false; + if (found) { /* we have found an adapter, so exit further checks */ /* check serial number matches if given */ commit 97b710131693bdcfdc112e4c183d8e65bd909e94 Author: Antonio Borneo <bor...@gm...> Date: Mon Jun 29 23:22:37 2020 +0200 cmsis-dap: prevent hidapi to search again for the adapter The code in cmsis_dap_usb_open() already searches for the right HID device that corresponds to the adapter. By calling hid_open() it asks hidapi to re-search the adapter again based on the VID:PID and the serial string of the adapter it has just found! Apart from being a run-time overhead, this has an additional drawback; there are USB adapters built as composite USB devices that, beside the cmsis-dap HID interface, have other HID interfaces for other purposes. A typical example is the NXP LPC-Link2, that over the 5 interfaces 0) cmsis-dap (HID) 1) VCOM-CDC 2) VCOM-CDC 3) LPCSIO (HID) 4) LPC-LINK2 DATA PORT (HID) has 3 of them of HID class. The code in cmsis_dap_usb_open() could select the right interface but then cannot propagate this information to hid_open(). Replace the call to hid_open() with hid_open_path(), passing as parameter the "unique" path of the HID device already found. Checking in hidapi source code, the implementation of hid_open() consists in enumerating the HID devices, scan for the first one matching VID:PID and serial number, and opening it by calling hid_open_path(). This analysis highlights that using directly hid_open_path() should not introduce any regression. While applying these changes, move hid_init() before enumerating the HID devices. This has no real consequences because the HID API is marked as optional but, logically, it should be called before any other HID API. Change-Id: I77ec01dca64223ec597f21f188f363366d0049c6 Signed-off-by: Antonio Borneo <bor...@gm...> Suggested-by: Masatoshi Tateishi <tat...@gm...> Reviewed-on: http://openocd.zylin.com/5731 Tested-by: jenkins diff --git a/src/jtag/drivers/cmsis_dap_usb.c b/src/jtag/drivers/cmsis_dap_usb.c index ee1cb533c..891583680 100644 --- a/src/jtag/drivers/cmsis_dap_usb.c +++ b/src/jtag/drivers/cmsis_dap_usb.c @@ -229,14 +229,16 @@ static int cmsis_dap_usb_open(void) int i; struct hid_device_info *devs, *cur_dev; unsigned short target_vid, target_pid; - wchar_t *target_serial = NULL; - bool found = false; - bool serial_found = false; target_vid = 0; target_pid = 0; + if (hid_init() != 0) { + LOG_ERROR("unable to open HIDAPI"); + return ERROR_FAIL; + } + /* * The CMSIS-DAP specification stipulates: * "The Product String must contain "CMSIS-DAP" somewhere in the string. This is used by the @@ -273,7 +275,6 @@ static int cmsis_dap_usb_open(void) /* check serial number matches if given */ if (cmsis_dap_serial != NULL) { if ((cur_dev->serial_number != NULL) && wcscmp(cmsis_dap_serial, cur_dev->serial_number) == 0) { - serial_found = true; break; } } else @@ -288,23 +289,16 @@ static int cmsis_dap_usb_open(void) if (NULL != cur_dev) { target_vid = cur_dev->vendor_id; target_pid = cur_dev->product_id; - if (serial_found) - target_serial = cmsis_dap_serial; } - hid_free_enumeration(devs); - if (target_vid == 0 && target_pid == 0) { LOG_ERROR("unable to find CMSIS-DAP device"); + hid_free_enumeration(devs); return ERROR_FAIL; } - if (hid_init() != 0) { - LOG_ERROR("unable to open HIDAPI"); - return ERROR_FAIL; - } - - dev = hid_open(target_vid, target_pid, target_serial); + dev = hid_open_path(cur_dev->path); + hid_free_enumeration(devs); if (dev == NULL) { LOG_ERROR("unable to open CMSIS-DAP device 0x%x:0x%x", target_vid, target_pid); commit e466f389a9f0e824d62c5ed6092507a2812427b7 Author: Antonio Borneo <bor...@gm...> Date: Sun Jun 28 23:19:23 2020 +0200 jtag/drivers: replace perror() with LOG_ERROR() The function perror() sends the output to stderr, but OpenOCD cannot intercept such output to send it to the log. Replace all occurrences of perror() with LOG_ERROR(), but keeping the same output format of perror(). The replacement is done automatically through: sed -i 's/perror("\([^":]*\)[: ]*")/LOG_ERROR("\1: %s", strerror(errno))/' src/jtag/drivers/*.c Change-Id: I4c140bdb09235d56cfd8bef75da9b56fbe7c2aec Signed-off-by: Antonio Borneo <bor...@gm...> Reviewed-on: http://openocd.zylin.com/5728 Tested-by: jenkins diff --git a/src/jtag/drivers/at91rm9200.c b/src/jtag/drivers/at91rm9200.c index 1026847fe..bccb9bb23 100644 --- a/src/jtag/drivers/at91rm9200.c +++ b/src/jtag/drivers/at91rm9200.c @@ -231,14 +231,14 @@ static int at91rm9200_init(void) dev_mem_fd = open("/dev/mem", O_RDWR | O_SYNC); if (dev_mem_fd < 0) { - perror("open"); + LOG_ERROR("open: %s", strerror(errno)); return ERROR_JTAG_INIT_FAILED; } sys_controller = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, dev_mem_fd, AT91C_BASE_SYS); if (sys_controller == MAP_FAILED) { - perror("mmap"); + LOG_ERROR("mmap: %s", strerror(errno)); close(dev_mem_fd); return ERROR_JTAG_INIT_FAILED; } diff --git a/src/jtag/drivers/bcm2835gpio.c b/src/jtag/drivers/bcm2835gpio.c index f868516d9..40cb5aa0b 100644 --- a/src/jtag/drivers/bcm2835gpio.c +++ b/src/jtag/drivers/bcm2835gpio.c @@ -473,7 +473,7 @@ static int bcm2835gpio_init(void) dev_mem_fd = open("/dev/mem", O_RDWR | O_SYNC); } if (dev_mem_fd < 0) { - perror("open"); + LOG_ERROR("open: %s", strerror(errno)); return ERROR_JTAG_INIT_FAILED; } @@ -481,7 +481,7 @@ static int bcm2835gpio_init(void) MAP_SHARED, dev_mem_fd, BCM2835_GPIO_BASE); if (pio_base == MAP_FAILED) { - perror("mmap"); + LOG_ERROR("mmap: %s", strerror(errno)); close(dev_mem_fd); return ERROR_JTAG_INIT_FAILED; } @@ -491,7 +491,7 @@ static int bcm2835gpio_init(void) MAP_SHARED, dev_mem_fd, BCM2835_PADS_GPIO_0_27); if (pads_base == MAP_FAILED) { - perror("mmap"); + LOG_ERROR("mmap: %s", strerror(errno)); close(dev_mem_fd); return ERROR_JTAG_INIT_FAILED; } diff --git a/src/jtag/drivers/ep93xx.c b/src/jtag/drivers/ep93xx.c index 5e0e62afa..94d65505f 100644 --- a/src/jtag/drivers/ep93xx.c +++ b/src/jtag/drivers/ep93xx.c @@ -127,7 +127,7 @@ static int set_gonk_mode(void) syscon = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, dev_mem_fd, 0x80930000); if (syscon == MAP_FAILED) { - perror("mmap"); + LOG_ERROR("mmap: %s", strerror(errno)); return ERROR_JTAG_INIT_FAILED; } @@ -151,14 +151,14 @@ static int ep93xx_init(void) dev_mem_fd = open("/dev/mem", O_RDWR | O_SYNC); if (dev_mem_fd < 0) { - perror("open"); + LOG_ERROR("open: %s", strerror(errno)); return ERROR_JTAG_INIT_FAILED; } gpio_controller = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, dev_mem_fd, 0x80840000); if (gpio_controller == MAP_FAILED) { - perror("mmap"); + LOG_ERROR("mmap: %s", strerror(errno)); close(dev_mem_fd); return ERROR_JTAG_INIT_FAILED; } diff --git a/src/jtag/drivers/imx_gpio.c b/src/jtag/drivers/imx_gpio.c index c80e84218..39b463d31 100644 --- a/src/jtag/drivers/imx_gpio.c +++ b/src/jtag/drivers/imx_gpio.c @@ -491,7 +491,7 @@ static int imx_gpio_init(void) dev_mem_fd = open("/dev/mem", O_RDWR | O_SYNC); if (dev_mem_fd < 0) { - perror("open"); + LOG_ERROR("open: %s", strerror(errno)); return ERROR_JTAG_INIT_FAILED; } @@ -502,7 +502,7 @@ static int imx_gpio_init(void) MAP_SHARED, dev_mem_fd, imx_gpio_peri_base); if (pio_base == MAP_FAILED) { - perror("mmap"); + LOG_ERROR("mmap: %s", strerror(errno)); close(dev_mem_fd); return ERROR_JTAG_INIT_FAILED; } diff --git a/src/jtag/drivers/sysfsgpio.c b/src/jtag/drivers/sysfsgpio.c index d9fd7756a..e16076942 100644 --- a/src/jtag/drivers/sysfsgpio.c +++ b/src/jtag/drivers/sysfsgpio.c @@ -127,7 +127,7 @@ static int setup_sysfs_gpio(int gpio, int is_output, int init_high) LOG_WARNING("gpio %d is already exported", gpio); } else { LOG_ERROR("Couldn't export gpio %d", gpio); - perror("sysfsgpio: "); + LOG_ERROR("sysfsgpio: %s", strerror(errno)); return ERROR_FAIL; } } @@ -147,7 +147,7 @@ static int setup_sysfs_gpio(int gpio, int is_output, int init_high) } if (ret < 0) { LOG_ERROR("Couldn't set direction for gpio %d", gpio); - perror("sysfsgpio: "); + LOG_ERROR("sysfsgpio: %s", strerror(errno)); unexport_sysfs_gpio(gpio); return ERROR_FAIL; } @@ -164,7 +164,7 @@ static int setup_sysfs_gpio(int gpio, int is_output, int init_high) } if (ret < 0) { LOG_ERROR("Couldn't open value for gpio %d", gpio); - perror("sysfsgpio: "); + LOG_ERROR("sysfsgpio: %s", strerror(errno)); unexport_sysfs_gpio(gpio); } @@ -208,7 +208,7 @@ static void sysfsgpio_swdio_drive(bool is_output) ret = open_write_close(buf, is_output ? "high" : "in"); if (ret < 0) { LOG_ERROR("Couldn't set direction for gpio %d", swdio_gpio); - perror("sysfsgpio: "); + LOG_ERROR("sysfsgpio: %s", strerror(errno)); } last_stored = false; ----------------------------------------------------------------------- Summary of changes: src/jtag/drivers/at91rm9200.c | 4 ++-- src/jtag/drivers/bcm2835gpio.c | 6 +++--- src/jtag/drivers/cmsis_dap_usb.c | 26 ++++++++++++-------------- src/jtag/drivers/ep93xx.c | 6 +++--- src/jtag/drivers/imx_gpio.c | 4 ++-- src/jtag/drivers/sysfsgpio.c | 8 ++++---- 6 files changed, 26 insertions(+), 28 deletions(-) hooks/post-receive -- Main OpenOCD repository |