Commit Graph

10470 Commits

Author SHA1 Message Date
R. Diez 1fba7d53bb configure.ac: show the dummy adapter in the configuration summary
The dummy adapter now uses the same config logic as most adapters.
Its name has changed from "dummy port driver" to "Dummy Adapter".

Change-Id: Ic9ee617aab1f54215835d4d8db03f6637b797082
Signed-off-by: R. Diez <rdiezmail-openocd@yahoo.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/7340
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-05-26 09:58:47 +00:00
Antonio Borneo fbea7d5d38 openocd: drop include of target_type.h
Few files include target_type.h even if it is not needed.
Drop the include.

Other files access directly to target type's name instead of using
the proper API target_type_name().
Use the API and drop the include.

Change-Id: I86c0e0bbad51db93500c0efa27b7d6f1a67a02c2
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8260
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2024-05-26 09:57:51 +00:00
Bernhard Rosenkränzer ccc5c1642b Fix build with clang even if it sets __GNUC__ to >= 4.4
clang doesn't support the gnu_printf attribute that OpenOCD uses if
__GNUC__ and __GNUC_MINOR__ indicates gcc >= 4.4.

Most clang builds set __GNUC__/__GNUC_MINOR__ to 4.2 for historical
reasons, so they don't trigger this condition; however, some builds set
it to something much higher to work around code using __GNUC__ to
determine if a feature that does exist in clang (but not gcc 4.2) is
available, causing OpenOCD to use attribute gnu_printf.

The problem can be reproduced without a special clang build by adding
-fgnuc-version=14.1 to CFLAGS.

Change-Id: I3c0832d4201578b116c5214203f95b6153dad30e
Signed-off-by: Bernhard Rosenkränzer <bero@baylibre.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8258
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-05-26 09:56:50 +00:00
Marc Schink bd89b91c69 target/semihosting: Fix double free()
Do not free the service in 'connection_closed_handler' because it is
free'd by the server infrastructure.

Checkpatch-ignore: COMMIT_LOG_LONG_LINE

This error was detected with valgrind:

