1{ lib, stdenv, fetchgit, pkg-config, zlib, pciutils, openssl, coreutils, acpica-tools, makeWrapper, gnugrep, gnused, file, buildEnv }:
2
3let
4 version = "4.21";
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; [ 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 = fetchgit {
18 url = "https://review.coreboot.org/coreboot";
19 rev = "c1386ef6128922f49f93de5690ccd130a26eecf2";
20 sha256 = "sha256-n/bo3hoY7DEP103ftWu3uCLFXEsz+F9rWS22kcF7Ah8=";
21 };
22
23 enableParallelBuilding = true;
24
25 postPatch = ''
26 substituteInPlace 3rdparty/vboot/Makefile --replace 'ar qc ' '$$AR qc '
27 cd ${path}
28 patchShebangs .
29 '';
30
31 makeFlags = [
32 "INSTALL=install"
33 "PREFIX=${placeholder "out"}"
34 ];
35
36 meta = commonMeta // args.meta;
37 } // (removeAttrs args [ "meta" ]));
38
39 utils = {
40 msrtool = generic {
41 pname = "msrtool";
42 meta.description = "Dump chipset-specific MSR registers";
43 meta.platforms = [ "x86_64-linux" "i686-linux" ];
44 buildInputs = [ pciutils zlib ];
45 preConfigure = "export INSTALL=install";
46 };
47 cbmem = generic {
48 pname = "cbmem";
49 meta.description = "coreboot console log reader";
50 };
51 ifdtool = generic {
52 pname = "ifdtool";
53 meta.description = "Extract and dump Intel Firmware Descriptor information";
54 };
55 intelmetool = generic {
56 pname = "intelmetool";
57 meta.description = "Dump interesting things about Management Engine";
58 meta.platforms = [ "x86_64-linux" "i686-linux" ];
59 buildInputs = [ pciutils zlib ];
60 };
61 cbfstool = generic {
62 pname = "cbfstool";
63 meta.description = "Management utility for CBFS formatted ROM images";
64 };
65 nvramtool = generic {
66 pname = "nvramtool";
67 meta.description = "Read and write coreboot parameters and display information from the coreboot table in CMOS/NVRAM";
68 meta.mainProgram = "nvramtool";
69 };
70 superiotool = generic {
71 pname = "superiotool";
72 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";
73 meta.platforms = [ "x86_64-linux" "i686-linux" ];
74 buildInputs = [ pciutils zlib ];
75 };
76 ectool = generic {
77 pname = "ectool";
78 meta.description = "Dump the RAM of a laptop's Embedded/Environmental Controller (EC)";
79 meta.platforms = [ "x86_64-linux" "i686-linux" ];
80 preInstall = "mkdir -p $out/sbin";
81 };
82 inteltool = generic {
83 pname = "inteltool";
84 meta.description = "Provides information about Intel CPU/chipset hardware configuration (register contents, MSRs, etc)";
85 meta.platforms = [ "x86_64-linux" "i686-linux" ];
86 buildInputs = [ pciutils zlib ];
87 };
88 amdfwtool = generic {
89 pname = "amdfwtool";
90 meta.description = "Create AMD firmware combination";
91 buildInputs = [ openssl ];
92 nativeBuildInputs = [ pkg-config ];
93 installPhase = ''
94 runHook preInstall
95
96 install -Dm755 amdfwtool $out/bin/amdfwtool
97
98 runHook postInstall
99 '';
100 };
101 acpidump-all = generic {
102 pname = "acpidump-all";
103 path = "util/acpi";
104 meta.description = "Walk through all ACPI tables with their addresses";
105 nativeBuildInputs = [ makeWrapper ];
106 dontBuild = true;
107 installPhase = ''
108 runHook preInstall
109
110 install -Dm755 acpidump-all $out/bin/acpidump-all
111
112 runHook postInstall
113 '';
114 postFixup = ''
115 wrapProgram $out/bin/acpidump-all \
116 --set PATH ${lib.makeBinPath [ coreutils acpica-tools gnugrep gnused file ]}
117 '';
118 };
119 };
120
121in
122utils // {
123 coreboot-utils = (buildEnv {
124 name = "coreboot-utils-${version}";
125 paths = lib.filter (lib.meta.availableOn stdenv.hostPlatform) (lib.attrValues utils);
126 postBuild = "rm -rf $out/sbin";
127 }) // {
128 inherit version;
129 meta = commonMeta;
130 };
131}