RK3399 Driver Development_ 04 - In the Android system, decompile the fdt file system to view the real and effective device tree configuration information in the device


foreword

Viewing the device tree in the root file system is a good way to debug. Because many times it will happen that you have modified the dts file and compiled a new dtb, but the previous dtb is still downloaded to the board, so it is very important to check the real and effective device tree configuration information in the board.


1. Where is the device tree saved in the file system?

a. /sys/firmware/fdt
进入/sys/firmware目录后便可看到二个文件,一个是devicetree文件夹,另一个是fdt(原始dtb文件,可以用hexdump -C fdt 将其打印出来查看就会发现里面的数据和dtb文件是一致的)。

b. /sys/firmware/devicetree
以目录结构呈现的dtb文件。 根节点对应base目录, 每一个节点对应一个目录, 每一个属性对应一个文件

c. /sys/devices/platform
系统中所有的platform_device, 有来自设备树的, 也有来有.c文件中注册的
对于来自设备树的platform_device,可以进入 /sys/devices/platform/<设备名>/of_node 查看它的设备树属性(例如进入/sys/devices/platform/led/后若发现该目录下有of_node节点,就表明该platform_device来自设备树)

d. /proc/device-tree
是链接文件, 指向 /sys/firmware/devicetree/base

2. File system device tree dts compilation and decompilation

2.1 Device tree original dtb format

After entering the /sys/firmware directory, you can see two files, one is the devicetree folder, and the other is fdt (the original dtb file, you can use hexdump -C fdt to print it out and check, and you will find that the data inside is consistent with the dtb file).

rk3399_xxx:/sys/firmware # ls
devicetree fdt

2.2 Obtain the target file fdt from the device

adb pull /sys/firmware/fdt
或者:
adb pull sys/firmware/devicetree/base/

2.3 Decompile fdt into dts in ubuntu system

2.3.1 Install the decompile dtc tool

在ubuntu 系统中安装反编译dtc工具:
apt install device-tree-compiler

2.3.2 Use the dtc tool that comes with the Android system

1. 在Android 源码中查找二进制工具dtc :
$  find ./ -name "*dtc*"
./out/soong/.glob/external/dtc
./prebuilts/misc/linux-x86/dtc
./prebuilts/misc/linux-x86/dtc/dtc

2.3.3 Decompile fdt into dts

dtc -I dtb -O dts fdt -o fdt.dts
-I 输入格式 dtb
-O 输出格式 dts
-o 输出文件名 fdt.dtsi

2.3.4 Decompile the device tree dts from the file system

fdtdump devicetree.dtb > devicetree.dts

2.4. Compile dtb into dts in ubuntu system

dtc -I dtb -O dts *.dtb > my.dts

3. Important Supplements

Linux 常用的文件系统有三个:procfs、sysfs、debugfs

procfs:该文件系统主要用来反馈内核的信息,包括系统中所有的中断、进程信息都可以在这里查看。挂载在 /proc/...

sysfs:该文件系统主要是和驱动强相关,会反馈所有的驱动信息,以目录形式显示。挂载在 /sys/...

debugfs:该文件系统挂载在 /sys/kernel/debug/...  ,主要用来 debug。

Guess you like

Origin blog.csdn.net/chenkanuo/article/details/130892911