The syscall generation phase parses all header files to look
for potential syscalls, and emits all the relevant files to
enable syscalls. However, this results in all the syscall
marshalling functions being included in the final binary.
This is due to these functions being referred to inside
the dispatch list, resulting in ineffective garbage
collection during linking. Previous commits allows each
drivers and subsystems to specify which header files
containing syscalls are relevant. So this commit changes
the syscall generation to only include the syscalls needed
for the build in the syscall dispatch list and removing
various bits related to that. This allows the linker to
garbage collect unused syscall related function, and thus
reducing final binary size.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This adds a new cmake function zephyr_syscall_header() which
will be used in the future to limit the scope of syscalls
in the built binary. Currently this is just an empty stub
so that add zephyr_syscall_header() to kernel, subsys, etc.
without breaking the build.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
As of today MWDT toolchain in case of Zephyr may use few
tools from GNU toolchain - GNU compiler for DTS preprocessing
and objcopy for section renaming.
Currently we were trying to find any GNU compiler & objcopy
which start to cause compatibility issues for new targets -
i.e. not every objcopy knows new ARC targets.
Let's use ARC GNU tools from Zephyr SDK as we still usually
require it when building with MWDT for other tools like DTC
(device tree compiler)
Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
Fixes an issue with relative paths both with and without using
sysbuild where they would not be updated properly or a warning
would previously be emitted.
Signed-off-by: Torsten Rasmussen <torsten.rasmussen@nordicsemi.no>
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
Fixes: #57139
Snippets provides the possibility of defining EXTRA_DTC_OVERLAY_FILE and
EXTRA_CONF_FILE in snippets.
Snippets must co-exist with existing infrastructure of
EXTRA_DTC_OVERLAY_FILE and EXTRA_CONF_FILE, and a user specifying a
snippet must be able to specify extra files for adjusting the snippet.
This means that if the following is specified:
`-DSNIPPET=some_snippet -DEXTRA_CONF_FILE=extra.conf`
then `extra.conf` may contain adjustments to the snippet.
Similar to sysbuild. Imagine a sysbuild controlled image uses a default
snippet for building, by ensuring that any extra
`-D<image>_EXTRA_CONF_FILE=extra.conf` arguments takes precedence over
the snippet we allow users to make adjustments if they need.
This commit introduces a snippets scope where snippet scoped variables
can be set with `zephyr_set()` and then `zephyr_get()` will take the
snippet scoped variables into consideration before returning.
Adjust calls to `zephyr_get(EXTRA_DTC_OVERLAY_FILE)` and
`zephyr_get(EXTRA_CONF_FILE)` to use `MERGE` to ensure all scopes are
considered.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
zephyr_get() supports multiple scopes when returning variables.
Variables are returned based on the scope's priority.
To facilitate creation of more scopes in Zephyr for variable handling
additional functions are introduced.
- zephyr_create_scope(<scope>)
creates a new scope
- zephyr_set(<var> <val>... SCOPE <scope>)
set the value of a variable in the specified scope.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Adding the possibility to have the list returned in reversed order when
using `zephyr_get(... MERGE).
`zephyr_get(... MERGE)` creates a list which populates the content based
on variable settings in the following scopes, in this order:
sysbuild, cache, environment, local.
This works well for lists where content first in list has highest
precedence, such as ROOTs settings.
However, for settings where the value last in the list will overwrite
values earlier in the list, we want the list to be reversed, examples
of such can be CONF_FILE, OVERLAY_CONFIG, DTC_OVERLAY_FILE, where the
content of the file last in the list will overrule the content from an
earlier file.
So to ensure that a DTC_OVERLAY_FILE defined as cache takes precedence
over an env or local scope variable the possibility of reversing the
list must be available.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit introduces an internal FORCE_CONF_FILE CMake setting which
allows higher order build systems to generate a configuration file
which will always take precedence.
This means that in case a user tries to change any setting to be
different than the defined value in the FORCE_CONF_FILE provide file(s),
then a warning will be printed and the setting will be reset to the
value given in the FORCE_CONF_FILE file.
Example of such warning:
<path>/.config.sysbuild:1: warning: BOOTLOADER_MCUBOOT
(defined at Kconfig.zephyr:766) set more than once.
Old value "n", new value "y".
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Align Zephyr modules with other user facing variables where settings
can be defined or extended, meaning Zephyr modules now supports:
ZEPHYR_MODULES and EXTRA_ZEPHYR_MODULES.
Support for ZEPHYR_EXTRA_MODULES is kept foir backward compatibility.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit introduces EXTRA_DTC_OVERLAY_FILE.
This allows users to specify additional devicetree overlays in addition
to a sample / board specific default devicetree overlay files.
It also allows snippets to provide extra devicetree overlays on addition
to sample / board specific overlays.
The name EXTRA_DTC_OVERLAY_FILE clearly indicates the purpose and
follows the naming scheme of EXTRA_ in front of variable name.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit introduces EXTRA_CONF_FILE and deprecates OVERLAY_CONFIG.
It has often caused confusion that OVERLAY_CONFIG adds extra
configuration fragments to the value of CONF_FILE (default: prj.conf),
but the similar named variable DTC_OVERLAY_FILE replaces the default
dtc overlay file used by the build system.
To remove such confusion, this commit introduces the EXTRA_ prefix in
front of CONF_FILE to clearly indicate it's purpose.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit extends zephyr_get() to support multiple variable names to
be fetched into a single variable.
Example:
zephyr_get(FOO VAR FOO_A FOO_B FOO_C)
will lookup each FOO_A, FOO_B, FOO_C for supported scopes and return
the value in FOO of the first scope encountered having one of the
variables defined.
If MERGE is specified, then all scopes for all vars are looped and the
variable values are merged into FOO and returned.
This functionality will allow to deprecate user-facing settings while
ensuring that both the new and deprecated variables are considered
in zephyr_get() and also taking into consideration the scope with
highest precedence.
This allows Zephyr CMake to do:
zephyr_get(FOO VAR FOO DEPRECATED_FOO)
zephyr_get(BAR MERGE VAR BAR DEPRECATED_BAR)
This allows support of old and new setting for a given number of
releases.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Also add a comment in each file reminding to keep them the same.
Fixes 251f269e23 ("west: v0.14.0 is required now (and soon, v1.1")
Confusing error message before this commit:
```
-- Found west (found suitable version 0.13.1, minimum required is 0.7.1)
CMake Error at SOF/zephyr/cmake/modules/zephyr_module.cmake:77 (message):
Traceback (most recent call last):
File "SOF/zephyr/scripts/zephyr_module.py", line 733, in <module>
main()
File "SOF/zephyr/scripts/zephyr_module.py", line 678, in main
west_projs = west_projects()
^^^^^^^^^^^^^^^
File "SOF/zephyr/scripts/zephyr_module.py", line 536, in west_projects
from west.configuration import MalformedConfig
ImportError: cannot import name 'MalformedConfig'
from 'west.configuration'
(west/src/west/configuration.py)
```
Clearer error message after this commit:
```
CMake Error at SOF/zephyr/cmake/modules/west.cmake:68 (message):
The detected west version, 0.13.1, is unsupported.
The minimum supported version is 0.14.0.
Please upgrade with:
/usr/bin/python3.11 -m pip install --upgrade west
```
Signed-off-by: Marc Herbert <marc.herbert@intel.com>
This configures the KCONFIG_ROOT variable to perform variable
substitution, this allows external applications/modules to supply
variables for this when will then be correctly used.
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
Adds a Kconfig option which controls the version of the application
to use when the image is signed using imgtool.
When an application VERSION file is present, the default value will be
identical to the application version, else it will be 0.0.0+0, but a
project may still decide another value, if it so prefers.
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Generalize the VERSION and version.h generation so that the same
infrastructure can be reused for generating other version related
header files, such as an application version header.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Fixes a string comparison which is missing quotes, this works
on the first invocation but fails on the second if quotes are
not present.
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
Add a new flag to zephyr_iterable_section, NUMERIC, that configures
sorting to be numeric (up to 2 digits), that is, 2 comes before e.g. 10.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
The 2c98a001a4 (#57597) cause
regression with ARC MWDT toolchain.
Restore CREATE_OBJ_LEVEL wildcard pattern to be suitable for
both GNU and MWDT toolchains. We return asterisk symbol which
was dropped in 2c98a001a4
(but keep rest of the changes to wildcard pattern).
Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
When the optional env_suffix_${env_var} was not set, USER_CACHE_DIR was
slightly malformed and had double slashes,
e.g. /home/user/.cache//zephyr.
To fix it string(JOIN ...) is used, which only sets slashes when
necessary.
Signed-off-by: Manoel Brunnen <mb@lee-brunnen.de>
This fixes a minor issue in sysbuild, where `-DOVERLAY_CONFIG=...` would
be applied not only to the main application, but also sysbuild itself.
This was incorrect, because sysbuild imports a different Kconfig tree
than normal Zephyr builds, so the same Kconfig fragment file would not
necessarily be valid for both.
This adds a new variable SB_OVERLAY_CONFIG to resolve this ambiguity.
It functions along the lines of SB_CONF_FILE, with both being sysbuild-
specific versions of existing variables.
To ensure that OVERLAY_CONFIG is still passed on to the main application
verbatim, its value is now loaded in `configuration_files.cmake`, rather
than `kconfig.cmake`. This is because the former file is not imported by
sysbuild, and it is where the related variables, such as CONF_FILE and
DTC_OVERLAY_FILE, are loaded as well.
Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
Fixes an issue where variables like BOARD_ROOT would be provided
to sysbuild but would then be lost on target images.
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
Cleanup RAM layout so that the RAM_REGION is now in the RAM memory
region. Put .bss in RAM_REGION.
This means we have a proper program header for the RAM region.
As part of this extend zephyr_linker_symbol to allow it to take
an OBJECT paramater to specify the region to associate a symbol to.
Signed-off-by: Kumar Gala <kumar.gala@intel.com>
For developers ease, let's try to find the simulator
thru west if the environment variables that tell where
the simulator is are not set.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Switch from using a generator expression to computing the value with a
conditional so that it is available during the execution of kconfig instead
of only being available while generating the build script.
Signed-off-by: Keith Packard <keithp@keithp.com>
Due to many layers of indirections (Github Actions, Docker scripts, SOF
build scripts, etc.), thesofproject/sof/pull/7452's first attempt to
turn off VLAs ended up setting `-DSPARSE=gar bage`:
west build ... -- '-DSPARSE=y -DCONFIG_LOG_USE_VLA=n'
Quoting issues are typical when trying to pass parameters through too
many layers of indirections. In this case, the mistake set the $SPARSE
variable to the 'y -DCONFIG_LOG_USE_VLA=n' garbage which printed this
confusing and time-consuming error message:
Setting SPARSE=y -DCONFIG_LOG_USE_VLA=n is deprecated.
Worse: this enabled sparse (!) while silently ignoring the garbage
trailing after "y".
1. Enable sparse only when $SPARSE is equal to "y" and nothing
else. This stops enabling sparse when `-DSPARSE=gar bage` which draws
more attention to the warning and gives a little more incentive to
leave the deprecated option behind. Don't make any difference between
the "n" and "gar bage" values because $SPARSE is deprecated so not
worth that much CMake code.
2. Add quotes in the deprecation message to make garbage values more
obvious, now:
Setting SPARSE='y -DCONFIG_LOG_USE_VLA=n' is deprecated.
Fixes: 60196ca112 ("cmake: sparse: deprecate old sparse support")
Signed-off-by: Marc Herbert <marc.herbert@intel.com>
This function allows subsystems to define libraries which get added to the
link command after all other libraries and modules. It's useful when using
a toolchain library, like libc or libgcc, as those can get added when
processing the 'lib' directory, before any module libraries and hence might
not get used to resolve symbols from modules.
Signed-off-by: Keith Packard <keithp@keithp.com>
Follow-up fixes to 64c7f50229
("cmake: extensions: fix zephyr_dt_preprocess() CPP handling") that
weren't urgent enough for the hotfix, or didn't get noticed:
- error out on missing CPP argument again (this regression was
introduced in 64c7f50229)
- use a UNIX manpage style argument arity format (formatting issues
were present when the function was introduced)
- fix incorrect signature comment: the CPP arguments are the
preprocessor and its arguments, not CMAKE_DTS_PREPROCESSOR
(this was present when the function was introduced)
Fixes: 64c7f50229
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This option argument needs to be able to accept a list of arguments.
One use case is the way CMAKE_DTS_PREPROCESSOR is set in
cmake/compiler/armclang/generic.cmake.
Reported-by: Kumar Gala <kumar.gala@intel.com>
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Cache the property GNULD_LINKER_IS_BFD between cmake invocations.
It is observed that, in repeated builds (2nd time and later),
this property becomes true even for non-bfd compatible linker.
So cache it to avoid any surprises.
Fixes#56501
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
Tighten up the interface boundaries by adding an extension function
that separates *how* we preprocess the DTS from *what* DTS files we
are preprocessing. This involves a functional change to the pre_dt
module.
This is useful cleanup but is also groundwork for relying on this
helper function when adding system devicetree support.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This list processing procedure will be useful elsewhere, so prep for
not repeating ourselves. Put it in a new zephyr_list() function whose
signature has room to grow if we keep adding list processing
extensions.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
When the build system was being split up into modules under
cmake/modules, most of the resulting cmake modules had their inputs
and outputs documented in top-of-file comments. The dts module is an
exception, which makes it harder to use since its contracts aren't
defined. Fix this by adding a contract.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Create a separate module that sets up all our devicetree handling, by
setting up common variables that would apply to any and all DT
processing. This is then included in the regular dts module that we
include in zephyr_default.cmake.
The separation of this code from dts.cmake is groundwork for enabling
system devicetree in Zephyr, which will need the same definitions
included into its scope.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Due to Hyrum's Law, there are users out in the wild depending on this
directory existing to place their own generated files, so it'd break
things unnecessarily to not do this if we don't have a DTS, as
explained in a source code comment.
However, this doesn't really have anything to do with DTS processing,
so split it into its own module to separate concerns. This isn't
really a CMake module in the usual sense of something that defines
functions you can use, and is therefore a form of technical debt. The
decision was made to accept this because fixing this is a larger task
for the files in cmake/modules/, since there are multiple other
examples of this in here.
This also paves the way for inserting another module in between the
generated_file_directories and dts modules that itself depends on
these directories existing.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
The name of each commented section should match the name in the "table
of contents", for consistency and so people can jump from contents to
implementations more easily with their editors' search functions.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
device_extern.h was still generated with an #error directive, not really
useful was it was never designed to be included directly, but via
device.h.
Fixes#56425
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
Fixes: #56235
Changes to the Zephyr VERSION file is not picked up by CMake and thus
not picked up by Kconfig which may rely on the KERNELVERSION setting.
Fix this by setting CMAKE_CONFIGURE_DEPENDS on the Zephyr VERSION file.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This adds a new output variable to FindGnuLd.cmake to indicate
if ld.bfd is found. Since we now ask the compilers for their
preferred ld.bfd linker, it may not match using the existing
string equal test to ${CROSS_COMPILE}ld.bfd. So set the new
variable GNULD_LINKER_IS_BFD to true if ld.bfd, and use it to
pass an extra argument to compiler to make it use ld.bfd.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This asks the clang if it has its own preference for ld.lld.
This is to mirror what we are doing to find GNU ld, and to
make sure we are using the linker clang is using.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This asks the compiler if it has its own preference for ld.bfd.
This is useful for LLVM (when CONFIG_LLVM_USE_LD=y) so we know
which linker clang is using.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This introduces a new cmake module FindGnuLd.cmake to do
the work to discover GNU ld (of binutils).
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
When checking that modules contain a file `modules/modules.cmake`,
the CMake file only actually checked for the existence of the module
root, not the `modules/modules.cmake` file inside of it.
Signed-off-by: Pete Dietl <pete.dietl@worldcoin.org>
Add a new script, snippets.py, which is responsible for searching
SNIPPET_ROOT for snippet definitions, validating them, and informing
the build system about what needs doing as a result.
Use this script in snippets.cmake to:
- validate any discovered snippet.yml files
- error out on undefined snippets
- add a 'snippets' build system target that prints all snippet
names (analogous to 'boards' and 'shields' targets)
- handle any specific build system settings properly,
by include()-ing a file it generates
With this patch, you can define or extend a snippet in a snippet.yml
file anywhere underneath a directory in SNIPPET_ROOT. The snippet.yml
file format has a schema whose initial definition is in a new file,
snippet-schema.yml.
This initial snippet.yml file format supports adding .overlay and
.conf files, like this:
name: foo
append:
DTC_OVERLAY_FILE: foo.overlay
OVERLAY_CONFIG: foo.conf
boards:
myboard:
append:
DTC_OVERLAY_FILE: myboard.overlay
OVERLAY_CONFIG: myboard.conf
/my-regular-expression-over-board-names/:
append:
DTC_OVERLAY_FILE: myregexp.overlay
OVERLAY_CONFIG: myregexp.conf
(Note that since the snippet feature is intended to be extensible, the
same snippet name may appear in multiple files throughout any
directory in SNIPPET_ROOT, with each addition augmenting prior ones.)
This initial syntax aligns with the following snippet design goals:
- extensible: you can add board-specific support for an existing
snippet in another module
- able to combine multiple types of configuration: we can now apply a
.overlay and .conf at the same time
- specializable: this allows you to define settings that only apply
to a selectable set of boards (including with regular expression
support for matching against multiple similar boards that follow
a naming convention)
- DRY: you can use regular expressions to apply the same snippet
settings to multiple boards like this: /(board1|board2|...)/
This patch is not trying to design and implement everything up front.
Additional features can and will be added to the snippet.yml format
over time; using YAML as a format allows us to make
backwards-compatible extensions as needed.
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
Basic things needed to integrate the new 'snippets' feature into the
build system. The main CMake variable which controls snippets is
SNIPPET. It is a whitespace-or-semicolon-separated list of snippet
names.
- Add minimal new cmake module for processing snippets. This just has
basic infrastructure for processing a SNIPPET variable into
SNIPPET_AS_LIST, and warning the user if they try to change it too
late.
- Integrate the new module into the build system, via
zephyr_default.cmake
This is anologous to the shields and boards modules' boilerplate and
input variables.
Signed-off-by: Marti Bolivar <marti.bolivar@nordicsemi.no>
Moves the deprecation notice for prj_<board>.conf files to the
proper location where other deprecation notices are located.
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
This now throws an error if there is no prj.conf file located in a
user-specified APPLICATION_CONFIG_DIR, which otherwise would have
used an empty configuration and not included board-specific files.
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>