当前位置:网站首页>U-Boot初始化及工作流程分析
U-Boot初始化及工作流程分析
2022-07-05 06:43:00 【Linux与SoC】
0. 概述
U-Boot通常是从架构相关的汇编文件(尾缀为大写S的汇编文件意为可链接)中获取第一条执行的指令,例如:
- arch/arm/cpu/armv7/start.S
- arch/powerpc/cpu/mpc83xx/start.S
- arch/mips/cpu/start.S
在以上所列出的汇编文件中,主要执行如下三个函数:
lowlevel_init()
board_init_f()
board_init_r()
完整的执行流程如下图所示:

1. lowlevel_init()
不同架构类型的处理器会单独定义lowlevel_init.S文件,例如:
./arch/arm/cpu/armv7/lowlevel_init.S
./arch/arm/cpu/armv8/lowlevel_init.S
./arch/mips/mach-ath79/ar933x/lowlevel_init.S
该函数的基本功能是使得CPU可以获取、执行到board_init_f()函数。在此函数中没有栈信息,不能设置SDRAM和控制台。
.pushsection .text.lowlevel_init, "ax"
WEAK(lowlevel_init)
#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_STACK)
ldr sp, =CONFIG_SPL_STACK
#else
ldr sp, =CONFIG_SYS_INIT_SP_ADDR
#endif
bic sp, sp, #7 /* 8-byte alignment for ABI compliance */
#ifdef CONFIG_SPL_DM
mov r9, #0
#else
#ifdef CONFIG_SPL_BUILD
ldr r9, =gdata
#else
sub sp, sp, #GD_SIZE
bic sp, sp, #7
mov r9, sp
#endif
#endif
push {ip, lr}
bl s_init
pop {ip, pc}
ENDPROC(lowlevel_init)
.popsection
2. board_init_f()
为执行board_init_r做准备,需要初始化两个关键功能:SDRAM和串口。
在此阶段,global_data已经可以使用,栈信息位于SRAM中。由于BSS段仍然无法使用,因此,不可以使用全局/静态变量。
若U-Boot中开启了SPL功能,则在common/spl.c代码中可以实现该函数,否则,通常以common/board_f.c中实现为准。
board_init_f()中调用的函数在数组init_sequence_f[]中定义:
static const init_fnc_t init_sequence_f[] = {
setup_mon_len,
......
env_init, /* initialize environment */
init_baud_rate, /* initialze baudrate settings */
serial_init, /* serial communications setup */
console_init_f, /* stage 1 init of console */
display_options, /* say that we are here */
display_text_info, /* show debugging info if required */
checkcpu,
#if defined(CONFIG_SYSRESET)
print_resetinfo,
#endif
#if defined(CONFIG_DISPLAY_CPUINFO)
print_cpuinfo, /* display cpu info (and speed) */
#endif
#if defined(CONFIG_DTB_RESELECT)
embedded_dtb_select,
#endif
#if defined(CONFIG_DISPLAY_BOARDINFO)
show_board_info,
#endif
INIT_FUNC_WATCHDOG_INIT
#if defined(CONFIG_MISC_INIT_F)
misc_init_f,
#endif
INIT_FUNC_WATCHDOG_RESET
#if defined(CONFIG_SYS_I2C)
init_func_i2c,
#endif
#if defined(CONFIG_VID) && !defined(CONFIG_SPL)
init_func_vid,
#endif
announce_dram_init,
dram_init, /* configure available RAM banks */
#ifdef CONFIG_POST
post_init_f,
#endif
......
#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \ !CONFIG_IS_ENABLED(X86_64)
jump_to_copy,
#endif
NULL,
};
3. board_init_r()
U-Boot执行到此处,已经进入到正常的功能代码调用流程,例如设备驱动、命令行、镜像搬移加载等功能。
若U-Boot中开启了SPL功能,则在common/spl.c代码中可以实现该函数,否则,通常以common/board_r.c中实现为准。
board_init_r()中调用的函数在数组init_sequence_r[]中定义:
static init_fnc_t init_sequence_r[] = {
initr_trace,
initr_reloc,
......
#ifdef CONFIG_MMC
initr_mmc,
#endif
......
run_main_loop,
};
以上所有的功能相关的初始化中,CPU相关的初始化代码通常位于如下路径:
[email protected]$ ls arch/arm/
config.mk lib mach-davinci mach-keystone mach-orion5x mach-snapdragon mach-tegra mach-zynqmp-r5
cpu mach-aspeed mach-exynos mach-kirkwood mach-owl mach-socfpga mach-uniphier Makefile
dts mach-at91 mach-highbank mach-mediatek ......
[email protected]$
板级相关的初始化代码通常位于如下路径:
[email protected]$ ls board/
abilis bluewater corscience ge lg qca sifive toradex
advantech bosch creative geekbuying l+g qemu-mips silica tplink
alliedtelesis boundary cssi google liebherr qualcomm sks-kinkel tqc
altera broadcom CZ.NIC grinn logicpd quipos socrates ucRobotics
......
边栏推荐
猜你喜欢
![[MySQL 8.0 does not support capitalization of table names - corresponding scheme]](/img/ea/a1e0722c43f56aff3e79f95c99ba8a.png)
[MySQL 8.0 does not support capitalization of table names - corresponding scheme]

【软件测试】04 -- 软件测试与软件开发

PHY驱动调试之 --- MDIO/MDC接口22号和45号条款(一)

Page type

Utf8 encoding

Use the Paping tool to detect TCP port connectivity

Vant weapp swippecell set multiple buttons
![[algorithm post interview] interview questions of a small factory](/img/62/6e330b1eba38f2dc67b21a10f0e2a8.jpg)
[algorithm post interview] interview questions of a small factory

Volcano resource reservation feature

【MySQL8.0不支持表名大写-对应方案】
随机推荐
Lexin interview process
Volcano resource reservation feature
Genesis builds a new generation of credit system
Rehabilitation type force deduction brush question notes D2
Database mysql all
Vant Weapp SwipeCell设置多个按钮
.net core踩坑实践
【软件测试】06 -- 软件测试的基本流程
Spinningup drawing curve
7. Oracle table structure
ROS2——topic话题(八)
In C language, int a= 'R'
Redis-02. Redis command
Preemption of CFS scheduling
Markdown syntax
Vscode creates its own code template
Qt项目中的日志库log4qt使用
PR automatically moves forward after deleting clips
[Chongqing Guangdong education] 1185t administrative leadership reference test of National Open University in autumn 2018
PHY驱动调试之 --- PHY控制器驱动(二)