uclinux-2008R1-RC8(bf561)到VDSP5的移植(58): unable to open an initial console blog.
碰到一个郁闷的问题,提示” unable to open an initial console”后再没有下文了。
搜了下这个错误出现的位置,在init_post函数中:
if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
printk(KERN_WARNING "Warning: unable to open an initial console./n");
刚开始以为是没有正确建立/dev/console的缘故,但是跟踪进去后才发现不是那么回事,/dev/console已经正确的创建了,问题出现在tty_open函数。
在这个函数里,它首先取得console的tty_driver:
if (device == MKDEV(TTYAUX_MAJOR,1)) {
driver = console_device(&index);
if (driver) {
/* Don't let /dev/console block */
filp->f_flags |= O_NONBLOCK;
noctty = 1;
goto got_driver;
}
mutex_unlock(&tty_mutex);
return -ENODEV;
}
看下console_device的实现:
/*
* Return the console tty driver structure and its associated index
*/
struct tty_driver *console_device(int *index)
{
struct console *c;
struct tty_driver *driver = NULL;
acquire_console_sem();
for (c = console_drivers; c != NULL; c = c->next) {
if (!c->device)
continue;
driver = c->device(c, index);
if (driver)
break;
}
release_console_sem();
return driver;
}
它将查找所有可用的console,找到一个提供了tty_driver的console并返回。在内核中,实际使用的console由bfin_serial_console(drivers/serial/bfin_5xx.c)这个全局变量来描述。在这个结构体中提供了device回调函数用以取得这个console所使用的tty_driver:
static struct console bfin_serial_console = {
.name = BFIN_SERIAL_NAME,
.write = bfin_serial_console_write,
.device = uart_console_device,
.setup = bfin_serial_console_setup,
.flags = CON_PRINTBUFFER,
.index = -1,
.data = &bfin_serial_reg,
};