diff --git a/overlay/default.nix b/overlay/default.nix index 3dad0df..cdf42a0 100644 --- a/overlay/default.nix +++ b/overlay/default.nix @@ -25,6 +25,8 @@ in { # disable firmware compression so that brcm firmware can be found at # the path expected by raspberry pi firmware/device tree compressFirmwareXz = x: x; + + # A recent known working version of libcamera-apps libcamera-apps = final.callPackage ./libcamera-apps.nix { }; # provide generic rpi arm64 u-boot @@ -37,14 +39,16 @@ in { url = "ftp://ftp.denx.de/pub/u-boot/u-boot-${version}.tar.bz2"; sha256 = "03wm651ix783s4idj223b0nm3r6jrdnrxs1ncs8s128g72nknhk9"; }; - # In raspberry pi products the firmware manipulates the device - # tree in a variety of ways before handing it off to the linux - # kernel. Since we have installed u-boot in place of a linux - # kernel we have the option of passing this device tree passed by - # the firmware to the kernel, or providing our own. This + # In raspberry pi sbcs the firmware manipulates the device tree in + # a variety of ways before handing it off to the linux kernel. [1] + # Since we have installed u-boot in place of a linux kernel we may + # pass the device tree passed by the firmware onto the kernel, or + # we may provide the kernel with a device tree of our own. This # configuration uses the device tree provided by firmware so that # we don't have to be aware of all manipulation done by the # firmware and attempt to mimic it. + # + # 1. https://forums.raspberrypi.com/viewtopic.php?t=329799#p1974233 extraConfig = '' CONFIG_OF_HAS_PRIOR_STAGE=y CONFIG_OF_BOARD=y @@ -54,6 +58,10 @@ in { raspberrypifw = final.rpi-kernels.v5_15_87.firmware; } // { + # rpi kernels and firmware are available at + # `pkgs.rpi-kernels..{kernel,firmware,wireless-firmware}'. + # + # For example: `pkgs.rpi-kernels.v5_15_87.kernel' rpi-kernels = rpi-kernels [ { version = "5.15.36"; diff --git a/rpi-3b-plus/default.nix b/rpi-3b-plus/default.nix deleted file mode 100644 index f3f7de2..0000000 --- a/rpi-3b-plus/default.nix +++ /dev/null @@ -1,14 +0,0 @@ -rpi: -{ lib, pkgs, config, ... }: - -{ - imports = [ rpi ]; - hardware.raspberry-pi.deviceTree = { - base-dtb = "bcm2710-rpi-3-b-plus.dtb"; - # u-boot expects bcm2837-rpi-3-b-plus.dtb for the 3b+ Rename the - # raspberry pi dtb to match mainline linux and satisfy u-boot. - postInstall = '' - mv $out/broadcom/bcm2710-rpi-3-b-plus.dtb $out/broadcom/bcm2837-rpi-3-b-plus.dtb - ''; - }; -} diff --git a/rpi-4b/default.nix b/rpi-4b/default.nix deleted file mode 100644 index c9141e2..0000000 --- a/rpi-4b/default.nix +++ /dev/null @@ -1,8 +0,0 @@ -rpi: -{ lib, pkgs, config, ... }: - -{ - imports = [ rpi ]; - hardware.raspberry-pi.deviceTree.base-dtb = "bcm2711-rpi-4-b.dtb"; -} - diff --git a/rpi-zero-2-w/default.nix b/rpi-zero-2-w/default.nix deleted file mode 100644 index 13a649b..0000000 --- a/rpi-zero-2-w/default.nix +++ /dev/null @@ -1,13 +0,0 @@ -rpi: -{ lib, pkgs, config, ... }: - -{ - imports = [ rpi ]; - hardware.raspberry-pi.deviceTree.base-dtb = "bcm2710-rpi-zero-2.dtb"; - # u-boot expects bcm2837-rpi-zero-2.dtb for the zero 2 w (this is - # the device tree name in the upstream kernel), Rename the raspberry - # pi dtb to the expected name to satisfy u-boot. - hardware.raspberry-pi.deviceTree.postInstall = '' - mv $out/broadcom/bcm2710-rpi-zero-2.dtb $out/broadcom/bcm2837-rpi-zero-2.dtb - ''; -} diff --git a/rpi/audio.nix b/rpi/audio.nix deleted file mode 100644 index 1d2f79b..0000000 --- a/rpi/audio.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ config, lib, pkgs, ... }: - -let cfg = config.hardware.raspberry-pi.audio; -in { - options.hardware.raspberry-pi.audio = { - enable = lib.mkEnableOption "configuration for audio"; - }; - config = lib.mkIf cfg.enable { - hardware = { - raspberry-pi.deviceTree.base-dtb-params = [ "audio=on" ]; - pulseaudio.configFile = lib.mkOverride 990 - (pkgs.runCommand "default.pa" { } '' - sed 's/module-udev-detect$/module-udev-detect tsched=0/' ${config.hardware.pulseaudio.package}/etc/pulse/default.pa > $out - ''); - }; - }; -} diff --git a/rpi/default.nix b/rpi/default.nix index 3d7f886..46ac142 100644 --- a/rpi/default.nix +++ b/rpi/default.nix @@ -2,14 +2,7 @@ { lib, pkgs, config, ... }: { - imports = [ - ../sd-image - ./device-tree.nix - ./audio.nix - ./i2c.nix - ./i2s.nix - ./modesetting.nix - ]; + imports = [ ../sd-image ]; nixpkgs = { overlays = [ overlay ]; }; boot = { diff --git a/rpi/device-tree.nix b/rpi/device-tree.nix deleted file mode 100644 index fc79365..0000000 --- a/rpi/device-tree.nix +++ /dev/null @@ -1,102 +0,0 @@ -{ config, lib, pkgs, ... }: - -let cfg = config.hardware.raspberry-pi.deviceTree; -in { - options.hardware.raspberry-pi.deviceTree = { - base-dtb = lib.mkOption { - type = lib.types.str; - example = "bcm2711-rpi-4-b.dtb"; - description = "base dtb to apply"; - }; - base-dtb-params = lib.mkOption { - type = lib.types.listOf lib.types.string; - default = [ ]; - example = [ "i2c1=on" "audio=on" ]; - description = "parameters to pass to the base dtb"; - }; - dt-overlays = lib.mkOption { - type = with lib.types; - listOf (submodule { - options = { - overlay = lib.mkOption { type = oneOf [ str path ]; }; - args = lib.mkOption { - type = listOf str; - default = [ ]; - }; - }; - }); - default = [ ]; - example = [{ - overlay = "vc4-fkms-v3d"; - args = [ "cma-512" ]; - }]; - description = "dtb overlays to apply"; - }; - postInstall = lib.mkOption { - type = lib.types.str; - default = ""; - description = "bash command to run after building dtb"; - }; - }; - config = { - hardware = { - deviceTree = { - enable = true; - filter = cfg.base-dtb; - package = let - dtbsWithSymbols = pkgs.stdenv.mkDerivation { - name = "dtbs-with-symbols"; - inherit (config.boot.kernelPackages.kernel) - src nativeBuildInputs depsBuildBuild; - patches = map (patch: patch.patch) - config.boot.kernelPackages.kernel.kernelPatches; - buildPhase = '' - patchShebangs scripts/* - substituteInPlace scripts/Makefile.lib \ - --replace 'DTC_FLAGS += $(DTC_FLAGS_$(basetarget))' 'DTC_FLAGS += $(DTC_FLAGS_$(basetarget)) -@' - make ${pkgs.stdenv.hostPlatform.linux-kernel.baseConfig} ARCH="${pkgs.stdenv.hostPlatform.linuxArch}" - make dtbs ARCH="${pkgs.stdenv.hostPlatform.linuxArch}" - ''; - installPhase = '' - make dtbs_install INSTALL_DTBS_PATH=$out/dtbs ARCH="${pkgs.stdenv.hostPlatform.linuxArch}" - ''; - }; - compiled-overlays = map (x: - let - overlay-file = if builtins.isPath x.overlay then - pkgs.runCommand "overlay.dtbo" { - buildInputs = with pkgs; [ dtc ]; - } "dtc -I dts -O dtb -o $out ${x.overlay}" - else - "${config.boot.kernelPackages.kernel}/dtbs/overlays/${x.overlay}.dtbo"; - in x // { overlay = overlay-file; }) cfg.dt-overlays; - in lib.mkForce (pkgs.runCommand "device-tree-overlays" { - buildInputs = with pkgs; [ findutils libraspberrypi ]; - } '' - cd ${dtbsWithSymbols}/dtbs - for dtb in $(find . -type f -name "${config.hardware.deviceTree.filter}") - do - install -D $dtb $out/$dtb - - ${ - lib.concatMapStrings (param: '' - dtmerge -d $out/$dtb{,-merged} - ${param} - mv $out/$dtb{-merged,} - '') cfg.base-dtb-params - } - - ${ - lib.concatMapStrings (x: '' - dtmerge -d $out/$dtb{,-merged} ${x.overlay} ${ - builtins.concatStringsSep " " x.args - } - mv $out/$dtb{-merged,} - '') compiled-overlays - } - done - ${cfg.postInstall} - ''); - }; - }; - }; -} diff --git a/rpi/i2c.nix b/rpi/i2c.nix deleted file mode 100644 index a59021f..0000000 --- a/rpi/i2c.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ config, lib, pkgs, ... }: - -let cfg = config.hardware.raspberry-pi.i2c; -in { - options.hardware.raspberry-pi.i2c = { - enable = lib.mkEnableOption "configuration for i2c"; - }; - config = lib.mkIf cfg.enable { - hardware = { - raspberry-pi.deviceTree.base-dtb-params = [ "i2c1=on" ]; - i2c.enable = true; - }; - }; -} diff --git a/rpi/i2s.nix b/rpi/i2s.nix deleted file mode 100644 index fc88deb..0000000 --- a/rpi/i2s.nix +++ /dev/null @@ -1,13 +0,0 @@ -{ config, lib, pkgs, ... }: - -let cfg = config.hardware.raspberry-pi.i2s; -in { - options.hardware.raspberry-pi.i2s = { - enable = lib.mkEnableOption "configuration for i2s"; - }; - config = lib.mkIf cfg.enable { - hardware = { - raspberry-pi.deviceTree.base-dtb-params = [ "i2s=on" ]; - }; - }; -} diff --git a/rpi/modesetting.nix b/rpi/modesetting.nix deleted file mode 100644 index f967b58..0000000 --- a/rpi/modesetting.nix +++ /dev/null @@ -1,23 +0,0 @@ -{ config, lib, pkgs, ... }: - -let cfg = config.hardware.raspberry-pi.fkms-3d; -in { - options.hardware.raspberry-pi.fkms-3d = { - enable = lib.mkEnableOption "Enable modesetting through fkms-3d"; - }; - config = lib.mkIf cfg.enable { - hardware = { - raspberry-pi.deviceTree.dt-overlays = [ - { - overlay = "cma"; - args = [ ]; - } - { - overlay = "vc4-fkms-v3d"; - args = [ ]; - } - ]; - }; - services.xserver.videoDrivers = lib.mkBefore [ "modesetting" "fbdev" ]; - }; -}