简体   繁体   English

Mips Linux:将内核Panic记录到mtd分区中

[英]Mips Linux: Logging Kernel Panic into mtd partition

We are experiencing kernel panics in the field for our MIPS based embedded devices. 我们在基于MIPS的嵌入式设备领域遇到内核恐慌。 How can I log the kernel panic trace in the MTD partition? 如何在MTD分区中记录内核恐慌跟踪? Do we have to write the trace only into MTD or is it possible to write over the NFS? 我们是否必须仅将跟踪写入MTD还是可以覆盖NFS? Can anyone explain how to get useful kernel traces after the panic for the remote boxes. 谁能解释一下在出现紧急情况之后,如何获得有用的内核跟踪。

You can turn on mtdoops module in the kernel and log the kernel panic traces on to mtd partition. 您可以在内核中打开mtdoops模块,并将内核恐慌跟踪记录到mtd分区上。 I don't think we can write the panic trace over NFS. 我认为我们无法在NFS上写出恐慌痕迹。 However, you may want to explore about ramoops. 但是,您可能需要探索有关ramoop的知识。

The following are the steps to configure the kernel to capture the kernel oops on to the mtd flash. 以下是配置内核以捕获mtd闪存上的内核oops的步骤。 Capturing the stack trace after the kernel panic is invaluable to debug the kernel problems particularly the ones happening in the field. 内核崩溃后捕获堆栈跟踪信息对于调试内核问题(特别是在现场发生的问题)非常有用。 During mtdoops module init, the mtd partition is turned into a circular buffer and erased beforehand. 在mtdoops模块初始化期间,会将mtd分区转换为循环缓冲区并事先擦除。

  1. The kernel flag, CONFIG_MTD_OOPS , configures the kernel to write the oops stack trace on to the MTD partition. 内核标志CONFIG_MTD_OOPS将内核配置为将oops堆栈跟踪写入MTD分区。 This MTD dev partition information can be hard coded inside mtdoops module or can be specified dynamically. 该MTD开发人员分区信息可以在mtdoops模块中进行硬编码,也可以动态指定。 This component can be built as part of kernel or as an separate module. 该组件可以作为内核的一部分或作为单独的模块构建。 Before building the kernel, you need to make sure that your mtd device has registered a panic_write handler. 在构建内核之前,您需要确保您的mtd设备已经注册了panic_write处理程序。 Remember, normal mtd write handler won't be enough as we have to write to mtd memory after kernel panic. 记住,普通的mtd写入处理程序还不够,因为我们必须在内核崩溃后写入mtd内存。 Please run this patch if the mtd device doesn't have its own a panic write handler. 如果mtd设备没有自己的紧急写入处理程序,请运行补丁。

    When built as part of the kernel, CONFIG_MTD_OOPS=y , the mtdoops module needs to be patched with the flash partition information (mtddev). 当作为内核的一部分CONFIG_MTD_OOPS = y构建时,需要使用闪存分区信息(mtddev)修补mtdoops模块。

 --- ./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"); 

While building it as a module, CONFIG_MTD_OOPS=m, the flash partition information is provided dynamically during module installation (insmod). 在将其构建为模块CONFIG_MTD_OOPS = m时,将在模块安装(insmod)期间动态提供闪存分区信息。

insmod mtdoops.ko mtddev=/dev/oops insmod mtdoops.ko mtddev = / dev / oops

In addition to enable the MTP OOPS flags, do configure, CONFIG_MAGIC_SYSRQ, to induce the panic and to test this functionality. 除了启用MTP OOPS标志外,还要配置CONFIG_MAGIC_SYSRQ,以引起恐慌并测试此功能。

  1. Now, we need to create a MTD partition (/dev/Oops) to store the panic traces. 现在,我们需要创建一个MTD分区(/ dev / Oops)以存储紧急跟踪。 MTD can be partitioned by modifying the memory layout and partition information defined in the kernel sources at arch///.c . 可以通过修改arch ///。c内核源中定义的内存布局和分区信息来对MTD进行分区。 Also, you need to be aware that the partition information passed as part of kernel command line will overrides board.c changes. 另外,您还需要注意,作为内核命令行的一部分传递的分区信息将覆盖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. Build the kernel and mtdoops.ko will get built as part of the root file system. 构建内核,mtdoops.ko将作为根文件系统的一部分被构建。 Install the file system and make sure that the partition gets created. 安装文件系统,并确保已创建分区。
 cat /proc/mtd dev: size erasesize name mtd0: 000e0000 00020000 "loader" mtd1: 002a0000 00020000 "kernel" mtd3: 000e0000 00020000 "Oops" mtd5: 08000000 00020000 "all" 
  1. Now, trigger the panic using Magic SysRq keys and observe the kernel panic logs in the Oops partition. 现在,使用Magic SysRq键触发紧急情况,并观察Oops分区中的内核紧急情况日志。

Thanks so much for the detailed steps. 非常感谢您的详细步骤。 Everything seems to be fine, except the device name. 除了设备名称,其他一切似乎都很好。 When I give the device name as "/dev/oops" mtdoops is not attached to any device in the boot message. 当我将设备名称指定为“ / dev / oops”时,mtdoops不会在启动消息中附加到任何设备。 After a level of debugging , I found that the device name shall be just "oops" or "Partition number" ie (if your oops partition is mtd9 just give "9" as partition number). 经过一定程度的调试后,我发现设备名称应为“ oops”或“分区号”,即(如果您的oops分区为mtd9,则只需输入“ 9”作为分区号)。 After changing it , it started working. 更改后,它开始工作。 I am able to see the logs using sp-oops-extract. 我可以使用sp-oops-extract查看日志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM