This is a walk-through Microchip repo to build u-boot and linux for beaglev-fire.
Linux Build flow Link to heading
In 1, The repo has scripts to build all software components including u-boot and linux. Let’s dig deeper into what is there. This the main script that calls some smaller scripts.
# Building Microchip Linux tree
./01_git_sync.sh
./02_build_hss.sh
./03_build_u-boot.sh
./04_build_linux.sh
./05_generate_payload.bin.sh
sudo ./06_generate_debian_console_root.sh
sudo ./07_create_sdcard_img.sh
01 clone git repos Link to heading
First, the scripts clone the required repos Linux, uboot and DeviceTree.
GIT_DEPTH="20"
GCC_VERSION="11.4.0"
HSS_BRANCH="v2023.02"
HSS_REPO="https://github.com/polarfire-soc/hart-software-services.git"
#UBOOT_BRANCH="mpfs-uboot-2022.01"
#UBOOT_BRANCH="linux4microchip+fpga-2023.02"
#UBOOT_REPO="https://github.com/polarfire-soc/u-boot.git"
UBOOT_BRANCH="v2023.02-BeagleV-Fire"
UBOOT_REPO="https://openbeagle.org/beaglev-fire/beaglev-fire-u-boot.git"
#UBOOT_REPO="git@openbeagle.org:beaglev-fire/beaglev-fire-u-boot.git"
DT_BRANCH="v6.6.x-Beagle"
DT_REPO="https://openbeagle.org/beagleboard/BeagleBoard-DeviceTrees.git"
#DT_REPO="git@openbeagle.org:beagleboard/BeagleBoard-DeviceTrees.git"
LINUX_BRANCH="linux4microchip+fpga-2024.09"
LINUX_REPO="https://github.com/linux4microchip/linux.git"
#LINUX_REPO="https://openbeagle.org/beaglev-fire/beaglev-fire-linux.git"
#LINUX_REPO="git@openbeagle.org:beaglev-fire/beaglev-fire-linux.git"
if [ ! -f ./mirror/x86_64-gcc-${GCC_VERSION}-nolibc-riscv64-linux.tar.xz ] ; then
echo "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"
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
fi
if [ ! -f ./riscv-toolchain/bin/riscv64-linux-gcc-${GCC_VERSION} ] ; then
echo "tar xf ./mirror/x86_64-gcc-${GCC_VERSION}-nolibc-riscv64-linux.tar.xz --strip-components=2 -C ./riscv-toolchain/"
tar xf ./mirror/x86_64-gcc-${GCC_VERSION}-nolibc-riscv64-linux.tar.xz --strip-components=2 -C ./riscv-toolchain/
fi
git clone -b ${HSS_BRANCH} ${HSS_REPO} ./hart-software-services/ --depth=${GIT_DEPTH}
git clone -b ${UBOOT_BRANCH} ${UBOOT_REPO} ./u-boot/ --depth=${GIT_DEPTH}
git clone -b ${DT_BRANCH} ${DT_REPO} ./device-tree/ --depth=${GIT_DEPTH}
git clone --reference-if-able ~/linux-src/ -b ${LINUX_BRANCH} ${LINUX_REPO} ./linux/ --depth=${GIT_DEPTH}
02 HSS Link to heading
for that, I need to install this package before building payload generator deploy/hss-payload-generator
sudo apt install libyaml-dev
Then we get HSS
make -C hart-software-services/tools/hss-payload-generator/
cp -v ./hart-software-services/tools/hss-payload-generator/hss-payload-generator ./deploy/
03 u-boot Link to heading
Then, compiling uboot
and copying src.bin
to deploy/src.bin
and deploy/u-boot.bin
.
CORES=$(getconf _NPROCESSORS_ONLN)
wdir=`pwd`
CC=${CC:-"${wdir}/riscv-toolchain/bin/riscv64-linux-"}
make -C u-boot ARCH=riscv CROSS_COMPILE=${CC} distclean
make -C u-boot ARCH=riscv CROSS_COMPILE=${CC} microchip_mpfs_icicle_defconfig
#make -C u-boot ARCH=riscv CROSS_COMPILE=${CC} menuconfig
make -C u-boot ARCH=riscv CROSS_COMPILE=${CC} olddefconfig
make -C u-boot ARCH=riscv CROSS_COMPILE=${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
echo "make -C u-boot -j${CORES} ARCH=riscv CROSS_COMPILE=${CC} all"
make -C u-boot -j${CORES} ARCH=riscv CROSS_COMPILE=${CC} all
cp -v ./u-boot/u-boot.bin ./deploy/
cp -v ./u-boot/u-boot.bin ./deploy/src.bin
04 Linux Link to heading
Next step, compiling Image, modules and dtb and copy them to deploy
make -j${CORES} ARCH=riscv CROSS_COMPILE="ccache ${CC}" DTC_FLAGS="-@" Image modules dtbs
deploy/6.6.51-linux4microchip+fpga-2024.09-20250214+-modules.tar.gz
make -s ARCH=riscv CROSS_COMPILE=${CC} modules_install INSTALL_MOD_PATH="${wdir}/deploy/tmp"
if [ -f "${wdir}/deploy/${KERNEL_UTS}-modules.tar.gz" ] ; then
rm -rf "${wdir}/deploy/${KERNEL_UTS}-modules.tar.gz" || true
fi
echo "Compressing ${KERNEL_UTS}-modules.tar.gz..."
echo "${KERNEL_UTS}" > "${wdir}/deploy/.modules"
cd "${wdir}/deploy/tmp" || true
tar --create --gzip --file "../${KERNEL_UTS}-modules.tar.gz" ./*
The build will copy deploy/input/Image
and deploy/input/mpfs-beaglev-fire.dtb
. Then generate deploy/Image.gz
cp -v ./arch/riscv/boot/Image ../deploy/input/
cp -v ./arch/riscv/boot/dts/microchip/mpfs-beaglev-fire.dtb ../deploy/input/
cd deploy/input
gzip -9 Image -c > Image.gz
cp -v ./patches/linux/beaglev_fire.its ./deploy/input/
if [ -f ../../u-boot/tools/mkimage ] ; then
../../u-boot/tools/mkimage -f beaglev_fire.its beaglev_fire.itb
fi
The generated files would be as follows:
input/
├── beaglev_fire.itb
├── beaglev_fire.its
├── Image
├── Image.gz
└── mpfs-beaglev-fire.dtb
05 payload Link to heading
Then generating deploy/input/payload.bin
with HSS above
./hss-payload-generator -vv -c config.yaml ./input/payload.bin
It will use the u-boot src.bin
that was compiler earlier.
#
# HSS Payload Generator - buildroot configuration file
#
# First, we can optionally set a name for our image, otherwise one will be created dynamically
set-name: 'PolarFire-SoC-HSS::U-Boot'
#
# Next, we'll define the entry point addresses for each hart, as follows:
#
hart-entry-points: {u54_1: '0x80200000', u54_2: '0x80200000', u54_3: '0x80200000', u54_4: '0x80200000'}
#
# Finally, we'll define a payloads (source binary file) that will be placed at certain regions in memory
# The payload section is defined with the keyword payloads, and then a number of individual
# payload descriptors.
#
# Each payload has a name (path to its ELF/bin file), an owner-hart, and optionally 1-3 secondary-harts.
#
# Additionally, it has a privilege mode in which it will start execution.
# * Valid privilege modes are PRV_M, PRV_S and PRV_U.
#
#
# In this case, the only payload is the u-boot s-mode binary.
#
# Case only matters for the ELF path names, not the keywords.
#
payloads:
src.bin: {exec-addr: '0x80200000', owner-hart: u54_1, secondary-hart: u54_2, secondary-hart: u54_3, secondary-hart: u54_4, priv-mode: prv_s}
06 root file Link to heading
Download riscv file system and copy stuff from deploy
into the filesystem
wget -c --directory-prefix=./deploy https://rcn-ee.net/rootfs/${distro}-riscv64-${version}-minimal/${datestamp}/${latest_rootfs}
tar xfp ./deploy/${distro}-${version}-console-riscv64-${datestamp}/riscv64-rootfs-${distro}-${codename}.tar -C ./ignore/.root
Install uboot stuff:
cp -v ./deploy/boot.scr deploy/input/
cp -v ./deploy/sysconf.txt deploy/input/
Change some stuff in the filesystem
echo "label Linux eMMC" > ./deploy/input/extlinux.conf
echo " kernel /Image" >> ./deploy/input/extlinux.conf
#echo " append root=/dev/mmcblk0p3 ro rootfstype=ext4 rootwait console=ttyS0,115200 earlycon uio_pdrv_genirq.of_id=generic-uio net.ifnames=0" >> ./deploy/input/extlinux.conf
echo " fdtdir /" >> ./deploy/input/extlinux.conf
echo " fdt /mpfs-beaglev-fire.dtb" >> ./deploy/input/extlinux.conf
echo " #fdtoverlays /overlays/<file>.dtbo" >> ./deploy/input/extlinux.conf
#echo "extlinux/extlinux.conf"
#cat ./deploy/input/extlinux.conf
mkdir -p ./ignore/.root/boot/firmware/ || true
echo '/dev/mmcblk0p2 /boot/firmware/ vfat user,uid=1000,gid=1000,defaults 0 2' >> ./ignore/.root/etc/fstab
echo '/dev/mmcblk0p3 / auto errors=remount-ro 0 1' >> ./ignore/.root/etc/fstab
echo 'debugfs /sys/kernel/debug debugfs mode=755,uid=root,gid=gpio,defaults 0 0' >> ./ignore/.root/etc/fstab
#Network-Manager, ignore eth1
#cp -v ./rootfs/etc/NetworkManager/conf.d/*.conf ./ignore/.root/etc/NetworkManager/conf.d/
cp -v ./ignore/.root/etc/bbb.io/templates/eth0-DHCP.network ./ignore/.root/etc/systemd/network/eth0.network || true
cp -v ./ignore/.root/etc/bbb.io/templates/eth1-DHCP.network ./ignore/.root/etc/systemd/network/eth1.network || true
# setuid root ping+ping6
chmod u+s ./ignore/.root/usr/bin/ping ./ignore/.root/usr/bin/ping6
#Default nginx export
rm -f ./ignore/.root/etc/nginx/sites-enabled/default || true
cp -v ./ignore/.root/etc/bbb.io/templates/nginx/nginx-autoindex ./ignore/.root/etc/nginx/sites-enabled/default
cp -v ./ignore/.root/etc/bbb.io/templates/nginx/*.html ./ignore/.root/var/www/html/
rm -f ./ignore/.root/var/www/html/index.nginx-debian.html || true
Install the kernel modules
if [ -f ./deploy/.modules ] ; then
version=$(cat ./deploy/.modules || true)
if [ -f ./deploy/${version}-modules.tar.gz ] ; then
tar xf ./deploy/${version}-modules.tar.gz -C ./ignore/.root/usr/
fi
fi
dd if=/dev/zero of=./deploy/input/root.ext4 bs=1 count=0 seek=2200M
mkfs.ext4 -F ./deploy/input/root.ext4 -d ./ignore/.root
07 SD Card Image Link to heading
genimage
is called to genreate the final sdcard image sdcard.img
with boot and filesystem partitions.
genimage is a tool to generate multiple filesystem and flash/disk images from a given root filesystem tree. genimage is intended to be run in a fakeroot environment. It also supports creating flash/disk images out of different file-system images and files.
genimage --config genimage.cfg
# Image for eMMC or SDCard boot on the Microchip PolarFire SOC Icicle Board
#
image boot.vfat {
vfat {
files = {
"beaglev_fire.itb",
"boot.scr",
"sysconf.txt"
}
}
size = 128M
}
image sdcard.img {
hdimage {
partition-table-type = "gpt"
}
partition uboot {
partition-type-uuid = 21686148-6449-6E6F-744E-656564454649
image = "payload.bin"
}
partition kernel {
partition-type-uuid = F
bootable = "true"
image = "boot.vfat"
}
partition rootfs {
partition-type-uuid = L
image = "root.ext4"
}
}
bmaptool generate the final sdcard.bmap
from sdcard.img
which seems faster
bmaptool is a generic tool for creating the block map (bmap) for a file and copying files using the block map. The idea is that large files, like raw system image files, can be copied or flashed a lot faster and more reliably with bmaptool than with traditional tools, like dd or cp.
bmaptool was originally created for the “Tizen IVI” project and it was used for flashing system images to USB sticks and other block devices. bmaptool can also be used for general image flashing purposes, for example, flashing Fedora Linux OS distribution images to USB sticks.
/usr/bin/bmaptool -d create -o ./images/sdcard.bmap ./images/sdcard.img