Skip to content

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:

Driver (kernel)
Device Tree (hardware description)

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:

/boot/firmware

Example:

ls /boot/firmware

Output includes many .dtb files:

bcm2712-rpi-5-b.dtb
bcm2712-rpi-500.dtb
bcm2712-rpi-cm5-cm5io.dtb
...

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:

Base Device Tree
      +
Device Tree Overlay
      =
Runtime Device Tree

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:

/boot/firmware/overlays

List available overlays:

ls /boot/firmware/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:

test-device-overlay.dts

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:

dtc -@ -I dts -O dtb -o test-device.dtbo test-device-overlay.dts

This generates:

test-device.dtbo

7. Install the Overlay

Copy the overlay to the Raspberry Pi overlay directory:

sudo cp test-device.dtbo /boot/firmware/overlays/

8. Enable Overlay

Edit the boot configuration:

sudo nano /boot/firmware/config.txt

Add:

dtoverlay=test-device

9. Reboot System

Overlay is applied during boot:

sudo reboot

10. Verify the Device Tree

Linux exposes the runtime Device Tree in:

/proc/device-tree

Check if the device exists:

ls /proc/device-tree

Expected node:

test-device

Check properties:

cat /proc/device-tree/test-device/compatible

11. Dump Runtime Device Tree

To view the complete Device Tree:

dtc -I fs -O dts /proc/device-tree > running.dts

Search the test node:

grep test-device running.dts

Example result:

test-device {
    compatible = "demo,test-device";
    status = "okay";
};

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 compatible property

Matching flow:

Device Tree node
compatible string
kernel driver match
probe()

13. Summary

Today we learned:

  • what Device Tree is
  • how Raspberry Pi uses .dtb files
  • 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:

Linux Driver Model