Customizing the bootloader

By default, to set Kconfig options, the nRF Secure Immutable Bootloader and MCUboot bootloaders use Kconfig project configuration files, usually called prj.conf, located in their source directories:

  • nRF Secure Immutable Bootloader - nrf/samples/bootloader

  • MCUboot - bootloader/mcuboot/boot/zephyr

However, there are other ways to customize your application using Kconfig options:

  • Using custom project configurations - For permanent options.

  • Using Kconfig fragments - For temporary options.

Using custom project configurations

You can also use custom project configuration files to set permanent options for the associated image, specifying them at build time using Image-specific variables.

For example, you can assign custom project configurations for both the bootloaders and a sample application as follows:

west build -b nrf52840dk_nrf52840 zephyr/samples/hello_world -- \
-Db0_CONF_FILE=prj_immutable.conf \
-Dmcuboot_CONF_FILE=prj_upgradable.conf \
-DCONF_FILE=prj_app.conf

In the example above, prj_app.conf includes CONFIG_SECURE_BOOT and CONFIG_BOOTLOADER_MCUBOOT to enable the immutable and upgradable bootloaders by default.

You can use custom project configuration files in combination with temporary configuration options associated with a single build, set using either the command line or Kconfig fragments.

Assigning Kconfig fragments

You can use Kconfig fragments specific to bootloaders to set temporary configuration options for the associated image, specifying them at build time using Image-specific variables.

For example, you can assign the my-custom-fragment.conf fragment to the nRF Secure Immutable Bootloader, which uses the child name of b0, as follows:

west build -b nrf52840dk_nrf52840 zephyr/samples/hello_world -- \
-DCONFIG_SECURE_BOOT=y \
-DCONFIG_BOOTLOADER_MCUBOOT=y \
-Db0_OVERLAY_CONFIG=my-custom-fragment.conf

In the same way, you can replace b0 with mcuboot to apply the my-custom-fragment.conf fragment to the MCUboot image:

west build -b nrf52840dk_nrf52840 zephyr/samples/hello_world -- \
-DCONFIG_SECURE_BOOT=y \
-DCONFIG_BOOTLOADER_MCUBOOT=y \
-Dmcuboot_OVERLAY_CONFIG=my-custom-fragment.conf

You can use this method to apply Kconfig fragments to any child image in the build, as well as to set any Kconfig option that can be set from the command line.

See Image-specific variables for more information about customizing images using this method.