From d00e26c04422b28090d6d9a222cbffb9b738271e Mon Sep 17 00:00:00 2001 From: Colin Date: Tue, 1 Oct 2024 13:50:37 +0000 Subject: [PATCH] plumb rk818-charger module into the moby config --- .../hal/pine64-pinephone-pro/default.nix | 6 ++++- .../linux-sane-pinephonepro/default.nix | 9 ++++--- pkgs/additional/rk818-charger/Makefile | 8 +++--- pkgs/additional/rk818-charger/default.nix | 26 ++++++++++++++++--- pkgs/default.nix | 10 ++++++- 5 files changed, 47 insertions(+), 12 deletions(-) diff --git a/hosts/modules/hal/pine64-pinephone-pro/default.nix b/hosts/modules/hal/pine64-pinephone-pro/default.nix index 2ca26494a..23d3f5f94 100644 --- a/hosts/modules/hal/pine64-pinephone-pro/default.nix +++ b/hosts/modules/hal/pine64-pinephone-pro/default.nix @@ -114,9 +114,13 @@ in # }) # config.boot.initrd.extraFiles # ); - # }); + boot.extraModulePackages = [ + # pkgs.rk818-charger #< rk818 battery/charger isn't mainline as of 2024-10-01 + config.boot.kernelPackages.rk818-charger #< rk818 battery/charger isn't mainline as of 2024-10-01 + ]; + boot.initrd.availableKernelModules = [ # see # - pmos includes: gpu_sched dw_wdt fusb302 panel_himax_hx8394 goodix_ts diff --git a/pkgs/additional/linux-sane-pinephonepro/default.nix b/pkgs/additional/linux-sane-pinephonepro/default.nix index ac02d4e83..a296b77bf 100644 --- a/pkgs/additional/linux-sane-pinephonepro/default.nix +++ b/pkgs/additional/linux-sane-pinephonepro/default.nix @@ -377,14 +377,17 @@ linux_latest.override { # } { # i'd like to patch some drivers, and that's easier to do when i build them for out-of-tree. + # i can't even set these to `=m`, because then nixpkgs `system.modulesTree` will complain + # about conflicting kernel modules (in tree + out-of-tree). + # so just don't build these here, and rely wholly on my out-of-tree modules. name = "make-module-for-out-of-tree"; patch = null; extraStructuredConfig = with lib.kernel; { # MFD_CORE = module; # MFD_ALTERA_SYSMGR = module; - MFD_RK8XX = module; - MFD_RK8XX_I2C = module; - MFD_RK8XX_SPI = module; #< necessary for MFD_RK8XX=m to apply + MFD_RK8XX = no; + MFD_RK8XX_I2C = no; + MFD_RK8XX_SPI = no; #< necessary for MFD_RK8XX=... to apply }; } ]; diff --git a/pkgs/additional/rk818-charger/Makefile b/pkgs/additional/rk818-charger/Makefile index dfb83f380..07c2cc782 100644 --- a/pkgs/additional/rk818-charger/Makefile +++ b/pkgs/additional/rk818-charger/Makefile @@ -3,7 +3,7 @@ obj-m := rk8xx-core.o rk8xx-i2c.o rk818_battery.o rk818_charger.o all: $(MAKE) -C "$(KERNEL_DIR)" M="$(PWD)" modules install: - install -D rk8xx-core.ko $(INSTALL_MOD_PATH)/mfd/rk8xx-core.ko - install -D rk8xx-i2c.ko $(INSTALL_MOD_PATH)/mfd/rk8xx-i2c.ko - install -D rk818_battery.ko $(INSTALL_MOD_PATH)/mfd/rk818_battery.ko - install -D rk818_charger.ko $(INSTALL_MOD_PATH)/mfd/rk818_charger.ko + install -Dm444 rk8xx-core.ko $(INSTALL_MOD_PATH)/drivers/mfd/rk8xx-core.ko + install -Dm444 rk8xx-i2c.ko $(INSTALL_MOD_PATH)/drivers/mfd/rk8xx-i2c.ko + install -Dm444 rk818_battery.ko $(INSTALL_MOD_PATH)/drivers/power/supply/rk818_battery.ko + install -Dm444 rk818_charger.ko $(INSTALL_MOD_PATH)/drivers/power/supply/rk818_charger.ko diff --git a/pkgs/additional/rk818-charger/default.nix b/pkgs/additional/rk818-charger/default.nix index 7944cc965..9f7f8cda2 100644 --- a/pkgs/additional/rk818-charger/default.nix +++ b/pkgs/additional/rk818-charger/default.nix @@ -7,8 +7,15 @@ # the former includes "rk817-charger", but nothing for the rk818. # the latter includes the PMIC, without mention of any battery/charger. # hmm... +# +# this package is part of the `linuxKernel.packagesFor ...` scope(s). +# build it e.g.: +# - `nix-build -A linuxPackages_6_11.rk818-charger` +# - `nix-build -A hosts.moby.config.boot.kernelPackages.rk818-charger` { - kernel ? linuxPackages_6_11.kernel, linuxPackages_6_11, + buildPackages, + kernel, + lib, stdenv, }: @@ -22,11 +29,24 @@ stdenv.mkDerivation { nativeBuildInputs = kernel.moduleBuildDependencies; makeFlags = [ - "KERNELRELEASE=${kernel.modDirVersion}" + # "KERNELRELEASE=${kernel.modDirVersion}" "KERNEL_DIR=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build" - "INSTALL_MOD_PATH=$(out)" + "INSTALL_MOD_PATH=$(out)/lib/modules/${kernel.modDirVersion}/kernel" + # from + "O=$(buildRoot)" + "CC=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc" + "HOSTCC=${buildPackages.stdenv.cc}/bin/${buildPackages.stdenv.cc.targetPrefix}cc" + "HOSTLD=${buildPackages.stdenv.cc.bintools}/bin/${buildPackages.stdenv.cc.targetPrefix}ld" + "ARCH=${stdenv.hostPlatform.linuxArch}" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "CROSS_COMPILE=${stdenv.cc.targetPrefix}" ]; + # the modules shipped in-tree are .xz, so if i want to replace those i need to also xz this module: + postInstall = '' + find $out -name '*.ko' -exec xz {} \; + ''; + # AFAICT the module names are really just the .o files. # i guess if you wanted a module with more than one file, # you would compile all their .c sources into one .o and add just that to `obj-m`? diff --git a/pkgs/default.nix b/pkgs/default.nix index 02ac2a990..aa906a8a1 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -14,6 +14,15 @@ let sane-data = import ../modules/data { inherit lib sane-lib; }; sane-lib = import ../modules/lib final'; + ### ADDITIONAL KERNEL PACKAGES + linuxKernel = unpatched.linuxKernel // { + packagesFor = kernel: (unpatched.linuxKernel.packagesFor kernel).extend (kFinal: kPrev: { + # build like `nix-build -A linuxPackages.rk818-charger` + # or `nix-build -A hosts.moby.config.boot.kernelPackages.rk818-charger` + rk818-charger = kFinal.callPackage ./additional/rk818-charger { }; + }); + }; + ### ADDITIONAL PACKAGES alsa-ucm-pinephone-manjaro = callPackage ./additional/alsa-ucm-pinephone-manjaro { }; alsa-ucm-pinephone-pmos = callPackage ./additional/alsa-ucm-pinephone-pmos { }; @@ -93,7 +102,6 @@ let pyln-client = callPackage ./additional/pyln-client { }; pyln-proto = callPackage ./additional/pyln-proto { }; qmkPackages = recurseIntoAttrs (callPackage ./additional/qmk-packages { }); - rk818-charger = callPackage ./additional/rk818-charger { }; rtl8723cs-firmware = callPackage ./additional/rtl8723cs-firmware { }; rtl8723cs-wowlan = callPackage ./additional/rtl8723cs-wowlan { }; sane-backgrounds = callPackage ./additional/sane-backgrounds { };