From 2e062e0dd80a21f4d7372087443ee1be515d8b54 Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Mon, 24 Mar 2025 18:13:43 +0200 Subject: [PATCH] RP2350: Improve config examples for secure/non-secure debug --- tcl/target/rp2350-dbgkey-nonsecure.cfg | 167 ------------------------- tcl/target/rp2350-dbgkey-secure.cfg | 160 ----------------------- tcl/target/rp2350-dbgkey.cfg | 82 ++++++++++++ tcl/target/rp2350-nonsecure.cfg | 16 +++ 4 files changed, 98 insertions(+), 327 deletions(-) delete mode 100644 tcl/target/rp2350-dbgkey-nonsecure.cfg delete mode 100644 tcl/target/rp2350-dbgkey-secure.cfg create mode 100644 tcl/target/rp2350-dbgkey.cfg create mode 100644 tcl/target/rp2350-nonsecure.cfg diff --git a/tcl/target/rp2350-dbgkey-nonsecure.cfg b/tcl/target/rp2350-dbgkey-nonsecure.cfg deleted file mode 100644 index 71bc152a1..000000000 --- a/tcl/target/rp2350-dbgkey-nonsecure.cfg +++ /dev/null @@ -1,167 +0,0 @@ -transport select swd - -source [find target/swj-dp.tcl] - -if { [info exists CHIPNAME] } { - set _CHIPNAME $CHIPNAME -} else { - set _CHIPNAME rp2350 -} - -if { [info exists WORKAREASIZE] } { - set _WORKAREASIZE $WORKAREASIZE -} else { - set _WORKAREASIZE 0x10000 -} - -if { [info exists CPUTAPID] } { - set _CPUTAPID $CPUTAPID -} else { - set _CPUTAPID 0x00040927 -} - -swj_newdap $_CHIPNAME swd -expected-id $_CPUTAPID -dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.swd -adiv6 - -init - -# Check idr -rp2350.dap apreg 0x80000 0xffc - -# reset -rp2350.dap apreg 0x80000 4 0x4 -# key = 0x108544d451c94a684448260128db1b8c -# LSB first -# i.e. c == 1100 -# push is bit 1, data is bit 0 -# so c is 0x2, 0x2, 0x3, 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x3 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 -rp2350.dap apreg 0x80000 4 0x2 - -echo "Now attach a debugger to your RP2350 and load some code" diff --git a/tcl/target/rp2350-dbgkey-secure.cfg b/tcl/target/rp2350-dbgkey-secure.cfg deleted file mode 100644 index a88cacb22..000000000 --- a/tcl/target/rp2350-dbgkey-secure.cfg +++ /dev/null @@ -1,160 +0,0 @@ -transport select swd - -source [find target/swj-dp.tcl] - -if { [info exists CHIPNAME] } { - set _CHIPNAME $CHIPNAME -} else { - set _CHIPNAME rp2350 -} - -if { [info exists WORKAREASIZE] } { - set _WORKAREASIZE $WORKAREASIZE -} else { - set _WORKAREASIZE 0x10000 -} - -if { [info exists CPUTAPID] } { - set _CPUTAPID $CPUTAPID -} else { - set _CPUTAPID 0x00040927 -} - -swj_newdap $_CHIPNAME swd -expected-id $_CPUTAPID -dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.swd -adiv6 - -init - -rp2350.dap apreg 0x80000 0x4 0x4 -# key = 0xa5a5c3c3cdef89ab45670123beefdead -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 -rp2350.dap apreg 0x80000 0x4 0x2 -rp2350.dap apreg 0x80000 0x4 0x3 - - -echo "Now attach a debugger to your RP2350 and load some code" diff --git a/tcl/target/rp2350-dbgkey.cfg b/tcl/target/rp2350-dbgkey.cfg new file mode 100644 index 000000000..e96a1d232 --- /dev/null +++ b/tcl/target/rp2350-dbgkey.cfg @@ -0,0 +1,82 @@ +# Input a debug key to RP2350 to enable access when keys 5 or 6 are +# configured in OTP. + +transport select swd + +source [find target/swj-dp.tcl] + +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + set _CHIPNAME rp2350 +} + +if { [info exists WORKAREASIZE] } { + set _WORKAREASIZE $WORKAREASIZE +} else { + set _WORKAREASIZE 0x10000 +} + +if { [info exists CPUTAPID] } { + set _CPUTAPID $CPUTAPID +} else { + set _CPUTAPID 0x00040927 +} + +if { [info exists DEBUGKEY] } { + set _DEBUGKEY $DEBUGKEY +} else { + echo "RP2350: Using example debug key, set your own with '-c set DEBUGKEY {0x12 0x34 ..}'" + set _DEBUGKEY {0xad 0xde 0xef 0xbe 0x23 0x01 0x67 0x45 0xab 0x89 0xef 0xcd 0xc3 0xc3 0xa5 0xa5} +} + +swj_newdap $_CHIPNAME swd -expected-id $_CPUTAPID +dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.swd -adiv6 + +init + +# Write RP_AP.DBGKEY RESET bit +rp2350.dap apreg 0x80000 0x4 0x4 + +# Write the key bytes bit-by-bit to RP_AP.DBGKEY +proc rp2350_dbgkey_send_bits {byte} { + for {set i 0} {$i < 8} {incr i} { + set mask [expr {1 << $i}] + if {[expr {$byte & $mask}]} { + rp2350.dap apreg 0x80000 0x4 0x3 + } else { + rp2350.dap apreg 0x80000 0x4 0x2 + } + } +} + +foreach _byte $_DEBUGKEY { + rp2350_dbgkey_send_bits $_byte +} + +proc rp2350_dbgkey_print_status {corename cswval} { + # Check CSW SDeviceEn bit + if {[expr {$cswval & 0x800000}]} { + set secdebug "allowed" + } else { + set secdebug "denied" + } + + # Check CSW DeviceEn bit + if {[expr {$cswval & 0x40}]} { + set nsecdebug "allowed" + } else { + set nsecdebug "denied" + } + + puts "Core $corename CSW value: $cswval (secure debug: $secdebug, non-secure debug: $nsecdebug)" +} + +set _CORE0_CSW [rp2350.dap apreg 0x2000 0xd00] +set _CORE1_CSW [rp2350.dap apreg 0x4000 0xd00] + +rp2350_dbgkey_print_status "0" $_CORE0_CSW +rp2350_dbgkey_print_status "1" $_CORE1_CSW + +echo "Now attach a debugger to your RP2350 and load some code" +exit diff --git a/tcl/target/rp2350-nonsecure.cfg b/tcl/target/rp2350-nonsecure.cfg new file mode 100644 index 000000000..bd20582ca --- /dev/null +++ b/tcl/target/rp2350-nonsecure.cfg @@ -0,0 +1,16 @@ +# Configure OpenOCD to perform non-secure bus access. +# By default debugger works in secure bus mode, which won't connect if only +# non-secure debugging is allowed. + +source [find target/rp2350.cfg] + +rp2350.dap.core0 configure -event examine-start { + rp2350.dap apsel 0x2000 + rp2350.dap apcsw 0x43000000 +} + +rp2350.dap.core1 configure -event examine-start { + rp2350.dap apsel 0x4000 + rp2350.dap apcsw 0x43000000 +} +