Commit graph zephyr/cmake
Author SHA1 Message Date
Tony Han
6f882517f9 arch: arm: core: add Cortex-A5 support to Kconfig and gcc-m-cpu.cmake
Add 'config CPU_CORTEX_A5' to arch/arm/core/cortex_a_r/Kconfig file.
Set 'GCC_M_CPU' to 'cortex-a5' in cmake/gcc-m-cpu.cmake for the
compiler.

Signed-off-by: Tony Han <tony.han@microchip.com>
2026-08-18 17:20:08 -04:00
Fin Maaß
a8649affcc riscv: select RISCV_ISA_EXT_ZBKB
select RISCV_ISA_EXT_ZBKB on extensions that
include it.

Signed-off-by: Fin Maaß <info@finmaass.de>
2026-08-17 16:27:42 -04:00
Josh DeWitt
f494cc3aed linker: Add a BSS linker location option
Allow applications to add special named sections to BSS or add linker
symbols around certain BSS objects without having to define their own
BSS area in RAM_SECTIONS that has to be memset separate of the rest of
BSS.

Signed-off-by: Josh DeWitt <josh.dewitt@garmin.com>
2026-08-13 16:21:54 -07:00
Torsten Rasmussen
437cd2641e cmake: restrict APPLICATION_CONFIG_DIR to zephyr_get(... LOCAL)
Application config dir is for the main application when using sysbuild.

Therefore restrict `zephyr_get(APPLICATION_CONFIG_DIR SYSBUILD_LOCAL)`
to ensure that other images does not pickup configuration files intended
for the main application.

APPLICATION_CONFIG_DIR can still be defined by the user for other images
using `<image>_APPLICATION_CONFIG_DIR=<path>`.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2026-08-13 13:12:59 -04:00
Fin Maaß
e9fd4d3118 cmake: clang: add -Wno-parentheses-equality
add -Wno-parentheses-equality, so
clang doesn't complain about redundant
parenthesis, like it does when K_TIMEOUT_EQ()
is directly used in a if.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2026-08-12 13:10:49 -04:00
Mike J. Chen
bc5a686851 linker/xt-ld: pass C_FLAGS when processing the linker_script
When invoking the C compiler to preprocess the linker script, also pass the
C_FLAGS so that the xtensa-core is specified. Otherwise, if the toolchain
has multiple cores registered, the toolchain will use a default core when
one isn't specified and it could be incorrect for the build target.

