11124 Commits

Author SHA1 Message Date
Antonio Borneo
880f234915 svf: rework svf_parse_cmd_string()
Rework the function to drop the goto in the switch statement.
While there, change some variable to boolean.

Change-Id: I37cbc8aafaeb8aef7f083ee6f5afa9eae71e0cd9
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9042
Tested-by: jenkins
Reviewed-by: zapb <dev@zapb.de>
2025-09-06 08:31:46 +00:00
Antonio Borneo
c22e1eb3ce svf: drop goto and label in switch statement
Drop the jumps to the label thanks to the factorized code.
Drop the now unused label.

Change-Id: I7e61ecee5a883a6ed6b77bfbff54a615d1b4d61c
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9041
Tested-by: jenkins
2025-09-06 08:31:30 +00:00
Antonio Borneo
1c668a0a6b svf: factorize big switch case
Factorize function svf_run_command() by moving out of the 'case'
the common code related to the label 'xxr_common'.

The target is to drop later on the ugly label 'xxr_common' inside
the switch.

Apart for:
- the function and local variables declaration,
- the added function call in place of original code,
- the reduced indentation in the new function,
this change is a dummy copy/paste with no code modification.

Change-Id: I8149cf25f460326ba6666a9287c5c309e5d99488
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9040
Tested-by: jenkins
2025-09-06 08:31:11 +00:00
Antonio Borneo
ad8d96230d svf: prepare for aligning switch and case statements
To prepare for aligning switch and case statements, fix in advance
some checkpatch error due to existing code:
- remove unnecessary parenthesis;
- uniform braces around if/else statements.

Change-Id: I851032e1b126462a325f73bdf236fd2dbc938ff3
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9039
Tested-by: jenkins
2025-09-06 08:30:55 +00:00
Antonio Borneo
15fb738850 rtos: linux: align switch and case statements
The coding style requires the 'case' to be at the same indentation
level of its 'switch' statement.

Align the code accordingly.

No changes are reported by
	git log -p -w --ignore-blank-lines --patience

Change-Id: Ic4070571d322776b638a15a40af85cd31fdae7ce
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9038
Tested-by: jenkins
2025-09-06 08:30:40 +00:00
Antonio Borneo
d34ff22429 rtos: linux: prepare for aligning switch and case statements
To prepare for aligning switch and case statements, fix in advance
some checkpatch error due to existing code:
- fix useless 'else' after 'break', by moving the 'break'
  statement.

While there:
- modify the checks on strncmp().

Change-Id: I123f3c0e3999669440845c946e4839d7288e8d91
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9037
Tested-by: jenkins
2025-09-06 08:30:23 +00:00
Antonio Borneo
c5806c0ae1 rtos: linux: drop useless code
Since the initial code merged in 2012, the last case of the switch
has a useless test on 'retval' that is not assigned in the case.
Since 'retval' is initialized to ERROR_OK, the condition is always
false.

Drop the check on 'retval'.
While there, drop the useless parenthesis around the 'case' and
add the 'break' statement.

Change-Id: I3f673b5e10f6b28a4a74881b8a06a71b58afb422
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9036
Tested-by: jenkins
2025-09-06 08:30:08 +00:00
Antonio Borneo
44b8d0f186 flash: nor: jtagspi: invert the operands in check
Check the variable against the constant.
No functional change.

Change-Id: Ie3138e516f4b81bf544780981863e856f8ffc528
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9035
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2025-09-06 08:29:54 +00:00
Antonio Borneo
36a2b6c6f8 flash: nor: align switch and case statements
The coding style requires the 'case' to be at the same indentation
level of its 'switch' statement.

Align the code accordingly.

No changes are reported by
	git log -p -w --ignore-blank-lines --patience

Change-Id: I6be44efd5189b671caabcf6753bb82ef44521440
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9034
Tested-by: jenkins
2025-09-06 08:29:38 +00:00
Antonio Borneo
ac527e7372 flash: nor: prepare for aligning switch and case statements
To prepare for aligning switch and case statements, fix in advance
some checkpatch error due to existing code:
- remove useless parenthesis;
- uniform braces around if/else statements,
- add space around operators.

While there:
- put the 'default' case as last in the list;
- convert format strings to drop cast.

Change-Id: I335b200add75b95bf1e908af39e957b61b617e22
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9033
Tested-by: jenkins
2025-09-06 08:29:13 +00:00
Antonio Borneo
f711ccfd7a flash: nand: align switch and case statements
The coding style requires the 'case' to be at the same indentation
level of its 'switch' statement.

Align the code accordingly.

No changes are reported by
	git log -p -w --ignore-blank-lines --patience

Change-Id: I9689e5b4650b8301d1b81e384e4db41b4efc3993
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9032
Tested-by: jenkins
2025-09-06 08:28:56 +00:00
Antonio Borneo
1042a8d179 flash: nand: prepare for aligning switch and case statements
To prepare for aligning switch and case statements, fix in advance
some checkpatch error due to existing code:
- remove useless parenthesis;
- don't end line with an open parenthesis;
- expand multiple assignments.

While there, put the 'default' case as last in the list.

Change-Id: I17bf5e88b145ef9b5b188424182f4e54b818eeae
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9011
Tested-by: jenkins
2025-09-06 08:28:40 +00:00
Antonio Borneo
d123cfdc58 helper: align switch and case statements
The coding style requires the 'case' to be at the same indentation
level of its 'switch' statement.

Align the code accordingly.

No changes are reported by
	git log -p -w --ignore-blank-lines --patience

Change-Id: Iea3b60b3f01afbe31c495e8ea4ddc2b4c8efa936
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9010
Tested-by: jenkins
2025-09-06 08:28:20 +00:00
Antonio Borneo
d10c839596 openocd: align switch and case statements
The coding style requires the 'case' to be at the same indentation
level of its 'switch' statement.

Align the code accordingly.

No changes are reported by
	git log -p -w --ignore-blank-lines --patience

Change-Id: I2a4c33f12506e898e1efbbfd711cc5834d81dda1
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9009
Tested-by: jenkins
2025-09-06 08:28:00 +00:00
Antonio Borneo
db79156fd5 doc: drop incorrect lack of namespaces in Jim Tcl
Since 2011 [1], Jim Tcl supports namespaces as an optional package
that is compiled-in by default.

Drop the incorrect sentence in OpenOCD documentation that reports
namespaces as not supported by Jim Tcl. It was true in 2008 when
the sentence was added with [2].
The meaning of the paragraph in the documentation does not change.

Change-Id: I30b422e369d106e70f5e1e20b21f0b6ea0fe6b8d
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Link: https://github.com/msteveb/jimtcl/commit/7f383c6726fd [1]
Fixes: a28eaa85f ("jtag newtap change & huge manual update") [2]
Reviewed-on: https://review.openocd.org/c/openocd/+/9093
Tested-by: jenkins
2025-09-06 08:25:11 +00:00
Antonio Borneo
a68856102f openocd: remove further obsolete hooks for building on eCos
The eCos build has been dropped in 2012 with commit 39650e2273
("ecosboard: delete bit-rotted eCos code").

Drop last eCos related code.

Change-Id: I6b0de6386386c0102d540504236dda58d7a664b9
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9092
Tested-by: jenkins
2025-09-06 08:24:51 +00:00
Marc Schink
20ca4f4bee flash/nor/stm32l4x: Change 'option_read' output
Remove the verbose command output to enable processing with Tcl.

Change-Id: I97c2ffbd7bbbb3064a98f8977373f6c48272e71e
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/9000
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2025-09-06 08:21:49 +00:00
Daniel Anselmi
9a5212560b tcl/board: Add digilent Zybo Zynq-7000 board
Add configuration for digilents Zybo Z7 board.
Documentation:
https://digilent.com/reference/programmable-logic/zybo-z7/start

Change-Id: I4b607e60f2bf531ee8f96739deb737376248fb8b
Signed-off-by: Daniel Anselmi <danselmi@gmx.ch>
Reviewed-on: https://review.openocd.org/c/openocd/+/8088
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2025-09-06 08:19:37 +00:00
Marc Schink
7bc74de62d adapter: Rework parallel port driver
Make the driver more flexible and define adapter-specific configurations
in Tcl instead of C using the adapter GPIO subsystem.

The rework also includes coding style fixes and improvements of the
documentation. All modifications are done such that backwards
compatibility is ensured.

