Commit graph

1784 commits

Author SHA1 Message Date
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
Luca Burelli
162cdcb454 llext-edk: refact: move file generation into functions
This commit refactors the code that generates the Makefile and CMake
EDK files into functions that accept the file type as an argument.

No functional changes are introduced in this commit.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-02-07 17:45:45 +01:00
Luca Burelli
aa8a617c3b llext-edk: refact: do not mix code and function definitions
Prepare the current code so that functions come before actual code.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-02-07 17:45:45 +01:00
Luca Burelli
7fa1fb7181 cmake: support generator expressions in build_info()
This patch enables support for genexes in the 'build_info()' function by
identifying when arguments contain them and passing the GENEX flag to
'yaml_set()'.

Genexes are not supported in tag lists; using them will immediately
trigger an error by the schema checks.

They are also not currently supported with PATH entries, because the
actual contents of the list (whose paths are to be converted) are not
known until after the CMake code has been processed.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-02-07 17:45:45 +01:00
Luca Burelli
8e66848418 cmake: yaml: use APPEND PROPERTY to shorten code
Use a more concise way to append to a list property, as suggested in a
previous PR review.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-02-07 17:45:45 +01:00
Lauren Murphy
f0eb7ebc83 llext: arc: enforce bitness match
Enforces bitness match of ARC compilers and linkers invoked
building LLEXT apps by inheriting -mcpu flag from Zephyr.
The ARC toolchain becomes confused without the -mcpu flag.
On qemu_hs5x we see GCC select elf32-littlearc64 for
linking an object previously compiled as elf64-littlearc64.

Fixes #80949

Signed-off-by: Lauren Murphy <lauren.murphy@intel.com>
2025-02-05 21:01:01 +01:00
Filip Kokosinski
ee07eba569 arch/riscv: add Zaamo and Zlrsc extension subsets
The Zaamo and Zalrsc Extension (Version v1.0.0, 2024-04-25; Ratified) split
the standard A extension into two subextensions. As of date, the `_zaamo`
and `_zlrsc` extension specifications are accepted by the upstream
in-development GCC through the `march` argument. This means that those
subextensions are not yet supported by GCC shipped with Zephyr SDK.

Signed-off-by: Filip Kokosinski <fkokosinski@antmicro.com>
2025-02-05 17:49:13 +01:00
Robin Kastberg
dac75f5ecb cmake: linker_script: move ztest to ROM
It seems ZTEST has been moved to ROM in
86cadf9 and this keeps linker generator
up to date. It is also causing some
issues with IAR toolchain where pbits
are being placed in RAM.

Signed-off-by: Robin Kastberg <robin.kastberg@iar.com>
2025-02-05 14:56:54 +01:00
Jamie McCrae
763a49f082 cmake: Remove build type
Build type was deprecated in Zephyr 3.6, it was replaced with
FILE_SUFFIX support

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-01-30 16:19:57 +01:00
Luca Burelli
cdc7f05cc9 cmake: yaml: add support for generator expressions
This commit adds support for generator expressions in values and lists
to the yaml module.

Generator expressions can only be expanded by CMake after all
configuration code has been executed and the final values of the project
properties are defined. This means that contexts that contain generator
expressions are written twice:

 - immediately, during the 'yaml_save()' call, a comment with the raw
   unexpanded string is saved instead of the key that uses generator
   expressions in the YAML file;

 - after the configuration step, a custom command updates the YAML file
   contents with the fully expanded values.

This two-step process also allows to overcome the issue of lists that
are extracted from generator expressions, whose elements would be
expanded into a single string if written directly to the YAML file.
Instead, the lists are stored in their CMake string format with a
special marker, expanded by CMake into a temporary JSON file, and the
conversion to a proper list is performed during the build step.

If the saved YAML file for context <name> is needed by further build
steps in this project, the target '<name>_yaml_saved' must be added as a
dependency to ensure the final contents are ready.

Note that when generator expressions are used in the context, the GENEX
keyword must be provided to yaml_set(). This is necessary to avoid
storing the genexes as raw strings in the YAML.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-01-30 14:10:53 +01:00
Luca Burelli
cf5607fb01 cmake: yaml: refactor yaml_set() list operations
This introductory commit refactors the `yaml_set` function separating
the bodies of list operations into internal functions while preserving
their original behavior.

The conditions that cause the value to be interpreted as a list are also
verified only once, avoiding multiple checks.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-01-30 14:10:53 +01:00
Luca Burelli
487f86183a cmake: llext: avoid always compiling extensions
In CMake, unless explicitly disabled, the 'add_library()' and
'add_executable()' functions add their result to the ALL target.

