Currently, to build Debian image we would need to build the kernel and bootstrap a minimal RISC-V root filesystem which later can be copied into an image. The final image then can be copy into the SD card.
Below command is running under Ubuntu 20.04.
gcc-riscv64-linux- version 8.4.0 (tootchain greater than version 8.0)
Suppose the root working directory
export VF2_WORK_DIR=$HOME/work
mkdir -p $VF2_WORK_DIR
Note: If you have a working Image and just want to test out new kernel. Just build the kernel, copy the kernel image e.g., linux-*.deb into the image and install the kernel. You can skip the bootstrapping root filesystem.
sudo apt install libncurses-dev libssl-dev bc flex bison make gcc gcc-riscv64-linux-gnu git
sudo apt install qemu-user-static binfmt-support debootstrap debian-ports-archive-keyring systemd-container rsync wget
cd $VF2_WORK_DIR
git clone https://github.com/starfive-tech/linux.git
pushd linux/
git checkout JH7110_VisionFive2_devel
cp arch/riscv/configs/starfive_visionfive2_defconfig .config
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- olddefconfig
nice make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- -j$(nproc) bindeb-pkg KDEB_COMPRESS=xz LOCALVERSION=-starfive
popd
cd $VF2_WORK_DIR
mkdir extra
git clone https://github.com/starfive-tech/soft_3rdpart.git
cd soft_3rdpart
git checkout JH7110_VisionFive2_devel
pushd wave511/code
make -C $VF2_WORK_DIR/linux/ M=$(pwd)/vdi/linux/driver LDDINCDIR=$(pwd)/vdi/linux/driver/../include CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv modules
cp ./vdi/linux/driver/vdec.ko $VF2_WORK_DIR/extra
popd
pushd wave420l/code
make -C $VF2_WORK_DIR/linux/ M=$(pwd)/vdi/linux/driver/ LDDINCDIR=$(pwd)/vdi/linux/driver/../include CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv modules
cp ./vdi/linux/driver/venc.ko $VF2_WORK_DIR/extra
popd
pushd codaj12/jdi/linux/driver
make -C $VF2_WORK_DIR/linux/ M=$(pwd) LDDINCDIR=$(pwd)/../include CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv modules
cp ./jpu.ko $VF2_WORK_DIR/extra
popd
cd $VF2_WORK_DIR
mkdir spl_tool
pushd soft_3rdpart/spl_tool
make CROSS_COMPILE=riscv64-linux-gnu- ARCH=riscv
cp spl_tool $VF2_WORK_DIR/spl_tool
cd $VF2_WORK_DIR
sudo debootstrap --arch=riscv64 --keyring /usr/share/keyrings/debian-ports-archive-keyring-removed.gpg --include=debian-ports-archive-keyring --no-merged-usr --exclude=usr-is-merged unstable riscv-chroot-snapshots https://snapshot.debian.org/archive/debian-ports/20221225T084846Z
Note:If your gpg incorrect or out of date. Using --no-check-gpg parameter to pass it.
sudo debootstrap --arch=riscv64 --no-check-gpg --no-merged-usr --exclude=usr-is-merged unstable riscv-chroot-snapshots https://snapshot.debian.org/archive/debian-ports/20221225T084846Z
sudo cp $VF2_WORK_DIR/linux-image-5.15.0-*.deb ./riscv-chroot-snapshots/root
sudo chroot $VF2_WORK_DIR/riscv-chroot-snapshots
dpkg -i /root/*.deb
mkdir /lib/firmware
sync
exit
sudo cp -r $VF2_WORK_DIR/extra/ $VF2_WORK_DIR/riscv-chroot-snapshots/lib/modules/5.15.0-starfive/
cd $VF2_WORK_DIR
git clone https://github.com/starfive-tech/buildroot.git
cd buildroot
git checkout JH7110_VisionFive2_devel
sudo cp -r $VF2_WORK_DIR/buildroot/package/starfive/starfive-firmware/aic8800-usb-wifi/aic8800 $VF2_WORK_DIR/riscv-chroot-snapshots/lib/firmware
sudo cp $VF2_WORK_DIR/buildroot/package/starfive/starfive-firmware/ECR6600U-usb-wifi/ECR6600U_transport.bin $VF2_WORK_DIR/riscv-chroot-snapshots/lib/firmware
Get these mesa packages from [https://github.com/starfive-tech/Debian/releases]
cd $VF2_WORK_DIR
mkdir mesa-pkgs && pushd mesa-pkgs
wget https://github.com/starfive-tech/Debian/releases/download/v0.13.0-engineering-release-wayland/mesa-debs.tar.gz
tar -zxvf mesa-debs.tar.gz
sudo cp -r debs/ $VF2_WORK_DIR/riscv-chroot-snapshots/opt
popd
These drivers are placed at VisionFive2 SDK. [https://github.com/starfive-tech/VisionFive2]
cp $VF2_WORK_DIR/soft_3rdpart/IMG_GPU/out/img-gpu-powervr-bin-1.19.6345021.tar.gz .
tar -zxvf img-gpu-powervr-bin-1.19.6345021.tar.gz
sudo cp -r img-gpu-powervr-bin-1.19.6345021/target/etc/* $VF2_WORK_DIR/riscv-chroot-snapshots/etc/
sudo cp -r img-gpu-powervr-bin-1.19.6345021/target/lib/* $VF2_WORK_DIR/riscv-chroot-snapshots/lib/
sudo cp -r img-gpu-powervr-bin-1.19.6345021/target/usr/* $VF2_WORK_DIR/riscv-chroot-snapshots/usr/
Custom applications can be fetched from [https://github.com/starfive-tech/Debian/releases]
cd $VF2_WORK_DIR
mkdir app-pkgs && pushd app-pkgs
wget https://github.com/starfive-tech/Debian/releases/download/v0.13.0-engineering-release-wayland/firefox_105.0_202305_riscv64.deb
wget https://github.com/starfive-tech/Debian/releases/download/v0.13.0-engineering-release-wayland/codec.tar.gz
wget https://github.com/starfive-tech/Debian/releases/download/v0.13.0-engineering-release-wayland/ffmpeg-deb.tar.gz
wget https://github.com/starfive-tech/Debian/releases/download/v0.13.0-engineering-release-wayland/gst-omx-deb.tar.gz
wget https://github.com/starfive-tech/Debian/releases/download/v0.13.0-engineering-release-wayland/vlc-deb.tar.gz
wget https://github.com/starfive-tech/Debian/releases/download/v0.13.0-engineering-release-wayland/libsdl2-2.0-0_2.26.1+dfsg-1_riscv64.deb
sudo cp * $VF2_WORK_DIR/riscv-chroot-snapshots/opt
popd
Note:We will update package on https://github.com/starfive-tech/Debian/releases,you can get the new tag from github.
Now enter the chroot and ensure that the package db is up to date
sudo chroot $VF2_WORK_DIR/riscv-chroot-snapshots
echo "Acquire::Check-Valid-Until no;" > /etc/apt/apt.conf.d/99-no-check-valid-until
apt update -y
apt upgrade -y
apt install initramfs-tools systemd-timesyncd rsync bash-completion u-boot-menu wget binutils alsa-utils
sudo network-manager network-manager-gnome openssh-server net-tools -y
DEBIAN_FRONTEND=noninteractive apt-get install gnome-shell gnome-terminal gnome-tweaks gnome-shell-extensions -y
cat << EOF > /boot/uEnv.txt
fdt_high=0xffffffffffffffff
initrd_high=0xffffffffffffffff
kernel_addr_r=0x40200000
kernel_comp_addr_r=0x5a000000
kernel_comp_size=0x4000000
fdt_addr_r=0x46000000
ramdisk_addr_r=0x46100000
#Move distro to first boot to speed up booting
boot_targets=distro mmc0 dhcp
#Fix wrong fdtfile name
fdtfile=starfive/jh7110-starfive-visionfive-2-v1.3b.dtb
#Fix missing bootcmd
bootcmd=run load_distro_uenv;run bootcmd_distro
EOF
cat << EOF >> /etc/default/u-boot
U_BOOT_PARAMETERS="root=/dev/mmcblk1p4 rw console=tty0 console=ttyS0,115200 earlycon rootwait
stmmaceth=chain_mode:1 selinux=0"
U_BOOT_FDT_DIR="/dtbs/"
EOF
dpkg-reconfigure linux-image-5.15.0-starfive
sed -e 's/\/boot//g' -i /boot/extlinux/extlinux.conf
sed -i '/append/i \\tfdtdir /dtbs' /boot/extlinux/extlinux.conf
cat << EOF >> /etc/network/interfaces
auto lo
iface lo inet loopback
#setup network for starfive end0
allow-hotplug end0
#iface end0 inet dhcp
#setup network for starfive end1
allow-hotplug end1
#iface end1 inet dhcp
EOFecho "net.ipv4.ping_group_range = 0 2147483647" | tee -a /etc/sysctl.conf
echo "root:starfive" | chpasswd
echo starfive > /etc/hostname
echo "export LD_LIBRARY_PATH=/usr/lib/riscv64-linux-gnu" >> /root/.bashrc
echo "export GST_PLUGIN_PATH=/usr/lib/riscv64-linux-gnu/gstreamer-1.0" >> /root/.bashrc
useradd user -s /bin/bash -m
echo "user:starfive" | chpasswd
echo "export LD_LIBRARY_PATH=/usr/lib/riscv64-linux-gnu" >> /home/user/.bashrc
echo "export GST_PLUGIN_PATH=/usr/lib/riscv64-linux-gnu/gstreamer-1.0" >> /home/user/.bashrc
usermod -aG sudo user
cd /opt/debs
dpkg -i *.deb
cat << EOF > /etc/udev/rules.d/61-mutter-primary-gpu.rules
ENV{DEVNAME}=="/dev/dri/card1", TAG+="mutter-device-preferred-primary"
EOF
cat << EOF > /usr/share/X11/xorg.conf.d/10-starfive.conf
Section "OutputClass"
Identifier "Starfive Display"
MatchDriver "starfive"
Driver "modesetting"
Option "PrimaryGPU" "true"
#Option "AccelMethod" "no"
Option "SWcursor" "false"
Option "NoCursor" "true"
Option "ShadowFB" "true"
Option "Atomic" "true"
Option "DoubleShadow" "true"
Option "PageFlip" "true"
Option "VariableRefresh" "true"
Option "AsyncFlipSecondaries" "true"
EndSection
#Section "Extensions"
#Option "glx" "Disable"
#Option "Composite" "Disable"
#EndSection
EOF
cat << EOF >> /etc/gdm3/daemon.conf
WaylandEnable=true
EOF
cat << EOF > /etc/environment
COGL_DRIVER=gles2
GST_GL_API=gles2
CLUTTER_PAINT="disable-clipped-redraws"
XWAYLAND_NO_GLAMOR=1
SDL_VIDEODRIVER=wayland
MESA_LOADER_DRIVER_OVERRIDE=pvr
EOF
mkdir -p /opt/initramfs-setup
cd /opt/initramfs-setup
cp /boot/initrd.img-5.15.0-starfive /opt/initramfs-setup
zstd -d initrd.img-5.15.0-starfive -o initrd
mkdir rootfs
cd rootfs
cpio -id < ../initrd
mkdir -p lib/firmware
mount -t tmpfs none lib/firmware
cp /lib/firmware/rgx.fw.* lib/firmware
cp /lib/firmware/rgx.sh.* lib/firmware
sync
find . | cpio -H newc -o | zstd -19 --ultra -o initrd.img-5.15.0-starfive
cp initrd.img-5.15.0-starfive /boot/initrd.img-5.15.0-starfive
umount /opt/initramfs-setup/rootfs/lib/firmware
rm -rf /opt/initramfs-setup
cd /etc/kernel/postinst.d
rm -rf zz-u-boot-menu
rm -rf zz-initramfs-mod
cat << EOF >> zz-u-boot-menu
#!/bin/sh
set -e
#Exit if extlinux was removed (!= purged)
if [ -x /usr/sbin/u-boot-update ]
then
#Update extlinux configuration
u-boot-update
fi
sed -i '/append/i \\\tfdtdir /dtbs' /boot/extlinux/extlinux.conf
EOF
cat << EOF >> zz-initramfs-mod
#!/bin/sh
set -e
VERSION="\$1"
INITRD="/boot/initrd.img-\$VERSION"
echo "Copying rgx firmware to initrd..."
TEMPDIR=\$(mktemp -d)
mkdir "\$TEMPDIR/initrd"
cd "\$TEMPDIR/initrd"
zstd -d --stdout "\$INITRD" | cpio -id
if [ ! -d "./lib/firmware" ]; then
echo "Creating lib/firmware folder in initrd..."
mkdir -p "./lib/firmware"
fi
#Copy firmware files to lib/firmware
cp /lib/firmware/rgx.* ./lib/firmware/
#Recreate initrd image
find . | cpio -H newc -o | zstd -19 --ultra > "\$INITRD.tmp"
mv "\$INITRD.tmp" "\$INITRD"
cd -
rm -rf "\$TEMPDIR"
echo "Done."
EOF
chmod +x zz-initramfs-mod
chmod +x zz-u-boot-menu
cd /etc/kernel/postrm.d
rm -rf zz-u-boot-menu
cat << EOF >> zz-u-boot-menu
#!/bin/sh
set -e
#Exit if extlinux was removed (!= purged)
if [ -x /usr/sbin/u-boot-update ]
then
#Update extlinux configuration
u-boot-update
fi
sed -i '/append/i \\\tfdtdir /dtbs' /boot/extlinux/extlinux.conf
EOF
chmod +x zz-u-boot-menu
Check at first whether your vpu driver can be loaded by kernel
depmod -a 5.15.0-starfive
cd /etc/init.d/
cat << EOF >> /etc/init.d/vpudev
#!/bin/sh
case "\$1" in
start)
echo "make vpu dev accesible to non root"
chmod 666 /dev/jpu
chmod 666 /dev/venc
chmod 666 /dev/vdec
chmod 666 /dev/i2c-*
;;
*)
echo "Usage: /etc/init.d/vpudev {start}"
exit 1
;;
esac
exit 0
EOF
chmod +x vpudev
update-rc.d vpudev defaults
echo 'set-card-profile alsa_card.platform-soc_snd-card6 pro-audio' >> /etc/pulse/default.pa
cat << EOF >> /usr/share/wireplumber/main.lua.d/51-alsa-rename.lua
rename_audiojack_rule = {
matches = {
{
{ "api.alsa.card.name", "equals", "Starfive-PWMDAC-Sound-Card" },
},
},
apply_properties = {
["node.description"] = "Audio Jack",
},
}
rename_hdmi_audio_rule = {
matches = {
{
{"api.alsa.card.name", "equals", "Starfive-HDMI-Sound-Card"},
},
},
apply_properties = {
["node.description"] = "HDMI Audio",
},
}
rename_wm8960_rule = {
matches = {
{
{"api.alsa.card.name", "equals", "Starfive-WM8960-Sound-Card"},
},
},
apply_properties = {
["node.description"] = "WM8960 Audio",
},
}
table.insert(alsa_monitor.rules, rename_wm8960_rule)
table.insert(alsa_monitor.rules, rename_audiojack_rule)
table.insert(alsa_monitor.rules, rename_hdmi_audio_rule)
EOF
rm -f /etc/ssh/ssh_host_*
cat << EOF >> /etc/systemd/system/sshd-keygen.service
[Unit]
Description=SSH Key Generation
ConditionPathExists=|!/etc/ssh/ssh_host_ecdsa_key
ConditionPathExists=|!/etc/ssh/ssh_host_ecdsa_key.pub
ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key
ConditionPathExists=|!/etc/ssh/ssh_host_ed25519_key.pub
ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key
ConditionPathExists=|!/etc/ssh/ssh_host_rsa_key.pub
[Service]
ExecStart=/usr/bin/ssh-keygen -A
Type=oneshot
RemainAfterExit=yes
EOF
sed -i 's/\"After=network.target\ auditd.service\"/\"After=network.target\ sshd-keygen.service\ auditd. service\\nWants=sshd-keygen.service\"/g' /lib/systemd/system/ssh.service
ssh-keygen -A
systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
cat << EOF >> /etc/modprobe.d/blacklist.conf
blacklist starfive_mailbox_test
blacklist e24
blacklist xrp
blacklist starfive_mailbox
blacklist wave5
EOF
cd /opt
wget https://snapshot.debian.org/archive/debian-ports/20220616T194833Z/pool-riscv64/main/i/icu/libicu71_71.1-3_riscv64.deb
dpkg -i libicu71_71.1-3_riscv64.deb
DEBIAN_FRONTEND=noninteractive apt-get install nautilus -y
DEBIAN_FRONTEND=noninteractive apt-get install libevent-dev libdbus-glib-1-dev -y
DEBIAN_FRONTEND=noninteractive apt-get install libopenal-dev libcdio-paranoia-dev libdc1394-dev libcaca-dev libv4l-dev libpocketsphinx-dev libbs2b-dev liblilv-0-0 librubberband-dev libmysofa-dev libflite1 libass-dev libvidstab-dev libzmq3-dev libzimg-dev libgme-dev libopenmpt-dev libchromaprint-dev librabbitmq-dev libssh-dev libsrt-openssl-dev liba52-0.7.4-dev libhwy1 libjxl0.7 -y
DEBIAN_FRONTEND=noninteractive apt-get install fonts-freefont-ttf libaribb24-0 libcddb2 libdvbpsi10 libebml5 libixml10 liblirc-client0 liblua5.2-0 libmad0 libmatroska7 libprotobuf-lite32 libqt5x11extras5 libresid-builder0c2a libsdl-image1.2 libsdl1.2debian libsidplay2 libspatialaudio0 libupnp13 libva-wayland2 libvncclient1 libopenmpt-modplug1 libxcb-composite0 -y
DEBIAN_FRONTEND=noninteractive apt-get install bluez-tools blueman -y
cd /opt/
dpkg -i firefox_105.0_202305_riscv64.deb
dpkg -i libsdl2-2.0-0_2.26.1+dfsg-1_riscv64.deb
tar -xvzf codec.tar.gz
cd $PWD/codec
dpkg --force-all -i *.deb
cd ..
tar -xvzf ffmpeg-deb.tar.gz
cd $PWD/ffmpeg-deb
dpkg --force-all -i *.deb
cd ..
tar -xvzf gst-omx-deb.tar.gz
cd $PWD/gst-omx-deb
dpkg --force-all -i *.deb
cd ..
tar -xvzf vlc-deb.tar.gz
cd $PWD/vlc-deb
dpkg --force-all -i *.deb
cd ..
mkdir -p /home/user/.config/vlc/
cd /home/user/.config/vlc/
wget https://github.com/starfive-tech/Debian/releases/download/v0.13.0-engineering-release-wayland/vlcrc
chown -R user:user /home/user/.config
cd /opt
rm libicu71_71.1-3_riscv64.deb
rm firefox_105.0_202305_riscv64.deb
rm libsdl2-2.0-0_2.26.1+dfsg-1_riscv64.deb
rm -rf codec.tar.gz
rm -rf ffmpeg-deb.tar.gz
rm -rf gst-omx-deb.tar.gz
rm -rf vlc-deb.tar.gz
rm -rf codec
rm -rf ffmpeg-deb
rm -rf gst-omx-deb
rm -rf vlc-deb
rm -rf debs
apt-mark hold ffmpeg libavcodec59 libavdevice59 libavfilter8 libavformat59 libavutil57 libpostproc56 libsdl2-2.0-0 libswresample4 libswscale6 vlc-plugin-base vlc-plugin-samba vlc-plugin-svg
rm -rf /etc/unsupported-skip-usrmerge-conversion
rm -rf /usr/local/bin/openssl
apt clean
history -c
sync
exit
These steps in this section are the base for building a image. Both eMMC and NVME image depend on these steps.
cd $VF2_WORK_DIR
mkdir create_sd_image
cd create_sd_image
sudo dd if=/dev/zero of=starfive-jh7110-SD-minimal-desktop.img bs=1M count=4000
sudo sgdisk -g --clear --new=1:4096:8191: --typecode=1:2e54b353-1271-4842-806f-e436d6af6985 --change-name=1:'spl' --new=2:8192:16383: --typecode=2:5b193300-fc78-40cd-8002-e86c45580b47 --change-name=2:'uboot' --new=3:16384:+100M: -t 3:EF00 --change-name=3:'image' --new=4:0:-1M: --change-name=4:'root' --attributes 4:set:2 starfive-jh7110-SD-minimal-desktop.img
sudo losetup --partscan --show --find starfive-jh7110-SD-minimal-desktop.img
Suppose loop devices is /dev/loop30
mkdir boot rootfs
sudo mkfs.vfat /dev/loop30p3
sudo mkfs.ext4 -m 0 -L root /dev/loop30p4
sudo mount /dev/loop30p3 $VF2_WORK_DIR/create_sd_image/boot
sudo mount /dev/loop30p4 $VF2_WORK_DIR/create_sd_image/rootfs
wget https://github.com/starfive-tech/VisionFive2/releases/download/JH7110_VF2_515_v5.12.0/u-boot-spl.bin.normal.out ./
wget https://github.com/starfive-tech/VisionFive2/releases/download/JH7110_VF2_515_v5.12.0/visionfive2_fw_payload.img ./
sudo dd if=u-boot-spl.bin.normal.out of=/dev/loop30p1 bs=4096
sudo dd if=visionfive2_fw_payload.img of=/dev/loop30p2 bs=4096
sudo cp -a $VF2_WORK_DIR/riscv-chroot-snapshots/* $VF2_WORK_DIR/create_sd_image/rootfs
sudo mv $VF2_WORK_DIR/create_sd_image/rootfs/boot/* $VF2_WORK_DIR/create_sd_image/boot
sudo mkdir -p $VF2_WORK_DIR/create_sd_image/boot/dtbs
sudo cp -r $VF2_WORK_DIR/create_sd_image/rootfs/usr/lib/linux-image-5.15.0*/* $VF2_WORK_DIR/create_sd_image/boot/dtbs
sync
sudo umount /dev/loop30p4
sudo umount /dev/loop30p3
sudo losetup -D /dev/loop30
Three steps are need to make this image:
sudo chroot $VF2_WORK_DIR/riscv-chroot-snapshots
sed -i 's/mmcblk1/mmcblk0/g' /etc/fstab
sed -i 's/mmcblk1/mmcblk0/g' /boot/extlinux/extlinux.conf
sed -i 's/mmcblk1/mmcblk0/g' /etc/default/u-boot
sync
exit
sudo cp $VF2_WORK_DIR/spl_tool/spl_tool .
sudo chmod +x spl_tool
sudo ./spl_tool -i -f starfive-jh7110-SD-minimal-desktop.img
sudo bzip2 -zk starfive-jh7110-SD-minimal-desktop.img
Two steps are need to make this image:
sudo chroot $VF2_WORK_DIR/riscv-chroot-snapshots
sed -i 's/mmcblk1/nvme0n1/g' /etc/fstab
sed -i 's/mmcblk1/nvme0n1/g' /boot/extlinux/extlinux.conf
sed -i 's/mmcblk1/nvme0n1/g' /etc/default/u-boot
sync
exit