How to build and install SP7021 Linux image to run Raspbian on eMMC

The goal of the document is to illustrate how to build SP7021 image and install it with Raspbian rootfs on eMMC. Raspbian is a famous and popular Linux distribution. It is based Debian and for running on Raspberry Pi boards. Raspbian is released in form of SD card image. Raspbian image file of SD card can be downloaded from web of Raspbian foundation. Users can then write the image file into an SD card. The SD card image consists of two partitions. One is boot partition which is formatted to DOS/Windows FAT32 file-system and the other is rootfs partition which is formatted to Linux Ext4 file-system. boot partition contains files, including boot-loader, Linux kernel image, and etc, for booting from Raspberry Pi boards. rootfs partition contains files of whole root file-system of Linux. To run Raspbian on eMMC on SP7021 platforms, we need to replace all files of rootfs partition of eMMC with Raspbian’s.

This document provides to two methods to replace all files of rootfs partition of eMMC with Raspbian’s. One is to copy all files of rootfs partition of Raspbian to rootfs partition of eMMC directly. The other is to use rootfs partition of Raspbian as source of rootfs when building SP7021 Linux image for eMMC. Step 4 ~ 9 is for method one (A). Step 10 ~ 20 is for method two (B). Step 1 ~ 3 is for both. Please follow the following steps.

1. Download Raspbian image file

Download Raspbian image file, for example “2020-05-27-raspios-buster-full-armhf.zip“ from https://www.raspberrypi.org/downloads/raspbian/.

2 . Unzip image file

Raspbian image file from web is a zipped image file. We need to unzip it. For example, we can use 7-zip to unzip image file. First, download 7-zip from web: https://www.7-zip.org/download.html

Second, run '7-zip' to unzip image file.

3. Write (Burn) the unzip image file to an SD card

Use Win32DiskImager, BalenaEther or other SD card writers to write the unzip Raspbian image to an SD card. Note that size of SD card should be greater than 8 GB. Refer to step 4 of https://sunplus.atlassian.net/wiki/spaces/doc/pages/662569085 for how to write an image file to an SD card. BalenaEther can loaded zipped image file directly, no need to unzip image file before load it.

Method A

4. Get source files, build and install SP7021 Linux image to eMMC

Refer to https://sunplus.atlassian.net/wiki/spaces/doc/pages/701202573, get source files of SP7021, build images, and write SP7021 Linux image to eMMC of SP7021 platform. After finish writing SP7021 Linux image to eMMC, set DIP-SW to boot from eMMC and turn on power to boot from eMMC device. At first boot, Linux will extend root file-system to end of rootfs partition. Refer to log below:

[ 1.747769] mmcblk0: p1 p2 p3 p4 p5 p6 p7 p8 [ 1.770798] EXT4-fs (mmcblk0p8): mounting ext3 file system using the ext4 subsystem [ 1.820259] random: fast init done [ 1.842710] mmc1: new high speed SDHC card at address aaaa [ 1.844094] mmcblk1: mmc1:aaaa SB16G 14.8 GiB [ 2.111919] EXT4-fs (mmcblk0p8): mounted filesystem with ordered data mode. Opts: (null) [ 2.112177] VFS: Mounted root (ext3 filesystem) on device 259:0. [ 2.114187] mmcblk1: p1 p2 [ 2.118216] devtmpfs: mounted [ 2.122654] Freeing unused kernel memory: 1024K [ 2.190434] Run /sbin/init as init process /etc/init.d/rcS starts... Mounting other filesystems ... rc.extra [bg] ******* resize2fs /dev/mmcblk0p8 **************** 0x00005B60 resize2fs 1.45.1 (12-May-2019) 0x00000006 Filesystem at /dev/mmcblk0p8 is mounted on /; on-line resizing required [ 2.467085] EXT4-fs (mmcblk0p8): resizing filesystem from 4110 to 1899447 blocks old_desc_blocks = 1, new_desc_blocks = 1 extra done [ 13.329636] EXT4-fs (mmcblk0p8): resized to 1212416 blocks [ 19.307623] EXT4-fs (mmcblk0p8): resized filesystem to 1899447 The filesystem on /dev/mmcblk0p8 is now 1899447 (4k) blocks long. End of /etc/init.d/rcS login[755]: root login on 'console' ~ #

From log, file system on rootfs partition (/dev/mmcblk0p8) was extended to 1,899,447 blocks (1,899,477 x 4KiB = 7,419 MiB). Note that this step is very important. Without this step, we cannot use all capacity of an eMMC device.

5. Build and install SP7021 Linux image to an SD card

