This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Unable to get app to run when flashing BL, SD and App via nrfjprog

I am trying to flash a secure DFU bootloader (compiled using my own key), a soft device, and my application using nrfjprog with the intention being to have the application boot when the board is reset. However, it always goes back to the bootloader after the reset.

I'm using SDK 15.3.0 and soft device s140_nrf52_6.1.1_softdevice.hex.

If I use nRF Connect on my phone to download my app it will launch no problem.

I found some articles that said I have to write specific values to 0x3FC00 and 0x3FC04 to fool the bootloader into launching the app but I believe these addresses are not applicable to my setup as I believe the bootloader settings are located at FF000. Is that right?

Here are the commands I'm using to write to the flash, patched together from a bunch of things I have read

nrfjprog --eraseall
nrfutil settings generate --family NRF52840 --application emf_firmware_pca10056_s140.hex  --application-version 1 --bootloader-version 0 --bl-settings-version 2 bootloader_setting.hex
nrfjprog --program s140_nrf52_6.1.1_softdevice.hex -f NRF52
nrfjprog --program bootloader_setting.hex -f NRF52
nrfjprog --program secure_bootloader_ble_s140_pca10056.hex -f NRF52
nrfjprog --program emf_firmware_pca10056_s140.hex -f NRF52
nrfjprog --reset

Can someone please let me know what I'm missing to make this work? I've been trying various things for the last two days.

Thanks.

Parents
  • Hi David, 

    the correct flashing order is 

    nrfjprog --eraseall

    nrfutil settings generate --family NRF52840 --application emf_firmware_pca10056_s140.hex  --application-version 1 --bootloader-version 0 --bl-settings-version 2 bootloader_setting.hex

    nrfjprog --program s140_nrf52_6.1.1_softdevice.hex -f NRF52

    nrfjprog --program secure_bootloader_ble_s140_pca10056.hex -f NRF52

    nrfjprog --program bootloader_setting.hex --sectorerase  -f NRF52

    nrfjprog --program emf_firmware_pca10056_s140.hex -f NRF52

    nrfjprog --reset

    The bootloader settings should set the bank 0 bank code to NRF_DFU_BANK_VALID_APP(0x01) and the bootloader should see this on boot and jump to the application. 

    Can you set a breakpoint in the app_is_valid if statement in dfu_enter_check() in nrf_bootloader.c to see if dfu_enter_check returns false?

    static bool dfu_enter_check(void)
    {
        if (!app_is_valid(crc_on_valid_app_required()))
        {
            NRF_LOG_DEBUG("DFU mode because app is not valid.");
            return true;
        }
        
        .
        .
        .
    }

    Best regards

    Bjørn

  • Thanks Bjørn

    I've changed the order of events in my flashing script to what you suggested, and added the sectorerase option when flashing the bootloader setting, but it still works the same way.

    I can't seem to set a breakpoint in that function, though (using SES). I get the ? in the breakpoint dot. I can set a breakpoint where it is called in nrf_bootloader_init() where it is called, though, but when I single step it does not seem to go into dfu_enter_check(). Very strange.

    Dave

  • Further info.

    I've added some code to turn LEDs on when various events happen. I'm finding that it is getting into this piece of code:

      static bool dfu_enter_check(void)
    {
    .
    .
    .
    if (NRF_BL_DFU_ENTER_METHOD_GPREGRET && (nrf_power_gpregret_get() & BOOTLOADER_DFU_START)) { NRF_LOG_DEBUG("DFU mode requested via GPREGRET."); <<< Gets here

    So it looks like GPREGRET is still set. I set it in my app when I want to go into DFU mode. How is that flag supposed to get cleared?

Reply
  • Further info.

    I've added some code to turn LEDs on when various events happen. I'm finding that it is getting into this piece of code:

      static bool dfu_enter_check(void)
    {
    .
    .
    .
    if (NRF_BL_DFU_ENTER_METHOD_GPREGRET && (nrf_power_gpregret_get() & BOOTLOADER_DFU_START)) { NRF_LOG_DEBUG("DFU mode requested via GPREGRET."); <<< Gets here

    So it looks like GPREGRET is still set. I set it in my app when I want to go into DFU mode. How is that flag supposed to get cleared?

Children
No Data
Related