Linux内核启动流程中设备树相关内容

上传人:jiups****uk12 文档编号:38309363 上传时间:2018-04-30 格式:PDF 页数:11 大小:177.14KB
返回 下载 相关 举报
Linux内核启动流程中设备树相关内容_第1页
第1页 / 共11页
Linux内核启动流程中设备树相关内容_第2页
第2页 / 共11页
Linux内核启动流程中设备树相关内容_第3页
第3页 / 共11页
Linux内核启动流程中设备树相关内容_第4页
第4页 / 共11页
Linux内核启动流程中设备树相关内容_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《Linux内核启动流程中设备树相关内容》由会员分享,可在线阅读,更多相关《Linux内核启动流程中设备树相关内容(11页珍藏版)》请在金锄头文库上搜索。

1、Linux 内核启动流程 -设备树的识别 曹忠明 ARM Linux 内核在 Linux-3.x 内核有了很大的变化,对一些新的平台的支持取消了传统的 设备文件而用设备树取代, 这里以 FS4412 设备树识别为例说明 Linux 是如何识别设备树的。 1、 设备树文件设备树文件 FS4412 设备树文件(exynos4412-fs4412.dts)部分内容: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 /* * Insignals Exynos4412 based Or

2、igen board device tree source * * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd. * http:/ * * Device tree source file for Insignals Origen board which is based on * Samsungs Exynos4412 SoC. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GN

3、U General Public License version 2 as * published by the Free Software Foundation. */ / dts - v1 /; #include “exynos4412.dtsi“ / model = “Insignal Origen evaluation board based on Exynos4412“; compatible = “insignal,origen4412“, “samsung,exynos4412“; memory reg = ; ; chosen bootargs = “root=/dev/nfs

4、 nfsroot=192.168.9.120:/source/rootfs init=/linuxrc console=ttySAC2,115200; firmware0203F000 compatible = “samsung,secure-firmware“; 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 reg = ; ; srom - cs15000000 compati

5、ble = “simple-bus“; #address-cells = ; #size-cells = ; reg = ; ranges; ethernet5000000 compatible = “davicom,dm9000“; reg = ; interrupt - parent = ; interrupts = ; davicom, no - eeprom; mac - address = 00 0a 2d a6 55 a2; ; ; regulators compatible = “simple-bus“; #address-cells = ; #size-cells = ; mm

6、c_reg: regulator0 compatible = “regulator-fixed“; reg = ; regulator - name = “VMEM_VDD_2.8V“; regulator - min - microvolt = ; regulator - max - microvolt = ; gpio = ; enable - active - high; ; ; g2d10800000 status = “okay“; ; sdhci12530000 76 77 78 79 80 81 82 83 bus - width = ; pinctrl - 0 = ; pinc

7、trl - names = “default“; vmmc - supply = ; status = “okay“; ; . ; 编译设备树文件,内核顶层目录下执行如下命令可以编译设备树文件: $ make dtbs 编译后生成文件为 exynos4412-fs4412.dtb,dtb 文件是使用大端字节序存储,显示其内 容如下: $ hexdump exynos4412-fs4412.dtb 内容如下: 0000000 0dd0 edfe 0000 a588 0000 3800 0000 0c82 0000010 0000 2800 0000 1100 0000 1000 0000 000

8、0 0000020 0000 9906 0000 d481 0000 0000 0000 0000 0000030 0000 0000 0000 0000 0000 0100 0000 0000 0000040 0000 0300 0000 0400 0000 0000 0000 0100 0000050 0000 0300 0000 0400 0000 0f00 0000 0100 0000060 0000 0300 0000 0400 0000 1b00 0000 0100 0000070 0000 0300 0000 2700 0000 2c00 6e69 6973 0000080 6e

9、67 6c61 6f2c 6972 6567 346e 3134 0032 0000090 6173 736d 6e75 2c67 7865 6e79 736f 3434 . 0008880 006e 6276 6361 2d6b 6f70 6372 0068 6676 0008890 6f72 746e 702d 726f 6863 7600 7973 636e 00088a0 6c2d 6e65 0000 00088a5 在 uboot 引导内核之前,会将设备树文件加载到内存中,以备 Linux 内核使用,这里就 不详细说明了 2、 Linux 内核启动内核启动 Linux 内核启动分几个

10、阶段: 1) Linux 内核自解压 2) Linux 内核初始化-汇编 3) Linux 内核初始化-C 这里从第三阶段开始说明,分析这个阶段,主要是查看函数 start_kernel,在start_kernel 中有几个函数这里重点分析: 2.1 setup_arch setup_arch( void _init setup_arch(char *cmdline_p) const struct machine_desc *mdesc; mdesc = setup_machine_fdt(_atags_pointer); if (!mdesc) mdesc = setup_machine_t

11、ags(_atags_pointer, _machine_arch_type); setup_machine_fdt: struct machine_desc *setup_machine_fdt(unsigned int dt_phys)函数是用来识别设备树, Linux 内核中是这样描述这个函数的: /* * Machine setup when an dtb was passed to the kernel,dt_phys * dt_phys: physical address of dt blob * * If a dtb was passed to the kernel in r2,

12、 then use it to choose the correct machine_desc * and to setup the system */ 也就是说 bootloader 如果将一个设备树文件加载到内存中,其通过 r2 寄存器将设备树 的物理地址传递到 Linux 内核中,Linux 内核来选择正确的机器且对其进行设置 setup_machine_tags: 这函数是在 Linux 内核不使用设备树的情况是使用,这里就不分析了。 setup_machine_fdt: cosnt struct machine_desc *_init setup_machine_fdt(unsign

13、ed int dt_phys) mdesc = of_flat_dt_match_machine(mdesc_best, arch_get_next_mach); if (!mdesc) dt_root = of_get_flat_dt_root(); prop = of_get_flat_dt_prop(dt_root, “compatible”, return mdesc; 函数中需要重点分析的函数有:of_flat_match_machine 和 of_get_flat_dt_root of_flat_match_machine: const void * _init of_flat_d

14、t_match_machine(const void *default_match const void * (*get_next_compat)(const char * const *) /* * 找到设备树中的根节点(开始结点) */ dt_root = of_get_flat_dt_root(); /* * get_next_compat = arch_get_next_mach * 内核中可以同时支持多个平台,这个函数用来获得下一个平台的 * dt_compat 属性,结合上边函数克制 data 内容 */ while(data = get_next_compat( if (scor

15、e 0 size -= strlen(prop) + 1; prop += strlen(prop) + 1; printk(“nn“); return NULL; 函数中会调用函数 of_get_flat_dt_root 和 get_next_compat,of_get_flat_dt_root 用来从 设备树文件中找到根节点, get_next_compat按照上下文这个函数等于arch_get_next_mach, 下边会重点分析这两个函数。 of_get_flat_dt_root: 补充补充:设备树相关宏和结构体设备树相关宏和结构体: 结点相关宏结点相关宏: OF_DT_HEADER 0xd00dfeed 标记 OF_DT_BEGIN_NODE 0x1 开始结点 OF_DT_END_NODE 0x2 结束结点 OF_DT_PROP 0x3 Property: name off, size, *content 资源 OF_DT_NOP 0x4 NOP OF_DT_END 0x9 结束 OF_DT_VERSION 0x10 版本 相关结构体: struct boot_param_header _be32 magic; / OF_DT_HEADER 幻数 _be32 tota

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号