This note explains how to load kernel and device tree images to the target via Ethernet. It is assumed that the Root Filesystem is already installed in a partition on the SD Card or eMMC as specified in the root= parameter in the bootargs U-Boot variable. With an Ethernet connection available, U-Boot can load images from a TFTP host quickly and easily. This is the development and software manufacturing option that is preferable with U-Boot and Linux.
The download procedure is based on the tftpboot command provided by the U-Boot command interface. tftboot implements a download capability over Ethernet using the TFTP protocol and has the following synopsis:
tftpboot <file> [<load_addr>]
If you do not specify a load address, then the value will be taken from the loadaddr environment variable. On the Emcraft i.MX 8M SOM, loadaddr is set as follows, placing the download buffer into the on-module DDR:
u-boot=> print loadaddr
loadaddr=0x40480000
u-boot=>
The MAC address of the Ethernet interface is defined by the ethaddr environment variable. The IP address of the board is defined by the ipaddr U-Boot environment variable. The TFTP server IP address is defined by the serverip U-Boot environment variable. Make sure you define these environment variables to values that make sense for your LAN and save them in the persistent storage:
u-boot=> setenv ethaddr C0:B1:3D:88:88:89
u-boot=> setenv ipaddr 192.168.1.151
u-boot=> setenv serverip 192.168.1.65
u-boot=> saveenv
Saving Environment to MMC...
Writing to MMC(1)... done
If there is a DHCP server available in the network the board is connected to, the DHCP IP address assignment can be used instead of static IP address. For this, define the following U-Boot environment variable:
u-boot=> setenv ip_dyn yes
u-boot=> saveenv
Saving Environment to MMC...
Writing to MMC(1)... done
Once the transmission using tftpboot finishes, the file will be in memory at the specified load address. The loadaddr environment variable will automatically be set to the address the tftpboot command used. The filesize environment variable will automatically be set to the number of bytes transferred during the load operation.
Then you are free to do whatever you like with the loaded image. You can boot Linux from the image (assuming it is a bootable Linux file), display the memory, etc.
One typical command sequence involving tftpboot is defined in the netboot environment variable, which by default is set in U-Boot as follows:
u-boot=> print netboot
netboot=echo Booting from net ...; run args sdargs; if test ${ip_dyn} = yes; then setenv get_cmd dhcp; else setenv get_cmd tftp; fi; ${get_cmd} ${loadaddr} ${image} && ${get_cmd} ${fdt_addr} ${fdt_file} && run addip && booti ${loadaddr} - ${fdt_addr};
u-boot=>
What netboot does is load from tftpdir in a TFTP host a file defined by image and a Device Tree file defined by fdt_file (the tftp commands), then add the TCP/IP related parameters to the kernel command string (addip), and finally boot Linux from the just loaded image (bootm).
Let's use netboot to boot Linux via TFTP from the sample Linux image (rootfs.Image) included in the Emcraft software distribution. Copy rootfs.Image to the appropriate (tftpdir) TFTP directory on the host and then from U-Boot on the target set the image environment variable to point to the image:
u-boot=> setenv tftpdir imx8m/
u-boot=> setenv image rootfs.Image
u-boot=> setenv fdt_file rootfs.dtb
u-boot=> saveenv
Saving Environment to MMC...
Writing to MMC(1)... done
u-boot=> run netboot
Booting from net ...
Using ethernet@30be0000 device
TFTP from server 172.17.0.1; our IP address is 172.17.33.41
Filename 'imx8m/rootfs.Image'.
Load address: 0x40480000
Loading: #################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
####
5.6 MiB/s
done
Bytes transferred = 20087296 (1328200 hex)
Using ethernet@30be0000 device
TFTP from server 172.17.0.1; our IP address is 172.17.33.41
Filename 'imx8m/rootfs.dtb'.
Load address: 0x43000000
Loading: ###
1.5 MiB/s
done
Bytes transferred = 42033 (a431 hex)
## Flattened Device Tree blob at 43000000
Booting using the fdt blob at 0x43000000
Using Device Tree in place at 0000000043000000, end 000000004300d430
Starting kernel ...
[ 0.000000] Booting Linux on physical CPU 0x0
[ 0.000000] Linux version 4.9.51-03919-ga36f73d-dirty (dk@dk-emc2.emcraft.com)
(gcc version 6.2.0 (GCC) ) #161 SMP PREEMPT Wed Mar 21 18:24:31 +0400 2018
[ 0.000000] Boot CPU: AArch64 Processor [410fd034]
...
NXP i.MX Release Distro 4.9.51-mx8-beta imx8m-som ttymxc0
imx8m-som login:
Here are some troubleshooting tips, in case tftpboot does not work for you from U-Boot:
- As trivial as it sounds make sure that the board is connected to the LAN with an Ethernet cable.
- Suppose you are still not getting your file from the TFTP server. It is possible that the problem is on the host side - you must set up a TFTP server correctly. Just google for "how to set up a tftp server" and follow the advice from some top articles.
- Make sure you have copied a file you are trying to download to the TFTP server directory on the host.
- Disable the firewall on the host since get enabled, it will block TFTP requests from the target.
- On the target, make sure that you have set ipaddr and serverip correctly. Check ethaddr and make sure that you don't have another embedded board (eg. another Emcraft i.MX 8M SOM) configured for the same MAC address.