aboutsummaryrefslogtreecommitdiff
path: root/src/jtag
AgeCommit message (Collapse)AuthorFilesLines
2020-07-26drivers/bitbang: blink LED on SWDAntonio Borneo1-0/+10
The blinking was implemented for JTAG only. Extend it to SWD. There is no error check on SWD exchange. Add a FIXME for further fix. Change-Id: I42a6708c54b1eefaf691e0fe09ca58c42b2764fd Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5771 Tested-by: jenkins
2020-07-26drivers/linuxgpiod: add ledAntonio Borneo1-1/+39
Bitbang interface allows having a LED on one of the GPIO. Let also linuxgpiod driver to specify and use the LED connection. Change-Id: Id3d8772ee1808b92354fd073ba3947bacd8253ef Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5770 Tested-by: jenkins
2020-07-26jtag: fix minor typosAntonio Borneo31-69/+69
Change-Id: I3a3370db438f8fd045fb22e7c9fff4e83794a3b7 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5767 Tested-by: jenkins
2020-07-26libjaylink: Update to 0.2.0 releaseMarc Schink1-0/+0
Change-Id: Ib53a98d0c715f91bdced1df6f157d2a50326fa8c Signed-off-by: Marc Schink <dev@zapb.de> Reviewed-on: http://openocd.zylin.com/5757 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2020-07-14cmsis-dap: fix USB interface for NXP LPC-Link2Antonio Borneo1-0/+4
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 <borneo.antonio@gmail.com> Suggested-by: Masatoshi Tateishi <tateishim3@gmail.com> Reported-by: Donald Bailey <donaldb@users.sourceforge.net> Fixes: https://sourceforge.net/p/openocd/tickets/255/ Reviewed-on: http://openocd.zylin.com/5732 Tested-by: jenkins
2020-07-14cmsis-dap: prevent hidapi to search again for the adapterAntonio Borneo1-14/+8
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 <borneo.antonio@gmail.com> Suggested-by: Masatoshi Tateishi <tateishim3@gmail.com> Reviewed-on: http://openocd.zylin.com/5731 Tested-by: jenkins
2020-07-14jtag/drivers: replace perror() with LOG_ERROR()Antonio Borneo5-14/+14
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 <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5728 Tested-by: jenkins
2020-07-14jtag/drivers: add linuxgpiod driverAntonio Borneo3-0/+609
New adapter driver for GPIO bitbanging over Linux GPIO descriptors through the library libgpiod. On Debian based distribution, the package libgpiod-dev is required for build. Change-Id: I1ce1a4f1ca79096d6d476b01b523c8c10f2cac07 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5559 Tested-by: jenkins
2020-07-14bcm2835gpio: enable only the transport specific gpioAntonio Borneo1-37/+53
Change-Id: Ice6744600079d5994d628bb3b782aa36e71f862e Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5558 Tested-by: jenkins
2020-07-14imx_gpio: enable only the transport specific gpioAntonio Borneo1-21/+25
Change-Id: Idb1fabbc1e9385f8c23b643584bf7863ea91ffbf Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5557 Tested-by: jenkins Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-07-14sysfsgpio: enable only the transport specific gpioAntonio Borneo1-42/+37
If the configuration file specifies both SWD and JTAG gpios, the current code request all of them. In case of overlap a warning is generated when the same gpio is released for the second time. Require and release only the gpio needed by the specified transport. Change-Id: I41a0970980ceeb559afa98ab34cfe93dffed2e1c Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5556 Tested-by: jenkins
2020-07-14bitbang: split jtag and swd operationsAntonio Borneo5-42/+33
The split in OpenOCD between SWD and JTAG has been already fully implemented. The bitbang driver still keeps a single API write() to drive the output lines. Introduce a new SWD specific API swd_write(). Move the existing SWD bitbang drivers to the new API by extracting the available conditional implementation. Cleanup some function prototype. Remove the now unused global swd_mode, handled implicitly. Rename bitbang_exchange() as bitbang_swd_exchange() to track its scope for SWD only. Change-Id: Ie53080b941cb1ac7a34a1f80bad8bee4e304454d Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5555 Tested-by: jenkins
2020-07-13bitbang: remove superfluous switch between jtag and swdAntonio Borneo5-18/+1
The SWD framework already takes care of switching between JTAG and SWD by calling driver's switch_seq() in swd_connect() and in swd_quit(); there is no need for the driver to force the switch again. Remove the extra switch between jtag and swd. Change-Id: I84de4bffb593374b96fce31951c6cc83f92d2578 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5554 Tested-by: jenkins
2020-07-13bitbang: document bitbang callbacksAntonio Borneo1-1/+9
Change-Id: I732c2eeb452f3ba8a2385d0e02fccbe86381812c Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5553 Tested-by: jenkins
2020-07-08coding style: add arguments to function prototypesAntonio Borneo2-4/+4
Issue identified by checkpatch script from Linux kernel v5.1 using the command find src/ -type f -exec ./tools/scripts/checkpatch.pl \ -q --types FUNCTION_ARGUMENTS -f {} \; This patch also fixes an incorrect function prototype in zy1000.c. ZY1000 minidriver implementation overrides the function arm11_run_instr_data_to_core_noack_inner(), but the prototype is not the same as in src/target/arm11_dbgtap.c and to avoid compile error it was changed also the prototype of the called function arm11_run_instr_data_to_core_noack_inner_default(). Change-Id: I476cda8cdb0e1e280795b3b43ca95c40d09e4a3d Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5630 Tested-by: jenkins Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
2020-07-08coding style: fix space separationAntonio Borneo2-20/+20
The checkpatch script from Linux kernel v5.1 complains about using space before comma, before semicolon and between function name and open parenthesis. Fix them! Issue identified using the command find src/ -type f -exec ./tools/scripts/checkpatch.pl \ -q --types SPACING -f {} \; The patch only changes amount and position of whitespace, thus the following commands show empty diff git diff -w git log -w -p git log -w --stat Change-Id: I1062051d7f97d59922847f5061c6d6811742d30e Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5627 Tested-by: jenkins
2020-07-08configure: split build of hla layoutsAntonio Borneo3-3/+9
Current hla driver supports two "layout": stlink and ti-icdi. The configure script allows to independently enable/disable the the two layout. But in reality by selecting only one of them the whole hla driver is built, including both "layouts". This is currently not a big issue because the dependencies of the two layout are the same (libusb), so we are sure that selecting one of them would permit to build both. This is going to change with the merge of a third "layout" for Nuvoton Nu-Link, because it would be based on hidapi. We need, at least, to decouple the build of libusb and hidapi "layouts". A full decouple of each "layout" is also welcome to match the selection done during configure. Introduce a new automake macro for each of the two "layout" and use them to conditionally build the "layout" files. Use the existing autoconf macros to conditionally compile the code that depends by the "layout". Change-Id: Ia20da7a260002a8d2af883425aa401b8920d3f36 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5719 Tested-by: jenkins
2020-07-08jtag/tcl: fix a double free of jim objectMikhail Rasputin1-2/+4
The Jim_SetResultFormatted() frees jim object earlier and the Jim_FreeNewObj() does it second time. It breaks the memory heap. To avoid it the Jim_IncrRefCount() + Jim_DecrRefCount() should be used instead of the Jim_FreeNewObj() call. Change-Id: Ifa5f38009b2d617624b5f27e916720888a3dbad9 Signed-off-by: Mikhail Rasputin <mikhail.godlike.rasputin@yandex.ru> Reviewed-on: http://openocd.zylin.com/5724 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2020-06-27jtag: drivers: xlnx-pcie-xvc: Add support for SWD mode.Moritz Fischer1-3/+213
Add support for SWD debug to the Xilinx XVC/PCIe driver. This is possible since the device is essentially a shift-register. So doing SWD vs JTAG is a matter of wiring things correctly on the RTL side (use TMS for SWDI, TDO for SWDO). The clang static checker doesn't find any new problems with this change. Change-Id: I3959e21440cd1036769e8e56a55e601d3e4aee9a Signed-off-by: Moritz Fischer <moritzf@google.com> Reviewed-on: http://openocd.zylin.com/5447 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2020-06-23libjaylink: Update to latest Git versionMarc Schink1-0/+0
This update is for testing the upcoming 0.2.0 release. Change-Id: I400b09eb3ead4306c83c7980c621124101aaef7e Signed-off-by: Marc Schink <dev@zapb.de> Reviewed-on: http://openocd.zylin.com/5723 Tested-by: jenkins Reviewed-by: Paul Fertser <fercerpav@gmail.com>
2020-06-18target/armv7m_trace: Calculate prescaler for external capture devicesMarc Schink1-7/+10
This fixes a regression introduced in "2dc88e1479f29ef0141b05bfcd907ad9a3e2d54c" Change-Id: I04dc19ed30118a4c499b83732700b2ee0fdb67b6 Signed-off-by: Marc Schink <dev@zapb.de> Reviewed-on: http://openocd.zylin.com/5610 Tested-by: jenkins Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
2020-06-14stlink: code factorization by introducing stlink_usb_exit_modeTarek BOCHKATI1-43/+24
Change-Id: I4abd6432c4ef969e382bfed96cd19a49d9610000 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com> Reviewed-on: http://openocd.zylin.com/5612 Tested-by: jenkins
2020-06-06jtag/tcl: fix memory leak in command 'irscan'Antonio Borneo1-4/+9
If the function parse_u64() fails, we jump to return, thus leaking the memory just allocated in 'v'. Issue identified by clang. Move earlier the call to parse_u64() and the associated test, before memory allocation. While there, fix a possible NULL pointer dereferencing in case the calloc() fails, by testing for allocation failure. Change-Id: I6a77ee17aceb282bbdfefe7cdafeba2e0e7012f1 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5692 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
2020-06-06libusb_helper: fix memory leak when no adapter is foundAntonio Borneo1-0/+3
When jtag_libusb_open() fails to find the adapter, it returns error but left libusb initialized causing memory leak of libusb internal data. Issue found with valgrind when no adapter or board is connected to the host, e.g. valgrind openocd -f board/st_nucleo_f4.cfg Close the libusb operations if jtag_libusb_open() has to return error. Change-Id: Ieb2f110be15705dafe80c099e7d83c07056c2a41 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5701 Tested-by: jenkins
2020-06-06jtag/drivers/bcm2835gpio: bcm2835gpio_init has been updatedtscn921-1/+5
For jtag/drivers/bcm2835gpio dev_mem_fd has been updated within bcm2835gpio_init with the add on of gpio to mem. This permits the access to memory of GPIO without the need for root access. For failed attempt, a fallback to original memory follows. It should be noted that any printed error is relative to original memory ("dev/mem"). Tested on EFM32GG12B390F board Change-Id: I4540bdf62fb3b91a51221e277881adfae138dcc5 Signed-off-by: tscn92 <tscn@kamstrup.com> Reviewed-on: http://openocd.zylin.com/5568 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2020-05-24helper/command: strip replicated command name in logAntonio Borneo1-3/+3
After commit 0840414f0e57 ("helper/command: do not replace new commands with ocd_ prefix"), the command name is present in argv[0], so there is no need to pass it directly. The current code causes the command name to be logged twice, once explicitly and then from the content of argv[0]: openocd -c 'debug_level 3; echo hello; shutdown' <snip> Debug: 13 3 command.c:142 script_debug(): command - echo echo hello <snip> Debug: 16 4 command.c:142 script_debug(): command - shutdown shutdown Remove the command name from the arguments of the function script_debug(). Change-Id: I57860774f450ff717ee71ef9dc07590549a84319 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5660 Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com> Tested-by: jenkins
2020-05-24stlink: fix open AP for v2j37 and v3j7Antonio Borneo1-4/+11
The new stlink firmware requires opening the AP before issuing any operation. In the current code we have a 'questionable' check about the core model to set the TAR autoincrement, that is issued without opening the AP, thus causing a STLINK_BAD_AP_ERROR. Modify the AP open API to handle this case and open AP#0 before the memory access to check the core model. Change-Id: I576955b5094bd41d63ff1fbad7b4fd9433253321 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reported-by: Andreas Bolsch <hyphen0break@gmail.com> Reviewed-on: http://openocd.zylin.com/5691 Tested-by: jenkins Reviewed-by: Andreas Bolsch <hyphen0break@gmail.com>
2020-05-24stlink: fix incorrectly returned error on v2j28Antonio Borneo1-1/+14
Firmware v2j28 introduces the API to open and close the AP, but closing AP always returns error 0x1d (STLINK_BAD_AP_ERROR). Ignore the error returned by the bogus firmware on closing AP. Change-Id: I992ddbf7acb10f1d376ed8f781eeb3344605b85d Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5683 Tested-by: jenkins
2020-05-24stlink: default dapdirect to SWD instead of JTAGAntonio Borneo1-1/+1
When the transport is not specified, OpenOCD uses the first listed by the selected adapter driver. The old HLA driver for stlink lists SWD as first. The new driver dapdirect instead lists JTAG, making more difficult a fallback to HLA when dapdirect is not available due to old stlink FW. Plus, in case of JTAG wiring, SWD is still possible, while the opposite is not. Reorder the list of transports to grant the default to SWD. Change-Id: Id9c529e921b148d5b352d4603a9028c2a5f15d83 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Suggested-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com> Reviewed-on: http://openocd.zylin.com/5538 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
2020-05-24Revert "adapter: expose HLA interface in struct adapter_driver"Antonio Borneo2-9/+0
No reason to keep longer this temporary hack. Remove it by reverting the original commit. Change-Id: I5c6dcdb1f4755b7dba4c03a5033913ef8db35e18 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5533 Tested-by: jenkins
2020-05-24stlink: simplify handling of SWIMAntonio Borneo1-17/+8
Now that SWIM is not accessed through HLA anymore, decouple the SWIM code and remove the conditional execution. Fix the inconsistency of the return type for stlink_usb_state() in case of SWIM (returns ERROR_OK while type is enum target_state) introduced by commit 3de6b5f6e52f ("jtag/drivers/stlink_usb : implemented and repaired SWIM support"). The code added by commit above in stlink_usb_state() is an hack to reuse existing HLA API to perform a reconnect. Move the SWIM specific code from stlink_usb_state() to a dedicated stlink_swim_op_reconnect() that provides consistent data type. Change-Id: I3fe175fef00b0735bea6139b057f217a080c9d38 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Fixes: 3de6b5f6e52f ("jtag/drivers/stlink_usb : implemented and repaired SWIM support") Reviewed-on: http://openocd.zylin.com/5532 Tested-by: jenkins
2020-05-24stlink: simplify mem R/W with SWIMAntonio Borneo1-12/+36
Thanks to API separation between SWIM and the other transports, we can easily split the memory read/write for SWIM from the rest of the code. While there, use the macro STLINK_DATA_SIZE as size of data chunks that can be read/write in SWIM. This was not implemented before. Change-Id: I7d913c92539007e4d914480bacc0126a8f0e9705 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5531 Tested-by: jenkins
2020-05-24swim: add new transportAntonio Borneo6-31/+160
Add SWIM and STM8 to documentation and update TODO file. Introduce transport "swim" and command "swim newtap". Switch in swim.c from HLA API to the new SWIM API. Implement in stlink driver the SWIM APIs as wrappers of existing HLA functions. Remove any SWIM related reference from HLA files. Update stm8 config files and stlink-dap interface config file. Change-Id: I2bb9f58d52900f6eb4df05f979f7ef11fd439c24 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5530 Tested-by: jenkins
2020-05-24swim: fix adapter speed handlingAntonio Borneo2-6/+13
SWIM transport only supports two adapter speeds: - "low speed" equal to 363 kHz (8 MHz / 22) - "high speed" equal to 800 kHz (8 MHz / 10) Replace the previous convention that use "0" or "1" for "low" or "high" speed with the effective speed in kHz. Rework the implementation of stlink_speed_swim(). Set low speed in the stm8 config files, because only low speed is permitted at debug connection; the previous code ignores the initial value. Change-Id: I2484c9419a2c554c59eb6b9216339393ab0b54f3 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5529 Tested-by: jenkins
2020-05-24swim: abstract the transport in stm8 targetAntonio Borneo3-0/+118
SWIM is implemented by (ab)using the HLA API. This was acceptable when OpenOCD code did not provided a clear separation between transports and related APIs. Still today SWIM in OpenOCD is only supported by STLink, so the decision to re-use the HLA API was the simpler way to implement it. After commit efd1d642220a ("adapter: switch from struct jtag_interface to adapter_driver") the transports API are better split and SWIM can be implemented as a separate set of API. This would open the possibility to extend OpenOCD for other adapters that provide SWIM, e.g. versaloon, or through SPI emulation [1]. Introduce a new set of files swim.[ch] to handle the SWIM API. Beside the API that almost match the transport low-level data communication (system_reset, read_mem, write_mem), add a further API reconnect. Today, inside HLA STLink code, the reconnect is implemented by hacking the HLA API state(). Please notice that due to this hack the return type is incorrect; stlink_usb_state() returns ERROR_OK in SWIM mode, while its return type is enum target_state. Ignore the type mismatch and still call the HLA API state in the new SWIM API reconnect. Further commit will fix it. [1] http://kuku.eu.org/?projects/stm8spi/stm8spi Change-Id: I52018e1e2200cbd41af8e5031f7b35dc761b61d6 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5528 Tested-by: jenkins
2020-05-24adapter: expose HLA interface in struct adapter_driverAntonio Borneo2-0/+9
The transition of STM8/SWIM out of HLA will require a new struct swim_ops in struct adapter_driver. To simplify the development, make the HLA interface temporarily accessible through the struct adapter_driver. This commit will be reverted after the swim rework. Change-Id: I1e4f370cf64641164d7bcaa22f75ac58c9240052 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5527 Tested-by: jenkins
2020-05-24stlink: reduce use of hla specific enum hl_transportsAntonio Borneo1-50/+52
In the driver's code it's widely used the enum hl_transports for any check concerning the current transport, even for the non-hla transport dapdirect. The driver already provides a stlink specific enum stlink_mode that can be used in place of the hla one. Replace the hla enum with the stlink one allover the code. Introduce a hla specific wrapper stlink_usb_hl_open() to cope with the only API that requires the hla specific enum. The overall behaviour is not changed, with exception for a debug message in stlink_usb_open() than now prints the numeric value of stlink enum in place of the numeric value of the corresponding hla one. This change prepares the road for moving SWIM transport out of hla by removing any reference to the macro HL_TRANSPORT_SWIM from the stlink driver. Change-Id: Ieeea34f312245a94bfc1333087afdb8eb9f77139 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5526 Tested-by: jenkins
2020-05-09coding style: join consecutive string fragmentsAntonio Borneo1-1/+1
The re is no need to split a long string, apart for fitting the predefined line width. Join the consecutive string fragments. Issue identified by checkpatch script from Linux kernel v5.1 using the command find src/ -type f -exec ./tools/scripts/checkpatch.pl \ -q --types STRING_FRAGMENTS -f {} \; Change-Id: I8de52d572b0e3d4788c1d4d2b0cf8f94c7f08409 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5625 Tested-by: jenkins Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-05-09coding style: remove useless return statement from void functionsAntonio Borneo3-15/+0
For void functions, a return as last statement is useless. Remove it. Issue identified by checkpatch script from Linux kernel v5.1 using the command find src/ -type f -exec ./tools/scripts/checkpatch.pl \ -q --types RETURN_VOID -f {} \; Change-Id: Ie0616fe98623f30d2d7b04ac9517d669774092de Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5622 Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com> Tested-by: jenkins
2020-05-09coding style: prototype of functions with no parametersAntonio Borneo5-7/+7
Functions that have no parameters should use "void" as parameter in the function declaration. Issue identified and fixed by script checkpatch from Linux kernel v5.1 using the command find src/ -type f -exec ./tools/scripts/checkpatch.pl \ -q --types FUNCTION_WITHOUT_ARGS --fix-inplace -f {} \; Change-Id: If104ac75b44e939ec86155ff7b5720f2e33c6b39 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5621 Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com> Tested-by: jenkins
2020-05-09coding style: avoid unnecessary line continuationsAntonio Borneo10-28/+28
Line continuation, adding a backslash as last char of the line, is requested in multi-line macro definition, but is not necessary in the rest of C code. Remove it where present. Identified by checkpatch script from Linux kernel v5.1 using the command find src/ -type f -exec ./tools/scripts/checkpatch.pl \ -q --types LINE_CONTINUATIONS -f {} \; Change-Id: Id0c69e93456731717a7b290b16580e9f8ae741bc Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5619 Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com> Tested-by: jenkins
2020-05-09coding style: add parenthesis around the argument of sizeofAntonio Borneo7-11/+11
The script checkpatch available in new Linux kernel offers an experimental feature for automatically fix the code in place. While still experimental, the feature works quite well for simple fixes, like parenthesis. This patch has been created automatically with the script under review for inclusion in OpenOCD, using the command: find src/ -type f -exec ./tools/scripts/checkpatch.pl \ -q --types SIZEOF_PARENTHESIS --fix-inplace -f {} \; Change-Id: I8adb325bdb0e13211f8bae8b4770ec1979c176bf Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5618 Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com> Tested-by: jenkins
2020-05-09coding style: remove useless break after a goto or returnAntonio Borneo2-19/+0
In a switch/case statement, a break placed after a goto or return is never executed. The script checkpatch available in Linux kernel v5.1 issues a warning for such unused break statements. In the process of reviewing the new checkpatch for its inclusion in OpenOCD, let's get rid of these warnings. The script checkpatch is unable to fixup automatically this case. Thanks to having "break" command using a single code line, this patch has been generated using the script below: find src/ -type f -exec ./tools/scripts/checkpatch.pl -q \ --types UNNECESSARY_BREAK -f {} \; \ | sed -n '/^#/{s/^.*FILE: //;s/:$//;s/:/ /;p}' \ | awk 'function P() {print "sed -i '\''"b"'\'' "a}; { if ($1!=a) { if (a) {P()}; a=$1; b=$2"{d}"; } else { b=b";"$2"{d}" } }; END {P()}' Change-Id: I56ca098faa5fe8d1e3f712dc0a029a3f10559d99 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5617 Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com> Tested-by: jenkins
2020-05-09hla: remove unused hl_interface_param_s.apiTarek BOCHKATI2-3/+1
Change-Id: I90a23293c7e3a6067d56e56d186f9f452af7c15e Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com> Reviewed-on: http://openocd.zylin.com/5611 Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com> Tested-by: jenkins
2020-05-02jtag: remove unused function adapter_driver_modules_load()Antonio Borneo2-8/+0
Commit c2cecc74b0ac ("Move JTAG interface list to new files.") merged in mid 2009 introduces an unused and empty function that the developer expects to use for loading adapter drivers from shared libraries. This have never happened and the function is still empty and unused. Remove it. Change-Id: I7c88dbf8a9747e96e5ca4e6e7038ac0f232604fd Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5601 Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com> Tested-by: jenkins
2020-05-02coding style: src: remove empty lines at end of text filesAntonio Borneo5-6/+0
Empty lines at end of text files are useless. Remove them. Change-Id: Ibac9b36682d58f81e34ca2b51e6260e7d472fb0e Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5172 Tested-by: jenkins
2020-04-24bitbang: Fix FTBFS with GCC 10Andreas Fritiofson1-1/+1
GCC 10 defaults to -fno-common which breaks the sharing of bitbang_swd struct between bitbang drivers due to a missing extern. Change-Id: I2b4122f7939cec91a72284006748f99a23548324 Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com> Reviewed-on: http://openocd.zylin.com/5592 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-by: Jonathan McDowell <noodles-openocd@earth.li>
2020-04-24ftdi: Report an error if no ftdi_vid_pid is specifiedLeonard Crestez1-0/+5
By default the list of VID/PID is empty so if ftdi_vid_pid is not called then no matches are attempted. The only message is at -d3: Command 'init' failed with error code -100" Check for this condition explicitly to make life easier for people configuring adapters. Change-Id: If0f93370c9e9ddc9700aae7c346c1c6dd319152e Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com> Reviewed-on: http://openocd.zylin.com/5440 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2020-04-21jtag/drivers: add debugging support for Mellanox BlueField SoCLiming Sun3-0/+532
This commits adds debugging support for the Mellanox BlueField SoC via rshim, which is an interface accessible from external USB or PCIe (for SmartNIC case) via the rshim driver. It implements the arm dap interfaces based on the existing dapdirect framework. Change-Id: I18eb1c54293ec2c581f853e0e55b3f96d7978b56 Signed-off-by: Liming Sun <lsun@mellanox.com> Reviewed-on: http://openocd.zylin.com/5457 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2020-04-20jtag/drivers/ulink: fix clang static analyzer warningsTomas Vanek1-8/+9
scan-build-9: Description: Potential leak of memory pointed to by 'cmd' File: /home/vanekt/openocd/scanbuild9/../src/jtag/drivers/ulink.c Line: 1075 Description: Potential leak of memory pointed to by 'cmd' File: /home/vanekt/openocd/scanbuild9/../src/jtag/drivers/ulink.c Line: 1275 ulink_append_xxx_cmd() functions allocate memory for cmd and then call ulink_allocate_payload(), which allocates cmd->payload_out or cmd->payload_in. ulink_append_queue() checks the size of queue and if the new payload does not fit, calls ulink_execute_queued_commands() and then ulink_post_process_queue(). If any of these two fails, an error is returned, allocated cmd struct leaks and the queue is left in an undefined state. Change ulink_append_queue() flow to proceed to appending cmd to the queue even in the case of fail in previous ulink_execute_queued_commands() or ulink_post_process_queue(). In case of fail then clear the queue including the last appended cmd. Change-Id: I967c07af19e9020c93bcb4ef403cf1f557dd1db1 Signed-off-by: Tomas Vanek <vanekt@fbl.cz> Reviewed-on: http://openocd.zylin.com/5370 Tested-by: jenkins Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>