openocd.git
3 years agotarget: fix registers reading from non examined target 27/5727/4
Mikhail Rasputin [Sat, 27 Jun 2020 20:30:42 +0000 (23:30 +0300)]
target: fix registers reading from non examined target

If a target is not examined when the debugger tries to connect to it
then it can lead to undesired/undefined behavior.

In particular it leads to a zero pointer dereference on the aarch64.

Change-Id: I67f2b714ab8b2727fd36f3de16d7f9017b4c55fe
Signed-off-by: Mikhail Rasputin <mikhail.godlike.rasputin@yandex.ru>
Reviewed-on: http://openocd.zylin.com/5727
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agoFix 2 warnings about obsolete Autoconf macros. 38/5638/2
R. Diez [Thu, 30 Apr 2020 14:28:28 +0000 (16:28 +0200)]
Fix 2 warnings about obsolete Autoconf macros.

Those changes were automatically suggested by tool "autoupdate".

Change-Id: Id70bdeacc3c80816f3f5c65d1abceabb5cdf3873
Signed-off-by: R. Diez <rdiezmail-openocd@yahoo.de>
Reviewed-on: http://openocd.zylin.com/5638
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agotcl/interface: snps_sdp: fix minor typo s/similiar/similar/ 88/5788/2
Antonio Borneo [Sun, 26 Jul 2020 22:29:50 +0000 (00:29 +0200)]
tcl/interface: snps_sdp: fix minor typo s/similiar/similar/

Change-Id: I4fd6af560278b3e114cc5d8ee1b49b5c4521d8be
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Fixes: b2821b607460 ("Introduce tcl config files for Synopsys HSDK board")
Reviewed-on: http://openocd.zylin.com/5788
Tested-by: jenkins
Reviewed-by: Evgeniy Didin <didin@synopsys.com>
3 years agotcl/target/armada370: remove useless 'init' command 86/5786/2
Antonio Borneo [Wed, 22 Jul 2020 10:10:26 +0000 (12:10 +0200)]
tcl/target/armada370: remove useless 'init' command

