Day 4 — Device Tree & Overlay¶
Objective¶
Understand how Device Tree works in Embedded Linux and learn how to use a Device Tree Overlay to modify hardware configuration without rebuilding the kernel.
1. Device Tree Overview¶
In Embedded Linux, the Device Tree describes the hardware layout of the system.
Instead of hard-coding hardware information inside kernel drivers, Linux uses Device Tree to provide information such as:
- hardware address
- interrupt lines
- bus connections
- device compatibility
This allows the same kernel to support multiple boards.
Conceptually:
The driver reads the Device Tree and configures the hardware accordingly.
2. Raspberry Pi Device Tree Files¶
On Raspberry Pi OS, the Device Tree files are located in:
Example:
Output includes many .dtb files:
These .dtb files represent different Raspberry Pi boards.
For example:
| File | Board |
|---|---|
| bcm2712-rpi-5-b.dtb | Raspberry Pi 5 |
| bcm2711-rpi-4-b.dtb | Raspberry Pi 4 |
| bcm2710-rpi-3-b.dtb | Raspberry Pi 3 |
During boot, the firmware loads the appropriate Device Tree for the board.
3. Device Tree Overlay¶
A Device Tree Overlay modifies the base Device Tree without rebuilding the kernel.
Conceptually:
Overlays are commonly used to:
- enable hardware modules
- configure GPIO
- add I2C or SPI devices
- support HAT expansion boards
4. Overlay Storage Location¶
Raspberry Pi overlays are stored in:
List available overlays:
Each overlay is compiled as a .dtbo file.
5. Overlay Exercise — Create a Fake Device¶
To understand overlays, we created a test device node.
File:
Example:
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2712";
fragment@0 {
target-path = "/";
__overlay__ {
test_device: test-device {
compatible = "demo,test-device";
status = "okay";
};
};
};
};
6. Compile Device Tree Overlay¶
Compile using the Device Tree Compiler:
This generates:
7. Install the Overlay¶
Copy the overlay to the Raspberry Pi overlay directory:
8. Enable Overlay¶
Edit the boot configuration:
Add:
9. Reboot System¶
Overlay is applied during boot:
10. Verify the Device Tree¶
Linux exposes the runtime Device Tree in:
Check if the device exists:
Expected node:
Check properties:
11. Dump Runtime Device Tree¶
To view the complete Device Tree:
Search the test node:
Example result:
12. What We Learned¶
Device Tree allows Linux to separate hardware description from driver implementation.
Key ideas:
- hardware configuration is stored in the Device Tree
- overlays allow dynamic modification
- kernel reads Device Tree during boot
- drivers match using the
compatibleproperty
Matching flow:
13. Summary¶
Today we learned:
- what Device Tree is
- how Raspberry Pi uses
.dtbfiles - how Device Tree overlays work
- how to create and compile an overlay
- how to verify the runtime Device Tree
The overlay mechanism allows flexible hardware configuration without modifying the kernel.
Next step: