Pstore qemu

Introduction
These instructions are useful for anyone trying to setup PSTORE with Qemu.

Configuring Qemu
To get your pstore setup up and running, you need to run Qemu. Have you run this before? I suggest to use Qemu for this project since it also allows to test kernels more easily.

To create a "simulated pstore" with Qemu, pass the follow options to Qemu in addition to any other options you are already passing. This creates a memory-backed DIMM which will be used as file-backed physical RAM that is backing the pstore:

-m ${RAM_SIZE}M,slots=2,maxmem=${MAX_SIZE}M                                                     \ -object memory-backend-file,id=mem1,share=on,mem-path=nvdimm.img,size=${NVDIMM_SIZE}M,align=128M \ -device nvdimm,id=nvdimm1,memdev=mem1                                                           \

The environment variables can be set as follows: RAM_SIZE=2024 NVDIMM_SIZE=128 MAX_SIZE=$(( RAM_SIZE + NVDIMM_SIZE ))

In addition to this, pass the following kernel command line options to let the kernel know about the pstore area. This can be done by using the -append command line option and passing it ramoops.mem_address=0x140000000 ramoops.mem_size=204800 ramoops.ecc=1

My full Qemu command line with all these changes looks like the following: RAM_SIZE=2024 NVDIMM_SIZE=128 MAX_SIZE=$(( RAM_SIZE + NVDIMM_SIZE ))

qemu-system-x86_64 -kernel $KIMG -append "console=ttyS0                                                \        ramoops.mem_address=0x140000000 ramoops.mem_size=204800 ramoops.ecc=1"                           \ -machine pc,nvdimm                                                                              \ -m ${RAM_SIZE}M,slots=2,maxmem=${MAX_SIZE}M                                                     \ -object memory-backend-file,id=mem1,share=on,mem-path=nvdimm.img,size=${NVDIMM_SIZE}M,align=128M \ -device nvdimm,id=nvdimm1,memdev=mem1                                                           \ -enable-kvm                                                                                     \ -smp 16                                                                                         \ -s -nographic

Additional kernel build steps for PSTORE
Edit .config and make sure the following options are enabled (=y): CONFIG_PSTORE=y CONFIG_PSTORE_FTRACE=y CONFIG_PSTORE_PMSG=y CONFIG_PSTORE_RAM=y

This sets up a 2152MB RAM out of which 128MB is used for pstore and 2024MB is used for regular physical memory. Any writes to the 128MB RAM area will be directly sent to the file.