Refer to https://sunplus.atlassian.net/wiki/spaces/doc/pages/662569085, build images again but this time is for booting from SD card. After finish writing SP7021 Linux image to an SD card, set DIP-SW to boot from SD card, plug in the SD card and turn on power to boot from the SD card. Wait for booting completes.

6. Mount rootfs partition of eMMC and remove all files.

After system boots completely, refer to log of commands below, first use mount command to mount rootfs partition of eMMC to folder /mnt. Second, use rm command to remove all files in root file-system of the eMMC device. Note that rootfs partition of eMMC is at /dev/mmcblk0p8.

~ # cd / / # mount /dev/mmcblk0p8 /mnt [ 743.749393] EXT4-fs (mmcblk0p8): mounting ext3 file system using the ext4 subsystem [ 744.103125] EXT4-fs (mmcblk0p8): recovery complete [ 744.103620] EXT4-fs (mmcblk0p8): mounted filesystem with ordered data mode. Opts: (null) / # / # ls -al /mnt drwxr-xr-x 15 root root 4096 Jan 1 00:07 . drwxr-xr-x 15 root root 4096 Jan 1 00:15 .. drwxrwxr-x 2 1000 1000 4096 Jun 22 2020 bin drwxrwxr-x 2 1000 1000 4096 Jun 7 2020 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 Jun 22 2020 lib lrwxrwxrwx 1 1000 1000 11 Jun 22 2020 linuxrc -> bin/busybox drwx------ 2 root root 16384 Jun 22 2020 lost+found drwxrwxr-x 2 1000 1000 4096 Jun 22 2020 mnt drwxrwxr-x 2 1000 1000 4096 Jun 22 2020 proc drwxrwxr-x 3 1000 1000 4096 Jan 1 00:14 root drwxrwxr-x 2 1000 1000 4096 Jun 7 2020 sbin drwxrwxr-x 2 1000 1000 4096 Jun 22 2020 sys drwxrwxr-x 2 1000 1000 4096 Jun 22 2020 tmp drwxrwxr-x 6 1000 1000 4096 Jun 22 2020 usr drwxrwxr-x 3 1000 1000 4096 Jun 7 2020 var / # / # rm -rf /mnt/* / # ls -al /mnt drwxr-xr-x 2 root root 4096 Jan 1 00:28 . drwxr-xr-x 15 root root 4096 Jan 1 00:15 .. ~ #

All files in rootfs partition of eMMC were removed.

7. Plug USB SD card reader with Raspbian SD card.

Plug your Raspbian SD card (created at step 3) into an USB SD card reader and plug your USB SD card reader into USB socket of your SP7021 platform. Refer to log below when you plug in your USB SD card reader.

[ 697.489341] usb 2-1: new high-speed USB device number 2 using ehci1-sunplus [ 697.546404] usb-storage 2-1:1.0: USB Mass Storage device detected [ 697.559843] scsi host0: usb-storage 2-1:1.0 [ 698.611980] scsi 0:0:0:0: Direct-Access SanDisk SDDR-B531 2920 PQ: 0 ANSI: 6 [ 698.613471] sd 0:0:0:0: Attached scsi generic sg0 type 0 [ 698.829899] sd 0:0:0:0: [sda] 30244864 512-byte logical blocks: (15.5 GB/14.4 GiB) [ 698.831952] sd 0:0:0:0: [sda] Write Protect is off [ 698.833951] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA [ 698.920824] sda: sda1 sda2 [ 698.930181] sd 0:0:0:0: [sda] Attached SCSI removable disk

From log, two partitions, sda1 and sda2, are detected. sda1 is boot partition (FAT32) and sda2 is rootfs partition of the Raspbian SD card.

8. Mount rootfs partition to folder /rpi_rootfs

Refer to log below, use mount command to mount rootfs partition of Raspbian SD card to folder /rpi_rootfs.

Use ls command to list contents of rootfs partition of the Raspbian SD card.

8. Copy all files of rootfs partition of the Raspbian SD card to rootfs partition of eMMC

Use cp command to copy all files of rootfs partition (mounted on rpi_rootfs) of the Raspbian SD card to rootfs partition (had mounted on /mnt) of eMMC. Note cp command should be issued with option -a to preserve everything of original files.

Copy processes may take tens minutes to complete. For example, size of rootfs partition of Raspbian is about 6.6 GiB, copy processes take about 50 minutes to complete.

9. Modify fstab

Original Raspbian image uses uuid to mount folders / and /boot in file /etc/fstab. Refer to content of /mnt/etc/fstab:

We don’t need to mount folders / and /boot manually. Please use vi or other text editor to mark out the two lines in /etc/fstab. Refer to new content of /mnt/etc/fstab:

9. Boot Raspbian from eMMC

