Android11 将logcat日志定位到uart串口输出

软件平台:Android11

硬件平台:QCS6125

需求:如题,串口需要输出logcat的系统全量日志,我这里边是把logcat日志定向到了/dev/kmsg从而使logcat跟kmsg一样通过串口输出。

改动如下:

diff --git a/rootdir/init.rc b/rootdir/init.rc
index 3cf6ffc35..12337986a 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -399,8 +399,10 @@ on init
     chmod 0660 /sys/power/wake_lock
     chmod 0660 /sys/power/wake_unlock
 
+    chmod 0660 /proc/kmsg
     # Start logd before any other services run to ensure we capture all of their logs.
     start logd
+    start logkevin
     # Start lmkd before any other services run so that it can register them
     chown root system /sys/module/lowmemorykiller/parameters/adj
     chmod 0664 /sys/module/lowmemorykiller/parameters/adj
@@ -423,6 +425,7 @@ on load_persist_props_action
     load_persist_props
     start logd
     start logd-reinit
+    start logkevin
 
 # Indicate to fw loaders that the relevant mounts are up.
 on firmware_mounts_complete
@@ -1058,6 +1061,11 @@ service ueventd /system/bin/ueventd
     seclabel u:r:ueventd:s0
     shutdown critical
 
+service logkevin /system/bin/logcat -f /dev/kmsg *:D
+    class main
+    user root
+    group logd system
+
 service console /system/bin/sh
     class core
     console

    重新编译刷机即可验证,注意如果串口日志仍不是全量则需要确认内核printk的级别,shell进设备,执行echo  7 > proc/sys/kernel/printk,可以将内核日志级别设置为最低,即基本上所有等级的日志都会输出到串口。

Mark~~~

你可能感兴趣的:(Android,android,uart,logcatd,init,串口重定向)