MIPS之u-boot流程分析

1、  系统上电后

由uboot的链接文件\u-boot\arch\mips\cpu\u-boot.lds知

ENTRY(_start)程序入口点是\u-boot\arch\mips\cpu\xburst\start.s

 

2、   由la  t9, board_init_f   知跳转到board_init_f  函数(\u-boot\arch\mips\lib\board.c)

主要工作:初始化内存

 

3、  回到\u-boot\arch\mips\cpu\xburst\start.s  运行relocate_code:

 

4、运行la       t9, board_init_r  跳转到board_init_r  函数(\u-boot\arch\mips\lib\board.c)

主要工作:board_early_init_r();

         serial_initialize();

         env_relocate();

         stdio_init();

         console_init_r();

       最后进入main_loop(); 跳转到\u-boot\common\main.c

5、  运行main.c 

 p = getenv("preboot");   取得环境变量中的启动命令  

run_command_list(p,-1, 0);  执行这个命令行

len = readline(CONFIG_SYS_PROMPT);  读取uboot模式下的命令

 

main.c代码

 

void main_loop(void)
{
#ifndef CONFIG_SYS_HUSH_PARSER
	static char lastcommand[CONFIG_SYS_CBSIZE] = { 0, };
	int len;
	int rc = 1;
	int flag;
#endif
#ifdef CONFIG_PREBOOT
	char *p;
#endif

	bootstage_mark_name(BOOTSTAGE_ID_MAIN_LOOP, "main_loop");

#ifdef CONFIG_MODEM_SUPPORT
	debug("DEBUG: main_loop:   do_mdm_init=%d\n", do_mdm_init);
	if (do_mdm_init) {
		char *str = strdup(getenv("mdm_cmd"));
		setenv("preboot", str);  /* set or delete definition */
		if (str != NULL)
			free(str);
		mdm_init(); /* wait for modem connection */
	}
#endif  /* CONFIG_MODEM_SUPPORT */

#ifdef CONFIG_VERSION_VARIABLE
	{
		setenv("ver", version_string);  /* set version variable */
	}
#endif /* CONFIG_VERSION_VARIABLE */

#ifdef CONFIG_SYS_HUSH_PARSER
	u_boot_hush_start();
#endif

#if defined(CONFIG_HUSH_INIT_VAR)
	hush_init_var();
#endif

#ifdef CONFIG_PREBOOT
	p = getenv("preboot");   //从环境变量中取得命令行    
	if (p != NULL) {
# ifdef CONFIG_AUTOBOOT_KEYED
		int prev = disable_ctrlc(1);	/* disable Control C checking */
# endif

		run_command_list(p, -1, 0);   // /执行启动命令  

# ifdef CONFIG_AUTOBOOT_KEYED
		disable_ctrlc(prev);	/* restore Control C checking */
# endif
	}
#endif /* CONFIG_PREBOOT */

#if defined(CONFIG_UPDATE_TFTP)
	update_tftp(0UL);
#endif /* CONFIG_UPDATE_TFTP */

#ifdef CONFIG_BOOTDELAY
	process_boot_delay();
#endif
	/*
	 * Main Loop for Monitor Command Processing
	 */
#ifdef CONFIG_SYS_HUSH_PARSER
	parse_file_outer();
	/* This point is never reached */
	for (;;);
#else
	for (;;) {                //进入uboot模式,进行人机交互
#ifdef CONFIG_BOOT_RETRY_TIME
		if (rc >= 0) {
			/* Saw enough of a valid command to
			 * restart the timeout.
			 */
			reset_cmd_timeout();
		}
#endif
		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;  //如果输入数据为零,则重复执行上次的命令,如果上次输入的是一个命令的话
#ifdef CONFIG_BOOT_RETRY_TIME
		else if (len == -2) {
			/* -2 means timed out, retry autoboot
			 */
			puts ("\nTimed out waiting for command\n");
# ifdef CONFIG_RESET_TO_RETRY
			/* Reinit board to run initialization code again */
			do_reset (NULL, 0, 0, NULL);
# else
			return;		/* retry autoboot */
# endif
		}
#endif

		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;   //执行失败,则清空记录
		}
	}
#endif /*CONFIG_SYS_HUSH_PARSER*/
}

 

 

 

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值