你好!这里是风筝的博客,
欢迎和我一起交流。
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
if (tstc()) {
(void) getc();
puts("\b\b\b 0");
abort = 1;
}
while ((bootdelay > 0) && (!abort)) {
--bootdelay;
ts = get_timer(0);
do {
if (tstc()) {
abort = 1;
bootdelay = 0;
# ifdef CONFIG_MENUKEY
menukey = getc();
# else
(void) getc();
# 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
if (tstc()) {
puts("\b\b\b 0");
if(' ' == getc())
abort = 1;
}
while ((bootdelay > 0) && (!abort)) {
--bootdelay;
ts = get_timer(0);
do {
if (tstc()&&(' ' == getc()) ) {
abort = 1;
bootdelay = 0;
# ifdef CONFIG_MENUKEY
menukey = getc();
# else
# endif
break;
}
udelay(10000);
} while (!abort && get_timer(ts) < 1000);
printf("\b\b\b%2d ", bootdelay);
}
putc('\n');
return abort;
}
这样,我们不接串口的情况下,也不会干扰到我们启动kernel了