Tested with Olimex ARM-JTAG cable [1] and APM32F103 target device on
Linux and FreeBSD. The driver works on Linux using direct I/O and PPDEV.
On FreeBSD, only PPDEV works. The build with direct I/O already failed
before the patch. This problem will be fixed in a subsequent patch.

The patch is not tested on Windows because there is no documentation
for it.

[1] https://www.olimex.com/Products/ARM/JTAG/ARM-JTAG/

Change-Id: Ib671d52a919eaf2959cf6365f2c8004257ae074c
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/8943
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2025-09-06 08:19:09 +00:00
Marc Schink
3bec165e25 adapter: Add 'user0' GPIO signal
Add a user-specific signal 'user0' which can be used for custom
functionality.

For now, only a single user-specific signal is supported. Additional
signals 'userX' or a more generic handling can be added in the future.
Also, the signal state can only be configured during the adapter
initialization and termination. Commands to change the signal state at
run-time may be added in the future.

Change-Id: I3f31242f6a693e11565542c3bd4521a245b4ff95
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/9088
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2025-09-06 08:18:57 +00:00
Marc Schink
d02389bbfa adapter: Add support for 'exit state' of GPIO signal
In addition to a signal's 'init state', add support to configure its
'exit state'. This option determines the state and configuration of a
pin when the adapter terminates its operation.

Change-Id: I0577ed9e3bc79715290b4e6a21e3f64c66f2ff9a
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/9087
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2025-09-06 08:18:41 +00:00
Brian Kuschak
fcff4b712c jtag/drivers/cmsis_dap: add new backend cmsis_dap_tcp
Create a new backend for cmsis_dap driver that allows CMSIS-DAP protocol
to run over TCP/IP instead of USB.

An example implementation of the firmware for an SWD programmer that
uses this cmsis_dap_tcp protocol can be found at the link below.
https://github.com/bkuschak/cmsis_dap_tcp_esp32

Using this cmsis_dap_tcp backend with the firmware above on an ESP32-C6
programmer and STM32F401RE target shows the following performance:
- loading 96KB image to RAM: 80 KB/sec
- dumping 96KB image from RAM: 72 KB/sec
- flashing 512KB image completes in about 13.5 seconds (including erase,
  program, and verify).

Change-Id: I6e3e45016bd16ef2259561b1046788f5536b0687
Signed-off-by: Brian Kuschak <bkuschak@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8973
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2025-09-01 07:46:39 +00:00
HAOUES Ahmed
64ed1c74d5 flash/stm32l4x: Support STM32U37/U38x devices
STM32U37/U38x devices have 1Mb flash (split into pages of 4 Kb)

Note: add wait for the BSY bit to be cleared in FLASH_SR

Change-Id: I8208aa81951b9e2f7b0a6bbfce3f7c8ad0f78ade
Signed-off-by: HAOUES Ahmed <ahmed.haoues@st.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8874
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2025-09-01 07:43:30 +00:00
Michal Lenc
61d1d13a02 doc/openocd.texi: add entry describing atsamv user signature area
Adds documentation entry for newly added possibility to program
ATSAMV family embedded flash signature area page.

Change-Id: I3bbaba304868dca49d6dd7006276d2d3a95facad
Signed-off-by: Michal Lenc <michallenc@seznam.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/9096
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Tested-by: jenkins
2025-08-29 12:08:20 +00:00
Tomas Vanek
fcbe243c0b flash/nor/atsamv: reduce flash driver verbosity
Remove useless LOG_INFO in samv_flash_bank_command().
Change LOG_INFO to LOG_DEBUG in samv_erase().

Change-Id: I46923ea4f020197ba902b1a7226cc8ee91831a5a
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/9061
Reviewed-by: zapb <dev@zapb.de>
Reviewed-by: Michal Lenc <michallenc@seznam.cz>
Tested-by: jenkins
2025-08-29 12:07:44 +00:00
Tomas Vanek
0819c3939f tcl/target/atsamv: disable watchdog in reset-init event
Prevent disrupting of 'flash erase_check' or 'flash verify_image'
running longer than 16 seconds.

Change-Id: I545a1155ac0d237c49f2f3a27235d8a67df2a61b
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/9060
Tested-by: jenkins
Reviewed-by: Michal Lenc <michallenc@seznam.cz>
2025-08-29 12:07:32 +00:00
Michal Lenc
5d333337b6 atsamv: add support for user signature partition write
Embedded flash also has a user signature area. This is a 512
bytes large page whose data are not erased by asserting ERASE pin or by
software ERASE command. It may be used to store configuration, keys,
trimming values etc.

This commit adds option to access this area from OpenOCD.

Change-Id: If870aa85938b9cccd94f958dd1f3d93dbdf779f0
Signed-off-by: Michal Lenc <michallenc@seznam.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/8302
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2025-08-29 12:07:04 +00:00
Antonio Borneo
e971d677c0 drivers ch347: drop useless initialization
Drop some useless initialization in the driver.
Replace a constant value returned through a variable with the
value itself.

Change-Id: I7b7c0b30c6d36e9763ff78bf826742792546fa7f
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9095
Tested-by: jenkins
Reviewed-by: Matthias Jentsch <info@easydevkits.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2025-08-27 14:36:55 +00:00
Antonio Borneo
96c219a408 drivers: ch347: fix scan-build warnings
The newly merged driver ch347 triggers two new scan-build warnings
about dead assignment to variables.

Fix them.

Change-Id: Ided14272c3573be1498584e68ac4653cde029f31
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Fixes: 7d0e125896 ("jtag/drivers: Add support for CH347-based JTAG adapters")
Reviewed-on: https://review.openocd.org/c/openocd/+/9094
Tested-by: jenkins
Reviewed-by: Matthias Jentsch <info@easydevkits.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2025-08-27 14:36:44 +00:00
Daniel Anselmi
56d67dac2e flash/nor/max32: fix: call to calloc
With gcc 15.2.1 we get the following error:
'calloc' sizes specified with 'sizeof' in the earlier argument and
not in the later argument.

Change-Id: Ib34d758bc09d34d86d29dd02ea9c7f05b1e83327
Signed-off-by: Daniel Anselmi <danselmi@gmx.ch>
Reviewed-on: https://review.openocd.org/c/openocd/+/9014
Reviewed-by: zapb <dev@zapb.de>
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2025-08-24 11:19:52 +00:00
Marc Schink
f381945567 tcl/file_renaming: Remove simple renames
The target configuration entries are simple renames and are handled
automatically.

Change-Id: Icae6b9b0f20b3c31df2900119f9ed2dadb2b768a
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/9085
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2025-08-24 11:18:47 +00:00
Marc Schink
65b886812b tcl/board: Move SiFive configs into vendor directory
Move the configuration files into a dedicated vendor folder as required
by the developer guidelines.

Change-Id: I5bf048f2d8d0fccbcfe40e0a0e7b30dfbab192d1
Signed-off-by: Marc Schink <dev@zapb.de>
Reviewed-on: https://review.openocd.org/c/openocd/+/9082
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2025-08-24 11:18:38 +00:00
Parshintsev Anatoly
23ab2062e7 server: global state updated by signal handlers should have a volatile sig_atomic_t type
Signal handlers currently violate both C language and POSIX requirements:
1. To avoid undefined behavior (UB), variables accessed or modified by
   signal handlers be of atomic lock-free type.
2. The respected variables should be marked as volatile.
3. Signal handlers may only call a very limited subset of standard
   library functions.
4. Additionally, POSIX restricts signal handlers to signal-safe
   functions.

This patch addresses the first two issues by changing the type of global
variables that are accessed inside signal handler to `sig_atomic_t` and
adding `volatile` qualifiers.

Items 3 and 4 must be handled separately but are outside the scope of
this change.

Change-Id: I9c344e87bab9eefe7d99b0aad300a3ef4712df51
Signed-off-by: Parshintsev Anatoly <anatoly.parshintsev@syntacore.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8927
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-by: Chris Head <chead@zaber.com>
2025-08-24 11:18:04 +00:00
Ashi Gupta
4e493229c6 tcl/target: Added target configuration for Qualcomm QCS6490 IOT
Processors.

QCS6490 and QCM6490 are 6nm processors designed for enterprise and IOT
applications featuring global 5G and Wi-Fi 6E support with similar
architecture.

This configuration file will allow debugging applications on these
processors.

