Commit Graph

10502 Commits

Author SHA1 Message Date
Tomas Vanek 4892e32294 target/cortex_m: allow poll quickly get out of TARGET_RESET state
cortex_m_poll_one() detects reset testing S_RESET_ST sticky bit.
If the signal comes unexpectedly, poll must return TARGET_RESET state.

On the contrary in case of polling inside of an OpenOCD reset command,
TARGET_RESET has been has already been set and we need to get out of
it as quickly as possible.

The original code needs 2 polls: the first clears S_RESET_ST
and keeps TARGET_RESET state, the current TARGET_RUNNING or TARGET_HALTED
is reflected as late as the second poll is done.

Change the logic to keep in TARGET_RESET only when necessary.

See also [1]

Link: [1] 8284: tcl/target: ti_cc3220sf: Use halt for CC3320SF targets | https://review.openocd.org/c/openocd/+/8284
Fixes: https://sourceforge.net/p/openocd/tickets/360/
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Change-Id: I759461e5f89ca48a6e16e4b4101570260421dba1
Reviewed-on: https://review.openocd.org/c/openocd/+/8285
Tested-by: jenkins
Reviewed-by: Dhruva Gole <d-gole@ti.com>
2024-06-17 14:04:49 +00:00
Daniel Anselmi bf4be566a7 pld: small documentation fixes.
Change-Id: I969f51c38fc0c34c6bdba98b0e618d7f28ea4052
Signed-off-by: Daniel Anselmi <danselmi@gmx.ch>
Reviewed-on: https://review.openocd.org/c/openocd/+/8084
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2024-06-15 14:25:17 +00:00
Daniel Anselmi 9bc7a381b2 pld/intel: remove idcodes from intel.c
Remove list of id codes for all families.
Maintain a list with id, bscan-length and check position
in the tcl config files for each family.

The Intel FPGA Driver option 'family' is not otional anymore.

Change-Id: I9a40a041069e84f6b4728f2cd715756a36759c89
Signed-off-by: Daniel Anselmi <danselmi@gmx.ch>
Reviewed-on: https://review.openocd.org/c/openocd/+/8083
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2024-06-15 14:25:05 +00:00
Daniel Anselmi 7e4c9609ca pld/intel: remove duplicated code
Change-Id: I043d16c77ce97d3e888774747ed6bfc4c7e63c04
Signed-off-by: Daniel Anselmi <danselmi@gmx.ch>
Reviewed-on: https://review.openocd.org/c/openocd/+/8082
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-06-15 14:24:32 +00:00
George Voicu b1600bb342 tcl/board: Support for Digilent Nexys 2 board
Support Digilent Nexys 2 board JTAG chain

Signed-off-by: George Voicu <razvanvg@hotmail.com>
Change-Id: I350f80b49303c4b0402d93ebc120a591ef727551
Reviewed-on: https://review.openocd.org/c/openocd/+/7336
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-06-15 14:14:11 +00:00
George Voicu a420f00d10 tcl/fpga: Support for Xilinx Spartan3 series devices
Tap definition for Xilinx Spartan 3/3E/3A/3AN/3A-DSP devices.

Signed-off-by: George Voicu <razvanvg@hotmail.com>
Change-Id: Ieda2b61fc270840f9192976697fcac259c45e3b8
Reviewed-on: https://review.openocd.org/c/openocd/+/7335
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2024-06-15 14:13:58 +00:00
George Voicu ed30c9a572 tcl/fpga/xilinx-dna: Support for reading Spartan3 DNA code
Add Xilinx Spartan3 ISC_DNA instruction

Signed-off-by: George Voicu <razvanvg@hotmail.com>
Change-Id: Iaddb079c9fdd1b91c65def36878fe81783098696
Reviewed-on: https://review.openocd.org/c/openocd/+/7331
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-06-15 14:13:28 +00:00
Antonio Borneo b49e03f77e target/arm_tpiu_swo: Fix memory leak on error
In case of fail to allocate 'obj->name', the memory allocated for
'obj->out_filename' is not freed, thus leaking.

Since 'obj' is allocated with calloc(), thus zeroed, switch to use
the common error exit path for both allocations of 'obj->name' and
'obj->out_filename'.

