summaryrefslogtreecommitdiff
path: root/pkgs/os-specific/linux/device-tree/default.nix
blob: a40c2d7c355b697f5c2c1e1c903345aedd4beef2 (plain)
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
{
  lib,
  stdenv,
  stdenvNoCC,
  dtc,
  writers,
  python3,
}:

{
  # Compile single Device Tree overlay source
  # file (.dts) into its compiled variant (.dtb)
  compileDTS = (
    {
      name,
      dtsFile,
      includePaths ? [ ],
      extraPreprocessorFlags ? [ ],
    }:
    stdenv.mkDerivation {
      inherit name;

      nativeBuildInputs = [ dtc ];

      buildCommand =
        let
          includeFlagsStr = lib.concatMapStringsSep " " (includePath: "-I${includePath}") includePaths;
          extraPreprocessorFlagsStr = lib.concatStringsSep " " extraPreprocessorFlags;
        in
        ''
          $CC -E -nostdinc ${includeFlagsStr} -undef -D__DTS__ -x assembler-with-cpp ${extraPreprocessorFlagsStr} ${dtsFile} | \
          dtc -I dts -O dtb -@ -o $out
        '';
    }
  );

  applyOverlays = (
    base: overlays':
    stdenvNoCC.mkDerivation {
      name = "device-tree-overlays";
      nativeBuildInputs = [
        (python3.pythonOnBuildForHost.withPackages (ps: [ ps.libfdt ]))
      ];
      buildCommand = ''
        python ${./apply_overlays.py} --source ${base} --destination $out --overlays ${writers.writeJSON "overlays.json" overlays'}
      '';
    }
  );
}