Skip to content

Commit 303c1eb

Browse files
tejlmandcarlescufi
authored andcommitted
sysbuild: support sample configuration of extra images
This commit introduces the possibility of a sample to locate configuration files for extra images that are used when building with MCUboot. This allows use-cases where a sample, A, want to include MCUboot but has adjustments to the default MCUboot configuration. By adding a Kconfig fragment `<sample>/sysbuild/mcuboot.conf`, then that fragment will be used together with the default configuration for MCUboot. It is also possible to completely replace the MCUboot configuration. This is done by creating `<sample>/sysbuild/mcuboot/` folder. This folder will then be used as the `APPLICATION_CONFIG_DIR` when building MCUboot. Signed-off-by: Torsten Rasmussen <[email protected]>
1 parent bf39f54 commit 303c1eb

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

cmake/modules/configuration_files.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ include_guard(GLOBAL)
2424

2525
include(extensions)
2626

27+
zephyr_get(APPLICATION_CONFIG_DIR)
2728
if(DEFINED APPLICATION_CONFIG_DIR)
2829
string(CONFIGURE ${APPLICATION_CONFIG_DIR} APPLICATION_CONFIG_DIR)
2930
if(NOT IS_ABSOLUTE ${APPLICATION_CONFIG_DIR})

doc/build/sysbuild/index.rst

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,69 @@ disable it using the Kconfig option ``SECOND_SAMPLE``.
484484
For more information on setting sysbuild Kconfig options,
485485
see :ref:`sysbuild_kconfig_namespacing`.
486486

487+
Zephyr application configuration
488+
================================
489+
490+
When adding a Zephyr application to sysbuild, such as MCUboot, then the
491+
configuration files from the application (MCUboot) itself will be used.
492+
493+
When integrating multiple applications with each other, then it is often
494+
necessary to make adjustments to the configuration of extra images.
495+
496+
Sysbuild gives users the ability of creating Kconfig fragments or devicetree
497+
overlays that will be used together with the application's default configuration.
498+
Sysbuild also allows users to change :ref:`application-configuration-directory`
499+
in order to give users full control of an image's configuration.
500+
501+
Zephyr application Kconfig fragment and devicetree overlay
502+
----------------------------------------------------------
503+
504+
In the folder of the main application, create a Kconfig fragment or a devicetree
505+
overlay under a sysbuild folder, where the name of the file is
506+
:file:`<image>.conf` or :file:`<image>.overlay`, for example if your main
507+
application includes ``my_sample`` then create a :file:`sysbuild/my_sample.conf`
508+
file or a devicetree overlay :file:`sysbuild/my_sample.overlay`.
509+
510+
A Kconfig fragment could look as:
511+
512+
.. code-block:: none
513+
514+
# sysbuild/my_sample.conf
515+
CONFIG_FOO=n
516+
517+
Zephyr application configuration directory
518+
------------------------------------------
519+
520+
In the folder of the main application, create a new folder under
521+
:file:`sysbuild/<image>/`.
522+
This folder will then be used as ``APPLICATION_CONFIG_DIR`` when building
523+
``<image>``.
524+
As an example, if your main application includes ``my_sample`` then create a
525+
:file:`sysbuild/my_sample/` folder and place any configuration files in
526+
there as you would normally do:
527+
528+
.. code-block:: none
529+
530+
<home>/application
531+
├── CMakeLists.txt
532+
├── prj.conf
533+
└── sysbuild
534+
└── my_sample
535+
├── prj.conf
536+
├── app.overlay
537+
└── boards
538+
├── <board_A>.conf
539+
├── <board_A>.overlay
540+
├── <board_B>.conf
541+
└── <board_B>.overlay
542+
543+
All configuration files under the :file:`sysbuild/my_sample/` folder will now
544+
be used when ``my_sample`` is included in the build, and the default
545+
configuration files for ``my_sample`` will be ignored.
546+
547+
This give you full control on how images are configured when integrating those
548+
with ``application``.
549+
487550
Adding non-Zephyr applications to sysbuild
488551
******************************************
489552

share/sysbuild/cmake/modules/sysbuild_extensions.cmake

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,39 @@ function(ExternalZephyrProject_Add)
117117
)
118118
endif()
119119

120+
set(sysbuild_image_conf_dir ${APP_DIR}/sysbuild)
121+
set(sysbuild_image_name_conf_dir ${APP_DIR}/sysbuild/${ZBUILD_APPLICATION})
122+
# User defined `-D<image>_CONF_FILE=<file.conf>` takes precedence over anything else.
123+
if (NOT ${ZBUILD_APPLICATION}_CONF_FILE)
124+
if(EXISTS ${sysbuild_image_name_conf_dir})
125+
set(${ZBUILD_APPLICATION}_APPLICATION_CONFIG_DIR ${sysbuild_image_name_conf_dir}
126+
CACHE INTERNAL "Application configuration dir controlled by sysbuild"
127+
)
128+
endif()
129+
130+
# Check for sysbuild related configuration fragments.
131+
# The contents of these are appended to the image existing configuration
132+
# when user is not specifying custom fragments.
133+
if(NOT "${CONF_FILE_BUILD_TYPE}" STREQUAL "")
134+
set(sysbuil_image_conf_fragment ${sysbuild_image_conf_dir}/${ZBUILD_APPLICATION}_${CONF_FILE_BUILD_TYPE}.conf)
135+
else()
136+
set(sysbuild_image_conf_fragment ${sysbuild_image_conf_dir}/${ZBUILD_APPLICATION}.conf)
137+
endif()
138+
139+
if (NOT ${ZBUILD_APPLICATION}_OVERLAY_CONFIG AND EXISTS ${sysbuild_image_conf_fragment})
140+
set(${ZBUILD_APPLICATION}_OVERLAY_CONFIG ${sysbuild_image_conf_fragment}
141+
CACHE INTERNAL "Kconfig fragment defined by main application"
142+
)
143+
endif()
144+
145+
# Check for overlay named <ZBUILD_APPLICATION>.overlay.
146+
set(sysbuild_image_dts_overlay ${sysbuild_image_conf_dir}/${ZBUILD_APPLICATION}.overlay)
147+
if (NOT ${ZBUILD_APPLICATION}_DTC_OVERLAY_FILE AND EXISTS ${sysbuild_image_dts_overlay})
148+
set(${ZBUILD_APPLICATION}_DTC_OVERLAY_FILE ${sysbuild_image_dts_overlay}
149+
CACHE INTERNAL "devicetree overlay file defined by main application"
150+
)
151+
endif()
152+
endif()
120153
# CMake variables which must be known by all Zephyr CMake build systems
121154
# Those are settings which controls the build and must be known to CMake at
122155
# invocation time, and thus cannot be passed though the sysbuild cache file.

0 commit comments

Comments
 (0)