当前位置:网站首页>Parse the bootargs from the device tree (dtb format data)
Parse the bootargs from the device tree (dtb format data)
2022-08-01 01:21:00 【The snail is taking off】
1、函数调用关系
start_kernel
setup_arch
setup_machine_fdt
early_init_dt_scan_nodes //Traverse device tree node,Analyze the important information for the kernel boot
of_scan_flat_dt //Analytical device tree node
early_init_dt_scan_chosen //用于解析chosen节点的函数
//函数调用
of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
(1)调用of_scan_flat_dt()函数遍历dtb的所有节点;
(2)Each node will callearly_init_dt_scan_chosen()函数进行解析,判断是不是chosen节点;
(3)如果是chosen节点,Just resolutionbootargsProperties and save toboot_command_line变量中;
2、dtb中bootargs的来源
(1)内核启动参数bootargsStored in the device treechosen节点的bootargs属性;
(2)bootargs数据可以是在dts源文件中定义,也可以是ubootStart the kernel passed to the kernel;
(3)优先级:uboot传递的bootargsParameter priority is higher thandts中定义的bootargs;
(4)如果是uboot传递的bootargs,In the kernel decompression stage is calledatags_to_fdt()函数将tag中的bootargs参数转换成dtb的格式,写进dtb数据中;
3、of_scan_flat_dt()函数
int __init of_scan_flat_dt(int (*it)(unsigned long node,const char *uname, int depth,
void *data), void *data)
{
//dtb数据的地址,Is the root node address
const void *blob = initial_boot_params;
const char *pathp;
int offset, rc = 0, depth = -1;
if (!blob)
return 0;
//从根节点遍历dtb中每个节点,返回的offsetIs each node address
for (offset = fdt_next_node(blob, -1, &depth);
offset >= 0 && depth >= 0 && !rc;
offset = fdt_next_node(blob, offset, &depth)) {
//Resolve the node name
pathp = fdt_get_name(blob, offset, NULL);
if (*pathp == '/')
pathp = kbasename(pathp);
//回调函数:解析节点
rc = it(offset, pathp, depth, data);
}
return rc;
}
(1)The device tree ordtb格式的二进制数据,从dtbParsing nodes and attributes in a format offer proprietary function,Specific how to parse out the don't care;
(2)blob:dtbThe data start address,Is also the address of the root node;
(3)offset:Said the address of the node relative to the root node of the offset,Lies the node data address;
(4)depth:On behalf of the depth of the node relative to the root node,Such as the depth of the root node is0,/chosen节点是1;
(5)it:Is passed in the device tree node of analytic function,What need to parse the message is passed to the corresponding node analytical function;
early_init_dt_scan_chosen()函数
int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
int depth, void *data)
{
int l;
const char *p;
pr_debug("search \"chosen\", depth: %d, uname: %s\n", depth, uname);
//The depth of the node for1,Data does not makeNULL,At the same time, the node name is"chosen"或者 "[email protected]"
if (depth != 1 || !data ||
(strcmp(uname, "chosen") != 0 && strcmp(uname, "[email protected]") != 0))
return 0;
//解析initrd相关
early_init_dt_check_for_initrd(node);
/* 从chosenNode of parsing outbootargs属性 */
p = of_get_flat_dt_prop(node, "bootargs", &l);
if (p != NULL && l > 0)
strlcpy(data, p, min((int)l, COMMAND_LINE_SIZE)); //将bootargs拷贝到data中
//The following code is fromchosenParsing of nodes are less thanbootargs,采用默认的bootargs
#ifdef CONFIG_CMDLINE
#if defined(CONFIG_CMDLINE_EXTEND)
strlcat(data, " ", COMMAND_LINE_SIZE);
strlcat(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
#elif defined(CONFIG_CMDLINE_FORCE)
strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
#else
/* No arguments from boot loader, use kernel's cmdl*/
if (!((char *)data)[0])
strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
#endif
#endif /* CONFIG_CMDLINE */
pr_debug("Command line is: %s\n", (char*)data);
/* break now */
return 1;
}
(1)Figure out whether incoming nodechosen节点,If is the parse outbootargs,并保存到data中(也就是boot_command_line);
(2)如果找不到chosen节点,或者chosen节点的bootargs属性是空,则使用默认的CONFIG_CMDLINE;
边栏推荐
- 数据中台建设(七):数据资产管理
- IDEA 找不到或无法加载主类 或 Module “*“ must not contain source root “*“ The root already belongs to module “*“
- 蓝图:杨辉三角排列
- JQESAP系统里的胖接口Fat interface
- 元宇宙改变人类工作模式的四种方式
- How is the tree structure of the device tree reflected?
- Blueprint: Yang Hui's Triangular Arrangement
- 彻底关闭Chrome浏览器更新及右上角的更新提示
- 现代企业架构框架1
- leetcode: 1648. Color ball with decreasing sales value [Boundary find by two points]
猜你喜欢

元宇宙改变人类工作模式的四种方式

Introduction to machine learning how to?

WeChat applet page syntax
![leetcode: 1562. Find latest grouping of size M [simulation + endpoint record + range merge]](/img/72/f52b5d3dcdb271f096c3e5108f0042.png)
leetcode: 1562. Find latest grouping of size M [simulation + endpoint record + range merge]

RTL8762DK UART (two)

STK8321 I2C (Shengjia-accelerometer) example

IDEA debugging

Key Points Estimation and Point Instance

RTL8762DK WDG(六)
![leetcode: 1648. Color ball with decreasing sales value [Boundary find by two points]](/img/b9/7bd33bd981ace25e3bbfc7be9117ff.png)
leetcode: 1648. Color ball with decreasing sales value [Boundary find by two points]
随机推荐
LeetCode每日一练 —— 环形链表问题(面试四连问)
Solve the problem that when IDEA creates a new file by default, right-click, new, there is no XML file
Basic implementation of vector
Application of integrated stepper motor in UAV automatic airport
The kernel of the decompression process steps
MYSQL two-phase commit
Introduction to machine learning how to?
Basic usage concepts of vim
Web3.0: Building an NFT Market (1)
C字符串数组反转
Rasa 3.x Learning Series - Using Lookup Tables to Improve Entity Extraction
device node结构体转换成platform_device结构体
MYSQL Index Analysis
软考高级系统架构设计师系列之:信息系统基础知识
WAASAP WebClient UI页面标签的决定逻辑介绍
北京突然宣布,元宇宙重大消息
MYSQL查询截取优化分析
Inheritance and friend, static member relationship
RTL8762DK UART (two)
July Bootcamp (Day 31) - Status Compression