调试内核,驱动的最简单的方法,是使用printk函数打印信息.printk函数与用户空间的printf函数格式完全相同,它所打印的字符串头部可以加入""样式的字符,其中n为0~7,表示这条信息的记录级别,那我们的printk串口输出时,是调用串口1还是串口2还是输出到LCD上,是由uboot里面的bootargs的console=xxx(下面的讲解以ttySAC0为例子)决定,来找到对应的硬件处理函数输出打印信息,那么内核是怎样根据命令行参数确定printk的输出设备呢,在kernel/printk.c中有如下代码
/*先注册控制台信息*/
_setup("console=",console_setup);
*/
static int __init console_setup(char *str)
{
char name[sizeof(console_cmdline[0].name)];
char *s, *options;
int idx;
/*
* Decode str into name, index, options.
*/
if (str[0] >= '0' && str[0] <= '9') {
strcpy(name, "ttyS");
strncpy(name + 4, str, sizeof(name) - 5);
} else {
strncpy(name, str, sizeof(name) - 1);
}
name[sizeof(name) - 1] = 0;
if ((options = strchr(str,