嵌入式Linux关闭串口打印-屏蔽串口打印

2019-07-12 17:35发布

公司某些产品可能涉及一些敏感信息,如芯片选型,参数配置,调试信息.不想让客户或者竞争对手看到.需要将串口打印信息屏蔽掉.最后以关闭内核和串口打印的方案最合适,稍加改动就可以实现.笔记记录如下: 以hi3518ev200为例,其他平台可参考配置. bootargs修改 修改前: setenv bootargs 'mem=64M console=ttyAMA0,115200 root=/dev/sda1 rootwait rw mtdparts=hi_sfc:256k(boot),64k(env),4M(kernel),7M(rootfs)' 修改后: setenv bootargs 'mem=64M root=/dev/sda1 rootwait rw mtdparts=hi_sfc:256k(boot),64k(env),4M(kernel),7M(rootfs)' 将console去掉 文件系统修改 在文件系统 /etc/inittab #::askfirst:-/bin/sh # Start an "askfirst" shell on /dev/tty2-4 # tty2::askfirst:-/bin/sh # tty3::askfirst:-/bin/sh # tty4::askfirst:-/bin/sh # /sbin/getty invocations for selected ttys # tty4::respawn:/sbin/getty 38400 tty5 # tty5::respawn:/sbin/getty 38400 tty6 # Example of how to put a getty on a serial line (for a terminal) ::respawn:/sbin/getty -L ttyS000 115200 vt100 -n root -I "Auto login as root ..." #::respawn:/sbin/getty -L ttyS1 9600 vt100 # # Example how to put a getty on a modem line. #::respawn:/sbin/getty 57600 ttyS2 # Stuff to do when restarting the init process ::restart:/sbin/init # Stuff to do before rebooting ::ctrlaltdel:/sbin/reboot ::shutdown:/bin/umount -a -r ::shutdown:/sbin/swapoff -a #::askfirst:-/bin/sh # Start an "askfirst" shell on /dev/tty2-4 # tty2::askfirst:-/bin/sh # tty3::askfirst:-/bin/sh # tty4::askfirst:-/bin/sh # /sbin/getty invocations for selected ttys # tty4::respawn:/sbin/getty 38400 tty5 # tty5::respawn:/sbin/getty 38400 tty6 # Example of how to put a getty on a serial line (for a terminal) #::respawn:/sbin/getty -L ttyS000 115200 vt100 -n root -I "Auto login as root ..." #::respawn:/sbin/getty -L ttyS1 9600 vt100 # # Example how to put a getty on a modem line. #::respawn:/sbin/getty 57600 ttyS2 # Stuff to do when restarting the init process ::restart:/sbin/init # Stuff to do before rebooting ::ctrlaltdel:/sbin/reboot ::shutdown:/bin/umount -a -r ::shutdown:/sbin/swapoff -a ~ 注释掉::respawn:/sbin/getty -L ttyS000 115200 vt100 -n root -I "Auto login as root ..." 重启, hi3516cv300 System startup U-Boot 2010.06 (Apr 20 2017 - 15:46:32) Check Flash Memory Controller v100 ... Found SPI Nor(cs 0) ID: 0xc2 0x20 0x18 Block:64KB Chip:16MB Name:"MX25L128XX" SPI Nor total size: 16MB In: serial Out: serial Err: serial Press Ctrl+C to stop autoboot 16384 KiB hi_fmc at 0:0 is now current device ## Booting kernel from Legacy Image at 82000000 ... Image Name: Linux-3.18.20 Image Type: ARM Linux Kernel Image (uncompressed) Data Size: 1939151 Bytes = 1.8 MiB Load Address: 80008000 Entry Point: 80008000 Loading Kernel Image ... OK OK Starting kernel ... 之后所有的打印都没有了. 特意打开了telnet跟踪下,app有没有在运行. hi3516c login: hi3516c login: hi3516c login: root Password: profile echoing PATH= /usr/bin:/usr/sbin:/bin:/sbin LIBRARY= /usr/local/lib:/usr/lib 1234567--->hi3516cv300 profile ending PATH= /usr/bin:/usr/sbin:/bin:/sbin:/app/bin LIBRARY= /usr/local/lib:/usr/lib:/app/lib Welcome to HiLinux. Mount: 192.168.5.172:/home/hecong/work/tcpip/7203/trunk/platform/pub/rootfs_glibc on / type nfs (rw,relatime,vers=2,rsize=4096,wsize=4096,namlen=255,hard,nolock,proto=udp,timeo=11,retrans=3,sec=sys,mountaddr=192.168.5.172,mountvers=1,mountproto=udp,local_lock=all,addr=192.168.5.172) chroot: can't execute '/usr/bin/env': No such file or directory ~ # ps PID USER TIME COMMAND 1 root 0:00 init 2 root 0:00 [kthreadd] 3 root 0:00 [ksoftirqd/0] 4 root 0:00 [kworker/0:0] 5 root 0:00 [kworker/0:0H] 6 root 0:00 [kworker/u2:0] 7 root 0:00 [khelper] 8 root 0:00 [kdevtmpfs] 9 root 0:00 [netns] 10 root 0:00 [writeback] 11 root 0:00 [crypto] 12 root 0:00 [bioset] 13 root 0:00 [kblockd] 14 root 0:00 [spi0] 15 root 0:00 [kworker/u2:1] 18 root 0:00 [rpciod] 19 root 0:00 [kworker/0:1] 20 root 0:00 [kswapd0] 21 root 0:00 [fsnotify_mark] 22 root 0:00 [nfsiod] 23 root 0:00 [cifsiod] 40 root 0:00 [ipv6_addrconf] 41 root 0:00 [deferwq] 42 root 0:00 [kworker/u2:2] 43 root 0:00 [kworker/0:2] 57 root 0:00 udevd --daemon 69 root 0:00 udevd --daemon 71 root 0:00 udevd --daemon 129 root 0:00 ./test1 130 root 0:00 telnetd 131 root 0:00 -sh 143 root 0:00 ps ~ # 测试程序test1正常后台运行,功能实现.