
Recall first from Config fragments and the product defconfig
- .config is generated output: every symbol expanded, thousands of lines, wrong for version control.
- make savedefconfig writes only the symbols that differ from the kernel's defaults, and the result is relative to that kernel version.
- merge_config.sh applies fragments in order: the last fragment wins, and every redefinition prints a warning.
Why the kernel needs a hardware description
4 min readUntil now the hardware was either emulated or configured in defconfig; the device tree is how a real kernel learns its hardware. This lesson answers why DT replaced board files, and how source, includes and the compiled blob fit together.
Start with the problem. A PC can ask its hardware what it is: PCI and USB devices identify themselves over the bus, and firmware tables such as ACPI describe the rest. Most of the hardware on an embedded SoC cannot do this. A UART controller sitting at some physical address, an I2C bus master, a GPIO bank wired to a specific pin: none of them can answer a probe. Someone must tell the kernel they exist, where they live in the memory map you studied earlier, and which interrupt line each one uses.
For years the ARM port answered this with per-board C source files inside the kernel tree, under arch/arm directories, that registered each device and its resources at boot. Every board had its own C file describing its devices, and every vendor copied and modified large chunks of platform code. The result was thousands of lines of near-duplicate C in the kernel, a rebuild for every board variant, and no way to boot one kernel image on two different boards. In March 2011 Linus Torvalds publicly complained about the state of the ARM platform code on the kernel mailing list, and the cleanup that followed pushed ARM toward a solution PowerPC and SPARC already used: the a structured data description of the hardware, passed to the kernel at boot instead of being compiled into it, which grew out of the Open Firmware standard (IEEE 1275).
The key move is separating data from code. The driver for a UART is code, and it is the same on every board that uses that UART. The address of the UART, its interrupt number and its clock are data, and they differ per board. Board files mixed the two; the device tree keeps only the data in a per-board file, while the drivers stay generic in the kernel. One kernel image can now boot many boards, each with its own device tree blob. This is also why defconfig from the previous lesson and the device tree answer different questions: Kconfig decides which drivers are built into the kernel, the device tree decides which hardware those drivers find at boot.
Two boundaries are worth naming now. First, the device tree describes hardware the kernel cannot discover by itself; devices on self-describing buses like PCI and USB are still enumerated at run time. Second, the device tree is not a configuration file for software: it describes the board, not user preferences. On your x86 Ubuntu host there is no device tree at all, because ACPI plays that role; you will compile your own device tree files in the practice exercises instead of reading a live one.
From source to blob: DTS, DTSI and dtc
5 min readThree file extensions carry the whole story. A device tree source: a human-readable text file describing one board, ending in .dts is the top-level source for a board. A device tree source include: a shared text fragment, ending in .dtsi, included by a .dts or another .dtsi holds descriptions shared by many boards, typically everything inside the SoC. A device tree blob: the compiled binary form of the tree, ending in .dtb, which the kernel parses at boot is what the machine reads. The compiler between them is the device tree compiler: it parses DTS text and emits a DTB, and can also decompile a DTB back to text.
The source language is small. A file starts with the version directive /dts-v1/;, then describes a tree of nodes starting at the root /. Each node has a name, braces, properties written as name = value;, and child nodes. Values are strings in quotes, numbers in angle brackets (called cells), or byte strings in square brackets. Here is a minimal but valid source you can compile yourself:
cat > demo.dts <<'EOF'
/dts-v1/;
/ {
#address-cells = <1>;
#size-cells = <1>;
model = "Demo board";
compatible = "demo,board";
memory@80000000 {
device_type = "memory";
reg = <0x80000000 0x20000000>;
};
chosen {
bootargs = "console=ttyS0,115200";
};
};
EOF
This says: a board called "Demo board", RAM starting at physical address 0x80000000, and a kernel command line. What compatible means for driver matching, and how cells are encoded, are the subjects of the next two lessons; here you only need to see that the file is plain structured text.
On Ubuntu 24.04, dtc comes from the device-tree-compiler package. The kernel also carries its own copy under scripts/dtc in the source tree, so a kernel build does not depend on the host package.
sudo apt install device-tree-compiler
dtc -I dts -O dtb -o demo.dtb demo.dts
dtc -I dtb -O dts -o demo.roundtrip.dts demo.dtb
The flags are consistent: -I sets the input format, -O the output format, -o the output file. The formats are dts (text), dtb (blob) and fs (a live tree exposed as a filesystem, which only exists on a board that booted with a device tree). The second command decompiles the blob back to text: open demo.roundtrip.dts next to demo.dts and you will see the same content, reformatted, with numbers normalized (a real run printed #address-cells = <0x01>; for the source line #address-cells = <1>;). dtc may print warnings about missing optional properties on such a minimal tree; a warning is not a failure, and the blob is still produced.
The DTB is a compact binary format called the flattened device tree. Its first four bytes are the magic value 0xd00dfeed, stored big-endian (a hex dump of the demo blob starts with d0 0d fe ed), followed by a header with offsets to a block of structure data and a block of strings. You never edit a DTB by hand: you edit the DTS and recompile, exactly as you edit C and rebuild rather than patching the executable.
Inside a kernel build you do not call dtc per file. The target make dtbs compiles every device tree source for the configured architecture; the sources live under arch/arm/boot/dts and arch/arm64/boot/dts, grouped by vendor, and the blobs appear beside them. With a cross build you pass ARCH= and CROSS_COMPILE= as in the cross-compilation lesson. One detail differs from your manual dtc run: kernel sources use #include and macros from include/dt-bindings/ headers, so the kernel build runs the C preprocessor over the source before dtc sees it.
At boot, the bootloader (U-Boot on the boards in this course) loads the DTB into RAM and passes its address to the kernel. The kernel parses the blob, builds an in-memory tree, and drivers consult it as they initialize. On a running board the live tree is visible under /proc/device-tree, which is a symlink to /sys/firmware/devicetree/base: one directory per node, one file per property. On your x86 WSL2 or VM that path does not exist, because the machine booted with ACPI, not a device tree.
dtc validates the syntax and structure of the tree, not whether the properties match what a driver expects. A misspelled property compiles cleanly and is silently ignored at boot. Checking sources against the documented bindings is a separate step (dtbs_check with the binding schemas), covered when you study bindings.
Includes, overlays and the base tree
3 min readA real SoC has hundreds of peripherals, and every board using that SoC inherits all of them. Duplicating that description in every board file would recreate the board-file problem in a new format. The solution is the .dtsi include: the SoC vendor writes one file describing everything on the chip, and each board's .dts includes it and adjusts only what differs. dtc supports its own /include/ "file.dtsi" directive, and the kernel build additionally allows C-style #include, which is what kernel sources use.
The typical layering for an STM32MP1 board looks like this: a common SoC .dtsi describes the blocks shared across the family, a variant .dtsi adds what is specific to one chip variant, and the board .dts includes them and describes only the board: which peripherals are actually used, which pins they are routed to, and what is attached externally. A common convention is that the SoC .dtsi marks peripherals status = "disabled"; and the board .dts switches on the ones it uses with status = "okay";. The compiler merges everything into a single flat tree; the DTB has no memory of which file a node came from.
Going deeperExplore the mechanism
An overlay solves a different problem: the base tree is fixed, but the hardware attached to it is not. A Raspberry Pi with a sensor HAT plugged in, or a carrier board with an optional display, needs to modify the tree without maintaining a full copy per combination.
An overlay is a small DTS marked with /plugin/;. Instead of describing a whole machine, it contains fragments that target a node in the base tree (by a reference called a phandle, or by path) and supply properties or child nodes to merge into it. To make references resolvable across separately compiled files, the base tree is compiled with dtc -@, which adds a __symbols__ node mapping labels to paths; the overlay is compiled the same way. Without -@, a label reference in an overlay cannot be resolved against the base blob: in a real run, fdtoverlay -i base.dtb -o merged.dtb overlay.dtbo with a base compiled without -@ stopped with "Failed to apply 'overlay.dtbo': FDT_ERR_NOTFOUND", and with -@ the merge worked and the node got status = "okay".
Overlays are applied by whoever owns the tree at that moment: U-Boot can merge them into the base DTB before booting (you will do this in the U-Boot session), the Raspberry Pi firmware applies overlays listed in config.txt, and a running kernel can apply them through its in-kernel overlay code (drivers/of/overlay.c); mainline 6.8 has no configfs or other user-space interface for it, which some vendor kernels add. The distinction to keep is: a .dtsi is merged at compile time and disappears into one blob; an overlay is compiled separately and merged later, against a tree that already exists. A full hands-on treatment of overlays comes later in this session.
You now have the complete picture: hardware data lives in DTS text, shared pieces live in DTSI includes, dtc compiles the merged result into a DTB, and the bootloader delivers that blob to the kernel. The next lesson, "Device tree nodes, phandles and driver binding", opens up the tree itself: how nodes are named and addressed, how phandles link one node to another, and how the compatible string you saw in the demo connects a node to the driver that claims it.
Key takeaways
- The device tree is a data description of non-discoverable hardware that the bootloader hands to the kernel at boot
- Board files forced a kernel rebuild per board; the device tree separates hardware data from driver code so one kernel image serves many boards
- dtc compiles .dts text (with .dtsi includes) into a binary .dtb blob; make dtbs does this inside the kernel build
- A DTB starts with the magic value 0xd00dfeed, and overlays compiled with dtc -@ modify a base tree instead of describing a whole board
Reflect
- Explain to a colleague, in two sentences: explain what the device tree describes and why it replaced per-board C files in the kernel
- Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
- What surprised you when you ran the commands yourself?
On a real board
Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.
References and further reading
- DocumentationLinux and the Devicetree: usage model
- DocumentationDevicetree Overlay Notes
- Kernel documentationWriting Devicetree Bindings in json-schema
Official documentation first. Links checked when the lesson was published.