通过串口看到printk打印信息的方法

[复制链接]
975|0
 楼主| keer_zu 发表于 2020-3-19 14:31 | 显示全部楼层 |阅读模式
本帖最后由 keer_zu 于 2020-3-19 14:33 编辑

通过串口看到内核的打印对于调试内核是十分必要的,否则只能dmesg看到过期的累积信息。

通过串口显示printk打印信息,需要修改内核以下部分,重新编译内核生成镜像文件,下载到硬件系统,就可以了。
需要修改的文件linux-kernel/kernel/printk/printk.c

  1. 1415 static void call_console_drivers(int level, const char *text, size_t len)
  2. 1416 {
  3. 1417     struct console *con;
  4. 1418  
  5. 1419     trace_console(text, len);
  6. 1420  
  7. 1421     if (level >= console_loglevel && !ignore_loglevel)
  8. 1422         return;
  9. 1423     if (!console_drivers)
  10. 1424         return;
  11. 1425 #if 0  // #ifndef CONFIG_DYNAMIC_DEBUG
  12. 1426     if (!perf_mode_console)
  13. 1427         return;
  14. 1428 #endif
  15. 1429  
  16. 1430     for_each_console(con) {
  17. 1431         if (exclusive_console && con != exclusive_console)
  18. 1432             continue;
  19. 1433         if (!(con->flags & CON_ENABLED))
  20. 1434             continue; ………
  21. 1441     }
  22. 1442 }

只需要将上面代码中的宏开关关闭即可,使用 #if 0  代替 #ifndef CONFIG_DYNAMIC_DEBUG


您需要登录后才可以回帖 登录 | 注册

本版积分规则

1488

主题

12949

帖子

55

粉丝
快速回复 在线客服 返回列表 返回顶部