我能够检测和调试内核崩溃,这要归功于@0andriy的评论。
如何在重新启动后检测内核崩溃。
在内核defconfig中启用ramoops:
+CONFIG_PSTORE=y
+CONFIG_PSTORE_ZLIB_COMPRESS=y
+CONFIG_PSTORE_CONSOLE=y
+CONFIG_PSTORE_RAM=y
在内核板初始化中添加代码来声明ramoops内存空间,你也可以使用设备树甚至在内核procline中使用参数。这是一个使用代码方法的示例,在我的用例中它位于arch/arm/mach-imx/mach-imx6ul.c文件中。
--- a/arch/arm/mach-imx/mach-imx6ul.c
+++ b/arch/arm/mach-imx/mach-imx6ul.c
@@ -21,6 +21,24 @@
#include "cpuidle.h"
#include "hardware.h"
+#include <linux/pstore_ram.h>
+#include <linux/memblock.h>
+
+static struct ramoops_platform_data ramoops_data = {
+ .mem_address = 0xXXXXXXXX,
+ .mem_size = 0x00005000,
+ .record_size = 0x00002000,
+ .dump_oops = 1,
+};
+
+static struct platform_device ramoops_dev = {
+ .name = "ramoops",
+ .dev = {
+ .platform_data = &ramoops_data,
+ },
+};
+
+
static void __init imx6ul_enet_clk_init(void)
{
struct regmap *gpr;
@@ -170,6 +188,14 @@ static inline void imx6ul_enet_init(void)
static void __init imx6ul_init_machine(void)
{
struct device *parent;
+ int ret;
+
+ ret = platform_device_register(&ramoops_dev);
+ if (ret) {
+ printk(KERN_ERR "unable to register platform device\n");
+ return;
+ }
+ memblock_reserve(ramoops_data.mem_address, ramoops_data.mem_size);
parent = imx_soc_device_init();
if (parent == NULL)
在启动时,我只需要检查ramoops的内容,以查看是否有可用的内核崩溃日志。我可以使用以下命令挂载ramoops内存空间:
mount -t pstore -o kmsg_bytes=1000 - /sys/fs/pstore
panic.c
来切换一些LED(如果有的话),或将一些命令发送回UART,或在LCD上显示一些数据;任何事情,但请尽量避免在内核崩溃期间访问文件系统。 - Gaurav Pathakpstore
和ramoops
。 - 0andriy