目录
开发环境
Ubuntu 16.04
安装tftp服务
tftp服务端
$ sudo apt-get install tftpd-hpa
tftp 客户端
建议安装,方便本机测试
$ sudo apt-get install tftp-hpa
配置TFTP服务
$ sudo vim /etc/default/tftpd-hpa
配置如下
# /etc/default/tftpd-hpa
TFTP_USERNAME="hayson"
TFTP_DIRECTORY="/work/tftp"
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="-s"
参数解释
- TFTP_USERNAME 用户名
请使用于ubuntu登录的用户名 - TFTP_DIRECTORY tftp文件目录
输入绝对路径即可,注意修改文件权限,最好chmod -R 777 /work/tftp - TFTP_OPTIONS tftp启动参数
不支持:-l:以standalone/listen模式启动TFTP服务,而不是从inetd启动
不支持:-c:可创建新文件。默认情况下,TFTP只允许覆盖原有文件,不能创建新文件
-s:改变TFTP启动的根目录。举栗子:就是可以直接tftp 0x40000000 test 而不是输入tftp 0x400000000 /work/nfs/test
重启TFTP服务
$ sudo service tftpd-hpa restart
确认tftp服务是否开启
$ ps aux|grep tftp
hayson@hayson-Server:/work/tftp$ ps aux|grep tftp root 32580 0.0 0.0 15180 152 ? Ss 10:37 0:00 /usr/sbin/in.tftpd --listen --user hayson --address 0.0.0.0:69 -s /work/tftp hayson 32737 0.0 0.0 21312 1028 pts/8 S+ 10:38 0:00 grep --color=auto tftp
- 或者
$ netstat-a|grep tftp
hayson@hayson-Server:/work/tftp$ netstat -a | grep tftp udp 0 0 *:tftp *:*
测试
在/work/nfs下新建一个test文件,随便写点字符
Ubuntu 测试
$ tftp localhost
hayson@hayson-Server:/work$ tftp localhost
tftp> get test
tftp> q
hayson@hayson-Server:/work$ cat test
aaaaaaaa
开发板测试
配置开发板网络
setenv ethaddr 00:10:ab:20:81:71
setenv ipaddr 172.16.134.15
setenv netmask 255.255.255.0
setenv gatewayip 172.16.134.1
setenv serverip 172.16.34.85
测试结果如下:
hisilicon # setenv ethaddr 00:10:ab:20:81:71
Warning: gmac0 MAC addresses don't match:
Address in SROM is 00:10:ab:20:81:71
Address in environment is 3e:e2:6c:dd:6f:04
hisilicon # setenv gatewayip 172.16.134.1
hisilicon # setenv netmask 255.255.255.0
hisilicon # setenv serverip 172.16.34.85
hisilicon # ping 172.16.34.85
ETH0: PHY(phyaddr=1, rgmii) link UP: DUPLEX=FULL : SPEED=1000M
MAC: 00-10-AB-20-81-71
Using gmac0 device
host 172.16.34.85 is alive
tftp 测试
$ tftp 0x42000000 test
结果如下:
hisilicon # tftp 0x42000000 test
ETH0: PHY(phyaddr=1, rgmii) link UP: DUPLEX=FULL : SPEED=1000M
MAC: 00-10-AB-20-81-71
Using gmac0 device
TFTP from server 172.16.34.85; our IP address is 172.16.134.15; sending through gateway 172.16.134.1
Filename 'test'.
Load address: 0x42000000
Loading: T #
0 Bytes/s
done
Bytes transferred = 6 (6 hex)
错误记录
-l -c 启动参数不支持
hayson@hayson-Server:/work/tftp$ sudo service tftpd-hpa start
Job for tftpd-hpa.service failed because the control process exited with error code. See "systemctl status tftpd-hpa.service" and "journalctl -xe" for details.
启动参数没加-s
hayson@hayson-Server:/work/tftp$ tftp 127.0.0.1
tftp> get test
Error code 2: Only absolute filenames allowed
查看出错日志
$ tail /var/log/syslog
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处!
更多精彩内容,欢迎访问一只海星的主页