1。console的过程描述
例如pmon下其内核命令 g console=ttyS0,115200 root=/dev/sda1 init=/bin/sh rw
对console的过程讨论主要是讨论console=ttyS0 如何影响选取哪种console?
在kernel/printk.c中的
__setup("console=", console_setup);
给出了用于解释console=ttyS0的函数console_setup
console_setup调用的__add_preferred_console确定了ttyS0在console_cmdline[]的索引号selected_console
2、从uart驱动到console
具体调用过程,
uart_probe------>uart_add_one_port----->uart_configure_port------->register_console
register_console有如下语句:
1196 if (i == selected_console) {
1198 console->flags |= CON_CONSDEV;
1199 preferred_console = selected_console;
1200 }
在i的循环中当regist的console名字与console_cmdline[selected_console]的名字相同时console->flags |= CON_CONSDEV
如下语句:
1223 if ((console->flags & CON_CONSDEV) || console_drivers == NULL) {
1224 console->next = console_drivers;
1225 console_drivers = console;
1226 if (console->next)
1227 console->next->flags &= ~CON_CONSDEV;
1228 } else {
1229 console->next = console_drivers->next;
1230 console_drivers->next = console;
1231 }
可知,在console_drivers链表中,只有与console_cmdline[selected_console]的名字相同console放在链表首位。
由此可得console=ttyS0实际上是保证console_drivers链表的首个console是名称为ttyS的console
3、从printk到console
printk --------------------------------------kernel/printk.c
printk处理完参数后调用vprintk
vprintk --------------------------------------kernel/printk.c
vprintk调用emit_log_char 将字符填充进log_buff中,并调用release_console_sem()将字符打印出
release_console_sem --------------------------kernel/printk.c
函数的本意是释放信号量,但同时调用了call_console_drivers(_con_start, _log_end)将log_buff中的字符打印出。
call_console_drivers ------------------------kernel/printk.c
调用_call_console_drivers打印字符
_call_console_drivers-------------------------kernel/printk.c
调用__call_console_drivers打印字符
__call_console_drivers------------------------kernel/printk.c
__call_console_drivers中语句如下:
436 for (con = console_drivers; con; con = con->next) {
437 if ((con->flags & CON_ENABLED) && con->write &&
438 (cpu_online(smp_processor_id()) ||
439 (con->flags & CON_ANYTIME)))
440 con->write(con, &LOG_BUF(start), end - start);
441 }
由此可见,printk最终会调用到uart驱动中注册的console。
阅读(2716) | 评论(0) | 转发(0) |