uboot启动过程 3
uboot启动过程1描述到
_start -> reset -> save_boot_params -> save_boot_params_ret
-> cpu_init_cp15: 配置cp15, 关闭MMU什么的
ENTRY(relocate_code)
// __image_copy_start等同_start, 也就是0x87800000
ldr r1, =__image_copy_start /* r1 <- SRC &__image_copy_start */
// uboot启动过程2描述到reserve_uboot定位到了uboot的最终位置并赋值给gd->relocaddr
// uboot启动过程1由 r0 = gd->relocaddr, 并调用relocate_code, 所以这里r4为两者offset
subs r4, r0, r1 /* r4 <- relocation offset */
beq relocate_done /* skip relocation */ // 源和目标相同,不用复制
// 通过uboot.lds可知, 其实bss部分没有被复制
ldr r2, =__image_copy_end /* r2 <- SRC &__image_copy_end */
copy_loop:
ldmia r1!, {r10-r11} /* copy from source address [r1] */
stmia r0!, {r10-r11} /* copy to target address [r0] */
cmp r1, r2 /* until source end address [r2] */
blo copy_loop
/*
* fix .rel.dyn relocations
*/
ldr r2, =__rel_dyn_start /* r2 <- SRC &__rel_dyn_start */
ldr r3, =__rel_dyn_end /* r3 <- SRC &__rel_dyn_end */
fixloop:
ldmia r2!, {r0-r1} /* (r0,r1) <- (SRC location,fixup) */
and r1, r1, #0xff
cmp r1, #23 /* relative fixup? */
bne fixnext
/* relative fix: increase location by offset */
add r0, r0, r4
ldr r1, [r0]
add r1, r1, r4
str r1, [r0]
fixnext:
cmp r2, r3
blo fixloop
relocate_done:
#ifdef __XSCALE__
/*
* On xscale, icache must be invalidated and write buffers drained,
* even with cache disabled - 4.2.7 of xscale core developer's manual
*/
mcr p15, 0, r0, c7, c7, 0 /* invalidate icache */
mcr p15, 0, r0, c7, c10, 4 /* drain write buffer */
#endif
/* ARMv4- don't know bx lr but the assembler fails to see that */
#ifdef __ARM_ARCH_4__
mov pc, lr
#else
bx lr
#endif
ENDPROC(relocate_code)