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-serverSecond, 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/rootfsLater, 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:
/home/nfs/system *(ro,no_subtree_check,no_root_squash)
/home/nfs/rootfs *(rw,no_subtree_check,no_root_squash)Fourth, notify the NFS sever that the settings has changed by issuing command:
wells@wells-linux:~/q628/sdc$ sudo exportfs -a -v
exporting *:/home/nfs/rootfs
exporting *:/home/nfs/systemwhere “-a” means export all folders listed in the configuration file. “-v” means be verbose.
Fifth, re-start NFS server by issuing commands:
wells@wells-linux:~/q628/sdc$ sudo /etc/init.d/nfs-kernel-server restart
Restarting nfs-kernel-server (via systemctl): nfs-kernel-server.service.Finally, use showmount command to list folders which have been exported by NFS server. For example, issue command as:
wells@wells-linux:~/q628/sdc$ showmount -e
Export list for wells-linux:
/home/nfs/rootfs *
/home/nfs/system *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
GitHub - 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:
wells@wells-linux:~/q628/sdc$ ll
total 52
drwxrwxr-x 12 wells wells 4096 Oct 14 20:54 ./
drwxrwxr-x 15 wells wells 4096 Oct 6 22:15 ../
drwxrwxr-x 8 wells wells 4096 Jun 7 19:59 boot/
drwxrwxr-x 4 wells wells 4096 Aug 23 01:49 build/
drwxrwxr-x 7 wells wells 4096 Jul 27 18:53 crossgcc/
drwxrwxr-x 6 wells wells 4096 Jun 7 19:59 eCos/
drwxrwxr-x 9 wells wells 4096 Jun 15 21:52 freertos/
drwxrwxr-x 8 wells wells 4096 Aug 19 00:21 ipack/
drwxrwxr-x 7 wells wells 4096 Jun 7 19:59 linux/
-r--r--r-- 1 wells wells 23 Jun 7 19:59 Makefile
drwxrwxr-x 4 wells wells 4096 Jun 7 19:59 nonos/
drwxrwxr-x 7 wells wells 4096 Jun 7 19:59 .repo/
drwxrwxr-x 3 wells wells 4096 Jun 27 16:34 yocto/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:
wells@wells-linux:~/q628/sdc$ ll out
total 19848
drwxrwxr-x 3 wells wells 4096 Oct 14 21:09 ./
drwxrwxr-x 13 wells wells 4096 Oct 14 21:09 ../
-rw-rw-r-- 1 wells wells 49152 Oct 14 21:09 a926.img
drwxrwxr-x 2 wells wells 4096 Oct 14 21:09 boot2linux_SDcard/
-rw-rw-r-- 1 wells wells 134144 Oct 14 21:07 down_32M.exe
-rw-rw-r-- 1 wells wells 19456 Oct 14 21:09 dtb
lrwxrwxrwx 1 wells wells 33 Oct 14 21:07 isp.sh -> /home/wells/q628/sdc/build/isp.sh*
lrwxrwxrwx 1 wells wells 34 Oct 14 21:07 part.sh -> /home/wells/q628/sdc/build/part.sh*
-rw-rw-r-- 1 wells wells 17825792 Oct 14 21:09 rootfs.img
-rw-rw-r-- 1 wells wells 426993 Oct 14 21:09 u-boot.img
-rw-rw-r-- 1 wells wells 4319184 Oct 14 21:09 uImage
-rw-rw-r-- 1 wells wells 25296 Oct 14 21:09 xboot.img5. Copy Linux kernel image and device-tree blob
Copy uImage and dtb to NFS service folder /home/nfs/system by issuing commands:
wells@wells-linux:~/q628/sdc$ sudo cp out/uImage /home/nfs/system
wells@wells-linux:~/q628/sdc$ sudo cp out/dtb /home/nfs/systemRefer to report of ll command, two files has been copied to NFS service folder:
wells@wells-linux:~/q628/sdc$ ll /home/nfs/system
total 4176
drwxrwxrwx 2 nobody nogroup 4096 Oct 14 15:14 ./
drwxr-xr-x 4 root root 4096 Jun 7 23:11 ../
-rw-rw-r-- 1 wells wells 19456 Oct 14 15:15 dtb
-rw-rw-r-- 1 wells wells 4245776 Oct 14 15:14 uImage6. Copy or link root file-system of SP7021 board
Copy root file system of SP7021 board to NFS service folder /home/nfs/rootfs by issuing command:
wells@wells-linux:~/q628/sdc$ cp -r linux/rootfs/initramfs/disk/. /home/nfs/rootfswhere 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:
wells@wells-linux:~/q628/sdc$ sudo umount /dev/sdb1
wells@wells-linux:~/q628/sdc$ sudo mkfs -t vfat -F 32 /dev/sdb18. 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:
wells@wells-linux:~/q628/sdc$ cp out/boot2linux_SDcard/ISPBOOOT.BIN /meida/wells/1C60-0544
wells@wells-linux:~/q628/sdc$ cp out/boot2linux_SDcard/u-boot.img /meida/wells/1C60-0544where 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.
#
## uEnv.txt -- boot from NFS server
#
nfs_system_dir=/home/nfs/system
nfs_rootfs_dir=/home/nfs/rootfs
set_server_ip=setenv serverip 192.168.1.118
get_ipaddr=setenv autoload no; dhcp
kernel_image=uImage
kernel_dtb=dtb
nfs_load_kernel=nfs ${addr_dst_kernel} ${serverip}:${nfs_system_dir}/${kernel_image}
nfs_load_dtb=nfs ${addr_dst_dtb} ${serverip}:${nfs_system_dir}/${kernel_dtb}
nfs_bootargs=setenv bootargs console=ttyS0,115200 earlyprintk root=/dev/nfs rw init=/init nfsroot=${serverip}:${nfs_rootfs_dir},vers=4,tcp ip=dhcp user_debug=255
nfs_boot=bootm ${addr_dst_kernel} - ${addr_dst_dtb}
uenvcmd=run set_server_ip; run get_ipaddr; run nfs_load_kernel; run nfs_load_dtb; run nfs_bootargs; run nfs_boot
#
## END
#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:
ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:hostname:eth0:off“${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:
wells@wells-linux:~$ ll /media/wells/1C60-0544/
total 496
drwxr-xr-x 2 wells wells 4096 Jan 1 1970 ./
drwxr-x---+ 3 root root 4096 Oct 15 20:49 ../
-rw-r--r-- 1 wells wells 65536 Oct 14 21:09 ISPBOOOT.BIN
-rw-r--r-- 1 wells wells 426993 Oct 14 21:09 u-boot.img
-rw-r--r-- 1 wells wells 607 Oct 15 20:47 uEnv.txt10. 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 Selection of boot devices of SP7021 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:
~ # ls -al /
drwxrwxr-x 14 root root 4096 Oct 14 2020 .
drwxrwxr-x 14 root root 4096 Oct 14 2020 ..
drwxrwxr-x 2 1000 1000 4096 Oct 14 2020 bin
drwxr-xr-x 6 root root 2400 Jan 1 00:00 dev
drwxrwxr-x 4 1000 1000 4096 Jun 7 2020 etc
lrwxrwxrwx 1 1000 1000 11 Jun 7 2020 init -> bin/busybox
drwxrwxr-x 4 1000 1000 4096 Oct 14 2020 lib
lrwxrwxrwx 1 1000 1000 11 Oct 14 2020 linuxrc -> bin/busybox
drwxrwxr-x 2 1000 1000 4096 Oct 14 2020 mnt
dr-xr-xr-x 83 root root 0 Jan 1 00:00 proc
drwxrwxr-x 3 1000 1000 4096 Oct 15 2020 root
drwxrwxr-x 2 1000 1000 4096 Jun 7 2020 sbin
dr-xr-xr-x 12 root root 0 Jan 1 00:00 sys
drwxrwxrwt 2 root root 40 Jan 1 00:00 tmp
drwxrwxr-x 6 1000 1000 4096 Oct 14 2020 usr
drwxrwxr-x 3 1000 1000 4096 Jun 7 2020 varRefer to report of df command for root, type of root is nfs4.
~ # df -hT /
Filesystem Type Size Used Available Use% Mounted on
192.168.1.118:/home/nfs/rootfs
nfs4 468.0G 81.3G 362.8G 18% /