This is an automated email from Gerrit.

"Holger Mößinger <[email protected]>" just uploaded a new patch set to 
Gerrit, which you can find at https://review.openocd.org/c/openocd/+/9389

-- gerrit

commit 97db0e2f8fbeeab0d3f73b7e2747e7775c791beb
Author: Holger Mößinger (hm2dev) <[email protected]>
Date:   Fri Jan 16 14:00:22 2026 +0100

    tcl/board/nordic/nrf54l.cfg Add recovery functions
    
    Add nrf54l_check_ap_lock and nrf54l_recover to nrf54l.cfg.
    Successfully tested on nRF54L15 hardware.
    
    These are the changes from change 9268, but for nrf54l only.
    
    Change-Id: I46c2fd544a20cfd2fc88260309a7e8a3924f665a
    Signed-off-by: Holger Mößinger (hm2dev) <[email protected]>

diff --git a/tcl/target/nordic/nrf54l.cfg b/tcl/target/nordic/nrf54l.cfg
index 3e14055f14..c097438034 100644
--- a/tcl/target/nordic/nrf54l.cfg
+++ b/tcl/target/nordic/nrf54l.cfg
@@ -65,3 +65,97 @@ targets $_TARGETNAME
 if {![using_hla]} {
        $_TARGETNAME cortex_m reset_config sysresetreq
 }
+
+if { [using_hla] } {
+       echo ""
+       echo "nRF device has a CTRL-AP dedicated to recover the device from AP 
lock."
+       echo "A high level adapter (like a ST-Link) you are currently using 
cannot access"
+       echo "the CTRL-AP so 'nrfxx_recover' command will not work."
+       echo "Do not enable UICR APPROTECT."
+       echo ""
+} else {
+
+       # Test if debug/MEM-AP is locked by UICR APPROTECT
+       proc nrf54l_check_ap_lock { } {
+
+               set target [target current]
+
+               set dap [$target cget -dap]
+               set err [catch {set APPROTECTSTATUS [$dap apreg 2 0x14]}]
+               if {$err == 0 && $APPROTECTSTATUS > 0} {
+                       echo "Warn :"
+                       echo "Warn : ****** WARNING ******"
+                       echo "Warn : \[$target\] has AP lock engaged (see UICR 
APPROTECT register)."
+                       echo "Warn : Debug access is denied."
+                       echo "Warn : Use 'nrf54l_recover' to erase and unlock 
the device."
+                       echo "Warn : "
+                       poll off
+                       return 1
+               } else {
+                       echo "Info : Debug access on \[$target\] is allowed."
+               }
+               return 0
+       }
+
+       # Mass erase and unlock the device using proprietary nRF CTRL-AP
+       proc nrf54l_recover { } {
+
+               set target [target current]
+               set dap [$target cget -dap]
+
+               set IDR [$dap apreg 2 0xfc]
+               if {$IDR != 0x32880000} {
+                       echo "Error: Cannot access \[$target\] CTRL-AP!"
+                       return
+               }
+
+               poll off
+
+               set APPROTECTSTATUS [$dap apreg 2 0x14]
+               if {$APPROTECTSTATUS == 0x0} {
+                       echo "Info : \[$target\] not locked. Skipping recovery."
+                       return
+               }
+
+               # Trigger the Erase all
+               $dap apreg 2 4 1
+
+               for {set i 0} {1} {incr i} {
+                       set ERASEALLSTATUS [$dap apreg 2 0x8]
+                       if {$ERASEALLSTATUS == 1} {
+                               echo "Info : \[$target\] is erased. Resetting 
to unlock."
+                               break
+                       }
+                       if {$i == 0} {
+                               echo "Info : Waiting up to 5 seconds for 
$target to be erased ..."
+                       }
+                       if {$i >= 50} {
+                               echo "Error: \[$target\] recovery failed."
+                               break
+                       }
+                       sleep 100
+               }
+
+               # Trigger the reset
+               $dap apreg 2 0 2
+
+               # Deassert reset
+               $dap apreg 2 0 0
+
+               sleep 100
+               $target arp_examine
+               poll on
+       }
+       add_help_text nrf54l_recover "Mass erase all device flash and unlock 
nRF54l"
+
+       lappend _telnet_autocomplete_skip nrf54l_check_ap_lock
+}
+
+flash bank $_CHIPNAME.flash nrf54 0x00000000 0 0 0 $_TARGETNAME
+
+if { ![using_hla] } {
+
+       $_TARGETNAME cortex_m reset_config sysresetreq
+       $_TARGETNAME configure -event examine-fail nrf54l_check_ap_lock
+
+}

-- 

Reply via email to