Configuring a TFTP Server for Linux

Most target boards use the Trivial File Transfer Protocol (TFTP) to download executables to the board. This requires that a TFTP server be available on the system on which you are hosting the Linux development board. On most modern Linux systems, the TFTP server is installed as a part of a network-capable system installation, but it is usually deactivated. This document explains how to activate the TFTP server on your Linux system and how to copy the kernel into an area from which the TFTP server can deliver the kernel to the target.

Note

If a TFTP server is not available on your Linux distribution or installed system, you can obtain a binary version for most Linux distributions from http://www.rpmfind.net/linux/rpm2html/ by searching for the string tftpd.

Ubuntu and Debian users can install the TFTP server with the following command:

# apt-get install xinetd tftpd

Before configuring the TFTP daemon itself, make sure that the entries for the TFTP protocol are not commented out in the /etc/services file. This file is typically consulted by each network service in order to determine the network ports that it should use.

You must be the root user to edit this file. Use your favorite text editor to remove the comment character (#) from the beginning of each line that contains the string tftp. Active TFTP entries in /etc/services should look like the following:

tftp            69/tcp
tftp            69/udp

Depending on the desktop Linux distribution and version you are using, Linux systems typically use one of two mechanisms to activate and manage network servers such as TFTP servers. These are either the Internet Services Daemon (inetd) or, more commonly, the Extended Internet Services Daemon (xinetd). Both of these commands manage a variety of network services by monitoring various network ports and starting the appropriate daemon in response to a valid request. The more modern mechanism is xinetd, and it is generally viewed as being more secure than the older inetd.

To determine which of these mechanisms your system uses to manage Internet services, you can use the system’s ps (process status) command, as in the following example:

# ps -alxww | grep inet
140      0    578      1   0  0  1152  356  do_select  S  ?  0:00  xinetd  ...
  0    500  13361  13336  18  0  1360  508  pipe_read  S  ?  0:00  grep -i  inet

In this example, the system is using the xinetd server, and you should follow the instructions in Configuring a TFTP Server Run by xinetd. If the output from this command shows that your system is running the inetd server, proceed to Configuring a TFTP Server Run by inetd.

Configuring a TFTP Server Run by xinetd

The servers that can be managed by the xinetd daemon are each listed in a server-specific configuration file located in the directory /etc/xinetd.d. The file for the TFTP server is named tftp, and looks like the following:

# default: off
# description: The tftp server serves files using the Trivial File Transfer \
#    Protocol.  The tftp protocol is often used to boot diskless \
#    workstations, download configuration files to network-aware printers, \
#    and to start the installation process for some operating systems.
service tftp
{
    socket_type     = dgram
    protocol        = udp
    wait            = yes
    user            = root
    server          = /usr/sbin/in.tftpd
    server_args     = -s /tftpboot
    disable         = yes
}

To enable the TFTP server, edit this file as the root user, replacing the word yes on the disable line with the word no. Then save the file and exit the editor.

Next, restart the xinetd process to force it to reread its configuration files, as described in Restarting the Service.

Configuring a TFTP Server Run by inetd

The servers that can be managed by the inetd daemon are listed in the file /etc/inetd.conf. Each line in this file contains the entry for a specific server. To enable the TFTP server, edit the file
/etc/inetd.conf as the root user on your system, and locate the line that looks like the following one:

#tftp   dgram   udp     wait    root    /usr/sbin/tcpd  /usr/sbin/in.tftpd

Use your favorite text editor to remove the comment character (#) from the beginning of this line, which causes the inetd daemon to skip this entry when processing the file.

Add the option and value -s /tftpboot to the end of this line. This specifies the directory in which the TFTP server will look for files. This is the directory in which you will put the kernel that the target board will download and boot. The modified entry should resemble the following one:

tftp   dgram   udp   wait   root   /usr/sbin/tcpd  /usr/sbin/in.tftpd -s /tftpboot

Save the modified file and exit the editor.

Next, restart the inetd process to force it to reread its configuration files, as described in Restarting the Service.

Restarting the Service

If your system is running a desktop Linux distribution such as Red Hat Linux, which starts and stops system processes by using run configuration (rc) scripts, you can simply restart the daemon by invoking these scripts in one of the following commands that is appropriate for your daemon:

# /etc/init.d/xinetd restart
# /etc/init.d/inetd restart

This command will stop and then restart all of the services managed by the daemon on your Linux system. In addition to the restart command, you can also issue stop and start commands this way.

Caution

If your Linux system is running Internet services on which other systems depend, restarting the daemon will cause a slight interruption in those services.

After executing this command, the TFTP server will be started on your system in response to incoming TFTP requests, and you can access any files you copied to /tftpboot.

Note

If you need another way to stop the process, the following method will work on any Linux distribution. Send the HUP signal to the running xinetd process. To do this, you must first determine the process ID of the process that is currently running on your system by using the ps process status command, as in the following example:

# ps -alxww | grep xinet
 140    0    578      1   0  0  1152     356  do_select  S  ?  0:00  xinetd 
   0  500  13361  13336  18  0  1360     508  pipe_read  S  ?  0:00  grep -i  xinet

Of course, substitute inetd if that is the service you are using.

The -alxww options to the ps command cause it to display all system processes in an extremely wide listing. The grep command then searches for the string xinet in the resulting listing. This example displays information about a running command whose name or arguments contain the string xinet. Of these, the first is the actual xinetd process, and the third field is its process ID (in this example, 578). The process ID is the information that you will need to restart the process.

After collecting this information, you can cause the xinetd process to reread its configuration file by executing a command like the following:

# kill -HUP 578

Testing the Service

To ensure the TFTP server is running place a small text file in /tftpboot:

# echo "Hello, embedded world" > /tftpboot/hello.txt"

Then execute the following commands:

# tftp localhost
tftp> get hello.txt
Received 23 bytes in 0.1 seconds
tftp> quit