dark_mode format_list_bulleted
Flashing ArchLinux RISC-V to Spacemit K1
Flashing ArchLinux RISC-V to Spacemit K1
Packing the ArchLinux RISC-V porting image and flash it to the eMMC on board or NVMe disk.
history
History
Updated at Thu, 13 Feb 2025 10:20:00 GMT
Published at Fri, 25 Oct 2024 09:30:00 GMT
archlinux
riscv
spacemit
visibility public group

NOTE for lazy person: I’ve packed the ROM package for eMMC with

Build the images by yourself

Felix Yan’s wiki about the ArchLinux RISC-V porting.

postmarketOS Wiki about Banana Pi F3 with Spacemit K1 SoC.

Banana Pi forum question about booting with root filesystem on NVMe.

Make the ext4 rootfs image

Download the ArchLinux RISC-V porting rootfs archive here.

# Allocate image file. Count defined by your eMMC free size.
dd if=/dev/zero of=rootfs.ext4 bs=1G count=14

# Copy file system tree.
mkfs.ext4 rootfs.ext4
mount rootfs.ext4 /mnt
cp -rp .../archriscv/* /mnt/
umount /mnt

Modify the fstab

The rootfs may will be mounted as read-only due to filesystem check. If it happens, remount it with option -o rw,remount then modify the fstab.

/dev/mmcblk2p5 /boot ext4 defaults,nofail 0 0
/dev/mmcblk2p6 /     ext4 defaults,rw     0 0

Replace boot splash image (optional)

The splash image file is in the BMP bitmap format by Microsoft and location specified by the variable defined under U-Boot: splashfile which is usually bianbu.bmp on bootfs.ext4.

Fetch the U-Boot and kernel

Download the Bianbu distro image archive at archive.spacemit.com.

[!NOTE]

Different release version has different kernel version.

It looks like:

.
├── bootfs.ext4
│     ^ /dev/mmcblk2p5
├── env.bin
├── factory
│        ├── bootinfo_emmc.bin
│        ├── bootinfo_sd.bin
│        ├── bootinfo_spinand.bin
│        ├── bootinfo_spinor.bin
│        └── FSBL.bin
├── fastboot.yaml
├── fw_dynamic.itb
├── genimage.cfg
├── partition_2M.json
├── partition_flash.json
├── partition_universal.json
├── rootfs.ext4
│     ^ /dev/mmcblk2p6: The image to be replaced.
└── u-boot.itb

Replace the rootfs.ext4 with the image you made.

Kernel modules

Copy all modules under /lib/modules from Bianbu’s rootfs.ext4 image to ArchLinux’s.

Some Bianbu releases does not contain kernel modules such as [ btrfs, xfs ] in the init ramdisk. Instead, they are stored on root filesystem. So you can only use ext4 for your root filesystem unless you build the kernel that with the modules static-linked in.

U-Boot environment variables

Force U-Boot falling back to prompt by removing SD Card from slot while U-Boot is booting.

env print -a

Root filesystem on NVMe

mkfs.ext4 /dev/nvme0n1p1
mount /dev/nvme0n1p1 /mnt
cp -rp .../* /mnt/

Extract the ArchLinux root filesystem archive to the partition you prepared for.

Modify /boot/env_k1-x.txt and insert the U-Boot environment variables below.

# For Bianbu v2.0.4 boot image.
nvme_boot=setenv bootargs root=/dev/nvme0n1p1 rootwait rootfstype=ext4 earlycon=${earlycon} console=tty1 console=${console} earlyprintk quiet clk_ignore_unused swiotlb=65536 workqueue.default_affinity_scope=system
autoboot=run nvme_boot; run detect_dtb; run loadknl; run loaddtb; run loadramdisk; run start_kernel;

For other Bianbu release version, try checking the U-Boot environment variables and the related booting commands.

The kernel on eMMC will mount the NVMe partition as root filesystem.

Flashing to SD Card

Use the genimage to generate sdcard image.

# For NixOS user.
nix-shell -p genimage

cd .../
ln -s . input
genimage

dd if=./images/...-sdcard.img of=/dev/mmcblk2 status=progress

Flashing to eMMC

The SoC will load one program, for processing packets from the host about firmware flashing.

The tool is flashing the target device via executing fastboot commands. You may have heard of it on Android.

Requires fastboot CLI utility.

Flash tool

Documentation about flashing Bianbu. There is a bundle of scripts using fastboot utility.

[!TIP]

You can also find it in the ROM package I packed.

Download flash tool from SpacemiT.

Extract the AppImage with option --appimage-extract.

Copy squashfs-root/resources/app/flashserver to one of the $PATH.

Connect to the board

Enter flash mode: press and hold FDL, press RST on the board.

Connect USB port on the board to your computer. It will show as a DFU device, and turn to U-Boot USB download gadget while flashing.

lsusb
Bus 001 Device 009: ID 361c:1001 U-Boot USB download gadget

Allow unprivileged users to access the board on DFU mode (optional)

Make the users in the group plugdev able to access it.

nano /etc/udev/rules.d/99-spacemit.rules
SUBSYSTEMS=="usb", ATTR{idVendor}=="361c", ATTR{idProduct}=="1001", GROUP="plugdev", MODE:="0660"

Flashing images

Run flashserver under the ROM directory.

flashserver
--- Available ports:
---  1: 1-7-2                'fastboot VID:PID=0x361c:0x1001 SER=None'
--- Enter port index or full name: 1
---》开始刷机
执行 fastboot getvar version-brom
Variable not implemented
执行 fastboot getvar mtd-size
NULL
执行 fastboot getvar blk-size
universal
开始匹配分区表: ['partition_{size0}.json', 'partition_{size1}.json']
匹配原始分区表: partition_universal.json
分区表匹配结果为: partition_universal.json
执行 fastboot flash gpt partition_universal.json
parse gpt/mtd table okay
执行 fastboot flash bootinfo bootinfo_sd.bin
执行 fastboot flash fsbl FSBL.bin
执行 fastboot flash env env.bin
执行 fastboot flash opensbi fw_dynamic.itb
执行 fastboot flash uboot u-boot.itb
执行 fastboot flash bootfs bootfs.ext4
start split gzip file in 2024-10-22 04:17:52
使用gzip压缩等级为: 5
切片缓存的数量:  1
split gzip file over, begin download in 2024-10-22 04:17:54


刷机总进度: 17%:  ▓▓▓▓▓▓▓▓
download over in  2024-10-22 04:18:02
执行 fastboot flash rootfs rootfs.ext4
max-download-size:  268435456
start split gzip file in 2024-10-22 04:18:02
使用gzip压缩等级为: 5
切片缓存的数量:  1
split gzip file over, begin download in 2024-10-22 04:18:04

... ... ...

刷机总进度: 99%:  ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
download over in  2024-10-22 04:24:12
split gzip file over, begin download in 2024-10-22 04:24:12


download over in  2024-10-22 04:24:23
---》刷机成功!
<-------------flash over ---------------->

Enjoy!

Reset BPi-F3. ArchLinux will boot!

By Felix Yan, the password of root is archriscv.

Start services

Network

systemctl enable --now systemd-networkd

Time Sync

systemctl enable --now systemd-timesyncd

[!NOTE]

SSL connections only work with correct time.

Install packages

pacman -Syu
pacman -S nano openssh

Choose the best mirror

nano /etc/pacman.d/mirrorlist
##
## Arch Linux RISC-V repository mirrorlist
##

## Worldwide
Server = https://riscv.mirror.pkgbuild.com/repo/$repo

## Canada
#Server = https://archriscv.felixc.at/repo/$repo

## China
#Server = https://mirror.iscas.ac.cn/archriscv/repo/$repo
#Server = https://mirrors.sustech.edu.cn/archriscv/repo/$repo
#Server = https://mirror.nju.edu.cn/archriscv/repo/$repo
#Server = https://mirrors.wsyu.edu.cn/archriscv/repo/$repo

## Finland
#Server = https://mirrors.felixc.at/archriscv/repo/$repo

Desktop Environment

The graphics performance is poor with llvmpipe.

But do not worry about it.

It’s not much better when using hardware acceleration.

KDE

pacman -S icu plasma-desktop plasma-nm plasma-pa plasma-workspace plasma-workspace-wallpapers xdg-desktop-portal-kde dolphin kate konsole okular spectacle
dbus-run-session startplasma-wayland

Xfce4

pacman -S icu xfce4 xorg
dbus-run-session startxfce4

GNOME

pacman -S gnome

FAQ

Official documentation about building drivers and libraries on Spacemit K1.

About the graphics hardware acceleration

The SoC integrated Imagination BXE-2-32 without opensource driver yet.

I haven’t made them working in success after built on ArchLinux. I gave up discovering this valueless platform.

[!TIP] If somebody has the solution please publish it in the remark area. Thanks!

The Chinese capital Canyon Bridge Capital has been the current parent company of Imagination since 2017.

The alternative is the software implementation llvmpipe.

About the media hardware codec

Spacemit has designed their own media API for their codec. They called it Multi Processing Platform (MPP).

They supported this media API in FFmpeg and Gstreamer on their distro Bianbu. I really couldn’t understand: why didn’t they make it VAAPI-compatible?

What do I use it for?

It’s affording some functionalities of this site with services proxied via Cloudflare Daemon running on it. Such as statistics and web traffic analysis.

What do you think about it?