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

bootloader and external application

In 15.3, there is a new application type valid for DFU, external app.  When loaded through DFU, the program just sits there in bank1, and doesn't get sent anywhere.  I'd like to use this as I assume it is intended, and send the program over to another MCU, which actually is working great.  I've modified the bootloader with code to do so, but I'm stuck at the end - how do I tell the bootloader it is done with the application in bank1?  

I've had to add some code before  nrf_bootloader_init() in main.c, because if there is a valid program in bank0, it will jump to that regardless of if you've got something waiting in bank1. 

 ret_val = nrf_dfu_settings_init(false);
    if (ret_val != NRF_SUCCESS)
    {
        NRF_LOG_INFO("settings init failed");
    }

    NRF_LOG_DEBUG("bank 0 code = %d", s_dfu_settings.bank_0.bank_code);
    NRF_LOG_DEBUG("bank 0 size = %d", s_dfu_settings.bank_0.image_size);
    NRF_LOG_DEBUG("bank 1 code = %d", s_dfu_settings.bank_1.bank_code);
    NRF_LOG_DEBUG("bank 1 size = %d", s_dfu_settings.bank_1.image_size);

    NRF_LOG_FLUSH();

    if (NRF_DFU_BANK_VALID_EXT_APP == s_dfu_settings.bank_1.bank_code) {
       boot_initialize();
       boot_program();
    }
    
    //This function will only return if there is a valid app, otherwise it will go into a DFU loop.l
    ret_val = nrf_bootloader_init(dfu_observer);
    APP_ERROR_CHECK(ret_val)

This works fine, but when I get to the end of the process in boot_program, I try to do this:

//Clear out the setting that says bank 1 has a valid app
// Invalidate bank, marking completion.
nrf_dfu_bank_invalidate(&s_dfu_settings.bank_1);

uint32_t ret_val = nrf_dfu_settings_write_and_backup(NULL);

if (ret_val == NRF_SUCCESS) { NRF_LOG_INFO("BOOT: settings cleaned up and ready."); }

It seems to always fail, as the RTT output shows:

<debug> nrf_dfu_settings: Writing settings...
<debug> nrf_dfu_settings: Erasing old settings at: 0x000FF000
<debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x000FF000, len=1 pages), queue usage: 0
<debug> nrf_dfu_flash: Flash erase failed (0x3): addr=0x000FF000, len=0x1 bytes, pending 0
<debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x000FF000, src=0x2000A314, len=896 bytes), queue usage: 1
<debug> nrf_dfu_flash: Flash write failed (0x3): addr=0x000FF000, len=0x380 bytes, pending 0
<info> nrf_dfu_settings: Backing up settings page to address 0xFE000.
<debug> nrf_dfu_settings: Writing settings...
<debug> nrf_dfu_settings: Erasing old settings at: 0x000FE000
<debug> nrf_dfu_flash: nrf_fstorage_erase(addr=0x0x000FE000, len=1 pages), queue usage: 1
<debug> nrf_dfu_flash: Flash erase failed (0x3): addr=0x000FE000, len=0x1 bytes, pending 0
<debug> nrf_dfu_flash: nrf_fstorage_write(addr=0x000FE000, src=0x2000A694, len=896 bytes), queue usage: 1
<debug> nrf_dfu_flash: Flash write failed (0x3): addr=0x000FE000, len=0x380 bytes, pending 0
<info> app: BOOT: settings cleaned up and ready.

What am I missing here?

Parents
  • Also, I lifted this code mostly from nrf_bootloader_fw_activate().  It looks to me like I'm doing it the same way this function uses the flash calls... the only weird thing I see in the docs is the following line:

    This function relies on accessing MBR commands through supervisor calls. It does not rely on the SoftDevice for flash operations.

    Not sure what this means.  In reading through the code, the stuff in app_activate(), image_copy(), etc seems to use the same stuff I use.  The only difference I see is that image_copy turns on the WDT.  That shouldn't be necessary to write to flash though, right?

Reply
  • Also, I lifted this code mostly from nrf_bootloader_fw_activate().  It looks to me like I'm doing it the same way this function uses the flash calls... the only weird thing I see in the docs is the following line:

    This function relies on accessing MBR commands through supervisor calls. It does not rely on the SoftDevice for flash operations.

    Not sure what this means.  In reading through the code, the stuff in app_activate(), image_copy(), etc seems to use the same stuff I use.  The only difference I see is that image_copy turns on the WDT.  That shouldn't be necessary to write to flash though, right?

Children
No Data
Related