The bootloader for the background DFU must be implemented using Bootloader modules. The main role of the bootloader is to check application integrity and, in case of dual bank updates (see Dual-bank and single-bank updates), to transfer the new image to the active bank. Unlike the BLE Secure DFU Bootloader, the bootloader for background DFU should not initialize any transports. Therefore, DFU is not possible in the bootloader. If a valid application is missing, the bootloader enters an infinite loop.
During system startup, the Master Boot Record (MBR) is responsible for starting the bootloader. MBR may be provided as part of the SoftDevice (if application uses a SoftDevice) or as a stand-alone binary firmware (if application does not use a SoftDevice). To start the bootloader, the MBR must know the start address of the bootloader. This start address is defined in UICR.BOOTLOADERADDR
(see NRF_UICR_BOOTLOADER_START_ADDRESS). Therefore, you must set UICR.BOOTLOADERADDR
to the correct value when you program the bootloader.
By default, the background DFU bootloader will start the application on the device. DFU Swap mode is started if indicated in bootloader settings. The bootloader settings contain a variable that defines if a new valid application, SoftDevice, or bootloader is present in the flash memory.
When implementing a mechanism to perform a Device Firmware Update, be aware where the different firmware components are located in the device memory.
The following figure displays the default memory layout of a 512 kB nRF52 device:
SoftDevices have different sizes. For example, the s1xx-iot-prototype3_nrf52 ends at 0x0001F000. The following table shows the memory layout on a 512 kB nRF52 device with the S132 SoftDevice:
Memory range | Usage |
---|---|
0x0007D000 - 0x00080000 | DFU Bootloader and data |
0x0001F000 - 0x0007D000 | Application code, free/swap, and application data |
0x00003000 - 0x0001F000 | SoftDevice |
0x00000000 - 0x00003000 | Master Boot Record (MBR) |
During system start-up, the Master Boot Record (MBR) will determine the start address of the bootloader by checking the address that is defined at UICR.BOOTLOADERADDR
. For information on how to change the start address of the bootloader, see Programming the bootloader.
The MBR will then initiate the bootloader. During initialization, the bootloader will either enter DFU swap mode to swap the old firmware with the new one or start the application.
Firmware updates can be performed only as a dual-bank update. For more information, see Dual-bank and single-bank updates.
The example project of Bootloader for Background DFU can be found in the following folder: <InstallFolder>/examples/iot/bootloader