Chinaunix首页 | 论坛 | 博客
  • 博客访问: 270767
  • 博文数量: 86
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 398
  • 用 户 组: 普通用户
  • 注册时间: 2014-09-27 15:56
文章存档

2017年(3)

2015年(21)

2014年(62)

我的朋友

分类: LINUX

2014-11-14 00:34:00


点击(此处)折叠或打开

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

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

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

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

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

  18.  debug ("monitor len: %08lX\n", gd->mon_len);
  19.  /*
  20.   * Ram is setup, size stored in gd !!
  21.   */
  22.  debug ("ramsize: %08lX\n", gd->ram_size);
  23. //不进入
  24. #if defined(CONFIG_SYS_MEM_TOP_HIDE)
  25.  /*
  26.   * Subtract specified amount of memory to hide so that it won''t
  27.   * get "touched" at all by U-Boot. By fixing up gd->ram_size
  28.   * the Linux kernel should now get passed the now "corrected"
  29.   * memory size and won''t touch it either. This should work
  30.   * for arch/ppc and arch/powerpc. Only Linux board ports in
  31.   * arch/powerpc with bootwrapper support, that recalculate the
  32.   * memory size from the SDRAM controller setup will have to
  33.   * get fixed.
  34.   */
  35.  gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
  36. #endif
  37.  //CONFIG_SYS_SDRAM_BASE=0x30000000 gd->ram_size=4000000 addr=0x34000000
  38.  addr = CONFIG_SYS_SDRAM_BASE + gd->ram_size;
  39. //不进入
  40. #ifdef CONFIG_LOGBUFFER
  41. #ifndef CONFIG_ALT_LB_ADDR
  42.  /* reserve kernel log buffer */
  43.  addr -= (LOGBUFF_RESERVE);
  44.  debug ("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr);
  45. #endif
  46. #endif
  47. //不进入
  48. #ifdef CONFIG_PRAM
  49.  /*
  50.   * reserve protected RAM
  51.   */
  52.  i = getenv_r ("pram", (char *)tmp, sizeof (tmp));
  53.  reg = (i > 0) ? simple_strtoul ((const char *)tmp, NULL, 10) : CONFIG_PRAM;
  54.  addr -= (reg << 10); /* size is in kB */
  55.  debug ("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
  56. #endif /* CONFIG_PRAM */
  57. //进入
  58. #if !(defined(CONFIG_SYS_NO_ICACHE) && defined(CONFIG_SYS_NO_DCACHE))
  59.  /* reserve TLB table *///保存页表缓冲
  60.  addr -= (4096 * 4);//addr=0x33FFC000

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

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

  66.  /* round down to next 4 kB limit */
  67.  addr &= ~(4096 - 1);//addr=0x33FF0000
  68.  debug ("Top of RAM usable for U-Boot at: %08lx\n", addr);
  69. //不进入
  70. #ifdef CONFIG_VFD
  71. # ifndef PAGE_SIZE
  72. # define PAGE_SIZE 4096
  73. # endif
  74.  /*
  75.   * reserve memory for VFD display (always full pages)
  76.   */
  77.  addr -= vfd_setmem (addr);
  78.  gd->fb_base = addr;
  79. #endif /* CONFIG_VFD */
  80. //不进入
  81. #ifdef CONFIG_LCD
  82. #ifdef CONFIG_FB_ADDR
  83.  gd->fb_base = CONFIG_FB_ADDR;
  84. #else
  85.  /* reserve memory for LCD display (always full pages) */
  86.  addr = lcd_setmem (addr);
  87.  gd->fb_base = addr;
  88. #endif /* CONFIG_FB_ADDR */
  89. #endif /* CONFIG_LCD */

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

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

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

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

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

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

  154.  /* NOTREACHED - relocate_code() does not return */
  155. }

阅读(1322) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~