@@ -20,7 +20,11 @@ func buildArgs(cfg hypervisor.VMConfig, machine MachineType) []string {
2020 microvm := machine == MachineTypeMicroVM
2121
2222 // Machine type with KVM acceleration (arch-specific when omitted).
23- args = append (args , "-machine" , string (machine )+ ",accel=kvm" )
23+ machineArg := string (machine ) + ",accel=kvm"
24+ if cfg .Firmware != nil && cfg .Firmware .SecureBoot {
25+ machineArg += ",smm=on"
26+ }
27+ args = append (args , "-machine" , machineArg )
2428 if microvm {
2529 // Do not allow a host qemu.conf to add devices outside microvm's
2630 // documented eight virtio-mmio-device limit.
@@ -51,6 +55,18 @@ func buildArgs(cfg hypervisor.VMConfig, machine MachineType) []string {
5155 args = append (args , "-device" , strings .Join (balloonOpts , "," ))
5256 }
5357
58+ // Firmware boot. The code image is shared and immutable; variable storage is
59+ // a per-instance writable copy.
60+ if cfg .EffectiveBootMode () == hypervisor .BootModeUEFI {
61+ args = append (args ,
62+ "-drive" , fmt .Sprintf ("if=pflash,format=raw,unit=0,file=%s,readonly=on" , cfg .Firmware .CodePath ),
63+ "-drive" , fmt .Sprintf ("if=pflash,format=raw,unit=1,file=%s" , cfg .Firmware .VarsPath ),
64+ )
65+ if cfg .Firmware .SecureBoot {
66+ args = append (args , "-global" , "driver=cfi.pflash01,property=secure,value=on" )
67+ }
68+ }
69+
5470 // Kernel and initrd
5571 if cfg .KernelPath != "" {
5672 args = append (args , "-kernel" , cfg .KernelPath )
@@ -64,7 +80,7 @@ func buildArgs(cfg hypervisor.VMConfig, machine MachineType) []string {
6480
6581 // Disk configuration
6682 for i , disk := range cfg .Disks {
67- driveOpts := fmt .Sprintf ("file=%s,format=raw ,if=none,id=drive%d" , disk .Path , i )
83+ driveOpts := fmt .Sprintf ("file=%s,format=%s ,if=none,id=drive%d" , disk .Path , disk . EffectiveFormat () , i )
6884 if disk .Readonly {
6985 // Disable host-side file locking for shared readonly bases so multiple
7086 // VMs can boot concurrently from the same image without lock contention.
@@ -80,6 +96,15 @@ func buildArgs(cfg hypervisor.VMConfig, machine MachineType) []string {
8096 args = append (args , "-device" , fmt .Sprintf ("%s,drive=drive%d" , virtioDevice (microvm , "virtio-blk" ), i ))
8197 }
8298
99+ // Software TPM 2.0. The swtpm process is started by Starter before QEMU.
100+ if cfg .TPM != nil {
101+ args = append (args ,
102+ "-chardev" , fmt .Sprintf ("socket,id=chrtpm,path=%s" , cfg .TPM .SocketPath ),
103+ "-tpmdev" , "emulator,id=tpm0,chardev=chrtpm" ,
104+ "-device" , "tpm-crb,tpmdev=tpm0" ,
105+ )
106+ }
107+
83108 // Network configuration
84109 for i , net := range cfg .Networks {
85110 netdevOpts := fmt .Sprintf ("tap,id=net%d,ifname=%s,script=no,downscript=no" , i , net .TAPDevice )
0 commit comments