Skip to content

QEMU/OVMF improvements #474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

nicholasbishop
Copy link
Member

@nicholasbishop nicholasbishop commented Jul 30, 2022

A few improvements to cargo xtask run to make it more likely to work well across various Linux distros and Windows.

  1. The paths where OVMF files get installed are annoyingly inconsistent between each OS/distro. I tried various methods to be clever about how the paths get searched, but what ended up being clearest in the end is just having separate functions to get the expected paths for each host type. This covers Windows and Linux (Arch, CentOS, Debian/Ubuntu, and Fedora). I only tested the results on Fedora and Windows since that's what I have installed, but I got paths for the others by using online package search tools.
  2. Changed the CLI interface to take separate --ovmf-code and --ovmf-vars options rather than --ovmf-dir. This works better because the file names of OVMF can vary a lot. For that reason, the uefi-test-runner directory is no longer automatically searched.
  3. On Windows, the QEMU installer doesn't add the QEMU directory to the PATH. Add the default directory to the search path to make it more likely that cargo xtask run will just work without manually modifying the PATH.
  4. The vars file is now always copied to a temporary location so that it can be made read+write. Previously we did this just for aarch64, but I think it's a little simpler (and more like a real UEFI env) to just always make it r+w.

Fixes #469

@nicholasbishop nicholasbishop force-pushed the bishop-improve-ovmf-paths branch from caf2690 to 0b14271 Compare July 30, 2022 22:02
@GabrielMajeri
Copy link
Collaborator

The paths where OVMF files get installed are annoyingly inconsistent between each OS/distro.

It's alright, they're sometimes even inconsistent across different versions of the same distro 😒 I've gotten used to copying them to the uefi-rs directory to avoid issues.

In the AArch64 version of OVMF currently used in CI, it crashes if the
vars aren't writable. (A newer version that I tested locally doesn't
have this problem.) Having vars be writable is a more normal UEFI
environment anyway though, so remove the special case for AArch64 and
make the vars always writable.

Since the vars file might be in some read-only location, or owned by
root (e.g. a system package installed to /usr), a temporary copy of the
vars file is made before using it.

Also add a `PflashMode` enum to make the call sites of `add_pflash_args`
a little clearer.
The QEMU installer for Windows does not automatically add the directory
containing the QEMU executables to the PATH. Add the default directory
to the PATH to make it more likely that QEMU will be found on
Windows. The directory is appended, so if a different directory on the
PATH already has the QEMU binary this change won't affect anything.
Prior to this commit we assumed that OVMF files for a given guest arch
have consistent file names across host operating systems, varying only
in the directory path. This turns out not to be a good assumption
though; the locations and names of OVMF files installed by system
packages very a lot between operating systems.

To make it easier to figure out where stuff is, add a number of
OS-specific functions that provide the fulls OVMF code and vars
paths. For now these functions cover Arch, CentOS, Debian/Ubuntu,
Fedora, and Windows. A selection of candidate paths is then collected
(one set of paths for Linux, a different set for Windows) and searched.

Along with the above changes, the `--ovmf-dir` option has been replaced
with separate `--ovmf-code` and `--ovmf-vars` options. When set, these
paths will be used instead of searching the candidate paths.

The `uefi-test-runner` directory is no longer automatically searched for
OVMF files since we no longer assume we know what these files would be
named. Hopefully the improved candidate search makes this moot, and the
`--ovmf-code`/`--ovmf-vars` options can still be used to search there if
desired.

CI changes:
* The aarch64 job has been simplified a bit since the system location of
  the files is now sufficient for `cargo xtask run` to work.
* The ia32 job now explicitly sets the location of the downloaded OVMF
  files.

Fixes rust-osdev#469
@nicholasbishop nicholasbishop force-pushed the bishop-improve-ovmf-paths branch from 0b14271 to 81f8380 Compare August 3, 2022 16:24
@GabrielMajeri GabrielMajeri merged commit 4221e42 into rust-osdev:main Aug 4, 2022
@nicholasbishop nicholasbishop deleted the bishop-improve-ovmf-paths branch August 4, 2022 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatically use the default location of the OVMF files on Windows
2 participants