-
Notifications
You must be signed in to change notification settings - Fork 2
/
coreboot.nix
97 lines (91 loc) · 3.24 KB
/
coreboot.nix
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
{ stdenv, fetchgit, bc, ncurses, m4, bison, flex, zlib
, lib
, iasl
, buildEnv
, pkgconfig
, pkgsCross
, python3
, rsync
, u-boot }:
let
crossTools = set: [
set.stdenv.cc
set.buildPackages.nasm
set.buildPackages.binutils
set.buildPackages.gcc-unwrapped
];
arm32 = pkgsCross.armv7l-hf-multiplatform;
arm64 = pkgsCross.aarch64-multiplatform;
crossEnv = buildEnv {
name = "coreboot-crossenv";
paths = crossTools arm64 ++ crossTools arm32 ++ [ pkgsCross.arm-embedded.stdenv.cc ];
pathsToLink = ["/bin"];
ignoreCollisions = true;
};
tool_gcc = tool: set: "${set.stdenv.cc}/bin/${set.stdenv.cc.targetPrefix}${tool}";
tool_binutils = tool: set: "${set.buildPackages.binutils-unwrapped}/bin/${set.stdenv.cc.targetPrefix}${tool}";
makeVars = arch: set: [
"CC_${arch}=${tool_gcc "cc" set}"
"LD_${arch}=${tool_gcc "ld" set}"
"OBJCOPY_${arch}=${tool_binutils "objcopy" set}"
"OBJDUMP_${arch}=${tool_binutils "objdump" set}"
"NM_${arch}=${tool_binutils "nm" set}"
"AR_${arch}=${tool_binutils "ar" set}"
];
atfSource = fetchgit {
url = "https://review.coreboot.org/arm-trusted-firmware.git";
rev = "v2.5";
sha256 = "0w3blkqgmyb5bahlp04hmh8abrflbzy0qg83kmj1x9nv4mw66f3b";
};
vbootSource = fetchgit {
url = "https://review.coreboot.org/vboot.git";
rev = "4e982f1c39da417100e4021fb1c2c370da5f8dd6"; # master 2021-06-15
sha256 = "1fr35gh4c81gb75q6zpf4v9hnvk74ppzdww54fhrr28ahzd73qi6";
};
in stdenv.mkDerivation {
name = "coreboot-4.11-${u-boot.pname}";
src = fetchgit {
url = "https://review.coreboot.org/coreboot.git";
rev = "4.14";
sha256 = "06y46bjzkmps84dk5l2ywjcxmsxmqak5cr7sf18s5zv1pm566pqa";
fetchSubmodules = false;
};
nativeBuildInputs = [ m4 bison flex bc iasl rsync python3 pkgconfig ];
buildInputs = [ zlib ];
makeFlags = makeVars "arm" arm32 ++ makeVars "arm64" arm64 ++ [
"CROSS_COMPILE_arm64=${arm64.stdenv.cc.targetPrefix}"
"CROSS_COMPILE_arm=${arm32.stdenv.cc.targetPrefix}"
];
postPatch = ''
patchShebangs util/xcompile
patchShebangs util/rockchip/make_idb.py
patchShebangs util/genbuild_h/genbuild_h.sh
'';
configurePhase = ''
runHook preConfigure
export PATH="${crossEnv}/bin:$PATH"
export ARCH=aarch64
export CPUS=$NIX_BUILD_CORES
grep -v -e 'CONFIG_PAYLOAD_FILE' ${./coreboot.config} > .config
cat >>.config <<EOF
CONFIG_PAYLOAD_FILE=${u-boot}/u-boot-dtb.bin
EOF
rm -r 3rdparty/arm-trusted-firmware
cp -r ${atfSource}/ 3rdparty/arm-trusted-firmware
chmod -R u+w 3rdparty/arm-trusted-firmware
rm -r 3rdparty/vboot
cp -r ${vbootSource} 3rdparty/vboot
chmod -R u+w 3rdparty/vboot
sed -i 's/-Wno-unknown-warning//' 3rdparty/vboot/Makefile
export NIX_CFLAGS_COMPILE_aarch64_unknown_linux_gnu=-Wno-error=address-of-packed-member\ -Wno-error=format-truncation\ -Wno-error=int-conversion
export NIX_CFLAGS_COMPILE=-Wno-error=format-truncation
runHook postConfigure
'';
enableParallelBuilding = true;
installPhase = ''
./build/cbfstool build/coreboot.rom remove -n fallback/payload
./build/cbfstool build/coreboot.rom add-flat-binary -f ${u-boot}/u-boot-dtb.bin -n fallback/payload -l 0x00a00000 -e 0x00a00000
mkdir $out
cp build/coreboot.rom $out
'';
}