Commit graph

153 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Torsten Rasmussen
4e29a35b22 cmake: use GLOBAL property instead TARGET properties for scoping
Targets are not available in script mode.
To support the Zephyr scoping feature used by snippets and yaml module
then this commit moves from using custom targets to use GLOBAL
properties for scopes.

A scope property is prefixed with `<scope>:<property>` to avoid naming
collisions.
A `scope:<scope-name>` global property is used to track created scopes.
Tracking valid scopes ensure that properties are only set on known
scopes and thus catches typos / naming errors.

Add zephyr_scope_exists() and zephyr_get_scoped() to abstract the
implementation details of the scoped property retrieval and refactor
current code to use them.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2024-12-26 09:31:11 +01:00
TOKITA Hiroshi
624e051372 linker: devicetree_regions: Add support memory region flag setting
Add `zephyr,memory-region-flags` for supporting memory region flags
setting.

For example, when the below node is in the devicetree,

```
    test_sram: sram@20010000 {
        compatible = "zephyr,memory-region", "mmio-sram";
        reg = < 0x20010000 0x1000 >;
        zephyr,memory-region = "FOOBAR";
        zephyr,memory-region-flags = "rw";
    };
```

We get the following line in MEMORY section of linker script.

```
FOOBAR (rw) : ORIGIN = (0x20010000), LENGTH = (0x1000)
```

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
2024-12-05 06:39:46 -05:00
Daniel DeGrasse
0ea212918f cmake: extensions: use INTERFACE_SOURCES as property for code relocation
In order to enable code relocation, we use a custom target
(code_data_relocation_target), and add files we wish to relocate, as
well as which sections should be relocated to the COMPILE_DEFINITIONS
property for the target.

This approach has been fragile, because COMPILE_DEFINITIONS can also be
added to for all targets using `add_definitions`. This means if another
part of the project uses `add_definitions` and
CONFIG_CODE_DATA_RELOCATION is on, a warning will appear about the
"file" not being found. The "file" of course, is just the definition
added by `add_definitions`.

To work around this, switch to overloading the INTERFACE_SOURCES
property. This property should be a bit more robust, because nobody else
will add sources to the code_data_relocation_target.

However, this approach has the downside that the CMake documentation
pstates targets created with `add_custom_target()` (which the
code_data_relocation_target is) do not have an INTERFACE scope for
their sources- so while this approach works, it is not officially
supported by CMake

Fixes #60220

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2024-11-16 13:35:36 -05:00
Torsten Rasmussen
a5cd46b843 cmake: support PATH argument in build_info()
Support PATH argument in build_info() function.
The PATH argument can be used to provide a list of paths paths and that
those paths might be using native style, such as `c:\win\path', and
therefore should be converted to CMake style path.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-10-10 20:21:45 -04:00
Torsten Rasmussen
5d5c2d4775 cmake: introduce build_info function
The build_info function provides a generic and stable way of dumping
build information to the <build>/build_info.yml file.

The build info file is in YAML format and the keys in the file are
intended to be stable, as to allow external tools to retrieve
information regarding the build.

The main differences to the CMakeCache.txt are:
- Settings in the CMakeCache.txt are user controlled, whereas the
  information in the build info file is intended to be those values
  which are used by the build system regardless if those are specified
  by the developer or picked up automatically.
- Internal build system variables are not present in the CMake cache
  and should not be, because their values are calculated when CMake
  runs.

This also has the benefits of decoupling CMake variable names from
build info keys. Several CMake variables has internal build system
names, and the build system is free to rename those at its own
discretion.

Having dedicated key names ensures a stable API that external tools can
rely upon.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-10-08 17:00:30 +02:00
Torsten Rasmussen
daac2d55ab cmake: move script mode handling from package helper to extensions.cmake
Move Zephyr CMake script mode handling from package_helper.cmake into
extensions.cmake.

This ensures that all Zephyr CMake script which includes
extensions.cmake will have the same functions stubbed or mocked and thus
does not need to replicate this behavior.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-10-08 17:00:30 +02:00
Torsten Rasmussen
102b3fc078 cmake: make TARGET optional in set_linker_property()
The `check_set_linker_property()` and `set_linker_property()` takes a
target argument. Make the target argument optional and use the target
`linker` as default target.

The function name `set_linker_property()` already implies that we are
setting a property and the linker target.

Remove the need to specify `TARGET linker` when using the default linker
property target.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-10-04 16:34:35 +01:00
Torsten Rasmussen
718b726b37 cmake: PROPERTY flag support on compile options and link libraries
Extend zephyr_link_libraries to allow an optional value together with
the `zephyr_link_libraries(PROPERTY <property> [<value>])`.

This allow setting linker property combined with a value when linking
Zephyr. The value will only be applied if the property is defined.

Extend zephyr_compile_options to support the same PROPERTY flag that
has been introduced for zephyr_link_libraries().
This remove the need for developers to write complex generator
expressions for compiler flags and thus minimizes mistakes.

The following syntax is now supported in addition to the existing
syntax: `zephyr_compile_options(PROPERTY <property> [<value>])`

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-10-04 16:34:35 +01:00
Torsten Rasmussen
2e3873adde cmake: improve Zephyr link phase
Zephyr is a bare metal build where standard libs are disabled.

This means that c and runtime libraries must manually be linked in.

This has generally been handled by using CMake's link libraries handling
but the issue with that is both de-duplication but also library link
order.

Standard libraries must be linked at last location to ensure symbols
are always available, however this is not optimal with
target_link_libraries() because this would ultimately require every
library to know the c library to link with, which is not desired.

Therefore, setup standard C and runtime library linking in linker
CMake files for toolchains where this is required.

This commit expands the principle introduced with toolchain abstraction,
see PR#24851.

This means that a toolchain implementation may specify standard C,
runtime, C++, etc libraries, as well as their link order.
Because a property approach is used, then Zephyr modules, such as the
Picolibc module can adjust such properties.

An optional `zephyr_linker_finalize()` macro is called at the end of
Zephyr's CMakeList process and can be used by the toolchain
implementation to define the final linker invocation.

This aligns the linker handling flow to the principle introduced in
PR#24851 and improves the flexibility and robustness of Zephyr build
system.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-10-04 16:34:35 +01:00
David van Rijn
96386eac0b cmake: Add REQUIRED option to devicetree getters
namely:
 - dt_nodelabel
 - dt_alias
 - dt_prop

these currently fail quietly.
This can cause some very confusing errors later on.
By adding `REQUIRED` to the function call one can
easily generate a more clear message:

    required nodelabel not found: ...

Signed-off-by: David van Rijn <david@refractor.dev>
2024-09-17 17:49:07 +01:00
Anas Nashif
a87eec570a cmake: Add board emulator extension functions
Adds new CMake extension functions that allow setting board-specific
emulator arguments, similar to existing support for setting
board-specific runner arguments.

Originally authored by: Maureen Helm

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-09-12 14:49:21 +02:00
Torsten Rasmussen
d63489195f cmake: support PROPERTY argument on zephyr_link_libraries.
To ease the use of linker flag properties and to simplify the use of
generator expression then an optional PROPERTY argument has been added
to the zephyr_link_libraries() function.

This means a call such as:
zephyr_link_libraries($<TARGET_PROPERTY:linker,<property-name>)
can instead be simplified to:
zephyr_link_libraries(PROPERTY <property-name>)

Thus making intention clearer and keeping the complexity and minimizes
the risk of typos when writing generator expressions.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-09-04 21:26:59 +02:00
Torsten Rasmussen
1728e04b8c cmake: fix check_set_linker_property() function
Fix check_set_linker_property() to correctly handle multiple linker
flags passed on function call.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-09-04 21:26:59 +02:00
Torsten Rasmussen
9da2766846 cmake: add check_arguments_... macro to facilitate function writing
Add a new zephyr_check_arguments_required_allow_empty() macro for
function argument validation.

Zephyr already has a zephyr_check_arguments_required() for checking
required arguments, like
zephyr_check_arguments_required(foo_func <prefix> FOO BAR)
which ensures that one of FOO or BAR are given in a call like:
foo_func(BAR val)

One limitation however, is that is some cases BAR may be allowed to be
empty, so that it's still possible to know if FOO or BAR were supplied.
In most case, BAR and FOO will have values following the keyword, like:
foo_func(BAR my_bar_val)
foo_func(FOO my_foo_val)

but in cases where `my_bar_val` is a variable which may be empty, like:
set(my_bar_val)
foo_func(BAR ${my_bar_val}) # (expands to: foo_func(BAR)

then BAR was actually supplied.
To support functions where such empty expansion is allowed, then a new
helper macro `zephyr_check_arguments_required_allow_empty()` has been
implemented, as to be able to distinguish `foo_func()` from
`foo_func(BAR)` when parsing arguments.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-08-23 08:02:11 -04:00
Mathieu Choplain
662b9803fa llext: disable verbose for SLID generation scripts
This commit removes the "-vvv" argument from the SLID generation
scripts' command line when building Zephyr or an extension with
Kconfig CONFIG_LLEXT_EXPORT_BUILTINS_BY_SLID enabled. This removes
a lot of noise in the build log (usually ~250 lines) and is fine to
do because the printed information is also saved in build artifacts.

Signed-off-by: Mathieu Choplain <mathieu.choplain@st.com>
2024-07-09 17:21:18 +02:00
Jamie McCrae
11c1f3de61 cmake: modules: extensions: Fix dts watch file processing
Fixes and simplifies the handling of how the dts watch file is
processed

Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2024-06-25 06:05:52 -04:00
Jamie McCrae
f4cfb8cd96 cmake: modules: extension: Fix dts file watch
Fixes an issue in the code that processes the output file of a
compiler to see which files should be watched, the compiler can
combine multiple files into a single line instead of putting them
each on separate lines if the length of the file paths is short,
therefore account for this and split it up into multiple elements

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2024-06-25 06:05:52 -04:00
Jordan Yates
07870934e3 everywhere: replace double words
Treewide search and replace on a range of double word combinations:
    * `the the`
    * `to to`
    * `if if`
    * `that that`
    * `on on`
    * `is is`
    * `from from`

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-06-22 05:40:22 -04:00
Pieter De Gendt
99366dd2be linker: Add ROM_SECTIONS location
Currently iterable sections as per the documentation are added with
zephyr_linker_sources(SECTIONS ...) after bss/noinit.
This commit allows putting sections after common-rom.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-06-20 12:08:58 -04:00
Luca Burelli
baa3b6a5ba llext: disable LL_EXTENSION_SYMBOL when not building an llext
The LL_EXTENSION_SYMBOL macro is used to export a symbol to the base
image. When CONFIG_LLEXT is not defined, or the file is being compiled
outside of an llext, the macro is not useful and would leave orphan
sections in the final image instead.

This patch adds the LL_EXTENSION_BUILD definition to the llext build
process, and uses it to stub out the symbol-defining macro when not
building an llext.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2024-06-14 19:24:51 +02:00
Mathieu Choplain
8aa6ae43ce llext: add support for SLID-based linking
This commit introduces support for an alternate linking method in the
LLEXT subsystem, called "SLID" (short for Symbol Link Identifier),
enabled by the CONFIG_LLEXT_EXPORT_BUILTINS_BY_SLID Kconfig option.

SLID-based linking uses a unique identifier (integer) to identify
exported symbols, instead of using the symbol name as done currently.
This approach provides several benefits:
 * linking is faster because the comparison operation to determine
   whether we found the correct symbol in the export table is now an
   integer compare, instead of a string compare
 * binary size is reduced as symbol names can be dropped from the binary
 * confidentiality is improved as a side-effect, as symbol names are no
   longer present in the binary

Signed-off-by: Mathieu Choplain <mathieu.choplain@st.com>
2024-06-03 15:29:34 -04:00