Commit graph

1860 commits

Author SHA1 Message Date
Björn Bergman
acdd816bdb cmake: linker generator: Add MIN/MAX_SIZE to zephyr_linker_section()
Add MIN_SIZE and MAX_SIZE options to zephyr_linker_section()
and zephyr_linker_section_configure().
This allows padding (for MIN_SIZE) and link-time checking (for MAX_SIZE)
of sections (and parts of sections).

Clarify comments for zephyr_linker_section_configure

Signed-off-by: Björn Bergman <bjorn.bergman@iar.com>
2025-03-27 17:17:03 +01:00
Björn Bergman
d3a88f7bfe cmake: linker generator: Handle NOT PASS and multiple PASS options
Make it possible to have multiple PASS parameters to
zephyr_linker_section() and zephyr_linker_section_configure() sections
(oring them) OR to have multiple PASS NOT p options (in which case the
sections applies in neither of the passes)

Signed-off-by: Björn Bergman <bjorn.bergman@iar.com>
2025-03-27 17:17:03 +01:00
Torsten Rasmussen
6384f28a2d cmake: support directory as argument to zephyr_library_amend()
Extend `zephyr_library_amend()` to support an optional directory
argument.
The current `zephyr_library_amend()` works well when used inside a
Zephyr module with same structure, but fails when the macro is called
from Zephyr module integration code is located in a Zephyr
`MODULE_EXT_ROOT` because in this case the CMake code being executed
is not present in the Zephyr module itself, in which case the dir name
creation based on relative to module dir give wrong result.

For this use-case then support a base directory.
This also allows for use-cases in Zephyr modules where the directory
structure matching Zephyr's own structure is placed in a sub-folder.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2025-03-26 16:26:40 +01:00
David Schneider
8b65862a83 cmake: mcuboot: Flash confirmed file if available
In case a confirmed image gets generated, it should be used during
flash process.

If there is a valid application in second image slot, flashing
*.signed.hex will result in a unconfirmed image in first slot.
After reboot MCUboot will replace the unconfirmed image by swaping
the confirmed application from the second into the first slot.

Signed-off-by: David Schneider <schneidav81@gmail.com>
2025-03-26 16:20:13 +01:00
Valerio Setti
13270a43c1 cmake: modules: dts: print error message if DTC fails
Currently stderr is printed only if dtc encounters warnings, but it's
not printed in case of errors. However this information can be useful
to quickly identify and resolve the problem.

To solve this let's add "COMMAND_ERROR_IS_FATAL ANY" to execute_process()
so that CMake will fail in case of errors and a proper message will be
printed on the output.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2025-03-24 19:33:18 +01:00
Jamie McCrae
cc453dfed8 cmake: Remove previously deprecated look-ups
Removes functions that would handle deprecated variables and
functionality from CMake within Zephyr that were deprecated in
Zephyr 3.1 onwards but before 3.7

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-03-24 07:53:31 +01:00
Tom Hughes
53f17c1d78 cmake clang/compiler_flags.cmake: Re-enable -Wsometimes-uninitialized
All warnings in the code base have been resolved.

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-03-23 13:19:27 +01:00
Lars-Ove Karlsson
4edb8af70c cmake: linker: Removed unnecessary regexp in link generator
In the linker script generator there was one error checking
construct that used regexp and that ended up in the generated
linker file, which caused parsing problems with the IAR
linker. It was unnecessary. Also updated
common-rom-kernel-devices.ld.

Signed-off-by: Lars-Ove Karlsson <lars-ove.karlsson@iar.com>
2025-03-20 21:58:14 +01:00
Fabio Baltieri
c60ffe1e1b linker: update section names to be unambiguous
Recently 0ae0c3dc44 allowed for three digit priorities, this resulted
in objects potentially matching multiple sections, for example:

.z_init_PRE_KERNEL_2_0_0_
.z_init_PRE_KERNEL_2_?_*
.z_init_PRE_KERNEL_2_???_*

This does not seem to be detected by ld, but the IAR linker emits a
warning.

Add some extra qualifiers in the object section name to make it
unambiguous, this has the extra value of making it easier to interpret,
for example going from:

.z_init_POST_KERNEL_90_00012_

to

.z_init_POST_KERNEL_P_90_SUB_00012_

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2025-03-20 12:20:55 -04:00
Josh DeWitt
0ae0c3dc44 linker: Allow for 999 priority levels in init levels
Some projects may have needs for more than 99 priority levels, so add
a third linker input section for each obj level.

Signed-off-by: Josh DeWitt <josh.dewitt@garmin.com>
2025-03-19 18:53:22 -04:00
Josh DeWitt
0f46359cbf linker: Add underscore between the init level and priority
Ensure the priority is surrounded by underscores for clarity. This makes
sections show up as
z_init_PRE_KERNEL_1_0_0_ instead of
z_init_PRE_KERNEL_10_0_

Signed-off-by: Josh DeWitt <josh.dewitt@garmin.com>
2025-03-19 18:53:22 -04:00
Lars-Ove Karlsson
bd278514e7 cmake: Fix warning levels for IAR
Rewrote the warning levels for toolchain IAR as IAR tools just turn
off warnings, not on. Also did some minor cleanup for coding
guidelines.

Signed-off-by: Lars-Ove Karlsson <lars-ove.karlsson@iar.com>
2025-03-19 10:57:41 +01:00
Lars-Ove Karlsson
22c04bdc66 cmake: linker: Add support for shared sw isr to link file gen
The link file generator didn't have support for
.gnu.linkonce.shared_sw_isr_table*

Signed-off-by: Lars-Ove Karlsson <lars-ove.karlsson@iar.com>
2025-03-14 05:46:36 +01:00
Tom Hughes
4b415dfc4c cmake: modules: Refer to log file based on CMake version
Starting with cmake 3.26, the log file used for configure-time checks
has changed:

https://cmake.org/cmake/help/latest/release/3.26.html#configure-log

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-03-14 01:01:43 +01:00
Daniel Leung
4b5ceb9dd0 cmake: compiler/xt-clang: add -Wno-unknown-warning-option
xt-clang is usually based on older version of clang, and
Zephyr main targets more recent versions. Because of this,
some newer compiler flags may cause warnings where twister
would mark as test being failed. To workaround that,
add -Wno-unknown-warning-option to suppress those warnings.

Fixes #84138

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-03-14 01:01:22 +01:00
Torsten Rasmussen
7f6b3f51ef cmake: remove BUILD type in function description.
Build type was removed in 763a49f082 but
the function description was not updated accordingly.

Remove build type from the function description.

Add board qualifier as that is missing.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2025-03-13 16:58:10 +00:00
Alex Fabre
5ba659c43f sca: gcc: add support for additional analyzer options
This commit brings support for additional GCC static analyzer options
with 'GCC_SCA_OPTS=...'

Linked to discussion on 'ccache' side effect on analyzer file
generation[1]

[1] https://github.com/zephyrproject-rtos/zephyr/discussions/86196

Signed-off-by: Alex Fabre <alex.fabre@rtone.fr>
2025-03-13 16:53:26 +00:00
Torsten Rasmussen
41ac85a2c5 cmake: introduce GCC_COMPILER_VERSION variable
Introduce GCC_COMPILER_VERSION to be used in Zephyr CMake when knowledge
of the current GCC Compiler version is needed and
CMAKE_C_COMPILER_VERSION has not been defined yet.

CMAKE_C_COMPILER_VERSION is not defined until project() is called.

Signed-off-by: Torsten Rasmussen <torsten.rasmussen@nordicsemi.no>
2025-03-13 16:53:26 +00:00
Jamie McCrae
9f12f8afb2 infrastructure: Remove hwmv1 support
Removes support for the deprecated hardware model version 1

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-03-13 16:53:07 +00:00
Luca Burelli
6debfe7934 llext-edk: export board information to EDK files
Export the currently used board name and (when applicable) qualifiers
and revisions to the EDK files.  This information can be used by EDK
users who deal with multiple targets to differentiate between them.

