Sergiu Iordache | 4126dac | 2011-08-13 12:34:56 -0700 | [diff] [blame] | 1 | Ramoops oops/panic logger |
| 2 | ========================= |
| 3 | |
| 4 | Sergiu Iordache <sergiu@chromium.org> |
| 5 | |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 6 | Updated: 17 November 2011 |
Sergiu Iordache | 4126dac | 2011-08-13 12:34:56 -0700 | [diff] [blame] | 7 | |
| 8 | 0. Introduction |
| 9 | |
| 10 | Ramoops is an oops/panic logger that writes its logs to RAM before the system |
| 11 | crashes. It works by logging oopses and panics in a circular buffer. Ramoops |
| 12 | needs a system with persistent RAM so that the content of that area can |
| 13 | survive after a restart. |
| 14 | |
| 15 | 1. Ramoops concepts |
| 16 | |
Tony Lindgren | 027bc8b0 | 2014-09-16 13:50:01 -0700 | [diff] [blame] | 17 | Ramoops uses a predefined memory area to store the dump. The start and size |
| 18 | and type of the memory area are set using three variables: |
Sergiu Iordache | 4126dac | 2011-08-13 12:34:56 -0700 | [diff] [blame] | 19 | * "mem_address" for the start |
| 20 | * "mem_size" for the size. The memory size will be rounded down to a |
| 21 | power of two. |
Tony Lindgren | 027bc8b0 | 2014-09-16 13:50:01 -0700 | [diff] [blame] | 22 | * "mem_type" to specifiy if the memory type (default is pgprot_writecombine). |
| 23 | |
| 24 | Typically the default value of mem_type=0 should be used as that sets the pstore |
| 25 | mapping to pgprot_writecombine. Setting mem_type=1 attempts to use |
| 26 | pgprot_noncached, which only works on some platforms. This is because pstore |
| 27 | depends on atomic operations. At least on ARM, pgprot_noncached causes the |
| 28 | memory to be mapped strongly ordered, and atomic operations on strongly ordered |
| 29 | memory are implementation defined, and won't work on many ARMs such as omaps. |
Sergiu Iordache | 4126dac | 2011-08-13 12:34:56 -0700 | [diff] [blame] | 30 | |
| 31 | The memory area is divided into "record_size" chunks (also rounded down to |
| 32 | power of two) and each oops/panic writes a "record_size" chunk of |
| 33 | information. |
| 34 | |
| 35 | Dumping both oopses and panics can be done by setting 1 in the "dump_oops" |
| 36 | variable while setting 0 in that variable dumps only the panics. |
| 37 | |
| 38 | The module uses a counter to record multiple dumps but the counter gets reset |
| 39 | on restart (i.e. new dumps after the restart will overwrite old ones). |
| 40 | |
Anton Vorontsov | 39eb7e97 | 2012-05-17 00:15:34 -0700 | [diff] [blame] | 41 | Ramoops also supports software ECC protection of persistent memory regions. |
| 42 | This might be useful when a hardware reset was used to bring the machine back |
| 43 | to life (i.e. a watchdog triggered). In such cases, RAM may be somewhat |
| 44 | corrupt, but usually it is restorable. |
| 45 | |
Sergiu Iordache | 4126dac | 2011-08-13 12:34:56 -0700 | [diff] [blame] | 46 | 2. Setting the parameters |
| 47 | |
| 48 | Setting the ramoops parameters can be done in 2 different manners: |
| 49 | 1. Use the module parameters (which have the names of the variables described |
| 50 | as before). |
Anton Vorontsov | 958502d | 2012-05-26 06:20:25 -0700 | [diff] [blame] | 51 | For quick debugging, you can also reserve parts of memory during boot |
| 52 | and then use the reserved memory for ramoops. For example, assuming a machine |
| 53 | with > 128 MB of memory, the following kernel command line will tell the |
| 54 | kernel to use only the first 128 MB of memory, and place ECC-protected ramoops |
| 55 | region at 128 MB boundary: |
| 56 | "mem=128M ramoops.mem_address=0x8000000 ramoops.ecc=1" |
Sergiu Iordache | 4126dac | 2011-08-13 12:34:56 -0700 | [diff] [blame] | 57 | 2. Use a platform device and set the platform data. The parameters can then |
| 58 | be set through that platform data. An example of doing that is: |
| 59 | |
Anton Vorontsov | 1894a25 | 2012-05-16 05:43:08 -0700 | [diff] [blame] | 60 | #include <linux/pstore_ram.h> |
Sergiu Iordache | 4126dac | 2011-08-13 12:34:56 -0700 | [diff] [blame] | 61 | [...] |
| 62 | |
| 63 | static struct ramoops_platform_data ramoops_data = { |
| 64 | .mem_size = <...>, |
| 65 | .mem_address = <...>, |
Tony Lindgren | 027bc8b0 | 2014-09-16 13:50:01 -0700 | [diff] [blame] | 66 | .mem_type = <...>, |
Sergiu Iordache | 4126dac | 2011-08-13 12:34:56 -0700 | [diff] [blame] | 67 | .record_size = <...>, |
| 68 | .dump_oops = <...>, |
Anton Vorontsov | 39eb7e97 | 2012-05-17 00:15:34 -0700 | [diff] [blame] | 69 | .ecc = <...>, |
Sergiu Iordache | 4126dac | 2011-08-13 12:34:56 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | static struct platform_device ramoops_dev = { |
| 73 | .name = "ramoops", |
| 74 | .dev = { |
| 75 | .platform_data = &ramoops_data, |
| 76 | }, |
| 77 | }; |
| 78 | |
| 79 | [... inside a function ...] |
| 80 | int ret; |
| 81 | |
| 82 | ret = platform_device_register(&ramoops_dev); |
| 83 | if (ret) { |
| 84 | printk(KERN_ERR "unable to register platform device\n"); |
| 85 | return ret; |
| 86 | } |
| 87 | |
Anton Vorontsov | 958502d | 2012-05-26 06:20:25 -0700 | [diff] [blame] | 88 | You can specify either RAM memory or peripheral devices' memory. However, when |
| 89 | specifying RAM, be sure to reserve the memory by issuing memblock_reserve() |
| 90 | very early in the architecture code, e.g.: |
| 91 | |
| 92 | #include <linux/memblock.h> |
| 93 | |
| 94 | memblock_reserve(ramoops_data.mem_address, ramoops_data.mem_size); |
| 95 | |
Sergiu Iordache | 4126dac | 2011-08-13 12:34:56 -0700 | [diff] [blame] | 96 | 3. Dump format |
| 97 | |
| 98 | The data dump begins with a header, currently defined as "====" followed by a |
| 99 | timestamp and a new line. The dump then continues with the actual data. |
| 100 | |
| 101 | 4. Reading the data |
| 102 | |
Kees Cook | 9ba80d9 | 2012-05-03 15:45:02 +1000 | [diff] [blame] | 103 | The dump data can be read from the pstore filesystem. The format for these |
| 104 | files is "dmesg-ramoops-N", where N is the record number in memory. To delete |
| 105 | a stored record from RAM, simply unlink the respective pstore file. |
Anton Vorontsov | a694d1b | 2012-07-09 17:10:44 -0700 | [diff] [blame] | 106 | |
| 107 | 5. Persistent function tracing |
| 108 | |
| 109 | Persistent function tracing might be useful for debugging software or hardware |
| 110 | related hangs. The functions call chain log is stored in a "ftrace-ramoops" |
| 111 | file. Here is an example of usage: |
| 112 | |
| 113 | # mount -t debugfs debugfs /sys/kernel/debug/ |
Anton Vorontsov | 65f8c95 | 2012-07-17 14:26:15 -0700 | [diff] [blame] | 114 | # echo 1 > /sys/kernel/debug/pstore/record_ftrace |
Anton Vorontsov | a694d1b | 2012-07-09 17:10:44 -0700 | [diff] [blame] | 115 | # reboot -f |
| 116 | [...] |
| 117 | # mount -t pstore pstore /mnt/ |
| 118 | # tail /mnt/ftrace-ramoops |
| 119 | 0 ffffffff8101ea64 ffffffff8101bcda native_apic_mem_read <- disconnect_bsp_APIC+0x6a/0xc0 |
| 120 | 0 ffffffff8101ea44 ffffffff8101bcf6 native_apic_mem_write <- disconnect_bsp_APIC+0x86/0xc0 |
| 121 | 0 ffffffff81020084 ffffffff8101a4b5 hpet_disable <- native_machine_shutdown+0x75/0x90 |
| 122 | 0 ffffffff81005f94 ffffffff8101a4bb iommu_shutdown_noop <- native_machine_shutdown+0x7b/0x90 |
| 123 | 0 ffffffff8101a6a1 ffffffff8101a437 native_machine_emergency_restart <- native_machine_restart+0x37/0x40 |
| 124 | 0 ffffffff811f9876 ffffffff8101a73a acpi_reboot <- native_machine_emergency_restart+0xaa/0x1e0 |
| 125 | 0 ffffffff8101a514 ffffffff8101a772 mach_reboot_fixups <- native_machine_emergency_restart+0xe2/0x1e0 |
| 126 | 0 ffffffff811d9c54 ffffffff8101a7a0 __const_udelay <- native_machine_emergency_restart+0x110/0x1e0 |
| 127 | 0 ffffffff811d9c34 ffffffff811d9c80 __delay <- __const_udelay+0x30/0x40 |
| 128 | 0 ffffffff811d9d14 ffffffff811d9c3f delay_tsc <- __delay+0xf/0x20 |