nRF5 SDK is not maintained anymore
More Info: Consider nRF Connect SDK for new designs

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.

  • Hi

    Some of the concepts in the previous linked example are explained in https://github.com/nrfconnect/sdk-nrf/tree/main/samples/nrf5340/multicore.

    Regards,
    Sigurd Hellesvik

  • Hi

    I have tried to do custom NSIB and b0n in the samples I suggested you, and I have talked with my colleagues about it.

    And I have finally found what I suspect you have tried to tell me all this time: It does not work.

    As far as I can find, CONFIG_SECURE_BOOT is needed for both NSIB and b0n, and if this is set the child images are imported directly from our samples folder.
    And CONFIG_SECURE_BOOT is too interconnected with the nRF Connect SDK for us to disable it without consequences.

    In conclusion, the only way to have custom NSIB/b0n is to fork the nRF Connect SDK, and make changes to our SDK.
    See my earlier comment for an example, and also Adding your own code.

    Thank you for being thorough in getting your point across.
    While this is not the solution you want right now, I hope it will suffice.
    I will ask our developers about this feature, and maybe we can get it in a future version of the nRF Connect SDK.

    Regards,
    Sigurd Hellesvik

  • Thanks for your honesty.

    This project is for a product that needs to be able to recover even under extreme circumstances so custom bootloaders are absolutely necessary. I have worked around the worst of the issues modifying the SDK by adding the following lines to the top of the application root CMakeLists.txt :

    set(CONFIG_B0_CUSTOM_FOLDER "${CMAKE_SOURCE_DIR}/cpuboot")
    set(CONFIG_B0N_CUSTOM_FOLDER "${CMAKE_SOURCE_DIR}/netboot")

    I have then added the custom bootloaders at those subdirectories. I then copied the SDK into a new directory next to the application (so as not to polute the common SDK) and made the following changes to the samples CMakeLists.txt :

    if (CONFIG_SECURE_BOOT)
      if (CONFIG_SOC_NRF5340_CPUNET)
        # Share some information which is used when generating the zip file
        # with the update binaries.
        set_shared(IMAGE net_core PROPERTY SOC ${CONFIG_SOC})
        set_shared(IMAGE net_core PROPERTY VERSION ${CONFIG_FW_INFO_FIRMWARE_VERSION})
        if (DEFINED CONFIG_B0N_CUSTOM_FOLDER)
          add_child_image(
            NAME b0n
            SOURCE_DIR ${CONFIG_B0N_CUSTOM_FOLDER}
            )
        else()
          add_child_image(
            NAME b0n
            SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/nrf5340/netboot
            )
        endif()
      else()
        if (DEFINED CONFIG_B0_CUSTOM_FOLDER)
          add_child_image(
            NAME b0
            SOURCE_DIR ${CONFIG_B0_CUSTOM_FOLDER}
            )
        else()
          add_child_image(
            NAME b0
            SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/bootloader
            )
        endif()
      endif()

    This does get the job done but is still a bit of a hack; so, I am not marking this as an answer until custom bootloaders can be built using the unmodified SDK.

Related