Device Tree Fundamentals: Concepts, Overlay Mechanism, and Debugging
The article explains Device Tree fundamentals—defining DTS, DTSI, DTB and DTBO formats, their origin as a cleaner alternative to kernel‑embedded platform code, how overlays decouple vendor changes via matching project and PCB IDs, the rules for modifying nodes, and debugging techniques using dtc and mkdtimgdump tools.
The document defines key Device Tree terminology: DTS (Device Tree Source) is a text file describing fixed hardware information; DTSI is a reusable include file; DTB is the compiled binary; DTBO is the overlay compiled binary; dtbo-base specifies the base DTB for overlay; Node and Property are tree nodes and their attributes.
It explains the origin of Device Tree: Linux kernel previously contained extensive platform‑specific configuration that was messy and repetitive, prompting ARM maintainers to seek a cleaner solution; the Device Tree concept, borrowed from Open Firmware, was adopted to pass hardware data to the OS without hard‑coding.
The purpose of Device Tree is to provide a data structure describing hardware, acting like a large struct where the struct is the platform and members are devices. It does not solve all hardware configuration problems but offers a language to extract hardware configuration from kernel source. Main motivations are platform identification, runtime configuration, and device instantiation.
Decoupling objectives: vendor‑specific changes must be isolated, prohibited from modifying soc‑native DTSI files and allowed only as DTBO overlays; additionally, DTBOs for the same baseline project should share a single binary.
The decoupling framework matches the project number (Project No) and PCB ID with the dtbo attributes dtsi_No and pcb_No ; when both match, the corresponding DTBO is selected and can be packed into dtbo.img via Makefile, achieving shared binary.
Device Tree code architecture organizes DTSI includes, node definitions, and properties to enable modular hardware description.
Overlay rules: (1) For the same node, DTS settings override DTSI; (2) To modify a node, first reference it then apply changes—for example, to alter the reserved‑memory node one must reference it before adding or removing properties or child nodes; (3) Only nodes that are declared with a reference (“&node”) in DTSI are effective; otherwise the reference has no effect.
Debugging involves verifying that changes are compiled into dtbo.img; decompilation tools are built in: initialize environment, then use dtc -I dtb -O dts dtb.img -o dtsi.txt to decompile a DTB, and for DTBO use mkdtimgdump dtbo.img -b dtbo followed by dtc -I dtb -O dts dtbo.00 -o dtsi.txt .
The document concludes with a reference to “设备树简介” by 猫的大兔子 and a promotional note for the “内核工匠微信” public account.
OPPO Kernel Craftsman
Sharing Linux kernel-related cutting-edge technology, technical articles, technical news, and curated tutorials
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.