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.

  • Try flashing the bootloader settings after flashing the bootloader and firmware. Otherwise these will get overwritten.

  • Thanks for the idea. I tried that, but no change in behaviour I'm afraid.

  • I have some updated information.

    Within my firmware app I have code that allows the user to switch to DFU mode so that they can upload a new firmware app via BLE DFU. If I go into DFU mode using that method and then run my script to erase all and flash everything it will not launch the app unless I power cycle the board after running my script. Once the board has been powered down and back up I can reflash everything over and over again and it always works.

    So to be clear, here is the sequence:

    1) f/w app running, go into DFU mode (see code below), flash SD/BL/APP (using nrfjprog) => bootloader still running and advertising for DFU

    2) power cycle board => firmware app launches ok

    3) flash SD/BL/APP (using nrfjprog) => firmware app is running

    Can repeat step 3 and always works

    This is what I'm doing within my firmware app to go into DFU mode:

        sd_power_gpregret_clr(0, 0xFF);
        sd_power_gpregret_set(0, 1);
        sd_nvic_SystemReset();
    

    Perhaps there is a better (proper?) way of getting into DFU mode?

  • 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

Related