2022-09-09 14:08:57 +00:00
|
|
|
{ stdenv, nixosTests, lib, edk2, util-linux, nasm, acpica-tools
|
2020-04-24 23:36:52 +00:00
|
|
|
, csmSupport ? false, seabios ? null
|
|
|
|
, secureBoot ? false
|
2021-02-17 17:02:09 +00:00
|
|
|
, httpSupport ? false
|
2021-10-17 02:12:59 +00:00
|
|
|
, tpmSupport ? false
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
assert csmSupport -> seabios != null;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
projectDscPath = if stdenv.isi686 then
|
|
|
|
"OvmfPkg/OvmfPkgIa32.dsc"
|
|
|
|
else if stdenv.isx86_64 then
|
|
|
|
"OvmfPkg/OvmfPkgX64.dsc"
|
|
|
|
else if stdenv.isAarch64 then
|
|
|
|
"ArmVirtPkg/ArmVirtQemu.dsc"
|
|
|
|
else
|
|
|
|
throw "Unsupported architecture";
|
|
|
|
|
|
|
|
version = lib.getVersion edk2;
|
2022-09-09 14:08:57 +00:00
|
|
|
|
|
|
|
suffixes = {
|
|
|
|
x86_64 = "FV/OVMF";
|
|
|
|
aarch64 = "FV/AAVMF";
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
in
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
edk2.mkDerivation projectDscPath (finalAttrs: {
|
2022-03-30 09:31:56 +00:00
|
|
|
pname = "OVMF";
|
|
|
|
inherit version;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
outputs = [ "out" "fd" ];
|
|
|
|
|
2022-06-16 17:23:12 +00:00
|
|
|
nativeBuildInputs = [ util-linux nasm acpica-tools ];
|
|
|
|
strictDeps = true;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
hardeningDisable = [ "format" "stackprotector" "pic" "fortify" ];
|
|
|
|
|
|
|
|
buildFlags =
|
2021-12-06 16:07:01 +00:00
|
|
|
lib.optionals secureBoot [ "-D SECURE_BOOT_ENABLE=TRUE" ]
|
2021-02-17 17:02:09 +00:00
|
|
|
++ lib.optionals csmSupport [ "-D CSM_ENABLE" "-D FD_SIZE_2MB" ]
|
2021-10-17 02:12:59 +00:00
|
|
|
++ lib.optionals httpSupport [ "-D NETWORK_HTTP_ENABLE=TRUE" "-D NETWORK_HTTP_BOOT_ENABLE=TRUE" ]
|
|
|
|
++ lib.optionals tpmSupport [ "-D TPM_ENABLE" "-D TPM2_ENABLE" "-D TPM2_CONFIG_ENABLE"];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
postPatch = lib.optionalString csmSupport ''
|
|
|
|
cp ${seabios}/Csm16.bin OvmfPkg/Csm/Csm16/Csm16.bin
|
|
|
|
'';
|
|
|
|
|
|
|
|
postFixup = if stdenv.isAarch64 then ''
|
|
|
|
mkdir -vp $fd/FV
|
|
|
|
mkdir -vp $fd/AAVMF
|
|
|
|
mv -v $out/FV/QEMU_{EFI,VARS}.fd $fd/FV
|
|
|
|
|
2020-07-18 16:06:22 +00:00
|
|
|
# Use Debian dir layout: https://salsa.debian.org/qemu-team/edk2/blob/debian/debian/rules
|
|
|
|
dd of=$fd/FV/AAVMF_CODE.fd if=/dev/zero bs=1M count=64
|
|
|
|
dd of=$fd/FV/AAVMF_CODE.fd if=$fd/FV/QEMU_EFI.fd conv=notrunc
|
|
|
|
dd of=$fd/FV/AAVMF_VARS.fd if=/dev/zero bs=1M count=64
|
|
|
|
|
|
|
|
# Also add symlinks for Fedora dir layout: https://src.fedoraproject.org/cgit/rpms/edk2.git/tree/edk2.spec
|
|
|
|
ln -s $fd/FV/AAVMF_CODE.fd $fd/AAVMF/QEMU_EFI-pflash.raw
|
|
|
|
ln -s $fd/FV/AAVMF_VARS.fd $fd/AAVMF/vars-template-pflash.raw
|
2020-04-24 23:36:52 +00:00
|
|
|
'' else ''
|
|
|
|
mkdir -vp $fd/FV
|
|
|
|
mv -v $out/FV/OVMF{,_CODE,_VARS}.fd $fd/FV
|
|
|
|
'';
|
|
|
|
|
|
|
|
dontPatchELF = true;
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
passthru =
|
|
|
|
let
|
|
|
|
cpuName = stdenv.hostPlatform.parsed.cpu.name;
|
|
|
|
suffix = suffixes."${cpuName}" or (throw "Host cpu name `${cpuName}` is not supported in this OVMF derivation!");
|
|
|
|
prefix = "${finalAttrs.finalPackage.fd}/${suffix}";
|
|
|
|
in {
|
|
|
|
firmware = "${prefix}_CODE.fd";
|
|
|
|
variables = "${prefix}_VARS.fd";
|
|
|
|
# This will test the EFI firmware for the host platform as part of the NixOS Tests setup.
|
|
|
|
tests.basic-systemd-boot = nixosTests.systemd-boot.basic;
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
meta = {
|
|
|
|
description = "Sample UEFI firmware for QEMU and KVM";
|
|
|
|
homepage = "https://github.com/tianocore/tianocore.github.io/wiki/OVMF";
|
2021-01-15 22:18:51 +00:00
|
|
|
license = lib.licenses.bsd2;
|
2020-05-15 21:57:56 +00:00
|
|
|
platforms = ["x86_64-linux" "i686-linux" "aarch64-linux" "x86_64-darwin"];
|
2022-09-09 14:08:57 +00:00
|
|
|
maintainers = [ lib.maintainers.raitobezarius ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2022-09-09 14:08:57 +00:00
|
|
|
})
|