arch\arm\lib crt0.S
1.设置sp为CONFIG_SYS_INIT_SP_ADDR
include/configs/xxx.h
#define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_INIT_RAM_ADDR + \
CONFIG_SYS_INIT_RAM_SIZE - GENERATED_GBL_DATA_SIZE)
#define CONFIG_SYS_INIT_RAM_ADDR 0x20000
#define CONFIG_SYS_INIT_RAM_SIZE 0x1000
CONFIG_SYS_INIT_SP_ADDR=0x21000
2.调用board_init_f_alloc_reserve
没有定义SYS_MALLOC_F_LEN,不执行。
3. r9(gd) = sp = top;
gd地址定了。CONFIG_SYS_INIT_SP_ADDR=0x21000
4.调用board_init_f
注意:串口初始化之后才能打印输出。
setup_dest_addr
#ifdef CONFIG_SYS_SDRAM_BASE
gd->ram_top = CONFIG_SYS_SDRAM_BASE;
#endif
gd->ram_top += get_effective_memsize();
gd->ram_top = board_get_usable_ram_top(gd->mon_len);
gd->relocaddr = gd->ram_top;
debug("Ram top: %08lX\n", (ulong)gd->ram_top);
gd->ram_top=0x20000+0x40000=0x60000
gd->relocaddr=gd->ram_top=0x60000
reserve_uboot --> Reserving 192k for U-Boot at: 0002f000 gd->relocaddr到此为止,之后gd->start_addr_sp出场
reserve_malloc --> Reserving 4k for malloc() at: 0002de70
reserve_board --> Reserving 80 Bytes for Board Info at: 0002de20
reserve_global_data --> Reserving 192 Bytes for Global Data at: 0002dd60 gd->new_gd
display_new_sp --> New Stack Pointer is: 0002dd40
reloc_fdt --> 因为CONFIG_OF_EMBED,所以不执行什么
reloc_bootstage --> 因为没有定义CONFIG_BOOTSTAGE,所以不执行什么
setup_reloc --> gd->reloc_off = gd->relocaddr - (unsigned long)__image_copy_start;
gd->relocaddr=
0002f000
__image_copy_start
就是CONFIG_SYS_TEXT_BASE=0x2f000
Relocation Offset is: 00000000
Relocating to 0002f000, new gd at 0002dd60, sp at 0002dd40
ldr r0, [r9, #GD_START_ADDR_SP] /* sp = gd->start_addr_sp */
bic r0, r0, #7 /* 8-byte alignment for ABI compliance */
mov sp, r0 //定义新sp 之前为0x21000
ldr r9, [r9, #GD_BD] /* r9 = gd->bd */
sub r9, r9, #GD_SIZE /* new GD is below bd */
adr lr, here
ldr r0, [r9, #GD_RELOC_OFF] /* r0 = gd->reloc_off */
add lr, lr, r0
#if defined(CONFIG_CPU_V7M)
orr lr, #1 /* As required by Thumb-only */
#endif
ldr r0, [r9, #GD_RELOCADDR] /* r0 = gd->relocaddr */
b relocate_code
如果gd->relocaddr和__image_copy_start相等
ldr r1, =__image_copy_start /* r1 <- SRC &__image_copy_start */
subs r4, r0, r1 /* r4 <- relocation offset */
beq relocate_done /* skip relocation */
就跳过搬移。
所以整个过程中,搬移的就只有gd_t。