Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

API to read the device tree from userspace

Is there an API to read the Open-Firmware device tree from userspace?

For example, reading /sys/firmware/fdt (flattened device tree)?

If not, is the file format published so a userspace application can read entries from the fdt?

like image 455
Stéphane Avatar asked May 18 '16 13:05

Stéphane


People also ask

Does Uboot use device tree?

A: U-boot allows the user to load a Device Tree Overlay and apply it on the base Device Tree Blob just before booting Linux, thus making it transparent for Linux (Linux will see just one Device Tree Blob like it expects).

How do I view a DTB file?

There are few tools: visualize FDT/DTB/DTBO -> https://github.com/dev-0x7C6/fdt-viewer. visualize DTS (dead) -> https://github.com/TheCodeArtist/dtv-demo. visualize DTS (my fork) -> https://github.com/bmx666/dtv-demo.

What is Phandle device tree?

3.3 Phandle More simply put, it is a property in one node that contains a pointer to another node. A phandle is created either by the device tree compiler or U-Boot for each label. In the following example, <&label> is converted to the phandle for the labeled node by the DTC. name@address {


1 Answers

This is easier than I first thought. On devices that support Open-Firmware, the linux kernel mounts it as a virtual filesystem at /proc/device-tree/.

In my case, on the systems I happened to be checking, this was a symbolic link to /sys/firmware/devicetree/base. But either way, walking through the files and directories in /proc/device-tree/ is relatively easy to do, regardless of the language.

like image 150
Stéphane Avatar answered Oct 22 '22 01:10

Stéphane