当前位置:网站首页>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
......
边栏推荐
- The difference between new and malloc
- 使用paping工具进行tcp端口连通性检测
- Integer to 8-bit binary explanation (including positive and negative numbers) scope of application -127~+127
- 并发编程 — 死锁排查及处理
- 基于FPGA的一维卷积神经网络CNN的实现(八)激活层实现
- Some classic recursion problems
- Vant Weapp SwipeCell设置多个按钮
- Getting started with typescript
- 2022 winter vacation training game 5
- 微信小程序路由再次跳转不触发onload
猜你喜欢
Vscode configures the typera editor for MD
Dameng database all
ROS2——常用命令行(四)
MPLS experiment
Financial risk control practice -- feature derivation based on time series
Some classic recursion problems
Ros2 - ros2 vs. ros1 (II)
Sum of two numbers, the numbers in the array are converted to decimal, added, and output inversely
Vant Weapp SwipeCell設置多個按鈕
Vscode creates its own code template
随机推荐
Special training of C language array
SolidWorks template and design library are convenient for designers to call
【软件测试】03 -- 软件测试概述
Log4qt usage of logbase in QT project
ROS2——初识ROS2(一)
你心目中的数据分析 Top 1 选 Pandas 还是选 SQL?
LSA Type Explanation - lsa-5 (type 5 LSA - autonomous system external LSA) and lsa-4 (type 4 LSA - ASBR summary LSA) explanation
The differences and connections among cookies, sessions, JWT, and tokens
Skywalking all
[MySQL 8.0 does not support capitalization of table names - corresponding scheme]
Volcano 资源预留特性
Adg5412fbruz-rl7 applies dual power analog switch and multiplexer IC
kata container
Xavier CPU & GPU 高负载功耗测试
[Chongqing Guangdong education] 1185t administrative leadership reference test of National Open University in autumn 2018
What is linting
ROS2——工作空间(五)
6-2 sequence table operation set
Configuration method and configuration file of SolidWorks GB profile library
【软件测试】04 -- 软件测试与软件开发