User:Rivnakm/VisionFive

From Gentoo Wiki
Jump to:navigation Jump to:search
Warning
This page is in progress, and the information within may be incorrect or incomplete

Summary

I'm working on getting an outline for installing Gentoo on a StarFive VisionFive V1. I'm still relatively new to this so I'm open to feedback and improvement, and errors are definitely possible.

I'm basing this off of documentation from the Debian Wiki for installing on the VisionFive

Installation

Setting up Partitions

Note
U-Boot on the VisionFive looks for the third partition so we need an empty first partition
Partition Filesystem Size Flags Description
/dev/mmcblk0p1 none 64KiB Unused partition for bootloader reasons
/dev/mmcblk0p2 fat32 256M esp EFI System Partition
/dev/mmcblk0p3 any Rest of disk legacy_boot Root Filesystem
Note
Depending on how your SD card is being read it can be /dev/sdx or /dev/mmcblkx

Mount the partitions

root #mkdir /mnt/gentoo
root #mount /dev/mmcblk0p3 /mnt/gentoo
root #mkdir -pv /mnt/gentoo/boot/efi
root #mount /dev/mmcblk0p2 /mnt/gentoo/boot/efi

Installing the Stage 3 Archive

Download the stage 3 archive of your choice (openrc/systemd) from your closest mirror. I'll be using systemd

root #cd /mnt/gentoo
root #tar xpvf stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner

Building the Kernel

Clone the kernel source repository

root #cd /mnt/gentoo/usr/src
root #cd /mnt/gentoo/usr/src/linux

Configure and the kernel

root #cp arch/riscv/configs/visionfive_defconfig .config
root #ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- make olddefconfig
root #ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- make menuconfig

Finally, build the kernel

root #ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- make

Setting up QEMU chroot

Note
Some additional information on using QEMU for a cross-chroot is available in the Embedded Handboo

Enable Kernel option

KERNEL Enable CONFIG_BINFMT_MISC
Executable file formats  --->
  <*> Kernel support for MISC binaries

Install QEMU Static

Set static-user USE flag for QEMU

root #echo app-emulation/qemu static-user >> /etc/portage/package.use

Set QEMU arch build flags

root #echo 'QEMU_SOFTMMU_TARGETS="riscv64"' >> /etc/portage/make.conf
root #echo 'QEMU_USER_TARGETS="riscv64"' >> /etc/portage/make.conf

Install QEMU

root #emerge --ask app-emulation/qemu

Register binary format handlers

root #[ -d /proc/sys/fs/binfmt_misc ] || modprobe binfmt_misc
root #[ -f /proc/sys/fs/binfmt_misc/register ] || mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
root #echo ':riscv64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-riscv64:' > /proc/sys/fs/binfmt_misc/register

For systemd systems

root #echo ':riscv64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-riscv64:' > /etc/binfmt.d/qemu-riscv64-static.conf

Start binfmt service

root #rc-service qemu-binfmt start

or

root #systemctl restart systemd-binfmt

Set up chroot

root #cp $(which qemu-riscv64-static) /mnt/gentoo/usr/bin/
root #mkdir -p /mnt/gentoo/var/db/repos/gentoo

Mount the required directories:

root #mount --bind /var/db/repos/gentoo /mnt/gentoo/var/db/repos/gentoo
root #mount --bind /proc /mnt/gentoo/proc
root #mount --bind /sys /mnt/gentoo/sys
root #mount --bind /dev /mnt/gentoo/dev
root #mount --bind /dev/pts /mnt/gentoo/dev/pts

Chroot into the environment:

root #chroot /mnt/gentoo/ /bin/bash --login

Configuring the system

Install the Kernel

root #cd /usr/src/linux
root #make modules_install
root #make install

Set the root password so we can login to the system

root #passwd

Configure fstab

root #echo "/dev/mmcblk0p2 /boot/efi vfat umask=0077 0 1" >> /etc/fstab

Configure the network interface

FILE /etc/network/interfaces
allow-hotplug eth0
iface eth0 inet dhcp

Installing the Bootloader

Configure U-Boot

FILE /boot/uEnv.txt
fdt_high=0xffffffffffffffff
initrd_high=0xffffffffffffffff
kernel_addr_r=0x84000000
kernel_comp_addr_r=0x90000000
kernel_comp_size=0x10000000
fdt_addr_r=0x88000000
ramdisk_addr_r=0x88300000
# Move DHCP after MMC to speed up booting
boot_targets=mmc0 dhcp
# Fix wrong fdtfile name
fdtfile=starfive/jh7100-starfive-visionfive-v1.dtb
# Fix missing bootcmd
bootcmd=run distro_bootcmd

Install GRUB

Note
I'm not sure what grub platforms are required at the moment
root #echo 'GRUB_PLATFORMS="efi-64 uboot"' >> /etc/portage/make.conf
root #emerge --ask sys-boot/grub

Configure GRUB

FILE /boot/grub/grub.cfg
set default=0
set timeout_style=menu
set timeout=2

set debug="linux,loader,mm"
set term="vt100"

menuentry 'Gentoo GNU/Linux' {
    linux /boot/vmlinuz-<x.y.z>-starfive root=/dev/mmcblk0p3 rw console=tty0 console=ttyS0,115200 earlycon rootwait stmmaceth=chain_mode:1 selinux=0
    devicetree /usr/lib/linux-image-<x.y.z>-starfive/starfive/jh7100-starfive-visionfive-v1.dtb
    initrd /boot/initrd.img-<x.y.z>-starfive
}
Note
<x.y.z> above needs to be replaced with the compiled kernel version

Final Steps

Sync and unmount partitions

root #sync
root #umount -R /mnt/gentoo