summaryrefslogtreecommitdiff
path: root/pkgs/misc/uboot/python.nix
blob: dc81ec04f37ff8a6158918d32a6f31bf3629e1f5 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
{
  lib,
  python3Packages,
  fetchPypi,
  makeWrapper,

  armTrustedFirmwareTools,
  bzip2,
  cbfstool,
  gzip,
  lz4,
  lzop,
  openssl,
  ubootTools,
  vboot-utils,
  xilinx-bootgen,
  xz,
  zstd,
}:

let
  # We are fetching from PyPI because the code in the repository seems to be
  # lagging behind the PyPI releases somehow...
  version = "0.0.7";
in
rec {

  u_boot_pylib = python3Packages.buildPythonPackage rec {
    pname = "u_boot_pylib";
    inherit version;
    pyproject = true;

    src = fetchPypi {
      inherit pname version;
      hash = "sha256-A5r20Y8mgxhOhaKMpd5MJN5ubzPbkodAO0Tr0RN1SRA=";
    };

    build-system = with python3Packages; [
      setuptools
    ];

    checkPhase = ''
      ${python3Packages.python.interpreter} "src/$pname/__main__.py"
      # There are some tests in other files, but they are broken
    '';

    pythonImportsCheck = [ "u_boot_pylib" ];
  };

  dtoc = python3Packages.buildPythonPackage rec {
    pname = "dtoc";
    inherit version;
    pyproject = true;

    src = fetchPypi {
      inherit pname version;
      hash = "sha256-NA96CznIxjqpw2Ik8AJpJkJ/ei+kQTCUExwFgssV+CM=";
    };

    build-system = with python3Packages; [
      setuptools
    ];

    dependencies =
      (with python3Packages; [
        libfdt
      ])
      ++ [
        u_boot_pylib
      ];

    pythonImportsCheck = [ "dtoc" ];
  };

  binman =
    let
      btools = [
        armTrustedFirmwareTools
        bzip2
        cbfstool
        # TODO: cst
        gzip
        lz4
        # TODO: lzma_alone
        lzop
        openssl
        ubootTools
        vboot-utils
        xilinx-bootgen
        xz
        zstd
      ];
    in
    python3Packages.buildPythonApplication rec {
      pname = "binary_manager";
      inherit version;
      pyproject = true;

      src = fetchPypi {
        inherit pname version;
        hash = "sha256-llEBBhUoW5jTEQeoaTCjZN8y6Kj+PGNUSB3cKpgD06w=";
      };

      patches = [
        ./binman-resources.patch
      ];
      patchFlags = [
        "-p2"
        "-d"
        "src"
      ];

      build-system = with python3Packages; [
        setuptools
      ];

      nativeBuildInputs = [ makeWrapper ];

      dependencies =
        (with python3Packages; [
          jsonschema
          pycryptodomex
          pyelftools
          yamllint
        ])
        ++ [
          dtoc
          u_boot_pylib
        ];

      preFixup = ''
        wrapProgram "$out/bin/binman" --prefix PATH : "${lib.makeBinPath btools}"
      '';
    };

  patman = python3Packages.buildPythonApplication rec {
    pname = "patch_manager";
    inherit version;
    pyproject = true;

    src = fetchPypi {
      inherit pname version;
      hash = "sha256-zD9e87fpWKynpUcfxobbdk6wbM6Ja3f8hEVHS7DGIKQ=";
    };

    build-system = with python3Packages; [
      setuptools
    ];

    dependencies =
      (with python3Packages; [
        aiohttp
        pygit2
      ])
      ++ [
        u_boot_pylib
      ];
  };

}