Linux设备树的传递以及kernel中对设备树的解析
转自:51CTO技术栈 - 云昭
#设备树的传递
/* Subcommand: GO */
static void boot_jump_linux(bootm_headers_t *images, int flag)
{
...
debug("## Transferring control to Linux (at address %08lx)" \
"...\n", (ulong) kernel_entry);
bootstage_mark(BOOTSTAGE_ID_RUN_OS);
announce_and_cleanup(fake);
if (IMAGE_ENABLE_OF_LIBFDT && images->ft_len)
r2 = (unsigned long)images->ft_addr;
else
r2 = gd->bd->bi_boot_params;
...
}
##bootm_header_t方式
/*
* Legacy and FIT format headers used by do_bootm() and do_bootm_<os>()
* routines.
*/
typedef struct bootm_headers {
...
char *ft_addr; /* flat dev tree address */
ulong ft_len; /* length of flat device tree */
...
} bootm_headers_t;
do_bootz(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
-bootz_start()
--bootm_find_images(int flag, int argc, char *const argv[], ulong start,ulong size)
---boot_get_fdt(flag, argc, argv, IH_ARCH_DEFAULT, &images,&images.ft_addr, &images.ft_len);
u-boot-v2021.04/common/image-fdt.c
##gd->bd->bi_boot_params方式
#kernel对设备树的解析
##第一阶段
Booting Linux on physical CPU 0x0
Linux version 5.4.124 (qemu@qemu) (gcc version 6.5.0 (Linaro GCC 6.5-2018.12)) #3 SMP Fri Jun 25 15:26:02 CST 2021
CPU: ARMv7 Processor [410fc090] revision 0 (ARMv7), cr=10c5387d
CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
OF: fdt: Machine model: V2P-CA9
// SPDX-License-Identifier: GPL-2.0
/*
* ARM Ltd. Versatile Express
*
* CoreTile Express A9x4
* Cortex-A9 MPCore (V2P-CA9)
*
* HBI-0191B
*/
/dts-v1/;
#include "vexpress-v2m.dtsi"
/ {
model = "V2P-CA9";
...
}
setup_arch(char **cmdline_p) arch/arm/kernel/setup.c
atags_vaddr = FDT_VIRT_BASE(__atags_pointer);
setup_machine_fdt(void *dt_virt) arch/arm/kernel/devtree.c
early_init_dt_verify()
of_flat_dt_match_machine() drivers/of/fdt.c
early_init_dt_scan_nodes();
__machine_arch_type = mdesc->nr;
head-common.S
.align 2
.type __mmap_switched_data, %object
__mmap_switched_data:
#ifdef CONFIG_XIP_KERNEL
#ifndef CONFIG_XIP_DEFLATED_DATA
.long _sdata @ r0
.long __data_loc @ r1
.long _edata_loc @ r2
#endif
.long __bss_stop @ sp (temporary stack in .bss)
#endif
.long __bss_start @ r0
.long __bss_stop @ r1
.long init_thread_union + THREAD_START_SP @ sp
.long processor_id @ r0
.long __machine_arch_type @ r1
.long __atags_pointer @ r2
A 对dtb文件进行crc32校验,检测设备树文件是否合法early_init_dt_verify()
B early_init_dt_scan_nodes()
/* Retrieve various information from the /chosen node */
of_scan_flat_dt(early_init_dt_scan_chosen, boot_command_line);
/* Initialize {size,address}-cells info */
of_scan_flat_dt(early_init_dt_scan_root, NULL);
/* Setup memory, calling early_init_dt_add_memory_arch */
of_scan_flat_dt(early_init_dt_scan_memory, NULL);
C 更新__machine_arch_type
D 更新chosen
##第二阶段
unflatten_device_tree();
*__unflatten_device_tree()
/* First pass, scan for size */
size = unflatten_dt_nodes(blob, NULL, dad, NULL);
/* Second pass, do actual unflattening */
unflatten_dt_nodes(blob, mem, dad, mynodes);
unflatten_dt_nodes()
populate_node()
最近很多小伙伴找我要一些程序员必备资料,于是我翻出了压箱底的宝藏,免费分享给大家!
扫描海报二维码免费获取。
评论