【Device Tree】Device Tree 基础概念

历史背景

Device Tree是一种描述硬件的数据结构,它起源于OpenFirmware(OF)。Device Tree的应用使得Linux Kernel中的驱动代码和硬件信息实现了相互的隔离,减少了Kernel代码中的耦合。Linux内核从3.x开始正式引入设备树的概念。

Open Firmware是Sun在20世纪80年代后期设计的固件接口规范,并移植到许多架构中.它指定运行时OS客户端接口,跨平台设备接口(FCode),用户界面和用于描述机器的设备树布局.

FDT是开放固件DSDT对ACPI的作用.FDT重用Open Firmware建立的设备树布局.实际上,Linux PowerPC支持使用相同的代码库来支持Open Firmware和FDT平台.

看看Kernel源码目录下的drivers/of/base.c.它是在1996年添加的,但它的功能用于现今的ARM设备树.所以FDT只是OF的一部分.这就是为什么设备树的所有功能都以of_前缀开头的原因.

基本语法

在学习Device Tree前需要主要目前讲到的Device Tree都是指的是Flattened Device Tree

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

上图是一个展示了简单device tree 的例子, 在这个例子中通过“o”和节点名称来代表一个节点(node)名称. device tree可以理解为节点和其属性构成,每个节点可以有2个或多个带名称的属性,而属性可以有对应的值。 这里只是以树形的方式的展示了什么是device tree.
上图的device tree就是由根节点和子节点构成.

根节点:
    o cpus
    memory@0
    o chosen

子节点:
    o PowerPC,970@0(父节点为cpus)

既然我们称上述结构为树,因此除了根节点没有父节点外其他节点有且只有一个节点。
一个节点可以有两个名称构成,主名称通常是和节点下的"name"相同, 另外一个在Linux Kernel的官方文档中称作"unit name", “unit name"主要是用于区分同级同主名称的jie节点, 通常一些节点还包含”@“符号和"unit address”, 用于指出该节点所在的bus类型。

ehh 整理到这里发现没表述好什么是device tree,于是又到互联网上找是否有更好的文章继续学习下,结果!!意外之中发现了一篇英文版本的文章,非常好的讲述了关于device tree的基本概念.

完整的目录结构如下:

Welcome to Devicetree Specification’s documentation!

  1. Introduction
    1.1. Purpose and Scope
    1.2. Relationship to IEEE™ 1275 and ePAPR
    1.3. 32-bit and 64-bit Support
    1.4. Definition of Terms
  2. The Devicetree
    2.1. Overview
    2.2. Devicetree Structure and Conventions
    2.2.1. Node Names
    2.2.2. Generic Names Recommendation
    2.2.3. Path Names
    2.2.4. Properties
    2.3. Standard Properties
    2.3.1. compatible
    2.3.2. model
    2.3.3. phandle
    2.3.4. status
    2.3.5. #address-cells and #size-cells
    2.3.6. reg
    2.3.7. virtual-reg
    2.3.8. ranges
    2.3.9. dma-ranges
    2.3.10. name (deprecated)
    2.3.11. device_type (deprecated)
    2.4. Interrupts and Interrupt Mapping
    2.4.1. Properties for Interrupt Generating Devices
    2.4.2. Properties for Interrupt Controllers
    2.4.3. Interrupt Nexus Properties
    2.4.4. Interrupt Mapping Example
  3. Device Node Requirements
    3.1. Base Device Node Types
    3.2. Root node
    3.3. /aliases node
    3.4. /memory node
    3.5. /chosen Node
    3.6. /cpus Node Properties
    3.7. /cpus/cpu* Node Properties
    3.7.1. General Properties of /cpus/cpu* nodes
    3.7.2. TLB Properties
    3.7.3. Internal (L1) Cache Properties
    3.7.4. Example
    3.8. Multi-level and Shared Cache Nodes (/cpus/cpu*/l?-cache)
    3.8.1. Example
  4. Device Bindings
    4.1. Binding Guidelines
    4.1.1. General Principles
    4.1.2. Miscellaneous Properties
    4.2. Serial devices
    4.2.1. Serial Class Binding
    4.2.2. National Semiconductor 16450/16550 Compatible UART Requirements
    4.3. Network devices
    4.3.1. Network Class Binding
    4.3.2. Ethernet specific considerations
    4.4. Power ISA Open PIC Interrupt Controllers
    4.5. simple-bus Compatible Value
  5. Flattened Devicetree (DTB) Format
    5.1. Versioning
    5.2. Header
    5.3. Memory Reservation Block
    5.3.1. Purpose
    5.3.2. Format
    5.4. Structure Block
    5.4.1. Lexical structure
    5.4.2. Tree structure
    5.5. Strings Block
    5.6. Alignment
  6. Devicetree Source (DTS) Format (version 1)
    6.1. Compiler directives
    6.2. Labels
    6.3. Node and property definitions
    6.4. File layout

献上链接: Welcome to Devicetree Specification’s documentation!

需要注意对于我们的实际开发中,不同的kernel版本使用的dts版本可能会有所差异,需要注意其语法差异;

相关链接

Device_Tree_Reference
蜗窝科技-Device Tree
Android - Device Tree Overlays
Device Tree: DTS/DTB/FDT

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值