User:Knuxfanwin8/Enabling pstore and ramoops

If you don't have a serial cable, and your device's downstream kernel does not support the android ramconsole driver, you might need to set up pstore and ramoops instead.

pstore
pstore is a persistent storage driver. It saves data in a reserved part of memory, which can then be read from a working kernel. Its primary purpose is to save kernel crash logs to memory.

ramoops
From the documentation:

Ramoops is an oops/panic logger that writes its logs to RAM before the system crashes. It works by logging oopses and panics in a circular buffer. Ramoops needs a system with persistent RAM so that the content of that area can survive after a restart.

Kernel configuration
To enable pstore and use the ramoops backend, make sure the following kernel options are set:

They can be found under.

On older kernels without  and , you'll need to enable

(found under ) instead of. Note that this will only allow you to preview kernel oopses/panics. If you need to get full kernel logs, you can either set up the ram_console driver (see "Android ram_console driver setup" section below) or backport CONFIG_PSTORE_RAM (see patches here).

Configuring ramoops
Follow the guide in the ramoops documentation (you only need to do one of the steps). Make sure that the memory address you reserve and its size is the same in your downstream and mainline configuration, or else you won't be able to read the information.

Reading from pstore
Now you can mount the pstore partition:

Android ram_console driver setup
For devices with older downstream kernels without  (kernels below v3.6(-rc1)) it may be easier to set up the ram_console driver.

Backporting the driver
Copy the driver from the p4wifi tree.

Kernel configuration
Make sure  is set to.

Configuring ram_console
This process will differ depending on your downstream kernel version.

If you backported the driver from p4wifi or your downstream kernel had the same driver
If you didn't have the ram_console driver because the kernel was too new (>3.6) and you copied it from the p4wifi tree, or if your downstream kernel was old enough to contain that version of the driver, follow the steps below.

In downstream, define the ram_console platform device:

Then, find the init function of your device (usually near the end of the file) and add the following lines:

Where  is the base address and   is the size of the buffer.

In upstream, reserve memory in the device tree:

Then in your board.c file (could be your chipset's, but only temporarily) define the ram_console platform device as outlined above.

If your board.c file does not have an init function, add one:

If you had separate ram_console and persistent_ram drivers
The setup process is different for kernels with separate persistent_ram and ram_console drivers. This applies to kernel 3.4.

In downstream, add the following to the includes of your device's board.c file (skip the ones you have already):

Then define the initialization functions:

Replace  with the ram console size, and   with the address at which you want to reserve the ram console.

Then, find your reserve function (look for  around the end of the board file). If it doesn't exist, define it and add it.

To your reserve function, add the following:

Then add the following to your init function:

Then follow the upstream setup section from the previous section.

Reading from the logs
In your downstream kernel, do:

I set my ramoops parameters in my kernel cmdline and it doesn't work!
If you added the ramoops parameters to  and they seem to be ignored, and there's a similar message in the dmesg:

~ # dmesg | grep ramoops <6>[   3.009338] C0 [      swapper/0] ramoops: platform device not found, using module parameters <3>[   3.009735] C0 [      swapper/0] ramoops: The memory size and the record size must be non-zero <4>[   3.009765] C0 [      swapper/0] ramoops: probe of ramoops failed with error -22

check if you don't have  set. If you do, set  to.

You're usually able to check the used cmdline at the beggining of the dmesg.

~ # dmesg | grep "Kernel command line" <5>[   0.000000] C0 [        swapper] Kernel command line: ...