2022-11-07 01:36:57 +01:00
|
|
|
{ stdenv, nixosTests, lib, edk2, util-linux, nasm, acpica-tools, llvmPackages
|
2023-11-29 20:17:01 +01:00
|
|
|
, csmSupport ? false, seabios
|
2023-07-19 15:07:19 +02:00
|
|
|
, fdSize2MB ? csmSupport
|
|
|
|
, fdSize4MB ? false
|
2019-07-15 16:35:30 +02:00
|
|
|
, secureBoot ? false
|
2021-02-16 01:34:59 +01:00
|
|
|
, httpSupport ? false
|
2021-10-11 08:28:39 +02:00
|
|
|
, tpmSupport ? false
|
2023-04-26 18:31:19 +02:00
|
|
|
, tlsSupport ? false
|
2023-04-26 18:31:57 +02:00
|
|
|
, debug ? false
|
2023-11-25 12:49:21 +01:00
|
|
|
# Usually, this option is broken, do not use it except if you know what you are
|
|
|
|
# doing.
|
|
|
|
, sourceDebug ? false
|
2019-07-15 16:35:30 +02:00
|
|
|
}:
|
|
|
|
|
2012-03-14 08:29:11 +01:00
|
|
|
let
|
|
|
|
|
2018-03-14 16:37:49 +01:00
|
|
|
projectDscPath = if stdenv.isi686 then
|
|
|
|
"OvmfPkg/OvmfPkgIa32.dsc"
|
2012-03-14 08:29:11 +01:00
|
|
|
else if stdenv.isx86_64 then
|
2018-03-14 16:37:49 +01:00
|
|
|
"OvmfPkg/OvmfPkgX64.dsc"
|
2023-01-02 04:31:18 +01:00
|
|
|
else if stdenv.hostPlatform.isAarch then
|
2018-03-14 16:37:49 +01:00
|
|
|
"ArmVirtPkg/ArmVirtQemu.dsc"
|
2023-11-25 13:12:30 +01:00
|
|
|
else if stdenv.hostPlatform.isRiscV then
|
|
|
|
"OvmfPkg/RiscVVirt/RiscVVirtQemu.dsc"
|
2012-03-14 08:29:11 +01:00
|
|
|
else
|
|
|
|
throw "Unsupported architecture";
|
|
|
|
|
2019-11-24 18:22:28 +01:00
|
|
|
version = lib.getVersion edk2;
|
2022-08-22 16:15:40 +02:00
|
|
|
|
|
|
|
suffixes = {
|
2022-12-29 21:28:40 +01:00
|
|
|
i686 = "FV/OVMF";
|
2022-08-22 16:15:40 +02:00
|
|
|
x86_64 = "FV/OVMF";
|
|
|
|
aarch64 = "FV/AAVMF";
|
|
|
|
};
|
|
|
|
|
2012-03-14 08:29:11 +01:00
|
|
|
in
|
|
|
|
|
2022-08-22 16:15:40 +02:00
|
|
|
edk2.mkDerivation projectDscPath (finalAttrs: {
|
2022-03-07 12:37:20 +01:00
|
|
|
pname = "OVMF";
|
|
|
|
inherit version;
|
2012-03-14 07:57:58 +01:00
|
|
|
|
2017-05-18 12:46:14 +02:00
|
|
|
outputs = [ "out" "fd" ];
|
|
|
|
|
2022-11-07 01:36:57 +01:00
|
|
|
nativeBuildInputs = [ util-linux nasm acpica-tools ]
|
|
|
|
++ lib.optionals stdenv.cc.isClang [ llvmPackages.bintools llvmPackages.llvm ];
|
2022-05-14 14:00:00 +02:00
|
|
|
strictDeps = true;
|
2016-02-09 00:18:03 +01:00
|
|
|
|
2019-07-15 16:35:30 +02:00
|
|
|
hardeningDisable = [ "format" "stackprotector" "pic" "fortify" ];
|
2017-05-29 12:20:05 +02:00
|
|
|
|
2019-07-15 16:35:30 +02:00
|
|
|
buildFlags =
|
2023-04-26 18:30:32 +02:00
|
|
|
# IPv6 has no reason to be disabled.
|
|
|
|
[ "-D NETWORK_IP6_ENABLE=TRUE" ]
|
2023-04-26 18:31:57 +02:00
|
|
|
++ lib.optionals debug [ "-D DEBUG_ON_SERIAL_PORT=TRUE" ]
|
|
|
|
++ lib.optionals sourceDebug [ "-D SOURCE_DEBUG_ENABLE=TRUE" ]
|
2023-04-26 18:30:32 +02:00
|
|
|
++ lib.optionals secureBoot [ "-D SECURE_BOOT_ENABLE=TRUE" ]
|
2023-07-19 15:07:19 +02:00
|
|
|
++ lib.optionals csmSupport [ "-D CSM_ENABLE" ]
|
|
|
|
++ lib.optionals fdSize2MB ["-D FD_SIZE_2MB"]
|
|
|
|
++ lib.optionals fdSize4MB ["-D FD_SIZE_4MB"]
|
2021-10-11 08:28:39 +02:00
|
|
|
++ lib.optionals httpSupport [ "-D NETWORK_HTTP_ENABLE=TRUE" "-D NETWORK_HTTP_BOOT_ENABLE=TRUE" ]
|
2023-04-26 18:31:19 +02:00
|
|
|
++ lib.optionals tlsSupport [ "-D NETWORK_TLS_ENABLE=TRUE" ]
|
2021-10-11 08:28:39 +02:00
|
|
|
++ lib.optionals tpmSupport [ "-D TPM_ENABLE" "-D TPM2_ENABLE" "-D TPM2_CONFIG_ENABLE"];
|
2015-01-26 21:13:31 +01:00
|
|
|
|
2023-04-26 18:31:57 +02:00
|
|
|
buildConfig = if debug then "DEBUG" else "RELEASE";
|
2023-02-20 16:26:44 +01:00
|
|
|
env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.cc.isClang "-Qunused-arguments";
|
2022-11-07 01:36:57 +01:00
|
|
|
|
2023-04-18 12:27:00 +02:00
|
|
|
env.PYTHON_COMMAND = "python3";
|
|
|
|
|
2019-07-15 16:35:30 +02:00
|
|
|
postPatch = lib.optionalString csmSupport ''
|
2023-11-29 20:17:01 +01:00
|
|
|
cp ${seabios}/share/seabios/Csm16.bin OvmfPkg/Csm/Csm16/Csm16.bin
|
2018-03-14 14:52:32 +01:00
|
|
|
'';
|
2015-01-26 21:13:31 +01:00
|
|
|
|
2023-11-25 13:12:30 +01:00
|
|
|
postFixup = (
|
|
|
|
if stdenv.hostPlatform.isAarch then ''
|
2018-03-14 16:37:49 +01:00
|
|
|
mkdir -vp $fd/FV
|
2020-06-14 23:25:42 +02:00
|
|
|
mkdir -vp $fd/AAVMF
|
2018-03-14 16:37:49 +01:00
|
|
|
mv -v $out/FV/QEMU_{EFI,VARS}.fd $fd/FV
|
|
|
|
|
2020-06-14 05:35:36 +02: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
|
2020-06-14 23:25:42 +02:00
|
|
|
|
|
|
|
# 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
|
2023-11-25 13:12:30 +01:00
|
|
|
''
|
|
|
|
else if stdenv.hostPlatform.isRiscV then ''
|
|
|
|
mkdir -vp $fd/FV
|
|
|
|
|
|
|
|
mv -v $out/FV/RISCV_VIRT_{CODE,VARS}.fd $fd/FV/
|
|
|
|
truncate -s 32M $fd/FV/RISCV_VIRT_CODE.fd
|
|
|
|
truncate -s 32M $fd/FV/RISCV_VIRT_VARS.fd
|
|
|
|
''
|
|
|
|
else ''
|
2019-07-15 16:35:30 +02:00
|
|
|
mkdir -vp $fd/FV
|
|
|
|
mv -v $out/FV/OVMF{,_CODE,_VARS}.fd $fd/FV
|
2023-11-25 13:12:30 +01:00
|
|
|
'');
|
2017-05-18 12:46:14 +02:00
|
|
|
|
|
|
|
dontPatchELF = true;
|
|
|
|
|
2022-08-22 16:15:40 +02: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;
|
|
|
|
};
|
|
|
|
|
2012-03-14 07:57:58 +01:00
|
|
|
meta = {
|
|
|
|
description = "Sample UEFI firmware for QEMU and KVM";
|
2020-05-04 16:00:37 +02:00
|
|
|
homepage = "https://github.com/tianocore/tianocore.github.io/wiki/OVMF";
|
2021-01-15 06:42:41 +01:00
|
|
|
license = lib.licenses.bsd2;
|
2023-01-02 04:30:12 +01:00
|
|
|
inherit (edk2.meta) platforms;
|
2023-07-27 23:44:12 +02:00
|
|
|
maintainers = with lib.maintainers; [ adamcstephens raitobezarius ];
|
2023-11-25 13:13:24 +01:00
|
|
|
broken = stdenv.isDarwin;
|
2012-03-14 07:57:58 +01:00
|
|
|
};
|
2022-08-22 16:15:40 +02:00
|
|
|
})
|