Signed-off-by: Mike J. Chen <mjchen@google.com>
2026-08-12 13:08:37 -04:00
Tobias Aguiar
c456d2b127 arch: arm: cortex_m: linker: preserve input section alignment for ITCM
Replace SUBALIGN with ALIGN on the ITCM output section. This mirrors the
DTCM fix in commit de3deb75d4 ("fix: DTCM section alignment for DMA TCD
pool", upstream #107114, issue #107058).

SUBALIGN does not just align the start of the output section. It also
forces every input section assigned to that output section to a 4-byte
alignment boundary. This overrides any stricter or different alignment
requirements specified by the input sections themselves.

Use ALIGN instead so the ITCM output sections still start on a
4-byte boundary while preserving the original alignment requirements of
their input sections.

Signed-off-by: Tobias Aguiar <tobias.aguiarsilvadealmeida@nxp.com>
2026-08-12 12:58:29 -04:00
Anas Nashif
23fe4a52a0 cmake: sca: eclair: deviate Rule 10.3 for likely() and unlikely()
likely() and unlikely() hand a truth value to __builtin_expect(),
whose parameters GCC declares as long.  The resulting conversion from
an essentially Boolean expression to an essentially signed one is what
MISRA C:2012 Rule 10.3 objects to, and because the macros are used
throughout the kernel this single pair of definitions accounts for
2261 of the 6595 Rule 10.3 reports in the ECLAIR scan of qemu_x86.

The conversion is value-preserving and the result is immediately
compared against 0, so nothing is lost and the intent of the rule is
met.  Rewriting the macros to select a signed value explicitly does
silence the reports, but it perturbs the most heavily used
branch-hint macro in the tree for no reduction in risk, so record a
deviation instead.  These macros already carry a deliberate Directive
4.9 deviation in zephyr_common_config.ecl, and Rule 8.8 is already
deviated for generated syscall declarations on the same reasoning:
the construct is imposed by a mechanism outside the coding standard's
model.

The selector follows the existing Rule 11.6 deviation for
__LOG_ARG_CAST.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-08-11 13:50:43 -04:00
Josh DeWitt
9591012d9e cmake: kconfig: Ensure .config is regenerated when devicetree changes
Kconfig values can be derived from devicetree via $(dt...) functions
which means the .config file must be regenerated whenever devicetree
changes.

Signed-off-by: Josh DeWitt <josh.dewitt@garmin.com>
2026-08-11 13:42:08 -04:00
Nam Nguyen
c994c79021 arch: arm64: Add support for ARM Cortex-A720 CPU
Add ARMv9-A Cortex-A70 CPU support.

Signed-off-by: Nam Nguyen <nam.nguyen.xn@renesas.com>
2026-08-10 16:31:01 -04:00
Jamie McCrae
9722a5d516 cmake: modules: soc: Deprecate SOC_NAME, SOC_SERIES, SOC_FAMILY...
These variables are duplicates of Kconfig values and they do not
need to exist, therefore deprecated them, including SOC_V2_DIR

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-08-08 16:33:24 -04:00
Hongquan Li
ce8d42d874 boards: qemu: add virtio-blk disk support
Create a raw disk image for QEMU virtio-blk tests.
Attach it through PCI or MMIO depending on the board.

Signed-off-by: Hongquan Li <hongquan.li@processmission.com>
2026-08-07 16:28:47 -04:00
Martin Meyer
d988cabdef cmake: ccache: fetch USE_CCACHE via zephyr_get for sysbuild
Add a `zephyr_get(USE_CCACHE)` call before the `USE_CCACHE` check so
that the variable is properly propagated from the sysbuild context,
allowing ccache to be enabled or disabled consistently across all
images in a sysbuild configuration.

Signed-off-by: Martin Meyer <meyer.m90@gmail.com>
2026-08-07 11:18:52 -04:00
Ederson de Souza
2cb53feca1 llext-edk: Properly get topdir when --sysbuild is used
When sysbuild is used with west (west build --sysbuild), west TOPDIR
variable is not saved to application build_info.yml, but to upper level
build_info.yml. Get topdir from there, otherwise during the EDK build
all paths relative to wesddt TOPDIR (such as modules) are handled as
absolute paths during EDK build.

Fixes: #110728

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
2026-08-07 11:17:44 -04:00
Pieter De Gendt
1309640202 cmake: honor an explicitly selected Zephyr SDK
When ZEPHYR_SDK_INSTALL_DIR is set, the Zephyr SDK is looked up with
find_package() using HINTS. Since HINTS does not prevent the other
default search locations from being used, an explicitly selected but
incompatible SDK was silently ignored: find_package() fell through to
another SDK found elsewhere (for example in the CMake package
registry), while ZEPHYR_SDK_INSTALL_DIR kept pointing at the selected
directory. This produced confusing output such as a version being
reported that did not match the selected directory.

Restrict the lookup to ZEPHYR_SDK_INSTALL_DIR with NO_DEFAULT_PATH so
that an explicitly selected SDK is used exactly, and an incompatible
one results in a clear error instead of a silent fallback. Pointing
ZEPHYR_SDK_INSTALL_DIR at a directory containing multiple SDKs keeps
working, as HINTS still selects the best compatible SDK below it.

Assisted-by: Claude Code:claude-opus-4.8
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-08-06 14:33:07 +02:00
Anas Nashif
575ef58acd cmake: emu: qemu: restore the pflash drives on the command line
The CONFIG_FLASH_INTEL_PFLASH_CFI01 block still contributed its two
-drive options by appending to the QEMU_EXTRA_FLAGS variable. Since
the qemu_append_*() API was introduced, qemu.cmake reads that variable
exactly once, near the top of the file, to seed the EXTRA slot with
what boards left behind. The block runs after that seeding, so its
options never reached the command line.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-08-05 18:36:55 +01:00
Adarsha Regmi
8925ae2806 toolchain: llvm: add ELD (ld.eld) linker support
ELD (“Embedded Linker”) is Qualcomm's open source, LLVM-based,
GNU-compatible linker designed for the needs of embedded systems. It can be
selected as an alternative to LLD when building Zephyr with the LLVM
toolchain.

This change adds a CONFIG_LLVM_USE_ELD Kconfig option and the required
CMake integration to locate ld.eld and use it during linking. A minimum ELD
version is enforced (22.0+) to ensure required linker-script features are
available.

ELD was discussed in several Zephyr Toolchain WG meetings from February
through June 2026. The meeting notes include links to recordings and
presentation slides covering key features such as linker plugins, LTO with
linker scripts, section budgeting, and rich diagnostics for facilitating
debugging.

Meeting notes: https://docs.google.com/document/d/1nFKhdhbxKhECvcVhwHQNytov3TbcN_eDUvPwPXlmXEM/edit#heading=h.8l0u6j5vo01p
Recording: https://zoom.us/rec/share/ztjugOyQ_zZcOf9zrZpomk2zxxE6aWeyvVJIUP2L-enc_wFubVJARkhOGlpzIEV2.nzAOoV97lPNrm_EB
Slides: https://riscv.atlassian.net/wiki/download/attachments/159286264/Invited%20Talk%20-Qualcomm%20Embedded%20Linker%20%E2%80%93%20Open%20sourcing.pdf?api=v2

ELD repository: https://github.com/qualcomm/eld
ELD docs: https://qualcomm.github.io/eld/

Prebuilt ELD binaries can be found on eld's github releases page:
https://github.com/qualcomm/eld/releases

Signed-off-by: Adarsha Regmi <aregmi@qti.qualcomm.com>
2026-08-05 18:36:15 +01:00
Anas Nashif
bcc6847d3a cmake: qemu: no need to check for CONFIG_QEMU_TARGET
CONFIG_QEMU_TARGET is assumed to always be set, no need for the check.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-08-05 13:54:30 +01:00
Anas Nashif
c03e2bce23 cmake: emu: qemu: apply -no-reboot consistently from CONFIG_REBOOT
QEMU restarts the guest when the machine resets. An application built
without reboot support has no reason to reset, so a reset means it
misbehaved, and restarting it hides that behind a boot loop instead of
letting an automated run finish.

qemu_x86 already reasoned this way, emitting -no-reboot when
CONFIG_REBOOT was not set. qemu_arc emitted it unconditionally, so an
arc application with CONFIG_REBOOT=y had reboot silently disabled
anyway. Every other QEMU board never emitted it at all, and would spin
in a boot loop on an unexpected reset.

Move the decision into a fragment keyed on CONFIG_REBOOT, so all boards
behave the way qemu_x86 already did, and delete the two board copies.
This is the same failure mode as the leon3 -icount flag fixed earlier: a
board level flag that did not track the Kconfig it was meant to follow.

Of the 36 configurations in the matrix, 32 now emit -no-reboot; the four
that do not (qemu_cortex_a9, qemu_cortex_r5, mps2, mps3) are exactly the
ones with CONFIG_REBOOT=y. On qemu_x86 and qemu_arc the flag only
changes position on the command line, which QEMU does not care about.

No qemu targeted test relies on the machine resetting and continuing.

Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-08-05 13:54:30 +01:00
Anas Nashif
575000192c cmake: emu: qemu: add a qemu_dumpdtb target
The arm and riscv "virt" machines generate a devicetree describing what
QEMU actually models, while Zephyr describes the same machines with a
hand written devicetree. There was no way to see the former, so keeping
the two in step meant reading QEMU's source.

Add a qemu_dumpdtb target that runs the emulator with -machine dumpdtb,
writing qemu.dtb into the build directory:

  west build -b qemu_riscv64 -t qemu_dumpdtb

QEMU exits as soon as the file is written without running the image, so
the target does not depend on the Zephyr binary. The board's -machine
argument merges with this one, since QEMU folds repeated -machine options
into a single option group.

Verified: qemu_riscv64 dumps a 4694 byte riscv-virtio devicetree and
qemu_cortex_a53 a linux,dummy-virt one. On a machine with no devicetree,
qemu_x86, QEMU declines with "This machine doesn't have an FDT" and the
target fails with that message rather than something obscure. The
run_qemu command line is unchanged on every board.

Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-08-05 13:54:30 +01:00
Anas Nashif
9b10a456b3 cmake: emu: qemu: expose QEMU's diagnostic log via QEMU_LOG
QEMU can report when the guest does something invalid, such as touching
an unassigned physical address, and when the guest reaches emulation
QEMU has not implemented. Zephyr never asked for either, so both are
silent: the guest just misbehaves and the developer is left guessing.

Add QEMU_LOG, a comma separated list of QEMU -d log items, and
QEMU_LOG_FILE, which defaults to qemu.log in the build directory and
accepts "-" for stderr:

  west build -b qemu_cortex_m3 -- -DQEMU_LOG=guest_errors,unimp

Both are read with zephyr_get() so they also work under sysbuild.

Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-08-05 13:54:30 +01:00
Anas Nashif
2667510656 cmake: emu: qemu: capture ethernet traffic with QEMU's filter-dump
PCAP=<file> only did anything for the serial transports, where
net_serial.cmake creates FIFOs and starts net-tools/monitor_15_4, an
out-of-tree binary the user has to build first. The block is POSIX only:
it shells out to mkfifo, stty and pkill. The ethernet transports,
CONFIG_NET_QEMU_ETHERNET and CONFIG_NET_QEMU_USER, had no capture at all.

QEMU can write the pcap itself. Attach a filter-dump object to the
netdev that net_nic.cmake already creates, so PCAP now works for the
ethernet transports with no FIFOs, no external capture process and no
POSIX-only tooling.

NET_QEMU_NETWORKING is a Kconfig choice, so at most one transport is
active in a build and PCAP stays unambiguous.

Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-08-05 13:54:30 +01:00
Anas Nashif
728c89b14a cmake: emu: qemu: rename QEMU_FLAGS_${ARCH} to QEMU_BOARD_FLAGS
Like QEMU_CPU_TYPE_${ARCH}, this was indexed by an architecture that is
fixed for any one build, so the suffix distinguished nothing. The name
also said nothing about who owns the variable, even though its whole
purpose is to hold what the board contributes: the machine, the CPU, the
memory size, and whatever board specific devices come with them.

Rename it to QEMU_BOARD_FLAGS, which reads as the counterpart of the
existing QEMU_EXTRA_FLAGS, and reject the old name at configure time. An
out-of-tree board left on the old spelling would otherwise lose its
-machine argument silently.

Update the icount guard added earlier to match, and verify it still
rejects a board that appends -icount to the renamed variable.

Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-08-05 13:54:30 +01:00
Anas Nashif
1018d71928 cmake: emu: qemu: drop the vestigial ARCH suffix from QEMU_CPU_TYPE
QEMU_CPU_TYPE_${ARCH} was indexed by architecture, but a build has
exactly one board and therefore exactly one ARCH, so the suffix
distinguished nothing. It only forced every board and the run target's
progress message to spell the same interpolation.

Rename it to QEMU_CPU_TYPE, and reject the old name at configure time so
an out-of-tree board does not silently end up with an empty progress
message.

Also record what the variable is for. Seven boards (cortex_a72,
cortex_a9, cortex_r5, leon3, malta, or1k, riscv32_xip) set it and never
pass -cpu, because their -machine already implies the CPU. It is not a
QEMU argument: the emulator code only reports it. Boards that do want a
-cpu argument reference it when composing QEMU_FLAGS_${ARCH}. That is
worth stating, since the name suggests it is what gets passed.

Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-08-05 13:54:30 +01:00
Anas Nashif
267747440f cmake: emu: qemu: unify QEMU_ARCH and QEMU_binary_suffix
Boards had two ways to say the same thing. QEMU_ARCH's only consumer
was binary.cmake, which did nothing with it but feed it to
set_ifndef(QEMU_binary_suffix ...), so the two variables named one
concept: the suffix of the qemu-system-* binary to run. Five boards
used one spelling and four the other.

Keep the name that describes what the value is, fix its casing to match
the rest of the tree, and drop the alias. Boards that set QEMU_ARCH now
set QEMU_BINARY_SUFFIX directly.

Because an out-of-tree board setting a now-ignored variable would
silently get the wrong emulator rather than a build failure, reject
both old names at configure time with a message naming the replacement.

Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-08-05 13:54:30 +01:00
Anas Nashif
eeecc4e2b0 cmake: emu: qemu: reject board -icount, drop dead flag on leon3
qemu_leon3 passed "-icount auto" in QEMU_FLAGS_${ARCH}, and icount.cmake
then appended "-icount shift=${CONFIG_QEMU_ICOUNT_SHIFT},...". QEMU
merges repeated -icount options into a single option group in which the
last shift= wins, so the board's value was silently discarded. Verified
against qemu-system-sparc: "-icount auto -icount shift=100" is rejected
for the invalid shift, while "-icount shift=100 -icount auto" is not.

Honouring the board's request instead turns out to break it: with
"-icount auto" actually applied, tests/kernel/timer/timer_api and
tests/kernel/sched/schedule_api on qemu_leon3 go from 170/170 passing
to 11 failed and 8 blocked. The derived shift is the value this board
wants, so the flag is dropped rather than migrated.

To keep the next board from losing an -icount flag the same silent way,
add QEMU_ICOUNT_OVERRIDE for boards that genuinely need a different
argument, and fail at configure time if a board puts -icount in
QEMU_FLAGS_${ARCH}, where it cannot take effect.

Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-08-05 13:54:30 +01:00
Anas Nashif
e94b6d46c5 cmake: emu: qemu: add an API for contributing to the command line
The QEMU command line was assembled by appending to a handful of
specifically named variables: QEMU_FLAGS, QEMU_EXTRA_FLAGS,
MORE_FLAGS_FOR_<target>, PRE_QEMU_COMMANDS_FOR_<target> and its POST
counterpart, plus QEMU_TARGET_DEPENDS. Which of them a contributor
should use, and what the resulting argument order would be, was
documented nowhere and had to be inferred from the layout of the file.

Replace the raw variables with qemu_append_flags(),
qemu_append_extra_flags(), qemu_append_target_flags(),
qemu_add_run_targets(), qemu_add_pre_commands(),
qemu_add_post_commands() and qemu_add_target_depends(), and name the
two ordered slots the flags land in. State is kept in global properties
rather than directory variables, so a contribution no longer has to
come from a file that happens to be include()d into qemu.cmake.

The two slots are kept distinct rather than merged because boards seed
FLAGS_EXTRA before this file runs, and because QEMU numbers -serial
ports in the order they appear on the command line, which makes the
order within a slot significant.

The board-facing contract is unchanged: boards still set
QEMU_FLAGS_${ARCH}, QEMU_EXTRA_FLAGS, QEMU_KERNEL_FILE and
QEMU_KERNEL_OPTION as before.

Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-08-05 13:54:30 +01:00
Anas Nashif
38d4a52a4f cmake: emu: qemu: split qemu.cmake into per-concern fragments
qemu.cmake had grown to 534 lines, most of which were per-subsystem
blocks (console, display, icount, Bluetooth, networking, CAN, ivshmem,
NVMe, the x86_64 image split) with no separation between them. Move
each block into its own fragment under cmake/emu/qemu/ and leave
qemu.cmake as a 120-line orchestrator that sets up the shared flag
lists, includes the fragments and emits the run targets.

The command line is assembled from two interleaved lists, QEMU_FLAGS
and QEMU_EXTRA_FLAGS, so the include order of the fragments fixes the
order of the resulting arguments. The fragments are therefore included
in exactly the order their blocks appeared in. This is also why QEMU
networking is split in two: the serial transports (SLIP, PPP, pipe
stack) contribute to QEMU_FLAGS early, while the ethernet NIC model
contributes to QEMU_EXTRA_FLAGS late, and the original file already
had them as two separate sections a hundred lines apart.

Document the flag lists and the ordering contract at the top of
qemu.cmake, which was previously implicit in the layout of the file.

Pure code motion, no functional change: the generated qemu-system-*
command lines and run-target dependency edges were captured for 36
board/app combinations covering the x86 locore, SLIP/PPP/pipe-stack
networking, CAN, ivshmem, Bluetooth, semihosting, NVMe, icount and SMP
paths, and are byte-identical before and after.

Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-08-05 13:54:30 +01:00
Anas Nashif
c399622ef3 cmake: emu: qemu: fix NVMe disk dependency and drop dead code
The qemu_nvme_disk target, which creates the backing image for the
-drive flag added under CONFIG_NVME, was only wired as a dependency of
the run targets when QEMU_KERNEL_FILE happened to be defined. That
variable is only ever set by the CONFIG_X86_64 block in this same file,
so on any other board CONFIG_NVME appended "-drive file=nvme_disk.img"
while nothing ever created the image. Accumulate run-target
dependencies in QEMU_TARGET_DEPENDS instead, so the NVMe image and the
x86_64 kernel image each register their own, and drop the empty
qemu_nvme_disk stub that existed only to satisfy the fused guard.

While here, remove PRE_QEMU_COMMANDS, which is dereferenced when
building the run targets but is set nowhere in the tree, and hoist the
three open-coded copies of the "escape QEMU_INSTANCE for the Makefiles
generator" conditional into a single qemu_instance variable.

Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-08-05 13:54:30 +01:00
Anas Nashif
73214f0516 cmake: sca: eclair: add deviation for directive 4.8 and explanation
Add deviation for directive 4.8, clarifying its advisory nature
and the rationale behind not adopting it in the project. This change
ensures that public headers define types consistently while
acknowledging the limitations of unit properties for shared headers.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-08-05 13:54:03 +01:00
Anas Nashif
ac5f4ad157 cmake: sca: eclair: deviate Directive 4.13 for va_start/va_end
Directive 4.13 (call resource operations in an appropriate sequence) flags
the va_start()/va_end() pairing used by the variadic assertion and print
helpers. By the definition of <stdarg.h> these are always used as a
correctly nested pair within a single function and the language guarantees
the sequence, so deviate them as deliberate and safe.

Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-08-05 13:54:03 +01:00
Anas Nashif
5bd7f28c56 cmake: sca: eclair: disapply advisory Rule 12.1
Rule 12.1 (make operator precedence explicit) is advisory and is not
adopted by the project. The reports are dominated by the universally
understood precedence between the equality/comparison operators and the
logical && / || operators (e.g. "a && b == c"), where adding parentheses
brings no clarity and would only churn the code base.

The genuinely error-prone precedence cases - a bitwise operator mixed with
a comparison, or an assignment used as a controlling expression - are
already diagnosed by the compiler via -Wparentheses, which is fatal under
-Werror. Disapplying Rule 12.1 therefore does not lose coverage of the
dangerous cases, consistent with the handling of other impractical advisory
guidelines (Directive 4.6 and 4.8).

Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-08-05 13:54:03 +01:00
Anas Nashif
a9bec7d63d cmake: sca: eclair: disapply advisory Directive 4.6
Directive 4.6 (use width-and-signedness typedefs instead of the basic
numerical types) is advisory and is not adopted by the project:

  - The basic numerical types are used throughout the tree where a specific
    width is not required (return codes, counters, line numbers, indices),
    and many of these appear in public APIs where churning int into int32_t
    has no safety benefit.

  - The directive cannot be satisfied at all for the basic floating types
    (float, double, long double), which make up a large fraction of the
    reports; the C standard provides no width-and-signedness typedefs for
    them.

Disapply the directive, consistent with the handling of other impractical
advisory guidelines (e.g. Rule 2.2, 13.5 and 14.2).

Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-08-05 13:54:03 +01:00
Anas Nashif
373496795b cmake: sca: eclair: deviate Rule 16.1 for allowed terminal statements
ECLAIR's well-formed-switch check (Rule 16.1) reports a violation for any
non-empty switch clause that does not end with an explicit break, even when
the clause ends with another statement that unconditionally transfers
control. This is the case for the very common return-per-case lookup idiom
(e.g. TC_RESULT_TO_STR(), get_friendly_phase_name()), where adding a break
after the return would only create unreachable code.

Rule 16.3 already treats break, continue, goto, return and calls to
no-return functions as "allowed terminal statements" via the
r16_3_allowed_terminal selector. Reuse that same selector for Rule 16.1 so
the two rules agree on what terminates a switch clause.

Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-08-05 13:54:03 +01:00
Anas Nashif
ee44d2ef77 cmake: sca: eclair: deviate four low-volume MISRA rules
Add deliberate/safe deviations for constructs that are intentional and
cannot or should not be changed:

  - Rule 8.12: CBPRINTF_PACKAGE_ARG_TYPE_COUNT is a deliberate readable
    alias of the implicit CBPRINTF_PACKAGE_ARG_TYPE_MAX bound, so the two
    enumeration constants intentionally share a value.

  - Rule 8.14: the POSIX headers must declare functions with the POSIX
    mandated signatures, which use the 'restrict' qualifier.

  - Rule 16.4: the switch statements in the fnmatch helpers are controlled
    by the RANGE_ERROR/RANGE_MATCH/RANGE_NOMATCH result of
    rangematch()/rangematch_cc(); all values are handled, so a default
    clause would be unreachable.

  - Rule 18.1: z_rb_foreach_next() indexes the iterator stack, which is
    bounded by the tree depth (<= Z_MAX_RBTREE_DEPTH) even though the
    analyser cannot prove it.

Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-08-05 13:54:03 +01:00
Anas Nashif
12abeb9018 cmake: sca: eclair: deviate Rule 11.9 for deliberate null-pointer idioms
ECLAIR reports MISRA C:2012 Rule 11.9 (the macro NULL shall be the only
permitted form of integer null pointer constant) against several
deliberate constructs in core headers. The reports are smeared across
every call site that expands the macros, but the constructs are safe:

  - Z_ARGIFY(arg) uses '(0) ? 0 : (arg)' as a universal compatible-zero
    so it yields an rvalue of any argument type (integers, floating
    types, bitfields and opaque struct pointers). When arg is a pointer
    the 0 acts as a null pointer constant. This is required to keep the
    cbprintf argument packaging type-generic.

  - CONTAINER_OF_VALIDATE probes a field type with '((type *)0)->field'
    inside a BUILD_ASSERT. The expression is only used by
    __builtin_types_compatible_p / __typeof__ in an unevaluated context
    and the null pointer is never dereferenced.

  - K_MEM_VIRT_RAM_START expands to '((uint8_t
    *)CONFIG_KERNEL_VM_BASE)'.  On configurations where
    CONFIG_KERNEL_VM_BASE is 0 the constant denotes the base address of
    the kernel virtual memory region, not a null pointer.
    K_MEM_VIRT_RAM_END is defined in terms of it and is covered too.

Add deliberate deviations for all three, following the existing
__ACCESS_ONCE Rule 11.9 deviation.

Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-08-05 13:54:03 +01:00
Anas Nashif
b7c7abb8cb cmake: sca: eclair: deviate Rule 18.3 for iterable-section iteration
Iterating over a Zephyr iterable linker section compares the iterator
against the section boundary markers (the generated _<type>_list_start and
_<type>_list_end symbols, also produced by STRUCT_SECTION_FOREACH, which
itself uses a relational comparison). The markers delimit a single
contiguous array, so the relational comparison is well defined even though
the analyser treats the two markers as pointers into separate objects.

Deviate Rule 18.3 for relational comparisons against the section end
marker. This covers both the STRUCT_SECTION_FOREACH macro and the
hand-rolled section loops (e.g. in the ztest runner). Unrelated Rule 18.3
reports (such as those from DEVICE_API_GET) are intentionally not covered.

Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-08-05 13:54:03 +01:00
Benjamin Cabé
dfafa1f4f9 build: cmake: deprecate zephyr_file_copy()
zephyr_file_copy() only existed because file(COPY_FILE ...) was not
available with CMake 3.20. With the minimum required CMake version now
being 3.28.3, call the native command directly everywhere in-tree and
deprecate the wrapper, which is kept for out-of-tree users.

Assisted-by: Claude:fable-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-08-03 15:03:35 -04:00
Benjamin Cabé
1a91c6bb9f build: cmake: remove checks obsoleted by CMake 3.28.0 requirement
Now that the minimum required CMake version is 3.28.0, remove version
checks and workarounds that can no longer trigger:

- the PyPI CMake 3.22.1 / 3.22.2 cmake_path() bug detection
- the CMakeError.log fallback name for the configure log, which has
  been CMakeConfigureLog.yaml since CMake 3.26
- the armclang generator check for CMake < 3.21

Assisted-by: Claude:fable-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-08-03 15:03:35 -04:00
Benjamin Cabé
a119dbf957 build: bump minimum CMake version to 3.28.0
Raise the minimum required CMake version from 3.20.0 (documented as
3.20.5) to 3.28.0, which is satisfied by the CMake 3.28.3 package
shipped in the Ubuntu 24.04 LTS repositories. Ubuntu 24.04 is the
current Ubuntu LTS release targeted by the Zephyr getting started
guide, and by the time of the next Zephyr release, Ubuntu 22.04 will be
within months of its end of standard support. Users of distributions
shipping an older CMake can use the Kitware APT repository or a
pip-installed CMake, as the documentation already suggests.

Raising the floor to 3.28 unlocks a range of modern CMake features for
the build system, among which the cmake_file_api() command (3.27),
file(COPY_FILE) (3.21), block()/endblock() (3.25), and allows removal
of several version-conditional workarounds.

The tree-wide cmake_minimum_required() occurrences in samples, tests
and boards are updated accordingly, together with the documentation
and the sysbuild CMake presets. The IAR C-STAT integration keeps its
own higher requirement (4.1.0).

Assisted-by: Claude:fable-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-08-03 15:03:35 -04:00
Zhiyuan Tang
2fbdc93cc9 cmake: gcc: fix double-precision FP codegen on single-precision Cortex-M55
commit 6612580d9e introduced PRECISION_TOKEN to pass -mfpu=fpv5-sp-d16
to GCC for Cortex-M55 SoCs with a single-precision-only FPU.

commit 570ef09d0f reverted FPU_FOR_cortex-m55 back to "auto" in the
shared gcc-m-fpu.cmake to fix a clang regression (clang treats an
explicit -mfpu= as a capability override, which silently disables
mve.fp).  However, GCC derives MVE capability from -mcpu alone and is
not affected by -mfpu=fpv5-sp-d16, so the revert was too broad: GCC
now also sees "auto" and assumes the full double-precision default
implied by -mcpu=cortex-m55, ignoring the SoC's actual hardware.

Fix this in the GCC-specific target_arm.cmake: when GCC_M_FPU is
"auto" and CPU_HAS_FPU_DOUBLE_PRECISION is not set, pass
-mfpu=fpv5-sp-d16 explicitly.  The clang and armclang paths already
skip -mfpu= for "auto" (commits 570ef09d0f and f30235f56a
respectively) and are unaffected.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Zhiyuan Tang <zhiyuan_tang@realsil.com.cn>
2026-08-03 15:02:13 -04:00
Ashish Mahanth
68078955f7 cmake: toolchain: add XC32 toolchain configuration files
Add the XC32 toolchain configuration files needed for Zephyr
to detect and use the Microchip compiler toolchain with the
expected compile/link defaults.

