aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Meyer <meyerpatrick@google.com>2021-09-02 13:44:04 +0200
committerAleksandr Nogikh <wp32pw@gmail.com>2021-09-03 11:24:18 +0200
commitd236a457274375e5273ac4e958722659929c469f (patch)
tree4226d78e902b1b5d50583bfa80d8ef2317978e05
parentf62a58290e2f1200a2b21f2707a9ff0394a2a724 (diff)
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.
-rw-r--r--docs/darwin/README.md4
-rw-r--r--vm/qemu/qemu.go28
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=<YOUR_APPLE_SMC_HERE> -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": "<YOUR_APPLE_SMC_HERE>"
}
}
```
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)
}