TFTP Server for U-Boot

Setting up a TFTP server inside U-Boot is very simple, and many guides are also available via Google.

Setup TFTP

Install TFTP packages:

1
$ sudo apt-get install openbsd-inetd tftpd tftp
  • Configuration

As root, enable the TFTP server by editing /etc/inetd.conf. Locate the line that looks similar to:

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

Uncomment this line, and add the option and value -s /srv/tftp to the end of this line:

1
# tftp   dgram   udp   wait   root   /usr/sbin/tcpd  /usr/sbin/in.tftpd -s /srv/tftp

Create and modify permissions on the TFTP root directory:

1
2
$ sudo mkdir /srv/tftp
$ sudo chown -R $(whoami) /srv/tftp

Restart the TFTP Service:

1
$ sudo /etc/init.d/xinetd restart

Install additional TFTP packages:

1
$ sudo apt-get install tftp-hpa tftpd-hpa
  • Configuration

As root, edit /etc/default/tftpd-hpa, and locate the line that looks similar to:

1
TFTP_DIRECTORY="/usr/lib/tftpboot"

Change the dir to /srv/tftp.

1
TFTP_DIRECTORY="/srv/tftp"

Create and modify permissions on the TFTP root directory:

1
2
$ sudo mkdir /srv/tftp
$ sudo chown -R $(whoami) /srv/tftp

Restart the TFTP Service:

1
$ sudo service tftpd-hpa restart

Setup TFTP on a Target Device

To setup TFTP on a target device, you will need to:

  • Connect a LAN cable to your target device, and make sure your device is on same local network with your Host PC.
  • Connect a “Serial-To-USB Module” between the target device and Host PC and ensure you have done the correct setup.
  • Power-on your target device, and ensure the device has a bootloader installed in it.

Stop U-boot from autobooting by hitting Enter or Space at the moment you power-on your target device:

1
2
3
4
5
6
7
8
9
10
U-Boot 2015.01 (May 18 2019 - 19:31:53)

DRAM: 3.8 GiB
Relocation Offset is: d6e56000

...

gpio: pin GPIOAO_7 (gpio 7) value is 1
Hit Enter or space or Ctrl+C key to stop autoboot -- : 0
kvim3#

Setup the ip address of the target client and TFTP host server:

1
2
kvim3# setenv ipaddr 192.168.1.249
kvim3# setenv serverip 192.168.1.117

Save the settings:

1
2
3
4
5
kvim3# saveenv
Saving Environment to aml-storage...
mmc env offset: 0x6c00000
Writing to MMC(1)... done
kvim3#

Running saveenv will save the env values to the env partition on the eMMC. You can run defenv to restore the env to the default values.

NOTE

Please confirm that your configuration is correct.

e.g.

1
2
3
4
kvim3#print ipaddr
ipaddr=192.168.1.249
kvim3#print serverip
serverip=192.168.1.117

Test Your TFTP Server

NOTE

VIM1/VIM2/VIM3/VIM3L is u-boot.bin, VIM4 is u-boot.bin.signed.

Make sure you have copied the testing file to the TFTF root path:

1
2
$ ls /srv/tftp/u-boot.bin
/srv/tftp/u-boot.bin

Load a file into the 0x1080000 address:

1
2
3
4
5
6
7
8
9
10
11
12
13
kvim3# tftp 1080000 u-boot.bin
Speed: 1000, full duplex
Using dwmac.ff3f0000 device
TFTP from server 192.168.1.117; our IP address is 192.168.1.249
Filename 'u-boot.bin'.
Load address: 0x1080000
Loading: #################################################################
#################################################################
###############################################
2.5 MiB/s
done
Bytes transferred = 1371504 (14ed70 hex)

If all went well, the terminal print-out should appear similar to what is shown above.

Troubleshooting

  • Check your LAN cable connection, if the terminal print-out looks like:

    1
    2
    3
    4
    kvim3# tftp 1080000 u-boot.bin
    dwmac.ff3f0000 Waiting for PHY auto negotiation to complete......... TIMEOUT !
    dwmac.ff3f0000: No link.
    kvim3#
  • Check your server IP or filename address, if the print-out looks like:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    kvim3#tftp 1080000 u-boot.bin
    Speed: 1000, full duplex
    Using dwmac.ff3f0000 device
    TFTP from server 192.168.1.177; our IP address is 192.168.1.249
    Filename 'u-boot.bin'.
    Load address: 0x1080000
    Loading: T T T T T T T T T T
    Retry count exceeded; starting again
    Speed: 1000, full duplex

    In this example, I had set the server IP address to 192.168.1.177 which is incorrect. It should be 192.168.1.117 instead.

Resources