Shell Script Note 01-tftp server automatic download debugging

Source: Internet
Author: User

As a result of the work to cross-compile the application from the PC repeatedly, and through TFTP download to the ZYNQ board to run debugging. Repeated knocking commands are too cumbersome, so write a script to automate the download, change permissions, and run functions.

First, the preparatory work

Connect the ZYNQ7000 board to the same network segment as the host side (PC or virtual machine).

Host side install TFTPD-HPA server and XINET.D, start running

sudo Service xinetd Restart #开启xinetd服务[sudo for z:xinetd stop/Waiti ngxinetd start4848[email protected]:sudo service tftpd-hpa Restart # Open TFTPD server tftpd-hpa stop/waitingtftpd4880[email protected]:

Install the TFTP service on the Zynq side.

Second, write the script getrun.sh

1#! /bin/SH2 3host="192.168.202.44" #主机地址4 5file_name=$1 #输入参数, host-side file name 6 7info="[ZYNQ-QT]:" #文件执行提示信息8 9 Ten if["$FILE _name"=""] #判断文件名是否为空 One  Then A         Echo$INFO"Not comfirm the file!" #为空则给出提示信息并退出 - Exit - fi the  - Echo$INFO"Get ${file_name} form ${host}\n" #打印提示信息, start tftp download  -  -TFTP ${host} <<!#注意 "<<!", which means waiting for keyboard input + Get ${file_name} - quit +!#键盘输入结束 A  atfile_length=$ (ls-L ${file_name} |awk '{print $}') #获取下载文件的文件长度 -  - if[$FILE _LENGTH-GT0] #如果文件长度大于0  -  Then -  -  Echo "\ n"$INFO"Change mode with EXE" in  -  chmod+x ${file_name} #增加可执行属性 to  +  Echo$INFO"run: {${file_name}}" -  Echo$INFO"----------------------------------\ n" the./${file_name} #运行程序 *  Echo$INFO"----------------------------------" $ Else #如果文件长度等于0, indicating that the download failed Panax Notoginseng  Echo$INFO"[${file_name}] is a bad or broken."  -  Echo$INFO"Remove the Null-file [${file_name}]" the  RM${file_name} #删除空文件 + fi

ZYNQ is running the Linrao Ubuntu system, the first time to download getrun.sh files

[Email protected]:/home/linaro/tftpboot# tftp 192.168.202.44
Tftp> Get getrun.sh
Received 696 bytes in 0.0 seconds
Tftp> quit
[Email protected]:/home/linaro/tftpboot# ls
getrun.sh

Increase execution permissions

chmod +x getrun. SH

Download the TEST_SPI program and execute

[Email protected]:/home/linaro/tftpboot#./getrun.sh TEST_SPI
[Zynq-qt]:get test_spi form 192.168.202.44

Tftp> Received 9334 bytes in 0.1 seconds
Tftp>
[Zynq-qt]:change mode with EXE
[Zynq-qt]:run: {TEST_SPI}
[ZYNQ-QT]:----------------------------------

INIT_SPI1 () + +
Handle_spi1dev = 0
Can ' t set SPI mode to 32bits
Handle_spi1dev = 3
INIT_SPI1 ()--

[ZYNQ-QT]:----------------------------------
[Email protected]:/home/linaro/tftpboot#

If you need to update the getrun.sh, you can run it directly

[Email protected]:/home/linaro/tftpboot#./getrun.SHGetrun.SH[ZYNQ-qt]:get Getrun.SHForm192.168.202.44TFTP> Received696bytesinch 0.0secondstftp>[ZYNQ-qt]:change mode with Exe[zynq-qt]:run: {getrun.SH}[zynq-QT]:----------------------------------[Zynq-qt]:not comfirm the file! This is the updated program, run again, due to missing parameters error[ZYNQ-QT]:----------------------------------[email protected]-ubuntu-desktop:/home/linaro/tftpboot#

Iii. issues to be aware of

    • The first line adds #! /bin/sh, specifying the shell resolver address
    • In variable assignment statements, there can be no spaces on either side of the equal sign
      HOST = "192.168.202.44" is illegal
    • The command line can be enclosed in parentheses, adding $ to assign the execution result to the variable,
    • file_length=$ (ls-l ${file_name} | awk ' {print $} ')
    • If statement the spaces on either side of the square brackets cannot be saved
    • If [$FILE _length-gt 0] will be an error 
    • When a similar TFTP-like tool requires multiple manual input, you can use <<! xxx! specify what you want to enter

Shell Script Note 01-tftp server automatic download debugging

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.