Commit Graph

1913 Commits

Author SHA1 Message Date
Antonio Borneo f788949651 openocd: fix command's usage string
The usage string should contain only the command parameters.
OpenOCD will automatically prepend the command name to the usage
string while dumping the usage or help message.

Remove the repeated command name from the usage string.

Change-Id: If10a0f1c254aee302b9ca08958390b7f21cdb21b
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5824
Tested-by: jenkins
2020-09-05 17:13:10 +01:00
Antonio Borneo 25b8b37638 jtag/aice: fix command's usage string
The usage string should contain only the command parameters.
OpenOCD will automatically prepend the command name to the usage
string while dumping the usage or help message.

Remove the repeated command name from the usage string.

Change-Id: Idbc301b34fab19e221131d232577c1629568e6ea
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5823
Tested-by: jenkins
2020-09-05 17:13:05 +01:00
Antonio Borneo 2f62883161 jtag: use proper format with uint32_t
Modify the format strings to properly handle uint32_t data types.

Change the prototype of detect_swo_freq_and_prescaler() in
'jlink.c' to avoid an implicit cast in the caller function.

Change the type of the variable retlen in some functions in
'usb_blaster.c' to properly pass their pointer to the local read
and write functions.

Use the proper parser COMMAND_PARSE_NUMBER(u32, ...).

Change-Id: I5227dbce04ee59881f173724db90790b7b9cc7af
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5815
Tested-by: jenkins
2020-09-05 17:12:25 +01:00
Antonio Borneo d493b53e8c jtag/aice: avoid abusing of int32_t type
In several cases the 'int' status value returned by libusb and by
aice internal functions is taken in a variable of type 'int32_t',
requiring an implicit (but trivial) cast.
This makes compulsory using 'PRId32' in the format strings that
print such 'int32_t' result and requires an additional implicit
conversion to return the 'int32_t' as 'int'.

Replace to type 'int' all the occurrences of 'int32_t result' and
fix accordingly the format strings.

Plus, all the size of aice commands are stored as int32_t const
variables with uppercase name, violating the coding style, and are
then passed as 'int' parameter to the read/write functions.

Replace the variables with C macros carrying an 'int' value.

While there, replace also a 'uint32_t' loop index with 'unsigned'
and fix the format string in the loop.

Change-Id: Ic57d58770f1af95f003b5a02fbcb7c926ec06fd1
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5814
Tested-by: jenkins
2020-09-05 17:12:19 +01:00
Antonio Borneo 60f104f450 hla_transport: split command registration per transport
All the HLA transports (hla_swd and hla_jtag) register the same
set of commands. Such commands are mainly aimed at handling JTAG
compatibility that is required for the transport hla_jtag only.

Split per transport the command registration and limit the
commands to only those required by the transport itself.
Replace the command "hla newtap" with the transport specific
"swd newdap" or "jtag newtap".
Deprecate the command "hla".

Change-Id: I79c78fa97b707482608516d3824151a4d07644c0
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4877
Tested-by: jenkins
2020-09-05 17:10:38 +01:00
Antonio Borneo 1457a1ab42 tcl/target: use command 'jtag newtap' to add a boundary scan TAP
A JTAG TAP for boundary scan should be added in the scan chain
through the command "jtag newtap".
In some TCL target script the boundary scan TAP is added through
the command "swj_newdap", command that is inappropriate in this
context because specific for arm adi-v5 SWJ-DP.
This situation was probably created to bypass the error with HLA
framework, caused by missing command "jtag newtap".

Add the command "jtag newtap" in HLA, by reusing the existing
code for command "hla newtap".
Fix the TCL target scripts to use the command "jtag newtap" for
the boundary scan TAPs.

The TCL script target/psoc6.cfg has no evident reference to HLA,
so the reason for using "swj_newdap" is less clear. Nevertheless
it uses the wrong command and, once HLA is fixed, there is no
reason to avoid fixing it too.

Change-Id: Ia92f8221430cf6f3d2c34294e22e5e18963bb88c
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4873
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
2020-09-05 17:10:14 +01:00
Samuel Obuch 3ac010bb9f Fix debug prints when loading to flash
While loading to flash with debug level at least 3,
OpenOCD tries to print the whole loaded bitstream.
This will be very-very-slow due to implementation of
conversion from buffer to string.

* fix condition on selected debug level in jtag/core.c
* replace slow buf_to_str function from helper/binarybuffer.c
  with faster but_to_hex_str function

Change-Id: I3dc01d5846941ca80736f2ed12e3a54114d2b6dd
Signed-off-by: Samuel Obuch <sobuch@codasip.com>
Reviewed-on: http://openocd.zylin.com/5800
Tested-by: jenkins
Reviewed-by: Jan Matyas <matyas@codasip.com>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2020-09-05 16:48:08 +01:00
Antonio Borneo 33b52174e6 nulink: add minimal support for Nu-Link2
Implementation largely taken from Nuvoton github
	https://github.com/OpenNuvoton/OpenOCD-Nuvoton

Reset is still not fully compatible with OpenOCD framework.
Adapted to hidapi.

Change-Id: Ieb1791b1b7f0b444c15c9668f8f2bcf34975d48f
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Zale Yu <cyyu@nuvoton.com>
Reviewed-on: http://openocd.zylin.com/5720
Tested-by: jenkins
Reviewed-by: Saravanan Sekar <saravanan@linumiz.com>
Reviewed-by: Marc Schink <dev@zapb.de>
2020-08-02 10:48:20 +01:00
Zale Yu b12fca236d jtag/drivers: add support for Nu-Link (Nuvoton ICE) over usb
Add support for Nu-Link1 over usb hidapi and config file.

The original work is fetched from Nuvoton github.
Code cleanup, fix merge conflicts, compile and runtime issues.
Switch the code from libusb to hidapi, being the device HID based.
Add documentation.
Merge fixes for multi-word memory read.

Reset is not fully compatible with openocd framework; currently
the target is reset and then halt at openocd start.

Change-Id: I9738de4e26783ba462ea3e39ec32069fd5bb7d94
Signed-off-by: Zale Yu <cyyu@nuvoton.com>
Signed-off-by: Saravanan Sekar <saravanan@linumiz.com>
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5635
Tested-by: jenkins
Reviewed-by: Marc Schink <dev@zapb.de>
2020-08-02 10:47:02 +01:00
Michal Potrzebicz fb739651c7 cmsis_dap_usb: Support for Microchip's nEDBG CMSIS-DAP interface
This commit fixes support for the nEDBG CMSIS-DAP interface
which is used ie. on the Curiosity Nano SAMD21 board.
nEDBG, similarily to mEDBG, does not support 512 byte HID packets.
This patch adds its USB PID to the exclusion list to make sure that
we stick with the default 64 bytes.