As the comment states, the 'init' command is issued before the
command 'dap apsel', otherwise it fails.
This dependency has been already fixed in commit e48690cb26e4
("target/arm_adi_v5: allow commands apsel and apcsw during init
phase"), so the command 'dap apsel' can now be issued directly.

Remove both the unneeded 'init' command and the comment that
documents and justify its presence.

Change-Id: I50f0a820fa7ead6f5a3bd9cc5180d521070822c9
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5786
Tested-by: jenkins
3 years agotarget/arm11: fix memory leaks, including register cache 94/5694/4
Antonio Borneo [Mon, 25 May 2020 10:04:17 +0000 (12:04 +0200)]
target/arm11: fix memory leaks, including register cache

There is no deinit_target method, so few memory allocations leak
at openocd exit.
Issue identified by tracking all calls to arm_dpm_setup().

Implement the method arm11_dpm_deinit() to free all the memory
allocated in arm11_dpm_init() and call it in the new
arm11_deinit_target().

NOT TESTED on real HW.

Change-Id: Icab86e290fc2db14f70eb84c8286357aadb02a35
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5694
Tested-by: jenkins
3 years agotarget: use one second timeout while halting target at gdb attach 87/5687/2
Antonio Borneo [Tue, 19 May 2020 14:41:17 +0000 (16:41 +0200)]
target: use one second timeout while halting target at gdb attach

By default GDB timeouts after 2 seconds, even if this value can be
modified with GDB command "set remotetimeout".
On OpenOCD side, the default event for GDB attach is to halt the
target and wait it to halt. But here the default timeout of the
halt command is 5 seconds!
If the target cannot be halted (e.g. it's kept in reset by another
core or the debugger doesn't have enough privileges) then GDB will
timeout while OpenOCD is still waiting and is unable to
communicate with GDB.

Decrease the halt timeout to 1 second in the default GDB attach
event handler.

Change-Id: I231c740816bb6a0d74b0bc679a368a6cbfb34824
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5687
Tested-by: jenkins
3 years agonulink: add minimal support for Nu-Link2 20/5720/4
Antonio Borneo [Thu, 11 Jun 2020 21:55:18 +0000 (23:55 +0200)]
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>
3 years agonor/spi.c: add N25Q032A flash chip 87/5787/2
Michael Betz [Sun, 26 Jul 2020 20:51:06 +0000 (13:51 -0700)]
nor/spi.c: add N25Q032A flash chip

this flash is used on the Digilent CMODA7 FPGA board

Change-Id: I6749ca3fbebf2e384051a26a3fd253da5d6e25fb
Signed-off-by: Michael Betz <michibetz@gmail.com>
Reviewed-on: http://openocd.zylin.com/5787
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
3 years agojtag/drivers: add support for Nu-Link (Nuvoton ICE) over usb 35/5635/10
Zale Yu [Wed, 29 Apr 2020 14:53:52 +0000 (16:53 +0200)]
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>
3 years agoMake autotools warnings visible. 39/5639/3
R. Diez [Thu, 30 Apr 2020 14:31:26 +0000 (16:31 +0200)]
Make autotools warnings visible.

Change-Id: Ibcdac7100faca7a66d9b3440431e74a8a8c5f042
Signed-off-by: R. Diez <rdiezmail-openocd@yahoo.de>
Reviewed-on: http://openocd.zylin.com/5639
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
3 years agocmsis_dap_usb: Support for Microchip's nEDBG CMSIS-DAP interface 56/5756/2
Michal Potrzebicz [Fri, 10 Jul 2020 21:13:15 +0000 (22:13 +0100)]
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>
3 years agotarget: fix minor typos and duplicated words 66/5766/3
Antonio Borneo [Sun, 12 Jul 2020 18:25:00 +0000 (20:25 +0200)]
target: fix minor typos and duplicated words

Change-Id: I8deb0017dc66a243e3dd51e285aa086db500decd
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5766
Tested-by: jenkins
3 years agodrivers/bitbang: blink LED on SWD 71/5771/2
Antonio Borneo [Sat, 4 Apr 2020 17:47:09 +0000 (19:47 +0200)]
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
3 years agodrivers/linuxgpiod: add led 70/5770/2
Antonio Borneo [Sat, 4 Apr 2020 17:46:38 +0000 (19:46 +0200)]
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
3 years agosvf: fix minor typos 61/5761/2
Antonio Borneo [Sat, 11 Jul 2020 22:38:12 +0000 (00:38 +0200)]
svf: fix minor typos

Change-Id: I40ac2d01c1feb2771ce96a26c4a4d05a1e816a61
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5761
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
3 years agoflash: fix minor typo s/fifo's/fifos/ 69/5769/3
Antonio Borneo [Sun, 12 Jul 2020 22:37:17 +0000 (00:37 +0200)]
flash: fix minor typo s/fifo's/fifos/

Change-Id: I21feee50377b13cd0d48749c19abb12d499fe199
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5769
Tested-by: jenkins
3 years agocontrib: fix minor typos 68/5768/3
Antonio Borneo [Sun, 12 Jul 2020 22:32:49 +0000 (00:32 +0200)]
contrib: fix minor typos

While there, replace s/return(0)/return 0/ that causes checkpatch
to fail.

Change-Id: I5ad54cffca629475563c471114a9f77301a9e4f8
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5768
Tested-by: jenkins
3 years agojtag: fix minor typos 67/5767/2
Antonio Borneo [Sun, 12 Jul 2020 21:40:41 +0000 (23:40 +0200)]
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
3 years agoxsvf: fix minor typos 65/5765/2
Antonio Borneo [Sat, 11 Jul 2020 22:45:23 +0000 (00:45 +0200)]
xsvf: fix minor typos

Change-Id: Ib36b2178eacf79dd26ebd2e15ba385853825c198
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5765
Tested-by: jenkins
3 years agotransport: fix minor typos 64/5764/2
Antonio Borneo [Sat, 11 Jul 2020 22:42:08 +0000 (00:42 +0200)]
transport: fix minor typos

Change-Id: I481d69f9953e04c881124b2da4d092213591e4ae
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5764
Tested-by: jenkins
3 years agoserver: fix minor typos 60/5760/3
Antonio Borneo [Sat, 11 Jul 2020 22:33:29 +0000 (00:33 +0200)]
server: fix minor typos

Change-Id: Ibf835dc174a1a160ec0d57000a113c35f2713045
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5760
Tested-by: jenkins
3 years agortos: fix minor typos 59/5759/3
Antonio Borneo [Sat, 11 Jul 2020 22:25:53 +0000 (00:25 +0200)]
rtos: fix minor typos

Change-Id: I9ed4e2150a0a057397538b608d4a72bc48d0d64f
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5759
Tested-by: jenkins
3 years agoflash: fix typos and duplicated words 58/5758/2
Antonio Borneo [Sat, 11 Jul 2020 22:00:47 +0000 (00:00 +0200)]
flash: fix typos and duplicated words

Fix typos and duplicated words in comments and strings.

Change-Id: I64282c7018462deefeeb8e5f4d0d81942425b3fc
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5758
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-by: Christopher Head <chead@zaber.com>
3 years agotarget/arm720t: fix memory leak of register cache 97/5697/4
Antonio Borneo [Mon, 25 May 2020 09:19:07 +0000 (11:19 +0200)]
target/arm720t: fix memory leak of register cache

There is no method to free the register cache, allocated in
arm720t_init_target().
Issue identified by tracking all calls to arm7tdmi_init_target().

Implement the method arm720t_deinit_target() by calling directly
arm7tdmi_deinit_target().

NOT TESTED on a real arm720t target.
Tested on a arm926ejs (SPEAr320) by hacking the target type and
pretending it is a xscale:
sed -i s/arm926ejs/arm720t/ tcl/target/spear3xx.cfg

Change-Id: I53c1f46c1a355a710e8df01468b19220671569dc
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5697
Tested-by: jenkins
3 years agotarget/arm7tdmi: fix memory leak of register cache 96/5696/4
Antonio Borneo [Mon, 25 May 2020 08:58:40 +0000 (10:58 +0200)]
target/arm7tdmi: fix memory leak of register cache

There is no method to free the register cache, allocated in
arm7tdmi_init_target(), so we get a memory leak.
Issue identified by tracking all calls to arm_build_reg_cache().

Implement the method arm7tdmi_deinit_target() that in turn calls
arm7tdmi_free_reg_cache().

NOT TESTED on a real arm7tdmi target.
Tested on a arm926ejs (SPEAr320) by hacking the target type and
pretending it is a arm7tdmi:
sed -i s/arm926ejs/arm7tdmi/ tcl/target/spear3xx.cfg

Change-Id: Iad465b708eb4ebb298725d7155fea76357e9045c
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5696
Tested-by: jenkins
3 years agotarget/xscale: fix memory leak of register cache 95/5695/4
Antonio Borneo [Mon, 25 May 2020 08:43:53 +0000 (10:43 +0200)]
target/xscale: fix memory leak of register cache

There is no method to free the register cache, allocated in
xscale_build_reg_cache(), so we get a memory leak.
Issue identified by tracking all calls to arm_build_reg_cache().

Implement the method xscale_deinit_target() that in turn calls the
new xscale_free_reg_cache().
Fix leak of struct xscale.

NOT TESTED on a real xscale target.
Tested on a arm926ejs (SPEAr320) by hacking the target type and
pretending it is a xscale:
sed -i s/arm926ejs/xscale/ tcl/target/spear3xx.cfg

Change-Id: Ibb2104c42411b76f4bb77c2fa387d1b85a3d2d5d
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5695
Tested-by: jenkins
3 years agotarget: fix memory leaks on targets based on arm9tdmi 99/5699/5
Antonio Borneo [Mon, 25 May 2020 09:28:22 +0000 (11:28 +0200)]
target: fix memory leaks on targets based on arm9tdmi

Similarly to the fix for arm926ejs (also base on arm9tdmi), fix
the other targets based on arm9tdmi.
The fix for arm926ejs is tested on SPEAr320 target.

This fix is proposed separately because is not tested on a correct
target device, but tested on SPEAr320 by hacking the target type
and pretending it is the correct one, e.g.:
sed -i s/arm926ejs/arm920t/ tcl/target/spear3xx.cfg

The memory leaks detected and fixed are:
- arm register cache;
- EmbeddedICE register cache;
- arm_jtag_reset_callback internal data;
- struct <target_type>_common.

Change-Id: I565f9a5bf144a9df78474434d86a64127ef0fbe5
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5699
Tested-by: jenkins
3 years agortos: add support for RIOT 56/4256/10
Daniel Krebs [Mon, 5 Oct 2015 13:37:57 +0000 (15:37 +0200)]
rtos: add support for RIOT

Add threads support for RIOT (https://github.com/RIOT-OS/RIOT).
Original code is from Daniel Krebs.

Change-Id: I83fe3b91dd75949e800b5aea1015d8fa37b09c61
Signed-off-by: Daniel Krebs <github@daniel-krebs.net>
Signed-off-by: Vincent Dupont <vincent@otakeys.com>
Signed-off-by: Benjamin Valentin <benpicco@googlemail.com>
Reviewed-on: http://openocd.zylin.com/4256
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agotcl/target: Add initial GigaDevice GD32VF103 support 55/5755/3
Marc Schink [Wed, 8 Jul 2020 13:36:29 +0000 (15:36 +0200)]
tcl/target: Add initial GigaDevice GD32VF103 support

There is no flash bank support at the moment.

Change-Id: I52a2bde39425d94d9333cda002e5df0a1ef63c08
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/5755
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agolibjaylink: Update to 0.2.0 release 57/5757/2
Marc Schink [Sat, 11 Jul 2020 14:50:19 +0000 (16:50 +0200)]
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>
3 years agotcl/target: add Rockchip RK3308 target 74/5774/6
Jiri Kastner [Wed, 15 Jul 2020 09:31:51 +0000 (11:31 +0200)]
tcl/target: add Rockchip RK3308 target

Change-Id: Ia8c2cec0761c37623fa8a416bcfc405f2af6a6b3
Signed-off-by: Jiri Kastner <cz172638@gmail.com>
Reviewed-on: http://openocd.zylin.com/5774
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
3 years agosrc/target/arm_adi_v5.c: add Cortex-A35 related entries 73/5773/6
Jiri Kastner [Wed, 15 Jul 2020 09:30:34 +0000 (11:30 +0200)]
src/target/arm_adi_v5.c: add Cortex-A35 related entries

ROM Table registers:
https://developer.arm.com/documentation/100236/0100/debug/rom-table/rom-table-peripheral-identification-registers
Debug reisters:
https://developer.arm.com/documentation/100236/0100/debug/memory-mapped-debug-registers/external-debug-peripheral-identification-registers
PMU registers:
https://developer.arm.com/documentation/100236/0100/debug/pmu-registers/performance-monitors-peripheral-identification-registers
CTI registers:
https://developer.arm.com/documentation/100236/0100/debug/cti-registers/cti-peripheral-identification-registers

Change-Id: Ibd57d91fb9b66bc46929f4e93d0bf23c2a32f11a
Signed-off-by: Jiri Kastner <cz172638@gmail.com>
Reviewed-on: http://openocd.zylin.com/5773
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
3 years agosrc/target/arm_adi_v5.c: resorted ids 72/5772/3
Jiri Kastner [Wed, 15 Jul 2020 10:10:57 +0000 (12:10 +0200)]
src/target/arm_adi_v5.c: resorted ids

Change-Id: Ieeccf48254032244a86d6cd35793f8f6076527e9
Signed-off-by: Jiri Kastner <cz172638@gmail.com>
Reviewed-on: http://openocd.zylin.com/5772
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agosrc/flash/nor/stm32f2x: fix format strings 80/5780/3
Christopher Head [Fri, 17 Jul 2020 18:37:59 +0000 (11:37 -0700)]
src/flash/nor/stm32f2x: fix format strings

* use proper type codes
* add 0x in front of hex values
* remove some concatenated empty strings

Change-Id: I77e8dd161887f02ecf8019b43d3e8e7cc122ad0e
Signed-off-by: Christopher Head <chead@zaber.com>
Reviewed-on: http://openocd.zylin.com/5780
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agodoc/target/mips: fix grammar 77/5777/3
Christopher Head [Fri, 17 Jul 2020 18:04:50 +0000 (11:04 -0700)]
doc/target/mips: fix grammar

Change-Id: Ib9012a1cfccbe4f69682d106688536c4d92392dd
Signed-off-by: Christopher Head <chead@zaber.com>
Reviewed-on: http://openocd.zylin.com/5777
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
3 years agoIntroduce tcl config files for Synopsys HSDK board 84/5784/3
Evgeniy Didin [Mon, 20 Jul 2020 10:27:46 +0000 (13:27 +0300)]
Introduce tcl config files for Synopsys HSDK board

With this commit we add tcl configure files
for ARCv2 HS Development kit(HSDK). HSDK board
has Quad-core ARC HS38 CPU with L1 and L2
caches.

Change-Id: I372ef45428c7c7ca1421a6da3e5ed08b86f705e0
Signed-off-by: Evgeniy Didin <didin@synopsys.com>
Reviewed-on: http://openocd.zylin.com/5784
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agotarget/arc: Introduce Actionpoints support 63/5763/5
Evgeniy Didin [Fri, 10 Jul 2020 11:52:35 +0000 (14:52 +0300)]
target/arc: Introduce Actionpoints support

Actionpoint mechanism allows to setup HW breakpoints and watchpoints on Synopsys ARC CPUs.
This mechanism is controlled by DEBUG register and by a set of auxilary registers.
Each actionpoint is controlled by 3 aux registers: Actionpoint(AP) match mask(AP_AMM),
AP match value(AP_AMV) and AP control(AC).

Note: some fields of actionpoint_t structure will be used in further
support of watchpoints.

Change-Id: I4efb24675f247cc19d9122501c9e63c3126fcab4
Signed-off-by: Evgeniy Didin <didin@synopsys.com>
Reviewed-on: http://openocd.zylin.com/5763
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agospi: add MX25U1635E flash 28/5428/2
Hellosun Wu [Mon, 3 Feb 2020 02:47:02 +0000 (10:47 +0800)]
spi: add MX25U1635E flash

* Macronix 16 MBit SPI flash
* https://www.macronix.com/en-us/products/NOR-Flash/Serial-NOR-Flash/Pages/spec.aspx?p=MX25R1635F&m=Serial%20NOR%20Flash&n=PM2161
* used e.g. on Andestech ADP-XC7KFF676

Change-Id: Ida701cf3832e3302aa29b4dded1c390c5ff8c482
Signed-off-by: Hellosun Wu <wujiheng.tw@gmail.com>
Reviewed-on: http://openocd.zylin.com/5428
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agocmsis-dap: fix USB interface for NXP LPC-Link2 32/5732/4
Antonio Borneo [Mon, 29 Jun 2020 21:58:09 +0000 (23:58 +0200)]
cmsis-dap: fix USB interface for NXP LPC-Link2

The adapter NXP LPC-Link2 is a USB composite device that provides
five interfaces; among three of them that are of HID class, only
one is cmsis-dap.

Accordingly to ticket 255, OpenOCD code is not opening the right
HID interface; then it fails to communicate with the cmsis-dap
while checking the adapter's info.

Unfortunately, hidapi does not provide any support for reading the
string descriptor of the interface, otherwise it would have been
trivial to look for the right cmsis-dap interface.
In fact the cmsis-dap specification reports:
The CMSIS-DAP Firmware can be also part of a USB composite
device. If this case, the HID Interface String must
contain the sub-string CMSIS-DAP.
This requirement is satisfied by the USB device descriptor of the
LPC-Link2 reported below, but cannot be used.

Add a quirk to let OpenOCD only accept interface number zero on a
LPC-Link2 device.

Bus 001 Device 050: ID 1fc9:0090 NXP Semiconductors
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass          239 Miscellaneous Device
  bDeviceSubClass         2
  bDeviceProtocol         1 Interface Association
  bMaxPacketSize0        64
  idVendor           0x1fc9 NXP Semiconductors
  idProduct          0x0090
  bcdDevice            1.00
  iManufacturer           1 NXP Semiconductors
  iProduct                2 LPC-LINK2 CMSIS-DAP V5.224
  iSerial                 3 I3F4AABA
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x00ab
    bNumInterfaces          5
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              500mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0
      bInterfaceProtocol      0
      iInterface              4 LPC-LINK2 CMSIS-DAP V5.224
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.00
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      35
         Report Descriptors:
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               4
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               4
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        4
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0
      bInterfaceProtocol      0
      iInterface              7 LPC-LINK2 DATA PORT
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.00
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      35
         Report Descriptors:
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x84  EP 4 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x04  EP 4 OUT
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               1
    Interface Association:
      bLength                 8
      bDescriptorType        11
      bFirstInterface         1
      bInterfaceCount         2
      bFunctionClass          2 Communications
      bFunctionSubClass       2 Abstract (modem)
      bFunctionProtocol       0
      iFunction               5 VCOM
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         2 Communications
      bInterfaceSubClass      2 Abstract (modem)
      bInterfaceProtocol      0
      iInterface              5 VCOM
      CDC Header:
        bcdCDC               1.10
      CDC Call Management:
        bmCapabilities       0x01
          call management
        bDataInterface          2
      CDC ACM:
        bmCapabilities       0x02
          line coding and serial state
      CDC Union:
        bMasterInterface        1
        bSlaveInterface         2
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0010  1x 16 bytes
        bInterval               4
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        2
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass        10 CDC Data
      bInterfaceSubClass      0
      bInterfaceProtocol      0
      iInterface              5 VCOM
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        3
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0
      bInterfaceProtocol      0
      iInterface              6 LPCSIO
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.11
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      33
         Report Descriptors:
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x85  EP 5 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               2
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x05  EP 5 OUT
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               2
Device Qualifier (for other device speed):
  bLength                10
  bDescriptorType         6
  bcdUSB               2.00
  bDeviceClass            0
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0        64
  bNumConfigurations      1
Device Status:     0x0000
  (Bus Powered)

Change-Id: Ib3d46f87743a2d35a266842cb356035d898d466e
Signed-off-by: Antonio Borneo <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
3 years agocmsis-dap: prevent hidapi to search again for the adapter 31/5731/3
Antonio Borneo [Mon, 29 Jun 2020 21:22:37 +0000 (23:22 +0200)]
cmsis-dap: prevent hidapi to search again for the adapter

The code in cmsis_dap_usb_open() already searches for the right
HID device that corresponds to the adapter. By calling hid_open()
it asks hidapi to re-search the adapter again based on the VID:PID
and the serial string of the adapter it has just found!

Apart from being a run-time overhead, this has an additional
drawback; there are USB adapters built as composite USB devices
that, beside the cmsis-dap HID interface, have other HID
interfaces for other purposes.
A typical example is the NXP LPC-Link2, that over the 5 interfaces
0) cmsis-dap (HID)
1) VCOM-CDC
2) VCOM-CDC
3) LPCSIO (HID)
4) LPC-LINK2 DATA PORT (HID)
has 3 of them of HID class.
The code in cmsis_dap_usb_open() could select the right interface
but then cannot propagate this information to hid_open().

