u-boot在匯編啟動階段對系統(tǒng)的一些初始化
當(dāng)cpu交由u-boot接管進(jìn)入u-boot后, 首先會到_start符號處開始執(zhí)行初始化, 并在此期間完成一些必要的系統(tǒng)寄存器相關(guān)的初始化,包括保存boot參數(shù), 進(jìn)行地址無關(guān)fixed,系統(tǒng)寄存器復(fù)位,底層平臺相關(guān)初始化等 ,啟動代碼位于arch/arm/cpu/armv8/start.S,入口地址為_start。
啟動前為后續(xù)流程做的一些平臺相關(guān)操作
從_start開始,u-boot會根據(jù)board定義做一些平臺化相關(guān)的初始化工作或者是保存一些重要寄存器信息,代碼如下:
/*************************************************************************
*
* Startup Code (reset vector)
*
*************************************************************************/
.globl _start
_start: ------------------------------------------------------------------------ (1)
#if defined(CONFIG_LINUX_KERNEL_IMAGE_HEADER) ---------------------------------- (2)
#include < asm/boot0-linux-kernel-header.h >
#elif defined(CONFIG_ENABLE_ARM_SOC_BOOT0_HOOK) -------------------------------- (3)
/*
* Various SoCs need something special and SoC-specific up front in
* order to boot, allow them to set that in their boot0.h file and then
* use it here.
*/
#include < asm/arch/boot0.h >
#else
b reset ----------------------------------------------------------------- (4)
#endif
.align 3
.globl _TEXT_BASE ------------------------------------------------------------ (5)
_TEXT_BASE:
.quad CONFIG_SYS_TEXT_BASE
/*
* These are defined in the linker script.
*/
.globl _end_ofs -------------------------------------------------------------- (5)
_end_ofs:
.quad _end - _start
.globl _bss_start_ofs
_bss_start_ofs:
.quad __bss_start - _start
.globl _bss_end_ofs
_bss_end_ofs:
.quad __bss_end - _start
reset:
/* Allow the board to save important registers */
b save_boot_params ----------------------------------------------------- (6)
.globl save_boot_params_ret
save_boot_params_ret:
... /* 此處省略無關(guān)代碼,待分析到時再展開代碼 */
...
WEAK(save_boot_params)
b save_boot_params_ret /* back to my caller */
ENDPROC(save_boot_params)
#endif
- ? (1)_start段標(biāo)記為全局可見并在鏈接腳本中被聲明為入口地址,表示u-boot的入口地址為_start;
- ? (2)首先進(jìn)入入口后有兩種可配置情況,一種就是定義了LINUX_KERNEL_IMAGE_HEADER,boot0-linux-kernel-header.h展開部分后如下:
.macro le64sym, sym
.long sym()_lo32
.long sym()_hi32
.endm
.globl _start
_start:
/*
* DO NOT MODIFY. Image header expected by Linux boot-loaders.
*/
b reset /* branch to kernel start, magic */
.long 0 /* reserved */
le64sym _kernel_offset_le /* Image load offset from start of RAM, little-endian */
le64sym _kernel_size_le /* Effective size of kernel image, little-endian */
le64sym _kernel_flags_le /* Informative flags, little-endian */
.quad 0 /* reserved */
.quad 0 /* reserved */
.quad 0 /* reserved */
.ascii "ARMx64" /* Magic number */
.long 0 /* reserved */
此處將與在鏈接腳本中定義的LINUX_KERNEL_IMAGE_HEADER對應(yīng)起來,為u-boot頭部添加一個類似與Linux arm64 的Image頭部,首先是起始8字節(jié), 如果沒有定義efi相關(guān)的功能則是一個跳轉(zhuǎn)指令,跳轉(zhuǎn)到reset段繼續(xù)執(zhí)行啟動流程 ,其他如鏈接腳本中解釋一致;
- ? (3)第二種可能的配置,就是定義了ENABLE_ARM_SOC_BOOT0_HOOK配置,此處的頭文件根據(jù)不同board會引用到不同頭文件,如瑞芯微的最終會引用到如下部分代碼頭文件:
#ifdef CONFIG_SPL_BUILD
/*
* We need to add 4 bytes of space for the 'RK33' at the
* beginning of the executable. However, as we want to keep
* this generic and make it applicable to builds that are like
* the RK3368 (TPL needs this, SPL doesn't) or the RK3399 (no
* TPL, but extra space needed in the SPL), we simply insert
* a branch-to-next-instruction-word with the expectation that
* the first one may be overwritten, if this is the first stage
* contained in the final image created with mkimage)...
*/
b 1f /* if overwritten, entry-address is at the next word */
1:
#endif
#if CONFIG_IS_ENABLED(ROCKCHIP_EARLYRETURN_TO_BROM)
adr r3, entry_counter
ldr r0, [r3]
cmp r0, #1 /* check if entry_counter == 1 */
beq reset /* regular bootup */
add r0, #1
str r0, [r3] /* increment the entry_counter in memory */
mov r0, #0 /* return 0 to the BROM to signal 'OK' */
bx lr /* return control to the BROM */
entry_counter:
.word 0
#endif
#if (defined(CONFIG_SPL_BUILD) || defined(CONFIG_ARM64))
/* U-Boot proper of armv7 do not need this */
b reset
#endif
#if !defined(CONFIG_ARM64)
/*
* For armv7, the addr '_start' will used as vector start address
* and write to VBAR register, which needs to aligned to 0x20.
*/
.align(5), 0x0
_start:
ARM_VECTORS
#endif
#if !defined(CONFIG_TPL_BUILD) && defined(CONFIG_SPL_BUILD) &&
(CONFIG_ROCKCHIP_SPL_RESERVE_IRAM > 0)
.space CONFIG_ROCKCHIP_SPL_RESERVE_IRAM /* space for the ATF data */
#endif
因為有些設(shè)備boot到u-boot之前已經(jīng)有安全固件了,
所以此時控制權(quán)交給u-boot時,其實是可能有一些傳遞參數(shù)信息的要求,比如這里瑞芯微芯片通過bootrom boot到tpl后,
后續(xù)在完成tpl初始化后會將控制權(quán)再交還給bootrom固件,由bootrom固件繼續(xù)加載spl,
所以這里在進(jìn)行u-boot流程之前保存了bootrom的返回地址,以便后續(xù)瑞芯微板級軟件使用。
定義有可能也是arm32的模式,所以還可能在入口地址處保存異常向量表;
- ? (4)如果對應(yīng)board沒有上述兩種需求,那么_start段則是一條最簡單的跳轉(zhuǎn)指令b reset跳轉(zhuǎn)到reset處繼續(xù)啟動流程初始化;
- ? (5)在_start到reset之間,有一個.align 3用于8字節(jié)對齊,因為可能在讀取常量地址之前各自平臺做了自己代碼邏輯導(dǎo)致當(dāng)前地址并不是8字節(jié)對齊的, 這里不管是否對齊都強制對齊了一下,之后還保存了一些常量信息,其中包括_TEXT_BASE保存了鏈接地址,用于在啟動地址無關(guān)功能時進(jìn)行對運行時地址的偏移計算,其他幾個偏移值目前未使用;
- ? (6)save_boot_params用于保存一些board相關(guān)的重要寄存器,此處定義為了一個弱函數(shù),為直接跳轉(zhuǎn)回save_boot_params_ret繼續(xù)往下執(zhí)行,如果某些board需要保存寄存器參數(shù)則可以在自己的lowlevel.S文件中實現(xiàn)此函數(shù)。 一般由atf,bl2或者rom跳轉(zhuǎn)到spl或u-boot時廠商可能需要在兩個固件之間傳遞參數(shù),比如由bl2在寄存器x0,x1,x2中分別存入了一些固件的地址信息,那么u-boot則可以在早期通過此函數(shù)保存這些信息,并在后續(xù)某個時機中使用。
-
ARM
+關(guān)注
關(guān)注
134文章
9165瀏覽量
369176 -
匯編
+關(guān)注
關(guān)注
2文章
214瀏覽量
26005 -
Uboot
+關(guān)注
關(guān)注
4文章
125瀏覽量
28348
發(fā)布評論請先 登錄
相關(guān)推薦
評論