- added svn props for newly added files
[fw/openocd] / 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 # Production command
9 # FIX!!! need to figure out how to feed back relevant output
10 # from e.g. "flash banks" command...
11 proc board_produce {filename serialnumber} {
12         openocd "reset init"
13         openocd "flash write_image erase $filename [flash] bin"]]
14         openocd "verify_image $filename [flash] bin"]]
15         echo "Successfully ran production procedure"
16 }
17
18 proc board_test {} {
19         echo "Production test not implemented"
20 }
21
22 # Show flash in human readable form
23 # This is an example of a human readable form of a low level fn
24 proc flash_banks_pretty {} { 
25         set i 0         
26         set result ""
27         foreach {a} [flash_banks] {
28                 if {$i > 0} {
29                         set result "$result\n"
30                 }
31                 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]]
32                 set i [expr $i+1]       
33         }       
34         return $result
35 }
36
37 # We need to explicitly redirect this to the OpenOCD command
38 # as Tcl defines the exit proc
39 proc exit {} {
40         openocd_throw exit
41 }
42
43 # We have currently converted only "flash banks" to tcl.
44 proc flash args {
45         if {[string compare [lindex $args 0] banks]==0} {
46                 return [flash_banks_pretty]
47         }
48         openocd_throw "flash $args"
49 }
50
51 # If a fn is unknown to Tcl, we try to execute it as an OpenOCD command
52 proc unknown {args} {
53         if {[string length $args]>0} {
54                 set cmd ""
55                 # We need to add back quotes for arguments w/space
56                 # for args without space, we can add quotes anyway
57                 foreach {a} $args {
58                         set cmd "$cmd \"$a\""
59                 }
60                 openocd_throw $cmd
61         }
62         # openocd_throw outputs while running and also sets the
63         # primary return value to the output of the command
64         #
65         # The primary return value have been set by "openocd" above,
66         # so we need to clear it, lest we print out the output from
67         # the command twice.
68         return ""
69 }