From c50c9710f0c144ce58392f95debd997d078751f5 Mon Sep 17 00:00:00 2001 From: Infinidoge Date: Sun, 23 Jun 2024 15:49:33 -0400 Subject: [PATCH] WIP: Infini-RASPBERRY: copy options from sd image experiment --- hosts/Infini-RASPBERRY/default.nix | 16 +++++- hosts/Infini-RASPBERRY/sd-image.nix | 87 +++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 hosts/Infini-RASPBERRY/sd-image.nix diff --git a/hosts/Infini-RASPBERRY/default.nix b/hosts/Infini-RASPBERRY/default.nix index d3d644f..fad24a9 100644 --- a/hosts/Infini-RASPBERRY/default.nix +++ b/hosts/Infini-RASPBERRY/default.nix @@ -3,7 +3,7 @@ with lib; { imports = [ inputs.nixos-hardware.nixosModules.raspberry-pi-4 - inputs.nixos-generators.nixosModules.sd-aarch64 + ./sd-image.nix ]; system.stateVersion = "23.11"; @@ -24,11 +24,14 @@ with lib; wireless.enable = mkDefault true; }; + systemd.services.wpa_aupplicant.wantedBy = lib.mkOverride 10 [ "multi-user.target" ]; + boot = { + consoleLogLevel = lib.mkDefault 7; kernelPackages = mkForce pkgs.linuxPackages_rpi4; # Removes ZFS >:( - supportedFilesystems = mkForce [ "btrfs" "cifs" "f2fs" "jfs" "ntfs" "reiserfs" "vfat" "xfs" "ext4" "vfat" ]; + supportedFilesystems = mkForce [ "btrfs" "ntfs" "vfat" "ext4" ]; tmp.useTmpfs = true; # kernelParams = [ @@ -43,6 +46,15 @@ with lib; }; }; + documentation = { + enable = false; + doc.enable = false; + man.enable = false; + man.man-dp.enable = false; + man.mandoc.enable = false; + nixos.enable = false; + }; + hardware.deviceTree = { enable = true; # filter = "*rpi-4-*.dtb"; diff --git a/hosts/Infini-RASPBERRY/sd-image.nix b/hosts/Infini-RASPBERRY/sd-image.nix new file mode 100644 index 0000000..b1d1785 --- /dev/null +++ b/hosts/Infini-RASPBERRY/sd-image.nix @@ -0,0 +1,87 @@ +{ modulesPath, config, lib, pkgs, ... }: + +{ + formatAttr = "sdImage"; + + imports = [ + "${modulesPath}/installer/sd-card/sd-image.nix" + "${modulesPath}/profiles/installation-device.nix" + ]; + + # sd-image-aarch64-installer/sd-image-raspberrypi-installer + installer.cloneConfig = false; + + # sd-image-raspberrypi + boot.consoleLogLevel = lib.mkDefault 7; + boot.kernelPackages = pkgs.linuxKernel.packages.linux_rpi4; + + # The serial ports listed here are: + # - ttyS0: for Tegra (Jetson TX1) + # - ttyAMA0: for QEMU's -machine virt + boot.kernelParams = [ "console=ttyS0,115200n8" "console=ttyAMA0,115200n8" "console=tty0" ]; + + sdImage = { + populateFirmwareCommands = + let + configTxt = pkgs.writeText "config.txt" '' + [pi3] + kernel=u-boot-rpi3.bin + + [pi02] + kernel=u-boot-rpi3.bin + + [pi4] + kernel=u-boot-rpi4.bin + enable_gic=1 + armstub=armstub8-gic.bin + + # Otherwise the resolution will be weird in most cases, compared to + # what the pi3 firmware does by default. + disable_overscan=1 + + # Supported in newer board revisions + arm_boost=1 + + [cm4] + # Enable host mode on the 2711 built-in XHCI USB controller. + # This line should be removed if the legacy DWC2 controller is required + # (e.g. for USB device mode) or if USB support is not required. + otg_mode=1 + + [all] + # Boot in 64-bit mode. + arm_64bit=1 + + # U-Boot needs this to work, regardless of whether UART is actually used or not. + # Look in arch/arm/mach-bcm283x/Kconfig in the U-Boot tree to see if this is still + # a requirement in the future. + enable_uart=1 + + # Prevent the firmware from smashing the framebuffer setup done by the mainline kernel + # when attempting to show low-voltage or overtemperature warnings. + avoid_warnings=1 + ''; + in + '' + (cd ${pkgs.raspberrypifw}/share/raspberrypi/boot && cp bootcode.bin fixup*.dat start*.elf $NIX_BUILD_TOP/firmware/) + + # Add the config + cp ${configTxt} firmware/config.txt + + # Add pi3 specific files + cp ${pkgs.ubootRaspberryPi3_64bit}/u-boot.bin firmware/u-boot-rpi3.bin + + # Add pi4 specific files + cp ${pkgs.ubootRaspberryPi4_64bit}/u-boot.bin firmware/u-boot-rpi4.bin + cp ${pkgs.raspberrypi-armstubs}/armstub8-gic.bin firmware/armstub8-gic.bin + cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/bcm2711-rpi-4-b.dtb firmware/ + cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/bcm2711-rpi-400.dtb firmware/ + cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/bcm2711-rpi-cm4.dtb firmware/ + cp ${pkgs.raspberrypifw}/share/raspberrypi/boot/bcm2711-rpi-cm4s.dtb firmware/ + ''; + populateRootCommands = '' + mkdir -p ./files/boot + ${config.boot.loader.generic-extlinux-compatible.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot + ''; + }; +}