【Linux】嵌入式Linux屏蔽调试串口在控制台的输出

发布于 2021-03-01  117 次阅读


问题记录

之前调试C串口通讯花了一些功夫,这里做一些总结并记录一些解决方案。
主要的坑有以下两点:
1. 周立功核心板A3352-W128Li 与 A3352-WB128Li存在硬件差异。A3352-WB128Li多了一个蓝牙,但是把串口1给占用了(串口1没有引出)。导致之前分配给某个模块的串口不能进行正常通信。
2. 使用串口0进行通信时,系统的调试数据会干扰串口0的正常使用。

关闭串口调试输出的方法

修改环境变量

之前我们是采用设置Uboot环境变量的方式,设置conosle=none来配置串口不要进行输出。
周立功的核心板也可以通过类似的方法,但是每次修改需要进入Uboot才能进行修改。

修改内核配置

通过TOP命令观察系统进程,找到了使用调试串口进行输出的程序 /sbin/getty
一开始我是打算干掉这个进程,但是发现该程序会不断被重启,可能存在守护进程。
直接重命名getty这个程序,发现进程是没有再被启动了,但是控制台仍然会被占用,并且不停输出

can't run `/sbin/getty` no such file or direct

看来只能放弃该方法,需要从启动getty的入口着手。

之后找到了配置文件/etc/inittab

# /etc/inittab
#
# Copyright (C) 2001 Erik Andersen <andersen@codepoet.org>
#
# Note: BusyBox init doesn't support runlevels.  The runlevels field is
# completely ignored by BusyBox init. If you want runlevels, use
# sysvinit.
#
# Format for each entry: <id>:<runlevels>:<action>:<process>
#
# id        == tty to run on, or empty for /dev/console
# runlevels == ignored
# action    == one of sysinit, respawn, askfirst, wait, and once
# process   == program to run

# Startup the system
#null::sysinit:/bin/mount -t proc proc /proc
#null::sysinit:/bin/mount -o remount,rw /
null::sysinit:/bin/mkdir -p /dev/pts
null::sysinit:/bin/mount -a
null::sysinit:/bin/hostname -F /etc/hostname
# now run any rc scripts
::sysinit:/etc/init.d/rcS

# Put a getty on the serial port
ttyO0::respawn:/sbin/getty -L ttyO0 115200 vt100 # GENERIC_SERIAL

# Logging junk
null::sysinit:/bin/touch /var/log/messages
null::respawn:/sbin/syslogd -n -m 0
null::respawn:/sbin/klogd -n
tty3::respawn:/usr/bin/tail -f /var/log/messages

# Stuff to do for the 3-finger salute
::ctrlaltdel:/sbin/reboot

# Stuff to do before rebooting
null::shutdown:/usr/bin/killall klogd
null::shutdown:/usr/bin/killall syslogd
null::shutdown:/bin/umount -a -r
null::shutdown:/sbin/swapoff -a

注意这条配置,很明显就是我们需要修改的地方

# Put a getty on the serial port
ttyO0::respawn:/sbin/getty -L ttyO0 115200 vt100 # GENERIC_SERIAL

直接注释掉,重启设备。
成功屏蔽了调试串口ttyO0的调试信息输出,串口模块也可以正常通信了。

Comments


来自像素世界的代码家,创造第九艺术!