Commit graph

751 commits

Author SHA1 Message Date
Martí Bolívar
86d0176f5f scripts: dts: verify default #address- and #size-cells are forbidden
Make sure that we don't allow bindings which manually
specify any defaults for the #address-cells or #size-cells
properties. See DTSpec 2.3.5.

Signed-off-by: Martí Bolívar <marti.bolivar@oss.qualcomm.com>
2026-03-08 16:36:20 +01:00
Martí Bolívar
97431a02cc scripts: dts: forbid #address- and #size-cells defaults
The devicetree specification section 2.3.5 says:

    The #address-cells and #size-cells properties are not inherited
    from ancestors in the devicetree. They shall be explicitly
    defined.

    A DTSpec-compliant boot program shall supply #address-cells and
    #size-cells on all nodes that have children.

    If missing, a client program should assume a default value of 2
    for #address-cells, and a value of 1 for #size- cells.

We are currently allowing defaults -- and notably, different defaults
from those recommended in the spec -- in the zephyr bindings for these
properties to pass without complaint.

Further, allowing the user to specify a default other than the
recommendations by the spec would be a bad design decision in my
opinion.

Handle this by erroring out explicitly when we try to set these
defaults in a binding. It's fine for people to do things like define
descriptions for these properties in a binding for some specific
compatible, but it's a footgun to allow bindings that would seem to
allow overruling the specification's explicit recommendation.

Signed-off-by: Martí Bolívar <marti.bolivar@oss.qualcomm.com>
2026-03-08 16:36:20 +01:00
James Roy
e2d805269a dts: gen_dts_cmake.py: Add a to_cmake_list() function
It conveniently converts an iterator into a CMake list.
(e.g.: `[1,2,3]` convert to `1;2;3`)

Signed-off-by: James Roy <rruuaanng@outlook.com>
2026-02-12 09:30:05 +01:00
Tomasz Chyrowicz
0e99df3ca8 dts: Handle phandles in cmake
Add a possibility to use phandles values in CMake.

Signed-off-by: Tomasz Chyrowicz <tomasz.chyrowicz@nordicsemi.no>
2026-02-09 13:30:23 +01:00
Pieter De Gendt
2b57985df1 scripts: dts: python-devicetree: Fix failing test with uppercase address
Commit f55358bcbf changed all hex values to
use lowercase characters. Update the test accordingly.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-02-09 09:37:12 +01:00
Kyle Bonnici
f55358bcbf dts: use lowercase hex values in DTS files.
Apply chnages from dts-linter 0.3.9.

Improve compliance with DTS Coding Style which says that:

4) Hex values in properties, e.g. “reg”, shall use lowercase hex.
   The address part can be padded with leading zeros.

Signed-off-by: Kyle Bonnici <kylebonnici@hotmail.com>
2026-02-04 13:49:43 +01:00
Pieter De Gendt
f728794ac0 scripts: dts: gen_dts_cmake.py: Fix keys in dict linter issue
Simplify loop as reported by ruff.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-02-02 11:37:53 -06:00
Pieter De Gendt
85a6e11bdb scripts: dts: gen_dts_cmake.py: Prevent trailing semicolon for lists
The generated lists have a trailing semicolon, which for CMake would
indicate a trailing empty item.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-02-02 11:37:53 -06:00
Pieter De Gendt
4159632248 scripts: dts: gen_dts_cmake.py: Format file
Format the gen_dts_cmake_py file using ruff.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-02-02 11:37:53 -06:00
Benjamin Cabé
1025dcc634 scripts: edtlib: preserve hexadecimal notation for integer values
When YAML binding files specify values in hexadecimal notation, this
information was previously lost during parsing as PyYAML converts hex to
regular integers.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-01-28 08:30:32 +01:00
TOKITA Hiroshi
724c35c871 scripts: dts: devicetree: tests: Add a map property test
Add a map property test for `test_edtlib.py`.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
2026-01-28 08:29:57 +01:00
TOKITA Hiroshi
5979e40d32 scripts: dts: Add handling for *-map property
This change introduces generating definitions corresponding to
`*-map` property, which was currently discarded.

For `*-map` properties are made able to be treated as a variation
of phandle-array, assign sequential cell names for each group of
specifiers (child_specifier_0, child_specifier_1, ...,
parent_specifier_0, ...).

The `*-map` data is like a two-dimensional array, so it is difficult to
handle with the existing APIs, so we will also provide new APIs.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
2026-01-28 08:29:57 +01:00
Pieter De Gendt
c1e2b83180 scripts: dts: gen_driver_kconfig_dts.py: Format and fix linter issue
Run ruff formatter and linter on the script file and remove exclusions.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-01-27 08:06:39 +01:00
James Roy
6524e670b3 edtlib: Fix the accidental merging of examples in the binding
Fix the example nodes in the examples block being accidentally
merged and overwritten during build.

Signed-off-by: James Roy <rruuaanng@outlook.com>
2026-01-21 17:05:41 +01:00
Jamie McCrae
ac348a7ab5 scripts: dts: gen_dts_cmake: Output compatibles for no prop. nodes
Seemingly partitions (fixed-partitions) have no properties when
the edt file is loaded, work around this issue by outputting
compatibles for nodes that have them but have no properties, also
fixes some other outputs for misc. devices

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-01-20 15:30:18 +00:00
Jamie McCrae
7a18e3a8cc scripts: dts: gen_dts_cmake: Add DT_UNIT_ADDR to pickled CMake
Adds a new property which outputs the absolute address of a dts
device (if it is available) which will take the parent nodes into
consideration without a user having to manually trawl through
devices (which is error prone depending upon how they are layered)

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-01-20 13:22:53 +00:00
Pieter De Gendt
91278bdddf devicetree: Add DT_CHILD_BY_UNIT_ADDR_INT
Allow fetching child node identifiers by integer unit address.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2025-12-08 13:09:24 -05:00
Lucien Zhao
98673d0aad scripts: ... :edtlib.py: update edtlib.py to generate some warning messages
During the actual development process, it was discovered that the
controller/device' would describe the bus type in the binding. However,
when the two sides did not match, the generated process would not be
affected and there were no any prompts. This made it very difficult for
developers to identify the problem.

I've updated the implementation to:
1. Add a `warn_bus_mismatch` kwarg to `edtlib.EDT()` constructor
   (default: False)
2. Add a `--warn-bus-mismatch` flag to gen_edt.py
3. Only show the warning when explicitly opted in
4. Add some checks in the edtlib. When the bus type of the node
   does not match the binding requirements, provide some auxiliary
   judgment information:
     a. bus position of the node
     b. available binding types
     c. expected binding type.

Signed-off-by: Lucien Zhao <lucien.zhao@nxp.com>
2025-12-06 11:39:17 -05:00
James Roy
44106ac05f edtlib: binding: Add a examples keyword
Add an `examples` keyword to the binding to
provide a minimal example node for the binding.

Signed-off-by: James Roy <rruuaanng@outlook.com>
2025-12-02 20:53:01 -05:00
Anton Puppe
043a725b1f edtlib: Fix unformatted error message
Adds a missing f in the second line of a multiline f-string.
Previously, having the wrong top-level keys in a DTS binding YAML file
could cause a partially unformatted error message to be printed.

Signed-off-by: Anton Puppe <anton-noel-flynn.puppe@zeiss.com>
on-behalf-of: @ZEISS anton-noel-flynn.puppe@zeiss.com
2025-12-02 20:52:34 -05:00
Kyle Bonnici
589be43e2e devicetree: remaining files
Applying dts-linter results for remaining format files

Signed-off-by: Kyle Bonnici <kylebonnici@hotmail.com>
2025-11-28 10:09:39 +00:00
Kyle Micallef Bonnici
1476fcb935 Devicetree: remove deprecated ok state
The `ok` state is deprecated and very few files are using this.
The DTS spec also does not have this value.

This PR removes this value once and for all.

Signed-off-by: Kyle Micallef Bonnici <kylebonnici@hotmail.com>
2025-10-09 12:36:43 -04:00
Martí Bolívar
0907a05baf scripts: dts: fix CMake DT API helper for compatible properties
Our build system DT API has a dt_comp_path() function used to look up
paths of nodes with a given compatible. This relies on the generated
edt.pickle.cmake file in the build directory to look inside the
concrete devicetree for the current application build.

The script gen_dts_cmake.py is responsible for generating
edt.pickle.cmake. It currently generates the data needed by
dt_comp_path() by looking inside each edtlib.Node object's "props"
attribute. This attribute in turn is fed by the "properties:" key in
the node's YAML binding. This leads to an edge case which is breaking
the dt_comp_path() API.

In most cases, we don't notice this edge case because base.yaml, which
is included by nearly all bindings, has a definition for "compatible"
in its "properties:" map. However, bindings are not required to
include base.yaml, and bindings do not have to explicitliy define a
"compatible" entry in their "properties:". An example of a binding
that does neither is fixed-partitions.yaml: it only has #address-cells
and #size-cells in its "properties:".

Nonetheless, "compatible:" is always a valid property name because
it's defined in the DT spec, and we should make the CMake API robustly
detect all nodes with a given compatible, regardless of whether that
node's binding explicitly defines it or not.

To make this happen, rely on the edtlib.Node.compats attribute instead
of edtlib.Node.props. The compats attribute is always defined even if
the node's YAML binding doesn't have an explicit entry for
"compatible".

