uboot启动过程 3
阅读原文时间:2023年07月08日阅读:1

uboot启动过程1描述到

_start -> reset ->  save_boot_params -> save_boot_params_ret

->  cpu_init_cp15: 配置cp15, 关闭MMU什么的****

->  cpu_init_crit -> lowlevel_init -> s_init

-> _main

-> board_init_f_alloc_reserve: 内存布局为gd_t: [0X0091FA00, 0X0091FB00-8)  alloc:[0X0091FB00, 0X0091FF00)

-> board_init_f_init_reserve: gd->malloc_base=0X0091FB00

-> board_init_f:  对gd进行了初步初始化,并分配了各个区块的内存空间

-> relocate_code

-> relocate_vectors

现在开始分析relocate_code

arch/arm/lib/relocate.S

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)

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章