一、配置u-boot

u-boot对设备树的支持很简单,uboot从v1.1.3开始支持设备树,为了使用设备树,需要在config文件里配置

a、#define CONFIG_OF_LIBFDT

b、配置device tree 分区

重新编译u-boot即可

1、确定u-boot中内核启动命令

U_BOOT_CMD(bootz,    CONFIG_SYS_MAXARGS, 1,  do_bootz,"boot Linux zImage image from memory","[addr [initrd[:size]] [fdt]]\n""    - boot Linux zImage stored in memory\n""\tThe argument 'initrd' is optional and specifies the address\n""\tof the initrd in memory. The optional argument ':size' allows\n""\tspecifying the size of RAW initrd.\n"
#if defined(CONFIG_OF_LIBFDT)"\tWhen booting a Linux kernel which requires a flat device-tree\n""\ta third argument is required which is the address of the\n""\tdevice-tree blob. To boot that kernel without an initrd image,\n""\tuse a '-' for the second argument. If you do not pass a third\n""\ta bd_info struct will be passed instead\n"
#endif
);

由此可见:

bootm <uImage_addr>                            // 无设备树
 bootm <uImage_addr> <initrd_addr> <dtb_addr>   // 有设备树

2、确定启动参数

initrd_addr 没有涉及到,便用-代替。

dtb_addr的选取遵循两个原则:

a、不破坏u-boot本身

b、不破坏内核

以JZ2440内存使用为例:这里选取0x32000000是合理的,当然也可以选择其他不破坏内核和u-boot的区域。

设置u-boot启动参数:bootcmd=nand read 0x30007FC0 kernel;nand read 32000000 device_tree;bootm 0x30007FC0 - 0x32000000

二、fdt命令

u-boot支持设备树最重要的便是fdt命令,可在u-boot命令交互界面修改dtb文件,这对于实际开发非常有帮助。

1、dtb修改原理

a、修改属性值value

value_new 要么与value_old相等,要么大于或者小于value_old,所以修改属性值:

1)、把原属性value_old所占空间从value_len字节扩展为value_len_new字节,把value_old之后的所有内容移动(|value_len_new- value_len|)字节。

2)、把新value_new 写入val所占的value_len_new字节空间。

3)、修改dtb头部信息中structure block的长度: size_dt_struct = size_dt_struct +(value_len_new- value_len)。

4)、修改dtb头部信息中string block的偏移值: off_dt_strings = off_dt_strings +(value_len_new- value_len)。

5)、修改dtb头部信息中的总长度: totalsize = totalsize +(value_len_new- value_len)。

b、在节点增加属性

1)、 如果在string block中没有这个属性的名字,就在string block尾部添加一个新字符串: 属性的名并且修改dtb头部信息中string block的长度: size_dt_strings,修改dtb头部信息中的总长度: totalsize

2)、找到属性所在节点, 在节点尾部扩展一块空间, 内容及长度为: 
   TAG      // 4字节, 对应0x00000003
   len      // 4字节, 表示属性的val的长度
   nameoff  // 4字节, 表示属性名的offset
   val      // len字节, 用来存放val

3)、修改dtb头部信息中structure block的长度: size_dt_struct

4)、修改dtb头部信息中string block的偏移值: off_dt_strings

5)、 修改dtb头部信息中的总长度: totalsize

2、使用fdt命令

在u-boot中使用 ?fdt   打印fdt命令的帮助信息如下:

SMDK2410 # ? fdt
fdt - flattened device tree utility commandsUsage:
fdt addr   <addr> [<length>]        - Set the fdt location to <addr>
fdt move   <fdt> <newaddr> <length> - Copy the fdt to <addr> and make it active
fdt resize                          - Resize fdt to size + padding to 4k addr
fdt print  <path> [<prop>]          - Recursive print starting at <path>
fdt list   <path> [<prop>]          - Print one level starting at <path>
fdt set    <path> <prop> [<val>]    - Set <property> [to <val>]
fdt mknode <path> <node>            - Create a new node after <path>
fdt rm     <path> [<prop>]          - Delete the node or <property>
fdt header                          - Display header info
fdt bootcpu <id>                    - Set boot cpuid
fdt memory <addr> <size>            - Add/Update memory node
fdt rsvmem print                    - Show current mem reserves
fdt rsvmem add <addr> <size>        - Add a mem reserve
fdt rsvmem delete <index>           - Delete a mem reserves
fdt chosen [<start> <end>]          - Add/update the /chosen branch in the tree<start>/<end> - initrd start/end addr

nand read 32000000 device_tree          // 从flash读出dtb文件到内存(0x32000000)
fdt addr 32000000                                 // 告诉fdt, dtb文件在哪
fdt print /led pin                                      // 打印/led节点的pin属性
fdt set /led pin <0x00050005>                // 设置/led节点的pin属性
fdt print /led pin                                       // 打印/led节点的pin属性
nand erase device_tree                          // 擦除flash分区
nand write 32000000 device_tree   // 把修改后的dtb文件写入flash分区

