Device tree (device tree) study notes

1. Decompile the device tree

When learning the device tree, if you can see the content of the finally generated device tree, it is very helpful for us to learn the device tree and analyze the problem. Here we need to use the decompilation function of the device tree generation tool dtc

root@pengdl-VirtualBox:~/tq2440/Linux/linux-4.0.1# ./scripts/dtc/dtc -h
Usage: dtc [options] <input file>

Options: -[qI:O:o:V:d:R:S:p:fb:i:H:sW:E:hv]
  -q, --quiet                
    Quiet: -q suppress warnings, -qq errors, -qqq all
  -I, --in-format <arg>      
    Input formats are:
        dts - device tree source text
        dtb - device tree blob
        fs  - /proc/device-tree style directory
-o, --out <arg>            
    Output file
  -O, --out-format <arg>     
    Output formats are:
        dts - device tree source text
        dtb - device tree blob
        asm - assembler source
  -V, --out-version <arg>    
    Blob version to produce, defaults to %d (for dtb and asm output)
  -d, --out-dependency <arg> 
    Output dependency file
  -R, --reserve <arg>        
    tMake space for <number> reserve map entries (for dtb and asm output)
  -S, --space <arg>          
    Make the blob at least <bytes> long (extra space)
  -p, --pad <arg>            
    Add padding to the blob of <bytes> long (extra space)
  -b, --boot-cpu <arg>       
    Set the physical boot cpu
  -f, --force                
    Try to produce output even if the input tree has errors
  -i, --include <arg>        
    Add a path to search for include files
  -s, --sort                 
    Sort nodes and properties before outputting (useful for comparing trees)
  -H, --phandle <arg>        
    Valid phandle formats are:
        legacy - "linux,phandle" properties only
        epapr  - "phandle" properties only
        both   - Both "linux,phandle" and "phandle" properties
  -W, --warning <arg>        
    Enable/disable warnings (prefix with "no-")
  -E, --error <arg>          
    Enable/disable errors (prefix with "no-")
  -h, --help                 
    Print this help and exit
  -v, --version              
    Print version and exit

Suppose our final device tree file is: arch/arm/boot/dts/s3c2416-smdk2416.dtb

./scripts/dtc/dtc -I dtb -O dts -o output.dts arch / arm / boot / dts / s3c2416-smdk2416.dtb

The output file output.dts is the result of disassembly. It is the actual device tree generated. Of course, the generated dts file can also be recompiled into a dtb file:

./scripts/dtc/dtc -I dts -O dtb -o s3c2416-smdk2416.dtb output.dts

2. Analysis tool fdtdump

In addition to the dtc tool provided in the scripts/dtc directory of Linux, a tool called fdtdump is also provided, which is also very helpful for analyzing the device tree.

usage:

fdtdump -h
Usage: fdtdump [options] <file>

Options: -[dshV]
  -d, --debug   Dump debug information while decoding the file
  -s, --scan    Scan for an embedded fdt in file
  -h, --help    Print this help and exit
  -V, --version Print version and exit

Usage example:

fdtdump -sd vexpress-v2p-ca9.dtb | tee vexpress.dts.debug

Look at the output file:

vexpress-v2p-ca9.dtb: found fdt at offset 0
/dts-v1/;
// magic:        0xd00dfeed
// totalsize:        0x2e9c (11932)
// off_dt_struct:    0x38
// off_dt_strings:    0x2bb8
// off_mem_rsvmap:    0x28
// version:        17
// last_comp_version:    16
// boot_cpuid_phys:    0x0
// size_dt_strings:    0x2e4
// size_dt_struct:    0x2b80

