Error on tfm_builtin_key_loader after flash and nrf5340 custom board flashing

Hello, I am developing on a custom board with the nrf5340 and programming through SWD using the nrf5340dk. A few days ago everything was running fine and I was able to continuously test and debug my application code for my board. However, yesterday during mid development, I started receiving these errors:

[error] [ Client] - Encountered error -90: Command read_memory_descriptors executed for 2 milliseconds with result -90
[error] [ Worker] - Can't read memory descriptors, ap-protection is enabled.
[error] [ Client] - Encountered error -90: Command erase_file executed for 123 milliseconds with result -90            
[error] [  nRF53] - Failed while detecting device memory block protection status!
[error] [  nRF53] - Failed while erasing device. -90: Access protection is enabled, can't read block protection state.
[error] [ Worker] - Access protection is enabled, can't read block protection state.
ERROR: The operation attempted is unavailable due to readback protection in
ERROR: your device. Please use --recover to unlock the device.
NOTE: For additional output, try running again with logging enabled (--log).
NOTE: Any generated log error messages will be displayed.
ERROR: runners.nrfjprog: Flashing failed because the target must be recovered.
  To fix, run "west flash --recover" instead.
  Note: your target is an nRF53; all flash memory for both the network and application cores will be erased prior to reflashing.

No matter what I tried, I could not flash my multi-image build as it would always fail when programming the network core. I did a lot of reading on devzone of other tickets with the same problem and tried many things to make it work. I reached a point where i'm able to go through a process in order to successfully flash both cores:

- Open the nrfprogrammer desktop app and erase all to start the chip fresh

- Then I go to the nrf connect terminal and run: nrfjprog --coprocessor CP_APPLICATION --recover. (Note. I also tried using just --recover. It recovers both cores but the error persists when it reaches the network core stage so I only recover the application core and both cores are able to flash)

- After I recover the application core, both cores are able to flash.

There is still a catch though. This process only works when I'm programming using non_secure (nrf5340_cpuapp_ns) . When trying using regular (nrf5340_cpuapp) this does not work at all and it fails when programming the network core no matter what with the same ap protect error.

But even after all this and when both cores are flashed using non secure and the method above, I am unable to debug and my application code does not run any more. Nothing appears on the RTT viewer and when I open debug I get this error with the Trusted Firmware-M:

JLinkGDBServerCLexe: SEGGER J-Link GDB Server V7.94e Command Line Version
JLinkGDBServerCLexe: 
JLinkGDBServerCLexe: JLinkARM.dll V7.94e (DLL compiled Jan 15 2024 15:13:39)
JLinkGDBServerCLexe: 
JLinkGDBServerCLexe: -----GDB Server start settings-----
JLinkGDBServerCLexe: GDBInit file:                  none
JLinkGDBServerCLexe: GDB Server Listening port:     55020
JLinkGDBServerCLexe: SWO raw output listening port: 2332
JLinkGDBServerCLexe: Terminal I/O port:             2333
JLinkGDBServerCLexe: Accept remote connection:      yes
JLinkGDBServerCLexe: Generate logfile:              off
JLinkGDBServerCLexe: Verify download:               off
JLinkGDBServerCLexe: Init regs on start:            off
JLinkGDBServerCLexe: Silent mode:                   on
JLinkGDBServerCLexe: Single run mode:               on
JLinkGDBServerCLexe: Target connection timeout:     0 ms
JLinkGDBServerCLexe: ------J-Link related settings------
JLinkGDBServerCLexe: J-Link Host interface:         USB
JLinkGDBServerCLexe: J-Link script:                 none
JLinkGDBServerCLexe: J-Link settings file:          none
JLinkGDBServerCLexe: ------Target related settings------
JLinkGDBServerCLexe: Target device:                 nRF5340_xxAA_APP
JLinkGDBServerCLexe: Target device parameters:      none
JLinkGDBServerCLexe: Target interface:              SWD
JLinkGDBServerCLexe: Target interface speed:        12000kHz
JLinkGDBServerCLexe: Target endian:                 little
JLinkGDBServerCLexe: 
=thread-group-added,id="i1"
=cmd-param-changed,param="pagination",value="off"
0x000007b6 in tfm_builtin_key_loader_init () at /opt/nordic/ncs/v2.5.0/modules/tee/tf-m/trusted-firmware-m/secure_fw/partitions/crypto/psa_driver_api/tfm_builtin_key_loader.c:325
325	}


Here is an image. Normally. the debug would boot into the application but it stops short here and clicking resume results in an indefinite hang



Please note I was actively developing on this just fine so the issue is not likely to be my custom board. I have tried other solutions such as the external oscillator setup which I had already setup a while ago, I upgraded and downgraded the nrfconnect-command-line tools to multiple different versions and installed and reinstalled everything in the nrfconnect vscode multiple times. I did not modify anything in my board files. They are identical to when I was developing on the custom board with no issues a few days ago. I did not add or remove anything to my application code as well. I am using sys build and I did not modify any of my build config files other these as well. 

Parents Reply Children
  • Hi Amanda, when I program only the application core without the network core with the (nrf5340_cpuapp) build configuration, it flashes just fine. However, the cores become protected once again so I am unable to debug. My application code also does not work (I am able to tell because the board is connected to stepper motor and has a stepper motor driver on the PCB so when the program is functioning properly the stepper is energized with a hum and does not rotate freely. This does not happen in this case)

  • I also recently tried programming an unopened and untouched backup unit of my custom PCB thinking maybe I did something to the board I was currently using. The same ap protect error persists and when I use the method to program with (nrf5340_cpuapp_ns), I get the Trusted-Firmware-M problem. This was leading me to believe maybe there is something wrong with my build and the firmware I’m flashing right?

    However when I disconnect the SWD and program the nrf5340dk with the same firmware as my custom board it programs with zero issues and I am able to debug like normal. No ap protect issues. The firmware I am flashing to the dk is not using the dk board files by the way. It’s using my custom board files so that looks like it’s eliminating the possibility of board file problems.

    So I am quite lost. Please also note I was programming the custom board just fine a few days ago. It did not come out of manufacturing with this issue.

  • Could you check CONFIG_NRF_APPROTECT_USE_UICR got enabled in the .config under build/zephyr and build/hci_ipc/zephyr? 

    I think you could compare the board files of nrf5340dk with your custom board. maybe zephyr.dts and .config under build/zephyr and build/hci_ipc/zephyr might have clues. 

  • Hi Amanda, I fixed the problem by examining the flash sectors and what I was actually flashing. The problem has to do with my sysbuild implementation. Something in this config file is causing the problem:

    sysbuild.cmake:

    #
    # Copyright (c) 2023 Nordic Semiconductor ASA
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    
    # Add net_core project
    ExternalZephyrProject_Add(
        APPLICATION net_core
        SOURCE_DIR ${APP_DIR}/net_core
        BOARD atreides_nrf5340_cpunet
      )
    set_property(GLOBAL APPEND PROPERTY PM_DOMAINS CPUNET)
    set_property(GLOBAL APPEND PROPERTY PM_CPUNET_IMAGES net_core)
    set_property(GLOBAL PROPERTY DOMAIN_APP_CPUNET net_core)
    set(CPUNET_PM_DOMAIN_DYNAMIC_PARTITION net_core CACHE INTERNAL "")
    
    # Add a dependency so that the net_core sample will be built and flashed first
    add_dependencies(base-firmware-V2 net_core)
    # Add dependency so that the net_core image is flashed first.
    sysbuild_add_dependencies(FLASH net_core)


    I just put this file in a different folder and essentially removed it from the build so now I am not independently programming the network core anymore. This issue set me back andI  had to continue working on the actual product code  so I stopped trying to figure out what in this file makes programming go nuclear. If you have any thoughts I'd be glad to know but in essence the issue is "fixed". Thanks

Related