How to install and boot SP7021 Linux from NFS server

The aim of the document is to illustrate how to install and boot SP7021 Linux from NFS (Network File System) server. That is, Linux kernel image and device-tree blob are downloaded from NFS server and root file-system of Linux is also mounted from the NFS server.

An SD card will be built to store boot-loader (X-Boot) and U-Boot. When power on SP7021 board, SP7021 loads boot-loader (X-Boot) from the SD card. Boot-loader then loads U-Boot from the SD card. U-Boot downloads Linux image, device-tree blob from NFS server and boot Linux. When Linux boots up, it mounts root file-system from remote root file-system exported by NFS server.

There are several steps you need to do. First, you need to install NFS (Network File System) server in your Linux PC. Second, you need to download sources of SP7021 and build Linux images. Third, copy Linux image, device-tree blob, and root file-system to NFS folders. Fourth, create an environment script file of U-Boot and stored it in SD card. Finally, you can boot Linux from remote file servers. Please follow the following steps.

1. Install NFS server

To mount root file-system of Linux from remote root file-system, you need to install an NFS server in your Linux PC or server. There are five sub-steps to complete this:

First, use apt command to install NFS server. For example, install package nfs-kernel-server by issuing command:

wells@wells-linux:~/q628/sdc$ sudo apt install nfs-kernel-server

Second, create two folders for NFS service. For example, create folder /home/nfs/rootfs and /home/nfs/system by issuing command:

wells@wells-linux:~/q628/sdc$ sudo mkdir -p /home/nfs/system wells@wells-linux:~/q628/sdc$ sudo mkdir -p /home/nfs/rootfs

Later, you need to copy Linux image and device-tree blob to folder /home/nfs/system and copy or link your root file-system of Linux to folder /home/nfs/rootfs

Third, modify NFS configuration file, /etc/exports, to export the folders for NFS service.

/home/nfs/system 192.168.1.0/24(ro,no_subtree_check,no_root_squash) /home/nfs/rootfs 192.168.1.0/24(rw,no_subtree_check,no_root_squash)

Adding the two lines listed above will create the NFS share folders /home/nfs/system and /home/nfs/rootfs. 192.168.1.0/24 is address of sub-net which is allowed to access the share folders.

You can also use * as sub-net address to allow connection from any sub-net. For example:

Fourth, notify the NFS sever that the settings has changed by issuing command:

where “-a” means export all folders listed in the configuration file. “-v” means be verbose.

Fifth, re-start NFS server by issuing commands:

Finally, use showmount command to list folders which have been exported by NFS server. For example, issue command as:

where “-e” means show export list of NFS server.

2. Download source files

Source files of SP7021 can be downloaded from GitHub or Yocto server of SP7021. Refer to https://github.com/sunplus-plus1/SP7021 or 2. HOW TO GET SOURCE FILE AND PACKAGE. Refer to report of ll command for the contents of top folder of source of SP7021:

3. Configure environment

Run make config command on top folder to configure compiler environment. After configuration menu pops up, first, choose board you want to build image for. For example, press 4 for SP7021 Demo Board (V3). Second, press 2 to choose to build image for SD card and then enter to start to configure building environment. Refer to screenshot below, make config is starting to configure building environment. It takes 1~2 minutes to complete.

4. Build all images

Run make all command to start to build all images and files for booting from an SD card. It may take several minutes to complete. After make all completes, you will see screen like:

All images and files are stored at folder out. Refer to report of ll command:

5. Copy Linux kernel image and device-tree blob

Copy uImage and dtb to NFS service folder /home/nfs/system by issuing commands:

Refer to report of ll command, two files has been copied to NFS service folder:

Copy root file system of SP7021 board to NFS service folder /home/nfs/rootfs by issuing command:

where the root file-system of SP7021 board is at linux/rootfs/initramfs/disk. You can copy or link root file-system from other folders.

7. Format your SD card to FAT32 file-system

Internal boot-loader (ROM code) of SP7021 supports only FAT32 file-system. Please format your SD card to FAT32 file-system. To format your SD card, plug your SD card to Linux PC and, for example, if your SD card is mounted on /dev/sdb1, issue commands as:

8. Copy boot-loader files to your SD card

After complete formatting, unplug and re-plug the SD card to let Linux PC mount it automatically again. Copy boot-loader (X-Boot) and U-Boot images from folder, out/boot2linux_SDcard, to the SD card. For example, if your SD card is mounted on /media/wells/1C60-0544, issue commands as:

where ISPBOOOT.BIN is the image of boot-loader (X-Boot) and u-boot.img is the image of U-Boot.

9. Create an environment script file ‘uEnv.txt’ of U-Boot on SD card.

Create a text file named uEnv.txt and add the following commands in it.

where “/home/nfs/system” is the directory of Linux image and device-tree blob exported by NFS server. “/home/nfs/rootfs” is the directory of root file-system exported by NFS server. “192.168.1.118” is the IP address of NSF server. “uImage” is file name of kernel image (with U-Boot header). “dtb” is file name of device-tree blob for kernel. dhcp command is used to get ip addresses of local-host, gateway and DNS, as well as netmask. nfs command is used to download kernel image and device-tree blob to memory addressed ${addr_dst_kernel} and ${addr_dst_dtb}, respectively, from NFS server. “root=/dev/nfs rw” means the root file-system will be mounted using NFS root file-system and it is writable. “nfsroot=${serverip}:${nfs_rootfs_dir}” sets IP address of NFS server and root file-system directory. “vers=4,tcp” means NFS version 4 and TCP are used. “ip=dhcp” means uses DHCP to get ip address of local-host, gateway, and DNS. bootm command is used to boot Linux kernel from memory.

Note that new NFS server does not support UDP based connection. Option “vers=4,tcp” is necessary for new NFS server. If your NFS server is old version which does not support version 4, you need to remove option “vers=4,tcp”.

If you want to use fixed IP address, instead of DHCP, the setting “ip=dhcp” can be changed to:

“${ipaddr} is IP address of local host. ${serverip} is IP address of NFS server. ${gatewayip} is IP address of gateway. ${netmask} is net mask. hostname can be empty. eth0 is name of net interface. off means auto-configuration off.

Save file to your SD card. Refer to report of ll command for the SD card, there are three files in the SD card:

10. Select boot-device

Insert your SD card to SP7021 board and set its DIP-SW to “boot from SD card”. For example, if you are using SP7021 Demo Board (V1/V2/V3), you need to set DIP-SW to ON-ON for booting from SD card. Refer to picture below:

DIP-SW is set to ON-ON. Refer to https://sunplus.atlassian.net/wiki/spaces/doc/pages/460981046 for details of boot selection.

11. Boot from SD card

Turn on power of SP7021 board to start booting. Refer to screenshot below, U-Boot loaded environment script file uEnv.txt and ran scripts in it.

First, a dhcp command was issued to get ip addresses of local-host, gateway, DNS and netmask from DHCP server. Refer to screenshot below:

where message “DHCP client bound to address 192.168.1.106 (2139 ms)” means ip address of local-host has been bound to “192.168.1.106”.
Next, two nfs commands were issued to download Linux kernel image and device-tree blob from NFS server. Refer to screenshot below:

Linux image was downloaded to address 0x307fC0 from NFS server. Its size is 4,319,184 bytes. Device-tree blob was downloaded to address 0x2fffc0 from NFS server. Its size is 19,456 bytes.

Finally, bootm command was issued to boot Linux kernel. Refer to screenshot below:

Refer to screenshot of kernel message, root file-system, nfs4, is mounted, process init runs completely.

Linux boots successfully.

12. Check NFS root

Refer to report of ll command for root:

Refer to report of df command for root, type of root is nfs4.