Skip to content

Conversation

@jwrdegoede
Copy link
Contributor

The Fedora 44 change to make aarch64 live isos just work on Windows on Arm laptops:
https://fedoraproject.org/wiki/Changes/Automatic_DTB_selection_for_aarch64_EFI_systems

This uses the auto DTB selection build into the systemd-stub. The modified kernel image is in essence an incomplete UKI containing just a UKI boot-stub and the DTBs, but not an initrd nor a kernel commandline. The host generated initrd and host specific commandline will still be supplied by GRUB as usual, including allowing the user to make changes to the commandline through GRUB.

Currently the rhboot/fedora-44 branch from which Fedora 44's GRUB is build fails to boot the UKI-light kernel images used for this changed.

This is caused by a set of Fedora downstream GRUB changes which replace calling EFI boot services load_image + start_image with code to manually load the PE binary and jump to the entry point.

This pull-requests consists of 8 (partial) reverts, reverting to the grub mainline code for starting EFI PE binaries on aarch64. Note the code changes only influence aarch64, which is why some of the reverts are partial since some of the code is also used on i386/x86_64 builds.

I've put a notice in the commit message which commits are full reverts so that the origin commit + the revert can simply be dropped on the next rebase.

On top of this reverts there are 2 bugfixes and a commit disabling most of the generic grub-core/loader/efi/linux.c code on i386/x86_64 since that is unused on i386/x86_64.

Hans de Goede added 11 commits December 4, 2025 23:03
This fully reverts commit ae0fba3.

This will break RISC-V builds, but further reverts in this series
will completely remove the troublesome parse_pe_header() function.