Uses the existing 'zephyr_string' function to sanitize the strings
instead of a custom regex replace.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-03-12 19:02:45 +01:00
Luca Burelli
b1e3fa4d77 llext-edk: fix -imacros handling
The -imacros flag may be given in a number of different variations:
 - with one or two preceding dashes, and
 - separated from its argument, joined by an equals sign, or joined with
   no separator

This patch fixes the handling of the -imacros flag in the LLEXT EDK to
detect all of those options.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-03-12 19:02:45 +01:00
Lars-Ove Karlsson
8d3dcd79f4 logging: Added config to disable vla in statements
The config LOG_USE_VLA depends on that MISRA_SANE is not set.
Unfortunately the IAR toolchain can't handle vla:s inside a
statement, which the LOG_USE_VLA macro does.

I've added a new, hidden config to check if vla is ok inside
statements, SUPPORT_VLA_IN_STATEMENTS. Default is always y, but
a toolchain can override it so that VLA is not used by
Z_LOG_MSG_ON_STACK_ALLOC.

Signed-off-by: Lars-Ove Karlsson <lars-ove.karlsson@iar.com>
2025-03-11 18:55:08 +01:00
Gerard Marull-Paretas
f44a30109c device: introduce device flags
Introduce a new field to store device flags. Only device deferred init
flag has been added, replacing usage of linker hackery to know wether a
device requires initialization at boot time or not. This change will be
helpful in the near future as devices will become reference counted, so we
will need to know wether they have been initialized or not.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2025-03-10 21:32:40 +01:00
Jamie McCrae
d65de42282 cmake: mcuboot: Configure key and signature variables
Configures both of these variables so that they can contain
CMake variables which will be expanded

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-03-07 20:36:04 +01:00
Lars-Ove Karlsson
a43bca0a8c cmake: compiler: Added property flag for optimization fast
CMSIS modules dsp and nn sets the optimization flag -Ofast for their
libraries. I've now made a new compiler property optimization_fast to
avoid using ifdefs in the cmsis CMakeLists.txt files.

I've update GCC and arcmwdt (not sure if arcmwdt supports -Ofast)

Signed-off-by: Lars-Ove Karlsson <lars-ove.karlsson@iar.com>
2025-03-07 20:01:18 +01:00
Robin Kastberg
da384651ec hal: infineon: handle gcc flag
Move -Wno-array-bounds from being hardcoded to a compiler
property

Signed-off-by: Robin Kastberg <robin.kastberg@iar.com>
2025-03-07 19:56:10 +01:00
Lars-Ove Karlsson
5a1f7a58db cmake: toolchain: Removed config FP16 from IAR kconfig.default
Removed config FP16 from kconfig.default as it is set by the arch/cpu.

Signed-off-by: Lars-Ove Karlsson <lars-ove.karlsson@iar.com>
2025-02-27 13:27:20 +00:00
Björn Bergman
f70e72ae69 toolchain: iar: Fixes for iar linker generator
I have found a number of problems that shows up for CONFIG_USERSPACE,
but may ake effect even without it.

 * Output the x_init block even if x dont have any content. This is
   rather common if you have sections guarded with PASS.
 * Put KEEP on init-blocks. To circumvent peculiarities in ilink,
   the _init blocks (as well as their content) needs to be tagged
   with keep.
 * Handle noinit linker sections. zephyr_linker_section( NOINIT )
   has been ignored so far. This change fixes that and puts it as
   do not initialize { }

Signed-off-by: Björn Bergman <bjorn.bergman@iar.com>
2025-02-26 15:06:15 +01:00
Robin Kastberg
6d5dd34860 iar: toolchain: enable VLA for IAR
Currently some subsystems outside the zephyr kernel
use VLA:s such as bluetooth. We will enable it for now
in the same kind of situations as gcc.

