之前了解了uboot链接脚本文件 u-boot.lds。
从 u-boot.lds 中我们已经知道了入口点是 arch/arm/lib/vectors.S 文件中的 _start。
本文了解 一下,uboot启动过程中涉及的 reset 函数。本文继上一篇文章学习,地址如下:
uboot启动流程-uboot链接脚本u-boot.lds_凌肖战的博客-CSDN博客
从 u-boot.lds 中,我们已经知道了入口点是 arch/arm/lib/vectors.S 文件中的 _start,代码如下:
- 38 /*
- 39 *************************************************************
- 40 *
- 41 * Exception vectors as described in ARM reference manuals
- 42 *
- 43 * Uses indirect branch to allow reaching handlers anywhere in
- 44 * memory.
- 45 **************************************************************
- 46 */
- 47
- 48 _start:
- 49
- 50 #ifdef CONFIG_SYS_DV_NOR_BOOT_CFG
- 51 .word CONFIG_SYS_DV_NOR_BOOT_CFG
- 52 #endif
- 53
- 54 b reset
- 55 ldr pc, _undefined_instruction
- 56 ldr pc, _software_interrupt
- 57 ldr pc, _prefetch_abort
- 58 ldr pc, _data_abort
- 59 ldr pc, _not_used
- 60 ldr pc, _irq
- 61 ldr pc, _fiq
第 48 行: _start 开始的是中断向量表,其中 54~61 行就是中断向量表,和我们裸机例程里面一样。
- 32 .globl reset
- 33 .globl save_boot_params_ret
- 34
- 35 reset:
- 36 /* Allow the board to save important registers */
- 37 b save_boot_params
start.S 文件的第 35 行就是 reset 函数。
第 37 行从 reset 函数跳转到了 save_boot_params 函数,而 save_boot_params 函数同样定义在 start.S 里面,定义如下:
100 ENTRY ( save_boot_params )101 b save_boot_params_ret @ back to my caller
- 38 save_boot_params_ret:
- 39 /*
- 40 * disable interrupts (FIQ and IRQ), also set the cpu to SVC32
- 41 * mode, except if in HYP mode already
- 42 */
- 43 mrs r0, cpsr
- 44 and r1, r0, #0x1f @ mask mode bits
- 45 teq r1, #0x1a @ test for HYP mode
- 46 bicne r0, r0, #0x1f @ clear all mode bits
- 47 orrne r0, r0, #0x13 @ set SVC mode
- 48 orr r0, r0, #0xc0 @ disable FIQ and IRQ
- 49 msr cpsr,r0
save_boot_params_ret 函数中,第43行~49行,将处理器设置为SVC模式,并且关闭FIQ和IRQ。
- 56 #if !(defined(CONFIG_OMAP44XX) && defined(CONFIG_SPL_BUILD))
- 57 /* Set V=0 in CP15 SCTLR register - for VBAR to point to vector */
- 58 mrc p15, 0, r0, c1, c0, 0 @ Read CP15 SCTLR Register
- 59 bic r0, #CR_V @ V = 0
- 60 mcr p15, 0, r0, c1, c0, 0 @ Write CP15 SCTLR Register
- 61
- 62 /* Set vector address in CP15 VBAR register */
- 63 ldr r0, =_start
- 64 mcr p15, 0, r0, c12, c0, 0 @Set VBAR
- 65 #endif
第 59 行,CR_V 在 arch/arm/include/asm/system.h 中有如下所示定义:
#define CR_V (1 << 13) /* Vectors relocated to 0xffff0000 */

第 60 行将 r0 寄存器的值重写写入到寄存器 SCTLR 中。
- 67 /* the mask ROM code should have PLL and others stable */
- 68 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
- 69 bl cpu_init_cp15
- 70 bl cpu_init_crit
- 71 #endif
- 72
- 73 bl _main
- 268 ENTRY(cpu_init_crit)
- 269 /*
- 270 * Jump to board specific initialization...
- 271 * The Mask ROM will have already initialized
- 272 * basic memory. Go here to bump up clock rate and handle
- 273 * wake up conditions.
- 274 */
- 275 b lowlevel_init @ go setup pll,mux,memory
- 276 ENDPROC(cpu_init_crit)