From 0b6f53e94cd81ee9c85ddc122004fa403b9cc454 Mon Sep 17 00:00:00 2001 From: Tomas Vanek Date: Sun, 2 Oct 2022 14:46:11 +0200 Subject: [PATCH] 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 Reviewed-on: https://review.openocd.org/c/openocd/+/7327 Reviewed-by: Jonathan Bell Reviewed-by: Antonio Borneo Tested-by: jenkins --- tcl/target/rp2040.cfg | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tcl/target/rp2040.cfg b/tcl/target/rp2040.cfg index 0593e03bad..de76b4e29c 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 -- 2.30.2