437 Commits

Author SHA1 Message Date
Jamie McCrae
8312b20ca9 sysbuild: Add ability to generate slot 1 variant image
Adds a new experimental Kconfig option to sysbuild which allows
generating a variant image to use with MCUboot in direct-xip mode.
It also includes base sysbuild infrastructure for creating
additional variant images in future (including out-of-tree),
whereby they use the base configuration of an existing image but
modify it, without creating the default zephyr extra targets for
images (e.g. menuconfig) to prevent changing configuration that
should not be changed.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-01-20 15:31:06 +00:00
Benjamin Cabé
60f97b4c7c cmake: modules: boards: fix typo in "outcome" target name
The module sets a target named "boards", not "board".

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-01-15 15:27:50 +01:00
Jamie McCrae
1bbbb286b3 cmake: Remove old deprecated code
Removes code that was deprecated in Zephyr 4.0

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-01-08 09:50:19 +01:00
Jamie McCrae
c02c6add10 cmake: modules: boards: Remove deprecated HWMv1 extension handling
This code was deprecated and removed from the documentation many
releases ago, remove the feature from the code

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-01-08 09:49:56 +01:00
Ben Marsh
9476c62c80 cmake: Fix extensions module's implicit dependency on yaml module
The CMake extensions module depends on the yaml module, but extensions did
not explicitly include yaml.

When using find_package(Zephyr ...) with no components specified this
issue is not seen as zephyr_default is included which includes many other
modules, including yaml and extensions.
However, when find_package(Zephyr ... COMPONENTS ...) is used only the
components specified are included, which can result in a build error. For
example, using find_package(Zephyr ... COMPONENTS FindHostTools ...)
includes FindHostTools, which includes extensions, which depends on yaml
but doesn't include it.

This issue is fixed by including yaml in extensions.

Signed-off-by: Ben Marsh <ben.marsh@helvar.com>
2026-01-07 14:08:00 +01:00
Jamie McCrae
ecd8a4bc7c cmake: modules: hwm_v2: Skip writing output on no change
Skips updating files if the output already matches the file
contents, this prevents a random occurance whereby sysbuild
reconfigures itself after a reconfiguration for no known
discernable reason

Signed-off-by: Jamie McCrae <spam@helper3000.net>
2025-12-18 23:38:25 +01:00
Benjamin Cabé
2bfd150128 cmake: hwmv2: optimize hardware list parsing with CMake lists
Replace inefficient string parsing loop with CMake list iteration for
processing list_hardware.py output. The previous implementation used
repeated string operations on the entire output string for each line,
which is increasingly slow as hardware list grows.

Local tests show hwmv2.cmake module loading in ~350 ms instead of
540 ms on my machine.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-12-18 14:51:29 +00:00
Alberto Escolar Piedras
654535bea3 cmake: FindHostTools: Do not override cross-compile for native builds
This check is meant to be easier on users so they do not need to bother
setting ZEPHYR_TOOLCHAIN_VARIANT to "host" when building for
native_simulator based targets, so we default in that case to it.
But when somebody has actively set it to "cross-compile" we should not
override it.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-12-05 13:38:48 +02:00
Benjamin Cabé
8349a01b13 cmake: extensions: remove invalid add_dependencies
The `add_dependencies` command in CMake is used to specify dependencies
between targets - here it was used to specify a dependency on a folder,
which is not valid (and causes failures on CMake 4.2 when using
the cmake-file-api).

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-11-27 14:46:50 +01:00
Torsten Rasmussen
18594c217c cmake: remove quotes around SUBALIGN
Quotes around `"SUBALIGN ${SUBALIGN}"` results in the parameters to
become a text string with a space, and therefore will give the warning

> CMake Warning at /.../extensions.cmake:5197 (message):
>  zephyr_linker_section(NAME ...) given unknown arguments: SUBALIGN 4
> Call Stack (most recent call first):
>   /.../extensions.cmake:5333 (zephyr_linker_section)
>   /.../CMakeLists.txt:x (zephyr_iterable_section)

