Skip to content

Instantly share code, notes, and snippets.

@jmontleon
Last active July 15, 2024 23:32
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.
@jmontleon
Copy link
Author

jmontleon commented Jun 7, 2024

@DaveWK there is no support in upstream yet, although as I understand it the patches have been accepted for 6.11.

The kernel I put in https://github.com/jmontleon/fedora-40-lpi4a should also have the pci-e stuff for the VF2.

If you are a little inventive moving partitions over you can actually boot using spi with /boot /boot/efi and / on nvme once you have nvme support.

@jmontleon
Copy link
Author

I have a 6.9.3 SRPM as well; I tested it, but I don't think I still have the binary RPMS around, not that it would be difficult to rebuild; more just need somewhere less silly than a github repo to host rpms

@DaveWK
Copy link

DaveWK commented Jun 7, 2024

@jmontleon I have been using the spi for boot, which was how I tested out booting from the emmc as well as sd card, but couldn't get it to boot off the nvme with the Fedora-Minimal-40-20240502.n.0-sda.raw image; I also noticed when I booted off the sd or emmc that I could not see the nvme drive in Fedora, so I assume this is because I am missing a kernel driver?

@jmontleon
Copy link
Author

Yes, with 6.11 it should all be available in upstream. They didn't make it in time for 6.10 so unfortunately we'll have to wait a bit longer.

@omac777
Copy link

omac777 commented Jun 8, 2024

unfortunately, I used the older Fedora-Minimal-40-20240426.n.0-sda.raw image.
I'm not on nvme. I used an sdcard as I can just push it in and pop it out of the board. The constant screwing and unscrewing of the nvme's was driving me crazy. The nvme design should have been more convenient to push in/push out in carriages and all. This really encouraged me to consider using NAS with convenient cartridges to insert and eject.

@DaveWK
Copy link

DaveWK commented Jun 22, 2024

Ope -- Wayland's terrible copy/paste strikes again.. looks like I clipped the end of my second flashcp command..
But it should be

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

also verify your mtd numbers by doing cat /proc/mtd to be sure there isn't some nondeterministic ordering.

@omac777
Copy link

omac777 commented Jun 29, 2024

Thank you for all your help from above. I succeeded in booting up on the Starfive Visionfive 2 using the following raw image:

wget http://fedora.riscv.rocks/kojifiles/work/tasks/1193/1691193/Fedora-Minimal-40-20240502.n.0-sda.raw.xz

The recipe above for the grub entries didn't point to the same hd1. for me it was hd0.

Found DTB: starfive/jh7110-starfive-visionfive-2-v1.3b.dtb                                                  GNU GRUB  version 2.12
Booting: Fedora
   Minimal BASH-like line editing is supported. For the first word, TAB lists possible command completions. Anywhere else TAB lists possible device or file completions. To enable less(1)-like paging, "set pager=1".                  


grub> linux (hd0,gpt4)/vmlinuz-6.8.7-300.4.riscv64.fc40.riscv64 ro root=UUID=ae525e47-51d5-4c98-8442-351d530612c3 rootflags=subvol=root
grub> initrd (hd0,gpt4)/initramfs-6.8.7-300.4.riscv64.fc40.riscv64.img
grub> boot
EFI stub: Decompressing Linux Kernel...
EFI stub: Loaded initrd from LINUX_EFI_INITRD_MEDIA_GUID device path
EFI stub: Using DTB from configuration table
EFI stub: Exiting boot services...
[    0.000000] Linux version 6.8.7-300.4.riscv64.fc40.riscv64 (mockbuild@04f1060c14404e2b85a3a21c28c7a74d) (gcc (GCC) 14.0.1 20240411 (Red Hat 14.0.1-0), GNU ld version 2.42-2.rvre0.fc40) #1 SMP PREEMPT_DYNAMIC Fri Apr 26 02:00:46 EDT 2024
[    0.000000] Machine model: StarFive VisionFive 2 v1.3B
[    0.000000] SBI specification v2.0 detected

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