aboutsummaryrefslogtreecommitdiff
path: root/src/helper
diff options
context:
space:
mode:
authorAntonio Borneo <borneo.antonio@gmail.com>2022-02-18 17:25:58 +0100
committerAntonio Borneo <borneo.antonio@gmail.com>2022-05-14 08:58:36 +0000
commitcc75aa37c5ba6267956a3613069b7d35420b76fc (patch)
treee1be729f0cf11a46c66fa0b7185ef1798b92d884 /src/helper
parent99293ebd15bd2980fa4cb9e161f0069092741a55 (diff)
downloadriscv-openocd-cc75aa37c5ba6267956a3613069b7d35420b76fc.zip
riscv-openocd-cc75aa37c5ba6267956a3613069b7d35420b76fc.tar.gz
riscv-openocd-cc75aa37c5ba6267956a3613069b7d35420b76fc.tar.bz2
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
Diffstat (limited to 'src/helper')
-rw-r--r--src/helper/startup.tcl22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/helper/startup.tcl b/src/helper/startup.tcl
index 71f489d..6389262 100644
--- a/src/helper/startup.tcl
+++ b/src/helper/startup.tcl
@@ -28,4 +28,26 @@ proc script {filename} {
add_help_text script "filename of OpenOCD script (tcl) to run"
add_usage_text script "<file>"
+# Run a list of post-init commands
+# Each command should be added with 'lappend post_init_commands command'
+lappend _telnet_autocomplete_skip _run_post_init_commands
+proc _run_post_init_commands {} {
+ if {[info exists ::post_init_commands]} {
+ foreach cmd $::post_init_commands {
+ eval $cmd
+ }
+ }
+}
+
+# Run a list of pre-shutdown commands
+# Each command should be added with 'lappend pre_shutdown_commands command'
+lappend _telnet_autocomplete_skip _run_pre_shutdown_commands
+proc _run_pre_shutdown_commands {} {
+ if {[info exists ::pre_shutdown_commands]} {
+ foreach cmd $::pre_shutdown_commands {
+ eval $cmd
+ }
+ }
+}
+
#########