aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Vanek <vanekt@fbl.cz>2022-10-02 14:46:11 +0200
committerAntonio Borneo <borneo.antonio@gmail.com>2023-01-28 15:57:24 +0000
commit0b6f53e94cd81ee9c85ddc122004fa403b9cc454 (patch)
tree2ba4c523e1c0422a74dcb7947a8dd9c02e0163f9
parent4423e05d9df8803e2311e70d5a2ffc55a92e5676 (diff)
downloadriscv-openocd-0b6f53e94cd81ee9c85ddc122004fa403b9cc454.zip
riscv-openocd-0b6f53e94cd81ee9c85ddc122004fa403b9cc454.tar.gz
riscv-openocd-0b6f53e94cd81ee9c85ddc122004fa403b9cc454.tar.bz2
tcl/target: add rescue mode to RP2040 config
Integrate a rescue mode inspired by [1]. The current OpenOCD must be restarted before normal work with the RP2040 because the rescue debug port must not be activated (or the target is reset every 'dap init'). To continue without restarting OpenOCD we would need to switch off the configured rescue dap. Change-Id: Ia05b960f06747063550c166e461939d92e232830 Link: [1] https://github.com/raspberrypi/openocd/blob/rp2040/tcl/target/rp2040-rescue.cfg Signed-off-by: Tomas Vanek <vanekt@fbl.cz> Reviewed-on: https://review.openocd.org/c/openocd/+/7327 Reviewed-by: Jonathan Bell <jonathan@raspberrypi.com> Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com> Tested-by: jenkins
-rw-r--r--tcl/target/rp2040.cfg30
1 files changed, 30 insertions, 0 deletions
diff --git a/tcl/target/rp2040.cfg b/tcl/target/rp2040.cfg
index 0593e03..de76b4e 100644
--- a/tcl/target/rp2040.cfg
+++ b/tcl/target/rp2040.cfg
@@ -26,6 +26,13 @@ if { [info exists CPUTAPID] } {
set _CPUTAPID 0x01002927
}
+# Set to '1' to start rescue mode
+if { [info exists RESCUE] } {
+ set _RESCUE $RESCUE
+} else {
+ set _RESCUE 0
+}
+
# Set to '0' or '1' for single core configuration, 'SMP' for -rtos hwthread
# handling of both cores, anything else for isolated debugging of both cores
if { [info exists USE_CORE] } {
@@ -37,6 +44,29 @@ set _BOTH_CORES [expr { $_USE_CORE != 0 && $_USE_CORE != 1 }]
swj_newdap $_CHIPNAME cpu -expected-id $_CPUTAPID
+# The rescue debug port uses the DP CTRL/STAT bit DBGPWRUPREQ to reset the
+# PSM (power on state machine) of the RP2040 with a flag set in the
+# VREG_AND_POR_CHIP_RESET register. Once the reset is released
+# (by clearing the DBGPWRUPREQ flag), the bootrom will run, see this flag,
+# and halt. Allowing the user to load some fresh code, rather than loading
+# the potentially broken code stored in flash
+if { $_RESCUE } {
+ dap create $_CHIPNAME.rescue_dap -chain-position $_CHIPNAME.cpu -dp-id $_CPUTAPID -instance-id 0xf -ignore-syspwrupack
+ init
+
+ # Clear DBGPWRUPREQ
+ $_CHIPNAME.rescue_dap dpreg 0x4 0x00000000
+
+ # Verifying CTRL/STAT is 0
+ set _CTRLSTAT [$_CHIPNAME.rescue_dap dpreg 0x4]
+ if {[expr {$_CTRLSTAT & 0xf0000000}]} {
+ echo "Rescue failed, DP CTRL/STAT readback $_CTRLSTAT"
+ } else {
+ echo "Now restart OpenOCD without RESCUE flag and load code to RP2040"
+ }
+ shutdown
+}
+
# core 0
if { $_USE_CORE != 1 } {
dap create $_CHIPNAME.dap0 -chain-position $_CHIPNAME.cpu -dp-id $_CPUTAPID -instance-id 0