Signed-off-by: Robin Kastberg <robin.kastberg@iar.com>
2025-02-24 15:37:07 +00:00
Jamie McCrae
04092f49aa cmake: reports: Fix file prefix for tfm/bl2
Fixes the prefix for these files to not have _report in them

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-02-24 15:36:45 +00:00
Jamie McCrae
548f6c2efe cmake: reports: Fix report targets
Fixes report targets where tfm_* and bl2_* targets wrongly
generates a footprint file by having a common target which
consists of RAM and ROM report targets

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-02-24 15:36:45 +00:00
Torsten Rasmussen
991396c54a cmake: do not double escape double quote
Do not escape single escaped quote '\"'.
A single escape quote in CMake indicates the use of literal '"'.
Escaping those results in '\\"' which is a literal '\' and a quote which
encapsulates a string.
This is a result we do not want.
Therefore, exempt the '\"' sequence from further escaping.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2025-02-24 15:35:48 +00:00
Ivar Bjerling
6230b348d6 cmake: linker_script: fix section name for .dbg_thread_info
This keeps it in sync with common-rom/common-rom-debug.ld.

Signed-off-by: Ivar Bjerling <ivar@ivarbjerling.com>
2025-02-21 15:15:31 +00:00
Torsten Rasmussen
cdbe424eca cmake: escape json input string
Escape the json input string given to `to_yaml()` function and the
content given to `yaml_set()` function.

This ensures that a string like `foo\bar` becomes `foo\\bar` during
internal CMake json processing and when written to the file it becomes
`foo\bar`.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2025-02-21 11:41:26 +00:00
Eric Ackermann
45b85bd220 llext: Disable small data sections on RISC-V
On RISC-V, GCC and possibly other compilers include small globals in
special "small data" sections like .sbss and .sdata.
This allows accessing these globals using the global pointer register
and an offset, which is faster than ordinary relocations.
Currently, llext_load does not support multiple NOBIT sections.
Thus, llext's that use both .bss and .sbss sections cannot be relocated.
Also, the global pointer cannot be used in llext's, as it does not
change when calling into or returning from an llext, making the
optimization pointless for llext.
This commit disables the use of small data sections by adding the
appropriate compiler flag when compiling llext's.
In addition to solving the aforementioned issue, this fixes llext's
test_inspect on RISC-V.

Signed-off-by: Eric Ackermann <eric.ackermann@cispa.de>
2025-02-21 11:40:44 +00:00
Björn Bergman
36a599f158 cmake: mwdt assembler option for imacros
Add the -imacros property for assembler language to compensate
for changes introduced in PR #84800.

Signed-off-by: Björn Bergman <bjorn.bergman@iar.com>
2025-02-19 14:50:17 +00:00
Lars-Ove Karlsson
4b40295e01 cmake: Always use Dwarf 4 for IAR
The IAR linker does not handle Dwarf 5 and since it uses the GCC
assembler for assembler files, we need to make sure the assembler
output uses Dwarf 4.

Signed-off-by: Lars-Ove Karlsson <lars-ove.karlsson@iar.com>
2025-02-18 18:38:41 +01:00
Robin Kastberg
9ab06ec667 toolchain: iar: Add experimental IAR support
This adds experimental support for the IAR toolchain.

Signed-off-by: Robin Kastberg <robin.kastberg@iar.com>
2025-02-14 19:12:44 +00:00
Robin Kastberg
e9a0d146cf toolchain: move some hardcoded flags to properties
Some basic flags that were hardcoded needed
to be moved to properties to be able to implement
alternative toolchains.

Signed-off-by: Robin Kastberg <robin.kastberg@iar.com>
2025-02-14 19:12:44 +00:00
Luca Burelli
c188dee334 llext-edk: add support for Zstd and Zip formats
This patch adds support for Zstd and Zip formats to the EDK generation
process. The user can now choose between XZ, Zstd, and Zip compression
and output formats for the EDK file.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-02-14 13:35:43 +01:00
Sylvain Chouleur
4454734d12 scripts: code_relocate: support section filter
One might want to select the symbols to be relocated inside a file or
a library. To do this, one can use the FILTER argument of
zephyr_code_relocate which must contain a regular expression of the
section names to be selected for relocation.

