Commit Graph

1365 Commits

Author SHA1 Message Date
Ryan McClelland 018dbcfd66 cmake: compiler: add double promotion warning
Too many times, code is pushed that includes floats that really
becomes doubles and C implicit promotion rules will want to make
floats into doubles very easily. As zephyr primarily targets
low-end process that may not have a double precision floating
point unit, enable this flag globally for now.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2024-01-26 21:37:24 -05:00
Greter Raffael e78aacdf29 cmake: zephyr_linker_sources: Link each file only once
If an ld file is included multiple times using `zephyr_linker_sources`,
only the last occurrence is actually used. Everything else is removed
again from the generated snippet files.

This allows to relocate certain blocks, e.g. the vector table, in an
application-specific CMakeLists.txt (or for an arch or soc).

Fixes: #66315

Signed-off-by: Greter Raffael <rgreter@baumer.com>
2024-01-26 11:26:06 +01:00
Flavio Ceolin 3fc5d971fe security: Add compiler static analysis support
Enable GCC builtin static analysis in Zephyr's static code analysis
(SCA) infra.

When this option is enabled GCC performs a static analysis and
can point problems like:

sample.c

+	int *j;
+
+	if (j != NULL) {
+		printf("j != NULL\n");

output:

${ZEPHYR_BASE}/samples/userspace/hello_world_user/src/main.c:30:12:
warning: use of uninitialized value 'j' [CWE-457]
[-Wanalyzer-use-of-uninitialized-value]

   30 |         if (j != NULL) {
      |            ^
  'main': events 1-2
    |
    |   25 |         int *j;
    |      |              ^
    |      |              |
    |      |              (1) region created on stack here
    |......
    |   30 |         if (j != NULL) {
    |      |            ~
    |      |            |
    |      |            (2) use of uninitialized value 'j' here

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2024-01-25 12:07:27 +01:00
Greter Raffael 81022fae79 linker: Only use itcm and dtcm snippets if regions exist
This tests whether there actually is an itcm or dtcm in the device tree.
Otherwise a FATAL_ERROR is generated.

Signed-off-by: Greter Raffael <rgreter@baumer.com>
2024-01-24 22:10:11 -06:00
Greter Raffael 33ffe001f8 linker: Generate snippets files for dtcm and itcm
This allows to link code and data blocks, e.g. the vector table, into
tightly coupled memory using `zephyr_linker_sources`.

Signed-off-by: Greter Raffael <rgreter@baumer.com>
2024-01-24 22:10:11 -06:00
Pieter De Gendt b0150d3ac3 cmake: modules: extensions: Add function to verify binary blobs
Add a cmake helper function to verify if blobs have a valid checksum.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-01-24 10:54:17 +01:00
Pieter De Gendt fcaed380cd cmake: Introduce ZEPHYR_CURRENT_MODULE_NAME
Add a cmake variable for the current module's name.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-01-24 10:54:17 +01:00
Attie Grande 003d2090b2 cmake: version: stop using to_hex() in favour of CMake's math()
Since v3.13, CMake has supported math(... OUTPUT_FORMAT <format>), which
will perform the same functionality as to_hex().

Signed-off-by: Attie Grande <attie.grande@argentum-systems.co.uk>
2024-01-22 09:48:33 +00:00
Attie Grande 20e2318b9f cmake: hex: deprecate use of to_hex() and from_hex() utility functions
Since v3.13, CMake has supported math(... OUTPUT_FORMAT <format>) and 0x
prefixes on numbers, which together provides the same functionality as
to_hex() and from_hex() that we've previously maintained.

Users should switch to using math() instead, and our functions are now
marked as deprecated.

Signed-off-by: Attie Grande <attie.grande@argentum-systems.co.uk>
2024-01-22 09:48:33 +00:00
Attie Grande 902751a19e cmake: hex: fix conversion of zero to hex
Previously, `to_hex(0 output)` would have placed `0x` into the `output`
variable, which is undesirable... this fix ensures that `0x0` is placed
into this variable if the input is zero.

Signed-off-by: Attie Grande <attie.grande@argentum-systems.co.uk>
2024-01-22 09:48:33 +00:00
Luca Burelli c5b7aabc06 llext: move all flags to compiler specific cmake files
Minimize the amount of flags that are hardcoded in the llext.cmake
module by moving them to the compiler specific cmake files.

The llext.cmake module will now use the new LLEXT_REMOVE_FLAGS and
LLEXT_APPEND_FLAGS global variables to adjust the set of flags used
to compile the llext code. This will make it easier to add support
for new architectures and compilers.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2024-01-21 10:59:49 +01:00
Luca Burelli feee017767 llext: rework add_llext_target() to use standard compile step
Separate the compilation of the source file from the conversion to an
llext file. This allows to reuse the include directories and macro
definitions of the current Zephyr build while compiling the llext source.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2024-01-21 10:59:49 +01:00
Luca Burelli 0747cd3358 llext: define add_llext_target() for llext compilation
This patch defines a generic function that encapsulates all the
architecture-specific machinery needed to compile llexts from source
files. Current tests are updated to use this function.

Output and source files must be specified using the OUTPUT and SOURCES
arguments. Only one source file is currently supported.

Arch-specific flags will be added automatically. The C_FLAGS argument
can be used to pass additional compiler flags to the compilation of
the source file.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2024-01-21 10:59:49 +01:00
Thomas Gagneret c62dbb1386 cmake: zephyr_module: Remove useless 'west_arg' variable
8cc716792a renamed this variable to lower
case to indicate it's only used locally however WEST_ARG is used as a
parameter of zephyr_module.py in CMakeLists.txt when
CONFIG_BUILD_OUTPUT_META is enabled.
This variable was used when west had some limitation. It does not
really make sense now, so it has been removed and content of west_arg
variable has been added by default.

Signed-off-by: Thomas Gagneret <tgagneret@witekio.com>
2024-01-19 09:47:09 +01:00
Grzegorz Swiderski 0b7fb57d09 cmake: code_relocation: Re-run when relocation_dict.txt changes
Fix an issue where updating a `zephyr_code_relocate()` call in CMake
didn't trigger regeneration of `code_relocation.c` and linker scripts.
The generation command was missing a dependency on the aforementioned
input text file, where the outcome of each call is cached.

Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
2024-01-15 13:20:17 +01:00
Grzegorz Swiderski 460b6ef122 code_relocation: Add NOKEEP option
When using the code and data relocation feature, every relocated symbol
would be marked with `KEEP()` in the generated linker script. Therefore,
if any input files contained unused code, then it wouldn't be discarded
by the linker, even when invoked with `--gc-sections`.

This can cause unexpected bloat, or other link-time issues stemming from
some symbols being discarded and others not.

On the other hand, this behavior has been present since the feature's
introduction, so it should remain default for the users who rely on it.

This patch introduces support for `zephyr_code_relocate(... NOKEEP)`.
This will suppress the generation of `KEEP()` statements for all symbols
in a particular library or set of files.

Much like `NOCOPY`, the `NOKEEP` flag is passed to `gen_relocate_app.py`
in string form. The script is now equipped to handle multiple such flags
when passed from CMake as a semicolon-separated list, like so:

   "SRAM2:NOCOPY;NOKEEP:/path/to/file1.c;/path/to/file2.c"

Documentation and tests are updated here as well.

Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
2024-01-15 13:20:17 +01:00
Marc Herbert d4b0273ab0 cmake: sparse.template: add COMMAND_ERROR_IS_FATAL
There are some situations like #67035 where sparse aborts and returns an
error code before the compiler has generated the .obj file; without any
clear indication that the .obj is missing (in normal situations sparse
prints warnings and _does_ creates the .obj file)

Also, builds are parallel by default and sparse runs tend to be massive
walls of text which all conspires to make it totally impossible to find
the relevant error message. Instead, we get an link-time error.

The only clear indication is the exit code. So catch it and abort the
build ASAP thanks to COMMAND_ERROR_IS_FATAL.

More generally speaking, the default behavior of execute_process() to
ignore errors is crazy. How frequently does a build system run commands
that do NOT matter?

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2024-01-15 11:32:44 +00:00
Andrej Butok 6b84d29c0c cmake: mcuboot: set align to 1 for overwrite only mode
Set align to 1 for CONFIG_MCUBOOT_IMGTOOL_OVERWRITE_ONLY,
used by non-swap update modes.
Fix imgtool error message for device with write size > 32B.

Signed-off-by: Andrej Butok <andrey.butok@nxp.com>
2024-01-12 09:59:51 +01:00
Keith Packard cdc686eecc compiler/gcc: _FORTIFY_SOURCE=1 doesn't mean compile-time only checks
_FORTIFY_SOURCE=1 differs from _FORTIFY_SOURCE=2 only in the bounds
checking mode that it uses.

With _FORTIFY_SOURCE=1, bounds checks are 'loose', allowing access to the
whole underlying object, not just the subset referenced in the expression
(e.g, the bounds of a struct member is the whole struct, not just the
member).

With _FORTIFY_SOURCE=2, bounds checks are strict, meaning that the bounds
of an expression are limited to the referenced value.

Both of these perform their checks at runtime, calling _chk_fail if the
bounds check fails. That's done in the __*_chk functions included in the C
library. These are always called when _FORTIFY_SOURCE > 0, unless the
compiler replaces the call with inline code.

GCC already does all of the compile-time bounds checking for string and mem
functions when not using -ffreestanding, so there's nothing we need to add
for that to work. That means the security_fortify_compile_time property
should be empty.

Signed-off-by: Keith Packard <keithp@keithp.com>
2024-01-10 20:50:51 -05:00
Jamie McCrae 1e72643b61 cmake: modules: shields: Process shields in order
Changes shield processing order from being on a root-by-root
basis to being order they were supplied to cmake

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2024-01-09 10:03:15 +01:00
Rodrigo Peixoto c992707251 zbus: add priority boost feature
Replace mutexes with semaphores to protect the channels in conjunction with
a priority boost algorithm based on the observers' priority.

Signed-off-by: Rodrigo Peixoto <rodrigopex@gmail.com>
2024-01-04 09:41:54 +01:00
Torsten Rasmussen 9981e69b91 cmake: update description of board_runner_args() function
Update description of board_runner_args() function so that it is
described that app_set_runner_args macro must be defined before the call
to `find_package(Zephyr)`.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-01-03 19:00:49 +00:00
Anas Nashif 7da7768095 cmake: remove deprecated XCC_USE_CLANG
This was deprecated in 3.0, so remove it now and remove all docs related
to it.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-12-14 09:31:45 +01:00
Marc Herbert 13df15845e cmake: drop ERROR_QUIET in python.cmake
ERROR_QUIET should be used only when the command is actually expected to
fail, otherwise discarding stderr can be extremely time-consuming. See
recent example of time lost in commit 40c2e08e82 ("xcc/cmake: don't
discard stderr; don't (ever!) use ERROR_QUIET")

If some Python interpreter cannot even evaluate `sys.version_info[:2]`,
then we definitely don't want to hide what its stderr says about that.

Fixes commit 94de3e9f60 ("cmake: FindPython3: Adjust python3 program
search")

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2023-12-13 13:56:59 +01:00
Jamie McCrae 2522a78566 linker: Add flash end ROM offset
Reduces the size of an image in the linker script by using the
ROM end offset Kconfig value

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-12-12 15:31:16 +01:00
Jamie McCrae 5031da95c6 cmake: linker: arm: Fix missing flash load size use
Fixes a mismatch between the cmake and ld linker scripts whereby
the cmake script was missing using the flash load size Kconfig
option (if it was said), which would result in images far larger
than they should have allowed to be

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-12-12 15:31:16 +01:00
Yuval Peress 3ddd36ff77 llvm: Allow llvm-readelf
Enable multiple names for the readelf program under llvm

Signed-off-by: Yuval Peress <peress@google.com>
2023-12-07 10:35:44 +00:00
Jamie McCrae 5dcc0d753a cmake: Remove support for deprecated prj_board.conf
Removes support for the deprecated features of having a prj file
which has the board name on the end of it. Board Kconfig fragments
should be used instead.

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2023-12-06 10:28:12 -05:00
Marc Herbert 837698b935 cmake/compiler/: drop ERROR_QUIET when looking for compiler --version
Commit 40c2e08e82 ("xcc/cmake: don't discard stderr; don't (ever!) use
ERROR_QUIET") fixed xcc but the corresponding code is duplicated. Fix
the duplicates too.

See that commit for the issue description, longer commit message and
rationale.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2023-12-04 16:38:08 +00:00
Marc Herbert 40c2e08e82 xcc/cmake: don't discard stderr; don't (ever!) use ERROR_QUIET
Remove ERROR_QUIET which is a bad idea 99.9% of the time. When any
program makes the effort of using stderr, we _really_ don't want to lose
those error messages.

Using ERROR_QUIET in XCC is even worse because of how high maintenance
XCC is; see another example in 4cba9e6d42 ("cmake: warn the user that
the toolchain cache hides errors")

No one expects error messages to be silently discarded and especially
not people not familiar with CMake (= most people); so hiding the
following error stalled progress for a couple days:

```
Error: there is no Xtensa core registered as the default.

You need to either specify the name of a registered Xtensa core (with
the --xtensa-core option or the XTENSA_CORE environment variable) or
specify a different registry of Xtensa cores (with the --xtensa-system
option or the XTENSA_SYSTEM environment variable).

Executing the below command failed.  Are permissions set correctly?
```

Also capture stdout and print it on failure because you never know.

Indent the ` ${CMAKE_C_COMPILER} --version` line in the error message so
CMake does not split that line.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2023-11-30 10:07:25 +01:00
Christopher Friedt afc59112a9 device: support for mutable devices
Add support for mutable devices. Mutable devices are those which
can be modified after declaration, in-place, in kernel mode.

In order for a device to be mutable, the following must be true

  * `CONFIG_DEVICE_MUTABLE` must be y-selected
  * the Devicetree bindings for the device must include
    `mutable.yaml`
  * the Devicetree node must include the `zephyr,mutable` property

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-11-28 15:35:39 +01:00
Jeppe Odgaard 05025e6b7c cmake: add initlevels to usage
Fix missing `initlevels` entry in the `usage` command.

Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
2023-11-24 11:39:21 +01:00
Andrej Butok d2bd778bcc kconfig: mcuboot: Add MCUBOOT_IMGTOOL_OVERWRITE_ONLY option
Add MCUBOOT_IMGTOOL_OVERWRITE_ONLY Kconfig option which
passes the --overwrite-only option to imgtool to avoid
adding the swap status area size when calculating overflow.
It is used by non-swap update modes.

Signed-off-by: Andrej Butok <andrey.butok@nxp.com>
2023-11-23 09:59:36 +01:00
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
Pisit Sawangvonganan 65b6d2f180 toolchain: esp32: fix cmake build issue with 'espressif' toolchain
Change CROSS_COMPILE_TARGET to be defined based on CONFIG_SOC_SERIES.
This fix adjusts CROSS_COMPILE_TARGET to ensure compatibility
with the 'espressif' toolchain variant, following the changes in
commit 6b57b3b786.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2023-11-22 09:52:29 +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
Fabio Baltieri fd9a464495 toolchain: llvm: use the "none" vendor triplet
This was submitted with "cros" in 77dde5dc9f, it was meant to be "none".

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-11-15 13:05:01 +01:00
Grant Ramsay a3ff19a39e cmake: compiler: Add compiler property for no-builtin
Abstracts these flags for multiple toolchain support

Signed-off-by: Grant Ramsay <gramsay@enphaseenergy.com>
2023-11-13 10:21:41 +01:00
Huifeng Zhang c3b857c434 arch: arm: cortex_ar: Use TPIDRURW as a base pointer for TLS
Replace the TLS base address pointer from TPIDRURO to TPIDRURW.

The difference between them is that TPIDRURO is read-only in user mode
but TPIDRURW isn't. So TPIDRURO is much more suitable for store
the address of _kernel.CPU[n]. For this reason, this commit replaces
the base pointer of the TLS area.

Signed-off-by: Huifeng Zhang <Huifeng.Zhang@arm.com>
2023-11-06 15:32:01 -06:00
Torsten Rasmussen 0b0f2f1912 cmake: safeguard path of SOC_LINKER_SCRIPT
Issue reported on Discord.

Safeguard cmake_path() for SOC_LINKER_SCRIPT so that the path is only
processed when SOC_LINKER_SCRIPT is defined.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2023-11-03 14:47:34 +00:00
Anas Nashif a6b490073e kernel: object: rename z_object -> k_object
Do not use z_ for internal structures and rename to k_object instead.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-03 11:46:52 +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
Bjarki Arge Andreasen 28f5f2d1ed drivers: Add GNSS API public header
This commit adds the public header for the GNSS API, along
with the initial GNSS Kconfig file and an entry in the
common linker file for registered GNSS data callbacks.

A very naive implementation of the GNSS data callback is
provided as well in drivers/gnss/gnss_publish.c

Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
2023-10-30 11:43:19 -04: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
Grzegorz Swiderski 12c8d11ee5 cmake: extra_flags: Use zephyr_get
This allows users to set `EXTRA_*FLAGS` variables when using sysbuild.

If these flags are provided in both local and global sysbuild scopes,
then only the local ones will be used for a given image. This is to
circumvent issues with mixing space-separated and `;`-separated lists.

Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
2023-10-24 11:35:27 +02:00
Patryk Duda ad1b1cf978 clang: target: Include gcc-m-fpu.cmake file
File gcc-m-fpu.cmake is responsible for determining what should be
passed to -mfpu option. Fortunately GCC and Clang options are compatible
so we can use the file for clang.

The list of supported -mfpu options can be found at
https://github.com/llvm/llvm-project in
llvm/include/llvm/TargetParser/ARMTargetParser.def file.

Signed-off-by: Patryk Duda <pdk@semihalf.com>
2023-10-23 16:04:39 +02: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
Dmitrii Golovanov 5008c31f8c config: qemu: Add QEMU_EXTRA_FLAGS config option
Add QEMU_EXTRA_FLAGS as QEMU board config option.

This allows Twister tests to provide additional device setup
commands to QEMU in prj.conf or testcase.yaml configuration files.

Example use case: to setup TCP or UDP network interfaces
with non-conflicting port numbers in different test suites
to avoid conflicts when Twister run tests in parallel on the
same host.

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2023-10-20 15:03:55 +02:00