linux内核earlyprink,linux – 在启用early_printk的情况下更改Printk行为

通常,printk不会在start_kernel中出现的console_init之前打印任何消息.但是在启用early_printk的情况下,printk会在控制台初始化之前开始打印消息.现在printk的这种行为如何改变,因为我仍然使用printk函数来打印调试消息而不是early_printk函数.这个映射是如何完成的?

解决方法:

这不是一个映射.当启用early_printk时,使用与之前相同的printk(),在这种情况下只注册新的启动控制台,而printk()在早期启动阶段使用它.

>使用register_console()函数注册新控制台

>该控制台具有CON_BOOT标志,因此只要注册了真正的控制台,它就会自动取消注册

>打印通过early_write()函数进行,而该函数又使用printch()函数,该函数分别为每个平台实现

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

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

}

上面的代码中的unregister_console()函数禁用了所有启动控制台(正在注册真正的控制台时).

And where is the real console getting registered?

真实控制台使用相同的方法进行注册 – register_console()函数.例如:

>从我的主板的defconfig文件(arch/arm/configs/omap2plus_defconfig)我可以看到我的主板正在使用CONFIG_SERIAL_8250作为真正的控制台

>我们可以搜索在我的串行驱动程序中执行register_console()的位置;它是在univ8250_console_init()功能完成的

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

只有在注册真实控制台时,才会自动取消注册引导控制台.遵循这个逻辑,您只需要禁用真正的控制台,以保持启动控制台完好无损.

所以你需要做的是找出在你的情况下哪个驱动程序用于真正的控制台.您可以查看.config文件或您的电路板的* _defconfig文件.找到它后,只需在配置中禁用该驱动程序并重建内核即可.

如果在这样做后你继续观察一些真正的控制台的注册,你需要向register_console()添加一些调试打印,以找出正在注册的驱动程序,然后在你的配置中禁用它.

标签:linux,linux-kernel,arm,linux-device-driver

来源: https://codeday.me/bug/20190701/1351474.html

你可能感兴趣的:(linux内核earlyprink,linux – 在启用early_printk的情况下更改Printk行为)