jtag/drivers: Extension of jtag_libusb_open 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>
stlink: increase stlink v2 max speed to 2.25 Mbps stlink v2 on Nucleo-64 board (e.g. NUCLEO-L476RG) has target SWO signal connected to STM32F103CB'S PA10, which is UART1_RX. UART1 within this MCU in theory can be configured to 4.5 Mbps baudrate, which means this is the upper limit supported by HW. As a confirmation BMP (Black Magic Probe) project also states in documentation that UART1 can be used with up to 4.5 Mbps baudrate. Tests have shown that configuring 4.5 Mbps baudrate on stlink v2 available on NUCLEO-L476RG board results in receiving corrupted data. Using 2.25 Mbps however allows to successfully receive all data from SWO. This makes sense in terms of STM32F103CB capabilities, since 2.25 Mbps is the next supported baudrate due to division by 2. Increase supported stlink v2 SWO speed from 2 to 2.25 Mbps. Tested with NUCLEO-L476RG: $ stm32l4x.tpiu configure -protocol uart \ -traceclk 80000000 -pin-freq 2250000 \ -output /dev/stdout $ stm32l4x.tpiu enable 2.25 Mbps speed confirmed with logic analyzer. Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev> Change-Id: Icbec04585664aba8b217e8f9a75458e577f7617f Reviewed-on: https://review.openocd.org/c/openocd/+/7848 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
jtag/stlink: add STLINK-V3PWR support STLINK-V3PWR is both a standalone debugger probe compatible with STLINK-V3 and a source measurement unit (SMU). Link: http://www.st.com/stlink-v3pwr This code adds support for the debugger probe functionality. Change-Id: Ib056e55722528f922c5574bb6fbf77e2f2b2b0c1 Signed-off-by: Laurent LEMELE <laurent.lemele@st.com> Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/7755 Tested-by: jenkins
jtag: drivers: with pointers, use NULL instead of 0 Don't compare pointers with 0, use NULL when needed. Don't assign pointer to 0, use NULL. Don't pass 0 ad pointer argument, pass NULL. While there, check for return value from malloc(), replace an assert() with a LOG_ERROR(), drop a useless cast. Detected through 'sparse' tool. Change-Id: Ia7cf52221b12198aba1a07ebdfaf57ce341d5699 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/7592 Tested-by: jenkins
openocd: fix SPDX tag format for files .c With the old checkpatch we cannot use the correct format for the SPDX tags in the file .c, in fact the C99 comments are not allowed and we had to use the block comment. With the new checkpatch, let's switch to the correct SPDX format. Change created automatically through the command: sed -i \ 's,^/\* *\(SPDX-License-Identifier: .*[^ ]\) *\*/$,// \1,' \ $(find src/ contrib/ -name \*.c) Change-Id: I6da16506baa7af718947562505dd49606d124171 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/7153 Tested-by: jenkins
openocd: src/jtag: replace the GPL-2.0-or-later license tag Replace the FSF boilerplate with the SPDX tag. The SPDX tag on files *.c is incorrect, as it should use the C99 single line comment using '//'. But current checkpatch doesn't allow C99 comments, so keep using standard C comments, by now. Change-Id: Ie873d12bb0fb838d0d6252e6b9ca3c2118853e9a Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/7069 Tested-by: jenkins
adiv6: use struct adiv5_ap->ap_num to contain the AP base address ADIv5 DAP can only have 256 AP, while ADIv6 can provide till 2**40 (1,099,511,627,776) AP per DAP. Reuse the field ap_num in struct adiv5_ap, currently used on ADIv5 to hold the ADIv5 AP number (apsel), to contain the ADIv6 AP base address. Convert struct adiv5_ap->ap_num to 64 bit and initialize it to DP_APSEL_INVALID for unused AP. Restrict dap_find_get_ap() to ADIv5 only. To be enhanced. On ADIv6, let dap_get_ap() return an already allocated AP, or allocate and return an unused AP. Add function is_ap_num_valid() and use it. Change-Id: Ib2fe8c7ec0d08393cd91c29fdac5d632dfc1e438 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6461 Reviewed-by: Daniel Goehring <dgoehrin@os.amperecomputing.com> Tested-by: jenkins
adiv6: add low level jtag transport swd and dap-direct are not implemented yet Split from change https://review.openocd.org/6077/ Change-Id: I6d73d8adf6a6090001c5d4771325fb1d63c45e3c Signed-off-by: Kevin Burke <kevinb@os.amperecomputing.com> Signed-off-by: Daniel Goehring <dgoehrin@os.amperecomputing.com> Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6459 Tested-by: jenkins
adiv6: re-organize mem_ap registers definition ADIv5 MEM-AP registers are a subset of ADIv6 MEM-AP registers and are located at different offset. To prepare for introducing ADIv6, add 'struct adiv5_dap *' as argument to ADIv5 registers macro. Check the ADI version and use the proper address. Both adapter drivers rshim and stlink are ADIv5 only, so let them use the ADIv5 macros only. Split from change https://review.openocd.org/6077/ Change-Id: Ib861ddcdab74637b2082cc9f2612dea0007d77b1 Signed-off-by: Kevin Burke <kevinb@os.amperecomputing.com> Signed-off-by: Daniel Goehring <dgoehrin@os.amperecomputing.com> Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6457 Tested-by: jenkins
stlink: manage TCP_BUSY status code when using RW MISC Change-Id: I4f9eed3781b549742565a3a8ac5245a4b94ceb53 Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6994 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
libusb_helper.h: Increase USB timeout When we debug a target that works as a USB device, halting the target causes the USB communication with the USB host to become unresponsive. The host will try to reconnect/reset/setup the unresponsive device during which communication with other devices on the same USB bus can get stalled for several seconds. If the JTAG adapter is on the same bus, we need to make sure openOCD will wait for packets at least as long as the host USB stack. Otherwise the USB stack might deliver a valid packet, but openOCD would ignore it due to the timeout. The xHCI spec uses 5 sec timeouts, so let's use that in openOCD with some margin. Use this value in all libusb calls. HID API might have a libusb backend and would probably be victim to the same bug, so it should use this timeout, too. Ticket: https://sourceforge.net/p/openocd/tickets/343/ Signed-off-by: Gabor Csapo <gaborcsapo@google.com> Change-Id: Ia3dc1356e676fe550f57a4c72f7a24ba296b6af2 Reviewed-on: https://review.openocd.org/c/openocd/+/6882 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
stlink: enable queuing with stlink-server API v3 ST-Link Server 2.1.0-1 fixes concurrency issue with RW_MISC command Starting from this version the ST-Link Server API is now v3. In this change we save the ST-Link Server version, and check if the API is greater or equal to 3 to enable the queuing. Change-Id: I239eb81024700514c607a269b66651f457206faa Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6876 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
drivers: call adapter_get_required_serial() in jtag_libusb_open() Now that adapter serial is handled independently from the adapter drivers, move inside jtag_libusb_open() the call to adapter_get_required_serial(), so every adapter that uses libusb will automagically get USB serial support. Extend the documentation to list the adapters involved. Change-Id: I75b3482d38f8ed3418329f3106c5e8b689fd460b Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6663 Tested-by: jenkins
jtag/hla, jtag/stlink: switch to command 'adapter serial' The driver hla defines the command 'hla_serial' to specify the serial string of the adapter. The driver st-link defines the command 'st-link serial' to specify the serial string of the adapter. Remove and deprecate the driver commands and use 'adapter serial'. Change-Id: I9505c398a77125b1ebf4ba71da7baf4d663b75be Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6657 Tested-by: jenkins
stlink (tcp): manage scattered stlink-server responses detected in ubuntu 20.04 sometimes, the stlink-server response could be segmented on multiple packets. this causes stlink_tcp_send_cmd to fail with the following msg: Error: failed to receive USB CMD response because the received_size < expected size to fix the issue, do recv in a loop till all data is received or timeout is reached. Change-Id: I46cc60c231b4cc52f150ead268f843bc60c41149 Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6671 Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com> Tested-by: jenkins
stlink: skip rw-misc commands with TCP server The main purpose of TCP server is to allow multiple clients to connect and share the same physical stlink. The commands RW MISC don't lock the communication between command and answer, thus cannot prevent another client to break this sequence. The commands are not supposed to be used in shared mode. Prevent the use of RW MISC commands on a (possibly) shared TCP backend. This degrades the overall performance, but the shared mode already adds its own overhead, so this is not really an issue. Change-Id: I713d912a269664859c8142932a9905d24b6d3caa Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6608 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
stlink: add support for rw-misc commands Firmware versions V2J32 and V3J2 introduce the commands RW-MISC to put in a single USB packet a sequence of mem_ap read/write. These commands provide a significant speed improvement while accessing the debug unit at scattered addresses. Add the low level commands and extend high level implementation. Skip for the moment the command to read the max number of items allowed by the firmware and use some hardcoded values. Change-Id: I8adc630cc0de733511e9d94533cbfe9f3b301a83 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6607 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
stlink: dequeue CSW write only if it doesn't change csw_default The stlink commands for buffer read/write carry the associated CSW value that has to be used. We can dequeue any CSW write request and add the CSW in the following buffer read/write. In preparation to next patch that uses stlink commands misc-rw (commands that don't handle CSW value), let's dequeue only those CSW write that don't change csw_default. Keep a local cache of last csw_default. Tag the queued CSW writes that change csw_default. Dequeue only the un-tagged CSW writes. On buffer read/write commands, limiting the dequeued CSW write surely adds a performance penalty. But csw_default is not changed often so the penalty is not significant. Change-Id: I538d257fe3c434fc97587846d759951384327f02 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6606 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
stlink: add support for native no_addr_incr commands Firmware versions V2J26 and V3J1 introduce the command STLINK_DEBUG_WRITEMEM_32BIT_NO_ADDR_INC Firmware versions V2J32 and V3J2 introduce the command STLINK_DEBUG_READMEM_32BIT_NO_ADDR_INC These new commands can provide speed improvement to Cortex-A memory download (its debug port use a FIFO for data transfer). Add the low level commands and extend high level implementation. Change-Id: I3b65acbeaec3bd305f5568b9ee4bc9495b113448 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6605 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
stlink: collapse consecutive mem AP r/w in a single command Detect a sequence of memory AP operations that can be issued as a single stlink command. This improves the data throughput during memory transfer. Change-Id: Ifa4488513346fc7cd0c9317b7d24ef510ccfd959 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6604 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>