This is undesirable for 'add_llext_target()', since it causes the source
files for all defined extensions to be compiled even when the extension
is not otherwise used by the build process.

Add 'EXCLUDE_FROM_ALL' where appropriate so that the object files are
only built when the extension is actually used by the project.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-01-29 17:55:04 +01:00
Benjamin Cabé
e547619de4 Revert "cmake: store board directories in build_info"
This reverts commit b1a27a77a2.
as it's part of a series of commits causing issues on Windows

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-01-29 09:27:31 +01:00
Benjamin Cabé
6fddb19463 Revert "cmake: support array of maps in yaml module"
This reverts commit f24f5288f3.
as it's part of a series of commits causing issues on Windows

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-01-29 09:27:31 +01:00
Benjamin Cabé
55112d658e Revert "cmake: modules: yaml: Remove debug messages"
This reverts commit 8f48758836.
as it's part of a series of commits causing issues on Windows

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-01-29 09:27:31 +01:00
Jamie McCrae
8f48758836 cmake: modules: yaml: Remove debug messages
Some debug output was accidentally  left in, this removes it

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-01-28 18:15:51 +01:00
Joel Holdsworth
46e37b00e7 compiler: gcc: Support versions predating include-fixed/limits.h
GCC versions starting from 4.3.0 until 12.4.0 stored the limits.h header in
a directory named include-fixed/ . Before 4.3.0 and after 12.4.0 i.e. from
13.1.0 onward, the header is stored in a directory named include/ .

Previously, target.cmake would only detect if the GCC version was 13.1.0 or
newer. This patch adds a check to also check if it is older than 4.3.0.

Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com>
2025-01-27 13:24:52 +01:00
Joel Holdsworth
6d63d4d904 cmake: modules/FindGnuLd: support an additional obselete version format
A legacy build of GNU ld emits the following version string:

GNU ld version 2.17.50.0.9 20070103

This patch fixes the regex parsing so that the version number is correctly
extracted from the string.

Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com>
2025-01-27 13:24:52 +01:00
Joel Holdsworth
8b59dcfd11 cmake: compiler: Check -fno-printf-return-value before using
GCC versions before 7.1.0 do not have the -fno-printf-return-value flag and
give an error if it is used. This patch improves compatibility with older
compilers by making CMake check for the flag's availability before using.

Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com>
2025-01-27 13:24:52 +01:00
Joel Holdsworth
c7bc47c60d cmake: compiler: Check -fdiagnostics-color=always before using
The -fdiagnostics-color flag is only on GCC versions 4.9.0 and newer.
Previously, CMake only checked that the compiler was not the XCC compiler
before using the flag.

However, given that the flag us unavailable on compilers other than XCC,
e.g. old versions of GCC, this patch replaces the previous logic with a
flag-check using the check_set_compiler_property() CMake function.

Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com>
2025-01-27 13:24:52 +01:00
Torsten Rasmussen
f24f5288f3 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-01-27 13:24:23 +01:00
Torsten Rasmussen
b1a27a77a2 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-01-27 13:24:23 +01:00
Luca Burelli
8660020205 llext: group LLEXT output files in a subdirectory
LLEXT-related files are currently scattered in multiple locations in the
build directory. For easier access, this patch groups the outputs in a
subdirectory named 'llext' at the root of the build binaries, alongside
the 'zephyr' directory. This directory will thus contain the generated
debug ELF and the final .llext file for each compiled extension.

Note that this does not affect out-of-tree projects that use LLEXT,
since they already pass the full LLEXT file path to add_llext_target().

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-01-27 08:54:44 +01:00
Luca Burelli
5b66af8adb llext: build with debug info, strip at packaging time
This patch changes the way extensions are built to allow for debugging
information to be collected. Debug flags are now used when compiling and
linking the extension source code, generating a debuggable ELF file.
The final .llext file is then stripped of unneeded symbols, including
all debugging information, at packaging time.

The debugging flag is still removed from the EDK-exported flags.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-01-27 08:54:44 +01:00
Luca Burelli
dda8d776ab cmake: bintools: add --strip-unneeded flag to elfconvert
This flag is used by LLEXT to strip all unreferenced symbols and
debugging information from a binary.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-01-27 08:54:44 +01:00
Pieter De Gendt
ab26ecce6e linker: iterable_section: Allow numeric sorting up to 5 numeric characters
This allows using a uint16_t value to sort iterable sections.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2025-01-22 10:40:45 +01:00
Nick Brook
4c1275d63a cmake: Added "-" support to EXTRAVERSION
cmake: Added "-" support to EXTRAVERSION.
Added to the regex and update the documentation.
Also updated the examples in the documentation.

Signed-off-by: Nick Brook <nrbrook@gmail.com>
2025-01-21 15:13:36 +01:00