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:
2. Device Tree Files¶
Device Tree is written in Device Tree Source (DTS) format.
Example:
It is compiled into a binary format:
Compilation tool:
Example command:
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:
Node name format:
Example:
6. Properties¶
Nodes contain properties.
Example:
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:
Kernel driver defines a matching table:
Matching flow:
8. Device Tree in Linux Runtime¶
Linux exposes the runtime Device Tree through:
Example:
To dump the full 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:
Example files:
Overlays are located in:
Enabled in:
Example:
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
compatibleproperty
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 @@@
Recommended Fix¶
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