Zynq-7000系列之linux开发学习笔记:NFS配置与开发板联网(七)

开发板:Zynq7030数据采集板
PC平台:Ubuntu-18.04 + MobaXterm
开发环境:Xilinx Vivado + SDK -18.3
交叉编译工具:arm-linux-gnueabihf-
学习目标:让开发板连接外网;并通过NFS挂载到虚拟机,运行一个 helloworld 程序

由于之前忙于别的工作,再来接触到这个7030,突然感觉有点陌生了0.0.0.0 这次来更新一些比较简单的。

一、开发板连接外网

在上一篇文章Zynq-7000系列之linux开发学习笔记:编译Linux内核和制作设备树(六)中,我们编译好了Linux内核和所需的设备树文件,并成功的在Zynq7030数据采集板上运行系统。接下来就安装NFS来与虚拟机进行挂载,方便后续开发。(好像也可以用SSH方式,不过还没弄过,不会0.0.0.0.0.0)
但在mount的过程中,遇到了如下问题:

root@linaro-ubuntu-desktop:~$ mount -t nfs -o nolock 192.168.3.100:/home/claude1009 /mnt
mount: wrong fs type, bad option, bad superblock on 192.168.3.100:/home/claude1009,
       missing codepage or helper program, or other error
       (for several filesystems (e.g. nfs, cifs) you might
       need a /sbin/mount.<type> helper program)
       In some cases useful info is found in syslog - try
       dmesg | tail  or so

在网上查找相关问题,没有找到比较好的回答。有些文章说再装一下 nfs-common 就行,所以才有了先让开发板连接外网的模块0.0.0 (如果有大神知道其他操作,欢迎留言!!) 。 另外,还可以安装vim工具,主要是觉得vi不太好用。

  • 先说一下目前的网络连接情况:
    • 开发板通过USB-HUB上的网口与主机相连;
    • 主机开着VMware虚拟机,与主机上的网络相连;
    • 主机通过WIFI与外网相连。

在这里插入图片描述
接下来操作步骤如下:

  1. 首先进到上图中的窗口,然后将WLAN适配器共享给以太网2,这时以太网2会被自动分配IP地址: 192.168.137.1 。记住个这地址,后面还会用到。
    在这里插入图片描述
  2. 然后给开发板上电,通过命令来设置开发板的IP地址,只要和以太网2的IP在同一网段就行。
root@linaro-ubuntu-desktop:~$ ifconfig eth0 192.168.137.2
root@linaro-ubuntu-desktop:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0a:35:00:01:22
          inet addr:192.168.137.2  Bcast:192.168.137.255  Mask:255.255.255.0
          inet6 addr: fe80::20a:35ff:fe00:122/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:352 errors:0 dropped:0 overruns:0 frame:0
          TX packets:507 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:41423 (41.4 KB)  TX bytes:37617 (37.6 KB)
          Interrupt:29 Base address:0xb000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:259 errors:0 dropped:0 overruns:0 frame:0
          TX packets:259 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:28800 (28.8 KB)  TX bytes:28800 (28.8 KB)
root@linaro-ubuntu-desktop:~$ ping 192.168.137.1
PING 192.168.137.1 (192.168.137.1) 56(84) bytes of data.
64 bytes from 192.168.137.1: icmp_req=1 ttl=128 time=0.900 ms
64 bytes from 192.168.137.1: icmp_req=2 ttl=128 time=0.683 ms
64 bytes from 192.168.137.1: icmp_req=3 ttl=128 time=0.550 ms
64 bytes from 192.168.137.1: icmp_req=4 ttl=128 time=0.535 ms

看到这里就表明开发板已经和主机网络连通了。
3. 然后网关配置为主机上的ip地址,如上面的IP: 192.168.137.1 。接着只需再PING一下外网IP就可以了,我这里的IP如下为: 10.33.10.124 。注意要设置网关 route add default gw 192.168.137.1 ,不然网络无法连通。
在这里插入图片描述

