Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions designs/DESIGN_ZEPHYR_REVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ post-verification states that a Kconfig or Devicetree logic error is not noise.
| Note | Loaded by |
|---|---|
| `general` | every patch |
| `boards` | `boards/`, `soc/` |
| `cmake` | `CMakeLists.txt` and `*.cmake` files |
| `execution-context` | `arch/`, `drivers/`, `kernel/`, `soc/`, or interrupt, timer, and callback symbols |
| `synchronization` | `kernel/`, or lock, workqueue, and thread symbols |
| `device-drivers` | `drivers/`, `include/zephyr/drivers/`, or `DEVICE_*` symbols |
Expand Down
4 changes: 2 additions & 2 deletions docs/zephyr-review.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ By default, three analysis stages always run: `goal`, `implementation`, and

| Stage | Looks for |
|---|---|
| `resources` | Leaks, object lifetime against pending work and timers, power management balance, DMA buffer ownership |
| `concurrency` | Blocking in the wrong execution context, locks, SMP, workqueues, unbounded work in ISRs |
| `resources` | Leaks, static RAM footprint, object lifetime against pending work and timers, power management balance, DMA buffer ownership |
| `concurrency` | Blocking in ISRs or non-yielding contexts, locks, panic/console lock safety, SMP, workqueues, bounded ISRs and timeouts |
| `configuration` | Kconfig, Devicetree, and CMake logic that disagrees with the code it gates |
| `security` | Untrusted input from peers, system call verification, flash and update paths |

Expand Down
53 changes: 48 additions & 5 deletions projects/zephyr/prompts/false-positive-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,16 @@ See doc/kernel/services/scheduling/index.rst and the Meta-IRQ Priorities section
of doc/kernel/services/threads/index.rst. A uniprocessor-only file does not need
SMP protection when Kconfig rules out `CONFIG_SMP`.

### 8. Hardware behavior you cannot verify
### 8. Hardware behavior and specifications you cannot verify

The datasheet is usually not in the tree. Do not report a register sequence as
wrong because it looks unusual. A vendor sequence can look redundant and still be
required. Report it only with evidence from the tree, such as a sibling driver,
a binding, or a vendor HAL header, or mark it speculative.
The datasheet and architecture reference manuals are usually not in the tree. Do
not invent or cite specific register bitfield positions, reserved-bit ranges, or
architecture manual section numbers from memory without verifiable evidence from
the tree (such as architecture or driver headers, a binding, or a sibling
driver). For other hardware register sequences that look unusual without a
datasheet in the tree, remember a vendor sequence can still be required: state
what you based the concern on and mark it speculative (capped per
`severity.md`), or drop it when there is no concrete in-tree basis.

### 9. External modules

Expand Down Expand Up @@ -105,3 +109,42 @@ locking, or system call verification defect.

Follow `doc/contribute/style/code.rst`, which says to match nearby code where the
guidelines leave a choice. Do not report a preference the guidelines do not state.

### 13. Auto-discovered board config and overlay files

Zephyr's build system automatically discovers application-local board and SoC
configuration and overlay files under `boards/` and `socs/` (for example
`boards/<board>.conf`, `boards/<board>.overlay`, and
`socs/<SOC>_<BOARD_QUALIFIERS>.overlay`, distinct from the top-level `boards/`
and `soc/` trees) unless `CONF_FILE` or `DTC_OVERLAY_FILE` overrides discovery
(verify the discovery rules in `doc/build/dts/howtos.rst` and
`doc/build/kconfig/setting.rst` in the target tree). Do not report a
`boards/<board>.conf` or `boards/<board>.overlay` file in `tests/` or `samples/`
as unused or orphaned merely because `testcase.yaml` or `sample.yaml` does not
reference it via `EXTRA_CONF_FILE` or `EXTRA_DTC_OVERLAY_FILE` or list the board
in `platform_allow`.

### 14. Invalid or unbuildable remediation suggestions

Verify that every suggested fix obeys Zephyr's build and runtime rules before
reporting it:

- Do not suggest sleeping, mutexes, or workqueue waits inside `PRE_KERNEL_1` or
`PRE_KERNEL_2` init paths.
- Do not suggest overriding `enum:` from an `include:`d Devicetree binding YAML;
`edtlib` forbids overriding keys from included bindings with conflicting
values (`doc/build/dts/bindings-syntax.rst`).
- Do not demand test Kconfig values that exceed target architecture or linker
limits without checking architecture Kconfig ranges in the tree.
- Do not ask a driver to accept invalid inputs to work around a buggy caller
when the subsystem API contract requires rejecting them.

### 15. Existing API signatures and non-functional coding-guideline noise

Consistent with Rule 11.8 in `maintainers/general.md`, do not report a
`(void *)` cast that drops `const` when it is forced by an unchanged existing
Zephyr API parameter type (such as `k_mem_phys_addr(void *)`), unless the
callee actually mutates read-only memory (which remains a `High` defect). Do not
report stylistic MISRA preferences with no functional or safety defect (such as
omitting an empty trailing `else` branch or testing `if (ret)` on an `int`
status code).
25 changes: 20 additions & 5 deletions projects/zephyr/prompts/maintainers/api-lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ these rules, because they differ by status. The `@version` tag in the header
records it: `0.1.z` is experimental, `0.y.z` with `y` above 1 is unstable, and
`1.0.0` or later is stable.

Source: doc/develop/api/api_lifecycle.rst.
Source: doc/develop/api/api_lifecycle.rst; doc/develop/api/overview.rst;
doc/releases/index.rst.

External issue metadata and Architecture working group approvals may be absent
from a local checkout. Treat them as unknown unless the supplied context can
Expand All @@ -25,16 +26,30 @@ missing approval.

- Experimental APIs may change, and unstable APIs may be removed without
deprecation.
- For stable APIs (`@version >= 1.0.0`, `doc/develop/api/overview.rst`), check
that the header's `@version` (`X.Y.Z`) follows SemVer: backwards-compatible
bug fixes increment `Z`, backwards-compatible additions or deprecations
increment `Y` and reset `Z` to `0`, and breaking changes increment `X`.
- Long-standing public headers under `include/zephyr/` that were shipped across
previous releases (`git_log`) without an explicit `@version` tag still require
scrutiny before breaking function signatures or semantics; flag unannounced
breaking signature changes (`Medium` or `Low` depending on blast radius).
- A breaking change to a stable API needs an RFC issue labeled Breaking API Change,
and the pull request needs an entry in the API Changes section of the release
notes. Check the release notes in the tree. Report a missing RFC issue or label
only when the supplied context establishes its absence; otherwise leave that
external requirement unassessed.
notes. Check the active draft version in `doc/releases/index.rst`
(`doc/releases/release-notes-<X.Y>.rst` and
`doc/releases/migration-guide-<X.Y>.rst`, never an already-released file).
User-visible behavioral changes, tightened static limits, or new Kconfig
requirements also belong in the current draft migration guide and release
notes. Report a missing RFC issue or label only when the supplied context
establishes its absence; otherwise leave that external requirement unassessed.
- Deprecating a stable API takes at least two full releases, unless the Architecture
working group approves a shorter period. The API is marked with `__deprecated` or
`__DEPRECATED_MACRO`, or through a Kconfig option that restores its previous form.
The deprecation is documented and added to the release notes, and in-tree users
are migrated in the same change.
- Flag new in-tree use of an API marked deprecated.
- A change to an API behavior contract also updates its doxygen, including the
`@retval` list and qualifiers such as `@isr_ok`.
complete `@retval` list, qualifiers such as `@isr_ok`, caller-side context
constraints, accurate `@ingroup` membership, and backend-specific differences
on shared architecture or subsystem headers.
48 changes: 48 additions & 0 deletions projects/zephyr/prompts/maintainers/boards.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
+++
title = "Board and SoC Porting"
paths = [
"boards/",
"soc/",
]
+++

# Board and SoC Porting

Applies to board and SoC definitions under `boards/` and `soc/`.

## Board YAML and Twister metadata

Source: doc/hardware/porting/board_porting.rst; doc/develop/twister/index.rst.

- Keep `supported:` in `<board>.yaml` populated with the hardware features
enabled on the board using valid Zephyr board tags (check sibling board YAML
files in `boards/` with `git_grep`, for example `netif:eth` rather than
ad-hoc names such as `ethernet`). Leaving `supported:` empty renders an empty
hardware table in `.. zephyr:board-supported-hw::`.
- Entries in `testing: ignore_tags:` have no effect unless matching tags appear
in `supported:` or in tests targeting the board. Flag dead `ignore_tags`
entries at `Low` severity.

## Board Devicetree factoring and documentation

Source: doc/hardware/porting/board_porting.rst.

- Factor shared peripherals, pinmux, and memory layout across sibling boards or
SoC variants into a common `.dtsi` instead of duplicating full `.dts` files.
- Board directory name, vendor prefix, `board.yml`, Devicetree, and board
documentation text must agree on the board identity, SoC, and vendor.
- Reuse vendor common `.rst` includes where sibling boards do so, and do not add
a manual `.. image::` directive in `doc/index.rst` when `doc/img/<board>.webp`
is auto-detected by the board catalog generator (`git_grep` sibling boards to
confirm the convention).

## Flash and debug runners (`board.cmake`)

Source: doc/hardware/porting/board_porting.rst (Flash and debug support).

