nRF53 Custom b0n Build

I am trying to compile a custom bootloader for nRF5340 net core (b0n) that is part of a multi-image build.

I have created two separate applications, one based on b0n (nrf/samples/nrf5340/netboot) and one based on nrf/samples/bluetooth/peripheral_lbs. These both build without issue when used as single image applications and I can debug them (using hello_world on the app core) and they appear to work.

I have tried adding the b0n as a child image of the application by adding the following code to CMakeLists.txt

if (CONFIG_SECURE_BOOT)
  add_child_image(
    NAME b0n
    SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/../boot_stage1
  )
endif()

If I then build the net app, the application builds, but b0n is neither built nor linked.

I have tried adding CONFIG_SECURE_BOOT=y to the prj.conf file. If I have the above CMakeLists.txt change, I get the following compilation error:

=== child image b0n -  begin ===
loading initial cache file C:/Users/anton/src/bootloader-test/netapp/build/b0n/child_image_preload.cmake
CMake Error: The source "C:/Users/anton/src/bootloader-test/boot_stage1/CMakeLists.txt" does not match the source "C:/Users/anton/ncs/v1.9.1/nrf/samples/nrf5340/netboot/CMakeLists.txt" used to generate cache.  Re-run cmake with a different source directory.
CMake Error at C:\Users\anton\ncs\v1.9.1\nrf\cmake\multi_image.cmake:409 (message):
  CMake generation for b0n failed, aborting.  Command: 1
Call Stack (most recent call first):
  C:\Users\anton\ncs\v1.9.1\nrf\cmake\multi_image.cmake:150 (add_child_image_from_source)
  c:\Users\anton\src\bootloader-test\netapp\build\CMakeLists.txt:21 (add_child_image)
This confuses me in the following ways
  • I don't know why the netboot sample should be used to generate the cache.
  • The CMakeLists.txt are identical in both the sample and in my local build.
  • I don't know why they need to match anyway.

What is going wrong here?

p.s. Most of the documnetation about multi-image bootloader builds suggest using CONFIG_B0_BUILD_STRATEGY_FROM_SOURCE=y. There doesn't appear to be an equivalent CONFIG_B0N_BUILD_STRATEGY_FROM_SOURCE.

  • Sigurd,

    Thank you for the fast response. Yes, I understand that it is possible to add another stage of custom bootloader that runs after  after SIBS or mcuboot runs  as long as the signing chain is honored.

    But this does add complexity and code size, and in some designs it is really required to do some custom development in the first stage boot (and there can be only one bootloader) and be as small as possible due to limited memory.

    I have been running  up to nrfconnect 2.3 and haven't toured 2.4 yet, and I missed sysbuild. Taking a quick look at the architecture, it can probably do the kind of things I requested.

    We have  accomplished this in the past  with customized linker scripts and custom makefile targets for 'standalone' or 'composite' images, but sysbuild can probably handle the job.

    I will take a further look.

    Thank you.

  • Quick answer before I am taking the weekend now:

    Joe Kane said:
    Thank you for the fast response. Yes, I understand that it is possible to add another stage of custom bootloader that runs after  after SIBS or mcuboot runs  as long as the signing chain is honored.

    This is not what I mean. I refer to only Custom Bootloader + Applicaton.

    For the case of the nRF5 Bootloader and the nRF52840Dongle, neither NSIB or MCUboot runs on the dongle with the NCS applications here.

  • Sigurd,

    Thank you for quick answer (again!) Please enjoy your weekend.

    I see now. I was still thinking in terms of  the sdk tool kit building (and it only supporting either SIBS or Mcuboot)  But you meant  build separate proprietary bootloader app. separately, and build NRF application with offset from CONFIG_FLASH_LOAD_OFFSET (separately) .

    This would be very similar to our previous process (with offsets tied to linker script and makefile targets (to know which offset to use) .

    And finally maybe we can build either standalone or composite images using sysbuild with sysbuild kconfig options.

  • Joe Kane said:
      But you meant  build separate proprietary bootloader app. separately, and build NRF application with offset from CONFIG_FLASH_LOAD_OFFSET (separately) .

    Correct

    Let me know if you got any further questions.

Related