root@linaro-ubuntu-desktop:~$ route add default gw 192.168.137.1
root@linaro-ubuntu-desktop:~$ ping 10.33.10.124
PING 10.33.10.124 (10.33.10.124) 56(84) bytes of data.
64 bytes from 10.33.10.124: icmp_req=1 ttl=127 time=0.586 ms
64 bytes from 10.33.10.124: icmp_req=2 ttl=127 time=0.659 ms
64 bytes from 10.33.10.124: icmp_req=3 ttl=127 time=0.550 ms
64 bytes from 10.33.10.124: icmp_req=4 ttl=127 time=0.529 ms
64 bytes from 10.33.10.124: icmp_req=5 ttl=127 time=0.634 ms
^C
--- 10.33.10.124 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4124ms
rtt min/avg/max/mdev = 0.529/0.591/0.659/0.055 ms
root@linaro-ubuntu-desktop:~$
root@linaro-ubuntu-desktop:~$ ping www.baidu.com
PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.
64 bytes from 61.135.169.121: icmp_req=1 ttl=53 time=4.51 ms
64 bytes from 61.135.169.121: icmp_req=2 ttl=53 time=4.72 ms
64 bytes from 61.135.169.121: icmp_req=3 ttl=53 time=3.78 ms
64 bytes from 61.135.169.121: icmp_req=4 ttl=53 time=3.65 ms
64 bytes from 61.135.169.121: icmp_req=5 ttl=53 time=3.89 ms
64 bytes from 61.135.169.121: icmp_req=6 ttl=53 time=4.50 ms
^C
--- www.a.shifen.com ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 25058ms
rtt min/avg/max/mdev = 3.653/4.179/4.724/0.418 ms

当看到这里的时候,就说明开发板可以上网了!! 网络可能有点慢0.0.0.0.0
现在我们就可以来安装 nfs-common vim 了!不过,首先还是得update更新一下,才可以正常下载软件。

root@linaro-ubuntu-desktop:~$ apt-get update
root@linaro-ubuntu-desktop:~$ apt-get install nfs-common
root@linaro-ubuntu-desktop:~$ apt-get install vim

这里安装完成后就可以按照下面NFS安装配置内容进行操作了。

另外,再补充两个问题:

  1. 关于apt-get安装软件时遇到的dpkg问题
    在这里插入图片描述
    在这里插入图片描述
    这是我第一次安装软件时遇到的问题,当时也是搞了好久,查了一次文章资料0.0.0.0 (很抓狂,没几步就有好多坑)。这里贴一下操作流程:
