This guide covers how to create a gentoo linux image for the BeagleV Fire development board from beagleboard.
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Penguin 02508fdf49 add qemu and chroot stuff NOT FINISHED 12 months ago
doc/img add qemu and chroot stuff NOT FINISHED 12 months ago
scripts init 12 months ago
BUILD-LINUX.org init 12 months ago
README.md add qemu and chroot stuff NOT FINISHED 12 months ago
README.org add qemu and chroot stuff NOT FINISHED 12 months ago

README.md

Table of Contents

  1. Preface
  2. Prerequisites
    1. Using the riscv toolchain provided via crossdev
    2. Using a precompiled toolchain
  3. Clone & Build Heart Software Services (HSS)
    1. Clone HSS
    2. Build HSS
  4. Clone & Build u-boot
    1. Clone u-boot
    2. Download the patches
    3. Build u-boot
  5. Build the Linux kernel
  6. Generate the HSS payload
  7. Gentoo

Preface

This guide is written in a way that forces the reader to manually perform every step, excluding environment variables via the setup script because I want to be able to change those. If you would like to follow the official guide provided by beagleboard, which is far more streamlined and automated, please see the references at the bottom of this document.

WARNING This guide is very much still a work in progress. Do not expect anything to work yet.

Prerequisites

emerge -a sys-block/bmap-tools sys-fs/genimage dev-libs/libyaml sys-fs/mtools
mkdir beaglev-fire-gentoo && cd beaglev-fire-gentoo
export PROJECT_ROOT="$PWD"
# deploy will contain any output files, images, etc
mkdir deploy

Using the riscv toolchain provided via crossdev

Crossdev is required for this step. If you dont have crossdev set up, use this guide to install it. At the time of writing this installs riscv64-unknown-linux-gnu-gcc 13.2.1. This is note worthy because the official guide uses 11.4. If there are issues with this toolchain, use the precompiled toolchain via these steps. https://en.wikipedia.org/wiki/google.com

crossdev -t riscv64-unknown-linux-gnu
export RISCV64_CC="riscv64-unknown-linux-gnu-"

Using a precompiled toolchain

mkdir mirror
mkdir toolchain
export GCC_VERSION=11.4.0
wget -c --directory-prefix=./mirror/ "https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/${GCC_VERSION}/x86_64-gcc-${GCC_VERSION}-nolibc-riscv64-linux.tar.xz"

tar xvf ./mirror/x86_64-gcc-${GCC_VERSION}-nolibc-riscv64-linux.tar.xz --strip-components=2 -C ./toolchain/
export RISCV64_CC="$PWD/toolchain/bin/riscv64-linux-"

From this point forward, instructions will use the RISCV64_CC variable as the toolchain.

Export some other misc. environment variables:

export HSS_BRANCH="v2023.02"
export HSS_REPO="https://github.com/polarfire-soc/hart-software-services.git"
export UBOOT_BRANCH="linux4microchip+fpga-2023.02"
export UBOOT_REPO="https://github.com/polarfire-soc/u-boot.git"
export GIT_DEPTH=20
export CORES=$(getconf _NPROCESSORS_ONLN)

Clone & Build Heart Software Services (HSS)

Clone HSS

# remove old if it exists, optional
if [ -d ./hart-software-services/ ] ; then
	rm -rf ./hart-software-services/ || true
fi
git clone -b ${HSS_BRANCH} ${HSS_REPO} ./hart-software-services/ --depth=${GIT_DEPTH}

Build HSS

make -C hart-software-services/tools/hss-payload-generator/ clean
make -C hart-software-services/tools/hss-payload-generator/
cp -v ./hart-software-services/tools/hss-payload-generator/hss-payload-generator ./deploy/

Clone & Build u-boot

Clone u-boot

# remove old if it exists, optional
if [ -d ./u-boot ] ; then
	rm -rf ./u-boot || true
fi
git clone -b ${UBOOT_BRANCH} ${UBOOT_REPO} ./u-boot/ --depth=${GIT_DEPTH}

Download the patches

The patches currently exist as part of BeagleVs BeagleV-Fire-ubuntu repo, so well just clone the whole thing for now. Eventually, Ill see if I can mirror just the patches somewhere.

git clone https://git.beagleboard.org/beaglev-fire/BeagleV-Fire-ubuntu.git ./beaglev --depth=${GIT_DEPTH}

WIP Build u-boot

# Apply patches to uboot
cp -v ./beaglev/patches/u-boot/beaglev-fire/microchip_mpfs_icicle.h ./u-boot/include/configs/microchip_mpfs_icicle.h
cp -v ./beaglev/patches/u-boot/beaglev-fire/microchip-mpfs-icicle-kit.dts ./u-boot/arch/riscv/dts/
cp -v ./beaglev/patches/u-boot/beaglev-fire/microchip_mpfs_icicle_defconfig ./u-boot/configs/microchip_mpfs_icicle_defconfig
make -C u-boot ARCH=riscv CROSS_COMPILE=${RISCV64_CC} microchip_mpfs_icicle_defconfig
# if you want to make configurations....
# make -C u-boot ARCH=riscv CROSS_COMPILE=${RISCV64_CC} menuconfig
make -C u-boot ARCH=riscv CROSS_COMPILE=${RISCV64_CC} olddefconfig
make -C u-boot ARCH=riscv CROSS_COMPILE=${RISCV64_CC} savedefconfig
cp -v ./u-boot/defconfig ./u-boot/configs/microchip_mpfs_icicle_defconfig
cp -v ./u-boot/defconfig ./beaglev/patches/u-boot/beaglev-fire/microchip_mpfs_icicle_defconfig
make -C u-boot -j${CORES} ARCH=riscv CROSS_COMPILE=${RISCV_CC} all
# copy the generated uboot into our deploy folder
cp -v ./u-boot/u-boot.bin ./deploy/
# i have no idea why 2 copies are being made, one u-boot.bin and one src.bin
cp -v ./u-boot/u-boot.bin ./deploy/src.bin

TODO Build the Linux kernel

cd ./beaglev/linux/
if [ ! -f ./.patched ] ; then
	if [ -f arch/riscv/configs/mpfs_defconfig ] ; then
		git am ../patches/linux/0002-PCIe-Change-controller-and-bridge-base-address.patch
		git am ../patches/linux/0003-GPIO-Add-Microchip-CoreGPIO-driver.patch
		git am ../patches/linux/0004-ADC-Add-Microchip-MCP356X-driver.patch
		git am ../patches/linux/0005-Microchip-QSPI-Add-regular-transfers.patch
		git am ../patches/linux/0006-BeagleV-Fire-Add-printk-to-IM219-driver-for-board-te.patch
		git am ../patches/linux/0007-MMC-SPI-Hack-to-support-non-DMA-capable-SPI-ctrl.patch
		git am ../patches/linux/0008-Add-wireless-regdb-regulatory-database-file.patch
		git am ../patches/linux/0009-Makefile-build-mpfs-beaglev-fire.dtb.patch
	fi
	touch .patched
fi

if [ -f arch/riscv/configs/mpfs_defconfig ] ; then
	cp -v ../device-tree/src/microchip/mpfs-beaglev-fire.dts arch/riscv/boot/dts/microchip/
	cp -v ../device-tree/src/microchip/mpfs-beaglev-fire-fabric.dtsi arch/riscv/boot/dts/microchip/
fi

echo "make ARCH=riscv CROSS_COMPILE=${RISCV64_CC} clean"
make ARCH=riscv CROSS_COMPILE=${RISCV64_CC} clean

if [ -f arch/riscv/configs/mpfs_defconfig ] ; then
	cp -v ../patches/linux/mpfs_defconfig ./arch/riscv/configs/mpfs_defconfig

	echo "make ARCH=riscv CROSS_COMPILE=${RISCV64_CC} mpfs_defconfig"
	make ARCH=riscv CROSS_COMPILE=${RISCV64_CC} mpfs_defconfig

	./scripts/config --set-str CONFIG_LOCALVERSION "-$(date +%Y%m%d)"

	./scripts/config --enable CONFIG_CRYPTO_USER_API_HASH
	./scripts/config --enable CONFIG_CRYPTO_USER_API_SKCIPHER
	./scripts/config --enable CONFIG_KEY_DH_OPERATIONS
	./scripts/config --enable CONFIG_CRYPTO_ECB
	./scripts/config --enable CONFIG_CRYPTO_MD4
	./scripts/config --enable CONFIG_CRYPTO_MD5
	./scripts/config --enable CONFIG_CRYPTO_CBC
	./scripts/config --enable CONFIG_CRYPTO_SHA256
	./scripts/config --enable CONFIG_CRYPTO_AES
	./scripts/config --enable CONFIG_CRYPTO_DES
	./scripts/config --enable CONFIG_CRYPTO_CMAC
	./scripts/config --enable CONFIG_CRYPTO_HMAC
	./scripts/config --enable CONFIG_CRYPTO_SHA512
	./scripts/config --enable CONFIG_CRYPTO_SHA1

	echo "make -j${CORES} ARCH=riscv CROSS_COMPILE=${RISCV64_CC} olddefconfig"
	make -j${CORES} ARCH=riscv CROSS_COMPILE=${RISCV64_CC} olddefconfig