Note the modifed code is not used on x86 (#ifdef !x86).

This is part of a series of reverts to move non x86 vmlinuz loading back
to using EFI boot services load_image + start_image calls.

The current DYI approach breaks booting kernel EFI binaries which have
the stubble stub for automatic DTB loading.

Switching back to EFI boot services load_image + start_image fixes this
and also brings Fedora's grub inline with how upstream grub is loading
and booting kernels on arm64 platforms.

Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com>
…NX is required."

This fully reverts commit b899582.

Note this is actually a no-op since the modified linux_cmd() x86-only code
is not used on x86 at all, instead x86 uses the linux_cmd() function
from grub-core/loader/i386/efi/linux.c .

This is part of a series of reverts to move non x86 vmlinuz loading back
to using EFI boot services load_image + start_image calls.

The current DYI approach breaks booting kernel EFI binaries which have
the stubble stub for automatic DTB loading.

Switching back to EFI boot services load_image + start_image fixes this
and also brings Fedora's grub inline with how upstream grub is loading
and booting kernels on arm64 platforms.

Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com>
This reverts a small part of commit be61be0.

The only reverted bits are the changes to grub_cmd_linux() these changes
call grub_efi_check_nx_image_support() and store the result into a local
variable, which is then never used. So reverting these changes is a no-op
as the removed code only reads a flag which is never used.

Also note that this version of grub_cmd_linux() is never used on x86,
which uses linux_cmd() from grub-core/loader/i386/efi/linux.c .

This is part of a series of reverts to move non x86 vmlinuz loading back
to using EFI boot services load_image + start_image calls.

This partial revert is done to make further reverts in this series cleaner.

The current DYI approach breaks booting kernel EFI binaries which have
the stubble stub for automatic DTB loading.

Switching back to EFI boot services load_image + start_image fixes this
and also brings Fedora's grub inline with how upstream grub is loading
and booting kernels on arm64 platforms.

Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com>
This fully reverts commit 9728e07.

Note that the modifed version of grub_cmd_linux() is never used on x86,
which uses linux_cmd() from grub-core/loader/i386/efi/linux.c .

This is part of a series of reverts to move non x86 vmlinuz loading back
to using EFI boot services load_image + start_image calls.

The current DYI approach breaks booting kernel EFI binaries which have
the stubble stub for automatic DTB loading.

Switching back to EFI boot services load_image + start_image fixes this
and also brings Fedora's grub inline with how upstream grub is loading
and booting kernels on arm64 platforms.

Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com>
This fully reverts commit ba84a3e.

Note the modifed code is not used on x86 (#ifdef !x86).

This is part of a series of reverts to move non x86 vmlinuz loading back
to using EFI boot services load_image + start_image calls.

The current DYI approach breaks booting kernel EFI binaries which have
the stubble stub for automatic DTB loading.

Switching back to EFI boot services load_image + start_image fixes this
and also brings Fedora's grub inline with how upstream grub is loading
and booting kernels on arm64 platforms.

Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com>
This fully reverts commit 81dbbbc.

Note the modifed code is not used on x86 (#ifdef !x86).

This is part of a series of reverts to move non x86 vmlinuz loading back
to using EFI boot services load_image + start_image calls.

The current DYI approach breaks booting kernel EFI binaries which have
the stubble stub for automatic DTB loading.

Switching back to EFI boot services load_image + start_image fixes this
and also brings Fedora's grub inline with how upstream grub is loading
and booting kernels on arm64 platforms.

Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com>
This fully reverts commit 3cfd4a1.

Note the modifed code is not used on x86 (#ifdef !x86).

This is part of a series of reverts to move non x86 vmlinuz loading back
to using EFI boot services load_image + start_image calls.

The current DYI approach breaks booting kernel EFI binaries which have
the stubble stub for automatic DTB loading.

Switching back to EFI boot services load_image + start_image fixes this
and also brings Fedora's grub inline with how upstream grub is loading
and booting kernels on arm64 platforms.

Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com>
This fully reverts commit fa8f199.

Note that the modifed version of grub_cmd_linux() is never used on x86,
which uses linux_cmd() from grub-core/loader/i386/efi/linux.c .

This concludes the series of reverts to move non x86 vmlinuz loading back
to using EFI boot services load_image + start_image calls.

The current DYI approach breaks booting kernel EFI binaries which have
the stubble stub for automatic DTB loading.

Switching back to EFI boot services load_image + start_image fixes this
and also brings Fedora's grub inline with how upstream grub is loading
and booting kernels on arm64 platforms.

This also fixes 2 issues with the xen_hypervisor and xen_module commands:

1) With the now reverted move of setting loaded_image->load_options in
finalize_params() the commandline would no longer be set for the xen case.

2) The handover_offset variable passed by grub_efi_linux_boot is a global
variable set by the linux cmd and this would either be 0 or the value
from the last run linux cmd, neither of which is likely correct for
the xen case.

Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com>
Fix grub_arch_efi_linux_boot_image () leaking the memory allocated for
mempath by freeing it after use.

Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com>
Fix grub_arch_efi_linux_boot_image () not unloading the loaded image when
allocating memory for the commandline fails.

Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com>
When building grub for x86_64-efi or i386-efi then loader/i386/efi/linux.c
already registers "linux" and "initrd" commands and those will be used
instead of those defined in the generic loader/efi/linux.c code.

Disable (#ifdef out) the unused code in loader/efi/linux.c when building
for x86. This also avoids registering the linux and initrd commands twice.

Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com>
@jwrdegoede
Copy link
Contributor Author

If it is deemed desirable to keep doing our own PE binary loading + jumping to the entry point then I suggest using the new upstream mechanism to hook the load- and start-image boot services calls, which is already (partly) backported on the fedora-44 branch, combined with this patch:

https://git.launchpad.net/ubuntu/+source/grub2/plain/debian/patches/secure-boot/efi-peimage.patch?h=applied/ubuntu/devel

This provides a much cleaner (and easier to rebase) to do our own PE binary loading + starting vs the current broken code. For now this can be used on just aarch64, but on the next rebase (once 2.14) is out I would suggest to also switch to this code for i386/x86_64 which would greatly reduce the delta vs upstream and if both Ubuntu and Fedora are using this it would seem reasonable to try and upstream this.

Let me know if you want to go the route of using the mechanism to hook the load- and start-image boot services calls together with Ubuntu's peimage module patch which uses these hooks, then I'll update this pull-request to include these patches.

@Conan-Kudo
Copy link
Contributor

I think you should go ahead and do this with the new upstream mechanism.

@Conan-Kudo
Copy link
Contributor

Also, FYI, I think this branch is out of date compared to what's in Dist-Git: https://src.fedoraproject.org/rpms/grub2/blob/rawhide/f/grub.patches

@lsandov1
Copy link
Contributor

lsandov1 commented Jan 7, 2026

Also, FYI, I think this branch is out of date compared to what's in Dist-Git: https://src.fedoraproject.org/rpms/grub2/blob/rawhide/f/grub.patches

Now this branch should be sync

@lsandov1
Copy link
Contributor

lsandov1 commented Jan 7, 2026

@jwrdegoede thanks for your patches. Let us revisit them ASAP.

@jwrdegoede
Copy link
Contributor Author

Thank you for fixing the fedora-44 branch being out of sync.

@lsandov1 I'm not sure what you mean with "Let us revisit them ASAP"?

Do you mean that you're going to take a look when you have some time ?

Or do you want me to rebase, finish the backport of the load-image + start-image hooks and add the peimage patch from Ubuntu which adds a cleaner version of the code to manually load the PE binary and jump to its entry point (vs relying on the UEFI firmware to do this) ?

Or maybe both?

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.

3 participants