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.

Parents
  • Hi Anton

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

    Can you specify which CmakeLists.txt you are referring to here?

    If I then build the net app

    The b0n is usually used alongside the bootloader in the application core. What happens if you build for nrf5340dk_nrf5340_cpuapp instead?

    Regards,
    Sigurd Hellesvik

  • The CMakeLists.txt that I am referring to is the root level CMakeLists.txt for the application on the net core (based on nrf/samples/bluetooth/peripheral_lbs on the net core).

    I think you are mistaken: b0 is the app core bootloader, b0n is the net core bootloader (https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/samples/nrf5340/netboot/README.html). Also, as I have said, I can compile and run b0n on the net core without issue. Also, b0n isn't used alongside the bootloader, it is a bootloader. Did you mean it is often run alongside mcuboot as a set of first and second stage bootloaders?

    Edited: I attempted to build the b0n/app using app core but that failed as it was unable to find "pm_config.h" ... but I don't think that is the correct path to follow anyway.

  • No. This is not what I am looking for. Modifying the SDK in this way is a bad idea for several reasons but most notably:

    • This will break any other project I am working on using the SDK supplanting the standard bootloader with a custom one.
    • If I need to change SDK version it will revert any changes and if this file changes significantly may mean that I cannot replicate this behaviour.
    • The source code for the bootloaders ends up in the SDK instead of a logical place for development/version control etc.

    Also, this doesn't really answer the network core app problem.

  • Hi

    Yea, I agree that it is far from ideal to make changes to the SDK.
    I asked our developers about this, and here is my question and what they had to say:

    "I want to make changes to the b0n child image for my application. So I copy nrf/samples/nrf5340/netboot to somewhere else(ex ~/custom_netboot).
    How to I tell my application(ex. hello_world) to include custom_netboot instead of netboot? How to do this without making changes to the SDK?"

    " You need to add new kconfig for selecting custom_netboot and then add some cmake code (typically in a ZEPHYR_EXTRA_MODULE which performs the conditional add_child_image. See the example: https://github.com/oivoii/rpmsg-simple-nrf5340/pull/2/files "

    I will try this myself as well. Then I will have a look at your network core app problem after.

    Regards,
    Sigurd Hellesvik

  • 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.

Reply
  • 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.

Children
No Data
Related