当前位置:网站首页>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;
边栏推荐
- Four ways the Metaverse is changing the way humans work
- leetcode:1648. 销售价值减少的颜色球【二分找边界】
- Web3.0: Building an NFT Market (1)
- Cmake introductory study notes
- RTL8762DK UART (two)
- Google engineer fired for claiming AI awareness: breach of nondisclosure agreement
- sqlserver cannot connect remotely
- RTL8762DK RTC(五)
- OSF understands the agile development model in one minute
- IDEA调试
猜你喜欢

ECCV2022 Workshop | 复杂环境中的多目标跟踪和分割

Application of integrated stepper motor in UAV automatic airport

Four ways the Metaverse is changing the way humans work

MYSQL经典面试题

VPGNet

MYSQL Keyword Explain Analysis

Flink 部署和提交job

【 】 today in history: on July 31, "brains in vats" the birth of the participant;The father of wi-fi was born;USB 3.1 standard

【数据分析】基于matlab GUI学生成绩管理系统【含Matlab源码 1981期】

【Cryptography/Cryptanalysis】Cryptanalysis method based on TMTO
随机推荐
Exam preparation plan
VPGNet
你需要知道的 TCP 四次挥手
WAASAP WebClient UI页面标签的决定逻辑介绍
Soft Exam Senior System Architect Series: Basic Knowledge of System Development
从零造键盘的键盘超级喜欢,IT人最爱
js 实现复制功能
北京突然宣布,元宇宙重大消息
RTL8762DK 点灯/LED(三)
How is the tree structure of the device tree reflected?
What is the meaning of JS timestamp?Know SQL will consider to add a timestamp, JS timestamp for the scene?
欧拉系统(euleros):升级Mysql
Rasa 3.x 学习系列- Rasa - Issues 4898 学习笔记
date command
Rasa 3.x 学习系列- Rasa - Issues 4918 学习笔记
WebApi 打个Attribute 统一处理异常
cmake入门学习笔记
设备树——dtb格式到struct device node结构体的转换
【Cryptography/Cryptanalysis】Cryptanalysis method based on TMTO
彻底关闭Chrome浏览器更新及右上角的更新提示