Signed-off-by: Ashish Mahanth <ashish.mahanth@microchip.com>
2026-07-17 14:42:46 -05:00
Daniel DeGrasse
5a48d77ab7 cmake: add qemu support for pflash launch arguments
Add support for launching qemu with pflash.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@analog.com>
2026-07-16 14:33:34 +02:00
Joel Holdsworth
8e6010a1bd cmake: emu: qemu: only add CAN bus when QEMU CAN hardware is needed
The previous condition (CONFIG_CAN && !CONFIG_SOC_LEON3) would add the
CAN bus QEMU object for any board with CAN enabled, even when the CAN
controller is not a QEMU-emulated device. This caused QEMU startup
failures on boards without QEMU CAN support.

Only add the CAN bus object when Kvaser PCI emulation or a SocketCAN
interface name is configured, which are the actual indicators that
QEMU-emulated CAN hardware is in use.

Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com>
2026-07-14 16:41:44 -04:00
Joel Holdsworth
81b6e13b36 arch: openrisc: add LLEXT ELF relocation support
Implement arch_elf_relocate() for the OpenRISC architecture to enable
the LLEXT (Linkable Loadable Extensions) subsystem.

Supported relocation types:
- R_OR1K_32, R_OR1K_32_PCREL (data)
- R_OR1K_INSN_REL_26 (26-bit PC-relative branch/jump)
- R_OR1K_HI_16_IN_INSN, R_OR1K_LO_16_IN_INSN (address pair)
- R_OR1K_AHI16 (adjusted high, sign-compensated)
- R_OR1K_SLO16 (split-immediate store encoding)
- R_OR1K_PCREL_PG21, R_OR1K_LO13, R_OR1K_SLO13 (page-relative)
- R_OR1K_TLS_LE_HI16, R_OR1K_TLS_LE_LO16, R_OR1K_TLS_LE_AHI16,
  R_OR1K_TLS_LE_SLO16, R_OR1K_TLS_TPOFF (TLS local-exec)

Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com>
2026-07-14 16:41:44 -04:00
Joel Holdsworth
5aa4def94c cmake: gcc: add target_openrisc.cmake to suppress RWX segment warning
OpenRISC runs code from RAM (non-XIP), so the single LOAD segment
legitimately needs RWX permissions. Add --no-warn-rwx-segments to
prevent ld >= 2.39 from turning this into an error under
--fatal-warnings.

Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com>
2026-07-14 16:41:44 -04:00
Evan Chen
a7214779d1 cmake: linker_script: arm: skip duplicate chosen ITCM region
Skip the ARM-specific chosen ITCM linker group when
the chosen node is already represented through
zephyr,memory-region.