Fixes: 2506ccb509 ("target/arm_tpiu_swo: Fix division by zero")
Change-Id: I412f66ddd7bf7d260cee495324058482b26ff0c5
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8300
Tested-by: jenkins
Reviewed-by: zapb <dev@zapb.de>
2024-06-15 14:12:06 +00:00
Evgeniy Naydanov 400cf213c0 fix GCC's `-Wcalloc-transposed-args` warning
GCC 14.1.0 warns about calls to `calloc()` with element size as the
first argument.
Link: https://gcc.gnu.org/onlinedocs/gcc-14.1.0/gcc/Warning-Options.html#index-Wcalloc-transposed-args

Change-Id: I7d44a74a003ee6ec49d165f91727972478214587
Signed-off-by: Evgeniy Naydanov <evgeniy.naydanov@syntacore.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8301
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2024-06-15 14:11:16 +00:00
Tomas Vanek e4c0904731 flash/nor/nrf5: handle ERROR_WAIT during nRF91 flash erase
Erase is initiated by write to a flash address. Due to the
silicon errata of nRF91 the write stalls the bus until the page erase
is finished (takes up to 87ms).
If the adapter does not handle SWD WAIT properly, the following read
in nrf5_wait_for_nvmc() returns ERROR_WAIT.

Wait for fixed time before accessing AP. Not nice, but the only
working solution until all adapters handle SWD WAIT.

If the fixed wait does not suffice, continue the wait loop after a delay.
It makes some unnecessary noise however erase works.

Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Change-Id: I63faf38dad79440a0117ed79930442bd2843c6db
Reviewed-on: https://review.openocd.org/c/openocd/+/8115
Reviewed-by: Tomáš Beneš <tomas@dronetag.cz>
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-06-08 09:20:14 +00:00
Tomas Vanek 70b362d4f4 flash/nor/nrf5: show proper SoC type on newer nRF91 devices
Since nRF9160 Product Specification v2.1 the new UICR SIPINFO
fields should be preferred over UICR INFO.
Tested on nRF9161.

Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Change-Id: Ib8005b3b6292aa20fa83c1dcebd2de27df58b661
Reviewed-on: https://review.openocd.org/c/openocd/+/8114
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-06-08 09:19:14 +00:00
Tomas Vanek 17be341d38 tcl/target: add nRF53 and nRF91 config files
Both devices can be configured with or without SWD multidrop.

nRF53 network core is examined on demand to avoid problems
when the core is forced off.

Change-Id: I08f88ff48ff7ac592e9214b89ca8e5e9428573a5
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/8113
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2024-06-08 09:12:14 +00:00
Tomas Vanek d94daf776c flash/nor/nrf5: add basic nRF53 and nRF91 support
Probes all flash and UICR areas.
Flash erase and write tested.

On nRF53 mass erase works on the application core flash bank only.
The Tcl script nrf53_recover can serve as the workaround on the
network core.
TODO: mass erase of the nRF53 network core flash.

Some ideas taken from [1] and [2].

Change-Id: I8e27a780f4d82bcabf029f79b87ac46cf6a531c7
Link: [1] 7404: flash: nor: add support for Nordic nRF9160 | https://review.openocd.org/c/openocd/+/7404
Link: [2] 8062: flash: nor: add support for Nordic nRF9160 | https://review.openocd.org/c/openocd/+/8062
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/8112
Reviewed-by: Tomáš Beneš <tomas@dronetag.cz>
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-06-08 09:04:34 +00:00
Tomas Vanek fc7a428fc2 flash/nor/nrf5: make flash erase little faster
Enable and disable erase mode only once
instead of toggling it for each sector.

Refactor to decrease the number of call levels.

Change-Id: Ie546a4fc24da0eea2753a2bebaa63d941ef7aa1d
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/8111
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-06-08 09:03:53 +00:00
Tomas Vanek 37f9485cef flash/nor/nrf5: introduce address maps
Preparatory change before extending support to nRF53 and 91.

While on it, rename nRF51 and 52 specific routines and constants.

