你好!这里是风筝的博客,
欢迎和我一起交流。
JZ2440开发板
u-boot2016.11
kernel4.8.17
我发现不接串口的情况下,不能启动kernel,重新接上串口,发现卡在uboot下,然后我直接把串口用串口线接到充电宝上,发现居然能启动了。
我当时在想,难道要给串口供电才能吗?不应该啊,没见过这种说法。
后来发现,应该是不接串口的话,在u-boot倒计时阶段受到了干扰,让u-boot误以为有按键按下,不自动启动kernel:
u-boot里倒计时的代码如下:
static int __abortboot(int bootdelay)
{
int abort = 0;
unsigned long ts;
#ifdef CONFIG_MENUPROMPT
printf(CONFIG_MENUPROMPT);
#else
printf("Hit any key to stop autoboot: %2d ", bootdelay);
#endif
/*
* 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 */
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);
} while (!abort && get_timer(ts) < 1000);
printf("\b\b\b%2d ", bootdelay);
}
putc('\n');
return abort;
}
其中,tstc函数就是检测是否获得按键,然后getc函数取出按键。
这里我们可以改写成只有获取空格时才取消启动kernel,否则一律启动kernel:
static int __abortboot(int bootdelay)
{
int abort = 0;
unsigned long ts;
#ifdef CONFIG_MENUPROMPT
printf(CONFIG_MENUPROMPT);
#else
printf("Hit any key to stop autoboot: %2d ", bootdelay);
#endif
/*
* Check if key already pressed
*/
if (tstc()) { /* we got a key press */
puts("\b\b\b 0");
if(' ' == getc())/*add 2017.10.17*///if got space
abort = 1; /* don't auto boot */
}
while ((bootdelay > 0) && (!abort)) {
--bootdelay;
/* delay 1000 ms */
ts = get_timer(0);
do {
if (tstc()&&(' ' == getc()) ) {//add kite 2017.10.17//if got space
abort = 1; /* don't auto boot */
bootdelay = 0; /* no more delay */
# ifdef CONFIG_MENUKEY
menukey = getc();
# else
//(void) getc();delete 2017.10.17 /* consume input */
# endif
break;
}
udelay(10000);
} while (!abort && get_timer(ts) < 1000);
printf("\b\b\b%2d ", bootdelay);
}
putc('\n');
return abort;
}
这样,我们不接串口的情况下,也不会干扰到我们启动kernel了