bruh
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
#! @bash@/bin/sh -e
|
||||
|
||||
# shellcheck disable=SC3030,SC3043,SC3044,SC3054
|
||||
|
||||
shopt -s nullglob
|
||||
|
||||
export PATH=/empty:@path@
|
||||
|
||||
usage() {
|
||||
echo "usage: $0 -c <path-to-configuration> [-d <destination-dir>] [-r]" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
generationPath= # Path to nixos configuration/generation
|
||||
target=/boot/firmware # Device tree files target directory
|
||||
|
||||
while getopts "c:d:r" opt; do
|
||||
case "$opt" in
|
||||
c) generationPath="$OPTARG" ;;
|
||||
d) target="$OPTARG" ;;
|
||||
r) useVendorDeviceTree=1 ;;
|
||||
\?) usage ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Copy a file from the Nix store to $target.
|
||||
declare -A filesCopied
|
||||
|
||||
copyForced() {
|
||||
local src="$1"
|
||||
local dst="$2"
|
||||
|
||||
local dstTmp="$dst.tmp.$$"
|
||||
|
||||
cp "$src" "$dstTmp"
|
||||
mv "$dstTmp" "$dst"
|
||||
}
|
||||
|
||||
echo "$0: $@"
|
||||
echo -n "installing device tree files: "
|
||||
|
||||
# Device Tree
|
||||
|
||||
if [ -n "$useVendorDeviceTree" ]; then
|
||||
echo -n "vendor firmware "
|
||||
dtb_path=@firmware@/share/raspberrypi/boot
|
||||
else
|
||||
echo -n "generation's kernel's "
|
||||
dtb_path=$(readlink -f "$generationPath/dtbs")
|
||||
fi
|
||||
echo "$dtb_path"
|
||||
|
||||
# firmware package has dtbs in its root,
|
||||
# dtbs built with kernel are in broadcom/
|
||||
DTBS=("$dtb_path"/*.dtb "$dtb_path"/broadcom/*.dtb)
|
||||
for dtb in "${DTBS[@]}"; do
|
||||
dst="$target/$(basename "$dtb")"
|
||||
copyForced "$dtb" "$dst"
|
||||
filesCopied[$dst]=1
|
||||
done
|
||||
|
||||
SRC_OVERLAYS=("$dtb_path/overlays"/*)
|
||||
mkdir -p "$target/overlays"
|
||||
for ovr in "${SRC_OVERLAYS[@]}"; do
|
||||
dst="$target/overlays/$(basename "$ovr")"
|
||||
copyForced "$ovr" "$dst"
|
||||
filesCopied[$dst]=1
|
||||
done
|
||||
|
||||
# remove obsolete device tree files
|
||||
for fn in $target/*.dtb $target/overlays/*; do
|
||||
if ! test "${filesCopied[$fn]}" = 1; then
|
||||
rm -vf -- "$fn"
|
||||
fi
|
||||
done
|
||||
@@ -0,0 +1,66 @@
|
||||
#! @bash@/bin/sh -e
|
||||
|
||||
# shellcheck disable=SC3030,SC3043,SC3044,SC3054
|
||||
|
||||
shopt -s nullglob
|
||||
|
||||
export PATH=/empty:@path@
|
||||
|
||||
usage() {
|
||||
echo "usage: $0 -c <path-to-configuration> [-d <firmware-dir>]" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
generationPath= # Path to nixos configuration/generation
|
||||
target=/boot/firmware # Firmware target directory
|
||||
|
||||
while getopts "c:d:" opt; do
|
||||
case "$opt" in
|
||||
c) generationPath="$OPTARG" ;;
|
||||
d) target="$OPTARG" ;;
|
||||
\?) usage ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Copy a file from the Nix store to $target.
|
||||
declare -A filesCopied
|
||||
|
||||
copyForced() {
|
||||
local src="$1"
|
||||
local dst="$2"
|
||||
|
||||
local dstTmp="$dst.tmp.$$"
|
||||
|
||||
cp "$src" "$dstTmp"
|
||||
mv "$dstTmp" "$dst"
|
||||
}
|
||||
|
||||
# Add the firmware files
|
||||
# fwdir=@firmware@/share/raspberrypi/boot/
|
||||
SRC_FIRMWARE_DIR=@firmware@/share/raspberrypi/boot
|
||||
|
||||
echo "copying raspberry pi firmware..."
|
||||
|
||||
# Boot code
|
||||
|
||||
STARTFILES=("$SRC_FIRMWARE_DIR"/start*.elf)
|
||||
BOOTCODE="$SRC_FIRMWARE_DIR/bootcode.bin"
|
||||
FIXUPS=("$SRC_FIRMWARE_DIR"/fixup*.dat)
|
||||
for SRC in "${STARTFILES[@]}" "$BOOTCODE" "${FIXUPS[@]}"; do
|
||||
dst="$target/$(basename "$SRC")"
|
||||
copyForced "$SRC" "$dst"
|
||||
filesCopied[$dst]=1
|
||||
done
|
||||
|
||||
# remove obsolete firmware files
|
||||
for fn in $target/start*.elf $target/fixup*.dat; do
|
||||
if ! test "${filesCopied[$fn]}" = 1; then
|
||||
rm -vf -- "$fn"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "copying config.txt..."
|
||||
# Add the config.txt
|
||||
copyForced @configTxt@ "$target/config.txt"
|
||||
|
||||
echo "raspberry pi firmware installed"
|
||||
@@ -0,0 +1,146 @@
|
||||
#! @bash@/bin/sh -e
|
||||
|
||||
# shellcheck disable=SC3043,SC3044,SC3054
|
||||
|
||||
shopt -s nullglob
|
||||
|
||||
export PATH=/empty:@path@
|
||||
|
||||
# used to track copied generations to decide which are obsolete
|
||||
# and need to be removed
|
||||
declare -A activeGenerations
|
||||
|
||||
moveWBackup() {
|
||||
local src="$1"
|
||||
local dst="$2"
|
||||
|
||||
# Backup $dst if already exists
|
||||
local dstBkp="$dst.bkp.$$"
|
||||
if [ -e "$dst" ]; then
|
||||
mv "$dst" "$dstBkp"
|
||||
fi
|
||||
|
||||
# Move $src as "new" $dst
|
||||
mv "$src" "$dst"
|
||||
|
||||
# Remove backup directory of the previous $dst
|
||||
rm -rf "$dstBkp"
|
||||
}
|
||||
|
||||
# Copy generation's kernel, initrd, cmdline to `gensDir/generationName`.
|
||||
addEntry() {
|
||||
local generationPath="$1"
|
||||
local generationName="$2"
|
||||
local gensDir="$3"
|
||||
|
||||
local dst="$gensDir/$generationName"
|
||||
|
||||
echo "* nixos generation '$generationName' -> $dst"
|
||||
# Don't copy the files if $dst already exists, unless it's the default
|
||||
# configuration.
|
||||
# This means that we have to create $dst atomically to prevent partially
|
||||
# copied generations if this script is ever interrupted.
|
||||
#
|
||||
# For "default" generation: make backup and then replace with the new
|
||||
# "default", minimizing the time when where isn't any "default" generation
|
||||
# directory
|
||||
if ! [ -e $dst ] || [ "$generationName" = "default" ]; then
|
||||
local dstTmp="$dst.tmp.$$"
|
||||
mkdir -p "$dstTmp" || true
|
||||
|
||||
@nixosGenBuilder@ -c "$generationPath" -n "$generationName" -d "$dstTmp"
|
||||
|
||||
# Move new generation on its place, backing up the previous version
|
||||
# if it exists
|
||||
# This may only happen when "$generationName" = "default"
|
||||
moveWBackup "$dstTmp" "$dst"
|
||||
fi
|
||||
|
||||
activeGenerations["$generationName"]=1
|
||||
}
|
||||
|
||||
removeObsoleteGenerations() {
|
||||
local path="$1"
|
||||
|
||||
echo "removing obsolete generations in $path..."
|
||||
for gen in $path/*; do
|
||||
if ! [ "${activeGenerations["$(basename "$gen")"]}" = 1 ]; then
|
||||
echo "* $gen is obsolete"
|
||||
rm -vrf "$gen"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
addAllEntries() {
|
||||
local defaultGenerationPath="$1"
|
||||
local outdir="$2"
|
||||
local numGenerations="$3"
|
||||
|
||||
local gensDir="$outdir/@nixosGenerationsDir@"
|
||||
mkdir -p "$gensDir" || true
|
||||
|
||||
# Add default generation
|
||||
addEntry "$defaultGenerationPath" default "$gensDir"
|
||||
|
||||
if [ "$numGenerations" -gt 0 ]; then
|
||||
# Add up to $numGenerations generations of the system profile, in reverse
|
||||
# (most recent to least recent) order.
|
||||
for generation in $(
|
||||
(cd /nix/var/nix/profiles && ls -d system-*-link) \
|
||||
| sed 's/system-\([0-9]\+\)-link/\1/' \
|
||||
| sort -n -r \
|
||||
| head -n "$numGenerations"); do
|
||||
link=/nix/var/nix/profiles/system-$generation-link
|
||||
addEntry "$link" "${generation}-default" "$gensDir"
|
||||
for specialisation in $(
|
||||
ls /nix/var/nix/profiles/system-$generation-link/specialisation \
|
||||
| sort -n -r); do
|
||||
link=/nix/var/nix/profiles/system-$generation-link/specialisation/$specialisation
|
||||
addEntry "$link" "${generation}-${specialisation}" "$gensDir"
|
||||
done
|
||||
done
|
||||
fi
|
||||
|
||||
removeObsoleteGenerations "$gensDir"
|
||||
}
|
||||
|
||||
usage() {
|
||||
echo "usage: $0 -c <path-to-default-configuration> [-b <boot-dir>] [-g <num-generations>]" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
default= # Default configuration
|
||||
numGenerations=0 # Number of other generations to keep (kernel, initrd, DTBs, overlays)
|
||||
|
||||
echo "$0: $@"
|
||||
while getopts "c:b:g:f:" opt; do
|
||||
case "$opt" in
|
||||
c) default="$OPTARG" ;;
|
||||
b) boottarget="$OPTARG" ;;
|
||||
g) numGenerations="$OPTARG" ;;
|
||||
f) fwtarget="$OPTARG" ;;
|
||||
\?) usage ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "$boottarget" ] && [ -z "$fwtarget" ]; then
|
||||
echo "Error: at least one of \`-b <boot-dir>\` and \`-f <firmware-dir>\` must be set"
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ -n "$fwtarget" ]; then
|
||||
echo "installing nixos-generation-independent firmware..."
|
||||
@installFirmwareBuilder@ -c "$default" -d "$fwtarget"
|
||||
|
||||
echo "installing nixos generations..."
|
||||
addAllEntries "$default" "$fwtarget" "$numGenerations"
|
||||
fi
|
||||
|
||||
if [ -n "$boottarget" ]; then
|
||||
echo "'-b $boottarget' isn't used when loading the kernel directly with \`kernel\`: "\
|
||||
"kernels are copied directly to <firmware-dir>"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "generational bootloader installed"
|
||||
Reference in New Issue
Block a user