X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fhelper%2Fstartup.tcl;h=3eb7419ffc6eb676da884aac9c2f27613db25d92;hb=9655c5b093d459df001d7a11742d9a84183ce1f2;hp=41137f1adb204a46f48afd782b59340c24c19f85;hpb=3a636951eba6d674762f3aa6dfc76c35655ca8a9;p=openocd diff --git a/src/helper/startup.tcl b/src/helper/startup.tcl index 41137f1a..3eb7419f 100644 --- a/src/helper/startup.tcl +++ b/src/helper/startup.tcl @@ -88,9 +88,10 @@ proc unknown {args} { # do the name mangling from "flash banks" to "flash_banks" if {[llength $args]>=2} { set cmd_name "[lindex $args 0]_[lindex $args 1]" - # Fix?? add a check here if this is a command? - # we'll strip away args until we fail anyway... - return [eval "$cmd_name [lrange $args 2 end]"] + if {[catch {info body $cmd_name}]==0} { + # the command exists, try it... + return [eval "$cmd_name [lrange $args 2 end]"] + } } # This really is an unknown command. return -code error "Unknown command: $args" @@ -122,31 +123,40 @@ proc script {filename} { source [find $filename] } -#proc daemon_reset {} { -# puts "Daemon reset is obsolete. Use -c init -c \"reset halt\" at end of openocd command line instead"); -#} - add_help_text script " - filename of OpenOCD script (tcl) to run" # Handle GDB 'R' packet. Can be overriden by configuration script, # but it's not something one would expect target scripts to do # normally -proc ocd_gdb_restart {target_num} { +proc ocd_gdb_restart {target_id} { # Fix!!! we're resetting all targets here! Really we should reset only # one target reset halt } -# If RCLK is not supported, use fallback_speed_khz -proc jtag_rclk {fallback_speed_khz} { - if {[catch {jtag_khz 0}]!=0} { - jtag_khz $fallback_speed_khz +global in_process_reset +set in_process_reset 0 + +# Catch reset recursion +proc ocd_process_reset { MODE } { + global in_process_reset + if {$in_process_reset} { + set in_process_reset 0 + return -code error "'reset' can not be invoked recursively" + } + + set in_process_reset 1 + set success [expr [catch {ocd_process_reset_inner $MODE} result]==0] + set in_process_reset 0 + + if {$success} { + return $result + } else { + return -code error $result } } -add_help_text jtag_rclk "fallback_speed_khz - set JTAG speed to RCLK or use fallback speed" - -proc ocd_process_reset { MODE } { +proc ocd_process_reset_inner { MODE } { # If this target must be halted... set halt -1 @@ -163,6 +173,11 @@ proc ocd_process_reset { MODE } { return -error "Invalid mode: $MODE, must be one of: halt, init, or run"; } + # Target event handlers *might* change which TAPs are enabled + # or disabled, so we fire all of them. But don't issue any + # of the "arp_*" commands, which may issue JTAG transactions, + # unless we know the underlying TAP is active. + foreach t [ target names ] { # New event script. $t invoke-event reset-start @@ -171,16 +186,20 @@ proc ocd_process_reset { MODE } { # Init the tap controller. jtag arp_init-reset - # Examine all targets. + # Examine all targets on enabled taps. foreach t [ target names ] { - $t arp_examine + if {[jtag tapisenabled [$t cget -chain-position]]} { + $t arp_examine + } } # Let the C code know we are asserting reset. foreach t [ target names ] { $t invoke-event reset-assert-pre # C code needs to know if we expect to 'halt' - $t arp_reset assert $halt + if {[jtag tapisenabled [$t cget -chain-position]]} { + $t arp_reset assert $halt + } $t invoke-event reset-assert-post } @@ -188,14 +207,19 @@ proc ocd_process_reset { MODE } { foreach t [ target names ] { $t invoke-event reset-deassert-pre # Again, de-assert code needs to know.. - $t arp_reset deassert $halt + if {[jtag tapisenabled [$t cget -chain-position]]} { + $t arp_reset deassert $halt + } $t invoke-event reset-deassert-post } # Pass 1 - Now try to halt. if { $halt } { foreach t [target names] { - + if {[jtag tapisenabled [$t cget -chain-position]] == 0} { + continue + } + # Wait upto 1 second for target to halt. Why 1sec? Cause # the JTAG tap reset signal might be hooked to a slow # resistor/capacitor circuit - and it might take a while @@ -216,6 +240,10 @@ proc ocd_process_reset { MODE } { #Pass 2 - if needed "init" if { 0 == [string compare init $MODE] } { foreach t [target names] { + if {[jtag tapisenabled [$t cget -chain-position]] == 0} { + continue + } + set err [catch "$t arp_waitstate halted 5000"] # Did it halt? if { $err == 0 } { @@ -244,7 +272,7 @@ add_help_text production " - Runs production procedure. Throws exc proc production_test {} { puts "Imagine nifty test procedure having run to completion here." } -add_help_text production "Runs test procedure. Throws exception if procedure failed. Prints progress messages. Implement in target script." +add_help_text production_test "Runs test procedure. Throws exception if procedure failed. Prints progress messages. Implement in target script." add_help_text cpu " - prints out target options and a comment on CPU which matches name" @@ -303,3 +331,11 @@ add_help_text srst_deasserted "Overridable procedure run when srst deassert is d proc srst_asserted {} { puts "Sensed nSRST asserted." } + +# catch any exceptions, capture output and return output +proc capture_catch {a} { + catch { + capture {uplevel $a} + } result + return $result +}