updated information on project directories and added gentoo stage 3 +

chroot and qemu information
unstable
Penguin 5 months ago
parent 02508fdf49
commit cecb495a31

@ -1,24 +1,33 @@
# Table of Contents
1. [Preface](#org50a5e4e)
2. [Prerequisites](#orgf2a2f54)
1. [Using the riscv toolchain provided via crossdev](#orgb4ce84a)
2. [Using a precompiled toolchain](#org9b64e30)
3. [Clone & Build Heart Software Services (HSS)](#org32e7194)
1. [Clone HSS](#orgb4d121b)
2. [Build HSS](#org726b843)
4. [Clone & Build u-boot](#org82839bd)
1. [Clone u-boot](#orgfa0f9c6)
2. [Download the patches](#orge8d926b)
3. [Build u-boot](#org705d7b6)
5. [Build the Linux kernel](#org83a0ff0)
6. [Generate the HSS payload](#orgc2f2fd3)
7. [Gentoo](#orgde9efba)
<a id="org50a5e4e"></a>
1. [Preface](#org66dd9fb)
2. [Prerequisites](#orga9cfe68)
1. [Using the riscv toolchain provided via crossdev](#org9a9d7be)
2. [Using a precompiled toolchain](#orgb4086bc)
3. [Configuring QEMU-user and binfmt](#orgdb683fc)
1. [Prepare to install QEMU](#orge05acb6)
2. [Install QEMU](#org5c92799)
3. [Specifying a riscv64 binfmt-misc handler for systemd-binfmt](#orga2a96e0)
3. [Clone & Build Heart Software Services (HSS)](#orgb322fe9)
1. [Clone HSS](#orgf0f9b3b)
2. [Build HSS](#orgae7e590)
4. [Clone & Build u-boot](#org80bf081)
1. [Clone u-boot](#orgdc01583)
2. [Download the patches](#orge5be306)
3. [Build u-boot](#org11baa04)
5. [Build the Linux kernel](#org02b74d7)
6. [Generate the HSS payload](#orgdc575ae)
7. [Installing the RootFS](#orgf09a8e9)
1. [Download and installing a stage tarball](#orgf48a868)
2. [Emerge the base system](#orgf1d5163)
3. [Customize & configure the rootfs](#orgf564865)
1. [Prepare to chroot](#orgc80751f)
2. [Chroot into the target](#org62cd5cf)
<a id="org66dd9fb"></a>
# Preface
@ -27,29 +36,33 @@ This guide is written in a way that forces the reader to manually perform every
**WARNING** This guide is very much still a work in progress. Do not expect anything to work yet.
<a id="orgf2a2f54"></a>
<a id="orga9cfe68"></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
# the target directory will be where we store relevant parts of our target image before we turn it into an image
# the boot dir will contain the linux image, hss payloads, and anything else needed to boot
mkdir -p target/boot target/rootfs
# The tools directory will contain anything needed to generate pieces of the image. The HSS payload generator is one example of this
mkdir tools
# We will store any temporary downloads we need here, like the stage3 tarball
mkdir downloads
<a id="orgb4ce84a"></a>
<a id="org9a9d7be"></a>
## Using the riscv toolchain provided via crossdev
Crossdev is required for this step. If you don&rsquo;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 is required for this step. If you don&rsquo;t have crossdev set up, use [this](https://wiki.gentoo.org/wiki/Crossdev) guide to install it. At the time of writing this, crossdev installs riscv64-unknown-linux-gnu-gcc 13.2.1. This is note worthy because the official beagleboard guide uses 11.4. If there are issues with this toolchain, use the precompiled toolchain via [these steps](#orgb4086bc).
crossdev -t riscv64-unknown-linux-gnu
export RISCV64_CC="riscv64-unknown-linux-gnu-"
<a id="org9b64e30"></a>
<a id="orgb4086bc"></a>
## Using a precompiled toolchain
@ -63,6 +76,8 @@ Crossdev is required for this step. If you don&rsquo;t have crossdev set up, use
From this point forward, instructions will use the `RISCV64_CC` variable as the toolchain.
**WARNING**: Using the precompiled toolchain instead of the toolchain provided by crossdev means the chroot and qemu steps likely won&rsquo;t work. More information on this will be added later, but in the meantime just know that if you don&rsquo;t use the crossdev toolchain, you&rsquo;ll need to skip cross emerging and chrooting. This just means you&rsquo;ll need to compile and configure on the device instead after the first boot. Using the toolchain provided by crossdev is highly recommended.
Export some other misc. environment variables:
export HSS_BRANCH="v2023.02"
@ -73,37 +88,89 @@ Export some other misc. environment variables:
export CORES=$(getconf _NPROCESSORS_ONLN)
<a id="org32e7194"></a>
<a id="orgdb683fc"></a>
## Configuring QEMU-user and binfmt
In a perfect world, producing a rootfs from scratch would simply mean downloading the tarball, unwrapping it into the destined rootfs folder, and running a few scripts to set it up. However, sometimes it can be useful to install a package or configure the system before deploying it to the target device. We can use [qemu-user](https://wiki.gentoo.org/wiki/Embedded_Handbook/General/Compiling_with_qemu_user_chroot) to [chroot](https://wiki.gentoo.org/wiki/Chroot) into our target system to do these things.
<a id="orge05acb6"></a>
### Prepare to install QEMU
echo 'QEMU_SOFTMMU_TARGETS="riscv64 x86_64"' >> /etc/portage/make.conf
echo 'QEMU_USER_TARGETS="riscv64"' >> /etc/portage/make.conf
echo app-emulation/qemu static-user >> /etc/portage/package.use/qemu
<a id="org5c92799"></a>
### Install QEMU
emerge --ask --update --newuse --deep app-emulation/qemu
Now create a binary package for QEMU. This is done so that we can install it into our target system to run chroot properly.
quickpkg app-emulation/qemu
Non-root users will need access to use qemu.
usermod -aG kvm,qemu $USER
<a id="orga2a96e0"></a>
### Specifying a riscv64 binfmt-misc handler for systemd-binfmt
1. Option A: Using the default binfmt configuration file shipped with qemu
&ldquo;For the systemd-binfmt service, add files containing the desired handler registration strings under *etc/binfmt.d*. Modern versions of qemu ship a binfmt configuration file that supports all binary formats. Simply link it to /etc for binary format support, then skip the following manual file creation steps.&rdquo; - [Gentoo Embedded Handbook](https://wiki.gentoo.org/wiki/Embedded_Handbook/General/Compiling_with_qemu_user_chroot)
ln -s /usr/share/qemu/binfmt.d/qemu.conf /etc/binfmt.d/qemu.conf
This supports *all* default architectures in the default `qemu.conf`. If you only want to support riscv64, use the [instructions](#orgc37565d) below.
2. Option B: Adding support for just riscv64
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
Now restart the service to register the binary formats:
systemctl restart systemd-binfmt
See the `chroot instructions below`
<a id="orgb322fe9"></a>
# Clone & Build Heart Software Services (HSS)
<a id="orgb4d121b"></a>
<a id="orgf0f9b3b"></a>
## 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}
<a id="org726b843"></a>
<a id="orgae7e590"></a>
## 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/
<a id="org82839bd"></a>
<a id="org80bf081"></a>
# Clone & Build u-boot
<a id="orgfa0f9c6"></a>
<a id="orgdc01583"></a>
## Clone u-boot
@ -114,7 +181,7 @@ Export some other misc. environment variables:
git clone -b ${UBOOT_BRANCH} ${UBOOT_REPO} ./u-boot/ --depth=${GIT_DEPTH}
<a id="orge8d926b"></a>
<a id="orge5be306"></a>
## Download the patches
@ -123,7 +190,7 @@ The patches currently exist as part of BeagleV&rsquo;s `BeagleV-Fire-ubuntu` rep
git clone https://git.beagleboard.org/beaglev-fire/BeagleV-Fire-ubuntu.git ./beaglev --depth=${GIT_DEPTH}
<a id="org705d7b6"></a>
<a id="org11baa04"></a>
## WIP Build u-boot
@ -139,13 +206,13 @@ The patches currently exist as part of BeagleV&rsquo;s `BeagleV-Fire-ubuntu` rep
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/
# copy the generated uboot into our boot folder
cp -v ./u-boot/u-boot.bin ./target/boot/u-boot.bin
# 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
cp -v ./u-boot/u-boot.bin ./target/boot/src.bin
<a id="org83a0ff0"></a>
<a id="org02b74d7"></a>
# TODO Build the Linux kernel
@ -331,7 +398,7 @@ The patches currently exist as part of BeagleV&rsquo;s `BeagleV-Fire-ubuntu` rep
fi
<a id="orgc2f2fd3"></a>
<a id="orgdc575ae"></a>
# WIP Generate the HSS payload
@ -371,30 +438,54 @@ The patches currently exist as part of BeagleV&rsquo;s `BeagleV-Fire-ubuntu` rep
#
<a id="orgde9efba"></a>
<a id="orgf09a8e9"></a>
# WIP Gentoo
# WIP Installing the RootFS
rootfs setup
install stage3
qemu
<a id="orgf48a868"></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
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
## Download and installing a stage tarball
chroot
This guide uses the systemd-mergedusr profile by default. Other profiles have not been tested.
wget https://distfiles.gentoo.org/releases/riscv/autobuilds/current-stage3-rv64_lp64d-systemd-mergedusr/stage3-rv64_lp64d-systemd-mergedusr-20231124T170207Z.tar.xz --directory-prefix=./download
tar xpvf ./download/stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner -C ./target/rootfs/
<a id="orgf1d5163"></a>
## Emerge the base system
riscv64-unknown-linux-gnu-emerge -va1 @system --keep-going
<a id="orgf564865"></a>
## Customize & configure the rootfs
<a id="orgc80751f"></a>
### Prepare to chroot
cd target
mount --bind rootfs rootfs
cd rootfs
ROOT=$PWD emerge --usepkgonly --oneshot --nodeps qemu
mount --bind /proc proc
mount --bind /sys sys
mount --bind /dev/pts dev/pts
mkdir -p var/db/repos/gentoo
mount --bind -o ro /var/db/repos/gentoo var/db/repos/gentoo
mkdir -p usr/src/linux
mount --bind -o ro linux usr/src/linux
<a id="org62cd5cf"></a>
### Chroot into the target
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}"

@ -0,0 +1,370 @@
= 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"
# the target directory will be where we store relevant parts of our target image before we turn it into an image
# the boot dir will contain the linux image, hss payloads, and anything else needed to boot
mkdir -p target/boot target/rootfs
# The tools directory will contain anything needed to generate pieces of the image. The HSS payload generator is one example of this
mkdir tools
# We will store any temporary downloads we need here, like the stage3 tarball
mkdir downloads
== Using the riscv toolchain provided via crossdev ==
Crossdev is required for this step. If you don&rsquo;t have crossdev set up, use [https://wiki.gentoo.org/wiki/Crossdev this] guide to install it. At the time of writing this, crossdev installs riscv64-unknown-linux-gnu-gcc 13.2.1. This is note worthy because the official beagleboard guide uses 11.4. If there are issues with this toolchain, use the precompiled toolchain via these steps.
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 <code>RISCV64_CC</code> variable as the toolchain.
'''WARNING''': Using the precompiled toolchain instead of the toolchain provided by crossdev means the chroot and qemu steps likely won&rsquo;t work. More information on this will be added later, but in the meantime just know that if you don&rsquo;t use the crossdev toolchain, you&rsquo;ll need to skip cross emerging and chrooting. This just means you&rsquo;ll need to compile and configure on the device instead after the first boot. Using the toolchain provided by crossdev is highly recommended.
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)
== Configuring QEMU-user and binfmt ==
In a perfect world, producing a rootfs from scratch would simply mean downloading the tarball, unwrapping it into the destined rootfs folder, and running a few scripts to set it up. However, sometimes it can be useful to install a package or configure the system before deploying it to the target device. We can use [https://wiki.gentoo.org/wiki/Embedded_Handbook/General/Compiling_with_qemu_user_chroot qemu-user] to [https://wiki.gentoo.org/wiki/Chroot chroot] into our target system to do these things.
=== Prepare to install QEMU ===
echo 'QEMU_SOFTMMU_TARGETS="riscv64 x86_64"' >> /etc/portage/make.conf
echo 'QEMU_USER_TARGETS="riscv64"' >> /etc/portage/make.conf
echo app-emulation/qemu static-user >> /etc/portage/package.use/qemu
=== Install QEMU ===
emerge --ask --update --newuse --deep app-emulation/qemu
Now create a binary package for QEMU. This is done so that we can install it into our target system to run chroot properly.
quickpkg app-emulation/qemu
Non-root users will need access to use qemu.
usermod -aG kvm,qemu $USER
=== Specifying a riscv64 binfmt-misc handler for systemd-binfmt ===
==== Option A: Using the default binfmt configuration file shipped with qemu ====
&ldquo;For the systemd-binfmt service, add files containing the desired handler registration strings under ''etc/binfmt.d''. Modern versions of qemu ship a binfmt configuration file that supports all binary formats. Simply link it to /etc for binary format support, then skip the following manual file creation steps.&rdquo; - [https://wiki.gentoo.org/wiki/Embedded_Handbook/General/Compiling_with_qemu_user_chroot Gentoo Embedded Handbook]
ln -s /usr/share/qemu/binfmt.d/qemu.conf /etc/binfmt.d/qemu.conf
This supports ''all'' default architectures in the default <code>qemu.conf</code>. If you only want to support riscv64, use the instructions below.
==== Option B: Adding support for just riscv64 ====
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
Now restart the service to register the binary formats:
systemctl restart systemd-binfmt
See the <code>chroot instructions below</code>
= Clone & Build Heart Software Services (HSS) =
== Clone HSS ==
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/
= 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 BeagleV&rsquo;s <code>BeagleV-Fire-ubuntu</code> repo, so we&rsquo;ll just clone the whole thing for now. Eventually, I&rsquo;ll 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 boot folder
cp -v ./u-boot/u-boot.bin ./target/boot/u-boot.bin
# 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 ./target/boot/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 Installing the RootFS =
== Download and installing a stage tarball ==
This guide uses the systemd-mergedusr profile by default. Other profiles have not been tested.
wget https://distfiles.gentoo.org/releases/riscv/autobuilds/current-stage3-rv64_lp64d-systemd-mergedusr/stage3-rv64_lp64d-systemd-mergedusr-20231124T170207Z.tar.xz --directory-prefix=./download
tar xpvf ./download/stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner -C ./target/rootfs/
== Emerge the base system ==
riscv64-unknown-linux-gnu-emerge -va1 @system --keep-going
== Customize & configure the rootfs ==
=== Prepare to chroot ===
cd target
mount --bind rootfs rootfs
cd rootfs
ROOT=$PWD emerge --usepkgonly --oneshot --nodeps qemu
mount --bind /proc proc
mount --bind /sys sys
mount --bind /dev/pts dev/pts
mkdir -p var/db/repos/gentoo
mount --bind -o ro /var/db/repos/gentoo var/db/repos/gentoo
mkdir -p usr/src/linux
mount --bind -o ro linux usr/src/linux
=== Chroot into the target ===
chroot $PWD /bin/bash
source /etc/profile
export PS1="(chroot) ${PS1}"

@ -11,14 +11,18 @@ This guide is written in a way that forces the reader to manually perform every
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
# the target directory will be where we store relevant parts of our target image before we turn it into an image
# the boot dir will contain the linux image, hss payloads, and anything else needed to boot
mkdir -p target/boot target/rootfs
# The tools directory will contain anything needed to generate pieces of the image. The HSS payload generator is one example of this
mkdir tools
# We will store any temporary downloads we need here, like the stage3 tarball
mkdir downloads
#+end_src
** Using the riscv toolchain provided via crossdev
Crossdev is required for this step. If you don't have crossdev set up, use [[https://wiki.gentoo.org/wiki/Crossdev][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 [[*Using a precompiled toolchain][these steps]].
[[wikipedia:google.com]]
Crossdev is required for this step. If you don't have crossdev set up, use [[https://wiki.gentoo.org/wiki/Crossdev][this]] guide to install it. At the time of writing this, crossdev installs riscv64-unknown-linux-gnu-gcc 13.2.1. This is note worthy because the official beagleboard guide uses 11.4. If there are issues with this toolchain, use the precompiled toolchain via [[*Using a precompiled toolchain][these steps]].
#+begin_src bash
crossdev -t riscv64-unknown-linux-gnu
export RISCV64_CC="riscv64-unknown-linux-gnu-"
@ -38,6 +42,8 @@ export RISCV64_CC="$PWD/toolchain/bin/riscv64-linux-"
From this point forward, instructions will use the ~RISCV64_CC~ variable as the toolchain.
*WARNING*: Using the precompiled toolchain instead of the toolchain provided by crossdev means the chroot and qemu steps likely won't work. More information on this will be added later, but in the meantime just know that if you don't use the crossdev toolchain, you'll need to skip cross emerging and chrooting. This just means you'll need to compile and configure on the device instead after the first boot. Using the toolchain provided by crossdev is highly recommended.
Export some other misc. environment variables:
#+begin_src bash
export HSS_BRANCH="v2023.02"
@ -48,10 +54,60 @@ export GIT_DEPTH=20
export CORES=$(getconf _NPROCESSORS_ONLN)
#+end_src
** Configuring QEMU-user and binfmt
In a perfect world, producing a rootfs from scratch would simply mean downloading the tarball, unwrapping it into the destined rootfs folder, and running a few scripts to set it up. However, sometimes it can be useful to install a package or configure the system before deploying it to the target device. We can use [[https://wiki.gentoo.org/wiki/Embedded_Handbook/General/Compiling_with_qemu_user_chroot][qemu-user]] to [[https://wiki.gentoo.org/wiki/Chroot][chroot]] into our target system to do these things.
*** Prepare to install QEMU
#+begin_src bash
echo 'QEMU_SOFTMMU_TARGETS="riscv64 x86_64"' >> /etc/portage/make.conf
echo 'QEMU_USER_TARGETS="riscv64"' >> /etc/portage/make.conf
echo app-emulation/qemu static-user >> /etc/portage/package.use/qemu
#+end_src
*** Install QEMU
#+begin_src bash
emerge --ask --update --newuse --deep app-emulation/qemu
#+end_src
Now create a binary package for QEMU. This is done so that we can install it into our target system to run chroot properly.
#+begin_src bash
quickpkg app-emulation/qemu
#+end_src
Non-root users will need access to use qemu.
#+begin_src bash
usermod -aG kvm,qemu $USER
#+end_src
*** Specifying a riscv64 binfmt-misc handler for systemd-binfmt
# TODO: Add information on why we need to specify a binfmt-misc handler at all. (Answer is the system needs to associate an elf signature to an architecture for qemu)
**** Option A: Using the default binfmt configuration file shipped with qemu
"For the systemd-binfmt service, add files containing the desired handler registration strings under /etc/binfmt.d/. Modern versions of qemu ship a binfmt configuration file that supports all binary formats. Simply link it to /etc for binary format support, then skip the following manual file creation steps." - [[https://wiki.gentoo.org/wiki/Embedded_Handbook/General/Compiling_with_qemu_user_chroot][Gentoo Embedded Handbook]]
#+begin_src bash
ln -s /usr/share/qemu/binfmt.d/qemu.conf /etc/binfmt.d/qemu.conf
#+end_src
This supports /all/ default architectures in the default ~qemu.conf~. If you only want to support riscv64, use the [[*Option B: Adding support for just riscv64][instructions]] below.
**** Option B: Adding support for just riscv64
#+begin_src bash
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
#+end_src
Now restart the service to register the binary formats:
#+begin_src bash
systemctl restart systemd-binfmt
#+end_src
# TODO: add an actual link to chroot instructions here
See the ~chroot instructions below~
* Clone & Build Heart Software Services (HSS)
** Clone HSS
# TODO: Add information about the HSS here. what is it?
#+begin_src bash
# remove old if it exists, optional
if [ -d ./hart-software-services/ ] ; then
rm -rf ./hart-software-services/ || true
fi
@ -62,7 +118,6 @@ git clone -b ${HSS_BRANCH} ${HSS_REPO} ./hart-software-services/ --depth=${GIT_D
#+begin_src bash
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/
#+end_src
* Clone & Build u-boot
@ -83,7 +138,6 @@ The patches currently exist as part of BeagleV's ~BeagleV-Fire-ubuntu~ repo, so
git clone https://git.beagleboard.org/beaglev-fire/BeagleV-Fire-ubuntu.git ./beaglev --depth=${GIT_DEPTH}
#+end_src
** WIP Build u-boot
#+begin_src bash
# Apply patches to uboot
@ -98,10 +152,10 @@ 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/
# copy the generated uboot into our boot folder
cp -v ./u-boot/u-boot.bin ./target/boot/u-boot.bin
# 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
cp -v ./u-boot/u-boot.bin ./target/boot/src.bin
#+end_src
* TODO Build the Linux kernel
@ -327,28 +381,48 @@ fi
#
#+end_src
* WIP Gentoo
rootfs setup
install stage3
* WIP Installing the RootFS
qemu
** Download and installing a stage tarball
This guide uses the systemd-mergedusr profile by default. Other profiles have not been tested.
# TODO: Change these instructions to pull the latest instead of a hard-timestamped url.
# TODO: Add info on verifying the hash
#+begin_src bash
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
wget https://distfiles.gentoo.org/releases/riscv/autobuilds/current-stage3-rv64_lp64d-systemd-mergedusr/stage3-rv64_lp64d-systemd-mergedusr-20231124T170207Z.tar.xz --directory-prefix=./download
tar xpvf ./download/stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner -C ./target/rootfs/
#+end_src
# TODO: Add system profile instructions. I'm leaving this out for now because until the guide is at a useable point, I only want the focus to be on systemd-mergedusr
# ** Set the system profile
# #+begin_src bash
# PORTAGE_CONFIGROOT=/usr/riscv64-unknown-linux-gnu eselect profile list
# #+end_src
** Emerge the base system
#+begin_src bash
riscv64-unknown-linux-gnu-emerge -va1 @system --keep-going
#+end_src
** Customize & configure the rootfs
*** Prepare to chroot
#+begin_src bash
cd target
mount --bind rootfs rootfs
cd rootfs
ROOT=$PWD emerge --usepkgonly --oneshot --nodeps qemu
mount --bind /proc proc
mount --bind /sys sys
mount --bind /dev/pts dev/pts
mkdir -p var/db/repos/gentoo
mount --bind -o ro /var/db/repos/gentoo var/db/repos/gentoo
mkdir -p usr/src/linux
mount --bind -o ro linux usr/src/linux
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
#+end_src
chroot
*** Chroot into the target
#+begin_src bash
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}"

Loading…
Cancel
Save