[转] uboot201106rc3的arm的board.c的board_init_f函数的注释

原帖 : http://blog.mcuol.com/User/pclli/Article/55554_1.htm

/

void board_init_f (ulong bootflag)//传入r0=0=bootflag
{
 bd_t *bd;//bd_t结构体指针
 init_fnc_t **init_fnc_ptr;//init_fnc_t   是个自定义的函数指针类型,初始化板
 gd_t *id;//gd_t结构体指针
 ulong addr, addr_sp;//addr将指向用户正常访问的最高地址+1的位置;addr_sp指向堆起始位置

 /* Pointer is writable since we allocated a register for it */
 gd = (gd_t *) ((CONFIG_SYS_INIT_SP_ADDR) & ~0x07);//gd指向0x30000f80
 /* compiler optimization barrier needed for GCC >= 3.4 */
 __asm__ __volatile__("": : :"memory");//告诉编译器内存已被修改

 memset ((void*)gd, 0, sizeof (gd_t));//gd的gd_t大小清0

 gd->mon_len = _bss_end_ofs;//_bss_end_ofs=0x000add6c u-boot code, data & bss段大小总和

 for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
  if ((*init_fnc_ptr)() != 0) {//如果板的初始化函数序列出错,死循环
   hang ();
  }
 }

 debug ("monitor len: %08lX\n", gd->mon_len);
 /*
  * Ram is setup, size stored in gd !!
  */
 debug ("ramsize: %08lX\n", gd->ram_size);
//不进入
#if defined(CONFIG_SYS_MEM_TOP_HIDE)
 /*
  * Subtract specified amount of memory to hide so that it won''t
  * get "touched" at all by U-Boot. By fixing up gd->ram_size
  * the Linux kernel should now get passed the now "corrected"
  * memory size and won''t touch it either. This should work
  * for arch/ppc and arch/powerpc. Only Linux board ports in
  * arch/powerpc with bootwrapper support, that recalculate the
  * memory size from the SDRAM controller setup will have to
  * get fixed.
  */
 gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
#endif
 //CONFIG_SYS_SDRAM_BASE=0x30000000  gd->ram_size=4000000  addr=0x34000000
 addr = CONFIG_SYS_SDRAM_BASE + gd->ram_size;
