console 启动流程:
start_kernel–>parse_args–>parse_early_options–>parse_args–>do_early_param–>console_setup–>__add_preferred_console–>console_cmdline[i],在该函数内部,将控制台参数保存到到了全局变量结构体console_cmdline[i]中。
console_cmdline 结构体:
struct console_cmdline
{
char name[8]; /* Name of the driver */
int index; /* Minor dev. to use */
char *options; /* Options for the driver */
#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
char *brl_options; /* Options for braille driver */
#endif
};
console_cmdline[MAX_CMDLINECONSOLES ] 是一个全局变量,最多可以存放MAX_CMDLINECONSOLES 个kernel启动参数cmdline.
#define MAX_CMDLINECONSOLES 8
static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES];
static int selected_console = -1;
static int preferred_console = -1;
int console_set_on_cmdline;
EXPORT_SYMBOL(console_set_on_cmdline);
kernel/printk中注册了’console='的解析函数console_setup(),找到匹配成功以后会调用console_setup来解析 , 参数值是console=的字符串,例如"ttyS0, 115200".
static int __init console_setup(char *str)
{
char buf[sizeof(console_cmdline[0].name) + 4]; /* 4 for index */
char *s, *options, *brl_options = NULL;
int idx;
#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
if (!memcmp(str, "brl,", 4)) {
brl_options = "";
str += 4;
} else if (!memcmp(str, "brl=", 4)) {
brl_options = str + 4;
str = strchr(brl_options, ',');
if (!str) {
printk(KERN_ERR "need port name after brl=\n");
return 1;
}
*(str++) = 0;
}
#endif
/*
* 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