当前位置:网站首页>U-boot initialization and workflow analysis

U-boot initialization and workflow analysis

2022-07-05 07:02:00 Linux and SOC

0. summary

U-Boot Usually from the architecture related assembly file ( Suffixed with capital S Assembly file of means linkable ) Get the first executed instruction in , for example :

- arch/arm/cpu/armv7/start.S
- arch/powerpc/cpu/mpc83xx/start.S
- arch/mips/cpu/start.S

In the assembly file listed above , It mainly performs the following three functions :

lowlevel_init()
board_init_f()
board_init_r()

The complete execution process is shown in the figure below :

U-Boot Code execution process

1. lowlevel_init()

Processors of different architecture types will be defined separately lowlevel_init.S file , for example :

./arch/arm/cpu/armv7/lowlevel_init.S
./arch/arm/cpu/armv8/lowlevel_init.S
./arch/mips/mach-ath79/ar933x/lowlevel_init.S

The basic function of this function is to make CPU Can get 、 Execute to board_init_f() function . There is no stack information in this function , Cannot set SDRAM And the console .

.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()

To carry out board_init_r To prepare for , Two key functions need to be initialized :SDRAM And serial port .
At this stage ,global_data Already available , Stack information is located in SRAM in . because BSS The segment is still unusable , therefore , You cannot use global / Static variables .

if U-Boot It turns on SPL function , It's in common/spl.c This function can be implemented in the code , otherwise , Usually, the common/board_f.c Implementation in .

board_init_f() The function called in array init_sequence_f[] In the definition of :

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 Execute here , It has entered the normal function code call process , For example, device driver 、 Command line 、 Image moving, loading and other functions .

if U-Boot It turns on SPL function , It's in common/spl.c This function can be implemented in the code , otherwise , Usually, the common/board_r.c Implementation in .

board_init_r() The function called in array init_sequence_r[] In the definition of :

static init_fnc_t init_sequence_r[] = {
    
	initr_trace,
	initr_reloc,
......
#ifdef CONFIG_MMC
	initr_mmc,
#endif
......
	run_main_loop,
};

All the above functions are related to initialization ,CPU The relevant initialization code is usually located in the following path :

[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]$

The initialization code related to the board level is usually located in the following path :

[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
......
原网站

版权声明
本文为[Linux and SOC]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050643202008.html