Signed-off-by: Martí Bolívar <marti.bolivar@oss.qualcomm.com>
2025-10-03 21:00:29 -04:00
Benjamin Cabé
635e7c7261 sca: add DT diagnostic tool
implemented as an SCA for now but might benefit from being baked into
the build system so that it's always available.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-09-18 15:42:42 +01:00
Declan Snyder
7e92b70437 include: devicetree: Add more PHA macros
Add more macros for interacting with controller/data type of
relationships (phandle arrays / cells)

Add macros for arbitrarily iterating cells of phandle specifiers

Add tests for the new macros

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
2025-09-04 14:43:13 +02:00
Luca Burelli
49bf6aad88 dtlib: (cosmetic) use filename and line number on all messages
Take advantage of the new 'filename' and 'lineno' attributes of Node and
Property objects to provide more informative error and status messages
by printing the actual source file reference of the corresponding
object, always using the unquoted file:line format in error messages.

No functional change is introduced by this commit.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-07-19 15:34:13 -04:00
Andrey VOLKOV
957f10c3a0 edtlib: add new tests for 'interrupt-map'
Add tests to check the correctness of '#address-cells' usage.
The missing tests have allowed bug #77890 to persist for years.

Signed-off-by: Andrey VOLKOV <andrey.volkov@munic.io>
2025-06-27 10:57:38 +02:00
Ioannis Damigos
871afee41c edtlib: fix _raw_unit_addr() function
The '_raw_unit_addr()' function was incorrectly written a long time ago.
It tries to look up and use the '#address-cells' of the node containing
the 'interrupts' property itself, instead of using the '#address-cells' of
the interrupt controller's node (or its parent).

As a result, the mapping is successful only if the '#address-cells' value
is the same in both the node and the interrupt controller, all other cases
lead to random errors being generated by the 'gen_defines.py' script.

Also, the function was trying to use the '#address-cells' value as a
little-endian one, which led to unpredictable results as well.
This problem has been fixed too.

Fixes #77890, and probably #78020

Signed-off-by: Andrey VOLKOV <andrey.volkov@munic.io>
Signed-off-by: Ioannis Damigos <ioannis.damigos.uj@renesas.com>
2025-06-27 10:57:38 +02:00
Ioannis Damigos
1b1bfc9cc8 edtlib: Improve _interrupt_parent() function
According to the following comment on github
https://github.com/zephyrproject-rtos/zephyr/pull/77900/files#r1750393745
edtlib implementation is partially correct and it is missing two things:

1. If an ancestor has an interrupt-controller or interrupt-map property,
   the walk must terminate.
2. If an interrupt-parent property is found, the linked node must be a
   valid interrupt controller or nexus.

This commit add these checks.

Signed-off-by: Ioannis Damigos <ioannis.damigos.uj@renesas.com>
2025-06-27 10:57:38 +02:00
Benjamin Cabé
b315a77808 scripts: dts: edtilb: inclusive language fix
replace "grandfathered-in" by the more inclusive "legacy"

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-06-23 16:31:16 -05:00
Camille BAUD
d03b7ffdbb scripts: gen_edt.py: add ability to get properties from /cpus
Adds ability to get properties from the /cpus group,
in the goal of retrieving timebase-frequency for CPU groups.

Signed-off-by: Camille BAUD <mail@massdriver.space>
2025-06-18 09:12:26 -04:00
Fin Maaß
c2fff4a3e4 devicetree: Enhance DT_ENUM_HAS_VALUE macro for arrays
On arrays DT_ENUM_HAS_VALUE() and DT_INST_ENUM_HAS_VALUE()
were only checking the first index, this changes it to check all indexes.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2025-06-12 11:44:46 +02:00
Luca Burelli
ed7f2e0833 scripts: dts: dtlib: preserve order of properties in DTS output
Ensure that the order of properties in the output DTS file matches the
order in which they are defined in the DTS source files by moving props
to the end of the dictionary when they are accessed.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-06-05 15:18:40 -05:00
Luca Burelli
0a4e2e383f scripts: dts: dtlib: improve formatting of long arrays
Split long arrays into multiple lines to improve readability of the
output DTS file. A new line is started when the array data exceeds
80 characters.

Add a few test entries to verify the new behavior.

Note: the F821 linter suppression prevents flagging 'array_start' and
'array_newline' as undefined variables. This is because these variables
are initialized when an opening brace is output, which is necessarily
before any element in a byte or prop array. A sequence of markers not
following this pattern would indicate a bug in the DTS parsing code.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-06-05 15:18:40 -05:00
Fin Maaß
f7153012ef dts: enum_macros: make sure that they are lowercase
DT_ENUM_HAS_VALUE_BY_IDX states, that the value
must be lowercase-and-underscores, this makes sure,
that they can match.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2025-05-28 17:48:57 +02:00
Grzegorz Swiderski
468db18389 cmake: modules: Add zephyr_dt_import
Extract the part of `dts.cmake` that invokes `gen_dts_cmake.py`, then
generalize it into a CMake extension, which can be reused by sysbuild.

