The zephyr_library macro does not expect any arguments, add a check for
that and similar for zephyr_library_named for no unexpected additional
arguments.
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
Add zephyr_check_no_arguments that macros and functions can call to check
that no arguments are given.
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
.xtensa.info section isn't large so it was ignored in the beginning,
but its contents can differ depending on the build platform even if
the sources and the toolchain are the same. Strip the section to
restore binary reproducibility.
Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Most uses of this macro should *not* include SUBALIGN as that can reduce
the alignment requirement for data and cause unaligned access faults in
the processor. Leave support for this in place in case there are
still uses for it.
Signed-off-by: Keith Packard <keithp@keithp.com>
zephyr_append_cmake_library attempts to warn the user if a user calls it
to create a Zephyr library while the build is in application mode. At
that stage of the build, the list of Zephyr libraries has already been
processed so the function is effectively a no-op.
This heuristic used to determine if the build was in kernel mode or
application mode checked for the presence of the zephyr_prebuilt target.
This check was broken by a previous commit that renamed this target.
This commit fixes the heuristic by checking for the zephyr_pre0 target.
This was tested by calling zephyr_append_cmake_library from some
application build files, building the application, and seeing the
warning only for the call I added. No warnings were printed for any
Zephyr internal libraries.
Link: https://github.com/zephyrproject-rtos/zephyr/pull/35887
Link: https://github.com/zephyrproject-rtos/zephyr/pull/39959
Signed-off-by: Kesavan Yogeswaran <hikes@google.com>
This fixes the invocation of the 'elfconvert' and 'slid_inject' commands
in the `add_llext_target` function by ensuring that the arguments are
expanded correctly before passing them to the shell.
Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>