Include MCUBoot as an External Library

Hello,

I am currently working with the nRF5340DK kit.

For my project, I need to incorporate some additional custom checks/code into the project's bootloader(MCUBoot).

As you know, MCUBoot is included in the project from the SDK when enabled through prj.conf.

  • If I make changes directly to the MCUBoot folder in the SDK, adding my own code, etc., would this be advisable?
  • My concern is that if there is an update to the MCUBoot library and I try to update my MCUBoot folder, it might either throw errors or simply overwrite the folder, removing my changes. Is my understanding correct?

Alternatively, I am considering cloning the MCUBoot folder, adding my custom code to it, then including this modified version as an external library and using it to build my application as a bootloader.

  • Would this approach work? Could you please provide guidance on how to do this?

Is there any alternative approach to achieving this without treating MCUBoot as an external library?

Best Regards
Dheeraj

Parents
  • Hello Dheeraj,

    You can maintain your own fork of the mcuboot repo if you need to make changes to it, see Forking a repository of the nRF Connect SDK. It's also possible to make the changes directly in your local repo.  You will need to re-apply these changes every time you update SDK. 

    It's also possible to supply a pre-compiled version of MCUBoot to the build by adding the following configurations to your parent image:

    CONFIG_MCUBOOT_BUILD_STRATEGY_USE_HEX_FILE=y
    CONFIG_MCUBOOT_HEX_FILE="<absolute path to mcuboot.hex>"
    # Key file to sign the app images. This key must match the key used to build the MCUBoot hex.
    CONFIG_BOOT_SIGNATURE_KEY_FILE="root-ec-p256.pem"
    # Sign application image to make it bootable for MCUBoot
    CONFIG_SIGN_IMAGES=y

    Best regards,

    Vidar

Reply
  • Hello Dheeraj,

    You can maintain your own fork of the mcuboot repo if you need to make changes to it, see Forking a repository of the nRF Connect SDK. It's also possible to make the changes directly in your local repo.  You will need to re-apply these changes every time you update SDK. 

    It's also possible to supply a pre-compiled version of MCUBoot to the build by adding the following configurations to your parent image:

    CONFIG_MCUBOOT_BUILD_STRATEGY_USE_HEX_FILE=y
    CONFIG_MCUBOOT_HEX_FILE="<absolute path to mcuboot.hex>"
    # Key file to sign the app images. This key must match the key used to build the MCUBoot hex.
    CONFIG_BOOT_SIGNATURE_KEY_FILE="root-ec-p256.pem"
    # Sign application image to make it bootable for MCUBoot
    CONFIG_SIGN_IMAGES=y

    Best regards,

    Vidar

Children
  • Hello Vidar,

    Thank you for your response.

    However my question is partially answered above.

    Here is a clear demonstration of the problem divided into 3 parts with some questions I faced during my research for which I did not find any clear responses.


    As shown in the Chapter 8 - Multi-image builds and the Partition Manager,

    As shown in the above image I want to add an src folder and add my .c files to this mcuboot image.

    How do I do this?

    Also could MCUBOOT_BOOTUTIL_LIB be used for this in any manner? If not, what is this config useful for exactly?


    As per mcuboot documentation :

    MCUboot comprises two packages:

    • The bootutil library (boot/bootutil)

    • The boot application (each port has its own at boot/)

    Now if I have to add some new functions to my mcuboot, my understanding is that I have to add a new folder to my  project and append this folder with the path and the .c files to the CMakeLists.txt present in the boot application (each port has its own at boot/) lib path. Is that correct?

    I request you to attach screenshots or a project .zip file of the implementation is its possible, using the hello world program as a base with mcuboot enabled.


    As per the section Chapter 8 -Configuring child images, one can only make changes to child image by adding kconfigs or like cmake variables using build command. However addition of new files to add to the build is not possible?

    Assuming this is possible, it would be an amazing customisability feature that developers can use and solves many problems.


    Thank you for your consideration and the support.

    Best Regards,

    Dheeraj

  • Hi Dheeraj,

    My suggestion was that you either create a fork of the MCUBoot repo or add your modifications directly in the SDK tree (i.e. in /bootloader/mcuboot/boot/zephyr). The parent image cannot control which files the mcuboot project will include in the build unless it is controlled by a Kconfig symbol. I assume you will also need to make changes to the existing code in MCUBoot source to be able to integrate your code. 

    Best regards,

    Vidar

  • Hello Vidar,

    Thank you for your reply.

    Could you please check and answer the other questions too as they are related to the same topic and will give me some more clarity.

    Thank you for considering,

    Best Regards

    Dheeraj

  • Hi Dheeraj,

    dheerkot said:
    Also could MCUBOOT_BOOTUTIL_LIB be used for this in any manner? If not, what is this config useful for exactly?

    This symbol is to enable support for managing MCUBoot images in your application. 

    dheerkot said:
    Now if I have to add some new functions to my mcuboot, my understanding is that I have to add a new folder to my  project and append this folder with the path and the .c files to the CMakeLists.txt present in the boot application (each port has its own at boot/) lib path. Is that correct?

    You need to add your modifications directly in the SDK tree (i.e. in /bootloader/mcuboot/boot/zephyr) to add new functionality to the bootloader that isn't already supported through Kconfig symbols.

    Best regards,

    Vidar

Related