注册 登录
电子工程世界-论坛 返回首页 EEWORLD首页 频道 EE大学堂 下载中心 Datasheet 专题
gongping11的个人空间 https://home.eeworld.com.cn/space-uid-67414.html [收藏] [复制] [分享] [RSS]
日志

嵌入式开化环境搭建2- nfs和tftp的安装配置

已有 3934 次阅读2011-9-18 15:37 |个人分类:嵌入式学习-uboot移植

嵌入式开发环境搭建,继前一篇开发环境搭建完成以后,忙了一段时间tftpnfs的基本安装和配置。其实基本的环境搭建完成就能实现开化了,但是为了减少程序烧写对flash的损伤以及提高编译下载的速度。实现基于网络的开发环境搭建——NFSTFTP的安装与配置。


NFSNetwork File System的简称,该服务可以实现不同的机器、不同的操作系统之间彼此共享文件。NFS可以让不同的主机通过网络将远端的NFS服务器共享出来的文件安装到自己的系统中,从客户端看来,使用NFS的远端文件就像是使用本地文件一样。NFS这种特性使它在嵌入式系统中得到了广泛的应用,它使得应用程序开发调试变得更加方便,不用反复烧写镜象文件。主要是避免反复的烧写文件。

TFTP是简单文件传输协议,是嵌入式系统中通过网络下载映像最常用的一种方法,它可以看作是FTP协议的简化版本,与FTP协议相比,最大的区别在于没有用户管理功能,并且传输速度快可以通过防火墙,使用方便快捷。同FTP一样,TFTP分为客户端和服务端两种。通常首先在宿主机上开启TFTP服务器端,设置好TFTP的根目录内容(也就是供下载的文件),接着,在目标板上开启TFTP的客户端程序。这样,把目标板和宿主机用直线连接之后,就可以通过TFTP协议传输可执行文件了。TFTP主要实现快速的下载程序,提高开发的速度。


我的主机环境是Fedora14,比较新的系统。我通过编辑/etc/sudoers实现了普通用户的sudo权限。

安装NFS服务。

基本的安装过程:

1、检测是否安装了NFS服务:

[gong@EmbedSky /]$ rpm -qa | grep nfs

system-config-nfs-1.3.51-1.fc14.noarch

nfs-utils-1.2.3-0.fc14.i686

nfs-utils-lib-1.1.5-2.fc14.i686

system-config-nfs-docs-1.0.9-1.fc14.noarch

以上说明NFS已经安装好了,因此只需要进行配置。如果没有安装完成通过如下的方式实现NFS的基本安装。

sudo yum install nfs*yum 实现软件的下载安装)

2、实现配置

首先设置的是需要共享的文件夹:vi /etc/profile,通常打开是一个空白文档。

书写内容的基本形式:分享的目录 主机名称1IP1(参数1,参数2) 主机名称2IP2(参数3,参数4)

参数的选择:

rw: 可擦写的权限
ro:
只读的权限
no_root_squash:
登入 NFS 主机使用分享目录的使用者,如果是 root 的话,那么对于这个分享的目录来说,他就具有 root 的权限!这个项目『极不安全』,不建议使用!
root_squash:
在登入 NFS 主机使用分享之目录的使用者如果是 root 时,那么这个使用者的权限将被压缩成为匿名使用者,通常他的 UID GID 都会变成 nobody 那个身份;
all_squash:
不论登入 NFS 的使用者身份为何,他的身份都会被压缩成为匿名使用者,通常也就是 nobody 啦!
anonuid:
前面关于 *_squash 提到的匿名使用者的 UID 设定值,通常为 nobody,但是你可以自行设定这个 UID 的值!当然,这个 UID 必需要存在于你的 /etc/passwd 当中!
anongid:
anonuid ,但是变成 group ID 就是了
sync:
资料同步写入到内存与硬盘当中
async:
资料会先暂存于内存当中,而非直接写入硬盘

输入:/opt/filesystem *(rw,sync,no_root_squash)

保存!!!!

基本的含义是:共享的目录是:/opt/filesystem

*表示可以访问的IP地址,在此没有设置,表示所有的主机都可以进行访问。也可以进行基本的设置比如设置为:192.168.1. 。这样只有IP地址在该网段的主机才能才能实现共享。

