kernel的source code中有很多使用pr_debug/dev_dbg输出的日志信息(例如device tree解析的代码,drivers/of/fdt.c)。
默认情况下,kernel不会将这些日志信息输出到控制台上,除非:
1)开启 DEBUG 宏
2)控制台日志级别 >= 8
具体操作如下:
1)开启DEBUG宏
在需要pr_debug/dev_dbg输出的模块开头,直接#define DEBUG即可,kernel中有一个例子:
/* init/main.c */
#define DEBUG /* Enable initcall_debug */
或者
在需要pr_debug/dev_dbg输出的源文件所在目录中的Makefile,加入
EXTRA_CFLAGS += -DDEBUG
注意:只有#define DEBUG后,相关日志信息才会编译进去内核镜像zImage/Image/uImage。
才能用dmesg查看到相关日志信息,但是串口控制台想要看到日志信息,还需要设置以下第二步。
2)控制台日志级别 >= 8,基于dts设置如下
chosen {
bootargs = "earlyprintk console=ttyFIQ0 rw root=PARTUUID=614e0000-0000 rootfstype=ext4 rootwait loglevel=8";
};
参考链接:
Linux kernel debug技巧----开启DEBUG选项