root@linaro-ubuntu-desktop:~$ mv /var/lib/dpkg/info/ /var/lib/dpkg/info_backup/	#将当前的info文件改名为info_backup做备份
root@linaro-ubuntu-desktop:~$ mkdir /var/lib/dpkg/info/	#新建一个info文件夹
root@linaro-ubuntu-desktop:~$ apt-get update	
root@linaro-ubuntu-desktop:~$ apt-get -f install	#执行这两个命令更新一下
#对于我的情况,到这里就可以正常install软件
#网上找到的资料还有后续步骤,这里也一并贴出来
root@linaro-ubuntu-desktop:~$ mv /var/lib/dpkg/info/* /var/lib/dpkg/info_backup	#将新生成的info文件夹里的内容移动到info_backup下
root@linaro-ubuntu-desktop:~$ rm -rf /var/lib/dpkg/info	#删除自己建的info文件夹
root@linaro-ubuntu-desktop:~$ mv /var/lib/dpkg/info_backup /var/lib/dpkg/info	#将info_backup改为info
  1. 静态IP设置
    设置静态IP可以通过修改 /etc/network/interfaces 文件来实现,具体操作如下:
root@linaro-ubuntu-desktop:~$ vim /etc/network/interfaces	#文件内容如下。这里的IP是为了后面和Ubuntu挂载的时候用!

#interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static

       address 192.168.3.101
       gateway 192.168.3.255
       netmask 255.255.255.0

保存文件后reboot就可以了。

二、NFS安装配置

1、服务端的NFS配置

  1. 首先打开虚拟机,在Ubuntu的终端命令窗口中下载NFS服务。
claude1009@ubuntu:~$ apt-get update
claude1009@ubuntu:~$ sudo apt-get install nfs-kernel-server
  1. 因为NFS的挂载目录及权限在 /etc/exports 文件中定义,这里需要root权限。
claude1009@ubuntu:~$ sudo vim /etc/exports

在这里插入图片描述
这里我选择挂载的目录为 /home/claude1009 ,IP为 192.168.3.*


NFS服务的配置文件:/etc/exports
添加内容格式:[共享的目录] [主机名或IP(参数…参数)]
当将同一目录共享给多个客户端,但对每个客户端提供不同权限时。
可以这样:[共享的目录] [主机名1或IP1(参数1,参数2)] [主机名2或IP2(参数3,参数4)]

后面的相关参数可参考如下:

 ro                   只读访问 
 rw                   读写访问 
 sync                 所有数据在请求时写入共享 
 async                NFS在写入数据前可以相应请求 
 secure               NFS通过1024以下的安全TCP/IP端口发送 
 insecure             NFS通过1024以上的端口发送 
 wdelay               如果多个用户要写入NFS目录,则归组写入(默认) 
 no_wdelay            如果多个用户要写入NFS目录,则立即写入,当使用async时,无需此设置。 
 Hide                 在NFS共享目录中不共享其子目录 
 no_hide              共享NFS目录的子目录 
 subtree_check        如果共享/usr/bin之类的子目录时,强制NFS检查父目录的权限(默认) 
 no_subtree_check     和上面相对,不检查父目录权限 
 all_squash           共享文件的UID和GID映射匿名用户anonymous,适合公用目录。 
 no_all_squash        保留共享文件的UID和GID(默认) 
 root_squash          root用户的所有请求映射成如anonymous用户一样的权限(默认) 
 no_root_squas        root用户具有根目录的完全管理访问权限 
 anonuid=xxx          指定NFS服务器/etc/passwd文件中匿名用户的UID 

接下来还要修改虚拟机的网络模式和Ubuntu的IP:
首先将虚拟机中的网络连接改为桥接模式,然后点开配置适配器,我们只选择 Realtek USB GbE Family Controller(这里要和主机上的USB-HUB网口名对应上),如下图所示。
在这里插入图片描述
在这里插入图片描述
然后打开Ubuntu的网络设置,修改IPv4的IP地址为 192.168.3.100 ,netmask为 255.255.255.0 ,如下图所示。
在这里插入图片描述
在这里插入图片描述
保存后,打开终端PING一下开发板。

claude1009@ubuntu:~$ ping 192.168.3.101
PING 192.168.3.101 (192.168.3.101) 56(84) bytes of data.
64 bytes from 192.168.3.101: icmp_seq=1 ttl=64 time=1.22 ms
64 bytes from 192.168.3.101: icmp_seq=2 ttl=64 time=0.494 ms
64 bytes from 192.168.3.101: icmp_seq=3 ttl=64 time=0.470 ms
64 bytes from 192.168.3.101: icmp_seq=4 ttl=64 time=10.2 ms
64 bytes from 192.168.3.101: icmp_seq=5 ttl=64 time=0.764 ms
64 bytes from 192.168.3.101: icmp_seq=6 ttl=64 time=1.21 ms
^C
--- 192.168.3.101 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5076ms
rtt min/avg/max/mdev = 0.470/2.406/10.268/3.529 ms

这下虚拟机Ubuntu网络就已经和开发板连通了,不容易啊0.0.0.0.0

2、客户端的NFS配置

开发板客户端这边已经在连外网的时候进行了nfs-common的安装,这里可以直接mount挂载到Ubuntu上的共享目录,这里我选择挂载到开发板的/mnt目录下。

root@linaro-ubuntu-desktop:~$ mount -t nfs -o nolock 192.168.3.100:/home/claude1009 /mnt
root@linaro-ubuntu-desktop:~$ cd /mnt
root@linaro-ubuntu-desktop:/mnt$ ls
Desktop    examples.desktop         vivado_2217.backup.jou
Documents  vivado.jou               vivado_2217.backup.log
Downloads  vivado.log               vivado_31905.backup.jou
Music      vivado_10970.backup.jou  vivado_31905.backup.log
Pictures   vivado_10970.backup.log  vivado_pid2083.str
Public     vivado_1856.backup.jou   vivado_pid2174.str
Templates  vivado_1856.backup.log   xc7030
Videos     vivado_2083.backup.jou
Xilinx     vivado_2083.backup.log

终于终于,开发板通过NFS服务成功挂载了0.0.0.0
下面我们写个简单的hello world程序来体验下!
在Ubuntu下写一个helloworld.c程序,如下所示:

#include <stdio.h>

int main()
{
	printf("Hello World!\n");
	return 0;
}

然后用Xilinx的arm工具链对这个C程序编译,就可以看见输出helloworld文件。

claude1009@ubuntu:~/xc7030/demo$ arm-linux-gnueabihf-gcc helloworld.c -o helloworld
claude1009@ubuntu:~/xc7030/demo$ ls
helloworld  helloworld.c

在开发板端,进入到/mnt目录下就可以看见刚才编译完成的helloworld文件,然后运行即可。

root@linaro-ubuntu-desktop:~$ cd /mnt
root@linaro-ubuntu-desktop:/mnt$ cd xc7030/demo/
root@linaro-ubuntu-desktop:/mnt/xc7030/demo$ ls
helloworld  helloworld.c
root@linaro-ubuntu-desktop:/mnt/xc7030/demo$ ./helloworld
Hello World!

成功运行!!!! 太好了0.0.0.0

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Claudedy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值