Sometimes working on an embedded system could happen to interface with a device tree.
Open Firmware Device Tree, or simply Device Tree (DT) consists of a structured
language, that describes how the hardware is interfaced with other ICs and which are its specs.
For example, it informs how big is the flash memory or how it’s connected to
the system on a chip (SoC) and ecc. Nowadays DT is a powerful tool widely used in different environments.
A basic definition of Terms
- DTB: device tree blob. A compact binary representation of the device tree.
- DTC: device tree compiler. An open-source tool used to build DTB files from DTS files.
- DTS: device tree syntax. A textual representation of a device or board.
Once Linux starts and it has built with open firmware (OF) support enabled, you can explore the path /proc/device-tree
that is used to export in user-space the device tree information.
A list of helpful tricks:
- Export device-tree from the running system and get DTS source file
In this way, you get an overview of the system that you’re inspecting.- Login into the target system and check if
/proc/device-tree
exists, if not, means that the target system has no Open Firmware support. - Be sure that your host has dtc tool installed, if not, fix the dependence using your package manager.
- Open a new terminal and enter:
$ scp -r root@IP_ADDR:/proc/device-tree ./target-dt
- Rebuild the dts source file starting from exported info:
$ dtc -I fs -O dts target-dt/ -o target.dts
- Login into the target system and check if
- Decompile device-tree blob file and get the DTS source file:
dtc -I dtb -O dts -o devicetree.dts devicetree.dtb
- On this https://github.com/mykhani/device-tree-guide repository, there is a user guide that shows how the DTS be used to describe the subsystem of a device