• 2、设备树的规范(dts和dtb格式)


    第01节_DTS格式
    (1) 语法:
    Devicetree node格式:
    [label:] node-name[@unit-address] {
    [properties definitions]          属性,格式见下面Property
    [child nodes]       节点       
    };

    Property格式1:
    [label:] property-name = value;

    Property格式2(没有值):
    [label:] property-name;

    Property取值只有3种:
    arrays of cells(1个或多个32位数据, 64位数据使用2个32位数据表示), 使用<>扩起来的
    string(字符串),  使用双引号扩起来
    bytestring(1个或多个字节) ,使用[]括起来的,16进制表示的  

    示例:
    a. Arrays of cells : cell就是一个32位的数据
    interrupts = <17 0xc>;

    b. 64bit数据使用2个cell来表示:
    clock-frequency = <0x00000001 0x00000000>;

    c. A null-terminated string (有结束符的字符串):
    compatible = "simple-bus";

    d. A bytestring(字节序列) :
    local-mac-address = [00 00 12 34 56 78]; // 每个byte使用2个16进制数来表示
    local-mac-address = [000012345678]; // 每个byte使用2个16进制数来表示

    e. 可以是各种值的组合, 用逗号隔开:
    compatible = "ns16550", "ns8250";
    example = <0xf00f0000 19>, "a strange property format";


    (2)
    DTS文件布局(layout):
    /dts-v1/;
    [memory reservations] // 格式为: /memreserve/ <address> <length>;
    / {                       “/”表示根节点
    [property definitions]
    [child nodes]
    };

    (3) 特殊的、默认的属性:
    a. 根节点:
    #address-cells // 在它的子节点的reg属性中, 使用多少个u32整数来描述地址(address)
    #size-cells // 在它的子节点的reg属性中, 使用多少个u32整数来描述大小(size)
    compatible // 定义一系列的字符串, 用来指定内核中哪个machine_desc可以支持本设备,eg:compatible = “samsung,smdk2440”,"samsung,s3c24xx"   这种情况,优先比较第一个“samsung,smdk2440”
          // 即这个板子兼容哪些平台
          // uImage : smdk2410 smdk2440 mini2440 ==> machine_desc

    model // 咱这个板子是什么
        // 比如有2款板子配置基本一致, 它们的compatible是一样的
        // 那么就通过model来分辨这2款板子

    b. /memory
    device_type = "memory";
    reg // 用来指定内存的地址、大小,里面的值可以是<起始地址1   长度1   起始地址2    长度2>

    c. /chosen
    bootargs // 内核command line参数, 跟u-boot中设置的bootargs作用一样

    d. /cpus
    /cpus节点下有1个或多个cpu子节点, cpu子节点中用reg属性用来标明自己是哪一个cpu
    所以 /cpus 中有以下2个属性:
    #address-cells // 在它的子节点的reg属性中, 使用多少个u32整数来描述地址(address)

    #size-cells // 在它的子节点的reg属性中, 使用多少个u32整数来描述大小(size)
    // 必须设置为0


    e. /cpus/cpu*
    device_type = "cpu";
    reg // 表明自己是哪一个cpu

    (4) 引用其他节点:
    a. phandle : // 节点中的phandle属性, 它的取值必须是唯一的(不要跟其他的phandle值一样)

    pic@10000000 {
    phandle = <1>;
    interrupt-controller;        中断控制器
    };

    another-device-node {
    interrupt-parent = <1>; // 使用phandle值为1来引用上述节点    表示该节点产生的中断传给那个中断控制器
    };

    b. label:

    PIC: pic@10000000 {
    interrupt-controller;
    };

    another-device-node {
    interrupt-parent = <&PIC>; // 使用label来引用上述节点,
    // 使用lable时实际上也是使用phandle来引用,
    // 在编译dts文件为dtb文件时, 编译器dtc会在dtb中插入phandle属性
    };


    官方文档:
    https://www.devicetree.org/specifications/

    第02节_DTB格式
    官方文档:
    https://www.devicetree.org/specifications/

    内核文档:
    Documentation/devicetree/booting-without-of.txt

    DTB文件布局:(内存中存储格式是大端)
    ------------------------------
    base -> | struct boot_param_header |
    ------------------------------
    | (alignment gap) (*) |
    ------------------------------
    | memory reserve map |
    ------------------------------
    | (alignment gap) |
    ------------------------------
    | |
    | device-tree structure |
    | |
    ------------------------------
    | (alignment gap) |
    ------------------------------
    | |
    | device-tree strings |
    | |
    -----> ------------------------------
    |
    |
    --- (base + totalsize)

  • 相关阅读:
    CMP指令(转)
    步进电机简介
    IDE改为AHCI后系统无法启动的解决办法
    无线网络(WLAN)常见加密方式介绍
    51单片机学习记录——数码管动态显示
    DEDECMS 调用上级栏目标题
    微信小程序开发系列(二)小程序的全局文件
    微信小程序开发系列(一)小程序开发初体验
    python+unittest日志和报告输出模块
    pip更换国内镜像源
  • 原文地址:https://www.cnblogs.com/liusiluandzhangkun/p/11629084.html
Copyright © 2020-2023  润新知