




已阅读5页,还剩22页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
精品【摘要】本文以MPC8378处理器、Linux2.6.25内核及U-boot1.3.4为例,讲述了如何在PowerPC架构下使用FDT。首先介绍了引入FDT的背景,接着详细介绍了FDT的组成及制作。最后介绍了U-boot及内核如何支持FDT。【关键字】PowerPC,MPC8378,DTS,DTB,FDT,device node,property,compatible1 背景 22 设备树的描述方式 22.1 root Node 32.2 chosen 32.3 cpus Node 32.4 System Memory 52.5 Devices 52.5.1 Compatible属性 62.5.2 Addressing 62.6 Interrupts and Interrupt Controllers 73 如何制作设备树映像 83.1 输入 83.2 输出 93.3 命令格式 94 设备树的传递途径 94.1 U-boot对FDT的支持 104.2 如何配置FDT 104.3 如何传递设备树 105 内核如何解析设备树 126 设备树对驱动设计产生的影响 151 背景通常情况下,桌面机和服务器可以兼容大部分软件。最好的结果就是当添加新硬件时,无需重新编译Linux内核。标准的固件接口可以保证bootloader将正确的参数传递给内核。PC可以采用bios,PowerPC and Sparc采用Open-Firmware接口。但是对于嵌入式系统,软件差别太大,内核本身也是定制的,bootloader只需要传递很少的参数,因为大部分信息都是硬编码在系统的配置中的。这样同一个内核映像很难同时使用在多个不同的平台上。早期的PowerPC平台采用特定的数据结构bd_info来传递参数,其定义在include/asm-ppc/ppcboot.h,#define来定义特定平台的数据域,但并没有什么信息来说明当前采用的是那个bd_info结构,所以必须保证在内核和bootloader中同时更新,以便保持一致。合并32-bit (arch/ppc) 和 64-bit (arch/ppc64) PowerPC的同时,决定重新整理固件接口,建立新的目录arch/powerpc,这里所有的平台必须向内核提供Open Firmware风格的设备树,以便内核启动时可以获得当前平台的硬件配置。2 设备树的描述方式简单的说设备书是一种描述硬件配置信息的数据结构,包括CPU,内存,总线及相关外设。内核启动时可以解析这些信息,以此决定如何配置内核及加载那些驱动。该数据结构有一个单一的根节点“/”。每个节点有个名字并可以包含多个子节点。数据的格式遵循IEEE standard 1275。Device tree source (.dts)采用一种易编辑的文本方式来表达设备树,device tree compiler tool (dtc)将.dts转换成binary device tree blob(.dtb)。设备树并不是控制系统设备的唯一方法,比如内核对USB和PCI已经有非常方便的检测机制。/ / the root node an-empty-property; a-child-node array-prop = ; string-prop = hello, world; ; another-child-node binary-prop = 0102CAFE; string-list = yes,no,maybe; ;Figure 1: Simple example of the .dts file format2.1 root Node设备树的起点是根节点,Model和compatible属性指明了当前平台的名字,格式为,:Mfg是vendor,board是板子模型Compatible属性不一定非得要,但是当两个系统在硬件配置上基本一致时,这个参数可以用于辨别当前系统。/ model = fsl,mpc8377rdb; compatible = fsl,mpc8377rdb; #address-cells = ; #size-cells = ; aliases ethernet0 = &enet0; ethernet1 = &enet1; serial0 = &serial0; serial1 = &serial1; /pci0 = &pci0; ; / Child nodes go here;Figure 3: Example system root node2.2 chosen此节点并不真正代表设备节点,而是一些虚拟的由bootloader传递给内核的一些参数,包括bootargs(cmdline)和initrd等。一般由bootloader在启动内核时添加此节点。2.3 cpus Nodecpus节点是root节点的子节点,对于多核CPU系统,每个CPU有一个子节点。Cpus节点并不需要特别的特性,但是通常习惯指定#address-cells = 和#size-cells = ,这指定了各个CPU节点的reg属性的格式,其用于编码物理CPU号。CPU节点的格式为cpux,model属性描述CPU类型,其他的是时钟频率及cache 相关属性。cpus #cpus = ; #address-cells = ; #size-cells = ; PowerPC,83770 device_type = cpu; model = PowerPC, 8377; reg = ; d-cache-line-size = ; i-cache-line-size = ; d-cache-size = ; i-cache-size = ; timebase-frequency = ; bus-frequency = ; clock-frequency = ; ;Figure 4: cpus nodecpus #cpus = ; #address-cells = ; #size-cells = ; PowerPC,86410 device_type = cpu; reg = ; d-cache-line-size = ; / 32 bytes i-cache-line-size = ; / 32 bytes d-cache-size = ; / L1, 32K i-cache-size = ; / L1, 32K timebase-frequency = ; / 33 MHz, from uboot bus-frequency = ; / From uboot clock-frequency = ; / From uboot 32-bit; linux,boot-cpu; ; PowerPC,86411 device_type = cpu; reg = ; d-cache-line-size = ; / 32 bytes i-cache-line-size = ; / 32 bytes d-cache-size = ; / L1, 32K i-cache-size = ; / L1, 32K timebase-frequency = ; / 33 MHz, from uboot bus-frequency = ; / From uboot clock-frequency = ; / From uboot 32-bit; ;2.4 System Memory描述系统内存的节点成为memory node,其为root节点的子节点,通常只用一个memory节点描述系统所有的内存范围,reg属性用来定义当前可用的各个memory范围。memory device_type = memory; reg = ; / 256MB at 0;Figure 5: Memory node2.5 Devices一系列节点用于描述系统总线及设备,每个总线及设备在设备树种都有自己的节点。处理器的local bus通常直接作为根节点的子节点,附着在local bus上的Devices and bridges将作为其子节点。下图显示的PLB bus上的设备包括interrupt controller, an Ethernet device,及 OPB bridge,OPB总线上有serial devices and a Flash deviceplb compatible = simple-bus; #address-cells = ; #size-cells = ; ranges; UIC0: interrupt-controller compatible = ibm,uic-440gp, ibm,uic; interrupt-controller; #interrupt-cells = ; ; ethernet20000 compatible = ibm,emac-440gp; reg = ; interrupt-parent = ; interrupts = ; ; opb compatible = simple-bus; #address-cells = ; #size-cells = ; ranges = ; serial0 compatible = ns16550; reg = ; interrupt-parent = ; interrupts = ; ; serial10000 compatible = ns16550; reg = ; interrupt-parent = ; interrupts = ; ; flash1ff00000 compatible = amd,s29gl256n, cfi-flash; reg = ; ; ;Figure 6: Simple System Device Hierarchy2.5.1 Compatible属性几乎每个设备都有compatible属性,OS利用此关键字来确定node所描述的设备,通常compatible字符串的格式如下:,对于每个特定的compatible值,需要为该设备定义一个device tree binding。有时候compatible是一系列字符串,如果某个设备在寄存器级别和某个旧设备兼容,则可以同时指定多个字串,这样OS就知道这两个驱动是兼容的。通常该设备的compatible字串在前,然后是兼容的旧设备的字串。2.5.2 Addressing设备地址由reg属性指定,其为一系列cell单元。格式如下:reg = ;每个reg的实际大小有父节点的#address-cells and #size-cells属性决定,#address-cells是用来指定base address基地址的cells个数,#size-cells是用来指定region size的cells个数。Reg所使用的cells个数必须是(#address-cells + #size-cells)的倍数。Reg定义的是bus address,而非system address,bus address是设备依赖的总线上的相对地址,或者更专业的说bus address是相对于父节点的。Ranges属性可以将bus address映射到父节点一级,格式如下:ranges = ;addr为总线地址,宽度为#address-cells,parent是父节点总线上的地址,宽度为父节点的#address-cells,size宽度为父节点的#size-cells。但是当总线地址和父节点地址映射关系为1:1时,可以简化映射关系:ranges;在本示例中,Flash在OPB总线上的地址为0x1ff00000,但OPB总线中,PLB bus address 0xe0000000 映射到了0x0000000 on the OPB bus,因此Flash设备的地址为0xfff00000。2.6 Interrupts and Interrupt Controllers设备树的自然布局很方便描述设备间的简单关系,但是中断系统是个比较复杂的例子。可以将serial device描述为OPB总线的子节点,但也可以说其是interrupt controller设备的子节点,那么如何描述呢?目前的规范是,自然树的结构适用于描述那些寻址和控制设备的主要接口,次要连接可以通过phandle属性来描述相互之间的关系,其为节点中的一个指针,指向另一个节点。对于中断连接,设备节点利用interrupt-parent and interrupts属性来描述到interrupt controller的连接。interrupt-parent是指向描述interrupt controller节点的指针,interrupts是interrupt controller可以触发的一系列中断信号。Interrupt controller节点必须定义空属性interrupt-controller,同时定义#interrupt-cells,确定几个cells描述一个中断信号。由于Interrupt controller节点在设备树种被其他节点链接,因此必须定义属性linux,phandle = 。对于大部分SOC系统,通常只有一个interrupt controller,,但是多个interrupt controller之间可以级联。interrupt controller和设备之间的关系就形成了interrupt tree。对于serial device node,interrupt-parent属性定义了其在中断树中与其父节点的关系。Interrupts属性定义了特定的中断标识,其格式取决于中断树中父节点的#interrupt-cells,通常#interrupt-cells为2,这样第一个值表示interrupt controller中的硬件中断编号,第二个值表示中断触发方式:电平触发或者边沿触发。/* IPIC* interrupts cell = * sense values match linux IORESOURCE_IRQ_* defines:* sense = 8: Level, low assertion* sense = 2: Edge, high-to-low change*/pic700 linux,phandle = ; interrupt-controller; #address-cells = ; #interrupt-cells = ; reg = ; built-in; device_type = ipic;serial4500 device_type = serial; compatible = ns16550; reg = ; clock-frequency = ; interrupts = ; interrupt-parent = ;3 如何制作设备树映像Device tree compiler(dtc)负责将文本格式的设备树转换成OS可以识别的格式。3.1 输入Dtc接受三种输入格式:源文件,即device tree source;Blob (dtb),flattened tree format,主要用于检查现有的DTB映像;FS文件系统,/proc/device-tree下面的文件树目录,主要用于从当前运行的内核中获得设备树映像。-sh-3.1# ls -al /proc/device-treels -l /proc/device-tree/-r-r-r- 1 root root 4 Jan 1 00:05 #address-cells-r-r-r- 1 root root 4 Jan 1 00:05 #size-cellsdr-xr-xr-x 2 root root 0 Jan 1 00:05 aliasesdr-xr-xr-x 2 root root 0 Jan 1 00:05 chosen-r-r-r- 1 root root 15 Jan 1 00:05 compatibledr-xr-xr-x 3 root root 0 Jan 1 00:05 cpusdr-xr-xr-x 15 root root 0 Jan 1 00:05 immre0000000dr-xr-xr-x 4 root root 0 Jan 1 00:05 localbuse0005000dr-xr-xr-x 2 root root 0 Jan 1 00:05 memory-r-r-r- 1 root root 1 Jan 1 00:05 namedr-xr-xr-x 2 root root 0 Jan 1 00:05 pcie000a000dr-xr-xr-x 2 root root 0 Jan 1 00:05 redbox-fpga-card0F0000000dr-xr-xr-x 2 root root 0 Jan 1 00:05 redbox-fpga-card1F0000000dr-xr-xr-x 2 root root 0 Jan 1 00:05 redbox-fpga-dbstateF0000000dr-xr-xr-x 2 root root 0 Jan 1 00:05 redbox-fpga-miscF0000000ls -l /proc/device-tree/immr/e0000000/-r-r-r- 1 root root 4 Jan 1 00:06 #address-cells-r-r-r- 1 root root 4 Jan 1 00:06 #size-cells-r-r-r- 1 root root 4 Jan 1 00:06 bus-frequency-r-r-r- 1 root root 11 Jan 1 00:06 compatible-r-r-r- 1 root root 4 Jan 1 00:06 device_typedr-xr-xr-x 2 root root 0 Jan 1 00:06 ethernet24000dr-xr-xr-x 2 root root 0 Jan 1 00:06 ethernet25000dr-xr-xr-x 2 root root 0 Jan 1 00:06 i2c3000dr-xr-xr-x 3 root root 0 Jan 1 00:06 i2c3100dr-xr-xr-x 2 root root 0 Jan 1 00:06 interrupt-controller700dr-xr-xr-x 3 root root 0 Jan 1 00:06 mdio24520-r-r-r- 1 root root 5 Jan 1 00:06 namedr-xr-xr-x 2 root root 0 Jan 1 00:06 powerb00-r-r-r- 1 root root 12 Jan 1 00:06 ranges-r-r-r- 1 root root 8 Jan 1 00:06 regdr-xr-xr-x 2 root root 0 Jan 1 00:06 serial4500dr-xr-xr-x 2 root root 0 Jan 1 00:06 serial4600dr-xr-xr-x 2 root root 0 Jan 1 00:06 spi7000dr-xr-xr-x 2 root root 0 Jan 1 00:06 timer500dr-xr-xr-x 2 root root 0 Jan 1 00:06 usb23000dr-xr-xr-x 2 root root 0 Jan 1 00:06 wdt2003.2 输出Blob (dtb),主要用于从DTS获得设备树映像;source (dts), 当输入参数为Blob (dtb),可以“反汇编”出设备树源文件;assembler source (asm),其最终可以编译成.O文件,可以链接到bootloader中或者frrmware image。3.3 命令格式dtc -I -O -o output-filename -V output_version input_filenamedtc -I dts -O dtb -S 0x3000 -o obj_name.dtb source_name.dts-S 指定的是生成的dtb文件的大小,需要适当地扩大以供u-boot 创建/choose节点时使用4 设备树的传递途径对于Open Firmware (OF)系统,prom_init.c中的代码负责解析设备树,并将其转化为blob印象。对于无Open Firmware (OF)的系统,内核可以直接从入口启动,并接受外部传递的flattened device tree参数。对于嵌入式系统,此参数由bootloader提供,或者封装过的zImage映像提供。4.1 U-boot对FDT的支持U-boot为了支持FDT,专门添加了新的代码,如下:/Libfdt目录fdt.hlibfdt.hfdt_support.hfdt_support.c4.2 如何配置FDT通常在板子配置头文件定义相关宏,以支持FDT/* Pass open firmware flat tree */#define CONFIG_OF_LIBFDT 1#define CONFIG_OF_BOARD_SETUP 1#define CONFIG_OF_STDOUT_VIA_ALIAS 1CONFIG_OF_BOARD_SETUP宏表示会对设备树中的部分参数进行调整,主要是timebase-frequency,bus-frequency,clock-frequency等参数,在设备树配置文件中,这些参数可能为0,即采用U-boot中的参数。4.3 如何传递设备树Lib_ppc/board.c中do_bootm_linux负责启动Linux内核。#if defined(CONFIG_OF_LIBFDT)#include #include #include static void fdt_error (const char *msg);static int boot_get_fdt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv, bootm_headers_t *images, char *of_flat_tree, ulong *of_size);static int boot_relocate_fdt (struct lmb *lmb, ulong bootmap_base, cmd_tbl_t *cmdtp, int flag, int argc, char *argv, char *of_flat_tree, ulong *of_size);#endif相关流程如下:在该流程中,主要从启动参数中找出设备树,然后在设备树中添加chosen 节点, 并将initrd 的地址地址,结束地址,bootargs,cmd_line 等参数保存到chosen 节点中,最后根据是否支持扁平设备树选择不同的内核启动方式。#if defined(CONFIG_OF_LIBFDT) if (of_flat_tree) /* device tree; boot new style */ /* * Linux Kernel Parameters (passing device tree): * r3: pointer to the fdt, followed by the board info data * r4: physical pointer to the kernel itself * r5: NULL * r6: NULL * r7: NULL */ debug ( Booting using OF flat tree./n); (*kernel) (bd_t *)of_flat_tree, (ulong)kernel, 0, 0, 0); /* does not return */ else#endif /* * Linux Kernel Parameters (passing board info data): * r3: ptr to board info data * r4: initrd_start or 0 if no initrd * r5: initrd_end - unused if r4 is 0 * r6: Start of command line string * r7: End of command line string */ debug ( Booting using board info./n); (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end); /* does not return */ 如果未定义CONFIG_OF_LIBFDT或者当前bootm命令没有FDT参数时则采用传统的方式启动内核。启动命令格式如下:Bootm kernel_addr ramdisk_addr/- fdt_addr当不采用ramdisk时,第二个参数为“-”5 内核如何解析设备树1)首先将从u-boot 传递过来的映像基地址和dtb 文件映像基地址保存通用寄存器r30,r31;2)通过调用machine_init()、early_init_devtree()函数来获取内核前期初始化所需的bootargs,cmd_line等系统引导参数;3)调用start_kernel()、setup_arch()、unflatten_device_tree()函数来解析dtb 文件,构建一个由device_node 结构连接而成的单项链表,并使用全局变量allnodes 指针来保存这个链表的头指针;4)内核调用OF 提供的API 函数获取allnodes链表信息来初始化内核其他子系统、设备等。Head_32.S/* This is where the main kernel code starts.*/start_here:。/* Do early platform-specific initialization,* and set up the MMU.*/ mr r3,r31 mr r4,r30 bl machine_init/* Find out what kind of machine were on and save any data we need* from the early boot process (devtree is copied on pmac by prom_init().* This is called very early on the boot process, after a minimal* MMU environment has been set up but before MMU_init is called.*/void _init machine_init(unsigned long dt_ptr, unsigned long phys) /* If btext is enabled, we might have a BAT setup for early display, * thus we do enable some very basic udbg output */#ifdef CONFIG_BOOTX_TEXT udbg_putc = btext_drawchar;#endif /* Do some early initialization based on the flat device tree */ early_i
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 睡眠监测助手App创新创业项目商业计划书
- 法律旅游线路创新创业项目商业计划书
- 游戏物品交易创新创业项目商业计划书
- 乳制品国际合作创新创业项目商业计划书
- 演出经纪人之《演出经纪实务》考前冲刺模拟题库含答案详解【考试直接用】
- 2025年教师招聘之《小学教师招聘》题库试题附完整答案详解(全优)
- 2025内蒙古呼伦贝尔农垦集团有限公司社会招聘笔试模拟附答案详解(突破训练)
- 2025内蒙古呼伦贝尔扎兰屯市教育系统“校园引才”27人笔试备考及1套完整答案详解
- 教师招聘之《幼儿教师招聘》考前冲刺分析及答案详解(考点梳理)
- 演出经纪人之《演出经纪实务》能力提升B卷题库含答案详解(模拟题)
- (2025秋新版)二年级上册道德与法治全册教案
- 老挝药品注册管理办法
- 2025年社工工作者考试真题及答案
- 建设工程项目协同作业方案
- 《肥胖症诊疗指南(2024年版)》解读课件
- 2025安化事业单位笔试真题
- 万玮:《班主任兵法》
- 拔牙知情同意书
- 个人分期还款协议书的范本
- SOP的作用与重要性
- 数据结构课程标准
评论
0/150
提交评论