Printk Behaviour Change with Early_Printk Enabled

Normally printk does not print any messages before console_init which is present in start_kernel. But with early_printk enabled, printk starts printing messages before console initialization. Now how does this behaviour of printk change since I am still using printk function to print debug messages and not early_printk function. How is this mapping done?

1 Answer

It's not really a mapping. When early_printk is enabled, the same printk() is used as before, just new boot console is being registered in that case, and printk() uses it on early boot stages.

Look at arch/arm/kernel/early_printk.c. You can see that:

  • new console being registered with register_console() function
  • that console has CON_BOOT flag, so it's unregistered automatically as soon as real console is registered
  • printing happens via early_write() function, which in turn uses printch() function, which implemented for each platform separately

Where in kernel source the early_console is disabled after kernel console initialization?

It's done in register_console() function:

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);
}

All boot consoles are disabled by unregister_console() function in code above (when real console is being registered).

And where is the real console getting registered?

Real consoles use the same method for registration -- register_console() function. For example:

Is there any way to keep boot consoles up after console initialization and disable real console?

Boot consoles are automatically unregistered only when real console is registered. Following this logic, you just need to disable the real console in order to keep boot console intact.

So what you need to do, is to find out which exactly driver is used for real console in your case. You can do that looking into your .config file, or the *_defconfig file for your board. Once you located it, just disable that driver in configuration and rebuild the kernel.

If after doing so you keep observing the registering of some real console, you need to add some debug printings to register_console(), to figure out what driver is being registered, and then disable it in your configuration.

10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest