diff --git a/overlays/default.nix b/overlays/default.nix index b48e75f..13a5745 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -1 +1,4 @@ -{ nibylandia = final: prev: (import ./nibylandia.nix) final prev; } +{ + nibylandia = final: prev: (import ./nibylandia.nix) final prev; + rpi5 = final: prev: (import ./rpi5.nix) final prev; +} diff --git a/overlays/rpi5.nix b/overlays/rpi5.nix new file mode 100644 index 0000000..dd4f116 --- /dev/null +++ b/overlays/rpi5.nix @@ -0,0 +1,11 @@ +self: super: { + linux_rpi5 = self.callPackage ../pkgs/linux_rpi/linux-rpi.nix { + kernelPatches = with self.kernelPatches; [ + bridge_stp_helper + request_key_helper + ]; + rpiVersion = 5; + }; + + linuxPackages_rpi5 = self.linuxPackagesFor linux_rpi5; +} diff --git a/pkgs/linux_rpi/linux-rpi.nix b/pkgs/linux_rpi/linux-rpi.nix new file mode 100644 index 0000000..8e2a5e8 --- /dev/null +++ b/pkgs/linux_rpi/linux-rpi.nix @@ -0,0 +1,73 @@ +{ stdenv, lib, buildPackages, fetchFromGitHub, perl, buildLinux, rpiVersion, ... } @ args: + +let + # NOTE: raspberrypifw & raspberryPiWirelessFirmware should be updated with this + modDirVersion = "6.1.63"; + tag = "stable_20231123"; +in +lib.overrideDerivation (buildLinux (args // { + version = "${modDirVersion}-${tag}"; + inherit modDirVersion; + + src = fetchFromGitHub { + owner = "raspberrypi"; + repo = "linux"; + rev = tag; + hash = "sha256-4Rc57y70LmRFwDnOD4rHoHGmfxD9zYEAwYm9Wvyb3no="; + }; + + defconfig = { + "1" = "bcmrpi_defconfig"; + "2" = "bcm2709_defconfig"; + "3" = if stdenv.hostPlatform.isAarch64 then "bcmrpi3_defconfig" else "bcm2709_defconfig"; + "4" = "bcm2711_defconfig"; + "5" = "bcm2712_defconfig"; + }.${toString rpiVersion}; + + features = { + efiBootStub = false; + } // (args.features or {}); + + extraMeta = if (rpiVersion < 3) then { + platforms = with lib.platforms; arm; + hydraPlatforms = []; + } else { + platforms = with lib.platforms; arm ++ aarch64; + hydraPlatforms = [ "aarch64-linux" ]; + }; +} // (args.argsOverride or {}))) (oldAttrs: { + postConfigure = '' + # The v7 defconfig has this set to '-v7' which screws up our modDirVersion. + sed -i $buildRoot/.config -e 's/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION=""/' + sed -i $buildRoot/include/config/auto.conf -e 's/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION=""/' + ''; + + # Make copies of the DTBs named after the upstream names so that U-Boot finds them. + # This is ugly as heck, but I don't know a better solution so far. + postFixup = '' + dtbDir=${if stdenv.isAarch64 then "$out/dtbs/broadcom" else "$out/dtbs"} + rm $dtbDir/bcm283*.dtb + copyDTB() { + cp -v "$dtbDir/$1" "$dtbDir/$2" + } + '' + lib.optionalString (lib.elem stdenv.hostPlatform.system ["armv6l-linux"]) '' + copyDTB bcm2708-rpi-zero-w.dtb bcm2835-rpi-zero.dtb + copyDTB bcm2708-rpi-zero-w.dtb bcm2835-rpi-zero-w.dtb + copyDTB bcm2708-rpi-b.dtb bcm2835-rpi-a.dtb + copyDTB bcm2708-rpi-b.dtb bcm2835-rpi-b.dtb + copyDTB bcm2708-rpi-b.dtb bcm2835-rpi-b-rev2.dtb + copyDTB bcm2708-rpi-b-plus.dtb bcm2835-rpi-a-plus.dtb + copyDTB bcm2708-rpi-b-plus.dtb bcm2835-rpi-b-plus.dtb + copyDTB bcm2708-rpi-b-plus.dtb bcm2835-rpi-zero.dtb + copyDTB bcm2708-rpi-cm.dtb bcm2835-rpi-cm.dtb + '' + lib.optionalString (lib.elem stdenv.hostPlatform.system ["armv7l-linux"]) '' + copyDTB bcm2709-rpi-2-b.dtb bcm2836-rpi-2-b.dtb + '' + lib.optionalString (lib.elem stdenv.hostPlatform.system ["armv7l-linux" "aarch64-linux"]) '' + copyDTB bcm2710-rpi-zero-2.dtb bcm2837-rpi-zero-2.dtb + copyDTB bcm2710-rpi-3-b.dtb bcm2837-rpi-3-b.dtb + copyDTB bcm2710-rpi-3-b-plus.dtb bcm2837-rpi-3-a-plus.dtb + copyDTB bcm2710-rpi-3-b-plus.dtb bcm2837-rpi-3-b-plus.dtb + copyDTB bcm2710-rpi-cm3.dtb bcm2837-rpi-cm3.dtb + copyDTB bcm2711-rpi-4-b.dtb bcm2838-rpi-4-b.dtb + ''; +}) diff --git a/pkgs/raspberrypi-wireless/default.nix b/pkgs/raspberrypi-wireless/default.nix new file mode 100644 index 0000000..386df84 --- /dev/null +++ b/pkgs/raspberrypi-wireless/default.nix @@ -0,0 +1,59 @@ +{ lib, stdenvNoCC, fetchFromGitHub }: + +stdenvNoCC.mkDerivation { + pname = "raspberrypi-wireless-firmware"; + version = "unstable-2023-11-15"; + + srcs = [ + (fetchFromGitHub { + name = "bluez-firmware"; + owner = "RPi-Distro"; + repo = "bluez-firmware"; + rev = "d9d4741caba7314d6500f588b1eaa5ab387a4ff5"; + hash = "sha256-CjbZ3t3TW/iJ3+t9QKEtM9NdQU7SwcUCDYuTmFEwvhU="; + }) + (fetchFromGitHub { + name = "firmware-nonfree"; + owner = "RPi-Distro"; + repo = "firmware-nonfree"; + rev = "88aa085bfa1a4650e1ccd88896f8343c22a24055"; + hash = "sha256-Yynww79LPPkau4YDSLI6IMOjH64nMpHUdGjnCfIR2+M="; + }) + ]; + + sourceRoot = "."; + + dontBuild = true; + # Firmware blobs do not need fixing and should not be modified + dontFixup = true; + + installPhase = '' + runHook preInstall + mkdir -p "$out/lib/firmware/brcm" + + # Wifi firmware + cp -rv "$NIX_BUILD_TOP/firmware-nonfree/debian/config/brcm80211/." "$out/lib/firmware/" + + # Bluetooth firmware + cp -rv "$NIX_BUILD_TOP/bluez-firmware/debian/firmware/broadcom/." "$out/lib/firmware/brcm" + + # brcmfmac43455-sdio.bin is a symlink to the non-existent path: ../cypress/cyfmac43455-sdio.bin. + # See https://github.com/RPi-Distro/firmware-nonfree/issues/26 + ln -s "./cyfmac43455-sdio-standard.bin" "$out/lib/firmware/cypress/cyfmac43455-sdio.bin" + + pushd $out/lib/firmware/brcm &>/dev/null + # Symlinks for Zero 2W + ln -s "./brcmfmac43436-sdio.clm_blob" "$out/lib/firmware/brcm/brcmfmac43430b0-sdio.clm_blob" + popd &>/dev/null + + runHook postInstall + ''; + + meta = with lib; { + description = "Firmware for builtin Wifi/Bluetooth devices in the Raspberry Pi 3+ and Zero W"; + homepage = "https://github.com/RPi-Distro/firmware-nonfree"; + license = licenses.unfreeRedistributableFirmware; + platforms = platforms.linux; + maintainers = with maintainers; [ lopsided98 ]; + }; +} diff --git a/pkgs/raspberrypi/armstubs.nix b/pkgs/raspberrypi/armstubs.nix new file mode 100644 index 0000000..72c6f62 --- /dev/null +++ b/pkgs/raspberrypi/armstubs.nix @@ -0,0 +1,53 @@ +{ lib, stdenv, fetchFromGitHub }: + +let + inherit (lib) optionals; +in +stdenv.mkDerivation { + pname = "raspberrypi-armstubs"; + version = "unstable-2022-07-11"; + + src = fetchFromGitHub { + owner = "raspberrypi"; + repo = "tools"; + rev = "439b6198a9b340de5998dd14a26a0d9d38a6bcac"; + hash = "sha512-KMHgj73eXHT++IE8DbCsFeJ87ngc9R3XxMUJy4Z3s4/MtMeB9zblADHkyJqz9oyeugeJTrDtuVETPBRo7M4Y8A=="; + }; + + env.NIX_CFLAGS_COMPILE = toString [ + "-march=armv8-a+crc" + ]; + + preConfigure = '' + cd armstubs + ''; + + makeFlags = [ + "CC8=${stdenv.cc.targetPrefix}cc" + "LD8=${stdenv.cc.targetPrefix}ld" + "OBJCOPY8=${stdenv.cc.targetPrefix}objcopy" + "OBJDUMP8=${stdenv.cc.targetPrefix}objdump" + "CC7=${stdenv.cc.targetPrefix}cc" + "LD7=${stdenv.cc.targetPrefix}ld" + "OBJCOPY7=${stdenv.cc.targetPrefix}objcopy" + "OBJDUMP7=${stdenv.cc.targetPrefix}objdump" + ] + ++ optionals (stdenv.isAarch64) [ "armstub8.bin" "armstub8-gic.bin" ] + ++ optionals (stdenv.isAarch32) [ "armstub7.bin" "armstub8-32.bin" "armstub8-32-gic.bin" ] + ; + + installPhase = '' + runHook preInstall + mkdir -vp $out/ + cp -v *.bin $out/ + runHook postInstall + ''; + + meta = with lib; { + description = "Firmware related ARM stubs for the Raspberry Pi"; + homepage = "https://github.com/raspberrypi/tools"; + license = licenses.bsd3; + platforms = [ "armv6l-linux" "armv7l-linux" "aarch64-linux" ]; + maintainers = with maintainers; [ samueldr ]; + }; +} diff --git a/pkgs/raspberrypi/default.nix b/pkgs/raspberrypi/default.nix new file mode 100644 index 0000000..0aea94b --- /dev/null +++ b/pkgs/raspberrypi/default.nix @@ -0,0 +1,36 @@ +{ lib, stdenvNoCC, fetchFromGitHub }: + +stdenvNoCC.mkDerivation rec { + # NOTE: this should be updated with linux_rpi + pname = "raspberrypi-firmware"; + # raspberrypi/firmware no longers tag the releases. However, since each commit + # on the stable branch corresponds to a tag in raspberrypi/linux repo, we + # assume they are cut together. + version = "stable_20231123"; + + src = fetchFromGitHub { + owner = "raspberrypi"; + repo = "firmware"; + rev = "524247ac6d8b1f4ddd53730e978a70c76a320bd6"; + hash = "sha256-rESwkR7pc5MTwIZ8PaMUPXuzxfv+jVpdRp8ijvxHGcg="; + }; + + installPhase = '' + mkdir -p $out/share/raspberrypi/ + mv boot "$out/share/raspberrypi/" + ''; + + dontConfigure = true; + dontBuild = true; + dontFixup = true; + + meta = with lib; { + description = "Firmware for the Raspberry Pi board"; + homepage = "https://github.com/raspberrypi/firmware"; + license = licenses.unfreeRedistributableFirmware; # See https://github.com/raspberrypi/firmware/blob/master/boot/LICENCE.broadcom + maintainers = with maintainers; [ dezgeg ]; + # Hash mismatch on source, mystery. + # Maybe due to https://github.com/NixOS/nix/issues/847 + broken = stdenvNoCC.isDarwin; + }; +}