一. TFTP的简介
TFTP(Trivial File Transfer Protocol,简单文件传输协议)是 TCP/IP 协议族中的一个用来在
TFTP代码所占的内存较小,这对于较小的计算机或者某些特殊用途的设备来说是很重要的,这些设备不需要硬盘,只需要固化了TFTP、UDP和IP的小容量只读存储器即可。因此,随着嵌入式设备在网络设备中所占的比例的不断提升,TFTP协议被越来越广泛的使用。
sudo apt-get install tftp-hpa tftpd-hpa
2.TFTP需要一个文件夹来存放文件
mkdir /home/wht/linux/tftpboot
chmod 777 /home/wht/linux/tftpboot
注:要给 tftpboot 文件夹权限,否则的话 uboot 不能从tftpboot 文件夹里面下载文件。
3.配置tftp
3.1安装xinetd。
sudo apt-get install xinetd
3.2 查询/etc/下是否存在 xinetd.conf 文件,没有的话则自己新建一个
ls /etc/xinetd.conf
这里查到有xinetd.conf文件,如果没有,就执行以下指令创建一个 xinetd.conf 文件。
sudo vi /etc/xinetd.conf
创建出来的文件是空白的,修改 xinetd.conf 文件内容如下:
# Simple configuration file for xinetd
#
# Some defaults, and include /etc/xinetd.d/
defaults
{
# Please note that you need a log_type line to be able to use log_on_success
# and log_on_failure. The default is the following :
# log_type = SYSLOG daemon info
}
includedir /etc/xinetd.d
3.3 安装完成以后新建文件/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/linux/linux/tftpboot/
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
启动TFTP服务
sudo service tftpd-hpa start
打开/etc/default/tftpd-hpa 文件,将其修改为如下所示内容:
# /etc/default/tftpd-hpa
TFTP_USERNAME = "tftp"
TFTP_DIRECTORY = "/home/linux/linux/tftpboot"
TFTP_ADDRESS = ":69"
TFTP_OPTIONS = "-l -c -s"
注:修改文件时要使用root权限打开。
sudo service tftpd-hpa restart
sudo service xinetd restart
三. tftp用法
开发板从unbutu获取文件(注意此时必须板子可以ping通unbutu,才可以实现从unbutu下载或者上传文件,一定要根据自己unbutu的ip地址来连接)
tftp 192.168.3.105 //连接unbutu ip地址
TFTP命令行的基本指令:
put:将文件上传到TFTP目录
get:取得TFTP目录上的文件
quit/q:退出TFTP
tftp>get a
tftp>put a
可以在开发板上或者unbutu的那个文件目录下看是否有a这个文件
基本参数:
-g: get,获取文件
-p: put,长传文件
-l FILE:本地的文件,名为FILE
-r FILE:远程的文件,名为FILE
tftp -g -r shall.bin 192.168.3.105 //这个ip地址的服务器获取文件
tftp -p -l shall.bin 192.168.3.105 /从开发板将某个文件上传到服务器
一般开发板使用nfs来挂载文件系统,不太会使用tftp来挂载。