else
	echo "make ARCH=riscv CROSS_COMPILE=${RISCV64_CC} defconfig"
	make ARCH=riscv CROSS_COMPILE=${RISCV64_CC} defconfig

	./scripts/config --enable CONFIG_PCIE_MICROCHIP_HOST

	./scripts/config --enable CONFIG_OF_OVERLAY

	./scripts/config --enable CONFIG_I2C
	./scripts/config --enable CONFIG_EEPROM_AT24
	./scripts/config --enable CONFIG_I2C_MICROCHIP_CORE

	./scripts/config --enable CONFIG_SPI_MICROCHIP_CORE
	./scripts/config --enable CONFIG_SPI_MICROCHIP_CORE_QSPI
	./scripts/config --module CONFIG_SPI_SPIDEV

	./scripts/config --enable CONFIG_GPIO_SYSFS

	./scripts/config --enable CONFIG_HW_RANDOM_POLARFIRE_SOC

	./scripts/config --enable CONFIG_USB_MUSB_HDRC
	./scripts/config --enable CONFIG_NOP_USB_XCEIV
	./scripts/config --enable CONFIG_USB_MUSB_POLARFIRE_SOC
	./scripts/config --enable CONFIG_USB_MUSB_DUAL_ROLE

	./scripts/config --enable CONFIG_MAILBOX
	./scripts/config --enable CONFIG_POLARFIRE_SOC_MAILBOX
	./scripts/config --disable CONFIG_SUN6I_MSGBOX

	./scripts/config --enable CONFIG_REMOTEPROC
	./scripts/config --enable CONFIG_REMOTEPROC_CDEV

	./scripts/config --enable CONFIG_POLARFIRE_SOC_SYS_CTRL

	./scripts/config --enable CONFIG_USB_GADGET
	./scripts/config --enable CONFIG_USB_CONFIGFS
	./scripts/config --enable CONFIG_CONFIGFS_FS
	./scripts/config --enable CONFIG_USB_CONFIGFS_SERIAL
	./scripts/config --enable CONFIG_USB_CONFIGFS_ACM
	./scripts/config --enable CONFIG_USB_CONFIGFS_OBEX
	./scripts/config --enable CONFIG_USB_CONFIGFS_NCM
	./scripts/config --enable CONFIG_USB_CONFIGFS_ECM
	./scripts/config --enable CONFIG_USB_CONFIGFS_ECM_SUBSET
	./scripts/config --enable CONFIG_USB_CONFIGFS_RNDIS
	./scripts/config --enable CONFIG_USB_CONFIGFS_EEM
	./scripts/config --enable CONFIG_USB_CONFIGFS_PHONET
	./scripts/config --enable CONFIG_USB_CONFIGFS_MASS_STORAGE
	./scripts/config --enable CONFIG_USB_CONFIGFS_F_LB_SS
	./scripts/config --enable CONFIG_USB_CONFIGFS_F_FS
	./scripts/config --enable CONFIG_USB_CONFIGFS_F_UAC1
	./scripts/config --enable CONFIG_USB_CONFIGFS_F_UAC2
	./scripts/config --enable CONFIG_USB_CONFIGFS_F_MIDI
	./scripts/config --enable CONFIG_USB_CONFIGFS_F_HID
	./scripts/config --enable CONFIG_USB_CONFIGFS_F_UVC
	./scripts/config --enable CONFIG_USB_CONFIGFS_F_PRINTER

	./scripts/config --module CONFIG_MEDIA_SUPPORT
	./scripts/config --enable CONFIG_MEDIA_SUPPORT_FILTER
	./scripts/config --enable CONFIG_MEDIA_SUBDRV_AUTOSELECT
	./scripts/config --enable CONFIG_MEDIA_CAMERA_SUPPORT
	./scripts/config --module CONFIG_VIDEO_IMX219

	./scripts/config --module CONFIG_IIO

	#Cleanup large DRM...
	./scripts/config --disable CONFIG_DRM
	./scripts/config --disable CONFIG_DRM_RADEON
	./scripts/config --disable CONFIG_DRM_NOUVEAU
	./scripts/config --disable CONFIG_DRM_SUN4I

	#Optimize:
	./scripts/config --enable CONFIG_IP_NF_IPTABLES
	./scripts/config --enable CONFIG_NETFILTER_XTABLES
	./scripts/config --enable CONFIG_NLS_ISO8859_1
	./scripts/config --enable CONFIG_BLK_DEV_DM

	./scripts/config --set-str CONFIG_LOCALVERSION "-$(date +%Y%m%d)"

	echo "make -j${CORES} ARCH=riscv CROSS_COMPILE=${RISCV64_CC} olddefconfig"
	make -j${CORES} ARCH=riscv CROSS_COMPILE=${RISCV64_CC} olddefconfig
fi

echo "make -j${CORES} ARCH=riscv CROSS_COMPILE=${RISCV64_CC} Image modules dtbs"
make -j${CORES} ARCH=riscv CROSS_COMPILE="ccache ${RISCV64_CC}" Image modules dtbs

if [ ! -f ./arch/riscv/boot/Image ] ; then
	echo "Build Failed"
	exit 2
fi

KERNEL_UTS=$(cat "${PROJECT_ROOT}/linux/include/generated/utsrelease.h" | awk '{print $3}' | sed 's/\"//g' )

if [ -d "${PROJECT_ROOT}/deploy/tmp/" ] ; then
	rm -rf "${PROJECT_ROOT}/deploy/tmp/"
fi
mkdir -p "${PROJECT_ROOT}/deploy/tmp/"

make -s ARCH=riscv CROSS_COMPILE=${RISCV64_CC} modules_install INSTALL_MOD_PATH="${PROJECT_ROOT}/deploy/tmp"

if [ -f "${PROJECT_ROOT}/deploy/${KERNEL_UTS}-modules.tar.gz" ] ; then
	rm -rf "${PROJECT_ROOT}/deploy/${KERNEL_UTS}-modules.tar.gz" || true
fi
echo "Compressing ${KERNEL_UTS}-modules.tar.gz..."
echo "${KERNEL_UTS}" > "${PROJECT_ROOT}/deploy/.modules"
cd "${PROJECT_ROOT}/deploy/tmp" || true
tar --create --gzip --file "../${KERNEL_UTS}-modules.tar.gz" ./*
cd "${PROJECT_ROOT}/linux/" || exit
rm -rf "${PROJECT_ROOT}/deploy/tmp" || true

if [ -f arch/riscv/configs/mpfs_defconfig ] ; then
	cp -v ./.config ../patches/linux/mpfs_defconfig
	cp -v ./arch/riscv/boot/dts/microchip/mpfs-beaglev-fire.dts ../patches/linux/dts/mpfs-beaglev-fire.dts
	cp -v ./arch/riscv/boot/dts/microchip/mpfs-beaglev-fire-fabric.dtsi ../patches/linux/dts/mpfs-beaglev-fire-fabric.dtsi
else
	cp -v ./.config ../patches/linux/mainline/defconfig
	cp -v ./arch/riscv/boot/dts/microchip/mpfs-beaglev-fire.dts ../patches/linux/mainline/dts/mpfs-beaglev-fire.dts
	cp -v ./arch/riscv/boot/dts/microchip/mpfs-beaglev-fire-fabric.dtsi ../patches/linux/mainline/dts/mpfs-beaglev-fire-fabric.dtsi
fi
if [ ! -d ../deploy/input/ ] ; then
	mkdir -p ../deploy/input/ || true
fi
cp -v ./arch/riscv/boot/Image ../deploy/input/
cp -v ./arch/riscv/boot/dts/microchip/mpfs-beaglev-fire.dtb ../deploy/input/

cd ../

cp -v ./patches/linux/beaglev_fire.its ./deploy/input/
cd ./deploy/input/
gzip -9 Image -c > Image.gz
if [ -f ../../u-boot/tools/mkimage ] ; then
	../../u-boot/tools/mkimage -f beaglev_fire.its beaglev_fire.itb
fi

WIP Generate the HSS payload

cd ./deploy/

if [ -f ./src.bin ] ; then
	if [ ! -d ./input/ ] ; then
		mkdir ./input/
	fi

	if [ -f ./input/payload.bin ] ; then
		rm -rf ./input/payload.bin || true
	fi

	./hss-payload-generator -vv -c config.yaml ./input/payload.bin

	date
	unset test_var
	test_var=$(strings ./u-boot.bin | grep 'U-Boot 20' | head -n1 || true)
	if [ ! "x${test_var}" = "x" ] ; then
		echo "[u-boot.bin: ${test_var}]"
	fi

	unset test_var
	test_var=$(strings ./src.bin | grep 'U-Boot 20' | head -n1 || true)
	if [ ! "x${test_var}" = "x" ] ; then
		echo "[src.bin:    ${test_var}]"
	fi

	unset test_var
	test_var=$(strings ./input/payload.bin | grep 'U-Boot 20' | head -n1 || true)
	if [ ! "x${test_var}" = "x" ] ; then
		echo "[payload.bin:${test_var}]"
	fi
fi

#

WIP Gentoo

rootfs setup install stage3

qemu

echo -E ':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

echo -E ':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

chroot

mount --types proc /proc    ./ignore/.root/proc
mount --rbind /sys          ./ignore/.root/sys
mount --make-rslave         ./ignore/.root/sys
mount --rbind /dev          ./ignore/.root/dev
mount --make-rslave         ./ignore/.root/dev
mount --bind /run           ./ignore/.root/run
mount --make-slave          ./ignore/.root/run

cd ./ignore/.root
chroot $PWD /bin/bash
source /etc/profile
export PS1="(chroot) ${PS1}"