How to boot SP7021 Linux from TFTP server

The aim of the document is to illustrate how to boot SP7021 Linux from TFTP (Trivial File Transfer Protocol) server. First, you need to install a TFTP server on your Linux PC. Second, you need to download SP7021 source files from SP7021 git server. Third, build image of SPI NOR flash and image of Linux kernel. Fourth, burn image of SPI NOR flash to an SPI NOR flash chip. Finally, turn on power of SP7021 board to boot Linux from TFTP server.

SPI-NOR flash acts as a starter. The image of SPI-NOR flash actually contains boot-loader (x-boot) and u-boot images. SP7021 board needs to be setup to boot from SPI NOR flash. So, when you turn SP7021 board power on, SP7021 starts to load image of boot-loader (x-boot) from SPI NOR flash chip and then runs it. x-boot then loads image of u-boot and then runs it. u-boot sends dhcp commands to get IP address of itself from DHCP server. Once it gets IP address, it starts to download images of Linux kernel from TFTP server. Finally, it sends bootm command to boot Linux. Please follow the following steps.

1. Install TFTP server

First, use apt command to install TFTP server. For example, install package tftpd-hpa by issuing command:

wells@wells-linux:~/q628/sdc$ sudo apt install tftpd-hpa

Second, create a folder for TFTP service. For example, create folder /home/scftp and setup its permission and owners by issuing commands:

wells@wells-linux:~/q628/sdc$ sudo mkdir /home/scftp wells@wells-linux:~/q628/sdc$ sudo chmod 777 -R /home/scftp wells@wells-linux:~/q628/sdc$ sudo chown nobody.nogroup -R /scftp

where ‘-R’ in chmod and chown command means recursive with sub-folder.

Later, you need to copy kernel image and device-tree blob to this folder.

Third, edit tftpd-hpa configuration file, /etc/default/tftpd-hpa, as below:

TFTP_USERNAME="tftp" TFTP_DIRECTORY="/home/scftp" TFTP_ADDRESS="0.0.0.0:69" TFTP_OPTIONS="--secure --create"

where “/home/scftp” is the folder you created for TFTP service. “--secure” means add security. This option is recommended for security as well as compatibility. “--create” means allow new files to be created. This is optional.

Fourth, re-start TFTP server to validate the new settings.

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. After configuration menu pops up, first, choose board you want to build image for. For example, press 1 for SP7021 Ev Board. Second, press 1 for selecting C-chip. Next, press 5 to select to configure for booting from TFTP server. Refer to screenshot below:

After press enter, make config will ask you to enter IP address of your TFTP server. Generally, you will set up your TFTP server in the machine as you build (compile) your Linux image. Please enter IP address of your TFTP server. Refer to screenshot below, IP address, 172.18.12.62, is entered:

make config will then ask you to enter TFTP service folder. Please enter TFTP service folder. After completing build image, make will copy image of Linux kernel and device-tree blob to the service folder. Refer to screenshot below, TFTP service folder, /home/scftp, is entered:

Note that you should have permission to write files to TFTP service folder.

Finally, make config will ask you to enter MAC address of your target board. If you want to preset (force to set) MAC address of your target board, please enter it. Refer to screenshot below, MAC address, 00:22:60:00:88:20, is entered:

If you don’t want to preset MAC address of your target board (using default random or hardware MAC address), just press enter directly. u-boot will skip presetting MAC address. After you press enter, make config will start to configure building environment. Please wait for a while. It takes 1~2 minutes to complete. After make config completes, you will see screen like:

Basic information, like default config files for xboot, uboot and kernel, dts file (sp7021-ev), cross-compiler are shown.

4. Build NOR image

Run make all command to start to create image of SPI NOR and Linux kernel. It may take several minutes to complete. When make all almost completes, it asks you to select iBoot, like:

Please select x. After make all completes, you will see screen like:

A binary file, spi_all.bin, for SPI NOR flash is built. Linux kernel image, uImage is built, renamed to uImage_xxxx and copied to TFTP service folder, /home/scftp. Linux device-tree blob, dtb, is built, renamed to dtb_xxxx and copied to TFTP service folder, /home/scftp. A926 image is built, renamed to a926_wellslu and copied to TFTP service folder, /home/scftp. xxxx is account of yours.

5. Burn your SPI NOR flash

Load binary file, spi_all.bin, to flash programmer application. It is placed at out/. Put your SPI NOR flash chip into socket of flash programmer. Be careful about the pin 1 position of the chip. It should be at the same corner of pin 1 of socket. Refer to screenshot below, a CFEON 64 Mibit (8 MiB) flash chip (EN25QH64) has been programmed and verified successfully.

Remove the SPI NOR flash chip from socket. Note that the size of 'spi_all.bin' is about 620 KiB. So, size of SPI NOR flash chip should be 1 MiB (or 8 Mibit) or greater.

6. In-system Program SPI-NOR flash

Besides, creating pure binary file, spi_all.bin, for SPI-NOR flash for flash programmer, make also creates another binary file, ISPBOOOT.BIN, for in-system program SPI-NOR flash. To in-system program SPI-NOR flash, you need to copy ISPBOOOT.BIN to an USB drive, set SP7021 board to boot from USB drive and then turn on power. U-Boot (which is self-contained in ISPBOOOT.BIN) will write image to SPI-NOR flash directly. Refer to step 7 of https://sunplus.atlassian.net/wiki/spaces/doc/pages/699007567 for details.

7. Install SP7021 Ev Board

a) Plug your SPI NOR flash chip into SPI NOR socket (U12). Be careful about the pin 1 position of chip. It should be at the same corner of pin 1 of socket.

b) Connect your Ethernet cable to RJ-45 socket of Ethernet. You’ll see Link/Act LED is blinking while cable is connected.

c) Set DIP-SW to ON-OFF-ON-OFF for booting from NOR flash (Refer to https://sunplus.atlassian.net/wiki/spaces/doc/pages/460981046 for details).

Refer to picture below:

You are ready to turn SP7021 power on.

8. Turn power on to boot Linux from TFTP server

After you turn on power of SP7021 board, u-boot gets control of CPU. It sends dhcp command out to get IP address of itself from DHCP server. Once IP address is got, it downloads image of A926, image of Linux kernel and device-tree blob from TFTP server, and then boot the image. The image of Linux kernel and device-tree blob u-boot downloads are those you built and copied to TFTP service folder in step 2.

Refer to screenshot below, first, MAC address of Ethernet is preset to 00:22:60:00:88:20 and IP address of TFTP server is set to 172.18.12.62. Second, u-boot starts to send dhcp (BOOTP broadcast 1, BOOTP broadcast 2, …) command to get IP address. It gets IP address, 172.18.12.76, in 1765 milliseconds. It soon starts to download A926 image, a926_wellslu, from TFTP server. After complete downloading image, it starts to boot A926.

Refer to screenshot below, u-boot then starts to download device-tree blob, dtb_wellslu, and Linux image, uImage_wellslu, from TFTP server. After complete downloading images, it starts to Linux kernel.

9. Modify kernel, dtb or rootfs, and re-boot Linux from TFTP server

When you modify Linux kernel or rootfs, you need to re-build build image. make will copy new image of Linux kernel and device-tree blob to TFTP service folder automatically. No need re-burn SPI NOR flash because u-boot is fixed. Just press reset or re-turn on power of SP7021 board, u-boot (in SPI NOR flash) will download images from TFTP server and boot automatically.

Appendix A. Log of Booting from TFTP server (from U-Boot to Linux)

Refer to detailed log below: