Commit graph zephyr/scripts/dts
Author SHA1 Message Date
Tomasz Moń
bdd9775677 scripts: dts: gen_defines: Avoid percent signs in identifiers
Update regular expression in str2ident to replace percent sign (%)
character when creating identifiers.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2026-08-26 15:15:44 -04:00
Perry Naseck
cb8b633d62 dts: Add gen defines and bnf for DT_BINDING_COMPAT_*
Add gen defines and bnf for DT_BINDING_COMPAT_*, which allows
for getting a node's compatible string at compile time. Adds
DT_BINDING_COMPAT_TOKEN, DT_BINDING_COMPAT_UPPER_TOKEN, and
DT_BINDING_COMPAT_UNQUOTED.

Assisted-by: Claude:claude-opus-5

Signed-off-by: Perry Naseck <pnaseck@media.mit.edu>
2026-08-25 08:05:11 -07:00
Etienne Carriere
7a65b76fc0 scripts: dts: Add info on how to test edtlib.py and dtlib.py
Add info in local README.txt on how to run edtlib.py and dtlib.py tests.

Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
2026-08-22 19:19:29 -04:00
Muhammad Waleed Badar
0791e4c24e dts: add devicetree support for the dma-ranges property
Zephyr's devicetree tooling parses and generates macros
for the ranges property but has no equivalent support for
dma-ranges, even though both are defined the same way by
the Devicetree Specification (§2.3.9) and edtlib.py already
has the machinery to parse address-translation triplets.

This adds the same pipeline that already exists for ranges.
edtlib.py now parses dma-ranges into Node. dma_ranges using
the same cell-based translation logic as Node via a new
_init_dma_ranges() method.

gen_defines.py emits DT_N_..._DMA_RANGES_* macros for each node
with a dma-ranges property through a new write_dma_ranges() function.

devicetree.h gains the DT_DMA_RANGES_* public API, including HAS_IDX,
CHILD_BUS_ADDRESS_BY_IDX, PARENT_BUS_ADDRESS_BY_IDX, LENGTH_BY_IDX,
NUM_DMA_RANGE, and FOREACH_DMA_RANGE. base.yaml documents the dma-ranges
property per DT spec §2.3.9.

Assisted-by: Claude:claude-sonnet-5
Signed-off-by: Muhammad Waleed Badar <walid.badar@gmail.com>
2026-08-19 17:09:21 +01:00
Sylvio Alves
3f969c6984 scripts: dts: only warn on a locally declared required default
The required-with-a-default check runs on the property settings
left after includes are merged, so a binding that inherits a
default and deliberately overrides it with required was reported
even though nothing is wrong.

That combination is well defined: the required check runs first
and errors out when the property is absent, so the inherited
default never applies. Keep a copy of the properties declared
locally and warn only when both settings come from the same file.

Included files are merged into the raw contents in place, which
also covers any nested child binding, so the copy is taken before
the merge and handed down to each child binding in turn. A child
binding which is only inherited declares nothing of its own and
so gets an empty copy. Add tests covering the reported and the
exempt cases, up to the grandchild binding level.

Assisted-by: Claude Code:opus-4-8
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2026-08-11 07:45:33 -04:00
Omar Naffaa
fd701acfe6 scripts: dts: Loosen type annotation on "val"
Update "out_dt_define" macro to allow integer types
as the value parameter. Prevents unneeded warning
when "val" is specified as an integer.

Signed-off-by: Omar Naffaa <onaffaa@qti.qualcomm.com>
2026-07-28 18:11:22 -04:00
Fin Maaß
71aadac132 dts: tests: allow cpu props be set in cpus
Add a test to check that putting common
cpu props in the parent cpus node works.

Assisted-by: GitHub Copilot:GPT-5.3-Codex

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2026-07-20 17:30:37 -05:00
Fin Maaß
11dc56c5c7 dts: allow cpu props be set in cpus
This allows to put common props of
cpu nodes in the parent cpus node, as
specified in the devicetree spec in 3.8.

Assisted-by: GitHub Copilot:GPT-5.3-Codex

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2026-07-20 17:30:37 -05:00
Fin Maaß
add5c1ccef dts: add test for dependency-mode
Add a test for dependency-mode.

Assisted-by: Github Copilot:GPT-4.1
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2026-07-16 10:43:34 -04:00
Fin Maaß
8d3f746994 dts: ethernet: use dependency-mode for phy-handle
Move `phy-handle` to use the dependency-mode prop
key instead of the hardcoded code.