Change-Id: I9010b0cf77c0b1347269a759b5d16ee5155abb16
Signed-off-by: Michal Potrzebicz <michal@elevendroids.com>
Reviewed-on: http://openocd.zylin.com/5756
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-07-30 12:16:23 +01:00
Antonio Borneo 3e6f4f8b21 drivers/bitbang: blink LED on SWD
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-26 20:15:42 +01:00
Antonio Borneo 9b32a06dad drivers/linuxgpiod: add led
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-26 20:15:34 +01:00
Antonio Borneo 4c8753a83c jtag: fix minor typos
Change-Id: I3a3370db438f8fd045fb22e7c9fff4e83794a3b7
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5767
Tested-by: jenkins
2020-07-26 20:14:37 +01:00
Marc Schink c1a3f2ce6b libjaylink: Update to 0.2.0 release
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-26 20:11:11 +01:00
Antonio Borneo 68611efcdf 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 <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-14 00:39:58 +01:00
Antonio Borneo 97b7101316 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 <borneo.antonio@gmail.com>
Suggested-by: Masatoshi Tateishi <tateishim3@gmail.com>
Reviewed-on: http://openocd.zylin.com/5731
Tested-by: jenkins
2020-07-14 00:39:52 +01:00
Antonio Borneo e466f389a9 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 <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5728
Tested-by: jenkins
2020-07-14 00:39:39 +01:00
Antonio Borneo 93be480c90 jtag/drivers: add linuxgpiod driver
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-14 00:38:48 +01:00
Antonio Borneo ee86f3ef92 bcm2835gpio: enable only the transport specific gpio
Change-Id: Ice6744600079d5994d628bb3b782aa36e71f862e
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5558
Tested-by: jenkins
2020-07-14 00:38:42 +01:00
Antonio Borneo a8e483a2bf imx_gpio: enable only the transport specific gpio
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-14 00:38:36 +01:00
Antonio Borneo ed17994757 sysfsgpio: enable only the transport specific gpio
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-14 00:38:28 +01:00
Antonio Borneo 964680ecff bitbang: split jtag and swd operations
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-14 00:38:21 +01:00
Antonio Borneo 49232a80d2 bitbang: remove superfluous switch between jtag and swd
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-13 23:52:44 +01:00
Antonio Borneo 1f5962203a bitbang: document bitbang callbacks
Change-Id: I732c2eeb452f3ba8a2385d0e02fccbe86381812c
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5553
Tested-by: jenkins
2020-07-13 23:52:38 +01:00
Antonio Borneo 996ff5bcfc coding style: add arguments to function prototypes
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-08 22:08:19 +01:00
Antonio Borneo e2315ccffd coding style: fix space separation
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-08 22:08:08 +01:00
Antonio Borneo 6a81bad3b9 configure: split build of hla layouts
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-08 22:07:21 +01:00
Mikhail Rasputin 70f69f8728 jtag/tcl: fix a double free of jim object
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-07-08 22:05:06 +01:00
Moritz Fischer 64733434e2 jtag: drivers: xlnx-pcie-xvc: Add support for SWD mode.
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-27 15:34:38 +01:00
Marc Schink 8833c889da libjaylink: Update to latest Git version
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-23 18:55:53 +01:00
Marc Schink 5a79481d3b target/armv7m_trace: Calculate prescaler for external capture devices
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-18 10:11:02 +01:00
Tarek BOCHKATI bd6072072e stlink: code factorization by introducing stlink_usb_exit_mode
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-14 14:24:08 +01:00
Antonio Borneo bd425de3fb jtag/tcl: fix memory leak in command 'irscan'
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-06 18:05:46 +01:00
Antonio Borneo f6b4079ce5 libusb_helper: fix memory leak when no adapter is found
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-06 18:04:57 +01:00
tscn92 93e4bed056 jtag/drivers/bcm2835gpio: bcm2835gpio_init has been updated
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-06-06 18:01:57 +01:00
Antonio Borneo 3008756604 helper/command: strip replicated command name in log
After commit 0840414f0e ("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-24 21:36:29 +01:00
Antonio Borneo 7456e6bac5 stlink: fix open AP for v2j37 and v3j7
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-24 21:36:02 +01:00
Antonio Borneo b342c67f77 stlink: fix incorrectly returned error on v2j28
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-24 21:35:47 +01:00
Antonio Borneo af0db36f92 stlink: default dapdirect to SWD instead of JTAG
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-24 21:35:16 +01:00
Antonio Borneo cc5889883f Revert "adapter: expose HLA interface in struct adapter_driver"
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-24 21:34:05 +01:00
Antonio Borneo ce9e21b769 stlink: simplify handling of SWIM
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 3de6b5f6e5 ("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: 3de6b5f6e5 ("jtag/drivers/stlink_usb : implemented and repaired SWIM support")
Reviewed-on: http://openocd.zylin.com/5532
Tested-by: jenkins
2020-05-24 21:33:22 +01:00
Antonio Borneo 72f67790cf stlink: simplify mem R/W with SWIM
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-24 21:32:48 +01:00
Antonio Borneo ffe6bc8220 swim: add new transport
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-24 21:32:05 +01:00
Antonio Borneo ac05f929ed swim: fix adapter speed handling
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-24 21:31:21 +01:00
Antonio Borneo ac18e960ce swim: abstract the transport in stm8 target
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 efd1d64222 ("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-24 21:29:42 +01:00
Antonio Borneo 93c4c0fcbe adapter: expose HLA interface in struct adapter_driver
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-24 21:29:11 +01:00
Antonio Borneo 94dfa68647 stlink: reduce use of hla specific enum hl_transports
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-24 21:27:34 +01:00
Antonio Borneo 4625257007 coding style: join consecutive string fragments
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-09 14:40:40 +01:00
Antonio Borneo 3883e769f4 coding style: remove useless return statement from void functions
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-09 14:40:07 +01:00
Antonio Borneo 3474aa223a coding style: prototype of functions with no parameters
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-09 14:39:59 +01:00
Antonio Borneo 4f459660a9 coding style: avoid unnecessary line continuations
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-09 14:39:29 +01:00
Antonio Borneo e66bb9d312 coding style: add parenthesis around the argument of sizeof
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-09 14:39:19 +01:00
Antonio Borneo 9b29cb58ac coding style: remove useless break after a goto or return
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-09 14:39:05 +01:00
Tarek BOCHKATI 6f91aae159 hla: remove unused hl_interface_param_s.api
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-09 14:35:01 +01:00
Antonio Borneo 8f2afaafe2 jtag: remove unused function adapter_driver_modules_load()
Commit c2cecc74b0 ("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-02 15:41:21 +01:00
Antonio Borneo 6572dd97b3 coding style: src: remove empty lines at end of text files
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-05-02 15:40:21 +01:00
Andreas Fritiofson c60252ac2b bitbang: Fix FTBFS with GCC 10
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-24 17:44:13 +01:00
Leonard Crestez 38d205ecc5 ftdi: Report an error if no ftdi_vid_pid is specified
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-24 17:40:07 +01:00
Liming Sun 699a8475a1 jtag/drivers: add debugging support for Mellanox BlueField SoC
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-21 11:18:11 +01:00
Tomas Vanek 3c296bd194 jtag/drivers/ulink: fix clang static analyzer warnings
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>
2020-04-20 18:26:58 +01:00
Tomas Vanek 6dcd255b7b jtag/drivers/ulink: fix clang static analyzer warning
scan-build-9:
Description: Access to field 'payload_in' results in a dereference
 of a null pointer (loaded from field 'queue_start')
File: src/jtag/drivers/ulink.c
Line: 2216

Set input/output_signals conditionally if ulink_append_get_signals_cmd()
and ulink_execute_queued_commands() returns no error.
Do not fail driver initialisation as the signals are only printed.

Change-Id: I6c842f0e9a604712abf7444a2fa95ba5810de1ff
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/5520
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
2020-04-20 18:26:33 +01:00
Tomas Vanek c064440162 jtag/drivers/ulink: fix clang static analyzer warning
scan-build-9:
Description: Potential leak of memory pointed to by 'tdo_buffer'
File: src/jtag/drivers/ulink.c
Line: 1629

Free the buffer before error return.

Change-Id: Ic47651a5ae78c7a47ae4fcbad225f329b14c45cb
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/5519
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
2020-04-20 18:25:53 +01:00
Ake Rehnman b9a30e0892 Entering SWIM mode on ST-LINK does not update swim status word.
As a consequence of a previous failed SWIM command any
subsequent attempts to enter SWIM mode fails. Change
stlink_usb_mode_enter to use stlink_usb_xfer_noerrcheck
instead.

Change-Id: I5c6a1a8e68d3dc77ec37264880383366fa6a75d9
Signed-off-by: Ake Rehnman <ake.rehnman@gmail.com>
Reviewed-on: http://openocd.zylin.com/5547
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2020-04-12 22:06:29 +01:00
Tarek BOCHKATI 68e200c660 stlink: always use a valid endpoint
In order to extend the driver to support stlink-server over TCP,
we should always use a valid endpoint, as stlink-server is not permissive
and do not accept the invalid STLINK_NULL_EP.

STLINK_NULL_EP value was used for commands without an expected reply,
this value could be replaced with a valid endpoint without any impact
when the size is set to zero.

Change-Id: I003ad364e03d3a10bc036772db86310d996cbe81
Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Reviewed-on: http://openocd.zylin.com/5455
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2020-04-12 22:06:02 +01:00
Antonio Borneo 263296e549 jtag: flush queue after reset for drivers using old reset model
Not all the jtag drivers have been migrated to the new reset model
and for those only we need to flush the jtag queue to make the
reset working with command 'adapter [de]assert ...'.

Add a queue flush and a FIXME comment to remove both when all the
drivers would be migrated.

Change-Id: Ib6667f987b1be2bce492841040302e742dd1cad1
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5430
Tested-by: jenkins
2020-04-12 22:05:46 +01:00
Antonio Borneo cbbc56f7f7 stlink: remove only instance of useconds_t
The usleep() function, and its associated useconds_t type
specifier, has been obsoleted by POSIX.1-2008.

OpenOCD has 28 call to usleep(), that should be migrated to the
replacement nanosleep(), but due to the different prototype
	int nanosleep(const struct timespec *req, struct timespec *rem);
this can take some effort.

The type useconds_t is used in only one case, where it's used both
as parameter of usleep() and as value passed to LOG_DEBUG(). Due
to different implementation of useconds_t, there are cases that
trigger a compile warning in LOG_DEBUG() when useconds_t is more
than 32 bit.
E.g. with unistd.h in MinGW 4.x, useconds_t is defined as unsigned
long, thus being 32 or 64 bits depending on the target.

Replace the only instance of useconds_t.

Change-Id: I21724f8b06780abdb003a57222ff1d6840ff5419
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5544
Tested-by: jenkins
Reviewed-by: Ake Rehnman <ake.rehnman@gmail.com>
2020-04-12 22:02:19 +01:00
Antonio Borneo 27d04d4284 sysfsgpio: minor fix for bool types
Return bool value in functions that return bool.
Change return type to bool to function is_gpio_valid().

Change-Id: Ic2e62be737772b22e69881c034956549f659370b
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5552
Tested-by: jenkins
Reviewed-by: Marc Schink <dev@zapb.de>
2020-04-12 22:01:18 +01:00
Laurent LEMELE d14eac569c stlink: remove 18 MHz jtag freq for stlink v2
While stlink v2 allows setting the jtag clock frequency till a max
of 18 MHz, the firmware seams unstable and not properly working.

Remove the entry for 18 MHz, at least until a fix get available.

Change-Id: I503e1b6a5709b5fbf1f1147fd3b5f34a0c5ee98c
Signed-off-by: Laurent LEMELE <laurent.lemele@st.com>
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5465
Tested-by: jenkins
Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
2020-04-05 14:12:26 +01:00
Laurent LEMELE 56ff1ecddb stlink: fix speed setting in dap mode
stlink accepts a set of values for "adapter speed".
Fix the api khz() to return one of the allowed speed values.

Change-Id: Iac640b6f76935891ca25ac168cab3809707f19d9
Signed-off-by: Laurent LEMELE <laurent.lemele@st.com>
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5464
Tested-by: jenkins
Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
2020-04-05 14:12:21 +01:00
Roman Elshin fa329f2852 cmsis_dap_usb: Light up the leds while connected
Tested with Keil ULINK2 CMSIS-DAP.

Change-Id: I331224d23412bed8b2dea25abacbf9096ddd18b1
Signed-off-by: Roman Elshin <roxmail@list.ru>
Reviewed-on: http://openocd.zylin.com/5385
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2020-04-05 14:09:41 +01:00
Antonio Borneo 85dc630113 jtag: fix command "adapter [de]assert" with dap direct
The commit fafe6dfc9c ("adapter: add command "adapter [de]assert
srst|trst [[de]assert srst|trst]"") was proposed in gerrit well
before commit a61ec3c1d7 ("adi_v5_dapdirect: add support for
adapter drivers that provide DAP API") get merged, so it didn't
include a complete support for dap direct.
The merge upstream of the two commits lacks the support by command
"adapter [de]assert" for dap direct

Let command command "adapter [de]assert" handle dap direct.

Change-Id: I1a69f8ee877c8fd57598ed4ad9d71da61d15457c
Fixes: commit fafe6dfc9c ("adapter: add command "adapter [de]assert srst|trst [[de]assert srst|trst]"")
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5515
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-03-24 17:27:39 +00:00
Edward Fewell d35c44c743 drivers: xds110: Add support of alternate XDS110 configurations
The XDS110 supports alternate configurations, each of which has
a unique vid/pid:

0451/bef3 -- Standard (legacy) configuration
0451/bef4 -- Drag-n-Drop configuration
1cbe/02a5 -- CMSIS-DAP 2.0 on BULK interface configuration

It's not important to OpenOCD what the differences are except
that OpenOCD needs to know how to connect using the different
vid/pids and, in the case of the last one, use a different
interface for the debug connection.

Updated the XDS110 source to search for all possible
configurations, and updated the udev rules file to enable
user access to the alternate configuraitons.

For the curious, you can download the latest XDS emupack from
software-dl.ti.com/ccs/esd/documents/xdsdebugprobes/emu_xds_software_package_download.html
Install to an empty directory, and documentation for the
XDS110 is located in the .../ccs_base/common/uscif/xds110
of the installation.

Updated for comments in code review. Changed const variable
names to lower case. Reworked interface/endpoint setting
to use arrays suggestion.

Change-Id: Icc9d11c6618f43d87ae8171c78ebf238800d3ac2
Signed-off-by: Edward Fewell <efewell@ti.com>
Reviewed-on: http://openocd.zylin.com/5494
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2020-03-24 17:18:14 +00:00
Edward Fewell 87a4158acf drivers: xds110: Clean up command syntax and documentation
Arrange all commands under a top level xds110 command. Fix
documentation to properly reflect the current functionality.

Also updated the links in the document to the new permanent
links for the XDS110 only support.

Patch updated for comments from code review. Return
ERROR_COMMAND_SYNTAX_ERROR for wrong number of args in
commands. Added deprecated commands to src/jtag/startup.tcl.

Change-Id: Ica45f65e1fdf7fa72866f4e28c4f6bce428d8ac9
Signed-off-by: Edward Fewell <efewell@ti.com>
Reviewed-on: http://openocd.zylin.com/5495
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2020-03-24 17:17:45 +00:00
Edward Fewell c9ebd488ea drivers: xds110: Add support TCK changes in firmware update
Starting with XDS110 firmware version 3.0.0.0, the peak TCK
frequency became 14,000 kHz. So the delay count calculation
in the current driver has been updated to use the new
formula for setting the TCK speed depending on which version
of the firmware is detected. And because of the changes, the
default TCK settings for the XDS110 based Launchpads can be
adjusted to take advantage of the higher TCK performance.
Note that the values used have been determined through
testing in the automated test labs to be the highest TCK
frequency with the XDS110 that are still reliable.
Different boards have a different peak TCK setting that
should be safe.

Change-Id: I4d66e90d8fac8272641ba4db4a3a510e3b444d86
Signed-off-by: Edward Fewell <efewell@ti.com>
Reviewed-on: http://openocd.zylin.com/5493
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2020-03-24 17:17:02 +00:00
Tarek BOCHKATI 4b4389a2d6 stlink: workaround serial bug with old ST-Link DFU
Old ST-LINK DFU returns an incorrect serial in the USB descriptor
 example for the following serial "57FF72067265575742132067"
  - the correct descriptor serial is:
    0x32, 0x03, 0x35, 0x00, 0x37, 0x00, 0x46, 0x00, 0x46, 0x00 ...
    this contains the length (0x32 = 50), the type (0x3 = DT_STRING)
    and the serial in unicode format.
    the serial part is: 0x0035, 0x0037, 0x0046, 0x0046 ... >>  57FF ...
    this format could be read correctly by 'libusb_get_string_descriptor_ascii'
    so this case is managed by libusb_helper::string_descriptor_equal
  - the buggy DFU is not doing any unicode conversion and returns a raw
    serial data in the descriptor:
    0x1a, 0x03, 0x57, 0x00, 0xFF, 0x00, 0x72, 0x00 ...
            >>    57          FF          72       ...
    based on the length (0x1a = 26) we could easily decide if we have to fixup the serial
    and then we have just to convert the raw data into printable characters using sprintf

example for an old ST-LINK/V2 standalone:
  before : 'W?rreWWB g'
  after  : '57FF72067265575742132067'
  => same as the displayed value in STM32CubeProgrammer

tested using these commands
  using the buggy serial
    -c "hla_serial \x57\x3f\x72\x06\x72\x65\x57\x57\x42\x13\x20\x67"
  using the computed serial
    -c "hla_serial 57FF72067265575742132067"

Change-Id: I1213818257663eeb8e76f419087d3127d0524842
Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Reviewed-on: http://openocd.zylin.com/5396
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2020-03-22 08:17:14 +00:00
Tarek BOCHKATI 6ecccc8895 jtag/libusb_helper: permit adapters to compute their custom serials
introduce a callback function that could be passed to jtag_libusb_open
to permit adapters to compute their custom/exotic serials.

the callback should return a non NULL value only when the serial could not
be retrieved by the standard 'libusb_get_string_descriptor_ascii'

Change-Id: Ib95d6bdfc4ee655eda538fba8becfa183c3b0059
Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Reviewed-on: http://openocd.zylin.com/5496
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
2020-03-22 08:17:06 +00:00
Edward Fewell a34c336cbf drivers: xds110: Fix errors in routine that toggles
TCK during nSRST assert/deassert code.

To support LPRF targets (CC13xx/CC26xx), TCK must be toggled
for 50 ms while nSRST is asserted and right after it is
released. This allows the core to halt in boot ROM before
code is run that might interfere with debug access.

The current routine has two issues. It shouldn't be run at
all if the target is using SWD. And the delay needs to
be a real-time 50 ms, so the number of TCK periods should
be calculated off the set speed.

Change-Id: If993031b84cf2a505ea67a6633602c4b01cd8e1e
Signed-off-by: Edward Fewell <efewell@ti.com>
Reviewed-on: http://openocd.zylin.com/5497
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-03-14 19:16:42 +00:00
Antonio Borneo fbbfbb2516 ftdi: flush mpsse queue after a level change on reset pins
The function ftdi_set_signal() does not propagate the pin change
until next call to mpsse_flush(). Current code does not toggles
immediately the reset pins if polling is turned off.

Call mpsse_flush() at the end of ftdi_reset().
While there, remove the duplicated LOG message.

Change-Id: I79eacfe4fc32b5cdf2dc1b78f3660d96988466bc
Fixes: 8850eb8f2c ("swd: get rid of jtag queue to assert/deassert srst")
Reported-by: Leonard Crestez <leonard.crestez@nxp.com>
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5431
Tested-by: jenkins
Reviewed-by: Leonard Crestez <leonard.crestez@nxp.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-03-12 10:05:09 +00:00
Antonio Borneo 44967a9e07 jtag: report API reset as synchronous
The jtag API reset() is synchronous, but this was not highlighted
in the description.

Change-Id: I76ffb7eec97c8608cfbef0b9268ee18a5f50b221
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Fixes: 8850eb8f2c ("swd: get rid of jtag queue to assert/deassert srst")
Reviewed-on: http://openocd.zylin.com/5471
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Tested-by: jenkins
2020-03-12 10:03:42 +00:00
Tomas Vanek a2e822834d helper/binarybuffer: fix clang static analyzer warnings
Writing bits to an uninitialized buffer generated false warnings.
Zero buffers before setting them by buf_set_u32|64()
(do it only if bit-by-bit copy loop is used,
zeroed buffer is not necessary if a fast path write is used)

Change-Id: I2f7f8ddb45b0cbd08d3e249534fc51f4b5cc6694
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/5383
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
2020-03-07 15:30:05 +00:00
Tomas Vanek b07604cc6a jtag/drivers/openjtag: fix clang static analyzer warnings
Change-Id: I900ce8157b3e220a4647871080bb9abc772446d1
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/5369
Tested-by: jenkins
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
2020-03-07 15:29:24 +00:00
Tomas Vanek 6ff852e415 jtag/aice: fix clang static analyzer warnings
Change-Id: I6c801c2406cd117f2bcf930a5b329c441ab5f1ff
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/5368
Tested-by: jenkins
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
2020-03-07 15:29:14 +00:00
Marc Schink 51dd4ce6bb drivers: Rename 'libusb1_common' to 'libusb_helper'
The name 'common' does not make sense anymore. While at it,
remove some unnecessary #includes.

Change-Id: If9798a5cce179438d89428a598d8ca05c8e5f20c
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/5434
Tested-by: jenkins
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
2020-03-03 09:12:02 +00:00
Marc Schink 93c6bf2cce drivers: libusb1_common code cleanup
Remove unncessary wrapper functions and 'jtag_' prefixes.

Change-Id: I0fd866ff1e1cf7386c4d58a808dfda2c1c0a1518
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/5433
Tested-by: jenkins
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
2020-03-03 07:24:33 +00:00
Oleksij Rempel 8abe91cff9 remove libusb0_common support
Supporting two libusb versions provides additional development challenges
without additional advantage. In most cases we need to patch libusb0_common and
libusb1_common without real ability to test libusb0_common.

Change-Id: Icbb19c6809b14533fe2acf7a877377b3be4cbd61
Signed-off-by: Oleksij Rempel <linux@rempel-privat.de>
Reviewed-on: http://openocd.zylin.com/5432
Tested-by: jenkins
2020-03-03 06:48:43 +00:00
Antonio Borneo e7306d361b coding style: fix space around pointer's asterisk
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 spacing.

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 POINTER_LOCATION --fix-inplace -f {} \;
then manually reviewed.

OpenOCD coding style does not mention the space around pointer's
asterisk, so no check is enforced. This patch only makes the style
uniform across the files.

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: Iefb4998e69bebdfe0d1ae65cadfc8d2c4f166d13
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5197
Tested-by: jenkins
2020-02-24 10:30:36 +00:00
Antonio Borneo ee56c50260 stlink: add trace support in DAP direct mode
Reuse the existing tracing functionality of HLA mode to support
tracing in DAP direct mode.

Change-Id: I75a01e88ba5d3e45717e4108b99697ac3225db9e
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5409
Tested-by: jenkins
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
2020-02-15 15:39:16 +00:00
Antonio Borneo 1492a103db coding style: use ARRAY_SIZE() when possible
We have the macro ARRAY_SIZE() already available. Use 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 ARRAY_SIZE -f {} \;

Change-Id: Ic7da9b710edf118eacb08f9e222f34208c580842
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5198
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-02-15 15:37:40 +00:00
Antonio Borneo def7318edd jtag/startup.tcl: remove trailing whitespaces
Change-Id: I1d6f4f47ee6f8985c84ddb2647e029c5f4e6a55a
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5194
Tested-by: jenkins
Reviewed-by: Marc Schink <dev@zapb.de>
2020-02-15 15:37:06 +00:00
Jan Matyas 4882acef80 jtag_vpi: added an option to stop simulation on exit
Command CMD_STOP_SIMU had been defined in jtag_vpi for a long time
(since the beginning?) but has not been utilized until now.
Its purpose is to signal to the jtag_vpi server (i.e. the RTL
simulation software) that the simulation shall be stopped.

This commit adds a TCL configuration command that selects whether
CMD_STOP_SIMU will be sent to the jtag_vpi server when OpenOCD is
about to exit. This functionality is off by default to maintain
identical behavior as in previous OpenOCD versions, unless the user
enables it explicitly.

Change-Id: If3894af6efa61038ccf6c9191f664e2128f2ef11
Signed-off-by: Jan Matyas <matyas@codasip.com>
Reviewed-on: http://openocd.zylin.com/5407
Tested-by: jenkins
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2020-02-15 15:32:53 +00:00
Marek Vasut 853a05287c jtag: Fix copy-paste error in 'irscan' help
Replace "Instruction Register (DR)" with "Instruction Register (IR)",
that is sed "s@DR@IR@", which was likely a copy-paste error.

Change-Id: I3e625872c855d655485b3efa5f50fe1c00ecbf52
Signed-off-by: Marek Vasut <marek.vasut@gmail.com>
Reviewed-on: http://openocd.zylin.com/5446
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Tested-by: jenkins
2020-02-09 20:06:32 +00:00
Antonio Borneo 324a45e029 stlink: fix max packet size for 8 bit R/W on stlink-v3
While ST internal documentation for STLINK-V3 reports that 8 bits
read/write commands handle 512 bytes of data, a firmware bug makes
it crashing on high data size.
This is fixed with firmware V3J6 (shipped together with V2J36).

Check for firmware version to use the proper data size.

Change-Id: Iaba6cd26bbe130097c1c19de610680e0e8b69bfc
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Fixes: https://sourceforge.net/p/openocd/tickets/259/
Reviewed-on: http://openocd.zylin.com/5408
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-02-08 09:13:44 +00:00
Antonio Borneo 7da165a11f jtag: flush jtag queue after jtag_add_tlr()
If the TLR sequence is sent as result of the command "adapter
assert trst" while polling is off, the TLR sequence is not sent out
until a following jtag operation.

Flush the jtag queue before return.

Change-Id: I20efd7137cb7b1d1c4f73c1362cbe4e57aeaae49
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5405
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-02-08 09:12:54 +00:00
Antonio Borneo d91e19eb16 jtag: drivers: xlnx-pcie-xvc: fix build on Linux pre v4.10
The macro PCI_CFG_SPACE_EXP_SIZE is exposed to userspace from
Linux kernel v4.10, with commit cc10385b6fde ("PCI: Move config
space size macros to pci_regs.h")
http://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=cc10385b6fde

Define the macro in the driver code, if not already defined.

Change-Id: I610219a2587eff2c142102b9f7830e3da882af78
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5435
Reviewed-by: Moritz Fischer <moritzf@google.com>
Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Tested-by: jenkins
2020-02-06 20:22:49 +00:00
Leonard Crestez 09ac9ab135 jtag: Fix jtag_reset fallback
The fallback provided for the jtag_reset command always fails with a
strange message: 'Error: invalid command name "de"'

This is caused by incorrect quoting inside the warning message.

Fixes: c07b774e8f ("jtag: replace command "jtag_reset" with "adapter [de]assert"")

Change-Id: Icd47fca2b5a7b33474bfb0040e88193a0968f301
Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
Reviewed-on: http://openocd.zylin.com/5416
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-01-29 10:06:58 +00:00
Antonio Borneo 291d1511aa openocd: fix minor inconsistencies after renaming "adapter" command
Replace in the code any reference to the deprecated commands.

Change-Id: I75d28064017d664990b4024967900f32e196230a
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5282
Tested-by: jenkins
Reviewed-by: Marc Schink <dev@zapb.de>
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
2020-01-29 05:36:30 +00:00
Oleksij Rempel 70babcc00b move ftdi_location deprecation helper to proper place
Change-Id: I927d4e918acbf321aea1dd7a8de95fbaa8fbbbf0
Signed-off-by: Oleksij Rempel <linux@rempel-privat.de>
Reviewed-on: http://openocd.zylin.com/5278
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2020-01-29 05:35:36 +00:00
Oleksij Rempel 5280eb618a jtag: adapter: rework adapter related commands
currently we have different types of same command group:
- starting with adapter_*
- starting with interface*
- without adapter or interface prefix.

Since interface name is already used, we can only use "adapter" command
group by keeping old commands as well.

Change-Id: Id0a1cb63a2ea6860c67ae1e7a3a06a37ddf464f4
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-on: http://openocd.zylin.com/4774
Reviewed-by: Marc Schink <dev@zapb.de>
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
2020-01-29 05:33:39 +00:00
Antonio Borneo 60aaf14837 jtag: drivers: xlnx-pcie-xvc: fix build after merge
Commit [1] was submitted in gerrit well before the conflicting
commit [2] get merged in master branch. While it was fine
committing in master branch [1] alone, it should not be
committed "as is" after [2].
Unfortunately gerrit did not complained committing [1] after [2].
The result is that master branch does not build anymore when the
driver xlnx-pcie-xvc is enabled at configure time by the optional
flag --enable-xlnx-pcie-xvc.

Apply to the driver the required changes as in [2].
While there, remove the duplicated struct xlnx_pcie_xvc_transports
and the struct field already implicitly initialized to zero.

[1] ff6d0704ec ("jtag: drivers: xlnx-pcie-xvc: Add support for
    Xilinx XVC/PCIe")
[2] efd1d64222 ("adapter: switch from struct jtag_interface to
    adapter_driver")

Change-Id: I5498479b802a231afbee1b845ae9775e1da7c728
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5402
Reviewed-by: Moritz Fischer <moritzf@google.com>
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
2020-01-22 12:49:59 +00:00
Oleksij Rempel d612baacaa jtag_libusb_bulk_read|write: return error code instead of size
A USB bulk write/read operation may fail with different errors:
 LIBUSB_ERROR_TIMEOUT if the transfer timed out (and populates transferred)
 LIBUSB_ERROR_PIPE if the endpoint halted
 LIBUSB_ERROR_OVERFLOW if the device offered more data, see Packets and overflows
 LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
 another LIBUSB_ERROR code on other failures

Current OpenOCD code is using the transfer size based error detection.
Which may not always work. For example for LIBUSB_ERROR_OVERFLOW as libusb
documentation says:
"Problems may occur if the device attempts to send more data than can fit in
the buffer. libusb reports LIBUSB_TRANSFER_OVERFLOW for this condition but
other behaviour is largely undefined: actual_length may or may not be accurate,
the chunk of data that can fit in the buffer (before overflow) may or may not
have been transferred."

This patch is refactoring code to use actual error return value for
error detection instead of size.

Change-Id: Iec0798438ca7b5c76e2e2912af21d9aa76ee0217
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-on: http://openocd.zylin.com/4590
Tested-by: jenkins
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
2020-01-22 05:33:31 +00:00
Moritz Fischer ff6d0704ec jtag: drivers: xlnx-pcie-xvc: Add support for Xilinx XVC/PCIe
Add support for Xilinx Virtual Cable over PCIe JTAG controller.
It is commonly used in Xilinx based PCI Express designs with JTAG IP
in the FPGA fabric.

Access to the JTAG registers happens via the PCI Express extended
configuration space.

This can be used to debug soft-cores instantiated in the FPGA fabric.

The clang static checker doesn't find any new problems with this change.

Change-Id: Ib12ede0d1f26dacfda808d5e05b947b640c5bde7
Signed-off-by: Moritz Fischer <moritzf@google.com>
Reviewed-on: http://openocd.zylin.com/5314
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Marex
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
2020-01-17 05:21:29 +00:00
Antonio Borneo d2308da6e9 stlink: fix handling of DPv1 and DPv2 banked registers
Arm DPv1 and DPv2 support banked registers by setting the bank in
field DPBANKSEL of register DP_SELECT.
Old ST-Link firmware don't support banked registers and setting a
bank other than bank zero on DPv1 or DPv2 cause issues in the
firmware because it cannot set back bank zero to read CTRL/STAT.
New ST-Link firmware mask away DPBANKSEL bits while writing in
DP_SELECT but support banked register using the same packed method
used by OpenOCD:
	#define BANK_REG(bank, reg) (((bank) << 4) | (reg))

Add a new macro STLINK_F_HAS_DPBANKSEL for firmware that support
arm DPv1 and DPv2, plus trigger an error if banked registers are
requested on old firmware.
Prevent changing DPBANKSEL on old firmware.
Log a debug message when changing DPBANKSEL will be ignored.

Change-Id: Iaa592517831d63f8da2290db54f6b32504e3081b
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4978
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-01-14 11:40:45 +00:00
Antonio Borneo 944d3e6771 stlink: add DAP direct driver
STLINK-V3 and the new firmware V2J24 for ST-LINK/V2 provide API
to directly access the DAP registers.
This mode permits to use the native target in cortex_m.c, with no
need to override it with the target in hla_target.c.
Other advantages wrt HLA are: support for Cortex-A cores, support
for SoC multi-core and/or multi AP, support for OpenOCD commands
"dap" thus including control of CSW.
This obsoletes the existing HLA driver for ST-Link, that should
anyway be kept for those cases where it's not possible to update
the ST-Link firmware.

This commit introduces the minimal implementation for direct DAP
access. The implementation is much slower than the HLA because
every memory transfer requires several USB packets. Further
commits will close the performance gap.
The whole ST-Link driver is compiled under BUILD_HLADAPTER, to
remove the need to split the driver between the two modes. This
has to be reworked, but it's quite invasive!
A new interface file stlink-dap.cfg is added and should be used
in place of stlink.cfg to enable the DAP mode.
Documentation is updated and reports limitation on the maximum AP
number that can be accessed by ST-Link for some firmware already
tested.

Change-Id: I932ffe16bc81d00b1fe489e2944fda13470cce9b
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4904
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-01-14 11:40:36 +00:00
Antonio Borneo a61ec3c1d7 adi_v5_dapdirect: add support for adapter drivers that provide DAP API
Some high level adapters, like STLINK-V3 and new firmware for
ST-Link/V2, provide API to directly access the DAP registers
hiding the details of the physical transport JTAG or SWD.
OpenOCD has already the intermediate API in struct dap_ops that
are suitable for such adapters, but are not exposed to the
adapter drivers.

Add in struct adapter_driver two independent struct dap_ops for
the cases of physical JTAG and SWD transport.
Add new transport names "dapdirect_jtag" and "dapdirect_swd", to
be used by the drivers that provide one or both DAP API.
Add the necessarily glue in target/adi_v5_dapdirect.c

Change-Id: I2bb8e3a80fba750f2c218d877cfa5888428e3c28
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4903
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-01-14 11:40:25 +00:00
Antonio Borneo efd1d64222 adapter: switch from struct jtag_interface to adapter_driver
To reorganize the adapters code, introduce an adapter_driver
struct that contains all the adapter generic part, while
keeping in two separate struct the specific API jtag_ops and
swd_ops.
Move the allocation of *adapter_driver from the JTAG-specific
file core.c to the more adapter-specific file adapter.c
While splitting the old jtag_interface for every driver, put
the fields in the same order as in the struct declaration so
we keep a consistent code across all the drivers.

While other transport specific API could/would be added as
separate ops, nothing is done here for HLA.

Change-Id: I2d60f97ac514c0dd2d93a6ec9be66fd9d388dad5
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4900
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-01-14 11:39:37 +00:00
Antonio Borneo 7268ff22c3 drivers/kitprog: remove unused JTAG execute_queue method
kitprog is SWD only and we do not rely on JTAG queue anymore.
Remove the remaining JTAG heritage.

Change-Id: Ic586278368301eb669bc6e4e641f683a81cb171d
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4899
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-01-14 11:39:25 +00:00
Antonio Borneo b5621bf2f9 hla: remove empty JTAG execute_queue method
We do not rely on JTAG queue anymore.
Remove the remaining JTAG heritage.

Change-Id: I6c87d9ffebaa383c998cf273188b3e7f28b3fe95
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4898
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-01-14 11:38:39 +00:00
Antonio Borneo f275ae586b jtag: print an errmsg on using jtag API for non jtag transport
After the cleanup of swd and hla, there should be no more calls
to jtag_execute_queue() or to queue jtag commands if current
transport is not jtag. Thus we can start removing the jtag
specific code from adapters that do not support jtag.

To prevent some remaining call to jtag_execute_queue() to crash
openocd, verify the transport, print an error message if the
transport is not jtag, call the adapter's jtag_execute_queue()
only if it exist.
To identify code that still add commands in the jtag queue even
if transport is not jtag, print an error message in the function
jtag_queue_command(). For the moment, still queue the message,
even if will cause a memory leak if there is no following call
to jtag_execute_queue(); the target is to identify the issue and
cleanup the code, thus solving also the leak.

Change-Id: I8fc85f754aa057aad1df05ff0448c8619897da23
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4897
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-01-14 11:38:23 +00:00
Antonio Borneo 0f24549ce9 hla: use the new system_reset API
HLA uses its own internal driver's API to control the adapter's
system reset, but at the same time it calls jtag_add_reset() to
avoid breaking the internal logic of OpenOCD. This implicitly
forces HLA to rely on jtag queue mechanism, even if HLA has no
link with JTAG state machine. It requires HLA to implement an
empty execute_queue() to comply with the JTAG queue.

Modify the HLA framework and the HLA targets to use the new
adapter API for system_reset and decouple HLA from JTAG queue.
Rename the HLA static functions adapter_assert_reset() and
adapter_deassert_reset() to avoid overlap with the global
functions with same name.
While there, fix a minor typo in a comment s/incase/in case/.

Do not remove from HLA the JTAG specific API execute_queue(),
even if not required anymore, because OpenOCD code still has
calls to jtag_execute_queue() in case of non JTAG transport.

Change-Id: I0e65e3e557bd665bd3d3aeaa84ea609b55a05e48
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4896
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-01-14 11:37:34 +00:00
Antonio Borneo 9daec098a9 bitbang: jtag-only drivers: switch to new reset API
Remove the JTAG_RESET command from the bitbang execute queue now
that all bitbang drivers have moved away from old reset method.
Remove also the internal reset API in struct bitbang_interface.

Tested parport only.

Change-Id: I12b157ef442f4c9912406b19b7a4d32ba6ec0b53
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5300
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-01-14 11:16:24 +00:00
Antonio Borneo 8850eb8f2c swd: get rid of jtag queue to assert/deassert srst
The transport SWD uses the JTAG queue to assert/deassert the
system reset srst. This is the major inconsistency that has to be
removed to properly split JTAG and SWD.

Introduce a new driver API, reset(), to controls both the signals
trst and srst in the driver, skipping the JTAG queue. Put the new
API in struct jtag_interface, even if in this patch it's used for
SWD only; the goal is to get it reused by the other transports.

Add the implementation of the API in all the drivers that
implement SWD. Such implementation is almost the same of the old
code in JTAG queue.

Create a wrapper adapter_system_reset() to use the new API and
remove the SWD specific swd_add_reset(). In the wrapper replace
jtag_add_sleep() with jtag_sleep(), because the former uses the
JTAG queue too.
Rename the old jtag_add_reset() as legacy_jtag_add_reset() with
the target to remove it when all drivers would be ported to the
new reset API. Create a new jtag_add_reset() that calls the
legacy function for drivers still on the old reset API.

Use the new API also on JTAG transport for the drivers that can
support both SWD and JTAG.

For the moment, do not modify the implementation of JTAG-only
drivers, which will continue using the usual method. This should
be cleaned-up in future commits.

Change-Id: I32331c88313f6059b25e12c6bb0156aebc1c074f
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4895
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-01-14 11:15:12 +00:00
Antonio Borneo be2d25efcc arm_adi_v5: add API send_sequence() and use it
The method to send an arbitrary sequence to DAP depends on the
transport and is thus different on JTAG and SWD. This is already
coded in dap_to_jtag() and dap_to_swd().

Add a new API send_sequence() in struct dap_ops.
Add the implementations of send_sequence() in adi_v5_jtag.c and
adi_v5_swd.c
Rewrite dap_to_jtag() and dap_to_swd() using the new API.
Move the enum swd_special_seq in arm_adi_v5.h to solve a circular
dependencies among swd.h and arm_adi_v5.h

Change-Id: I9db13a00f129761eab283783c094cfff2dd92610
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4902
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-01-02 21:24:54 +00:00
Antonio Borneo c07b774e8f jtag: replace command "jtag_reset" with "adapter [de]assert"
Replace the JTAG transport specific command with a more generic
one. Deprecate "jtag_reset" and update the documentation.
While there, fix an error in the documentation, where the command
"jtag_reset" was used in place of command "reset_config".

Change-Id: I41a988d37ce69f7b35a960cbaf5306aab0299b99
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5286
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-01-02 21:24:38 +00:00
Antonio Borneo fafe6dfc9c adapter: add command "adapter [de]assert srst|trst [[de]assert srst|trst]"
Inspired from http://openocd.zylin.com/#/c/3720/1

Add commands to control the adapter's signals srst and trst.
Add macros for the flag's values assert/deassert to make clear what
they mean and to propose a uniform set of values across the code.

Change-Id: Ia8b13f4ded892942916cad7bda49540a896e7218
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/5277
Tested-by: jenkins
2020-01-02 21:24:30 +00:00
Jan Matyas deff24afa1 jtag_vpi: multiple improvements
- Fix: Proper handling of read_socket() and write_socket()
in case of "partial" read/write.

- Added low-level JTAG IO debug capability (_DEBUG_JTAG_IO_)

- Zero-fill packet buffers, avoid sending pieces of uninitialized
memory over the network (memset struct vpi_cmd)

- Use close_socket() instead of close() - needed for Win32

- Fixed usage messages of jtag_vpi_command_handlers

Change-Id: I8bd19bc5c9512fe8e798600212e8a95213f50f5b
Signed-off-by: Jan Matyas <matyas@codasip.com>
Reviewed-on: http://openocd.zylin.com/5177
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2020-01-02 21:22:33 +00:00
Marc Schink 2dc88e1479 target/armv7m_trace: Improve SWO frequency auto-detection
The SWO frequency auto-detection with J-Link adapters does not work
properly in the current implementation. This is because the trace layer
has only information about the highest possible SWO frequency supported
by the adapter. With that the trace layer calculates the SWO prescaler
which usually leads to a frequency deviation greater than what is
permitted by J-Link adapters.

Move the calculation of the SWO prescaler from the trace layer into the
trace configuration of the adapter to overcome this problem.
The adapter has the necessary information to choose a suitable SWO
frequency and calculate the corresponding prescaler that complies with
the maximum allowed frequency deviation.

Tested with:
  - STM32L152RC Discovery Kit (ST-Link)
  - EFM32GG-STK3700 (J-Link)

Change-Id: I38ff2b89d32f0a92c597989b590afe5c75cf4902
Signed-off-by: Marc Schink <openocd-dev@marcschink.de>
Reviewed-on: http://openocd.zylin.com/3903
Tested-by: jenkins
Reviewed-by: Paul Fertser <fercerpav@gmail.com>
2019-12-21 19:25:32 +00:00
Antonio Borneo 49d71d06d1 sysfsgpio: give time to udev to change gpio permission
When a gpio is exported by writing in /sys/class/gpio/export, the
corresponding gpio control files appear immediately in sysfs but
with default access permission for root user only. The daemon udev
requires some time to get notified of the new files before it can
change the permissions to allow access to unprivileged users.
Due to this race condition, sysfsgpio can fail with EACCES error
if OpenOCD is executed by any unprivileged user.

Give 0.5 seconds to udev to identify the new files and change the
permission.

Tested with udev rules:
	SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c 'find -L /sys/class/gpio/ -maxdepth 2 -exec chown root:uucp {} \; -exec chmod g=u {} \; || true'"

Change-Id: I1316c66ff103ffe23e5e4720f33372dc272a3766
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5302
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-12-19 20:42:01 +00:00
Jan Matyas 881484708d jtag_vpi: ensured constant packet size & endianness
Made sure that size and endianness of jtag_vpi structures sent
over the network is the same, regardless of the platform.

Little endian chosen to maintain as much compatibility
with existing OpenOCD builds as possible.

Matching change in the original jtag_vpi server:
https://github.com/fjullien/jtag_vpi/pull/4

Change-Id: Ib839fea9bb2d5190b5643c970b89333b286dce71
Signed-off-by: Jan Matyas <matyas@codasip.com>
Reviewed-on: http://openocd.zylin.com/5152
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Tested-by: jenkins
2019-12-16 23:27:32 +00:00
Alexandru Gagniuc 4333339680 jtag: usb_blaster: Add missing 'default' to switch statement
If a new JTAG command is added, then GCC will complain that
enumeration value not handled in switch. This is the only driver not
to have a default case, so add it.

Change-Id: Icb838087bb7525d057a911bd256300e256da1668
Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
Reviewed-on: http://openocd.zylin.com/5333
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-11-07 08:21:19 +00:00
Alexandru Gagniuc 4f779a88db jtag: jtag_vpi: Add missing 'default' to switch statement
If a new JTAG command is added, then GCC will complain that
enumeration value not handled in switch. Make this consistent with
other drivers, and add a 'default' case.

Change-Id: I66d6d0db3fcae93ea246f2d4882ffff5dec14693
Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
Reviewed-on: http://openocd.zylin.com/5340
Tested-by: jenkins
Reviewed-by: Jan Matyas <matyas@codasip.com>
Reviewed-by: Franck Jullien <franck.jullien@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-11-07 08:21:02 +00:00
Marc Schink ded6799025 libjaylink: Update to latest Git version
This version adds two new USB PIDs and fixes a build issue under MSYS2.

Change-Id: I753fab827783ea64e55e59d833742c9f70a28a2b
Signed-off-by: Marc Schink <openocd-dev@marcschink.de>
Reviewed-on: http://openocd.zylin.com/5309
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2019-10-19 13:27:29 +01:00
Antonio Borneo e99a43a276 drivers/gw16012: remove useless cast on gw16012_port
The variable gw16012_port is of type uint16_t.
There is no need for a cast to print it.

Change the format modifier to PRIx16

Change-Id: I16fe688b9d235bae46525635d07849a00fba9548
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5195
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
2019-10-18 09:22:34 +01:00
Tim Newsome 462c012066 Add complete JTAG debug logging.
Sample output, with default_interface_jtag_execute_queue replaced by
dijeq to satisfy commit message line length check:
Debug: 646 18 core.c:847 dijeq(): JTAG IR SCAN to RUN/IDLE
Debug: 647 18 core.c:852 dijeq():   5b out: 11
Debug: 648 18 core.c:847 dijeq(): JTAG DR SCAN to RUN/IDLE
Debug: 649 18 core.c:852 dijeq():   40b out: 4400000001
Debug: 650 18 core.c:857 dijeq():   40b in: 4400000000

Signed-off-by: Tim Newsome <tim@sifive.com>
Change-Id: I014e9e3a77755413b36edfcede2ab8f6aa08061b
Reviewed-on: http://openocd.zylin.com/4451
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-10-15 08:59:00 +01:00
Tim Newsome d214cadfef Add wall clock timeout warning to mpsse_flush()
I think that libusb_handle_events_timeout_completed is supposed to make
progress or time out, but sometimes we hit a case where it makes no
progress, and mpsse_flush() loops forever. This wall clock timeout
notifies the user that this is going on.

When I wrote this code, this bug would reproduce every hour or two, but
right now it's not happening for me.

Change-Id: I7eb66f43462298e263a48048aa0c8769095661eb
Signed-off-by: Tim Newsome <tim@sifive.com>
Reviewed-on: http://openocd.zylin.com/4767
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
2019-10-15 08:58:56 +01:00
Seth LaForge 3110092720 src/jtag/aice: Fix obviously incorrect bit op.
Fix expression "(pin_status | 0x4)" which was always true rather than
testing a bit. Untested - was clearly not expressing the intent of the
author by inspection. Found by automated tooling and rtrieu@google.com.

Signed-off-by: Seth LaForge <sethml@google.com>
Change-Id: I4bb91e60e8ce9757bf21976cc48de6f85a39c68d
Reviewed-on: http://openocd.zylin.com/5301
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-09-24 05:47:43 +01:00
Antonio Borneo 9879f9bf04 jtag: fix error on TCL command "return" in jtag event handler
The TCL command "return" always returns error code JIM_RETURN, to
indicate that the effective error code and message are elsewhere.

In the current implementation, the caller of jtag's event only
checks for return code JIM_OK and considers any other value,
including JIM_RETURN, as an error condition.

It can be tested running openocd on a jtag target and adding a
jtag event "setup" with a single line "return", e.g.
	openocd -f board/ti_cc3200_launchxl.cfg \
	-c 'jtag configure cc32xx.cpu -event setup return'
to get the message:
	../src/jtag/core.c:1599: Error:
	in procedure 'jtag_init' called at file "../src/jtag/core.c",
	line 1599

Modify jtag_tap_handle_event() to detect the specific return value
of the "return" command and to test the real error code that is,
eventually, specified to the TCL "return" command.

Change-Id: I6d6febc15ef169638afffbffc1810e0b84fcf5c8
Reported-by: Tomas Vanek <vanekt@fbl.cz>
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5199
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-06-13 12:40:51 +01:00
Tilman Sauerbeck 8ed19a2e29 jtag: drivers: buspirate: chunk SWD switch sequence transfer.
Commit c2e18bfaea changed the size of the JTAG-to-SWD sequence
from 15 bytes to 17 bytes. This broke SWD switch sequence transfer
for buspirate, since buspirate packets can only hold a payload of up
to 16 bytes and we tried to fit the whole sequence in a single packet.

Splitting up the sequence transfer in appropriately sized packets
makes buspirate SWD work again (successfully tested with buspirate
firmwares v6.1 and v7.0).

Change-Id: Ib5b412b9e77287d705d2762e31c16d30318b50e3
Signed-off-by: Tilman Sauerbeck <tilman@code-monkey.de>
Reviewed-on: http://openocd.zylin.com/5200
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-06-13 12:39:38 +01:00
Christopher Head b6fa208759 jtag/drivers/jtag_usb_common: fix typo
Change-Id: If1f56fd5d610b993a4ecbc900fac9f90638037c9
Signed-off-by: Christopher Head <chead@zaber.com>
Reviewed-on: http://openocd.zylin.com/5202
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-06-13 12:39:09 +01:00
Antonio Borneo 159f11fefc jtag: set default "jtag_only" to uninitialized transports
For legacy support, drivers that do not define a list of
transports get identified as jtag_only.

Cleanup this old crust and initialize properly the transports
field in the jtag_interface for all the drivers.

Change-Id: I9c86064e5d05bd0212bc18f4424414e615e617fe
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4893
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-06-06 16:45:31 +01:00
Antonio Borneo e26910fdad jtag: simplify management of non-implemented handlers
There is just a single entry point for the jtag API .khz(),
.speed_div(), .power_dropout(), .srst_asserted().

Simplify the code by in-lining the default handler.
The overall code behaviour is not changed.
This change prevents modifying at run-time the content of
struct jtag_interface.

Inspired from change http://openocd.zylin.com/943
by Evan Hunter <ehunter@broadcom.com>

Change-Id: I09aeb76d614db57b1884ac7ee9f00c152cd77849
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4892
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-06-06 16:21:23 +01:00
Antonio Borneo 7cddeb0af2 swd: remove unused API frequency()
The specific SWD API to change/query the adapter speed is never
called because the equivalent JTAG API is used in place of it.
In the restructure of struct jtag_interface, the JTAG API is
promoted as global adapter API, thus a specific SWD one is not
anymore required.

Change-Id: I1e810d255b4dfcd5791b4fac8ae1260c31a057fd
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4891
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-06-06 16:20:58 +01:00
Andreas Fritiofson 8b9560349f Convert DEBUG_JTAG_IO to LOG_DEBUG_IO
Change-Id: Ifee9723a57fea93a7022be3299f69680860f236b
Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Reviewed-on: http://openocd.zylin.com/3910
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-06-04 21:48:39 +01:00
Oleksij Rempel 85ed41d210 jlink: add usb location support
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>
2019-05-31 08:49:38 +01:00
Marc Schink 9655da5aed jtag/drivers/jtag_usb_common: Fix variable name
Change-Id: I3773afa75724dc71801af39cc9135b7b9585bc47
Signed-off-by: Marc Schink <openocd-dev@marcschink.de>
Reviewed-on: http://openocd.zylin.com/5154
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-05-31 08:49:08 +01:00
Oleksij Rempel 37ad15bcb3 libjaylink: Update to latest Git version
This version introduces jaylink_device_get_usb_bus_ports()

Change-Id: Ib3fea95c3545c1340a6798e100f5ca644ec89510
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-on: http://openocd.zylin.com/4629
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-05-31 08:48:12 +01:00
Marc Schink cbf99d2df3 jtag/drivers/jtag_usb_common: Remove warning
The warning appears for every possible device during enumeration
and provides no useful information for an end-user.

Change-Id: I56e7889a5d9d4656de13ad9e21be3a6e1906e05f
Signed-off-by: Marc Schink <openocd-dev@marcschink.de>
Reviewed-on: http://openocd.zylin.com/5155
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-05-31 08:47:41 +01:00
Marc Schink e162200ab2 Fix 'adapter usb location' documentation
Change-Id: Ifd1d21f2a3cc25ee25e3c7dd04dbb8190d41a1ea
Signed-off-by: Marc Schink <openocd-dev@marcschink.de>
Reviewed-on: http://openocd.zylin.com/5156
Tested-by: jenkins
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-05-16 22:39:38 +01:00
Jan Matyas 04ebb43f93 jtag/drivers/imx_gpio: fixed calls to command_print
Two calls to command_print() in imx_gpio fixed - the first parameter
adjusted (CMD_CTX -> CMD) per the changes from this commit:
6cb5ba6f11

Change-Id: I6cb0909439a632d3109edfc68070b9b561f86d49
Signed-off-by: Jan Matyas <matyas@codasip.com>
Reviewed-on: http://openocd.zylin.com/5176
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2019-05-15 08:02:41 +01:00
Antonio Borneo ea45029829 drivers/bcm2835gpio: fix build for ARM host
The commit 84ca4995ad ("drivers/bcm2835gpio: fix usage messages")
has been merged before commit 6cb5ba6f11 ("helper/command: change
prototype of command_print/command_print_sameline") introducing two
new call to command_print() that were not modified by the second
commit.
This triggers a compile error on ARM host.

Fix the incorrect function call.

Change-Id: I2736bae24141685b7590fd6b4aa5e6a29b2cab29
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5174
Tested-by: jenkins
2019-05-15 05:33:59 +01:00
Jan Matyas b3d4c97b9f jtag_vpi: fixed state transitions in "stableclocks"
In jtag_vpi_stableclocks() the TMS line needs to be set properly
based on the current JTAG TAP state (TMS=1 in TAP_RESET state vs.
TMS=0 in other cases).

Change-Id: Id49622ba83015f97b61b6a896edde4448f1fbdc6
Signed-off-by: Jan Matyas <matyas@codasip.com>
Reviewed-on: http://openocd.zylin.com/5151
Tested-by: jenkins
Reviewed-by: Franck Jullien <franck.jullien@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-05-14 20:50:19 +01:00
Megan Wachs 6dab4c70c8 jtag_vpi: correct runtest behavior
Prevent the State Machine from moving at the end
of several cycles during run_test_idle
state.

Change-Id: Iabdf90a58334dd3d0e6e34b02983a85662062825
Signed-off-by: Megan Wachs <megan@sifive.com>
Reviewed-on: http://openocd.zylin.com/3635
Tested-by: jenkins
Reviewed-by: Jan Matyas <matyas@codasip.com>
Reviewed-by: Franck Jullien <franck.jullien@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-05-14 20:50:03 +01:00
Antonio Borneo 6cb5ba6f11 helper/command: change prototype of command_print/command_print_sameline
To prepare for handling TCL return values consistently, all calls
to command_print/command_print_sameline should switch to CMD as
first parameter.

Change prototype of command_print() and command_print_sameline()
to pass CMD instead of CMD_CTX.
Since the first parameter is currently not used, the change can be
done though scripts without manual coding.
This patch is created using the command:
	sed -i PATTERN $(find src/ doc/ -type f)
with all the following patters:
	's/\(command_print(cmd\)->ctx,/\1,/'
	's/\(command_print(CMD\)_CTX,/\1,/'
	's/\(command_print(struct command_\)context \*context,/\1invocation *cmd,/'
	's/\(command_print_sameline(cmd\)->ctx,/\1,/'
	's/\(command_print_sameline(CMD\)_CTX,/\1,/'
	's/\(command_print_sameline(struct command_\)context \*context,/\1invocation *cmd,/'

This change is inspired by http://openocd.zylin.com/1815 from Paul
Fertser but is now done through scripting.

Change-Id: I3386d8f96cdc477e7a2308dd18269de3bed04385
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/5081
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-05-14 19:37:11 +01:00
Paul Fertser 6916550938 jlink: change prototype of show_config*() functions
To prepare for handling TCL return values consistently, all calls
to command_print/command_print_sameline should be ready to switch
to CMD as first parameter.

Change prototype of show_config*() functions to pass CMD instead
of CMD_CTX.

This change was part of http://openocd.zylin.com/1815 from Paul
Fertser and has been extracted and rebased to simplify the review.

Change-Id: I131a904774bf60ad1bf9d90dbc65927c246ac23a
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5080
Tested-by: jenkins
2019-05-14 19:37:00 +01:00
Mete Balci 5b263d7b0c fix for sanitizer errors in left shifts
The modified lines cause "runtime error: left shift of <X> by <Y>
places cannot be represented in type 'int'", because integer
literal is cast to int by default.

Change-Id: Ie38119b5eb46ee470e0d149959e523b48ac4d66d
Signed-off-by: Mete Balci <metebalci@gmail.com>
Reviewed-on: http://openocd.zylin.com/5005
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-10 16:37:51 +01:00
Leonard Crestez 84e3f63a8c jtag: tcl: Add cget -idcode
This can be used to dynamically distinguish between similar chips in tcl
code.

Change-Id: Ic4dfb61693e78616355173142dc7f9b9683a9f73
Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
Reviewed-on: http://openocd.zylin.com/5033
Tested-by: jenkins
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
2019-04-10 10:16:06 +01:00
Antonio Borneo b61e454869 Set empty usage field for commands that do not need parameters
The missing field causes runtime debug message
	BUG: command '%s' does not have the '.usage' field filled out

While there, fix some minor typo in the help messages:
	s/deasert/deassert/
	s/Deasert/Deassert/

Change-Id: If3dd18265cda103ca0d05609f67f4ca58e7cbb27
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5024
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-07 08:19:34 +01:00
Antonio Borneo fcfbb1792c drivers/at91rm9200: fix help and usage to command "at91rm9200_device"
Add usage and fix the help text of the command

Change-Id: I0e157d76f5d87bcda80f82a110912994908c8e03
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5023
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Tested-by: jenkins
2019-04-07 08:18:48 +01:00
Antonio Borneo 3d59e0f612 drivers/vsllink: add help and usage to commands
Change-Id: I4a8a68147011525191ca79e65fc3d7e760371ae1
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5020
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-07 08:18:18 +01:00
Antonio Borneo 84ca4995ad drivers/bcm2835gpio: fix usage messages
The notation "(tck tms tdi tdo)* " is incorrect, because it means the
quadruple of gpio can be repeated on the command-line.
The correct syntax of the command requires instead to provide either
all the four gpio numbers (in order to set the values) or to pass an
empty command-line (to dump the values previously set).

Change the .usage field to "[tck tms tdi tdo]".
Change similarly the corresponding .usage field for SWD command.
Add the .usage field for the commands that individually set each gpio
or gpio property.
Dump the previously set values when commands bcm2835gpio_speed_coeffs
or bcm2835gpio_peripheral_base are executed with empty command-line.

Change-Id: Ie45d8268c1de331aded0bb52d5e6b8f0e8766a5b
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5019
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Tested-by: jenkins
2019-04-07 08:17:58 +01:00
Antonio Borneo f9056d222c drivers/imx_gpio: fix usage messages
The notation "(tck tms tdi tdo)* " is incorrect, because it means the
quadruple of gpio can be repeated on the command-line.
The correct syntax of the command requires instead to provide either
all the four gpio numbers (in order to set the values) or to pass an
empty command-line (to dump the values previously set).

Change the .usage field to "[tck tms tdi tdo]".
Change similarly the corresponding .usage field for SWD command.
Add the .usage field for the commands that individually set each gpio
or gpio property.
Dump the previously set values when commands imx_gpio_speed_coeffs or
imx_gpio_peripheral_base are executed with empty command-line.

Change-Id: Id56a68622817101bd0a46fed1fead6d2cd2b6ec6
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5018
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-07 08:17:48 +01:00
Antonio Borneo 57962f4d1c command_registration: add empty usage field to chained commands
Chained command require a subcommand as first argument. The usage
field for chained commands is not really important because the
"help" command will list all the subcommands with their respective
usage.

Add a empty usage field on all chained command.
The command "jlink config" can be either followed by a subcommand
or used alone, so use a dedicated usage string.

Change-Id: I43c3f8a766f96a9bdab4e709e3c90713be41fcef
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5017
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-07 08:17:36 +01:00
Frans-Willem Hardijzer 89f07325f2 stlink: Set speed before entering JTAG/SWD mode
Some boards require a slower clock speed because of passive components on the
JTAG/SWD lines. The previous implementation would first try to discover the
chips on the default speed, and only after discovery switch to the requested
adapter_khz speed.

This patch moves the speed change to just before entering the SWD/JTAG mode,
which should alleviate this problem.

Tested on an STLink V2 clone.

Change-Id: I9734452dcc8bb28d6629e64d9a7e32ef92868cf9
Signed-off-by: Frans-Willem Hardijzer <fw@hardijzer.nl>
Reviewed-on: http://openocd.zylin.com/4818
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2019-03-26 08:20:06 +00:00
Antonio Borneo 56568b7996 drivers/stlink_usb: use command STLINK_DEBUG_APIV2_READ_IDCODES
API v2 deprecates using command STLINK_DEBUG_READCOREID to read
the core ID.
Switch to STLINK_DEBUG_APIV2_READ_IDCODES on new stlink firmware
version.

Change-Id: Iabadfc116c57f2c31f08f2e77baefea0cf90bdc3
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4826
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-03-08 07:06:28 +00:00
Antonio Borneo 05c6c871e3 drivers/stlink_usb: check error code returned by st-link
Most of ST-Link commands return an error code, but this is almost
never checked.

Check for the error code for every command that returns it.

Change-Id: Ifc4e32f8c73196de23700ba0989bfdfe0f5b46e3
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4825
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-03-08 06:41:37 +00:00
Antonio Borneo d46b28983d drivers/stlink_usb: fix stlink_usb_read_regs() for API v2
API v2 implementation for command READALLREGS returns the status
in the first two bytes, followed by two bytes of padding.
This makes the reply 4 bytes longer and changes the offset of the
first register value to 4.

Fix it for the case API v2 and clean-up the management of the
return value.

Change-Id: I448c82bcc0baa72d66fdfe7f0c525b94f8a4468b
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4824
Tested-by: jenkins
Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-03-08 06:01:52 +00:00
Antonio Borneo 720380f9e3 stlink: handle error GET_IDCODE
When the connection with target is lost on the physical JTAG/SWD
link (either wire disconnected or DAP/TAP in reset), STLINK fail
to connect and returns error STLINK_JTAG_GET_IDCODE_ERROR.

Add it in the list of known errors.

Change-Id: Iabd6e6892111726f614345497d9286554bfe4ac0
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4982
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Tested-by: jenkins
2019-03-07 21:00:53 +00:00
Antonio Borneo 5c55fbb065 stlink: handle error bad-AP
The new firmwares for ST-Link support handling multiple AP, but
are (actually) limited to the AP number in range [0..8].
Any tentative to operate on AP number higher than 8 returns an
error "bad AP".
Add the error code and the related message.

Change-Id: I78a98b2612d10e580d03fc43ed9f2b09619d39d8
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4981
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Tested-by: jenkins
2019-03-07 21:00:41 +00:00
Antonio Borneo 79a8594130 stlink: remove unused assignment
Fix a warning identified by clang 7.0.1:
stlink_usb.c:1092:3: warning: Value stored to 'p' is never read
	p += sprintf(p, "S%d", swim);
	^    ~~~~~~~~~~~~~~~~~~~~~~~

Change-Id: Ic9da57e19ceecb0e3d65d3ea3412a05e1c2c779a
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4945
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-03-06 15:36:14 +00:00
Diego Herranz 4db695c66c src/jtag/drivers/ftdi: fix swd pin comment and links
- TDI/DO is not pin 2 and in fact, we don't even need to mention which
pin number it is. "TDI/DO pin" is descriptive enough.

- FT2232D link didn't work anymore. It could have been updated to the
current working FT2232D link but changed to link the FT2232H instead
which is the latest generation and the most commonly used these days.

- Taking advantage of the change, link to the MPSSE document updated.
It still worked but through a redirection, so updated just in case the
redirection stops working.

Change-Id: Ia7d01bbcac2158026831edb010a6b50f58351e42
Signed-off-by: Diego Herranz <diegoherranz@diegoherranz.com>
Reviewed-on: http://openocd.zylin.com/4908
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
2019-03-05 08:04:47 +00:00
Paul Fertser 2c76f1ac0e jtag: drivers: cmsis-dap: correct vendor request code
While at it, change the macro name to make it obvious it's a string,
not some numeric ID. This also matches ARM code that's using

Change-Id: Id35ba5b95cef0ac77657c40985b24c1ae2720748
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/3855
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-02-25 23:53:48 +00:00
Oleksij Rempel b04c7c2ca5 ftdi: use "adapter usb location" instead of ftdi_location command
Use unified "adapter usb location" instead of driver specific
command.

Change-Id: I568a76b87d09cea0f40f1580cf81f7c51402f6f1
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-on: http://openocd.zylin.com/4771
Tested-by: jenkins
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
2019-02-19 08:53:47 +00:00
Marc Schink 6c2020eb48 jlink: Use correct SWD buffer size
Currently, the SWD buffer size is adjusted corresponding to the free
device memory. However, the adjusted size is not used.

This fixes SWD operations on devices with small device memory, such as
EFM32PG12 Pearl Gecko STK. It should also fix #184.

Change-Id: I2ec5cf25c62f18bd9e99a2f4aa1aa8d85ed0821b
Signed-off-by: Marc Schink <openocd-dev@marcschink.de>
Reviewed-on: http://openocd.zylin.com/4878
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Tested-by: jenkins
2019-02-07 19:32:41 +00:00
Antonio Borneo d869c5d3d7 drivers/bitbang: remove unused extern declaration of jtag_interface
After commit a6c4eb0345 ("swd: Remove DAP from parameter list")
the global variable jtag_interface is not referenced in the driver.

Remove the extern declaration.

Change-Id: I72018a59c9cecaa52d9a49ec0d7816ac0e656314
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4874
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
2019-02-07 19:32:14 +00:00
Antonio Borneo 3117a318d4 command: fix the mode for command "jtag configure"
Before commit 877cec20dc ("command:
check command mode for native jim commands") all the jim commands
were erroneously treated as they had mode COMMAND_ANY.
The commit above fixes the code in order to check the mode and
permit running the commands only if the mode is respected.

Those jim commands that have incorrect mode were not detected nor
fixes because the wrong mode was masked by the missing mode check.
After the commit above, the wrong mode triggers error in several
existing configuration scripts.
A complete list of commands that now does not run anymore as
CONFIG_ANY is reported in ticket 225, but most of them have the
mode set correctly.
At least two instances of command "jtag configure" have the wrong
mode.

Fix the mode to CONFIG_ANY for command "jtag configure" in files
src/jtag/aice/aice_transport.c and src/jtag/tcl.c

Change-Id: I3f96c5fd24d7d463712cbaf1295284fe0dc56b23
Ticket: https://sourceforge.net/p/openocd/tickets/225/
Reported-by: Bill Paul <wpaul@users.sourceforge.net>
Fixes: 877cec20dc ("command: check command mode for native jim commands")
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4886
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Tested-by: jenkins
2019-02-07 19:01:15 +00:00
Antonio Borneo 0d48104e03 drivers/imx_gpio: fix polarity of srst and trst
The comment above the function is correct, but the code set
the GPIO with wrong (reversed) polarity.

Change-Id: Ifd09688150d3d2018af73521e0da3926bb1b7f84
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4847
Tested-by: jenkins
Reviewed-by: Grzegorz Kostka <kostka.grzegorz@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-02-07 07:51:41 +00:00
Oleksij Rempel a1b308abd4 jtag: drivers: provide initial support for usb path filtering
With this patch drivers will be able to use usb path filtering.
The path format is identical to the format provided by linux kernel:
bus-port.port....
With this format it should be easier just to copy and paste
path found in dmesg.

Change-Id: I8bafa6fcb7a66ff68cc961a376f97f4f3dee35aa
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-on: http://openocd.zylin.com/4580
Tested-by: jenkins
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
2019-02-07 07:51:30 +00:00
Antonio Borneo f63b519385 jtag: cmsis-dap: use macro SWJ_PIN_SRST in place of magic value
While connecting under reset, use the already defined macro
SWJ_PIN_SRST to assert the srst pin.

Change-Id: Icebed462c0fe8f8c15f6522dc56625aa580b8858
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4846
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-01-23 15:27:13 +00:00
Antonio Borneo c2e18bfaea arm_adi_v5: fix and update sequences to spec IHI 0031E
Fix the SWD line reset sequence accordingly to Arm specification IHI
0031E that requires at least 2 idle clocks after the 50 clocks with
SWDIO high.
Fix the value of the activation code in the (currently unused)
sequence dormant-to-SWD.
Make each sequence's length multiple of 8, so it is compatible with
adapters that have such limitation (e.g. buspirate) and try to split
and comment each part of the sequence (when possible keep each part
byte aligned, inspired from commit 3ef9beb52c). This slightly
increases the sequence length but does not impact run-time
performance because these are rarely used sequences.
Add the missing sequence dormant-to-JTAG and JTAG-to-dormant, not
used yet.

On devices that implements the dormant state, IHI 0031E deprecates
the direct switching between SWD and JTAG, and recommends using a
transition through dormant. This is not implemented.

Change-Id: Iad18c0e736cfd9366be175d22658d664b0c61eab
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4851
Tested-by: jenkins
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
2019-01-23 15:26:28 +00:00
Antonio Borneo 87adca299d drivers/sysfsgpio: fix usage messages
The notation "(tck tms tdi tdo)* " is incorrect, because it means the
quadruple of gpio can be repeated on the command-line.
The correct syntax of the command requires instead to provide either
all the four gpio numbers (in order to set the values) or to pass an
empty command-line (to dump the values previously set).

Change the .usage field to "[tck tms tdi tdo]".
Change similarly the corresponding .usage field for SWD command.
Add the .usage field for the commands that individually set each gpio.

Change-Id: If5b3c618097b71dfe7fcf988fb3c1499ae03a6d5
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4833
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-01-14 08:45:35 +00:00
Austin Phillips 42d8fa899c stlink_usb: Submit multiple USB URBs at once to improve performance
Commands to stlink devices are typically comprised of multiple
transactions with each transaction completing before moving to the next.
This change allows for multiple USB transactions to be issued at once
followed by a check that all transactions completed successfully.  This
improves performance on some machines where there is a large turn-around
time between USB transfers such as is seen on some virtual machines.

This change is only supported when compiled with libusb1 as libusb1
supports and asynchronous interface.

Multi-transaction queueing introduced in this change paves the way for
improving speed of other transactions in the future such as memory and
register reads where multiple USB transactions in succession are
required to complete a command.  Multiple USB transactions can be
submitted at once using jtag_libusb_bulk_transfer_n function.

Change-Id: I924e049217a789ef445b14e00aa1983576970fbf
Signed-off-by: Austin Phillips <austin_phillips@hotmail.com>
Reviewed-on: http://openocd.zylin.com/4484
Tested-by: jenkins
Reviewed-by: Andreas Bolsch <hyphen0break@gmail.com>
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2019-01-08 10:05:36 +00:00
Antonio Borneo 3792f3c114 libusb: add debug message on adapter not found due to wrong serial
When few adapters of the same type are in use, the serial string is
the way to select the right one.
Currently a serial string that does not match any of the connected
adapters will just fail the open, without specific information to
track the issue.

Add a specific message to highlight that the open failure is caused
by a serial mismatch.

Change-Id: I5cb77f1045cc746e532d395b2e5ced40a23ab638
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4701
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2019-01-08 10:04:42 +00:00
Antonio Borneo bf7a363b44 jtag/drivers/usb_common: return oocd error values
Where possible, keep the same style for returning error.

Change-Id: I3a04220c0b9f129a36e9fe83038b7c19dd57fe61
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4699
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2019-01-08 10:02:43 +00:00
Antonio Borneo 1b8091d253 libusb0: return oocd error values
Commit d1b7437633 fixes libusb1 to
return OpenOCD error values instead of negative errors in Linux
kernel's style.
The same fix should be applied to libusb0 too.

Fix return value of libusb0 to uniform it to OpenOCD style.

Change-Id: I68478c29c91c6be720074f58c432fe51477e03ed
Fixes: d1b7437633 ("libusb: return oocd error values")
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4698
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2019-01-08 10:01:48 +00:00
Edward Fewell 615a066629 drivers: xds110: Add support for XDS110 stand-alone probe
The XDS110 stand-alone version has the ability to supply
voltage to the target board via it's AUX FUNCTIONS port.
Added command to enable setting the voltage on the XDS110
stand-alone.

Change-Id: I2f21c4a3d15ed99e649f3a83973c5e724c4bfeb6
Signed-off-by: Edward Fewell <efewell@ti.com>
Reviewed-on: http://openocd.zylin.com/4793
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2019-01-08 09:49:03 +00:00
Antonio Borneo ff5d13a5f8 libusb0: add compatibility define for transfer type bulk
For compatibility with libusb1, define LIBUSB_TRANSFER_TYPE_BULK
in libusb0.
Remove the #ifdef HAVE_LIBUSB1 in jtag/driver/aice

This also fixes a compile error in jtag/drivers/openjtag with
libusb0.

Change-Id: I827b77eac10216759eb31aab461b2b63cabaf195
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4700
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
2018-12-11 13:29:21 +00:00
Reto Schneider a50964246d jtag: sysfsgpio: clean up swd gpios
All SWD GPIOs should be un-exported when no longer needed, not just
srst.

Change-Id: I998377afe43b72446cab3da2d4406fc2912ff8c3
Signed-off-by: Reto Schneider <code@reto-schneider.ch>
Reviewed-on: http://openocd.zylin.com/4784
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2018-12-11 13:26:22 +00:00
Tomas Vanek d5f82eea3d jtag: cmsis-dap: developer tool - enter a command by hex nuber
Handy to test vendor commands in a CMSIS-DAP adapter.

Change-Id: Ieeaa276edf770b1a3076a186e9056b4e5180362a
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/3103
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2018-12-11 13:24:55 +00:00
Antonio Borneo 0bad9a42a3 stlink: add support for STLINK-V3
Extend the driver to include the minimal functionality to support
the HLA model.
Due to the small change in the name (ST-LINK/V2 => STLINK-V3), fix
the existing names in the comments in udev rules.

Change-Id: Ied33e38063a6da81d9bf249ed195444d7cdf4f03
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4717
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
Tested-by: Spencer Oliver <spen@spen-soft.co.uk>
2018-12-06 13:06:59 +00:00
Antonio Borneo 5babb63462 stlink: fix printed version for new STM8 nucleo board
The ST-LINK/V2.1 embedded in the new nucleo boards for STM8 does
not follow the normal versioning rules, and puts mass-storage and
swim version in the field normally used respectively for jtag and
mass-storage version.

Apply the check suggested by STMicroelectronics to discriminate
the two cases and print the correct version.

Change-Id: I0dd1da11013be3f1e56084489e28cfba98bb07af
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4716
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
Tested-by: Spencer Oliver <spen@spen-soft.co.uk>
2018-12-06 13:06:34 +00:00
Antonio Borneo 6807e6b23d stlink: dump version in the same format of ST firmware upgrade tool
This should help comparing the versions before deciding for a
firmware update.

Change-Id: I7012a60587587539b2fd1a5f9c3b1ce72877793f
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4715
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
Tested-by: Spencer Oliver <spen@spen-soft.co.uk>
2018-12-06 13:06:10 +00:00
Antonio Borneo 3e2967c75a stlink: add STLINK_F_HAS_GETLASTRWSTATUS2
Starting from stlink V2J15 the API
STLINK_DEBUG_APIV2_GETLASTRWSTATUS
is obsoleted and replaced by the new API
STLINK_DEBUG_APIV2_GETLASTRWSTATUS2.

Manage the two cases to be prepared for an eventual future
removal of the obsolete API.

Change-Id: Ic4498a652865b2eb6148825138c2f6855a06ba47
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4714
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2018-12-06 13:05:49 +00:00
Antonio Borneo 717d3af087 stlink: remove reset pulse when entering in JTAG
Until version J14 the behaviour of ST-Link was to send a reset
pulse to the target when the debug connection is started in JTAG
mode. No reset pulse is sent, instead, in SWD mode.
Version J15 introduces a new parameter to avoid the reset pulse in
JTAG mode, aligning the behaviour with SWD.

This reset from the ST-Link, if propagated to the target, prevents
attaching a running target.

Actually this reset pulse is very short (few microsecond) and can
be easily filtered out by an on-board capacitor, usually present
on the reset wire (mainly to filter the bounces of the reset
button). Moreover, most of the use cases for ST-Link are with SWD
(not with JTAG) and this has probably further masked this JTAG
specific behaviour.

OpenOCD can tolerate it but requires the flag "connect_assert_srst"
to the command "reset_config", but the flag is not present in any
configurations in folder tcl. This enforces the guess it was not
noticed due to on-board capacitors or missing connection of reset
pin or ST-Link only used in SWD; so it's safe applying this patch.

Change the default behaviour to avoid reset in JTAG at connection.
There is no need to manage the ST-Link version here, since every
parameter that is not recognized by older ST-Link is treated as
"connect in JTAG with reset pulse", keeping backward compatibility.

Change-Id: Idc97a1457279e3970fd0839cadbff22d9b0302d4
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4713
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2018-12-06 13:05:44 +00:00
Antonio Borneo 80ce68b42c stlink: simplify api version handling
The API version is hardcoded in the STLINK device and depends on
the specific firmware version. There is no way to switch between
different API. Thus, it make no sense to keep in two separate
variables the current and the max API supported because they are
always equal to "the only" API supported by the specific STLINK.

Collapse h->version.jtag_api_max and h->jtag_api in a single
variable h->version.jtag_api
Remove an extra print of api version; this is already advertised
while printing the STLINK version.

Change-Id: I0519694a34748e5a0aa330932c1256080a6d5f20
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4712
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2018-12-06 13:05:38 +00:00
Antonio Borneo 861730f732 stlink: add STLINK_F_HAS_MEM_16BIT
Change-Id: I51a160a105342ddbab99c4182d89650a436f5945
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4711
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
Tested-by: Spencer Oliver <spen@spen-soft.co.uk>
2018-12-06 13:05:27 +00:00
Antonio Borneo 85223bb500 stlink: add STLINK_F_HAS_JTAG_SET_FREQ
Change-Id: I591543f218c6bb30aaeb6321ba8a9425a2b5b6e2
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4710
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
Tested-by: Spencer Oliver <spen@spen-soft.co.uk>
2018-12-06 13:05:06 +00:00
Antonio Borneo d705389f67 stlink: add STLINK_F_HAS_SWD_SET_FREQ
Change-Id: Ibba786c7e18bf15a04b85a2071c79f631a252ccf
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4709
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
Tested-by: Spencer Oliver <spen@spen-soft.co.uk>
2018-12-06 13:04:30 +00:00
Antonio Borneo ab9221f805 stlink: add STLINK_F_HAS_TARGET_VOLT
Use an alias to STLINK_F_HAS_TRACE, both are added in the same version

Change-Id: Iabf2fdac407f5c4737c3da942323d60ee50c3470
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4708
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
Tested-by: Spencer Oliver <spen@spen-soft.co.uk>
2018-12-06 13:04:09 +00:00
Antonio Borneo 3148bf838d stlink: add STLINK_F_HAS_TRACE
Fix the condition for ST-Link/V1; it does not support trace.
Trace is added on ST-Link/V2 and ST-Link/V2.1 only.

Change-Id: I17416edd05a2c8ece605560b7533edac4f982cfc
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4707
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2018-12-06 12:59:53 +00:00
Antonio Borneo 9252a94218 stlink: simplify maintenance of version and features
The number of stlink firmware version is growing, each carrying new
features. Today's code has several check distributed here and there
and it's already hard to track them and verify the correctness.
The introduction of STLINK-V3 will make the situation much worst,
and the code much less readable.

Add a "flags" bitmask in the struct stlink_usb_version to allow
setting individual bits for each feature available or for specific
quirks and workarounds.
This patch does not implement setting nor testing "flags"; it would
be introduced in following patches, one bit at a time.

Change-Id: I09d78202646a6c8330731f8aa96dc9d295fa5655
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4706
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2018-12-06 10:03:14 +00:00
Antonio Borneo 1822c2fb94 stlink: check for SWD support
The old ST-Link/V1 can either run an obsolete firmware with API_V1 or
a more recent firmware (from V1J11 to last V1J13) with API_V2.
SWD is only provided by the latter API.

Return error is SWD is selected on adapters that does not support it.

Change-Id: Iac4ba54d191ba80fb445a7cd3d8c2621dc7a4846
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4705
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2018-12-06 10:03:05 +00:00
Laurent LEMELE 81142fa6da stlink: add support for 16 bit memory read/write
Recent stlink version V2J26 introduces support for 16 bit memory
read/write.
Add the new API and modify the wrappers stlink_usb_{read|write}_mem
For older version of stlink keep the same behavior as in current
code.
While there, fix some minor typo in comments inside the wrappers.
This fixes ticket #204 ("st-link can't flash stm32f2x based flash
without target algorithms").

Change-Id: Id7d404e588f10a4b0f8a93d7ca44cef8e4c49b4f
Author: Laurent LEMELE <laurent.lemele@st.com>
Rebased-by: Antonio Borneo <borneo.antonio@gmail.com>
Ticket: https://sourceforge.net/p/openocd/tickets/204/
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4704
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2018-12-06 10:02:55 +00:00
Laurent LEMELE 1a51d493de stlink: add JTAG speed selection
ST-Link uses two separate API for setting the interface speed in SWD
and JTAG.
Add the missing API for JTAG and run the proper API depending on the
selected mode.

Change-Id: I71e955e23c1d82c2ea1c8bfade7612c5a0377a74
Author: Laurent LEMELE <laurent.lemele@st.com>
Rebased-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4703
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2018-12-06 10:02:43 +00:00
Antonio Borneo 5d9dad6de1 stlink: add usb pid for v2.1 without mass storage device
New version of ST-Link/V2.1 without mass storage device.
From debug point of view, it is compatible with existing ST-Link/V2.1
It uses a new USB PID because the USB endpoints and interfaces are
different from usual ST-Link/V2.1

Add the new PID in the driver, in the tcl interface script and in the
udev configuration script.

Change-Id: Id2e1b5a5d0347c5d951a86a9cdb76be52cfd4ea3
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4702
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2018-12-06 10:02:33 +00:00
EMARD dc415cb26c jtag: drivers: ft232r: unhardcoded
FT232R: introducing configurable parameters for pinout,
initial buffer size, state of RS232 signals at exit with
option to reattach kernel driver. All this was hardcoded before.
New parameters are documented in "openocd.texi" file.
Allows hopfully self-explainable and user-friendly adaptation to
various pinouts and similar chips like FT230X and FT231X.

Change-Id: Ib807f2ea3d4c1a164d351d65aeacd1978318d217
Signed-off-by: EMARD <vordah@gmail.com>
Reviewed-on: http://openocd.zylin.com/4681
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-by: Paul Fertser <fercerpav@gmail.com>
2018-12-06 08:51:01 +00:00
Darius Rad eb8dfd5ca8 Set TCP_NODELAY for local connections to jtag_vpi.
This increases performance drematically for local connections, which is the
most likely arrangement for a VPI connection.

Change-Id: Id15b29ae663f5d8100b2175357649bd03d05b7c8
Signed-off-by: Darius Rad <darius@bluespec.com>
Reviewed-on: http://openocd.zylin.com/4549
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2018-11-26 09:35:48 +00:00
xuguangxiao 8262e8a2c0 jtag/bitq: array boundary overflow
The for loop inside bitq_path_move function is not correct, this will
overflow the cmd->path array and produces an unpredictable result.

Change-Id: I81e3bc9ee6d1dd948acd2fe4c667103ac22bb26f
Signed-off-by: xuguangxiao <szgxxu@qq.com>
Reviewed-on: http://openocd.zylin.com/4733
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2018-11-10 21:15:39 +00:00
Tomas Vanek da4b2d5beb drivers/cmsis-dap: speed up sending multiple HID requests
The performance of CMSIS-DAP in long data transfers was improved substantially in
ef02b69b14. But it not as good as some
other USB/MCU based adapters. Using HID and therefore interrupt endpoint
is slower than USB bulk transfer.

CMSIS-DAP adapter implements multiple HID buffer handling and OpenOCD already
reads number of buffers from info command.

This change adds capability to sumbit more than one HID requests before
driver waits for a HID response. This scenario is used for long transfers only.
Results show about double speed on USB FS and ~140% speed on USB HS:

                                         | w/o this change | with multi HIDrq
-----------------------------------------+-----------------+-----------------
Open source CMSIS-DAP, USB FS, adapter_khz 1000
dump_image ram32k.bin 0x1fffe000 0x8000  |   23.225 KiB/s  |   45.901 KiB/s
load_image ram32k.bin 0x1fffe000         |   23.324 KiB/s  |   46.552 KiB/s

Cypress' Kitprog in CMSIS-DAP mode, USB FS, adapter_khz 1000 (over firmware limit)
dump_image ram64k.bin 0x20000000 0x10000 |   15.537 KiB/s  |   42.558 KiB/s
load_image ram64k.bin 0x20000000         |   15.605 KiB/s  |   43.291 KiB/s

Atmel's EDBG, USB HS, adapter_khz 10000 (#3945 applied)
dump_image ram384k.bin 0x20400000 0x6000 |  248.402 KiB/s  |  345.250 KiB/s
load_image ram384k.bin 0x20400000        |  256.039 KiB/s  |  365.945 KiB/s

Change-Id: I9edbe018086176d357c6aaba5d6b657a5e5e1c64
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/4080
Tested-by: jenkins
Reviewed-by: Paul Fertser <fercerpav@gmail.com>
2018-10-28 07:29:41 +00:00
Steven Stallion 7c298a7637 ftdi: demote unhelpful debug messages
Some protocols make use of empty scan fields for optional padding, which
causes the log to fill with unhelpful messages that a field is empty.
The remaining LOG_DEBUG messages in ftdi_execute_scan have been demoted
to DEBUG_JTAG_IO such that these messages are only seen when debugging
JTAG.

Change-Id: I61fd4551411ce851da34e67d003bca5d7a71cd92
Signed-off-by: Steven Stallion <stallion@squareup.com>
Reviewed-on: http://openocd.zylin.com/4112
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
2018-10-16 18:07:02 +01:00
Steven Stallion e72b2601e7 jtag: make cmd_queue_scan_field_clone public
This patch makes the cmd_queue_scan_field_clone function public. This
permits targets to insert fields without affecting the submitted
scan_field list. This will be used in an upcoming target implementation
that needs to insert additional padding bits.

Change-Id: I8fbd3b9b4e413432471f4f1444048932c8fa189e
Signed-off-by: Steven Stallion <stallion@squareup.com>
Reviewed-on: http://openocd.zylin.com/4082
Tested-by: jenkins
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
2018-10-16 11:58:17 +01:00
Antonio Borneo 06589d2de4 drivers: cmsis-dap: fix connection in JTAG mode
Commit 5aceec2412 ("drivers:
cmsis-dap: pull up common connect code") breaks the driver and it
cannot connect anymore in JTAG mode.
The issue is caused in cmsis_dap_init() by anticipating the call to
cmsis_dap_usb_open(), which then sets cmsis_dap_handle and makes the
following test to always fail.
Actually the original code was quite tricky:
	if (swd_mode)
		do something that also sets cmsis_dap_handle;
	if (cmsis_dap_handle == NULL)
		do something for !swd_mode;

Convert the sequence of tricky "if"s in a single "if-then-else" to
handle clearly the cases swd_mode and !swd_mode.

Change-Id: I359a23bf26a3edc2461f4352daa0be83e78868f7
Fixes: 5aceec2412 ("drivers: cmsis-dap: pull up common connect code")
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4697
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Tested-by: jenkins
2018-10-09 08:35:34 +01:00
Oleksij Rempel 2253a31fb1 ftdi: extend ftdi_location format
To existing <bus>:<port>,<port> format add <bus>-<port>.<port> support.
The last format is used by kernel and other drivers.

Change-Id: I6528970d3af4f6a8bf7b27a0f7a763b5957fdf2b
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-on: http://openocd.zylin.com/4631
Tested-by: jenkins
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
2018-09-10 11:55:43 +01:00
Oleksij Rempel d1b7437633 libusb: return oocd error values
keep same return style where possible

Change-Id: I2f9b85dbc307a483609f76a84de77e3c74d346c7
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-on: http://openocd.zylin.com/4588
Tested-by: jenkins
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
2018-09-07 08:18:53 +01:00
Antonio Borneo 64bb624479 zy1000: fix compile error with gcc 8.1.1
The fall-through comment is not taken in consideration by gcc 8.1.1
because it is inside the braces of a C-code block.

Move the comment outside the C block.

Change-Id: I22d87b2dee109fb8bcf2071ac55fdf7171ffcf4b
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4614
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2018-08-01 14:32:03 +01:00
Karl Palsson 1e374d508b drivers: cmsis-dap: print serial if available
Helpful for sanity checking connections

Change-Id: Ife0d8b4e12d4c03685aac8115c9739a4c1e994fe
Signed-off-by: Karl Palsson <karlp@tweak.net.au>
Reviewed-on: http://openocd.zylin.com/3405
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2018-07-25 14:17:00 +01:00
Daniel Glöckner e57f8e12da usb_blaster: Don't unnecessarily go through DR-/IR-Pause
There is no need to pass through DR-/IR-Pause after a scan if we want to
go to DR-/IR-Update. We just have to skip the first step of the path to
the end state because we already did that step when shifting the last
bit.

v2:
 - Fix comments as remarked in review of v1

Change-Id: I3c10f02794b2233f63d2150934e2768430873caa
Signed-off-by: Daniel Glöckner <daniel-gl@gmx.net>
Reviewed-on: http://openocd.zylin.com/4245
Tested-by: jenkins
Reviewed-by: Christopher Head <chead@zaber.com>
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
2018-07-24 13:07:44 +01:00
Antonio Borneo c5658364b2 drivers: cmsis_dap_usb: implement cmd JTAG_TMS
Simply add a wrapper around cmsis_dap_cmd_DAP_SWJ_Sequence()

Change-Id: Icf86f84b24e9fec56e2f9e155396aac34b0e06d2
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4517
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2018-07-23 14:12:10 +01:00
Darius Rad fe38562dbe Avoid dereferencing NULL pointer.
If a NULL pointer is passed, don't attempt to increment it.  This avoids
passing the now not-NULL pointer on and eventually segfaulting.  Also
remove some unnecessary temporary variables.

Change-Id: I268e225121aa283d59179bfae407ebf6959d3a4e
Signed-off-by: Darius Rad <darius@bluespec.com>
Reviewed-on: http://openocd.zylin.com/4550
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
2018-07-23 14:04:42 +01:00
Marc Schink 9f93cca427 target/armv7m_trace: Use prefix for enums
Change-Id: I3f199e6053146a1094d96b98ea174b41bb021599
Signed-off-by: Marc Schink <openocd-dev@marcschink.de>
Reviewed-on: http://openocd.zylin.com/3905
Tested-by: jenkins
Reviewed-by: Paul Fertser <fercerpav@gmail.com>
2018-07-19 10:49:24 +01:00
Marc Schink 55abb63752 target/armv7m_trace: Fix typo in enum
Change-Id: I6364ee5011ef2d55c59674e3b97504a285de0cb2
Signed-off-by: Marc Schink <openocd-dev@marcschink.de>
Reviewed-on: http://openocd.zylin.com/3904
Tested-by: jenkins
Reviewed-by: Paul Fertser <fercerpav@gmail.com>
2018-07-19 10:48:58 +01:00
Karl Palsson b24301a01a drivers: cmsis-dap: Print version info when available
No need to wait until after connecting, might help diagnose part information by
printing earlier.

Change-Id: I51eb0d584be306baa811fbeb1ad6a604773e602c
Signed-off-by: Karl Palsson <karlp@tweak.net.au>
Reviewed-on: http://openocd.zylin.com/3404
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2018-07-18 21:08:20 +01:00
Karl Palsson 5aceec2412 drivers: cmsis-dap: pull up common connect code
Just a minor deduplication

Change-Id: Idd256883e5f6d4bd4dcc18462dd5468991f507b3
Signed-off-by: Karl Palsson <karlp@tweak.net.au>
Reviewed-on: http://openocd.zylin.com/3403
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2018-07-18 21:07:43 +01:00
Hellosun Wu e36c2f2da4 nds32: Avoid detected JTAG clock
AICE2 doesn't support scan for the maximum clock frequency of
JTAG chain. It will cause USB command timeout.

Change-Id: I41d1e3be387b6ed5a4dd0be663385a5f053fbcf9
Signed-off-by: Hellosun Wu <wujiheng.tw@gmail.com>
Reviewed-on: http://openocd.zylin.com/4292
Tested-by: jenkins
Reviewed-by: Hsiangkai Wang <hsiangkai@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2018-07-18 21:06:51 +01:00
Antonio Borneo 91c125a906 jtag/drivers/cmsis-dap: fix connect in cmsis_dap_swd_switch_seq()
The proc cmsis_dap_swd_switch_seq() is part of the SWD API for
this interface driver. It is valid only when the interface is
used in SWD mode.
In this proc there is the need to call, in sequence, first
cmsis_dap_cmd_DAP_Disconnect() then cmsis_dap_cmd_DAP_Connect().
The latter call requires the connection mode as parameter, that
inside cmsis_dap_swd_switch_seq() can only be CONNECT_SWD.

The current implementation is not correct and in some cases can
pass mode CONNECT_JTAG. Moreover, JTAG is optional in CMSIS-DAP
and passing mode CONNECT_JTAG triggers an error with SWD-only
interfaces.

Use mode CONNECT_SWD in SWD specific cmsis_dap_swd_switch_seq().

Change-Id: Ib455bf5b69cb2a2d146a6c8875387b00c27a5690
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4571
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2018-07-03 07:27:14 +01:00
Edward Fewell fb287ec5f5 drivers: xds110: Remove unnecessary and deprecated libusb function.
libusb-1.0.22 has deprecated the libusb_set_debug function. This
function was present in the XDS110 driver as an artifact left over
from early debugging. It isn't required because logging is disabled
by default. Removing it to simplify the code and no longer need to
have libusb version specific #if's in the code.

Change-Id: I9c3f16c039da3f3fad9c4a1169978b0d85a1b45c
Signed-off-by: Edward Fewell <efewell@ti.com>
Reviewed-on: http://openocd.zylin.com/4553
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Tested-by: jenkins
2018-06-06 15:50:39 +01:00
Khem Raj ebf2d73340 Fix libusb-1.0.22 deprecated libusb_set_debug with libusb_set_option
libusb_set_debug is deprecated in libusb >= 1.0.22 therefore replace
with equivalent libusb_set_option()  API

Change-Id: Ic0287a1bc0ccc90afe8e4c688085f0b25a7fb004
Signed-off-by: Khem Raj <raj.khem@gmail.com>
Reviewed-on: http://openocd.zylin.com/4540
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2018-06-05 12:36:53 +01:00
Paul Fertser cdf1e826eb jtag: drivers: sysfsgpio: lift upper gpio number limit
Recent Linux maps GPIOs from 1023 downwards so do not limit the number
to 1000.

This should fix #183.

Change-Id: I6d4f493b670be9ed9b82759f0fb686a9faddbbf5
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/4502
Tested-by: jenkins
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
2018-05-31 13:25:30 +01:00
Edward Fewell 2ba27e2f3e jtag/drivers: Add support for TI XDS110 debug probe
Add support for the XDS110 debug probe using the APIs in the
probe's firmware. Includes support for older versions of the
firmware (with reduced performance) and support for a newer
version that includes OpenOCD specific APIs. Tested on various
TI LauchPads including MSP432P4, MSP432E4, CC2650, CC2652, and
CC3220SF.

Updated to add better support for swd switch. Removed issues found with
clang static analysis.

Updated to add rules entry for the XDS110 probe and Tiva DFU mode (which
affects both XDS110 and ICDI probes).

Change-Id: Ib274143111a68e67e80003797c6a68e3e80976b2
Signed-off-by: Edward Fewell <efewell@ti.com>
Reviewed-on: http://openocd.zylin.com/4322
Tested-by: jenkins
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
2018-05-31 13:25:16 +01:00
Paul Fertser b50fa9a19d Fix warnings exposed by GCC8
gcc (GCC) 8.1.0 generates new warnings and thus fails the build.

The ARM disassembler warnings actually exposed a bug in SMALW, SMULW and
SMUL instructions decoding.

Reported by Eimers on IRC.

Change-Id: I200c70f75a9e07a1f13a592addc1c5fb37714440
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/4526
Tested-by: jenkins
Reviewed-by: Jiri Kastner <cz172638@gmail.com>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
2018-05-30 09:36:46 +01:00
Antonio Borneo 3a28c8c4ba jtag: adapter: fix indentation in handle_interface_command
Minor fix, no code change, just align it to the block it belongs to.

Change-Id: I4c3b0d0bd00a55d5109d3723e5c4bfb2fc72e366
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4492
Tested-by: jenkins
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
2018-04-17 08:29:49 +01:00
Matthias Welwarsky 09076d10dd armv8: valgrind memleak fixes
Various fixes for memory leaks, adds a target cleanup for aarch64
and ARM CTI objects.

Change-Id: I2267f0894df655fdf73d70c11ed03df0b8f8d07d
Signed-off-by: Matthias Welwarsky <matthias.welwarsky@sysgo.com>
Reviewed-on: http://openocd.zylin.com/4478
Tested-by: jenkins
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2018-04-10 09:13:02 +01:00
Tomas Vanek 7829bb701f drivers/kitprog: workaround KitProg firmware bug of missing ZLP
KitProg firmware does not send a zero length packet at the end of the bulk-in
transmission of a length divisible by a bulk packet size. This is inconsistent
with the USB specification and results in jtag_libusb_bulk_read()
waits forever when a transmission of specific size is received.

Limit bulk read size to expected number of bytes for problematic tranfer sizes.
Use 1 second timeout as the last resort.

Change-Id: Ice80306424afd76e9fbc6851911ffd5109c84501
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/4426
Tested-by: jenkins
Reviewed-by: Bohdan Tymkiv <bhdt@cypress.com>
2018-04-04 21:26:59 +01:00
Tomas Vanek 6eba3777fc jtag/core, target: unregister JTAG events
Also call adapter_exit() before command_exit() as the latter releases
Jim interpreter so JTAG events should be released before.

Fixes memory leak reported by valgrind

Change-Id: I493f3fcba34ea2b4234148e79a4e329c866e0f05
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/4474
Tested-by: jenkins
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
2018-03-30 10:15:23 +01:00
Matthias Welwarsky 2231da8ec4 target: restructure dap support
- add 'dap create' command to create dap instances
- move all dap subcmmand into the dap instance commands
- keep 'dap info' for convenience
- change all armv7 and armv8 targets to take a dap
  instance instead of a jtag chain position
- restructure tap/dap/target relations, jtag tap no
  longer references the dap, daps are now independently
  created and initialized.
- clean up swd connect
- re-initialize DAP also on JTAG errors (e.g. after reset,
  power cycle)
- update documentation
- update target files

Change-Id: I322cf3969b5407c25d1d3962f9d9b9bc1df067d9
Signed-off-by: Matthias Welwarsky <matthias.welwarsky@sysgo.com>
Reviewed-on: http://openocd.zylin.com/4468
Tested-by: jenkins
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
2018-03-30 09:58:21 +01:00
Tomas Vanek 78a44055c5 transport: add transport_is_hla()
and move declaration of all transport_is_xxx() functions to transport.h

Change-Id: Ib229115b5017507b49655bc43b517ab6fb32f7a6
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/4469
Tested-by: jenkins
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
2018-03-20 11:48:44 +00:00
Tomas Vanek ff23980434 drivers/ftdi: free allocated memory
Also uses calloc() for mpsse_ctx->write_buffer to prevent a false
positive valgrind report
"Syscall param ioctl(USBDEVFS_SUBMITURB).buffer points to uninitialised bytes(s)"

Change-Id: I91963371d15c21ea0fee4c40c1da86174db44520
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/4418
Tested-by: jenkins
2018-03-15 17:10:16 +00:00
Tomas Vanek 71f5f6eb14 src/jtag/hla: free allocated memory in hl_interface_quit()
Change-Id: If6ead00e47021c88e4c106b4aeaf038db87ff50b
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/4413
Tested-by: jenkins
2018-03-15 17:09:56 +00:00
Tomas Vanek 63d7688245 jtag/core: free all taps and daps in adapter_quit()
Change-Id: I74496f6ddfb0a72b2933e8d682a73a694b8d107b
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/4411
Tested-by: jenkins
2018-03-15 17:09:09 +00:00
Matej Kogovsek ffb93ef371 jtag: drivers: add support for FT232R sync bitbang JTAG interfaces
Change-Id: Ib88a9e270f5c2a50902a137bcc97fdefd5aad1c6
Signed-off-by: Matej Kogovsek <matej@hamradio.si>
Reviewed-on: http://openocd.zylin.com/4215
Tested-by: jenkins
Reviewed-by: Paul Fertser <fercerpav@gmail.com>
2018-03-13 08:47:46 +00:00
Paul Fertser b8c7232b66 jtag: drivers: buspirate: fix abuse of "char" type
Change occurrences of char to uint8_t where appropriate as a binary
protocol is used to talk to this adapter.

This fixes a build issue with modern clang.

Change-Id: I21cc82c8cad148bd0977533c12c74a9d6ba2faff
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/4462
Tested-by: jenkins
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
2018-03-12 18:59:32 +00:00
Mateusz Manowiecki 6a4f5a4a67 Add SWD protocol support to buspirate (2nd try)
This is a second try for this patch. I removed the queues from the
previous version. I made it compatible with SRST reset and added
support for those features that could be supported in raw binary
mode.

Change-Id: I96fc06abbea9873e98b414f34afd9043fd9c2a41
Signed-off-by: Mateusz Manowiecki <segmentation@fault.pl>
Reviewed-on: http://openocd.zylin.com/3960
Tested-by: jenkins
Reviewed-by: Eric Work <work.eric@gmail.com>
Reviewed-by: Thomas Jarosch <thomas.jarosch@intra2net.com>
Reviewed-by: Jacob Alexander <haata@kiibohd.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2018-03-12 14:14:36 +00:00
Hellosun Wu 69325f6970 nds32: Add jtag scan_chain command
Create new command to refresh idcode list during runtime
and update Tap idcode.

Change-Id: Ie889a39a6f57cea207b2b9c9e42c51c97cfe4d8e
Signed-off-by: Hellosun Wu <wujiheng.tw@gmail.com>
Reviewed-on: http://openocd.zylin.com/4133
Tested-by: jenkins
Reviewed-by: Hsiangkai Wang <hsiangkai@gmail.com>
Reviewed-by: penny chen <penny6610231@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2018-03-12 14:12:59 +00:00
Paul Fertser 6c6b42664a jtag: hla: tcl: fix inconsistent expected_id handling
Copy from 20fcd0729e.
Should fix
http://build.openocd.org/job/openocd-clang/doclinks/1/report-1e9b08.html

Change-Id: I1a83387b4d745134acc38eeba08aa869d9895573
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/4333
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2018-03-12 14:10:18 +00:00
Paul Fertser f2b228f5d1 jtag: drivers: stlink: ignore write verify error
This looks like some inappropriate stlink (mis-)feature and it messes
operations for writing to certain memory-mapped registers.

Discussed at https://forum.sparkfun.com/viewtopic.php?f=18&t=44949 .
Also known to be problematic for working with Kinetis parts.

Reported by robertfoss_ on IRC.

Change-Id: I8633aed13346c596000ba6c377758e1bb96db73f
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/4368
Tested-by: jenkins
Reviewed-by: Robert Foss <robert.foss@memcpy.io>
Reviewed-by: Andreas Bolsch <hyphen0break@gmail.com>
Reviewed-by: Freddie Chopin <freddie.chopin@gmail.com>
2018-02-03 15:33:56 +00:00
Paul Fertser e60573c528 jtag: drivers: usb_blaster: clarify lowlevel driver selection code
This patch should make the code logic more transparent and user
notifications more useful.

It also fixes a warning "array subscript is below array bounds" that
leads to FTBFS on Raspbian GNU/Linux 8 (jessie).

Change-Id: I626b6a5bc013dfee7d36cf196f0abab981d30675
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/3931
Tested-by: jenkins
2018-01-27 17:16:02 +00:00
Tim Newsome 64f1f7b1c1 Add read buffer to bitbang, improving performance.
Previously for every bit scanned OpenOCD would write the bit, wait for
that bit to be scanned, and then read the result. This involves at least
2 context switches. Most of the time the next bit scanned does not
depend on the last bit we read, so with a buffer we now write a bunch of
bits to be scanned all at once, and then we wait for them all to be
scanned and have a result.

This reduces the time for one testcase where OpenOCD connects to a
simulator from 12.30s to 5.35s!

Running all our tests went from 13m13s to 3m55s.

Change-Id: Ie9fcea043ac1d7877a521125334ed47d4b3e1615
Signed-off-by: Tim Newsome <tim@sifive.com>
Reviewed-on: http://openocd.zylin.com/4312
Tested-by: jenkins
Reviewed-by: Freddie Chopin <freddie.chopin@gmail.com>
2018-01-25 16:44:06 +00:00
Christopher Head 2428722a23 Use timeval helpers
Some of these changes actually fix broken comparisons which could
occasionally fail. Others just clean up the code and make it more clear.

Change-Id: I6c398bdc45fa0d2716f48a74822457d1351f81a5
Signed-off-by: Christopher Head <chead@zaber.com>
Reviewed-on: http://openocd.zylin.com/4380
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2018-01-25 16:43:49 +00:00
Patrick Stewart 1003bc7be7 ftdi swd: disable SWD output pin during input
* Disables the data output pin while SWD is reading, so that a simple FTDI
   SWD interface can be made by connecting TCK to SWD_CLK and TDI+TDO directly
   to SWDIO. Enabled by setting SWDIO_OE to 0.

Change-Id: I7d3b71cf3f4eea163cb320aff69ed95d219190bd
Signed-off-by: Patrick Stewart <patstew@gmail.com>
Signed-off-by: Roger Lendenmann <roger.lendenmann@intel.com>
Reviewed-on: http://openocd.zylin.com/2274
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Tested-by: jenkins
2018-01-13 11:37:13 +00:00
Paul Fertser 85ac081c22 jtag: drivers: sysfsgpio, bcm2835gpio: remove requirement to have trst or srst
This doesn't seem to make any sense.

Change-Id: I272de0ea3c0e86cc9a798cbd864050aaa597c3f0
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/3933
Tested-by: jenkins
2018-01-13 08:40:44 +00:00
Ake Rehnman a6dea119a3 stlink_usb: Changes to make connect_under_reset work
Leaving mode before closing added
Resolved a collision with JTAG API v1 error/status
checking overwriting SWIM status bytes

Change-Id: I35444ec0e6caace3e072c60085059602f4cdf0a4
Signed-off-by: Ake Rehnman <ake.rehnman@gmail.com>
Reviewed-on: http://openocd.zylin.com/4265
Tested-by: jenkins
Reviewed-by: Philipp Klaus Krause
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2018-01-12 20:19:42 +00:00
Ake Rehnman 3de6b5f6e5 jtag/drivers/stlink_usb : implemented and repaired SWIM support
Fixed a bug in stlink_usb_read_mem/write_mem preventing large data transfers

The SWIM support in stlink_usb was basically non existent so I have
implemented the missing parts. The bCBWCBLength and dCBWDataTransferLength
for STLINK-V1 protocol was not correct so that was fixed. The reason for
adding SWIM support is to add STM8 support for OpenOCD.

I have tested the driver on:
STM8 discovery board with the built-in STLINK-V1
STM8 discovery board with STLINK-V2 dongle
STM32 vldiscovery board with the built-in STLINK-V1
STM32F1xxx processor with STLINK-V2 dongle

Change-Id: I4aa80a92fb0226174356adaf2f8ff949920a621f
Signed-off-by: Ake Rehnman <ake.rehnman@gmail.com>
Reviewed-on: http://openocd.zylin.com/3952
Tested-by: jenkins
Reviewed-by: Philipp Klaus Krause
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2018-01-12 20:17:55 +00:00
Forest Crossman 6f5e9941df jtag/drivers/kitprog: Enable LOG_DEBUG_IO
Change-Id: Ic01b0acf01e18bcb2bf98c101c7b5888cdc10186
Signed-off-by: Forest Crossman <cyrozap@gmail.com>
Reviewed-on: http://openocd.zylin.com/4323
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2018-01-09 16:22:30 +00:00
Tomas Vanek bb976e3c38 jtag/drivers/cmsis-dap: fix connect under reset
Commit ef02b69b14 included
a call to cmsis_dap_cmd_DAP_Connect() before calling
cmsis_dap_cmd_DAP_SWJ_Sequence(). According to comment
it is necessary for at least Keil ULINK-ME.

Commit 72c3464be4 added
a cmsis_dap_cmd_DAP_Disconnect() before connect call to pair
connection/disconnection. It solves some problems on Atmel EDBG.

Unfortunately calling either of cmsis_dap_cmd_DAP_Connect()
or cmsis_dap_cmd_DAP_Disconnect() deasserts reset signal.
So these workarounds break ability to connect under reset.

Use cmsis_dap_cmd_DAP_Disconnect() and cmsis_dap_cmd_DAP_Connect()
pair only if both SRST and TRST are deasserted.

Change-Id: I0914dae0a1360b8c7fe48231ff3867caedfb2dbe
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reported-by: Leonardo Sabino dos Santos <leonardo.sabino@gmail.com>
Reviewed-on: http://openocd.zylin.com/4100
Tested-by: jenkins
Reviewed-by: Paul Fertser <fercerpav@gmail.com>
2018-01-03 10:56:32 +00:00
Paul Fertser 31c58c139d jtag: drivers: stlink: handle all versions with single config
Extend HLA interface to allow multiple VID/PID pairs and use it to
autodetect the connected stlink version.

Change-Id: I35cd895b2260e23cf0e8fcb1fc11a78c2b99c69b
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/3961
Tested-by: jenkins
Reviewed-by: Karl Palsson <karlp@tweak.net.au>
Reviewed-by: Andreas Bolsch <hyphen0break@gmail.com>
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2017-12-12 21:13:55 +00:00
Bas Vermeulen 06aebfacda Only call cmsis_dap_cmd_DAP_SWD_Configure when swd_mode is enabled
The CMSIS-DAP used by NXP's LS1012ARDB board only supports JTAG,
and not SWD. Calling cmsis_dap_cmd_DAP_SWD_Configure returns with an
error (and doesn't actually do anything in the debugger).

Wrap the call to cmsis_dap_cmd_DAP_SWD_Configure in a check for
swd_mode, to make sure initialisation doesn't fail needlessly.

Change-Id: Id7e568cb6e36886bd7c5b3699d198a77a51c28c9
Signed-off-by: Bas Vermeulen <bas@daedalean.ai>
Reviewed-on: http://openocd.zylin.com/4294
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
2017-12-06 21:07:10 +00:00
Jonas Norling 41092636d1 ftdi: Enable SWDIO output before sending data on it
The SWDIO buffer has to be enabled, by setting SWDIO_OE, for data on
SWDIO to reach the target. Explicitly do this before sending the
switch sequences for JTAG-to-SWD, etc.

This makes the code insensitive to the state of SWDIO_OE specified in
ftdi_layout_init. It used to work only on adapters with a non-inverted
SWDIO_OE inited to 1, or inverted SWDIO_OE inited to 0.

Change-Id: I4b9e520ac1c7ce2a437251a05fc036bc68de718e
Signed-off-by: Jonas Norling <jonas.norling@cyanconnode.com>
Reviewed-on: http://openocd.zylin.com/4270
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
2017-10-27 11:48:36 +01:00
Freddie Chopin 9364b0dba4 Fix GCC7 warnings about switch-case fallthroughs
GCC7 with -Wextra warns about switch-case blocks which fallthrough with
"this statement may fall through [-Werror=implicit-fallthrough=]". This
can be fixed by adding "special" comments: "/* fallthrough */".

See https://gcc.gnu.org/gcc-7/changes.html

Change-Id: Iba0be791dbdd86984489b2d9a0592bb59828da1e
Signed-off-by: Freddie Chopin <freddie.chopin@gmail.com>
Reviewed-on: http://openocd.zylin.com/4174
Tested-by: jenkins
2017-10-23 10:54:16 +01:00
Marc Schink b0dcff5e34 jlink: Disable TCP/IP discovery
If no serial number is specified, disable TCP/IP device discovery to
ensure that a user does not unintentionally operate on a remote device.

Change-Id: I6a7e913b8b679fae003825468cd86d2014849b29
Signed-off-by: Marc Schink <openocd-dev@marcschink.de>
Reviewed-on: http://openocd.zylin.com/4214
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2017-10-03 11:19:10 +01:00
Marc Schink 98e63cdc86 jlink: Disable automatic device selection
If multiple devices are attached, do not automatically use the first
device found. Otherwise, a user may unintentionally operate on the
wrong device.

Change-Id: I08c4110b82e911e9e3e744d41830ffc6c56c44bf
Signed-off-by: Marc Schink <openocd-dev@marcschink.de>
Reviewed-on: http://openocd.zylin.com/4213
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2017-10-03 11:18:52 +01:00
Marc Schink f981730fe7 jlink: Use error description in log messages
Use a human-readable error description rather than just the error name
in log messages.

Change-Id: Iab4ff7a7e4d9993983a07eab9f462820d4ee8190
Signed-off-by: Marc Schink <openocd-dev@marcschink.de>
Reviewed-on: http://openocd.zylin.com/4212
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2017-10-03 11:18:46 +01:00
Marc Schink 7d8d2654e6 jlink: Make libusb optional
libusb is now optional for libjaylink because support for TCP/IP
devices is always available.

Change-Id: I03f2566f8e1703276671ac0f353f72394d21f2f0
Signed-off-by: Marc Schink <openocd-dev@marcschink.de>
Reviewed-on: http://openocd.zylin.com/4204
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
2017-10-03 11:18:40 +01:00