Fixes an issue whereby a board revision is 0 and the overlay file
exists but would not be included
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
Add a CMake zephyr library extension for add_dependencies, similar
to the target_<func> functions.
This avoids using ${ZEPHYR_CURRENT_LIBRARY} directly.
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
This commit updates the handling of board and SoC linker scripts.
Several SoCs creates a linker.ld file which sole purpose is to include
another arch common linker script, often with content like this:
#include <arch>/linker.ld
instead of 100+ SoC specific linker.ld files containing just a single
include line of above structure, then this commit introduces two now
CMake variables, BOARD_LINKER_SCRIPT and SOC_LINKER_SCRIPT.
This allows the board and SoC CMake code to point directly to a common
linker script instead of creating a dummy linker.ld file doing this.
This removes the need for several dummy linker.ld file.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Generate ZEPHYR_{MODULE_NAME}_MODULE for existent modules
for unittests as well since they may be using Zephyr modules.
Fixes: 64348
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
HAS_DTS has become a redundant option. All Zephyr architectures now
select this option, meaning devicetree has become a de-facto
requirement. In fact, if any board does not provide a devicetree
source, the build system uses an empty stub, meaning the devicetree
machinery always runs.
Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
By providing a devicetree stub file, we make sure some internal macros
required by devicetree.h are generated in devicetree_generated.h. This
makes sure that systems without devicetree can continue working without
extra ifdeffery.
Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
Functions `zephyr_linker_dts_memory()` and `zephyr_linker_dts_section()`
are described as defining a memory region or section based on a DT node,
as long as it "exists and has status okay". However, only the existence
of the node is actually checked, using `dt_node_exists()`. To fix that,
employ `dt_node_has_status()` instead, which can check both conditions.
The status check is important, because both functions require the given
DT node to contain a `zephyr,memory-region` property (not to be confused
with the compatible string). This property is required by the associated
binding as well, but required properties can be omitted from nodes which
don't have status "okay". In those cases, edtlib won't raise an error,
and neither should CMake, because those nodes should be ignored.
Speaking of that property, add a missing error check for it as a bonus
(tucked behind the status check, of course).
Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
Calling this function with an output variable named `var` or `okay`
could produce an incorrect result, due to the variable being mishandled.
Add simple changes to avoid this.
Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
When `toolchain_is_ok` fails, the error message points the user at the
CMake logs. But those logs will be empty if the user tried to compile
more than once (typically: cleans everything and tries again). So tell
the user that cleaning the toolchain cache is required to see the error.
Tell the user to "move" the cache instead of removing it in case
technical support needs the cache for forensics.
Some finicky toolchains can be "non-deterministic" and fail
_sometimes_. For instance a license server can be flaky, or the
toolchain can require an "elaborate" set of environment variables
triggering some configuration "trial-and-error". In such a
non-deterministic case deleting the cache is enough to get rid of the
issue and move on! Looking at logs is not even required; even
better. Once the toolchain cache believes that the toolchain works, any
future toolchain glitch will be obvious at actual compilation time.
To test all this:
```
# Verify that the toolchain can compile a dummy file, if it is not we
# won't be able to test for compatibility with certain C flags.
-zephyr_check_compiler_flag(C "" toolchain_is_ok)
+zephyr_check_compiler_flag(C "-fubar" toolchain_is_ok)
assert(toolchain_is_ok "The toolchain is unable to build a dummy C file.\
```
Signed-off-by: Marc Herbert <marc.herbert@intel.com>
This mirrors TOOLCHAIN_HAS_NEWLIB to picolibc so the cmake
variable TOOLCHAIN_HAS_PICOLIBC can be used in kconfig.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
The armclang version detection introduced in #55133 does not correctly
detect a valid ARM Compiler (armclang) installation in all situations.
When ARM Compiler for Embedded is installed as part of ARM-DS or Keil,
then it may report itself in following output:
> Product: Arm Development Studio ... <year>.<no>
> Component: ARM Compiler x.y(.z)
> Tool: armclang [...]
>
> Target: ...
Correct the version extraction by turning each line into a list of
strings which can then be looped to find the ARM compiler component to
ensure the correct line is used for retrieving the version information.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Some tests require the zephyr toolchain version 0.16 or newer to
be able to use picolibc functionality.
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
This function performs topological sorting of CMake targets. Its initial
use case in Zephyr will be for implementing sysbuild image dependencies,
i.e., specifying an image order for CMake configuration and flashing.
Sourced from a comment on PR #57884 (anchor: #discussion_r1206807021)
Authored-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
Forces setting the cached APPLICATION_CONFIG_DIR variable so that
it gets updated with the absolute path instead of reverting back
to the relative path which then causes problems when sourcing
other files, e.g. app.overlay
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
This changes to cache variable GNULD_VERSION_STRING across cmake
runs. This variable is used to determine whether -Wl,-no-pie is
being passed to linker. However, if cmake is run multiple times
without clearing the build directory, GNULD_VERSION_STRING was
lost and the script falsely assumed the linker could not take
this argument, and thus omitting it during linking. Depending on
the host, it would warn on something like this:
/usr/bin/ld.bfd: app/libapp.a(main.c.obj):
warning: relocation in read-only section
`.text._posix_zephyr_main'
/usr/bin/ld.bfd: warning: creating DT_TEXTREL in a PIE
To fix this, simply caches GNULD_VERSION_STRING so it can be
used during subsequent cmake runs.
Fixes#61725
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
Adds support for absolute paths on windows, this supports the likes
of C:\, C:/ but does not support network \\ paths
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
When west is used by Zephyr, then minimum required version is 0.14.0.
Therefore cleanup west.cmake by removing code which are created to
support west versions =< 0.7.x.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Board extensions are board fragments that may be present in any board
root folder, under `${BOARD_ROOT}/extensions/${BOARD}`. The board
extension directory may contain Kconfig fragments and/or devicetree
overlays. Board extensions are automatically loaded and applied on top
of board files, before anything else. There is no guarantee on which
order extensions are applied, in case multiple exist.
Board extensions may be useful in the context of Zephyr modules, such as
`example-application`. In some situations, certain hardware description
or choices can not be added in the upstream Zephyr context, but they do
in a downstream project, where custom bindings or driver classes can
also be created. This feature may also be useful in development phases,
when the board skeleton lives upstream, but other board features are not
yet present.
Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
CMake 3.16 find_python3 module introduced `Python3_EXECUTABLE` as
artifact specifier.
This allows Zephyr to cleanup its Python detection mechanism and thus
remove the Zephyr specific `PYTHON_PREFER` variable, which is now
deprecated.
This further improves the Python detection mechanism in Zephyr as it
allows users to specify Python3_EXECUTABLE and thereby follows CMake
documentation.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Extend zephyr_file(CONF_FILES <paths>) to take a list of paths to lookup
instead of a single path.
This remove the need of callers to do:
> foreach(p ${paths})
> zephyr_file(CONF_FILES ${p})
> ...
> endforeach()
and instead allow them to just pass the list directly to
> zephyr_file(CONF_FILES ${paths})
In addition the help text is updated with the detail that CONF_FILES can
be given an empty list. This has always been possible, but not
described.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Fixes#56200
Add the ZephyrAppConfiguration package and update the corresponding
documentation. This adds flexibility to the CMake build configuration
by providing a workspace configuration package and an application
package, which only applies to the current application. The workspace
package stays the same as before, but the application package is
new and lives, per default, inside the application folder.
Signed-off-by: Nico Lüthi <nylnx@outlook.com>
Clear the output variable with an empty string, before appending to it.
Unsetting the variable locally is insufficient, because its value from
the parent scope or cache can still creep into the final result.
Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
According to the doc comment:
If using MERGE then SYSBUILD GLOBAL will get both the local and global
sysbuild scope variables (in that order, if both exist).
This stopped working in commit 8460d91e32,
when support for `zephyr_get(... VAR <multiple-variables>)` was added.
Instead of returning both values, the local sysbuild scope value would
clobber the global one. Fix this by splitting the internal `sysbuild`
scope into `sysbuild_local` and `sysbuild_global`, in that order.
Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
Currently zephyr_code_relocate() will exit with an error if the
library does not exist. This commit adds a macro that only calls
zephyr_code_relocate() when a specific Kconfig symbol is enabled.
Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
Add a new option to `board_check_revision` that can make specifying a
board revision optional. This makes it easier to work with boards that
can come in a base variant with extensions. For example Fanstel BLE
modules that come with/without power amplifiers.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
This tiny patch makes two improvements:
1. Preserve boolean (=n) assignments from command-line.
This fixes an issue where, if a symbol with `default y` were turned off
via command-line, e.g., `-DCONFIG_BOOT_BANNER=n`, a CMake re-run would
revert that symbol back to its default value.
To avoid this, the assignment should have been preserved in CMake cache
as `CLI_CONFIG_BOOT_BANNER:INTERNAL=n`. However, `kconfig.cmake` clears
unset variables from cache, and (=n) symbols become unset variables, so
an exception had to be made for them.
2. Discard invalid assignments from command-line.
Although `kconfig.cmake` takes care to discard assignments to symbols
which get unset by Kconfig, it wasn't handling the case where Kconfig
would keep the symbol but replace its value, making the CMake-cached
assignment invalid.
For example, this assignment:
west build . -DCONFIG_PRINTK=n
could be invalidated if PRINTK were selected by, e.g., BOOT_BANNER,
producing this warning:
PRINTK (...) was assigned the value 'n' but got the value 'y'. (...)
Still, the old value of (=n) was being cached. One way in which this was
evident was when setting an unrelated symbol in a separate invocation:
west build . -DCONFIG_MAIN_STACK_SIZE=512
the same warning for PRINTK would show up again.
Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
This function has been working fine for parsing Kconfig fragments as
processed by Kconfiglib, but it can be made more robust for parsing
fragments from other sources, including handwritten ones.
Previously, Kconfig fragment lines of the form `# CONFIG_FOO is not set`
were ignored entirely, while lines of the form `CONFIG_FOO=n` would set
the corresponding CMake variable or target property to a literal `n`.
However, Kconfiglib treats both equivalently - as assignments to `n` -
so `import_kconfig()` should too.
Due to the fact that `.config` files output by Kconfiglib always show
disabled options as `# CONFIG_FOO is not set` (which was being ignored),
existing CMake code expects `CONFIG_FOO` to be unset. To avoid breakage,
the variable/property will now be unset explicitly by `import_kconfig()`
when it encounters either representation of `CONFIG_FOO=n`.
Moreover, for bool and tristate symbols, Kconfiglib accepts assignments
like `CONFIG_FOO=yeah`, `CONFIG_FOO=maybe`, or `CONFIG_FOO=nope`, and it
transforms the value of `CONFIG_FOO` into `y`, `m`, or `n` respectively.
This effect is now replicated in CMake.
Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
This makes checksum calculation over Kconfig fragments more consistent,
which prevents writing a new `.config` when nothing really changes.
To explain this, consider the following sequence:
1. west build . -DCONFIG_XXXX=y -DCONFIG_YYYY=y
2. west build . -DCONFIG_YYYY=y
3. west build . -DCONFIG_XXXX=y
At (1), we set new values for XXXX and YYYY, so the `.config` changes.
At (2), we set a value for YYYY, but it's the same value as before, so
the `.config` doesn't get overwritten.
At (3), we set a value for XXXX, but it's the same value as before, so
the `.config` shouldn't get overwritten... but it does. What happened?
The reason is that the generated `extra_kconfig_options.conf` fragment,
which is included in the checksum calculation, was being populated using
two sets of CMake cache variables:
- past assignments, prefixed with `CLI_${KCONFIG_NAMESPACE}_`.
- new assignments, prefixed with just `${KCONFIG_NAMESPACE}_`.
Usually, past assignments would appear before new assignments, because
the default `${KCONFIG_NAMESPACE}` is CONFIG, which goes after CLI in
alphabetical order. As a result, the contents of EXTRA_KCONFIG_OPTIONS
at (1) and (2):
CONFIG_XXXX=y
CONFIG_YYYY=y
were not identical to its contents at (3):
CONFIG_YYYY=y
CONFIG_XXXX=y
resulting in a different checksum.
This is resolved by stripping out the CLI prefix first, then effectively
"mergesorting" the past and new assignments, before starting to populate
EXTRA_KCONFIG_OPTIONS.
Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
Add an additional option to the `append` schema for appending to the
`DTS_EXTRA_CPPFLAGS` cmake cache variable, enabling finer control over
the content of devicetree files.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
This reverts commit f5eada5553.
Fixes#57590.
In order to fix incorrect program headers with CMAKE_LINKER_GENERATOR,
issue #59064 needs to be addressed first. Until then, revert to the
status quo from several versions back.
Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
Fixes an issue whereby absolute paths in libraries would have
duplicate paths in the name, causing issues in that they would
not be relocated.
Signed-off-by: Torsten Rasmussen <torsten.rasmussen@nordicsemi.no>
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
The find_package_handle_standard_args function is used in FindLlvmLld
without being imported. This may cause FindLlvmLld to fail
non-determistically based on if it's evaluated in a CMake build/process
before find_package_handle_standard_args is included.
We should include what we use. Explicitly include
find_package_handle_standard_args.
Signed-off-by: Aaron Massey <aaronmassey@google.com>
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>