82959c8a136b418890f3ddbb3cc94eee3d723e71
[openocd.git] / src / flash / startup.tcl
1 # Defines basic Tcl procs for OpenOCD flash module
2
3 #
4 # program utility proc
5 # usage: program filename
6 # optional args: verify, reset and address
7 #
8
9 proc program {filename args} {
10
11 foreach arg $args {
12 if {[string equal $arg "verify"]} {
13 set verify 1
14 } elseif {[string equal $arg "reset"]} {
15 set reset 1
16 } else {
17 set address $arg
18 }
19 }
20
21 # make sure init is called
22 if {[catch {init}] != 0} {
23 echo "** OpenOCD init Failed **"
24 shutdown
25 return
26 }
27
28 # reset target and call any init scripts
29 if {[catch {reset init}] != 0} {
30 echo "** Unable to reset target **"
31 shutdown
32 return
33 }
34
35 # start programming phase
36 echo "** Programming Started **"
37 if {[info exists address]} {
38 set flash_args "$filename $address"
39 } else {
40 set flash_args "$filename"
41 }
42
43 if {[catch {eval flash write_image erase $flash_args}] == 0} {
44 echo "** Programming Finished **"
45 if {[info exists verify]} {
46 # verify phase
47 echo "** Verify Started **"
48 if {[catch {eval verify_image $flash_args}] == 0} {
49 echo "** Verified OK **"
50 } else {
51 echo "** Verify Failed **"
52 }
53 }
54
55 if {[info exists reset]} {
56 # reset target if requested
57 echo "** Resetting Target **"
58 reset run
59 }
60 } else {
61 echo "** Programming Failed **"
62 }
63
64 # shutdown OpenOCD
65 shutdown
66 }
67
68 add_help_text program "write an image to flash, address is only required for binary images. verify, reset are optional"
69 add_usage_text program "<filename> \[address\] \[verify\] \[reset\]"
70
71 # ease migration to updated flash driver
72 proc stm32x args {
73 echo "DEPRECATED! use 'stm32f1x $args' not 'stm32x $args'"
74 eval stm32f1x $args
75 }
76
77 proc stm32f2xxx args {
78 echo "DEPRECATED! use 'stm32f2x $args' not 'stm32f2xxx $args'"
79 eval stm32f2x $args
80 }