Main_loop()函数在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_VERSION_VARIABLE
{
extern char version_string[];
setenv ("ver", version_string); /* set version variable */
}
#endif /* CONFIG_VERSION_VARIABLE */
//是否终止引导
if (bootdelay >= 0 && s && !abortboot(bootdelay)) {
int prev = disable_ctrlc(1); /* 禁止 ^C */
s = getenv ("bootdelay"); //延迟
bootdelay = s ? (int)simple_strtol(s, NULL, 10) : CONFIG_BOOTDELAY;
debug ("### main_loop entered: bootdelay=%d\n\n", bootdelay);
}
# ifdef CONFIG_MENUKEY
if (menukey == CONFIG_MENUKEY) {
s = getenv("menucmd"); //命令行菜单
if (s) {
# ifndef CONFIG_SYS_HUSH_PARSER
run_command (s, 0);
# else
}
}
/*
* Main Loop for Monitor Command Processing
*/
#ifdef CONFIG_SYS_HUSH_PARSER
parse_file_outer(); //解析输出流
/* This point is never reached */
for (;;);
#else
for (;;) {
len = readline (CONFIG_SYS_PROMPT);
// "fastboot# " /* Monitor Command Prompt */
if (len > 0) { //读取控制台命令
strncpy (lastcommand, console_buffer, sizeof(lastcommand));
lastcommand[sizeof(lastcommand) - 1] = '\0';
}
else if (len == 0)
flag |= CMD_FLAG_REPEAT;
else if (len == -2) {
/* -2 表示超时, 尝试自动重启
*/
//重新初始化
do_reset (NULL, 0, 0, NULL);
return; /* retry autoboot */
}
if (len == -1)
puts ("<INTERRUPT>\n");
else
rc =run_command (lastcommand, flag);
/* 清零 避免重复 */
lastcommand[0] = 0;
}
}
static __inline__ int abortboot(int bootdelay)
{
int abort = 0;
#ifdef CONFIG_MENUPROMPT
printf(CONFIG_MENUPROMPT);
#else
printf("Hit any key to stop autoboot: %2d ", bootdelay);
#endif
#if defined CONFIG_ZERO_BOOTDELAY_CHECK
/*
* Check if key already pressed
* Don't check if bootdelay < 0
*/
if (bootdelay >= 0) {
if (tstc()) { //是否有键按下
(void) getc(); /* consume input */ //接收键值
puts ("\b\b\b 0");
abort = 1; /* don't auto boot */
//修改标记,停止自动引导
}
}
#endif
while ((bootdelay > 0) && (!abort)) { //如果延时大于0并且停止标记没有赋值则进入延时循环,直到延时