Commit Graph

7717 Commits

Author SHA1 Message Date
Antonio Borneo 057e566097 openocd: src/target: replace the GPL-2.0-or-later license tag
Replace the FSF boilerplate with the SPDX tag.

The SPDX tag on files *.c is incorrect, as it should use the C99
single line comment using '//'. But current checkpatch doesn't
allow C99 comments, so keep using standard C comments, by now.

Change-Id: I255ad17235ff1e01bf0aa4deed4d944e1d693ddb
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7071
Tested-by: jenkins
2022-07-23 13:58:51 +00:00
Antonio Borneo 58f987aa85 openocd: src/rtos: replace the GPL-2.0-or-later license tag
Replace the FSF boilerplate with the SPDX tag.

The SPDX tag on files *.c is incorrect, as it should use the C99
single line comment using '//'. But current checkpatch doesn't
allow C99 comments, so keep using standard C comments, by now.

Change-Id: If0194089baded7f58dc5d87a35d6e0aff9f43785
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7070
Tested-by: jenkins
2022-07-23 13:58:32 +00:00
Antonio Borneo eb56509fa4 openocd: src/jtag: replace the GPL-2.0-or-later license tag
Replace the FSF boilerplate with the SPDX tag.

The SPDX tag on files *.c is incorrect, as it should use the C99
single line comment using '//'. But current checkpatch doesn't
allow C99 comments, so keep using standard C comments, by now.

Change-Id: Ie873d12bb0fb838d0d6252e6b9ca3c2118853e9a
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7069
Tested-by: jenkins
2022-07-23 13:55:06 +00:00
Antonio Borneo 533f0f1b87 openocd: src/helper: replace the GPL-2.0-or-later license tag
Replace the FSF boilerplate with the SPDX tag.

The SPDX tag on files *.c is incorrect, as it should use the C99
single line comment using '//'. But current checkpatch doesn't
allow C99 comments, so keep using standard C comments, by now.

Change-Id: I7851617e2682f97ccc3927e3941aadef2df63b54
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7068
Tested-by: jenkins
2022-07-23 13:54:09 +00:00
Antonio Borneo c270e96637 openocd: src/flash: replace the GPL-2.0-or-later license tag
Replace the FSF boilerplate with the SPDX tag.

The SPDX tag on files *.c is incorrect, as it should use the C99
single line comment using '//'. But current checkpatch doesn't
allow C99 comments, so keep using standard C comments, by now.

Change-Id: Ic7db91fe37d1139d42c99e303b3243b6c8fe3ea2
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7067
Tested-by: jenkins
2022-07-23 13:16:27 +00:00
Antonio Borneo c3d3487d61 openocd: src: fix incorrect SPDX tags
The SPDX tag is aimed at machine handling and it's thus expected
to be placed in the first line in specific format.

Move the SPDX tag to the first line and fix it where needed.

The SPDX tag on files *.c is incorrect, as it should use the C99
single line comment using '//'. But current checkpatch doesn't
allow C99 comments, so keep using standard C comments, by now.

Change-Id: Ie9a05f530009d482a4116eebd147fd7e1ee3d41e
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7066
Tested-by: jenkins
2022-07-23 13:16:09 +00:00
Antonio Borneo 4db9add47f openocd: src: fix incorrect GPL license tag
Use the standard SPDX tag, where it was incorrectly applied.

The SPDX tag on files *.c is incorrect, as it should use the C99
single line comment using '//'. But current checkpatch doesn't
allow C99 comments, so keep using standard C comments, by now.

Change-Id: Iaec63abc6e0a38e5b0ae0ea7f5ecee7ca007bbbd
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7065
Tested-by: jenkins
2022-07-23 13:15:54 +00:00
Antonio Borneo 665b501203 openocd: src: replace the GPL-2.0-only license tag
Replace the FSF boilerplate with the SPDX tag.

Change-Id: I29f51caa5ae9854d05ce7e150d168a7002607cd1
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7064
Tested-by: jenkins
2022-07-23 13:15:43 +00:00
Antonio Borneo 5635fbc25a openocd: src: replace the incomplete GPL-2.0-or-later license tag
Few files have the FSF boilerplate without the latest statement on
where to get the GPL license.

Manually replace the FSF boilerplate with the SPDX tag.
While there, reorganize the copyright statement.

The SPDX tag on files *.c is incorrect, as it should use the C99
single line comment using '//'. But current checkpatch doesn't
allow C99 comments, so keep using standard C comments, by now.

Change-Id: I0c908d01c010e24f9c7e94885e7fbed4ecf26a86
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7063
Tested-by: jenkins
2022-07-23 13:15:24 +00:00
Antonio Borneo d1a5921ce8 openocd: src: replace the GPL and BSD-Source-Code license tags
Add the new license text in the license pool.
Replace the GPL and BSD boilerplates with the SPDX tag.
Add the copyright owner of Atmel, as it was explicitly listed in
the BSD boilerplate text.

The SPDX tag on files *.c is incorrect, as it should use the C99
single line comment using '//'. But current checkpatch doesn't
allow C99 comments, so keep using standard C comments, by now.

Change-Id: Ibb117dbf8402269be3e5ba4f4c472162494d813f
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7062
Tested-by: jenkins
2022-07-23 13:14:59 +00:00
Antonio Borneo 7907d982fa openocd: src: replace the GPL with eCos exception 2.0 license tag
Add the license exception text in the license pool.
Add the exception chapter in license-rules.txt
Replace the boilerplate with the SPDX tag.

The SPDX tag on files *.c is incorrect, as it should use the C99
single line comment using '//'. But current checkpatch doesn't
allow C99 comments, so keep using standard C comments, by now.

Change-Id: Ied513b7c9c0722ed2a9c11dbdff3fbf59f1b41ce
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7061
Tested-by: jenkins
2022-07-23 13:14:44 +00:00
Antonio Borneo 1b682fc4da openocd: src: replace the BSD-2-Clause-Views license tag
Add the license text in the license pool.
Replace the BSD boilerplate with the SPDX tag.
Add the copyright owner of Jim Project, as it was explicitly
listed in the boilerplate text.

The SPDX tag on files *.c is incorrect, as it should use the C99
single line comment using '//'. But current checkpatch doesn't
allow C99 comments, so keep using standard C comments, by now.

Change-Id: I6dd004b1945773c10539016ce733d1fbfe776a9d
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7060
Tested-by: jenkins
2022-07-23 13:14:24 +00:00
Antonio Borneo a5747fe4f5 openocd: src: replace the BSD-3-Clause license tag
Replace the BSD boilerplate with the SPDX tag.

The SPDX tag on files *.c is incorrect, as it should use the C99
single line comment using '//'. But current checkpatch doesn't
allow C99 comments, so keep using standard C comments, by now.

Change-Id: I5a8cab2051eee7eb99adf67f9631b0827c1359de
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7059
Tested-by: jenkins
2022-07-23 13:14:01 +00:00
Antonio Borneo db0d4dbc3f openocd: src: add GPL license tag on files that miss it
Some file miss completely the license tag.

Add the SPDX tag, using the same GPL-2.0-or-later license of the
OpenOCD project.

The SPDX tag on files *.c is incorrect, as it should use the C99
single line comment using '//'. But current checkpatch doesn't
allow C99 comments, so keep using standard C comments, by now.

Change-Id: I1fb51e722232d14f050458a820c3041de3dc9138
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7058
Tested-by: jenkins
2022-07-23 13:13:39 +00:00
Antonio Borneo dba88e0238 openocd: src: remove duplicated GPL license tag
SPDX tag is replacing the FSF boilerplate.
For files that have both, remove the FSF boilerplate and keep only
the SPDX tag.

Change-Id: I04c4764d13d4ca92453f30ed16aeae53cd4c3fc8
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7057
Tested-by: jenkins
2022-07-23 13:07:57 +00:00
Antonio Borneo 96202cda19 openocd: build: add SPDX tag
Add the SPDX tag to makefiles, configuration scripts and tcl files
present in the folders under src/

Change-Id: I1e4552aafe46ef4893d510da9d732c5f181784a4
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7051
Tested-by: jenkins
2022-07-23 13:06:38 +00:00
Pavel Kirienko 5e96b012af semihosting: fix return value of SYS_READ and SYS_WRITE
ARM/RISC-V semihosting calls SYS_READ/SYS_WRITE require
inversion of the result value as described in
"Semihosting for AArch32 and AArch64". Prior to
this patch, this was done correctly only if
(semihosting->is_fileio==false).

This patch has been tested with STM32F446.

Change-Id: I1b34c8d8393f7dfa66ee6539904a2eaf8f9154b0
Signed-off-by: Pavel Kirienko <pavel.kirienko@gmail.com>
Fixes: https://sourceforge.net/p/openocd/tickets/232/
Reviewed-on: https://review.openocd.org/c/openocd/+/6803
Tested-by: jenkins
Reviewed-by: Tim Newsome <tim@sifive.com>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2022-07-02 08:28:30 +00:00
Antonio Borneo b7125c369c target: esp_xtensa_smp: fix clang report
The variable 'smp_break' is only set and used in case of smp.
But clang cannot track if 'target->smp' get modified between the
set and the use of 'smp_break', so it consider possible to use
'smp_break' uninitialized.

Initialize 'smp_break' to silent clang.

Change-Id: Ifa25a84fe9ffa25b8b58d7920ec77994c3b7ebfe
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Fixes: 77287b8d47 ("target: add Espressif ESP32 basic support")
Reviewed-on: https://review.openocd.org/c/openocd/+/7050
Reviewed-by: Erhan Kurubas <erhan.kurubas@espressif.com>
Tested-by: jenkins
2022-07-02 08:27:31 +00:00
Erhan Kurubas 06c3240155 semihosting: move semihosting_result_t from riscv.h to the semihosting_common.h
These enum values are useful for the arch level semihosting call handlers.
Currently riscv uses them, we also need similar return codes for the xtensa.

Signed-off-by: Erhan Kurubas <erhan.kurubas@espressif.com>
Change-Id: I8f63749cc203c59b07862f33edf3c393cd7e33a9
Reviewed-on: https://review.openocd.org/c/openocd/+/7039
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2022-07-02 08:27:12 +00:00
Erhan Kurubas 3d61a9593e jtag: add esp_usb_jtag driver
This driver is used with the ESP32 chips which has builtin USB-JTAG
interface. e.g. with ESP32-C3, ESP32-S3

Signed-off-by: Erhan Kurubas <erhan.kurubas@espressif.com>
Change-Id: If966268cb8d26f76540dd5440245a17ed0b72c61
Reviewed-on: https://review.openocd.org/c/openocd/+/6943
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2022-07-02 08:24:01 +00:00
Antonio Borneo a70bab9e51 helper: fix build with mingw gcc 12.1.0
New mingw compiler correctly complains for using a freed memory
area:

	src/helper/configuration.c: In function 'get_home_dir':
	src/helper/configuration.c:182:29: error: dangling pointer 'home'
		to 'homepath' may be used [-Werror=dangling-pointer=]
	182 | home_path = alloc_printf("%s/%s", home, append_path);
	    |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In fact the variable 'homepath' is declared inside an 'if' branch
and is not available outside.

Move the declaration of 'homepath' to have it available in a wider
context.

Change-Id: I4a43a03c007c9f0d5c4cee962a9f7cc83ca49637
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reported-by: Dietmar May <dietmar.may@outlook.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7038
Tested-by: jenkins
Reviewed-by: Dietmar May <dietmar.may@outlook.com>
2022-06-24 21:54:46 +00:00
Antonio Borneo 717b99164a semihosting: remove comparison with NULL
Commit b9526f1401 ("semihosting: permit redirection of
semihosting I/O to TCP") introduces a new comparison with NULL.

Remove it.

Change-Id: Ice4333c50d16f7592f0ff86b1640217fa42e34f6
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Fixes: b9526f1401 ("semihosting: permit redirection of semihosting I/O to TCP")
Reviewed-on: https://review.openocd.org/c/openocd/+/7031
Tested-by: jenkins
2022-06-24 21:50:41 +00:00
Antonio Borneo eab88eadd7 drivers/linuxgpiod: simplify gpio release
We already have a helper to release the gpio.
Extend it to also release its corresponding gpio chip.

As side effect, remove comparison with NULL.

Change-Id: I47cd446edfaead662d63c3330f25a791b747e882
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7033
Tested-by: jenkins
Reviewed-by: Steve Marple <stevemarple@googlemail.com>
2022-06-24 21:50:19 +00:00
Antonio Borneo 1a3573d731 drivers/linuxgpiod: release gpio at exit
Commit 20adf85f34 ("linuxgpiod: add SWDIO buffer") introduces an
additional gpio for SWDIO direction, but does not release it at
driver's exit.

Release the gpio at exit.

Change-Id: If7ea31f79ffed04af585864e49bcf1f35e118bdd
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7032
Tested-by: jenkins
Reviewed-by: Steve Marple <stevemarple@googlemail.com>
2022-06-24 21:50:07 +00:00
Antonio Borneo e4f5ce5d3e aarch64: fix handling of 'reset halt'
Commit 6c0151623c ("aarch64: add support for "reset halt"")
introduces the register setting to halt at reset vector, but:
- does not consider the case 'srst_pulls_trst' that makes useless
  setting the registers as they will be erased by the pulled trst;
- does not clean sticky errors in case of 'srst_gates_jtag'.

Avoid any register initialization on 'srst_pulls_trst' and move
the cleaning of sticky errors in the common block.

Change-Id: I6f839f06f7b091e234ede31ec18096e51f017bcd
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Fixes: 6c0151623c ("aarch64: add support for "reset halt"")
Reviewed-on: https://review.openocd.org/c/openocd/+/7034
Tested-by: jenkins
Reviewed-by: Christian Hoff <christian.hoff@advantest.com>
2022-06-24 21:49:25 +00:00
Erhan Kurubas 334a187e64 semihosting: add custom user command handler
Custom user syscalls can be handled with target events in the TCL scripts.
This patch gives another opportunity to handle custom syscalls in the c files.
Besides that some utility functions are also exported for the custom handlers.

Signed-off-by: Erhan Kurubas <erhan.kurubas@espressif.com>
Change-Id: Ice13d527540a0de0b2a8abda912ae3dcff3834b7
Reviewed-on: https://review.openocd.org/c/openocd/+/6889
Tested-by: jenkins
Reviewed-by: Ian Thompson <ianst@cadence.com>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2022-06-24 21:47:43 +00:00
Erhan Kurubas af9daf4433 esp32s2: convert counted timeout to timeval_ms
Signed-off-by: Erhan Kurubas <erhan.kurubas@espressif.com>
Change-Id: Id685408281478cec0e7e886dbedb3b8972c7b652
Reviewed-on: https://review.openocd.org/c/openocd/+/7020
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Ian Thompson <ianst@cadence.com>
2022-06-24 21:47:07 +00:00
Erhan Kurubas 2053120ba1 target: add Espressif ESP32-S3 basic support
ESP32-S3 is a dual core Xtensa SoC
Not full featured yet. Some of the missing functionality:
-Semihosting
-Flash breakpoints
-Flash loader
-Apptrace
-FreeRTOS

Signed-off-by: Erhan Kurubas <erhan.kurubas@espressif.com>
Change-Id: I44e17088030c96a9be9809f6579a4f16dbfc5794
Reviewed-on: https://review.openocd.org/c/openocd/+/6990
Tested-by: jenkins
Reviewed-by: Ian Thompson <ianst@cadence.com>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2022-06-24 21:46:42 +00:00
Erhan Kurubas 77287b8d47 target: add Espressif ESP32 basic support
ESP32 is a dual core Xtensa SoC
Not full featured yet. Some of the missing functionality:
-Semihosting
-Flash breakpoints
-Flash loader
-Apptrace
-FreeRTOS

Signed-off-by: Erhan Kurubas <erhan.kurubas@espressif.com>
Change-Id: I76fb184aa38ab9f4e30290c038b5ff8850060750
Reviewed-on: https://review.openocd.org/c/openocd/+/6989
Tested-by: jenkins
Reviewed-by: Ian Thompson <ianst@cadence.com>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2022-06-24 21:46:07 +00:00
Antonio Borneo c28ae626a2 arm_adi_v5: parse ROM tables behind SoC-600 APv1 adapter
Arm "CoreSight System-on-Chip SoC-600" specification describes a
bridge "Access Port v1 adapter" aimed to "connect a legacy Access
Port (AP) ... into an CoreSight Architecture v3 system".

A ROM table can be located in the "legacy" part of the system,
on the legacy AP behind the APv1 adapter.

For the purpose of scanning the ROM tables, consider an ADIv6
SoC-600 APv1 adapter as an ADIv5 AP.

Change-Id: I97d42fb77013c1251fb68d0caa4274086bf38a70
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6827
Tested-by: jenkins
2022-06-24 21:39:39 +00:00
Antonio Borneo 1842cf69a9 adiv6: stay in same AP during dap_lookup_cs_component()
Configuration file can specify, as target's debug AP, an AP that
contains a ROM table that points, in turn, to other APs.
Current code in cortex_a and aarch64 is not able to handle a
return from dap_lookup_cs_component() that points to another AP.

While it could be interesting to specify 'root' as target's debug
AP, drop any found value if it's not in the starting AP.

Change-Id: Id206e4fa7a29e9402c8e2393026817b410bbb8bd
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6826
Tested-by: jenkins
2022-06-24 21:39:16 +00:00
Antonio Borneo 9f0ac0e6bb adiv6: add support for ROM tables in AP
ADIv6 adds AP that only contain a ROM table in the AP itself, that
can point to other AP containing either another AP level ROM table
or a MEM-AP to be parsed as usual.

Add support for parsing AP level ROM tables.

Change-Id: Ic25863b16463b8a6adc3b15e26db7fdca858d6df
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6467
Tested-by: jenkins
2022-06-24 21:38:52 +00:00
Antonio Borneo b987a419b4 adiv6: prepare for AP level ROM tables
ADIv6 adds AP that only contain a ROM table in the AP itself, that
can point to other AP containing either another AP level ROM table
or a MEM-AP to be parsed as usual.

To handle recursive AP access, reorganize the code to:
- pass the depth==0 from the command 'dap info';
- print the AP number as first line, adding proper indentation on
  depth>0;
- align the following print with proper indentation.

Change-Id: I5b811810c807fc51b307bd60f67817d9de2aa095
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6466
Tested-by: jenkins
2022-06-24 21:38:30 +00:00
Antonio Borneo 8c1d518232 arm_adi_v5: add option 'root' to 'dap info' command
On ADIv6 the system root ROM table is found by reading the DAP DP
registers BASEPTR0 and BASEPTR1.

Add option 'root' to the commands 'dap info' to let it retrieve
the system root ROM table's AP from DAP DP, then use such AP for
following dump.

Change-Id: I1789457a005faa3870c5d14f763378d2f6a5f095
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6462
Tested-by: jenkins
2022-06-24 21:38:08 +00:00
Antonio Borneo 3f4bc6ce7f adiv6: use struct adiv5_ap->ap_num to contain the AP base address
ADIv5 DAP can only have 256 AP, while ADIv6 can provide till
2**40 (1,099,511,627,776) AP per DAP.

Reuse the field ap_num in struct adiv5_ap, currently used on ADIv5
to hold the ADIv5 AP number (apsel), to contain the ADIv6 AP base
address.

Convert struct adiv5_ap->ap_num to 64 bit and initialize it to
DP_APSEL_INVALID for unused AP.
Restrict dap_find_get_ap() to ADIv5 only. To be enhanced.
On ADIv6, let dap_get_ap() return an already allocated AP, or
allocate and return an unused AP.
Add function is_ap_num_valid() and use it.

Change-Id: Ib2fe8c7ec0d08393cd91c29fdac5d632dfc1e438
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6461
Reviewed-by: Daniel Goehring <dgoehrin@os.amperecomputing.com>
Tested-by: jenkins
2022-06-24 21:37:44 +00:00
Antonio Borneo 72fb88613f adiv6: add low level swd transport
During enter in SWD read DP_DPIDR without selecting the register
bank through DP_SELECT_DPBANK.
Handle the different format of DP_SELECT register.

Change-Id: Iea1b8eb6ec94177e16a430d5885595a38e833eeb
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6697
Tested-by: jenkins
2022-06-24 21:37:21 +00:00
Kevin Burke 62058c0a32 adi_v5_jtag: extend memaccess_tck to every AP access
ADIv5 reports:
	Accessing AP registers or debug resources in connected
	device through an AP can be subjected to other variable
	response delays in the system. A debugger that can adapt
	to these delays and avoid wasting WAIT scans operates more
	efficiently and provides higher maximum data throughput.

The existing code in OpenOCD uses extra tck only for accessing
resources through an AP.

Extend the use of extra tck also for accessing an AP register.

Split from change https://review.openocd.org/6077/

Change-Id: I2082362e098d09f4ba0668e01f5196afc965c8f3
Signed-off-by: Kevin Burke <kevinb@os.amperecomputing.com>
Signed-off-by: Daniel Goehring <dgoehrin@os.amperecomputing.com>
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6460
Tested-by: jenkins
2022-06-24 21:37:00 +00:00
Kevin Burke 8f8fb0fa79 adiv6: add low level jtag transport
swd and dap-direct are not implemented yet

Split from change https://review.openocd.org/6077/

Change-Id: I6d73d8adf6a6090001c5d4771325fb1d63c45e3c
Signed-off-by: Kevin Burke <kevinb@os.amperecomputing.com>
Signed-off-by: Daniel Goehring <dgoehrin@os.amperecomputing.com>
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6459
Tested-by: jenkins
2022-06-24 21:35:46 +00:00
Antonio Borneo edb575800a adi_v5_jtag: clear sticky overrun error
By accessing invalid AP in JTAG mode, it's possible to trigger the
error:
	JTAG-DP STICKY ERROR
After that the sticky error is never cleared and the whole DAP
gets not anymore accessible.

Clean-up the sticky error once detected.

Change-Id: I8b07263b30f9e46645f0c29084b8f1626e241f45
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6430
Tested-by: jenkins
2022-06-24 21:35:27 +00:00
Kevin Burke 513aba1930 adiv6: read ROM Table address size
Required for parsing ADIv6 ROM tables.

Split from change https://review.openocd.org/6077/

Change-Id: I849543b7b4a4455b10bd9fc7da38a37849d71700
Signed-off-by: Kevin Burke <kevinb@os.amperecomputing.com>
Signed-off-by: Daniel Goehring <dgoehrin@os.amperecomputing.com>
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6458
Tested-by: jenkins
2022-06-24 21:35:08 +00:00
Kevin Burke a6e4aabc66 adiv6: re-organize mem_ap registers definition
ADIv5 MEM-AP registers are a subset of ADIv6 MEM-AP registers and
are located at different offset.

To prepare for introducing ADIv6, add 'struct adiv5_dap *' as
argument to ADIv5 registers macro.
Check the ADI version and use the proper address.
Both adapter drivers rshim and stlink are ADIv5 only, so let them
use the ADIv5 macros only.

Split from change https://review.openocd.org/6077/

Change-Id: Ib861ddcdab74637b2082cc9f2612dea0007d77b1
Signed-off-by: Kevin Burke <kevinb@os.amperecomputing.com>
Signed-off-by: Daniel Goehring <dgoehrin@os.amperecomputing.com>
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6457
Tested-by: jenkins
2022-06-24 21:34:51 +00:00
Kevin Burke 1fe82f9f1d adiv6: add dap flags -adiv5 and -adiv6
Add flags to 'dap create' command and set the field adi_version
in struct adiv5_dap.

Actually only ADIv5 is functional. Other patches are needed to get
ADIv6 working.

Split from change https://review.openocd.org/6077/

Change-Id: I63d3902f99a7f139c15ee4e07c19eae9ed4534b9
Signed-off-by: Kevin Burke <kevinb@os.amperecomputing.com>
Signed-off-by: Daniel Goehring <dgoehrin@os.amperecomputing.com>
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6456
Tested-by: jenkins
2022-06-24 21:34:30 +00:00
Antonio Borneo 35a503b08d arm_adi_v5: add ap refcount and add get/put around ap use
While an ADIv5 DAP can only have 256 AP, ADIv6 can provide till
2**40 (1,099,511,627,776) AP per DAP.
The actual trivial code implementation for ADIv5 (that uses an
array of 256 ap in the struct adiv5_dap) cannot be extended as-is
to handle ADIv6.

The simple array of 256 AP can be reused as a dynamic storage for
ADIv6 ap:
- the ADIv5 AP number is replaced by the ADIv6 base address;
- the index of the array (equal to ADIv5 AP number) has no link to
  any ADIv6 property;
- the ADIv6 base_address has to be searched in the array of AP.

The 256 elements in the AP array should be enough for any device
available today. In future it can be easily increased, if needed.

To efficiently use the 256 elements in the AP array, the code
should associate one element of the array to an ADIv6 AP (through
the AP base address), then cancel the association when the AP is
not anymore needed. This is important to avoid saturating the AP
array while exploring the device through 'dap apreg' commands.

Add a reference counter in the struct adiv5_ap to track how many
times the struct has been associated with the same base address.
Introduce the function dap_get_ap() to associate and return the
struct, and dap_put_ap() to release the struct. For the moment the
code covers ADIv5 only, so the association is through the index.
Use the two functions above and dap_find_get_ap() throughout the
code.
Check the return value of dap_get_ap(). It is always not NULL in
the current ADIv5-only implementation, but can be NULL for ADIv6
when there are no more available AP in the array.
Instrument dap_queue_ap_read() and dap_queue_ap_write() to log an
error message if the AP has reference counter zero, meaning that
the AP has not been 'get' yet. This helps identifying AP used
without get/put, e.g. code missed by this patch, or merged later.
Instrument dap_cleanup_all() to log an error message if an AP has
reference counter not zero at openocd exit, meaning that the AP
has not been 'put' yet.

Change-Id: I98316eb42b9f3d9c9bbbb6c73b1091b53f629092
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6455
Reviewed-by: Daniel Goehring <dgoehrin@os.amperecomputing.com>
Tested-by: jenkins
2022-06-24 21:33:23 +00:00
Erhan Kurubas 480d4e1772 semihosting: fix accessing memory outside the bounds of the fn array
There is an accsess to wrong index, when arm semihosting_basedir
command not used or basedir set to empty string.

Signed-off-by: Erhan Kurubas <erhan.kurubas@espressif.com>
Change-Id: I3afa049d74b30496f5c03ba4ef67431784f81bdc
Fixes: ce5027ab01 ("semihosting: add semihosting_basedir command")
Reviewed-on: https://review.openocd.org/c/openocd/+/7005
Tested-by: jenkins
Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2022-06-10 21:56:47 +00:00
Tarek BOCHKATI d1b882f2c0 telnet_server: fix scan-build warning
fix "Declared variable-length array (VLA) has zero size" warning
raised in .../src/server/telnet_server.c:633:2:

Change-Id: Icff5228b02790c472b212a86a3849b1a3df98fdb
Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6565
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2022-06-10 21:55:39 +00:00
Antonio Borneo 7cc79a8d62 arm_adi_v5: check for calloc() return value
In function adiv5_jim_configure() check that calloc() returns a
valid allocated memory pointer.

Change-Id: I97287e168834693900341add9d9eb9a5f38c55b4
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reported-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/7014
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2022-06-10 21:54:55 +00:00
Antonio Borneo 54f0cab18e drivers/bitbang: silence scan-build warning
The array is partially initialized with buf_set_u32(,5,32,), then
the rest of the array is read from SWD.
But scan-build report the array to have garbage content after the
initialization, due to the offset of 5 bit that only inits part of
the first byte.

Silence the false positive from scan-build by initializing the
array.

Change-Id: Ic38d50280f67939e3ec5fa05741f66d5f993f8c2
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7013
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2022-06-10 21:54:40 +00:00
Antonio Borneo 95135b39cc arm_adi_v5: fix scan-build warning [3/3]
While scan-build complains that dap_p or ap_num_p could be NULL,
the current code never passes NULL pointers.
Add an assert() to silent scan-build and prevent any further use
of the function with incorrect parameters.

Change-Id: I656810dddcea61e85d85b13efb114f7607ef837c
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7012
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2022-06-10 21:54:29 +00:00
Antonio Borneo aee7c70a1a arm_adi_v5: fix scan-build warning [2/3]
Commit d01b3d69ec ("arm_adi_v5: separate ROM table parsing from
command output [3/3]") introduces a new scan-build warning because
removing one return in case of error causes using uninitialized
values.

Add back the return on error.

Change-Id: I10ddc548b756d34aaccc0511f091b4caa5ec271a
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Fixes: d01b3d69ec ("arm_adi_v5: separate ROM table parsing from command output [3/3]")
Reviewed-on: https://review.openocd.org/c/openocd/+/7011
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2022-06-10 21:54:17 +00:00
Antonio Borneo 63e22d5fb9 arm_adi_v5: fix scan-build warning [1/3]
Commit 21f7885d1c ("arm_adi_v5: separate ROM table parsing from
command output [1/3]") introduces a new scan-build warning because
continues the execution even when dap_get_debugbase() returns
error. The value of 'apid' can be uninitialized:

	5th function call argument is an uninitialized value

Check the return value and quit on error.
While there, remove the useless initialization of 'dbgbase' that
was apparently required for the same problem.

Change-Id: Iade26a152925ee0f1bf114ed829b94f7ed5b254f
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Fixes: 21f7885d1c ("arm_adi_v5: separate ROM table parsing from command output [1/3]")
Reviewed-on: https://review.openocd.org/c/openocd/+/7010
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2022-06-10 21:54:01 +00:00
Tomas Vanek e78b96421c flash/nor/numicro: remove useless architecture check
target_to_armv7m() just returns a type-cast of target->arch_info,
so the test has no value.

Following target_run_algorithm() checks magic number so
we need not worry about execution on mismatched architecture.

Change-Id: Ic9892a488a42af1d8e8731eddb39240deeb26020
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/6755
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2022-06-10 21:50:39 +00:00
Erhan Kurubas 822097a351 telnet_server: fix valgrind error
Error: Uninitialised value was created by a heap allocation
at telnet_new_connection (telnet_server.c:227)

Signed-off-by: Erhan Kurubas <erhan.kurubas@espressif.com>
Change-Id: I698a3648be698c93a2395a718ee1ade028226995
Reviewed-on: https://review.openocd.org/c/openocd/+/7006
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2022-06-08 08:46:09 +00:00
Tarek BOCHKATI 4f42600541 flash/stm32l4x: fix scan-build warnings
fix "Declared variable-length array (VLA) has zero size" warnings

while at there instrument the probe function to ensure the flash bank
contains at least 1 sector

Change-Id: I3ba0e6345881557ad1aab2d1b41eee438b49fe04
Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6470
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2022-06-04 08:25:23 +00:00
Tarek BOCHKATI 4a20a1d1c0 stlink: manage TCP_BUSY status code when using RW MISC
Change-Id: I4f9eed3781b549742565a3a8ac5245a4b94ceb53
Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6994
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2022-06-04 08:20:40 +00:00
Tomas Vanek 7e9e5dca07 target/riscv: drop unused variable registers_initialized
Change-Id: If7bfe38ac273ce9e54003e003807e128cced1568
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/6995
Tested-by: jenkins
Reviewed-by: Tim Newsome <tim@sifive.com>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2022-06-04 08:20:09 +00:00
Erhan Kurubas 78c87f5e81 target: add Espressif ESP32-S2 basic support
ESP32-S2 is a single core Xtensa chip.
Not full featured yet. Some of the missing functionality:
-Semihosting
-Flash breakpoints
-Flash loader
-Apptrace
-FreeRTOS

Signed-off-by: Erhan Kurubas <erhan.kurubas@espressif.com>
Change-Id: I2fb32978e801af5aa21616c581691406ad7cd6bb
Reviewed-on: https://review.openocd.org/c/openocd/+/6940
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-by: Ian Thompson <ianst@cadence.com>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2022-06-04 08:18:44 +00:00
Tarek BOCHKATI b470b664ca cortex_a: get rid of not needed log messages
when using semi-hosting with cortex_a this LOG_INFO pollutes openocd
console, so just reduce the log level of this message.

Change-Id: I91aa70492f4e361b25a0e5517d0cf73f2f8ed599
Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Reviewed-on: https://gerrit.st.com/c/stm32ide/official/openocd/+/248225
Tested-by: Tarek BOCHKATI <tarek.bouchkati@st.com>
Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@st.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6993
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2022-06-03 23:46:21 +00:00
Tomas Vanek cc8b491856 flash/nor/core, target: don't ask for working mem if no target algo
The command 'flash erase_check' showed the message
'Running slow fallback erase check - add working memory'
even in the case the target didn't implement blank_check_memory.

Change return code of target_blank_check_memory() in this case
and sense it in default_flash_blank_check() and show a message
without a request for working memory.

Change-Id: I7cf9bf77742964b4f377c9ce48ca689e57d0882f
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/6765
Tested-by: jenkins
Reviewed-by: Tim Newsome <tim@sifive.com>
2022-05-29 15:47:21 +00:00
Tim Newsome bce93f6d51 Give each SMP group a unique number.
This helps e.g. if there are 8 cores, and cores 0--3 are in one SMP
group while 4--7 are in another group. (And there are 2 gdb instances
connected, one debugging the first group, and one the second.)

Signed-off-by: Tim Newsome <tim@sifive.com>
Change-Id: I7b6c9382eadf964529105eaf0411a42d48768668
Reviewed-on: https://review.openocd.org/c/openocd/+/6979
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2022-05-27 22:52:35 +00:00
Erhan Kurubas ce5027ab01 semihosting: add semihosting_basedir command
This command allows users to set base working directory for the
semihosting I/O operations.Default is the current OpenOCD directory.

Signed-off-by: Erhan Kurubas <erhan.kurubas@espressif.com>
Change-Id: I80c5979e4c96d66cccdd12cc6fcd5f353e5c6b4d
Reviewed-on: https://review.openocd.org/c/openocd/+/6888
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2022-05-21 09:01:56 +00:00
Erhan Kurubas 631d0bddfa flash: fix clang static analyzer build errors
Fixes "variable set but not used" errors.
Tested with Homebrew clang version 13.0.1

Signed-off-by: Erhan Kurubas <erhan.kurubas@espressif.com>
Change-Id: Ia90baf5b4857db2b5569ebe6adbbb832de772aad
Reviewed-on: https://review.openocd.org/c/openocd/+/6971
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2022-05-21 09:00:51 +00:00
Tomas Vanek 0f11f951e7 target: fix clang static analyzer warning
Removes Warning:	line 6482, column 12
1st function call argument is an uninitialized value

Use target ptr directly as checked in previous lines instead of
dereferencing head->target

Change-Id: I6804b776fd493af71f3098d702f9cdc7acb50151
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/6970
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2022-05-21 09:00:05 +00:00
Tomas Vanek 7d2ea186cf target/riscv: fix 'reset run' after 'reset halt'
'reset halt' does not clear DM_DMCONTROL_HALTREQ at deassert_reset().
If hw reset line is configured e.g. 'reset_config srst_only'
the folowing 'reset run' halts:

 > gd32v.cpu curstate
 running

 > reset halt
 JTAG tap: gd32v.cpu tap/device found: 0x1000563d (mfg: 0x31e ...
 > gd32v.cpu curstate
 halted

 > reset
 JTAG tap: gd32v.cpu tap/device found: 0x1000563d (mfg: 0x31e ...
 > gd32v.cpu curstate
 halted <<<<---- wrong!!!

 > reset
 JTAG tap: gd32v.cpu tap/device found: 0x1000563d (mfg: 0x31e ...
 > gd32v.cpu curstate
 running

Clear DM_DMCONTROL_HALTREQ when acking reset.

Change-Id: Iae0454b425e81e64774b9785bb5ba1d4564d940b
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/6961
Tested-by: jenkins
Reviewed-by: Tim Newsome <tim@sifive.com>
2022-05-18 09:03:41 +00:00
Steve Marple bd4bd54b60 drivers/am335xgpio: Add AM335x driver for bitbang support on BeagleBones
Change-Id: Iac1c9f3d380e2474c8b77407c89c2aad96fbf2ea
Signed-off-by: Steve Marple <stevemarple@googlemail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6941
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2022-05-14 08:59:30 +00:00
Steve Marple 0b241ca042 bcm2835gpio: Fix incorrect GPIO validation
Incorrect validation prevented GPIO0 from controlling the direction of
the SWDIO buffer or operating TRST/SRST.

Have all GPIO number validation checks performed by is_gpio_valid().

Change-Id: Ib8fb704ab588a618ac41c111f6168d658891d92c
Signed-off-by: Steve Marple <stevemarple@googlemail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6938
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
2022-05-14 08:59:03 +00:00
Antonio Borneo cc75aa37c5 openocd: add post-init and pre-shutdown helpers
It is a common requirement to automatically execute some command
after "init".
This can be achieved, either in scripts or through OpenOCD command
line, by explicitly calling "init" followed by the commands.
But this approach fails if the request for post-init commands is
spread across configuration files; only one of the files can split
pre-init and post-init status by calling "init".
The common workaround is to "rename" the command "init" and
replace it with a TCL proc that calls the original "init" and the
post-init commands. E.g. in Zephyr script [1].

To simplify and formalize the post-init execution, use a TCL list
that contains the list of commands to be executed. Every script
can contribute adding new commands, e.g. using "lappend".

In the same way, formalize the pre-shutdown execution with a TCL
list of user commands to be executed before OpenOCD exit.

Document them and add trivial examples.

Drop from documentation the suggestion to rename "shutdown".

Change-Id: I9464fb40ccede3e7760d425873adca363b49a64f
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Link: [1] https://github.com/zephyrproject-rtos/zephyr/blob/zephyr-v2.7.1/boards/arm/nucleo_h743zi/support/openocd.cfg#L15
Reviewed-on: https://review.openocd.org/c/openocd/+/6851
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Tested-by: jenkins
2022-05-14 08:58:36 +00:00
Antonio Borneo 99293ebd15 aarch64: don't wait for smp targets halted in deassert reset
The function target_type::deassert_reset() is called for every
target after reset is deasserted. If the target fails to get
halted, we log a warning and issue a halt request for the target
itself.

Current code calls the generic target_halt() that:
- extends the halt to all the targets in the SMP node;
- waits for targets to halt.
This breaks the logic of running target_type::deassert_reset()
per target. Plus, waiting for targets to halt delays the call of
target_type::deassert_reset() for the next targets.

Replace the call to target_halt() with the aarch64 specific
function to halt the single target. Pass the parameter HALT_LAZY
to prevent the wait for target halted.
Similar solution is already implemented for cortex_a.

Change-Id: I446dc03cb91524c6d388db485bc2388177af77b6
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6947
Tested-by: jenkins
2022-05-14 08:57:36 +00:00
Antonio Borneo a47d1f1b79 arm_adi_v5: add support for 64bit Class 0x9 ROM tables
Arm documentation does not explicitly report the order of the two
32bit words that compose the 64bit value. But both ADIv5 and ADIv6
specify that only little-endian is supported (ADIv5.2 obsoletes
the big-endian support). This change reads the 64bit value in
little-endian.

Detect the 64bit content and use it.

Change-Id: I723ec099c7e8c70c1f9a568e32ea867fcbf1f1db
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6465
Tested-by: jenkins
2022-05-14 08:56:37 +00:00
Antonio Borneo d74f11dcd4 arm_adi_v5: replace dap_lookup_cs_component()
With the generic function for ROM table walk-through, reimplement
dap_lookup_cs_component().

Catch the code CORESIGHT_COMPONENT_FOUND and halt the search.
While there, drop two macros in arm_coresight.h, now unused.

Change-Id: I589ef7ae8a651d0c422ce7d0b4ed913713a8217e
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6824
Tested-by: jenkins
2022-05-14 08:55:52 +00:00
Antonio Borneo 613f1c6abb arm_adi_v5: let dap_lookup_cs_component() to get AP dbgbase
Simplify the code in cortex_a and aarch64 by moving the call to
dap_get_debugbase() inside dap_lookup_cs_component().

This has the further effects:
- dap_get_debugbase() is not referenced outside arm_adi_v5.c and
  becomes static;
- dap_lookup_cs_component() looses one parameter;
- the coreid parameter 'idx' is passed as value;
- the caller in aarch64 don't have and don't print the irrelevant
  value of AP register APID;
- fixes the debug message in the caller in aarch64 to print the
  coreid value instead of always zero.

Change-Id: Ic7f0f643fdf067c059c8f2455a02ff18a3fed054
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6823
Tested-by: jenkins
2022-05-14 08:55:33 +00:00
Antonio Borneo 7351330a0f arm_adi_v5: abstract actions during ROM table parsing
Now all the actions (build command output) of command "dap info"
are decoupled from the ROM walk-through.
Pass the actions as a generic parameter to ROM walk-through code.
Put as private data every information that is only required by the
actions and not by the ROM walk-through.

Change-Id: I3b6ad112ea21296458c94aebbf91bf65bf6657a7
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6822
Tested-by: jenkins
2022-05-14 08:54:53 +00:00
Antonio Borneo d01b3d69ec arm_adi_v5: separate ROM table parsing from command output [3/3]
This change only targets the output of rtp_rom_loop().

Change-Id: If9ac013798923428c3b897a969887e98b6935a2b
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6821
Tested-by: jenkins
2022-05-14 08:54:36 +00:00
Antonio Borneo c83b94b2c8 arm_adi_v5: separate ROM table parsing from command output [2/3]
This change only targets the output of rtp_cs_component().
To easily propagate the coordinates of the CoreSight component,
add them in the struct that holds the register values.
While there, define a macro for the max depth of ROM tables.

Change-Id: I75e5ef4f9419da3192123aebcd61471c2af9374f
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6820
Tested-by: jenkins
2022-05-14 08:54:25 +00:00
Antonio Borneo 21f7885d1c arm_adi_v5: separate ROM table parsing from command output [1/3]
In OpenOCD arm_adi_v5 we have already two implementations of code
for parsing the ADIv5 ROM table:
- in the commands "dap info" and "$dap_name info";
- in the function dap_lookup_cs_component().
Adding support for ADIv6 requires extending both implementations.

Moreover, current code does not handle few aspects of the ROM
parsing, e.g. the "Power Domain IDs".
To add such extensions both implementations should be touched.

I plan to add a command to parses (again) the ROM table and dump a
simple prototype of a configuration script for the target, useful
while analysing a new target.

Keeping aligned all these implementation would be too complex.

With focus to "dap info" command, decouple the part of code to
walk-through the ROM table from the code that creates the command
output.
The idea is to keep a single implementation for the walk-through
code, while parametrizing the output code to handle the generation
of a configuration script or the result of the function
dap_lookup_cs_component().

This change only targets the output of MEM-AP header
Further changes will target other parts of the code.

While there, add a message if MEM-AP is not accessible.

Change-Id: I112f637edfdb8688afb4e631297f6536da9604f1
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6819
Tested-by: jenkins
2022-05-14 08:54:02 +00:00
Antonio Borneo a73adb5241 arm_adi_v5: handle faulting entry in ROM table
ARM IHI0031F "Arm Debug Interface Architecture Specification"
chapter C2.6.1 "BASE, Debug Base Address register" reports:
	A debugger must handle the following situations as
	non-fatal errors:
	- ...
	- An entry in the ROM Table points to a faulting location.
	- ...
	Typically, a debugger issues a warning if it encounters
	one of these situations. However, Arm recommends that it
	continues operating. An example of an implementation that
	might cause errors of this type is a system with static
	base address or ROM Table entries that enable entire
	subsystems to be disabled, for example by a tie-off input,
	packaging choice, fuse, or similar.

Don't halt ROM table parsing if one entry causes an error; log the
error condition and continue to next entry.
Not sure if we have to send an ABORT before continuing.

Change-Id: I94fdb5b175bfb07dde378149421582b7e7cd5b09
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6818
Tested-by: jenkins
Reviewed-by: Daniel Goehring <dgoehrin@os.amperecomputing.com>
2022-05-14 08:53:35 +00:00
Antonio Borneo d4335071b8 arm_adi_v5: report sysmem on class 0x9 ROM tables
As Class 0x1 ROM table, also Class 0x9 ROM tables encodes a flag
for system memory access.

Detect the flag in rtp_cs_component() and dump the same message
for both type of ROM tables.
Extend rtp_read_cs_regs() to read ARM_CS_C9_DEVID.

Change-Id: Ic85d1ea068ed706ceedfd65076ff4c96d04e9792
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6817
Tested-by: jenkins
Reviewed-by: Daniel Goehring <dgoehrin@os.amperecomputing.com>
2022-05-14 08:52:30 +00:00
Antonio Borneo 209cb38aa1 arm_adi_v5: split ROM table loop from generic coresight
During ROM table parsing, each ROM table entry points to a
CoreSight component that can, in turn, be another ROM table.

Split the specific code for ROM table handling from the generic
CoreSight code.
Log an error if a ROM table entry cannot be read.

Change-Id: I5ad106a99b9c21ddb48b5b162ae87101e4f49878
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6816
Tested-by: jenkins
2022-05-14 08:51:07 +00:00
Antonio Borneo c3f6e21d5c arm_adi_v5: rework dap_read_part_id()
Rework dap_read_part_id() while preparing for reorganizing the
'ROM Table Parsing' (RTP):
- rename it with 'rtp' prefix;
- extends it to read other CoreSight registers, thus improving the
  overall speed by queuing more reads;
- reduce the list of arguments by using a struct;
- reorder the reads by increasing offset, potentially gaining
  speed using MEM_AP_REG_BDx and/or auto-increment;
- log a debug message in case of read error.

Change-Id: I6544ac7740b808a6c0fbacf97ac00b97f5bd3832
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6815
Tested-by: jenkins
2022-05-14 08:50:41 +00:00
Florian Fainelli 1fd2a6c7f5 arm_adi_v5: add support for display Class 0x9 ROM tables
ADI v5.1 and v6.0 permit the definition of CoreSight components (class 9
ROM entries).

dap_rom_display() is refactored a bit such that we always end up with
attempting to parse the ROM contents using the appropriate upper limit
for class 1 and 9 ROM types.

Change-Id: I4ba497b3807f1f11f06186eb6e61959ea3540c59
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6359
Tested-by: jenkins
2022-05-14 08:48:10 +00:00
Antonio Borneo fed329feec arm_adi_v5: describe Class 0x9 Device Architecture register
Use the list of values from ARM IHI0029E to decode and print the
Device Architecture register.
Add attribute 'unused' to the function, not used yet.

Change-Id: I7b1dd204bd1db671578c588372b667e23611876c
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6463
Tested-by: jenkins
Reviewed-by: Daniel Goehring <dgoehrin@os.amperecomputing.com>
2022-05-14 08:43:51 +00:00
Antonio Borneo a785ca315b adi_v5_jtag: reduce verbosity on persistent WAIT
In case of AP not responding, e.g. not clocked, the first WAIT
reply is logged as:
	DAP transaction stalled (WAIT) - slowing down
then OpenOCD retries the transaction few times, until it timeouts.
At each retry it prints the message:
	DAP transaction stalled during replay (WAIT) - resending
Depending on JTAG speed and transport latency, the amount of log
messages can be quite annoying and not relevant.
The last printed line is at timeout:
	Timeout during WAIT recovery

Reduce the verbosity.

Change-Id: I5a7a337527c98b2450de59066b13713511c2894f
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6814
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-by: Daniel Goehring <dgoehrin@os.amperecomputing.com>
2022-05-14 08:43:30 +00:00
Antonio Borneo d796f5929c arm_coresight: define ARM_CS_CIDR_CLASS()
Right now it has a single use but it will soon be used more.

Change-Id: I9a819c65df467fc859e4b5251035a17ed33daa35
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6813
Tested-by: jenkins
Reviewed-by: Daniel Goehring <dgoehrin@os.amperecomputing.com>
2022-05-14 08:42:29 +00:00
Tomas Vanek 4c1919c566 target: document possibly unreachable target in deinit_target()
Change-Id: I95ff3d200bb2c8f5bc43a34c92726d9c47f8c172
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/6953
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2022-05-07 11:04:45 +00:00
Antonio Borneo 7819834ace target: fix build with jimtcl 0.79
In jimtcl 0.80 the prototype of Jim_DictPairs() has changed.
The only code in OpenOCD that uses Jim_DictPairs() has been merged
recently and it only uses the current jimtcl syntax.

To allow compiling OpenOCD master branch with older versions of
jimtcl, detect the version of jimtcl and use the appropriate
syntax.

Change-Id: I6fc78303b6a4db064a97f326c46119f4568e88f3
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reported-by: dullfire@yahoo.com
Reviewed-on: https://review.openocd.org/c/openocd/+/6948
Tested-by: jenkins
2022-05-07 11:04:18 +00:00
Salvatore Giorgio PECORINO ad5ca263e9 bluenrg: add support for bluenrg-lps device and board
Added bluenrg-lps support
Added file for the board steval-idb012v1
Fixed size_info information using a mask
Changed the if condition in bluenrg-x.cfg to be valid only for bluenrg-1 and bluenrg-2

Signed-off-by: Salvatore Giorgio PECORINO <salvatore-giorgio.pecorino@st.com>
Change-Id: Ic0777ec0811ee6fac7d5e1d065c4629e47d84a1f
Reviewed-on: https://review.openocd.org/c/openocd/+/6928
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2022-05-07 11:03:25 +00:00
Antonio Borneo f88a7dde6a server/gdb: fix gdb remote monitor cmd on multi-target
Commit 5ebb1bdea1 ("server/gdb: fix return of gdb remote monitor
command") replaces the call to command_run_line() with call to
Jim_EvalObj() but does not properly set the "context".
In multi-target environment, his can cause the erroneously
execution of the command on the wrong target.

Copy from the code in command_run_line() the proper setup before
executing Jim_EvalObj().

Change-Id: I56738c80779082ca146a06c01bc30e28bc835fd3
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reported-by: Bohdan Tymkiv <bohdan200@gmail.com>
Fixes: 5ebb1bdea1 ("server/gdb: fix return of gdb remote monitor command")
Reviewed-on: https://review.openocd.org/c/openocd/+/6966
Tested-by: jenkins
Reviewed-by: Bohdan Tymkiv <bohdan200@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-by: Tim Newsome <tim@sifive.com>
2022-05-07 11:03:03 +00:00
Antonio Borneo b4f8d99c8d smp: deprecate legacy SMP core switching support
The deprecation was already in the documentation since v0.11.0
through commit 85ba2dc4c6 ("rtos/hwthread: add hardware-thread
pseudo rtos") but OpenOCD was not informing the user printing a
runtime message.

Remove the deprecated method from the documentation and print a
deprecated message at runtime.
There is no reliable way to print the same message in GDB console,
so we have to rely on user noticing it in the OpenOCD log.
Target is to remove the functionality after v0.12.0.

Change-Id: Idd2d9e3b6eccc92dcf0432c3c7de2f8a0fcabe9f
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6862
Tested-by: jenkins
2022-05-07 11:00:00 +00:00
jihongbin 66335683fe drivers/cmsis-dap: Correct the DAP protocol parameter parsing error
Fixes: 01030fb893 (drivers/cmsis-dap: tidy up buffer access)

Change-Id: Id192d3930a89980d641058b6444d12caec19ce6f
Signed-off-by: Hongbin Ji <longma@orbbec.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6954
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: jihongbin <jhb_ee@163.com>
2022-05-01 04:48:19 +00:00
fatalc 12d1ad0c75 target/disassembler: update capstone include path to <capstone.h>
on macos (homebrew base) `pkg-config --cflags capstone` output with
`-I/opt/homebrew/Cellar/capstone/4.0.2/include/capstone`
gcc not find headers on parent "include" path,
causes build error `fatal error: 'capstone/capstone.h' file not found`
it's ok to change to <capstone.h> for all platforms.

Signed-off-by: fatalc <cnfatal@gmail.com>
Change-Id: Ia2e2058024d4fc1a57a8b4ea847c664d74f67efb
Reviewed-on: https://review.openocd.org/c/openocd/+/6946
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2022-04-30 17:53:30 +00:00
Marc Schink 8789513fa9 target/arm_cti: Fix error handling in 'cti create'
Handle JIM_CONTINUE return value of adiv5_jim_mem_ap_spot_configure(),
otherwise OpenOCD silently quits when an unknown option is provided.

Change-Id: I9b1351c0911e74999d8dd1260ede9760088510d7
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/6944
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2022-04-30 17:52:40 +00:00
Steve Marple 9eddc21a58 bcm2835gpio: Make buffer an output before the GPIO connected to it
The correct ordering is required to prevent two outputs connected
together.

Change-Id: I634a9ca7e0ccf337d1723011b8aee1f2d81efbcf
Signed-off-by: Steve Marple <stevemarple@googlemail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6937
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2022-04-30 17:48:42 +00:00
Steve Marple 20adf85f34 linuxgpiod: add SWDIO buffer
The SWDIO buffer requires a direction pin to select input or output
direction. Output is selected by a high logic level (matches
bcm2835gpio driver).

Change-Id: I240cb99a5dfea08121bb33d4b5e2108ce7597468
Signed-off-by: Steve Marple <stevemarple@googlemail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6936
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2022-04-30 17:47:38 +00:00
Tomas Vanek 9de084e006 flash/nor/stm32f1x: add can_load_options flag for GD32F1x0, F3x0 and E23x
According to GigaDevice user manuals the devices have OBRLD bit in FMC_CTL
register which is functionally compatible with OBL_LAUNCH @ FLASH_CR
of STM32 counterparts.

Change-Id: I84d231b38815fcb6452fd73b9153b269cce3b737
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/6759
Tested-by: jenkins
Reviewed-by: Andrzej Sierżęga <asier70@gmail.com>
2022-04-24 08:27:28 +00:00
Tomas Vanek f2b4897773 flash/stm32f1x: add support for RISC-V GigaDevice GD32VF103
The device has compatible flash macro with STM32F1 family, reuse
stm32f1x driver code.

Detect non-ARM target - for simplicy test target type name 'riscv'
and the address has 32 bits.

In case of RISC-V CPU use simple chunked write algo - async algo
cannot be used as the core implemented in this device doesn't
allow memory access while running.

Change-Id: Ie3886fbd8573652691f91a02335812a7300689f7
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/6704
Tested-by: jenkins
Reviewed-by: Tim Newsome <tim@sifive.com>
2022-04-24 08:26:08 +00:00
Julien Massot a26ee5344c rtos: zephyr: do not use deprecated symbols name
Zephyr plan to remove openocd specific symbols in favour
of more generic one.

These generic symbols has been introduced in Zephyr 2.6.

Signed-off-by: Julien Massot <julien.massot@iot.bzh>
Change-Id: I89418c9c378fb8b8baa29763fc6f1b6e652dc7ef
Reviewed-on: https://review.openocd.org/c/openocd/+/6844
Tested-by: jenkins
Reviewed-by: Stephanos Ioannidis <root@stephanos.io>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2022-04-23 09:26:32 +00:00
Jan Matyas a213397323 target/image: fix - p_flags field in ELF64 segment headers is 64 bits wide
Fixed the reading of p_flags in ELF64 segment headers - that field
is 64 bits wide.

Change-Id: I053ca57d36efb54b7c638484acd6c7a2fbcbd05a
Signed-off-by: Jan Matyas <matyas@codasip.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6927
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2022-04-23 09:26:15 +00:00
Antonio Borneo 5ebb1bdea1 server/gdb: fix return of gdb remote monitor command
Current implementation for gdb remote monitor command uses the
command_run_line() to execute the command.
While command_run_line() has several advantages, it unfortunately
hides the error codes and outputs the result of the command
through LOG_USER(), which is not what gdb requires. See 'qRcmd' in
https://sourceware.org/gdb/onlinedocs/gdb/General-Query-Packets.html

Replace command_run_line() with Jim_EvalObj() and parse the output
to provide the proper result to gdb.

Can be tested by defining in OpenOCD:
	proc a {} {return hello}
	proc b {} {return -code 4}
	proc c {} {return -code 4 "This is an error!"}
then by executing in gdb console:
	monitor a
	monitor b
	monitor c
	monitor foo

Change-Id: I1b85554d59221560e97861a499e16764e70c1172
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reported-by: Torbjorn Svensson <torbjorn.svensson@st.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6886
Tested-by: jenkins
2022-04-23 09:25:43 +00:00
Tomas Vanek e83eeb44aa flash/nor/stm32f1x: lock flash in case of error
The current code locks the flash controller in case of error during
flash write only. An error in other flash operations may cause the
flash is left unlocked.

Implement locking also after error in erase, mass erase, options
write and erase.

Change-Id: I26c2ed7914e7847122306f29b777b9eefd1dc580
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/6710
Tested-by: jenkins
Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
2022-04-13 16:56:18 +00:00
Tomas Vanek b801452d42 flash/nor/stm32f1x: unify flash error reporting
stm32x_wait_status_busy() has two side effects in case of flash programming error:
- reports error
- clears error bit in status register

Use stm32x_wait_status_busy() to report also flash error during target
algo flash write.

While on it use more descriptive error codes in stm32x_wait_status_busy().

Change-Id: I6e1cffc2aa5411b918a23ed62d5194910888a9d1
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/6709
Tested-by: jenkins
Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
2022-04-13 16:53:14 +00:00
Tomas Vanek e3f4ea0b57 flash/nor/stm32f1x: tidy up async algo supporting code
Use target_get_working_area_avail() instead of try-fail iteration.

Call destroy_reg_param() in a for cycle.

Change-Id: I1891d1ffdea99010c6ab66b9578400b9d7922e20
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/6708
Tested-by: jenkins
Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
2022-04-13 16:52:41 +00:00