Remove USB SD card reader, remove SD card, set DIP-SW to boot from eMMC, and then turn on power to boot Raspbian from eMMC device. After Raspbian starts up successfully, it will ask you to enter account name and password. The default user of Raspbian is pi, and the default password is raspberry.

Method B

10. Get source files and build SP7021 Linux image for booting from eMMC device

Refer to , get source files of SP7021 and build SP7021 Linux image for booting from eMMC device. Refer to log of running make:

Use ll command to list contents of out folder:

11. Copy image of rootfs partition of Raspbian

Plug your Raspbian SD card (created at step 3) into an USB SD card reader and plug your USB SD card reader into USB socket of your Linux (compiler) computer. Use dd command to copy image of rootfs partition of Raspbian.

where rootfs partition of Raspbian is at /dev/sda2. 6.6 GiB of rootfs image was copied and stored at file rpi_rootfs_2020_0527. Refer to report of ll command:

12. Mount image of rootfs partition of Raspbian to a folder

Refer to log below, use mkdir -p command to create folder rpi_rootfs and use mount -o loop command to mount the Raspbian image file to it.

13. Modify fstab

Original Raspbian image uses uuid to mount folders / and /boot in file /etc/fstab. Refer to content of linux/rootfs/disk/etc/fstab:

We don’t need to mount folders / and /boot manually. Please use vi or other text editor to mark out the two lines in etc/fstab. Refer to new content of etc/fstab:

14. Copy Linux modules to rootfs partition of Raspbian

Copy the following files:

linux/rootfs/initramfs/disk/lib/modules/5.4.35-SUNPLUS-v7+/kernel/

linux/rootfs/initramfs/disk/lib/modules/5.4.35-SUNPLUS-v7+/modules.*

to folder:

rpi_rootfs/lib/modules/5.4.35-SUNPLUS-v7+/

where “5.4.35-SUNPLUS-v7+” is Linux kernel release of SP7021.

15. Un-mount the folder of rootfs partition of Raspbian

Refer to log below, use umount command to un-mount the folder of Raspbian image file.

Refer to log below, use rm command remove original out/rootfs.img and use ln command to link Raspbian image file to out/rootfs.img

out/rootfs.img was linked to image file of rootfs of Raspbian.

17. Build ISP files

Go to out folder and run isp.sh script to build ISP files. Refer to log below:

Two binary files, ISPBOOOT.BIN and ISPBOOT1.BIN were created in out folder. Refer to report of ll out command:

18. Copy ISPBOOOT.BIN and ISPBOOTx.BIN to an USB flash drive

Copy the built binary files, ISPBOOOT.BIN, ISPBOOT1.BIN, ISPBOOT2.BIN, … to root directory of an USB flash drive. Note that the USB flash drive should be formatted to DOS/Windows FAT32 file-system. SP7021 can only load files from an USB flash drive which is formatted to FAT32 file-system. Note that FAT32 file-system should be in the first or the sole partition of the USB flash drive.

19. Set DIP-SW to “boot from USB”

Set DIP-SW (boot-select switch) to “boot from USB”. For example, if you are using SP7021 Demo Board (V1/V2/V3), please set DIP-SW to ON-OFF (0-1) for booting from USB flash drive. Refer to picture below, DIP-SW is set to ON-OFF.

Refer to for details of boot selection of SP7021.

20. Write all SP7021 images to eMMC device

Plug your USB flash drive which contains ISPBOOOT.BIN, ISPBOOT1.BIN, ISPBOOT2.BIN, … files into an USB socket of SP7021 board. Turn on power of SP7021 board. After power on, SP7021 starts to write the images to eMMC one by one. Wait for writing to complete. Finally, you will see screen like:

ISP all: Done” means all images were written to eMMC and verified successfully.

Note that in-system-program (ISP) of SP7021 does not support USB hub. The USB flash drive for ISP should be plugged into USB socket of SP7021 board directly.

If you are using Banana Pi BPI-F2P boards, please plug you USB flash drive to the micro USB socket for ISP. It is the only USB socket that is connected to SP7021 directly.

21. Boot Linux from eMMC device

Set DIP-SW (boot select switch) to “boot from eMMC device”. For example, if you are using SP7021 Demo Board (V1/V2/V3), please set DIP-SW to OFF-OFF (1-1) for booting from eMMC device. Refer to picture below:

DIP-SW is set to OFF-OFF. Now, you are ready to boot SP7021 Linux from eMMC device.

Remove the USB drive, and then turn on power to boot Linux with Raspbian from eMMC device. After Raspbian starts up successfully, it will ask you to enter account name and password. The default user of Raspbian is pi, and the default password is raspberry.