Android系统编译成user版本时,UART口关闭输入输出功能,adb功能也将关闭,这个时候非常不方便进行调试。
我们可以按照以下方式设置,在user版本的时候打开UART调试功能,同时将logcat重定向到UART口打出。
1、原因:
编译user版本之后 ro.debuggable=0
build/core/main.mk:
ifeq (true,$(strip $(enable_target_debugging)))
# Target is more debuggable and adbd is on by default
ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=1
# Enable Dalvik lock contention logging.
ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.lockprof.threshold=500
# Include the debugging/testing OTA keys in this build.
INCLUDE_TEST_OTA_KEYS := true
else # !enable_target_debugging
# Target is less debuggable and adbd is off by default
ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=0
endif # !enable_target_debugging
system/core/rootdir/init.rc
service console /system/bin/sh
class core
console
disabled
user shell
group shell log readproc
seclabel u:r:shell:s0
on property:ro.debuggable=1
# Give writes to anyone for the trace folder on debug builds.
# The folder is used to store method traces.
chmod 0773 /data/misc/trace
start console
2、解决办法:
(1)修改 ro.debuggable = 1
(2)直接将disabled移除,默认无条件启动console
service console /system/bin/sh
class core
console
disabled
#user shell 修改成root权限
user root
group shell log readproc
seclabel u:r:shell:s0
###on property:ro.debuggable=1 ###注释掉这行
# Give writes to anyone for the trace folder on debug builds.
# The folder is used to store method traces.
chmod 0773 /data/misc/trace
start console
3、将logcat信息重定向到UART口
原理上就是根据kernel log能够从串口输出,只要将logcat重定向到kmsg即可实现,因此各个平台的原理是一样的应该通用。(但须注意这样打印虽然能够有android log从串口输出,但串口输出量过大可能会出现丢log的情况) 如下:
system/core/rootdir/init.rc中添加:
chmod 0660 /proc/kmsg
###############################################################
# redirect logs(LOGE, LOGI...) to linux console
###############################################################
service logcat /system/bin/logcat -f /dev/kmsg *:D
class main
user root
group log
默认启动