Migration from NCS v2.1.3 to v2.6.0 with prebuilt B0 binaries

Hello,

We are in the process of migrating from NCS v2.1.3 to NCS v2.6.0.

Since we have many devices fielded already, one of our requirements is to continue using pre-built hex files for NSIB/B0 and mcuboot.
As such, we also have a separate pre-built hex file to provision our public key hashes to the OTP region.

Our pre-built hex files predate the following features of the NSIB introduced in v2.2.0:

  • PRoT lifecycle state
  • Implementation ID

The addition of this new data to the OTP region would not be a problem in itself, but it seems to have also brought a breaking change to the build process.

  • In NCS v2.6.0, provision.hex is always generated and appended to merged.hex even when using CONFIG_B0_BUILD_STRATEGY_USE_HEX_FILE=y.
    • I do not know if this behavior is true for v2.2.0 - v2.5.0; we will not be doing any migrations to those versions.
  • In NCS v2.1.3, provision.hex is not appended to merged.hex when using CONFIG_B0_BUILD_STRATEGY_USE_HEX_FILE=y.

We want to generate one set of binaries without provision.hex, and one set with provision.hex (for the manufacturing process).

When trying to create the latter set, mergehex fails with the following error message:


mergehex -m /path/to/prebuilt/provision.hex build/zephyr/merged.hex -o merged-with-provision.hex
Parsing input files.
Merging file "provision.hex" into output.
Merging file "merged.hex" into output.
Overlapping segments detected at address 16744752.ERROR: The hex files cannot be merged since there are conflicts.
ninja: build stopped: subcommand failed.


It is not possible to use the generated provision.hex even with the same public keys because the offset of data in provision.hex now accounts for PRoT lifecycle state and Implementation ID. Our old, pre-built bootloaders will not have knowledge of this layout change for the bl_storage library.

For now as a workaround I will be stripping the generated provision.hex as a post-build step, but this is very tedious to maintain; what if build output paths/filenames change in the future?

My questions boil down to:

  • Is there a white paper or migration guide detailing how applications with B0 built from NCS <=v2.1.x should proceed? I was surprised to find no migration guide for NCS v2.2.0...
  • Is there a Kconfig option to control this behavior -- that is, to prevent generating & merging provision.hex? I cannot find one documented.

Thank you in advance for your guidance!

Parents
  • Correction: I have stumbled on CONFIG_BOOTLOADER_PROVISION_HEX, but it has no prompt so is not user configurable:

    error: BOOTLOADER_PROVISION_HEX (defined at /opt/ncs2/nrf/subsys/bootloader/Kconfig:34) is assigned
    in a configuration file, but is not directly user-configurable (has no prompt). It gets its value
    indirectly from other symbols. See

    I was able to override the selected value with the following change to my app's Kconfig file and setting CONFIG_BOOTLOADER_PROVISION_HEX=n in prj.conf. It must appear before source $(ZEPHYR_BASE)/Kconfig.zephyr, or else the NCS default will be used first.

    +config BOOTLOADER_PROVISION_HEX
    +    bool "Generate provision.hex for B0"
    +
     menu "Zephyr Kernel"
     source "$ZEPHYR_BASE/Kconfig.zephyr"
     endmenu

    This can be resolved with a conditional prompt for this Kconfig option when B0's build strategy is USE_HEX_FILE. I will be opening a pull request suggesting this change shortly.

Reply
  • Correction: I have stumbled on CONFIG_BOOTLOADER_PROVISION_HEX, but it has no prompt so is not user configurable:

    error: BOOTLOADER_PROVISION_HEX (defined at /opt/ncs2/nrf/subsys/bootloader/Kconfig:34) is assigned
    in a configuration file, but is not directly user-configurable (has no prompt). It gets its value
    indirectly from other symbols. See

    I was able to override the selected value with the following change to my app's Kconfig file and setting CONFIG_BOOTLOADER_PROVISION_HEX=n in prj.conf. It must appear before source $(ZEPHYR_BASE)/Kconfig.zephyr, or else the NCS default will be used first.

    +config BOOTLOADER_PROVISION_HEX
    +    bool "Generate provision.hex for B0"
    +
     menu "Zephyr Kernel"
     source "$ZEPHYR_BASE/Kconfig.zephyr"
     endmenu

    This can be resolved with a conditional prompt for this Kconfig option when B0's build strategy is USE_HEX_FILE. I will be opening a pull request suggesting this change shortly.

Children
  • Hmm, this seems to have the unfortunate side effect of preventing an MCUBoot built from source from being signed.

    This backwards compatibility story is not great. IMO the signing of the MCUBoot image should not be coupled to the generation of provision.hex, especially when there is no way to generate a provision.hex that is compatible with versions that don't have knowledge of the PRoT lifecycle state and implementation ID.

Related