testing/*.tcl sample & test code
[openocd.git] / src / startup.tcl
1 #
2 # Defines basic Tcl procs that must be there for
3 # OpenOCD to work.
4 #
5 # Embedded into OpenOCD executable
6 #
7
8
9 # Help text list. A list of command + help text pairs.
10 #
11 # Commands can be more than one word and they are stored
12 # as "flash banks" "help text x x x"
13
14 global ocd_helptext
15 set ocd_helptext {}
16
17 proc add_help_text {cmd cmd_help} {
18 global ocd_helptext
19 lappend ocd_helptext [list $cmd $cmd_help]
20 }
21
22 proc get_help_text {} {
23 global ocd_helptext
24 return $ocd_helptext
25 }
26
27 # Production command
28 # FIX!!! need to figure out how to feed back relevant output
29 # from e.g. "flash banks" command...
30 proc board_produce {filename serialnumber} {
31 openocd "reset init"
32 openocd "flash write_image erase $filename [flash] bin"]]
33 openocd "verify_image $filename [flash] bin"]]
34 echo "Successfully ran production procedure"
35 }
36
37 proc board_test {} {
38 echo "Production test not implemented"
39 }
40
41 # Show flash in human readable form
42 # This is an example of a human readable form of a low level fn
43 proc flash_banks_pretty {} {
44 set i 0
45 set result ""
46 foreach {a} [flash_banks] {
47 if {$i > 0} {
48 set result "$result\n"
49 }
50 set result [format "$result#%d: %s at 0x%08x, size 0x%08x, buswidth %d, chipwidth %d" $i [lindex $a 0] [lindex $a 1] [lindex $a 2] [lindex $a 3] [lindex $a 4]]
51 set i [expr $i+1]
52 }
53 return $result
54 }
55
56 # We need to explicitly redirect this to the OpenOCD command
57 # as Tcl defines the exit proc
58 proc exit {} {
59 openocd_throw exit
60 }
61
62 # We have currently converted only "flash banks" to tcl.
63 proc flash args {
64 if {[string compare [lindex $args 0] banks]==0} {
65 return [flash_banks_pretty]
66 }
67 openocd_throw "flash $args"
68 }
69
70 #Print help text for a command. Word wrap
71 #help text that is too wide inside column.
72 proc help {args} {
73 global ocd_helptext
74 set cmd $args
75 foreach a [lsort $ocd_helptext] {
76 if {[string length $cmd]==0||[string first $cmd $a]!=-1||[string first $cmd [lindex $a 1]]!=-1} {
77 set w 50
78 set cmdname [lindex $a 0]
79 set h [lindex $a 1]
80 set n 0
81 while 1 {
82 if {$n > [string length $h]} {break}
83
84 set next_a [expr $n+$w]
85 if {[string length $h]>$n+$w} {
86 set xxxx [string range $h $n [expr $n+$w]]
87 for {set lastpos [expr [string length $xxxx]-1]} {$lastpos>=0&&[string compare [string range $xxxx $lastpos $lastpos] " "]!=0} {set lastpos [expr $lastpos-1]} {
88 }
89 #set next_a -1
90 if {$lastpos!=-1} {
91 set next_a [expr $lastpos+$n+1]
92 }
93 }
94
95
96 puts [format "%-25s %s" $cmdname [string range $h $n [expr $next_a-1]] ]
97 set cmdname ""
98 set n [expr $next_a]
99 }
100 }
101 }
102 }
103
104 add_help_text help "Tcl implementation of help command"
105
106
107 # If a fn is unknown to Tcl, we try to execute it as an OpenOCD command
108 proc unknown {args} {
109 if {[string length $args]>0} {
110 set cmd ""
111 # We need to add back quotes for arguments w/space
112 # for args without space, we can add quotes anyway
113 foreach {a} $args {
114 set cmd "$cmd \"$a\""
115 }
116 openocd_throw $cmd
117 }
118 # openocd_throw outputs while running and also sets the
119 # primary return value to the output of the command
120 #
121 # The primary return value have been set by "openocd" above,
122 # so we need to clear it, lest we print out the output from
123 # the command twice.
124 return ""
125 }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)