Remove the quotes so that `SUBALIGN` and the value are correctly treated
as argument name and value.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2025-11-24 17:31:51 +01:00
Jamie McCrae
cebdb0d1ec cmake: modules: boards: Fix board moved check
Fixes checking for board folders that have moved by checking if
the BOARD_DIR variable is already set (i.e. loaded from cache)

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-11-18 08:09:49 -05:00
Josuah Demangeon
bf9c3b150d style: cmake: apply coding style on CMakeLists.txt files
Apply the CMake style guidelines to all CMakeList.txt files in cmake/.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-11-17 13:48:03 -05:00
Jamie McCrae
2b52c91c06 cmake: modules: version: Check that required fields are present
Will throw an error showing what the issue with the VERSION file
is if a required field is missing

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-11-13 23:16:02 +02:00
Jamie McCrae
6be751a2ed cmake: Remove HWMv1 checks
Removes checks for HWMv1 as the code for HWMv1 was removed from
Zephyr some time ago and these checks are not needed

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-11-13 23:09:55 +02:00
Anas Nashif
303af992e5 style: fix 'if (' usage in cmake files
Replace with 'if(' and 'else(' per the cmake style guidelines.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-10-29 11:44:13 +02:00
Luca Burelli
e4fa6a8f61 traceconfig: add target to export value origin traces to Markdown
The new 'traceconfig' target generates a Markdown file listing all
configuration symbols, their values, and where those values originated
(user assignment, default, selection, implication, or unset).

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-10-22 18:34:49 +03:00
Jukka Rissanen
5795b51ece cmake: extensions: Fix compliance errors
Change "if ()" to "if()" so that CI compliance checker passes.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-10-16 12:15:47 -04:00
Daniel Leung
e8a66d57db linker: add a way to add snippets to text section
This adds a way to add to the text section via
zephyr_linker_sources(TEXT_SECTIONS <...>).

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-10-06 20:16:31 -04:00
Torsten Rasmussen
ddb9e3fae6 cmake: use zephyr_file_copy(...) instead of file(COPY_FILE ...)
`file(COPY_FILE ...)` is from CMake 3.21.
Zephyr still supports CMake 3.20, so use zephyr_file_copy(...)
instead of `file(COPY_FILE ...)`.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2025-10-02 21:58:40 +02:00
Fabio Baltieri
3232354456 cmake: unittest: set -Wshadow
Set -Wshadow when compiling unit tests, this way we can test macro
combinations and ensure they don't generate shadowed variables, which
would generate a warning by default in normal Zephyr builds.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2025-09-26 13:24:30 +02:00
Jamie McCrae
dc56fb2e69 cmake: Use temp. for edt pickle CMake output
This potentially fixes an issues whereby when sysbuild projects
import dts configuration from images and images are reconfigured,
that sysbuild will needlessly rerun even if the output has not
changed by using a temporary output file and then only updating
the actual file if the contents have changed

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-09-23 09:41:28 +01:00
Jamie McCrae
f624525f30 kconfig: Load Kconfig env file better
Loads this file in a better way that means samples and modules
should not have to source the file before referencing Kconfig
module path variables

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-09-12 13:19:56 +02:00
Kesavan Yogeswaran
493ce8efa6 cmake: Merge extra Zephyr modules from multiple sources
Extra Zephyr modules can be provided via the EXTRA_ZEPHYR_MODULES CMake
list variable. Previously, if this variable were set in multiple places
(e.g. local CMake variable, cache variable set via -D, environment
variable), Zephyr will pick one source based on zephyr_get's documented
hierarchy and ignore the others.

Add the MERGE keyword when EXTRA_ZEPHYR_MODULES is read so that the list
of Zephyr modules is merged from all sources if this variable is set in
multiple places.

An example where this can be useful is when integrating additional Zephyr
modules with a vendor's Zephyr-based application whose build system already
contains usage of EXTRA_ZEPHYR_MODULES.

Signed-off-by: Kesavan Yogeswaran <hikes@google.com>
2025-09-10 22:38:41 -04:00
Aaron Wisner
f7dbf5f800 build-system: Replace ~ when creating library names from path
Bazel likes to use '~` in path of external repos.

