2 # Defines basic Tcl procs that must be there for
5 # Embedded into OpenOCD executable
9 # Help text list. A list of command + help text pairs.
11 # Commands can be more than one word and they are stored
12 # as "flash banks" "help text x x x"
17 proc add_help_text {cmd cmd_help} {
19 lappend ocd_helptext [list $cmd $cmd_help]
22 proc get_help_text {} {
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} {
32 openocd "flash write_image erase $filename [flash] bin"]]
33 openocd "verify_image $filename [flash] bin"]]
34 echo "Successfully ran production procedure"
38 echo "Production test not implemented"
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 {} {
46 foreach {a} [flash_banks] {
48 set result "$result\n"
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]]
56 # We need to explicitly redirect this to the OpenOCD command
57 # as Tcl defines the exit proc
62 # We have currently converted only "flash banks" to tcl.
64 if {[string compare [lindex $args 0] banks]==0} {
65 return [flash_banks_pretty]
67 openocd_throw "flash $args"
70 #Print help text for a command. Word wrap
71 #help text that is too wide inside column.
75 foreach a [lsort $ocd_helptext] {
76 if {[string length $cmd]==0||[string first $cmd $a]!=-1||[string first $cmd [lindex $a 1]]!=-1} {
78 set cmdname [lindex $a 0]
82 if {$n > [string length $h]} {break}
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]} {
91 set next_a [expr $lastpos+$n+1]
96 puts [format "%-25s %s" $cmdname [string range $h $n [expr $next_a-1]] ]
104 add_help_text help "Tcl implementation of help command"
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} {
111 # We need to add back quotes for arguments w/space
112 # for args without space, we can add quotes anyway
114 set cmd "$cmd \"$a\""
118 # openocd_throw outputs while running and also sets the
119 # primary return value to the output of the command
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