1{ lib, stdenv, fetchurl, zlib, pciutils, coreutils, acpica-tools, makeWrapper, gnugrep, gnused, file, buildEnv }:
2
3let
4 version = "4.14";
5
6 commonMeta = with lib; {
7 description = "Various coreboot-related tools";
8 homepage = "https://www.coreboot.org";
9 license = with licenses; [ gpl2Only gpl2Plus ];
10 maintainers = with maintainers; [ petabyteboy felixsinger yuka ];
11 platforms = platforms.linux;
12 };
13
14 generic = { pname, path ? "util/${pname}", ... }@args: stdenv.mkDerivation (rec {
15 inherit pname version;
16
17 src = fetchurl {
18 url = "https://coreboot.org/releases/coreboot-${version}.tar.xz";
19 sha256 = "0viw2x4ckjwiylb92w85k06b0g9pmamjy2yqs7fxfqbmfadkf1yr";
20 };
21
22 enableParallelBuilding = true;
23
24 postPatch = ''
25 cd ${path}
26 patchShebangs .
27 '';
28
29 makeFlags = [
30 "INSTALL=install"
31 "PREFIX=${placeholder "out"}"
32 ];
33
34 meta = commonMeta // args.meta;
35 } // (removeAttrs args ["meta"]));
36
37 utils = {
38 msrtool = generic {
39 pname = "msrtool";
40 meta.description = "Dump chipset-specific MSR registers";
41 buildInputs = [ pciutils zlib ];
42 preConfigure = "export INSTALL=install";
43 };
44 cbmem = generic {
45 pname = "cbmem";
46 meta.description = "coreboot console log reader";
47 };
48 ifdtool = generic {
49 pname = "ifdtool";
50 meta.description = "Extract and dump Intel Firmware Descriptor information";
51 };
52 intelmetool = generic {
53 pname = "intelmetool";
54 meta.description = "Dump interesting things about Management Engine";
55 buildInputs = [ pciutils zlib ];
56 };
57 cbfstool = generic {
58 pname = "cbfstool";
59 meta.description = "Management utility for CBFS formatted ROM images";
60 };
61 nvramtool = generic {
62 pname = "nvramtool";
63 meta.description = "Read and write coreboot parameters and display information from the coreboot table in CMOS/NVRAM";
64 };
65 superiotool = generic {
66 pname = "superiotool";
67 meta.description = "User-space utility to detect Super I/O of a mainboard and provide detailed information about the register contents of the Super I/O";
68 buildInputs = [ pciutils zlib ];
69 };
70 ectool = generic {
71 pname = "ectool";
72 meta.description = "Dump the RAM of a laptop's Embedded/Environmental Controller (EC)";
73 meta.platforms = [ "x86_64-linux" "i686-linux" ];
74 preInstall = "mkdir -p $out/sbin";
75 };
76 inteltool = generic {
77 pname = "inteltool";
78 meta.description = "Provides information about Intel CPU/chipset hardware configuration (register contents, MSRs, etc)";
79 buildInputs = [ pciutils zlib ];
80 };
81 amdfwtool = generic {
82 pname = "amdfwtool";
83 meta.description = "Create AMD firmware combination";
84 installPhase = ''
85 runHook preInstall
86
87 install -Dm755 amdfwtool $out/bin/amdfwtool
88
89 runHook postInstall
90 '';
91 };
92 acpidump-all = generic {
93 pname = "acpidump-all";
94 path = "util/acpi";
95 meta.description = "Walk through all ACPI tables with their addresses";
96 nativeBuildInputs = [ makeWrapper ];
97 dontBuild = true;
98 installPhase = ''
99 runHook preInstall
100
101 install -Dm755 acpidump-all $out/bin/acpidump-all
102
103 runHook postInstall
104 '';
105 postFixup = let
106 binPath = [ coreutils acpica-tools gnugrep gnused file ];
107 in "wrapProgram $out/bin/acpidump-all --set PATH ${lib.makeBinPath binPath}";
108 };
109 };
110
111in utils // {
112 coreboot-utils = (buildEnv {
113 name = "coreboot-utils-${version}";
114 paths = lib.attrValues utils;
115 postBuild = "rm -rf $out/sbin";
116 }) // {
117 inherit version;
118 meta = commonMeta;
119 };
120}