U-Boot U盘启动 OS(Debian),添加GRUB(EFI)启动

u-boot-spl.bin.normal.out: JH7110 VF2 JUNE 2023
visionfive2_fw_payload.img: VisionFive2 Software v5.13.1
Debian Version: starfive-jh7110-202409-SD-minimal-desktop-wayland.img.bz2

正常的烧录步骤:昉·星光 2单板计算机快速参考手册

烧录好后修改一下 /boot/extlinux/extlinux.conf
root=/dev/mmcblk1p4 改为 root=/dev/sda4

启动 U-Boot 后输入以下命令:
pci enum; usb start; usb reset; usb storage; fatls usb 0:3
一般会列出 /boot 下的文件

  4463954   System.map-5.15.0-starfive
   240909   config-6.6.20-starfive
   214822   config-5.15.0-starfive
  9575181   vmlinuz-6.6.20-starfive
            extlinux/
 13238353   initrd.img-5.15.0-starfive
            dtbs/
      419   uEnv.txt
  8489463   vmlinuz-5.15.0-starfive
            grub/
            EFI/
      400   ubootefi.var
 18172777   initrd.img-6.6.20-starfive
  3492851   System.map-6.6.20-starfive

10 file(s), 4 dir(s)

再输入:
setenv devnum 0; if usb dev ${devnum}; then devtype=usb; run scan_dev_for_boot_part; fi
之后就是正常的启动界面:

U-Boot menu
1:      Debian GNU/Linux trixie/sid 6.6.20-starfive
2:      Debian GNU/Linux trixie/sid 6.6.20-starfive (rescue target)
3:      Debian GNU/Linux trixie/sid 5.15.0-starfive
4:      Debian GNU/Linux trixie/sid 5.15.0-starfive (rescue target)
Enter choice: 1

GRUB

换源 /etc/apt/sources.listdeb http://ftp.cn.debian.org/debian sid main
运行:

sudo apt update
sudo apt install grub-efi-riscv64
sudo grub-install --efi-directory=/boot
grub-mkconfig -o /boot/grub/grub.cfg

/boot 下会新建目录 EFI,修改 /etc/grub.d/10_linux
linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${args} 将 ro 改为 rw;

/etc/default/grub 添加 linux 启动参数:

GRUB_DEFAULT=0
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR=`( . /etc/os-release; echo ${NAME:-Debian} ) 2>/dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200 earlycon rootwait stmmaceth=chain_mode:1 selinux=0"

运行 sudo update-grub 之后重启

U-Boot 命令:

pci enum; usb start; usb reset; usb storage; fatls usb 0:3
fatload usb 0:3 $fdt_addr_r dtbs/6.6.20-starfive/starfive/jh7110-starfive-visionfive-2-v1.3b.dtb; fatload usb 0:3 $kernel_addr_r EFI/debian/grubriscv64.efi; bootefi $kernel_addr_r $fdt_addr_r

有可能会看不到grub界面,等一会会自动进入Linux。

重启进入用户登陆界面,但是鼠标移动到用户选项时非常卡顿,猜测是 grub 安装时替换了libc,依据 昉·星光 2单板计算机软件技术参考手册 重新编译安装 .deb 内核软件包。
如果 /boot/efi 空间不够可以先卸载其他内核,安装好后界面恢复流畅。