Because all ethernet drivers only need to use the
phy-handle in the iface init, we can ignore the
phy-handle dependency completly instead of only
ignoring it if the phy-handle pointing to a child
node of the ethernet node.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2026-07-16 10:43:34 -04:00
Fin Maaß
e29a7d2a22 dts: add dependency-mode prop key
add dependency-mode prop key, so it can be
changed what dependency a phandle
in the dt introduces. With this it can be set
in the dt binding that a phandle is f.e. ignored
when the dt ordinal is calculated.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2026-07-16 10:43:34 -04:00
Etienne Carriere
086b5b43f7 scripts: dts: python-devicetree: warn required props with a default value
Emit a warning trace message when a DT property is required but
also provides a default value.

Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
2026-07-10 08:52:35 -05:00
Jamie McCrae
31da142a93 scripts: dts: gen_defines: Fix ZEPHYR_BASE output
Fixes this missing output, which helps with repducible build
debugging, to use the zephyr prefix when the bindings are located
there irrespective of if the (long deprecated) environmental value
is set

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-07-07 09:52:35 +02:00
Guðni Már Gilbert
e68fdcfe32 scripts: dts: apply ruff format to gen_edt.py
Drop the script from .ruff-excludes.toml

Signed-off-by: Guðni Már Gilbert <gudni.m.g@gmail.com>
2026-07-01 14:32:29 -04:00
Ryan McClelland
739f9edba9 counter: add devicetree reader macros
Add devicetree reader macros for counter capture. These include
an index for the channel number and default flags. These are
intended to eventually to be used within drivers for timestamp
capturing.

Signed-off-by: Ryan McClelland <rymcclel@gmail.com>
2026-06-30 06:46:41 -04:00
Jamie McCrae
9197ece1e8 scripts/cmake: Add monitoring for dts bindings being changed
Generates a new file for use by the build system which lists all
the paths to dts bindings used in a build, then from CMake adds a
dependency to these files so that if they are modified, CMake will
re-run.

This has been implemented by adding support to edtlib to output
details on bindings and binding paths inside of the python code

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-06-29 11:28:16 +02:00
Anas Nashif
e836695cc8 scripts: fix various typos
Fix various typos under scripts/

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-06-23 09:12:58 -04:00
Guðni Már Gilbert
efe74cabc3 scripts: dts: apply ruff format to gen_defines
Drop the script from .ruff-excludes.toml

Signed-off-by: Guðni Már Gilbert <gudni.m.g@gmail.com>
2026-06-22 18:02:08 -04:00
Fabio Baltieri
38906f701a scripts: dts: Add min-len/max-len test cases
Add test cases for the min-len and max-len binding properties.

Assisted-by: Gemini
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2026-06-03 18:27:48 -04:00
Fabio Baltieri
1ebe3a53db scripts: dts: Add min-len/max-len properties to edtlib spec.
Add optional min-len/max-len properties to edtlib spec to specify a valid
length range for array type values. Basically same as 7ddcb93d4a but
for prop length.

Assisted-by: Gemini
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2026-06-03 18:27:48 -04:00
Josuah Demangeon
1d35748d5c style: remove whitespace in < ... >; syntax from doc/comments
Fix devicetree coding style regarding whitespaces through the tree.
This affects code snippets inside documentation, comments, error messages
as to encourage a style that passes CI. Follow-up of #101619

Signed-off-by: Josuah Demangeon <me@josuah.net>
2026-05-29 20:53:20 -07:00
James Roy
28b8d644c1 devicetree: Add DT_NODELABEL_C_TOKEN_* macros
Add the `DT_NODELABEL_C_TOKEN` and
`DT_NODELABEL_C_TOKEN_BY_IDX` macros to retrieve
the C symbolic name of a node.

Signed-off-by: James Roy <rruuaanng@outlook.com>
2026-05-22 21:55:42 +02:00
Pieter De Gendt
5faf064e72 scripts: dts: edtlib: Verify const type
Update the const value validation, to also include falsy constants, and
check for plain integer types in case of int/array property type.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-05-20 14:06:50 +02:00
Pieter De Gendt
3720dabf37 scripts: dts: edtlib: Verify plain int type for default values
If the binding has a default property that is an int or an array of
integers, we verify for plain ints.
As bool is a subclass of int in Python we should check for non boolean
values.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-05-20 14:06:50 +02:00
Pieter De Gendt
4cb99015a7 scripts: dts: Add test cases for min/max properties
Add success and error tests for min/max binding properties.

Assisted-by: Claude:claude-sonnet-4.6
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-05-20 14:06:50 +02:00
Pieter De Gendt
7ddcb93d4a scripts: dts: Add min/max properties to edtlib spec.
Add optional min/max properties to edtlib spec to specify a valid range for
int or array type values.

Assisted-by: Claude:claude-sonnet-4.6
Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-05-20 14:06:50 +02:00
Pieter De Gendt
c54d4c6bcf scripts: dts: tests: dtlib: Test signed-aware negative expressions
Add a test case verifying that a parenthesized expression evaluating to
a negative value (e.g. `(4 - 6)`) is preserved as signed when decoded
via to_num(signed_aware=True) and to_nums(signed_aware=True), extending
the existing coverage for negative literals like `(-1)`.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-05-20 10:56:34 +02:00
Kyle Bonnici
9fc69ebbb1 Style: remove space between block comment and > ]
Linter not ensures that > and ] have no white spaces when these are
preceded with a block comment.

Signed-off-by: Kyle Bonnici <kylebonnici@hotmail.com>
2026-05-19 17:46:18 -04:00
Swift Tian
a8bb4fdf93 scripts: devicetree: add DESCENDANT_NUM_ON_BUS generated macros
Add generated macros for counting nodes on a specific bus under a bus
controller:

- DT_(INST_)DESCENDANT_NUM_ON_BUS()
- DT_(INST_)DESCENDANT_NUM_ON_BUS_STATUS_OKAY()

The count intentionally walks descendants instead of only direct children.
This covers common devicetree structures where helper/container nodes sit
between a controller and the actual on-bus device nodes.

Traversal stops at child bus-controller nodes, so devices behind sub-buses
are not counted in the parent controller's result.

Also add edtlib Node.on_bus resolution, validated against the parent bus
controller bus types, so generation uses the resolved on-bus value.

Signed-off-by: Swift Tian <swift.tian@ambiq.com>
2026-05-18 10:14:32 +01:00
Pieter De Gendt
1b0dcebb9b scripts: dts: tests: dtlib: Add tests for signed_aware to_num(s)
Make sure we cover different types of signed_aware parsing. Negative
literals like (-1) or a hex value like 0xFFFFFFFF should result in
different values.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-05-12 17:12:41 +02:00
Pieter De Gendt
17648dbeff scripts: dts: tests: dtlib: Add negative override tests
Validate that the signed cell offsets are cleared on override.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-05-12 17:12:41 +02:00
Pieter De Gendt
34ddd823c4 scripts: dts: Add negative int test
Add negative and negative-array properties to the test binding and
test DTS to verify that signed integer literals are correctly
propagated through edtlib as negative Python integers.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-05-12 17:12:41 +02:00
Pieter De Gendt
44518e7cbe scripts: dts: Allow signed int/array values
Track the byte offsets of cells parsed from negative literals
(e.g. (-1)) in a new _signed_cell_offsets set on Property. Expose
this via a signed_aware parameter on to_num() and to_nums(): when
True, each cell is interpreted as signed only if it was written as a
negative literal, leaving positive and hex values unsigned.

Update edtlib to pass signed_aware=True when reading "int" and "array"
typed properties so binding values reflect the sign as written in the DTS
source.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2026-05-12 17:12:41 +02:00
Guðni Már Gilbert
1fc3294526 scripts: dts: optimize generated edt.pickle.cmake
Instead of  writing one item for each set_target_properties()

set_target_properties(${DEVICETREE_TARGET} PROPERTIES <item1>)
set_target_properties(${DEVICETREE_TARGET} PROPERTIES <item2>)
...
set_target_properties(${DEVICETREE_TARGET} PROPERTIES <itemN>)

Write one set_target_properties which contains all items:

set_target_properties(${DEVICETREE_TARGET}
  PROPERTIES
    <item1>
    <item2>
    ...
    <itemN>
)

Later when edt.pickle.cmake is included in extensions.cmake
via include(${gen_dts_cmake_output})
CMake will process the file much faster.

Signed-off-by: Guðni Már Gilbert <gudni.m.g@gmail.com>
2026-05-06 07:08:57 +02:00
Kyle Bonnici
94ed499c2c scripts: dts: verify default status is forbidden
Make sure that we don't allow bindings which manually
specify any defaults for the status
properties. See DTSpec 2.3.4.

