一、Kernel适配Ethernet
我使用的linux_kernel版本是5.2.y
<1> 配置menuconfig
进入linux kernel目录下/home/daemonchen/linux/V3S/linux_kernel/linux/linux-zero-5.2.y,首先配置menuconfig。
make ARCH=arm menuconfig
按照如下路径进行配置:
#配置以太网
Device Drivers --->
[*] Network device support --->
[*] Ethernet driver support --->
[*] STMicroelectronics devices
<*> STMicroelectronics Multi-Gigabit Ethernet driver
<*> STMMAC Platform bus support (NEW)
<*> Support for snps,dwc-qos-ethernet.txt DT binding.
<*> Generic driver for DWMAC (NEW)
<*> Allwinner GMAC support (NEW)
<*> Allwinner sun8i GMAC support (NEW)
#配置nfs
[*] Networking support --->
Networking options --->
[*] TCP/IP networking
[*] IP: kernel level autoconfiguration
[*] IP: DHCP support
[*] IP: BOOTP support
File systems --->
[*] Network File Systems --->
<*> NFS client support
<*> NFS client support for NFS version 3 (NEW)
[*] NFS client support for the NFSv3 ACL protocol extension
<*> NFS client support for NFS version 4
[*] NFS client support for NFSv4.1
[*] Root file system on NFS
保存退出
为了方便下次直接调用这些配置,使用下列命令将配置保存为Licheepi_MY_Ethernet_defconfig.
make savedefconfig
cp defconfig arch/arm/configs/Licheepi_MY_Ethernet_defconfig
<2> 修改dts
5.2版本的dock版本的设备树中已经添加了。
<3> 编译
make -j16
得到zImage和sun8i-v3s-licheepi-zero-dock.dtb,将其移动到烧录文件夹下:
cp arch/arm/boot/zImage /home/daemonchen/linux/V3S/mysys_kernel_5.2.y/ -f
cp arch/arm/boot/dts/sun8i-v3s-licheepi-zero-dock.dtb /home/daemonchen/linux/V3S/mysys_kernel_5.2.y/ -f
<4> 配置ip为固定,并且开机自动启动网卡
在根文件系统/etc/init.d/rcS中添加以下内容:
#网络开机自启动设置
ifconfig eth0 up
#配置IP地址和子网掩码
ifconfig eth0 192.168.147.132 netmask 255.255.255.0
#配置网关
route add default gw 192.168.147.2
<5> 配置域名解析服务器IP
我们需要配置域名解析服务器的 IP 地址,一般域名解析地址可以设置为所处网络的网关地址,我的是 192.168.147.2。也可以设置为 114.114.114.114,这个是运营商的域名解析服务器地址。
进入rootfs目录下的etc/文件夹/home/daemonchen/linux/V3S/mysys_kernel_5.2.y/rootfs/etc,创建文件resolv.conf,加入域名解析服务器地址。
cd /home/daemonchen/linux/V3S/mysys_kernel_5.2.y/rootfs/etc
vi resolv.conf
#add nameserver 114.114.114.114
#add nameserver 192.168.147.2
配置后如下所示:
<5> 烧录
按照全志V3S开发(四)-系统烧录方式进行烧录。
<6> 启动测试
利用SecureCRT查看串口log,按照全志V3S开发(四)-系统烧录方式配置bootargs和bootcmd,按照全志V3S开发(一)-主线uboot移植方式配置uboot网络环境。如下所示。
之后重启,kernel启动后输入root进入根文件系统。
用以下命令查看网卡:
ifconfig
网卡eth0已开机自启动,eth0的IP地址与之前设置的相符。
ping一下ubuntu主机192.168.147.130,成功!
ping一下百度www.baidu.com,成功!
至此Linux_kernel已适配好以太网!
二、实现nfs和tftp服务器挂载
为了方便后续Linux驱动调试,避免每次调试都要重新烧录SD卡,需要创建nfs和tftp服务器,nfs目录下面放根文件系统rootfs,tftpboot目录下放系统镜像zimage和设备树dtb。
<1> nfs服务器创建
1. 使用如下命令安装NFS安装包:
sudo apt-get install nfs-kernel-server rpcbind
sudo apt-get install nfs-common
2. 在/home/daemonchen/linux文件夹下创建文件夹nfs/,作为nfs服务的共享文件夹,并更改权限。
cd /home/daemonchen/linux
mkdir nfs
sudo chmod -R 777 /home/daemonchen/linux/nfs
sudo chown -R nobody /home/daemonchen/linux/nfs
3. 为了在开发板上通过网络文件系统来访问nfs文件夹,要先配置nfs,使用如下命令打开nfs配置文件/etc/exports:
sudo vi /etc/exports
打开以后在后面添加如下内容:
/home/daemonchen/linux/nfs *(rw,sync,no_root_squash)
添加完成以后的/etc/exports如下图所示:
4. 重启NFS服务:
sudo /etc/init.d/nfs-kernel-server restart
<2> tftp服务器创建
1. 使用如下命令安装tftp服务器。
sudo apt-get install tftp-hpa tftpd-hpa
sudo apt-get install xinetd
2. 创建tftp服务器共享目录,并赋予其权限。
mkdir /home/daemonchen/linux/tftpboot
chmod 777 /home/daemonchen/linux/tftpboot
3. 配置 tftp,安装完成以后新建文件/etc/xinetd.d/tftp,如果没有/etc/xinetd.d 目录的话自行创建,然后在里面输入如下内容:
server tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /home/daemonchen/linux/tftpboot/
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
4. 重启tftp服务:
sudo service tftpd-hpa start
5. 打开/etc/default/tftpd-hpa 文件,将其修改为如下所示内容:
# /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/home/daemonchen/linux/tftpboot"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="-l -c -s"
6. 重启tftp服务:
sudo service tftpd-hpa restart
<3> 文件准备及烧录
1. 按照全志V3S开发(四)-系统烧录清空SD卡、仅将uboot烧录至8k偏移处。
2. 将/home/daemonchen/linux/V3S/mysys_kernel_5.2.y下的rootfs复制到/home/daemonchen/linux/nfs下.
cd /home/daemonchen/linux/V3S/mysys_kernel_5.2.y/rootfs
tar -czvf rootfs.tar.gz *
mv rootfs.tar.gz /home/daemonchen/linux/nfs -f
cd /home/daemonchen/linux/nfs
mkdir rootfs
sudo tar xzvf rootfs.tar.gz -C rootfs/
3. 将zImage和sun8i-v3s-licheepi-zero-dock.dtb复制到/home/daemonchen/linux/tftpboot下。
cp /home/daemonchen/linux/V3S/mysys_kernel_5.2.y/zImage /home/daemonchen/linux/tftpboot -f
cp /home/daemonchen/linux/V3S/mysys_kernel_5.2.y/sun8i-v3s-licheepi-zero-dock.dtb /home/daemonchen/linux/tftpboot -f
<4> 启动测试
1. 使用SecureCRT查看串口0的uboot log,在倒计时结束前回车进入uboot设置界面。
2. 配置网络相关变量:
setenv ipaddr 192.168.147.132
setenv gatewayip 192.168.147.2
setenv netmask 255.255.255.0
setenv serverip 192.168.147.130
saveenv
3. ping一下主机192.168.147.130 ,务必保证是通的。
4. 重点:配置bootargs和bootcmd
setenv bootcmd 'tftp 0x41000000 zImage; tftp 0x41800000 sun8i-v3s-licheepi-zero-dock.dtb; bootz 0x41000000 - 0x41800000'
setenv bootargs 'console=ttyS0,115200 root=/dev/nfs rw nfsroot=192.168.147.130:/home/daemonchen/linux/nfs/rootfs ip=192.168.147.132:192.168.147.130:192.168.147.2:255.255.255.0::eth0::off init=/linuxrc'
saveenv
配置好以后输入boot启动:
boot
5. 如果启动以后报这个错误:
[ 116.988470] VFS: Unable to mount root fs via NFS, trying floppy.
[ 116.995477] VFS: Cannot open root device "nfs" or unknown-block(2,0): error -6
[ 117.002832] Please append a correct "root=" boot option; here are the available partitions:
[ 117.011250] b300 30289920 mmcblk0
[ 117.011255] driver: mmcblk
[ 117.018065] b301 20480 mmcblk0p1 05bf1120-01
[ 117.018067]
[ 117.024899] b302 30267392 mmcblk0p2 05bf1120-02
[ 117.024901]
[ 117.031721] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)
[ 117.039990] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.2.0-licheepi-zero #2
[ 117.047034] Hardware name: Allwinner sun8i Family
[ 117.051774] [<c010ed14>] (unwind_backtrace) from [<c010b72c>] (show_stack+0x10/0x14)
[ 117.059528] [<c010b72c>] (show_stack) from [<c0736d90>] (dump_stack+0x84/0x98)
[ 117.066760] [<c0736d90>] (dump_stack) from [<c011dddc>] (panic+0x110/0x2fc)
[ 117.073729] [<c011dddc>] (panic) from [<c0a0136c>] (mount_block_root+0x1a0/0x288)
[ 117.081219] [<c0a0136c>] (mount_block_root) from [<c0a01598>] (mount_root+0x144/0x160)
[ 117.089142] [<c0a01598>] (mount_root) from [<c0a01704>] (prepare_namespace+0x150/0x194)
[ 117.097153] [<c0a01704>] (prepare_namespace) from [<c074f1e4>] (kernel_init+0x8/0x10c)
[ 117.105077] [<c074f1e4>] (kernel_init) from [<c01010e8>] (ret_from_fork+0x14/0x2c)
[ 117.112646] Exception stack(0xc3833fb0 to 0xc3833ff8)
[ 117.117699] 3fa0: 00000000 00000000 00000000 00000000
[ 117.125879] 3fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
[ 117.134056] 3fe0: 00000000 00000000 00000000 00000000 00000013 00000000
[ 117.140685] ---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0) ]---
关键在:
VFS: Cannot open root device "nfs" or unknown-block(2,0): error -6
需要修改NFS配置文件:
sudo vim /etc/default/nfs-kernel-server
在最后加入:
RPCNFSDOPTS="--nfs-version 2,3,4 --debug --syslog"
如下所示:
重启NFS服务:
sudo /etc/init.d/nfs-kernel-server restart
6. 重新启动,成功进入根文件系统:
至此,成功开启NFS和TFTP服务,后续做Linux驱动开发可以大大减少烧录的繁琐步骤,直接从服务器端启动开发板!
标签:Kernel,kernel,00000000,适配,nfs,linux,home,daemonchen,以太网 From: https://blog.csdn.net/Jlinkneeder/article/details/141420955