方法一:
common/main.c
void main_loop(void)
{const char *s;bootstage_mark_name(BOOTSTAGE_ID_MAIN_LOOP, "main_loop");if (IS_ENABLED(CONFIG_VERSION_VARIABLE))env_set("ver", version_string); /* set version variable */cli_init();s = env_get("bootcmd");printf(" cli_init env_get bootcmd is %s run_command_list\r\n",s);run_command_list(s, -1, 0); // 启动内核if (IS_ENABLED(CONFIG_USE_PREBOOT))run_preboot_environment_command();if (IS_ENABLED(CONFIG_UPDATE_TFTP))update_tftp(0UL, NULL, NULL);s = bootdelay_process();if (cli_process_fdt(&s))cli_secure_boot_cmd(s);autoboot_command(s);cli_loop();panic("No CLI available");
}
方法二:
common/autoboot.c
void autoboot_command(const char *s)
{debug("### main_loop: bootcmd=\"%s\"\n", s ? s : "<UNDEFINED>");if (stored_bootdelay != -1 && s && !abortboot(stored_bootdelay)) {bool lock;int prev;lock = IS_ENABLED(CONFIG_AUTOBOOT_KEYED) &&!IS_ENABLED(CONFIG_AUTOBOOT_KEYED_CTRLC);if (lock)prev = disable_ctrlc(1); /* disable Ctrl-C checking */run_command_list(s, -1, 0);if (lock)disable_ctrlc(prev); /* restore Ctrl-C checking */}if (IS_ENABLED(CONFIG_USE_AUTOBOOT_MENUKEY) &&menukey == AUTOBOOT_MENUKEY) {s = env_get("menucmd");if (s)run_command_list(s, -1, 0);}
}static int abortboot(int bootdelay)
{int abort = 0;return 0 ; // 直接返回 if (bootdelay >= 0) {if (IS_ENABLED(CONFIG_AUTOBOOT_KEYED))abort = abortboot_key_sequence(bootdelay);elseabort = abortboot_single_key(bootdelay);}if (IS_ENABLED(CONFIG_SILENT_CONSOLE) && abort)gd->flags &= ~GD_FLG_SILENT;return abort;
}void autoboot_command(const char *s)
{debug("### main_loop: bootcmd=\"%s\"\n", s ? s : "<UNDEFINED>");if (stored_bootdelay != -1 && s && !abortboot(stored_bootdelay)) {bool lock;int prev;lock = IS_ENABLED(CONFIG_AUTOBOOT_KEYED) &&!IS_ENABLED(CONFIG_AUTOBOOT_KEYED_CTRLC);if (lock)prev = disable_ctrlc(1); /* disable Ctrl-C checking */run_command_list(s, -1, 0); // 启动内核if (lock)disable_ctrlc(prev); /* restore Ctrl-C checking */}if (IS_ENABLED(CONFIG_USE_AUTOBOOT_MENUKEY) &&menukey == AUTOBOOT_MENUKEY) {s = env_get("menucmd");if (s)run_command_list(s, -1, 0);}
}static int abortboot_single_key(int bootdelay)
{int abort = 0;unsigned long ts;printf("Hit any key to stop autoboot: %2d ", bootdelay); // 打印/** Check if key already pressed*/if (tstc()) { /* we got a key press */(void) getc(); /* consume input */puts("\b\b\b 0");abort = 1; /* don't auto boot */}while ((bootdelay > 0) && (!abort)) {--bootdelay;/* delay 1000 ms */ts = get_timer(0);do {if (tstc()) { /* we got a key press */int key;abort = 1; /* don't auto boot */bootdelay = 0; /* no more delay */key = getc(); /* consume input */if (IS_ENABLED(CONFIG_USE_AUTOBOOT_MENUKEY))menukey = key;break;}udelay(10000);} while (!abort && get_timer(ts) < 1000);printf("\b\b\b%2d ", bootdelay); // 打印倒计时 }putc('\n');return abort;
}