Signed-off-by: Aaron Wisner <aaronwisner@gmail.com>
2025-09-10 10:12:16 +02:00
Jamie McCrae
4977c5cef9 scripts/kconfig/cmake: Generate/use env file for zephyr module paths
Adds a output env file that lists the paths of zephyr modules
which can be used in Kconfig files and uses this in Kconfig. Also
updates Kconfig doc output to generate and use this

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-09-03 11:03:40 +02:00
Jamie McCrae
ea9815ff34 scripts: zephyr_module: Add variable with module path
Adds a variable that has the path of the module directory, this
is supplied as an argument when running cmake normally but is
not supplied when running the check compliance script, this
addition allows checks to be ran that use such syntax in Kconfig
files. This is then removed from cmake as the python file handles
it instead

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-08-20 12:05:41 +02:00
Keith Packard
d77b58aacb cmake: Delay computation of linker paths until needed
With inclusion of the optimization flag into the multilib selection
process, we cannot compute the compiler library path when the compiler's
target.cmake is processed as LINKER_OPTIMIZATION_FLAG is not computed until
much later.

Instead, add a function (compiler_file_path) which can be used to locate
the appropriate crtbegin.o and crtend.o files.

Delay computation of lib_include_dir and rt_library until after all
compiler flags have been computed by adding compiler_set_linker_properties
and calling that just before toolchain_linker_finalize is invoked.

Place default implementations of both of these functions in a new file,
cmake/compiler/target_template.cmake, where we assume the compiler works
like gcc or clang and handlers the --print-file-name and
--print-libgcc-file-name options. Compilers needing alternate
implementations can override these functions in their target.cmake files.

These implementations require that no generator expressions are necessary
for the compiler to compute the right library paths.

This mechanism is also used to take any additional compiler options by
adding a new (optional) linker function,
toolchain_linker_add_compiler_options, which maps compiler options to
equivalent linker options, discarding any that aren't applicable.

Signed-off-by: Keith Packard <keithp@keithp.com>
2025-08-13 22:13:24 -04:00
Lauren Murphy
69a3ed2753 llext: replace stripping script with call to zephyr sdk strip
Replace custom stripping script with a call to Zephyr SDK strip.

Signed-off-by: Lauren Murphy <lauren.murphy@intel.com>
2025-08-01 19:36:59 +01:00
Lauren Murphy
92db7bcf11 llext: compile llext with arc mwdt on nsim vpx5
Allow users to compile LLEXTs with the MetaWare Design Toolchain.
Provides utility to dramatically shrink bloated extensions by removing
unused section names left behind by MWDT strip. Test extensions will
not fit in NSIM VPX5 memory otherwise; each is reduced from ~16k to ~1k.

Signed-off-by: Lauren Murphy <lauren.murphy@intel.com>
2025-08-01 19:36:59 +01:00
Nick Brook
d7fb46ac04 cmake: Merge in DTS_ROOT from sysbuild
Merging in DTS_ROOT from sysbuild allows applications to specify a custom
DTS_ROOT path for the application via sysbuild.

Signed-off-by: Nick Brook <nrbrook@gmail.com>
2025-07-30 17:34:39 -04:00
Serhiy Katsyuba
7dbde64738 cmake: llext: Fix llext incremental build
Before this commit, building llext packages with a `POST_BUILD` step added
via `add_llext_command()` only worked for from-scratch builds (tested with
Ninja).

When the client CMake script called `add_llext_command()` to add a custom
`POST_BUILD` step, `has_post_build_cmds` was set to 1, and a `true` (do
nothing) command was executed instead of `copy` for the `llext_pkg_input`
target. Consequently, the timestamp of `llext_pkg_input` was not updated.
Before executing `llext_proc_target`, Ninja seems to check the timestamp
of `llext_pkg_input`. When the custom command added by
`add_llext_command()` generated a new `llext_pkg_input`, Ninja was unaware
that `llext_pkg_input` had been updated, and the dependent
`llext_pkg_output` was not executed. Building only worked if
`llext_pkg_input` was missing, i.e., only for from-scratch builds.

The fix replaces dependencies so the command for `llext_pkg_input` is
executed after `llext_proc_target` (after `llext_proc_target` may generate
a new `llext_pkg_input`).

