summary refs log tree commit diff
path: root/pkgs/misc/barebox/default.nix
blob: 78d4228abb3bd1b78302fbba804b5be91d92d527 (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
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
{ stdenv
, lib
, fetchurl
, bison
, dtc
, flex
, libusb1
, lzop
, openssl
, pkgconfig
, buildPackages
}:

let
  buildBarebox = {
    filesToInstall
  , installDir ? "$out"
  , defconfig
  , extraMeta ? {}
  , ... } @ args: stdenv.mkDerivation rec {
    pname = "barebox-${defconfig}";

    version = "2020.12.0";

    src = fetchurl {
      url = "https://www.barebox.org/download/barebox-${version}.tar.bz2";
      sha256 = "06vsd95ihaa2nywpqy6k0c7xwk2pzws4yvbp328yd2pfiigachrv";
    };

    postPatch = ''
      patchShebangs scripts
    '';

    nativeBuildInputs = [
      bison
      dtc
      flex
      openssl
      libusb1
      lzop
      pkgconfig
    ];
    depsBuildBuild = [ buildPackages.stdenv.cc ];

    hardeningDisable = [ "all" ];

    makeFlags = [
      "DTC=dtc"
      "CROSS_COMPILE=${stdenv.cc.targetPrefix}"
    ];

    configurePhase = ''
      runHook preConfigure

      make ${defconfig}

      runHook postConfigure
    '';

    installPhase = ''
      runHook preInstall

      mkdir -p ${installDir}
      cp ${lib.concatStringsSep " " filesToInstall} ${installDir}

      runHook postInstall
    '';

    enableParallelBuilding = true;

    dontStrip = true;

    meta = with lib; {
      homepage = "https://www.barebox.org";
      description = "The Swiss Army Knive for bare metal";
      license = licenses.gpl2;
      maintainers = with maintainers; [ emantor ];
    } // extraMeta;
  } // removeAttrs args [ "extraMeta" ];

in {
  inherit buildBarebox;

  bareboxTools = buildBarebox {
    defconfig = "hosttools_defconfig";
    installDir = "$out/bin";
    extraMeta.platforms = lib.platforms.linux;
    filesToInstall = [
      "scripts/bareboximd"
      "scripts/imx/imx-usb-loader"
      "scripts/omap4_usbboot"
      "scripts/omap3-usb-loader"
      "scripts/kwboot"
    ];
  };
}