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 a FuEfivars class that can be used to set up a test framework #7322

Merged
merged 8 commits into from
Jun 12, 2024

Conversation

hughsie
Copy link
Member

@hughsie hughsie commented Jun 4, 2024

This allows us to create a FuDummyEfivars and then test various UEFI methods without reading and writing to the filesystem.

Type of pull request:

@superm1
Copy link
Member

superm1 commented Jun 4, 2024

Maybe a dumb question; but why not umockdev? Can't we just mock the directory with the variables instead of a whole backend?

@hughsie
Copy link
Member Author

hughsie commented Jun 4, 2024

Can't we just mock the directory with the variables

Not a dumb question at all; I'm reimplementing a bit of efibootmgr that means we can do A/B updates for bootloader components -- and I need something I can set up in half a dozen different configurations and then examine the steps -- doing things like simulating a reboot (clearing BootNext for example).

@superm1
Copy link
Member

superm1 commented Jun 4, 2024

I'm reimplementing a bit of efibootmgr that means we can do A/B updates for bootloader components

As in fwupd does the A/B updates of bootloader components? Like part of something like Silverblue? Might want to hear more of the big picture here.

I (of course naively) view GRUB as on the general chopping block a few years from now and UKI's taking over.

and I need something I can set up in half a dozen different configurations and then examine the steps -- doing things like simulating a reboot (clearing BootNext for example).

To me; this feels a safer to do with umockdev. You don't have to worry about implementation bugs that only show up in real environment.

@hughsie
Copy link
Member Author

hughsie commented Jun 5, 2024

As in fwupd does the A/B updates of bootloader components?

Yes, something like that. I think the idea is that we have something like /usr/lib/firmware.d where we dump shim.efi, and grub.efi -- and in the medium term future replacing grub.efi with nmbl.efi -- which is the not-a-bootloader-tiny-kernel-that-can-kexec new thing that Red Hat is working on for the cases where we need a bit more than just booting kernel-uki. We then copy /usr/lib/firmware.d into the ESP with a fallback using EFI vars so that we can do A/B updates of all the early-boot stuff. e.g. something like:

shimctl-2024-06-05-081302

I (of course naively) view GRUB as on the general chopping block a few years from now and UKI's taking over.

Yes, I think that's fair. nmbl is basically "we don't need a bootloader"

To me; this feels a safer to do with umockdev.

Let me show you the tests -- then maybe you might see how we're peeking into the EFI variables. The other thing having "an object" lets you have is caching; so we don't have to hit either efivarfs or the filesystem repeatedly -- e.g. we put a single hashtable in fu-efivars.c and we get it for all the windows/linux/freebsd/dummy implementations.

@superm1
Copy link
Member

superm1 commented Jun 5, 2024

We then copy /usr/lib/firmware.d into the ESP with a fallback using EFI vars so that we can do A/B updates of all the early-boot stuff. e.g. something like:

Something I want to caution in this design is the optimism in use of switching BootXXXX variables. Don't underestimate the assumptions that vendors have made in their BIOS for their boot manager to 'auto-add' entries for common paths. Think like how we have Linux-Firmware-Updater for Lenovo and Linux Firmware Updater for everyone else?
Just this past month BIOS for AMD internal reference systems nominally testing Ubuntu got stuck in a boot loop because Ubuntu 23.10 -> Ubuntu 24.04 switched from ubuntu to Ubuntu 🤦

So I would think it's generally safer to keep a single boot entry and instead iterate on another variable or a flat file on the filesystem to decide what "shim" loads. But if you're envisioning swapping shim that's another story and this may be inevitable.

Anyway; that's generally divergent, I get the big picture now.

Yes, I think that's fair. nmbl is basically "we don't need a bootloader"

👍

Let me show you the tests -- then maybe you might see how we're peeking into the EFI variables. The other thing having "an object" lets you have is caching; so we don't have to hit either efivarfs or the filesystem repeatedly -- e.g. we put a single hashtable in fu-efivars.c and we get it for all the windows/linux/freebsd/dummy implementations.

Yeah; I could see caching increases speed of tests by a magnitude. I guess you envision enough tests to justify the improvement?

@hughsie
Copy link
Member Author

hughsie commented Jun 5, 2024

So I would think it's generally safer to keep a single boot entry

We actually tested that; we saw a few [old] systems doing horrible things when modifying the active boot entry.

got stuck in a boot loop

Ohh interesting; can you share the root cause? i.e. that's exactly the kind of thing I want to write tests for.

I guess you envision enough tests to justify the improvement?

I think there's a lot of broken hardware, and I think we'll need the ability to do various insane things to the variable.

@superm1
Copy link
Member

superm1 commented Jun 5, 2024

Ohh interesting; can you share the root cause? i.e. that's exactly the kind of thing I want to write tests for.

Heuristics associated with mucking with boot order. The fact that this BIOS team did it and it caused problems means it's probably done by others too. I think that a test case confirming that the expected entries are still in the same position in the boot order would catch it.

I think there's a lot of broken hardware, and I think we'll need the ability to do various insane things to the variable.

It's interesting to think of fwupd as critical path here for UKIs because these are traditionally "distribution" provided components. Do you think LVFS would be how UKIs get rolled out then?

@hughsie
Copy link
Member Author

hughsie commented Jun 5, 2024

Do you think LVFS would be how UKIs get rolled out then

I don't think so, but I think the SBAT (and microsoft thing) will be in a future fwupd release ;)

src/fu-tool.c Outdated Show resolved Hide resolved
src/fu-tool.c Show resolved Hide resolved
libfwupdplugin/fu-context.c Outdated Show resolved Hide resolved
libfwupdplugin/fu-dummy-efivars.c Show resolved Hide resolved
libfwupdplugin/fu-dummy-efivars.c Outdated Show resolved Hide resolved
@hughsie hughsie force-pushed the hughsie/efivars branch 2 times, most recently from dab3530 to 8a6086a Compare June 12, 2024 11:25
This allows us to create a FuDummyEfivars and then test various UEFI methods
without reading and writing to the filesystem.
We need the same handling in three places, and we're about to add a fourth.

This also allows us to add a `fwupdtool efivar-boot` debug command.
This also adds fu_context_get_esp_volume_by_hard_drive_device_path() for future
use.
…he context

This also adds `fwupdtool efivar-files` as a debug command.
This means it works on non-Linux, and gets rid of more binary blobs from git.
Copy link
Member

@superm1 superm1 left a comment

Choose a reason for hiding this comment

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

I'm happy with this once tests are pasing.

@hughsie hughsie merged commit 442713f into main Jun 12, 2024
18 checks passed
@hughsie hughsie deleted the hughsie/efivars branch June 12, 2024 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants