我看到很多产品在启动的时候,需要按空格键几秒钟进入U-boot,并且串口这时候才有显示。请问这是如何实现的呢?
我现在的情况是刚开始就有显示,并且默认是按任何键就可以进入u-boot。
u-boot中代码我找到了这个地方:
static __inline__ int abortboot(int bootdelay)
{
int abort = 0;
#ifdef CONFIG_SILENT_CONSOLE
{
DECLARE_GLOBAL_DATA_PTR;
if (gd->flags & GD_FLG_SILENT) {
/* Restore serial console */
console_assign (stdout, "serial");
console_assign (stderr, "serial");
}
}
#endif
#ifdef CONFIG_MENUPROMPT
printf(CONFIG_MENUPROMPT, bootdelay);
#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()) { /* we got a key press */
(void) getc(); /* consume input */
puts ("\b\b\b 0");
abort = 1; /* don't auto boot */
}
}
#endif
while ((bootdelay > 0) && (!abort)) {
int i;
--bootdelay;
/* delay 100 * 10ms */
for (i=0; !abort && i<100; ++i) {
if (tstc()) { /* we got a key press */
abort = 1; /* don't auto boot */
bootdelay = 0; /* no more delay */
# ifdef CONFIG_MENUKEY
menukey = getc();
# else
(void) getc(); /* consume input */
# endif
break;
}
udelay (10000);
}
printf ("\b\b\b%2d ", bootdelay);
}
putc ('\n');
#ifdef CONFIG_SILENT_CONSOLE
{
DECLARE_GLOBAL_DATA_PTR;
if (abort) {
/* permanently enable normal console output */
gd->flags &= ~(GD_FLG_SILENT);
} else if (gd->flags & GD_FLG_SILENT) {
/* Restore silent console */
console_assign (stdout, "nulldev");
console_assign (stderr, "nulldev");
}
}
#endif
return abort;
}
其实我这边主要有两个问题:
1.如果检测用户按空格几秒钟了,然后退出自动启动?
2.如何在启动的时候不把输出信息打印到串口上,后来通过检测到用户按键来把打印信息又输出来?