1{ stdenv, lib, buildPackages, fetchFromGitHub, perl, buildLinux, rpiVersion, ... } @ args:
2
3let
4 # NOTE: raspberrypifw & raspberryPiWirelessFirmware should be updated with this
5 modDirVersion = "6.1.21";
6 tag = "1.20230405";
7in
8lib.overrideDerivation (buildLinux (args // {
9 version = "${modDirVersion}-${tag}";
10 inherit modDirVersion;
11
12 src = fetchFromGitHub {
13 owner = "raspberrypi";
14 repo = "linux";
15 rev = tag;
16 hash = "sha256-ILwecHZ1BN6GhZAUB6/UwiN/rZ8gHndKON6DUhidtxI=";
17 };
18
19 defconfig = {
20 "1" = "bcmrpi_defconfig";
21 "2" = "bcm2709_defconfig";
22 "3" = if stdenv.hostPlatform.isAarch64 then "bcmrpi3_defconfig" else "bcm2709_defconfig";
23 "4" = "bcm2711_defconfig";
24 }.${toString rpiVersion};
25
26 features = {
27 efiBootStub = false;
28 } // (args.features or {});
29
30 extraMeta = if (rpiVersion < 3) then {
31 platforms = with lib.platforms; arm;
32 hydraPlatforms = [];
33 } else {
34 platforms = with lib.platforms; arm ++ aarch64;
35 hydraPlatforms = [ "aarch64-linux" ];
36 };
37} // (args.argsOverride or {}))) (oldAttrs: {
38 postConfigure = ''
39 # The v7 defconfig has this set to '-v7' which screws up our modDirVersion.
40 sed -i $buildRoot/.config -e 's/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION=""/'
41 sed -i $buildRoot/include/config/auto.conf -e 's/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION=""/'
42 '';
43
44 # Make copies of the DTBs named after the upstream names so that U-Boot finds them.
45 # This is ugly as heck, but I don't know a better solution so far.
46 postFixup = ''
47 dtbDir=${if stdenv.isAarch64 then "$out/dtbs/broadcom" else "$out/dtbs"}
48 rm $dtbDir/bcm283*.dtb
49 copyDTB() {
50 cp -v "$dtbDir/$1" "$dtbDir/$2"
51 }
52 '' + lib.optionalString (lib.elem stdenv.hostPlatform.system ["armv6l-linux"]) ''
53 copyDTB bcm2708-rpi-zero-w.dtb bcm2835-rpi-zero.dtb
54 copyDTB bcm2708-rpi-zero-w.dtb bcm2835-rpi-zero-w.dtb
55 copyDTB bcm2708-rpi-b.dtb bcm2835-rpi-a.dtb
56 copyDTB bcm2708-rpi-b.dtb bcm2835-rpi-b.dtb
57 copyDTB bcm2708-rpi-b.dtb bcm2835-rpi-b-rev2.dtb
58 copyDTB bcm2708-rpi-b-plus.dtb bcm2835-rpi-a-plus.dtb
59 copyDTB bcm2708-rpi-b-plus.dtb bcm2835-rpi-b-plus.dtb
60 copyDTB bcm2708-rpi-b-plus.dtb bcm2835-rpi-zero.dtb
61 copyDTB bcm2708-rpi-cm.dtb bcm2835-rpi-cm.dtb
62 '' + lib.optionalString (lib.elem stdenv.hostPlatform.system ["armv7l-linux"]) ''
63 copyDTB bcm2709-rpi-2-b.dtb bcm2836-rpi-2-b.dtb
64 '' + lib.optionalString (lib.elem stdenv.hostPlatform.system ["armv7l-linux" "aarch64-linux"]) ''
65 copyDTB bcm2710-rpi-zero-2.dtb bcm2837-rpi-zero-2.dtb
66 copyDTB bcm2710-rpi-3-b.dtb bcm2837-rpi-3-b.dtb
67 copyDTB bcm2710-rpi-3-b-plus.dtb bcm2837-rpi-3-a-plus.dtb
68 copyDTB bcm2710-rpi-3-b-plus.dtb bcm2837-rpi-3-b-plus.dtb
69 copyDTB bcm2710-rpi-cm3.dtb bcm2837-rpi-cm3.dtb
70 copyDTB bcm2711-rpi-4-b.dtb bcm2838-rpi-4-b.dtb
71 '';
72})