==272468== Invalid free() / delete / delete[] / realloc()
==272468==    at 0x484B27F: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==272468==    by 0x1F34C7: remove_service (server.c:374)
==272468==    by 0x2ED3D5: semihosting_tcp_close_cnx (semihosting_common.c:1819)
==272468==    by 0x2ED3D5: handle_common_semihosting_redirect_command (semihosting_common.c:1926)
==272468==    by 0x1FC703: exec_command (command.c:520)
==272468==    by 0x1FC703: jim_command_dispatch (command.c:931)
==272468==    by 0x36980F: JimInvokeCommand (in /home/marc/openocd/build/src/openocd)
==272468==    by 0x1FFFFFFFFF: ???
==272468==    by 0x53ED09F: ???
==272468==    by 0x300000001: ???
==272468==    by 0x1FFEFFF7FF: ???
==272468==    by 0x3D3984: ??? (in /home/marc/openocd/build/src/openocd)
==272468==    by 0x2: ???
==272468==  Address 0x5fff650 is 0 bytes inside a block of size 24 free'd
==272468==    at 0x484B27F: free (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==272468==    by 0x2ECA42: semihosting_service_connection_closed_handler (semihosting_common.c:1807)
==272468==    by 0x1F2E39: remove_connection.isra.0 (server.c:164)
==272468==    by 0x1F349E: remove_connections (server.c:350)
==272468==    by 0x1F349E: remove_service (server.c:364)
==272468==    by 0x2ED3D5: semihosting_tcp_close_cnx (semihosting_common.c:1819)
==272468==    by 0x2ED3D5: handle_common_semihosting_redirect_command (semihosting_common.c:1926)
==272468==    by 0x1FC703: exec_command (command.c:520)
==272468==    by 0x1FC703: jim_command_dispatch (command.c:931)
==272468==    by 0x36980F: JimInvokeCommand (in /home/marc/openocd/build/src/openocd)
==272468==    by 0x1FFFFFFFFF: ???
==272468==    by 0x53ED09F: ???
==272468==    by 0x300000001: ???
==272468==    by 0x1FFEFFF7FF: ???
==272468==    by 0x3D3984: ??? (in /home/marc/openocd/build/src/openocd)
==272468==  Block was alloc'd at
==272468==    at 0x484DA83: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==272468==    by 0x2ED326: handle_common_semihosting_redirect_command (semihosting_common.c:1931)
==272468==    by 0x1FC703: exec_command (command.c:520)
==272468==    by 0x1FC703: jim_command_dispatch (command.c:931)
==272468==    by 0x36980F: JimInvokeCommand (in /home/marc/openocd/build/src/openocd)
==272468==    by 0x1FFFFFFFFF: ???
==272468==    by 0x53ED09F: ???
==272468==    by 0x400000002: ???
==272468==    by 0x1FFEFFF7FF: ???
==272468==    by 0x3D3984: ??? (in /home/marc/openocd/build/src/openocd)
==272468==    by 0x2: ???
==272468==

Change-Id: I3e5323f145a98d1ff9ea7d03f87ed96140f49a18
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/8257
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-05-26 09:55:45 +00:00
Marc Schink edb14a02e9 tcl/target/nrf52: Configure trace port speed
Configure the TRACECONFIG.TRACEPORTSPEED register depending on the
trace clock speed. Also catch invalid trace clock speeds.

Change-Id: I1ece1cc59da539732d2d71f296fd55799c195387
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/8256
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2024-05-26 09:55:31 +00:00
Marc Schink 1a00c67e10 tcl/target/nrf52: Use 'error' instead of 'echo'
Use 'error' instead of 'echo' for error messages. Otherwise, capturing
is always started, for example with an unsupported device.

While at it, make the error messages more consistent and clear.

Change-Id: I83c9abfb4514e6b638c4be14651e67f768af8bad
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/8255
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: <post@frankplowman.com>
2024-05-26 09:54:17 +00:00
Marc Schink be1aebd818 target/arm_tpiu_swo: Handle errors in pre/post-enable events
Currently, errors in pre/post-enable events are ignored and capturing is
always started, even if necessary device configuration fails. This
behaviour is confusing to users. Also, the TPIU must be disabled before
re-configuration is possible.

Start capturing and enable TPIU only if no errors in pre/post-enable
events occurred.

Change-Id: I422033e36ca006e38aa4504d491b7947def1237a
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/8254
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2024-05-26 09:54:01 +00:00
Marc Schink c831758ea4 server/gdb: Use 'bool' data type where appropriate
Change-Id: Ic23c5469334337963185b69fcabeedf70c2c7ae9
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/8253
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2024-05-26 09:53:40 +00:00
Marc Schink 2506ccb509 target/arm_tpiu_swo: Fix division by zero
When external capturing is configured (default), the SWO pin frequency
is required. Enforce this to avoid a division by zero error.

While at it, ensure that the 'out_filename' variable always contains a
valid string. This saves a few checks and makes the code more clean and
readable.

Change-Id: If8c1dae9549dd10e2f21d5b896414d47edac9fc2
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/8224
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-05-26 09:53:03 +00:00
Ian Thompson 2c8376b79d target/xtensa: avoid IHI for writes to non-executable memory
For MPU configs, determine memory access rights
by probing protection TLB.  Issuing IHI without execute
permissions can trigger an exception.

No new clang static analyzer warnings.

Change-Id: Iea8eab5c2113df3f954285c3b9a79e96d41aa941
Signed-off-by: Ian Thompson <ianst@cadence.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8080
Reviewed-by: Erhan Kurubas <erhan.kurubas@espressif.com>
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-05-11 11:55:55 +00:00
Parshintsev Anatoly 22ddf62d75 gdb_server: enable keep-alive packets for qCRC packet
Change-Id: Ia384179bb83ad6b70bf385cc9d575e9ec58f76c7
Signed-off-by: Parshintsev Anatoly <anatoly.parshintsev@syntacore.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8227
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-05-11 11:55:17 +00:00
Antonio Borneo 126d8a0972 cortex_a: drop cortex_a_dap_write_memap_register_u32()
Historically, the function cortex_a_dap_write_memap_register_u32()
was used to discriminate the register write in APB-AP CPU debug
against the complex memory access in AHB-AP memory bus.

It has no sense to keep the function and its comment.
Plus, by forcing atomic write it impacts the debug performance.

Drop it!
A further rework to enqueue sequence of atomic writes is needed.

Change-Id: I2f5e9015f0e27fa5a6d8337a1ae25e753e2e1d26
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8231
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
Tested-by: jenkins
2024-05-11 11:54:51 +00:00
Antonio Borneo caabdd4a66 cortex_a: drop the command 'cache auto'
The command 'cache auto' was introduced with commit cd440bd32a
("add armv7a_cache handlers") in 2015 to allow disabling the cache
handling done automatically by OpenOCD.
This was probably a way to test the cache handling when there were
still the two independent accesses for APB-AP CPU debug and for
AHB-AP memory bus.

The handling of cache for cortex_a is robust and there is no more
reason to disable it.
The command 'cache auto' is not used in any upstream script.
On target aarch64 this command has never been introduced as the
cache is always handled automatically by OpenOCD.

Drop the command 'cache auto' and add it in the deprecated list.
Drop the flag 'auto_cache_enabled' by considering it as true.
Rename the function 'armv7a_cache_auto_flush_all_data()' as
'armv7a_cache_flush_all_data()' and, while there, fix the error
propagation in SMP case.

Change-Id: I0399f1081b08c4929e0795b76f4a686630f41d56
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8230
Tested-by: jenkins
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
2024-05-11 11:54:40 +00:00
Antonio Borneo dbef02789f cortex_a: drop useless cache invalidate on mem write
The initial OpenOCD code for Cortex-A (ARMv7a) [1] was merged in
2009 but, due to lack of public documentation for ARMv7a, it was
almost a simple copy/paste from the existing code for Cortex-M
(ARMv7m).

On Cortex-M the same AP provides access to both CPU debug and CPU
memory. This feature is not present on ARMv7a.
To still keep some communality with ARMv7m code, the change [2]
splits the CPU debug access from the CPU memory access by using
two independent AP; this is copied from the system architecture of
TI OMAP3530 which provides to DAP a direct AHB-AP memory bus on
AP#0, separated from AP#1 for the APB-AP CPU debug.
But the direct memory access through the system bus breaks the
coherency between memory and CPU caches, so change [3] added some
cache invalidation to avoid issues.

The code to allow ARMv7a CPU to really read/write in CPU memory
was added by change [4] in 2011. Such still not optimized
implementation was very slow, so it did not replace the access
through the system bus. A selection through DAP's 'apsel" command
was used to select between the two modes.

Only in 2015, with change [5], the speed of CPU read/write was
improved using the DCC_FAST_MODE. But the direct access to the
memory through the system bus remained.

Finally, with change [6] in 2018 the system bus access was dropped
for good, as the new virtual target "mem_ap" could implement such
access in a more clean way.
Only memory access through CPU remained for ARMv7a.
Nevertheless, a useless cache invalidation remained in the code,
decreasing the speed of the write access.

Drop the useless cache invalidate on CPU memory write and the
associated comment, not anymore valid.
Drop the now unused function armv7a_cache_auto_flush_on_write().

This provides a speedup of between 4 and 8, depending on adapter
and JTAG/SWD speed.

Link: [1] 7a93100c2d ("Add minimalist Cortex A8 file")
Link: [2] 1d0b276c9f ("The rest of the Cortex-A8 support from Magnus: ...")
Link: [3] d4e4d65d28 ("Cache invalidation when writing to memory")
Link: [4] 05ab8bdb81 ("cortex_a9: implement read/write memory through APB-AP")
Link: [5] 0228f8e827 ("Cortex A: fix extra memory read and non-word sizes")
Link: [6] fac9be64d9 ("target/cortex_a: remove buggy memory AP accesses")

Change-Id: Ifa3c7ddf2698b2c87037fb48f783844034a7140e
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8229
Tested-by: jenkins
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
2024-05-11 11:54:11 +00:00
Daniel Anselmi bc9ca5f4a8 ipdbg: fix double free of virtual-ir data
Fix possible double free and possible
memory leak while creating an ipdbg hub.

Change-Id: I6254663c27c4f38d46008c4dbff11aa27b84f399
Signed-off-by: Daniel Anselmi <danselmi@gmx.ch>
Reviewed-on: https://review.openocd.org/c/openocd/+/8085
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-05-04 08:36:50 +00:00
Sean Anderson a84d1b5f5e tcl/target: Add helpers for booting Xilinx ZynqMP from JTAG
Add some helpers for booting ZynqMPs over JTAG. Normally, the CSU ROM
will load boot.bin from the boot medium. However, when booting from JTAG
we have to do this ourselves. There are generally two parts to this.
First, we need to load the PMU firmware. Xilinx's tools do this by
attaching to the PMU (a Microblaze CPU) over JTAG. However, the TAP is
undocumented and we don't have any microblaze support in-tree. So
instead we do it the same way FSBL does it:

- We ask the PMU to halt
- We load the firmware into the PMU RAM
- We ask the PMU to resume

The second thing we need to do is start one of the APU cores. When an
APU is released from reset, it starts executing at the value of its
RVBARADDR. While we could load the APU firmware over the AXI target,
it is faster to load it over the APU target. To do this, we put the APU
into an infinite loop before halting it. As an aside, I chose to use the
"APU" terminology as opposed to "core" to make it clear that these
commands operate on the A53 cores and not the R5F cores.

Typical usage of these commands could look something like

	targets uscale.axi
	boot_pmu /path/to/pmu-firmware.bin
	boot_apu /path/to/u-boot-spl.bin

But of course there is always the option to call lower-level commands
individually if your boot process is more unusual.

Signed-off-by: Sean Anderson <sean.anderson@seco.com>
Change-Id: I816940c2022ccca0fabb489aa75d682edd0f6138
Reviewed-on: https://review.openocd.org/c/openocd/+/8133
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2024-05-04 08:36:23 +00:00
Antonio Borneo 3eba7b53bf smp: fix SIGSEGV for "smp off" during target examine
The gdb subsystem is initialized after the first target examine,
so the field struct target::gdb_service is NULL during examine.

A command "smp off" in the examine event handler causes a SIGSEGV
during OpenOCD startup.

Check for pointer not NULL before dereferencing it.

Change-Id: Id115e28be23a957fef1b97ab66d7273f0ea0dce4
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8216
Tested-by: jenkins
2024-05-04 08:35:27 +00:00
Antonio Borneo c72afedce7 target: cortex_a: fix regs invalidation when -defer-examine
The code for cortex_a allocates the register cache during the very
first examine of the target.
To prevent a segmentation fault in assert_reset(), the call to
register_cache_invalidate() is guarded by target_was_examined().

But for targets with -defer-examine, the target is set as not
examined in handle_target_reset() just before entering in
assert_reset().

This causes registers to not be invalidated while reset a target
examined but with -defer-examine.

Change the condition and invalidate the register cache if it has
been already allocated.

Change-Id: I81ae782ddce07431d5f2c1bea3e2f19dfcd6d1ce
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8215
Tested-by: jenkins
2024-05-04 08:35:00 +00:00
Antonio Borneo 42e31d75b4 target: aarch64: fix regs invalidation when -defer-examine
The code for aarch64 allocates the register cache during the very
first examine of the target.
To prevent a segmentation fault in assert_reset(), the call to
register_cache_invalidate() is guarded by target_was_examined().

But for targets with -defer-examine, the target is set as not
examined in handle_target_reset() just before entering in
assert_reset().

This causes registers to not be invalidated while reset a target
examined but with -defer-examine.

Change the condition and invalidate the register cache if it has
been already allocated.

Change-Id: Ie13abb0ae2cc28fc3295d678c4ad1691024eb7b8
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8214
Tested-by: jenkins
2024-05-04 08:34:37 +00:00
Antonio Borneo 89d881c19a cortex_m: don't try to halt not-examined targets
Prevent a segmentation fault by preventing to try to halt a target
that has not been examined yet.

Change-Id: I5d344e7fbdb5422f7c5e2c39bdd48cbc6c2a3e58
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8213
Tested-by: jenkins
2024-05-04 08:33:54 +00:00
Marc Schink 8667a72653 target/target: Add 'debug_reason' to current target
Change-Id: Ie35b13b3e06411b4866ffeada47b3262493dbf2e
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/8021
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-05-04 08:31:14 +00:00
Antonio Borneo ac6b00c3ca target: cortex_m: fix display of DWT registers
Commit 16b4b8cf54 ("Cortex-M3: expose most DWT registers") added
the DWT registers to the list of CPU registers.
The commit message from 2009 reports the reason behind this odd
mixing of CPU and DWT registers.
This feature got broken in 2017 with the introduction of the field
struct reg::exist and its further use in the code. As result, the
command 'reg' on a target Cortex-M reports only the core registers
and then the header line
	===== Cortex-M DWT registers
not anymore followed by the DWT registers.

Fix it by tagging each DWT registers as existing.

Change-Id: Iab026e7da8d6b8ba052514c3fd3b5cdfe301f330
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Fixes: b5964191f0 ("register: support non-existent registers")
Reviewed-on: https://review.openocd.org/c/openocd/+/8198
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Tested-by: jenkins
2024-05-04 08:24:27 +00:00
Antonio Borneo a9e8ca55a6 jtag: linuxgpiod: minor alignment to coding style
Avoid double TAB in 'then' block by increasing indentation of the
multi-line condition.

Change-Id: I7f5a4437fe4f74228f1b0d98e5c5921af4fd36b8
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8200
Tested-by: jenkins
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
2024-05-04 08:22:11 +00:00
Antonio Borneo 495311d206 doc: style: report indentation of multi-line condition
To help readability and discriminate the 'then' block from the
multi-line condition, suggest to increase the indentation of the
condition.

Change-Id: I02e3834be3001e7ecf24349ad3cefe94b27b79c8
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8199
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Tested-by: jenkins
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
2024-05-04 08:21:33 +00:00
Antonio Borneo 04154af5d6 jtag: linuxgpiod: drop extra parenthesis
Checkpatch complains for extra parenthesis not required.

Drop them.

Change-Id: I311409f5732acf10a4910de5dcf0fb05f43e21b5
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8187
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Tested-by: jenkins
2024-04-07 20:09:42 +00:00
Walter Ji 47d983a77a target/mips32: fix clang sbuild check fail
Initialized `value` variables that could only be set in a branch.

Change-Id: Iec7413ade9d053c93352a58ff954ad49a6545923
Signed-off-by: Walter Ji <walter.ji@oss.cipunited.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8179
Tested-by: jenkins
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-04-07 19:36:49 +00:00
J. Neuschäfer 79b51fedab remote_bitbang: Change sleep commands to Zz to avoid conflict with SWD
It was noticed that the remote_bitbang protocol has a design issue:
SWD and sleep commands cannot be implemented at the same time, because
they overlap:

 - SWD uses d,e,f,g for setting pin state
 - sleep uses d,D for microsecond and millisecond sleep, respectively

This has previously been reported by Marek Vrbka, but it wasn't fixed.

This commit does the following to resolve the issue:

 - Change the sleep commands to 'Z' for 1 ms, 'z' for 1 µs
 - Document 'D' and 'd' as deprecated aliases
 - Switch the remote_bitbang driver in OpenOCD to 'Z' and 'z'

Unfortunately that's a breaking change, because existing adapter-side
implementations of the protocol will have to implement the new commands
to keep working with future versions of OpenOCD. Fortunately, the
remote sleep commands haven't been part of an OpenOCD release yet,
which should limit the breakage somewhat.

Reported-by: Marek Vrbka <marek.vrbka@codasip.com>
Link: https://sourceforge.net/p/openocd/mailman/openocd-devel/thread/670d28d2-75a1-45ec-afe5-541415701d7a%40codasip.com/
Fixes: e8e09b1b5 ("remote_bitbang: add use_remote_sleep option to send delays to remote")
Change-Id: I04d2790a33bff9d47eb7f69b3275fd9a271625ae
Signed-off-by: J. Neuschäfer <j.neuschaefer@gmx.net>
Reviewed-on: https://review.openocd.org/c/openocd/+/8191
Reviewed-by: David Ryskalczyk <david.rysk@gmail.com>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
Reviewed-by: Jeremy Herbert <jeremy.006@gmail.com>
2024-04-07 19:36:29 +00:00
Antonio Borneo e035756b22 jtag: linuxgpiod: fix detection for line request bias
Commit 290eac04b9 ("drivers/linuxgpiod: Migrate to adapter gpio
commands") introduced an incorrect check to determine if the
library libgpiod declares the line request flags:
	GPIOD_LINE_REQUEST_FLAG_BIAS_DISABLE
	GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_UP
	GPIOD_LINE_REQUEST_FLAG_BIAS_PULL_DOWN
The names above are declared by the library inside an enum, thus
cannot be used by the C preprocessor in a #ifdef.

Determine in configure if the version of libgpiod provides the
line request flags for "bias" and define a C macro.
Use the new macro in the driver code.

Change-Id: Iaa452230f4753fce4c6e9daa254299cedb7cab7f
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Fixes: 290eac04b9 ("drivers/linuxgpiod: Migrate to adapter gpio commands")
Reviewed-on: https://review.openocd.org/c/openocd/+/8186
Tested-by: jenkins
Reviewed-by: Michael Heimpold <michaheimpold@gmail.com>
2024-04-07 19:35:41 +00:00
Antonio Borneo 74e7fcb2dd configure: prevent build of linuxgpiod with libgpiod v2
The API in libgpiod v2 have changed, and current driver code for
linuxgpiod does not build anymore.

Prevent building the current driver linuxgpiod with the new
library.

Change-Id: Ie673db786dc50ae18a263d2c0a2b46b106866450
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8185
Reviewed-by: Michael Heimpold <michaheimpold@gmail.com>
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2024-04-07 19:35:02 +00:00
Dominik Wernberger 329e983ee9 zynq_7000.cfg: Fix issue 'Error: can't read "zynq_pl": no such variable'
Change-Id: Ic79ce114b60d0707a6e082a81743b378b164b4e2
Signed-off-by: Dominik Wernberger <dominik.wernberger@gmx.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/8190
Reviewed-by: Daniel Anselmi <danselmi@gmx.ch>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Tested-by: jenkins
2024-04-07 13:46:13 +00:00
Steven Chang dd17582722 flash/nor/eneispif: support ENE KB1200 ispi flash
Change-Id: I03bccceb1956ee121e6a3728b7d647ef1262fa23
Signed-off-by: Steven Chang <steven@ene.com.tw>
Reviewed-on: https://review.openocd.org/c/openocd/+/8136
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2024-04-01 05:51:33 +00:00
Tomas Vanek a35e254c53 target/adi_v5_swd: move setting of do_reconnect one level up
Move setting of do_reconnect flag from swd_run_inner()
to swd_run(). Reconnect is not used at the inner level
and the flag had to be cleared after swd_run_inner()
to prevent recursion.

Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Change-Id: Ib1de80bbdf10d1cbfb1dd351c6a5658e50d12af2
Reviewed-on: https://review.openocd.org/c/openocd/+/8155
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2024-03-24 13:42:24 +00:00
Antonio Borneo c02cf9404d helper/list: include the correct header file
The file 'list.h', copied from FreeBSD, does not depend from any
OpenOCD specific include file, but only needs 'stddef.h' for the
type 'size_t'.

Let 'list.h' to include the correct header file, then fix the now
broken dependencies in the other files that were incorrectly
relying on 'list.h' to include 'helper/types.h'

Change-Id: Idd31b5bf607e226cac44ef41b2aa335ae4dbf519
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8173
Tested-by: jenkins
2024-03-24 13:41:17 +00:00
Antonio Borneo a213afad09 helper/list: Replace Linux code with FreeBSD one
The file list.h was originally taken from the Linux kernel code,
thus under license GPL-2.0-only. This locks OpenOCD to follow the
same license, even if the majority of OpenOCD files are licensed
as GPL-2.0-or-later.

A similar file is also present in FreeBSD code base under the more
permissive license BSD-2-Clause.

Drop the code from Linux kernel and replace it with the code from
FreeBSD 13.3.0.
Adapt the code to OpenOCD coding style by fixing the majority of
issues identified by checkpatch.
Add the OpenOCD specific macros and comments.

Unfortunately this causes the lost of all the doxygen comments.

Checkpatch-ignore: MACRO_ARG_REUSE, MACRO_ARG_PRECEDENCE
Change-Id: I6d86752c50158f3174c4e8c4add81e9998d01e0e
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8172
Tested-by: jenkins
2024-03-24 13:41:03 +00:00
Antonio Borneo 35e4c4616f gdb_server: drop useless check in gdb_keep_client_alive()
OpenOCD can send it's log to gdb, and gdb replies with 'OK'.
Calls to LOG_XXX() are also present in the code that communicates
with gdb. This can cause infinite nested calls.

OpenOCD uses the flag 'gdb_con->busy' to protect the communication
with gdb and prevent nested calls.

There is no reason to check for 'gdb_con->busy' in the code for
keep-alive, as keep_alive() is never called in this gdb server;
the flag would eventually be set if the current keep_alive() will
send something to gdb.

Drop the flag 'gdb_con->busy' in gdb_keep_client_alive().
While there, document the use of 'gdb_con->busy'.

Change-Id: I1ea20bf96abb5d2f1fcdba1e3861df257c396bb6
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8166
Tested-by: jenkins
2024-03-24 13:40:27 +00:00
Antonio Borneo 0c0243228c gdb_server: add async-notif keep-alive during memory read/write
To avoid gdb to timeout, OpenOCD implements a keep-alive mechanism
that consists in sending periodically to gdb empty strings embedded
in the "O" remote reply packet.

The main purpose of "O" packets is to forward in the gdb console
the output of the remote execution; the gdb-remote puts in the "O"
packet the string that gdb will print. It's use is restricted to
few "running/execution" contexts listed in
http://sourceware.org/gdb/onlinedocs/gdb/Stop-Reply-Packets.html
and this currently limits the keep-alive capabilities of OpenOCD.

Long data transfer (memory R/W) can also cause gdb to timeout if
the interface is too slow. In this case the usual keep-alive based
on "O" packet cannot be used and, if used, would trigger a protocol
error that causes the transfer to be dropped.
The slow transfer rate can be simulated by adding some delay in the
main loop of mem_ap_write() and mem_ap_read(), then using the gdb
commands "dump" and "restore".

In the wait loop during a memory R/W, gdb drops any extra character
received from the gdb-remote that is not recognized as a valid
reply to the memory command. Every dropped character re-initializes
the timeout counter and could be used as keep-alive.

From gdb 7.0 (released 2009-10-06), an asynchronous notification
can also be received from gdb-remote during a memory R/W and has
the effect to reset the timeout counter, thus can be used as
keep-alive.
The notification would be treated as "junk" extra characters by any
gdb older than 7.0, being still valid as keep-alive.
Check putpkt_binary() and getpkt_sane() in gdb commit
74531fed1f2d662debc2c209b8b3faddceb55960

Currently, only one notification packet ("Stop") is recognized by
gdb, and gdb documentation reports that notification packets that
are not recognized should be silently dropped.
Use 'set debug remote 1' in gdb to dump the received notifications
and the junk extra characters.

Add a new level in enum gdb_output_flag for using the asynchronous
notifications.
Activate this new level during memory transfers.
Send a custom "oocd_keepalive" notification packet as keep_alive.
While there, drop a useless return in the switch/case, already
managed in case of break.

After this commit, the proper calls to keep_alive() have to be
added in the loops that code the memory transfers. Of course, the
keep_alive() should be placed during the wait for JTAG flush, not
while locally queuing the JTAG elementary transfers.

Change-Id: I9ca8e78630611597d15984bd0e8634c8fc3c32b9
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8165
Tested-by: jenkins
2024-03-24 13:40:11 +00:00
Walter Ji 01a797af14 target/mips32: add fpu access support
Add access to fpr and cp1 registers.
GDB can now check the FPRs with `info reg f` and change them.
Checkpatch-ignore: MACRO_ARG_REUSE

Change-Id: I63896ab6f6737054d8108db105a13a58e1446fbc
Signed-off-by: Walter Ji <walter.ji@oss.cipunited.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7866
Tested-by: jenkins
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-03-16 14:47:16 +00:00
Daniel Anselmi a88db9b121 ipdbg: configurable queue size used between JTAG-Host and JTAG-Hub
Change-Id: I7941de02a968ccab730bfebd3483b8c3b84d7e53
Signed-off-by: Daniel Anselmi <danselmi@gmx.ch>
Reviewed-on: https://review.openocd.org/c/openocd/+/7980
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2024-03-16 14:44:31 +00:00
Daniel Anselmi 7a77355a3e ipdbg: split ipdbg command into multiple commands
To simplify the ipdbg start/stop command and be able to
add additional commands in the future, we introduce the
concept of a hub which has to be created before a
ipdbg server can be started.
The hub was created on the fly in previous versions.

Change-Id: I55f317542d01a7324990b2cacd496a41fa5ff875
Signed-off-by: Daniel Anselmi <danselmi@gmx.ch>
Reviewed-on: https://review.openocd.org/c/openocd/+/7979
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2024-03-16 14:43:33 +00:00
Antonio Borneo 1d076d6ce1 openocd: dump full command line in the debug log
When receiving an OpenOCD debug log to investigate about errors or
issues, the first question is often about providing the complete
command line to better understand the use context.
Plus, when OpenOCD is lunched by an IDE, its command line is kept
hidden inside the IDE, adding troubles to the user to recover it.

Add the full command line directly inside the debug log.

It could have been useful to also search and add in the log the
full path of the OpenOCD executable, but this is not an immediate
task due to portability among OS's. See, for example:
	https://stackoverflow.com/questions/933850
This part could be handled in a future change, if really needed.

Change-Id: Ia6c5b838b9b7208bf1ecac7f95b5efc319aeabf5
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8170
Tested-by: jenkins
Reviewed-by: Paul Fertser <fercerpav@gmail.com>
2024-03-16 14:42:20 +00:00
Antonio Borneo e9df8a5102 target: aarch64: add support for 32 bit MON mode
Extend the existing code to support Monitor mode in AArch32.

Change-Id: Ia43df98d1497baac48aea67b92d81344c24f0635
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8169
Tested-by: jenkins
2024-03-16 14:41:53 +00:00
Tomas Vanek 4c0a2cf42e target/adi_v5_swd: fix DP registers banking
ADIv6 brought more complicated rules for DP reg 0 banking.
Neither the original implementation [1] nor the later
modification [2] respected that the DP reg 0 is banked
for read only, not for write. Enforcing of an useless
SELECT write before a write to ABORT register may trigger
FAULT (CTRL/STAT bits ORUNDETECT and STICKYORUN are set)
or WAIT (DP is stalled by an outstanding previous operation)
and therefore make ABORT register virtually unusable
on some adapters (bitbang, CMSIS-DAP).

There are DP ABORT specific functions swd_queue_ap_abort()
and swd_clear_sticky_errors() which worked around the problem
using the lowest level swd->write_reg(). Using a specific
write procedure for a single DP register was error prone
(there are other DP_ABORT writes using swd_queue_dp_write_inner())
and also the Tcl command 'xx.dap dpreg 0 value' suffered
from unwanted SELECT write.

Other smaller discords in DP banking probably do not
influence normal DP operation however they may complicate
debugging in corner cases.

Adhere strictly to the DP banking rules for both ADI versions.

Fixes: [1] commit 72fb88613f ("adiv6: add low level swd transport")
Fixes: [2] commit ee3fb5a0ea ("target/arm_adi_v5: fix DP SELECT logic")
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Change-Id: I3328748c1c3e0661c5ecd6eb070ac519b190ace2
Reviewed-on: https://review.openocd.org/c/openocd/+/8154
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-03-16 14:38:21 +00:00
Tomas Vanek 31af18e9d1 jtag/drivers/bitbang: limit SWD WAIT retries by timeout
The bitbang driver kept retrying a SWD command as long as
the debugged device had been responding by SWD WAIT.
If the DP stalled in WAIT permanently, OpenOCD hanged.

Check 0.5 sec timeout in WAIT retry loop.

While on it insert a short alive_sleep() if the command
is retried 20 or more times.

Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Change-Id: I744e56e21a5a2dc2c4494cc0d7bbcb4be14ddb23
Reviewed-on: https://review.openocd.org/c/openocd/+/8153
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2024-03-16 14:37:26 +00:00
Tomas Vanek f7f4fa84f1 jtag/drivers/bitbang: use LOG_CUSTOM_LEVEL() macro for SWD
Log SWD commands with not OK response but WAIT retries at debug level.
For commands responded OK and WAIT retries use debug io level
not to flood the log.

Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Change-Id: Idf658e82ed970061c155945df55d06908ed25e09
Reviewed-on: https://review.openocd.org/c/openocd/+/8152
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-03-16 14:37:03 +00:00
Tomas Vanek b63e065f23 helper/log: add LOG_CUSTOM_LEVEL() macro
Allow logging at a changeable level.

Add an example of usage in ftdi driver.
Log SWD commands with not OK response at debug level (3).
For commands which responded OK use debug io level (4)
not to flood the log.

Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Change-Id: I67a472b293f7ed9ee84cadb7c081803e9eeb1ad0
Reviewed-on: https://review.openocd.org/c/openocd/+/8151
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2024-03-16 14:36:48 +00:00
Tomas Vanek 263dbc1472 target/arm_adi_v5: introduce adiv5_jim_configure_ext()
Allow direct pointer to struct adiv5_private_config
for targets with adiv5_private_config inside of a bigger
private config container. Use it instead of the private_config
pointer toggling hack in aarch64.c

Allow optional use of -dap parameter and use it instead
of the static variable hack in xtensa_chip.c

Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Change-Id: I7260c79332940adfa49d57b45cae39325cdaf432
Reviewed-on: https://review.openocd.org/c/openocd/+/8138
Tested-by: jenkins
Reviewed-by: Ian Thompson <ianst@cadence.com>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-03-16 14:35:24 +00:00
Tomas Vanek 348b79aafe drivers/cmsis_dap, kitprog: use helper to derive err code from ack
Unify the error codes returned by adapter drivers in the case
of the received SWD ACK field differs from OK.

Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Change-Id: I29e478390b4b30408054a090ac6a7fac3415ae71
Reviewed-on: https://review.openocd.org/c/openocd/+/8137
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2024-03-16 14:34:28 +00:00
Tomas Vanek 12ff36bd19 flash/nor/nrf5: drop useless for cycle condition
Commit [1] added a break on error to the nrf5_erase() sector loop
and the checking of the res value became useless in the for loop condition.

Removing nrf5_get_probed_chip_if_halted() later in [2]
dropped res initialization and clang static analyser complains
  "The left operand of '==' is a garbage value"

Drop the useless test!

Fixes: [1] commit 491636c8b8 ("flash/nor/nrf5: check protection before flash erase/write on nRF51")
Fixes: [2] commit 2db325f539 ("flash/nor/nrf5: drop nrf5_get_probed_chip_if_halted()")
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Change-Id: Ife6071c509719f8d7dc312fe9a780bdcf2575f69
Reviewed-on: https://review.openocd.org/c/openocd/+/8174
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-03-10 17:54:52 +00:00
Walter Ji 561ea48d83 target/mips32: add dsp access support
Add access to dsp registers and a command for dsp related operations.
Checkpatch-ignore: MACRO_ARG_REUSE

Change-Id: I30aec0b9e4984896965edb1663f74216ad41101e
Signed-off-by: Walter Ji <walter.ji@oss.cipunited.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7867
Tested-by: jenkins
Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-03-09 11:08:21 +00:00
Antonio Borneo fcda9f1561 gdb_server: fix segfault with GDB command 'flash-erase'
Running the GDB command 'flash-erase' triggers sending the remote
GDB commands 'vFlashErase' (one per flash bank) followed by one
single 'vFlashDone', with no 'vFlashWrite' commands in between.
This causes the field 'gdb_connection->vflash_image' to be NULL
during the execution of 'vFlashDone', triggering a segmentation
fault in OpenOCD.

While parsing 'vFlashDone', check if any image to flash has been
received.

Change-Id: I443021c7a531255b60f2c44c2685e52e3c34b5c8
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8164
Tested-by: jenkins
2024-03-09 11:04:29 +00:00