Lastlog使用参考


REVISION HISTORY

Revision No. Description Date
1.0
  • Initial release
  • 04/27/2024

    1. Lastlog简介

    SigmaStar Lastlog其实就是Linux原生支持的pstore功能。

    pstore最初是用于系统发生oops或panic时,自动保存内核log buffer中的日志。在当前内核版本中,其已经支持了更多的功能,如保存console日志、ftrace消息和用户空间日志。同时,它还支持将这些消息保存在不同的存储设备中,如内存、块设备或mtd设备。

    PCUPID目前在spinand和emmc上均已支持lastlog功能,默认不打开。若要开启该功能,则需要修改配置文件以及新增pstore分区。下面分别介绍在spinand和emmc上开启lastlog功能的步骤。

    2. 在spinand上添加lastlog功能

    2.1. 修改Linux配置

    按照下面的配置修改Linux kernel的defconfig,修改完成后保存。

    make menuconfig
    #   File systems  --->
    #       [*] Miscellaneous filesystems  --->
    #           <M>   Persistent store support
    #           <M>     DEFLATE (ZLIB) compression
    #           < >     LZO compression
    #           < >     LZ4 compression
    #           < >     LZ4HC compression
    #           [ ]     842 compression
    #           [ ]     zstd compression
    #            Default pstore compression algorithm (deflate)  --->
    #           [*]     Log kernel console messages
    #           [*]     Log user space messages
    #           < >     Log panic/oops to a RAM buffer
    #           [*]     Record order by counter instead of timestamp.
    #           <M>     Log panic/oops to a block device
    #           () block device identifierntifier
    #           (64)      Size in Kbytes of kmsg dump log to store
    #           (2) Maximum kmsg dump reason to store store
    #           (64)      Size in Kbytes of pmsg to store
    #           (64)      Size in Kbytes of console log to store
    #   Device Drivers  --->
    #       <*> Memory Technology Device (MTD) support  --->
    #           <M>   Log panic/oops to an MTD buffer based on pstore
    #   Kernel hacking  --->
    #       Generic Kernel Debugging Instruments  --->
    #           [*] Magic SysRq key
    #           (0x1) Enable magic SysRq key functions by default
    #           [*]   Enable magic SysRq key over serial
    #           ()      Char sequence that enables magic SysRq over serial
    

    2.2. 修改project的defconfig

    在project里的defconfig里新增配置:CONFIG_PSTORE=y,这样打包镜像时会自动执行pstore相关的命令。

    2.3. 在分区配置文件中添加pstore分区

    • 修改IMAGE_LIST

      IMAGE_LIST = cis boot kernel rootfs misc pstore ubia miservice customer

    • 修改cis$(SYSTAB)

      cis$(SYSTAB) = $(env$(MTDPART)),$(kernel$(MTDPART)),$(rootfs$(MTDPART)),$(vendor_storage$(MTDPART)),$(misc$(MTDPART)),$(pstore$(MTDPART)),$(ubia$(MTDPART))
      
    • 新增pstore分区

    2.4. 重新生成镜像

    在project目录下执行下列命令重新生成镜像文件:

    make xxx_defconfig
    
    make clean -j32
    
    make image -j32
    

    3. 在emmc上添加lastlog功能

    3.1. 修改Linux配置

    按照下面的配置修改Linux kernel的defconfig,修改完成后保存。

    make menuconfig
    #   File systems  --->
    #       [*] Miscellaneous filesystems  --->
    #           <M>   Persistent store support
    #           <M>     DEFLATE (ZLIB) compression
    #           < >     LZO compression
    #           < >     LZ4 compression
    #           < >     LZ4HC compression
    #           [ ]     842 compression
    #           [ ]     zstd compression
    #            Default pstore compression algorithm (deflate)  --->
    #           [*]     Log kernel console messages
    #           [*]     Log user space messages
    #           < >     Log panic/oops to a RAM buffer
    #           [*]     Record order by counter instead of timestamp.
    #           <M>     Log panic/oops to a block device
    #           () block device identifierntifier
    #           (64)      Size in Kbytes of kmsg dump log to store
    #           (2) Maximum kmsg dump reason to store store
    #           (64)      Size in Kbytes of pmsg to store
    #           (64)      Size in Kbytes of console log to store
    #   Kernel hacking  --->
    #       Generic Kernel Debugging Instruments  --->
    #           [*] Magic SysRq key
    #           (0x1) Enable magic SysRq key functions by default
    #           [*]   Enable magic SysRq key over serial
    #           ()      Char sequence that enables magic SysRq over serial
    

    3.2. 修改project的defconfig

    在project里的defconfig里新增配置:CONFIG_PSTORE=y,这样打包镜像时会自动执行pstore相关的命令。

    3.3. 在分区配置文件中添加pstore分区

    • 修改IMAGE_LIST

      IMAGE_LIST = boot kernel rootfs misc miservice pstore customer

    • 新增pstore分区

    3.4. 重新生成镜像

    在project目录下执行下列命令重新生成镜像文件:

    make xxx_defconfig
    
    make clean -j32
    
    make image -j32
    

    4. 验证lastlog功能

    • reboot后生成console log

      烧录完成后启动至Linux命令行,然后reboot Linux,可以看到Linux重新启动后pstore模块生成了console-pstore_blk-0文件,其内容为Linux的dmesg log。Linux每次reboot后都会重新生成该文件。

    • panic/oops生成log

      输入echo c > /proc/sysrq-trigger手动触发panic,重启Linux后可以看到pstore模块生成了console-pstore_blk-0文件和dmesg-pstore_blk-0文件。其中的dmesg-pstore_blk-0文件里包含了完整的panic信息。dmesg-pstore_blk-0文件只有系统出现panic或oops时才会生成。

    • pmsg生成log

      pmsg是一个用户空间可以访问的pstore对象。用户可以向/dev/pmsg0写入数据,Linux重启后pstore模块会生成pmsg-pstore_blk-0文件,这里保存了Linux重启前用户写入的内容。