3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/pkgs/applications/virtualization/OVMF/default.nix
Nikolay Amiantov c3a6c8de88 edk2: 2017-12-05 -> 201905
* Move to stable version;
* Refactor `setup` to `mkDerivation`;
* Use flags instead of `sed`;
* Support Secure Boot builds.
2019-08-19 19:52:30 +03:00

63 lines
1.8 KiB
Nix

{ stdenv, lib, edk2, utillinux, nasm, iasl
, csmSupport ? false, seabios ? null
, secureBoot ? false
}:
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 = (builtins.parseDrvName edk2.name).version;
in
edk2.mkDerivation projectDscPath {
name = "OVMF-${version}";
outputs = [ "out" "fd" ];
buildInputs = [ utillinux nasm iasl ];
hardeningDisable = [ "format" "stackprotector" "pic" "fortify" ];
buildFlags =
lib.optional secureBoot "-DSECURE_BOOT_ENABLE=TRUE"
++ lib.optionals csmSupport [ "-D CSM_ENABLE" "-D FD_SIZE_2MB" ];
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
# Uses Fedora dir layout: https://src.fedoraproject.org/cgit/rpms/edk2.git/tree/edk2.spec
# FIXME: why is it different from Debian dir layout? https://anonscm.debian.org/cgit/pkg-qemu/edk2.git/tree/debian/rules
dd of=$fd/AAVMF/QEMU_EFI-pflash.raw if=/dev/zero bs=1M count=64
dd of=$fd/AAVMF/QEMU_EFI-pflash.raw if=$fd/FV/QEMU_EFI.fd conv=notrunc
dd of=$fd/AAVMF/vars-template-pflash.raw if=/dev/zero bs=1M count=64
'' else ''
mkdir -vp $fd/FV
mv -v $out/FV/OVMF{,_CODE,_VARS}.fd $fd/FV
'';
dontPatchELF = true;
meta = {
description = "Sample UEFI firmware for QEMU and KVM";
homepage = https://github.com/tianocore/tianocore.github.io/wiki/OVMF;
license = stdenv.lib.licenses.bsd2;
platforms = ["x86_64-linux" "i686-linux" "aarch64-linux"];
};
}