at 22.05-pre 69 lines 2.2 kB view raw
1{ stdenv, lib, edk2, util-linux, nasm, acpica-tools 2, csmSupport ? false, seabios ? null 3, secureBoot ? false 4, httpSupport ? false 5, tpmSupport ? false 6}: 7 8assert csmSupport -> seabios != null; 9 10let 11 12 projectDscPath = if stdenv.isi686 then 13 "OvmfPkg/OvmfPkgIa32.dsc" 14 else if stdenv.isx86_64 then 15 "OvmfPkg/OvmfPkgX64.dsc" 16 else if stdenv.isAarch64 then 17 "ArmVirtPkg/ArmVirtQemu.dsc" 18 else 19 throw "Unsupported architecture"; 20 21 version = lib.getVersion edk2; 22in 23 24edk2.mkDerivation projectDscPath { 25 name = "OVMF-${version}"; 26 27 outputs = [ "out" "fd" ]; 28 29 buildInputs = [ util-linux nasm acpica-tools ]; 30 31 hardeningDisable = [ "format" "stackprotector" "pic" "fortify" ]; 32 33 buildFlags = 34 lib.optionals secureBoot [ "-D SECURE_BOOT_ENABLE=TRUE" ] 35 ++ lib.optionals csmSupport [ "-D CSM_ENABLE" "-D FD_SIZE_2MB" ] 36 ++ lib.optionals httpSupport [ "-D NETWORK_HTTP_ENABLE=TRUE" "-D NETWORK_HTTP_BOOT_ENABLE=TRUE" ] 37 ++ lib.optionals tpmSupport [ "-D TPM_ENABLE" "-D TPM2_ENABLE" "-D TPM2_CONFIG_ENABLE"]; 38 39 postPatch = lib.optionalString csmSupport '' 40 cp ${seabios}/Csm16.bin OvmfPkg/Csm/Csm16/Csm16.bin 41 ''; 42 43 postFixup = if stdenv.isAarch64 then '' 44 mkdir -vp $fd/FV 45 mkdir -vp $fd/AAVMF 46 mv -v $out/FV/QEMU_{EFI,VARS}.fd $fd/FV 47 48 # Use Debian dir layout: https://salsa.debian.org/qemu-team/edk2/blob/debian/debian/rules 49 dd of=$fd/FV/AAVMF_CODE.fd if=/dev/zero bs=1M count=64 50 dd of=$fd/FV/AAVMF_CODE.fd if=$fd/FV/QEMU_EFI.fd conv=notrunc 51 dd of=$fd/FV/AAVMF_VARS.fd if=/dev/zero bs=1M count=64 52 53 # Also add symlinks for Fedora dir layout: https://src.fedoraproject.org/cgit/rpms/edk2.git/tree/edk2.spec 54 ln -s $fd/FV/AAVMF_CODE.fd $fd/AAVMF/QEMU_EFI-pflash.raw 55 ln -s $fd/FV/AAVMF_VARS.fd $fd/AAVMF/vars-template-pflash.raw 56 '' else '' 57 mkdir -vp $fd/FV 58 mv -v $out/FV/OVMF{,_CODE,_VARS}.fd $fd/FV 59 ''; 60 61 dontPatchELF = true; 62 63 meta = { 64 description = "Sample UEFI firmware for QEMU and KVM"; 65 homepage = "https://github.com/tianocore/tianocore.github.io/wiki/OVMF"; 66 license = lib.licenses.bsd2; 67 platforms = ["x86_64-linux" "i686-linux" "aarch64-linux" "x86_64-darwin"]; 68 }; 69}