Chinaunix首页 | 论坛 | 博客
  • 博客访问: 637873
  • 博文数量: 113
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 4176
  • 用 户 组: 普通用户
  • 注册时间: 2012-11-15 20:22
个人简介

最大化我的市场价值

文章分类

全部博文(113)

文章存档

2013年(113)

分类: LINUX

2013-02-21 20:21:19

u-boot->start.s->stage2->start_armboot()  


这里就是之前启动的C的函数:start_armboot()

start_armboot()函数主要初始化ARM系统的硬件和环境变量,包括Flash存储器、FrameBuffer、网卡等,最后进入U-Boot应用程序主循环

=========================================

236 void start_armboot (void)  

237 {  

238           init_fnc_t **init_fnc_ptr;  

239           char *s;  

240 #ifndef CFG_NO_FLASH  

241          ulong size;  

242 #endif  

243 #if defined(CONFIG_VFD) || defined(CONFIG_LCD)  

244         unsigned long addr;  

245 #endif  

246   

247   /* Pointer is writable since we allocated a register for it */  

/////////////////////////////////////////////////////////////////////////////////////////////////////////

  /* Pointer is writable since we allocateda register for it 
   gd_t: 
定义在/include/asm-arm/Global_data.h,包含一些全局通用的变量
   _armboot_start: 
代码的起始地址,它定义在start.S中的前几行中,定义为_start
   
当系统第一次加电时,指令是从0x0地址开始执行的,所以此时的_start
   
应为0x0;而当uboot经过代码重定位后,指令会从_TEXT_BASE 处开始执行,
   
此时的_start值就成了_TEXT_BASE的值
   CFG_MALLOC_LEN: 
/include/configs/smdk2440.h中有定义,该变量表示供
   malloc
函数使用的内存池空间,代码中定义值为:0x10000+128*1024 
 |-------|<--- _armboot_start
基址
 |  4    |  
 |-------|<--- malloc
函数池基址
 |  3    | 
 |-------|<--- (gd_t)gd(
全局变量表)基址
 |  2    | 
 |-------|<--- (bt_t)bd(
板卡信息表)基址
 |  1    | 
  ------- 
   4 
就是为malloc函数预留的数据空间
   3 
是全信息表gd的数据区
 2 
是板卡信息表bd的数据区
 
网上找了个图片,更能反应这个空间的分配关系
 
 */

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

248   gd = (gd_t*)(_armboot_start - CFG_MALLOC_LEN - sizeof(gd_t));  

249   /* compiler optimization barrier needed for GCC >= 3.4 */  

250   __asm__ __volatile__("": : :"memory");  

251   

252   memset(  (void*)gd,   0,    sizeof (gd_t)  );  

253   gd->bd = (bd_t*)( (char*)gd  -  sizeof(bd_t) );  

254   memset (  gd->bd,  0,   sizeof (bd_t) );  

255   

256   monitor_flash_len = _bss_start - _armboot_start;  

257   

258   for (init_fnc_ptr = init_sequence;    *init_fnc_ptr;     ++init_fnc_ptr) {  

259           if ((*init_fnc_ptr)() != 0) {  

260           hang ();  

261     }  

262   }  

263   

264 #ifndef CFG_NO_FLASH  

265   /* configure available FLASH banks */  

266       size = flash_init ();                // 初始化Flash存储器配置  

267       display_flash_config (size);  // 显示Flash存储器配置  

268 #endif /* CFG_NO_FLASH */  

269   

270 #ifdef CONFIG_VFD  

271 # ifndef PAGE_SIZE  

272 #   define PAGE_SIZE 4096  

273 # endif  

274   /*  

275    * reserve memory for VFD display (always full pages)  

276    */  

277   /* bss_end is defined in the board-specific linker script */  

278   addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);  

                                            // 计算FrameBuffer内存地址  

279   size = vfd_setmem (addr);             // 设置FrameBuffer占用内存大小  

280   gd->fb_base = addr;                     // 设置FrameBuffer内存起始地址  

281 #endif /* CONFIG_VFD */  

282   

283 #ifdef CONFIG_LCD  

284 # ifndef PAGE_SIZE  

285 #   define PAGE_SIZE 4096  

286 # endif  

287   /*  

288    * reserve memory for LCD display (always full pages)  

289    */  

290   /* bss_end is defined in the board-specific linker script */  

291   addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);  

                                                             // 计算FrameBuffer内存地址  

292   size = lcd_setmem (addr);             // 设置FrameBuffer大小  

293   gd->fb_base = addr;                     // 设置FrameBuffer内存起始地址  

294 #endif /* CONFIG_LCD */  

295   

296   /* armboot_start is defined in the board-specific linker script */  

297   mem_malloc_init (_armboot_start - CFG_MALLOC_LEN);  

298   

299 #if (CONFIG_COMMANDS & CFG_CMD_NAND)  

300        puts ("NAND:  ");  

301         nand_init();    /* go init the NAND */           // 初始化NAND Flash存储器  

302 #endif  

303   

