openocd: build: add SPDX tag
[fw/openocd] / src / helper / startup.tcl
1 # SPDX-License-Identifier: GPL-2.0-or-later
2
3 # Defines basic Tcl procs that must exist for OpenOCD scripts to work.
4 #
5 # Embedded into OpenOCD executable
6 #
7
8 # Try flipping / and \ to find file if the filename does not
9 # match the precise spelling
10 proc find {filename} {
11         if {[catch {ocd_find $filename} t]==0} {
12                 return $t
13         }
14         if {[catch {ocd_find [string map {\ /} $filename} t]==0} {
15                 return $t
16         }
17         if {[catch {ocd_find [string map {/ \\} $filename} t]==0} {
18                 return $t
19         }
20         # make sure error message matches original input string
21         return -code error "Can't find $filename"
22 }
23 add_usage_text find "<file>"
24 add_help_text find "print full path to file according to OpenOCD search rules"
25
26 # Find and run a script
27 proc script {filename} {
28         uplevel #0 [list source [find $filename]]
29 }
30 add_help_text script "filename of OpenOCD script (tcl) to run"
31 add_usage_text script "<file>"
32
33 # Run a list of post-init commands
34 # Each command should be added with 'lappend post_init_commands command'
35 lappend _telnet_autocomplete_skip _run_post_init_commands
36 proc _run_post_init_commands {} {
37         if {[info exists ::post_init_commands]} {
38                 foreach cmd $::post_init_commands {
39                         eval $cmd
40                 }
41         }
42 }
43
44 # Run a list of pre-shutdown commands
45 # Each command should be added with 'lappend pre_shutdown_commands command'
46 lappend _telnet_autocomplete_skip _run_pre_shutdown_commands
47 proc _run_pre_shutdown_commands {} {
48         if {[info exists ::pre_shutdown_commands]} {
49                 foreach cmd $::pre_shutdown_commands {
50                         eval $cmd
51                 }
52         }
53 }
54
55 #########