Commit graph

19 commits

Author SHA1 Message Date
Torsten Rasmussen fc1884ecf5 sysbuild: support sysbuild/CMakeLists.txt as entry point for samples
This commit refactors sysbuild entry code by creating a CMake sysbuild
module for image processing and place sysbuild entry code in a
<app>/sysbuild/CMakeLists.txt file.

A template/CMakeLists.txt file will be use as template for applications
which doesn't provide their own entry file.

An application may create a sysbuild/CMakeLists.txt file.
The sysbuild/CMakeLists.txt file is similar in nature to the
toplevel CMakeLists.txt file but intended to used by sysbuild.
This allows application developers to adjust how an application is
built with sysbuild.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-05-27 14:05:38 +01:00
Torsten Rasmussen e2ff2a88ba sysbuild: include HWMv2 Kconfig in sysbuild
Including HWMv2 Kconfig in sysbuild allows sysbuild to introduce
configuration options or defaults based on selected board and SoC.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-03-04 15:27:09 +00:00
Jamie McCrae 9104a804b9 sysbuild: Add pre_image and post_image hooks
Adds hooks that run before and after every image has been
configured

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-12-12 15:31:16 +01:00
Alberto Escolar Piedras 94cdfa60dc sysbuild: Add extensions for native_simulator based targets
Add 3 new functions to perform functions typically needed
for native_simulator based targes and reduce the amount
of boilerplate.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-12-02 07:53:11 -05:00
Grzegorz Swiderski 4cfea45c44 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-09-05 15:27:04 +02:00
Grzegorz Swiderski 6640c04df6 sysbuild: Remove IMAGES variable
This variable was originally provided for two indended purposes:

  * Let users manually add a new image in a desired order in the list.
  * Let users set build-only images, which are excluded from the list.

Given the recent additions of the `sysbuild_add_dependencies()` function
and the `BUILD_ONLY` parameter, `IMAGES` should be considered obsolete.

Furthermore, the list of images added to sysbuild should be updated
automatically when calling `ExternalZephyrProject_Add()`. This is now
possible by using a GLOBAL property internal to sysbuild.

With that, the `IMAGES` variable can be removed. Its existing usage for
image ordering is replaced with `sysbuild_add_dependencies()` treewide.

Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
2023-09-05 15:27:04 +02:00
Grzegorz Swiderski c323cc6fb1 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-09-05 15:27:04 +02:00
Torsten Rasmussen f380f8200c sysbuild: refactor image_config.cmake handling
Refactor image_config.cmake so that it is no longer sourced
unconditionally for all images. Instead image_config.cmake has been
split into BOOTLOADER_image_default.cmake and MAIN_image_default.cmake
and is set as property on the image.

This means the code in image_config.cmake can be split into dedicated
files which depends on the image type. Furthermore it allows sysbuild
modules to append extra config snippets to process for sysbuild kconfig
overwrite, or even remove the default snippet and have full control.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2023-08-24 10:57:28 +02:00
Torsten Rasmussen db89e7699d sysbuild: generate .config.sysbuild for controlling build settings
Sysbuild now generates a .config.sysbuild config file which specifies
settings controlled by sysbuild.
Any setting specified in this .config will overrule user provided
setting, and a warning will be raised if the sysbuild controlled value
is different from the value specified by the user.

This has the following benefits:
- Allow sysbuild to control any build setting without adjustments to
  the existing Kconfig tree
- Allow sysbuild to adjust settings based on knowledge regarding enabled
  images / bootloaders.
- Cleanup CMake code, as settings in sysbuild no longer needs to be
  propagated using CMake cache variables.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2023-05-25 14:57:41 +02:00
Torsten Rasmussen 9940940cea cmake: sysbuild PRE_CMAKE, POST_CMAKE, PRE_DOMAINS, POST_DOMAINS hooks
Provide a uniform way for sysbuild modules to create hooks that are
called at specific time during sysbuild CMake configure time.

A module can create functions following the scheme:
- <module-name>_pre_cmake
- <module-name>_post_cmake
- <module-name>_pre_domains
- <module-name>_post_domains

those functions, if defined, will be called by sysbuild CMake at the
location indicated by the function name.

A new global variable `SYSBUILD_CURRENT_MODULE_NAME` is created, which
a module can use to know it's own name when defining those functions
during sysbuild module CMake inclusion.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2023-03-11 19:53:40 +01:00
Jamie McCrae 5739d8dc1b sysbuild: Fix mcuboot checksum only verification not working
Fixes an issue when configuring a project through sysbuild to use
mcuboot and setting the verification to checksum only whereby the
image would be unbootable.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-03-09 09:44:54 +00:00
Jamie McCrae df9027a64a sysbuild: support Zephyr modules
This commit extends the Zephyr module yaml scheme with additional
entries for sysbuild in the build section.

This allows for Zephyr modules to extend the sysbuild infrastructure
by providing additional CMake and Kconfig files to be included in
sysbuild.

The new settings are:
build:
  sysbuild-cmake: <path>
  sysbuild-kconfig: <path>/<file>
  sysbuild-ext: <true>|<false>
  sysbuild-kconfig-ext:  <true>|<false>

those settings follow the same pattern as the equivalent Zephyr build
settings but are processed by sysbuild.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2023-03-09 09:25:00 +01:00
Jamie McCrae 631fa63610 sysbuild: split running of CMake from ExternalZephyrProject_add()
Split running CMake from ExternalZephyrProject_add().

This will allow systems to define all Zephyr projects and then at later
stages run the CMake configure stage.

This makes it both cleaner when CMake is invoked as well as prepare for
future work where images could be depending on CMake outcome from other
projects.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-03-09 09:25:00 +01:00
Jamie McCrae f4ddca5dca sysbuild: Check for duplicate image names
Checks if the IMAGES variable has been updated with a duplicate
image name, which would otherwise cause an infinite loop.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2023-01-13 12:00:57 +01:00
Jamie McCrae b65699cc4a cmake: sysbuild: Add support for recurive target cmake inclusion
Adds support for all sysbuild targets to have a sysbuild.cmake file
included and processed as part of sysbuild instead of just the main
application.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-11-03 13:04:08 +01:00
Torsten Rasmussen b88c8e1363 cmake: sysbuild: signing support
This commit introduces image signing by adding the possibility to
specify algorithm and signing key for sysbuild images.

It introduces Kconfig setting to specify signing algorithm and key file.

It will default the signing key to the default key provided by MCUBoot
if no key has been specified.

When signing is enabling, the signature key will be passed to the
application so the build system can sign the image as post build step.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-08-03 16:05:07 +02:00
Torsten Rasmussen 598bea0899 cmake: create domains.yaml
Support creation of domains.yaml to support
`west <build|flash|debug> --domain` when working with sysbuild multi
image.

Each Zephyr based image is added to list of domain that can be handled
by the Zephyr west extension commands.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-08-03 16:05:07 +02:00
Torsten Rasmussen 3d520dde2b cmake: support MCUBoot bootloader natively with SYSBuild
This commit adds CMake and Kconfig files needed to build MCUboot as
an extra image using SYSBuild.

Building an application with MCUBoot using SYSBuild allows users to
build both images using a single build.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-08-03 16:05:07 +02:00
Torsten Rasmussen 9d6cc39d6f cmake: initial sysbuild / multi image support
This is the initial commit with system build, sysbuild.

Using CMake as infrastructure together with the Zephyr sysbuild allows
us to support a convenient way of building a sample and allow for extra
images to be built as part of a larger system.

It uses Kconfig for configuration of image builds.
This allows for future extension with additional build images.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-08-03 16:05:07 +02:00