DTS structure and Compilation Method
I. Main Problems
1. Understand the relationship between DTSI and DTS
2. DTS Structure Model
3. How DTS is compiled and what file will be generated after compilation.
Ii. References
1. DTS (Device Tree source)
The. DTS file is a devicetree description in ASCII text format. Basically, in armlinux, A. DTS file corresponds to an arm machine, which is generally placed in the arch/ARM/boot/DTS/directory of the kernel. Because one SOC may correspond to multiple machines (one SOC can correspond to multiple products and boards), these. DTS files must contain many common parts. To simplify the Linux kernel, the common parts of SOC or the common parts of multiple machines are generally extracted as. DTSI, which is similar to the header file of C language. The. DTS corresponding to other machines will include this. DTSI.
2. DTS Structure Model
To understand the structure of devicetree, we first provide an example of devicetree:
/O device-tree
|-Name = "device-tree"
|-Model = "myboardname"
|-Compatible = "myboardfamilyname"
|-# Address-cells = <2>
|-# Size-cells = <2>
|-Linux, phandle = <0>
|
O CPUs
|-Name = "CPUs"
|-Linux, phandle = <1>
|-# Address-cells = <1>
|-# Size-cells = <0>
|
| O PowerPC, [email protected]
|-Name = "PowerPC, 970"
|-Device_type = "CPU"
|-Reg = <0>
|-Clock-frequency = <0x5f5e1000>
|-64-bit
|-Linux, phandle = <2>
|
O [email protected]
|-Name = "Memory"
|-Device_type = "Memory"
|-Reg = <0x00000000 0x00000000 0x00000000 0x20000000>
|-Linux, phandle = <3>
|
O Chosen
|-Name = "Chosen"
|-Bootargs = "root =/dev/sda2"
|-Linux, phandle = <4>
It can be seen that the basic unit of devicetree is node. These nodes are organized into a tree structure. Except for rootnode, each node has only one parent. One devicetree file can have only one rootnode. Each node contains several properties/values to describe some features of the node. Each node is identified by a node name (nodename). The node name format is [email protected]. If the node does not have the reg attribute (this property will be described later), the node name must not include @ and unit-address. The specific format of unit-address is related to the bus on which the device is mounted. For example, for the CPU, the unit-address is the address starting from 0, and then add one. The Unit-address of a specific device, such as an Ethernet controller, is the register address. The nodename of the rootnode is determined and must be "/".
3. How DTS is compiled and what file will be generated after compilation.
DTC (Device Tree compiler)
DTC is a tool that compiles. DTS into. dtb. The source code of DTC is located in the scripts/DTC directory of the kernel. When devicetree is enabled in the Linux kernel, the host tool DTC will be compiled during kernel compilation, corresponds to the hostprogs-Y: = DTC in scripts/DTC/makefile to compile the target.
In the ARCH/ARM/boot/DTS/makefile of the Linux kernel, describe which. dtb files will be compiled when a SoC is selected. Example:
For example, the. dtb corresponding to vexpress includes:
dtb-$(CONFIG_ARCH_VEXPRESS) += vexpress-v2p-ca5s.dtb vexpress-v2p-ca9.dtb vexpress-v2p-ca15-tc1.dtb vexpress-v2p-ca15_a7.dtb xenvm-4.2.dtb
In Linux, We can compile the devicetree file separately. When we run makedtbs in the Linux kernel, If we select arch_vexpress before, the above. dtb will be compiled by the corresponding. DTS. Because ARCH/ARM/makefile contains a dtbs compiled target project.
- Devicetree blob (. dtb)
. Dtb is the devicetree description in binary format after data transmission is compiled by DTC. It can be parsed by the Linux kernel. When we make NAND and SD boot images for the circuit board. the dtb file is stored in a small area, and then the bootloader will read this during the kernel boot process. dtb to memory.
- Source code embodiment
There are two ways to use DT. The first type can contain multiple dtb, which can be compiled into DT. IMG and put into boot. IMG. The second type only contains one dtb, which is directly appended to the end of the kernelimage and placed in Boot. IMG.
DTC is compiled and defined in kernel/androidkernel. mk. First define the "dts_names" variable. Each entry of the variable (as "dts_name" variable, the $ arch below) may have two parts: arch and Rev, and. the configuration in config is related. Use the following method to find out.
while (<>) {$$a = $$1 if /CONFIG_ARCH_((?:MSM|QSD|MPQ)[a-zA-Z0-9]+)=y/;$$r = $$1 if /CONFIG_MSM_SOC_REV_(?!NONE)(\w+)=y/;$$arch = $$arch.lc("$$a$$r ") if /CONFIG_ARCH_((?:MSM|QSD|MPQ)[a-zA-Z0-9]+)=y/} print $$arch;
Obtain the preceding "dts_names" variable and use "$ (dts_name) *. DTS" to match the variable under "kernel/ARCH/ARM/boot/DTS. See the following definition. The "cat" command generates a kernelimage with DT.
define append-dtbmkdir -p $(KERNEL_OUT)/arch/arm/boot;$(foreach DTS_NAME, $(DTS_NAMES), $(foreach d, $(DTS_FILES), $(DTC) -p 1024 -O dtb -o $(call DTB_FILE,$(d)) $(d); cat $(KERNEL_ZIMG) $(call DTB_FILE,$(d)) > $(call ZIMG_FILE,$(d));))endef
The second method does not show how to put boot. IMG in the future. For the first method, the following rule defined in "device/qcom/common/generate_extra_images.mk" is used to compile "DT. IMG ",
$(INSTALLED_DTIMAGE_TARGET): $(DTBTOOL) $(INSTALLED_KERNEL_TARGET) $(build-dtimage-target)
Use the following statement in "build/CORE/makefile" to compile it into boot. IMG.
ifeq ($(strip $(BOARD_KERNEL_SEPARATED_DT)),true) INTERNAL_BOOTIMAGE_ARGS += --dt $(INSTALLED_DTIMAGE_TARGET) BOOTIMAGE_EXTRA_DEPS s:= $(INSTALLED_DTIMAGE_TARGET)endif
(DT Series 1) DTS structure and Compilation Method