设备树(二)—— u-boot对设备树的支持相关推荐

  1. 第五十二讲 DTS(设备树)

    第五十二讲 DTS(设备树) 一.简介 随着硬件设备的种类逐年递增,板级platform平台设备文件越来越多.在过去的Linux中,arch/arm/plat-xxx和arch/arm/mach-xx ...

  2. linux设备和驱动匹配的方法,Linux使用设备树的i2c驱动与设备匹配方式

    Linux使用设备树的i2c驱动与设备匹配有3种方式: of_driver_match_device acpi_driver_match_device i2c_match_id 源码: static ...

  3. linux kernel 2.6 i2c设备驱动程序框架介绍,linux设备驱动程序-i2c(2)-adapter和设备树的解析...

    linux设备驱动程序-i2c(2)-adapter和设备树的解析 (注: 基于beagle bone green开发板,linux4.14内核版本) 而在linux设备驱动程序--串行通信驱动框架分 ...

  4. Solaris10中级读书笔记之二:管理本地磁盘设备

    一.基本的磁盘结构的介绍 磁盘设备有物理和逻辑成分.物理成分包括磁盘浅盘和读写磁头.逻辑成分包括磁盘片,柱面,磁轨和扇区. 1.物理磁盘结构 磁盘的物理结构由一系列平面的,在轴上有一堆有磁力的盘片组成 ...

  5. 二十、SPI设备驱动及应用(一)

    先给出Linux SPI子系统的体系结构图: SPI子系统体系结构 下面开始分析SPI子系统. Linux中SPI子系统的初始化是从drivers/spi/spi.c文件中的spi_init函数开始的 ...

  6. i.MX 6ULL 驱动开发 二十七:块设备

    参考:[块设备]通用块层 struct bio 详解 | zzm (aliez22.github.io) 一.Linux 中块设备驱动框架 二.块设备基本概念 1.扇区的概念来自硬件,扇区是硬件最小操 ...

  7. adb通信协议分析以及实现(二):adb服务进程发现设备

    adb服务进程一个重要的功能就是查找设备,当插入一个android设备,并且成功安装手机驱动后,adb的服务进程就可以发现设备,当adb进程使用devices命令的时候,服务进程把自己保存的设备列表返 ...

  8. 机器学习Sklearn实战——梯度提升树二分类原理

    一.算法使用 (一)创建 (二)参数调整 cross_val_score:求单一参数最合适的值(KNN) GridSearchCV网格搜索:多参数组合最优的值 标准:准确率,精确率,召回率,F1 (三 ...

  9. AVL树(二)之 C++的实现

    AVL树(二)之 C++的实现 概要 上一章通过C语言实现了AVL树,本章将介绍AVL树的C++版本,算法与C语言版本的一样. 目录 1. AVL树的介绍 2. AVL树的C++实现 转载请注明出处: ...

  10. 【数据结构与算法】之深入解析“把二叉搜索树转换为累加树”和“从二叉搜索树到更大和树”的求解思路与算法示例

    一.题目要求 ① 把二叉搜索树转换为累加树 给出二叉搜索树的根节点,该树的节点值各不相同,请将其转换为累加树(Greater Sum Tree),使每个节点 node 的新值等于原树中大于或等于 no ...

最新文章

  1. 三刺激值计算公式_常用的车削、铣削、钻削加工计算公式全在这里了,随用随查...
  2. 【消息中间件】Spring整合RabbitMQ
  3. 基于触发机制的脚本系统
  4. 单例模式源码分析(jdk+spring+mybatis)
  5. 13.1-13.3 设置更改root密码,连接MySQL,MySQL常用命令
  6. 【MySQL性能优化】数据库设计三大范式(二)
  7. Golang——枚举(iota)的使用
  8. docsify神奇的文档网站生成工具
  9. 通过cookie保存并读取用户登录信息实例
  10. Website English Comments
  11. TinyMind 和机器之心收藏
  12. caffe手写数字分类-学习曲线
  13. EDA技术实用教程 | 复习十三 | 计数器
  14. 觅风易语言视频教程全集(143集)
  15. PHP语言基本数据类型
  16. 网易公开课APP如何修改视频缓存地址
  17. npm warn config global `--global`, `--local` are deprecated. use `--location=global` instead.
  18. 人民币对美元汇率中间价报6.7774元 下调109个基点
  19. 【C++ 程序】 TVJ Complex Calculator (v 2.1) 复数计算器
  20. CSS压缩之:正则五步替换法

热门文章

  1. YOLOV2网络模型
  2. jsonp跨域的缺点ajax缺点,浅析JSONP解决Ajax跨域访问问题的思路详解
  3. javascript中级阶段测试
  4. 莫比乌斯环matlab代码,《莫比乌斯时空》:当《神秘博士》遇上《源代码》
  5. 区块链推文@2019.1.24
  6. Day2 - 基础语法和变量
  7. linux index shell,Linux shell 数组使用
  8. 用计算机找一个人,我可以通过ID号找到一个人的位置吗?
  9. 欧拉函数(C++ 实现)
  10. 23Flutter FloatingActionButton实现类似闲鱼App底部导航凸起按钮: