|
发表于 2014-10-24 23:12:40
16479 浏览 3 回复
【uboot】uboot启动C语言主函数start_armboot
uboot启动的主函数 start_armboot 主要工作是初始化硬件资源和搬运linux内核从内核启动或者收到中断后,进入uboot系统中,主函数代码比较复杂。我精简了一下,主要去掉了#ifdef。。。主函数代码如下:
void start_armboot (void)
{
init_fnc_t **init_fnc_ptr;
char *s;
int mmc_exist = 0;
/* Pointer is writable since we allocated a register for it */
gd = (gd_t*)(_armboot_start - CONFIG_SYS_MALLOC_LEN - sizeof(gd_t));
/* compiler optimization barrier needed for GCC >= 3.4 */
__asm__ __volatile__("": : :"memory");
memset ((void*)gd, 0, sizeof (gd_t));
gd->bd = (bd_t*)((char*)gd - sizeof(bd_t));
memset (gd->bd, 0, sizeof (bd_t));
// gd->flags |= GD_FLG_RELOC;
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 ();
}
}
/* armboot_start is defined in the board-specific linker script */
mem_malloc_init (_armboot_start - CONFIG_SYS_MALLOC_LEN, CONFIG_SYS_MALLOC_LEN);
puts ("MMC: ");
mmc_exist = mmc_initialize (gd->bd);
if (mmc_exist != 0)
{
puts ("0 MB\n");
}
/* initialize environment */
env_relocate ();
/* IP Address */
gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
stdio_init (); /* get the devices list going. */
jumptable_init ();
console_init_r (); /* fully init console as a device */
/* enable exceptions */
enable_interrupts ();
/* Initialize from environment */
if ((s = getenv ("loadaddr")) != NULL)
{
load_addr = simple_strtoul (s, NULL, 16);
}
board_late_init ();
/*
char tmp_cmd[100];
sprintf(tmp_cmd, "emmc open 0");
run_command(tmp_cmd, 0);
*/
/* main_loop() can return to retry autoboot, if so just run it again. */
recovery_preboot();
for (;;)
{
main_loop ();
}
/* NOTREACHED - no way out of command loop except booting */
}
|
|
|
|
|
|
|
|
楼主|
发表于 2014-10-24 23:18:07
主函数中for(;;)中的main_loop ();精简后代码如下
/****************************************************************************/
void main_loop (void)
{
static char lastcommand[CONFIG_SYS_CBSIZE] = { 0, };
int len;
int rc = 1;
int flag;
char *s;
int bootdelay;
s = getenv ("bootdelay");
bootdelay = s ? (int)simple_strtol(s, NULL, 10) : CONFIG_BOOTDELAY;
debug ("### main_loop entered: bootdelay=%d\n\n", bootdelay);
s = getenv ("bootcmd");
debug ("### main_loop: bootcmd=\"%s\"\n", s ? s : "<UNDEFINED>");
if (bootdelay >= 0 && s && !abortboot (bootdelay))
{
run_command (s, 0);
}
/*
* Main Loop for Monitor Command Processing
*/
for (;;)
{
len = readline (CONFIG_SYS_PROMPT);
flag = 0; /* assume no special flags for now */
if (len > 0)
strcpy (lastcommand, console_buffer);
else if (len == 0)
flag |= CMD_FLAG_REPEAT;
if (len == -1)
puts ("<INTERRUPT>\n");
else
rc = run_command (lastcommand, flag);
if (rc <= 0)
{
/* invalid command or not repeatable, forget it */
lastcommand[0] = 0;
}
}
}
|
|
|
|
|
|
|
|
发表于 2014-10-25 12:08:24
|
|
|
|
|
|
登录或注册
扫一扫关注迅为公众号
|