Commit graph

1784 commits

Author SHA1 Message Date
Björn Bergman
1e1f94405f toolchain: iar: Fix sections placed at address
zephyr_linker_section(... ADDRESS 0xF00) was broken. The fixed
placement was using their parent group address.

This also removes some dead code in config_file_script.cmake that
helped confuse what is going on with fixed sections.

Signed-off-by: Björn Bergman <bjorn.bergman@iar.com>
2025-04-15 11:25:07 +02:00
Robin Kastberg
f9ec5f86fa iar: toolchain: arm: Fix FPU settings for CM55 and CM85
Currently the FPU settings for CM55 and CM85 are not complete.
This will complete them.

Signed-off-by: Robin Kastberg <robin.kastberg@iar.com>
2025-04-14 13:06:41 +02:00
Luca Burelli
0f71880001 cmake: yaml: update timestamp on intermediate file save
file(GENERATE ...) does not update the output file if the content is
unchanged. Since the metadata in build_info.yml mostly depends on the
build configuration, the timestamp of the intermediate file does not get
updated on most rebuilds, while the final file does, due to immediate
file(WRITE ...) calls. Since the latter is newer, no post-process step
is executed and the file is left with commented genexes.

Touching the intermediate file ensures that the post-process step is
performed every time, even if the content is unchanged, restoring the
expected behavior.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-04-14 13:06:30 +02:00
Luca Burelli
a90870da4c cmake: yaml: improve escaping of strings with backslashes and quotes
Switching the intermediate file format from JSON to YAML has a very
significant benefit: the file is now loaded via yaml_load(), which
internally calls Python to parse the file into the JSON format that
CMake expects. This means that the file contents are now automatically
escaped properly for JSON; it is a huge improvement over the previous
implementation, which was escaping everything given as input to
to_yaml().

With the removal of the now-redundant call in to_yaml(), escaping is
applied exactly once per value or list, when it is passed to yaml_set().
This allows to convert the logic in zephyr_string(ESCAPE ...) to a more
robust "escape everything" approach.

These changes fix the handling of strings with backslashes and different
types of quotes passed either directly or via generator expression. The
existing tests are updated to cover these cases.

Two other small changes are made in this commit:

- a small check in internal_yaml_list_append() is removed, as the same
  issue is already detected by the caller yaml_set() logic.

- the to_yaml() function is modified to initialize the YAML output
  variable at the top level, which is the expected behavior. This
  resulted in genex temp files sometimes having duplicate lines.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-04-10 10:11:47 +02:00
Luca Burelli
90aa937e3a cmake: yaml: switch to yaml for intermediate file
The intermediate file used to expand the generator expressions is now in
YAML format. This allows for a more robust handling of the data, as the
single quoted strings are a lot easier to escape: inside them every
character is a literal except for two single quotes (which intuitively
map to a literal single quote).

When saving a simple YAML file without genexes, the single quotes in
strings need to be escaped. However, doing so when saving the
intermediate file would make it harder to properly escape them later,
since it could be possible that the expansion of the generator
expressions would introduce new single quotes. For this reason, when
genexes are enabled, the escaping is now done in a single pass inside
the yaml-filter.cmake script.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-04-10 10:11:47 +02:00
Luca Burelli
4a50fbf804 cmake: yaml: properly store strings
Store strings in YAML as single-quoted entries to avoid issues with
special characters. This also fixes a quirk with the current test
suite where the quotes in the expected value are filtered out by the
YAML import.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-04-10 10:11:47 +02:00
Luca Burelli
f5b3e0adf4 cmake: extensions: (cosmetic) refactor zephyr_string()
This commit refactors the zephyr_string() function to explicitly
show that ESCAPE and SANITIZE are mutually exclusive options and
that SANITIZE joins multiple arguments into a single string before
processing it.

No functional change introduced by this commit.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-04-10 10:11:47 +02:00
Luca Burelli
cab474affe cmake: yaml: (cosmetic) avoid referring to file type in variable names
To move away from the JSON/YAML terminology, rename the variables that
refer to the intermediate files to "expanded" and "output" files.

Also, clean up a few "C-style" function calls and a typo in a variable
name in the same files.

No functional change introduced in this commit.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-04-10 10:11:47 +02:00
Ederson de Souza
c9a18fd487 mcuboot: Kconfig options for single app slot RAM loading mode
MCUboot has a configuration for single application slot RAM loading, in
which the single loader (or a hook thereof) can load an application from
an arbitrary flash location to RAM. Applications that are to be loaded
in this way need to specify, in their mcuboot header, the load address
in RAM they are meant to be loaded.

This patch adds a new Kconfig for this mode. The load address used comes
from devicetree chosen property "mcuboot,ram-load-dev", if it exists,
and if not, "zephyr,sram".

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
2025-04-08 16:12:33 +02:00
Tom Hughes
1415796bb2 cmake clang/compiler_flags.cmake: Re-enable Wunused-function for clang
All warnings in the code base have been resolved.

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-04-08 10:50:08 +02:00
Julien Racki
6d1cb00627 arch: arm: Add Cortex-A7 support
Pass the correct -mfpu and -mcpu flags to the compiler when building
for the Cortex-A7.

Signed-off-by: Julien Racki <julien.racki@st.com>
2025-04-04 09:35:03 +02:00
Torsten Rasmussen
a713f79031 cmake: fix Zephyr module ext order
MODULE_EXT_ROOT allows Zephyr modules to provide glue code for Zephyr
modules using `cmake-ext: True` and/or `kconfig-ext:True`.

A module ext root provides a `modules.cmake` file which defines
variables like: `set(ZEPHYR_FOO_CMAKE_DIR  <glue-code-path>/foo)`

It is intended that a downstream module can replace Zephyr's default
glue code, which again can be replaced further downstream.

