From 14777d1f0c44626b7e48a6fe7318f7370ce6e4de Mon Sep 17 00:00:00 2001 From: Adam Stephens Date: Tue, 30 Jul 2024 22:25:13 -0400 Subject: [PATCH] finally load the gpu firmware in initrd --- flake.nix | 40 ++++++++++++++++++++----------------- module.nix | 27 ++++++++++++++++++++----- packages/default.nix | 15 ++++++++++++-- packages/extra-firmware.nix | 21 ------------------- 4 files changed, 57 insertions(+), 46 deletions(-) delete mode 100644 packages/extra-firmware.nix diff --git a/flake.nix b/flake.nix index d4e92f0..ad80416 100644 --- a/flake.nix +++ b/flake.nix @@ -79,7 +79,6 @@ ... }: let - dtb = "${config.boot.kernelPackages.kernel}/dtbs/qcom/${dtbName}"; image = import "${inputs.nixpkgs}/nixos/lib/make-disk-image.nix" { inherit config lib pkgs; @@ -92,8 +91,6 @@ in { - imports = [ "${toString modulesPath}/installer/cd-dvd/iso-image.nix" ]; - hardware.deviceTree = { enable = true; name = "qcom/${dtbName}"; @@ -101,11 +98,18 @@ system.build.bootstrap-image = image; - boot.initrd.systemd.enable = true; - boot.initrd.systemd.emergencyAccess = true; - boot.loader.grub.enable = false; - boot.loader.systemd-boot.enable = true; - boot.loader.systemd-boot.graceful = true; + boot = { + initrd = { + systemd.enable = true; + systemd.emergencyAccess = true; + }; + + loader = { + grub.enable = false; + systemd-boot.enable = true; + systemd-boot.graceful = true; + }; + }; nixpkgs.config.allowUnfree = true; @@ -114,16 +118,16 @@ bluetoothMac = "02:68:b3:29:da:98"; }; - isoImage = { - makeEfiBootable = true; - makeUsbBootable = true; - - contents = [ - { - source = dtb; - target = "/x13s.dtb"; - } - ]; + fileSystems = { + "/boot" = { + fsType = "vfat"; + device = "/dev/disk/by-label/ESP"; + }; + "/" = { + device = "/dev/disk/by-label/nixos"; + fsType = "ext4"; + autoResize = true; + }; }; } ) diff --git a/module.nix b/module.nix index 1afe684..f6168bc 100644 --- a/module.nix +++ b/module.nix @@ -20,6 +20,21 @@ let ); dtb = "${linuxPackages_x13s.kernel}/dtbs/qcom/${dtbName}"; dtbEfiPath = "dtbs/x13s.dtb"; + + modulesClosure = pkgs.makeModulesClosure { + rootModules = config.boot.initrd.availableKernelModules ++ config.boot.initrd.kernelModules; + kernel = config.system.modulesTree; + firmware = config.hardware.firmware; + allowMissing = false; + }; + + modulesWithExtra = pkgs.symlinkJoin { + name = "modules-closure"; + paths = [ + modulesClosure + x13sPackages.graphics-firmware + ]; + }; in { options.nixos-x13s = { @@ -44,9 +59,14 @@ in environment.systemPackages = [ pkgs.efibootmgr ]; hardware.enableAllFirmware = true; - hardware.firmware = [ x13sPackages."x13s/extra-firmware" ]; + hardware.firmware = lib.mkBefore [ x13sPackages.graphics-firmware ]; boot = { + initrd.systemd.enable = true; + initrd.systemd.contents = { + "/lib".source = lib.mkForce "${modulesWithExtra}/lib"; + }; + loader.efi.canTouchEfiVariables = true; loader.systemd-boot.enable = lib.mkDefault true; loader.systemd-boot.extraFiles = { @@ -65,9 +85,6 @@ in "pd_ignore_unused" "arm64.nopauth" # "regulator_ignore_unused" # allows for > 30 sec to load msm, at the potential cost of power - - # blacklist graphics in initrd so the firmware can load from disk - "rd.driver.blacklist=msm" ]; initrd = { @@ -91,7 +108,7 @@ in "dispcc_sc8280xp" "phy_qcom_edp" "panel-edp" - # "msm" + "msm" ]; }; }; diff --git a/packages/default.nix b/packages/default.nix index 9e09493..f4a84f7 100644 --- a/packages/default.nix +++ b/packages/default.nix @@ -14,12 +14,23 @@ let } ); in -rec { +{ linux_jhovold = pkgs.callPackage linux_x13s_pkg { src = sources.linux-jhovold; version = "6.11.0-rc1"; defconfig = "johan_defconfig"; }; - "x13s/extra-firmware" = pkgs.callPackage ./extra-firmware.nix { }; + graphics-firmware = + let + gpu-src = pkgs.fetchurl { + url = "https://download.lenovo.com/pccbbs/mobiles/n3hdr20w.exe"; + hash = "sha256-Jwyl9uKOnjpwfHd+VaGHjYs9x8cUuRdFCERuXqaJwEY="; + }; + in + pkgs.runCommand "graphics-firmware" { } '' + mkdir -vp "$out/lib/firmware/qcom/sc8280xp/LENOVO/21BX" + ${lib.getExe pkgs.innoextract} ${gpu-src} + cp -v code\$GetExtractPath\$/*/*.mbn "$out/lib/firmware/qcom/sc8280xp/LENOVO/21BX/" + ''; } diff --git a/packages/extra-firmware.nix b/packages/extra-firmware.nix deleted file mode 100644 index 2578627..0000000 --- a/packages/extra-firmware.nix +++ /dev/null @@ -1,21 +0,0 @@ -{ stdenvNoCC, fetchFromGitHub }: - -stdenvNoCC.mkDerivation { - pname = "x13s-extra-firmware"; - version = "1.0.0"; - - src = fetchFromGitHub { - owner = "ironrobin"; - repo = "x13s-alarm"; - rev = "efa51c3b519f75b3983aef67855b1561d9828771"; - sha256 = "sha256-weETbWXz9aL2pDQDKk7fkb1ecQH0qrhUYDs2E5EiJcI="; - }; - - dontFixup = true; - dontBuild = true; - - installPhase = '' - mkdir -p $out/lib/firmware/qcom/sc8280xp/LENOVO/21BX - cp x13s-firmware/qcvss8280.mbn $out/lib/firmware/qcom/sc8280xp/LENOVO/21BX/ - ''; -}