zephyr/share/sysbuild/CMakeLists.txt

45 lines
1.8 KiB
CMake
Raw Normal View History

# Copyright (c) 2021-2023 Nordic Semiconductor
#
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.20)
if(NOT DEFINED APP_DIR)
message(FATAL_ERROR "No main application specified")
endif()
# This will update the APP_DIR cache variable to PATH type and apply a comment.
# If APP_DIR is a relative path, then CMake will adjust to absolute path based
# on current working dir.
set(APP_DIR ${APP_DIR} CACHE PATH "Main Application Source Directory")
# Add sysbuild/cmake/modules to CMAKE_MODULE_PATH which allows us to integrate
# sysbuild CMake modules with general Zephyr CMake modules.
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake/modules)
# List of Zephyr and sysbuild CMake modules we need for sysbuild.
# Note: sysbuild_kconfig will internally load kconfig CMake module.
set(zephyr_modules extensions sysbuild_extensions python west root zephyr_module boards shields sysbuild_kconfig)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} COMPONENTS ${zephyr_modules})
project(sysbuild LANGUAGES)
get_filename_component(APP_DIR ${APP_DIR} ABSOLUTE)
get_filename_component(app_name ${APP_DIR} NAME)
set(DEFAULT_IMAGE "${app_name}")
sysbuild: Make the image processing order well-defined Adjust the order in which image-specific `sysbuild.cmake` files are iteratively included by sysbuild. This is motivated by the introduction of `sysbuild_add_dependencies()`. In the following example: sysbuild_add_dependencies(CONFIGURE my_sample sample_a sample_b) the `my_sample` image is expected to be added before this function is called. Success depends not only on the placement of the call, but on the order in which new images are added, which itself is influenced by the order in which `sysbuild.cmake` files are included. This last order can be tweaked to make the "dependencies" feature more user-friendly. This is done by rewriting the internal `sysbuild.cmake` processing loop into a new, general purpose function - `sysbuild_add_subdirectory()` - which is a wrapper for `add_subdirectory(<source_dir>)` that recursively includes `sysbuild.cmake` files for all images found in `<source_dir>`. With the new function, all images that are expected to be found in a given `<source_dir>` are guaranteed to be added around the same time. This wasn't the case with the old processing loop, because the image- specific `sysbuild.cmake` files (where "sub-images" could be defined) were left to be processed at the very end. Below is the initial order in which sysbuild will add all images. Note: the order of Zephyr modules (from 1 to n) is well-defined. 1. Main application (aka DEFAULT_IMAGE) 2. MCUboot (optional) 3. All images added via these directories: 3.1. <module-1>.sysbuild-cmake 3.2. <module-2>.sysbuild-cmake ... 3.n. <module-n>.sysbuild-cmake 4. All images added via these files: 4.1. ${BOARD_DIR}/sysbuild.cmake 4.2. ${APP_DIR}/sysbuild.cmake (aka sub-images of DEFAULT_IMAGE) These images are intended to be sorted for the users' convenience, from most to least important in the build system, or least to most dependent on other images for configuration (potentially). Finally, the use of `sysbuild_add_subdirectory()` requires updating the directory structure in sysbuild: ./images - All images should belong here. The `DEFAULT_IMAGE` should be the first and only image at the top level, so that it gets added first and its sub-images get added last. ./images/bootloader - Moved from ./bootloader. ./images/boards - Adds images from the board-specific `sysbuild.cmake` file. Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
2023-08-25 18:45:14 +08:00
# This is where all Zephyr applications are added to the multi-image build.
sysbuild_add_subdirectory(images)
get_property(IMAGES GLOBAL PROPERTY sysbuild_images)
sysbuild_module_call(PRE_CMAKE MODULES ${SYSBUILD_MODULE_NAMES} IMAGES ${IMAGES})
sysbuild: Support relative ordering of images Fixes #53650 The existing solution for image ordering involves the `IMAGES` variable, which sysbuild originally provided to let users manually add a new image in a desired order. This isn't very flexible for the following reasons: * The order in which `IMAGES` is updated across multiple modules and `sysbuild.cmake` files is not well defined. * Having a single variable means that the same order is used for both configuration and flashing. Usually, there is no reason for the flashing order to be the same as the configuration order. Introduce the `sysbuild_add_dependencies()` function for more fine-tuned ordering of images. It makes one image depend on other images in either configuration or flashing order. Its usage is similar to the standard CMake function `add_dependencies()`, but with an extra parameter to distinguish between two types of dependencies: sysbuild_add_dependencies(CONFIGURE my_sample sample_a sample_b) sysbuild_add_dependencies(FLASH my_sample sample_c sample_d) CONFIGURE dependencies determine the order in which sysbuild configures (runs CMake for) the individual images. This is useful if there is some information from one application's build which needs to be available to another application. FLASH dependencies control the sequence of images used by `west flash`. This could be used if a specific flashing order is required by an SoC, a runner, or something else. Note that these dependencies are not valid for images specified as `BUILD_ONLY`. The internal `sysbuild_images_order()` function is responsible for assembling two sorted lists of images based on the added dependencies, with the help of `topological_sort()`. Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
2023-05-15 17:19:47 +08:00
sysbuild_images_order(IMAGES_CONFIGURATION_ORDER CONFIGURE IMAGES ${IMAGES})
foreach(image ${IMAGES_CONFIGURATION_ORDER})
ExternalZephyrProject_Cmake(APPLICATION ${image})
endforeach()
sysbuild_module_call(POST_CMAKE MODULES ${SYSBUILD_MODULE_NAMES} IMAGES ${IMAGES})
sysbuild_module_call(PRE_DOMAINS MODULES ${SYSBUILD_MODULE_NAMES} IMAGES ${IMAGES})
include(cmake/domains.cmake)
sysbuild_module_call(POST_DOMAINS MODULES ${SYSBUILD_MODULE_NAMES} IMAGES ${IMAGES})