Replace the call to hid_open() with hid_open_path(), passing as
parameter the "unique" path of the HID device already found.

Checking in hidapi source code, the implementation of hid_open()
consists in enumerating the HID devices, scan for the first one
matching VID:PID and serial number, and opening it by calling
hid_open_path(). This analysis highlights that using directly
hid_open_path() should not introduce any regression.

While applying these changes, move hid_init() before enumerating
the HID devices. This has no real consequences because the HID API
is marked as optional but, logically, it should be called before
any other HID API.

Change-Id: I77ec01dca64223ec597f21f188f363366d0049c6
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Suggested-by: Masatoshi Tateishi <tateishim3@gmail.com>
Reviewed-on: http://openocd.zylin.com/5731
Tested-by: jenkins
3 years agojtag/drivers: replace perror() with LOG_ERROR() 28/5728/2
Antonio Borneo [Sun, 28 Jun 2020 21:19:23 +0000 (23:19 +0200)]
jtag/drivers: replace perror() with LOG_ERROR()

The function perror() sends the output to stderr, but OpenOCD
cannot intercept such output to send it to the log.

Replace all occurrences of perror() with LOG_ERROR(), but keeping
the same output format of perror().

The replacement is done automatically through:
sed -i 's/perror("\([^":]*\)[: ]*")/LOG_ERROR("\1: %s", strerror(errno))/' src/jtag/drivers/*.c

Change-Id: I4c140bdb09235d56cfd8bef75da9b56fbe7c2aec
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5728
Tested-by: jenkins
3 years agodoc: remove duplicated words 54/5754/2
Antonio Borneo [Sat, 4 Jul 2020 17:38:00 +0000 (19:38 +0200)]
doc: remove duplicated words

Remove occurrences of duplicated words in the documentation.

Change-Id: Ib6ef1607fc5e6387764be108b2b9c0c93ac10a62
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5754
Tested-by: jenkins
Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
3 years agotcl/interface: add example of linuxgpiod through dln-2 61/5561/5
Antonio Borneo [Wed, 1 Apr 2020 22:14:21 +0000 (00:14 +0200)]
tcl/interface: add example of linuxgpiod through dln-2

The USB adapter DLN-2 provides 32 GPIO (beside I2C, SPI, ...).
Use the first 6 GPIO for a SWD/JTAG bitbanging example through
linuxgpiod driver.

Change-Id: I229c2078142ec648fc6430b5d123539045dcfbda
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5561
Tested-by: jenkins
3 years agocontrib/60-openocd.rules: add udev rules for Linux gpiod 60/5560/5
Antonio Borneo [Mon, 30 Mar 2020 19:54:17 +0000 (21:54 +0200)]
contrib/60-openocd.rules: add udev rules for Linux gpiod

Change-Id: I767776d3659adddefe81a63f351794318463fd50
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5560
Tested-by: jenkins
3 years agojtag/drivers: add linuxgpiod driver 59/5559/5
Antonio Borneo [Sun, 29 Mar 2020 14:08:50 +0000 (16:08 +0200)]
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
3 years agobcm2835gpio: enable only the transport specific gpio 58/5558/3
Antonio Borneo [Wed, 1 Apr 2020 10:03:47 +0000 (12:03 +0200)]
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
3 years agoimx_gpio: enable only the transport specific gpio 57/5557/3
Antonio Borneo [Wed, 1 Apr 2020 09:53:30 +0000 (11:53 +0200)]
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>
3 years agosysfsgpio: enable only the transport specific gpio 56/5556/3
Antonio Borneo [Wed, 1 Apr 2020 09:37:54 +0000 (11:37 +0200)]
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
3 years agobitbang: split jtag and swd operations 55/5555/4
Antonio Borneo [Wed, 1 Apr 2020 09:00:39 +0000 (11:00 +0200)]
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
3 years agobitbang: remove superfluous switch between jtag and swd 54/5554/3
Antonio Borneo [Wed, 1 Apr 2020 07:39:40 +0000 (09:39 +0200)]
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
3 years agobitbang: document bitbang callbacks 53/5553/3
Antonio Borneo [Wed, 1 Apr 2020 07:37:54 +0000 (09:37 +0200)]
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
3 years agoflash/nor/kinetis: fix FCF handling 53/5753/3
Tomas Vanek [Thu, 2 Jul 2020 08:50:15 +0000 (10:50 +0200)]
flash/nor/kinetis: fix FCF handling

Kinetis Flash Configuration Field needs special handling to prevent unwanted
locking of the device. Warn user about any difference between generated
FCF and FCF data in the programmed file. Inform user that re-programming
of already programmed FCF may fail on devices with FTFE flash module.

While on it remove useless setting of is_erased flag after erase.

Change-Id: I3911f436674547fa12ef3886c7d5e8cd889f9e2b
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Fixes: https://sourceforge.net/p/openocd/tickets/270/
Reported-by: Noel Diviney <vk3avm@users.sourceforge.net>
Reviewed-on: http://openocd.zylin.com/5753
Tested-by: jenkins
3 years agoflash/nor/kinetis: use target_get_working_area_avail() 52/5752/2
Tomas Vanek [Thu, 2 Jul 2020 07:33:57 +0000 (09:33 +0200)]
flash/nor/kinetis: use target_get_working_area_avail()

Since e22c6484eaedd56d71 the trial/error allocation shows
"not enough working area available(requested 2048)" message
on klx.cfg. The message is not clear if it means a problem or not.

Replace with new style allocation using target_get_working_area_avail()

Change-Id: I87fe1e38248fcac29982b72aaba12217a0552f38
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: http://openocd.zylin.com/5752
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
3 years agogdb_server: suggest user to prefer GDB extended mode 11/5311/3
Antonio Borneo [Fri, 27 Sep 2019 11:17:15 +0000 (13:17 +0200)]
gdb_server: suggest user to prefer GDB extended mode

In case of GDB connection not using extended mode, issue a warning
message to suggest the user to switch using the extended mode.
Issue the message only once at each run of OpenOCD, to avoid too
much noise.
Update the documentation to suggest using extended mode.

Change-Id: I9326e84f748d5d7912d5a48f00f0fb541ca19221
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5311
Tested-by: jenkins
Reviewed-by: Karl Palsson <karlp@tweak.net.au>
3 years agocoding style: add arguments to function prototypes 30/5630/3
Antonio Borneo [Mon, 6 May 2019 22:26:46 +0000 (00:26 +0200)]
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>
3 years agocoding style: fix space separation 27/5627/4
Antonio Borneo [Mon, 6 May 2019 16:16:17 +0000 (18:16 +0200)]
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
3 years agocoding style: fix print of hex values as decimal 24/5624/4
Antonio Borneo [Mon, 6 May 2019 12:22:06 +0000 (14:22 +0200)]
coding style: fix print of hex values as decimal

It is an error to prefix with "0x" the print of values in decimal.
Replace the incorrect decimal format specifier with PRIx32.

Issue identified by checkpatch script from Linux kernel v5.1 using
the command

find src/ -type f -exec ./tools/scripts/checkpatch.pl \
-q --types PRINTF_0XDECIMAL -f {} \;

Change-Id: I2eb867ef654527b2737ba573a405ec8f97c6a739
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5624
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
3 years agotarget/arm926ejs: fix memory leaks 98/5698/4
Antonio Borneo [Sun, 14 Jun 2020 21:18:21 +0000 (23:18 +0200)]
target/arm926ejs: fix memory leaks

The memory leaks detected and fixed are:
- arm register cache;
- EmbeddedICE register cache;
- arm_jtag_reset_callback internal data;
- struct arm926ejs_common.

Issue identified with valgrind.
Tested on SPEAr320 based on arm926ejs.

Change-Id: If2bed02c516051ce4d0eb29b204a3f3337fe5d6a
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5698
Tested-by: jenkins
3 years agoconfigure: split build of hla layouts 19/5719/2
Antonio Borneo [Wed, 10 Jun 2020 14:08:41 +0000 (16:08 +0200)]
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
3 years agoflash/nor/w600: Use 'bool' data type 51/5751/2
Marc Schink [Wed, 1 Jul 2020 08:27:19 +0000 (10:27 +0200)]
flash/nor/w600: Use 'bool' data type

Change-Id: Ia71ffba82b23ed1860acc5daf6c66fa574a0d797
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/5751
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agoflash/nor/stmsmi: Use 'bool' data type 50/5750/2
Marc Schink [Wed, 1 Jul 2020 08:27:11 +0000 (10:27 +0200)]
flash/nor/stmsmi: Use 'bool' data type

Change-Id: I0b9d3eb6fa40cc9fed6491c8f583580fb471bcac
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/5750
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agoflash/nor/stm32h7x: Use 'bool' data type 49/5749/2
Marc Schink [Wed, 1 Jul 2020 08:26:57 +0000 (10:26 +0200)]
flash/nor/stm32h7x: Use 'bool' data type

Change-Id: Ib9c567e2287f2a99172bd3bd35a81e3205cea421
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/5749
Tested-by: jenkins
Reviewed-by: Christopher Head <chead@zaber.com>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agoflash/nor/sh_qspi: Use 'bool' data type 48/5748/2
Marc Schink [Wed, 1 Jul 2020 08:26:32 +0000 (10:26 +0200)]
flash/nor/sh_qspi: Use 'bool' data type

Change-Id: Id5567102013648b1565078310abc27bee4446992
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/5748
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agoflash/nor/pic32mx: Use 'bool' data type 47/5747/2
Marc Schink [Wed, 1 Jul 2020 08:26:12 +0000 (10:26 +0200)]
flash/nor/pic32mx: Use 'bool' data type

Change-Id: I9a0b60bc07781401f26df31303b8c04822b7ddc2
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/5747
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agoflash/nor/mrvlqspi: Use 'bool' data type 46/5746/2
Marc Schink [Wed, 1 Jul 2020 08:25:45 +0000 (10:25 +0200)]
flash/nor/mrvlqspi: Use 'bool' data type

Change-Id: Icc64d9ba56841ff6eb96efcbdc9545938ebb7347
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/5746
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agoflash/nor/mdr: Use 'bool' data type 45/5745/2
Marc Schink [Wed, 1 Jul 2020 08:25:27 +0000 (10:25 +0200)]
flash/nor/mdr: Use 'bool' data type

Change-Id: I1eced61e5cb062445078e05507f6ad1a5a594c8d
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/5745
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agoflash/nor/max32xxx: Use 'bool' data type 44/5744/2
Marc Schink [Wed, 1 Jul 2020 08:25:07 +0000 (10:25 +0200)]
flash/nor/max32xxx: Use 'bool' data type

Change-Id: I828cdd6d97a59fd0692eb22ba8fc0a5759029432
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/5744
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agoflash/nor/lpcspifi: Use 'bool' data type 43/5743/2
Marc Schink [Wed, 1 Jul 2020 08:24:53 +0000 (10:24 +0200)]
flash/nor/lpcspifi: Use 'bool' data type

Change-Id: I0485a7885fe154f983c7a7ce84cbedb0ba32ca31
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/5743
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agoflash/nor/jtagspi: Use 'bool' data type 42/5742/2
Marc Schink [Wed, 1 Jul 2020 08:24:35 +0000 (10:24 +0200)]
flash/nor/jtagspi: Use 'bool' data type

Change-Id: I0e81dd476c6b3ec7fee6c84ab1bfcf9bca90c532
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/5742
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agoflash/nor/fm3: Use 'bool' data type 41/5741/2
Marc Schink [Wed, 1 Jul 2020 08:24:19 +0000 (10:24 +0200)]
flash/nor/fm3: Use 'bool' data type

Change-Id: Ic90ab762488063f6958f5e775c1b2fe5f3f1718f
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/5741
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agoflash/nor/fespi: Use 'bool' data type 40/5740/2
Marc Schink [Wed, 1 Jul 2020 08:24:11 +0000 (10:24 +0200)]
flash/nor/fespi: Use 'bool' data type

Change-Id: I4583b4475b2fa2733db0861bfe8f52f0a514c472
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/5740
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agoflash/nor/em357: Use 'bool' data type 39/5739/2
Marc Schink [Wed, 1 Jul 2020 08:23:59 +0000 (10:23 +0200)]
flash/nor/em357: Use 'bool' data type

Change-Id: I251b62275d204fdc315cd167685799c15d4e7cf4
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/5739
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agoflash/nor/cfi: Use 'bool' data type 38/5738/4
Marc Schink [Wed, 1 Jul 2020 08:23:44 +0000 (10:23 +0200)]
flash/nor/cfi: Use 'bool' data type

Change-Id: I25198223175c26aded9ad667b802da09883e94ee
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/5738
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agoflash/nor/atsamv: Use 'bool' data type 37/5737/2
Marc Schink [Wed, 1 Jul 2020 08:23:23 +0000 (10:23 +0200)]
flash/nor/atsamv: Use 'bool' data type

Change-Id: Id4ceaf38dc5eba5b0eb62416fc357fdfc7ea21c0
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/5737
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agoflash/nor/ath79: Use 'bool' data type 36/5736/2
Marc Schink [Wed, 1 Jul 2020 08:22:37 +0000 (10:22 +0200)]
flash/nor/ath79: Use 'bool' data type

Change-Id: Iecd29dcfcc1ae983e4e0828025d2d174944c1e9d
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/5736
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agoflash/nor/at91sam4: Use 'bool' data type 35/5735/2
Marc Schink [Wed, 1 Jul 2020 08:22:15 +0000 (10:22 +0200)]
flash/nor/at91sam4: Use 'bool' data type

Change-Id: Iade91ac58a995676c412606a63e62b70337427f1
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/5735
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agoflash/nor/at91sam3: Use 'bool' data type 34/5734/2
Marc Schink [Wed, 1 Jul 2020 08:21:52 +0000 (10:21 +0200)]
flash/nor/at91sam3: Use 'bool' data type

Change-Id: Ibaf599a4ab88ea36a84b3389e2f704554d465434
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/5734
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agoflash/nor/ambiqmicro: Use 'bool' data type 33/5733/2
Marc Schink [Wed, 1 Jul 2020 08:21:06 +0000 (10:21 +0200)]
flash/nor/ambiqmicro: Use 'bool' data type

Change-Id: Ia8492905dc506d518266343d699c3245efbc1ab1
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/5733
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agojtag/tcl: fix a double free of jim object 24/5724/4
Mikhail Rasputin [Wed, 24 Jun 2020 16:21:31 +0000 (19:21 +0300)]
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>
3 years agoflash/nor: Use proper data types in driver API 29/4929/7
Marc Schink [Sun, 7 Jun 2020 15:00:13 +0000 (17:00 +0200)]
flash/nor: Use proper data types in driver API

Use 'unsigned int' and 'bool' instead of 'int' where appropriate.
While at it, fix some coding style issues.

No new Clang analyzer warnings.

Change-Id: I700802c9ee81c3c7ae73108f0f8f06b15a4345f8
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/4929
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agoflash/nor/atsame5: Fix a timeout when erasing 06/5706/7
Michael Hope [Fri, 29 May 2020 20:30:44 +0000 (22:30 +0200)]
flash/nor/atsame5: Fix a timeout when erasing

According to the datasheet, erasing a block can take up to 200 ms.
When using a Segger J-Link with a 2 MHz clock the current loop
finishes after < 50 ms, ignores the timeout, and then fails when
erasing the next block.

Switch to a time based check, add an explicit yield, and report an
error on timeout.

Change-Id: I8255401d1e59f427a08d2cccb8a66143dcdbb324
Signed-off-by: Michael Hope <mlhx@google.com>
Reviewed-on: http://openocd.zylin.com/5706
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
3 years agotarget: do not print an error on shutdown in target events 10/5710/2
Antonio Borneo [Tue, 2 Jun 2020 12:43:29 +0000 (14:43 +0200)]
target: do not print an error on shutdown in target events

Before commit b3ce5a0ae545 ("target: use LOG_USER to print errors
in events") an error in an event handler was silently lost, while
now the associated message is printed out.

A "shutdown" command in a target event (e.g. in gdb-detach) causes
the event to end with error code ERROR_COMMAND_CLOSE_CONNECTION,
that triggers the error message:
shutdown command invoked
Error executing event <event-name> on target <target-name>:

The error code returned by the command "shutdown" is required to
stop the execution in a script/proc and avoid executing any
further command in the script/proc.
It is then normal to get an error code from the "shutdown" command
and it should not be printed out.

Intercept the return code of the event in case of "shutdown", then
skip scheduling other target events and return without printing
the incorrect error message.

Change-Id: Ia3085fb46beacb90a5e4bf0abf7c6e28bb9e6a9b
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reported-by: Laurent Lemele <laurent.lemele@st.com>
Reviewed-on: http://openocd.zylin.com/5710
Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Tested-by: jenkins
3 years agojtag: drivers: xlnx-pcie-xvc: Add support for SWD mode. 47/5447/5
Moritz Fischer [Sun, 9 Feb 2020 00:09:04 +0000 (16:09 -0800)]
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>
3 years agotarget/arc: Introduce L1I,L1D,L2 caches support 88/5688/5
Evgeniy Didin [Fri, 15 May 2020 20:04:01 +0000 (23:04 +0300)]
target/arc: Introduce L1I,L1D,L2 caches support

With this commit we introduce L1 and L2 cache
flush and invalidate operations which are necessary for
getting/setting actual data during memory r/w operations.

We introduce L2 cache support, which is not presented
on currently support EMSK board. But L2 is presented
on HSDK board, which soon will be introduced.

Change-Id: I2fda505a47ecb8833cc9f5ffe24f6a4e22ab6eb0
Signed-off-by: Evgeniy Didin <didin@synopsys.com>
Reviewed-on: http://openocd.zylin.com/5688
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agoaarch64: Add support for debugging in HYP mode on ARMv8-A cores 55/5255/4
Lucas [Sun, 17 May 2020 15:42:39 +0000 (16:42 +0100)]
aarch64: Add support for debugging in HYP mode on ARMv8-A cores

When debugging an ARMv8-A/AArch32 target running HYP mode, OpenOCD would
throw the following error to GDB on most operations (step, set breakpoint):

cannot read system control register in this mode

The mode in question is 0x1A, a privilege level 2 mode available on cores
that have the virtualization extensions (such as the Raspi 3).

Note: this mode is only used when running in AArch32 compatibility mode.

Signed-off-by: Lucas Jenss <public@x3ro.de>
Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Change-Id: Ia8673ff34c5b3eed60e24d8da57c3ca8197a60c2
Reviewed-on: http://openocd.zylin.com/5255
Tested-by: jenkins
Reviewed-by: Lucas Jenß <lucas.jenss@gmail.com>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agolibjaylink: Update to latest Git version 23/5723/2
Marc Schink [Sun, 14 Jun 2020 19:57:35 +0000 (21:57 +0200)]
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>
3 years agotarget/armv7m_trace: Calculate prescaler for external capture devices 10/5610/3
Marc Schink [Sun, 26 Apr 2020 17:28:15 +0000 (19:28 +0200)]
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>
3 years agotarget/icepick.cfg: Add support for Test TAPs in ICEPick C 15/5715/2
Edward Fewell [Wed, 3 Jun 2020 19:55:07 +0000 (14:55 -0500)]
target/icepick.cfg: Add support for Test TAPs in ICEPick C

In addition to the debug TAPs, the ICEPick C also supports
a bank of Test TAPs (limited functionality intended for
non-debuggable targets). Added support for Test TAPs to
the icepick_c_tapenable routine. Port numbers of 0 to 15
will continue to be handled as a debug TAP number. Test
TAPs will be port numbers of 16 to 31.

This functionality will be needed for doing a flash
mass erase on CC26xx/CC13xx targets. It is possible
for user application to block even adding the Cortex M
TAP to the scan chain, so the only way to unbrick the
target and erase the flash is using a component on a
test TAP of the device's ICEPick router.

Change-Id: I0aa52a08d43a00cbd396efdeadd504fc31c98510
Signed-off-by: Edward Fewell <efewell@ti.com>
Reviewed-on: http://openocd.zylin.com/5715
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agoflash/nor/stm32l4x: Fix check for number of arguments 16/5716/2
Marc Schink [Fri, 15 May 2020 08:06:07 +0000 (10:06 +0200)]
flash/nor/stm32l4x: Fix check for number of arguments

The current version erroneously allows any number of arguments >= 1.

Change-Id: I64156c11b48d411c72bebbf866954818cd036ff2
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: http://openocd.zylin.com/5716
Tested-by: jenkins
Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agostlink: code factorization by introducing stlink_usb_exit_mode 12/5612/3
Tarek BOCHKATI [Mon, 27 Apr 2020 12:09:27 +0000 (13:09 +0100)]
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
3 years agoopenocd: fix issue in WIN32 with TCP adapters 56/5456/5
Tarek BOCHKATI [Thu, 23 Apr 2020 10:00:31 +0000 (11:00 +0100)]
openocd: fix issue in WIN32 with TCP adapters

Issue: server_quit is called before adapter_quit:
  In WIN32 only in server_quit we do an WSACleanup,
  which terminates/closes all active sockets.
  So if the adapter is TCP based, the adapter.quit handler
  will fail if it will need to send some commands through TCP.

Example: close_socket in jtag_vpi_quit will fail in WIN32
  because the socket is already closed
  and the errno is set as "Bad File Descriptor"

To fix that we introduced new functions called server_host_os_entry/quit
to manage specific OS setup (hence WSA for sockets in WINDOWS) in order
to delay WSACleanup after adapter_quit().

Change-Id: Ie4afacafe123857f6ae300e376bdfcf0d8c027ac
Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Reviewed-on: http://openocd.zylin.com/5456
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
3 years agoboard: Add the HiFive1 revB board configuration 80/5680/2
Alistair Francis [Wed, 13 May 2020 22:04:16 +0000 (15:04 -0700)]
board: Add the HiFive1 revB board configuration

Change-Id: If186afcfd2c87414b9323569a16aed9a6054c883
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-on: http://openocd.zylin.com/5680
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Tim Newsome <tim@sifive.com>
3 years agoflash: Add the Freedom E310-G002 SPI Flash 79/5679/2
Alistair Francis [Wed, 13 May 2020 22:03:44 +0000 (15:03 -0700)]
flash: Add the Freedom E310-G002 SPI Flash

Change-Id: Id9f4a209a6eacf186931b142e70a5b0458517be0
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-on: http://openocd.zylin.com/5679
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Tim Newsome <tim@sifive.com>
3 years agocoding style: fix multi-line dereferencing 29/5629/4
Antonio Borneo [Mon, 6 May 2019 17:31:00 +0000 (19:31 +0200)]
coding style: fix multi-line dereferencing

Issue identified by checkpatch script from Linux kernel v5.1 using
the command

find src/ -type f -exec ./tools/scripts/checkpatch.pl \
-q --types MULTILINE_DEREFERENCE -f {} \;

Change-Id: Icba05613e22a72ecc3e6a0aad7cb6b479496146f
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5629
Tested-by: jenkins
Reviewed-by: Marc Schink <dev@zapb.de>
3 years agojtag/tcl: fix memory leak in command 'irscan' 92/5692/2
Antonio Borneo [Thu, 21 May 2020 14:03:17 +0000 (16:03 +0200)]
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>
3 years agotarget/cortex_a: fix memory leak of register cache 93/5693/3
Antonio Borneo [Fri, 22 May 2020 16:55:34 +0000 (18:55 +0200)]
target/cortex_a: fix memory leak of register cache

There is no method to free the register cache, allocated in
armv4_5, so we get a memory leak.
Issue identified by valgrind.

Implement the method arm_free_reg_cache() and call it in cortex_a
deinit and to exit for error during arm_dpm_setup().
Tested on dual cortex-A stm32mp15x.
This change is inspired from similar fix in commit b01b5fe13a67
("armv7m: Fix memory leak in register caching.").

The same allocation is also used by target types "arm7tdmi",
"arm9tdmi", "arm11" and "xscale" but they all lack the deinit
method and I do not have relevant HW to test the fix. For such
reasons they are not addressed in this patch.

Change-Id: I4da1e1f12e36ec245d1f3b11a4eafcbd9a1d2e25
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5693
Tested-by: jenkins
3 years agotarget/mem_ap: fix two memory leaks 00/5700/2
Antonio Borneo [Fri, 22 May 2020 16:08:55 +0000 (18:08 +0200)]
target/mem_ap: fix two memory leaks

The target mem_ap misses the method 'deinit_target' and does not
free the memory allocated during 'target create' and 'configure'.

Add the missing method and free the allocated memory.
Issue identified with valgrind.

Change-Id: If0d0114a75dd76a8b65c2d46d96c6085fd31a09d
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5700
Tested-by: jenkins
3 years agolibusb_helper: fix memory leak when no adapter is found 01/5701/2
Antonio Borneo [Mon, 25 May 2020 19:37:12 +0000 (21:37 +0200)]
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
3 years agotarget/cortex-m: enable C_DEBUGEN during examine 02/5702/2
Antonio Borneo [Tue, 26 May 2020 22:03:45 +0000 (00:03 +0200)]
target/cortex-m: enable C_DEBUGEN during examine

Current code for Cortex M does not set C_DEBUGEN as soon as
possible, (which means during target examine), but later-on either:
1) at command 'halt' (e.g. for 'gdb-attach' event);
2) at command 'soft_reset_halt';
3) at commands 'reset', 'reset halt' or 'reset init';
4) during polling, but only if the target:
    = enter in 'double fault', or
    = exit from a reset, or
    = halts (not possible if C_DEBUGEN is not set)

Plus, if commands in 1) or 2) are executed before the very first
poll of the target, the value of 'cortex_m->dcb_dhcsr' is used not
initialized while writing it back in DCB_DHCSR.

Another side effect of this situation is that it's possible to set
a HW breakpoint with the target running, while C_DEBUGEN is not
set. Accordingly to [1], C1.3.1 "Debug authentication":
    When DGBEN is LOW and DHCSR.S_HALT == 0:
    ...
    FPB breakpoints do not generate an entry to Debug state and,
    if no DebugMonitor exception is generated, will escalate to
    HardFault, Lockup, or be ignored.
On STM32MP15x I get HW breakpoint ignored, while on STM32F411 I
get HardFault.
E.g. following these steps:
- power-on a pre-flashed board that starts running the firmware;
- connect openocd, without halting or resetting the board;
- set a HW breakpoint to some address often executed;
- wait, but the board doesn't halt ...;
- type the command 'halt';
- if the Cortex-M has HardFault it would be visible and the fault
  is at the breakpoint address;
- if no HardFault then type the command 'resume';
- wait and the board will finally halt at the HW breakpoint.

A similar issue has been detected on Cortex-A code and fixed by
commit bff87a7f28fb ("target/cortex_a: enable DSCR_HALT_DBG_MODE
during examine").
Follow the same approach and set C_DEBUGEN during examine.
Also, initialize 'cortex_m->dcb_dhcsr' during examine.

[1] ARM DDI 0403E "ARM v7-M Architecture Reference Manual"

Change-Id: I5b0b23403634f7dfce38f104bba9f59c33eb3e99
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5702
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Reviewed-by: Moritz Fischer <moritzf@google.com>
3 years agolog: fix kept_alive() and report expired timeout 05/5705/3
Antonio Borneo [Fri, 29 May 2020 10:00:35 +0000 (12:00 +0200)]
log: fix kept_alive() and report expired timeout

The kept_alive() function is called to inform the keep-alive code
that a keep-alive as been just kicked through some other path.
But kept_alive() erroneously resets the timeout counter without
checking if it has already expired, thus masking a potential
timeout.

Check if timeout counter has expired during kept_alive().
While there, put the timeout values in macros and explicit the
units in the timeout messages.

Change-Id: Iaf6368b44e5b5352b1cc4e7efbb2368575dcfa08
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/5705
Reviewed-by: <jonatan_zeidler@gmx.de>
Tested-by: jenkins

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)