Compile and burn the V3s core board of SPI-NOR-Flash (3): rootfs

Make root file system rootfs

Get buildroot

I used the final version of buildroot-2022.11, the file address is

http://buildroot.uclibc.org/downloads/buildroot-2022.11.tar.xz

After downloading, extract it to the …/v3s/buildroot directory.

Configure buildroot

cd .../v3s/buildroot
make licheepi_zero_defconfig
make menuconfig

Start configuring buildroot.

Target options

The set Target options are as shown in the screenshot below.

Toolchain

The configured Toolchain options are shown in the figure below. I use the configuration of external compilation tools, please note that the External toolchain gcc version is 6.x, and the External toolchain kernel headers series is 4.6.x.

Use the following methods to obtain the value of the External toolchain kernel headers series.

cat /opt/gcc-linaro-6.3.1-2017.02-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/include/linux/version.h
#define LINUX_VERSION_CODE 263680
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))

Seeing that the value of LINUX_VERSION_CODE is 263680, which is equal to the hexadecimal number 0x040600, the value in dotted format is 4.6.0.

The C library still uses glibc. Using uclibc can reduce the size of the root file system, but you must compile uclibc yourself, so I didn’t bother.

Toolchain has C++ support must be checked.

Build options

The configured Build options are as shown below. Please note three points:

  1. Location to save buildroot_config I used an absolute path, which is safer.
  2. Check [*] strip target binaries to reduce rootfs size.
  3. gcc optimization level uses optimize for size for the same reason as above.

Other options are not modified.

System configuration

The configured System configuration options are shown in the figure below.

  1. System hostname, give the host a name, which can be displayed with the hostname command at runtime.
  2. Init system using Busybox
  3. Check [*] Enable root login with password, then set a password for root
  4. busybox’ default shell uses /bin/sh, if there is no special requirement, you can also choose bash
  5. Check [*] Purge unwanted locales
  6. Select [*] Install timezone info, set default local time to Aisa/Shanghai

Kernel is cleared, Bootloaders is cleared

You have already compiled u-boot and linux kernel separately, so you don’t need buildroot to compile the kernel and bootloader again.

Target packages

Considering the needs of the application, only the options I need are listed here, and I have cleared the rest.

  1. Libraries -> Compression and decompression check zlib support.
  2. Libraries -> Crypto, check openssl support.
  3. Libraries -> Database, select sqlite.
  4. Networking applications, select dropbear, select client program, optimize for size
  5. Networking applications, select ifupdown scripts
  6. Networking applications, select ntp, select ntpdate

Filesystem images

Select ext2/3/4 root filesystem and tar the root filesystem.

Configure Busybox

use

sudo make busybox-menuconfig

Configure busybox. The reason for using sudo is because in my development environment, it will error without sudo.

Using the default configuration can meet the needs of most situations.

After saving and exiting busybox-menuconfig, execute the following command to make it take effect.

sudo make busybox-menuconfig
sudo make busybox-update-config

Compile

make -j16
# or use
# sudo make -j16

I used sudo.

During this period, you need to download the application software package. If the download fails, you can use Thunder and other software to download the file in the download link in advance, copy it to the …/v3s/buildroot/dl directory, and then continue to make, and buildroot will automatically recognize it.

After compiling, three files will be generated in the …/v3s/buildroot/output/images directory: rootfs.ext2, rootrs.ext4 and rootfs.tar, among which rootfs.tar is what we need.

Make flashimg.bin

For convenience, a new folder …/v3s/target is created, and all the required files are copied to this folder. The file list is as follows:

  • u-boot-sunxi-with-spl.bin, compiled u-boot executable image
  • sun8i-v3s-licheepi-zero.dtb and sun8i-v3s-licheepi-zero-dock.dtb, compiled device tree
  • zImage, compiled linux kernel
  • rootfs.tar, compiled root file system compressed package

I wrote another mkimg script with the following content.

#!/bin/bash

if [ ! -e rootfs. tar ]; then
    echo "Need rootfs.tar"
    exit -1
the fi

echo "Extracting rootfs..."
if [ ! -d rootfs ]; then
    mkdir rootfs
the fi

cd rootfs; rm -rf *; tar -xvf ../rootfs.tar > /dev/null 2> & amp;1; cd ..

echo "Preparing customer-tailored scripts..."
cp template /etc/network/interfaces rootfs /etc/network/interfaces
rm -f rootfs/etc/resolv.conf
cp template/etc/resolv.conf rootfs/etc/resolv.conf
cp template /etc/profile.d/dir.sh rootfs /etc/profile.d/dir.sh

rm -f rootfs /etc/localtime
cp template /etc/localtime rootfs /etc/localtime

echo "Making jffs..."
mkfs.jffs2 -s 0x100 -e 0x10000 -p 0x1AF0000 -d rootfs/ -o jffs2.img

echo "Making flash image..."
dd if=/dev/zero of=flashimg.bin bs=1M count=32
dd if=u-boot-sunxi-with-spl.bin of=flashimg.bin bs=1K conv=notrunc
dd if=sun8i-v3s-licheepi-zero-dock.dtb of=flashimg.bin bs=1K seek=1024 conv=notrunc
dd if=zImage of=flashimg.bin bs=1K seek=1088 conv=notrunc
dd if=jffs2.img of=flashimg.bin bs=1K seek=5184 conv=notrunc

echo "Transtoring images..."
cp flashimg.bin $TFTP_ROOT/.
scp flashimg.bin fileserver:~/../smbshare/Buffer/flashimg.0531.bin

echo "[Done]"

exit 0

The last paragraph of the script is to copy the flashimg.bin file to the TFTP server for downloading.

Burn

Connect the uart0 of the core board to the host computer, open the secureCRT window on the host computer, and then power on the core board, when the prompt to enter u-boot appears, press the Enter key to enter u-boot, and then use the following command to flashimg.bin burn into Flash.

setenv serverip 192.168.0.104
setenv ipaddr 192.168.0.101
tftp 0x41800000 flashimg.bin
sf probe 0
sf update 0x41800000 0 0x2000000

setenv bootargs console=ttyS0,115200 earlyprintk panic=5 rootwait mtdparts=spi0.0:1M(uboot)ro,64k(dtb)ro,5M(kernel)ro,-(rootfs) root=31:03 rw rootfstype=jffs2

setenv bootcmd=sf probe 0; sf read 0x41800000 0x100000 0x10000; sf read 0x41000000 0x110000 0x500000; bootz 0x41000000 - 0x41800000

The ip address segment I use here is 192.168.0.x, and the specific ip address is allocated according to the network environment.

After all the above commands are executed correctly, enter the boot command. If everything goes well, it can be started normally.

Summary

In order to correctly drive the SPI-NOR flash over 16MB, use the SPI-NOR flash to start the V3s core board, you need to pay attention to the following points:

  1. Prepare the flash partitions in advance, and calculate the bootargs and bootcmd of u-boot according to the partitions.
  2. Modify ./u-boot/arch/arm/dts/sun8i-v3s-licheepi-zero.dts and ./u-boot/arch/arm/dts/sun8i-v3s.dts to set spi and emac nodes so that u- boot supports SPI Flash and network.
  3. Modify the device tree of the linux kernel and add the flash model used.
  4. The compiled size of linux-4.13.y is less than 4M, and the size of linux-5.2.y is larger than 4M