android 禁止串口日志输出

发布于:2025-03-30 ⋅ 阅读:(34) ⋅ 点赞:(0)

本文基于android9;
在做Mtk android9车载项目时,信息安全上要求去除realse版本的串口打印功能,涉及到SOC和MCU两个串口,SOC串口取消由android侧负责,所以做了简单的调研;

目录

1,console的功能使用
2,禁止kernal日志输出

1、console的功能使用

console服务是端口输出服务,串口里android系统的log输出其实就是console输出的。实际上该service就是启动一个shell程序,目标程序位置/system/bin/sh。通过shell我们就拥有了一个人机交互的接口了,类似于一个超级终端,通过串口就可以输入命令了,支持串口调试进入sh。

console服务在init.rc中声明定义,并通过ro.debuggable控制功能的开关。在init.rc中配置,如果ro.debuggable=1则开启console,ro.debuggable=0则关闭。关闭后,串口禁止指令输入。

setprop ro.debuggable 1
service console /system/bin/sh
class core
console
disabled
user shell
group log

on property:ro.debuggable=1
start console

一般user版本会将 console关闭,userdebug版本上console默认是打开的。如果user版本想实现conole的打开,则需要强制加上实现的代码在:
build/make/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

将其中ro.debuggable值改成1,即可打开console功能。
执行完上面的动作以后,刷机后的串口效果是,无法通过console控制台输入指令,但是开机阶段会打印部分kernal日志信息;

2,kernal禁止日志输出

从网上找了一些指导,但是在我们项目上均无效果;
本项目调试下来是修改
修改文件kernel-4.9/arch/arm/boot/dts/device_id.dts中的bootargs = "console=ttyS0,将console=ttyS0修改成console=null

	fragment@2 {
 		target-path = "/chosen";
 		__overlay__ {
 			bootargs = "console=ttyS0,921600n1 initrd=0x4a000000,32M debugshell=1 printk.disable_uart=0 rootwait ro init=/initfast vmalloc=496M initcall_debug=0 clk_ignore_unused earlycon=uart8250,mmio32,0x11002000 androidboot.console=ttyS0 androidboot.hardware=mt2712 androidboot.selinux=enforcing androidboot.serialno=GFEDCBA0987654321";
 		};
 	};

还有个打印等级修改,CONFIG_CONSOLE_LOGLEVEL_DEFAULT=3,就可以了