Signed-off-by: Serhiy Katsyuba <serhiy.katsyuba@intel.com>
2025-07-30 17:21:53 -04:00
Luca Burelli
83b9577f38 west build: display closest matching board names on error
This commit modifies the 'west build' command to display the closest
matching boards when an invalid board is specified, making it easier
for users to find a typo in the used board name.

The user is also instructed to run 'west boards' if he wants to get
the full list of available boards.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-07-30 06:11:09 -04:00
Joakim Andersson
12fdde6694 cmake: kconfig: Add APP_DIR to kconfig environment
Add APP_DIR as a kconfig environment variable.

This is useful in cases where you want to set a config path relative to
the directory of the application.

An example of this is how many sysbuild.cmake files sets the source
directory like this:

ExternalZephyrProject_Add(
  APPLICATION remote
  SOURCE_DIR ${APP_DIR}/remote
  BOARD ${SB_CONFIG_REMOTE_BOARD}
)

The same however cannot be done in Kconfig.sysbuild:

config NETCORE_IMAGE_PATH
    default "${APP_DIR}/<image_path>" if NETCORE_ABC

Instead they must use ZEPHYR_MY_MODULE_MODULE_DIR, however not all
applications are part of a zephyr module.

Signed-off-by: Joakim Andersson <joerchan@gmail.com>
2025-07-08 13:40:34 -05:00
Benjamin Cabé
f672cb72d4 Revert "doc: ci: Zephyr now requires Python 3.12 or higher"
This reverts commit 043bb58488.

Note that  scripts/requirements-actions.txt might not be 100% the same
as what was pinned prior to the revert due to it being difficult to
restore previous versions while also accounting for the new dependencies
that were added in the meantime.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-07-04 15:50:06 -05:00
Benjamin Cabé
33d6061fe7 Revert "doc: correct python minimum required"
This reverts commit c68d0b9630.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-07-04 15:50:06 -05:00
Tu Nguyen Van
c68d0b9630 doc: correct python minimum required
Fixes #92059

Update getting started guide, migration-guide and
python.cmake to use Python 3.12.1 as minimum supported
version

Signed-off-by: Tu Nguyen Van <tu.nguyenvan@nxp.com>
2025-06-27 09:15:42 -10:00
Pieter De Gendt
ba905d045b cmake: extensions: Check no arguments are given to zephyr_library
The zephyr_library macro does not expect any arguments, add a check for
that and similar for zephyr_library_named for no unexpected additional
arguments.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2025-06-27 10:59:22 +02:00
Pieter De Gendt
775696c297 cmake: extensions: Add macro helper for functions to have no arguments
Add zephyr_check_no_arguments that macros and functions can call to check
that no arguments are given.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2025-06-27 10:59:22 +02:00
Guennadi Liakhovetski
a3089c1ffc llext: xtensa: strip the .xtensa.info section
.xtensa.info section isn't large so it was ignored in the beginning,
but its contents can differ depending on the build platform even if
the sources and the toolchain are the same. Strip the section to
restore binary reproducibility.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
2025-06-19 13:59:15 +02:00
Benjamin Cabé
043bb58488 doc: ci: Zephyr now requires Python 3.12 or higher
Update getting started guide, release notes, CI actions and
Python version compliance check to use Python 3.12 as
minimum supported version.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-06-19 13:56:59 +02:00
Richard Hughes
3c97bf1014 cmake: kconfig: regenerate .config when Kconfig sources are updated
The existing logic caused a regeneration when any of the .conf files
changed, but modifying the Kconfig files can also cause the .config file
to become out of date e.g. by adding a new config option or by changing
the default value of a config option (when that default is not
overridden by a .conf).

Without this change, an incremental build wouldn't pick up the new value
and would require the user to notice that and manually do a clean build.

Signed-off-by: Richard Hughes <rhughes@xilinx.com>
2025-06-18 09:08:52 -04:00
Richard Hughes
3aaa68faad cmake: kconfig: rename variable to correct naming convention
Variables used only internally in the module should have lowercase
names.

Signed-off-by: Richard Hughes <rhughes@xilinx.com>
2025-06-18 09:08:52 -04:00
Keith Packard
ff8b24b6bd cmake/modules: Make SUBALIGN parameter to zephyr_iterable_sections optional
Most uses of this macro should *not* include SUBALIGN as that can reduce
the alignment requirement for data and cause unaligned access faults in
the processor. Leave support for this in place in case there are
still uses for it.

Signed-off-by: Keith Packard <keithp@keithp.com>
2025-06-17 16:06:21 +02:00
Kesavan Yogeswaran
d5fc087690 cmake: Fix warning if a Zephyr library is created in app-mode
zephyr_append_cmake_library attempts to warn the user if a user calls it
to create a Zephyr library while the build is in application mode. At
that stage of the build, the list of Zephyr libraries has already been
processed so the function is effectively a no-op.

This heuristic used to determine if the build was in kernel mode or
application mode checked for the presence of the zephyr_prebuilt target.
This check was broken by a previous commit that renamed this target.

This commit fixes the heuristic by checking for the zephyr_pre0 target.

This was tested by calling zephyr_append_cmake_library from some
application build files, building the application, and seeing the
warning only for the call I added. No warnings were printed for any
Zephyr internal libraries.

Link: https://github.com/zephyrproject-rtos/zephyr/pull/35887
Link: https://github.com/zephyrproject-rtos/zephyr/pull/39959

Signed-off-by: Kesavan Yogeswaran <hikes@google.com>
2025-06-09 15:02:01 -07:00
Luca Burelli
8e765b78a2 cmake: add_llext_target: fix command expansion
This fixes the invocation of the 'elfconvert' and 'slid_inject' commands
in the `add_llext_target` function by ensuring that the arguments are
expanded correctly before passing them to the shell.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-06-06 11:52:31 +02:00
Björn Bergman
01d3316810 linker generator: Handle .last_section
Add  cmake linker generator things for .last_section.

Follow up to #88970. Fixes bug #89719, for gcc/ld & iar

Signed-off-by: Björn Bergman <bjorn.bergman@iar.com>
2025-05-26 14:17:21 +02:00
Benjamin Cabé
66fda826e1 shields: scripts: cmake: use list_shields.py in shields.cmake
The logic to "guess" shield names/dirs was duplicated between
list_shields.py (which is used by e.g. west shields) and shields.cmake.
This commit moves the logic to list_shields.py, and updates
shields.cmake to call the script and process its JSON output.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-05-23 17:19:58 +02:00
Grzegorz Swiderski
da197fe9ef sysbuild: Import image devicetrees
Make the image devicetrees available to sysbuild for advanced use cases.

This is done by calling `zephyr_dt_import` on each image target. The DT
target properties are all expected to be prefixed with `DT_`, so there
should be no conflicts.

Thus, the DT contents of a given `<image>` can be retrieved using e.g.:

    dt_nodelabel(<var> NODELABEL <label> TARGET <image>)

as noted in `extensions.cmake`.

Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
2025-05-22 13:44:18 +02:00
Grzegorz Swiderski
7cddb2a5e5 cmake: extensions: Add TARGET arguments to the dt_* API
The CMake dt_* API is backed by target properties. By default, it uses
the target named `devicetree_target` that is initialized in `dts.cmake`.

We should be able to customize this, now that we have a function for
loading those properties into a different target. For example:

    zephyr_dt_import(EDT_PICKLE_FILE /path/to/edt.pickle TARGET target)

    dt_nodelabel(node NODELABEL label TARGET target)

This would make it possible to reference multiple devicetrees in the
same build system, particularly sysbuild.

Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
2025-05-22 13:44:18 +02:00
Grzegorz Swiderski
468db18389 cmake: modules: Add zephyr_dt_import
Extract the part of `dts.cmake` that invokes `gen_dts_cmake.py`, then
generalize it into a CMake extension, which can be reused by sysbuild.

The Python script itself is also updated, so that the generated CMake
file can accept an input variable DEVICETREE_TARGET, which comes from
the `zephyr_dt_import(TARGET ...)` argument.

Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
2025-05-22 13:44:18 +02:00