3、为了能够实现基本的权限,将该目录的读写权限设置为chmod 777 filesystem

4、由于Fedora14采用的是NFS4的协议,而我们通常使用的是NFS2或者NFS3版本的服务,因此需要取消NFS4,实现过程如下:

vi/etc/sysconfig/nfs

# Turn off v4 protocol support

去掉#RPCNFSDARGS="-N 4"所在行的#,实现关闭NFS4的功能。


5、重启NFS服务

sudo /etc/init.d/nfs restart

5、关闭防火墙,这一步非常的重要,需要特别注意。

[gong@EmbedSky /]$ sudo /etc/init.d/iptables status

[sudo] password for gong:

表格:filter

Chain INPUT (policy ACCEPT)

num target prot opt source destination

Chain FORWARD (policy ACCEPT)

num target prot opt source destination

Chain OUTPUT (policy ACCEPT)

num target prot opt source destination

以上表明防火墙以及关闭了。如果没有则需要执行

列出几个关掉Linux防火墙的方法

	service iptables stop 
	service iptables start
	redhat-config-securitylevel

永久关闭防火墙

	service iptables stop

chkconfig iptables off

这些都能够实现防火墙的关闭。

最后还要关闭Selinux管理,通过系统-》管理-Selinux管理-》将当前应用模式的“强制”设置为“允许”。

实现NFS的测试:在本机做测试:

mount -o nolock -t nfs 192.168.1.8:/opt/filesystem /mnt/nfs

通过就说明安装配置成功了,还需要然后就可以通过/mnt/nfs仿问/opt/filesystem下的文件。

取消挂载:umount nfs就取消了挂载。


TFTP的基本安装和配置

1、检测是否安装了tftp

rpm -qa | grep tftp

2.安装tftp

yum install tftp-server

yum install tftp

3、配置tftp服务器

[gong@EmbedSky /]$ sudo vi /etc/xinetd.d/tftp


# default: off

# description: The tftp server serves files using the trivial file transfer \

# protocol. The tftp protocol is often used to boot diskless \

# workstations, download configuration files to network-aware printers, \

# and to start the installation process for some operating systems.

service tftp

{

#主要是关闭disable,将他设置为 no,同时设置服务器的路劲

disable = no

socket_type = dgram

protocol = udp

wait = yes

user = root

server = /usr/sbin/in.tftpd

server_args = -s /tftpboot -c

per_source = 11

cps = 100 2

flags = IPv4

}

-s /tftpboot表示为服务器的根目录是/tftpboot-c表示可以创建文件

保存!!!

PC跟目录下创建一个/tftpboot,

>mkdir /tftp

设置权限

>chmod 777 /tftp

启动服务

>service xinetd restart

本机测试:

>tftp localhost

tfpt>get hello.c

Error code 0: Permission denied

这个问题需要设置Selinux管理,通过系统-》管理-Selinux管理-》将当前应用模式的“强制”设置为“允许”。即可解决问题。

以上就实现了所有的设置,实际上安装完成以后可以通过setup中的系统服务选择开启服务。选择nfstftp即可实现开启。



实现PCTQ2440的网络下载和NFS文件系统

TFTP下载,关于uboot的移植还没有进行,现在采用天嵌提供的uboot实现内核的下载。

首先是下载:

##### EmbedSky BIOS for SKY2440/TQ2440 #####

Press Space key to Download Mode !

##### Boot for Nor Flash Main Menu #####

##### EmbedSky USB download mode #####

[1] Download u-boot or STEPLDR.nb1 or other bootloader to Nand Flash

[2] Download Eboot (eboot.nb0) to Nand Flash

[3] Download Linux Kernel (zImage.bin) to Nand Flash

[5] Download CRAMFS image to Nand Flash

[6] Download YAFFS image (root.bin) to Nand Flash

[7] Download Program (uCOS-II or TQ2440_Test) to SDRAM and Run it

[8] Boot the system

[9] Format the Nand Flash

[0] Set the boot parameters

[a] Download User Program (eg: uCOS-II or TQ2440_Test)

[b] Download LOGO Picture (.bin) to Nand Flash

[l] Set LCD Parameters

[n] Enter TFTP download mode menu

[o] Download u-boot to Nor Flash

[r] Reboot u-boot

[t] Test Linux Image (zImage)

[q] quit from menu

