diff --git a/samples/drivers/ipm/ipm_mcux/sysbuild.cmake b/samples/drivers/ipm/ipm_mcux/sysbuild.cmake index 2153852ce4d..6ca2faf7d34 100644 --- a/samples/drivers/ipm/ipm_mcux/sysbuild.cmake +++ b/samples/drivers/ipm/ipm_mcux/sysbuild.cmake @@ -9,9 +9,13 @@ ExternalZephyrProject_Add( BOARD ${SB_CONFIG_IPM_REMOTE_BOARD} ) -# Add a dependency so that the remote sample will be built and flashed first +# Add dependencies so that the remote sample will be built first # This is required because some primary cores need information from the # remote core's build, such as the output image's LMA add_dependencies(ipm_mcux ipm_mcux_remote) -# Place remote image first in the image list -set(IMAGES "ipm_mcux_remote" ${IMAGES}) +sysbuild_add_dependencies(CONFIGURE ipm_mcux ipm_mcux_remote) + +if(SB_CONFIG_BOOTLOADER_MCUBOOT) + # Make sure MCUboot is flashed first + sysbuild_add_dependencies(FLASH ipm_mcux_remote mcuboot) +endif() diff --git a/samples/subsys/ipc/openamp/sysbuild.cmake b/samples/subsys/ipc/openamp/sysbuild.cmake index 84df278aba3..7278a1af4d4 100644 --- a/samples/subsys/ipc/openamp/sysbuild.cmake +++ b/samples/subsys/ipc/openamp/sysbuild.cmake @@ -9,9 +9,13 @@ ExternalZephyrProject_Add( BOARD ${SB_CONFIG_OPENAMP_REMOTE_BOARD} ) -# Add a dependency so that the remote sample will be built and flashed first +# Add dependencies so that the remote sample will be built first # This is required because some primary cores need information from the # remote core's build, such as the output image's LMA add_dependencies(openamp openamp_remote) -# Place remote image first in the image list -set(IMAGES "openamp_remote" ${IMAGES}) +sysbuild_add_dependencies(CONFIGURE openamp openamp_remote) + +if(SB_CONFIG_BOOTLOADER_MCUBOOT) + # Make sure MCUboot is flashed first + sysbuild_add_dependencies(FLASH openamp_remote mcuboot) +endif() diff --git a/share/sysbuild/CMakeLists.txt b/share/sysbuild/CMakeLists.txt index b52f1cbabf5..d7b9d15f4e7 100644 --- a/share/sysbuild/CMakeLists.txt +++ b/share/sysbuild/CMakeLists.txt @@ -24,9 +24,6 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} COMPONENTS ${zephyr_modules project(sysbuild LANGUAGES) -# Global list of images enabled in this multi image build system. -set(IMAGES) - get_filename_component(APP_DIR ${APP_DIR} ABSOLUTE) get_filename_component(app_name ${APP_DIR} NAME) @@ -54,7 +51,6 @@ ExternalZephyrProject_Add( SOURCE_DIR ${APP_DIR} APP_TYPE MAIN ) -list(APPEND IMAGES "${app_name}") set(DEFAULT_IMAGE "${app_name}") add_subdirectory(bootloader) @@ -63,6 +59,7 @@ add_subdirectory(bootloader) include(${BOARD_DIR}/sysbuild.cmake OPTIONAL) # This allows image specific sysbuild.cmake to be processed. +get_property(IMAGES GLOBAL PROPERTY sysbuild_images) list(LENGTH IMAGES images_length) while(NOT "${images_length}" EQUAL "${processed_length}") foreach(image ${IMAGES}) @@ -73,6 +70,7 @@ while(NOT "${images_length}" EQUAL "${processed_length}") endif() endforeach() + get_property(IMAGES GLOBAL PROPERTY sysbuild_images) list(LENGTH IMAGES images_length) list(LENGTH images_sysbuild_processed processed_length_new) diff --git a/share/sysbuild/bootloader/CMakeLists.txt b/share/sysbuild/bootloader/CMakeLists.txt index 0d75ee7a407..c00a8e97783 100644 --- a/share/sysbuild/bootloader/CMakeLists.txt +++ b/share/sysbuild/bootloader/CMakeLists.txt @@ -12,7 +12,7 @@ if(SB_CONFIG_BOOTLOADER_MCUBOOT) ) # MCUBoot default configuration is to perform a full chip erase. # Placing MCUBoot first in list to ensure it is flashed before other images. - set(IMAGES ${image} ${IMAGES} PARENT_SCOPE) + sysbuild_add_dependencies(FLASH ${DEFAULT_IMAGE} ${image}) set_config_string(${image} CONFIG_BOOT_SIGNATURE_KEY_FILE "${SB_CONFIG_BOOT_SIGNATURE_KEY_FILE}") endif() diff --git a/share/sysbuild/cmake/modules/sysbuild_extensions.cmake b/share/sysbuild/cmake/modules/sysbuild_extensions.cmake index a399e643d6c..fd776f8e4ed 100644 --- a/share/sysbuild/cmake/modules/sysbuild_extensions.cmake +++ b/share/sysbuild/cmake/modules/sysbuild_extensions.cmake @@ -155,6 +155,11 @@ function(ExternalZephyrProject_Add) endif() + set_property( + GLOBAL + APPEND PROPERTY sysbuild_images ${ZBUILD_APPLICATION} + ) + set(sysbuild_image_conf_dir ${APP_DIR}/sysbuild) set(sysbuild_image_name_conf_dir ${APP_DIR}/sysbuild/${ZBUILD_APPLICATION}) # User defined `-D_CONF_FILE=` takes precedence over anything else. diff --git a/tests/boot/test_mcuboot/sysbuild.cmake b/tests/boot/test_mcuboot/sysbuild.cmake index 0c5ebac2690..dc5165114b5 100644 --- a/tests/boot/test_mcuboot/sysbuild.cmake +++ b/tests/boot/test_mcuboot/sysbuild.cmake @@ -15,11 +15,12 @@ ExternalZephyrProject_Add( ) # Add the swapped app to the list of images to flash -# Ensure the order of images is as follows: +# Ensure the flashing order of images is as follows: # - mcuboot # - swapped app # - primary app (test_mcuboot) # This order means that if the debugger resets the MCU in between flash # iterations, the MCUBoot swap won't be triggered until the secondary app # is actually present in flash. -set(IMAGES "mcuboot" "swapped_app" "test_mcuboot") +sysbuild_add_dependencies(FLASH test_mcuboot swapped_app) +sysbuild_add_dependencies(FLASH swapped_app mcuboot)