Setting values in first modules.cmake (Zephyr's) are replaced by later
processed modules.cmake (downstream) when the setting name is identical.

Therefore the module ext root list should not be reversed, and Zephyr
itself should be placed as first entry in the list.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2025-04-03 13:16:56 +02:00
Robin Kastberg
216ff00422 cmake: linker: dont place device tree memories at absolute addresses
Avoid placing the device tree memories at an absolute address.
This avoids placing both .rom_start AND SSRAM1 at
the same address on mps2/an521/cpu0.

This seems fine according to ld (since one placement is empty)
but causes a currently non-suppressable diag_warning

Signed-off-by: Robin Kastberg <robin.kastberg@iar.com>
2025-04-03 13:15:47 +02:00
Luca Burelli
652ee91b7f llext-edk: fix BOARD_TARGET variable generation to be Zephyr-compatible
The board revision is not part of the NORMALIZED_BOARD_TARGET variable
as composed by Zephyr, so it must also not be used in the EDK exported
value to avoid mismatches. The revision is exported as a separate
variable, so it can still be used to differentiate between board
revisions.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-04-02 19:02:45 +02:00
Charles Hardin
b1775914d6 cmake: mcuboot: refactor the checks for west and the key files
As of c952f09a79 the calls to west
sign were replaced with imgtool but a lingering integration with
WEST_TOPDIR was allowed to remain which is not needed when there
are absolute paths available for the configuration. So, this
attempts to refactor the code to allow a few things

- allow a search of relative paths to application config and
  then west topdir
- only fatal error when a west workspace is needed but not found,
  so if the config is all absolute files then a west workspace is
  not required

Fixes: #86438
Signed-off-by: Charles Hardin <ckhardin@gmail.com>
2025-04-02 12:53:13 +02:00
Björn Bergman
98ac4becab iar: toolchain: Enable TOOLCHAIN_HAS_BUILTIN_FFS
icc has support for __builtin_ffs() and its friends,
but it was disabled in the toolchain files.

Signed-off-by: Björn Bergman <bjorn.bergman@iar.com>
2025-04-01 11:51:41 +02:00
Robin Kastberg
2e2e3a3894 cmake: linker_script: keep .symbol_to_keep
Update to keep in sync with common-rom-misc.ld

Signed-off-by: Robin Kastberg <robin.kastberg@iar.com>
2025-03-31 14:31:57 +02:00
Wilfried Chauveau
fa45bebccf cmake: emu: armfvp: Only add the -a argument if not already present
Some target may need to pass in the application argument. In such case
do not override it.

Signed-off-by: Wilfried Chauveau <wilfried.chauveau@arm.com>
Signed-off-by: Sudan Landge <sudan.landge@arm.com>
2025-03-31 11:30:55 +02:00
Björn Bergman
fe0b16583c cmake: linker generator: ld: Files for section input patterns
For CONFIG_USERSPACE the input from gen_app_partitions.py there is
a need to be able to specify input files as well as input sections
patterns for zephyr_linker_section_configure().  This is used for
app partitions from libraries (which generate input patterns like
foo.a:*(.data*)).

This adds documentation to zephyr_linker_section_configure() to clarify
what INPUT allows, and also adds some parsing tricks to ld_script.cmake
to properly add the file patterns when they are missing.

Signed-off-by: Björn Bergman <bjorn.bergman@iar.com>
2025-03-27 17:17:03 +01:00
Björn Bergman
9ac12b68b5 cmake: linker generator: ld: Fix alignment bug
It seems as if ld_script.cmake hasnt handled
zephyr_linker_section_configure( ALIGN ...) due to a typo
in a variable name,

Signed-off-by: Björn Bergman <bjorn.bergman@iar.com>
2025-03-27 17:17:03 +01:00
Björn Bergman
128698fd36 cmake: userspace: A stab at USERSPACE + CMAKE_LINKER_GENERATOR
All in all this makes cmake linker generator able to work for at least
most of the kernel tests and samples, on cortex m4.

Make the cmake linker generator have a file-structure more similar to
the ld-skeletons.

Add or edit groups, sections and logic to make the generator reflect
what the ld-skeletons do, esp. for kobjects and APP_SMEM, nonint and
some other details are also effected.

Use the new zephyr_linker_include_generated() and
zephyr_linker_include_var() functions to to handle
${DEVICE_API_LINKER_SECTIONS_CMAKE}, the kobject-prebuilt-*.h files and
APP_SMEM partition. Essentially the output from gen_app_partitions.py,
gen_kobject_placeholders.py.

Add ALIGN_WITH_INPUT on sections being put into DATA_REGION. This makes
the init layout work for ld.

This leverages the updates in gen_app_partitions.py to generate its
output as cmake linker generator sections too, and puts them into a
group defined in linker.cmake

Setup generator variables for alignment of APP_SMEM. Note that this does
not yet handle MPU_ALIGN which depends on the size of the section...

Fix broken k_object_assignment iterable section

Signed-off-by: Björn Bergman <bjorn.bergman@iar.com>
2025-03-27 17:17:03 +01:00
Björn Bergman
6f74d6fa90 cmake: linker generator: Functions for input from prev linker pass
Add methods for the linker-script generator to pick up information
from previus linkerpasses:
 * zephyr_linker_include_generated(FILE f.cmake [PASS X]  [KCONFIG])
   cmake-includes f.cmake in the relevant PASSes. This allows scripts
   to generate any content (e.g. sections or section configs) as if
   it was generated by the main cmake machiery. This is intended to
   cover the case of ld-script snippets generated by e.g.
   gen_app_partitions.py
   It can also parse KCconfig files to capture @CONFIG_FOO@ variables
 * @FOO[,undef:v]@ in an value or expression in the zephyr_linker_*
   inputs. This looks for a defintion of FOO (se below), and uses its
   value if found. If FOO is not defined, the whole @@ thing is left
   untouched, unless ,undef: is used, in which case v is used instead.
 * zephyr_linker_include_generated(FILE f.h [PASS x]) greps for f.h
   for #define FOO value to be accessed as @FOO@
 * zephyr_linker_include_var(VAR FOO VALUE V) allows the main
   cmake-script to set a @FOO@ variable.

Note that the #define support is VERY basic, and does not use a proper
pre-processor. It works for the current use of files generated by e.g.
gen_kobject_placeholders.py but is not a general solution.

Signed-off-by: Björn Bergman <bjorn.bergman@iar.com>
2025-03-27 17:17:03 +01:00
Björn Bergman
8382d67a9b cmake: linker generator: Refactor generator input file creation
Move creation of the generator arguments file from each target.cmake
into a function (zephyr_linker_generate_linker_settings_file).

Signed-off-by: Björn Bergman <bjorn.bergman@iar.com>
2025-03-27 17:17:03 +01:00
Björn Bergman
0b40dfa013 cmake: linker generator: ld: Implement MIN/MAX_SIZE for sections in ld
Implement the MIN_SIZE and MAX_SIZE options for the ld linker file
generator

Signed-off-by: Björn Bergman <bjorn.bergman@iar.com>
2025-03-27 17:17:03 +01:00
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