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 :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 146Configuration namespacing 147************************* 148 149When building a single Zephyr application without sysbuild, all CMake cache 150settings and Kconfig build options given on the command line as 151``-D<var>=<value>`` or ``-DCONFIG_<var>=<value>`` are handled by the Zephyr 152build system. 153 154However, when sysbuild combines multiple Zephyr build systems, there could be 155Kconfig settings exclusive to sysbuild (and not used by any of the applications). 156To handle this, sysbuild has namespaces for configuration variables. You can use these 157namespaces to direct settings either to sysbuild itself or to a specific Zephyr 158application managed by sysbuild using the information in these sections. 159 160The following example shows how to build :ref:`hello_world` with MCUboot enabled, 161applying to both images debug optimizations: 162 163.. tabs:: 164 165 .. group-tab:: ``west build`` 166 167 .. zephyr-app-commands:: 168 :tool: west 169 :app: samples/hello_world 170 :board: reel_board 171 :goals: build 172 :west-args: --sysbuild 173 :gen-args: -DSB_CONFIG_BOOTLOADER_MCUBOOT=y -DCONFIG_DEBUG_OPTIMIZATIONS=y -Dmcuboot_CONFIG_DEBUG_OPTIMIZATIONS=y 174 :compact: 175 176 .. group-tab:: ``cmake`` 177 178 .. zephyr-app-commands:: 179 :tool: cmake 180 :app: share/sysbuild 181 :board: reel_board 182 :goals: build 183 :gen-args: -DAPP_DIR=samples/hello_world -DSB_CONFIG_BOOTLOADER_MCUBOOT=y -DCONFIG_DEBUG_OPTIMIZATIONS=y -Dmcuboot_CONFIG_DEBUG_OPTIMIZATIONS=y 184 :compact: 185 186See the following subsections for more information. 187 188.. _sysbuild_cmake_namespace: 189 190CMake variable namespacing 191========================== 192 193CMake variable settings can be passed to CMake using ``-D<var>=<value>`` on the 194command line. You can also set Kconfig options via CMake as 195``-DCONFIG_<var>=<value>`` or ``-D<namespace>_CONFIG_<var>=<value>``. 196 197Since sysbuild is the entry point for the build system, and sysbuild is written 198in CMake, all CMake variables are first processed by sysbuild. 199 200Sysbuild creates a namespace for each domain. The namespace prefix is the 201domain's application name. See :ref:`sysbuild_zephyr_application` for more 202information. 203 204To set the variable ``<var>`` in the namespace ``<namespace>``, use this syntax:: 205 206 -D<namespace>_<var>=<value> 207 208For example, to set the CMake variable ``FOO`` in the ``my_sample`` application 209build system to the value ``BAR``, run the following commands: 210 211.. tabs:: 212 213 .. group-tab:: ``west build`` 214 215 .. code-block:: shell 216 217 west build --sysbuild ... -- -Dmy_sample_FOO=BAR 218 219 .. group-tab:: ``cmake`` 220 221 .. code-block:: shell 222 223 cmake -Dmy_sample_FOO=BAR ... 224 225.. _sysbuild_kconfig_namespacing: 226 227Kconfig namespacing 228=================== 229 230To set the sysbuild Kconfig option ``<var>`` to the value ``<value>``, use this syntax:: 231 232 -DSB_CONFIG_<var>=<value> 233 234In the previous example, ``SB_CONFIG`` is the namespace prefix for sysbuild's Kconfig 235options. 236 237To set a Zephyr application's Kconfig option instead, use this syntax:: 238 239 -D<namespace>_CONFIG_<var>=<value> 240 241In the previous example, ``<namespace>`` is the application name discussed above in 242:ref:`sysbuild_cmake_namespace`. 243 244For example, to set the Kconfig option ``FOO`` in the ``my_sample`` application 245build system to the value ``BAR``, run the following commands: 246 247.. tabs:: 248 249 .. group-tab:: ``west build`` 250 251 .. code-block:: shell 252 253 west build --sysbuild ... -- -Dmy_sample_CONFIG_FOO=BAR 254 255 .. group-tab:: ``cmake`` 256 257 .. code-block:: shell 258 259 cmake -Dmy_sample_CONFIG_FOO=BAR ... 260 261.. tip:: 262 When no ``<namespace>`` is used, the Kconfig setting is passed to the main 263 Zephyr application ``my_sample``. 264 265 This means that passing ``-DCONFIG_<var>=<value>`` and 266 ``-Dmy_sample_CONFIG_<var>=<value>`` are equivalent. 267 268 This allows you to build the same application with or without sysbuild using 269 the same syntax for setting Kconfig values at CMake time. 270 For example, the following commands will work in the same way: 271 272 .. code-block:: shell 273 274 west build -b <board> my_sample -- -DCONFIG_FOO=BAR 275 276 .. code-block:: shell 277 278 west build -b <board> --sysbuild my_sample -- -DCONFIG_FOO=BAR 279 280Sysbuild flashing using ``west flash`` 281************************************** 282 283You can use :ref:`west flash <west-flashing>` to flash applications with 284sysbuild. 285 286When invoking ``west flash`` on a build consisting of multiple images, each 287image is flashed in sequence. Extra arguments such as ``--runner jlink`` are 288passed to each invocation. 289 290For more details, see :ref:`west-multi-domain-flashing`. 291 292Sysbuild debugging using ``west debug`` 293*************************************** 294 295You can use ``west debug`` to debug the main application, whether you are using sysbuild or not. 296Just follow the existing :ref:`west debug <west-debugging>` guide to debug the main sample. 297 298To debug a different domain (Zephyr application), such as ``mcuboot``, use 299the ``--domain`` argument, as follows:: 300 301 west debug --domain mcuboot 302 303For more details, see :ref:`west-multi-domain-debugging`. 304 305Building a sample with MCUboot 306****************************** 307 308Sysbuild supports MCUboot natively. 309 310To build a sample like ``hello_world`` with MCUboot, 311enable MCUboot and build and flash the sample as follows: 312 313.. tabs:: 314 315 .. group-tab:: ``west build`` 316 317 .. zephyr-app-commands:: 318 :tool: west 319 :app: samples/hello_world 320 :board: reel_board 321 :goals: build 322 :west-args: --sysbuild 323 :gen-args: -DSB_CONFIG_BOOTLOADER_MCUBOOT=y 324 :compact: 325 326 .. group-tab:: ``cmake`` 327 328 .. zephyr-app-commands:: 329 :tool: cmake 330 :app: share/sysbuild 331 :board: reel_board 332 :goals: build 333 :gen-args: -DAPP_DIR=samples/hello_world -DSB_CONFIG_BOOTLOADER_MCUBOOT=y 334 :compact: 335 336This builds ``hello_world`` and ``mcuboot`` for the ``reel_board``, and then 337flashes both the ``mcuboot`` and ``hello_world`` application images to the 338board. 339 340More detailed information regarding the use of MCUboot with Zephyr can be found 341in the `MCUboot with Zephyr`_ documentation page on the MCUboot website. 342 343.. note:: 344 345 The deprecated MCUBoot Kconfig option ``CONFIG_ZEPHYR_TRY_MASS_ERASE`` will 346 perform a full chip erase when flashed. If this option is enabled, then 347 flashing only MCUBoot, for example using ``west flash --domain mcuboot``, may 348 erase the entire flash, including the main application image. 349 350Sysbuild Kconfig file 351********************* 352 353You can set sysbuild's Kconfig options for a single application using 354configuration files. By default, sysbuild looks for a configuration file named 355``sysbuild.conf`` in the application top-level directory. 356 357In the following example, there is a :file:`sysbuild.conf` file that enables building and flashing with 358MCUboot whenever sysbuild is used: 359 360.. code-block:: none 361 362 <home>/application 363 ├── CMakeLists.txt 364 ├── prj.conf 365 └── sysbuild.conf 366 367 368.. code-block:: cfg 369 370 SB_CONFIG_BOOTLOADER_MCUBOOT=y 371 372You can set a configuration file to use with the 373``-DSB_CONF_FILE=<sysbuild-conf-file>`` CMake build setting. 374 375For example, you can create ``sysbuild-mcuboot.conf`` and then 376specify this file when building with sysbuild, as follows: 377 378.. tabs:: 379 380 .. group-tab:: ``west build`` 381 382 .. zephyr-app-commands:: 383 :tool: west 384 :app: samples/hello_world 385 :board: reel_board 386 :goals: build 387 :west-args: --sysbuild 388 :gen-args: -DSB_CONF_FILE=sysbuild-mcuboot.conf 389 :compact: 390 391 .. group-tab:: ``cmake`` 392 393 .. zephyr-app-commands:: 394 :tool: cmake 395 :app: share/sysbuild 396 :board: reel_board 397 :goals: build 398 :gen-args: -DAPP_DIR=samples/hello_world -DSB_CONF_FILE=sysbuild-mcuboot.conf 399 :compact: 400 401Sysbuild targets 402**************** 403 404Sysbuild creates build targets for each image (including sysbuild itself) for 405the following modes: 406 407 * menuconfig 408 * hardenconfig 409 * guiconfig 410 411For the main application (as is the same without using sysbuild) these can be 412ran normally without any prefix. For other images (including sysbuild), these 413are ran with a prefix of the image name and an underscore e.g. ``sysbuild_`` or 414``mcuboot_``, using ninja or make - for details on how to run image build 415targets that do not have mapped build targets in sysbuild, see the 416:ref:`sysbuild_dedicated_image_build_targets` section. 417 418.. _sysbuild_dedicated_image_build_targets: 419 420Dedicated image build targets 421***************************** 422 423Not all build targets for images are given equivalent prefixed build targets 424when sysbuild is used, for example build targets like ``ram_report``, 425``rom_report``, ``footprint``, ``puncover`` and ``pahole`` are not exposed. 426When using :ref:`Trusted Firmware <tfm_build_system>`, this includes build 427targets prefix with ``tfm_`` and ``bl2_``, for example: ``tfm_rom_report`` 428and ``bl2_ram_report``. To run these build targets, the build directory of the 429image can be provided to west/ninja/make along with the name of the build 430target to execute and it will run. 431 432.. tabs:: 433 434 .. group-tab:: ``west`` 435 436 Assuming that a project has been configured and built using ``west`` 437 using sysbuild with mcuboot enabled in the default ``build`` folder 438 location, the ``rom_report`` build target for ``mcuboot`` can be ran 439 with: 440 441 .. code-block:: shell 442 443 west build -d build/mcuboot -t rom_report 444 445 .. group-tab:: ``ninja`` 446 447 Assuming that a project has been configured using ``cmake`` and built 448 using ``ninja`` using sysbuild with mcuboot enabled, the ``rom_report`` 449 build target for ``mcuboot`` can be ran with: 450 451 .. code-block:: shell 452 453 ninja -C mcuboot rom_report 454 455 .. group-tab:: ``make`` 456 457 Assuming that a project has been configured using ``cmake`` and built 458 using ``make`` using sysbuild with mcuboot enabled, the ``rom_report`` 459 build target for ``mcuboot`` can be ran with: 460 461 .. code-block:: shell 462 463 make -C mcuboot rom_report 464 465.. _sysbuild_zephyr_application: 466 467Adding Zephyr applications to sysbuild 468************************************** 469 470You can use the ``ExternalZephyrProject_Add()`` function to add Zephyr 471applications as sysbuild domains. Call this CMake function from your 472application's :file:`sysbuild.cmake` file, or any other CMake file you know will 473run as part sysbuild CMake invocation. 474 475Targeting the same board 476======================== 477 478To include ``my_sample`` as another sysbuild domain, targeting the same board 479as the main image, use this example: 480 481.. code-block:: cmake 482 483 ExternalZephyrProject_Add( 484 APPLICATION my_sample 485 SOURCE_DIR <path-to>/my_sample 486 ) 487 488This could be useful, for example, if your board requires you to build and flash an 489SoC-specific bootloader along with your main application. 490 491Targeting a different board 492=========================== 493 494In sysbuild and Zephyr CMake build system a board may refer to: 495 496* A physical board with a single core SoC. 497* A specific core on a physical board with a multi-core SoC, such as 498 :ref:`nrf5340dk_nrf5340`. 499* A specific SoC on a physical board with multiple SoCs, such as 500 :ref:`nrf9160dk_nrf9160` and :ref:`nrf9160dk_nrf52840`. 501 502If your main application, for example, is built for ``mps2_an521``, and your 503helper application must target the ``mps2_an521_remote`` board (cpu1), add 504a CMake function call that is structured as follows: 505 506.. code-block:: cmake 507 508 ExternalZephyrProject_Add( 509 APPLICATION my_sample 510 SOURCE_DIR <path-to>/my_sample 511 BOARD mps2_an521_remote 512 ) 513 514This could be useful, for example, if your main application requires another 515helper Zephyr application to be built and flashed alongside it, but the helper 516runs on another core in your SoC. 517 518Targeting conditionally using Kconfig 519===================================== 520 521You can control whether extra applications are included as sysbuild domains 522using Kconfig. 523 524If the extra application image is specific to the board or an application, 525you can create two additional files: :file:`sysbuild.cmake` and :file:`Kconfig.sysbuild`. 526 527For an application, this would look like this: 528 529.. code-block:: none 530 531 <home>/application 532 ├── CMakeLists.txt 533 ├── prj.conf 534 ├── Kconfig.sysbuild 535 └── sysbuild.cmake 536 537In the previous example, :file:`sysbuild.cmake` would be structured as follows: 538 539.. code-block:: cmake 540 541 if(SB_CONFIG_SECOND_SAMPLE) 542 ExternalZephyrProject_Add( 543 APPLICATION second_sample 544 SOURCE_DIR <path-to>/second_sample 545 ) 546 endif() 547 548:file:`Kconfig.sysbuild` would be structured as follows: 549 550.. code-block:: kconfig 551 552 source "sysbuild/Kconfig" 553 554 config SECOND_SAMPLE 555 bool "Second sample" 556 default y 557 558This will include ``second_sample`` by default, while still allowing you to 559disable it using the Kconfig option ``SECOND_SAMPLE``. 560 561For more information on setting sysbuild Kconfig options, 562see :ref:`sysbuild_kconfig_namespacing`. 563 564Building without flashing 565========================= 566 567You can mark ``my_sample`` as a build-only application in this manner: 568 569.. code-block:: cmake 570 571 ExternalZephyrProject_Add( 572 APPLICATION my_sample 573 SOURCE_DIR <path-to>/my_sample 574 BUILD_ONLY TRUE 575 ) 576 577As a result, ``my_sample`` will be built as part of the sysbuild build invocation, 578but it will be excluded from the default image sequence used by ``west flash``. 579Instead, you may use the outputs of this domain for other purposes - for example, 580to produce a secondary image for DFU, or to merge multiple images together. 581 582You can also replace ``TRUE`` with another boolean constant in CMake, such as 583a Kconfig option, which would make ``my_sample`` conditionally build-only. 584 585.. note:: 586 587 Applications marked as build-only can still be flashed manually, using 588 ``west flash --domain my_sample``. As such, the ``BUILD_ONLY`` option only 589 controls the default behavior of ``west flash``. 590 591.. _sysbuild_application_configuration: 592 593Zephyr application configuration 594================================ 595 596When adding a Zephyr application to sysbuild, such as MCUboot, then the 597configuration files from the application (MCUboot) itself will be used. 598 599When integrating multiple applications with each other, then it is often 600necessary to make adjustments to the configuration of extra images. 601 602Sysbuild gives users the ability of creating Kconfig fragments or devicetree 603overlays that will be used together with the application's default configuration. 604Sysbuild also allows users to change :ref:`application-configuration-directory` 605in order to give users full control of an image's configuration. 606 607Zephyr application Kconfig fragment and devicetree overlay 608---------------------------------------------------------- 609 610In the folder of the main application, create a Kconfig fragment or a devicetree 611overlay under a sysbuild folder, where the name of the file is 612:file:`<image>.conf` or :file:`<image>.overlay`, for example if your main 613application includes ``my_sample`` then create a :file:`sysbuild/my_sample.conf` 614file or a devicetree overlay :file:`sysbuild/my_sample.overlay`. 615 616A Kconfig fragment could look as: 617 618.. code-block:: cfg 619 620 # sysbuild/my_sample.conf 621 CONFIG_FOO=n 622 623Zephyr application configuration directory 624------------------------------------------ 625 626In the folder of the main application, create a new folder under 627:file:`sysbuild/<image>/`. 628This folder will then be used as ``APPLICATION_CONFIG_DIR`` when building 629``<image>``. 630As an example, if your main application includes ``my_sample`` then create a 631:file:`sysbuild/my_sample/` folder and place any configuration files in 632there as you would normally do: 633 634.. code-block:: none 635 636 <home>/application 637 ├── CMakeLists.txt 638 ├── prj.conf 639 └── sysbuild 640 └── my_sample 641 ├── prj.conf 642 ├── app.overlay 643 └── boards 644 ├── <board_A>.conf 645 ├── <board_A>.overlay 646 ├── <board_B>.conf 647 └── <board_B>.overlay 648 649All configuration files under the :file:`sysbuild/my_sample/` folder will now 650be used when ``my_sample`` is included in the build, and the default 651configuration files for ``my_sample`` will be ignored. 652 653This give you full control on how images are configured when integrating those 654with ``application``. 655 656.. _sysbuild_file_suffixes: 657 658Sysbuild file suffix support 659---------------------------- 660 661File suffix support through the makevar:`FILE_SUFFIX` is supported in sysbuild 662(see :ref:`application-file-suffixes` for details on this feature in applications). For sysbuild, 663a globally provided option will be passed down to all images. In addition, the image configuration 664file will have this value applied and used (instead of the build type) if the file exists. 665 666Given the example project: 667 668.. code-block:: none 669 670 <home>/application 671 ├── CMakeLists.txt 672 ├── prj.conf 673 ├── sysbuild.conf 674 ├── sysbuild_test_key.conf 675 └── sysbuild 676 ├── mcuboot.conf 677 ├── mcuboot_max_log.conf 678 └── my_sample.conf 679 680* If ``FILE_SUFFIX`` is not defined and both ``mcuboot`` and ``my_sample`` images are included, 681 ``mcuboot`` will use the ``mcuboot.conf`` Kconfig fragment file and ``my_sample`` will use the 682 ``my_sample.conf`` Kconfig fragment file. Sysbuild itself will use the ``sysbuild.conf`` 683 Kconfig fragment file. 684 685* If ``FILE_SUFFIX`` is set to ``max_log`` and both ``mcuboot`` and ``my_sample`` images are 686 included, ``mcuboot`` will use the ``mcuboot_max_log.conf`` Kconfig fragment file and 687 ``my_sample`` will use the ``my_sample.conf`` Kconfig fragment file (as it will fallback to the 688 file without the suffix). Sysbuild itself will use the ``sysbuild.conf`` Kconfig fragment file 689 (as it will fallback to the file without the suffix). 690 691* If ``FILE_SUFFIX`` is set to ``test_key`` and both ``mcuboot`` and ``my_sample`` images are 692 included, ``mcuboot`` will use the ``mcuboot.conf`` Kconfig fragment file and 693 ``my_sample`` will use the ``my_sample.conf`` Kconfig fragment file (as it will fallback to the 694 files without the suffix). Sysbuild itself will use the ``sysbuild_test_key.conf`` Kconfig 695 fragment file. This can be used to apply a different sysbuild configuration, for example to use 696 a different signing key in MCUboot and when signing the main application. 697 698The ``FILE_SUFFIX`` can also be applied only to single images by prefixing the variable with the 699image name: 700 701.. tabs:: 702 703 .. group-tab:: ``west build`` 704 705 .. zephyr-app-commands:: 706 :tool: west 707 :app: file_suffix_example 708 :board: reel_board 709 :goals: build 710 :west-args: --sysbuild 711 :gen-args: -DSB_CONFIG_BOOTLOADER_MCUBOOT=y -Dmcuboot_FILE_SUFFIX="max_log" 712 :compact: 713 714 .. group-tab:: ``cmake`` 715 716 .. zephyr-app-commands:: 717 :tool: cmake 718 :app: share/sysbuild 719 :board: reel_board 720 :goals: build 721 :gen-args: -DAPP_DIR=<app_dir> -DSB_CONFIG_BOOTLOADER_MCUBOOT=y -Dmcuboot_FILE_SUFFIX="max_log" 722 :compact: 723 724.. _sysbuild_zephyr_application_dependencies: 725 726Adding dependencies among Zephyr applications 727============================================= 728 729Sometimes, in a multi-image build, you may want certain Zephyr applications to 730be configured or flashed in a specific order. For example, if you need some 731information from one application's build system to be available to another's, 732then the first thing to do is to add a configuration dependency between them. 733Separately, you can also add flashing dependencies to control the sequence of 734images used by ``west flash``; this could be used if a specific flashing order 735is required by an SoC, a _runner_, or something else. 736 737By default, sysbuild will configure and flash applications in the order that 738they are added, as ``ExternalZephyrProject_Add()`` calls are processed by CMake. 739You can use the ``sysbuild_add_dependencies()`` function to make adjustments to 740this order, according to your needs. Its usage is similar to the standard 741``add_dependencies()`` function in CMake. 742 743Here is an example of adding configuration dependencies for ``my_sample``: 744 745.. code-block:: cmake 746 747 sysbuild_add_dependencies(IMAGE CONFIGURE my_sample sample_a sample_b) 748 749This will ensure that sysbuild will run CMake for ``sample_a`` and ``sample_b`` 750(in some order) before doing the same for ``my_sample``, when building these 751domains in a single invocation. 752 753If you want to add flashing dependencies instead, then do it like this: 754 755.. code-block:: cmake 756 757 sysbuild_add_dependencies(IMAGE FLASH my_sample sample_a sample_b) 758 759As a result, ``my_sample`` will be flashed after ``sample_a`` and ``sample_b`` 760(in some order), when flashing these domains in a single invocation. 761 762.. note:: 763 764 Adding flashing dependencies is not allowed for build-only applications. 765 If ``my_sample`` had been created with ``BUILD_ONLY TRUE``, then the above 766 call to ``sysbuild_add_dependencies()`` would have produced an error. 767 768Adding non-Zephyr applications to sysbuild 769****************************************** 770 771You can include non-Zephyr applications in a multi-image build using the 772standard CMake module `ExternalProject`_. Please refer to the CMake 773documentation for usage details. 774 775When using ``ExternalProject``, the non-Zephyr application will be built as 776part of the sysbuild build invocation, but ``west flash`` or ``west debug`` 777will not be aware of the application. Instead, you must manually flash and 778debug the application. 779 780.. _MCUboot with Zephyr: https://docs.mcuboot.com/readme-zephyr 781.. _ExternalProject: https://cmake.org/cmake/help/latest/module/ExternalProject.html 782 783Extending sysbuild 784****************** 785 786Sysbuild can be extended by other modules to give it additional functionality 787or include other configuration or images, an example could be to add support 788for another bootloader or external signing method. 789 790Modules can be extended by adding custom CMake or Kconfig files as normal 791:ref:`modules <module-yml>` do, this will cause the files to be included in 792each image that is part of a project. Alternatively, there are 793:ref:`sysbuild-specific module extension <sysbuild_module_integration>` files 794which can be used to include CMake and Kconfig files for the overall sysbuild 795image itself, this is where e.g. a custom image for a particular board or SoC 796can be added. 797