verification platform
-
win10 64 bit
-
VMware Workstation Pro 16
-
ubuntu 20.04
-
dtc tool: from
linux-6.3.5
inscripts/dtc/
Install the dtc tool
-
In fact, you can install the dtc software package, but it is not recommended to do so. It is best to obtain this dtc tool by compiling the latest Linux kernel
-
The method of compiling the Linux kernel to generate the dtc tool
-
Download the latest Linux kernel, unzip it into ubuntu 20.04, and find a board defconfig, such as qemu
arch/arm/configs/vexpress_defconfig
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- vexpress_defconfig
$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- dtbs
-
Using the dtc tool compiled by the latest Linux kernel, it will be more reliable to compile or decompile the device tree file in this way. Of course, to study the Linux device tree, it is best to prepare the Linux compilation environment in advance
-
There is no need to recompile the Linux kernel here, just compile the device tree separately
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- dtbs
decompile dtb
-
That is to decompile the dtb device tree binary file into a dts device tree source file, here use the dtc tool
-
The command to decompile is as follows:
./dtc -I dtb -O dts vexpress-v2p-ca9.dtb -o vexpress-v2p-ca9_0603.dts
-
Just pay attention to the parameters:
-
./dtc
Indicates the execution path of dtc, which can be specified according to the actual situation,./dtc
indicating that the dtc tool is under the current path -
-I dtb -O dts
Note that hereI
isInput
the abbreviation of , that is, the input format:dtb
,O
indicatingOutput
the output format:dts
-
vexpress-v2p-ca9.dtb
: The binary dtb file of the device tree, that is, the decompiled dtb file -
-o vexpress-v2p-ca9_0603.dts
, here-o
in lowercaseoutput
, the output file, the following name can be defined by yourself, such asxxx.dts
-
The above operations can decompile a dtb file into a device tree source file dts
The generated dts is compared with the original dts
-
The Linux device tree file may be composed of a dts source file, multiple dtsi and .h header files, so only one original dts file is generated after decompilation. Compared with the content, it may be necessary to combine multiple dtsi files for viewing
-
As follows, I use the existing dts of Linux to generate dtb, and then decompile dtb into dts, and compare the contents of the files, and find some differences
-
After all, the generated dts is a combination of multiple files, but the content is basically the same. For example, you can compile the decompiled dts into dtb, and then verify whether the function is normal.
dts compiled to dtb
- As above, if there is only one dts file, the way to compile it into dtb is very simple, that is to use the dtc tool, the command is as follows:
$ ./dtc -I dts -O dtb vexpress-v2p-ca9_0603.dts -o vexpress-v2p-ca9_0603.dtb
-
If it is a complete device tree, including one dts, multiple dtsi and .h files, you need to use gcc preprocessing and then use dtc to compile it into dtb. Here you can use shell script or Makefile to achieve it. Related articles:
-
Shell script for manual compilation of Linux device tree files
summary
-
This article pays attention to how to decompile the device tree file dtb generated by Linux into a device tree source file dts file
-
Pay attention to the method of obtaining the device tree compilation tool dtc, it is best to obtain it through the latest Linux kernel compilation