//不进入
#ifdef CONFIG_LOGBUFFER
#ifndef CONFIG_ALT_LB_ADDR
 /* reserve kernel log buffer */
 addr -= (LOGBUFF_RESERVE);
 debug ("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr);
#endif
#endif
//不进入
#ifdef CONFIG_PRAM
 /*
  * reserve protected RAM
  */
 i = getenv_r ("pram", (char *)tmp, sizeof (tmp));
 reg = (i > 0) ? simple_strtoul ((const char *)tmp, NULL, 10) : CONFIG_PRAM;
 addr -= (reg << 10);  /* size is in kB */
 debug ("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
#endif /* CONFIG_PRAM */
//进入
#if !(defined(CONFIG_SYS_NO_ICACHE) && defined(CONFIG_SYS_NO_DCACHE))
 /* reserve TLB table *///保存页表缓冲
 addr -= (4096 * 4);//addr=0x33FFC000

 /* round down to next 64 kB limit */
 addr &= ~(0x10000 - 1);//addr=0x33FF0000

 gd->tlb_addr = addr;
 debug ("TLB table at: %08lx\n", addr);
#endif

 /* round down to next 4 kB limit */
 addr &= ~(4096 - 1);//addr=0x33FF0000
 debug ("Top of RAM usable for U-Boot at: %08lx\n", addr);
//不进入
#ifdef CONFIG_VFD
# ifndef PAGE_SIZE
#   define PAGE_SIZE 4096
# endif
 /*
  * reserve memory for VFD display (always full pages)
  */
 addr -= vfd_setmem (addr);
 gd->fb_base = addr;
#endif /* CONFIG_VFD */
//不进入
#ifdef CONFIG_LCD
#ifdef CONFIG_FB_ADDR
 gd->fb_base = CONFIG_FB_ADDR;
#else
 /* reserve memory for LCD display (always full pages) */
 addr = lcd_setmem (addr);
 gd->fb_base = addr;
#endif /* CONFIG_FB_ADDR */
#endif /* CONFIG_LCD */

 /*
  * reserve memory for U-Boot code, data & bss
  * round down to next 4 kB limit
  */
 addr -= gd->mon_len;//addr再去掉code, data & bss的大小 0x000add6c addr为0x33F52294
 addr &= ~(4096 - 1);//4k的页对齐 addr为0x33F52000

 debug ("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10, addr);
//进入
#ifndef CONFIG_PRELOADER
 /*
  * reserve memory for malloc() arena
  */
  //TOTAL_MALLOC_LEN在include/common.h中定义 值为0x00410000
 addr_sp = addr - TOTAL_MALLOC_LEN;//留出0x410000的空间给malloc  addr_sp为0x33B42000
 debug ("Reserving %dk for malloc() at: %08lx\n",
   TOTAL_MALLOC_LEN >> 10, addr_sp);
 /*
  * (permanently) allocate a Board Info struct
  * and a permanent copy of the "global" data
  */
 addr_sp -= sizeof (bd_t);//留出bd_t的大小24字节 0x18 addr_sp为0x33B41FE8
 bd = (bd_t *) addr_sp;
 gd->bd = bd;
 debug ("Reserving %zu Bytes for Board Info at: %08lx\n", 
   sizeof (bd_t), addr_sp);
 addr_sp -= sizeof (gd_t);//再留出gd_t的大小92字节 0x5c addr_sp为0x33B41F8C
 id = (gd_t *) addr_sp; //id为0x33B41F8C
 debug ("Reserving %zu Bytes for Global Data at: %08lx\n",
   sizeof (gd_t), addr_sp);

 /* setup stackpointer for exeptions */
 gd->irq_sp = addr_sp;
//不进入
#ifdef CONFIG_USE_IRQ
 addr_sp -= (CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ);
 debug ("Reserving %zu Bytes for IRQ stack at: %08lx\n",
  CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ, addr_sp);
#endif
 /* leave 3 words for abort-stack    */
 addr_sp -= 12;//预留12字节 0x0c addr_sp为0x33B41F80

 /* 8-byte alignment for ABI compliance */
 addr_sp &= ~0x07;//对齐 addr_sp为0x33B41F80
#else
 //不进入
 addr_sp += 128; /* leave 32 words for abort-stack   */
 gd->irq_sp = addr_sp;
#endif
 //addr_sp为0x33B41F80  addr为0x33F52000
 debug ("New Stack Pointer is: %08lx\n", addr_sp);//得到最终的堆指针
//不进入
#ifdef CONFIG_POST
 post_bootmode_init();
 post_run (NULL, POST_ROM | post_bootmode_get(0));
#endif

 gd->bd->bi_baudrate = gd->baudrate;
 /* Ram ist board specific, so move it to board code ... */
 dram_init_banksize();
 display_dram_config(); /* and display it */

 gd->relocaddr = addr;//搬运的起始地址(高位)
 gd->start_addr_sp = addr_sp;//堆栈的起始地址
 gd->reloc_off = addr - _TEXT_BASE;//搬运的偏移地址(高位)
 debug ("relocation Offset is: %08lx\n", gd->reloc_off);
 memcpy (id, (void *)gd, sizeof (gd_t));//把在低位的gd搬移到高位的id处,id为入口 id为0x33B41F8C
 //堆栈入口addr_sp gd入口id 搬运的起始地址(高位)addr 调用start.s的relocate_code子程序
 relocate_code (addr_sp, id, addr);//传参r0 r1 r2 分别为addr_sp, id, addr

 /* NOTREACHED - relocate_code() does not return */
}


 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值