1.. _sysbuild:
2
3Sysbuild (System build)
4#######################
5
6Sysbuild is a higher-level build system that can be used to combine multiple
7other build systems together. It is a higher-level layer that combines one
8or more Zephyr build systems and optional additional build systems
9into a hierarchical build system.
10
11For example, you can use sysbuild to build a Zephyr application together
12with the MCUboot bootloader, flash them both onto your device, and
13debug the results.
14
15Sysbuild works by configuring and building at least a Zephyr application and, optionally, as many
16additional projects as you want. The additional projects can be either Zephyr applications
17or other types of builds you want to run.
18
19Like Zephyr's :ref:`build system <build_overview>`, sysbuild is written in
20CMake and uses :ref:`Kconfig <kconfig>`.
21
22Definitions
23***********
24
25The following are some key concepts used in this document:
26
27Single-image build
28    When sysbuild is used to create and manage just one Zephyr application's
29    build system.
30
31Multi-image build
32   When sysbuild is used to manage multiple build systems.
33   The word "image" is used because your main goal is usually to generate the binaries of the firmware
34   application images from each build system.
35
36Domain
37   Every Zephyr CMake build system managed by sysbuild.
38
39Multi-domain
40   When more than one Zephyr CMake build system (domain) is managed by sysbuild.
41
42Architectural Overview
43**********************
44
45This figure is an overview of sysbuild's inputs, outputs, and user interfaces:
46
47.. figure:: sysbuild.svg
48    :align: center
49    :alt: Sysbuild architectural overview
50    :figclass: align-center
51    :width: 80%
52
53The following are some key sysbuild features indicated in this figure:
54
55- You can run sysbuild either with :ref:`west build
56  <west-building>` or directly via ``cmake``.
57
58- You can use sysbuild to generate application images from each build system,
59  shown above as ELF, BIN, and HEX files.
60
61- You can configure sysbuild or any of the build systems it manages using
62  various configuration variables. These variables are namespaced so that
63  sysbuild can direct them to the right build system. In some cases, such as
64  the ``BOARD`` variable, these are shared among multiple build systems.
65
66- Sysbuild itself is also configured using Kconfig. For example, you can
67  instruct sysbuild to build the MCUboot bootloader, as well as to build and
68  link your main Zephyr application as an MCUboot-bootable image, using sysbuild's
69  Kconfig files.
70
71- Sysbuild integrates with west's :ref:`west-build-flash-debug` commands. It
72  does this by managing the :ref:`west-runner`, and specifically the
73  :file:`runners.yaml` files that each Zephyr build system will contain. These
74  are packaged into a global view of how to flash and debug each build system
75  in a :file:`domains.yaml` file generated and managed by sysbuild.
76
77- Build names are prefixed with the target name and an underscore, for example
78  the sysbuild target is prefixed with ``sysbuild_`` and if MCUboot is enabled
79  as part of sysbuild, it will be prefixed with ``mcuboot_``. This also allows
80  for running things like menuconfig with the prefix, for example (if using
81  ninja) ``ninja sysbuild_menuconfig`` to configure sysbuild or (if using make)
82  ``make mcuboot_menuconfig``.
83
84Building with sysbuild
85**********************
86
87As mentioned above, you can run sysbuild via ``west build`` or ``cmake``.
88
89.. tabs::
90
91   .. group-tab:: ``west build``
92
93      Here is an example. For details, see :ref:`west-multi-domain-builds` in
94      the ``west build documentation``.
95
96      .. zephyr-app-commands::
97         :tool: west
98         :zephyr-app: samples/hello_world
99         :board: reel_board
100         :goals: build
101         :west-args: --sysbuild
102         :compact:
103
104      .. tip::
105
106         To configure ``west build`` to use ``--sysbuild`` by default from now on,
107         run:
108
109         .. code-block:: shell
110
111            west config build.sysbuild True
112
113         Since sysbuild supports both single- and multi-image builds, this lets you
114         use sysbuild all the time, without worrying about what type of build you are
115         running.
116
117         To turn this off, run this before generating your build system:
118
119         .. code-block:: shell
120
121            west config build.sysbuild False
122
123         To turn this off for just one ``west build`` command, run:
124
125         .. code-block:: shell
126
127            west build --no-sysbuild ...
128
129   .. group-tab:: ``cmake``
130
131      Here is an example using CMake and Ninja.
132
133      .. zephyr-app-commands::
134         :tool: cmake
135         :app: share/sysbuild
136         :board: reel_board
137         :goals: build
138         :gen-args: -DAPP_DIR=samples/hello_world
139         :compact:
140
141      To use sysbuild directly with CMake, you must specify the sysbuild
142      project as the source folder, and give ``-DAPP_DIR=<path-to-sample>`` as
143      an extra CMake argument. ``APP_DIR`` is the path to the main Zephyr
144      application managed by sysbuild.
145
146      .. tip::
147
148         The environment variables, ``CMAKE_BUILD_PARALLEL_LEVEL`` and ``VERBOSE``, can be used to
149         control the build process when using sysbuild with CMake and ninja.
150
151         To set number of jobs for ninja for all sysbuild images, set the CMAKE_BUILD_PARALLEL_LEVEL
152         environment variable and invoke the build with ``cmake --build``, for example:
153
154         .. code-block:: shell
155
156            CMAKE_BUILD_PARALLEL_LEVEL=<n> cmake --build .
157
158         For verbose output of all images, use:
159
160         .. code-block:: shell
161
162            VERBOSE=1 cmake --build .
163
164
165Configuration namespacing
166*************************
167
168When building a single Zephyr application without sysbuild, all CMake cache
169settings and Kconfig build options given on the command line as
170``-D<var>=<value>`` or ``-DCONFIG_<var>=<value>`` are handled by the Zephyr
171build system.
172
173However, when sysbuild combines multiple Zephyr build systems, there could be
174Kconfig settings exclusive to sysbuild (and not used by any of the applications).
175To handle this, sysbuild has namespaces for configuration variables. You can use these
176namespaces to direct settings either to sysbuild itself or to a specific Zephyr
177application managed by sysbuild using the information in these sections.
178
179The following example shows how to build :zephyr:code-sample:`hello_world` with MCUboot enabled,
180applying to both images debug optimizations:
181
182.. tabs::
183
184   .. group-tab:: ``west build``
185
186      .. zephyr-app-commands::
187         :tool: west
188         :zephyr-app: samples/hello_world
189         :board: reel_board
190         :goals: build
191         :west-args: --sysbuild
192         :gen-args: -DSB_CONFIG_BOOTLOADER_MCUBOOT=y -DCONFIG_DEBUG_OPTIMIZATIONS=y -Dmcuboot_CONFIG_DEBUG_OPTIMIZATIONS=y
193         :compact:
194
195   .. group-tab:: ``cmake``
196
197      .. zephyr-app-commands::
198         :tool: cmake
199         :app: share/sysbuild
200         :board: reel_board
201         :goals: build
202         :gen-args: -DAPP_DIR=samples/hello_world -DSB_CONFIG_BOOTLOADER_MCUBOOT=y -DCONFIG_DEBUG_OPTIMIZATIONS=y -Dmcuboot_CONFIG_DEBUG_OPTIMIZATIONS=y
203         :compact:
204
205See the following subsections for more information.
206
207.. _sysbuild_cmake_namespace:
208
209CMake variable namespacing
210==========================
211
212CMake variable settings can be passed to CMake using ``-D<var>=<value>`` on the
213command line. You can also set Kconfig options via CMake as
214``-DCONFIG_<var>=<value>`` or ``-D<namespace>_CONFIG_<var>=<value>``.
215
216Since sysbuild is the entry point for the build system, and sysbuild is written
217in CMake, all CMake variables are first processed by sysbuild.
218
219Sysbuild creates a namespace for each domain. The namespace prefix is the
220domain's application name. See :ref:`sysbuild_zephyr_application` for more
221information.
222
223To set the variable ``<var>`` in the namespace ``<namespace>``, use this syntax::
224
225  -D<namespace>_<var>=<value>
226
227For example, to set the CMake variable ``FOO`` in the ``my_sample`` application
228build system to the value ``BAR``, run the following commands:
229
230.. tabs::
231
232   .. group-tab:: ``west build``
233
234      .. code-block:: shell
235
236         west build --sysbuild ... -- -Dmy_sample_FOO=BAR
237
238   .. group-tab:: ``cmake``
239
240      .. code-block:: shell
241
242         cmake -Dmy_sample_FOO=BAR ...
243
244.. _sysbuild_kconfig_namespacing:
245
246Kconfig namespacing
247===================
248
249To set the sysbuild Kconfig option ``<var>`` to the value ``<value>``, use this syntax::
250
251  -DSB_CONFIG_<var>=<value>
252
253In the previous example, ``SB_CONFIG`` is the namespace prefix for sysbuild's Kconfig
254options.
255
256To set a Zephyr application's Kconfig option instead, use this syntax::
257
258  -D<namespace>_CONFIG_<var>=<value>
259
260In the previous example, ``<namespace>`` is the application name discussed above in
261:ref:`sysbuild_cmake_namespace`.
262
263For example, to set the Kconfig option ``FOO`` in the ``my_sample`` application
264build system to the value ``BAR``, run the following commands:
265
266.. tabs::
267
268   .. group-tab:: ``west build``
269
270      .. code-block:: shell
271
272         west build --sysbuild ... -- -Dmy_sample_CONFIG_FOO=BAR
273
274   .. group-tab:: ``cmake``
275
276      .. code-block:: shell
277
278        cmake -Dmy_sample_CONFIG_FOO=BAR ...
279
280.. tip::
281   When no ``<namespace>`` is used, the Kconfig setting is passed to the main
282   Zephyr application ``my_sample``.
283
284   This means that passing ``-DCONFIG_<var>=<value>`` and
285   ``-Dmy_sample_CONFIG_<var>=<value>`` are equivalent.
286
287   This allows you to build the same application with or without sysbuild using
288   the same syntax for setting Kconfig values at CMake time.
289   For example, the following commands will work in the same way:
290
291   .. code-block:: shell
292
293      west build -b <board> my_sample -- -DCONFIG_FOO=BAR
294
295   .. code-block:: shell
296
297      west build -b <board> --sysbuild my_sample -- -DCONFIG_FOO=BAR
298
299Sysbuild flashing using ``west flash``
300**************************************
301
302You can use :ref:`west flash <west-flashing>` to flash applications with
303sysbuild.
304
305When invoking ``west flash`` on a build consisting of multiple images, each
306image is flashed in sequence. Extra arguments such as ``--runner jlink`` are
307passed to each invocation.
308
309For more details, see :ref:`west-multi-domain-flashing`.
310
311Sysbuild debugging using ``west debug``
312***************************************
313
314You can use ``west debug``  to debug the main application, whether you are using sysbuild or not.
315Just follow the existing :ref:`west debug <west-debugging>` guide to debug the main sample.
316
317To debug a different domain (Zephyr application), such as ``mcuboot``, use
318the ``--domain`` argument, as follows::
319
320  west debug --domain mcuboot
321
322For more details, see :ref:`west-multi-domain-debugging`.
323
324Building a sample with MCUboot
325******************************
326
327Sysbuild supports MCUboot natively.
328
329To build a sample like ``hello_world`` with MCUboot,
330enable MCUboot and build and flash the sample as follows:
331
332.. tabs::
333
334   .. group-tab:: ``west build``
335
336      .. zephyr-app-commands::
337         :tool: west
338         :zephyr-app: samples/hello_world
339         :board: reel_board
340         :goals: build
341         :west-args: --sysbuild
342         :gen-args: -DSB_CONFIG_BOOTLOADER_MCUBOOT=y
343         :compact:
344
345   .. group-tab:: ``cmake``
346
347      .. zephyr-app-commands::
348         :tool: cmake
349         :app: share/sysbuild
350         :board: reel_board
351         :goals: build
352         :gen-args: -DAPP_DIR=samples/hello_world -DSB_CONFIG_BOOTLOADER_MCUBOOT=y
353         :compact:
354
355This builds ``hello_world`` and ``mcuboot`` for the ``reel_board``, and then
356flashes both the ``mcuboot`` and ``hello_world`` application images to the
357board.
358
359More detailed information regarding the use of MCUboot with Zephyr can be found
360in the `MCUboot with Zephyr`_ documentation page on the MCUboot website.
361
362.. note::
363
364   The deprecated MCUBoot Kconfig option ``CONFIG_ZEPHYR_TRY_MASS_ERASE`` will
365   perform a full chip erase when flashed. If this option is enabled, then
366   flashing only MCUBoot, for example using ``west flash --domain mcuboot``, may
367   erase the entire flash, including the main application image.
368
369Sysbuild Kconfig file
370*********************
371
372You can set sysbuild's Kconfig options for a single application using
373configuration files. By default, sysbuild looks for a configuration file named
374``sysbuild.conf`` in the application top-level directory.
375
376In the following example, there is a :file:`sysbuild.conf` file that enables building and flashing with
377MCUboot whenever sysbuild is used:
378
379.. code-block:: none
380
381   <home>/application
382   ├── CMakeLists.txt
383   ├── prj.conf
384   └── sysbuild.conf
385
386
387.. code-block:: cfg
388
389   SB_CONFIG_BOOTLOADER_MCUBOOT=y
390
391You can set a configuration file to use with the
392``-DSB_CONF_FILE=<sysbuild-conf-file>`` CMake build setting.
393
394For example, you can create ``sysbuild-mcuboot.conf`` and then
395specify this file when building with sysbuild, as follows:
396
397.. tabs::
398
399   .. group-tab:: ``west build``
400
401      .. zephyr-app-commands::
402         :tool: west
403         :zephyr-app: samples/hello_world
404         :board: reel_board
405         :goals: build
406         :west-args: --sysbuild
407         :gen-args: -DSB_CONF_FILE=sysbuild-mcuboot.conf
408         :compact:
409
410   .. group-tab:: ``cmake``
411
412      .. zephyr-app-commands::
413         :tool: cmake
414         :app: share/sysbuild
415         :board: reel_board
416         :goals: build
417         :gen-args: -DAPP_DIR=samples/hello_world -DSB_CONF_FILE=sysbuild-mcuboot.conf
418         :compact:
419
420Sysbuild targets
421****************
422
423Sysbuild creates build targets for each image (including sysbuild itself) for
424the following modes:
425
426 * menuconfig
427 * hardenconfig
428 * guiconfig
429
430For the main application (as is the same without using sysbuild) these can be
431ran normally without any prefix. For other images (including sysbuild), these
432are ran with a prefix of the image name and an underscore e.g. ``sysbuild_`` or
433``mcuboot_``, using ninja or make - for details on how to run image build
434targets that do not have mapped build targets in sysbuild, see the
435:ref:`sysbuild_dedicated_image_build_targets` section.
436
437.. _sysbuild_dedicated_image_build_targets:
438
439Dedicated image build targets
440*****************************
441
442Not all build targets for images are given equivalent prefixed build targets
443when sysbuild is used, for example build targets like ``ram_report``,
444``rom_report``, ``footprint``, ``puncover`` and ``pahole`` are not exposed.
445When using :ref:`Trusted Firmware <tfm_build_system>`, the build targets prefixed
446with ``tfm_`` and ``bl2_`` are also not exposed, for example: ``tfm_rom_report``
447and ``bl2_ram_report``. To run these build targets, the build directory of the
448image can be provided to west/ninja/make along with the name of the build
449target to execute and it will run.
450
451.. tabs::
452
453   .. group-tab:: ``west``
454
455      Assuming that a project has been configured and built using ``west``
456      using sysbuild with mcuboot enabled in the default ``build`` folder
457      location, the ``rom_report`` build target for ``mcuboot`` can be ran
458      with:
459
460      .. code-block:: shell
461
462         west build -d build/mcuboot -t rom_report
463
464      For TF-M projects using TF-M targets, the application build directory is
465      used like so:
466
467      .. code-block:: shell
468
469         west build -d build/<app_name> -t tfm_rom_report
470
471   .. group-tab:: ``ninja``
472
473      Assuming that a project has been configured using ``cmake`` and built
474      using ``ninja`` using sysbuild with mcuboot enabled, the ``rom_report``
475      build target for ``mcuboot`` can be ran with:
476
477      .. code-block:: shell
478
479         ninja -C mcuboot rom_report
480
481      For TF-M projects using TF-M targets, the application build directory is
482      used like so:
483
484      .. code-block:: shell
485
486         ninja -C <app_name> -t tfm_rom_report
487
488   .. group-tab:: ``make``
489
490      Assuming that a project has been configured using ``cmake`` and built
491      using ``make`` using sysbuild with mcuboot enabled, the ``rom_report``
492      build target for ``mcuboot`` can be ran with:
493
494      .. code-block:: shell
495
496         make -C mcuboot rom_report
497
498      For TF-M projects using TF-M targets, the application build directory is
499      used like so:
500
501      .. code-block:: shell
502
503         make -C <app_name> -t tfm_rom_report
504
505.. _sysbuild_zephyr_application:
506
507Adding Zephyr applications to sysbuild
508**************************************
509
510You can use the ``ExternalZephyrProject_Add()`` function to add Zephyr
511applications as sysbuild domains. Call this CMake function from your
512application's :file:`sysbuild.cmake` file, or any other CMake file you know will
513run as part sysbuild CMake invocation.
514
515Targeting the same board
516========================
517
518To include ``my_sample`` as another sysbuild domain, targeting the same board
519as the main image, use this example:
520
521.. code-block:: cmake
522
523   ExternalZephyrProject_Add(
524     APPLICATION my_sample
525     SOURCE_DIR <path-to>/my_sample
526   )
527
528This could be useful, for example, if your board requires you to build and flash an
529SoC-specific bootloader along with your main application.
530
531Targeting a different board
532===========================
533
534In sysbuild and Zephyr CMake build system a board may refer to:
535
536* A physical board with a single core SoC.
537* A specific core on a physical board with a multi-core SoC, such as
538  :ref:`nrf5340dk_nrf5340`.
539* A specific SoC on a physical board with multiple SoCs, such as
540  :ref:`nrf9160dk_nrf9160` and :ref:`nrf9160dk_nrf52840`.
541
542If your main application, for example, is built for ``mps2/an521/cpu0``, and your
543helper application must target the ``mps2/an521/cpu1`` board target, add
544a CMake function call that is structured as follows:
545
546.. code-block:: cmake
547
548   ExternalZephyrProject_Add(
549     APPLICATION my_sample
550     SOURCE_DIR <path-to>/my_sample
551     BOARD mps2/an521/cpu1
552   )
553
554This could be useful, for example, if your main application requires another
555helper Zephyr application to be built and flashed alongside it, but the helper
556runs on another core in your SoC.
557
558Targeting conditionally using Kconfig
559=====================================
560
561You can control whether extra applications are included as sysbuild domains
562using Kconfig.
563
564If the extra application image is specific to the board or an application,
565you can create two additional files: :file:`sysbuild.cmake` and :file:`Kconfig.sysbuild`.
566
567For an application, this would look like this:
568
569.. code-block:: none
570
571   <home>/application
572   ├── CMakeLists.txt
573   ├── prj.conf
574   ├── Kconfig.sysbuild
575   └── sysbuild.cmake
576
577In the previous example, :file:`sysbuild.cmake` would be structured as follows:
578
579.. code-block:: cmake
580
581   if(SB_CONFIG_SECOND_SAMPLE)
582     ExternalZephyrProject_Add(
583       APPLICATION second_sample
584       SOURCE_DIR <path-to>/second_sample
585     )
586   endif()
587
588:file:`Kconfig.sysbuild` would be structured as follows:
589
590.. code-block:: kconfig
591
592   source "sysbuild/Kconfig"
593
594   config SECOND_SAMPLE
595           bool "Second sample"
596           default y
597
598This will include ``second_sample`` by default, while still allowing you to
599disable it using the Kconfig option ``SECOND_SAMPLE``.
600
601For more information on setting sysbuild Kconfig options,
602see :ref:`sysbuild_kconfig_namespacing`.
603
604Building without flashing
605=========================
606
607You can mark ``my_sample`` as a build-only application in this manner:
608
609.. code-block:: cmake
610
611   ExternalZephyrProject_Add(
612     APPLICATION my_sample
613     SOURCE_DIR <path-to>/my_sample
614     BUILD_ONLY TRUE
615   )
616
617As a result, ``my_sample`` will be built as part of the sysbuild build invocation,
618but it will be excluded from the default image sequence used by ``west flash``.
619Instead, you may use the outputs of this domain for other purposes - for example,
620to produce a secondary image for DFU, or to merge multiple images together.
621
622You can also replace ``TRUE`` with another boolean constant in CMake, such as
623a Kconfig option, which would make ``my_sample`` conditionally build-only.
624
625.. note::
626
627   Applications marked as build-only can still be flashed manually, using
628   ``west flash --domain my_sample``. As such, the ``BUILD_ONLY`` option only
629   controls the default behavior of ``west flash``.
630
631.. _sysbuild_application_configuration:
632
633Zephyr application configuration
634================================
635
636When adding a Zephyr application to sysbuild, such as MCUboot, then the
637configuration files from the application (MCUboot) itself will be used.
638
639When integrating multiple applications with each other, then it is often
640necessary to make adjustments to the configuration of extra images.
641
642Sysbuild gives users the ability of creating Kconfig fragments or devicetree
643overlays that will be used together with the application's default configuration.
644Sysbuild also allows users to change :ref:`application-configuration-directory`
645in order to give users full control of an image's configuration.
646
647Zephyr application Kconfig fragment and devicetree overlay
648----------------------------------------------------------
649
650In the folder of the main application, create a Kconfig fragment or a devicetree
651overlay under a sysbuild folder, where the name of the file is
652:file:`<image>.conf` or :file:`<image>.overlay`, for example if your main
653application includes ``my_sample`` then create a :file:`sysbuild/my_sample.conf`
654file or a devicetree overlay :file:`sysbuild/my_sample.overlay`.
655
656A Kconfig fragment could look as:
657
658.. code-block:: cfg
659
660   # sysbuild/my_sample.conf
661   CONFIG_FOO=n
662
663Zephyr application configuration directory
664------------------------------------------
665
666In the folder of the main application, create a new folder under
667:file:`sysbuild/<image>/`.
668This folder will then be used as ``APPLICATION_CONFIG_DIR`` when building
669``<image>``.
670As an example, if your main application includes ``my_sample`` then create a
671:file:`sysbuild/my_sample/` folder and place any configuration files in
672there as you would normally do:
673
674.. code-block:: none
675
676   <home>/application
677   ├── CMakeLists.txt
678   ├── prj.conf
679   └── sysbuild
680       └── my_sample
681           ├── prj.conf
682           ├── app.overlay
683           └── boards
684               ├── <board_A>.conf
685               ├── <board_A>.overlay
686               ├── <board_B>.conf
687               └── <board_B>.overlay
688
689All configuration files under the :file:`sysbuild/my_sample/` folder will now
690be used when ``my_sample`` is included in the build, and the default
691configuration files for ``my_sample`` will be ignored.
692
693This give you full control on how images are configured when integrating those
694with ``application``.
695
696.. _sysbuild_file_suffixes:
697
698Sysbuild file suffix support
699----------------------------
700
701File suffix support through the :makevar:`FILE_SUFFIX` is supported in sysbuild
702(see :ref:`application-file-suffixes` for details on this feature in applications). For sysbuild,
703a globally provided option will be passed down to all images. In addition, the image configuration
704file will have this value applied and used (instead of the build type) if the file exists.
705
706Given the example project:
707
708.. code-block:: none
709
710   <home>/application
711   ├── CMakeLists.txt
712   ├── prj.conf
713   ├── sysbuild.conf
714   ├── sysbuild_test_key.conf
715   └── sysbuild
716       ├── mcuboot.conf
717       ├── mcuboot_max_log.conf
718       └── my_sample.conf
719
720* If ``FILE_SUFFIX`` is not defined and both ``mcuboot`` and ``my_sample`` images are included,
721  ``mcuboot`` will use the ``mcuboot.conf`` Kconfig fragment file and ``my_sample`` will use the
722  ``my_sample.conf`` Kconfig fragment file. Sysbuild itself will use the ``sysbuild.conf``
723  Kconfig fragment file.
724
725* If ``FILE_SUFFIX`` is set to ``max_log`` and both ``mcuboot`` and ``my_sample`` images are
726  included, ``mcuboot`` will use the ``mcuboot_max_log.conf`` Kconfig fragment file and
727  ``my_sample`` will use the ``my_sample.conf`` Kconfig fragment file (as it will fallback to the
728  file without the suffix). Sysbuild itself will use the ``sysbuild.conf`` Kconfig fragment file
729  (as it will fallback to the file without the suffix).
730
731* If ``FILE_SUFFIX`` is set to ``test_key`` and both ``mcuboot`` and ``my_sample`` images are
732  included, ``mcuboot`` will use the ``mcuboot.conf`` Kconfig fragment file and
733  ``my_sample`` will use the ``my_sample.conf`` Kconfig fragment file (as it will fallback to the
734  files without the suffix). Sysbuild itself will use the ``sysbuild_test_key.conf`` Kconfig
735  fragment file. This can be used to apply a different sysbuild configuration, for example to use
736  a different signing key in MCUboot and when signing the main application.
737
738The ``FILE_SUFFIX`` can also be applied only to single images by prefixing the variable with the
739image name:
740
741.. tabs::
742
743   .. group-tab:: ``west build``
744
745      .. zephyr-app-commands::
746         :tool: west
747         :app: file_suffix_example
748         :board: reel_board
749         :goals: build
750         :west-args: --sysbuild
751         :gen-args: -DSB_CONFIG_BOOTLOADER_MCUBOOT=y -Dmcuboot_FILE_SUFFIX="max_log"
752         :compact:
753
754   .. group-tab:: ``cmake``
755
756      .. zephyr-app-commands::
757         :tool: cmake
758         :app: share/sysbuild
759         :board: reel_board
760         :goals: build
761         :gen-args: -DAPP_DIR=<app_dir> -DSB_CONFIG_BOOTLOADER_MCUBOOT=y -Dmcuboot_FILE_SUFFIX="max_log"
762         :compact:
763
764.. _sysbuild_zephyr_application_dependencies:
765
766Adding dependencies among Zephyr applications
767=============================================
768
769Sometimes, in a multi-image build, you may want certain Zephyr applications to
770be configured or flashed in a specific order. For example, if you need some
771information from one application's build system to be available to another's,
772then the first thing to do is to add a configuration dependency between them.
773Separately, you can also add flashing dependencies to control the sequence of
774images used by ``west flash``; this could be used if a specific flashing order
775is required by an SoC, a _runner_, or something else.
776
777By default, sysbuild will configure and flash applications in the order that
778they are added, as ``ExternalZephyrProject_Add()`` calls are processed by CMake.
779You can use the ``sysbuild_add_dependencies()`` function to make adjustments to
780this order, according to your needs. Its usage is similar to the standard
781``add_dependencies()`` function in CMake.
782
783Here is an example of adding configuration dependencies for ``my_sample``:
784
785.. code-block:: cmake
786
787   sysbuild_add_dependencies(IMAGE CONFIGURE my_sample sample_a sample_b)
788
789This will ensure that sysbuild will run CMake for ``sample_a`` and ``sample_b``
790(in some order) before doing the same for ``my_sample``, when building these
791domains in a single invocation.
792
793If you want to add flashing dependencies instead, then do it like this:
794
795.. code-block:: cmake
796
797   sysbuild_add_dependencies(IMAGE FLASH my_sample sample_a sample_b)
798
799As a result, ``my_sample`` will be flashed after ``sample_a`` and ``sample_b``
800(in some order), when flashing these domains in a single invocation.
801
802.. note::
803
804   Adding flashing dependencies is not allowed for build-only applications.
805   If ``my_sample`` had been created with ``BUILD_ONLY TRUE``, then the above
806   call to ``sysbuild_add_dependencies()`` would have produced an error.
807
808Adding non-Zephyr applications to sysbuild
809******************************************
810
811You can include non-Zephyr applications in a multi-image build using the
812standard CMake module `ExternalProject`_. Please refer to the CMake
813documentation for usage details.
814
815When using ``ExternalProject``, the non-Zephyr application will be built as
816part of the sysbuild build invocation, but ``west flash`` or ``west debug``
817will not be aware of the application. Instead, you must manually flash and
818debug the application.
819
820.. _MCUboot with Zephyr: https://docs.mcuboot.com/readme-zephyr
821.. _ExternalProject: https://cmake.org/cmake/help/latest/module/ExternalProject.html
822
823.. _sysbuild_var_override:
824
825Configuring sysbuild internal state
826***********************************
827
828Because sysbuild is a CMake project in it's own right, it runs and sets up itself similar to a
829Zephyr application but using it's own CMake code. This means that some features, for example
830specifying variables in an application ``CMakeLists.txt`` (such as ``BOARD_ROOT``) will not work,
831instead these must be set by using a :ref:`a module <modules_build_settings>` or by using a custom
832sysbuild project file as ``<application>/sysbuild/CMakeLists.txt``, for example:
833
834.. code-block:: cmake
835
836   # Place pre-sysbuild configuration items here
837
838   # For changing configuration that sysbuild itself uses:
839   # set(<var> <value>)
840   # list(APPEND <list> <value>)
841
842   # For changing configuration of other images:
843   # set(<image>_<var> <value> CACHE INTERNAL "<description>")
844
845   # Finds the sysbuild project and includes it with the new configuration
846   find_package(Sysbuild REQUIRED HINTS $ENV{ZEPHYR_BASE})
847
848   project(sysbuild LANGUAGES)
849
850An example of adding a ``BOARD_ROOT``:
851
852.. code-block:: cmake
853
854   list(APPEND BOARD_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../<extra-board-root>)
855
856   find_package(Sysbuild REQUIRED HINTS $ENV{ZEPHYR_BASE})
857
858   project(sysbuild LANGUAGES)
859
860This will pass the board root on to all images as part of a project, it does not need to be
861repeated in each image's ``CMakeLists.txt`` file.
862
863Extending sysbuild
864******************
865
866Sysbuild can be extended by other modules to give it additional functionality
867or include other configuration or images, an example could be to add support
868for another bootloader or external signing method.
869
870Modules can be extended by adding custom CMake or Kconfig files as normal
871:ref:`modules <module-yml>` do, this will cause the files to be included in
872each image that is part of a project. Alternatively, there are
873:ref:`sysbuild-specific module extension <sysbuild_module_integration>` files
874which can be used to include CMake and Kconfig files for the overall sysbuild
875image itself, this is where e.g. a custom image for a particular board or SoC
876can be added.
877
878
879.. toctree::
880    :maxdepth: 1
881
882    images.rst
883