接下来进入到Bootloader Stage 2即C语言代码部分,入口是start_armboot,对应的源文件是lib_arm/board.c,这一文件对所有的ARM处理器都是通用的,因此在移植的时候不用修改。相关源代码如下: DECLARE_GLOBAL_DATA_PTR; /* 在include/asm-arm/global_data.h中定义的一个全局寄存器变量的声明: * #define DECLARE_GLOBAL_DATA_PTR register volatile gd_t *gd asm ("r8") * 用于存放全局数据结构体gd_t的地址。 */ void start_armboot (void) { init_fnc_t **init_fnc_ptr; char *s; #ifndef CFG_NO_FLASH ulong size; #endif #if defined(CONFIG_VFD) || defined(CONFIG_LCD) /* 本次移植暂不配置VFD和LCD,后面也将不考虑的部分略去 */ /* 初始化全局数据结构体指针gd */ gd = (gd_t*)(_armboot_start - CFG_MALLOC_LEN - sizeof(gd_t)); ....../* memset在lib_generic/string.c中定义*/ memset ((void*)gd, 0, sizeof (gd_t)); /*用0填充全局数据表*gd */ gd->bd = (bd_t*)((char*)gd - sizeof(bd_t)); memset (gd->bd, 0, sizeof (bd_t)); /*用0填充(初始化) *gd->bd */
if ((*init_fnc_ptr)() != 0) { hang (); /* 打印错误信息并死锁 */ } }
/* configure available FLASH banks */ size = flash_init (); /* drivers/cfi_flash.c或自定义 */ display_flash_config (size); #endif /* CFG_NO_FLASH */
mem_malloc_init (_armboot_start - CFG_MALLOC_LEN); ...... /* initialize environment */ env_relocate ();
gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr"); /* MAC Address */ { int i; ulong reg; char *s, *e; char tmp[64];
s = (i > 0) ? tmp : NULL;
gd->bd->bi_enetaddr[reg] = s ? simple_strtoul (s, &e, 16) : 0; if (s) s = (*e) ? e + 1 : e; } }
....... jumptable_init (); console_init_r (); /* fully init console as a device */ enable_interrupts (); /* enable exceptions */
#if defined(CONFIG_DRIVER_SMC91111)| |defined (CONFIG_DRIVER_LAN91C96) if (getenv ("ethaddr")) smc_set_mac_addr(gd->bd->bi_enetaddr); #endif /* CONFIG_DRIVER_SMC91111 || CONFIG_DRIVER_LAN91C96 */
if ((s = getenv ("loadaddr")) != NULL) { load_addr = simple_strtoul (s, NULL, 16); }
if ((s = getenv ("bootfile")) != NULL) copy_filename (BootFile, s, sizeof (BootFile)); #endif #ifdef BOARD_LATE_INIT board_late_init (); #endif ...... /*main_loop() can return to retry autoboot, if so just run it again.*/ for (;;) { main_loop (); } } 文章出处:飞诺网(www.):http://www./course/6_system/linux/Linuxjs/200899/141116_2.html |
|