flash: Clean up/add support for RPi 3
Although the official Fedora CoreOS documentation only provides instructions for running CoreOS on a Raspberry Pi 4, it does actually work on older boards as well. `coreos-installer` creates a GPT disk label, which the older devices do not support, but this can be worked around using a hybrid MBR label. Unfortunately, after I put all the effort into refactoring this script and adding support for the older devices, I realized that it was rather pointless as those boards simply do not have enough memory to be useful Kubernetes nodes. I was hoping to move the Zigbee and ZWave controllers to a Raspberry Pi 3, but these processes take way too much memory for that.
parent
364f4fed50
commit
40bde4df26
|
@ -1,3 +1,4 @@
|
||||||
*.ign
|
*.ign
|
||||||
frigate.env
|
frigate.env
|
||||||
*.token
|
*.token
|
||||||
|
RPi4boot
|
||||||
|
|
35
flash.sh
35
flash.sh
|
@ -1,35 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
# vim: set sw=4 ts=4 sts=4 et :
|
|
||||||
|
|
||||||
set -eu
|
|
||||||
|
|
||||||
ignition=${1}
|
|
||||||
dev=${2:-/dev/disk/by-id/usb-Generic_STORAGE_DEVICE_000000001206-0:0}
|
|
||||||
|
|
||||||
if [ -z "${ignition}" ]; then
|
|
||||||
printf 'usage: %s ignition\n' "${0##*/}" >&2
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $(id -u) -ne 0 ]; then
|
|
||||||
sudo=sudo
|
|
||||||
fi
|
|
||||||
|
|
||||||
${sudo} coreos-installer install \
|
|
||||||
-a aarch64 \
|
|
||||||
-s stable \
|
|
||||||
-i "${ignition}" \
|
|
||||||
--console ttyS0,115200n8 \
|
|
||||||
"${dev}"
|
|
||||||
sync; sync; sync
|
|
||||||
|
|
||||||
until [ -n "${efi_part}" ]; do
|
|
||||||
efi_part=$(
|
|
||||||
lsblk -o LABEL,PATH \
|
|
||||||
| awk '$1=="EFI-SYSTEM"{print $2}'
|
|
||||||
)
|
|
||||||
done
|
|
||||||
pmount "${efi_part}" coreos-efi
|
|
||||||
rsync -ah --ignore-existing RPi4boot/boot/efi/ /media/coreos-efi/
|
|
||||||
sync; sync; sync
|
|
||||||
pumount coreos-efi
|
|
|
@ -0,0 +1,139 @@
|
||||||
|
#!/bin/zsh
|
||||||
|
# vim: set ft=sh sw=4 ts=4 sts=4 et :
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
function copy_firmware() {
|
||||||
|
local dev="$1"
|
||||||
|
local efi_part
|
||||||
|
local mountpoint=/run/media/coreos-efi
|
||||||
|
|
||||||
|
if [ ! -d RPi4boot ]; then
|
||||||
|
download_firmware
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf 'Waiting for device to settle ...' >&2
|
||||||
|
until [ -n "${efi_part-}" ]; do
|
||||||
|
printf '.'
|
||||||
|
efi_part=$(
|
||||||
|
lsblk -o LABEL,PATH "${dev}" \
|
||||||
|
| awk '$1=="EFI-SYSTEM"{print $2}'
|
||||||
|
)
|
||||||
|
sleep 0.25
|
||||||
|
done
|
||||||
|
printf '\n'
|
||||||
|
|
||||||
|
mkdir -p "${mountpoint}"
|
||||||
|
mount "${efi_part}" "${mountpoint}"
|
||||||
|
rsync -rtiOh --ignore-existing RPi4boot/boot/efi/ "${mountpoint}"
|
||||||
|
sync; sync; sync
|
||||||
|
umount "${mountpoint}"
|
||||||
|
rmdir "${mountpoint}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function download_firmware() {
|
||||||
|
local rpm
|
||||||
|
|
||||||
|
echo 'Downloading Raspberry Pi Firmware blobs ...'
|
||||||
|
mkdir RPi4boot
|
||||||
|
podman run --rm -it \
|
||||||
|
-v $(PWD)/RPi4boot:/RPi4boot:rw,z \
|
||||||
|
registry.fedoraproject.org/fedora:38 \
|
||||||
|
dnf install -y \
|
||||||
|
--downloadonly \
|
||||||
|
--forcearch=aarch64 \
|
||||||
|
--destdir=/RPi4boot \
|
||||||
|
uboot-images-armv8 \
|
||||||
|
bcm283x-firmware \
|
||||||
|
bcm283x-overlays
|
||||||
|
--
|
||||||
|
for rpm in RPi4boot/*.rpm; do
|
||||||
|
rpm2cpio "${rpm}" | cpio -idv -D RPi4boot/
|
||||||
|
done
|
||||||
|
|
||||||
|
cp RPi4boot/usr/share/uboot/rpi_3/u-boot.bin RPi4boot/boot/efi/rpi3-u-boot.bin
|
||||||
|
cp RPi4boot/usr/share/uboot/rpi_4/u-boot.bin RPi4boot/boot/efi/rpi4-u-boot.bin
|
||||||
|
cp RPi4boot/usr/share/uboot/rpi_arm64/u-boot.bin RPi4boot/boot/efi/rpi-u-boot.bin
|
||||||
|
}
|
||||||
|
|
||||||
|
function hybridize_gpt() {
|
||||||
|
local dev="$1"
|
||||||
|
|
||||||
|
echo 'Creating Hybrid MBR partition table ...'
|
||||||
|
sgdisk -h 2:EE "${dev}"
|
||||||
|
echo type=0c,bootable | sfdisk -Y mbr -N 1 "${dev}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function install_coreos() {
|
||||||
|
local ignition="$1"
|
||||||
|
local dev="$2"
|
||||||
|
|
||||||
|
coreos-installer install \
|
||||||
|
-a aarch64 \
|
||||||
|
-s stable \
|
||||||
|
-i "${ignition}" \
|
||||||
|
--console ttyS0,115200n8 \
|
||||||
|
"${dev}"
|
||||||
|
sync; sync; sync
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse_args() {
|
||||||
|
pi=4
|
||||||
|
while [ $# -gt 0 ]; do
|
||||||
|
case "$1" in
|
||||||
|
--pi)
|
||||||
|
shift
|
||||||
|
pi=${1}
|
||||||
|
;;
|
||||||
|
--pi=*)
|
||||||
|
pi=${1#--pi=}
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
if [ -z "${ignition-}" ]; then
|
||||||
|
ignition="${1}"
|
||||||
|
elif [ -z "${dev-}" ]; then
|
||||||
|
dev="${1}"
|
||||||
|
else
|
||||||
|
usage >&2
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z "${ignition-}" ]; then
|
||||||
|
usage >&2
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
if [ -z "${dev-}" ]; then
|
||||||
|
dev=/dev/disk/by-id/usb-Generic_STORAGE_DEVICE_000000001206-0:0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function usage() {
|
||||||
|
printf 'usage: %s [--pi PI] ignition [device]\n' "${0##*/}"
|
||||||
|
}
|
||||||
|
|
||||||
|
parse_args "$@"
|
||||||
|
|
||||||
|
case "${pi}" in
|
||||||
|
0*|1)
|
||||||
|
printf 'Raspberry Pi model %s is not supported\n' "${pi}" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ $(id -u) -ne 0 ]; then
|
||||||
|
exec sudo "$0" "$@"
|
||||||
|
fi
|
||||||
|
|
||||||
|
install_coreos "${ignition}" "${dev}"
|
||||||
|
|
||||||
|
case "${pi}" in
|
||||||
|
2|3)
|
||||||
|
hybridize_gpt "${dev}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
copy_firmware "${dev}"
|
Loading…
Reference in New Issue