[RK3399][Android7.1] 调试笔记 --- 开机后台抓取kmsg log

Platform: RK3399
OS: Android 7.1
Kernel: v4.4.83

此功能在rk3288上有实现过,rk3399上脚本稍微有点差异。

  1. 记录文件生成时间,因为可能会遇到异常重启的情况,而文件的生成时间会随着Log的写入而更新。
  2. dmesg先保存前面的Log
  3. 每次开机会启动一次脚本,默认保留5次开机Log,kmsg_5.log为最新

改动如下:
system/core/rootdir/init.rc:

diff --git a/rootdir/init.rc b/rootdir/init.rc
index 3aa4426..30b823f 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -692,3 +692,8 @@ service syslog /system/bin/logcat -f /data/log/system.log -r 10240 -v time
     user root
     group system
     oneshot
+
+#Kris, 170814, save kernel log.
+service kmsg_log /system/bin/kmsg.sh
+    class late_start
+

device/rockchip/rk3399/device.mk:

diff --git a/device.mk b/device.mk
index 900aa99..2a730bc 100755
--- a/device.mk
+++ b/device.mk

+
+#Kris,170814.
+PRODUCT_COPY_FILES += \
+    device/rockchip/rk3399/kmsg.sh:system/bin/kmsg.sh

kmsg.sh:

#!/system/bin/sh
#Kris, 20170814, Created.

#Save five files as max.
count=5
for i in `seq $(($count+1))`
do
    #echo "i is $i"
    if [ ! -f "/data/log/kmsg_$i.log" ]; then
        break
    fi
done

if [ $i -eq $(($count+1)) ]; then 
    rm /data/log/kmsg_1.log
    i=$count
    for j in `seq $(($count-1))`
    do
        #echo "/data/log/kmsg_$(($j+1)).log /data/log/kmsg_$j.log"
        mv /data/log/kmsg_$(($j+1)).log /data/log/kmsg_$j.log
    done
fi

#save date, otherwise the date of file will be flushed.
date > /data/log/kmsg_$i.log

dmesg >> /data/log/kmsg_$i.log
cat /proc/kmsg >> /data/log/kmsg_$i.log

你可能感兴趣的:(RK3399,子类__Android)