304 #ifdef CONFIG_HAS_DATAFLASH  

305   AT91F_DataflashInit();                                      // 初始化Hash表 

306   dataflash_print_info();  

307 #endif  

308   

309   /* initialize environment */  

310   env_relocate ();                                                 // 重新设置环境变量 

311       

312 #ifdef CONFIG_VFD  

313   /* must do this after the framebuffer is allocated */  

314   drv_vfd_init();                                                 // 初始化虚拟显示设备  

315 #endif /* CONFIG_VFD */  

316   

317   /* IP Address */  

318   gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr");    // 设置网卡的IP地址  

319   

320   /* MAC Address */  

321   {  

322     int i;  

323     ulong reg;  

324     char *s, *e;  

325     char tmp[64];  

326   

327     i = getenv_r ("ethaddr", tmp, sizeof (tmp));          // 从网卡寄存器读取  MAC地址  

328     s = (i > 0) ? tmp : NULL;  

329   

330     for (reg = 0; reg < 6; ++reg) {  

331       gd->bd->bi_enetaddr[reg] = s ? simple_strtoul (s, &e, 16) : 0;  

332       if (s)  

333         s = (*e) ? e + 1 : e;  

334     }  

335   

336 #ifdef CONFIG_HAS_ETH1  

337     i = getenv_r ("eth1addr", tmp, sizeof (tmp));           // 读取Hash值  

338     s = (i > 0) ? tmp : NULL;  

339   

340     for (reg = 0; reg < 6; ++reg) {  

341       gd->bd->bi_enet1addr[reg] = s ? simple_strtoul (s, &e, 16) : 0;  

342       if (s)  

343         s = (*e) ? e + 1 : e;  

344     }  

345 #endif  

346   }  

347   

348   devices_init ();                                                    /* get the devices list going. */  

                                                                                     // 初始化开发板上的设备 

349   

350 #ifdef CONFIG_CMC_PU2  

351   load_sernum_ethaddr ();  

352 #endif /* CONFIG_CMC_PU2 */  

353   

354   jumptable_init ();                                                // 初始化跳转表 

355   

356   console_init_r ();  /* fully init console as a device */  

                                                                                    // 初始化控制台 

357   

358 #if defined(CONFIG_MISC_INIT_R)  

359   /* miscellaneous platform dependent initialisations */  

360   misc_init_r ();                                                    // 初始化其他设备 

361 #endif  

362   

363   /* enable exceptions */  

364   enable_interrupts ();                                         // 打开中断 

365   

366   /* Perform network card initialisation if necessary */  

367 #ifdef CONFIG_DRIVER_CS8900  

368   cs8900_get_enetaddr (gd->bd->bi_enetaddr);    // 获取CS8900网卡MAC地址  

369 #endif  

370   

371 #if defined(CONFIG_DRIVER_SMC91111) || defined (CONFIG_DRIVER_   

LAN91C96)  

372   if (getenv ("ethaddr")) {  

373     smc_set_mac_addr(gd->bd->bi_enetaddr);      // 设置SMC网卡MAC地址  

374   }  

375 #endif /* CONFIG_DRIVER_SMC91111 || CONFIG_DRIVER_LAN91C96 */  

376   

377   /* Initialize from environment */  

378   if ((s = getenv ("loadaddr")) != NULL) {  

379     load_addr = simple_strtoul (s, NULL, 16);  

380   }  

381 #if (CONFIG_COMMANDS & CFG_CMD_NET)  

382   if ((s = getenv ("bootfile")) != NULL) {  

383     copy_filename (BootFile, s, sizeof (BootFile));            // 保存FrameBuffer  

384   }  

385 #endif  /* CFG_CMD_NET */  

386   

387 #ifdef BOARD_LATE_INIT  

388   board_late_init ();                                                         // 开发板相关设备初始化  

389 #endif  

390 #if (CONFIG_COMMANDS & CFG_CMD_NET)  

391 #if defined(CONFIG_NET_MULTI)  

392   puts ("Net:   ");  

393 #endif  

394   eth_initialize(gd->bd);  

395 #endif  

396   /* main_loop() can return to retry autoboot, if so just run it again. */  

397   for (;;) {  

398     main_loop ();                               // 进入主循环  

399   }  

400   

401   /* NOTREACHED - no way out of command loop except booting */  

402 } 

start_armboot()函数代码里有许多的宏开关,供用户根据自己开发板的情况进行配置。在start_armboot()函数第388行调用board_late_init()函数,该函数是开发板提供的,供不同的开发板做一些特有的初始化工作。

在start_armboot()函数中,使用宏开关括起来的代码是在各种开发板上最常用的功能,如CS8900网卡配置。整个函数配置完毕后,进 入一个for死循环,调用main_loop()函数。请读者注意,在main_loop()函数中也有一个for死循环。 start_armboot()函数使用死循环调用main_loop()函数,作用是防止main_loop()函数开始的初始化代码如果调用失败后重 新执行初始化操作,保证程序能进入到U-Boot的命令行。
阅读(1596) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~