printk 中console_cmdline数组的填充

来源:互联网 发布:底层软件开发 编辑:程序博客网 时间:2024/05/22 00:32
在printk.c 中有定义一个数组
static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES];其中MAX_CMDLINECONSOLES等于8,表示cmdline最多可以传递8个console
要填充这个数组有两种方式,
一种是在console driver中主动调用add_preferred_console
例如    add_preferred_console("hvc", index, NULL);

第二种是通过传递console 这个commmand line,这个参数可以传递多个,例如console=tty0,console=ttyS0等
static int __init console_setup(char *str)
{
    char buf[sizeof(console_cmdline[0].name) + 4]; /* 4 for "ttyS" */
    char *s, *options, *brl_options = NULL;
    int idx;

    if (_braille_console_setup(&str, &brl_options))
        return 1;

    /*
     * Decode str into name, index, options.
     */
    if (str[0] >= '0' && str[0] <= '9') {
        strcpy(buf, "ttyS");
        strncpy(buf + 4, str, sizeof(buf) - 5);
    } else {
        strncpy(buf, str, sizeof(buf) - 1);
    }
    buf[sizeof(buf) - 1] = 0;
    options = strchr(str, ',');
    if (options)
        *(options++) = 0;
#ifdef __sparc__
    if (!strcmp(str, "ttya"))
        strcpy(buf, "ttyS0");
    if (!strcmp(str, "ttyb"))
        strcpy(buf, "ttyS1");
#endif
    for (s = buf; *s; s++)
        if (isdigit(*s) || *s == ',')
            break;
    idx = simple_strtoul(s, NULL, 10);
    *s = 0;

    __add_preferred_console(buf, idx, options, brl_options);
    console_set_on_cmdline = 1;
    return 1;
}
如果传递console的话,主要通过这个函数解析的,可以看到如果传递的是ttyS0的话,可以简写成console=0.这个数字是0~9
这个函数最终也是调用__add_preferred_console 将自己添加到console_cmdline 数组中。console_set_on_cmdline 这个参数只在suncore.c中有使用
    if (!console_set_on_cmdline) {
        con->index = line;
        add_preferred_console(con->name, line, NULL);
    }



0 0