Linux device tree manually decompile dtb to generate source file dts

verification platform

  • win10 64 bit

  • VMware Workstation Pro 16

  • ubuntu 20.04

  • dtc tool: from linux-6.3.5inscripts/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

insert image description here

insert image description here

  • 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 separatelymake 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:

  • ./dtcIndicates the execution path of dtc, which can be specified according to the actual situation, ./dtcindicating that the dtc tool is under the current path

  • -I dtb -O dtsNote that here Iis Inputthe abbreviation of , that is, the input format: dtb, Oindicating Outputthe 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 -oin lowercase output, 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.

insert image description here

insert image description here

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

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

Guess you like

Origin blog.csdn.net/tcjy1000/article/details/131017104