@ -1,51 +1,55 @@
# Table of Contents
1. [Preface ](#org 1e835ab )
2. [Prerequisites ](#org 906530a )
1. [Using the riscv toolchain provided via crossdev ](#org 81f210c )
2. [Using a precompiled toolchain ](#org cee506a )
3. [Clone & Build Heart Software Services (HSS) ](#org cf597f6 )
1. [Clone HSS ](#org 457b83e )
2. [Build HSS ](#org 3e3a28d )
4. [Clone & Build u-boot ](#org f0e36 bd)
1. [Clone u-boot ](#org 8956801 )
2. [Download the patches ](#org 93d8740 )
3. [Build u-boot ](#org 6208aac )
5. [Build the Linux kernel ](#org 9277169 )
6. [Generate the HSS payload ](#org 48e5af c)
7. [Gentoo ](#orgd c16ac3 )
1. [Preface ](#org 50a5e4e )
2. [Prerequisites ](#org f2a2f54 )
1. [Using the riscv toolchain provided via crossdev ](#org b4ce84a )
2. [Using a precompiled toolchain ](#org 9b64e30 )
3. [Clone & Build Heart Software Services (HSS) ](#org 32e7194 )
1. [Clone HSS ](#org b4d121b )
2. [Build HSS ](#org 726b843 )
4. [Clone & Build u-boot ](#org 82839 bd)
1. [Clone u-boot ](#org fa0f9c6 )
2. [Download the patches ](#org e8d926b )
3. [Build u-boot ](#org 705d7b6 )
5. [Build the Linux kernel ](#org 83a0ff0 )
6. [Generate the HSS payload ](#org c2f2fd3 )
7. [Gentoo ](#orgd e9efba )
< a id = "org 1e835ab "> < / a >
< a id = "org 50a5e4e "> < / a >
# 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.
< a id = "org906530a" > < / a >
< a id = "orgf2a2f54" > < / a >
# 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
< a id = "org 81f210c "> < / a >
< a id = "org b4ce84a "> < / a >
## Using the riscv toolchain provided via crossdev
Crossdev is required for this step. If you don’ t have crossdev set up, use [this ](https://wiki.gentoo.org/wiki/Crossdev ) 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 ](#orgcee506a ).
Crossdev is required for this step. If you don’ t have crossdev set up, use [this ](https://wiki.gentoo.org/wiki/Crossdev ) 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 ](#org9b64e30 ).
< https: / / en . wikipedia . org / wiki / google . com >
crossdev -t riscv64-unknown-linux-gnu
export RISCV64_CC="riscv64-unknown-linux-gnu-"
< a id = "org cee506a "> < / a >
< a id = "org 9b64e30 "> < / a >
## Using a precompiled toolchain
@ -69,12 +73,12 @@ Export some other misc. environment variables:
export CORES=$(getconf _NPROCESSORS_ONLN)
< a id = "org cf597f6 "> < / a >
< a id = "org 32e7194 "> < / a >
# Clone & Build Heart Software Services (HSS)
< a id = "org 457b83e "> < / a >
< a id = "org b4d121b "> < / a >
## Clone HSS
@ -85,7 +89,7 @@ Export some other misc. environment variables:
git clone -b ${HSS_BRANCH} ${HSS_REPO} ./hart-software-services/ --depth=${GIT_DEPTH}
< a id = "org 3e3a28d "> < / a >
< a id = "org 726b843 "> < / a >
## Build HSS
@ -94,12 +98,12 @@ Export some other misc. environment variables:
cp -v ./hart-software-services/tools/hss-payload-generator/hss-payload-generator ./deploy/
< a id = "org f0e36 bd"> < / a >
< a id = "org 82839 bd"> < / a >
# Clone & Build u-boot
< a id = "org 8956801 "> < / a >
< a id = "org fa0f9c6 "> < / a >
## Clone u-boot
@ -110,7 +114,7 @@ Export some other misc. environment variables:
git clone -b ${UBOOT_BRANCH} ${UBOOT_REPO} ./u-boot/ --depth=${GIT_DEPTH}
< a id = "org 93d8740 "> < / a >
< a id = "org e8d926b "> < / a >
## Download the patches
@ -119,21 +123,21 @@ The patches currently exist as part of BeagleV’s `BeagleV-Fire-ubuntu` rep
git clone https://git.beagleboard.org/beaglev-fire/BeagleV-Fire-ubuntu.git ./beaglev --depth=${GIT_DEPTH}
< a id = "org 6208aac "> < / a >
< a id = "org 705d7b6 "> < / a >
## WIP Build u-boot
# Apply patches to uboot
cp -v ./patches/u-boot/beaglev-fire/microchip_mpfs_icicle.h ./u-boot/include/configs/microchip_mpfs_icicle.h
cp -v ./patches/u-boot/beaglev-fire/microchip-mpfs-icicle-kit.dts ./u-boot/arch/riscv/dts/
cp -v ./patches/u-boot/beaglev-fire/microchip_mpfs_icicle_defconfig ./u-boot/configs/microchip_mpfs_icicle_defconfig
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 ./patches/u-boot/beaglev-fire/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/
@ -141,17 +145,257 @@ The patches currently exist as part of BeagleV’s `BeagleV-Fire-ubuntu` rep
cp -v ./u-boot/u-boot.bin ./deploy/src.bin
< a id = "org 9277169 "> < / a >
< a id = "org 83a0ff0 "> < / a >
# 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
< a id = "orgc2f2fd3" > < / a >
# 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
#
< a id = "orgde9efba" > < / a >
# WIP Gentoo
rootfs setup
install stage3
qemu
< a id = "org48e5afc" > < / a >
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
# TODO Generate the HSS payload
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
< a id = "orgdc16ac3" > < / a >
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
# TODO Gentoo
cd ./ignore/.root
chroot $PWD /bin/bash
source /etc/profile
export PS1="(chroot) ${PS1}"