Skip to content

Instantly share code, notes, and snippets.

@jmontleon
Last active May 5, 2024 23:03
Show Gist options
  • Save jmontleon/ae5457e1d289719046f915a9cb83a32b to your computer and use it in GitHub Desktop.
Save jmontleon/ae5457e1d289719046f915a9cb83a32b to your computer and use it in GitHub Desktop.
Install Fedora 40 on the VisionFive 2
################################################################################################
There is some long text that needs to be copied into grub in order to boot.
You should be able to copy and paste it using minicom if you add a 1 or 2 ms delay to text input
Ctrl-A Z Minicom Menu
T Terminal Settings
F Character tx delay (ms)
2
################################################################################################
### Choose your SD Card
### You need to edit this
export SDCARD=/dev/sdX
### Set the Fedora Image
# It should be fine to replace this with a newer version from
# http://riscv.rocks/koji/tasks?state=all&view=tree&method=all&order=-id
# but the UUID for /boot and /root will on lines ~65 and ~100 will need to be updated by
# by downloading, decompressing, mapping with kpartx, and running blkid, e.g.
# wget http://fedora.riscv.rocks/kojifiles/packages/uboot-tools/2024.04/1.1.riscv64.fc40/noarch/uboot-images-riscv64-2024.04-1.1.riscv64.fc40.noarch.rpm
# unxz Fedora-Minimal-40-20240426.n.0-sda.raw.xz
# sudo kpartx -av Fedora-Minimal-40-20240426.n.0-sda.raw
# blkid /dev/mapper/loop0p2
# blkid /dev/mapper/loop0p3
export FEDORAR5IMAGE=Fedora-Minimal-40-20240426.n.0-sda.raw
### Get stuff
wget http://fedora.riscv.rocks/kojifiles/packages/uboot-tools/2024.04/1.1.riscv64.fc40/noarch/uboot-images-riscv64-2024.04-1.1.riscv64.fc40.noarch.rpm
wget http://fedora.riscv.rocks/kojifiles/work/tasks/1108/1691108/${FEDORAR5IMAGE}.xz
wget https://github.com/jmontleon/grub2-dist-git/raw/f40-2.12-riscv-f40-binaries/grubriscv64.efi
### Extract stuff
rpm2cpio uboot-images-riscv64-2024.04-1.1.riscv64.fc40.noarch.rpm | cpio -ivd
unxz ${FEDORAR5IMAGE}.xz
### Create a new gpt label on your SD Card
### Double check your sd card device is correct
sudo parted ${SDCARD} mklabel gpt
### Partition your SD Card
sudo sgdisk -g --clear --set-alignment=1 \
--new=1:4096:+2M: --change-name=1:'spl' --typecode=1:2e54b353-1271-4842-806f-e436d6af6985 \
--new=2:8192:+16M: --change-name=2:'opensbi-uboot' --typecode=2:5b193300-fc78-40cd-8002-e86c45580b47 \
--new=3:40960:235519 --typecode=3:C12A7328-F81F-11D2-BA4B-00A0C93EC93B \
--new=4:235520:2189311 --typecode=4:0FC63DAF-8483-4772-8E79-3D69D8477DE4 \
--new=5:2189312:17813503 --typecode=5:0FC63DAF-8483-4772-8E79-3D69D8477DE4 \
${SDCARD}
### Write your SD Card
sudo dd if=./usr/share/uboot/starfive_visionfive2/spl/u-boot-spl.bin.normal.out of=${SDCARD}1 bs=4096 oflag=direct
sudo dd if=./usr/share/uboot/starfive_visionfive2/u-boot.itb of=${SDCARD}2 bs=4096 oflag=direct
sudo kpartx -av ${FEDORAR5IMAGE}
export F40R5LODEV=$(losetup -a | grep ${FEDORAR5IMAGE} | head -n 1 | awk -F ':' '{ print $1 }' | awk -F '/' '{ print $3}')
sudo dd if=/dev/mapper/${F40R5LODEV}p1 of=${SDCARD}3 bs=64M status=progress
sudo dd if=/dev/mapper/${F40R5LODEV}p2 of=${SDCARD}4 bs=64M status=progress
sudo dd if=/dev/mapper/${F40R5LODEV}p3 of=${SDCARD}5 bs=64M status=progress
sudo kpartx -dv ${FEDORAR5IMAGE}
### Replace grub with a working version
mkdir riscv-fedora-boot riscv-fedora-efi
sudo mount ${SDCARD}3 riscv-fedora-efi
sudo mount ${SDCARD}4 riscv-fedora-boot
sudo cp grubriscv64.efi riscv-fedora-efi/EFI/fedora/grubriscv64.efi
sudo bash -c 'cat << EOF > riscv-fedora-efi/EFI/fedora/grub.cfg
search --no-floppy --fs-uuid --set=dev 601e15e4-c750-4e41-99eb-01f7a7ee2364
set prefix=(\$dev)/grub2
export \$prefix
configfile \$prefix/grub.cfg
EOF'
sudo umount riscv-fedora-boot
sudo umount riscv-fedora-efi
rmdir riscv-fedora-boot riscv-fedora-efi
# Eject SD Card
sudo eject ${SDCARD}
# Boot configuratio on VisionFive 2
Hit space once you reach the `Hit any key to stop autoboot` prompt.
env default -f -a
env save
eficonfig
Select Add Boot Option
Set the description to Fedora
File
Select File
mmc 1:3
EFI\fedora\grubriscv64.efi
Save
Change Boot Order
Highlight Fedora and press the + key (Shift+=) to bring it to the top
Save
Quit
bootmenu
boot fedora
You should boot to a grub prompt.
linux (hd1,gpt4)/vmlinuz-6.8.7-300.4.riscv64.fc40.riscv64 ro root=UUID=ffa41c6d-e304-460e-9190-91456e86f7d0 rootflags=subvol=root
initrd (hd1,gpt4)/initramfs-6.8.7-300.4.riscv64.fc40.riscv64.img
boot
#Finish fixing boot
Login as root
grub2-mkconfig -o /boot/grub2/grub.cfg
dnf config-manager --disable fedora updates fedora-cisco-openh264
dnf -y update https://github.com/jmontleon/grub2-dist-git/raw/f40-2.12-riscv-f40-binaries/grub2-common-2.12-0.1.1.riscv64.fc40.noarch.rpm https://github.com/jmontleon/grub2-dist-git/raw/f40-2.12-riscv-f40-binaries/grub2-efi-riscv64-2.12-0.1.1.riscv64.fc40.riscv64.rpm https://github.com/jmontleon/grub2-dist-git/raw/f40-2.12-riscv-f40-binaries/grub2-efi-riscv64-modules-2.12-0.1.1.riscv64.fc40.noarch.rpm https://github.com/jmontleon/grub2-dist-git/raw/f40-2.12-riscv-f40-binaries/grub2-tools-2.12-0.1.1.riscv64.fc40.riscv64.rpm https://github.com/jmontleon/grub2-dist-git/raw/f40-2.12-riscv-f40-binaries/grub2-tools-minimal-2.12-0.1.1.riscv64.fc40.riscv64.rpm
# Reboot and test. You should be booting without manual intervention now.
@DaveWK
Copy link

