Aquila Boot Linux

Aquila HW

The Aquila SoC hardware project is at aquila/hw/, using the build.tcl to create the project.

cd aquila/hw
vivado -mode batch -source build.tcl

Software Enivronment Setup

Build GNU RISC-V Toolchain

clone from github

git clone https://github.com/riscv-collab/riscv-gnu-toolchain.git

installation for newlib

./configure --prefix=/opt/riscv --with-arch=rv32ima --with-abi=ilp32
sudo make -j16

installation for linux (glibc)

./configure --prefix=/opt/riscv-linux --with-arch=rv32ima --with-abi=ilp32
sudo make linux -j16

In shell rc file, add:

# RISCV Newlib toolchain
export RISCV=/opt/riscv
export PATH=$PATH:$RISCV/bin

# RISCV Linux toolchain
export RISCV=/opt/riscv-linux
export PATH=$PATH:$RISCV/bin

When using newlib to build, comment out the Linux toolchain and vice versa.
To Build OpenSBI, U-Boot and Linux, using RISC-V Linux toolchain (glibc)

Boot Software

We will using OpenSBI, U-Boot, Linux kernel and Busybox, the following will guide you build the software from source code.

The configs file for Aquila of each software is at aquila/sw/linux_boot

linux_boot
โ”œโ”€โ”€ linux-aquila
โ”œโ”€โ”€ opensbi-aquila
โ””โ”€โ”€ u-boot-aquila

Build U-Boot

clone from U-Boot GitHub

git clone https://github.com/u-boot/u-boot.git
git checkout v2023.04-rc3

copy Aquila devices tree and config file to u-boot

cp -r aquila/sw/linux_boot/u-boot-aquila/* u-boot/

build with the following command

cd u-boot
make CROSS_COMPILE=riscv32-unknown-linux-gnu- eisl-nctu_aquila32_kc705_defconfig
make CROSS_COMPILE=riscv32-unknown-linux-gnu- -j $(nproc)

Build OpenSBI

clone from OpenSBI GitHub

git clone https://github.com/riscv-software-src/opensbi.git 
git checkout v1.2

copy Aquila config files and platform files to OpenSBI

cp -r aquila/sw/linux_boot/opensbi-aquila/* opensbi/

Build OpenSBI with our custom platform

cd opensbi
make all \
CROSS_COMPILE=riscv32-unknown-linux-gnu- \
PLATFORM=fpga/aquila \
PLATFORM_RISCV_XLEN=32 \
PLATFORM_RISCV_ABI=ilp32 \
PLATFORM_RISCV_ISA=rv32ima_zicsr_zifencei \
FW_PAYLOAD_PATH=<path to u-boot/u-boot.bin> \
-j $(nproc)

Preparing Initramfs

First, we need to prepare rootfs for initramfs.
Create a folder named initramfs, and create the directory that initrmafs needs.

mkdir initramfs
cd initramfs
mkdir dev
mkdir proc
mkdir sys

in dev/, create device node console and null

sudo mknod -m 600 dev/console c 5 1
sudo mknod -m 600 dev/null c 1 3

using busybox in rootfs, first we need to build busybox.

clone from Busybox GitHub

git clone https://github.com/mirror/busybox.git

build busybox

cd busybox
make defconfig
make menuconfig (settings -> build options -> choose build static binary (no shared libs))
make CROSS_COMPILE=riscv32-unknown-linux-gnu- -j $(nproc) install

the busybox binary executable will install at busybox/_install, copy the binary executable to our initramfs folder.

cp -r _install/bin <path_to_initramfs_folder>

create an init script as the first initial program, create a file named init and makes it executable.

touch init
sudo chmod +x init

the content of the init is like a shell script :

#!/bin/busybox sh

/bin/mount -t devtmpfs none /dev
/bin/mount -t proc none /proc
/bin/mount -t sysfs none /sys

echo "Hello Aquila!"

/bin/sh

now, our inintramfs folder has:

initramfs
โ”œโ”€โ”€ bin
โ”‚   โ”œโ”€โ”€ arch -> busybox
โ”‚   โ”œโ”€โ”€ ash -> busybox
โ”‚   โ”œโ”€โ”€ base32 -> busybox
โ”‚   โ”œโ”€โ”€ base64 -> busybox
โ”‚   โ”œโ”€โ”€ busybox
โ”‚   โ”œโ”€โ”€ cat -> busybox
โ”‚   โ”œโ”€โ”€ ...
โ”‚   โ”œโ”€โ”€ vi -> busybox
โ”‚   โ”œโ”€โ”€ watch -> busybox
โ”‚   โ””โ”€โ”€ zcat -> busybox
โ”œโ”€โ”€ dev
โ”‚   โ”œโ”€โ”€ console
โ”‚   โ””โ”€โ”€ null
โ”œโ”€โ”€ init
โ”œโ”€โ”€ proc
โ””โ”€โ”€ sys

Build Linux Kernel

clone from Linux GitHub

git clone https://github.com/torvalds/linux.git

copy Aquila config files to linux

cp -r aquila/sw/linux_boot/linux-aquila/* linux/

set kernel configs

cd linux
git checkout v5.19
make ARCH=riscv CROSS_COMPILE=riscv32-unknown-linux-gnu- aquila32_defconfig
make ARCH=riscv CROSS_COMPILE=riscv32-unknown-linux-gnu- menuconfig (General setup -> Initramfs source files(s))

in menuconfig, set the path to our initramfs folder

build kernel

make ARCH=riscv CROSS_COMPILE=riscv32-unknown-linux-gnu- -j $(nproc)

Preparing Boot SD-Card

preparing a SD-card, formatting to FAT-32

copy the opensbi payload elf to SD-card and rename to system.elf

cp opensbi/build/platform/fpga/aquila/firmware/fw_payload.elf <path_to_sdcard>/system.elf

copy the Linux kernel image to SD-card

cp linux/arch/riscv/boot/Image <path_to_sdcard>