在调试linux时,经常需要翻阅串口的信息,而串口通常需要串口线引出来,而整机一般情况下串口是封闭的。为了调试更好的看的串口信息,可以借助netconsole功能。
CONFIG_NETCONSOLE=y
这里默认对serverip进行ping操作,如果serverip在线,则自动开始netconsole,否则正常流程boot
setenv serverip 172.25.80.123 setenv ipaddr 172.25.80.124 setenv if_netconsole 'ping $serverip' setenv start_netconsole 'setenv ncip $serverip; setenv stdin nc; setenv stdout nc; setenv stderr nc;' run if_netconsole start_netconsole
netconsole命令来自uboot源码tools/netconsole。
./netconsole 172.25.80.124 6666
在某些情况下,如果linux内核破坏,uboot正常。系统无法开机,并且uboot的下载按键无法使用时。可以通过默认的服务器ip地址来对uboot进行命令行调试。例如download命令进入下载模式。
但是在一般情况下,只要保证uboot的下载按键正常时,此方法并无大用。仅留作备选方案之一考虑
CONFIG_NETCONSOLE=m CONFIG_NETCONSOLE_DYNAMIC=y
编译的netconsole.ko,在需要使用的时候,有两种方式来使用
insmod netconsole.ko netconsole=6666@172.25.80.125/eth0,6666@172.25.80.123/00:0c:29:d7:44:0b
这里netconsole参数需要带如下几个信息
netconsole=[+][src-port]@[src-ip]/[<dev>],[tgt-port]@<tgt-ip>/[tgt-macaddr] where + if present, enable extended console support src-port source for UDP packets (defaults to 6665) src-ip source IP to use (interface address) dev network interface (eth0) tgt-port port for logging agent (6666) tgt-ip IP address for logging agent tgt-macaddr ethernet MAC address for logging agent (broadcast)
通俗点也就是
端口地址@本机IP地址/网卡名称,端口地址@服务器IP地址/MAC地址 这里 本地IP为172.25.80.125,网卡名称为eth0,默认使用端口6666,远程IP为172.25.80.123,网卡mac地址为00:0c:29:d7:44:0b,默认使用端口为6666
cd /sys/kernel/config/netconsole/ mkdir target echo 6666 > local_port echo 172.25.80.125 > local_ip echo eth0 > dev_name echo 6666 > remote_port echo 172.25.80.123 > remote_ip echo 00:0c:29:d7:44:0b > remote_mac echo 1 > enabled
卸载
echo 0 > enabled rmdir target rmmod netconsole
默认内核的cmdline没有指定loglevel的情况下,可以通过dmesg手动调试日志
dmesg -n 8
这样在netconsole就能看的内核日志信息了
在设备上,如果不想登录服务器地址,可以通过arp查看mac
ping -c 1 172.25.80.123 ; /sbin/arp -n | grep 172.25.80.123
nc -lup 6666
内核打开netconsole的作用比较明显,内核本身的/var/log/kern.log带缓冲,信息不及时。串口接出来不方便。但是需要实时的查看内核日志的时候,可以使用这个办法
https://github.com/u-boot/u-boot/blob/master/doc/usage/netconsole.rst https://www.kernel.org/doc/html/latest/networking/netconsole.html