git.iko.soy/typeable/nixpkgs
on master help sign in
raspberrypi-bootloader: allow specification of target directory
commitbcb9e17bba8857fa5cd63c74ead67e6029e50437 authorBen Wolsieffer <benwolsieffer@gmail.com> dateTue 4 Sep 2018, 16:52 (8 years ago) parent73f796a
3 files changed+53−42
nixos/modules/system/boot/loader/raspberrypi/raspberrypi-builder.nix+10 nixos/modules/system/boot/loader/raspberrypi/builder.sh → nixos/modules/system/boot/loader/raspberrypi/raspberrypi-builder.sh+40−30 nixos/modules/system/boot/loader/raspberrypi/raspberrypi.nix+3−12
nixos/modules/system/boot/loader/raspberrypi/raspberrypi-builder.nixnew file+10
@@ -0,0 +1,10 @@
1+{ pkgs, version, configTxt }:
2+
3+pkgs.substituteAll {
4+ src = ./raspberrypi-builder.sh;
5+ isExecutable = true;
6+ inherit (pkgs) bash;
7+ path = [pkgs.coreutils pkgs.gnused pkgs.gnugrep];
8+ firmware = pkgs.raspberrypifw;
9+ inherit version configTxt;
10+}
nixos/modules/system/boot/loader/raspberrypi/builder.sh → nixos/modules/system/boot/loader/raspberrypi/raspberrypi-builder.shrenamed+40−30
@@ -5,15 +5,25 @@ shopt -s nullglob
55export PATH=/empty
66for i in @path@; do PATH=$PATH:$i/bin; done
77
8−default=$1
9−if test -z "$1"; then
10− echo "Syntax: builder.sh <DEFAULT-CONFIG>"
8+usage() {
9+ echo "usage: $0 -c <path-to-default-configuration> [-d <boot-dir>]" >&2
1110 exit 1
12−fi
11+}
12+
13+default= # Default configuration
14+target=/boot # Target directory
15+
16+while getopts "c:d:" opt; do
17+ case "$opt" in
18+ c) default="$OPTARG" ;;
19+ d) target="$OPTARG" ;;
20+ \?) usage ;;
21+ esac
22+done
1323
1424echo "updating the boot generations directory..."
1525
16−mkdir -p /boot/old
26+mkdir -p $target/old
1727
1828# Convert a path to a file in the Nix store such as
1929# /nix/store/<hash>-<name>/file to <hash>-<name>-<file>.
@@ -22,12 +32,12 @@ cleanName() {
2232 echo "$path" | sed 's|^/nix/store/||' | sed 's|/|-|g'
2333}
2434
25−# Copy a file from the Nix store to /boot/kernels.
35+# Copy a file from the Nix store to $target/kernels.
2636declare -A filesCopied
2737
2838copyToKernelsDir() {
2939 local src="$1"
30− local dst="/boot/old/$(cleanName $src)"
40+ local dst="$target/old/$(cleanName $src)"
3141 # Don't copy the file if $dst already exists. This means that we
3242 # have to create $dst atomically to prevent partially copied
3343 # kernels or initrd if this script is ever interrupted.
@@ -47,10 +57,10 @@ copyForced() {
4757 mv $dst.tmp $dst
4858}
4959
50−outdir=/boot/old
60+outdir=$target/old
5161mkdir -p $outdir || true
5262
53−# Copy its kernel and initrd to /boot/kernels.
63+# Copy its kernel and initrd to $target/old.
5464addEntry() {
5565 local path="$1"
5666 local generation="$2"
@@ -74,25 +84,25 @@ addEntry() {
7484 echo $initrd > $outdir/$generation-initrd
7585 echo $kernel > $outdir/$generation-kernel
7686
77− if test $(readlink -f "$path") = "$default"; then
87+ if test "$generation" = "default"; then
7888 if [ @version@ -eq 1 ]; then
79− copyForced $kernel /boot/kernel.img
89+ copyForced $kernel $target/kernel.img
8090 else
81− copyForced $kernel /boot/kernel7.img
91+ copyForced $kernel $target/kernel7.img
8292 fi
83− copyForced $initrd /boot/initrd
93+ copyForced $initrd $target/initrd
8494 for dtb in $dtb_path/bcm*.dtb; do
85− dst="/boot/$(basename $dtb)"
95+ dst="$target/$(basename $dtb)"
8696 copyForced $dtb "$dst"
8797 filesCopied[$dst]=1
8898 done
89− cp "$(readlink -f "$path/init")" /boot/nixos-init
90− echo "`cat $path/kernel-params` init=$path/init" >/boot/cmdline.txt
91−
92− echo "$2" > /boot/defaultgeneration
99+ cp "$(readlink -f "$path/init")" $target/nixos-init
100+ echo "`cat $path/kernel-params` init=$path/init" >$target/cmdline.txt
93101 fi
94102}
95103
104+addEntry $default default
105+
96106# Add all generations of the system profile to the menu, in reverse
97107# (most recent to least recent) order.
98108for generation in $(
@@ -105,21 +115,21 @@ done
105115
106116# Add the firmware files
107117fwdir=@firmware@/share/raspberrypi/boot/
108−copyForced $fwdir/bootcode.bin /boot/bootcode.bin
109−copyForced $fwdir/fixup.dat /boot/fixup.dat
110−copyForced $fwdir/fixup_cd.dat /boot/fixup_cd.dat
111−copyForced $fwdir/fixup_db.dat /boot/fixup_db.dat
112−copyForced $fwdir/fixup_x.dat /boot/fixup_x.dat
113−copyForced $fwdir/start.elf /boot/start.elf
114−copyForced $fwdir/start_cd.elf /boot/start_cd.elf
115−copyForced $fwdir/start_db.elf /boot/start_db.elf
116−copyForced $fwdir/start_x.elf /boot/start_x.elf
118+copyForced $fwdir/bootcode.bin $target/bootcode.bin
119+copyForced $fwdir/fixup.dat $target/fixup.dat
120+copyForced $fwdir/fixup_cd.dat $target/fixup_cd.dat
121+copyForced $fwdir/fixup_db.dat $target/fixup_db.dat
122+copyForced $fwdir/fixup_x.dat $target/fixup_x.dat
123+copyForced $fwdir/start.elf $target/start.elf
124+copyForced $fwdir/start_cd.elf $target/start_cd.elf
125+copyForced $fwdir/start_db.elf $target/start_db.elf
126+copyForced $fwdir/start_x.elf $target/start_x.elf
117127
118128# Add the config.txt
119−copyForced @configTxt@ /boot/config.txt
129+copyForced @configTxt@ $target/config.txt
120130
121−# Remove obsolete files from /boot and /boot/old.
122−for fn in /boot/old/*linux* /boot/old/*initrd-initrd* /boot/bcm*.dtb; do
131+# Remove obsolete files from $target and $target/old.
132+for fn in $target/old/*linux* $target/old/*initrd-initrd* $target/bcm*.dtb; do
123133 if ! test "${filesCopied[$fn]}" = 1; then
124134 rm -vf -- "$fn"
125135 fi
nixos/modules/system/boot/loader/raspberrypi/raspberrypi.nix+3−12
@@ -5,25 +5,16 @@ with lib;
55let
66 cfg = config.boot.loader.raspberryPi;
77
8− builderGeneric = pkgs.substituteAll {
9− src = ./builder.sh;
10− isExecutable = true;
11− inherit (pkgs) bash;
12− path = [pkgs.coreutils pkgs.gnused pkgs.gnugrep];
13− firmware = pkgs.raspberrypifw;
14− version = cfg.version;
15− inherit configTxt;
16− };
17−
188 inherit (pkgs.stdenv.hostPlatform) platform;
199
20− builderUboot = import ./builder_uboot.nix { inherit config; inherit pkgs; inherit configTxt; };
10+ builderUboot = import ./builder_uboot.nix { inherit config pkgs configTxt; };
11+ builderGeneric = import ./raspberrypi-builder.nix { inherit pkgs configTxt; inherit (cfg) version; };
2112
2213 builder =
2314 if cfg.uboot.enable then
2415 "${builderUboot} -g ${toString cfg.uboot.configurationLimit} -t ${timeoutStr} -c"
2516 else
26− builderGeneric;
17+ "${builderGeneric} -c";
2718
2819 blCfg = config.boot.loader;
2920 timeoutStr = if blCfg.timeout == null then "-1" else toString blCfg.timeout;