TFTP and NFS

Why is NFS and TFTP?

In embedded development, we have to build and flash system image very often. There is a convinient way to flash and switch different kernel and root filesystem. We can utilize Network File System(NFS) to do this. In general, NFS host multiple rootfs in a centeral server, distrubuted embedded devices can launch rootfs through internet. In 1000Mb LAN enviroment, modify and distrubute kernel and rootfs will extremely easy. High Speed internet only give a very small latency.

So In my case, the idea is R board’s U-Boot has TFTP client, bootscript use TFTP boot and trivial uImage and device tree file, then Mount rootfs from NSF server to boot up R board.

In this case, cross-compiled application just need to build and deploy on the host machine, and run on R board device.

Setup TFTP

1
2
sudo apt-get install tftpd-hpa
sudo vim /etc/rc.local

the rc.local should looks like

1
2
3
4
# By default this script does nothing.
service tftpd-hpa start
exit 0

then run

1
sudo service tftpd-hpa restart

edit tftp configuration file: /etc/default/tftpd-hpa if /srv/tftp/lager is the correct TFTP path, uImage-lager.bin and dtb file should located at here

1
2
3
4
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/srv/tftp/lager"
TFTP_ADDRESS="[::]:69"
TFTP_OPTIONS="--secure"

to utilize the benefit from NFS, we can have multiple bootloader and root filesystem. Following is the idea TFTP folder structure looks like.

1
2
3
4
5
6
7
/svr/tftp/ // TFTP service directory
lager/ // lager from robert repo
uImage-lager.bin
uImage-r8a7790-lager.dtb
vs_lager/ // lager from vs repo
uImage-lager.bin
uImage-r8a7790-lager.dtb

To make sure /srv/tftp should be owned by nobody:nogroup

1
sudo chown -R nobody:nogroup /srv/tftp/

setup xinet

  1. install xinetd package
    sudo apt-get install xinetd

  2. configure /etc/xinetd.d/tftp After configuration, it should looks like following

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    serivce tftp
    {
    protocol = udp
    port = 69
    socket_type = dgram
    wait = yes
    user = nobody
    server = /usr/sbin/in.tftpd
    server_args =/srv/tftp/lager
    disable = no
    }
  3. restart the xinetd and tftp service

    1
    2
    sudo service xinetd restart
    sudo service tftpd-hpa restart

Setup the NFS

the ideal nfs directories should looks like following structure

1
2
3
/svr/nfsroot/ // nfs service directory
res/ // lager from robert repo
vs_res/ // lager from vs repo

make corresponding directories.

  1. Install NFS service, and run nfs service

    1
    2
    sudo apt-get install nfs-kernel-server
    sudo service nfs-kernel-server restart
  2. Edit exports file:
    sudo vim /etc/exports
    add following line in the /etc/exports

    1
    2
    /srv/nfsroot 192.168.23.0/24(rw,sync,no_root_squash)
    /srv/nfsroot/res *(rw, no_subtree_check,sync,no_root_squash,no_all_squash)

This edit will give access permission for corresponding folder.

Export the NFS directories

sudo service nfs-kernel-server restart

Once you see following message

1
2
3
4
* Stopping NFS kernel daemon [ OK ]
* Unexporting directories for NFS kernel daemon... [ OK ]
* Exporting directories for NFS kernel daemon... [ OK ]
* Starting NFS kernel daemon ... [ OK ]

Then NFS service is running.