Go to file
Simon Glass d6c37926ff dtc: Move path-reference handling out of the grammar
The grammar action for a top-level &{/path} { ... } holds its merge
logic, including making an overlay fragment in a plugin.

Move it into merge_ref(), which can tell a path from a label by looking
at the reference, and use a single rule for both kinds of reference.

The output does not change.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Message-ID: <20261126184126.1472738-9-sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
2026-11-27 14:00:59 +11:00
.github/workflows ci: Disable libyaml for mingw32 Windows builds 2026-11-11 15:41:46 +11:00
Documentation fdtput: Correct the description of -t in the manual 2026-10-28 12:45:39 +11:00
libfdt libfdt: Don't zero alignment padding bytes if there aren't any 2026-11-23 11:47:36 +11:00
pylibfdt pylibfdt: Unpack Property.as_list() in a single struct.unpack() call 2026-11-17 14:43:54 +11:00
scripts scripts: Report failures in scripts/install-deps.sh 2026-10-19 12:50:24 +11:00
tests dtc: Merge &{label} in a plugin as with &label 2026-11-27 14:00:59 +11:00
.clang-format Add clang-format config 2024-12-06 14:44:46 +11:00
.editorconfig editorconfig: use tab indentation for version.lds 2023-08-04 18:02:21 +10:00
.gitignore .gitignore: Ignore .cache/ 2026-11-23 11:35:10 +11:00
.gitlab-ci.yml ci: Add GitLab CI configuration for Linux builds 2025-08-01 15:46:48 +10:00
AGENTS.md tests: More portable installation of SIGINT handler 2026-05-28 13:55:51 +10:00
BSD-2-Clause README.license: Update to reflect SPDX tag usage 2019-06-21 21:06:10 +10:00
CLAUDE.md docs: Add CLAUDE.md referencing AGENTS.md 2026-05-26 17:50:29 +10:00
CONTRIBUTING.md README: Explain how to build with meson 2026-10-30 06:52:57 -06:00
GPL Update the GPL2 text to the latest revision 2019-05-21 09:58:37 +10:00
Makefile meson: Add missing -Wsign-compare warning 2026-11-23 13:41:38 +11:00
Makefile.convert-dtsv0 dtc: Add GPLv2 SPDX tags to files missing license text 2019-06-21 21:06:10 +10:00
Makefile.dtc dtc: Replace GPLv2 boilerplate/reference with SPDX tags 2019-06-21 21:06:10 +10:00
Makefile.utils dtc: Add GPLv2 SPDX tags to files missing license text 2019-06-21 21:06:10 +10:00
README.license Fix some typos 2025-03-14 13:50:32 +11:00
README.md README: Add overview blurbs for dtc and ancillary tools 2026-11-17 14:43:54 +11:00
TODO dtc: Update TODO files 2007-12-19 08:20:26 -06:00
VERSION.txt Bump version to v1.8.1 2026-05-28 12:40:45 +10:00
checks.c treewide: Clean up #includes 2026-11-11 17:39:07 +11:00
convert-dtsv0-lexer.l meson: Add missing -Wsign-compare warning 2026-11-23 13:41:38 +11:00
data.c treewide: Clean up #includes 2026-11-11 17:39:07 +11:00
dtc-lexer.l meson: Add missing -Wsign-compare warning 2026-11-23 13:41:38 +11:00
dtc-parser.y dtc: Move path-reference handling out of the grammar 2026-11-27 14:00:59 +11:00
dtc.c treewide: Clean up #includes 2026-11-11 17:39:07 +11:00
dtc.h dtc: Move label-reference handling out of the grammar 2026-11-27 14:00:59 +11:00
dtdiff dtdiff: Use input format dtb for dtbo files 2025-07-01 20:42:22 +10:00
fdtdump.c treewide: Clean up #includes 2026-11-11 17:39:07 +11:00
fdtget.c fdtget: Use libfdt iterators instead of open coded loops 2026-08-27 13:48:09 +10:00
fdtoverlay.c fdtoverlay: provide better error message for missing `/__symbols__` 2024-10-30 16:01:37 +11:00
fdtput.c fdtput: Name the property when it cannot be deleted 2026-10-29 12:59:28 +11:00
flattree.c treewide: Clean up #includes 2026-11-11 17:39:07 +11:00
fstree.c treewide: Clean up #includes 2026-11-11 17:39:07 +11:00
livetree.c dtc: Move path-reference handling out of the grammar 2026-11-27 14:00:59 +11:00
meson.build meson: Add missing -Wsign-compare warning 2026-11-23 13:41:38 +11:00
meson_options.txt meson: port python bindings to build natively via meson and meson-python 2025-05-01 19:27:10 +07:00
pyproject.toml meson: port python bindings to build natively via meson and meson-python 2025-05-01 19:27:10 +07:00
srcpos.c treewide: Clean up #includes 2026-11-11 17:39:07 +11:00
srcpos.h srcpos: Define srcpos_free 2025-06-09 22:27:00 +10:00
treesource.c treewide: Clean up #includes 2026-11-11 17:39:07 +11:00
util.c Escape spaces in depfile with backslashes. 2024-10-24 15:44:47 +11:00
util.h Escape spaces in depfile with backslashes. 2024-10-24 15:44:47 +11:00
version_gen.h.in build-sys: add meson build 2020-10-21 14:36:07 +11:00
yamltree.c treewide: Clean up #includes 2026-11-11 17:39:07 +11:00

README.md

Device Tree Compiler and libfdt

