在 VisionFive 2 上用 16GB 傲腾启动 Arch Linux

cwt 为 VisionFive 2 RISC-V 单板计算机提供了 Arch Linux 镜像。这一镜像中,U-Boot 采用主线版本,与 StarFive 提供的版本相比,在启动时无法识别 16GB 傲腾 M10(MEMPEK1J016GAL)。以下是使用 StarFive 提供的 U-Boot 在 VisionFive 2 上用 16GB 傲腾启动 Arch Linux 的方法。

准备

这里下载镜像 ArchLinux-VF2_6.12_v6.0.0-cwt25.img.zst,烧录到 micro SD 卡。

这里下载 StarFive 版 SPL(u-boot-spl.bin.normal.out)和 U-Boot(visionfive2_fw_payload.img)。

启动 VisionFive 2

插入傲腾和 SD 卡,RGPIO_0 开关拨向 H(左侧),连接网线和电源,系统启动,使用 ssh 登录。

  • 默认用户名:user;密码:user
  • root 密码:archriscv
  • 主机名:ArchVF2

如果尚未扩展 /dev/mmcblk1p4 分区,则扩展之(参考后面“扩展分区”章节,但将 /dev/nvme0n1 改为 /dev/mmcblk1,或直接参考这里这里),以便容纳较大的镜像文件。

scp 将 镜像 ArchLinux-VF2_6.12_v6.0.0-cwt25.img.zst、StarFive 版 u-boot-spl.bin.normal.outvisionfive2_fw_payload.img 拷贝到卡内。

烧录 StarFive 提供的 U-Boot

sudo flashcp -v u-boot-spl.bin.normal.out /dev/mtd0
sudo flashcp -v visionfive2_fw_payload.img /dev/mtd2

安装系统到傲腾

sudo blkdiscard /dev/nvme0n1 -f	# 注意:将清空傲腾上的数据

zstd -c -T0 -d ArchLinux-VF2_6.12_v6.0.0-cwt25.img.zst \
  | sudo dd of=/dev/nvme0n1 bs=32M \
    iflag=fullblock oflag=direct \
    status=progress

注意:此时如果重新启动,即使仍然插着 SD 卡,/home 分区也将使用傲腾上的版本而非 SD 卡上的版本。

修改 uEnv.txt

挂载傲腾上的 /boot 分区:

sudo mkdir /mnt/optaneboot
sudo mount /dev/nvme0n1p3 /mnt/optaneboot

uEnv.txt 最后加入如下内容(注意权限):

# Fix wrong fdtfile name
fdtfile=starfive/jh7110-starfive-visionfive-2-v1.3b.dtb

卸载傲腾上的 /boot 分区并关机:

sudo umount /dev/nvme0n1p3
sudo poweroff

重启

拔出 SD 卡、将 RGPIO_0 开关拨向 L(右侧),重新上电或按 RESET 开关

此时应能正常启动(可看到心跳灯闪烁)。

如果无法正常启动,则连接 TTL 串口,进入 U-Boot,将 env 恢复到缺省状态:

env default -f -a
env save

扩展分区

sudo fdisk /dev/nvme0n1

p 指令查看现分区表:

Command (m for help): p

Disk /dev/nvme0n1: 13.41 GiB, 14403239936 bytes, 28131328 sectors
Disk model: INTEL MEMPEK1J016GAL
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 57A4CE7A-AB9C-4AA5-9B07-5FD3BA412477

Device          Start     End Sectors  Size Type
/dev/nvme0n1p1   4096    8191    4096    2M HiFive BBL
/dev/nvme0n1p2   8192   16383    8192    4M HiFive FSBL
/dev/nvme0n1p3  16384  221183  204800  100M EFI System
/dev/nvme0n1p4 221184 4605951 4384768  2.1G Linux filesystem

d 指令删除分区 4

Command (m for help): d
Partition number (1-4, default 4): 4

Partition 4 has been deleted.

n 指令重建分区 4

Command (m for help): n
Partition number (4-128, default 4):	# 直接回车
First sector (221184-28131294, default 221184):	# 直接回车
Last sector, +/-sectors or +/-size{K,M,G,T,P} (221184-28131294, default 28129279):	# 直接回车

Created a new partition 4 of type 'Linux filesystem' and of size 13.3 GiB.
Partition #4 contains a btrfs signature.

Do you want to remove the signature? [Y]es/[N]o: n	# 输入 n 回车

确认分区表情况并写入:

Command (m for help): p

Disk /dev/nvme0n1: 13.41 GiB, 14403239936 bytes, 28131328 sectors
Disk model: INTEL MEMPEK1J016GAL
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 57A4CE7A-AB9C-4AA5-9B07-5FD3BA412477

Device          Start      End  Sectors  Size Type
/dev/nvme0n1p1   4096     8191     4096    2M HiFive BBL
/dev/nvme0n1p2   8192    16383     8192    4M HiFive FSBL
/dev/nvme0n1p3  16384   221183   204800  100M EFI System
/dev/nvme0n1p4 221184 28129279 27908096 13.3G Linux filesystem

Command (m for help): w
The partition table has been altered.
Syncing disks.

扩展文件系统:

sudo btrfs filesystem resize max /

df -h 确认:

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p4   14G  1.6G   12G  12% /
devtmpfs        4.0M     0  4.0M   0% /dev
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           1.6G  1.8M  1.6G   1% /run
none            1.0M     0  1.0M   0% /run/credentials/systemd-journald.service
tmpfs           3.9G     0  3.9G   0% /tmp
tmpfs           3.9G     0  3.9G   0% /var/tmp
/dev/nvme0n1p3  100M   22M   79M  22% /boot
/dev/nvme0n1p4   14G  1.6G   12G  12% /.snapshots
/dev/nvme0n1p4   14G  1.6G   12G  12% /home
/dev/nvme0n1p4   14G  1.6G   12G  12% /var/cache/pacman/pkg
/dev/nvme0n1p4   14G  1.6G   12G  12% /var/log
none            1.0M     0  1.0M   0% /run/credentials/serial-getty@ttyS0.service
none            1.0M     0  1.0M   0% /run/credentials/getty@tty1.service
tmpfs           790M  4.0K  790M   1% /run/user/1000