開發環境
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