Skip to content

Commit

Permalink
QEMU Apple Silicon: Find BIOS FD wherever
Browse files Browse the repository at this point in the history
QEmu normally install BIOS images under `/usr/local` prefix, but
Homebrew installs them under `/opt/homebrew`.  This change searches both
locations and then puts back to an unpathed name if it doesn't find the
BIOS.  (I imitated other architectures' implemenations in that failback
behavior.)

[NO TESTS NEEDED]

Signed-off-by: Jonathan Springer <[email protected]>
  • Loading branch information
jonpspri authored and mheon committed Sep 20, 2021
1 parent 075086b commit 845f1cc
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion pkg/machine/qemu/options_darwin_arm64.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package qemu

import (
"os"
"os/exec"
"path/filepath"
)
Expand All @@ -15,7 +16,7 @@ func (v *MachineVM) addArchOptions() []string {
"-accel", "hvf",
"-cpu", "cortex-a57",
"-M", "virt,highmem=off",
"-drive", "file=/usr/local/share/qemu/edk2-aarch64-code.fd,if=pflash,format=raw,readonly=on",
"-drive", "file=" + getEdk2CodeFd("edk2-aarch64-code.fd") + ",if=pflash,format=raw,readonly=on",
"-drive", "file=" + ovmfDir + ",if=pflash,format=raw"}
return opts
}
Expand All @@ -34,3 +35,23 @@ func (v *MachineVM) archRemovalFiles() []string {
func getOvmfDir(imagePath, vmName string) string {
return filepath.Join(filepath.Dir(imagePath), vmName+"_ovmf_vars.fd")
}

/*
* QEmu can be installed in multiple locations on MacOS, especially on
* Apple Silicon systems. A build from source will likely install it in
* /usr/local/bin, whereas Homebrew package management standard is to
* install in /opt/homebrew
*/
func getEdk2CodeFd(name string) string {
dirs := []string{
"/usr/local/share/qemu",
"/opt/homebrew/share/qemu",
}
for _, dir := range dirs {
fullpath := filepath.Join(dir, name)
if _, err := os.Stat(fullpath); err == nil {
return fullpath
}
}
return name
}

0 comments on commit 845f1cc

Please sign in to comment.