当前位置:网站首页>21天学习挑战赛(2)图解设备树的使用
21天学习挑战赛(2)图解设备树的使用
2022-08-05 02:55:00 【小辉_Super】
活动地址:CSDN21天学习挑战赛
原文专栏地址:RK3399平台开发入门到精通系列专栏
原文地址:RK3399平台开发系列讲解(内核设备树篇)3.2、图解Kernel Device Tree(设备树)的使用
以前也接触过 Linux 的内核,主要就是编写一些小的驱动,调试一些模块,但没有真正地去研究过内核底层,因为底层已经由芯片厂商整理好,无需我去调试。现在趁着这个 21 天学习挑战赛,我打算认真学习一下 Linux 内核的一些基本知识,说不定以后能用上。
学习日记
设备树包含的硬件信息有哪些?
设备树 Device Tree 可以描述的硬件信息包括:
- CPUs
- Memory
- Buses
- Peripheral Connections
- Interrupt Controllers
- GPIO Controllers
- Clock Controllers
设备树示例
下面是一个 Device Tree 的示例(来自课程原文),重要的属性包括 compatible
、reg
、clocks
、interrupts
和 status
。这些属性的具体介绍写在后面的章节。下图摘自原文。
设备树语法解析
设备树的结构很简单,主要由 Node
(节点)和 Property
(属性)组成。比如上图就是一个 Node,系统中每个设备都用一个 Node 来描述,这些 Node 被组织成树状结构。每个 Node 中包含了若干的 Property/Value 来描述 Node 的一些特性。
每个 Node 用 node name 进行标识,节点名字由 node-name 和 unit-address 组成。node-name 说明了设备的名字,必须使用字符开头,unit-address 为此设备的主地址,要求唯一且与此节点的 reg 属性的开始地址一致。
设备树格式示例:
[label:] node-name[@unit-address] {
[properties definitions]
[child nodes]
}
“[ ]” 表示可选项,label 是 Node 的标识,便于在 dts 文件中引用。 child node 的格式和 node 完全相同。
特殊节点介绍
根节点
一个设备树只能有一个根节点(root node),至少需要由 cpu 和 memory 节点组成。
例如(原文的示例)
/ {
compatible = "rockchip,rk3399";
interrupt-parent = <&gic>;
#address-cells = <2>;
#size-cells = <2>;
cpus {
......
}
别名节点
aliases 节点可以用来定义别名节点。在引用一个节点时需要指定其完整地址,如果每次引用都要写完整的地址,未免有些麻烦,而 aliases 可以解决这个问题。下图摘自原文。
CPU 节点
前面提到,根节点必须有一个 cpu 节点,下面的例子摘自原文:
cpus {
#address-cells = <2>;
#size-cells = <0>;
cpu_l0: [email protected]0 {
device_type = "cpu";
compatible = "arm,cortex-a53", "arm,armv8";
reg = <0x0 0x0>;
enable-method = "psci";
#cooling-cells = <2>; /* min followed by max */
clocks = <&cru ARMCLKL>;
dynamic-power-coefficient = <100>;
};
Memory 节点
memory device node 是所有设备树文件的必备节点,它描述了系统的物理内存布局。
可选节点
chosen 主要用来描述由系统硬件指定的运行参数,并不是一个真实的设备,该节点主要是为了 uboot 向 Linux 内核传递数据。重点是 bootargs 这个参数,例如:
chosen {
bootargs = "console=ttymxc0,115200"; };
属性
compatible 属性 和 model 属性
compatible 属性通常用来实现 device 和 driver 的适配,推荐格式为 “manufacturer,model”
驱动文件中一般都有一个 OF 匹配表,里面有一些 compatible 值,如果设备节点的 compatible 与驱动 OF 匹配表中任何一个相同,那么表示该设备可以使用这个驱动。
model 属性用来表示型号,一般用来描述设备模块的信息,如名字。
寻址属性
如果设备节点中有寻址需求(定义了 reg),那就必须要定义下面这两个属性:
- #address-cells
- #size-cells
‘#’ 符号表示 number 的意思,#address-cells 用来描述 sub node 中 reg 属性的地址域特性,即要用多少个 u32 来描述地址域。如:
reg = <address1 length1 [address2 length2] [address3 length3] ... >
#size-cells 用来表示地址长度。
下图摘自原文:
中断
中断属性包括 interrupt-controller,#interrupt-celles,interrupt-parent 和 interrupts。
暂时先不学习。
节点状态
设备树中一般使用 okay 和 disabled 来打开或关闭设备,下面是一些与设备状态有关的值:
值 | 描述 |
---|---|
“okay” | 设备可操作(已开启) |
“diable” | 设备不可操作(已关闭) |
“fail” | 设备不可操作,设备检测到了一些错误 |
“fail-sss” | 同 “fail” |
边栏推荐
- Snapback - same tree
- 627. Change of gender
- [机缘参悟-60]:《兵者,诡道也》-2-孙子兵法解读
- Principle and Technology of Virtual Memory
- DAY22: sqli-labs shooting range clearance wp (Less01~~Less20)
- 通过模拟Vite一起深入其工作原理
- Data storage practice based on left-order traversal
- Syntax basics (variables, input and output, expressions and sequential statements)
- private封装
- shell statement to modify txt file or sh file
猜你喜欢
How to sort multiple fields and multiple values in sql statement
How OpenGL works
甘特图来啦,项目管理神器,模板直接用
A small tool to transfer files using QR code - QFileTrans 1.2.0.1
DAY22: sqli-labs shooting range clearance wp (Less01~~Less20)
正则表达式,匹配中间的某一段字符串
[LeetCode Brush Questions] - Sum of Numbers topic (more topics to be added)
The linear table lookup
word分栏小记
mysql can't Execute, please solve it
随机推荐
torch.roll()
How to transfer a single node of Youxuan database to a cluster
The pit of std::string::find return value
Principle and Technology of Virtual Memory
Error: Not a signal or slot declaration
采用redis缓存的linux主从同步服务器图片硬盘满了移到新目录要修改哪些指向
北斗三号短报文终端露天矿山高边坡监测方案
Ant Sword Advanced Module Development
The 20th day of the special assault version of the sword offer
C student management system head to add a student node
A small tool to transfer files using QR code - QFileTrans 1.2.0.1
1484. 按日期分组销售产品
【 genius_platform software platform development 】 : seventy-six vs the preprocessor definitions written cow force!!!!!!!!!!(in the other groups conding personnel told so cow force configuration to can
Syntax basics (variables, input and output, expressions and sequential statements)
沃谈小知识 |“远程透传”那点事儿
注意潍坊开具发票一般需要注意
Lexicon - the maximum depth of a binary tree
Solve connect: The requested address is not valid in its context
private package
Is your data safe in this hyperconnected world?