The test_function_in_sram2 test case in
`tests/application_development/code_relocation` has been updated to
verify that only one function `function_in_sram()` is relocated to ram
and that the function `function_not_relocated()` is not being relocated
when using relocation filter.

Signed-off-by: Sylvain Chouleur <sylvain.chouleur@gmail.com>
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2025-02-14 03:02:56 +01:00
Torsten Rasmussen
cb8f99ab7a cmake: code relocation setting.
With code relocation directives passed to the gen_relocate_app.py script
using generated file, then each directive can be place on individual
line in the file and thus free up the `|` character as separator.

Furthermore, a multi-line file with each directive on separate line is
also more user-readable, making debugging easier.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2025-02-14 03:02:56 +01:00
Björn Bergman
b0e08c8262 cmake: SHELL: vs zephyr_get_compile_X_for_lang
In zephyr_get_XYZ_for_lang() functions in extensions.cmake we try to mimic
what cmake does in generation time to filter out SHELL: tags. However,
this filtering was only done for list entries that did not contain
generator expressions.

This causes broken command lines for e.g. e.g. for the kobject_hash*c
if the toolchain puts "SHELL: $<$<COMPILER_LANGUAGE:C>:some thing>"
into the options.

Signed-off-by: Björn Bergman <bjorn.bergman@iar.com>
2025-02-13 20:09:13 +01:00
Jamie McCrae
95dbbde12b cmake: mcuboot: Set encrypted header flag when key is used
Uses the clear imgtool argument to set the encrypted flag in the
header of the signed hex output, without encrypting the data. This
addresses an issue whereby the first update would swap images and
leave the swapped output in the secondary slot without encryption

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-02-13 16:43:40 +01:00
Jamie McCrae
0201683adb cmake: snippets: Add snippet help message
Adds a help message which gives details on a common issue with
snippets where the roots are not known or a snippet is applied
to multiple images

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-02-13 16:43:20 +01:00
Jamie McCrae
f80446973a cmake: reports: Add support for JSON prefix
Adds support for prefixing files with the target of bl2 or tfm

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-02-12 20:16:47 +01:00
Torsten Rasmussen
0828d0b0ef cmake: support array of maps in yaml module
This commit introduce support for maps in a yaml list.

The yaml_set() function has been extended with the following signature:
> yaml_set(NAME <name> KEY <key>...
>          [APPEND] LIST MAP <map1> MAP <map2> MAP ...
> )

where a `MAP <map>` has the form:
`MAP "<key1>: <value1>, <key2>: <value2>, ...`

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2025-02-10 15:56:52 +00:00
Torsten Rasmussen
b78c269c0b cmake: store board directories in build_info
The schema for build info already contained a `board:path` sequence tag
definition, but boards.cmake did not populate this in the generated
build_info.yml.

Fix this by correctly populating the `board:path` with list of board
directories.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2025-02-10 15:56:52 +00:00
Luca Burelli
5d3fe7e85a llext-edk: import data from build_info.yml and .config
Currently, the llext-edk.cmake script requires a number of variables to
be passed in from the main CMakeLists.txt file as arguments to be able
to customize the generated files.

To improve this rigid approach, the script is modified to read in the
following files in the build directory:

 * 'zephyr/.config', for the final set of Kconfig options used;
 * 'build_info.yml', for the cmake-related variables.

This is more flexible and also easier to maintain, as it doesn't require
manual changes to the main CMakelists.txt file when new variables need
to be referenced.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-02-07 17:45:45 +01:00
Luca Burelli
701f5797fc llext-edk: merge target-specific file generation
This commit removes all CMake- or Makefile-specific variables from the
code and instead uses a single list for each type of flag. Where a
difference is needed between the two, a special marker is used.
These markers are replaced later in the target-specific area of the
write functions.

Escaping of problematic characters is also added to the write functions,
to ensure that quotes and backslashes in the flags are properly handled.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-02-07 17:45:45 +01:00