Mips Linux:将内核崩溃日志记录到mtd分区

6
我们在MIPS嵌入式设备中遇到了内核崩溃的问题。我该如何将内核崩溃跟踪记录在MTD分区中?我们必须将跟踪的内容仅写入MTD中,还是可以通过NFS进行覆盖写入?有人能解释一下如何在远程设备发生内核崩溃后获取有用的内核跟踪信息吗?
2个回答

7
你可以在内核中打开mtdoops模块并将内核崩溃跟踪记录到mtd分区。我认为我们不能将panic跟踪写入NFS。但是,您可能想探索ramoops。
以下是配置内核以将内核oops捕获到mtd闪存的步骤。在内核崩溃后捕获堆栈跟踪非常有价值,特别是在现场发生的问题。在mtdoops模块初始化期间,mtd分区被转换为循环缓冲区并预先擦除。
The kernel flag, CONFIG_MTD_OOPS, is used to configure the kernel to write the oops stack trace onto the MTD partition. This MTD dev partition information can be hard coded inside the mtdoops module or specified dynamically. This component can be built as part of the kernel or as a separate module. Before building the kernel, you need to ensure that your mtd device has registered a panic_write handler. Please note that a normal mtd write handler won't suffice as we have to write to mtd memory after kernel panic. If the mtd device does not have its own panic write handler, please run this patch. When built as part of the kernel, CONFIG_MTD_OOPS=y, the mtdoops module needs to be patched with the flash partition information (mtddev).
--- ./drivers/mtd/mtdoops.c.orig 2014-11-17 12:06:59.000000000 +0000
+++ ./drivers/mtd/mtdoops.c 2014-11-17 12:07:36.000000000 +0000
@@ -44,7 +44,7 @@
MODULE_PARM_DESC(record_size,
"record size for MTD OOPS pages in bytes (default 4096)");

-static char mtddev[80];
+static char mtddev[80]="/dev/oops";
module_param_string(mtddev, mtddev, 80, 0400);
MODULE_PARM_DESC(mtddev,
"name or index number of the MTD device to use");

在将其构建为模块时,需要使用CONFIG_MTD_OOPS=m,模块安装(insmod)期间动态提供闪存分区信息。

insmod mtdoops.ko mtddev=/dev/oops

除了启用MTP OOPS标志外,还需配置CONFIG_MAGIC_SYSRQ以引发紧急情况并测试此功能。

  1. 现在,我们需要创建一个MTD分区(/dev/Oops)来存储紧急情况的跟踪信息。可以通过修改内核源代码中定义的内存布局和分区信息来对MTD进行分区,在arch///.c中。另外,您需要知道作为内核命令行的一部分传递的分区信息将覆盖board.c的更改。
{
.name = "loader",
.size = 0x000E0000,
.offset = MTDPART_OFS_APPEND
},
{
.name = "kernel",
.size = 0x002A0000,
.offset = MTDPART_OFS_APPEND
},
{
.name = "oops",
.size = 0x000E0000,
.offset = MTDPART_OFS_APPEND
},
{
.name = "all",
.size = MTDPART_SIZ_FULL,
.offset = 0x00000000
},
  1. 编译内核时,mtdoops.ko会随着根文件系统一起构建。安装文件系统并确保分区已创建。
cat /proc/mtd
dev: size erasesize name
mtd0: 000e0000 00020000 "loader"
mtd1: 002a0000 00020000 "kernel"
mtd3: 000e0000 00020000 "Oops"
mtd5: 08000000 00020000 "all"
现在,使用Magic SysRq键触发紧急情况,并观察Oops分区中的内核紧急情况日志。

0
非常感谢详细的步骤。除了设备名称之外,一切似乎都很好。当我将设备名称设置为“/dev/oops”时,在启动消息中没有将mtdoops附加到任何设备上。经过一定程度的调试,我发现设备名称应该只是“oops”或“分区号”,即(如果您的oops分区是mtd9,则只需将“9”作为分区号)。更改后,它开始工作。我能够使用sp-oops-extract查看日志。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接