From d236a457274375e5273ac4e958722659929c469f Mon Sep 17 00:00:00 2001 From: Patrick Meyer Date: Thu, 2 Sep 2021 13:44:04 +0200 Subject: vm/qemu: add apple_smc_osk and efi_{code,vars}_device options This way users don't have to overwrite qemu_args in their configs. --- docs/darwin/README.md | 4 +++- vm/qemu/qemu.go | 28 ++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/docs/darwin/README.md b/docs/darwin/README.md index 7deebf2d4..d6d5cde0c 100644 --- a/docs/darwin/README.md +++ b/docs/darwin/README.md @@ -250,7 +250,9 @@ make HOSTOS=darwin HOSTARCH=amd64 TARGETOS=darwin TARGETARCH=amd64 SOURCEDIR=/Us "count": 2, "cpu": 2, "mem": 4096, - "qemu_args": "-device isa-applesmc,osk= -accel hvf -machine q35 -cpu Penryn,vendor=GenuineIntel,+invtsc,vmware-cpuid-freq=on,+pcid,+ssse3,+sse4.2,+popcnt,+avx,+aes,+xsave,+xsaveopt,check -drive if=pflash,format=raw,readonly=on,file=/usr/local/share/OVMF/OVMF_CODE.fd -drive if=pflash,format=raw,readonly=on,file=/usr/local/share/OVMF/OVMF_VARS.fd" + "efi_code_device": "/usr/local/share/OVMF/OVMF_CODE.fd", + "efi_vars_device": "/usr/local/share/OVMF/OVMF_VARS.fd", + "apple_smc_osk": "" } } ``` diff --git a/vm/qemu/qemu.go b/vm/qemu/qemu.go index 157c4c7da..957325f0a 100644 --- a/vm/qemu/qemu.go +++ b/vm/qemu/qemu.go @@ -56,6 +56,9 @@ type Config struct { // The modern way of describing QEMU hard disks is supported, so the value // "drive index=0,media=disk,file=" is transformed to "-drive index=0,media=disk,file=image" for QEMU. ImageDevice string `json:"image_device"` + // EFI images containing the EFI itself, as well as this VMs EFI variables. + EfiCodeDevice string `json:"efi_code_device"` + EfiVarsDevice string `json:"efi_vars_device"` // QEMU network device type to use. // If not specified, some default per-arch value will be used. // See the full list with qemu-system-x86_64 -device help. @@ -66,6 +69,8 @@ type Config struct { Mem int `json:"mem"` // For building kernels without -snapshot for pkg/build (true by default). Snapshot bool `json:"snapshot"` + // Magic key used to dongle macOS to the device. + AppleSmcOsk string `json:"apple_smc_osk"` } type Pool struct { @@ -202,8 +207,12 @@ var archConfigs = map[string]*archConfig{ RngDev: "virtio-rng-pci", }, "darwin/amd64": { - Qemu: "qemu-system-x86_64", - QemuArgs: "-enable-kvm -machine q35 -cpu host,migratable=off", + Qemu: "qemu-system-x86_64", + QemuArgs: strings.Join([]string{ + "-accel hvf -machine q35 ", + "-cpu Penryn,vendor=GenuineIntel,+invtsc,vmware-cpuid-freq=on,", + "+pcid,+ssse3,+sse4.2,+popcnt,+avx,+aes,+xsave,+xsaveopt,check ", + }, ""), TargetDir: "/tmp", NetDev: "e1000-82545em", RngDev: "virtio-rng-pci", @@ -458,6 +467,21 @@ func (inst *instance) boot() error { "-append", strings.Join(cmdline, " "), ) } + if inst.cfg.EfiCodeDevice != "" { + args = append(args, + "-drive", "if=pflash,format=raw,readonly=on,file="+inst.cfg.EfiCodeDevice, + ) + } + if inst.cfg.EfiVarsDevice != "" { + args = append(args, + "-drive", "if=pflash,format=raw,readonly=on,file="+inst.cfg.EfiVarsDevice, + ) + } + if inst.cfg.AppleSmcOsk != "" { + args = append(args, + "-device", "isa-applesmc,osk="+inst.cfg.AppleSmcOsk, + ) + } if inst.debug { log.Logf(0, "running command: %v %#v", inst.cfg.Qemu, args) } -- cgit mrf-deployment