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