User:Dlan/RISC-V/TH1520

From Gentoo Wiki
< User:Dlan‎ | RISC-V
Jump to:navigation Jump to:search

This document describes how to install Gentoo Linux on the board with T-Head TH1520 RISC-V SoC solder.

Here we will use SiPeed's Lichee Pi 4A (aka Lpi4A) board as reference target.

Host Env Setup

Following are collected information for setting up a typical Arch=amd64 Gentoo Linux to do RISC-V development.

Cross Toolchain

Install the crossdev utils

root #emerge --ask sys-devel/crossdev

Generate cross toolchains, including gcc, glibc, binutils, gdb

root #crossdev --target riscv64-unknown-linux-gnu

Prepare the Firmware

Following are collected information for describing how to prepare an ARCH=riscv Gentoo Linux Image for Lpi4A.

Use prebuilt binary

To make user easy to deploy, we will start with prebuilt binaries - which include u-boot/opensbi/kernel image

Bootloader

Boot image

Root image

Create a rootfs image, make sure the size of image less than 6.8GB, as the eMMC is 8GB in total

root #dd if=/dev/zero of=th1520_root_20230412.ext4 bs=1M count=4096

Format the image as ext4 fs

root #mkfs.ext4 -U 9b5a703c-7068-4ea8-8d1d-ad225e839c5d -b 4096 -L root th1520_root_20230412.ext4

Get RISC-V images from any of Gentoo Linux Mirror.

Deploy the stage3 image

root #mkdir -p /mnt/gentoo
root #mount -o loop th1520_root_20230412.ext4 /mnt/gentoo/
root #tar Jxvf stage3-rv64_lp64d-systemd-mergedusr-20230428T170354Z.tar.xz -C /mnt/gentoo/

Deploy prebuilt kernel modules

root #tar Jxvf th1520_modules_5.10.113.tar.xz -C /mnt/gentoo/

Adjust fstab

FILE /etc/fstab
# root setting
UUID=9b5a703c-7068-4ea8-8d1d-ad225e839c5d               /               ext4            noatime         0 1

Delete root passwd

FILE /etc/passwd
# delete 'x', make change 'root:x:' -> 'root::'
root::0:0:System user; root:/root:/bin/bash

Umount root

root #sync
root #umount /mnt/gentoo/

Build from source

Setup alias

root #alias rvmake='make ARCH=riscv CROSS_COMPILE=riscv64-unknown-linux-gnu- -j30 '

U-boot

Get the u-boot source

root #git clone --depth=1 -b lpi4a https://github.com/revyos/thead-u-boot u-boot
root #cd u-boot

Build the u-boot image

root #rvmake distclean && rvmake light_lpi4a_defconfig && rvmake

OpenSBI

Kernel

Get the kernel source

root #git clone --depth=1 -b lpi4a https://github.com/revyos/thead-kernel kernel
root #cd kernel
root #rvmake revyos_defconfig

Disable a few kernel config options which lead to compiling failure

# CONFIG_VECTOR is not set
# CONFIG_LIGHT_GPU_VIV is not set
root #rvmake menuconfig
KERNEL
Platform type  --->
  [ ] VECTOR support
Device Drivers  --->
  Light Vivante GPU support  --->
    < > Light Vivante GPU support

Build kernel and modules dtbs

root #rvmake Image && rvmake modules && rvmake dtbs

Install modules to rootfs

root #mount -o loop th1520_root_20230412.ext4 /mnt/gentoo/
root #rvmake modules_install INSTALL_MOD_PATH=/mnt/gentoo/
root #umount /mnt/gentoo

Flash the Firmware

Prepare tools

To flash firmware, we need fastboot, so please install

root #emerge --ask dev-util/android-tools

Board Fastboot mode

Power off the board, hold "BOOT" key, and power on the board, then it will enter Brom's fastboot mode.

Enter U-boot fastboot

root #fastboot flash ram u-boot-with-spl.bin
root #fastboot reboot

Flash all images

root #fastboot flash uboot u-boot-with-spl.bin
root #xz -d th1520_boot_20230412.ext4.xz
root #fastboot flash boot th1520_boot_20230412.ext4
root #fastboot flash root th1520_root_20230412.ext4

Reboot

Press "RESET" key, and welcome to new Gentoo Linux