nRF5 SDK v15.0.0
Bootloader

The bootloader module (Bootloader modules) is responsible for:

Each bootloader example provided in this SDK contains one DFU transport.

Bootloader Settings page

A page in non-volatile memory (see Memory layout) is used to keep the bootloader and DFU information. The settings page contains information about:

Firmware activation

Firmware activation is the final step of firmware update process. It is triggered based on the information in the settings page which is read during boot-up. Firmware activation involves copying the new firmware in place of the exitsing one (in case of application dual-bank update Dual-bank and single-bank updates), and updating the settings page to allow the new firmware to boot. The bootloader ensures that copying is power fail safe. In case of updating bootloader, MBR feature is used to perform power fail safe copy (SD_MBR_COMMAND_COPY_BL).

DFU mode

In DFU mode, the bootloader activates DFU transports and the device is ready to receive new firmware. The bootloader enters DFU mode on following conditions.

When DFU mode is entered, the inactivity timer is started. On timer expiration, the bootloader resets. Inactivity timer is restarted on any DFU activity. Inactivity timeout is by default set to NRF_BL_DFU_INACTIVITY_TIMEOUT_MS. If DFU mode is entered after SoftDevice activation, then timeout is set to NRF_BL_DFU_CONTINUATION_TIMEOUT_MS.

Starting the application

Based on information from the settings page, the bootloader determines whether the application exists and where it is located. The bootloader checks the integrity of the application before starting. Optionally, integrity check can be skipped in certain cases to reduce boot-up time (NRF_BL_APP_CRC_CHECK_SKIPPED_ON_GPREGRET2, NRF_BL_APP_CRC_CHECK_SKIPPED_ON_SYSTEMOFF_RESET). If no application is installed, if the integrity check fails, or if there is no settings page, the bootloader enters DFU mode.

Watchdog timer support

The bootloader detects if the watchdog timer (WDT) is active and feeds it to prevent watchdog reset.

Bootloader dependencies

Bootloader modules, except for the transports, do not depend on the SoftDevice. Only the BLE DFU transport (BLE) depends on the SoftDevice.

The bootloader supports the case where SoftDevice is not present in the system at all.

Programming the bootloader

During system startup, the Master Boot Record (MBR) is responsible for starting the bootloader, if a bootloader is installed. To do this, the MBR must know the start address of the bootloader. This start address is defined in UICR.BOOTLOADERADDR, which is located at address 0x10001014 (see NRF_UICR_BOOTLOADER_START_ADDRESS). Therefore, you must set UICR.BOOTLOADERADDR to the correct value when you program the bootloader.

Programming the bootloader requires the following steps:

  1. Erase the device.
  2. Program the SoftDevice. See Programming SoftDevices for instructions.
  3. Compile the bootloader.
  4. Program the bootloader and write to UICR.BOOTLOADERADDR. See the following sections for instructions for Keil, IAR, and nrfjprog directly (if you are using GCC).

Using Keil

You cannot write to UICR.BOOTLOADERADDR when using the default J-Link target driver in Keil. Therefore, you must configure Keil to use an external tool, nrfjprog. To do so, select Project > Options for Target 'xxx' and configure nrfjprog.exe as the tool for flash programming. nrfjprog.exe is installed with the nRF5 MDK and must be in the Windows system path. The following screenshot shows the required settings for nrfjprog.exe:

keil_project_flash_tool_nrf52.png
Flash tool configuration in Keil

After configuring the flash command, program the bootloader as you would do with a normal application. If several J-Link emulators are connected, select the one that contains the nRF5 IC that you want to flash.

Using IAR

You cannot write to UICR.BOOTLOADERADDR when using the default J-Link target driver in IAR. Therefore, you must set up nrfjprog as an external tool. To do so, select Tools > Configure Tools. nrfjprog.exe is installed with the nRF5 MDK and must be in the Windows system path. The following screenshot shows the settings for nrfjprog.exe:

iar_project_flash_tool_nrf52.png
Flash tool configuration in IAR

Change "app.hex" to the file name of your HEX file and the initial directory to the directory that contains the HEX file. After configuring the flash command, program the bootloader as you would do with a normal application. If several J-Link emulators are connected, select the one that contains the nRF5 IC that you want to flash.

Using nrfjprog directly

You can also program the bootloader using nrfjprog directly from the command line. To do so, run the following command:

nrfjprog --reset --program application.hex --family NRF52 --sectoranduicrerase

Change "application.hex" to the file name of your HEX file.

Memory layout

When adding a bootloader to your device, you must be aware of where in the device memory the different firmware components are located.

The following table shows the memory layout for the different chips with current SoftDevices:

Usage Memory range nRF52832 (S132 v6.0.x) Memory range nRF52840 (S140 v6.0.x)
Bootloader settings 0x0007 F000 - 0x0008 0000 (4 kB) 0x000F F000 - 0x0010 0000 (4 kB)
MBR parameter storage 0x0007 E000 - 0x0007 F000 (4 kB) 0x000F E000 - 0x000F F000 (4 kB)
Bootloader 0x0007 8000 - 0x0007 E000 (24 kB) 0x000F 8000 - 0x000F E000 (24 kB)
Application area (incl. free space) 0x0002 0000 - 0x0007 8000 (352 kB) 0x0002 0000 - 0x000F 8000 (864 kB)
SoftDevice 0x0000 1000 - 0x0002 6000 (148 kB) 0x0000 1000 - 0x0002 6000 (148 kB)
Master Boot Record (MBR) 0x0000 0000 - 0x0000 1000 (4 kB) 0x0000 0000 - 0x0000 1000 (4 kB)

The following figure shows the default memory layout for nRF52 devices, where nRF52832 has a flash size of 512 kB and nRF52840 has a flash size of 1024 kB:

bootloader_memory_nrf52.svg

Documentation feedback | Developer Zone | Subscribe | Updated