Commit Graph

192 Commits

Author SHA1 Message Date
Jamie McCrae 46889819e6 cmake: modules: dts: Fix board revision 0 overlay
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>
2023-11-22 21:55:17 +01:00
Pieter De Gendt 58152eb938 cmake: modules: Add zephyr_library_add_dependencies extension
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>
2023-11-20 09:19:34 +01:00
Torsten Rasmussen 26b649ea53 cmake: update board and soc linker script handling
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>
2023-11-03 11:01:23 +01:00
Flavio Ceolin a6c3230b74 unittest: Generate symbol for existent modules
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>
2023-10-27 13:33:30 -05:00
Gerard Marull-Paretas 915cb05bb6 dts: drop HAS_DTS
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>
2023-10-20 12:18:17 -07:00
Gerard Marull-Paretas e1137a3e5e cmake: modules: dts: use devicetree stub file
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>
2023-10-20 12:18:17 -07:00
Anas Nashif 996c8457d7 ztest: remove old ztest api
Remove old Ztest API entirely. New API is the now the default.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-10-20 15:04:29 +02:00
Grzegorz Swiderski 5cf5282e60 cmake: extensions: Check status of "zephyr,memory-region" DT nodes
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>
2023-10-11 22:36:13 +03:00
Grzegorz Swiderski de85a208a0 cmake: extensions: Robustify dt_node_has_status
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>
2023-10-11 22:36:13 +03:00
Marc Herbert 4cba9e6d42 cmake: warn the user that the toolchain cache hides errors
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>
2023-09-22 13:42:21 +02:00
Daniel Leung 718a219bf1 cmake: expose TOOLCHAIN_HAS_PICOLIBC to kconfig
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>
2023-09-13 17:36:46 -04:00
Torsten Rasmussen 25d82ddead cmake: armclang version detection
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>
2023-09-13 16:23:30 +02:00
Jamie McCrae 20d2bbdbf0 cmake: modules: host tools: Bump minimum version to 0.16
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>
2023-09-12 13:47:23 +02:00
Grzegorz Swiderski 6c2ad89e4c cmake: extensions: Add zephyr_topological_sort()
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>
2023-09-05 15:27:04 +02:00
Jamie McCrae 3c34ca6fb9 cmake: modules: configuration_files: Force set app config dir
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>
2023-09-01 17:44:59 +02:00
Jamie McCrae ad981acc1b cmake: version: Fix example comment
Fixes a missing parameter from the comment

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-09-01 17:44:28 +02:00
Daniel Leung 2d78cb74bd cmake: modules/FindGnuLd: cache variable GNULD_VERSION_STRING
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>
2023-09-01 09:02:38 -04:00
Jamie McCrae 2447ac7164 cmake: code relocation: Add support for absolute windows paths
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>
2023-08-25 12:21:49 +02:00
Torsten Rasmussen 5e4710ce68 cmake: cleanup old west version support
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>
2023-08-24 10:47:00 +02:00
Gerard Marull-Paretas 11d782ce56 cmake: modules: add support for board extensions
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>
2023-08-21 16:28:22 +02:00
Torsten Rasmussen 40d85ebcc5 cmake: python module cleanup.
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>
2023-08-21 13:21:52 +02:00
Torsten Rasmussen 6e32f28a01 cmake: extend zephyr_file(CONF_FILES <paths>) to allow a list of paths
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>
2023-08-17 15:25:21 +02:00
Nico Lüthi cd2a0389ed cmake: add ZephyrAppConfiguration package
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>
2023-08-17 10:36:45 +02:00
Grzegorz Swiderski 199cc7f91b cmake: Fix scope pollution in zephyr_get(... MERGE)
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>
2023-08-16 15:01:57 +02:00
Grzegorz Swiderski 7f4b1abb39 cmake: Don't lose global sysbuild value with zephyr_get(... MERGE)
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>
2023-08-16 15:01:57 +02:00
Andriy Gelman 53c5897b98 cmake: modules: Add zephyr_code_relocate_ifdef() macro
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>
2023-08-14 13:34:50 +00:00
Jordan Yates a5895d6464 cmake: extensions: board revisions can be optional
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>
2023-08-07 13:26:35 +02:00
Grzegorz Swiderski cb46ed6a32 cmake: kconfig: Preserve correct CLI assignments across re-runs
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>
2023-08-07 13:04:44 +02:00
Grzegorz Swiderski 9228c379cd cmake: extensions: Improve import_kconfig() bool/tristate parsing
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>
2023-08-07 13:04:44 +02:00
Grzegorz Swiderski 0d12e1b5c0 cmake: kconfig: Keep symbol names sorted in EXTRA_KCONFIG_OPTIONS
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>
2023-08-07 13:04:44 +02:00
Jordan Yates fe498ada60 scripts: snippets: add `DTS_EXTRA_CPPFLAGS` support
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>
2023-08-02 16:27:11 +02:00
Grzegorz Swiderski e4de669bed Revert "cmake: linker: arm: put RAM sections in RAM region"
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>
2023-08-01 10:47:31 +02:00
Jamie McCrae 695616c177 cmake: Fix code relocation functions with absolute paths
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>
2023-07-10 12:05:00 +02:00
Armin Brauns 70655721fb cmake: remove extraneous newlines in build output
Using `west build --board=stm32f769i_disco --pristine=always
samples/subsys/shell/fs/` as an example:

