当前位置:网站首页>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默认情况下新建文件时,右击,new,没有XML文件的问题
- OSF understands the agile development model in one minute
- VPGNet
- MYSQL Keyword Explain Analysis
- /usr/sbin/vmware-authdlauncher: error while loading shared libraries: libssl.so.1.0.2*解决办法
- Data Middle Office Construction (VII): Data Asset Management
- By Value or By Reference
- Basic usage concepts of vim
- RTL8762DK UART(二)
- You need to know the TCP wave four times
猜你喜欢
[Data analysis] Based on matlab GUI student achievement management system [including Matlab source code 1981]
Euler system (euleros): upgrade Mysql
Daily practice of LeetCode - Circular linked list question (interview four consecutive questions)
YOLO怎么入门?怎么实现自己的训练集?
IDEA debugging
你需要知道的 TCP 四次挥手
Completely closed Chrome updated and in the top right corner of the tip
Four ways the Metaverse is changing the way humans work
北京突然宣布,元宇宙重大消息
MYSQL master-slave replication
随机推荐
Item 36: Specify std::launch::async if asynchronicity is essential.
Daily practice of LeetCode - Circular linked list question (interview four consecutive questions)
设计消息队列存储消息数据的MySQL表格
RTL8762DK 使用DebugAnalyzer(四)
欧拉系统(euleros):升级Mysql
MYSQL关键字Explain解析
Cmake introductory study notes
Game Security 03: A Simple Explanation of Buffer Overflow Attacks
【密码学/密码分析】基于TMTO的密码分析方法
RTL8762DK RTC(五)
/usr/sbin/vmware-authdlauncher: error while loading shared libraries: libssl.so.1.0.2*Solution
The kernel of the decompression process steps
Fat interface in JQESAP system
MYSQL query interception optimization analysis
OSF understands the agile development model in one minute
cmake入门学习笔记
你需要知道的 TCP 四次挥手
Unity3D study notes 10 - texture array
Academicians of the two academies speak bluntly: Don't be superstitious about academicians
MVCC总结