linux pstore驅動分析和調試


1.簡介

pstore(persistent storage)

  主要用於存儲內核異常時的log信息。實現方式是,管理一塊“非易失性的存儲空間”,如不斷電的RAM或外部存儲,當系統異常時,將log信息寫到Pstore管理的存儲空間,直到下一次系統正常時,在將log讀出來,以文件形式提供給用戶使用。

  ramoops指的是采用ram保存oops信息的一個功能,在內核開關中用3個開關控制:PSTORE_CONSOLE控制是否保存控制台輸出,PSTORE_FTRACE控制是否保存函數調用序列,PSTORE_RAM控制是否保存panic/oops信息。

  pstore簡單來說就是一個小文件系統。主要是讀取Android設備內核日志時會用到該模塊。

 

2.整體框架

 

3. 配置

3.1. dts

32位操作系統如下配置

reserved-memory {

  #address-cells = <2>;

  #size-cells = <2>;

  ranges;

  reg = <0x50008000 0x100000>;

  reg-names = "reserved-memory ";

};

 

ramoops {

  compatible = "ramoops ";

  record-size = <0x0 0x20000>;

  console-size = <0x0 0x20000>;

  ftrace-size = <0x0 0x20000>;

  pmsg-size = <0x0 0x20000>;

  memory-region = <&reserved-memory>;

  status = "okay";

};

 

  由於dts指定的是物理地址,如果內核地址為0x40008000那么可以把pstore地址配置為0x50008000,留出256M空間給內核使用。reg這么配置是32位。每個日志是128KB,總大小是1M,最多可有8個。

 

3.2. Kconfig

文件路徑:linux/fs/pstore/Kconfig

部分內容如下

config PSTORE

tristate "Persistent store support"

select CRYPTO if PSTORE_COMPRESS

default n

help

   This option enables generic access to platform level

   persistent storage via "pstore" filesystem that can

   be mounted as /dev/pstore.  Only useful if you have

   a platform level driver that registers with pstore to

   provide the data, so you probably should just go say "Y"

   (or "M") to a platform specific persistent store driver

   (e.g. ACPI_APEI on X86) which will select this for you.

   If you don't have a platform persistent store driver,

   say N.

 

config PSTORE_CONSOLE

bool "Log kernel console messages"

depends on PSTORE

help

  When the option is enabled, pstore will log all kernel

  messages, even if no oops or panic happened.

 

config PSTORE_PMSG

bool "Log user space messages"

depends on PSTORE

help

  When the option is enabled, pstore will export a character

  interface /dev/pmsg0 to log user space messages. On reboot

  data can be retrieved from /sys/fs/pstore/pmsg-ramoops-[ID].

 

  If unsure, say N.

 

config PSTORE_FTRACE

bool "Persistent function tracer"

depends on PSTORE

depends on FUNCTION_TRACER

depends on DEBUG_FS

help

  With this option kernel traces function calls into a persistent

  ram buffer that can be decoded and dumped after reboot through

  pstore filesystem. It can be used to determine what function

  was last called before a reset or panic.

 

  If unsure, say N.

 

config PSTORE_RAM

tristate "Log panic/oops to a RAM buffer"

depends on PSTORE

depends on HAS_IOMEM

depends on HAVE_MEMBLOCK

select REED_SOLOMON

select REED_SOLOMON_ENC8

select REED_SOLOMON_DEC8

help

  This enables panic and oops messages to be logged to a circular

  buffer in RAM where it can be read back at some later point.

 

  Note that for historical reasons, the module will be named

  "ramoops.ko".

 

  For more information, see Documentation/admin-guide/ramoops.rst.

 

 

根據Kconfig文件,對應的配置選項為

選項

Kconfig選項

含義

PSTORE_CONSOLE

Log kernel console messages

內核日志信息

PSTORE_PMSG

Log user space messages

用戶日志信息

PSTORE_FTRACE

Persistent function tracer

函數調用關系

PSTORE_RAM

Log panic/oops to a RAM buffer"

內核崩潰或錯誤日志

 

3.3. makefile

文件路徑:fs/pstore/makefile

# SPDX-License-Identifier: GPL-2.0

#

# Makefile for the linux pstorefs routines.

#

 

obj-$(CONFIG_PSTORE) += pstore.o

 

pstore-objs += inode.o platform.o

pstore-$(CONFIG_PSTORE_FTRACE) += ftrace.o

 

pstore-$(CONFIG_PSTORE_PMSG) += pmsg.o

 

ramoops-objs += ram.o ram_core.o

obj-$(CONFIG_PSTORE_RAM) += ramoops.o

默認就已經配好了。

 

3.4. menuconfig配置

如下面三張圖配置對應的選項

 

 

3.5. 編譯

make kernel -j8

 

4. 測試

查看模pstore模塊開起來沒有

dmesg | grep -i pstore

dmesg | grep -i ramoops

 

日志生成目錄

cd /sys/fs/pstore

 

生成一個內核日志和用戶日志

reboot

 

產生一個崩潰日志

echo c > /proc/sysrq-trigger

 

產生函數調用日志

echo 1 > /proc/sys/kernel/sysrq

 

5. 測試參考資料

Documentation/ramoops.txt

https://blog.csdn.net/zgp2917/article/details/107711813

https://blog.csdn.net/qq_27125121/article/details/78666907

https://www.cnblogs.com/ZanyRain/p/10076645.html

http://iyounix.com/2018/03/03/Android_Driver/Driver/[Android7.1[RK3399]%20%E4%BD%BF%E7%94%A8%20ramoops%20%E6%9C%BA%E5%88%B6%E6%9F%A5%E7%9C%8B%E5%BC%80%E6%9C%BA%20Kernel%20Log/

http://huaqianlee.github.io/2020/11/13/Android/pstore/

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM