Skip to content

Yocto Setup TFTP/NFS

Running a Yocto Root Filesystem on a Variscite Board Using TFTP and NFS

On the Host

Prepare the root filesystem directory:

cd ~/var-fsl-yocto
sudo mkdir rootfs
cd rootfs
sudo tar xvf ../build_xwayland/images/imx8mn-var-som/fsl-image-gui-imx8mn-var-som.tar.gz

Install the NFS server:

sudo apt install nfs-kernel-server

Edit /etc/exports:

sudo nano /etc/exports

And add the following line to it (replace <uname> with the actual username):

/home/<uname>/var-yocto/rootfs    *(rw,sync,no_root_squash,no_all_squash,no_subtree_check)

Restart the NFS server:

sudo /etc/init.d/nfs-kernel-server restart

Install the TFTP server:

Ubuntu 24.04 and newer:

sudo apt install xinetd tftpd-hpa tftp-hpa

Ubuntu 22.04 and older:

sudo apt install xinetd tftpd tftp

Configure tftpd-hpa for Ubuntu 24.04 and newer:

sudo nano /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/tftpboot"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="--secure"

Configure tftpd for Ubuntu 22.04 and older:

ls /usr/sbin/in.tftpd
sudo nano /etc/xinetd.d/tftp
service tftp
{
    protocol = udp
    port = 69
    socket_type = dgram
    wait = yes
    user = nobody
    server = /usr/sbin/in.tftpd
    server_args = /tftpboot
    disable = no
}

Create the TFTP directory and restart the services:

sudo mkdir /tftpboot
sudo chmod -R 777 /tftpboot
sudo systemctl restart xinetd
sudo systemctl restart tftpd-hpa
cd ~/var-fsl-yocto/build_xwayland/
sudo cp /images/imx8mn-var-som/Image.gz /tftpboot
for f in /images/imx8mn-var-som/*.dtb; do if [[ -L $f ]] && [[ $f != *imx8mn-var-som.dtb ]]; then sudo cp $f /tftpboot; fi done
sudo rename 's/Image.gz-//' /tftpboot/Image.gz-*.dtb

Configure the root filesystem:

If the target uses NetworkManager, prevent it from managing the interface used for NFS boot. Add the following to

/home/<uname>/var-yocto/rootfs/etc/NetworkManager/NetworkManager.conf:

[keyfile]
unmanaged-devices=interface-name:eth0

Enable DNS:

sudo ln -fs /proc/net/pnp /home/<uname>/var-yocto/rootfs/etc/resolv.conf

On the Target

Connect to the target's serial console.

Boot the board and press any key to interrupt autoboot and access the U-Boot command line. Run the following commands in U-Boot:

Replace <HOST_IP_ADDRESS> with your host's IP address. Run ifconfig on the host to find it.

Replace <uname> with the actual username.

setenv serverip <HOST_IP_ADDRESS>

setenv nfsroot /home/<uname>/var-yocto/rootfs

setenv bootcmd run netboot
saveenv

Connect the target board to the same network as the host using an Ethernet cable, then power cycle the board. It should boot over NFS.