使用情境:

embedded 內含 tftp 指令, 電腦安裝 tftp server,

在 embedded console 使用 tftp 指令進行檔案下載或上傳

0. 電腦執行 tftp server:

ex: Tftpd64

0-1. 先確保電腦和 embedded board 位於同一網域

0-2. 執行後, 進入 [setting] -> [TFTP], 

打開 Bind TFTP to this address, 選擇接上 embedded board 的 network interface

OK, restart Tftpd64

0-3. [Server interface] 選擇上述 network interface

 

1. embedded console:

1-1. download file (to embedded)

編輯 download_file.sh

vi download_file.sh

 

if [ $# == 2 ]
then
    TARGET=$1
    IP=$2
 
    echo "*** going to tftp getting $TARGET from $IP ...***"
 
    tftp -g -r $TARGET $IP
    
    if [ "$?" == "0" ]
    then
        echo "*** [$0 ok] do mv to /usr/lib/ & sync & reboot after 5 sec. ...***"
        sleep 5
        mv -f $TARGET /usr/lib/
        sync
        reboot
    else
        echo "*** [error] failed to use tftp ...*** "
    fi
else
    echo "*** [error] MUST input one target file name and one tftp server ip address*** "
fi
 

執行 download_file.sh

sh download_file.sh [target file name] [tftp server ip]

 

1-2. upload file (from embedded)

編輯 upload_file.sh

vi upload_file.sh

if [ $# == 1 ]
then
    IP=$1
    TARGET=xxxxxxxxxx.so
    
    tftp -p -l $TARGET $IP
else
    echo "MUST input one and only one tftp server ip address"
fi

執行 upload_file.sh

sh upload_file.sh [tftp server ip]

 

1-3. upload more files (from embedded)

編輯 upload_file.sh

vi upload_file.sh

if [ $# -gt 0 ]
then
    read -p "Input the tftp server IP address: " IP

    for var in "$@"
    do
        TEST="tftp -p -l $var $IP"
        echo "$TEST"
        tftp -p -l $var $IP
    done
else
    echo " [ $0 ] MUST input the file name(s) needed to be pushed ..., error !"
fi

執行 upload_file.sh

sh upload_file.sh [tftp server ip]

 

 

Reference:

1. tftp server

http://www.tricksguide.com/how-to-setup-a-tftp-server-tftpd32-windows.html

2. prompt for input (shell script)

http://stackoverflow.com/questions/226703/how-do-i-prompt-for-input-in-a-linux-shell-script

3. iterate over arguments (shell script)

http://stackoverflow.com/questions/255898/how-to-iterate-over-arguments-in-bash-script

 

 

 

arrow
arrow
    全站熱搜

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