From cc75aa37c5ba6267956a3613069b7d35420b76fc Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Fri, 18 Feb 2022 17:25:58 +0100 Subject: 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 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 Tested-by: jenkins --- src/server/server.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/server') diff --git a/src/server/server.c b/src/server/server.c index dd40804..c7cafb7 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -762,6 +762,8 @@ COMMAND_HANDLER(handle_shutdown_command) shutdown_openocd = SHUTDOWN_REQUESTED; + command_run_line(CMD_CTX, "_run_pre_shutdown_commands"); + if (CMD_ARGC == 1) { if (!strcmp(CMD_ARGV[0], "error")) { shutdown_openocd = SHUTDOWN_WITH_ERROR_CODE; -- cgit v1.1