This avoids generating duplicate ITCM execution
regions under armlink for boards that model the same
memory both ways.

Assisted-by: GitHub Copilot:GPT-5.4 [apply_patch] [run_in_terminal]
Signed-off-by: Evan Chen <bugena123@gmail.com>
2026-07-13 16:16:13 -05:00
Alberto Escolar Piedras
94f0908052 Revert "cmake: modules: hwm_v2: Narrowly load a SoC target"
This reverts commit cf15ee1fa6.

Unfortunately this commit has revealed quite a few issues in the tree.
Some are trivial to fix properly, but some are not.
Let's revert it to stabilize main while the issues are fixed.
After it can be merged back.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2026-07-13 18:06:00 +02:00
Jamie McCrae
cf15ee1fa6 cmake: modules: hwm_v2: Narrowly load a SoC target
This changes from loading all SoCs from python into CMake to just
loading the one that the user is using.

When configuring hello_world using sysbuild for
nrf52840dk/nrf52840, this results in a whole 1.7 second speed-up
on the system used for testing (12%)

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-07-13 16:40:01 +02:00
Anil Ozrenk
880b2cc6f5 cmake: toolchain: cross-compile: support per-board CROSS_COMPILE
Use zephyr_get() with VAR fallback to resolve CROSS_COMPILE and
CROSS_COMPILE_TOOLCHAIN_PATH per board target, falling back to the
global variable. This follows the same pattern used by XTENSA_CORE
in xcc/common.cmake.

Users can now set CROSS_COMPILE_<normalized_board_target> to specify
different toolchain prefixes for different boards without changing
the global CROSS_COMPILE between builds.

Signed-off-by: Anil Ozrenk <anil.ozrenk@analog.com>
2026-07-09 11:21:12 +01:00