当前位置:网站首页>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;
边栏推荐
- Chain programming, packages, access
- Basic implementation of vector
- MYSQL主从复制
- RTL8762DK uses DebugAnalyzer (four)
- SC7A20 (Silan Micro-Accelerometer) Example
- 【历史上的今天】7 月 31 日:“缸中之脑”的提出者诞生;Wi-Fi 之父出生;USB 3.1 标准发布
- Soft Exam Senior System Architect Series: Basic Knowledge of System Development
- Modern Enterprise Architecture Framework 1
- ROS2系列知识(4): 理解【服务】的概念
- 设备树——dtb格式到struct device node结构体的转换
猜你喜欢

【密码学/密码分析】基于TMTO的密码分析方法

彻底关闭Chrome浏览器更新及右上角的更新提示

RTL8762DK RTC(五)

Google engineer fired for claiming AI awareness: breach of nondisclosure agreement

ROS2系列知识(4): 理解【服务】的概念

IDEA 找不到或无法加载主类 或 Module “*“ must not contain source root “*“ The root already belongs to module “*“

The IDEA can't find or unable to load The main class or Module "*" must not contain The source root "*" The root already belongs to The Module "*"

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

MVCC总结

Completely closed Chrome updated and in the top right corner of the tip
随机推荐
YOLO怎么入门?怎么实现自己的训练集?
sqlserver无法远程连接
RTL8762DK Lighting/LED (3)
高维高斯分布基础
cmake入门学习笔记
Flink 部署和提交job
WeChat applet page syntax
High dimensional Gaussian distribution basics
从零造键盘的键盘超级喜欢,IT人最爱
ECCV2022 Workshop | Multi-Object Tracking and Segmentation in Complex Environments
机器学习初学者可以学哪些实战项目?
LeetCode每日一练 —— 环形链表问题(面试四连问)
IDEA无法识别module(module右下角没有蓝色小方块)
/usr/sbin/vmware-authdlauncher: error while loading shared libraries: libssl.so.1.0.2*解决办法
Handwritten binary search tree and test
OSD读取SAP CRM One Order应用日志的优化方式
Design the message queue storage MySQL form of message data
Blueprint: Yang Hui's Triangular Arrangement
leetcode: 1648. Color ball with decreasing sales value [Boundary find by two points]
RTL8762DK UART (two)