The source tree contains the Device Tree Compiler (dtc) toolchain for working with device tree source and binary files and also libfdt, a utility library for reading and manipulating the binary format.

dtc and libfdt are maintained by:

Building

dtc and libfdt are built with Meson:

$ meson setup build
$ meson compile -C build
$ meson test -C build
$ meson install -C build

meson configure build lists the build options, e.g. -Dpython=disabled to skip the Python library. See the Meson quick guide for more, such as installing with --destdir. scripts/install-deps.sh installs the packages needed on common systems.

Building with make still works but is deprecated.

Python library

A Python library wrapping libfdt is also available. To build this you will need to install swig and Python development files. On Debian distributions:

$ sudo apt-get install swig python3-dev

The library provides an Fdt class which you can use like this, from build/tests after running the tests:

$ PYTHONPATH=../pylibfdt python3
>>> import libfdt
>>> fdt = libfdt.Fdt(open('test_tree1.dtb', mode='rb').read())
>>> node = fdt.path_offset('/subnode@1')
>>> print(node)
124
>>> prop_offset = fdt.first_property_offset(node)
>>> prop = fdt.get_property_by_offset(prop_offset)
>>> print('%s=%s' % (prop.name, prop.as_str()))
compatible=subnode1
>>> node2 = fdt.path_offset('/')
>>> print(fdt.getprop(node2, 'compatible').as_str())
test_tree1

You will find tests in tests/pylibfdt_tests.py showing how to use each method. Help is available using the Python help command, e.g.:

$ cd build/pylibfdt
$ python3 -c "import libfdt; help(libfdt)"

If you add new features, please check code coverage:

$ sudo apt-get install python3-coverage
$ cd build/tests
# It's just 'coverage' on most other distributions
$ python3-coverage run ../../tests/pylibfdt_tests.py
$ python3-coverage html
# Open 'htmlcov/index.html' in your browser

The library can be installed with pip from a local source tree:

$ pip install . [--user|--prefix=/path/to/install_dir]

Or directly from a remote git repo:

$ pip install git+git://git.kernel.org/pub/scm/utils/dtc/dtc.git@main

The install depends on libfdt shared library being installed on the host system first. Generally, using --user or --prefix is not necessary and pip will use the default location for the Python installation which varies if the user is root or not.

You can also install everything with meson if you like, but pip is recommended.

To install both libfdt and pylibfdt you can use:

$ meson setup [--prefix=/path/to/install_dir] build
$ meson install -C build

To disable building the python library, even if swig and Python are available, use:

$ meson setup -Dpython=disabled build

More work remains to support all of libfdt, including access to numeric values.

dtc

dtc compiles device tree source (.dts) into flattened device tree blobs (.dtb), decompiles .dtb blobs or /proc/device-tree-style filesystem trees (fs) back to .dts, emits YAML (.yaml, when built with libyaml) or assembly (.S), and runs semantic checks on the tree:

$ dtc -I dts -O dtb -o board.dtb board.dts
$ dtc -I dtb -O dts -o board.dts board.dtb

See Documentation/manual.txt for full command-line reference documentation for dtc and the C utility tools below.

dtdiff

dtdiff normalizes and sorts two device trees via dtc -s -O dts and prints a unified diff between them. Each input may be a .dts source file, a .dtb / .dtbo blob, or a /proc/device-tree-style directory:

$ dtdiff before.dtb after.dtb
$ dtdiff board.dts /proc/device-tree

fdtget

fdtget reads property values (<node> <property> pairs), lists property names (-p, --properties), or lists subnode names (-l, --list) from a .dtb blob. Use -t, --type (e.g. -ts for strings, -ti / -tu / -tx for signed, unsigned, or hex integers, or -tr for raw bytes) to control formatting, and -d, --default to provide a fallback when a node or property is missing:

$ fdtget board.dtb / model /cpus/cpu@0 reg
$ fdtget -tx board.dtb /soc/serial@1000 reg
$ fdtget -l board.dtb /soc

fdtput

fdtput modifies a .dtb blob in place: writing property values, creating nodes (-c, --create), deleting nodes and their subnodes (-r, --remove), or deleting properties (-d, --delete). Pass -t, --type (e.g. -ts for strings or -tx for hex integers; default is decimal integers) to control value encoding, and -p, --auto-path to create any missing nodes along the target path:

$ fdtput -p -ts board.dtb /soc/i2c@3000 compatible vendor,i2c
$ fdtput -tx board.dtb /soc/serial@1000 reg 1000 100
$ fdtput -d board.dtb /soc/i2c@3000 compatible

fdtdump

fdtdump is a low-level debugging tool that dumps the FDT header, /memreserve/ entries, and raw structure-block contents of a .dtb blob (-d, --debug prints tag offsets; -s, --scan scans a larger file for an embedded FDT). For general decompilation of a .dtb to .dts, use dtc -I dtb -O dts instead:

$ fdtdump -d board.dtb

convert-dtsv0

convert-dtsv0 converts obsolete version 0 .dts source files to /dts-v1/; syntax, writing each output to <filename>v1:

$ convert-dtsv0 old-board.dts

fdtoverlay

fdtoverlay applies one or more compiled .dtbo overlays (-v, --verbose for progress) onto a base .dtb blob (-i, --input, compiled with dtc -@ when overlays reference symbols) and writes the merged blob to -o, --output:

$ fdtoverlay -i base.dtb -o merged.dtb overlay1.dtbo overlay2.dtbo

Mailing lists