Linux内核移植 part2:uboot 设备树--基本概念和源码介绍
来源:互联网 发布:淘宝折扣怎么设置 编辑:程序博客网 时间:2024/06/05 05:33
arm uboot的设备树源文件位于arch/arm/dts/
目录下,网络上有很多介绍Linux设备树概念的文章,这里以dts相关的API为切入点,如果都懂了,设备树的东西就迎刃而解了。本篇文章首先记录一些基本知识,下一篇进行源码分析。
一、设备树文件基础
这里的内容根据kernel/Documentation/devicetree/booting-without-of.txt
,翻译加总结而来。有这些概念理解源码就不会有设备树相关知识性的问题了。
dtb文件由dts文件通过dtc工具编译而来,用来描述硬件配置。
dts叫设备树,顾名思义,就是以树结构来描述设备。树的成员称为节点,有一个根节点,只有根节点没有父亲节点,其他节点有且只有一个父亲节点。
节点名字
根节点没有名字,路径为”/”
每个节点有两个名字,真正的名字包含在名为name的属性中,还有一个unit name,用来区分同一层级上拥有相同name的节点,由node name,@和unit address构成。通常用来表示在设备树中的路径。路径用”/father1/father2/”表示。
compatible 属性
每个表示实际设备的节点需要compatible属性,用来表示向后完全兼容的硬件。
phandle or linux,phandle
可以通过其他节点属性来引用的节点必须有这个属性。
简单示例
/ 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,970@0 | |- name = "PowerPC,970" | |- device_type = "cpu" | |- reg = <0> | |- clock-frequency = <0x5f5e1000> | |- 64-bit | |- linux,phandle = <2> | o memory@0 | |- name = "memory" | |- device_type = "memory" | |- reg = <0x00000000 0x00000000 0x00000000 0x20000000> | |- linux,phandle = <3> | o chosen |- name = "chosen" |- bootargs = "root=/dev/sda2" |- linux,phandle = <4>
“/”是根节点,他的unit name为device tree,拥有name, model, compatible等属性,其他的也类似。
1.2 设备树的结构块
结构块描述每个节点的结构。每个节点内容包含:
一个开始标识符,全路径,属性列表,子节点列表,一个结束标识符。
the basic structure of a single node: * token OF_DT_BEGIN_NODE (that is 0x00000001) * for version 1 to 3, this is the node full path as a zero terminated string, starting with "/". For version 16 and later, this is the node unit name only (or an empty string for the root node) * [align gap to next 4 bytes boundary] * for each property: * token OF_DT_PROP (that is 0x00000003) * 32-bit value of property value size in bytes (or 0 if no value) * 32-bit value of offset in string block of property name * property value data if any * [align gap to next 4 bytes boundary] * [child nodes if any] * token OF_DT_END_NODE (that is 0x00000002)
1.3 设备树字符串块
为了节省空间,属性名字被单独放在strings block中,structure block中的属性定义包含了属性值在strings block中的偏移。
基本知识就简单罗列到这里,其实要理解设备树做到两点就可以了:
- 理解节点组织方式
- 理解<属性,值>对的含义
二. dts相关源代码
位于$(tree)/lib/
以及$(tree)/lib/libfdt/
。完成Flattened Device Tree Decode的功能。
43e440a0 <__dtb_dt_begin>:/* 这是magic number: 0xd00dfeed */43e440a0: edfe0dd0 ldcl 13, cr0, [lr, #832]! ; 0x34043e440a4: 2f360000 svccs 0x0036000043e440a8: 78000000 stmdavc r0, {} ; <UNPREDICTABLE>
libfdt介绍:
The libfdt functionality was written by David Gibson. The original
source came from the git repository:URL: git://ozlabs.org/home/dgibson/git/libfdt.git
author David Gibson dgibson@sneetch.(none)
Fri, 23 Mar 2007 04:16:54 +0000 (15:16 +1100)
committer David Gibson dgibson@sneetch.(none)
Fri, 23 Mar 2007 04:16:54 +0000 (15:16 +1100)
commit 857f54e79f74429af20c2b5ecc00ee98af6a3b8b
tree 2f648f0f88225a51ded452968d28b4402df8ade0
parent 07a12a08005f3b5cd9337900a6551e450c07b515To adapt for u-boot usage, only the applicable files were copied and
imported into the u-boot git repository.
Omitted:
* GPL - u-boot comes with a copy of the GPL license
* test subdirectory - not directly useful for u-bootAfter importing, other customizations were performed. See the git log
for details.Jerry Van Baren
- Linux内核移植 part2:uboot 设备树--基本概念和源码介绍
- Linux内核移植 part2:uboot设备树--生成过程分析
- Linux内核移植 part2:uboot设备树--解析过程分析
- Linux内核移植 part2:uboot 设备驱动模型
- Linux内核移植 part2:uboot bootdelay参数
- Linux内核移植 part2:uboot load_addr 释疑
- Linux内核移植 part2:uboot lcd驱动
- Linux内核移植 part2:printascii详解
- uboot 与 Linux 内核移植
- 放弃uboot和内核移植
- Linux内核移植--设备树支持
- S3c6410 linux内核移植(11)---用SD卡下载uboot、linux内核和文件系统
- Linux内核编程三:uboot移植
- zynq-7000 zc706 uboot和内核及设备树编译
- 6410 uboot和内核的移植
- 友善mini2440:uboot和内核的移植
- mini2440:uboot和内核的移植
- linux系统移植和Uboot 移植
- mapping parameters
- shell学习记录
- 启动hadoop 2.6遇到的datanode启动不了
- 将真分数分解为埃及分数
- 微服务架构
- Linux内核移植 part2:uboot 设备树--基本概念和源码介绍
- jquery $(document).ready() 与window.onload的区别
- redis全面讲解使用场景
- myeclipse修改内存大小不足
- POJ 3278 Catch That Cow
- ios 实现自定义状态栏StatusBar 和 导航栏navigationBar 的状态和颜色
- 121. Best Time to Buy and Sell Stock 类别:动态规划 难度:easy
- 二维常用分布
- HTML注意事项