openocd: rewrite command 'version' as COMMAND_HANDLER Trivial change. While there: - add the mandatory 'usage' field; - document the optional parameter 'git'; - reword the documentation. Change-Id: I6be4d4423128fa026a62e2ef355f77b69d50397e Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/7488 Tested-by: jenkins
openocd: revert workarounds for 'expr' syntax change With OpenOCD v0.12.0 released, drop the workarounds for 'expr' syntax change by reverting: - commit 320043c054dc ("openocd: fix for polling during "expr" computation"); - commit c7eaaf620488 ("openocd: prepare for jimtcl 0.81 'expr' syntax change"). Replace the call to target_call_timer_callbacks_now() with call to target_call_timer_callbacks(). Change-Id: Iae5afc50e3f688e11176a52648efc9a6577a9a11 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/7405 Tested-by: jenkins
openocd: fix SPDX tag format for files .c With the old checkpatch we cannot use the correct format for the SPDX tags in the file .c, in fact the C99 comments are not allowed and we had to use the block comment. With the new checkpatch, let's switch to the correct SPDX format. Change created automatically through the command: sed -i \ 's,^/\* *\(SPDX-License-Identifier: .*[^ ]\) *\*/$,// \1,' \ $(find src/ contrib/ -name \*.c) Change-Id: I6da16506baa7af718947562505dd49606d124171 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/7153 Tested-by: jenkins
openocd: prevent target polling during 'init' The command 'init' causes the execution of few lower level commands, e.g. 'target init', and switches from command mode COMMAND_CONFIG to COMMAND_EXEC, with an intermediate switch back to mode COMMAND_CONFIG. A timed target polling can occur during the execution of 'init' and the target's status can trigger the execution of some events. E.g. if a target has been left halted by a previous execution of OpenOCD, the first poll will find the target halted, calling the corresponding 'halted' event. The event handler can use commands that can only be executed in mode COMMAND_EXEC. If the poll happens while OpenOCD is in mode COMMAND_CONFIG, the triggered handler will fail. Prevent the target polling to operate during the execution of the 'init' command. Change-Id: Ia435a5d2039be9b247e2336616dab53ed5d983ac Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/7007 Reviewed-by: Tomas Vanek <vanekt@fbl.cz> Tested-by: jenkins
openocd: src: replace the GPL-2.0-or-later license tag Replace the FSF boilerplate with the SPDX tag. The SPDX tag on files *.c is incorrect, as it should use the C99 single line comment using '//'. But current checkpatch doesn't allow C99 comments, so keep using standard C comments, by now. Change-Id: I30cd66ac7d737f1973c68fdbb841ffcf00e917c4 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/7072 Tested-by: jenkins
openocd: add post-init and pre-shutdown helpers It is a common requirement to automatically execute some command after "init". This can be achieved, either in scripts or through OpenOCD command line, by explicitly calling "init" followed by the commands. But this approach fails if the request for post-init commands is spread across configuration files; only one of the files can split pre-init and post-init status by calling "init". The common workaround is to "rename" the command "init" and replace it with a TCL proc that calls the original "init" and the post-init commands. E.g. in Zephyr script [1]. To simplify and formalize the post-init execution, use a TCL list that contains the list of commands to be executed. Every script can contribute adding new commands, e.g. using "lappend". In the same way, formalize the pre-shutdown execution with a TCL list of user commands to be executed before OpenOCD exit. Document them and add trivial examples. Drop from documentation the suggestion to rename "shutdown". Change-Id: I9464fb40ccede3e7760d425873adca363b49a64f Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Link: [1] https://github.com/zephyrproject-rtos/zephyr/blob/zephyr-v2.7.1/boards/arm/nucleo_h743zi/support/openocd.cfg#L15 Reviewed-on: https://review.openocd.org/c/openocd/+/6851 Reviewed-by: Tomas Vanek <vanekt@fbl.cz> Tested-by: jenkins
log: fix memory leak when log to file is enabled When log to file is enabled, the file is not closed by OpenOCD at exit. This is reported by Valgrind as a memory leak that is still reachable, as the internal buffers of 'FILE *log_output' are freed by the automatic fclose() at exit. Close the log file before exit. Change-Id: Id472c0d04462035254a9b49ecb0a4037263c6f6f Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6789 Tested-by: jenkins
jtag: remove file driver.h The only purpose of include file driver.h was to expose the API to register the adapter's commands. Move the prototype in adapter.h, already used by openocd.c. Change-Id: Ie1090c60ef9e5bac5ea187c87bed6e7b08d9671c Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6645 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
jtag: move prototype of adapter init/quit and speed to adapter.h After moved the code, align the include files. Change-Id: I514a3020648816810d69f76c2ec4f6e52a1c57ab Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6643 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
openocd: prepare for jimtcl 0.81 'expr' syntax change Jimtcl commit 1843b79a03dd ("expr: TIP 526, only support a single arg") drops the support for multi-argument syntax for the TCL command 'expr'. All the scripts distributed with OpenOCD are already compliant with the new syntax. To avoid breaking user script, introduce a replacement for 'expr' command that handles the old syntax while issuing a deprecated warning. This change should be part of OpenOCD v0.12.0, then reverted. Change-Id: Ib08aa8ebcb634c81a3ce9d24fb4938b0418c947c Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/6510 Reviewed-by: Oleksij Rempel <linux@rempel-privat.de> Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com> Tested-by: jenkins
openocd: fix cleanup order: cti before dap cti access is based on dap. During cleanup, drop cti before dropping dap to guarantee that cti can still access its dap. Change-Id: I40c7f67d4d4a32f53802c0ce7668a5321a05893c Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/6414 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
openocd: remove NULL comparisons with checkpatch [2/2] Patch generated automatically through a modified checkpatch that detects the patterns if (NULL == symbol) if (NULL != symbol) and through flags "--types COMPARISON_TO_NULL --fix-inplace". The unmodified checkpatch detects this pattern as Yoda condition, but it's odd fixing it as Yoda condition and then again as NULL comparison. This triggered the modification to the script. Change-Id: I5fe984a85e9c4fc799f049211797aef891ebce18 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/6352 Tested-by: jenkins
openocd: fix simple cases of Yoda condition There are ~900 Yoda conditions to be aligned to the coding style. For recurrent Yoda conditions it's preferable using a trivial script in order to minimize the review effort. E.g. comparison of uppercase macro/enum with lowercase variable: - ...(ERROR_OK == retval)... + ...(retval == ERROR_OK)... Patch generated automatically with the command: sed -i \ 's/(\([A-Z][A-Z0-9_]*\) \([=!]=\) \([a-z][a-z0-9_]*\))/(\3 \2 \1)/g' \ $(find src/ -type f) While there, remove the braces {} around a single statement block to prevent warning from checkpatch. Change-Id: If585b0a4b4578879c87b2dd74d9e0025e275ec6b Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/6354 Tested-by: jenkins Reviewed-by: Xiang W <wxjstz@126.com>
help: re-implement 'help' independent from tree of struct command The current implementation of "help" related commands is tightly connected to the tree of struct command. The TCL commands 'add_usage_text' and 'add_help_text' have to add fake commands in the tree of struct command to handle the help of TCL procs. Move all the help texts in a list accessible from the struct command_context and register the commands through their full name. Keep the list sorted alphabetically by the command name, so the result of commands 'help' and 'usage' will be sorted too. Remove the associated help and usage during commands un-register, but call help_del_all_commands() for the text added through TCL commands 'add_usage_text' and 'add_help_text'. The resulting help and usage output is not changed by this patch (tested on all the help and usage strings in current master branch). Change-Id: Ifd37bb5bd374cba1a22cd7aac208505b4ae1e6fc Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5670 Tested-by: jenkins Reviewed-by: Oleksij Rempel <linux@rempel-privat.de>
ioutil: drop the code, deprecated in v0.10.0 The code for ioutil has been marked as deprecated in release v0.10.0, 4 years ago. Time to drop it! Change-Id: I36dce1669ebe9acada5f9e752835c53e5214e3be Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/6089 Tested-by: jenkins
arm_tpiu_swo: add support for independent TPIU and SWO This is supposed to replace big part of armv7m_trace.[ch], since TPIU is not only the one implemented in Cortex-M3 and M4. Change-Id: I7588d16cbefe9cdb371c52fb0aa5cdfb48518804 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5858 Tested-by: jenkins
Add initial RTT support Real Time Transfer (RTT) is an interface specified by SEGGER based on basic memory reads and writes to transfer data bidirectionally between target and host. Every target that supports so called "background memory access", which means that the target memory can be accessed by the debugger while the target is running, can be used. RTT is especially of interest for targets which do not support Serial Wire Output (SWO) (e.g. ARM Cortex-M0) or where using semihosting is not possible (e.g. real-time applications) [1]. The data transfer is organized in channels where each channel consists of an up- and/or down-channel. See [2] for more details. Channels are exposed via TCP connections. One or more RTT server can be assigned to each channel to make them accessible to an unlimited number of TCP connections. The current implementation does not respect buffer flags which are used to determine what happens when writing to a full buffer. Note that the implementation is designed in a way that the RTT operations can be directly performed by an adapter (e.g. J-Link). [1] https://devzone.nordicsemi.com/tutorials/6/ [2] https://www.segger.com/jlink-rtt.html Change-Id: I8bc8a1b381fb74e08b8752d5cf53804cc573c1e0 Signed-off-by: Marc Schink <dev@zapb.de> Reviewed-on: http://openocd.zylin.com/4055 Tested-by: jenkins Reviewed-by: Tomas Vanek <vanekt@fbl.cz> Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
openocd: convert function setup_command_handler() to static The function setup_command_handler() was used in the eCos build of OpenOCD, thus it was exported and a comment was added to remark it should remain not-static. Unfortunately the comment was missing the relevant information of the special build that requires so. Also unusual is that there is no include file that declares the prototype of the function. The comment above the function was added in two steps, in commit ea3e49f4e22d ("fix embedded builds") and commit fb96b8607a0c ("openocd: setup_command_handler() must not be static"), again without info about the special build. Also the mailing list archive does not report any further detail. The only hint is in the first commit above that also adds a test on BUILD_ECOSBOARD in a #if. Commit 39650e2273bc ("ecosboard: delete bit-rotted eCos code") removes all the eCos code, that effectively includes the both the prototype and the call to the function setup_command_handler(), http://openocd.zylin.com/#/c/503/2/src/ecosboard.c@a1092 but did not reverted the function to static. With all the 'external' uses of this function being dropped, set the function setup_command_handler() to static and remove the obsoleted and misleading comment. Change-Id: I4d6b83dec2a838119821189fc67949bfca070035 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: http://openocd.zylin.com/5902 Tested-by: jenkins Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
openocd: fix issue in WIN32 with TCP adapters Issue: server_quit is called before adapter_quit: In WIN32 only in server_quit we do an WSACleanup, which terminates/closes all active sockets. So if the adapter is TCP based, the adapter.quit handler will fail if it will need to send some commands through TCP. Example: close_socket in jtag_vpi_quit will fail in WIN32 because the socket is already closed and the errno is set as "Bad File Descriptor" To fix that we introduced new functions called server_host_os_entry/quit to manage specific OS setup (hence WSA for sockets in WINDOWS) in order to delay WSACleanup after adapter_quit(). Change-Id: Ie4afacafe123857f6ae300e376bdfcf0d8c027ac Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com> Reviewed-on: http://openocd.zylin.com/5456 Tested-by: jenkins Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
mflash: Remove this broken flash driver This is causing repeated build failures. Its design is so fundamentally broken that if someone actually wants to use it, a full rewrite is the only option. So it's not even worth deprecating in the hope that someone will notice and fix it, just get rid of it. Change-Id: I513069919a3873bd69253110f7fb6f622ee7d061 Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com> Reviewed-on: http://openocd.zylin.com/5243 Tested-by: jenkins Reviewed-by: Jeffrey Booher-Kaeding <Jeff.Booher-Kaeding@arm.com> Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>