flash/nor: use command_print() in command "flash banks"
[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, exit and address
7 #
8
9 proc program_error {description exit} {
10 if {$exit == 1} {
11 echo $description
12 shutdown error
13 }
14
15 error $description
16 }
17
18 proc program {filename args} {
19 set exit 0
20
21 foreach arg $args {
22 if {[string equal $arg "verify"]} {
23 set verify 1
24 } elseif {[string equal $arg "reset"]} {
25 set reset 1
26 } elseif {[string equal $arg "exit"]} {
27 set exit 1
28 } else {
29 set address $arg
30 }
31 }
32
33 # make sure init is called
34 if {[catch {init}] != 0} {
35 program_error "** OpenOCD init failed **" 1
36 }
37
38 # reset target and call any init scripts
39 if {[catch {reset init}] != 0} {
40 program_error "** Unable to reset target **" $exit
41 }
42
43 # start programming phase
44 echo "** Programming Started **"
45 set filename \{$filename\}
46 if {[info exists address]} {
47 set flash_args "$filename $address"
48 } else {
49 set flash_args "$filename"
50 }
51
52 if {[catch {eval flash write_image erase $flash_args}] == 0} {
53 echo "** Programming Finished **"
54 if {[info exists verify]} {
55 # verify phase
56 echo "** Verify Started **"
57 if {[catch {eval verify_image $flash_args}] == 0} {
58 echo "** Verified OK **"
59 } else {
60 program_error "** Verify Failed **" $exit
61 }
62 }
63
64 if {[info exists reset]} {
65 # reset target if requested
66 if {$exit == 1} {
67 # also disable target polling, we are shutting down anyway
68 poll off
69 }
70 echo "** Resetting Target **"
71 reset run
72 }
73 } else {
74 program_error "** Programming Failed **" $exit
75 }
76
77 if {$exit == 1} {
78 shutdown
79 }
80 return
81 }
82
83 add_help_text program "write an image to flash, address is only required for binary images. verify, reset, exit are optional"
84 add_usage_text program "<filename> \[address\] \[verify\] \[reset\] \[exit\]"
85
86 # stm32f0x uses the same flash driver as the stm32f1x
87 # this alias enables the use of either name.
88 proc stm32f0x args {
89 eval stm32f1x $args
90 }
91
92 # stm32f3x uses the same flash driver as the stm32f1x
93 # this alias enables the use of either name.
94 proc stm32f3x args {
95 eval stm32f1x $args
96 }
97
98 # stm32f4x uses the same flash driver as the stm32f2x
99 # this alias enables the use of either name.
100 proc stm32f4x args {
101 eval stm32f2x $args
102 }
103
104 # ease migration to updated flash driver
105 proc stm32x args {
106 echo "DEPRECATED! use 'stm32f1x $args' not 'stm32x $args'"
107 eval stm32f1x $args
108 }
109
110 proc stm32f2xxx args {
111 echo "DEPRECATED! use 'stm32f2x $args' not 'stm32f2xxx $args'"
112 eval stm32f2x $args
113 }