// 0038: tag: 0x00000001 (FDT_BEGIN_NODE)
/ {
// 0040: tag: 0x00000003 (FDT_PROP)
// 2bb8: string: model
// 004c: value
    model = "V2P-CA9";

As you can see, this tool will print out the analysis sentence and the original file at the same time. The output after // is the analysis sentence, and the others are the original sentence. It is very helpful to traverse and expand the device tree mirroring when the Linux kernel is started.

3. Linux configuration, support device tree

make menuconfig ---> Boot options ---> Flattened Device Tree support

4. Linux compile device tree

You can check whether the dtb file of the device tree you want in arch/arm/boot/dts/Makefile is configured.

make dtbs

5. Tool dtc to compile device tree from Linux kernel code

The source code implementation of the dtc tool is provided in the kernel source directory. The following is the command to generate this tool:

make scripts

6. How to delete device tree attributes

Sometimes we have such a need to delete certain properties of the device tree, but we don't want to modify the source file of the device tree, so we can use the delete-property method.

 1 / {
 2     ... ...
 3     demo1: demo1 {
 4         compatible = "demo1";
 5         property1 = <1>;
 6         property2;
 7         property3 = <2>;
 8         property4;
 9     };
10 };
11 
12 &demo1 {
13     /delete-property/property2;
14     /delete-property/property3;
15 };

After the compilation is complete, execute decompilation and you can see that property2 and property3 have disappeared:

1     demo1 {
2         compatible = "demo1";
3         property1 = <0x1>;
4         property4;
5     };

7. Two new device tree debugging tools for the kernel

  • ./scripts/dtc/dt_to_config

According to the incoming device tree, you can parse out which drivers each node corresponds to and whether the kernel has been configured. You can even directly modify the .config file by passing --config-format. If the path of the node is too long, you can pass parameters - short-name, usage example:

# Here --include-suspec is used to parse the include field in the device tree 
$./scripts/dtc/dt_to_config arch/arm/boot/dts/s3c2440-tq2440-dt.dts --include-suspect --config ./ .config 
-dDc-E-Hx----: /i2c-gpio-1: i2c-gpio: arch/arm/mach-ep93xx/core.c: obj-y: x 
-dDc-EHn--F: / i2c-gpio-1: i2c-gpio: arch/arm/mach-ixp4xx/avila-setup.c: CONFIG_MACH_AVILA: n 
-dDc-EHn--F: /i2c-gpio-1: i2c-gpio: arch/arm/ mach-ixp4xx/dsmg600-setup.c: CONFIG_MACH_DSMG600: n 
...

Of course, you can also follow the dtb file directly:

$./scripts/dtc/dt_to_config arch/arm/boot/dts/s3c2440-tq2440-dt.dtb --include-suspect --config ./.config
-dDc-E-Hx---- : /i2c-gpio-1 : i2c-gpio : arch/arm/mach-ep93xx/core.c : obj-y : x
-dDc-E-H-n--F : /i2c-gpio-1 : i2c-gpio : arch/arm/mach-ixp4xx/avila-setup.c : CONFIG_MACH_AVILA : n
-dDc-E-H-n--F : /i2c-gpio-1 : i2c-gpio : arch/arm/mach-ixp4xx/dsmg600-setup.c : CONFIG_MACH_DSMG600 : n
-dDc-E-H-n--F : /i2c-gpio-1 : i2c-gpio : arch/arm/mach-ixp4xx/fsg-setup.c : CONFIG_MACH_FSG : n
...
  • ./scripts/dtc/dtx_diff

This tool is used to compare two device trees and can also decompile the device trees. Example:

# Pass a device tree represents decompile 
./scripts/dtc/dtx_diff Arch / ARM / the Boot / dts / S3C2440-tq2440-dt.dtb 

# also pass a dts files directly, this tool will expand the dts file 
./ scripts/dtc/dtx_diff arch/arm/boot/dts/s3c2440-tq2440-dt.dts #Transfer 

two device trees for comparison. /scripts/dtc/dtx_diff arch/arm 
/boot/dts/s3c2440-tq2440-dt.dtb /tftpboot/dtb 
--- /dev/fd/63 2017-09-23 22:01:48.407691984 +0800 
+++ /dev/fd/62 2017-09-23 22:01:48.407691984 +0800 
@@ -125 ,7 +125,7 @@ 
         pinctrl-names = "default"; 
         reg = <0x54000000 0x100>; 
         samsung,i2c-max-bus-freq = <0x30d40>; 
-status = "disabled"; 
+ status = "okay" ; 
 
         demo0@51 { 
             compatible = "demo0";

It can also be all dts files, or one dts one dtb file.

8. How to control the number of bytes occupied by attribute values ​​in the device tree?

http://www.cnblogs.com/pengdonglin137/p/6044418.html

9. Analysis of the ranges attribute in the device tree

http://www.cnblogs.com/pengdonglin137/p/7401049.html

10. The difference between memreserve and reserved-memory in dts

https://www.cnblogs.com/pengdonglin137/articles/10483018.html

11、devicetree-specification

https://files.cnblogs.com/files/pengdonglin137/devicetree-specification.pdf

Other debugging documents about the device tree

1、Solving Device Tree Issues

2、Youtube:Solving Devicetree Issues, part 3.0

3. There are many good patches in the devicetree-compiler mailing list of Linux kernel, you can choose the ones you want, such as the following:

  [RFC PATCH 0/3] dtc: dts source location annotation This series of patches adds an annotate configuration to dtc, so that when the device tree is compiled, a hidden file with the suffix of annotate.dts.tmp will be generated, and you can view the final result of each attribute Set by the device tree file

[RFC PATCH 1/3] dtc: dts source location annotation

[RFC PATCH 2/3] dtc: make check test for dtc --annotate

[RFC PATCH 3/3] dtc: linux kernel build process to create annotated .dts

  effect:

sdhci@f9824900 { /* arch/arm/boot/dts/qcom-apq8074-dragonboard.dts:14 */ compatible = "qcom,sdhci-msm-v4"; /* arch/arm/boot/dts/qcom-msm8974.dtsi:240 */ reg = <0xf9824900 0x11c 0xf9824000 0x800>; /* arch/arm/boot/dts/qcom-msm8974.dtsi:241 */ reg-names = "hc_mem", "core_mem"; /* arch/arm/boot/dts/qcom-msm8974.dtsi:242 */ interrupts = <0x0 0x7b 0x0 0x0 0x8a 0x0>; /* arch/arm/boot/dts/qcom-msm8974.dtsi:243 */ interrupt-names = "hc_irq", "pwr_irq"; /* arch/arm/boot/dts/qcom-msm8974.dtsi:244 */ clocks = <0xd 0xd8 0xd 0xd7>; /* arch/arm/boot/dts/qcom-msm8974.dtsi:245 */ clock-names = "core", "iface"; /* arch/arm/boot/dts/qcom-msm8974.dtsi:246 */ status = "ok"; /* arch/arm/boot/dts/qcom-apq8074-dragonboard.dts:17 */ bus-width = <0x8>; /* arch/arm/boot/dts/qcom-apq8074-dragonboard.dts:15 */ non-removable; /* arch/arm/boot/dts/qcom-apq8074-dragonboard.dts:16 */ }; /* arch/arm/boot/dts/qcom-apq8074-dragonboard.dts:18 */

==

This article participates in Tencent Cloud's self-media sharing plan . You are welcome to join and share with you who are reading.

Guess you like

Origin blog.csdn.net/a8039974/article/details/107726455