github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/pkg/machine/qemu/options_darwin_arm64.go (about)

     1  package qemu
     2  
     3  import (
     4  	"os"
     5  	"os/exec"
     6  	"path/filepath"
     7  )
     8  
     9  var (
    10  	QemuCommand = "qemu-system-aarch64"
    11  )
    12  
    13  func (v *MachineVM) addArchOptions() []string {
    14  	ovmfDir := getOvmfDir(v.ImagePath.GetPath(), v.Name)
    15  	opts := []string{
    16  		"-accel", "hvf",
    17  		"-accel", "tcg",
    18  		"-cpu", "cortex-a57",
    19  		"-M", "virt,highmem=off",
    20  		"-drive", "file=" + getEdk2CodeFd("edk2-aarch64-code.fd") + ",if=pflash,format=raw,readonly=on",
    21  		"-drive", "file=" + ovmfDir + ",if=pflash,format=raw"}
    22  	return opts
    23  }
    24  
    25  func (v *MachineVM) prepare() error {
    26  	ovmfDir := getOvmfDir(v.ImagePath.GetPath(), v.Name)
    27  	cmd := []string{"/bin/dd", "if=/dev/zero", "conv=sync", "bs=1m", "count=64", "of=" + ovmfDir}
    28  	return exec.Command(cmd[0], cmd[1:]...).Run()
    29  }
    30  
    31  func (v *MachineVM) archRemovalFiles() []string {
    32  	ovmDir := getOvmfDir(v.ImagePath.GetPath(), v.Name)
    33  	return []string{ovmDir}
    34  }
    35  
    36  func getOvmfDir(imagePath, vmName string) string {
    37  	return filepath.Join(filepath.Dir(imagePath), vmName+"_ovmf_vars.fd")
    38  }
    39  
    40  /*
    41   *  QEmu can be installed in multiple locations on MacOS, especially on
    42   *  Apple Silicon systems.  A build from source will likely install it in
    43   *  /usr/local/bin, whereas Homebrew package management standard is to
    44   *  install in /opt/homebrew
    45   */
    46  func getEdk2CodeFd(name string) string {
    47  	dirs := []string{
    48  		"/opt/homebrew/opt/podman/libexec/share/qemu",
    49  		"/usr/local/share/qemu",
    50  		"/opt/homebrew/share/qemu",
    51  	}
    52  	for _, dir := range dirs {
    53  		fullpath := filepath.Join(dir, name)
    54  		if _, err := os.Stat(fullpath); err == nil {
    55  			return fullpath
    56  		}
    57  	}
    58  	return name
    59  }