Change-Id: I46bc496cef5cbde46d6755a4b908c875351f6612
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/8110
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-06-08 08:59:53 +00:00
Paul Fertser ed9203f4aa gdb_server: do not start multiple instances on "pipe"
For configurations which include multiple targets and the "pipe" mode is
requested only the first gdb_server instance should be enabled,
otherwise GDB gets confusing replies, goes out of sync and the session
fails in weird ways.

Compile-tested only.

Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Change-Id: If8f13aa7b58e9b0dc6d5ae88cf75538b34cc1218
Reviewed-on: https://review.openocd.org/c/openocd/+/8222
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-06-08 08:51:20 +00:00
Marc Schink 1fba55a9b6 flash/nor/tcl: Fix memory leak of flash bank name
Change-Id: I54cd1ee479a0570ae849a71be47c82eebd1ae454
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/8303
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2024-06-08 08:50:55 +00:00
Marc Schink 0a3217b8ff tcl/board: Add config for NXP FRDM-KV31F
Change-Id: I4d7cd1bcadd8159e4830107c2788708aef02add0
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/8299
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-06-08 08:46:36 +00:00
Marc Schink 84126893ff tcl/board: Add config for NXP FRDM-KV11Z
Change-Id: I9cd497a085f8f9c7854ae3b96e60a73b3b050d0e
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/8298
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2024-06-08 08:46:24 +00:00
Parshintsev Anatoly d382c95d57 target/riscv: support for smp group manipulation
this functionality allows to query if a target belongs to some smp group
and to dynamically turn on/off smp-specific behavior

Change-Id: I67bafb1817c621a38ae4a2f55e12e4143e992c4e
Signed-off-by: Parshintsev Anatoly <anatoly.parshintsev@syntacore.com>
Signed-off-by: Bernhard Rosenkränzer <bero@baylibre.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8296
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-06-08 08:45:44 +00:00
Tim Newsome 2f8bb252ff doc: Minimally describe the BSCAN tunnel interface.
Add minimal documentation for the BSCAN tunnel interface.
This is based on Tim Newsome <tim@sifive.com>'s work on
the RISC-V fork.

Change-Id: I5e0cd6972cb90649670249765e9bb30c2847eea6
Signed-off-by: Tim Newsome <tim@sifive.com>
Signed-off-by: Bernhard Rosenkränzer <bero@baylibre.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8297
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-06-08 08:45:21 +00:00
Mark Featherston 9623069e80 jtag/drivers/ftdi: Use command_print instead of LOG_USER for get_signal
LOG_USER only outputs to user interfaces, but leaves no way to get the
FTDI inputs over the RPC interface. Switch to command_print so this
string goes to both logs and the RPC interface.

Change-Id: I99024194b6687b88d354ef278aa25f372c862c22
Signed-off-by: Mark Featherston <mark@embeddedts.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8294
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
Reviewed-by: zapb <dev@zapb.de>
2024-06-08 08:45:04 +00:00
Antonio Borneo 72b39088ee target: reset examine after assert_reset
For some target, the API assert_reset() checks if the target has
been examined, with target_was_examined(), to perform conditional
operations like:
- assert adapter's srst;
- write some register to catch the reset vector;
- invalidate the register cache.

Targets created with -defer-examine gets the examine flag reset
right before entering in their assert_reset(), disrupting the
actions above.

For targets created with -defer-examine, move the reset examine
after the assert_reset().

Change-Id: If96e7876dcace8905165115292deb93a3e45cb36
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8293
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2024-06-08 08:44:36 +00:00
Noah Moroze b5e7118048 src/helper/startup: fix syntax errors
The missing closing brackets were caught by tclint v0.2.5
(https://github.com/nmoroze/tclint):

```
tclint src/helper/startup.tcl | grep "syntax error"
```

The improperly escaped backslash was caught by manual inspection during
code review.

Change-Id: I8cd44e58040d4627f6b2fc8b88ca8a930cda0ba6
Signed-off-by: Noah Moroze <noahmoroze@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8282
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-06-08 08:44:18 +00:00
Noah Moroze 7050cade9d tcl/chip/st/spear: fix syntax errors
While the current jimtcl does not consider this an error, the Tcl
dodekalogue states that strings terminate at the second double quote
character (see https://www.tcl.tk/man/tcl/TclCmd/Tcl.htm#M8).

These syntax errors were caught by tclint v0.2.5
(https://github.com/nmoroze/tclint):

```
tclint tcl/chip/st/spear/spear3xx_ddr.tcl | grep "syntax error"
```

Change-Id: I2763d93095e3db7590644652f16b7b24939d6cae
Signed-off-by: Noah Moroze <noahmoroze@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8281
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-06-08 08:44:04 +00:00
Noah Moroze 223e3d8fe7 tcl/target/c100helper: fix syntax errors
Fixes: 64d89d5ee1 ("tcl: [3/3] prepare for jimtcl 0.81 'expr' syntax change")

These syntax errors were caught by tclint v0.2.5
(https://github.com/nmoroze/tclint):

```
tclint tcl/target/c100helper.tcl | grep "syntax error"
```

Change-Id: I511c54353c4853560adca6b4852d48df2aade283
Signed-off-by: Noah Moroze <noahmoroze@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8280
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2024-06-08 08:43:30 +00:00
Noah Moroze eecba412cd tcl/memory: fix syntax errors
Using a command in an expression requires a bracketed command
substitution.

These syntax errors were caught by tclint v0.2.5
(https://github.com/nmoroze/tclint):

```
tclint tcl/memory.tcl | grep "syntax error"
```

Change-Id: I510d46222f4fb02d6ef73121b231d5b2df77e5c0
Signed-off-by: Noah Moroze <noahmoroze@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8279
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2024-06-08 08:42:34 +00:00
Marc Schink c7c4d4d48c contrib: Drop 'coresight-trace.txt'
This document is outdated and has broken text formatting. It also
provides no useful information to users nor developers, at worst it
causes confusion. For that reason, drop this file.

Change-Id: Id5ee1f6e74d1a641c60d897f114bb97f5fd48e5b
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/8292
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2024-06-08 08:42:04 +00:00
Antonio Borneo 71013521d7 server: gdb: respect command gdb_report_register_access_error
Commit 236c54c94a ("server/gdb_server.c: support unavailable
registers") correctly returns a string of 'x' when the register is
not available in the current target.

While implementing this, it incorrectly drops the pre-existing
feature of optionally ignoring errors while reading a register.
This feature has a real use case documented in the OpenOCD manual
in chapter 'Using GDB as a non-intrusive memory inspector', where
GDB attaches to a target without halting it. For targets that need
to be halted to read its registers, we need to hack the values of
the registers returned to GDB; either returning 'xxxx' or an error
causes GDB to drop the connection.

Re-add the check on 'gdb_report_register_access_error' to keep the
pre-existing behavior when a register error has to be ignored:
- return a string of '0';
- drop a debug message.

Change-Id: Ie65c92f259f92502e688914f334655b635874179
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Fixes: 236c54c94a ("server/gdb_server.c: support unavailable registers")
Reviewed-on: https://review.openocd.org/c/openocd/+/8228
Tested-by: jenkins
2024-06-08 08:38:26 +00:00
R. Diez 437dde701c Documentation: fix warning "unbalanced square brackets"
Change-Id: I17b716533f5c9371600f0d932bf9b81c95c349e7
Signed-off-by: R. Diez <rdiezmail-openocd@yahoo.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/8261
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2024-05-26 10:01:03 +00:00
R. Diez 7c4ddfb546 Documentation: Fix 2 warnings "Underfull \hbox (badness 10000)"
The link to product GW16042 was broken, so it has been reduced to
the manufacturer's website, which fixes the warning as a side effect.

The link to Raisonance RLink was broken, and the new one is shorter,
which fixes the warning as a side effect.

Change-Id: I4df9acf2d994d51cd8f375bdac6c803270029506
Signed-off-by: R. Diez <rdiezmail-openocd@yahoo.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/8264
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2024-05-26 10:00:42 +00:00
R. Diez cf48bf6d3d ChangeLog: fix warning "Wide character in print" from git2cl
Change-Id: Iaefd989413753fb59642c3887807abd6ddac4b53
Signed-off-by: R. Diez <rdiezmail-openocd@yahoo.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/8262
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Tested-by: jenkins
2024-05-26 10:00:00 +00:00
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