summary refs log tree commit diff
path: root/pkgs/os-specific/linux/firmware/facetimehd-calibration/default.nix
blob: 86a3924c0e28bcee92c180a2053d5868e13cb9e5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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; [ alexshpilkin womfoo grahamc ];
    platforms = [ "i686-linux" "x86_64-linux" ];
  };

}