diff options
author | Graham Christensen <graham@grahamc.com> | 2022-04-29 15:53:30 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-29 15:53:30 -0400 |
commit | f00109472a78ec3e59819d870c22be5c0069db61 (patch) | |
tree | 3cdd2bf1e9e9e024ac3224d32544f357bbc505cd | |
parent | a7caefa4c0d0672108db1514fa693802930ef6b4 (diff) | |
parent | 0d233ebed02d41aeef53e1c35b596baa20ce9c31 (diff) | |
download | nixpkgs-f00109472a78ec3e59819d870c22be5c0069db61.tar nixpkgs-f00109472a78ec3e59819d870c22be5c0069db61.tar.gz nixpkgs-f00109472a78ec3e59819d870c22be5c0069db61.tar.bz2 nixpkgs-f00109472a78ec3e59819d870c22be5c0069db61.tar.lz nixpkgs-f00109472a78ec3e59819d870c22be5c0069db61.tar.xz nixpkgs-f00109472a78ec3e59819d870c22be5c0069db61.tar.zst nixpkgs-f00109472a78ec3e59819d870c22be5c0069db61.zip |
Merge pull request #164185 from alexshpilkin/calibration
facetimehd: support sensor calibration files
-rw-r--r-- | nixos/modules/hardware/all-firmware.nix | 5 | ||||
-rw-r--r-- | nixos/modules/hardware/video/webcam/facetimehd.nix | 15 | ||||
-rw-r--r-- | pkgs/os-specific/linux/firmware/facetimehd-calibration/default.nix | 62 | ||||
-rw-r--r-- | pkgs/top-level/all-packages.nix | 2 |
4 files changed, 82 insertions, 2 deletions
diff --git a/nixos/modules/hardware/all-firmware.nix b/nixos/modules/hardware/all-firmware.nix index 74678416a15..176056d0a91 100644 --- a/nixos/modules/hardware/all-firmware.nix +++ b/nixos/modules/hardware/all-firmware.nix @@ -85,7 +85,10 @@ in { b43Firmware_6_30_163_46 b43FirmwareCutter xow_dongle-firmware - ] ++ optional pkgs.stdenv.hostPlatform.isx86 facetimehd-firmware; + ] ++ optionals pkgs.stdenv.hostPlatform.isx86 [ + facetimehd-calibration + facetimehd-firmware + ]; }) (mkIf cfg.wirelessRegulatoryDatabase { hardware.firmware = [ pkgs.wireless-regdb ]; diff --git a/nixos/modules/hardware/video/webcam/facetimehd.nix b/nixos/modules/hardware/video/webcam/facetimehd.nix index b13f103350e..c48eac5e9c1 100644 --- a/nixos/modules/hardware/video/webcam/facetimehd.nix +++ b/nixos/modules/hardware/video/webcam/facetimehd.nix @@ -14,6 +14,18 @@ in options.hardware.facetimehd.enable = mkEnableOption "facetimehd kernel module"; + options.hardware.facetimehd.withCalibration = mkOption { + default = false; + example = true; + type = types.bool; + description = '' + Whether to include sensor calibration files for facetimehd. + This makes colors look much better but is experimental, see + <link xlink:href="https://github.com/patjak/facetimehd/wiki/Extracting-the-sensor-calibration-files"/> + for details. + ''; + }; + config = mkIf cfg.enable { boot.kernelModules = [ "facetimehd" ]; @@ -22,7 +34,8 @@ in boot.extraModulePackages = [ kernelPackages.facetimehd ]; - hardware.firmware = [ pkgs.facetimehd-firmware ]; + hardware.firmware = [ pkgs.facetimehd-firmware ] + ++ optional cfg.withCalibration pkgs.facetimehd-calibration; # unload module during suspend/hibernate as it crashes the whole system powerManagement.powerDownCommands = '' diff --git a/pkgs/os-specific/linux/firmware/facetimehd-calibration/default.nix b/pkgs/os-specific/linux/firmware/facetimehd-calibration/default.nix new file mode 100644 index 00000000000..5152b3dfe71 --- /dev/null +++ b/pkgs/os-specific/linux/firmware/facetimehd-calibration/default.nix @@ -0,0 +1,62 @@ +{ lib, stdenv, fetchurl, unrar-wrapper, pkgs }: + +let + + version = "5.1.5769"; + + + # Described on https://github.com/patjak/facetimehd/wiki/Extracting-the-sensor-calibration-files + + # From the wiki page, range extracted with binwalk: + zipUrl = "https://download.info.apple.com/Mac_OS_X/031-30890-20150812-ea191174-4130-11e5-a125-930911ba098f/bootcamp${version}.zip"; + zipRange = "2338085-3492508"; # the whole download is 518MB, this deflate stream is 1.2MB + + # CRC and length from the ZIP entry header (not strictly necessary, but makes it extract cleanly): + gzFooter = ''\x51\x1f\x86\x78\xcf\x5b\x12\x00''; + + # Also from the wiki page: + calibrationFiles = [ + { file = "1771_01XX.dat"; offset = "1644880"; size = "19040"; } + { file = "1871_01XX.dat"; offset = "1606800"; size = "19040"; } + { file = "1874_01XX.dat"; offset = "1625840"; size = "19040"; } + { file = "9112_01XX.dat"; offset = "1663920"; size = "33060"; } + ]; + +in + +stdenv.mkDerivation { + + pname = "facetimehd-calibration"; + inherit version; + src = fetchurl { + url = zipUrl; + sha256 = "1dzyv457fp6d8ly29sivqn6llwj5ydygx7p8kzvdnsp11zvid2xi"; + curlOpts = "-r ${zipRange}"; + }; + + dontUnpack = true; + dontInstall = true; + + buildInputs = [ unrar-wrapper ]; + + buildPhase = '' + { printf '\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x00' + cat $src + printf '${gzFooter}' + } | zcat > AppleCamera64.exe + unrar x AppleCamera64.exe AppleCamera.sys + + mkdir -p $out/lib/firmware/facetimehd + '' + lib.concatMapStrings ({file, offset, size}: '' + dd bs=1 skip=${offset} count=${size} if=AppleCamera.sys of=$out/lib/firmware/facetimehd/${file} + '') calibrationFiles; + + meta = with lib; { + description = "facetimehd calibration"; + homepage = "https://support.apple.com/kb/DL1837"; + license = licenses.unfree; + maintainers = with maintainers; [ womfoo grahamc ]; + platforms = [ "i686-linux" "x86_64-linux" ]; + }; + +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 0b091de97ea..bd01fc2dd2d 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -22907,6 +22907,8 @@ with pkgs; extrace = callPackage ../os-specific/linux/extrace { }; + facetimehd-calibration = callPackage ../os-specific/linux/firmware/facetimehd-calibration { }; + facetimehd-firmware = callPackage ../os-specific/linux/firmware/facetimehd-firmware { }; fatrace = callPackage ../os-specific/linux/fatrace { }; |