- Do not hardcode OS-specific device paths (such as a fixed `/dev/ttyUSB0`) or
assume local udev rules in `board.cmake`; keep device selection overridable so
multiple boards and non-Linux hosts work.
- Remember that the first `include()` in `board.cmake` sets the default flash or
debug runner if not already set; verify runner ordering matches the board's
documented default runner.
55 changes: 55 additions & 0 deletions projects/zephyr/prompts/maintainers/cmake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
+++
title = "CMake Build Configuration"
paths = [
"CMakeLists.txt",
"**/CMakeLists.txt",
"*.cmake",
"**/*.cmake",
]
+++

# CMake Build Configuration

Applies to `CMakeLists.txt` and `*.cmake` files. Mechanical formatting checked
by `scripts/ci/check_compliance.py` (`CMakeStyle`) is excluded; focus on build
logic, layering, and portability defects that CI does not catch.

## Include path boundaries

Source: doc/contribute/guidelines.rst; CMakeLists.txt.

- Do not expose private kernel or internal architecture include directories
(such as `${ZEPHYR_BASE}/kernel/include` or `${ARCH_DIR}/${ARCH}/include`) via
`zephyr_include_directories()` or `include_directories()` in driver or
subsystem `CMakeLists.txt` files.

## Host tools and configure-time side effects

Source: doc/hardware/porting/board_porting.rst.

- Do not invoke optional external host tools (such as `qemu-img`)
unconditionally with `execute_process()` at CMake configure time when a
missing tool would break build-only workflows. Attach host-tool invocations to
run, flash, or debug targets instead, or guard them behind the target that
requires them.

## Configuration and overlay discovery

Source: doc/build/dts/howtos.rst (Set devicetree overlays).

- Per `doc/build/dts/howtos.rst` (verify against the target tree's
`cmake/modules/configuration_files.cmake`), setting `DTC_OVERLAY_FILE`
replaces automatic discovery of application-local `socs/` and
`boards/<board>.overlay` files (distinct from the top-level `soc/` and
`boards/` trees), whereas `EXTRA_DTC_OVERLAY_FILE` appends overlays while
preserving auto-discovery. Flag `DTC_OVERLAY_FILE` assignments that
unintentionally drop board overlays instead of using
`EXTRA_DTC_OVERLAY_FILE`.

## Diff hygiene

Source: doc/contribute/style/cmake.rst.

- Avoid redundant no-op variable updates, and do not mix unrelated CMake
reformatting into functional commits (diff-scope hygiene only; leave
mechanical formatting to `CMakeStyle`). Report at `Low` severity.
28 changes: 24 additions & 4 deletions projects/zephyr/prompts/maintainers/device-drivers.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,40 @@ Source: doc/contribute/guidelines.rst (Specialized driver requirements).
- A driver for a standalone device uses the Zephyr bus APIs (SPI, I2C, and so on)
so that it works on any SoC. An SoC-specific fast path must keep a regular
path for all other SoCs, and exceptions need Architecture WG approval.
- Keep standard specification register or descriptor definitions in shared
subsystem headers and keep protocol-level retry loops in the subsystem stack
rather than duplicating them inside one vendor driver.

## Blocking and interrupts
## Blocking, timeouts, and interrupts

Source: doc/kernel/drivers/index.rst.
Source: doc/kernel/drivers/index.rst; include/zephyr/sys/clock.h;
include/zephyr/sys/util.h.

- A driver should support an interrupt-based implementation rather than polling,
unless the hardware provides no interrupt.
- Calls through device APIs such as `i2c.h` or `spi.h` are usually synchronous, so
they should block until the operation completes.
- Compute a single deadline at API entry using `k_timepoint_t`
(`sys_timepoint_calc()` and `sys_timepoint_timeout()`) rather than restarting
fresh per-step timeouts across multi-phase operations or retries, and prefer
`WAIT_FOR()` over ad-hoc busy-wait loops.

## Return values
## Hardware bounds, state, and return values

Source: the doxygen for each API in `include/zephyr/drivers/`.

- Check the return value of bus transfers. Report a value used after the transfer
that should have produced it failed.
- Return the errno the API documents, since callers rely on specific codes.
- Return the errno the API documents (for example `-ETIMEDOUT` versus
`-EAGAIN`), since callers rely on specific codes.
- Do not permanently latch a device into a failed state after a recoverable
configuration, negotiation, or tuning error unless hardware state is genuinely
unrecoverable.
- When bounds-checking MMIO register offsets against a mapped window size,
include the register access width without integer overflow (for example
`size >= sizeof(uint32_t) && offset <= size - sizeof(uint32_t)`) and apply the
check on every active access path, not only initialization.
- Check power-of-two assumptions on MSI vector counts and ring sizes (including
`UINT32_MAX` wrap on non-power-of-two indices), and watch for zero-initialized
table slots or `0` return sentinels colliding with valid ID `0` or empty
success.
22 changes: 20 additions & 2 deletions projects/zephyr/prompts/maintainers/devicetree.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,18 @@ Source: doc/build/dts/howtos.rst; doc/build/dts/dt-vs-kconfig.rst.
- A change to an SoC `.dtsi` affects every board using it. Check boards that
relied on the old value, particularly a change to `status`, a clock, or
a `reg` base address.
- Validate paired optional properties symmetrically at build time (for example,
checking with `BUILD_ASSERT` that `dmas` and `dma-names` are either both
present or both absent) so half-configured Devicetree nodes fail at build time
instead of misbehaving at runtime.
- Avoid deprecated `CONFIG_SRAM_BASE_ADDRESS` and `CONFIG_SRAM_SIZE` in new
code; derive RAM base and size from `DT_CHOSEN(zephyr_sram)` (`DT_REG_ADDR` /
`DT_REG_SIZE`) and watch for 32-bit overflow when RAM size reaches or exceeds
4 GiB.

## Rules for upstream bindings

Source: doc/build/dts/bindings-upstream.rst.
Source: doc/build/dts/bindings-upstream.rst; doc/build/dts/bindings-syntax.rst.

- Compare with an existing Linux or vendor binding when it is available in the
tree or supplied context. Check that its properties are reused and divergences
Expand All @@ -52,8 +60,18 @@ Source: doc/build/dts/bindings-upstream.rst.
binding may add the bus to the name.
- A device with a vendor listed in `dts/bindings/vendor-prefixes.txt` must use that
prefix. A device not made by a specific hardware vendor must not get one.
- Give bindings with multi-paragraph `description:` blocks a concise `title:`
(at most 100 characters, omitting the words "binding", "schema", and
"driver"). Do not copy or rewrite an inherited property's `description:` from
an `include:`d binding unless specializing it; remember `include:` forbids
overriding keys with conflicting values (except strengthening `required: true`
and unioning `class:`).
- Where `default:` is used, the `description:` must explain why that value was
chosen and when a different one is needed. If the right value depends on the
board, the property should be `required: true` instead.
board, the property should be `required: true` instead. Conversely, when a
property has one hardware-defined fallback value, prefer setting `default:` in
the binding and reading it with `DT_PROP()`/`DT_INST_PROP()` rather than
omitting `default:` and repeating `DT_PROP_OR()` with the same constant in
driver code.
- Use the `zephyr,` prefix for Zephyr-specific extensions to bindings shared with
Linux, and for configuration specific to a Zephyr driver.
24 changes: 22 additions & 2 deletions projects/zephyr/prompts/maintainers/dma-and-cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ symbols = [
"dma_config",
"dma_reload",
"dma_start",
"k_mem_phys_addr",
"sys_cache_data_*",
]
+++
Expand Down Expand Up @@ -42,5 +43,24 @@ Source: doc/hardware/cache/guide.rst.
with unrelated data can destroy that data.
- `__nocache` requires `CONFIG_NOCACHE_MEMORY`. Check that the option is enabled
for configurations using the attribute.
- Do not report cache maintenance on SoCs without a data cache, or where the driver
is built only for such SoCs. Confirm that through Kconfig before reporting.
- On architectures where the MMU enables hardware data caches independently of
`CONFIG_DCACHE` or `CONFIG_CACHE_MANAGEMENT` (inspect the target
architecture's MMU and cache headers in the tree, such as ARM64 with
`CONFIG_ARM_MMU`), `sys_cache_data_*()` can silently become a no-op or return
`-ENOTSUP` while caches remain active; check that Kconfig guards keep cache
maintenance active wherever DMA touches cached memory.
- Verify `k_mem_phys_addr()` preconditions in
`include/zephyr/kernel/internal/mm.h` and `include/zephyr/sys/mem_manage.h`
in the target tree: it only translates permanent linearly mapped kernel RAM
(not dynamic `k_mem_map()` regions, which may not be physically contiguous),
and under `CONFIG_MMU=n` with `CONFIG_ASSERT=y` it can assert on non-SRAM
addresses before a subsequent driver range check runs.
- On transfer abort, timeout, or controller reset, halt in-flight hardware DMA
and clear saved caller buffer pointers before returning buffer ownership to
the caller. Masking interrupts does not stop active bus-master DMA, and a
stale saved pointer later passed to `sys_cache_data_invd_range()` can corrupt
freed or reused memory.
- Do not report cache maintenance on SoCs whose hardware has no data cache, or
where the driver is built only for such SoCs (confirm via hardware capability
symbols such as `CPU_HAS_DCACHE` and architecture MMU/cache setup in the tree,
not `CONFIG_DCACHE=n` alone).
Loading