转自:https://www.cnblogs.com/pengdonglin137/p/4495056.html

作者信息

作者:彭东林

邮箱:pengdonglin137@163.com

1、反编译设备树

在设备树学习的时候,如果可以看到最终生成的设备树的内容,对于我们学习设备树以及分析问题有很大帮助。这里我们需要使用设备树生成工具dtc的反编译功能

  1. root@pengdl-VirtualBox:~/tq2440/Linux/linux-4.0.1# ./scripts/dtc/dtc -h
  2. Usage: dtc [options] <input file>
  3.  
  4. Options: -[qI:O:o:V:d:R:S:p:fb:i:H:sW:E:hv]
  5. -q, --quiet
  6. Quiet: -q suppress warnings, -qq errors, -qqq all
  7. -I, --in-format <arg>
  8. Input formats are:
  9. dts - device tree source text
  10. dtb - device tree blob
  11. fs - /proc/device-tree style directory
  12. -o, --out <arg>
  13. Output file
  14. -O, --out-format <arg>
  15. Output formats are:
  16. dts - device tree source text
  17. dtb - device tree blob
  18. asm - assembler source
  19. -V, --out-version <arg>
  20. Blob version to produce, defaults to %d (for dtb and asm output)
  21. -d, --out-dependency <arg>
  22. Output dependency file
  23. -R, --reserve <arg>
  24. tMake space for <number> reserve map entries (for dtb and asm output)
  25. -S, --space <arg>
  26. Make the blob at least <bytes> long (extra space)
  27. -p, --pad <arg>
  28. Add padding to the blob of <bytes> long (extra space)
  29. -b, --boot-cpu <arg>
  30. Set the physical boot cpu
  31. -f, --force
  32. Try to produce output even if the input tree has errors
  33. -i, --include <arg>
  34. Add a path to search for include files
  35. -s, --sort
  36. Sort nodes and properties before outputting (useful for comparing trees)
  37. -H, --phandle <arg>
  38. Valid phandle formats are:
  39. legacy - "linux,phandle" properties only
  40. epapr - "phandle" properties only
  41. both - Both "linux,phandle" and "phandle" properties
  42. -W, --warning <arg>
  43. Enable/disable warnings (prefix with "no-")
  44. -E, --error <arg>
  45. Enable/disable errors (prefix with "no-")
  46. -h, --help
  47. Print this help and exit
  48. -v, --version
  49. Print version and exit

假设我们最终的设备树文件是:arch/arm/boot/dts/s3c2416-smdk2416.dtb

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

输出文件output.dts就是反汇编的结果,他就是实际生成的设备树,当然也可以重新将生成的dts文件在编译成dtb文件:

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

2、分析工具fdtdump

在Linux的scripts/dtc目录下除了提供dtc工具外,还提供了一个叫做fdtdump的工具,对于分析设备树也非常有帮助。

用法:

  1. fdtdump -h
  2. Usage: fdtdump [options] <file>
  3.  
  4. Options: -[dshV]
  5. -d, --debug Dump debug information while decoding the file
  6. -s, --scan Scan for an embedded fdt in file
  7. -h, --help Print this help and exit
  8. -V, --version Print version and exit

使用范例:

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

看看输出的文件:

  1. vexpress-v2p-ca9.dtb: found fdt at offset 0
  2. /dts-v1/;
  3. // magic: 0xd00dfeed
  4. // totalsize: 0x2e9c (11932)
  5. // off_dt_struct: 0x38
  6. // off_dt_strings: 0x2bb8
  7. // off_mem_rsvmap: 0x28
  8. // version: 17
  9. // last_comp_version: 16
  10. // boot_cpuid_phys: 0x0
  11. // size_dt_strings: 0x2e4
  12. // size_dt_struct: 0x2b80
  13.  
  14. // 0038: tag: 0x00000001 (FDT_BEGIN_NODE)
  15. / {
  16. // 0040: tag: 0x00000003 (FDT_PROP)
  17. // 2bb8: string: model
  18. // 004c: value
  19. model = "V2P-CA9";

可以看到,其中这个工具会同时把分析语句和原始文件打印出来,其中 // 后输出的是分析语句,其他的是原始语句。对分析Linux内核启动时遍历展开设备树镜像很有帮助。

3、Linux配置,支持设备树

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

4、Linux 编译设备树

可以看看arch/arm/boot/dts/Makefile中你要的那个设备树的dtb文件是否配置上了。

  1. make dtbs

5、从Linux内核代码中编译设备树的工具dtc

在内核源码目录下提供了dtc工具的源码实现, 下面是生成这个工具的命令:

  1. make scripts

6、删除设备树属性的方法

有时我们有这样的需求,需要删除设备树的某些属性, 但是我们又不想修改设备树源文件,那么可以利用delete-property方法。

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

编译完成后,执行反编译可以看到property2和property3已经消失了:

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

7、两个内核新增的设备树调试工具

  • ./scripts/dtc/dt_to_config

可以根据传入的设备树解析出每个节点对应那些驱动以及内核是否已经配置,甚至可以通过传递--config-format来直接修改.config文件,如果嫌节点的路径过长,可以传递参数--short-name,用法示例:

  1. # 这里的--include-suspec用于解析设备树中的include字段
  2. $./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-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
  3. ...

当然后面也可以直接跟dtb文件:

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

这个工具用于比较两个设备树,也可以对设备树反编译。示例:

  1. #传递一个设备树,表示反编译
  2. ./scripts/dtc/dtx_diff arch/arm/boot/dts/s3c2440-tq2440-dt.dtb
  3.  
  4. #也可以直接传递一个dts文件,这个工具会将该dts文件展开
    ./scripts/dtc/dtx_diff arch/arm/boot/dts/s3c2440-tq2440-dt.dts
  5.  
  6. #传递两个设备树表示比较
  7. ./scripts/dtc/dtx_diff arch/arm/boot/dts/s3c2440-tq2440-dt.dtb /tftpboot/dtb
  8. --- /dev/fd/63 2017-09-23 22:01:48.407691984 +0800
  9. +++ /dev/fd/62 2017-09-23 22:01:48.407691984 +0800
  10. @@ -125,7 +125,7 @@
  11. pinctrl-names = "default";
  12. reg = <0x54000000 0x100>;
  13. samsung,i2c-max-bus-freq = <0x30d40>;
  14. - status = "disabled";
  15. + status = "okay";
  16.  
  17. demo0@51 {
  18. compatible = "demo0";

也可以都是dts文件,或者一个dts一个dtb文件。

8、如何在设备树里控制属性值占用的字节数?

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

9、设备树中ranges属性分析

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

10、dts中memreserve和reserved-memory的区别

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

11、devicetree-specification

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

其他关于设备树的调试文档

1、Solving Device Tree Issues

2、Youtube:Solving Devicetree Issues, part 3.0

3、Linux kernel的devicetree-compiler邮件列表里有很多好的patch,可以挑选自己想要的, 比如下面几个:

  [RFC PATCH 0/3] dtc: dts source location annotation 这个系列的patch为dtc增加了一个annotate配置,这样在编译设备树时会生成annotate.dts.tmp后缀的隐藏文件,可以查看每个属性最终是被那个设备树文件设置的

    [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

  效果:

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 */

设备树(device tree)学习笔记【转】的更多相关文章

  1. 珂朵莉树(Chtholly Tree)学习笔记

    珂朵莉树(Chtholly Tree)学习笔记 珂朵莉树原理 其原理在于运用一颗树(set,treap,splay......)其中要求所有元素有序,并且支持基本的操作(删除,添加,查找......) ...

  2. 【转载】Linux设备树(Device Tree)机制

    转:Linux设备树(Device Tree)机制   目录 1. 设备树(Device Tree)基本概念及作用2. 设备树的组成和使用 2.1. DTS和DTSI 2.2. DTC 2.3. DT ...

  3. ARM Linux 3.x的设备树(Device Tree)

    1. ARM Device Tree起源 Linus Torvalds在2011年3月17日的ARM Linux邮件列表宣称“this whole ARM thing is a f*cking pai ...

  4. 转:Linux设备树(Device Tree)机制

    目录 1. 设备树(Device  Tree)基本概念及作用 2. 设备树的组成和使用 2.1. DTS和DTSI 2.2. DTC 2.3. DTB 2.4. Bootloader 3. 设备树中d ...

  5. dsu on tree学习笔记

    前言 一次模拟赛的\(T3\):传送门 只会\(O(n^2)\)的我就\(gg\)了,并且对于题解提供的\(\text{dsu on tree}\)的做法一脸懵逼. 看网上的其他大佬写的笔记,我自己画 ...

  6. Linux device tree 简要笔记

    第一.DTS简介     在嵌入式设备上,可能有不同的主板---它们之间差异表现在主板资源不尽相同,比如I2C.SPI.GPIO等接口定义有差别,或者是Timer不同,等等.于是这就产生了BSP的一个 ...

  7. 基于设备树的controller学习(2)

    作者 彭东林 pengdonglin137@163.com 平台 TQ2440 Linux-4.10.17 概述 上一篇大概介绍了一下demo-controller的结构,下面结合驱动分析.   正文 ...

  8. 基于设备树的controller学习(1)

    作者 彭东林pengdonglin137@163.com 平台 TQ2440Linux-4.10.17 概述 在设备树中我们经常见到诸如"#clock-cells"."# ...

  9. 矩阵树定理(Matrix Tree)学习笔记

    如果不谈证明,稍微有点线代基础的人都可以在两分钟内学完所有相关内容.. 行列式随便找本线代书看一下基本性质就好了. 学习资源: https://www.cnblogs.com/candy99/p/64 ...

  10. Link Cut Tree学习笔记

    从这里开始 动态树问题和Link Cut Tree 一些定义 access操作 换根操作 link和cut操作 时间复杂度证明 Link Cut Tree维护链上信息 Link Cut Tree维护子 ...

随机推荐

  1. python中基本数据类型以及运算符

    python中基本数据类型以及运算符的知识 一.与用户的交互以及python2与python的区别 1.1什么是与用户交互 用户交互就是人往计算机中input(输入数据),计算机print(输出结果) ...

  2. RPM命令总结

    RPM软件管理程序 rpm命令是RPM软件包的管理工具.rpm原本是Red Hat Linux发行版专门用来管理Linux各项套件的程序,由于它遵循GPL规则且功能强大方便,因而广受欢迎.逐渐受到其他 ...

  3. linux下编译时的默认库和头文件搜索路径

    链接库路径 默认的链接库路径,定义在搜索/etc/ld.so.conf下的一些路径,其包含了一些重要的系统位置:LIBRARY_PATH, 但如果定义了LD_LIBRARY_PATH, 动态库的搜索路 ...

  4. acwing 652. 切蛋糕

    题目地址 今天是小Z的生日,同学们为他带来了一块蛋糕. 这块蛋糕是一个长方体,被用不同色彩分成了N个相同的小块,每小块都有对应的幸运值. 小Z作为寿星,自然希望吃到的第一块蛋糕的幸运值总和最大,但小Z ...

  5. AcWing 29. 删除链表中重复的节点

    题目地址 https://www.acwing.com/problem/content/description/27/ 来源:剑指Offer 题目描述在一个排序的链表中,存在重复的结点,请删除该链表中 ...

  6. ES6 class类中定义私有变量

    ES6 class类中定义私有变量 class类的不足 看起来, es6 中 class 的出现拉近了 JS 和传统 OOP 语言的距离.但是,它仅仅是一个语法糖罢了,不能实现传统 OOP 语言一样的 ...

  7. expect实现非交互下的ssh连接, expect简单使用整理

    1. shell中使用ssh远程连接服务器做一些事情通常需要交互输入些信息, 可使用expect语句解决: 2. expect中设置变量语法: set name xxx set age    xxx  ...

  8. Codeforces Round 596 题解

    万幸的是终于碰上了一场上分好场. 不幸的是一开始差点不会 A. 万幸的是想了个不那么稳的结论过了 pretest. 不幸的是罚时很高,而且慌得一比. 万幸的是然后半个小时内把 B 和 C 码了. 不幸 ...

  9. ASP.NET Core 中基于 API Key 对私有 Web API 进行保护

    这两天遇到一个应用场景,需要对内网调用的部分 web api 进行安全保护,只允许请求头账户包含指定 key 的客户端进行调用.在网上找到一篇英文博文 ASP.NET Core - Protect y ...

  10. Vscode 打字特效插件Power Mode安装使用说明

     壹 ❀ 引 我记得在17年使用atom编辑器的时候,使用过一款打字特效的插件,只要我们输入代码,代码上方就会有与代码颜色对应的星星效果,今天脑抽突然想起了这个中二插件,搜索了一番成功安装,大致效果如 ...