Before:

-- west build: building application
[1/205] Preparing syscall dependency handling

[2/205] Generating include/generated/version.h
-- Zephyr version: 3.4.0 ($ZEPHYR_HOME), build:
zephyr-v3.4.0-9-gec9b30d354ec
[195/205] Linking C executable zephyr/zephyr_pre0.elf

[199/205] Linking C executable zephyr/zephyr_pre1.elf

[205/205] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:       94040 B         2 MB      4.48%
             RAM:       39528 B       384 KB     10.05%
            QSPI:          0 GB       256 MB      0.00%
            DTCM:          0 GB       128 KB      0.00%
          SDRAM1:          0 GB        16 MB      0.00%
        IDT_LIST:          0 GB         2 KB      0.00%

After:

-- west build: building application
[1/205] Preparing syscall dependency handling

[2/205] Generating include/generated/version.h
-- Zephyr version: 3.4.0 ($ZEPHYR_HOME), build:
zephyr-v3.4.0-9-gec9b30d354ec
[205/205] Linking C executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
           FLASH:       94040 B         2 MB      4.48%
             RAM:       39528 B       384 KB     10.05%
            QSPI:          0 GB       256 MB      0.00%
            DTCM:          0 GB       128 KB      0.00%
          SDRAM1:          0 GB        16 MB      0.00%
        IDT_LIST:          0 GB         2 KB      0.00%

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
2023-06-30 16:08:42 +02:00
Aaron Massey 15cdcc79f0 cmake: Fix FindLlvmLld usage of unimported package
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>
2023-06-26 12:40:03 +00:00
Daniel Leung 80e78208e6 kernel: syscalls: no need to include all syscalls in binary
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>
2023-06-17 07:57:45 -04:00
Daniel Leung 9eec3fc6eb cmake: add zephyr_syscall_header stub
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>
2023-06-17 07:57:45 -04:00
Evgeniy Paltsev b64cfe9832 ARC: MWDT: rework GNU helper tools usage
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>
2023-06-17 07:44:31 -04:00
Jamie McCrae 9642c48a29 cmake: boards: Fix issue with relative paths
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>
2023-06-15 05:10:42 -04:00
Torsten Rasmussen ba48dd8763 cmake: support snippets scope for `zephyr_get()`
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>
2023-05-25 13:31:53 +00:00
Torsten Rasmussen a6d9105d51 cmake: create Zephyr scope functions for variables
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>
2023-05-25 13:31:53 +00:00
Torsten Rasmussen fd526cc4b2 cmake: add reverse option to `zephyr_get(... MERGE)`
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>
2023-05-25 13:31:53 +00:00
Torsten Rasmussen 5c71e68607 kconfig: provide an option for enforcing Kconfig settings
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>
2023-05-25 14:57:41 +02:00
Torsten Rasmussen a88502783b cmake: align Zephyr module variable to EXTRA_ZEPHYR_MODULES
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>
2023-05-23 16:40:21 +02:00
Torsten Rasmussen 384fb1e478 cmake: introduce EXTRA_DTC_OVERLAY_FILE for devicetree
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>
2023-05-23 16:40:21 +02:00
Torsten Rasmussen 3a345682ba cmake: introduce EXTRA_CONF_FILE and deprecate OVERLAY_CONFIG
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>
2023-05-23 16:40:21 +02:00
Torsten Rasmussen 8460d91e32 cmake: extend zephyr_get() to support fetching of multiple variables
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>
2023-05-23 16:40:21 +02:00
Marc Herbert 4975c94845 west.cmake: make MIN_WEST_VERSION catch up with requirements-base.txt
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>
2023-05-22 10:17:11 +02:00
Jamie McCrae 0972cb9d87 cmake: kconfig: Configure KCONFIG_ROOT variable
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>
2023-05-17 16:14:49 +02:00
Torsten Rasmussen 49389b546a west: sign: Add Kconfig with application version
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>
2023-05-17 13:56:58 +02:00