MCUBoot fails to load if using CMake Overlay Config

I am developing an app with the MCUBoot and a main applicaton. I followed the SMP SVR tutorial and modified it to my needs.

I have noticed that if I use a config overlay for MCUBoot (in CMake), it fails to set the config CONFIG_PARTITION_MANAGER_ENABLED and CONFIG_FLASH_MAP_CUSTOM=y, which then makes the bootloader fail. (Note: I am using a custom static partition yaml filee)

If I declare all my overlay configurations in child_image/mcuboot.conf or as CMake defines as mcuboot_CONFIG_HELLO, it works.

I need an overlay config since only when I am in a certain build configuration I want to activate them

This is how the CMake snippet looks like

if(MYCONDITION_FOR_USING_OVERLAY)
    set(mcuboot_OVERLAY_CONFIG ${CMAKE_CURRENT_LIST_DIR}/child_image/mcuboot_my_overlay.conf)
endif()

And the file child_image/mcuboot_my_overlay.conf looks as follows

CONFIG_LOG=y
CONFIG_SERIAL=y
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y

Log error message

*** Booting Zephyr OS build v3.0.99-ncs1  ***
I: Starting bootloader
W: Failed reading sectors; BOOT_MAX_IMG_SECTORS=128 - too small?
W: Cannot upgrade: not a compatible amount of sectors
E: Image in the primary slot is not valid!
E: Unable to find bootable image

However, if I use CMake options or declare everything in the child_image_name/child_image.conf dir (i.e., child_image/mcuboot.conf) it works:

if(MYCONDITION_FOR_USING_OVERLAY)
    set(mcuboot_CONFIG_SERIAL y)
    set(mcuboot_CONFIG_LOG y)
    set(mcuboot_CONFIG_CONSOLE y)
    set(mcuboot_CONFIG_UART_CONSOLE y)
endif()

Am I missing something that makes the build not include my static partition and thus making the bootloader fail?

I used as reference this:

developer.nordicsemi.com/.../ug_multi_image.html

Parents
  • From Multi-Image builds, Image Specific Variables:

    The build system grabs the Kconfig fragment or configuration file
    specified in a CMake argument relative to that image’s application
    directory.
    For example, the build system uses nrf/samples/bootloader/my-fragment.conf when building with the -Db0_OVERLAY_CONFIG=my-fragment.conf option, whereas -DOVERLAY_CONFIG=my-fragment.conf grabs the fragment from the main application’s directory, such as zephyr/samples/hello_world/my-fragment.conf.

    So the fix would be to use mcuboot_CONF_FILE instead. Keep in mind that with mcuboot_CONF_FILE, you need to re-specify the whole config file and not just overlay, so the easier way is just to use child_image/mcuboot.conf

Reply
  • From Multi-Image builds, Image Specific Variables:

    The build system grabs the Kconfig fragment or configuration file
    specified in a CMake argument relative to that image’s application
    directory.
    For example, the build system uses nrf/samples/bootloader/my-fragment.conf when building with the -Db0_OVERLAY_CONFIG=my-fragment.conf option, whereas -DOVERLAY_CONFIG=my-fragment.conf grabs the fragment from the main application’s directory, such as zephyr/samples/hello_world/my-fragment.conf.

    So the fix would be to use mcuboot_CONF_FILE instead. Keep in mind that with mcuboot_CONF_FILE, you need to re-specify the whole config file and not just overlay, so the easier way is just to use child_image/mcuboot.conf

Children
Related