Skip to content

Commit

Permalink
Merge pull request #820 from jcdickinson/feat/xdg-like-firmware-lookup
Browse files Browse the repository at this point in the history
feat: look for firmware in $HOME/.local/share/qemu
  • Loading branch information
AkihiroSuda authored May 10, 2022
2 parents 0a5e1b5 + 7559909 commit 051fc82
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions pkg/qemu/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/fs"
"os"
"os/exec"
"os/user"
"path/filepath"
"runtime"
"strconv"
Expand Down Expand Up @@ -615,11 +616,20 @@ func getFirmware(qemuExe string, arch limayaml.Arch) (string, error) {
default:
return "", fmt.Errorf("unexpected architecture: %q", arch)
}
binDir := filepath.Dir(qemuExe) // "/usr/local/bin"
localDir := filepath.Dir(binDir) // "/usr/local"

currentUser, err := user.Current()
if err != nil {
return "", err
}

binDir := filepath.Dir(qemuExe) // "/usr/local/bin"
localDir := filepath.Dir(binDir) // "/usr/local"
userLocalDir := filepath.Join(currentUser.HomeDir, ".local") // "$HOME/.local"

relativePath := fmt.Sprintf("share/qemu/edk2-%s-code.fd", arch)
candidates := []string{
filepath.Join(localDir, fmt.Sprintf("share/qemu/edk2-%s-code.fd", arch)), // macOS (homebrew)
filepath.Join(userLocalDir, relativePath), // XDG-like
filepath.Join(localDir, relativePath), // macOS (homebrew)
}

switch arch {
Expand Down Expand Up @@ -648,5 +658,5 @@ func getFirmware(qemuExe string, arch limayaml.Arch) (string, error) {
if arch == limayaml.X8664 {
return "", fmt.Errorf("could not find firmware for %q (hint: try setting `firmware.legacyBIOS` to `true`)", qemuExe)
}
return "", fmt.Errorf("could not find firmware for %q", qemuExe)
return "", fmt.Errorf("could not find firmware for %q (hint: try copying the \"edk-%s-code.fd\" firmware to $HOME/.local/share/qemu/)", arch, qemuExe)
}

0 comments on commit 051fc82

Please sign in to comment.