当前位置:网站首页>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;
边栏推荐
- 【历史上的今天】7 月 31 日:“缸中之脑”的提出者诞生;Wi-Fi 之父出生;USB 3.1 标准发布
- Exam preparation plan
- 如何编辑epub电子书的目录
- RTL8762DK UART (two)
- VPGNet
- Solve the problem that when IDEA creates a new file by default, right-click, new, there is no XML file
- MYSQL二阶段提交
- Nmap Operation Manual - Full Version
- You need to know the TCP wave four times
- MYSQL Classic Interview Questions
猜你喜欢

Flink 部署和提交job

MYSQL Index Analysis

IDEA无法识别module(module右下角没有蓝色小方块)
![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]

两院院士直言:不要迷信院士

现代企业架构框架1

欧拉系统(euleros):升级Mysql

Google "Cloud Developer Quick Checklist"; Tsinghua 3D Human Body Dataset; SenseTime "Universal Vision Framework" open class; Web3 Minimalist Getting Started Guide; Free Books for Efficient Deep Learni

JVM面试题总结(持续更新中)

MYSQL master-slave replication
随机推荐
Exam preparation plan
MYSQL master-slave replication
cmake入门学习笔记
数据中台建设(七):数据资产管理
Chinese version of Pylint inspection rules
STK8321 I2C(昇佳-加速度传感器)示例
Js replication
Summary of MVCC
Completely closed Chrome updated and in the top right corner of the tip
sqlserver cannot connect remotely
MYSQL-Batch insert data
Introduction to the decision logic of WAASAP WebClient UI page labels
从设备树(dtb格式数据)中解析出bootargs
Inheritance and friend, static member relationship
Google Earth Engine - Error resolution of Error: Image.clipToBoundsAndScale, argument 'input': Invalid type
Game Security 03: A Simple Explanation of Buffer Overflow Attacks
WeChat applet page syntax
VPGNet
Four ways the Metaverse is changing the way humans work
JQESAP系统里的胖接口Fat interface