前面我们知道注册earlycon和console 最终都是调用register_console 这个函数,这个函数有几点需要注意一下
1:可以注册多个console,但是不能重复注册。且earlycon只能有一个。
if (console_drivers)
for_each_console(bcon)
if (WARN(bcon == newcon,
"console '%s%d' already registered\n",
bcon->name, bcon->index))
return;
这段code 就会比较现在要注册的console是否已经注册,如果已经注册就直接return了,如果没有注册就继续往下走进行注册
if (console_drivers && newcon->flags & CON_BOOT) {
/* find the last or real console */
for_each_console(bcon) {
if (!(bcon->flags & CON_BOOT)) {
pr_info("Too late to register bootconsole %s%d\n",
newcon->name, newcon->index);
return;
}
}
}
这段code就证明earlycon 只能有一个,判断是否earlycon只要是看是否有CON_BOOT。
if (console_drivers && console_drivers->flags & CON_BOOT)
bcon = console_drivers;
这段code就是给bcon赋值代表earlycon
2:当console 注册时,earlycon就会被卸载掉
if (bcon &&
((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV) &&
!keep_bootcon) {
/* We need to iterate through all boot consoles, to make
* sure we print everything out, before we unregister them.
*/
for_each_console(bcon)
if (bcon->flags & CON_BOOT)
unregister_console(bcon);
}
可见bcon不为null,且新注册的console含有CON_CONSDEV的flag,且keep_bootcon=0,也就没有通过cmdline 让kernel保留earlycon的话,就卸载掉earlycon
如果要通过cmdline保留earlycon,可以通过下面的方式进行.
static int __init keep_bootcon_setup(char *str)
{
keep_bootcon = 1;
pr_info("debug: skip boot console de-registration.\n");
return 0;
}
early_param("keep_bootcon", keep_bootcon_setup);
1:可以注册多个console,但是不能重复注册。且earlycon只能有一个。
if (console_drivers)
for_each_console(bcon)
if (WARN(bcon == newcon,
"console '%s%d' already registered\n",
bcon->name, bcon->index))
return;
这段code 就会比较现在要注册的console是否已经注册,如果已经注册就直接return了,如果没有注册就继续往下走进行注册
if (console_drivers && newcon->flags & CON_BOOT) {
/* find the last or real console */
for_each_console(bcon) {
if (!(bcon->flags & CON_BOOT)) {
pr_info("Too late to register bootconsole %s%d\n",
newcon->name, newcon->index);
return;
}
}
}
这段code就证明earlycon 只能有一个,判断是否earlycon只要是看是否有CON_BOOT。
if (console_drivers && console_drivers->flags & CON_BOOT)
bcon = console_drivers;
这段code就是给bcon赋值代表earlycon
2:当console 注册时,earlycon就会被卸载掉
if (bcon &&
((newcon->flags & (CON_CONSDEV | CON_BOOT)) == CON_CONSDEV) &&
!keep_bootcon) {
/* We need to iterate through all boot consoles, to make
* sure we print everything out, before we unregister them.
*/
for_each_console(bcon)
if (bcon->flags & CON_BOOT)
unregister_console(bcon);
}
可见bcon不为null,且新注册的console含有CON_CONSDEV的flag,且keep_bootcon=0,也就没有通过cmdline 让kernel保留earlycon的话,就卸载掉earlycon
如果要通过cmdline保留earlycon,可以通过下面的方式进行.
static int __init keep_bootcon_setup(char *str)
{
keep_bootcon = 1;
pr_info("debug: skip boot console de-registration.\n");
return 0;
}
early_param("keep_bootcon", keep_bootcon_setup);