Signed-off-by: Kyle Bonnici <kylebonnici@hotmail.com>
2026-03-27 20:22:23 -04:00
Kyle Bonnici
1e3aa2ae79 scripts: dts: forbid status defaults
The status property indicates the operational status of a device.
    The lack of a status property should be treated as
    if the property existed with the value of "okay".

We are currently allowing defaults.

This is a continuation of
https://github.com/zephyrproject-rtos/zephyr/pull/104931

Signed-off-by: Kyle Bonnici <kylebonnici@hotmail.com>
2026-03-27 20:22:23 -04:00
Yves Wang
b104f826ca scripts: dts: edtlib: improve dts binding path formatting
Add quotes around binding file paths in error messages for better
readability and consistency. Also normalize paths using os.path.normpath
to ensure consistent path separators across platforms.

Signed-off-by: Yves Wang <zhengjia.wang@nxp.com>
2026-03-24 07:26:21 +01:00
Oleksii Moisieiev
9f37bb0059 devicetree: add macros for reg property iteration
Introduce DT_FOREACH_REG and DT_INST_FOREACH_REG macros to enable
iteration over reg entries in devicetree nodes by invoking a user-
supplied macro per entry. Add support for macros accepting a
separator and variadic arguments with the new DT_FOREACH_REG_SEP,
DT_FOREACH_REG_VARGS, and DT_FOREACH_REG_SEP_VARGS macros, as well
as their DT_INST_ variants.

The DT_FOREACH_REG macro mirrors the behavior of the ranges property.

Update the devicetree macro generation logic in gen_defines.py to
emit the new macro variants. Document the additions by expanding the
Augmented Backus-Naur Form grammar in macros.bnf. Add detailed
comments with usage examples and parameter details for all new macros.

Expand test coverage with new overlay nodes and dedicated tests to
verify macro correctness and behavior, across various node scenarios
including multi-register, single-register, and nodes lacking reg
properties.

Signed-off-by: Oleksii Moisieiev <oleksii_moisieiev@epam.com>
Signed-off-by: Svitlana Drozd <svitlana_drozd@epam.com>
2026-03-23 12:30:30 -05:00
Kyle Bonnici
eecf59716c dts: address dtslib unambiguous path matching
The spec makes it clear that node address can be omitted from node path
if not unambiguous see 2.2.3. Path Names

> A unit address may be omitted if the full path to the node is
unambiguous.

e.g.
````
/ {
foo@10 {};
}
```

both paths -> /foo and /foo@10 should work.

Signed-off-by: Kyle Bonnici <kylebonnici@hotmail.com>
2026-03-20 07:11:12 +01:00
Kyle Bonnici
82a84d628c dts: address dtslib address case sensitivity
IMO the spec is clear about the case insensitivity. The node address
must be match the reg value see 2.2.1.1. Node Name Requirements

> The unit-address must match the first address specified in the reg
property of the node.

reg property is a prop-encoded array and by definition.
reg = <0xA> or reg = <0xa> are the same. hence Both foo@a and foo@A
are the same.

Signed-off-by: Kyle Bonnici <kylebonnici@hotmail.com>
2026-03-20 07:11:12 +01:00
Fin Maaß
41ac62b79a dts: allow refering childs with phy-handle
According to the DT spec the 'phy-handle' phandle prop
is required, when a phy is used. As this phy could be
a child, we have to filter it out to not get a cycle in the graph.

This allows the phy to be a child of the eternet controller,
when using the  'phy-handle' dt prop.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2026-03-19 11:37:05 +00:00
Bjarki Arge Andreasen
9bfe7ca1f5 scripts: dts: python-devicetree: extend special casing to io-channels
Extend the special casing of specifer space to include io-channels,
making the implementation a bit more easily scalable for the
future as well. This allows defining io-channels like gpios,
prepending a name like foo-io-channels, which is useful when
multiple groups of io-channels need to be defined for a node:

  foo {
          bar-io-channels = <&baz 0>, <&baz 1>;
          qiz-io-channels = <&baz 2>, <&baz 3>;
  };

This is useful for defining channels to be read in parralel
sequences.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
2026-03-18 15:16:49 -05:00
Jamie McCrae
ba68dd026f scripts: dts: gen_defines: Add support for zephyr,mapped-partitions
Adds support for outputting partition information on this new
compatible, to match fixed-partitions

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-03-17 18:24:52 -04:00
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