Enter your selection: n

##### Boot for Nor Flash Main Menu #####

##### EmbedSky TFTP download mode #####

[1] Download u-boot.bin to Nand Flash

[2] Download Eboot (eboot.nb0) to Nand Flash

[3] Download Linux Kernel (zImage.bin) to Nand Flash

[4] Download stepldr.nb1 to Nand Flash

[5] Set TFTP parameters(PC IP,TQ2440 IP,Mask IP...)

[6] Download YAFFS image (root.bin) to Nand Flash

[7] Download Program (uCOS-II or TQ2440_Test) to SDRAM and Run it

[8] Boot the system

[9] Format the Nand Flash

[0] Set the boot parameters

[a] Download User Program (eg: uCOS-II or TQ2440_Test)

[b] Download LOGO Picture (.bin) to Nand Flash

[l] Set LCD Parameters

[o] Download u-boot to Nor Flash

[p] Test network (TQ2440 Ping PC's IP)

[r] Reboot u-boot

[t] Test Linux Image (zImage)

[q] Return main Menu

Enter your selection: 5

Enter the TFTP Server(PC) IP address:(xxx.xxx.xxx.xxx)

172.16.14.40

Enter the SKY2440/TQ2440 IP address:(xxx.xxx.xxx.xxx)

172.16.14.50

Enter the Mask IP address:(xxx.xxx.xxx.xxx)

255.255.255.0

Save TFTP IP parameters?(y/n)

y

##### Boot for Nor Flash Main Menu #####

##### EmbedSky TFTP download mode #####

[1] Download u-boot.bin to Nand Flash

[2] Download Eboot (eboot.nb0) to Nand Flash

[3] Download Linux Kernel (zImage.bin) to Nand Flash

[4] Download stepldr.nb1 to Nand Flash

[5] Set TFTP parameters(PC IP,TQ2440 IP,Mask IP...)

[6] Download YAFFS image (root.bin) to Nand Flash

[7] Download Program (uCOS-II or TQ2440_Test) to SDRAM and Run it

[8] Boot the system

[9] Format the Nand Flash

[0] Set the boot parameters

[a] Download User Program (eg: uCOS-II or TQ2440_Test)

[b] Download LOGO Picture (.bin) to Nand Flash

[l] Set LCD Parameters

[o] Download u-boot to Nor Flash

[p] Test network (TQ2440 Ping PC's IP)

[r] Reboot u-boot

[t] Test Linux Image (zImage)

[q] Return main Menu

Enter your selection: 3

dm9000 i/o: 0x20000300, id: 0x90000a46

MAC: 0a:1b:2c:3d:4e:5f

TFTP from server 172.16.14.40; our IP address is 172.16.14.50

Filename 'zImage.bin'.

Load address: 0x30000000

Loading: T #################################################################

#################################################################

#######

done

Bytes transferred = 1997952 (1e7c80 hex)

NAND erase: device 0 offset 0x200000, size 0x300000

Erasing at 0x4e0000 -- 100% complete.

OK

NAND write: device 0 offset 0x200000, size 0x1e7c80

Writing data at 0x3e7800 -- 100% complete.

1997952 bytes written: OK

实现了tftp的下载功能。


Nfs的挂载

启动以后出现

eth0: link down

Try to bring eth0 interface up ...

ifconfig eth0 hw ether 10:23:45:67:89:ab

eth0: link down

ifconfig eth0 192.168.1.6 netmask 255.255.255.0 up

open device leds: No such file or directory

add default gw 192.168.1.2



Please press Enter to activate this console. eth0: link up, 100Mbps, full-duple1

这与我实际的IP 地址不符合,因此需要重新配置IP地址。

[root@EmbedSky /]# ifconfig eth0 172.16.14.50

[root@EmbedSky /]# ifconfig

eth0 Link encap:Ethernet HWaddr 10:23:45:67:89:AB

inet addr:172.16.14.50 Bcast:172.16.255.255 Mask:255.255.0.0

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:229 errors:0 dropped:0 overruns:0 frame:0

TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:42295 (41.3 KiB) TX bytes:0 (0.0 B)

Interrupt:51

lo Link encap:Local Loopback

inet addr:127.0.0.1 Mask:255.0.0.0

UP LOOPBACK RUNNING MTU:16436 Metric:1

RX packets:0 errors:0 dropped:0 overruns:0 frame:0

TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

配置好网络以后,互相的ping

[root@EmbedSky /]# ping 172.16.14.40

PING 172.16.14.40 (172.16.14.40): 56 data bytes

64 bytes from 172.16.14.40: seq=0 ttl=64 time=2.688 ms

64 bytes from 172.16.14.40: seq=1 ttl=64 time=0.910 ms

64 bytes from 172.16.14.40: seq=2 ttl=64 time=0.911 ms

64 bytes from 172.16.14.40: seq=3 ttl=64 time=0.906 ms


PC ping TQ2440

[gong@EmbedSky filesystem]$ ping 172.16.14.40

PING 172.16.14.40 (172.16.14.40) 56(84) bytes of data.

64 bytes from 172.16.14.40: icmp_req=1 ttl=64 time=0.071 ms

64 bytes from 172.16.14.40: icmp_req=2 ttl=64 time=0.063 ms

64 bytes from 172.16.14.40: icmp_req=3 ttl=64 time=0.063 ms

64 bytes from 172.16.14.40: icmp_req=4 ttl=64 time=0.055 ms

64 bytes from 172.16.14.40: icmp_req=5 ttl=64 time=0.063 ms


以上说明实现了两者之间的通信。


挂载NFS文件系统

我的文件系统是处于/opt/filesystem目录。因此在TQ的界面下实现挂载/opt/filesystem,其中的主要内容如下:

[gong@EmbedSky filesystem]$ ls -al

总用量 20

drwxrwxrwx. 3 root root 4096 918 14:38 .

drwxr-xr-x. 9 root root 4096 918 09:12 ..

-rwxrwxr-x. 1 gong gong 5637 918 12:49 hello

-rw-r--r--. 1 root root 0 918 14:47 hello.c

drwxr-xr-x. 19 gong gong 4096 124 2010 root_nfs


TQ2440下挂载filesystem

[root@EmbedSky /]# mount -o nolock -t nfs 172.16.14.40:/opt/filesystem /mnt

[root@EmbedSky /]# cd /mnt/

[root@EmbedSky /mnt]# ls -al

drwxrwxrwx 3 root root 4096 Sep 18 2011 .

drwxr-xr-x 1 root root 2048 Jan 1 00:02 ..

-rwxrwxr-x 1 500 500 5637 Sep 18 2011 hello

-rw-r--r-- 1 root root 0 Sep 18 2011 hello.c

drwxr-xr-x 19 500 500 4096 Dec 4 2010 root_nfs

[gong@EmbedSky filesystem]$ cd root_nfs/

[gong@EmbedSky root_nfs]$ ls -al

总用量 76

drwxr-xr-x. 19 gong gong 4096 124 2010 .

drwxrwxrwx. 3 root root 4096 918 14:38 ..

drwxr-xr-x. 2 gong gong 4096 124 2010 bin

drwxr-xr-x. 2 gong gong 4096 124 2010 dev

drwxr-xr-x. 6 gong gong 4096 124 2010 etc

drwxr-xr-x. 3 gong gong 4096 124 2010 home

drwxr-xr-x. 3 gong gong 4096 124 2010 lib

lrwxrwxrwx. 1 gong gong 11 918 12:38 linuxrc -> bin/busybox

drwxr-xr-x. 4 gong gong 4096 124 2010 mnt

drwxr-xr-x. 4 gong gong 4096 124 2010 opt

drwxr-xr-x. 2 gong gong 4096 124 2010 proc

drwxr-xr-x. 5 gong gong 4096 124 2010 root

drwxr-xr-x. 2 gong gong 4096 124 2010 sbin

drwxr-xr-x. 2 gong gong 4096 124 2010 sddisk

drwxr-xr-x. 2 gong gong 4096 124 2010 sys

drwxr-xr-x. 2 gong gong 4096 124 2010 tmp

drwxr-xr-x. 2 gong gong 4096 124 2010 udisk

drwxr-xr-x. 6 gong gong 4096 124 2010 usr

drwxr-xr-x. 2 gong gong 4096 124 2010 var

drwxr-xr-x. 2 gong gong 4096 124 2010 web

因此也实现了文件系统的共享。实现了挂载。

这是我自己的总结。坚持就是胜利!!。

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

热门文章