Skip to content
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

Add optional loading of UEFI firmware via -bios parameter in QEMU #3261

Merged
merged 1 commit into from
Feb 25, 2025

Conversation

arixmkii
Copy link
Contributor

@arixmkii arixmkii commented Feb 18, 2025

Fixes #3176

Limiting this to X8664 arch as there is no information if this works for other architectures. This allows to load UEFI firmware on Windows hosts, where pflash can't be used in combination with WHPX acceleration. Default to false on non-Windows hosts and true on Windows (to have working default).

The FW resolution if set to true and running amd64 VM works like this

  1. Check if we have it in already loaded image, if so, then consider it valid (already concatenated)
  2. Check all downloads, if any matches then consider it concatenated image and use like regular download (downloading through standard mechanisms is removed to prevent potential incompatibilities)
  3. If not yet available in downloaded, then try to find firmware and firmware vars, concatenate and store into downloaded file (so, future runs could find it w/o additional actions)

PR update to use env var instead of Lima yaml

@arixmkii
Copy link
Contributor Author

I'm, like many people with JVM background, genuinely bad at naming user facing settings. Any better ideas than ugly compatUEFIInBIOS are welcome.

@@ -182,6 +182,11 @@ type Firmware struct {
// LegacyBIOS is ignored for aarch64.
LegacyBIOS *bool `yaml:"legacyBIOS,omitempty" json:"legacyBIOS,omitempty" jsonschema:"nullable"`

// CompatUEFIViaBIOS forces QEMU to load concatenated firmware with -bios option
// CompatUEFIViaBIOS is ignored for non x86_64
// This should be deprecated, if the issue in QEMU is fixed https://gitlab.com/qemu-project/qemu/-/issues/513
Copy link
Member

@AkihiroSuda AkihiroSuda Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is already planned to be deprecated since its birth, may this should rather be an env var?
Similar to LIMA_SSH_PORT_FORWARDER (originally planned to be deprecated in v1.0, now postponed to v1.1)
https://lima-vm.io/docs/config/environment-variables/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. It might never be removed, because fixes in Windows QEMU version are not of the highest priority. If the ergonomics of the environment var would be insufficient it could be changed later into full-fledged option in Lima yaml. I'm moving this into draft to rework.

pkg/qemu/qemu.go Outdated
var targetArch string
switch arch {
case limayaml.X8664:
targetArch = "i386"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x86_64 and i386 use the same layout for vars, so, there is no x86_64 version in the distribution. One needs to concatenate i386 to x86_64 code. This is the legacy of x86_64 being derivative of i386. Probably this deserves explanation with a comment.

pkg/qemu/qemu.go Outdated
return "", nil, err
}
defer codeFile.Close()
downloadedFile, err := os.OpenFile(downloadedFirmware, os.O_CREATE|os.O_WRONLY, 0o644)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably the file name should be changed, as the concatenated file would be incompatible with QemuEfiCodeFD

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change this. No objection here. I just re-used current code for quick prototype, but it is obviously not the most straightforward or easy to understand hack.

@arixmkii arixmkii marked this pull request as draft February 19, 2025 17:25
@arixmkii arixmkii marked this pull request as ready for review February 19, 2025 22:03
@arixmkii
Copy link
Contributor Author

arixmkii commented Feb 19, 2025

Reworked based on received feedback. Now env var is used as the mode switch. And now original and altered code paths has clearer separation in code. Also, downloading mechanism is disabled if compatibility mode is used.

I performed manual testing and compared the QEMU command lines in both modes.

@@ -598,36 +599,89 @@ func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err er
}
if !legacyBIOS {
var firmware string
firmwareInBios := runtime.GOOS == "windows"
if envVar := os.Getenv("LIMA_QEMU_UEFI_IN_BIOS"); envVar != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

AkihiroSuda
AkihiroSuda previously approved these changes Feb 24, 2025
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@AkihiroSuda AkihiroSuda added this to the v1.1 (tentative) milestone Feb 24, 2025
Limiting this to X8664 arch as there is no information if this works for
other architectures. This allows to load UEFI firmware on Windows hosts,
where pflash can't be used in combination with WHPX acceleration.
Default to false on non-Windows hosts and true on Windows (to have
working default).

Signed-off-by: Arthur Sengileyev <[email protected]>
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@AkihiroSuda AkihiroSuda merged commit 26a3821 into lima-vm:master Feb 25, 2025
31 checks passed
@arixmkii arixmkii deleted the bios-uefi branch March 6, 2025 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QEMU: support UEFI via -bios
2 participants