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 ||
\
53 [string first
$cmd $a] != -1 ||
\
54 [string first
$cmd [lindex $a 1]] != -1} \
57 set cmdname
[lindex $a 0]
61 if {$n > [string length
$h]} {break}
63 set next_a
[expr $n + $w]
64 if {[string length
$h] > $n + $w} \
66 set xxxx
[string range
$h $n [expr $n + $w]]
67 for {set lastpos
[expr [string length
$xxxx] - 1]} \
68 {$lastpos >= 0 && [string compare
\
69 [string range
$xxxx $lastpos $lastpos] " "] != 0} \
70 {set lastpos
[expr $lastpos - 1]} \
75 set next_a
[expr $lastpos + $n + 1]
79 puts [format "%-25s %s" $cmdname \
80 [string range
$h $n [expr $next_a-1]] ]
88 add_help_text help
"Tcl implementation of help command"
91 # If a fn is unknown to Tcl, we try to execute it as an OpenOCD command
93 # We also support two level commands. "flash banks" is translated to
96 # do the name mangling from "flash banks" to "flash_banks"
97 if {[llength $args]>=2} {
98 set cmd_name
"[lindex $args 0]_[lindex $args 1]"
99 if {[catch {info body
$cmd_name}]==0} {
100 # the command exists, try it...
101 return [eval "$cmd_name [lrange $args 2 end]"]
104 # This really is an unknown command.
105 return -code error "Unknown command: $args"
108 proc new_target_name
{ } {
109 return [target number
[expr [target count
] - 1 ]]
112 # Try flipping / and \ to find file if the filename does not
113 # match the precise spelling
114 proc find
{filename} {
115 if {[catch {ocd_find
$filename} t
]==0} {
118 if {[catch {ocd_find
[string map
{\ /} $filename} t
]==0} {
121 if {[catch {ocd_find
[string map
{/ \\} $filename} t
]==0} {
124 # make sure error message matches original input string
125 return -code error "Can't find $filename"
127 add_help_text find
"<file> - print full path to file according to OpenOCD search rules"
130 proc script
{filename} {
131 source [find
$filename]
134 add_help_text script
"<filename> - filename of OpenOCD script (tcl) to run"
136 # Handle GDB 'R' packet. Can be overriden by configuration script,
137 # but it's not something one would expect target scripts to do
139 proc ocd_gdb_restart
{target_id
} {
140 # Fix!!! we're resetting all targets here! Really we should reset only
147 # Temporary migration aid. May be removed starting in January 2011.
148 proc armv4_5 params
{
149 echo
"DEPRECATED! use 'arm $params' not 'armv4_5 $params'"
155 # This reset logic may be overridden by board/target/... scripts as needed
156 # to provide a reset that, if possible, is close to a power-up reset.
158 # Exit requirements include: (a) JTAG must be working, (b) the scan
159 # chain was validated with "jtag arp_init" (or equivalent), (c) nothing
160 # stays in reset. No TAP-specific scans were performed. It's OK if
161 # some targets haven't been reset yet; they may need TAP-specific scans.
163 # The "mode" values include: halt, init, run (from "reset" command);
164 # startup (at OpenOCD server startup, when JTAG may not yet work); and
165 # potentially more (for reset types like cold, warm, etc)
166 proc init_reset
{ mode
} {
171 global in_process_reset
172 set in_process_reset
0
174 # Catch reset recursion
175 proc ocd_process_reset
{ MODE
} {
176 global in_process_reset
177 if {$in_process_reset} {
178 set in_process_reset
0
179 return -code error "'reset' can not be invoked recursively"
182 set in_process_reset
1
183 set success [expr [catch {ocd_process_reset_inner
$MODE} result
]==0]
184 set in_process_reset
0
189 return -code error $result
193 proc ocd_process_reset_inner
{ MODE
} {
194 set targets
[target names
]
196 # If this target must be halted...
198 if { 0 == [string compare
$MODE halt
] } {
201 if { 0 == [string compare
$MODE init
] } {
204 if { 0 == [string compare
$MODE run
] } {
208 return -error "Invalid mode: $MODE, must be one of: halt, init, or run";
211 # Target event handlers *might* change which TAPs are enabled
212 # or disabled, so we fire all of them. But don't issue any
213 # target "arp_*" commands, which may issue JTAG transactions,
214 # unless we know the underlying TAP is active.
216 # NOTE: ARP == "Advanced Reset Process" ... "advanced" is
217 # relative to a previous restrictive scheme
221 $t invoke-event reset-start
224 # Use TRST or TMS/TCK operations to reset all the tap controllers.
225 # TAP reset events get reported; they might enable some taps.
228 # Examine all targets on enabled taps.
230 if {[jtag tapisenabled
[$t cget
-chain-position
]]} {
235 # Assert SRST, and report the pre/post events.
236 # Note: no target sees SRST before "pre" or after "post".
238 $t invoke-event reset-assert-pre
241 # C code needs to know if we expect to 'halt'
242 if {[jtag tapisenabled
[$t cget
-chain-position
]]} {
243 $t arp_reset assert
$halt
247 $t invoke-event reset-assert-post
250 # Now de-assert SRST, and report the pre/post events.
251 # Note: no target sees !SRST before "pre" or after "post".
253 $t invoke-event reset-deassert-pre
256 # Again, de-assert code needs to know if we 'halt'
257 if {[jtag tapisenabled
[$t cget
-chain-position
]]} {
258 $t arp_reset deassert
$halt
262 $t invoke-event reset-deassert-post
265 # Pass 1 - Now wait for any halt (requested as part of reset
266 # assert/deassert) to happen. Ideally it takes effect without
267 # first executing any instructions.
270 if {[jtag tapisenabled
[$t cget
-chain-position
]] == 0} {
274 # Wait upto 1 second for target to halt. Why 1sec? Cause
275 # the JTAG tap reset signal might be hooked to a slow
276 # resistor/capacitor circuit - and it might take a while
279 # Catch, but ignore any errors.
280 catch { $t arp_waitstate halted
1000 }
285 if { 0 != [string compare
$s "halted" ] } {
286 return -error [format "TARGET: %s - Not halted" $t]
291 #Pass 2 - if needed "init"
292 if { 0 == [string compare init
$MODE] } {
294 if {[jtag tapisenabled
[$t cget
-chain-position
]] == 0} {
298 set err
[catch "$t arp_waitstate halted 5000"]
301 $t invoke-event reset-init
307 $t invoke-event reset-end
313 # REVISIT power_restore, power_dropout, srst_deasserted, srst_asserted
314 # are currently neither documented nor supported except on ZY1000.
316 proc power_restore
{} {
317 puts "Sensed power restore."
321 add_help_text power_restore
"Overridable procedure run when power restore is detected. Runs 'reset init' by default."
323 proc power_dropout
{} {
324 puts "Sensed power dropout."
327 proc srst_deasserted
{} {
328 puts "Sensed nSRST deasserted."
331 add_help_text srst_deasserted
"Overridable procedure run when srst deassert is detected. Runs 'reset init' by default."
333 proc srst_asserted
{} {
334 puts "Sensed nSRST asserted."
339 # catch any exceptions, capture output and return output
340 proc capture_catch
{a
} {
348 # Executed during "init". Can be overridden
349 # by board/target/... scripts
351 if {[catch {jtag arp_init
} err
]!=0} {
352 # try resetting additionally
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)