Verified with Olimex(ARM-USB-OCD-H):
openocd -f tcl/interface/ftdi/olimex-arm-usb-ocd-h.cfg 
-c 'transport select jtag' 
-f <path_to_qcs6490_cfg>

and Jlink:
openocd -f tcl/interface/jlink.cfg 
-c 'transport select jtag' 
-f <path_to_qcs6490_cfg>

Change-Id: I05e923293134eaa9b70d3cf0d18efac9a024b6c7
Signed-off-by: Ashi Gupta <quic_ashig@quicinc.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8615
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
2025-08-24 11:17:19 +00:00
Marek Vrbka
160e2343bd replacements: make socket_select() work on Windows if no sockets are provided
On Windows 11, if select() is called with empty sets, it fails and
returns WSAINVAL. On POSIX this works fine.

This patch addresses it by detecting this case in OpenOCD replacements
and returning 0 in these cases.

This fixes OpenOCD crash on Windows if no services are enabled
(gdb server, tcl server and telnet server all disabled).

Change-Id: I601878671caf4ae44e105d6a819251d2d96c607c
Signed-off-by: Marek Vrbka <marek.vrbka@codasip.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9081
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2025-08-24 11:16:42 +00:00
Andreas Dannenberg
7e403d9d3b tcl/target: add Rockchip RK3588 target
The Rockchip RK3588 SoC is used in systems such as the GenBook RK3588
open-hardware laptop and the Coolpi CM5 compute module. This patch adds
support for debugging those. Tested using the ST-LINK/V2 debug adapter
in SWD mode connected to the SDMMC_D2 (SWCLK) and SDMMC_D3 (SWDIO) pins
on the 50-pin J17 connector inside the GenBook RK3588 laptop.

Change-Id: Ia5da403054b6c9aa41184a4e092a74aa882a267d
Signed-off-by: Andreas Dannenberg <andre@miauco.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9013
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2025-08-24 11:16:01 +00:00
Antonio Borneo
93f16eed4d command: fix OpenOCD commands return value for next jimtcl
JimTcl has been so far quite comfortable with new commands that
return error codes not supported by JimTcl itself.
This has been exploited by OpenOCD, allowing the OpenOCD commands
to return OpenOCD error codes mixed with JimTcl error code.

With the change [1] merged in JimTcl branch 'master' for 0.84, any
negative value returned by a command gets interpreted as a syntax
error detected at runtime by the command itself; JimTcl dumps the
correct syntax and returns a valid JimTcl error code that replaces
the negative value.
Since all OpenOCD error codes are negative values, they are all
taken as syntax errors by the new JimTcl. E.g.:
	openocd -c exit
dumps
	wrong # args: should be "exit ..."

Actually OpenOCD does not need the OpenOCD error code from the
commands, with the exception of the codes:
[a] ERROR_COMMAND_SYNTAX_ERROR, used internally by the command
    dispatcher, before returning to JimTcl;
[b] ERROR_COMMAND_CLOSE_CONNECTION, to alert the telnet server
    that the current connection should be closed.

With [a] already used internally, only [b] needs to be propagated
through JimTcl and back to the OpenOCD caller.

Map the OpenOCD error code ERROR_COMMAND_CLOSE_CONNECTION to the
existing JimTcl error code JIM_EXIT, originally used only by
JimTcl 'exit' command.

Detect JIM_EXIT in command_run_line() and return to the caller the
original ERROR_COMMAND_CLOSE_CONNECTION.

Let exec_command(), and also its caller jim_command_dispatch(),
to only return JimTcl error codes. Rename it to report the change.

Modify the test suite as now a syntax error does not returns -601
anymore.

While there, drop the association key "retval" as it's not used.

Note: after this change there is no real need to replace the
JimTcl command 'exit' with the OpenOCD version as both produce the
same result. But I prefer keeping the code as is to mask any
future change in the related JimTcl code.

Link: https://github.com/msteveb/jimtcl/commit/5669e84aad22 [1]
Change-Id: Ibd7aaeccdf4d7c9efe72aa71909aef83be5ecd27
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reported-by: Andrzej Sierżęga <asier70@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9084
Tested-by: jenkins
2025-08-24 11:15:31 +00:00
Antonio Borneo
7effc6f825 helper: command: inline command_retval_set()
Inline the function command_retval_set(), called only once.
No functional changes.

