Skip to content

Device Tree

Device Tree is a data structure used by the Linux kernel to describe the hardware of a system.

Instead of hardcoding hardware details in kernel drivers, the system provides hardware information through a Device Tree Blob (DTB) that is loaded during boot.

This mechanism allows the same kernel to support multiple hardware platforms.


1. Why Device Tree Exists

Embedded systems often have many different hardware configurations.

Examples:

  • different CPUs
  • different GPIO layouts
  • different sensors
  • different memory maps

Without Device Tree, drivers would need board-specific code.

Device Tree separates:

Hardware description
Driver implementation

2. Device Tree Files

Device Tree is written in Device Tree Source (DTS) format.

Example:

example.dts

It is compiled into a binary format:

example.dtb

Compilation tool:

dtc (Device Tree Compiler)

Example command:

dtc -I dts -O dtb -o example.dtb example.dts

3. Boot Process and Device Tree

During system boot:

Boot ROM
Bootloader / Firmware
Load Kernel
Load Device Tree Blob (DTB)
Kernel parses Device Tree
Kernel creates devices

The Device Tree tells the kernel:

  • what hardware exists
  • how devices are connected
  • what drivers should handle them

4. Device Tree Structure

Device Tree is organized as a hierarchical tree.

Example:

/ {
    cpus {
        cpu@0 {
            compatible = "arm,cortex-a76";
        };
    };

    memory@0 {
        device_type = "memory";
    };

    soc {
        i2c@7e804000 {
            compatible = "brcm,bcm2835-i2c";
        };
    };
};

Key characteristics:

  • hierarchical nodes
  • properties inside nodes
  • hardware address in node names

5. Nodes

A node represents a hardware component.

Example:

i2c@7e804000 {
};

Node name format:

device-name@address

Example:

uart@7e201000
spi@7e204000
i2c@7e804000

6. Properties

Nodes contain properties.

Example:

compatible = "brcm,bcm2835-i2c";
reg = <0x7e804000 0x1000>;
status = "okay";

Common properties:

Property Purpose
compatible driver matching
reg register address
interrupts interrupt lines
status enable/disable device

7. The "compatible" Property

The compatible string connects Device Tree nodes to kernel drivers.

Example:

compatible = "brcm,bcm2835-i2c";

Kernel driver defines a matching table:

static const struct of_device_id match_table[] = {
    { .compatible = "brcm,bcm2835-i2c" },
};

Matching flow:

Device Tree node
compatible string
driver match
probe()

8. Device Tree in Linux Runtime

Linux exposes the runtime Device Tree through:

/proc/device-tree

Example:

ls /proc/device-tree

To dump the full tree:

dtc -I fs -O dts /proc/device-tree

This shows the final Device Tree after overlays are applied.


9. Device Tree in Raspberry Pi

On Raspberry Pi systems:

Device Tree files are located in:

/boot/firmware

Example files:

bcm2712-rpi-5-b.dtb
bcm2711-rpi-4-b.dtb

Overlays are located in:

/boot/firmware/overlays

Enabled in:

/boot/firmware/config.txt

Example:

dtoverlay=i2c1
dtoverlay=spi0

10. Summary

Device Tree provides a standardized way to describe hardware to the Linux kernel.

Key ideas:

  • hardware description separate from drivers
  • hierarchical tree structure
  • nodes represent hardware devices
  • properties describe configuration
  • drivers match using the compatible property

Device Tree is essential for Embedded Linux systems.


11. From Device Tree to Platform Device

In embedded Linux, many devices are not dynamically discovered.

Instead, they are defined in Device Tree and converted into platform devices by the kernel.

Flow:

@@@ Device Tree node ↓ Kernel parses DT ↓ platform_device created ↓ Matched with platform_driver ↓ probe() is called @@@


Example Observation

In the system:

@@@ /proc/device-tree/test-device@0 /sys/bus/platform/devices/test-device@0 @@@

This shows:

  • Device Tree node exists
  • Kernel created a platform device
  • Device is visible in sysfs

Important Insight

Even without a driver:

@@@ Device exists (platform device) Driver may NOT exist yet @@@

This separation is fundamental in Linux.


12. /dev vs /sys vs Device Tree

Linux uses different layers to represent devices.


/dev

User-space interface

Examples:

@@@ /dev/ttyAMA0 /dev/i2c-1 /dev/spidev0.0 @@@

Used by applications.


/sys

Kernel device model representation

Examples:

@@@ /sys/bus/ /sys/devices/ /sys/class/ @@@

Shows:

  • device hierarchy
  • driver binding
  • bus structure

/proc/device-tree

Hardware description

@@@ /proc/device-tree @@@

Represents:

  • hardware layout
  • DT nodes
  • compatible strings

Key Relationship

@@@ Device Tree → creates device /sys → shows device model /dev → user access interface @@@


Example

@@@ /dev/ttyAMA10 → /sys/class/tty/ttyAMA10 → /sys/devices/platform/.../ttyAMA10 @@@

This shows how layers are connected.


13. Notes on Device Tree Warnings

When dumping Device Tree using:

@@@ dtc -I fs -O dts /proc/device-tree @@@

You may see many warnings.


Common Reasons

  • Live device tree is not identical to original DTS
  • Missing metadata (phandle, reg format)
  • Flattened structure after boot

Example Warning

@@@ Warning (unit_address_vs_reg): node has a unit name, but no reg property @@@

Cause:

@@@ test-device@0 // has @0 but no reg property @@@


If no register mapping exists:

@@@ test-device { compatible = "my,test-device"; }; @@@


Key Takeaway

  • Many dtc warnings are normal
  • Focus on real hardware definition issues
  • Naming conventions still matter