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