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"
14 proc add_help_text
{cmd cmd_help
} {
16 lappend ocd_helptext
[list $cmd $cmd_help]
19 proc get_help_text
{} {
25 # Show flash in human readable form
26 # This is an example of a human readable form of a low level fn
30 foreach {a
} [ocd_flash_banks
] {
32 set result
"$result\n"
34 set result
[format "$result#%d: %s at 0x%08x, size 0x%08x, buswidth %d, chipwidth %d" $i $a(name
) $a(base
) $a(size
) $a(bus_width
) $a(chip_width
)]
40 # We need to explicitly redirect this to the OpenOCD command
41 # as Tcl defines the exit proc
46 #Print help text for a command. Word wrap
47 #help text that is too wide inside column.
51 foreach a
[lsort $ocd_helptext] {
52 if {[string length
$cmd]==0||
[string first
$cmd $a]!=-1||
[string first
$cmd [lindex $a 1]]!=-1} {
54 set cmdname
[lindex $a 0]
58 if {$n > [string length
$h]} {break}
60 set next_a
[expr $n+$w]
61 if {[string length
$h]>$n+$w} {
62 set xxxx
[string range
$h $n [expr $n+$w]]
63 for {set lastpos
[expr [string length
$xxxx]-1]} {$lastpos>=0&&[string compare
[string range
$xxxx $lastpos $lastpos] " "]!=0} {set lastpos
[expr $lastpos-1]} {
67 set next_a
[expr $lastpos+$n+1]
72 puts [format "%-25s %s" $cmdname [string range
$h $n [expr $next_a-1]] ]
80 add_help_text help
"Tcl implementation of help command"
83 # If a fn is unknown to Tcl, we try to execute it as an OpenOCD command
85 # We also support two level commands. "flash banks" is translated to
88 # do the name mangling from "flash banks" to "flash_banks"
89 if {[llength $args]>=2} {
90 set cmd_name
"[lindex $args 0]_[lindex $args 1]"
91 if {[catch {info body
$cmd_name}]==0} {
92 # the command exists, try it...
93 return [eval "$cmd_name [lrange $args 2 end]"]
96 # This really is an unknown command.
97 return -code error "Unknown command: $args"
100 proc new_target_name
{ } {
101 return [target number
[expr [target count
] - 1 ]]
104 # Try flipping / and \ to find file if the filename does not
105 # match the precise spelling
106 proc find
{filename} {
107 if {[catch {ocd_find
$filename} t
]==0} {
110 if {[catch {ocd_find
[string map
{\ /} $filename} t
]==0} {
113 if {[catch {ocd_find
[string map
{/ \\} $filename} t
]==0} {
116 # make sure error message matches original input string
117 return -code error "Can't find $filename"
119 add_help_text find
"<file> - print full path to file according to OpenOCD search rules"
122 proc script
{filename} {
123 source [find
$filename]
126 add_help_text script
"<filename> - filename of OpenOCD script (tcl) to run"
128 # Handle GDB 'R' packet. Can be overriden by configuration script,
129 # but it's not something one would expect target scripts to do
131 proc ocd_gdb_restart
{target_id
} {
132 # Fix!!! we're resetting all targets here! Really we should reset only
137 global in_process_reset
138 set in_process_reset
0
140 # Catch reset recursion
141 proc ocd_process_reset
{ MODE
} {
142 global in_process_reset
143 if {$in_process_reset} {
144 set in_process_reset
0
145 return -code error "'reset' can not be invoked recursively"
148 set in_process_reset
1
149 set success [expr [catch {ocd_process_reset_inner
$MODE} result
]==0]
150 set in_process_reset
0
155 return -code error $result
159 proc ocd_process_reset_inner
{ MODE
} {
161 # If this target must be halted...
163 if { 0 == [string compare
$MODE halt
] } {
166 if { 0 == [string compare
$MODE init
] } {
169 if { 0 == [string compare
$MODE run
] } {
173 return -error "Invalid mode: $MODE, must be one of: halt, init, or run";
176 # Target event handlers *might* change which TAPs are enabled
177 # or disabled, so we fire all of them. But don't issue any
178 # of the "arp_*" commands, which may issue JTAG transactions,
179 # unless we know the underlying TAP is active.
181 foreach t
[ target names
] {
183 $t invoke-event reset-start
186 # Init the tap controller.
189 # Examine all targets on enabled taps.
190 foreach t
[ target names
] {
191 if {[jtag tapisenabled
[$t cget
-chain-position
]]} {
196 # Let the C code know we are asserting reset.
197 foreach t
[ target names
] {
198 $t invoke-event reset-assert-pre
199 # C code needs to know if we expect to 'halt'
200 if {[jtag tapisenabled
[$t cget
-chain-position
]]} {
201 $t arp_reset assert
$halt
203 $t invoke-event reset-assert-post
206 # Now de-assert reset.
207 foreach t
[ target names
] {
208 $t invoke-event reset-deassert-pre
209 # Again, de-assert code needs to know..
210 if {[jtag tapisenabled
[$t cget
-chain-position
]]} {
211 $t arp_reset deassert
$halt
213 $t invoke-event reset-deassert-post
216 # Pass 1 - Now try to halt.
218 foreach t
[target names
] {
219 if {[jtag tapisenabled
[$t cget
-chain-position
]] == 0} {
223 # Wait upto 1 second for target to halt. Why 1sec? Cause
224 # the JTAG tap reset signal might be hooked to a slow
225 # resistor/capacitor circuit - and it might take a while
228 # Catch, but ignore any errors.
229 catch { $t arp_waitstate halted
1000 }
234 if { 0 != [string compare
$s "halted" ] } {
235 return -error [format "TARGET: %s - Not halted" $t]
240 #Pass 2 - if needed "init"
241 if { 0 == [string compare init
$MODE] } {
242 foreach t
[target names
] {
243 if {[jtag tapisenabled
[$t cget
-chain-position
]] == 0} {
247 set err
[catch "$t arp_waitstate halted 5000"]
250 $t invoke-event reset-init
255 foreach t
[ target names
] {
256 $t invoke-event reset-end
260 # stubs for targets scripts that do not have production procedure
261 proc production_info
{} {
262 return "Imagine an explanation here..."
264 add_help_text production_info
"Displays information on production procedure for target script. Implement this procedure in target script."
266 proc production
{firmwarefile serialnumber
} {
267 puts "Imagine production procedure running successfully. Programmed $firmwarefile with serial number $serialnumber"
270 add_help_text production
"<serialnumber> - Runs production procedure. Throws exception if procedure failed. Prints progress messages. Implement this procedure in the target script."
272 proc production_test
{} {
273 puts "Imagine nifty test procedure having run to completion here."
275 add_help_text production_test
"Runs test procedure. Throws exception if procedure failed. Prints progress messages. Implement in target script."
277 add_help_text cpu
"<name> - prints out target options and a comment on CPU which matches name"
279 # A list of names of CPU and options required
283 options {xscale
-variant IXP42x
}
288 options {arm7tdmi
-variant arm7tdmi
}
289 comment
{vanilla ARM7
}
293 # Invoked from Tcl code
294 proc ocd_cpu
{args
} {
298 foreach a
[lsort $ocd_cpu_list] {
299 if {[string length
$args]==0||
[string first
[string toupper
$name] [string toupper
"$a(name)$a(options)$a(comment)"]]!=-1} {
307 # 0123456789012345678901234567890123456789012345678901234567890123456789
308 puts "CPU Options Comment"
309 foreach a
[lsort [ocd_cpu
$args]] {
310 puts [format "%-20s%-40s%s" $a(name
) $a(options) $a(comment
)]
314 proc power_restore
{} {
315 puts "Sensed power restore."
319 add_help_text power_restore
"Overridable procedure run when power restore is detected. Runs 'reset init' by default."
321 proc power_dropout
{} {
322 puts "Sensed power dropout."
325 proc srst_deasserted
{} {
326 puts "Sensed nSRST deasserted."
329 add_help_text srst_deasserted
"Overridable procedure run when srst deassert is detected. Runs 'reset init' by default."
331 proc srst_asserted
{} {
332 puts "Sensed nSRST asserted."
335 # catch any exceptions, capture output and return output
336 proc capture_catch
{a
} {
Linking to existing account procedure
If you already have an account and want to add another login method
you
MUST first sign in with your existing account and
then change URL to read
https://review.openocd.org/login/?link
to get to this page again but this time it'll work for linking. Thank you.
SSH host keys fingerprints
1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=.. |
|+o.. . |
|*.o . . |
|+B . . . |
|Bo. = o S |
|Oo.+ + = |
|oB=.* = . o |
| =+=.+ + E |
|. .=o . o |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)