register_console的理解

前面我们知道注册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
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值