linux仿真运行环境 (NFS启动)(4)

六 在 arm-linux 里运行我们自己的程序
现在 arm-linux 在 skyeye 上跑起来了, 我们能运行里面的命令, 但这些都是 busybox的,是系统程序。怎样才能在 arm-linux 里运行我们自己的程序呢? 有两种方案,我们不妨讨论一下,择优而录之:

1.在制作根文件系统 initrd.img 的时候把我们自己的程序加进去,比如放在 /usr/bin 里目录下,然后重新生成 initrd.img,并用这个新的根文件系统来运行 arm-linux。其实这是我们的产品在 arm-linux 上发布的最终方式,但这有个缺点: 在产品开发/调试阶段这么做比较麻烦,每修改一次代码就得 build 一次根文件系统。

2.利用挂接 NFS(Network file system) 的方式,我们访问/执行一个网络文件系统上的文件就像它在本地一样,显然这么做能避免第一种方案的弊端! 如何实现呢? 随我来:

(1)在 arm-linux 的宿主机里配置 NFS Server (我用是 Ubuntu,而且是在 vmware 里)
     #apt-get install nfs-kernel-server
     #apt-get install nfs-common
(2)编辑文件 /etc/exports, 内容如下(具体需求由你而定):
     /test                          *(rw,sync,no_root_squash)
     /usr/local/arm/3.3.2/lib       *(ro,sync,no_root_squash)   
(3)配置宿主机的 ip
     #ifconfig eth1 down
     #ifconfig eth1 10.0.0.1 netmask 255.0.0.0 up
     注:你的可能是 eth0, 另外 ip 地址你也可自己定义,只要能和 arm-liux 通信
(4)重启 nfs server
     #/usr/sbin/exportfs
     #/etc/init.d/nfs-kernel-server restart
     #/etc/init.d/portmap restart
(5)在 skyeye 运行 arm-linux,为其配置 ip
     #ifconfig lo down
     #ifconfig eth0 down  
     #ifconfig lo 127.0.0.1 up
     #ifconfig eth0 10.0.0.2 netmask 255.0.0.0 up
     注:可将这几个命令加到 rcS 脚本里,让 arm-linux 启动时帮你做
(6)在 skyeye 上运行 arm-linux,演示 nfs 挂接
     #mount -o nolock 10.0.0.1:/usr/local/arm/3.3.2/lib /lib
     #export LD_LIBRARY_PATH=/lib  
     #mount -o nolock 10.0.0.1:/test /tmp

在宿主机的 /test 下建立文件 hello.c,用 arm-linux-gcc 3.3.2 编译
     #cd /test
     #arm-linux-gcc -o hello hello.c

在 arm-linux 的 /tmp 下看看,是不是有 hello.c 和 hello 这两个文件了? 试着运行看看:
     #cd /tmp
     #./hello

注:为了确认 arm-linux 能和宿主机通信, 可尝试以下手段:
(1)在宿主机上 ping 你的 arm-linux
   #ping 10.0.0.2 -c 2
(2)在 arm-linux 里 ping 你的宿主机
   #ping 10.0.0.1 -c 2
(3)如果相互都 ping 不通过,可这样做:
   重新设置一下 arm-linux 的网络:
   #ifconfig eth0 down
   #ifconfig eth0 up

再重新设置一下宿主机的网络:
   #ifconfig eth1 down
   #ifconfig eth1 up

然后再像上一步那样,相互 ping 对方,直至 ping 通为止。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzywyz.html