U-BOOT從ROM拷到RAM
詳見start.S
relocate: /* relocate U-Boot to RAM */
adr r0, _start /* r0 <- current position of code */
ldr r1, _TEXT_BASE /* test if we run from flash or RAM */
cmp r0, r1 /* don't reloc during debug */
beq stack_setup
ldr r2, _armboot_start
ldr r3, _bss_start
sub r2, r3, r2 /* r2 <- size of armboot */
add r2, r0, r2 /* r2 <- source end address */
copy_loop:
ldmia r0!, {r3-r10} /* copy from source address [r0] */
stmia r1!, {r3-r10} /* copy to target address [r1] */
cmp r0, r2 /* until source end addreee [r2] */
ble copy_loop
其中,
adr r0, _start
是取得_start行在內存(Nor Flash ROM)的實際位置,_TEXT_BASE則是RAM中的位置。
實際把plain binary格式的u-boot燒寫到NOR Flash運行時,需要把Nor Flash中的代碼拷貝到RAM。當u-boot在NorFlash中運行時,adr r0,_start可以取得該行的實際位置。
_armboot_start的值
_armboot_start:
.word _start
此值在編譯時已經決定,為0x33F80000
_bss_start的值
_bss_start:
.word __bss_start
此值在編譯時已經決定,即__bss_start的值,在link script中定義。
u-boot代碼長度 = _armboot_start - _bss_start
u-boot代碼末地址 = r2
ldmia : 每次取8個word
ldmia r0!, {r3-r10} /* copy from source address [r0] */
stmia r1!, {r3-r10} /* copy to target address [r1] */
直到r0 > r2 ,其中ble表示 <=,即r0<=r2時循環拷貝