Bianbu 2.0 ROOTFS Creation
Prerequisites
The host machine is recommended to be Ubuntu 20.04/22.04, with docker CE and customized qemu-user-static (version 8.0.4, with Vector 1.0 support enabled by default) installed.
Docker
For Docker CE installation, refer to https://docs.docker.com/engine/install/.
QEMU
-
Uninstall binfmt-support
The customized qemu-user-static conflicts with binfmt-support since binfmt-support provides the
/etc/init.d/binfmt-support
SysVinit script, while the customized qemu-user-static provides a systemd service unit file/lib/systemd/system/systemd-binfmt.service
. The/etc/init.d/binfmt-support
script executes later than/lib/systemd/system/systemd-binfmt.service
, causing it to overwrite the systemd settings.sudo apt-get purge binfmt-support
-
Download the customized qemu
wget https://archive.spacemit.com/qemu/qemu-user-static_8.0.4%2Bdfsg-1ubuntu3.23.10.1_amd64.deb
-
Install the customized qemu
sudo dpkg -i qemu-user-static_8.0.4+dfsg-1ubuntu3.23.10.1_amd64.deb
-
Register qemu-user-static with the kernel to allow system-wide execution of riscv binaries (including within containers)
sudo systemctl restart systemd-binfmt.service
-
Verify the successful registration of qemu-user-static
wget https://archive.spacemit.com/qemu/rvv
chmod a+x rvv
./rvvSeeing the following output indicates successful registration.
helloworld
spacemit
Prepare the Base ROOTFS
-
Create a working directory
mkdir ~/bianbu-workspace
-
Create and start the container
docker run --privileged -itd -v ~/bianbu-workspace:/mnt --name build-bianbu-rootfs harbor.spacemit.com/bianbu/bianbu:latest
-
Enter the container
docker exec -it -w /mnt build-bianbu-rootfs bash
-
Install basic tools
apt-get update
apt-get -y install wget uuid-runtime -
Configure environment variables for later commands
export BASE_ROOTFS_URL=https://archive.spacemit.com/bianbu-base/bianbu-base-24.04-base-riscv64.tar.gz
export BASE_ROOTFS=$(basename "$BASE_ROOTFS_URL")
export TARGET_ROOTFS=rootfs -
Download
wget $BASE_ROOTFS_URL
-
Extract to the specified directory
mkdir -p $TARGET_ROOTFS && tar -zxpf $BASE_ROOTFS -C $TARGET_ROOTFS
-
Mount some system resources into the rootfs
mount -t proc /proc $TARGET_ROOTFS/proc
mount -t sysfs /sys $TARGET_ROOTFS/sys
mount -o bind /dev $TARGET_ROOTFS/dev
mount -o bind /dev/pts $TARGET_ROOTFS/dev/pts
Necessary Configuration
Configure Repository
-
First, set environment variables for subsequent commands
export REPO="archive.spacemit.com/bianbu"
export VERSION="v2.0" -
Configure bianbu.sources
cat <<EOF | tee $TARGET_ROOTFS/etc/apt/sources.list.d/bianbu.sources
Types: deb
URIs: https://$REPO/
Suites: noble/snapshots/$VERSION noble-security/snapshots/$VERSION noble-porting/snapshots/$VERSION noble-customization/snapshots/$VERSION
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/bianbu-archive-keyring.gpg
EOF
Configure DNS
echo "nameserver 8.8.8.8" >$TARGET_ROOTFS/etc/resolv.conf
Install Hardware-related Packages
chroot $TARGET_ROOTFS /bin/bash -c "apt-get update"
chroot $TARGET_ROOTFS /bin/bash -c "DEBIAN_FRONTEND=noninteractive apt-get -y --allow-downgrades upgrade"
chroot $TARGET_ROOTFS /bin/bash -c "DEBIAN_FRONTEND=noninteractive apt-get -y --allow-downgrades install initramfs-tools"
chroot $TARGET_ROOTFS /bin/bash -c "DEBIAN_FRONTEND=noninteractive apt-get -y --allow-downgrades install bianbu-esos img-gpu-powervr k1x-vpu-firmware k1x-cam spacemit-uart-bt spacemit-modules-usrload opensbi-spacemit u-boot-spacemit linux-image-6.6.36"
Install Metapackages
Different variants come with different metapackages:
- Minimal: bianbu-minimal
- Desktop: bianbu-desktop bianbu-desktop-zh bianbu-desktop-en bianbu-desktop-minimal-en bianbu-standard bianbu-development
- NAS: bianbu-nas
minimal:
chroot $TARGET_ROOTFS /bin/bash -c "DEBIAN_FRONTEND=noninteractive apt-get -y --allow-downgrades install bianbu-minimal"
Desktop: The minimal meta package needs to be installed first.
chroot $TARGET_ROOTFS /bin/bash -c "DEBIAN_FRONTEND=noninteractive apt-get -y --allow-downgrades install bianbu-minimal"
chroot $TARGET_ROOTFS /bin/bash -c "DEBIAN_FRONTEND=noninteractive apt-get -y --allow-downgrades install bianbu-desktop bianbu-desktop-zh bianbu-desktop-en bianbu-desktop-minimal-en bianbu-standard bianbu-development"
NAS:
chroot $TARGET_ROOTFS /bin/bash -c "DEBIAN_FRONTEND=noninteractive apt-get -y --allow-downgrades install bianbu-nas"
General Configuration
Configure Locale
chroot $TARGET_ROOTFS /bin/bash -c "apt-get -y install locales"
chroot $TARGET_ROOTFS /bin/bash -c "echo \"locales locales/locales_to_be_generated multiselect en_US.UTF-8 UTF-8, zh_CN.UTF-8 UTF-8\" | debconf-set-selections"
chroot $TARGET_ROOTFS /bin/bash -c "echo \"locales locales/default_environment_locale select zh_CN.UTF-8\" | debconf-set-selections"
chroot $TARGET_ROOTFS /bin/bash -c "sed -i 's/^# zh_CN.UTF-8 UTF-8/zh_CN.UTF-8 UTF-8/' /etc/locale.gen"
chroot $TARGET_ROOTFS /bin/bash -c "dpkg-reconfigure --frontend=noninteractive locales"
Configure Timezone
chroot $TARGET_ROOTFS /bin/bash -c "echo 'tzdata tzdata/Areas select Asia' | debconf-set-selections"
chroot $TARGET_ROOTFS /bin/bash -c "echo 'tzdata tzdata/Zones/Asia select Shanghai' | debconf-set-selections"
chroot $TARGET_ROOTFS /bin/bash -c "rm /etc/timezone"
chroot $TARGET_ROOTFS /bin/bash -c "rm /etc/localtime"
chroot $TARGET_ROOTFS /bin/bash -c "dpkg-reconfigure --frontend=noninteractive tzdata"
Configure Time Server
sed -i 's/^#NTP=.*/NTP=ntp.aliyun.com/' $TARGET_ROOTFS/etc/systemd/timesyncd.conf
Set Password
chroot $TARGET_ROOTFS /bin/bash -c "echo root:bianbu | chpasswd"
Configure Network (Optional)
If you only installed the minimal (bianbu-minimal) metapackage, use netplan to configure the network:
cat <<EOF | tee $TARGET_ROOTFS/etc/netplan/01-netcfg.yaml
network:
version: 2
renderer: networkd
ethernets:
end0:
dhcp4: true
EOF
chroot $TARGET_ROOTFS /bin/bash -c "chmod 600 /etc/netplan/01-netcfg.yaml"
If the Desktop (bianbu-desktop) meta package is installed, the configuration is as follows.
cat >$TARGET_ROOTFS/etc/netplan/01-network-manager-all.yaml <<EOF
# Let NetworkManager manage all devices on this system
network:
version: 2
renderer: NetworkManager
EOF
chroot $TARGET_ROOTFS /bin/bash -c "chmod 600 /etc/netplan/01-network-manager-all.yaml"
Generate Partition Images
Before finalizing, ensure to unmount!
mount | grep "$TARGET_ROOTFS/proc" > /dev/null && umount -l $TARGET_ROOTFS/proc
mount | grep "$TARGET_ROOTFS/sys" > /dev/null && umount -l $TARGET_ROOTFS/sys
mount | grep "$TARGET_ROOTFS/dev/pts" > /dev/null && umount -l $TARGET_ROOTFS/dev/pts
mount | grep "$TARGET_ROOTFS/dev" > /dev/null && umount -l $TARGET_ROOTFS/dev
Generate UUID and write to /etc/fstab
UUID_BOOTFS=$(uuidgen)
UUID_ROOTFS=$(uuidgen)
cat >$TARGET_ROOTFS/etc/fstab <<EOF
# <file system> <dir> <type> <options> <dump> <pass>
UUID=$UUID_ROOTFS / ext4 defaults,noatime,errors=remount-ro 0 1
UUID=$UUID_BOOTFS /boot ext4 defaults 0 2
EOF
Move boot to a different directory, to separately create bootfs and rootfs partitions,
mkdir -p bootfs
mv $TARGET_ROOTFS/boot/* bootfs
Create bootfs.ext4,
mke2fs -d bootfs -L bootfs -t ext4 -U $UUID_BOOTFS bootfs.ext4 "256M"
mke2fs -d $TARGET_ROOTFS -L rootfs -t ext4 -N 524288 -U $UUID_ROOTFS rootfs.ext4 "2048M"
Create rootfs.ext4
Minimal:
mke2fs -d $TARGET_ROOTFS -L rootfs -t ext4 -N 524288 -U $UUID_ROOTFS rootfs.ext4 "2048"
Desktop:
mke2fs -d $TARGET_ROOTFS -L rootfs -t ext4 -N 524288 -U $UUID_ROOTFS rootfs.ext4 "8848M"
NAS:
mke2fs -d $TARGET_ROOTFS -L rootfs -t ext4 -N 524288 -U $UUID_ROOTFS rootfs.ext4 "4048M"
Now, you can see two partition images in the current directory, bootfs.ext4 and rootfs.ext4, which can be burned to the board using fastboot.
Create Firmware
Titan Image
-
Install dependencies
apt-get -y install zip
-
Copy required files for the image
export TMP=pack_dir
mkdir -p $TMP/factory/
cp $TARGET_ROOTFS/usr/lib/u-boot/spacemit/bootinfo_emmc.bin $TMP/factory
cp $TARGET_ROOTFS/usr/lib/u-boot/spacemit/bootinfo_sd.bin $TMP/factory
cp $TARGET_ROOTFS/usr/lib/u-boot/spacemit/bootinfo_spinand.bin $TMP/factory
cp $TARGET_ROOTFS/usr/lib/u-boot/spacemit/bootinfo_spinor.bin $TMP/factory
cp $TARGET_ROOTFS/usr/lib/u-boot/spacemit/FSBL.bin $TMP/factory
cp $TARGET_ROOTFS/usr/lib/u-boot/spacemit/u-boot.itb $TMP
cp $TARGET_ROOTFS/usr/lib/u-boot/spacemit/env.bin $TMP
cp $TARGET_ROOTFS/usr/lib/riscv64-linux-gnu/opensbi/generic/fw_dynamic.itb $TMP
cp bootfs.ext4 $TMP
cp rootfs.ext4 $TMP -
Download reference partition tables
wget -P $TMP https://gitee.com/bianbu/firmware-config/raw/main/fastboot.yaml
wget -P $TMP https://gitee.com/bianbu/firmware-config/raw/main/partition_2M.json
wget -P $TMP https://gitee.com/bianbu/firmware-config/raw/main/partition_flash.json
wget -P $TMP https://gitee.com/bianbu/firmware-config/raw/main/partition_universal.json -
Package the image
cd $TMP
zip -r ../bianbu-custom.zip *
SDCARD Image
Here’s how to create an SDCARD image using genimage
.
-
Install dependencies
echo 'tzdata tzdata/Areas select Asia' | debconf-set-selections
echo 'tzdata tzdata/Zones/Asia select Shanghai' | debconf-set-selections
DEBIAN_FRONTEND=noninteractive apt-get -y install wget python3 genimage -
Copy required files for the image
export TMP_SD=pack_dir
mkdir -p $TMP_SD/factory/
cp $TARGET_ROOTFS/usr/lib/u-boot/spacemit/bootinfo_emmc.bin $TMP_SD/factory
cp $TARGET_ROOTFS/usr/lib/u-boot/spacemit/bootinfo_sd.bin $TMP_SD/factory
cp $TARGET_ROOTFS/usr/lib/u-boot/spacemit/bootinfo_spinand.bin $TMP_SD/factory
cp $TARGET_ROOTFS/usr/lib/u-boot/spacemit/bootinfo_spinor.bin $TMP_SD/factory
cp $TARGET_ROOTFS/usr/lib/u-boot/spacemit/FSBL.bin $TMP_SD/factory
cp $TARGET_ROOTFS/usr/lib/u-boot/spacemit/u-boot.itb $TMP_SD
cp $TARGET_ROOTFS/usr/lib/u-boot/spacemit/env.bin $TMP_SD
cp $TARGET_ROOTFS/usr/lib/riscv64-linux-gnu/opensbi/generic/fw_dynamic.itb $TMP_SD
cp bootfs.ext4 $TMP_SD
cp rootfs.ext4 $TMP_SD -
Download reference partition table
wget -P $TMP_SD https://gitee.com/bianbu/firmware-config/raw/main/partition_universal.json
-
Download script to generate
genimage.cfg
and creategenimage.cfg
wget -P $TMP_SD https://gitee.com/bianbu-linux/scripts/raw/bl-v1.0.y/gen_imgcfg.py
python3 $TMP_SD/gen_imgcfg.py -i $TMP_SD/partition_universal.json -n bianbu-custom.sdcard -o $TMP_SD/genimage.cfgIf it is the desktop version, modify the genimage.cfg and change the rootfs partition size to 12G.
partition rootfs {
image = "rootfs.ext4"
offset = "260M"
size = "12G"
holes = {}
in-partition-table = "true"
} -
Generate SDCARD image
ROOTPATH_TMP="$(mktemp -d)"
GENIMAGE_TMP="$(mktemp -d)"
genimage \
--config "$TMP_SD/genimage.cfg" \
--rootpath "$ROOTPATH_TMP" \
--tmppath "$GENIMAGE_TMP" \
--inputpath "$TMP_SD" \
--outputpath "."If you see the following messages, the packaging was successful:
INFO: hdimage(bianbu-custom): adding partition 'bootinfo' from 'factory/bootinfo_sd.bin' ...
INFO: hdimage(bianbu-custom): adding partition 'fsbl' (in MBR) from 'factory/FSBL.bin' ...
INFO: hdimage(bianbu-custom): adding partition 'env' (in MBR) from 'env.bin' ...
INFO: hdimage(bianbu-custom): adding partition 'opensbi' (in MBR) from 'fw_dynamic.itb' ...
INFO: hdimage(bianbu-custom): adding partition 'uboot' (in MBR) from 'u-boot.itb' ...
INFO: hdimage(bianbu-custom): adding partition 'bootfs' (in MBR) from 'bootfs.ext4' ...
INFO: hdimage(bianbu-custom): adding partition 'rootfs' (in MBR) from 'rootfs.ext4' ...
INFO: hdimage(bianbu-custom): adding partition '[MBR]' ...
INFO: hdimage(bianbu-custom): adding partition '[GPT header]' ...
INFO: hdimage(bianbu-custom): adding partition '[GPT array]' ...
INFO: hdimage(bianbu-custom): adding partition '[GPT backup]' ...
INFO: hdimage(bianbu-custom): writing GPT
INFO: hdimage(bianbu-custom): writing protective MBR
INFO: hdimage(bianbu-custom): writing MBR
INFO: cmd: "rm -rf "/tmp/tmp.rX4fZ39DKG"/*" (stderr):