Skip to content

Instantly share code, notes, and snippets.

@Fiwi1265
Created September 10, 2025 17:24
Show Gist options
  • Select an option

  • Save Fiwi1265/af3cace80d80bfe8dc3bd90d6ef8ff5a to your computer and use it in GitHub Desktop.

Select an option

Save Fiwi1265/af3cace80d80bfe8dc3bd90d6ef8ff5a to your computer and use it in GitHub Desktop.
u-boot-rpi4-scripts
#!/bin/bash
set -euo pipefail
if [ "$(id -u)" -ne 0 ]; then
echo "Error: This script must be run as root." >&2
exit 1
fi
generate_fit() {
local version="$1"
local its="/tmp/boot-${version}.its"
local itb="/boot/boot-${version}.itb"
cat > "$its" <<EOF
/dts-v1/;
/ {
description = "Debian ${version}";
#address-cells = <1>;
images {
kernel {
data = /incbin/("/boot/vmlinuz-${version}");
type = "kernel";
arch = "arm64";
os = "linux";
compression = "none";
load = <0x80000>;
entry = <0x80000>;
};
ramdisk {
data = /incbin/("/boot/initrd.img-${version}");
type = "ramdisk";
arch = "arm64";
os = "linux";
};
fdt {
data = /incbin/("/boot/firmware/bcm2711-rpi-4-b.dtb");
type = "flat_dt";
arch = "arm64";
compression = "none";
};
};
configurations {
default = "conf";
conf {
kernel = "kernel";
ramdisk = "ramdisk";
fdt = "fdt";
};
};
};
EOF
mkimage -f "$its" "$itb"
rm "$its"
}
if [ $# -ge 1 ]; then
generate_fit "$1"
else
for kernel in /boot/vmlinuz-*; do
version="$(basename "$kernel" | sed 's/^vmlinuz-//')"
generate_fit "$version"
done
fi
#!/bin/bash
set -euo pipefail
if [ "$(id -u)" -ne 0 ]; then
echo "Error: This script must be run as root." >&2
exit 1
fi
cat > "/tmp/u-boot.env.tmp" <<EOF
bootmenu_delay=5
EOF
i=0
for itb in $(ls /boot/*.itb | sort -Vr); do
[ -e "$itb" ] || continue
file="$(basename "$itb")"
version="${file#boot-}"
version="${version%.itb}"
echo "bootmenu_${i}=Debian ${version}=load mmc 0:2 0x10000000 ${file}; bootm 0x10000000" >> "/tmp/u-boot.env.tmp"
i=$((i + 1))
done
mkenvimage -s 0x4000 -o "/boot/firmware/u-boot.env" "/tmp/u-boot.env.tmp"
rm -f "/tmp/u-boot.env.tmp"
#!/bin/bash
set -euo pipefail
if [ "$(id -u)" -ne 0 ]; then
echo "Error: This script must be run as root." >&2
exit 1
fi
/usr/local/bin/u-boot-fit
/usr/local/bin/u-boot-menu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment