這是 for Ubuntu 11.04 版本的tftp server安裝與設定方法, 10.x之前版本略有不同, 找了一整晚才找到正確的設定方法.
如果需要在 "Host" "Target board" 之間交換資料, 方法之一就是架個 tftp server.
我的 Ubuntu 是在 VM裡面跑的, 不是本機系統, 需要多作埠號轉向, 讓本機的 69 指到 VM 裡的 69 port.


* 安裝 tftpd-hpa server *
用 apt-get 下載並安裝
root@ubuntu:~# apt-get install tftpd-hpa
修改設定檔
root@ubuntu:~# vim /etc/default/tftpd-hpa
# /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/tftpboot"
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="-l -c -s"

如果是 Ubuntu 10.4 之前版本, 設定檔內容不同 (上面10.4之後的設定找了好久才找到!)
 RUN_DAEMON="yes"
 OPTIONS="-l -c -s tftpboot"
 
建立共享目錄
root@ubuntu:~# mkdir /tftpboot
修改目錄下所有檔權限 (全開,以便上傳下載)
root@ubuntu:~# chmod 777 -R /tftpboot
修改目錄下所有檔擁有者及群組
root@ubuntu:~# chown nobody.nogroup -R /tftpboot
查看權限是否作用
root@ubuntu:~# ls /tftpboot -ld
drwxrwxrwx 2 nobody nogroup 4096 2011-10-10 09:51 /tftpboot
建立一個下載用的測試檔
root@ubuntu:~# echo "This is a tftpd-hpa testfile" > /tftpboot/testfile
重啟 tftpd-hpa 服務
root@ubuntu:~# service tftpd-hpa restart
確認 tftp(69埠) 是否監聽中
root@ubuntu:~# netstat -a | grep tftp
udp        0      0 *:tftp                  *:*  
root@ubuntu:~#


* 安裝 tftp-hpa client *
1. 用 apt-get 下載並安裝
root@ubuntu:~# apt-get install tftp-hpa

2. VM本機連線測試
建立一個即將上傳的檔案
root@ubuntu:~# echo "uploaded file" > 1.txt
連線到 localhost ip
root@ubuntu:~# tftp 127.0.0.1
顯示詳細過程
verbose
抓取檔案
get testfile
放檔案上去
put 1.txt
離開
quit

改用 VM 外部 ip  192.168.33.145 連
查看網卡外連 ip
root@ubuntu:~# ifconfig eth0 | grep addr
用一條指令抓取檔案
root@ubuntu:~# tftp 192.168.33.145 -v -c get testfile
用一條指令放檔案上去 
root@ubuntu:~# tftp 192.168.33.145 -v -c put 1.txt

3. Target board 測試, 連到主電腦 ip 192.168.2.110, 再利用 Port forwarding 轉到 VM ip 同樣是 69埠
查看 VM 網卡 ip
root@ubuntu:~# ifconfig eth0
在 VMWare 設定埠號轉向功能, 將連到 Host 69 的連線轉到 192.168.33.145 69
VMware® Workstation 7.0 ->Editor ->Virtual Network Editor ->VMnet8 ->NAT settings-> Add -> 69, UDP, 192.168.33.145, 69, ubuntu_11_tftp ->OK

開啟 RS-232 連線程式
root@ubuntu:~#  minicom
接好 DMA-6410L 開電源到 OS(Android)
設定開發板網卡 ip
# busybox ifconfig eth0 192.168.2.55
進入 sd 卡的目錄 (其他目錄可能會遇到唯讀)
# cd /sdcard
抓取檔案 (從 Host 電腦抓到板子)
# busybox tftp -g -r testfile 192.168.2.110 (注意這裡是連到 Host ip, 不是 VM ip )
顯示抓到的檔案內容
# cat testfile                                                                 
This is a tftpd-hpa testfile                                   
建立一個上傳用的檔案
# echo "DMA-6410L uploaded file" > 2.txt
放檔案上去 (從板子上傳到 Host 電腦)
# busybox tftp -p -l 2.txt 192.168.2.110
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 aries 的頭像
    aries

    aries's Embedded Notes

    aries 發表在 痞客邦 留言(0) 人氣()