This post accompanies the following YouTube video:
In preparation for installing Linux Gentoo on a Raspberry Pi 5 it was necessary to rebuild the boot partition and prepare related files (such as kernel modules, overlay files, and device firmware).
The boot partition of the Raspberry Pi is the first OS related software that is loaded when the Raspberry Pi is turned on or restarted. In the boot partition we will find various files including the Linux kernel itself, configuration settings (config.txt), dtb overlay files, and the boot parameters (cmdline.txt).
In the previous post located here we rebuilt the Linux kernel, now it is time to rebuild the boot partition and gather other related files (kernel modules, dtb overlay files, and settings files). These operations do not require the micro sd card from the Raspberry Pi except for one file, config.txt, which could be downloaded from elsewhere, but the file on the micro sd card is copied and used. It will also be provided here for download. The script that was used for these operations is provided below as well.
Starting off we will set some environment variables in an attempt to make modifications easier in the future. These are set with the below lines. Make sure to make changes to match your own specific setup, specifically WORKDIR and KERNEL_ROOT.
The necessary files in KERNEL_ROOT were created in the previous post and can be downloaded below if desired.
Start off by executing the environment variables below:
NOW_YMDHMS="$(date +"%Y%m%d%H%M%S")"
NOW_YMD="$(date +"%Y%m%d")"
DATESTAMP="${NOW_YMD}"
WORKDIR="/var/datadisk/raspberrypi_gentoo_rpi64/build_attempt_20250116/prebuild_archive_${DATESTAMP}"
BOOTFS_ROOT="${WORKDIR}/bootfs"
ROOTFS_FIRMWARE_NONFREE="${WORKDIR}/rootfs_firmware-nonfree"
ROOTFS_FIRMWARE_BLUEZ="${WORKDIR}/rootfs_firmware_bluez"
ROOTFS_MODULES="${WORKDIR}/rootfs_modules"
KERNEL_ROOT="/var/datadisk/raspberrypi_gentoo_rpi64/raspberrypi_kernel_20250110/kernel_build_20250113"
KERNEL1_ARCHIVE="${KERNEL_ROOT}/linux_6.6.70_kernel8_20250113.tar.bz2"
KERNEL1_ARCHIVE_MODULES="${KERNEL_ROOT}/linux_6.6.70_kernel8_modules_20250113.tar.bz2"
KERNEL1_ARCHIVE_DTB="${KERNEL_ROOT}/linux_6.6.70_kernel8_dtb_20250113.tar.bz2"
KERNEL1_FILENAME_KERNEL="kernel8.img"
KERNEL1_FILENAME_CONFIG="kernel8.config"
KERNEL2_ARCHIVE="${KERNEL_ROOT}/linux_6.6.70_kernel_2712_20250113.tar.bz2"
KERNEL2_ARCHIVE_MODULES="${KERNEL_ROOT}/linux_6.6.70_kernel_2712_modules_20250113.tar.bz2"
KERNEL2_ARCHIVE_DTB="${KERNEL_ROOT}/linux_6.6.70_kernel_2712_dtb_20250113.tar.bz2"
KERNEL2_FILENAME_KERNEL="kernel_2712.img"
KERNEL2_FILENAME_CONFIG="kernel_2712.config"
Next we will setup and prepare the working directory that will be used for the operations.
mkdir -p ${WORKDIR}
cd ${WORKDIR}
Then follow up with grabbing the latest versions of the following repositories.
Download the current Raspberry Pi firmware (basically the files for the boot partition):
rm -rf ${WORKDIR}/firmware
git clone --depth=1 https://github.com/raspberrypi/firmware
Download the current hardware firmware files (used during device driver loading):
rm -rf ${WORKDIR}/firmware-nonfree
git clone --depth=1 https://github.com/RPi-Distro/firmware-nonfree.git
Download the current Bluetooth hardware firmware files (used during Bluetooth device driver loading):
rm -rf ${WORKDIR}/bluez-firmware
git clone --depth=1 https://github.com/RPi-Distro/bluez-firmware.git
Next create an archive of these downloads that may come in handy later on if needed. These archives are also provided below along with instructions on how to extract them (if the above files are no longer available or compatibility issues arise.
tar -jcvpf ${WORKDIR}/firmware_${DATESTAMP}.tar.bz2 --directory=${WORKDIR}/firmware .
tar -jcvpf ${WORKDIR}/firmware-nonfree_${DATESTAMP}.tar.bz2 --directory=${WORKDIR}/firmware-nonfree .
tar -jcvpf ${WORKDIR}/bluez-firmware_${DATESTAMP}.tar.bz2 --directory=${WORKDIR}/bluez-firmware .
Here are downloads of those above files along with the commands to extract them (they will replace the above repositories):
#extract the firmware to retrieve necessary files
rm -rf ${WORKDIR}/firmware
mkdir -p ${WORKDIR}/firmware
tar xpjf ${WORKDIR}/firmware_${DATESTAMP}.tar.bz2 -C ${WORKDIR_REMOTE}/firmware
#extract the firmware-nonfree to retrieve necessary files
rm -rf ${WORKDIR}/firmware-nonfree
mkdir -p ${WORKDIR}/firmware-nonfree
tar xpjf ${WORKDIR}/firmware-nonfree_${DATESTAMP}.tar.bz2 -C ${WORKDIR}/firmware-nonfree
#extract the firmware-bluetooth to retrieve the necessary files
rm -rf ${WORKDIR}/bluez-firmware
mkdir -p ${WORKDIR}/bluez-firmware
tar xpjf ${WORKDIR}/bluez-firmware_${DATESTAMP}.tar.bz2 -C ${WORKDIR}/bluez-firmware
Now that we have all the files locally available let’s go ahead and create the new boot partition which can be transferred to a micro sd card later. Create the bootfs directory first, this will also delete the previous bootfs directory.
rm -rf ${BOOTFS_ROOT}
mkdir -p ${BOOTFS_ROOT}
Copy in the necessary files from the firmware repository:
cp -a ${WORKDIR}/firmware/boot/COPYING.linux ${BOOTFS_ROOT}/.
cp -a ${WORKDIR}/firmware/boot/LICENCE.broadcom ${BOOTFS_ROOT}/.
cp -a ${WORKDIR}/firmware/boot/bootcode.bin ${BOOTFS_ROOT}/.
cp -a ${WORKDIR}/firmware/boot/fixup.dat ${BOOTFS_ROOT}/.
cp -a ${WORKDIR}/firmware/boot/fixup4.dat ${BOOTFS_ROOT}/.
cp -a ${WORKDIR}/firmware/boot/fixup4cd.dat ${BOOTFS_ROOT}/.
cp -a ${WORKDIR}/firmware/boot/fixup4db.dat ${BOOTFS_ROOT}/.
cp -a ${WORKDIR}/firmware/boot/fixup4x.dat ${BOOTFS_ROOT}/.
cp -a ${WORKDIR}/firmware/boot/fixup_cd.dat ${BOOTFS_ROOT}/.
cp -a ${WORKDIR}/firmware/boot/fixup_db.dat ${BOOTFS_ROOT}/.
cp -a ${WORKDIR}/firmware/boot/fixup_x.dat ${BOOTFS_ROOT}/.
cp -a ${WORKDIR}/firmware/boot/start.elf ${BOOTFS_ROOT}/.
cp -a ${WORKDIR}/firmware/boot/start4.elf ${BOOTFS_ROOT}/.
cp -a ${WORKDIR}/firmware/boot/start4cd.elf ${BOOTFS_ROOT}/.
cp -a ${WORKDIR}/firmware/boot/start4db.elf ${BOOTFS_ROOT}/.
cp -a ${WORKDIR}/firmware/boot/start4x.elf ${BOOTFS_ROOT}/.
cp -a ${WORKDIR}/firmware/boot/start_cd.elf ${BOOTFS_ROOT}/.
cp -a ${WORKDIR}/firmware/boot/start_db.elf ${BOOTFS_ROOT}/.
cp -a ${WORKDIR}/firmware/boot/start_x.elf ${BOOTFS_ROOT}/.
Also copy in the kernel8 and kernel_2712 from the recent kernel build:
tar xjfv ${KERNEL1_ARCHIVE} -C ${BOOTFS_ROOT} ./${KERNEL1_FILENAME_KERNEL}
tar xjfv ${KERNEL1_ARCHIVE} -C ${BOOTFS_ROOT} ./${KERNEL1_FILENAME_CONFIG}
tar xjfv ${KERNEL2_ARCHIVE} -C ${BOOTFS_ROOT} ./${KERNEL2_FILENAME_KERNEL}
tar xjfv ${KERNEL2_ARCHIVE} -C ${BOOTFS_ROOT} ./${KERNEL2_FILENAME_CONFIG}
Copy in the DTB files (which should be the same for both kernels):
tar xjfv ${KERNEL1_ARCHIVE_DTB} -C ${BOOTFS_ROOT}
Next, setup the cmdline.txt file, which can be different depending on your specific installation. In my cause I will be using /dev/sda2 as my root partition which will be formatted in a btfrs filesystem.
echo "console=serial0,115200 console=tty1 root=/dev/sda2 rootfstype=btrfs rootdelay=10 fsck.repair=yes rootwait plymouth.ignore-serial-consoles cfg80211.ieee80211_regdom=JP" > ${BOOTFS_ROOT}/cmdline.txt
The original cmdline.txt file that was on the micro sd card is as follows, taken into account to modify the PARTUUID to match your own micro sd card. The PARTUUID can be found using the blkid command. Also the “cfg80211.ieee80211_regdom” setting will depend on your specific region and sets the bands for the WiFi device to confirm to local regulations.
echo "console=serial0,115200 console=tty1 root=PARTUUID=25370e36-02 rootfstype=ext4 fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles cfg80211.ieee80211_regdom=JP" > ${BOOTFS_ROOT}/cmdline.txt
Finally copy over the config.txt file, the Rapsberry Pi configuration:
cp -a ${WORKDIR}/../config.txt ${BOOTFS_ROOT}/.
Executing the below command should allow us to see the new boot partition layout:
ls ${BOOTFS_ROOT}
Finally archive the new boot partition for later use:
tar -jcvpf ${WORKDIR}/bootfs_${DATESTAMP}.tar.bz2 --directory=${BOOTFS_ROOT} .
This concludes the recreation of the new boot partition but we have a few more archives to create which include the kernel modules and hardware firmware files.
Begin by creating a folder for the kernel modules folder below then extracting the kernel modules into this folder for each of the two kernel configurations, examine what was extracted, then finally create an archive for use later.
sudo rm -rf ${ROOTFS_MODULES}
mkdir -p ${ROOTFS_MODULES}
sudo tar xpjf ${KERNEL1_ARCHIVE_MODULES} -C ${ROOTFS_MODULES}
sudo tar xpjf ${KERNEL2_ARCHIVE_MODULES} -C ${ROOTFS_MODULES}
ls -l ${ROOTFS_MODULES}
tar -jcvpf ${WORKDIR}/rootfs_modules_${DATESTAMP}.tar.bz2 --directory=${ROOTFS_MODULES} .
Next prepare a directory for the firmware files and create the necessary directory structure:
sudo rm -rf ${ROOTFS_FIRMWARE_NONFREE}
mkdir -p ${ROOTFS_FIRMWARE_NONFREE}
mkdir -p ${ROOTFS_FIRMWARE_NONFREE}/brcm
mkdir -p ${ROOTFS_FIRMWARE_NONFREE}/cypress
Copy in the following firmware files from the firmware-nonfree repository:
#raspberry pi 3
cp -a ${WORKDIR}/firmware-nonfree/debian/config/brcm80211/cypress/cyfmac43430-sdio.bin ${ROOTFS_FIRMWARE_NONFREE}/cypress/.
cp -a ${WORKDIR}/firmware-nonfree/debian/config/brcm80211/cypress/cyfmac43430-sdio.clm_blob ${ROOTFS_FIRMWARE_NONFREE}/cypress/.
cp -a ${WORKDIR}/firmware-nonfree/debian/config/brcm80211/brcm/brcmfmac43430-sdio.txt ${ROOTFS_FIRMWARE_NONFREE}/brcm/.
##raspberry pi 3b+ and raspberry pi 4 and raspberry pi 5
cp -a ${WORKDIR}/firmware-nonfree/debian/config/brcm80211/cypress/cyfmac43455-sdio-standard.bin ${ROOTFS_FIRMWARE_NONFREE}/cypress/.
cp -a ${WORKDIR}/firmware-nonfree/debian/config/brcm80211/cypress/cyfmac43455-sdio.clm_blob ${ROOTFS_FIRMWARE_NONFREE}/cypress/.
cp -a ${WORKDIR}/firmware-nonfree/debian/config/brcm80211/brcm/brcmfmac43455-sdio.txt ${ROOTFS_FIRMWARE_NONFREE}/brcm/.
#compute module 4 and raspberry pi 400
cp -a ${WORKDIR}/firmware-nonfree/debian/config/brcm80211/brcm/brcmfmac43456-sdio.bin ${ROOTFS_FIRMWARE_NONFREE}/brcm/.
cp -a ${WORKDIR}/firmware-nonfree/debian/config/brcm80211/brcm/brcmfmac43456-sdio.clm_blob ${ROOTFS_FIRMWARE_NONFREE}/brcm/.
cp -a ${WORKDIR}/firmware-nonfree/debian/config/brcm80211/brcm/brcmfmac43456-sdio.txt ${ROOTFS_FIRMWARE_NONFREE}/brcm/.
#raspberry pi zero 2w
cp -a ${WORKDIR}/firmware-nonfree/debian/config/brcm80211/brcm/brcmfmac43436-sdio.bin ${ROOTFS_FIRMWARE_NONFREE}/brcm/.
cp -a ${WORKDIR}/firmware-nonfree/debian/config/brcm80211/brcm/brcmfmac43436-sdio.clm_blob ${ROOTFS_FIRMWARE_NONFREE}/brcm/.
cp -a ${WORKDIR}/firmware-nonfree/debian/config/brcm80211/brcm/brcmfmac43436-sdio.txt ${ROOTFS_FIRMWARE_NONFREE}/brcm/.
cp -a ${WORKDIR}/firmware-nonfree/debian/config/brcm80211/brcm/brcmfmac43436s-sdio.bin ${ROOTFS_FIRMWARE_NONFREE}/brcm/.
cp -a ${WORKDIR}/firmware-nonfree/debian/config/brcm80211/brcm/brcmfmac43436s-sdio.txt ${ROOTFS_FIRMWARE_NONFREE}/brcm/.
We will need to setup some symbolic links for these as well:
cd ${ROOTFS_FIRMWARE_NONFREE}/brcm
ln -s ../cypress/cyfmac43430-sdio.bin brcmfmac43430-sdio.raspberrypi,3-model-b.bin
ln -s ../cypress/cyfmac43430-sdio.clm_blob brcmfmac43430-sdio.raspberrypi,3-model-b.clm_blob
ln -s brcmfmac43430-sdio.txt brcmfmac43430-sdio.raspberrypi,3-model-b.txt
#raspberry pi 3a+
cd ${ROOTFS_FIRMWARE_NONFREE}/brcm
ln -s ../cypress/cyfmac43455-sdio-standard.bin brcmfmac43455-sdio.raspberrypi,3-model-a-plus.bin
ln -s ../cypress/cyfmac43455-sdio.clm_blob brcmfmac43455-sdio.raspberrypi,3-model-a-plus.clm_blob
ln -s brcmfmac43455-sdio.txt brcmfmac43455-sdio.raspberrypi,3-model-a-plus.txt
#raspberry pi 3b+
cd ${ROOTFS_FIRMWARE_NONFREE}/brcm
ln -s ../cypress/cyfmac43455-sdio-standard.bin brcmfmac43455-sdio.raspberrypi,3-model-b-plus.bin
ln -s ../cypress/cyfmac43455-sdio.clm_blob brcmfmac43455-sdio.raspberrypi,3-model-b-plus.clm_blob
ln -s brcmfmac43455-sdio.txt brcmfmac43455-sdio.raspberrypi,3-model-b-plus.txt
#raspberry pi 4
cd ${ROOTFS_FIRMWARE_NONFREE}/brcm
ln -s ../cypress/cyfmac43455-sdio-standard.bin brcmfmac43455-sdio.raspberrypi,4-model-b.bin
ln -s ../cypress/cyfmac43455-sdio.clm_blob brcmfmac43455-sdio.raspberrypi,4-model-b.clm_blob
ln -s brcmfmac43455-sdio.txt brcmfmac43455-sdio.raspberrypi,4-model-b.txt
#raspberry pi 5
cd ${ROOTFS_FIRMWARE_NONFREE}/brcm
ln -s ../cypress/cyfmac43455-sdio-standard.bin brcmfmac43455-sdio.raspberrypi,5-model-b.bin
ln -s ../cypress/cyfmac43455-sdio.clm_blob brcmfmac43455-sdio.raspberrypi,5-model-b.clm_blob
ln -s brcmfmac43455-sdio.txt brcmfmac43455-sdio.raspberrypi,5-model-b.txt
#compute module 4
cd ${ROOTFS_FIRMWARE_NONFREE}/brcm
ln -s brcmfmac43456-sdio.bin brcmfmac43456-sdio.raspberrypi,4-compute-module.bin
ln -s brcmfmac43456-sdio.clm_blob brcmfmac43456-sdio.raspberrypi,4-compute-module.clm_blob
ln -s brcmfmac43456-sdio.txt brcmfmac43456-sdio.raspberrypi,4-compute-module.txt
#raspberry pi 400
cd ${ROOTFS_FIRMWARE_NONFREE}/brcm
ln -s brcmfmac43456-sdio.bin brcmfmac43456-sdio.raspberrypi,400.bin
ln -s brcmfmac43456-sdio.clm_blob brcmfmac43456-sdio.raspberrypi,400.clm_blob
ln -s brcmfmac43456-sdio.txt brcmfmac43456-sdio.raspberrypi,400.txt
#raspberry pi zero 2w
cd ${ROOTFS_FIRMWARE_NONFREE}/brcm
ln -s brcmfmac43436s-sdio.bin brcmfmac43430-sdio.raspberrypi,model-zero-2-w.bin
ln -s brcmfmac43436s-sdio.txt brcmfmac43430-sdio.raspberrypi,model-zero-2-w.txt
ln -s brcmfmac43436-sdio.bin brcmfmac43430b0-sdio.raspberrypi,model-zero-2-w.bin
ln -s brcmfmac43436-sdio.clm_blob brcmfmac43430b0-sdio.raspberrypi,model-zero-2-w.clm_blob
ln -s brcmfmac43436-sdio.txt brcmfmac43430b0-sdio.raspberrypi,model-zero-2-w.txt
ln -s brcmfmac43436-sdio.bin brcmfmac43436-sdio.raspberrypi,model-zero-2-w.bin
ln -s brcmfmac43436-sdio.clm_blob brcmfmac43436-sdio.raspberrypi,model-zero-2-w.clm_blob
ln -s brcmfmac43436-sdio.txt brcmfmac43436-sdio.raspberrypi,model-zero-2-w.txt
ln -s brcmfmac43436s-sdio.bin brcmfmac43436s-sdio.raspberrypi,model-zero-2-w.bin
ln -s brcmfmac43436s-sdio.txt brcmfmac43436s-sdio.raspberrypi,model-zero-2-w.txt
cd ${WORKDIR}
Setup the correct user/group ownership then examine and archive the directory for later use:
sudo chown -R root:root ${ROOTFS_FIRMWARE_NONFREE}/*
ls -l ${ROOTFS_FIRMWARE_NONFREE}/brcm
ls -l ${ROOTFS_FIRMWARE_NONFREE}/cypress
tar -jcvpf ${WORKDIR}/rootfs_firmware-nonfree_${DATESTAMP}.tar.bz2 --directory=${ROOTFS_FIRMWARE_NONFREE} .
The final archive to create is the Bluetooth firmware archive. Prepare a directory below and create the necessary directory structure:
sudo rm -rf ${ROOTFS_FIRMWARE_BLUEZ}
mkdir -p ${ROOTFS_FIRMWARE_BLUEZ}
mkdir -p ${ROOTFS_FIRMWARE_BLUEZ}/brcm
mkdir -p ${ROOTFS_FIRMWARE_BLUEZ}/synaptics
Copy in the following firmware files from the firmware-bluez repository:
#raspberry pi 3
cp -a ${WORKDIR}/bluez-firmware/debian/firmware/broadcom/BCM43430A1.hcd ${ROOTFS_FIRMWARE_BLUEZ}/brcm/.
#raspberry pi 3+ and raspberry pi 4 and raspberry pi 5
cp -a ${WORKDIR}/bluez-firmware/debian/firmware/broadcom/BCM4345C0.hcd ${ROOTFS_FIRMWARE_BLUEZ}/brcm/.
#compute module 4 and raspberry pi 400
cp -a ${WORKDIR}/bluez-firmware/debian/firmware/broadcom/BCM4345C5.hcd ${ROOTFS_FIRMWARE_BLUEZ}/brcm/.
#raspberry pi zero w2
cp -a ${WORKDIR}/bluez-firmware/debian/firmware/synaptics/LICENSE.synaptics ${ROOTFS_FIRMWARE_BLUEZ}/synaptics/.
cp -a ${WORKDIR}/bluez-firmware/debian/firmware/synaptics/SYN43430A1.hcd ${ROOTFS_FIRMWARE_BLUEZ}/synaptics/.
cp -a ${WORKDIR}/bluez-firmware/debian/firmware/synaptics/SYN43430B0.hcd ${ROOTFS_FIRMWARE_BLUEZ}/synaptics/.
Setup the correct user/group ownership then examine and archive the directory for later use:
sudo chown -R root:root ${ROOTFS_FIRMWARE_BLUEZ}/*
ls -l ${ROOTFS_FIRMWARE_BLUEZ}/brcm
ls -l ${ROOTFS_FIRMWARE_BLUEZ}/synaptics
tar -jcvpf ${WORKDIR}/rootfs_firmware-bluez_${DATESTAMP}.tar.bz2 --directory=${ROOTFS_FIRMWARE_BLUEZ} .
Finally examine the files that were created:
ls -l ${WORKDIR}
This concludes creating archives that will be used for the Linux Gentoo installation.
All the files created above are available for download here: