分享

start_armboot分析2

 njy131 2012-06-01

接下来进入到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 */

 


monitor_flash_len = _bss_start - _armboot_start;

 


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

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

hang (); /* 打印错误信息并死锁 */

}

}

 


#ifndef CFG_NO_FLASH

/* configure available FLASH banks */

size = flash_init (); /* drivers/cfi_flash.c或自定义 */

display_flash_config (size);

#endif /* CFG_NO_FLASH */

 


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

mem_malloc_init (_armboot_start - CFG_MALLOC_LEN);

......

/* initialize environment */

env_relocate ();

 


/* IP Address */

gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr");

/* MAC Address */

{

int i;

ulong reg;

char *s, *e;

char tmp[64];

 


i = getenv_r ("ethaddr", tmp, sizeof (tmp));

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

 


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

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

if (s)

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

}

}

 


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

.......

jumptable_init ();

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

enable_interrupts (); /* enable exceptions */

 


/* Perform network card initialisation if necessary */

#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 */

 


/* Initialize from environment */

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

load_addr = simple_strtoul (s, NULL, 16);

}

 


#if defined(CONFIG_CMD_NET)

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

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多