The Python script itself is also updated, so that the generated CMake
file can accept an input variable DEVICETREE_TARGET, which comes from
the `zephyr_dt_import(TARGET ...)` argument.

Signed-off-by: Grzegorz Swiderski <grzegorz.swiderski@nordicsemi.no>
2025-05-22 13:44:18 +02:00
Luca Burelli
fe7f71ba16 dtlib: add test for lineno/filename comments
Tweak the existing filename_and_lineno test to also check the generated
comments in the string representation of the devicetree match expected
contents and alignment.

Using tmpdir as the base directory simplifies the comparison by avoiding
directory separator issues.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-05-16 09:38:35 +02:00
Luca Burelli
c1603b3163 gen_edt: use workspace dir as base for relative paths in comments
This commit allows comments to reference files with paths that are relative
to the Zephyr workspace root. This is done by adding a new argument
'--workspace-dir' to the 'gen_edt.py' script, which is passed to the
'EDT' and 'DT' classes and used instead of the current working directory.

The workspace directory is set to WEST_TOPDIR if West is in use,
otherwise it is set to the parent directory of ZEPHYR_BASE so that
Zephyr files have a 'zephyr/' prefix.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-05-16 09:38:35 +02:00
Luca Burelli
a63cb8e74d dtlib: fix double empty line before root node
The root node is the first node in the DTS string representation, and is
currently separated from the headers by two empty lines.

Adjust the spacing so that only one line is printed in all situations. A
small adjustment is added to the test suite to keep the current expected
outputs unchanged.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-05-16 09:38:35 +02:00
Benjamin Cabé
afdb62d1e2 dtlib: add lineno/filename to string representation of a DT
Output lineno/filename as comments in the string representation of a DT
to help with debugging DT issues. Also, remove the added comments when
comparing the string representation of a DT to a reference string in the
DT testsuite.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-05-16 09:38:35 +02:00
Luca Burelli
6b325daa2a dtlib: wrap array properties in string representation
List each element of a property array in a different line to improve
the readability of the generated DTS file.
Update the test suite's expected outputs accordingly.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-05-16 09:38:35 +02:00
Luca Burelli
4b8be385c0 dtlib: fix 'phandle' property's filename and line number
The phandle property is auto-generated when parsing the DTS, so there is
no 'source information'. This commit sets the filename and line number
of the phandle property to be the same as the first reference to the
target node.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-05-16 09:38:35 +02:00
Aksel Skauge Mellbye
73b8d1b637 edtlib: Expose binding title in node class
Make the binding title available from the node the same way
the binding description is propagated.

Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
2025-05-02 09:15:50 +02:00
Jamie McCrae
51cf4157e6 scripts: dts: gen_defines: Add support for fixed-subpartitions
Adds support for generating defines for this binding type

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-04-30 18:44:06 +02:00
James Roy
285b8ac933 style: edtlib: Use a more efficient expression
Replaced nested loops with a list comprehension
to improve performance. Execution time improved
from 0.0046203136444s to 0.0040774345397s

Signed-off-by: James Roy <rruuaanng@outlook.com>
2025-04-09 22:05:22 +02:00
James Roy
ee17657ad3 edtlib: binding: Add a title keyword
Add a 'title' keyword to the binding to provide a short
description of the binding, while 'description' serves as
the long description.

Signed-off-by: James Roy <rruuaanng@outlook.com>
2025-04-02 12:54:24 +02:00
James Roy
9b795840f9 style: edtlib: Remove the redundant keys() method
Remove the redundant keys method when using the
in statement on a dict to fix the Ruff SIM118
warning.

Signed-off-by: James Roy <rruuaanng@outlook.com>
2025-03-28 12:22:00 +01:00
James Roy
8a2cde9688 style: edtlib: Use from to chain the exception
Use the from keyword to chain exceptions in
order to fix the Ruff B904 warning.

Signed-off-by: James Roy <rruuaanng@outlook.com>
2025-03-28 12:22:00 +01:00
James Roy
826ddaed97 style: edtlib: Use the more readable not-equal operator
Replace 'not xx == xx' with 'xx != xx' to
fix the Ruff SIM201 warning.

Signed-off-by: James Roy <rruuaanng@outlook.com>
2025-03-28 12:22:00 +01:00
James Roy
b543c26548 style: edtlib: Reorganize the single-line if statement block
Move the statement in the single-line if block
to a new line to fix the Ruff E701 warning.

Signed-off-by: James Roy <rruuaanng@outlook.com>
2025-03-28 12:22:00 +01:00