Use FTP in embedded system to implement communication between host machine and target machine

Source: Internet
Author: User

In embedded development, due to limited resources on the embedded development board, file compilation is not allowed. Therefore, we compile all the written code on the host machine (PC) for debugging and then generate a binary file, then transmitted to the Development Board through TFTP or NFS. But how to configure TFTP? After some configuration, I finally succeeded. Here I will share with you.

Environment: tq2440 Development Board

Linux Kernel: linux2.6.25

PC: centos6.0

Now, let's get started with configuration!

First, we need to use the host machine (PC) as the server, because we want to download files from the computer to the Development Board. Install the TFTP service on the PC server and client.

# Yum TFTP. i386 TFTP-server-***. i386

After installation, edit VI/etc/xinetd. d/TFTP

Service tftp
...{
Socket_type = dgram
Protocol = UDP
Wait = Yes
User = root
Server =/usr/sbin/in. tftpd
Server_args =-S/tftpboot
Disable = No
}

Change disable to No. Save and exit.

Next, create the default tftp root directory, which should be the same as the preceding server_args path. Here is/tftpboot:

# Cd/

# Mkdir tftpboot

#/Etc/rc. d/init. d/xinetd restart
Stop xinetd: [OK]
Start xinetd: [OK]

Enter setup in the command line

# Setup

Select <system services> select TFTP and remove the iptables option. You must also select Portmap (Port ing). If this option is not available in the system, you must install related services. Then, yum install Portmap will be OK.

Again

#/Etc/rc. d/init. d/xinetd restart

In this case, TFTP is configured. Now the client (Development Board) can upload and download files to the/tftpboot directory on the PC end.

In this case, how does one use TFTP to upload and download all files on the client. This is a little different from the PC end. Enter the terminal on the Development Board.

# TFTP

Usage: TFTP [Option]... host [port]

Transfer a file from/to TFTP Server

Options:

-L file local file
-R File Remote File
-G get File
-P put File
-B Size transfer blocks of size octets
Parameter description:
-L is the abbreviation of local, followed by the name of the renamed file after local or download to local.
-R is short for remote, followed by the file name in the root directory of the TFTP server on the PC, or the renamed file name after being uploaded to the PC.
-G is short for get. It is used to download a file, followed by the IP address of the PC.
-P is short for put. It is used when uploading files, followed by the IP address of the PC.
By default, TFTP uses port 69 to download files: [root @ wanyao/] # TFTP-l hello_arm-r hello_arm -G192.168.1.103 69
Upload a file: [root @ wanyao/] # TFTP-l hello_arm-r hello_arm -P192.168.1.103 69, where 192.168.1.103 is the IP address of the host machine

Note: When downloading or uploading a file, it is recommended that the file name on the server be the same as the local file name. Otherwise, the file size is 0 kb. If this problem occurs, run the command several times. Because the TFTP service is based on the UDP protocol, the file cannot be correctly transmitted.
Problems and causes during installation
Symptom 1:
TFTP> get test. Log
Transfer timed out.
Cause:
Tftpd service not started

Symptom 2
TFTP> put Test2
Error code 0: Permission denied

Cause:
Run the command to view system logs.
# Tail/var/log/messages
The following text is found:
Mar24 19:05:26 localhost setroubleshoot: SELinux is preventing
/Usr/sbin/in. tftpd (tftpd_t) "write" to tftpboot (tftpdir_t).
Complete SELinux messages. Run sealert-l
40a5a6bf-8ded-4bfa-ab6e-fa669a25fc6c
It is known that this is caused by SELinux. In FC versions after FC3 and FC3, SELinux is enabled by default. disable it, modify the file/etc/sysconfig/SELinux, and set

SELinux = disabled

Restart your computer.

Or run the system-config-securitylevel command to open the "security level Configuration" dialog box and change "force" in SELinux (s) to "allow ".

Symptom 3:
TFTP> put ex070416.log
Error Code 1: file not found
Cause:
The specified file does not exist; or the-C option is not specified in the tftpd startup parameter, allowing the file to be uploaded

Symptom 4:
TFTP> get test. Log
Error Code 2: only absolute filenames allowed
Cause:
Set server_args in/etc/xinetd. d/tftpd to/etc/default/tftpd-HPA
CAT/etc/default/tftpd-HPA
# Defaults for tftpd-HPA
Run_daemon = "no"
Options = "-S/home/tftpd-C-p-u 077-u tftpd"
You only need to change server_args = to the server folder you set.

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.