Change-Id: I4478002adf92c2328e4879019020de5d1dfe89c8
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9083
Tested-by: jenkins
2025-08-24 11:15:21 +00:00
Antonio Borneo
fe0080478b jimtcl: fix build with jimtcl master branch
Current jimtcl release 0.83 has been tagged on 2024-08-28 and the
new 0.84 is on the way.

The change [1] merged in jimtcl branch 'master' for 0.84 breaks
the build of OpenOCD.
OpenOCD releases are not frequent and jimtcl is now by default an
external build dependency. The release of jimtcl 0.84 could force
OpenOCD to deliver a fix release to support it.

Anticipate the change [1] by detecting it at compile time, without
relying on jimtcl version, and providing an alternative code.

Link: https://github.com/msteveb/jimtcl/commit/5669e84aad22 [1]
Change-Id: I61bf100d447083258aea222aaf15608b7cbe2e57
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8956
Tested-by: jenkins
Reviewed-by: Andrzej Sierżęga <asier70@gmail.com>
2025-08-24 11:15:07 +00:00
Antonio Borneo
443139db00 jtag: keep the list of drivers in alphabetic order
The introduction of the driver ch347 breaks the order.
Fix it.

Change-Id: I868fd3ec0b6694fb4bb7b28db0083ab1a9409b1c
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/9089
Reviewed-by: Matthias Jentsch <info@easydevkits.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-by: ZhiYuanNJ <871238103@qq.com>
Tested-by: jenkins
2025-08-24 05:05:05 +00:00
Tomas Vanek
1879145bff drivers/ch347: limit SWD packet size by processing time
CH347 chip firmware probably does not service USB poll/requests
from the host during processing of SWD packet. If the processing
takes longer than approx 8 ms, USB host disconnects the adapter
from the bus as if it were dead.

To avoid disconnect, compute approximate processing time
of SWD transactions and flush the queue if the total time
gets over the limit (use 7 ms to keep some safety margin).

Allow ch347_swd_send_idle() to split the requested delay
to more partial sequences. It prevents USB disconnect at beginning
of target examine, when memaccess 255 clk is used.
Also memaccess > 255 clk is now possible.

Set the maximal divisor to fit the longest ADI sequence
into 7 ms processing time.

Tested on a linux x64 PC and RPi 5.

Change-Id: Ibdcff4de52e3eb4d86ed83af81a1c64f1f9b5d24
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/8746
Tested-by: jenkins
Reviewed-by: ZhiYuanNJ <871238103@qq.com>
2025-08-24 05:04:50 +00:00
Tomas Vanek
b4a1976886 drivers/ch347: fix SWD log messages
Remove annoying and not too informative error message `ack != SWD_ACK_OK`.
Fix copy&paste error in message `SWD Read data parity mismatch` logged
in case of a write returning bad ack.
Raise log level of read/write descriptive message to DEBUG when reg
read/writes returns bad ack.

Change-Id: Ic3433ae8bd02472756adf269658bfba0ba34dc26
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/8747
Reviewed-by: ZhiYuanNJ <871238103@qq.com>
Tested-by: jenkins
2025-08-24 05:04:30 +00:00
Tomas Vanek
fe50eceaff drivers/ch347: don't loose swd_read/write_reg errors
SWD read_reg() and write_reg() methods are declared with
void return. Save the error code to ch347_swd_context.queued_retval
(will be returned later by SWD run method) instead of ignoring it.

Change-Id: Ib95a1bc3398712ac2f8520c79d281633d75f0335
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/8745
Reviewed-by: ZhiYuanNJ <871238103@qq.com>
Tested-by: jenkins
2025-08-24 05:04:14 +00:00
Tomas Vanek
0c575ced95 drivers/ch347: fix conditional sending of idle clock cycles
ch347_swd_run_queue() fulfilled ADI requirement for idle cycles
after the last transaction just if there was room in the buffer.
A lazy programmer avoided this way the danger of recurrent call.

Introduce ch347_swd_run_queue_inner() without sending idle cycles.
They are useless when flushing the queue to get room for the next
transaction.

ch347_swd_run_queue() now can make room for idle cycles
in the queue without recursion.

While on it remove two useless debug logs showing ap_delay_clk
value and prevent the overflow of ap_delay_clk forcing it to be <= 255.

Change-Id: Ia7b7f0d373ff463e2f0742bdd068c3833c57f340
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/8744
Reviewed-by: ZhiYuanNJ <871238103@qq.com>
Tested-by: jenkins
2025-08-24 05:03:55 +00:00
Tomas Vanek
87f7828679 drivers/ch347: add SWD speed settings
SWD has completely different speed setting than JTAG.
There is no official chip documentation. The trial and error
method on SWD init USB packet discovered a byte parameter used
as a divisor from 1 MHz maximal clock.

Prevent setting too low clocks as it may trigger USB disconnects.

CH347T/F versions 5.44/1.1 add 5 MHz SWD speed at divisor/index 0.

CH347F related parts co-authored by ZhiYuanNJ <871238103@qq.com>

Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Change-Id: I5a990a43dcd7a6d73c71b795283a9fbdff489bf4
Reviewed-on: https://review.openocd.org/c/openocd/+/8743
Reviewed-by: ZhiYuanNJ <871238103@qq.com>
Tested-by: jenkins
2025-08-24 05:03:34 +00:00
Tomas Vanek
c7aaaac809 drivers/ch347: detailed packet logging
Split USB data packet logs by CH347 protocol commands

Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Change-Id: I0f61529755f007ab13f42643676199790c5be2d4
Reviewed-on: https://review.openocd.org/c/openocd/+/8742
Reviewed-by: ZhiYuanNJ <871238103@qq.com>
Tested-by: jenkins
2025-08-24 05:03:20 +00:00
Tomas Vanek
99cb670bec drivers/ch347, doc: warn about CH347T problems
Also suggest a possible solution if available.

CH347F related parts co-authored by ZhiYuanNJ <871238103@qq.com>

Change-Id: Id6557909fcb56a1e95e16277c1cd7df6769cf4dd
Signed-off-by: Tomas Vanek <vanekt@fbl.cz>
Reviewed-on: https://review.openocd.org/c/openocd/+/8741
Reviewed-by: ZhiYuanNJ <871238103@qq.com>
Tested-by: jenkins
2025-08-24 05:03:02 +00:00
EasyDevKits
7d0e125896 jtag/drivers: Add support for CH347-based JTAG adapters
This adds general support for JTAG adapters based on the WCH CH347T and
CH347F chips.

The CH347T must be configured in mode 3 to provide both UART and JTAG
interfaces. The CH347F exposes UART and JTAG directly. Similar to FTDI
FT2232-based devices, the CH347T/F can be used for simultaneous UART and
JTAG communication.

The ch347 driver code is based on:
  https://github.com/WCHSoftGroup/ch347

Bug fixes and adjustments were made to align the code with OpenOCD style
and ensure compatibility. The driver was integrated into the OpenOCD
build system.

The USB packet format was identified using public GitHub sources and
documented here:
  https://www.easydevkits.com/wch-ch347-jtag-interface/

Change-Id: I5fca9dd015111e4410fea029611fdeedbb228fdb
Signed-off-by: EasyDevKits <info@easydevkits.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/7937
Tested-by: jenkins
Reviewed-by: ZhiYuanNJ <871238103@qq.com>
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2025-08-24 05:02:38 +00:00
Adrien Charruel
68b6d3ad47 jtag/driver/angie: Update Angie probe driver
Update jtag driver code to reflect these changes and properly drive
Angie probe.
The rationale behind this is to increase the probe performances,
especially in use cases when large files shall be loaded on a target.
The USB transfer performances are now close to those obtained with a
standard FTDI probe.

Change-Id: I3b31d75a3f66c2d07fed8c7423f765acc30925f8
Signed-off-by: Adrien Charruel <acharruel@nanoxplore.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8711
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2025-08-17 13:42:45 +00:00
Ahmed BOUDJELIDA
c132aed2a6 contrib/firmware/angie: deactivate srst signal in bitstream
angie probe doesn't use srst pin anymore, it was removed in
latest version.

Change-Id: I6b1439f2328770e5b525c3d129afd08bddf42025
Signed-off-by: Ahmed BOUDJELIDA <aboudjelida@nanoxplore.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8859
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
2025-08-17 13:39:16 +00:00