Skip to content

Instantly share code, notes, and snippets.

@jmontleon
Last active May 5, 2024 23:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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.
@NeilHanlon
Copy link

Thanks for this! A couple notes from my usage:

  • kpartx can return different results if you already have loop devices setup (stares pointedly at snapd). In my case I had to use loop18 instead of loop0.
  • 1ms char delay on minicom was not sufficient, 2ms seemed OK
  • my sd card when booting from grub was on hd0 instead of hd1.
  • need to flip the boot-mode dip switch to the sd-card boot configuration (0 1), otherwise eficonfig is not available on the on-board uboot.

@jmontleon
Copy link
Author

jmontleon commented Apr 29, 2024

@NeilHanlon glad it (mostly) worked. I updated the instructions to make it a 2 ms delay.

I can probably add something along the lines of losetup -a | grep Fedora-Minimal-40-20240426.n.0-sda.raw | awk -F ':' '{ print $1 }' to set an env var for the loop device after running kpartx so it gets the right device and doesn't assume things.

And hopefully the wall of instructions just gets a lot shorty in the coming days.

@DaveWK
Copy link

DaveWK commented May 5, 2024

I have been eagerly awaiting F40 for VisionFive2 and happy to see there's some progress! I tried to follow these instructions but noticed that you reference a grubriscv64.efi file that doesn't seem to exist (at least publicly) -- I attempted to cross compile the riscv64 branch you have for grub on my amd64 workstation (running Fedora 40 KDE Plasma) by doing:

ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- ./bootstrap
ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- ./autogen.sh
ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- ./configure --target=riscv64-linux-gnu --with-platform=efi
ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- make -j$(nproc)

but assume I did something wrong; after ignoring a few -Wmaybe-uninitialized and -Wunused-variable errors, I got:

riscv64-linux-gnu-gcc -DHAVE_CONFIG_H -I. -I..  -Wall -W  -DGRUB_MACHINE_EFI=1 -DGRUB_MACHINE=RISCV64_EFI -nostdinc -isystem /usr/lib/gcc/riscv64-linux-gnu/13/include -I../include -I../include -DGRUB_FILE=\"lib/setjmp.S\" -I. -I. -I.. -I.. -I../include -I../include -I../grub-core/lib/libgcrypt-grub/src/     -g  -march=rv64imac_zicsr_zifencei -mabi=lp64 -DGRUB_FILE=\"lib/setjmp.S\" -I. -I. -I.. -I.. -I../include -I../include -I../grub-core/lib/libgcrypt-grub/src/ -DASM_FILE=1     -MT lib/setjmp_module-setjmp.o -MD -MP -MF lib/.deps-core/setjmp_module-setjmp.Tpo -c -o lib/setjmp_module-setjmp.o `test -f 'lib/setjmp.S' || echo './'`lib/setjmp.S
setjmp.S: Assembler messages:
setjmp.S:143: Error: missing name
setjmp.S:24:  Info: macro invoked from here
setjmp.S:144: Error: unknown pseudo-op: `.module_license'
setjmp.S:24:  Info: macro invoked from here
setjmp.S:145: Error: unrecognized opcode `a"'
setjmp.S:24:  Info: macro invoked from here
make[3]: *** [Makefile:36902: lib/setjmp_module-setjmp.o] Error 1

@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