From 1afff7c10bdacbdd2d5c2d7010ee96987fdffb0e Mon Sep 17 00:00:00 2001 From: Ben Wolsieffer Date: Mon, 10 Sep 2018 23:21:41 -0400 Subject: raspberrypi-bootloader: support Raspberry Pi 3 w/o U-Boot and explicitly support Raspberry Pi Zero --- .../boot/loader/raspberrypi/builder_uboot.nix | 34 --------------------- .../boot/loader/raspberrypi/builder_uboot.sh | 29 ------------------ .../loader/raspberrypi/raspberrypi-builder.nix | 4 +-- .../boot/loader/raspberrypi/raspberrypi-builder.sh | 8 ++--- .../system/boot/loader/raspberrypi/raspberrypi.nix | 12 ++++---- .../boot/loader/raspberrypi/uboot-builder.nix | 35 ++++++++++++++++++++++ .../boot/loader/raspberrypi/uboot-builder.sh | 29 ++++++++++++++++++ 7 files changed, 75 insertions(+), 76 deletions(-) delete mode 100644 nixos/modules/system/boot/loader/raspberrypi/builder_uboot.nix delete mode 100644 nixos/modules/system/boot/loader/raspberrypi/builder_uboot.sh create mode 100644 nixos/modules/system/boot/loader/raspberrypi/uboot-builder.nix create mode 100644 nixos/modules/system/boot/loader/raspberrypi/uboot-builder.sh (limited to 'nixos/modules/system') diff --git a/nixos/modules/system/boot/loader/raspberrypi/builder_uboot.nix b/nixos/modules/system/boot/loader/raspberrypi/builder_uboot.nix deleted file mode 100644 index 47f25a9c2b1..00000000000 --- a/nixos/modules/system/boot/loader/raspberrypi/builder_uboot.nix +++ /dev/null @@ -1,34 +0,0 @@ -{ config, pkgs, configTxt }: - -let - cfg = config.boot.loader.raspberryPi; - isAarch64 = pkgs.stdenv.isAarch64; - - uboot = - if cfg.version == 1 then - pkgs.ubootRaspberryPi - else if cfg.version == 2 then - pkgs.ubootRaspberryPi2 - else - if isAarch64 then - pkgs.ubootRaspberryPi3_64bit - else - pkgs.ubootRaspberryPi3_32bit; - - extlinuxConfBuilder = - import ../generic-extlinux-compatible/extlinux-conf-builder.nix { - inherit pkgs; - }; -in -pkgs.substituteAll { - src = ./builder_uboot.sh; - isExecutable = true; - inherit (pkgs) bash; - path = [pkgs.coreutils pkgs.gnused pkgs.gnugrep]; - firmware = pkgs.raspberrypifw; - inherit uboot; - inherit configTxt; - inherit extlinuxConfBuilder; - version = cfg.version; -} - diff --git a/nixos/modules/system/boot/loader/raspberrypi/builder_uboot.sh b/nixos/modules/system/boot/loader/raspberrypi/builder_uboot.sh deleted file mode 100644 index 36bf1506627..00000000000 --- a/nixos/modules/system/boot/loader/raspberrypi/builder_uboot.sh +++ /dev/null @@ -1,29 +0,0 @@ -#! @bash@/bin/sh -e - -copyForced() { - local src="$1" - local dst="$2" - cp $src $dst.tmp - mv $dst.tmp $dst -} - -# Call the extlinux builder -"@extlinuxConfBuilder@" "$@" - -# Add the firmware files -fwdir=@firmware@/share/raspberrypi/boot/ -copyForced $fwdir/bootcode.bin /boot/bootcode.bin -copyForced $fwdir/fixup.dat /boot/fixup.dat -copyForced $fwdir/fixup_cd.dat /boot/fixup_cd.dat -copyForced $fwdir/fixup_db.dat /boot/fixup_db.dat -copyForced $fwdir/fixup_x.dat /boot/fixup_x.dat -copyForced $fwdir/start.elf /boot/start.elf -copyForced $fwdir/start_cd.elf /boot/start_cd.elf -copyForced $fwdir/start_db.elf /boot/start_db.elf -copyForced $fwdir/start_x.elf /boot/start_x.elf - -# Add the uboot file -copyForced @uboot@/u-boot.bin /boot/u-boot-rpi.bin - -# Add the config.txt -copyForced @configTxt@ /boot/config.txt diff --git a/nixos/modules/system/boot/loader/raspberrypi/raspberrypi-builder.nix b/nixos/modules/system/boot/loader/raspberrypi/raspberrypi-builder.nix index 27fea4e623e..7eb52e3d021 100644 --- a/nixos/modules/system/boot/loader/raspberrypi/raspberrypi-builder.nix +++ b/nixos/modules/system/boot/loader/raspberrypi/raspberrypi-builder.nix @@ -1,4 +1,4 @@ -{ pkgs, version, configTxt }: +{ pkgs, configTxt }: pkgs.substituteAll { src = ./raspberrypi-builder.sh; @@ -6,5 +6,5 @@ pkgs.substituteAll { inherit (pkgs) bash; path = [pkgs.coreutils pkgs.gnused pkgs.gnugrep]; firmware = pkgs.raspberrypifw; - inherit version configTxt; + inherit configTxt; } diff --git a/nixos/modules/system/boot/loader/raspberrypi/raspberrypi-builder.sh b/nixos/modules/system/boot/loader/raspberrypi/raspberrypi-builder.sh index 68be4e28cd0..0fb07de10c0 100644 --- a/nixos/modules/system/boot/loader/raspberrypi/raspberrypi-builder.sh +++ b/nixos/modules/system/boot/loader/raspberrypi/raspberrypi-builder.sh @@ -85,13 +85,9 @@ addEntry() { echo $kernel > $outdir/$generation-kernel if test "$generation" = "default"; then - if [ @version@ -eq 1 ]; then - copyForced $kernel $target/kernel.img - else - copyForced $kernel $target/kernel7.img - fi + copyForced $kernel $target/kernel.img copyForced $initrd $target/initrd - for dtb in $dtb_path/bcm*.dtb; do + for dtb in $dtb_path/{broadcom,}/bcm*.dtb; do dst="$target/$(basename $dtb)" copyForced $dtb "$dst" filesCopied[$dst]=1 diff --git a/nixos/modules/system/boot/loader/raspberrypi/raspberrypi.nix b/nixos/modules/system/boot/loader/raspberrypi/raspberrypi.nix index bef66bfd41a..17c09d7c4f6 100644 --- a/nixos/modules/system/boot/loader/raspberrypi/raspberrypi.nix +++ b/nixos/modules/system/boot/loader/raspberrypi/raspberrypi.nix @@ -7,8 +7,8 @@ let inherit (pkgs.stdenv.hostPlatform) platform; - builderUboot = import ./builder_uboot.nix { inherit config pkgs configTxt; }; - builderGeneric = import ./raspberrypi-builder.nix { inherit pkgs configTxt; inherit (cfg) version; }; + builderUboot = import ./uboot-builder.nix { inherit pkgs configTxt; inherit (cfg) version; }; + builderGeneric = import ./raspberrypi-builder.nix { inherit pkgs configTxt; }; builder = if cfg.uboot.enable then @@ -34,9 +34,11 @@ let '' + optional isAarch64 '' # Boot in 64-bit mode. arm_control=0x200 - '' + optional cfg.uboot.enable '' + '' + (if cfg.uboot.enable then '' kernel=u-boot-rpi.bin - '' + optional (cfg.firmwareConfig != null) cfg.firmwareConfig); + '' else '' + kernel=kernel.img + '') + optional (cfg.firmwareConfig != null) cfg.firmwareConfig); in @@ -56,7 +58,7 @@ in version = mkOption { default = 2; - type = types.enum [ 1 2 3 ]; + type = types.enum [ 0 1 2 3 ]; description = '' ''; }; diff --git a/nixos/modules/system/boot/loader/raspberrypi/uboot-builder.nix b/nixos/modules/system/boot/loader/raspberrypi/uboot-builder.nix new file mode 100644 index 00000000000..e929c33c6ee --- /dev/null +++ b/nixos/modules/system/boot/loader/raspberrypi/uboot-builder.nix @@ -0,0 +1,35 @@ +{ pkgs, version, configTxt }: + +let + isAarch64 = pkgs.stdenv.isAarch64; + + uboot = + if version == 0 then + pkgs.ubootRaspberryPiZero + else if version == 1 then + pkgs.ubootRaspberryPi + else if version == 2 then + pkgs.ubootRaspberryPi2 + else + if isAarch64 then + pkgs.ubootRaspberryPi3_64bit + else + pkgs.ubootRaspberryPi3_32bit; + + extlinuxConfBuilder = + import ../generic-extlinux-compatible/extlinux-conf-builder.nix { + inherit pkgs; + }; +in +pkgs.substituteAll { + src = ./uboot-builder.sh; + isExecutable = true; + inherit (pkgs) bash; + path = [pkgs.coreutils pkgs.gnused pkgs.gnugrep]; + firmware = pkgs.raspberrypifw; + inherit uboot; + inherit configTxt; + inherit extlinuxConfBuilder; + inherit version; +} + diff --git a/nixos/modules/system/boot/loader/raspberrypi/uboot-builder.sh b/nixos/modules/system/boot/loader/raspberrypi/uboot-builder.sh new file mode 100644 index 00000000000..36bf1506627 --- /dev/null +++ b/nixos/modules/system/boot/loader/raspberrypi/uboot-builder.sh @@ -0,0 +1,29 @@ +#! @bash@/bin/sh -e + +copyForced() { + local src="$1" + local dst="$2" + cp $src $dst.tmp + mv $dst.tmp $dst +} + +# Call the extlinux builder +"@extlinuxConfBuilder@" "$@" + +# Add the firmware files +fwdir=@firmware@/share/raspberrypi/boot/ +copyForced $fwdir/bootcode.bin /boot/bootcode.bin +copyForced $fwdir/fixup.dat /boot/fixup.dat +copyForced $fwdir/fixup_cd.dat /boot/fixup_cd.dat +copyForced $fwdir/fixup_db.dat /boot/fixup_db.dat +copyForced $fwdir/fixup_x.dat /boot/fixup_x.dat +copyForced $fwdir/start.elf /boot/start.elf +copyForced $fwdir/start_cd.elf /boot/start_cd.elf +copyForced $fwdir/start_db.elf /boot/start_db.elf +copyForced $fwdir/start_x.elf /boot/start_x.elf + +# Add the uboot file +copyForced @uboot@/u-boot.bin /boot/u-boot-rpi.bin + +# Add the config.txt +copyForced @configTxt@ /boot/config.txt -- cgit 1.4.1