DaveWK commented May 5, 2024

@jmontleon
Copy link
Author

Thanks @DaveWK for catching this. I renamed the repo when I was cloning rhboot/grub2 to work with an in progress 2.12 rebase of the official package. I've updated the instructions to download it from the correct repo.

@DaveWK
Copy link

DaveWK commented May 5, 2024

cool -- I just ran through the instructions, and had some trouble getting u-boot to load off the image. I suspect I messed something up with changing the UUID's.

To simplify my process, I first booted the arch riscv distro, then I flashed the fedora u-boot images to the SPI by doing:

flashcp -v usr/share/uboot/starfive_visionfive2/spl/u-boot-spl.bin.normal.out /dev/mtd/by-name/spl
flashcp -v usr/share/uboot/starfive_visionfive2/spl/u-boot.itb

after which, I was able to dd Fedora-Minimal-40-20240502.n.0-sda.raw to the root device of my emmc (this also works with sd cards)
and then followed the instructions for the eficonfig menu and setting up grub. this way I didn't have to mess with the partitions.

happy to report that I was able to boot and use the Fedora image on both an EMMC and SD card at this point. Thanks for the info!

I used a newer image I noticed was available at: http://fedora.riscv.rocks/kojifiles/work/tasks/1193/1691193/Fedora-Minimal-40-20240502.n.0-sda.raw.xz

I noticed there's also a link to the other repo at: https://gist.github.com/jmontleon/ae5457e1d289719046f915a9cb83a32b#file-gistfile1-txt-L108 which needs to be changed as well to the other grub2-dist-git repo -- https://github.com/jmontleon/grub2-dist-git/raw/f40-2.12-riscv-f40-binaries/grub2-2.12-0.1.1.riscv64.fc40.src.rpm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment