[toc]
U-Boot 启动流程
lds链接脚本
- 从链接脚本中定义了ENTRY(_start),即开始入口为_start
_start函数
- arch/arm/lib/vectors_m.S 编译的时候设置中断向量表
- 顺序执行下去,执行了reset函数
reset函数
- arch/arm/cpu/armv7m/start.S 定义了reset函数,跳转到_main
_main函数
- arch/arm/lib/crt0.S 定义了_main函数
初始化堆栈指针sp为CONFIG_SYS_INIT_SP_ADDR
1 | /* 设置初始 C 运行环境并调用 board_init_f(0)*/ |
board_init_f_alloc_reserve 板级初始化第一次分配保留空间
- 保留gd_t结构体大小的空间
1 | // top:栈顶地址,即堆栈指针地址sp传入 |
board_init_f_init_reserve 板级初始化第一次始化保留
- 将传入的地址清零,并初始化全局数据结构;并设置malloc_base为base
1 | void board_init_f_init_reserve(ulong base) |
board_init_f 执行一系列的初始化函数
- 调用板级初始化,执行一系列的初始化函数;初始化失败则死循环
init_sequence_f 板级初始化调用列表
1 | static const init_fnc_t init_sequence_f[] = { |
relocate_code 重新定位代码
- relocate_code 函数,用于重新定位代码
- 在 U-Boot 启动过程中,重定位是一个关键步骤,它将 U-Boot 从加载地址移动到运行地址,并修正所有相关的地址引用。
relocate_vectors 重新定位向量表
c_runtime_cpu_setup 设置最终 (完整) 环境
board_init_r 板级初始化重定向后的板级初始化
init_sequence_r 板级初始化调用列表
1 | static init_fnc_t init_sequence_r[] = { |
run_main_loop 运行主循环
cli_init 命令行初始化
bootdelay_process 获取启动延迟
- 获取
bootdelay
的值,如果没有配置,则使用CONFIG_BOOTDELAY
的值 - 一般为3秒
cli_process_fdt 从fdt中获取命令行
- 获取
bootcmd
和bootsecure
参数 - configs/stm32h750-art-pi_defconfig
1
CONFIG_BOOTCOMMAND="bootm 90080000"
- include/env_default.h
1
2
3
"bootcmd=" CONFIG_BOOTCOMMAND "\0" - 这里获取到的
bootcmd
为bootm 90080000
autoboot_command 处理自动启动命令
没有自动启动命令或者执行按键中断,则进入命令行循环
cli_loop 命令行循环
否则执行自动启动命令
run_command_list 将自启动命令解析并执行
- 解析
bootcmd
命令,并执行
do_bootm 执行bootm命令
bootm_run_states 执行bootm命令
- bootm_find_os
- bootm_find_other
- bootm_disable_interrupts
- bootm_load_os
bootm_find_os 找到操作系统
boot_get_kernel 获取内核镜像头、起始地址和长度
- 解析 FIT 说明符,获取内核地址
1 | static int boot_get_kernel(const char *addr_fit, struct bootm_headers *images, |
genimg_get_format 获取镜像格式
1 | static int bootm_find_os(const char *cmd_name, const char *addr_fit) |
fit_image_load 加载 FIT 镜像
1 | IH_TYPE_KERNEL, /* OS Kernel Image */ |
fit_conf_get_node 获取 FIT 配置节点
- 查找/configurations节点中的配置节点,默认为default的配置
fit_image_select 打印 FIT 镜像信息
bootm_find_other 找到其他镜像 ramdisk、fdt
- 从镜像或者命令行中查找 ramdisk 和 fdt
bootm_disable_interrupts 禁用中断
bootm_load_os 加载操作系统
image_decomp 从镜像中解压
boot_ramdisk_high 加载 ramdisk 到顶部地址
do_bootm_linux 执行bootm命令 linux
boot_prep_linux 执行linux启动前的准备工作
image_setup_linux 从镜像中设置linux
- 设置FDT内存保留区域 boot_fdt_add_mem_rsv_regions
- 将FDT从内核镜像中拷贝到指定地址 boot_relocate_fdt
- 将FDT转换为动态设备树 image_setup_libfdt
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 wdfk-prog的个人博客!
评论