Skip to content

Commit

Permalink
config(qemu): support secure boot when TPM is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
osy committed Jul 8, 2023
1 parent 65325b0 commit 50c205a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
15 changes: 15 additions & 0 deletions Configuration/QEMUConstant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,14 @@ extension QEMUArchitecture {
return false
#endif
}

var hasSecureBootSupport: Bool {
switch self {
case .x86_64, .i386: return true
case .aarch64: return true
default: return false
}
}
}

extension QEMUTarget {
Expand All @@ -461,4 +469,11 @@ extension QEMUTarget {
default: return true
}
}

var hasSecureBootSupport: Bool {
switch self.rawValue {
case "microvm": return false
default: return true
}
}
}
8 changes: 7 additions & 1 deletion Configuration/UTMQemuConfiguration+Arguments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ import Virtualization // for getting network interfaces
system.architecture.hasUsbSupport && system.target.hasUsbSupport && input.usbBusSupport != .disabled
}

private var isSecureBootUsed: Bool {
system.architecture.hasSecureBootSupport && system.target.hasSecureBootSupport && qemu.hasTPMDevice
}

@QEMUArgumentBuilder private var machineArguments: [QEMUArgument] {
f("-machine")
system.target
Expand Down Expand Up @@ -370,7 +374,9 @@ import Virtualization // for getting network interfaces
f("ICH9-LPC.disable_s3=1") // applies for pc-q35-* types
}
if qemu.hasUefiBoot {
let bios = resourceURL.appendingPathComponent("edk2-\(system.architecture.rawValue)-code.fd")
let secure = isSecureBootUsed ? "-secure" : ""
let code = system.target.rawValue == "microvm" ? "microvm" : "code"
let bios = resourceURL.appendingPathComponent("edk2-\(system.architecture.rawValue)\(secure)-\(code).fd")
let vars = qemu.efiVarsURL ?? URL(fileURLWithPath: "/\(QEMUPackageFileName.efiVariables.rawValue)")
if !hasCustomBios && FileManager.default.fileExists(atPath: bios.path) {
f("-drive")
Expand Down

0 comments on commit 50c205a

Please sign in to comment.