Validating bank1 in the application instead of the bootloader

Hello,

We want to flag the bootloader to activate an firmware upgrade that we downloaded and validated in the application code. I am trying to set bank_1.bank_code to NRF_DFU_BANK_VALID_APP, which I think is all that is needed to trigger an activation in the bootloader, but the change is not persisting in the bootloader. Here is what I currently have in the test app:

//System Start
nrf_bootloader_mbr_addrs_populate();
uint8_t ret_code = nrf_dfu_settings_init(false);
s_dfu_settings.bank_1.bank_code = NRF_DFU_BANK_VALID_APP;
ret_code = nrf_dfu_settings_write(NULL);
//System Reboot

I don't think I can call the validation functions directly because we're using QSPI as bank 1, so there is no address to point those functions to. I really want to do all of the validation myself, and then "trick" the bootloader into thinking that everything is good and to proceed with the activation.

Thank you!

-nRF52840

-nRF5 SDK 17.1

-pca10056_s140_ble_debug DFU bootloader

  • Hello,

    To limit the attack surface, we have not given the application access to change the bank codes in the settings page as the bank code states. This is the bootloader's responsibility when it performs the post-validation and activation step using the init command stored by the application in the settings page.

    In general, to have the bootloader activate a FW image downloaded by the app, you need to build the bootloader with NRF_BL_DFU_ALLOW_UPDATE_FROM_APP and have the app update the elements that are not circled around here:

    The problem in your case is that the existing activation routine implemented in the bootloader does not support externally mapped memory, so you will need a custom copy routine to make the bootloader move the image from bank 1 residing in external flash to bank 0. 

    A good place to implement this may be here in the nrf_bootloader.c:nrf_bootloader_init() function: 

    Best regards,

    Vidar

  • Hi Vidar,

    Thank you for the information, that helps.

    I notice that you commented out postvalidate() and suggest copying the image within that if statement. If I do it that way, do I also need to modify the activation function? Currently the image copy happens within the nrf_bootloader_fw_activate() function call chain, so I assume some modification there will be needed.

    Will the activation functions even succeed if the image is not post validated?

    I will give your original suggestions a try and report back. Thanks!

  • Hi,

    My idea was that you could make your own routine adapted to work with external flash and place it before nrf_bootloader_fw_activate() call to bypass the activation logic already implemented in the bootloader. The other option would be to modify the activation functions in nrf_bootloader_fw_activation.c to copy the image from your SPI flash.

Related