Merge ~xypron/grub:riscv into ~ubuntu-core-dev/grub/+git/ubuntu:ubuntu

Proposed by Heinrich Schuchardt
Status: Merged
Merge reported by: Julian Andres Klode
Merged at revision: aa394cde19ed136dc1d0feabe89e9de44a2826c1
Proposed branch: ~xypron/grub:riscv
Merge into: ~ubuntu-core-dev/grub/+git/ubuntu:ubuntu
Diff against target: 4172 lines (+3092/-223) (has conflicts)
37 files modified
debian/control (+57/-7)
debian/patches/0076-ubuntu-Make-the-linux-command-in-EFI-grub-always-try.patch (+1/-1)
debian/patches/0096-linuxefi-fail-kernel-validation-without-shim-protoco.patch (+22/-22)
debian/patches/0099-chainloader-Avoid-a-double-free-when-validation-fail.patch (+3/-3)
debian/patches/RISC-V-Update-image-header.patch (+84/-0)
debian/patches/RISC-V-Use-common-linux-loader.patch (+120/-0)
debian/patches/dejavu-font-path.patch (+2/-2)
debian/patches/efi-add-definition-of-LoadFile2-protocol.patch (+61/-0)
debian/patches/efi-correct-struct-grub_efi_boot_services.patch (+28/-0)
debian/patches/efi-implement-grub_efi_run_image.patch (+898/-0)
debian/patches/efi-implemented-LoadFile2-initrd-loading-protocol-fo.patch (+183/-0)
debian/patches/efi-variable-storage-minimise-writes.patch (+1/-1)
debian/patches/efinet-set-dns-from-uefi-proto.patch (+4/-4)
debian/patches/efinet-set-network-from-uefi-devpath.patch (+3/-3)
debian/patches/efinet-uefi-ipv6-pxe-support.patch (+2/-2)
debian/patches/fat-fix-listing-the-root-directory.patch (+46/-0)
debian/patches/gfxpayload-dynamic.patch (+3/-3)
debian/patches/linux-ignore-FDT-unless-we-need-to-modify-it.patch (+80/-0)
debian/patches/loader-Move-arm64-linux-loader-to-common-code.patch (+1091/-0)
debian/patches/loader-drop-argv-argument-in-grub_initrd_load.patch (+178/-0)
debian/patches/maybe-quiet.patch (+3/-3)
debian/patches/mkconfig-ubuntu-recovery.patch (+2/-2)
debian/patches/no-devicetree-if-secure-boot.patch (+3/-3)
debian/patches/pc-verifiers-module.patch (+1/-1)
debian/patches/quick-boot.patch (+2/-2)
debian/patches/riscv-adjust-march-flags-for-binutils-2.38.patch (+43/-0)
debian/patches/series (+14/-0)
debian/patches/suse-add-support-for-UEFI-network-protocols.patch (+11/-11)
debian/patches/ubuntu-add-initrd-less-boot-fallback.patch (+1/-1)
debian/patches/ubuntu-efi-allow-loopmount-chainload.patch (+4/-4)
debian/patches/ubuntu-fix-lzma-decompressor-objcopy.patch (+1/-1)
debian/patches/ubuntu-linuxefi-arm64-set-base-addr.patch (+4/-4)
debian/patches/ubuntu-linuxefi-arm64.patch (+39/-52)
debian/patches/ubuntu-linuxefi.patch (+84/-83)
debian/patches/vt-handoff.patch (+2/-2)
debian/postinst.in (+2/-1)
debian/rules (+9/-5)
Conflict in debian/patches/series
Reviewer Review Type Date Requested Status
Ubuntu Core Development Team Pending
Review via email: mp+415733@code.launchpad.net

Commit message

With this pull request GRUB is built for riscv64.

* for ARM keep the broken existing code path
* for RISC-V use a new implementation of LoadImage(), StartImage() in peimage.c
* signing is not foreseen for RISC-V currently

This replaces https://code.launchpad.net/~xypron/grub/+git/grub/+merge/415323 and considers the comments provided.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/debian/control b/debian/control
index cdcb96f..f88631f 100644
--- a/debian/control
+++ b/debian/control
@@ -34,8 +34,8 @@ Build-Depends: debhelper-compat (= 10),
34 libparted-dev [any-powerpc any-ppc64 any-ppc64el],34 libparted-dev [any-powerpc any-ppc64 any-ppc64el],
35 pkg-config,35 pkg-config,
36 bash-completion,36 bash-completion,
37 libefiboot-dev [i386 amd64 ia64 x32 armel armhf arm64],37 libefiboot-dev [i386 amd64 ia64 x32 armel armhf arm64 riscv64],
38 libefivar-dev [i386 amd64 ia64 x32 armel armhf arm64],38 libefivar-dev [i386 amd64 ia64 x32 armel armhf arm64 riscv64],
39Build-Conflicts: autoconf2.13, libzfs-dev, libnvpair-dev39Build-Conflicts: autoconf2.13, libzfs-dev, libnvpair-dev
40Standards-Version: 3.9.640Standards-Version: 3.9.6
41Homepage: https://www.gnu.org/software/grub/41Homepage: https://www.gnu.org/software/grub/
@@ -63,9 +63,9 @@ Description: GRand Unified Bootloader, version 2 (dummy package)
63 This is a dummy transitional package that depends on grub-coreboot.63 This is a dummy transitional package that depends on grub-coreboot.
6464
65Package: grub-efi65Package: grub-efi
66Architecture: any-i386 any-amd64 any-arm64 any-ia64 any-arm66Architecture: any-i386 any-amd64 any-arm64 any-ia64 any-arm any-riscv64
67Pre-Depends: ${misc:Pre-Depends}67Pre-Depends: ${misc:Pre-Depends}
68Depends: ${misc:Depends}, grub-efi-ia32 (= ${binary:Version}) [any-i386], grub-efi-amd64 (>= ${binary:Version}) [any-amd64], grub-efi-arm64 (>= ${binary:Version}) [any-arm64], grub-efi-ia64 (= ${binary:Version}) [any-ia64], grub-efi-arm (= ${binary:Version}) [any-arm]68Depends: ${misc:Depends}, grub-efi-ia32 (= ${binary:Version}) [any-i386], grub-efi-amd64 (>= ${binary:Version}) [any-amd64], grub-efi-arm64 (>= ${binary:Version}) [any-arm64], grub-efi-ia64 (= ${binary:Version}) [any-ia64], grub-efi-arm (= ${binary:Version}) [any-arm], grub-efi-riscv64 (= ${binary:Version}) [any-riscv64]
69Multi-Arch: foreign69Multi-Arch: foreign
70Description: GRand Unified Bootloader, version 2 (dummy package)70Description: GRand Unified Bootloader, version 2 (dummy package)
71 This is a dummy package that depends on the grub-efi-$ARCH package most likely71 This is a dummy package that depends on the grub-efi-$ARCH package most likely
@@ -77,7 +77,7 @@ Built-Using: ${Built-Using}
77Depends: ${shlibs:Depends}, ${misc:Depends}, gettext-base, ${lsb-base-depends}77Depends: ${shlibs:Depends}, ${misc:Depends}, gettext-base, ${lsb-base-depends}
78Replaces: grub-pc (<< 2.00-4), grub-ieee1275 (<< 2.00-4), grub-efi (<< 1.99-1), grub-coreboot (<< 2.00-4), grub-linuxbios (<< 1.96+20080831-1), grub-efi-ia32 (<< 2.00-4), grub-efi-amd64 (<< 2.00-4), grub-efi-ia64 (<< 2.00-4), grub-yeeloong (<< 2.00-4), init-select78Replaces: grub-pc (<< 2.00-4), grub-ieee1275 (<< 2.00-4), grub-efi (<< 1.99-1), grub-coreboot (<< 2.00-4), grub-linuxbios (<< 1.96+20080831-1), grub-efi-ia32 (<< 2.00-4), grub-efi-amd64 (<< 2.00-4), grub-efi-ia64 (<< 2.00-4), grub-yeeloong (<< 2.00-4), init-select
79Recommends: os-prober (>= 1.33)79Recommends: os-prober (>= 1.33)
80Suggests: multiboot-doc, grub-emu [any-i386 any-amd64 any-powerpc], mtools [any-i386 any-amd64 any-ia64 any-arm any-arm64], xorriso (>= 0.5.6.pl00), desktop-base (>= 4.0.6), console-setup80Suggests: multiboot-doc, grub-emu [any-i386 any-amd64 any-powerpc], mtools [any-i386 any-amd64 any-ia64 any-arm any-arm64 riscv64], xorriso (>= 0.5.6.pl00), desktop-base (>= 4.0.6), console-setup
81Conflicts: init-select81Conflicts: init-select
82# mdadm: See bugs #435983 and #45574682# mdadm: See bugs #435983 and #455746
83Breaks: mdadm (<< 2.6.7-2), lupin-support (<< 0.55), friendly-recovery (<< 0.2.13), apport (<< 2.1.1)83Breaks: mdadm (<< 2.6.7-2), lupin-support (<< 0.55), friendly-recovery (<< 0.2.13), apport (<< 2.1.1)
@@ -94,7 +94,7 @@ Package: grub2-common
94# Not Architecture: any because this package contains some things which are94# Not Architecture: any because this package contains some things which are
95# only built when there is a real platform (e.g. grub-install), and the rest95# only built when there is a real platform (e.g. grub-install), and the rest
96# of the package is not very useful in a utilities-only build.96# of the package is not very useful in a utilities-only build.
97Architecture: any-i386 any-amd64 any-powerpc any-ppc64 any-ppc64el any-sparc any-sparc64 any-mipsel any-ia64 any-arm any-arm6497Architecture: any-i386 any-amd64 any-powerpc any-ppc64 any-ppc64el any-sparc any-sparc64 any-mipsel any-ia64 any-arm any-arm64 any-riscv64
98Depends: grub-common (= ${binary:Version}), dpkg (>= 1.15.4) | install-info, ${shlibs:Depends}, ${misc:Depends}98Depends: grub-common (= ${binary:Version}), dpkg (>= 1.15.4) | install-info, ${shlibs:Depends}, ${misc:Depends}
99Replaces: grub, grub-legacy, ${legacy-doc-br}, grub-common (<< 1.99-1), grub-pc (<< 2.02+dfsg1-7), grub-coreboot (<< 2.02+dfsg1-7), grub-efi-ia32 (<< 2.02+dfsg1-7), grub-efi-amd64 (<< 2.02+dfsg1-7), grub-efi-ia64 (<< 2.02+dfsg1-7), grub-efi-arm (<< 2.02+dfsg1-7), grub-efi-arm64 (<< 2.02+dfsg1-7), grub-ieee1275 (<< 2.02+dfsg1-7), grub-uboot (<< 2.02+dfsg1-7), grub-xen (<< 2.02+dfsg1-7), grub-yeeloong (<< 2.02+dfsg1-7), grub-cloud-amd64 (<< 0.0.4)99Replaces: grub, grub-legacy, ${legacy-doc-br}, grub-common (<< 1.99-1), grub-pc (<< 2.02+dfsg1-7), grub-coreboot (<< 2.02+dfsg1-7), grub-efi-ia32 (<< 2.02+dfsg1-7), grub-efi-amd64 (<< 2.02+dfsg1-7), grub-efi-ia64 (<< 2.02+dfsg1-7), grub-efi-arm (<< 2.02+dfsg1-7), grub-efi-arm64 (<< 2.02+dfsg1-7), grub-ieee1275 (<< 2.02+dfsg1-7), grub-uboot (<< 2.02+dfsg1-7), grub-xen (<< 2.02+dfsg1-7), grub-yeeloong (<< 2.02+dfsg1-7), grub-cloud-amd64 (<< 0.0.4)
100Conflicts: grub-legacy100Conflicts: grub-legacy
@@ -526,6 +526,56 @@ Description: GRand Unified Bootloader, version 2 (ARM64 UEFI signing template)
526 This package contains template files for grub-efi-arm64-signed.526 This package contains template files for grub-efi-arm64-signed.
527 This is only needed for Secure Boot signing.527 This is only needed for Secure Boot signing.
528528
529Package: grub-efi-riscv64-bin
530Architecture: any-riscv64
531Depends: ${shlibs:Depends}, ${misc:Depends}, grub-common (>= 2.02~beta2-9)
532Recommends: efibootmgr [linux-any]
533Multi-Arch: foreign
534XB-Efi-Vendor: ${efi:Vendor}
535Description: GRand Unified Bootloader, version 2 (riscv64 UEFI modules)
536 GRUB is a portable, powerful bootloader. This version of GRUB is based on a
537 cleaner design than its predecessors, and provides the following new features:
538 .
539 - Scripting in grub.cfg using BASH-like syntax.
540 - Support for modern partition maps such as GPT.
541 - Modular generation of grub.cfg via update-grub. Packages providing GRUB
542 add-ons can plug in their own script rules and trigger updates by invoking
543 update-grub.
544 .
545 This package contains GRUB modules that have been built for use on riscv64
546 systems with UEFI. It can be installed in parallel with other flavours,
547 but will not automatically install GRUB as the active boot loader nor
548 automatically update grub.cfg on upgrade unless grub-efi-riscv64 is also
549 installed.
550
551Package: grub-efi-riscv64-dbg
552Section: debug
553Architecture: any-riscv64
554Depends: ${misc:Depends}, grub-efi-riscv64-bin (= ${binary:Version})
555Multi-Arch: foreign
556Description: GRand Unified Bootloader, version 2 (riscv64 UEFI debug files)
557 This package contains debugging files for grub-efi-riscv64-bin. You only
558 need these if you are trying to debug GRUB using its GDB stub.
559
560Package: grub-efi-riscv64
561Architecture: any-riscv64
562Pre-Depends: ${misc:Pre-Depends}
563Depends: ${shlibs:Depends}, ${misc:Depends}, grub2-common (>= 2.02~beta2-9), grub-efi-riscv64-bin (= ${binary:Version}), ucf
564Multi-Arch: foreign
565Description: GRand Unified Bootloader, version 2 (riscv64 UEFI version)
566 GRUB is a portable, powerful bootloader. This version of GRUB is based on a
567 cleaner design than its predecessors, and provides the following new features:
568 .
569 - Scripting in grub.cfg using BASH-like syntax.
570 - Support for modern partition maps such as GPT.
571 - Modular generation of grub.cfg via update-grub. Packages providing GRUB
572 add-ons can plug in their own script rules and trigger updates by invoking
573 update-grub.
574 .
575 This is a dependency package for a version of GRUB that has been built for
576 use on RISC-V 64-bit systems with UEFI. Installing this package indicates that
577 this version of GRUB should be the active boot loader.
578
529Package: grub-ieee1275-bin579Package: grub-ieee1275-bin
530Architecture: any-i386 any-amd64 any-powerpc any-ppc64 any-ppc64el any-sparc any-sparc64580Architecture: any-i386 any-amd64 any-powerpc any-ppc64 any-ppc64el any-sparc any-sparc64
531Depends: ${shlibs:Depends}, ${misc:Depends}, grub-common (= ${binary:Version})581Depends: ${shlibs:Depends}, ${misc:Depends}, grub-common (= ${binary:Version})
@@ -765,7 +815,7 @@ Description: GRand Unified Bootloader, version 2 (Yeeloong version)
765Package: grub-theme-starfield815Package: grub-theme-starfield
766# Could be Architecture: any, but in practice this package is useless in a816# Could be Architecture: any, but in practice this package is useless in a
767# utilities-only build.817# utilities-only build.
768Architecture: any-i386 any-amd64 any-powerpc any-ppc64 any-ppc64el any-sparc any-sparc64 any-mipsel any-ia64 any-arm any-arm64818Architecture: any-i386 any-amd64 any-powerpc any-ppc64 any-ppc64el any-sparc any-sparc64 any-mipsel any-ia64 any-arm any-arm64 any-riscv64
769Depends: ${misc:Depends}, grub-common (= ${binary:Version})819Depends: ${misc:Depends}, grub-common (= ${binary:Version})
770Multi-Arch: foreign820Multi-Arch: foreign
771Description: GRand Unified Bootloader, version 2 (starfield theme)821Description: GRand Unified Bootloader, version 2 (starfield theme)
diff --git a/debian/patches/0076-ubuntu-Make-the-linux-command-in-EFI-grub-always-try.patch b/debian/patches/0076-ubuntu-Make-the-linux-command-in-EFI-grub-always-try.patch
index 53b5557..c225492 100644
--- a/debian/patches/0076-ubuntu-Make-the-linux-command-in-EFI-grub-always-try.patch
+++ b/debian/patches/0076-ubuntu-Make-the-linux-command-in-EFI-grub-always-try.patch
@@ -50,7 +50,7 @@ index 382ff52..9241fed 100644
50 50
51 params = grub_efi_allocate_pages_max (0x3fffffff,51 params = grub_efi_allocate_pages_max (0x3fffffff,
52diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c52diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c
53index d55b7cd..1649342 10064453index b6c13d7..e764e2a 100644
54--- a/grub-core/loader/i386/linux.c54--- a/grub-core/loader/i386/linux.c
55+++ b/grub-core/loader/i386/linux.c55+++ b/grub-core/loader/i386/linux.c
56@@ -665,35 +665,40 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),56@@ -665,35 +665,40 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
diff --git a/debian/patches/0096-linuxefi-fail-kernel-validation-without-shim-protoco.patch b/debian/patches/0096-linuxefi-fail-kernel-validation-without-shim-protoco.patch
index 433780e..360e21c 100644
--- a/debian/patches/0096-linuxefi-fail-kernel-validation-without-shim-protoco.patch
+++ b/debian/patches/0096-linuxefi-fail-kernel-validation-without-shim-protoco.patch
@@ -12,16 +12,28 @@ CVE-2020-15705
12Reported-by: Mathieu Trudel-Lapierre <cyphermox@ubuntu.com>12Reported-by: Mathieu Trudel-Lapierre <cyphermox@ubuntu.com>
13Signed-off-by: Dimitri John Ledkov <xnox@ubuntu.com>13Signed-off-by: Dimitri John Ledkov <xnox@ubuntu.com>
14---14---
15 grub-core/loader/arm64/linux.c | 13 +++++++++----
16 grub-core/loader/efi/chainloader.c | 1 +15 grub-core/loader/efi/chainloader.c | 1 +
17 grub-core/loader/efi/linux.c | 1 +16 grub-core/loader/efi/linux.c | 13 +++++++++----
17 grub-core/loader/efi/linux_sb.c | 1 +
18 grub-core/loader/i386/efi/linux.c | 2 +-18 grub-core/loader/i386/efi/linux.c | 2 +-
19 4 files changed, 12 insertions(+), 5 deletions(-)19 4 files changed, 12 insertions(+), 5 deletions(-)
2020
21diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c21diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c
22index 4e9eac3..f60ca2f 10064422index 2b74d79..9042603 100644
23--- a/grub-core/loader/arm64/linux.c23--- a/grub-core/loader/efi/chainloader.c
24+++ b/grub-core/loader/arm64/linux.c24+++ b/grub-core/loader/efi/chainloader.c
25@@ -1097,6 +1097,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
26
27 return 0;
28 }
29+ // -1 fall-through to fail
30
31 grub_file_close (file);
32 grub_device_close (dev);
33diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c
34index 93e4cfc..56d6745 100644
35--- a/grub-core/loader/efi/linux.c
36+++ b/grub-core/loader/efi/linux.c
25@@ -34,6 +34,7 @@37@@ -34,6 +34,7 @@
26 #include <grub/i18n.h>38 #include <grub/i18n.h>
27 #include <grub/lib/cmdline.h>39 #include <grub/lib/cmdline.h>
@@ -30,7 +42,7 @@ index 4e9eac3..f60ca2f 100644
30 42
31 GRUB_MOD_LICENSE ("GPLv3+");43 GRUB_MOD_LICENSE ("GPLv3+");
32 44
33@@ -345,11 +346,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),45@@ -455,11 +456,15 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
34 46
35 grub_dprintf ("linux", "kernel @ %p\n", kernel_addr);47 grub_dprintf ("linux", "kernel @ %p\n", kernel_addr);
36 48
@@ -50,22 +62,10 @@ index 4e9eac3..f60ca2f 100644
50 }62 }
51 63
52 pe = (void *)((unsigned long)kernel_addr + lh.hdr_offset);64 pe = (void *)((unsigned long)kernel_addr + lh.hdr_offset);
53diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c65diff --git a/grub-core/loader/efi/linux_sb.c b/grub-core/loader/efi/linux_sb.c
54index cf76f48..d64c851 100644
55--- a/grub-core/loader/efi/chainloader.c
56+++ b/grub-core/loader/efi/chainloader.c
57@@ -1098,6 +1098,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
58
59 return 0;
60 }
61+ // -1 fall-through to fail
62
63 grub_file_close (file);
64 grub_device_close (dev);
65diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c
66index 73a7196..a09479c 10064466index 73a7196..a09479c 100644
67--- a/grub-core/loader/efi/linux.c67--- a/grub-core/loader/efi/linux_sb.c
68+++ b/grub-core/loader/efi/linux.c68+++ b/grub-core/loader/efi/linux_sb.c
69@@ -34,6 +34,7 @@ struct grub_efi_shim_lock69@@ -34,6 +34,7 @@ struct grub_efi_shim_lock
70 };70 };
71 typedef struct grub_efi_shim_lock grub_efi_shim_lock_t;71 typedef struct grub_efi_shim_lock grub_efi_shim_lock_t;
diff --git a/debian/patches/0099-chainloader-Avoid-a-double-free-when-validation-fail.patch b/debian/patches/0099-chainloader-Avoid-a-double-free-when-validation-fail.patch
index 73748a8..defec76 100644
--- a/debian/patches/0099-chainloader-Avoid-a-double-free-when-validation-fail.patch
+++ b/debian/patches/0099-chainloader-Avoid-a-double-free-when-validation-fail.patch
@@ -7,10 +7,10 @@ Subject: chainloader: Avoid a double free when validation fails
7 1 file changed, 6 insertions(+), 3 deletions(-)7 1 file changed, 6 insertions(+), 3 deletions(-)
88
9diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c9diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c
10index d64c851..8515f89 10064410index 9042603..4a85f41 100644
11--- a/grub-core/loader/efi/chainloader.c11--- a/grub-core/loader/efi/chainloader.c
12+++ b/grub-core/loader/efi/chainloader.c12+++ b/grub-core/loader/efi/chainloader.c
13@@ -1086,6 +1086,9 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),13@@ -1085,6 +1085,9 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
14 if (rc > 0)14 if (rc > 0)
15 {15 {
16 grub_file_close (file);16 grub_file_close (file);
@@ -20,7 +20,7 @@ index d64c851..8515f89 100644
20 grub_loader_set (grub_secureboot_chainloader_boot,20 grub_loader_set (grub_secureboot_chainloader_boot,
21 grub_secureboot_chainloader_unload, 0);21 grub_secureboot_chainloader_unload, 0);
22 return 0;22 return 0;
23@@ -1094,15 +1097,15 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),23@@ -1093,15 +1096,15 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
24 {24 {
25 grub_load_and_start_image(boot_image);25 grub_load_and_start_image(boot_image);
26 grub_file_close (file);26 grub_file_close (file);
diff --git a/debian/patches/RISC-V-Update-image-header.patch b/debian/patches/RISC-V-Update-image-header.patch
27new file mode 10064427new file mode 100644
index 0000000..224165a
--- /dev/null
+++ b/debian/patches/RISC-V-Update-image-header.patch
@@ -0,0 +1,84 @@
1From: Atish Patra <atish.patra@wdc.com>
2Date: Thu, 28 Oct 2021 23:31:19 +0300
3Subject: RISC-V: Update image header
4
5Update the RISC-V Linux kernel image headers as per the current header.
6
7Reference:
8<Linux kernel source>/Documentation/riscv/boot-image-header.rst
9
10Signed-off-by: Atish Patra <atish.patra@wdc.com>
11Origin: https://lists.gnu.org/archive/html/grub-devel/2021-10/msg00213.html
12---
13 include/grub/riscv32/linux.h | 15 ++++++++-------
14 include/grub/riscv64/linux.h | 15 ++++++++-------
15 2 files changed, 16 insertions(+), 14 deletions(-)
16
17diff --git a/include/grub/riscv32/linux.h b/include/grub/riscv32/linux.h
18index 512b777..de0dbdc 100644
19--- a/include/grub/riscv32/linux.h
20+++ b/include/grub/riscv32/linux.h
21@@ -19,20 +19,21 @@
22 #ifndef GRUB_RISCV32_LINUX_HEADER
23 #define GRUB_RISCV32_LINUX_HEADER 1
24
25-#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x52534356 /* 'RSCV' */
26+#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x05435352 /* 'RSC\0x5' */
27
28-/* From linux/Documentation/riscv/booting.txt */
29+/* From linux/Documentation/riscv/boot-image-header.rst */
30 struct linux_riscv_kernel_header
31 {
32 grub_uint32_t code0; /* Executable code */
33 grub_uint32_t code1; /* Executable code */
34- grub_uint64_t text_offset; /* Image load offset */
35- grub_uint64_t res0; /* reserved */
36- grub_uint64_t res1; /* reserved */
37+ grub_uint64_t text_offset; /* Image load offset, little endian */
38+ grub_uint64_t image_size; /* Effective Image size, little endian */
39+ grub_uint64_t flags; /* kernel flags, little endian */
40+ grub_uint32_t version; /* Version of this header */
41+ grub_uint32_t res1; /* reserved */
42 grub_uint64_t res2; /* reserved */
43 grub_uint64_t res3; /* reserved */
44- grub_uint64_t res4; /* reserved */
45- grub_uint32_t magic; /* Magic number, little endian, "RSCV" */
46+ grub_uint32_t magic; /* Magic number, little endian, "RSC\x05" */
47 grub_uint32_t hdr_offset; /* Offset of PE/COFF header */
48 };
49
50diff --git a/include/grub/riscv64/linux.h b/include/grub/riscv64/linux.h
51index 3630c30..7c28bc9 100644
52--- a/include/grub/riscv64/linux.h
53+++ b/include/grub/riscv64/linux.h
54@@ -19,22 +19,23 @@
55 #ifndef GRUB_RISCV64_LINUX_HEADER
56 #define GRUB_RISCV64_LINUX_HEADER 1
57
58-#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x52534356 /* 'RSCV' */
59+#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x05435352 /* 'RSC\0x5' */
60
61 #define GRUB_EFI_PE_MAGIC 0x5A4D
62
63-/* From linux/Documentation/riscv/booting.txt */
64+/* From linux/Documentation/riscv/boot-image-header.rst */
65 struct linux_riscv_kernel_header
66 {
67 grub_uint32_t code0; /* Executable code */
68 grub_uint32_t code1; /* Executable code */
69- grub_uint64_t text_offset; /* Image load offset */
70- grub_uint64_t res0; /* reserved */
71- grub_uint64_t res1; /* reserved */
72+ grub_uint64_t text_offset; /* Image load offset, little endian */
73+ grub_uint64_t image_size; /* Effective Image size, little endian */
74+ grub_uint64_t flags; /* kernel flags, little endian */
75+ grub_uint32_t version; /* Version of this header */
76+ grub_uint32_t res1; /* reserved */
77 grub_uint64_t res2; /* reserved */
78 grub_uint64_t res3; /* reserved */
79- grub_uint64_t res4; /* reserved */
80- grub_uint32_t magic; /* Magic number, little endian, "RSCV" */
81+ grub_uint32_t magic; /* Magic number, little endian, "RSC\x05" */
82 grub_uint32_t hdr_offset; /* Offset of PE/COFF header */
83 };
84
diff --git a/debian/patches/RISC-V-Use-common-linux-loader.patch b/debian/patches/RISC-V-Use-common-linux-loader.patch
0new file mode 10064485new file mode 100644
index 0000000..de50acc
--- /dev/null
+++ b/debian/patches/RISC-V-Use-common-linux-loader.patch
@@ -0,0 +1,120 @@
1From: Atish Patra <atish.patra@wdc.com>
2Date: Thu, 28 Oct 2021 23:31:20 +0300
3Subject: RISC-V: Use common linux loader
4
5RISC-V doesn't have to do anything very different from other architectures
6to loader EFI stub linux kernel. As a result, just use the common linux
7loader instead of defining a RISC-V specific linux loader.
8
9Signed-off-by: Atish Patra <atish.patra@wdc.com>
10Origin: https://lists.gnu.org/archive/html/grub-devel/2021-10/msg00211.html
11---
12 grub-core/Makefile.core.def | 4 +--
13 grub-core/loader/riscv/linux.c | 59 ------------------------------------------
14 include/grub/riscv32/linux.h | 1 +
15 include/grub/riscv64/linux.h | 1 +
16 4 files changed, 4 insertions(+), 61 deletions(-)
17 delete mode 100644 grub-core/loader/riscv/linux.c
18
19diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
20index b36cf66..0536575 100644
21--- a/grub-core/Makefile.core.def
22+++ b/grub-core/Makefile.core.def
23@@ -1809,8 +1809,8 @@ module = {
24 arm_efi = loader/efi/linux.c;
25 arm_uboot = loader/arm/linux.c;
26 arm64 = loader/efi/linux.c;
27- riscv32 = loader/riscv/linux.c;
28- riscv64 = loader/riscv/linux.c;
29+ riscv32 = loader/efi/linux.c;
30+ riscv64 = loader/efi/linux.c;
31 common = loader/linux.c;
32 common = lib/cmdline.c;
33 enable = noemu;
34diff --git a/grub-core/loader/riscv/linux.c b/grub-core/loader/riscv/linux.c
35deleted file mode 100644
36index d17c488..0000000
37--- a/grub-core/loader/riscv/linux.c
38+++ /dev/null
39@@ -1,59 +0,0 @@
40-/*
41- * GRUB -- GRand Unified Bootloader
42- * Copyright (C) 2018 Free Software Foundation, Inc.
43- *
44- * GRUB is free software: you can redistribute it and/or modify
45- * it under the terms of the GNU General Public License as published by
46- * the Free Software Foundation, either version 3 of the License, or
47- * (at your option) any later version.
48- *
49- * GRUB is distributed in the hope that it will be useful,
50- * but WITHOUT ANY WARRANTY; without even the implied warranty of
51- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52- * GNU General Public License for more details.
53- *
54- * You should have received a copy of the GNU General Public License
55- * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
56- */
57-
58-#include <grub/command.h>
59-#include <grub/dl.h>
60-#include <grub/lib/cmdline.h>
61-
62-GRUB_MOD_LICENSE ("GPLv3+");
63-
64-static grub_err_t
65-grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
66- int argc __attribute__ ((unused)),
67- char *argv[] __attribute__ ((unused)))
68-{
69- grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("Linux not supported yet"));
70-
71- return grub_errno;
72-}
73-
74-static grub_err_t
75-grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
76- int argc __attribute__ ((unused)),
77- char *argv[] __attribute__ ((unused)))
78-{
79- grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("Linux not supported yet"));
80-
81- return grub_errno;
82-}
83-
84-static grub_command_t cmd_linux, cmd_initrd;
85-
86-GRUB_MOD_INIT (linux)
87-{
88- cmd_linux = grub_register_command ("linux", grub_cmd_linux, 0,
89- N_("Load Linux."));
90- cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, 0,
91- N_("Load initrd."));
92-}
93-
94-GRUB_MOD_FINI (linux)
95-{
96- grub_unregister_command (cmd_linux);
97- grub_unregister_command (cmd_initrd);
98-}
99diff --git a/include/grub/riscv32/linux.h b/include/grub/riscv32/linux.h
100index de0dbdc..706c690 100644
101--- a/include/grub/riscv32/linux.h
102+++ b/include/grub/riscv32/linux.h
103@@ -38,5 +38,6 @@ struct linux_riscv_kernel_header
104 };
105
106 #define linux_arch_kernel_header linux_riscv_kernel_header
107+# define GRUB_LINUX_ARCH_MAGIC_SIGNATURE GRUB_LINUX_RISCV_MAGIC_SIGNATURE
108
109 #endif /* ! GRUB_RISCV32_LINUX_HEADER */
110diff --git a/include/grub/riscv64/linux.h b/include/grub/riscv64/linux.h
111index 7c28bc9..88d5df7 100644
112--- a/include/grub/riscv64/linux.h
113+++ b/include/grub/riscv64/linux.h
114@@ -40,5 +40,6 @@ struct linux_riscv_kernel_header
115 };
116
117 #define linux_arch_kernel_header linux_riscv_kernel_header
118+# define GRUB_LINUX_ARCH_MAGIC_SIGNATURE GRUB_LINUX_RISCV_MAGIC_SIGNATURE
119
120 #endif /* ! GRUB_RISCV64_LINUX_HEADER */
diff --git a/debian/patches/dejavu-font-path.patch b/debian/patches/dejavu-font-path.patch
index 18b8376..2d9d197 100644
--- a/debian/patches/dejavu-font-path.patch
+++ b/debian/patches/dejavu-font-path.patch
@@ -8,10 +8,10 @@ Patch-Name: dejavu-font-path.patch
8 1 file changed, 1 insertion(+), 1 deletion(-)8 1 file changed, 1 insertion(+), 1 deletion(-)
99
10diff --git a/configure.ac b/configure.ac10diff --git a/configure.ac b/configure.ac
11index b3fb743..22c6cf7 10064411index d422626..a29beb9 100644
12--- a/configure.ac12--- a/configure.ac
13+++ b/configure.ac13+++ b/configure.ac
14@@ -1719,7 +1719,7 @@ fi14@@ -1727,7 +1727,7 @@ fi
15 15
16 if test x"$starfield_excuse" = x; then16 if test x"$starfield_excuse" = x; then
17 for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz; do17 for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz; do
diff --git a/debian/patches/efi-add-definition-of-LoadFile2-protocol.patch b/debian/patches/efi-add-definition-of-LoadFile2-protocol.patch
18new file mode 10064418new file mode 100644
index 0000000..d2263d3
--- /dev/null
+++ b/debian/patches/efi-add-definition-of-LoadFile2-protocol.patch
@@ -0,0 +1,61 @@
1From: Ard Biesheuvel <ard.biesheuvel@arm.com>
2Date: Thu, 28 Oct 2021 23:31:15 +0300
3Subject: efi: add definition of LoadFile2 protocol
4
5Incorporate the EFI_LOAD_FILE2_PROTOCOL GUID and C types from the
6UEFI spec.
7
8Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
9Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
10Signed-off-by: Nikita Ermakov <arei@altlinux.org>
11Origin: https://lists.gnu.org/archive/html/grub-devel/2021-10/msg00210.html
12---
13 grub-core/commands/efi/lsefi.c | 1 +
14 include/grub/efi/api.h | 15 +++++++++++++++
15 2 files changed, 16 insertions(+)
16
17diff --git a/grub-core/commands/efi/lsefi.c b/grub-core/commands/efi/lsefi.c
18index d1ce99a..4085f5d 100644
19--- a/grub-core/commands/efi/lsefi.c
20+++ b/grub-core/commands/efi/lsefi.c
21@@ -55,6 +55,7 @@ struct known_protocol
22 { GRUB_EFI_ABSOLUTE_POINTER_PROTOCOL_GUID, "absolute pointer" },
23 { GRUB_EFI_DRIVER_BINDING_PROTOCOL_GUID, "EFI driver binding" },
24 { GRUB_EFI_LOAD_FILE_PROTOCOL_GUID, "load file" },
25+ { GRUB_EFI_LOAD_FILE2_PROTOCOL_GUID, "load file2" },
26 { GRUB_EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID, "simple FS" },
27 { GRUB_EFI_TAPE_IO_PROTOCOL_GUID, "tape I/O" },
28 { GRUB_EFI_UNICODE_COLLATION_PROTOCOL_GUID, "unicode collation" },
29diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
30index f1a5221..3de0a7d 100644
31--- a/include/grub/efi/api.h
32+++ b/include/grub/efi/api.h
33@@ -149,6 +149,11 @@
34 { 0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B } \
35 }
36
37+#define GRUB_EFI_LOAD_FILE2_PROTOCOL_GUID \
38+ { 0x4006c0c1, 0xfcb3, 0x403e, \
39+ { 0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d } \
40+ }
41+
42 #define GRUB_EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \
43 { 0x0964e5b22, 0x6459, 0x11d2, \
44 { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \
45@@ -1729,6 +1734,16 @@ struct grub_efi_rng_protocol
46 };
47 typedef struct grub_efi_rng_protocol grub_efi_rng_protocol_t;
48
49+struct grub_efi_load_file2
50+{
51+ grub_efi_status_t (*load_file)(struct grub_efi_load_file2 *this,
52+ grub_efi_device_path_t *file_path,
53+ grub_efi_boolean_t boot_policy,
54+ grub_efi_uintn_t *buffer_size,
55+ void *buffer);
56+};
57+typedef struct grub_efi_load_file2 grub_efi_load_file2_t;
58+
59 #if (GRUB_TARGET_SIZEOF_VOID_P == 4) || defined (__ia64__) \
60 || defined (__aarch64__) || defined (__MINGW64__) || defined (__CYGWIN__) \
61 || defined(__riscv)
diff --git a/debian/patches/efi-correct-struct-grub_efi_boot_services.patch b/debian/patches/efi-correct-struct-grub_efi_boot_services.patch
0new file mode 10064462new file mode 100644
index 0000000..a4bf2c2
--- /dev/null
+++ b/debian/patches/efi-correct-struct-grub_efi_boot_services.patch
@@ -0,0 +1,28 @@
1From: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2Date: Sat, 22 Jan 2022 11:11:32 +0100
3Subject: efi: correct struct grub_efi_boot_services
4
5The UEFI specification defines that the EFI_BOOT_SERVICES.Exit(() service
6may return EFI_SUCCESS or EFI_INVALID_PARAMETER. So it cannot be
7__attribute__((noreturn)).
8
9Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
10Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
11Origin: https://lists.gnu.org/archive/html/grub-devel/2022-01/msg00121.html
12---
13 include/grub/efi/api.h | 2 +-
14 1 file changed, 1 insertion(+), 1 deletion(-)
15
16diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
17index 3211f04..c5dd4af 100644
18--- a/include/grub/efi/api.h
19+++ b/include/grub/efi/api.h
20@@ -1267,7 +1267,7 @@ struct grub_efi_boot_services
21 (*exit) (grub_efi_handle_t image_handle,
22 grub_efi_status_t exit_status,
23 grub_efi_uintn_t exit_data_size,
24- grub_efi_char16_t *exit_data) __attribute__((noreturn));
25+ grub_efi_char16_t *exit_data);
26
27 grub_efi_status_t
28 (*unload_image) (grub_efi_handle_t image_handle);
diff --git a/debian/patches/efi-implement-grub_efi_run_image.patch b/debian/patches/efi-implement-grub_efi_run_image.patch
0new file mode 10064429new file mode 100644
index 0000000..1ab5ba0
--- /dev/null
+++ b/debian/patches/efi-implement-grub_efi_run_image.patch
@@ -0,0 +1,898 @@
1From: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2Date: Tue, 18 Jan 2022 11:55:56 +0100
3Subject: efi: implement grub_efi_run_image
4
5Provide function grub_efi_run_image() which consumes a PE-COFF image
6loaded into memory. The function
7
8* checks validity of header
9* copies the sections
10* relocates the code
11* invalidates the instruction cache
12* executes the image
13* returns to caller
14
15Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
16---
17 grub-core/Makefile.core.def | 4 +
18 grub-core/loader/efi/linux.c | 21 ++
19 grub-core/loader/efi/peimage.c | 765 +++++++++++++++++++++++++++++++++++++++++
20 include/grub/efi/linux.h | 3 +
21 include/grub/efi/peimage.h | 28 ++
22 5 files changed, 821 insertions(+)
23 create mode 100644 grub-core/loader/efi/peimage.c
24 create mode 100644 include/grub/efi/peimage.h
25
26diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
27index 3b06462..2cfea95 100644
28--- a/grub-core/Makefile.core.def
29+++ b/grub-core/Makefile.core.def
30@@ -1822,13 +1822,17 @@ module = {
31 arm_coreboot = loader/arm/linux.c;
32 arm_efi = loader/efi/linux.c;
33 arm_efi = loader/efi/linux_sb.c;
34+ arm_efi = loader/efi/peimage.c;
35 arm_uboot = loader/arm/linux.c;
36 arm64 = loader/efi/linux.c;
37 arm64 = loader/efi/linux_sb.c;
38+ arm64 = loader/efi/peimage.c;
39 riscv32 = loader/efi/linux.c;
40 riscv32 = loader/efi/linux_sb.c;
41+ riscv32 = loader/efi/peimage.c;
42 riscv64 = loader/efi/linux.c;
43 riscv64 = loader/efi/linux_sb.c;
44+ riscv64 = loader/efi/peimage.c;
45 cflags = '-Wno-error=cast-align';
46 common = loader/linux.c;
47 common = lib/cmdline.c;
48diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c
49index 56d6745..18e7fe2 100644
50--- a/grub-core/loader/efi/linux.c
51+++ b/grub-core/loader/efi/linux.c
52@@ -190,7 +190,28 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr __attribute__((unused)),
53
54 grub_dprintf ("linux", "linux command line: '%s'\n", args);
55
56+/*
57+ * FIXME:
58+ *
59+ * We know that grub_efi_linux_boot() is broken:
60+ *
61+ * - The entry point address is not correctly determined.
62+ * - Section addresses are ignored.
63+ * - Sections having a raw size that is smaller than the virtual size are not
64+ * filled up with zeros.
65+ * - Relocations are ignored.
66+ * - Binaries calling Exit() quit GRUB.
67+ *
68+ * Thus we expect kernels to fail badly.
69+ *
70+ * Yet reviewers suggested to only change the code path for RISC-V until a
71+ * security audit of the code in grub_efi_run_image() is completed.
72+ */
73+#ifndef __riscv
74 retval = grub_efi_linux_boot (kernel_addr, handover_offset, kernel_addr);
75+#else
76+ retval = grub_efi_run_image (kernel_addr, kernel_size, linux_args);
77+#endif
78
79 /* When successful, not reached */
80 free_params();
81diff --git a/grub-core/loader/efi/peimage.c b/grub-core/loader/efi/peimage.c
82new file mode 100644
83index 0000000..f9735ab
84--- /dev/null
85+++ b/grub-core/loader/efi/peimage.c
86@@ -0,0 +1,765 @@
87+// SPDX-License-Identifier: GPL-3.0+
88+
89+#include <grub/cache.h>
90+#include <grub/cpu/efi/memory.h>
91+#include <grub/efi/efi.h>
92+#include <grub/efi/linux.h>
93+#include <grub/efi/pe32.h>
94+#include <grub/efi/peimage.h>
95+#include <grub/env.h>
96+#include <grub/misc.h>
97+#include <grub/mm.h>
98+#include <grub/setjmp.h>
99+
100+struct image_info {
101+ void *data;
102+ grub_efi_uint32_t data_size;
103+ grub_efi_uint16_t machine;
104+ grub_efi_uint16_t num_sections;
105+ struct grub_pe32_section_table *section;
106+ struct grub_pe32_data_directory *reloc;
107+ grub_uint64_t image_base;
108+ grub_uint32_t section_alignment;
109+ grub_uint32_t image_size;
110+ void *alloc_addr;
111+ grub_uint32_t alloc_pages;
112+ void *image_addr;
113+ grub_efi_entry_point entry_point;
114+};
115+
116+static struct {
117+ grub_jmp_buf jmp;
118+ grub_efi_handle_t image_handle;
119+ grub_efi_status_t exit_status;
120+ grub_efi_status_t EFIAPI (*exit)(grub_efi_handle_t image_handle,
121+ grub_efi_status_t exit_status,
122+ grub_efi_uintn_t exit_data_size,
123+ grub_efi_char16_t *exit_data);
124+} started_image;
125+
126+static int
127+debug_enabled(const char *condition)
128+{
129+ const char *debug;
130+
131+ debug = grub_env_get ("debug");
132+ if (!debug || !grub_strword(debug, condition))
133+ return 0;
134+
135+ return 1;
136+}
137+
138+static void
139+debug(const char *constraint)
140+{
141+ volatile grub_uint64_t x;
142+
143+ if (!debug_enabled(constraint))
144+ return;
145+
146+ grub_printf("Attach debugger\n");
147+ for (x = 1; x; ++x)
148+ ;
149+}
150+
151+__attribute__((unused)) static void
152+dump(const char *text, void *addr, unsigned int size)
153+{
154+ char *pos = addr;
155+
156+ grub_printf("%s @ 0x%lx\n", text, (unsigned long)addr);
157+ for (unsigned int i = 0; i < size; i += 16)
158+ grub_printf("%04x: %02x%02x %02x%02x %02x%02x %02x%02x "
159+ "%02x%02x %02x%02x %02x%02x %02x%02x\n", i,
160+ pos[i + 0], pos[i + 1], pos[i + 2], pos[i + 3],
161+ pos[i + 4], pos[i + 5], pos[i + 6], pos[i + 7],
162+ pos[i + 8], pos[i + 9], pos[i + 10], pos[i + 11],
163+ pos[i + 12], pos[i + 13], pos[i + 14], pos[i + 15]);
164+}
165+
166+static grub_uint16_t machines[] = {
167+#if defined(__x86_64__)
168+ GRUB_PE32_MACHINE_AMD64,
169+#elif defined(__i386__) || defined(__i486__) || defined(__i686__)
170+ GRUB_PE32_MACHINE_AMD64,
171+ GRUB_PE32_MACHINE_I386,
172+#elif defined(__aarch64__)
173+ GRUB_PE32_MACHINE_ARM64,
174+#elif defined(__arm__)
175+ GRUB_PE32_MACHINE_ARMTHUMB_MIXED,
176+#elif defined(__riscv) && __riscv_xlen == 32
177+ GRUB_PE32_MACHINE_RISCV32,
178+#elif defined(__riscv) && __riscv_xlen == 64
179+ GRUB_PE32_MACHINE_RISCV64,
180+#endif
181+};
182+
183+/**
184+ * check_machine_type() - check if the machine type matches the architecture
185+ *
186+ * @machine: the value of the Machine field of the COFF file header.
187+ * Return: status code
188+ */
189+static grub_efi_status_t check_machine_type(grub_uint16_t machine)
190+{
191+ for (grub_size_t i = 0; i < sizeof(machines) / sizeof(*machines); ++i) {
192+ if (machine == machines[i])
193+ return GRUB_EFI_SUCCESS;
194+ }
195+
196+ return GRUB_EFI_LOAD_ERROR;
197+}
198+
199+/**
200+ * check_pe_header() - check the headers of a PE-COFF image
201+ *
202+ * @info: information about the image
203+ */
204+static grub_efi_status_t check_pe_header(struct image_info *info)
205+{
206+ struct grub_dos_stub *dos_stub = info->data;
207+ void *pe_magic;
208+ struct grub_pe32_coff_header *coff_header;
209+ struct grub_pe32_optional_header *pe32_header;
210+ struct grub_pe64_optional_header *pe64_header;
211+ grub_uint32_t header_size;
212+
213+ if (info->data_size < sizeof(struct grub_dos_stub)) {
214+ grub_error(GRUB_ERR_BAD_OS, "truncated image");
215+ return GRUB_EFI_LOAD_ERROR;
216+ }
217+ if (dos_stub->magic != GRUB_PE32_MAGIC) {
218+ grub_error(GRUB_ERR_BAD_OS, "not a PE-COFF file");
219+ return GRUB_EFI_UNSUPPORTED;
220+ }
221+ if (info->data_size < dos_stub->pe_addr + sizeof(GRUB_PE_MAGIC) +
222+ sizeof(struct grub_pe32_coff_header) +
223+ sizeof(struct grub_pe64_optional_header)) {
224+ grub_error(GRUB_ERR_BAD_OS, "truncated image");
225+ return GRUB_EFI_LOAD_ERROR;
226+ }
227+ pe_magic = (void *)((unsigned long)info->data + dos_stub->pe_addr);
228+ if (grub_memcmp(pe_magic, GRUB_PE_MAGIC, sizeof(GRUB_PE_MAGIC))) {
229+ grub_error(GRUB_ERR_BAD_OS, "not a PE-COFF file");
230+ return GRUB_EFI_LOAD_ERROR;
231+ }
232+
233+ coff_header = (void *)((unsigned long)pe_magic + sizeof(GRUB_PE_MAGIC));
234+ info->machine = coff_header->machine;
235+ info->num_sections = coff_header->num_sections;
236+
237+ if (check_machine_type(info->machine) != GRUB_EFI_SUCCESS) {
238+ grub_error(GRUB_ERR_BAD_OS, "wrong machine type %u",
239+ coff_header->machine);
240+ return GRUB_EFI_LOAD_ERROR;
241+ }
242+
243+ pe32_header = (void *)((unsigned long)coff_header +
244+ sizeof(*coff_header));
245+ pe64_header = (void *)((unsigned long)coff_header +
246+ sizeof(*coff_header));
247+
248+ switch (pe32_header->magic) {
249+ case GRUB_PE32_PE32_MAGIC:
250+ info->section_alignment = pe32_header->section_alignment;
251+ info->image_base = pe32_header->image_base;
252+ info->image_size = pe32_header->image_size;
253+ info->entry_point =
254+ (void *)(unsigned long)pe32_header->entry_addr;
255+ header_size = pe32_header->header_size;
256+ if (info->data_size < header_size) {
257+ grub_error(GRUB_ERR_BAD_OS, "truncated image");
258+ return GRUB_EFI_LOAD_ERROR;
259+ }
260+
261+ if (pe32_header->num_data_directories >= 6 &&
262+ pe32_header->base_relocation_table.size)
263+ info->reloc = &pe32_header->base_relocation_table;
264+
265+ info->section = (void *)((unsigned long)&pe32_header->export_table +
266+ pe32_header->num_data_directories *
267+ sizeof(struct grub_pe32_data_directory));
268+ break;
269+ case GRUB_PE32_PE64_MAGIC:
270+ info->section_alignment = pe64_header->section_alignment;
271+ info->image_base = pe64_header->image_base;
272+ info->image_size = pe64_header->image_size;
273+ info->entry_point =
274+ (void *)(unsigned long)pe64_header->entry_addr;
275+ header_size = pe64_header->header_size;
276+ if (info->data_size < header_size) {
277+ grub_error(GRUB_ERR_BAD_OS, "truncated image");
278+ return GRUB_EFI_LOAD_ERROR;
279+ }
280+
281+ if (pe64_header->num_data_directories >= 6 &&
282+ pe64_header->base_relocation_table.size)
283+ info->reloc = &pe64_header->base_relocation_table;
284+
285+ info->section = (void *)((unsigned long)&pe64_header->export_table +
286+ pe64_header->num_data_directories *
287+ sizeof(struct grub_pe32_data_directory));
288+ break;
289+ default:
290+ grub_error(GRUB_ERR_BAD_OS, "not a PE-COFF file");
291+ return GRUB_EFI_LOAD_ERROR;
292+ }
293+
294+ if ((unsigned long)info->section +
295+ info->num_sections * sizeof(*info->section) >
296+ (unsigned long)info->data + info->data_size) {
297+ grub_error(GRUB_ERR_BAD_OS, "truncated image");
298+ return GRUB_EFI_LOAD_ERROR;
299+ }
300+
301+ grub_dprintf("linux", "PE-COFF header checked\n");
302+
303+ return GRUB_EFI_SUCCESS;
304+}
305+
306+/**
307+ * load_sections() - load image sections into memory
308+ *
309+ * Allocate fresh memory and copy the image sections there.
310+ *
311+ * @info: image information
312+ */
313+static grub_efi_status_t load_sections(struct image_info *info)
314+{
315+ struct grub_pe32_section_table *section;
316+ unsigned long align_mask = 0xfff;
317+
318+ /* Section alignment must be a power of two */
319+ if (info->section_alignment & (info->section_alignment - 1)) {
320+ grub_error(GRUB_ERR_BAD_OS, "invalid section alignment");
321+ return GRUB_EFI_LOAD_ERROR;
322+ }
323+
324+ if (info->section_alignment > align_mask)
325+ align_mask = info->section_alignment - 1;
326+
327+ info->alloc_pages = GRUB_EFI_BYTES_TO_PAGES(info->image_size +
328+ (align_mask & ~0xfffUL));
329+
330+ info->alloc_addr = grub_efi_allocate_pages_real(
331+ GRUB_EFI_MAX_USABLE_ADDRESS, info->alloc_pages,
332+ GRUB_EFI_ALLOCATE_MAX_ADDRESS, GRUB_EFI_LOADER_DATA);
333+ if (!info->alloc_addr)
334+ return GRUB_EFI_OUT_OF_RESOURCES;
335+
336+ info->image_addr =
337+ (void *)(((unsigned long)info->alloc_addr + align_mask) &
338+ ~align_mask);
339+
340+ for (section = &info->section[0];
341+ section < &info->section[info->num_sections]; ++section) {
342+ if (section->raw_data_offset + section->raw_data_size >
343+ info->data_size) {
344+ grub_error(GRUB_ERR_BAD_OS, "truncated image");
345+ return GRUB_EFI_LOAD_ERROR;
346+ }
347+ if (section->virtual_address + section->virtual_size >
348+ info->image_size) {
349+ grub_error(GRUB_ERR_BAD_OS, "section outside image");
350+ return GRUB_EFI_LOAD_ERROR;
351+ }
352+
353+ grub_memset(
354+ (void *)((unsigned long)info->image_addr +
355+ section->virtual_address), 0,
356+ section->virtual_size);
357+ grub_memcpy(
358+ (void *)((unsigned long)info->image_addr +
359+ section->virtual_address),
360+ (void *)((unsigned long)info->data +
361+ section->raw_data_offset),
362+ section->raw_data_size);
363+ }
364+
365+ info->entry_point = (void *)((unsigned long)info->entry_point +
366+ (unsigned long)info->image_addr);
367+
368+ grub_dprintf("linux", "sections loaded\n");
369+
370+ return GRUB_EFI_SUCCESS;
371+}
372+
373+/**
374+ * lo12i_get() - get the immediate value of a format I instruction
375+ *
376+ * Instruction format I::
377+ *
378+ * +---------------------------------------------------------------+
379+ * |f e d c b a 9 8 7 6 5 4 3 2 1 0 f e d c b a 9 8 7 6 5 4 3 2 1 0|
380+ * +-----------------------+---------+-----+---------+-------------+
381+ * | imm[11:0] | rs1 |fun3 | rd | opcode |
382+ * +-----------------------+---------+-----+---------+-------------+
383+ *
384+ * @instr: pointer to instruction
385+ * Return: immediate value
386+ */
387+static grub_uint16_t
388+lo12i_get(grub_uint32_t *instr)
389+{
390+ return ((*instr & 0xfff00000) >> 20);
391+}
392+
393+/**
394+ * lo12i_set() - set the immediate value of a format I instruction
395+ *
396+ * Instruction format I::
397+ *
398+ * +---------------------------------------------------------------+
399+ * |f e d c b a 9 8 7 6 5 4 3 2 1 0 f e d c b a 9 8 7 6 5 4 3 2 1 0|
400+ * +-----------------------+---------+-----+---------+-------------+
401+ * | imm[11:0] | rs1 |fun3 | rd | opcode |
402+ * +-----------------------+---------+-----+---------+-------------+
403+ *
404+ * @instr: pointer to instruction
405+ * @imm: immediate value
406+ */
407+static void
408+lo12i_set(grub_uint32_t *instr, grub_uint32_t imm)
409+{
410+ *instr = (*instr & 0x000fffff) |
411+ (imm & 0x00000fff << 20);
412+}
413+
414+/**
415+ * hi20_get() - get the immediate value of a format I instruction
416+ *
417+ * Instruction format U::
418+ *
419+ * +---------------------------------------------------------------+
420+ * |f e d c b a 9 8 7 6 5 4 3 2 1 0 f e d c b a 9 8 7 6 5 4 3 2 1 0|
421+ * +---------------------------------------+---------+-------------+
422+ * | imm[31:12] | rd | opcode |
423+ * +---------------------------------------+---------+-------------+
424+ *
425+ * @instr: pointer to instruction
426+ * Return: immediate value
427+ */
428+static grub_uint16_t
429+hi20_get(grub_uint32_t *instr)
430+{
431+ return *instr & 0xfffff000;
432+}
433+
434+/**
435+ * hi20_set() - set the immediate value of a format I instruction
436+ *
437+ * Instruction format U::
438+ *
439+ * +---------------------------------------------------------------+
440+ * |f e d c b a 9 8 7 6 5 4 3 2 1 0 f e d c b a 9 8 7 6 5 4 3 2 1 0|
441+ * +---------------------------------------+---------+-------------+
442+ * | imm[31:12] | rd | opcode |
443+ * +---------------------------------------+---------+-------------+
444+ *
445+ * @instr: pointer to instruction
446+ * @imm: immediate value
447+ */
448+static void
449+hi20_set(grub_uint32_t *instr, grub_uint32_t imm)
450+{
451+ *instr = (*instr & 0x00000fff) |
452+ (imm & 0xfffff000);
453+}
454+
455+/**
456+ * lo12s_get() - get the immediate value of a format I instruction
457+ *
458+ * Instruction format S::
459+ *
460+ * +---------------------------------------------------------------+
461+ * |f e d c b a 9 8 7 6 5 4 3 2 1 0 f e d c b a 9 8 7 6 5 4 3 2 1 0|
462+ * +-------------+---------+---------+-----+----+----+-------------+
463+ * | imm[11:5] | rs2 | rs1 |fun3 |imm[4:0] | opcode |
464+ * +-------------+---------+---------+-----+----+----+-------------+
465+ *
466+ * @instr: pointer to instruction
467+ * Return: immediate value
468+ */
469+static grub_uint16_t
470+lo12s_get(grub_uint32_t *instr)
471+{
472+ return ((*instr & 0x00000f80) >> 7) |
473+ ((*instr & 0xfe000000) >> 20);
474+}
475+
476+/**
477+ * lo12s_set() - set the immediate value of a format I instruction
478+ *
479+ * Instruction format S::
480+ *
481+ * +---------------------------------------------------------------+
482+ * |f e d c b a 9 8 7 6 5 4 3 2 1 0 f e d c b a 9 8 7 6 5 4 3 2 1 0|
483+ * +-------------+---------+---------+-----+----+----+-------------+
484+ * | imm[11:5] | rs2 | rs1 |fun3 |imm[4:0] | opcode |
485+ * +-------------+---------+---------+-----+----+----+-------------+
486+ *
487+ * @instr: pointer to instruction
488+ * @imm: immediate value
489+ */
490+static void
491+lo12s_set(grub_uint32_t *instr, grub_uint32_t imm)
492+{
493+ *instr = (*instr & 0x01fff07f) |
494+ (imm & 0x00000fe0 << 20) |
495+ (imm & 0x0000001f << 7);
496+}
497+
498+/**
499+ * movw_get_imm() - get the immediate value of MOVT and MOVT instructions
500+ *
501+ * MOVT::
502+ *
503+ * +-------------------------------+-------------------------------+
504+ * |f e d c b a 9 8 7 6 5 4 3 2 1 0|f e d c b a 9 8 7 6 5 4 3 2 1 0|
505+ * +---------+-+-----------+-------+-+-----+-------+---------------+
506+ * |1 1 1 1 0|i|1 0 1 1 0 0| imm4 |0| imm3| Rd | imm8 |
507+ * +---------+-+-----------+-------+-+-----+-------+---------------+
508+ *
509+ * MOVW::
510+ *
511+ * +-------------------------------+-------------------------------+
512+ * |f e d c b a 9 8 7 6 5 4 3 2 1 0|f e d c b a 9 8 7 6 5 4 3 2 1 0|
513+ * +---------+-+-----------+-------+-+-----+-------+---------------+
514+ * |1 1 1 1 0|i|1 0 0 1 0 0| imm4 |0| imm3| Rd | imm8 |
515+ * +---------+-+-----------+-------+-+-----+-------+---------------+
516+ *
517+ * @instr: pointer to instruction
518+ * Return: immediate value
519+ */
520+static grub_uint16_t
521+movw_get_imm(grub_uint16_t *instr)
522+{
523+ /* imm16 = imm4:i:imm3:imm8; */
524+ return (instr[1] & 0x00ff) |
525+ ((instr[1] & 0x7000) >> 3) |
526+ ((instr[0] & 0x0400) >> 8) |
527+ ((instr[0] & 0x000f) << 12);
528+}
529+
530+/**
531+ * movw_set_imm() - set the immediate value of MOVT and MOVT instructions
532+ *
533+ * MOVT::
534+ *
535+ * +-------------------------------+-------------------------------+
536+ * |f e d c b a 9 8 7 6 5 4 3 2 1 0|f e d c b a 9 8 7 6 5 4 3 2 1 0|
537+ * +---------+-+-----------+-------+-+-----+-------+---------------+
538+ * |1 1 1 1 0|i|1 0 1 1 0 0| imm4 |0| imm3| Rd | imm8 |
539+ * +---------+-+-----------+-------+-+-----+-------+---------------+
540+ *
541+ * MOVW::
542+ *
543+ * +-------------------------------+-------------------------------+
544+ * |f e d c b a 9 8 7 6 5 4 3 2 1 0|f e d c b a 9 8 7 6 5 4 3 2 1 0|
545+ * +---------+-+-----------+-------+-+-----+-------+---------------+
546+ * |1 1 1 1 0|i|1 0 0 1 0 0| imm4 |0| imm3| Rd | imm8 |
547+ * +---------+-+-----------+-------+-+-----+-------+---------------+
548+ *
549+ * @instr: pointer to instruction
550+ * @imm immediate value
551+ */
552+static void
553+movw_set_imm(grub_uint16_t *instr, grub_uint16_t imm)
554+{
555+ /* imm16 = imm4:i:imm3:imm8; */
556+ instr[0] = (instr[0] & 0xfbf0) |
557+ (imm & 0xf000) >> 12 |
558+ (imm & 0x0800) << 3;
559+ instr[1] = (instr[0] & 0x8f00) |
560+ (imm & 0xff) |
561+ (imm & 0x0700) >> 4;
562+}
563+
564+/**
565+ * relocate() - apply relocations to the image
566+ *
567+ * @info: information about the loaded image
568+ */
569+static grub_efi_status_t
570+relocate(struct image_info *info)
571+{
572+ struct grub_pe32_fixup_block *block, *reloc_end;
573+ unsigned long offset;
574+ grub_uint16_t reloc_type;
575+ grub_uint16_t *reloc_entry;
576+ grub_uint32_t *rvhi20_addr = NULL;
577+
578+ if (!info->reloc || !(info->reloc->size)) {
579+ grub_dprintf("linux", "no relocations\n");
580+ return GRUB_EFI_SUCCESS;
581+ }
582+
583+ if (info->reloc->rva + info->reloc->size > info->image_size) {
584+ grub_error(GRUB_ERR_BAD_OS, "relocation block outside image");
585+ return GRUB_EFI_LOAD_ERROR;
586+ }
587+
588+ /*
589+ * The relocations are based on the difference between
590+ * actual load address and the preferred base address.
591+ */
592+ offset = (unsigned long)info->image_addr - info->image_base;
593+
594+ block = (void *)((unsigned long)info->image_addr + info->reloc->rva);
595+ reloc_end = (void *)((unsigned long)block + info->reloc->size);
596+
597+ for (; block < reloc_end;
598+ block = (void *)((unsigned long)block + block->block_size)) {
599+ reloc_entry = block->entries;
600+ grub_uint16_t *block_end =
601+ (void *)((unsigned long)block + block->block_size);
602+
603+ for (; reloc_entry < block_end; ++reloc_entry) {
604+ void *addr = (void *)((unsigned long)info->image_addr +
605+ block->page_rva +
606+ (*reloc_entry & 0xfff));
607+
608+ reloc_type = *reloc_entry >> 12;
609+
610+ switch (reloc_type) {
611+ case GRUB_PE32_REL_BASED_ABSOLUTE:
612+ /* skip */
613+ break;
614+ case GRUB_PE32_REL_BASED_HIGH:
615+ *(grub_uint16_t *)addr += offset >> 16;
616+ break;
617+ case GRUB_PE32_REL_BASED_LOW:
618+ *(grub_uint16_t *)addr += offset;
619+ break;
620+ case GRUB_PE32_REL_BASED_HIGHLOW:
621+ *(grub_uint32_t *)addr += offset;
622+ break;
623+ case GRUB_PE32_REL_BASED_RISCV_HI20:
624+ switch (info->machine) {
625+ case GRUB_PE32_MACHINE_RISCV32:
626+ case GRUB_PE32_MACHINE_RISCV64:
627+ rvhi20_addr = addr;
628+ break;
629+ default:
630+ goto bad_reloc;
631+ }
632+ break;
633+ case GRUB_PE32_REL_BASED_ARM_MOV32T:
634+ /* = GRUB_PE32_REL_BASED_RISCV_LOW12I */
635+ switch (info->machine) {
636+ case GRUB_PE32_MACHINE_ARMTHUMB_MIXED: {
637+ grub_uint16_t *instr = addr;
638+ grub_uint32_t val;
639+
640+ val = movw_get_imm(&instr[0]) +
641+ (movw_get_imm(&instr[2]) << 16) +
642+ offset;
643+ movw_set_imm(&instr[0], val);
644+ movw_set_imm(&instr[2], val >> 16);
645+ break;
646+ }
647+ case GRUB_PE32_MACHINE_RISCV32:
648+ case GRUB_PE32_MACHINE_RISCV64:
649+ if (rvhi20_addr) {
650+ grub_uint32_t val =
651+ hi20_get(rvhi20_addr) +
652+ lo12i_get(addr) +
653+ offset;
654+ hi20_set(rvhi20_addr, val);
655+ lo12i_set(addr, val);
656+ rvhi20_addr = NULL;
657+ } else {
658+ goto bad_reloc;
659+ }
660+ break;
661+ default:
662+ goto bad_reloc;
663+ }
664+ break;
665+ case GRUB_PE32_REL_BASED_RISCV_LOW12S:
666+ switch (info->machine) {
667+ case GRUB_PE32_MACHINE_RISCV32:
668+ case GRUB_PE32_MACHINE_RISCV64:
669+ if (rvhi20_addr) {
670+ grub_uint32_t val =
671+ hi20_get(rvhi20_addr) +
672+ lo12s_get(addr) +
673+ offset;
674+ hi20_set(rvhi20_addr, val);
675+ lo12s_set(addr, val);
676+ rvhi20_addr = NULL;
677+ } else {
678+ goto bad_reloc;
679+ }
680+ break;
681+ default:
682+ goto bad_reloc;
683+ }
684+ break;
685+ case GRUB_PE32_REL_BASED_DIR64:
686+ *(grub_uint64_t *)addr += offset;
687+ break;
688+ default:
689+ goto bad_reloc;
690+ }
691+ }
692+ }
693+
694+ grub_dprintf("linux", "image relocated\n");
695+
696+ return GRUB_EFI_SUCCESS;
697+
698+bad_reloc:
699+ grub_error(GRUB_ERR_BAD_OS,
700+ "unsupported relocation type %d, rva 0x%08lx\n",
701+ *reloc_entry >> 12,
702+ (unsigned long)reloc_entry -
703+ (unsigned long)info->image_addr);
704+ return GRUB_EFI_LOAD_ERROR;
705+}
706+
707+/**
708+ * efi_exit() - replacement for EFI_BOOT_SERVICES.Exit()
709+ *
710+ * This function is inserted into system table to trap invocations of
711+ * EFI_BOOT_SERVICES.Exit(). If Exit() is called with our handle
712+ * return to our start routine using a long jump.
713+ *
714+ * @image_handle: handle of the application as passed on entry
715+ * @exit_status: the images exit code
716+ * @exit_data_size: size of @exit_data
717+ * @exit_data: null terminated string followed by optional data
718+ */
719+static grub_efi_status_t EFIAPI
720+efi_exit(grub_efi_handle_t image_handle,
721+ grub_efi_status_t exit_status,
722+ grub_efi_uintn_t exit_data_size,
723+ grub_efi_char16_t *exit_data)
724+{
725+ grub_efi_system_table->boot_services->exit = started_image.exit;
726+
727+ if (!image_handle)
728+ return GRUB_EFI_INVALID_PARAMETER;
729+
730+ if (image_handle != started_image.image_handle) {
731+ grub_dprintf("linux", "delegating Exit()\n");
732+ return efi_call_4(started_image.exit, image_handle,
733+ exit_status, exit_data_size,
734+ (grub_efi_char16_t *)exit_data);
735+ }
736+
737+ started_image.exit_status = exit_status;
738+
739+ if (exit_status != GRUB_EFI_SUCCESS) {
740+ grub_printf("Application failed, r = %d\n",
741+ (int)exit_status & 0x7fffffff);
742+ if (exit_data_size && exit_data) {
743+ grub_printf("exit message: ");
744+ for (grub_efi_uintn_t pos = 0;
745+ exit_data[pos] && pos < exit_data_size / 2; ++pos)
746+ grub_printf("%C", exit_data[pos]);
747+ grub_printf("\n");
748+ }
749+ }
750+ if (exit_data_size && exit_data) {
751+ /* exit data must be freed by the caller */
752+ efi_call_1(grub_efi_system_table->boot_services->free_pool,
753+ exit_data);
754+ }
755+ grub_longjmp(started_image.jmp, 1);
756+}
757+
758+/**
759+ * start_image() - our implementation of StartImage()
760+ *
761+ * As we do not load the image via LoadImage() we need our own implementation
762+ * of StartImage() to launch the PE-COFF image.
763+ */
764+static grub_efi_status_t
765+start_image(struct image_info *info)
766+{
767+ int ret;
768+ grub_efi_status_t status;
769+ grub_efi_loaded_image_t *loaded_image;
770+
771+ /*
772+ * TODO: It would better comply to the UEFI specification to
773+ * use a separate handle for the image we are running.
774+ */
775+ started_image.image_handle = grub_efi_image_handle;
776+
777+ loaded_image = grub_efi_get_loaded_image(grub_efi_image_handle);
778+ if (loaded_image) {
779+ loaded_image->image_base = info->image_addr;
780+ loaded_image->image_size = info->image_size;
781+ } else {
782+ grub_dprintf ("linux", "Loaded image protocol missing\n");
783+ }
784+
785+ ret = grub_setjmp(started_image.jmp);
786+ if (ret) {
787+ started_image.image_handle = NULL;
788+
789+ return started_image.exit_status;
790+ }
791+
792+ started_image.exit = grub_efi_system_table->boot_services->exit;
793+ grub_efi_system_table->boot_services->exit = efi_exit;
794+
795+ grub_dprintf("linux",
796+ "Executing image loaded at 0x%lx\nEntry point 0x%lx\nSize 0x%08x\n",
797+ (unsigned long)info->image_addr,
798+ (unsigned long)info->entry_point,
799+ info->image_size);
800+
801+ /* Invalidate the instruction cache */
802+ grub_arch_sync_caches(info->image_addr, info->image_size);
803+
804+ debug("pestart");
805+ status = efi_call_2(info->entry_point, started_image.image_handle,
806+ grub_efi_system_table);
807+
808+ grub_dprintf("linux", "Application returned\n");
809+
810+ return efi_exit(started_image.image_handle, status, 0, NULL);
811+}
812+
813+/**
814+ * grub_efi_run_image() - run a PE-COFF image from memory
815+ *
816+ * TODO: move the creation of the load options here
817+ *
818+ * @data: buffer with PE-COFF image
819+ * @data_size: size of the buffer
820+ * @args: command line to be passed as load options
821+ */
822+grub_efi_boolean_t
823+grub_efi_run_image(void *data, grub_efi_uint32_t data_size,
824+ const char *args __attribute__((unused)))
825+{
826+ struct image_info info = {
827+ .data = data,
828+ .data_size = data_size,
829+ };
830+
831+ /* read and check header */
832+ if (check_pe_header(&info) != GRUB_EFI_SUCCESS)
833+ goto err;
834+ /* load sections */
835+ if (load_sections(&info) != GRUB_EFI_SUCCESS)
836+ goto err;
837+
838+ if (relocate(&info) != GRUB_EFI_SUCCESS)
839+ goto err;
840+
841+ if (start_image(&info) != GRUB_EFI_SUCCESS)
842+ goto err;
843+
844+err:
845+ /* free allocated memory */
846+ if (info.alloc_addr)
847+ grub_efi_free_pages((unsigned long)info.alloc_addr,
848+ info.alloc_pages);
849+
850+ return 0;
851+}
852diff --git a/include/grub/efi/linux.h b/include/grub/efi/linux.h
853index 0033d93..39f5a9a 100644
854--- a/include/grub/efi/linux.h
855+++ b/include/grub/efi/linux.h
856@@ -27,5 +27,8 @@ EXPORT_FUNC(grub_linuxefi_secure_validate) (void *data, grub_uint32_t size);
857 grub_err_t
858 EXPORT_FUNC(grub_efi_linux_boot) (void *kernel_address, grub_off_t offset,
859 void *kernel_param);
860+grub_efi_boolean_t
861+EXPORT_FUNC(grub_efi_run_image) (void *data, grub_efi_uint32_t data_size,
862+ const char *args);
863
864 #endif /* ! GRUB_EFI_LINUX_HEADER */
865diff --git a/include/grub/efi/peimage.h b/include/grub/efi/peimage.h
866new file mode 100644
867index 0000000..70bfdc7
868--- /dev/null
869+++ b/include/grub/efi/peimage.h
870@@ -0,0 +1,28 @@
871+/* SPDX-License-Identifier: GPL-3.0+ */
872+
873+#define GRUB_PE_MAGIC "PE\0"
874+
875+#ifdef __x86_64__
876+#define EFIAPI __attribute__((ms_abi))
877+#else
878+#define EFIAPI
879+#endif
880+
881+#define EFI_LOADED_IMAGE_PROTOCOL_REVISION (0x1000)
882+
883+typedef grub_efi_status_t (*grub_efi_entry_point)
884+ (grub_efi_handle_t image_handle, grub_efi_system_table_t *system_table);
885+
886+struct grub_dos_stub {
887+ grub_uint16_t magic; /* MZ magic */
888+ grub_uint16_t lbsize; /* size of last block */
889+ grub_uint32_t res0; /* reserved */
890+ grub_uint64_t res1; /* reserved */
891+ grub_uint64_t res2; /* reserved */
892+ grub_uint64_t res3; /* reserved */
893+ grub_uint64_t res4; /* reserved */
894+ grub_uint64_t res5; /* reserved */
895+ grub_uint64_t res6; /* reserved */
896+ grub_uint32_t linux_arch; /* linux architecture */
897+ grub_uint32_t pe_addr; /* offset of PE/COFF header */
898+};
diff --git a/debian/patches/efi-implemented-LoadFile2-initrd-loading-protocol-fo.patch b/debian/patches/efi-implemented-LoadFile2-initrd-loading-protocol-fo.patch
0new file mode 100644899new file mode 100644
index 0000000..be73410
--- /dev/null
+++ b/debian/patches/efi-implemented-LoadFile2-initrd-loading-protocol-fo.patch
@@ -0,0 +1,183 @@
1From: Ard Biesheuvel <ard.biesheuvel@arm.com>
2Date: Thu, 28 Oct 2021 23:31:16 +0300
3Subject: efi: implemented LoadFile2 initrd loading protocol for Linux
4
5Recent Linux kernels will invoke the LoadFile2 protocol installed on
6a well-known vendor media path to load the initrd if it is exposed by
7the firmware. Using this method is preferred for two reasons:
8- the Linux kernel is in charge of allocating the memory, and so it can
9 implement any placement policy it wants (given that these tend to
10 change between kernel versions),
11- it is no longer necessary to modify the device tree provided by the
12 firmware.
13
14So let's install this protocol when handling the 'initrd' command if
15such a recent kernel was detected (based on the PE/COFF image version),
16and defer loading the initrd contents until the point where the kernel
17invokes the LoadFile2 protocol.
18
19Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
20Signed-off-by: Nikita Ermakov <arei@altlinux.org>
21Origin: https://lists.gnu.org/archive/html/grub-devel/2021-10/msg00214.html
22---
23 grub-core/loader/arm64/linux.c | 117 ++++++++++++++++++++++++++++++++++++++++-
24 1 file changed, 116 insertions(+), 1 deletion(-)
25
26diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c
27index aed7a20..6b03455 100644
28--- a/grub-core/loader/arm64/linux.c
29+++ b/grub-core/loader/arm64/linux.c
30@@ -48,9 +48,18 @@ static grub_uint32_t cmdline_size;
31 static grub_addr_t initrd_start;
32 static grub_addr_t initrd_end;
33
34+static struct grub_linux_initrd_context initrd_ctx = { 0, 0, 0 };
35+static grub_efi_handle_t initrd_lf2_handle;
36+static int initrd_use_loadfile2;
37+static grub_efi_guid_t load_file2_guid = GRUB_EFI_LOAD_FILE2_PROTOCOL_GUID;
38+static grub_efi_guid_t device_path_guid = GRUB_EFI_DEVICE_PATH_GUID;
39+
40 grub_err_t
41 grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh)
42 {
43+ struct grub_pe32_coff_header *coff_header;
44+ struct grub_pe32_optional_header *optional_header;
45+
46 if (lh->magic != GRUB_LINUX_ARMXX_MAGIC_SIGNATURE)
47 return grub_error(GRUB_ERR_BAD_OS, "invalid magic number");
48
49@@ -61,6 +70,21 @@ grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh)
50 grub_dprintf ("linux", "UEFI stub kernel:\n");
51 grub_dprintf ("linux", "PE/COFF header @ %08x\n", lh->hdr_offset);
52
53+ coff_header = (struct grub_pe32_coff_header *)((unsigned long)lh + lh->hdr_offset);
54+ optional_header = (struct grub_pe32_optional_header *)(coff_header + 1);
55+
56+ /*
57+ * Linux kernels built for any architecture are guaranteed to support the
58+ * LoadFile2 based initrd loading protocol if the image version is >= 1.
59+ */
60+ if (optional_header->major_image_version >= 1)
61+ initrd_use_loadfile2 = 1;
62+ else
63+ initrd_use_loadfile2 = 0;
64+
65+ grub_dprintf ("linux", "LoadFile2 initrd loading %sabled\n",
66+ initrd_use_loadfile2 ? "en" : "dis");
67+
68 return GRUB_ERR_NONE;
69 }
70
71@@ -230,13 +254,86 @@ allocate_initrd_mem (int initrd_pages)
72 GRUB_EFI_LOADER_DATA);
73 }
74
75+struct initrd_media_device_path {
76+ grub_efi_vendor_media_device_path_t vendor;
77+ grub_efi_device_path_t end;
78+} GRUB_PACKED;
79+
80+#define LINUX_EFI_INITRD_MEDIA_GUID \
81+ { 0x5568e427, 0x68fc, 0x4f3d, \
82+ { 0xac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68 } \
83+ }
84+
85+static struct initrd_media_device_path initrd_lf2_device_path = {
86+ {
87+ {
88+ GRUB_EFI_MEDIA_DEVICE_PATH_TYPE,
89+ GRUB_EFI_VENDOR_MEDIA_DEVICE_PATH_SUBTYPE,
90+ sizeof(grub_efi_vendor_media_device_path_t),
91+ },
92+ LINUX_EFI_INITRD_MEDIA_GUID
93+ }, {
94+ GRUB_EFI_END_DEVICE_PATH_TYPE,
95+ GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE,
96+ sizeof(grub_efi_device_path_t)
97+ }
98+};
99+
100+static grub_efi_status_t
101+grub_efi_initrd_load_file2(grub_efi_load_file2_t *this,
102+ grub_efi_device_path_t *device_path,
103+ grub_efi_boolean_t boot_policy,
104+ grub_efi_uintn_t *buffer_size,
105+ void *buffer);
106+
107+static grub_efi_load_file2_t initrd_lf2 = {
108+ grub_efi_initrd_load_file2
109+};
110+
111+static grub_efi_status_t
112+grub_efi_initrd_load_file2(grub_efi_load_file2_t *this,
113+ grub_efi_device_path_t *device_path,
114+ grub_efi_boolean_t boot_policy,
115+ grub_efi_uintn_t *buffer_size,
116+ void *buffer)
117+{
118+ grub_efi_status_t status = GRUB_EFI_SUCCESS;
119+ grub_efi_uintn_t initrd_size;
120+
121+ if (!this || this != &initrd_lf2 || !buffer_size)
122+ return GRUB_EFI_INVALID_PARAMETER;
123+
124+ if (device_path->type != GRUB_EFI_END_DEVICE_PATH_TYPE ||
125+ device_path->subtype != GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE)
126+ return GRUB_EFI_NOT_FOUND;
127+
128+ if (boot_policy)
129+ return GRUB_EFI_UNSUPPORTED;
130+
131+ initrd_size = grub_get_initrd_size (&initrd_ctx);
132+ if (!buffer || *buffer_size < initrd_size)
133+ {
134+ *buffer_size = initrd_size;
135+ return GRUB_EFI_BUFFER_TOO_SMALL;
136+ }
137+
138+ grub_dprintf ("linux", "Providing initrd via LOAD_FILE2_PROTOCOL\n");
139+
140+ if (grub_initrd_load (&initrd_ctx, buffer))
141+ status = GRUB_EFI_LOAD_ERROR;
142+
143+ grub_initrd_close (&initrd_ctx);
144+ return status;
145+}
146+
147 static grub_err_t
148 grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
149 int argc, char *argv[])
150 {
151- struct grub_linux_initrd_context initrd_ctx = { 0, 0, 0 };
152 int initrd_size, initrd_pages;
153 void *initrd_mem = NULL;
154+ grub_efi_boot_services_t *b;
155+ grub_efi_status_t status;
156
157 if (argc == 0)
158 {
159@@ -254,6 +351,24 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
160 if (grub_initrd_init (argc, argv, &initrd_ctx))
161 goto fail;
162
163+ if (initrd_use_loadfile2 && !initrd_lf2_handle)
164+ {
165+ b = grub_efi_system_table->boot_services;
166+ status = b->install_multiple_protocol_interfaces (&initrd_lf2_handle,
167+ &load_file2_guid,
168+ &initrd_lf2,
169+ &device_path_guid,
170+ &initrd_lf2_device_path,
171+ NULL);
172+ if (status == GRUB_EFI_OUT_OF_RESOURCES)
173+ {
174+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
175+ return grub_errno;
176+ }
177+ grub_dprintf ("linux", "LoadFile2 initrd loading protocol installed\n");
178+ return GRUB_ERR_NONE;
179+ }
180+
181 initrd_size = grub_get_initrd_size (&initrd_ctx);
182 grub_dprintf ("linux", "Loading initrd\n");
183
diff --git a/debian/patches/efi-variable-storage-minimise-writes.patch b/debian/patches/efi-variable-storage-minimise-writes.patch
index 4d3d134..7609e21 100644
--- a/debian/patches/efi-variable-storage-minimise-writes.patch
+++ b/debian/patches/efi-variable-storage-minimise-writes.patch
@@ -179,7 +179,7 @@ index 27f9482..a3d134b 100644
179 179
180 script = {180 script = {
181diff --git a/configure.ac b/configure.ac181diff --git a/configure.ac b/configure.ac
182index e11df6b..b3fb743 100644182index b4e33a6..d422626 100644
183--- a/configure.ac183--- a/configure.ac
184+++ b/configure.ac184+++ b/configure.ac
185@@ -452,6 +452,18 @@ AC_CHECK_HEADER([util.h], [185@@ -452,6 +452,18 @@ AC_CHECK_HEADER([util.h], [
diff --git a/debian/patches/efinet-set-dns-from-uefi-proto.patch b/debian/patches/efinet-set-dns-from-uefi-proto.patch
index 4588309..03da490 100644
--- a/debian/patches/efinet-set-dns-from-uefi-proto.patch
+++ b/debian/patches/efinet-set-dns-from-uefi-proto.patch
@@ -245,10 +245,10 @@ index 2d3b00f..82a28fb 100644
245 }245 }
246 246
247diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h247diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
248index 4b4652c..9cab1a5 100644248index d67c3f1..479c2a8 100644
249--- a/include/grub/efi/api.h249--- a/include/grub/efi/api.h
250+++ b/include/grub/efi/api.h250+++ b/include/grub/efi/api.h
251@@ -354,6 +354,16 @@251@@ -359,6 +359,16 @@
252 { 0x86, 0x2e, 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44 } \252 { 0x86, 0x2e, 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44 } \
253 }253 }
254 254
@@ -265,9 +265,9 @@ index 4b4652c..9cab1a5 100644
265 struct grub_efi_sal_system_table265 struct grub_efi_sal_system_table
266 {266 {
267 grub_uint32_t signature;267 grub_uint32_t signature;
268@@ -1793,6 +1803,72 @@ struct grub_efi_rng_protocol268@@ -1808,6 +1818,72 @@ struct grub_efi_load_file2
269 };269 };
270 typedef struct grub_efi_rng_protocol grub_efi_rng_protocol_t;270 typedef struct grub_efi_load_file2 grub_efi_load_file2_t;
271 271
272+enum grub_efi_ip4_config2_data_type {272+enum grub_efi_ip4_config2_data_type {
273+ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_INTERFACEINFO,273+ GRUB_EFI_IP4_CONFIG2_DATA_TYPE_INTERFACEINFO,
diff --git a/debian/patches/efinet-set-network-from-uefi-devpath.patch b/debian/patches/efinet-set-network-from-uefi-devpath.patch
index af95c63..bd19f83 100644
--- a/debian/patches/efinet-set-network-from-uefi-devpath.patch
+++ b/debian/patches/efinet-set-network-from-uefi-devpath.patch
@@ -357,10 +357,10 @@ index fc90415..2d3b00f 100644
357 }357 }
358 }358 }
359diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h359diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
360index 50ab8e8..4b4652c 100644360index 2c649cf..d67c3f1 100644
361--- a/include/grub/efi/api.h361--- a/include/grub/efi/api.h
362+++ b/include/grub/efi/api.h362+++ b/include/grub/efi/api.h
363@@ -849,6 +849,8 @@ struct grub_efi_ipv4_device_path363@@ -854,6 +854,8 @@ struct grub_efi_ipv4_device_path
364 grub_efi_uint16_t remote_port;364 grub_efi_uint16_t remote_port;
365 grub_efi_uint16_t protocol;365 grub_efi_uint16_t protocol;
366 grub_efi_uint8_t static_ip_address;366 grub_efi_uint8_t static_ip_address;
@@ -369,7 +369,7 @@ index 50ab8e8..4b4652c 100644
369 } GRUB_PACKED;369 } GRUB_PACKED;
370 typedef struct grub_efi_ipv4_device_path grub_efi_ipv4_device_path_t;370 typedef struct grub_efi_ipv4_device_path grub_efi_ipv4_device_path_t;
371 371
372@@ -903,6 +905,15 @@ struct grub_efi_sata_device_path372@@ -908,6 +910,15 @@ struct grub_efi_sata_device_path
373 } GRUB_PACKED;373 } GRUB_PACKED;
374 typedef struct grub_efi_sata_device_path grub_efi_sata_device_path_t;374 typedef struct grub_efi_sata_device_path grub_efi_sata_device_path_t;
375 375
diff --git a/debian/patches/efinet-uefi-ipv6-pxe-support.patch b/debian/patches/efinet-uefi-ipv6-pxe-support.patch
index 13f69ed..d256127 100644
--- a/debian/patches/efinet-uefi-ipv6-pxe-support.patch
+++ b/debian/patches/efinet-uefi-ipv6-pxe-support.patch
@@ -51,10 +51,10 @@ index 5388f95..fc90415 100644
51 }51 }
52 }52 }
53diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h53diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
54index f1a5221..50ab8e8 10064454index 3de0a7d..2c649cf 100644
55--- a/include/grub/efi/api.h55--- a/include/grub/efi/api.h
56+++ b/include/grub/efi/api.h56+++ b/include/grub/efi/api.h
57@@ -1476,14 +1476,67 @@ typedef struct grub_efi_simple_text_output_interface grub_efi_simple_text_output57@@ -1481,14 +1481,67 @@ typedef struct grub_efi_simple_text_output_interface grub_efi_simple_text_output
58 58
59 typedef grub_uint8_t grub_efi_pxe_packet_t[1472];59 typedef grub_uint8_t grub_efi_pxe_packet_t[1472];
60 60
diff --git a/debian/patches/fat-fix-listing-the-root-directory.patch b/debian/patches/fat-fix-listing-the-root-directory.patch
61new file mode 10064461new file mode 100644
index 0000000..335ec4c
--- /dev/null
+++ b/debian/patches/fat-fix-listing-the-root-directory.patch
@@ -0,0 +1,46 @@
1From: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2Date: Fri, 21 Jan 2022 20:15:41 +0100
3Subject: fat: fix listing the root directory
4
5ls / for a FAT partition leads to
6
7 error: invalid modification timestamp for /.
8
9Not all entries of the directory are displayed.
10
11Linux never updates the modification timestamp of the /. directory entry.
12The FAT specification allows the access and creation date fields to be
13zero.
14
15We should follow Linux and render initial FAT timestamps as start of
16the epoch.
17
18Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
19Origin: https://lists.gnu.org/archive/html/grub-devel/2022-01/msg00116.html
20---
21 grub-core/fs/fat.c | 12 ++++++++++++
22 1 file changed, 12 insertions(+)
23
24diff --git a/grub-core/fs/fat.c b/grub-core/fs/fat.c
25index dd82e4e..35ff0b2 100644
26--- a/grub-core/fs/fat.c
27+++ b/grub-core/fs/fat.c
28@@ -901,6 +901,18 @@ grub_fat_timestamp (grub_uint16_t time, grub_uint16_t date, grub_int64_t *nix) {
29 .second = (time & 0x001F) * 2,
30 };
31
32+ /*
33+ * The modification time of the root directory is never set by Linux.
34+ * Creation and access time are optional and can be zero.
35+ * Follow Linux and render FAT initial timestamps as the start of the epoch.
36+ */
37+ if (date == 0 && time == 0)
38+ {
39+ datetime.year = 1970;
40+ datetime.month = 1;
41+ datetime.day = 1;
42+ }
43+
44 /* The conversion below allows seconds=60, so don't trust its validation. */
45 if ((time & 0x1F) > 29)
46 return 0;
diff --git a/debian/patches/gfxpayload-dynamic.patch b/debian/patches/gfxpayload-dynamic.patch
index 0148257..e59cb02 100644
--- a/debian/patches/gfxpayload-dynamic.patch
+++ b/debian/patches/gfxpayload-dynamic.patch
@@ -21,10 +21,10 @@ Patch-Name: gfxpayload-dynamic.patch
21 create mode 100644 grub-core/commands/i386/pc/hwmatch.c21 create mode 100644 grub-core/commands/i386/pc/hwmatch.c
2222
23diff --git a/configure.ac b/configure.ac23diff --git a/configure.ac b/configure.ac
24index c42e4c7..947fd52 10064424index 4882eba..3203749 100644
25--- a/configure.ac25--- a/configure.ac
26+++ b/configure.ac26+++ b/configure.ac
27@@ -1937,6 +1937,17 @@ else27@@ -1945,6 +1945,17 @@ else
28 fi28 fi
29 AC_SUBST([QUICK_BOOT])29 AC_SUBST([QUICK_BOOT])
30 30
@@ -43,7 +43,7 @@ index c42e4c7..947fd52 100644
43 43
44 AC_SUBST([FONT_SOURCE])44 AC_SUBST([FONT_SOURCE])
45diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def45diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
46index 715d137..10f839b 10064446index 1a3ead6..0d7bce1 100644
47--- a/grub-core/Makefile.core.def47--- a/grub-core/Makefile.core.def
48+++ b/grub-core/Makefile.core.def48+++ b/grub-core/Makefile.core.def
49@@ -964,6 +964,14 @@ module = {49@@ -964,6 +964,14 @@ module = {
diff --git a/debian/patches/linux-ignore-FDT-unless-we-need-to-modify-it.patch b/debian/patches/linux-ignore-FDT-unless-we-need-to-modify-it.patch
50new file mode 10064450new file mode 100644
index 0000000..a37aea4
--- /dev/null
+++ b/debian/patches/linux-ignore-FDT-unless-we-need-to-modify-it.patch
@@ -0,0 +1,80 @@
1From: Ard Biesheuvel <ard.biesheuvel@arm.com>
2Date: Thu, 28 Oct 2021 23:31:17 +0300
3Subject: linux: ignore FDT unless we need to modify it
4
5Now that we implemented supported for the LoadFile2 protocol for initrd
6loading, there is no longer a need to pass the initrd parameters via
7the device tree. This means there is no longer a reason to update the
8device tree in the first place, and so we can ignore it entirely.
9
10The only remaining reason to deal with the devicetree is if we are
11using the 'devicetree' command to load one from disk, so tweak the
12logic in grub_fdt_install() to take that into account.
13
14Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
15Origin: https://lists.gnu.org/archive/html/grub-devel/2021-10/msg00216.html
16---
17 grub-core/loader/arm64/linux.c | 22 +++++++++++-----------
18 grub-core/loader/efi/fdt.c | 7 +++++--
19 2 files changed, 16 insertions(+), 13 deletions(-)
20
21diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c
22index 6b03455..65f1275 100644
23--- a/grub-core/loader/arm64/linux.c
24+++ b/grub-core/loader/arm64/linux.c
25@@ -95,21 +95,21 @@ finalize_params_linux (void)
26
27 void *fdt;
28
29- fdt = grub_fdt_load (GRUB_EFI_LINUX_FDT_EXTRA_SPACE);
30+ /* Set initrd info */
31+ if (initrd_start && initrd_end > initrd_start)
32+ {
33+ fdt = grub_fdt_load (GRUB_EFI_LINUX_FDT_EXTRA_SPACE);
34
35- if (!fdt)
36- goto failure;
37+ if (!fdt)
38+ goto failure;
39
40- node = grub_fdt_find_subnode (fdt, 0, "chosen");
41- if (node < 0)
42- node = grub_fdt_add_subnode (fdt, 0, "chosen");
43+ node = grub_fdt_find_subnode (fdt, 0, "chosen");
44+ if (node < 0)
45+ node = grub_fdt_add_subnode (fdt, 0, "chosen");
46
47- if (node < 1)
48- goto failure;
49+ if (node < 1)
50+ goto failure;
51
52- /* Set initrd info */
53- if (initrd_start && initrd_end > initrd_start)
54- {
55 grub_dprintf ("linux", "Initrd @ %p-%p\n",
56 (void *) initrd_start, (void *) initrd_end);
57
58diff --git a/grub-core/loader/efi/fdt.c b/grub-core/loader/efi/fdt.c
59index c86f283..771d455 100644
60--- a/grub-core/loader/efi/fdt.c
61+++ b/grub-core/loader/efi/fdt.c
62@@ -89,13 +89,16 @@ grub_fdt_install (void)
63 grub_efi_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID;
64 grub_efi_status_t status;
65
66+ if (!fdt && !loaded_fdt)
67+ return GRUB_ERR_NONE;
68+
69 b = grub_efi_system_table->boot_services;
70- status = b->install_configuration_table (&fdt_guid, fdt);
71+ status = b->install_configuration_table (&fdt_guid, fdt ?: loaded_fdt);
72 if (status != GRUB_EFI_SUCCESS)
73 return grub_error (GRUB_ERR_IO, "failed to install FDT");
74
75 grub_dprintf ("fdt", "Installed/updated FDT configuration table @ %p\n",
76- fdt);
77+ fdt ?: loaded_fdt);
78 return GRUB_ERR_NONE;
79 }
80
diff --git a/debian/patches/loader-Move-arm64-linux-loader-to-common-code.patch b/debian/patches/loader-Move-arm64-linux-loader-to-common-code.patch
0new file mode 10064481new file mode 100644
index 0000000..0cf0470
--- /dev/null
+++ b/debian/patches/loader-Move-arm64-linux-loader-to-common-code.patch
@@ -0,0 +1,1091 @@
1From: Atish Patra <atish.patra@wdc.com>
2Date: Thu, 28 Oct 2021 23:31:18 +0300
3Subject: loader: Move arm64 linux loader to common code
4
5ARM64 linux loader code is written in such a way that it can be reused
6across different architectures without much change. Move it to common
7code so that RISC-V doesn't have to define a separate loader.
8
9Signed-off-by: Atish Patra <atish.patra@wdc.com>
10Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
11Origin: https://lists.gnu.org/archive/html/grub-devel/2021-10/msg00215.html
12---
13 grub-core/Makefile.core.def | 4 +-
14 grub-core/loader/arm64/linux.c | 508 -----------------------------------------
15 grub-core/loader/efi/linux.c | 508 +++++++++++++++++++++++++++++++++++++++++
16 include/grub/arm/linux.h | 2 +-
17 include/grub/arm64/linux.h | 2 +-
18 5 files changed, 512 insertions(+), 512 deletions(-)
19 delete mode 100644 grub-core/loader/arm64/linux.c
20 create mode 100644 grub-core/loader/efi/linux.c
21
22diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
23index 8022e1c..b36cf66 100644
24--- a/grub-core/Makefile.core.def
25+++ b/grub-core/Makefile.core.def
26@@ -1806,9 +1806,9 @@ module = {
27 sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c;
28 ia64_efi = loader/ia64/efi/linux.c;
29 arm_coreboot = loader/arm/linux.c;
30- arm_efi = loader/arm64/linux.c;
31+ arm_efi = loader/efi/linux.c;
32 arm_uboot = loader/arm/linux.c;
33- arm64 = loader/arm64/linux.c;
34+ arm64 = loader/efi/linux.c;
35 riscv32 = loader/riscv/linux.c;
36 riscv64 = loader/riscv/linux.c;
37 common = loader/linux.c;
38diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c
39deleted file mode 100644
40index 65f1275..0000000
41--- a/grub-core/loader/arm64/linux.c
42+++ /dev/null
43@@ -1,508 +0,0 @@
44-/*
45- * GRUB -- GRand Unified Bootloader
46- * Copyright (C) 2013 Free Software Foundation, Inc.
47- *
48- * GRUB is free software: you can redistribute it and/or modify
49- * it under the terms of the GNU General Public License as published by
50- * the Free Software Foundation, either version 3 of the License, or
51- * (at your option) any later version.
52- *
53- * GRUB is distributed in the hope that it will be useful,
54- * but WITHOUT ANY WARRANTY; without even the implied warranty of
55- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
56- * GNU General Public License for more details.
57- *
58- * You should have received a copy of the GNU General Public License
59- * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
60- */
61-
62-#include <grub/charset.h>
63-#include <grub/command.h>
64-#include <grub/err.h>
65-#include <grub/file.h>
66-#include <grub/fdt.h>
67-#include <grub/linux.h>
68-#include <grub/loader.h>
69-#include <grub/mm.h>
70-#include <grub/types.h>
71-#include <grub/cpu/linux.h>
72-#include <grub/efi/efi.h>
73-#include <grub/efi/fdtload.h>
74-#include <grub/efi/memory.h>
75-#include <grub/efi/pe32.h>
76-#include <grub/i18n.h>
77-#include <grub/lib/cmdline.h>
78-#include <grub/verify.h>
79-
80-GRUB_MOD_LICENSE ("GPLv3+");
81-
82-static grub_dl_t my_mod;
83-static int loaded;
84-
85-static void *kernel_addr;
86-static grub_uint64_t kernel_size;
87-
88-static char *linux_args;
89-static grub_uint32_t cmdline_size;
90-
91-static grub_addr_t initrd_start;
92-static grub_addr_t initrd_end;
93-
94-static struct grub_linux_initrd_context initrd_ctx = { 0, 0, 0 };
95-static grub_efi_handle_t initrd_lf2_handle;
96-static int initrd_use_loadfile2;
97-static grub_efi_guid_t load_file2_guid = GRUB_EFI_LOAD_FILE2_PROTOCOL_GUID;
98-static grub_efi_guid_t device_path_guid = GRUB_EFI_DEVICE_PATH_GUID;
99-
100-grub_err_t
101-grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh)
102-{
103- struct grub_pe32_coff_header *coff_header;
104- struct grub_pe32_optional_header *optional_header;
105-
106- if (lh->magic != GRUB_LINUX_ARMXX_MAGIC_SIGNATURE)
107- return grub_error(GRUB_ERR_BAD_OS, "invalid magic number");
108-
109- if ((lh->code0 & 0xffff) != GRUB_PE32_MAGIC)
110- return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
111- N_("plain image kernel not supported - rebuild with CONFIG_(U)EFI_STUB enabled"));
112-
113- grub_dprintf ("linux", "UEFI stub kernel:\n");
114- grub_dprintf ("linux", "PE/COFF header @ %08x\n", lh->hdr_offset);
115-
116- coff_header = (struct grub_pe32_coff_header *)((unsigned long)lh + lh->hdr_offset);
117- optional_header = (struct grub_pe32_optional_header *)(coff_header + 1);
118-
119- /*
120- * Linux kernels built for any architecture are guaranteed to support the
121- * LoadFile2 based initrd loading protocol if the image version is >= 1.
122- */
123- if (optional_header->major_image_version >= 1)
124- initrd_use_loadfile2 = 1;
125- else
126- initrd_use_loadfile2 = 0;
127-
128- grub_dprintf ("linux", "LoadFile2 initrd loading %sabled\n",
129- initrd_use_loadfile2 ? "en" : "dis");
130-
131- return GRUB_ERR_NONE;
132-}
133-
134-static grub_err_t
135-finalize_params_linux (void)
136-{
137- int node, retval;
138-
139- void *fdt;
140-
141- /* Set initrd info */
142- if (initrd_start && initrd_end > initrd_start)
143- {
144- fdt = grub_fdt_load (GRUB_EFI_LINUX_FDT_EXTRA_SPACE);
145-
146- if (!fdt)
147- goto failure;
148-
149- node = grub_fdt_find_subnode (fdt, 0, "chosen");
150- if (node < 0)
151- node = grub_fdt_add_subnode (fdt, 0, "chosen");
152-
153- if (node < 1)
154- goto failure;
155-
156- grub_dprintf ("linux", "Initrd @ %p-%p\n",
157- (void *) initrd_start, (void *) initrd_end);
158-
159- retval = grub_fdt_set_prop64 (fdt, node, "linux,initrd-start",
160- initrd_start);
161- if (retval)
162- goto failure;
163- retval = grub_fdt_set_prop64 (fdt, node, "linux,initrd-end",
164- initrd_end);
165- if (retval)
166- goto failure;
167- }
168-
169- if (grub_fdt_install() != GRUB_ERR_NONE)
170- goto failure;
171-
172- return GRUB_ERR_NONE;
173-
174-failure:
175- grub_fdt_unload();
176- return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT");
177-}
178-
179-grub_err_t
180-grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)
181-{
182- grub_efi_memory_mapped_device_path_t *mempath;
183- grub_efi_handle_t image_handle;
184- grub_efi_boot_services_t *b;
185- grub_efi_status_t status;
186- grub_efi_loaded_image_t *loaded_image;
187- int len;
188-
189- mempath = grub_malloc (2 * sizeof (grub_efi_memory_mapped_device_path_t));
190- if (!mempath)
191- return grub_errno;
192-
193- mempath[0].header.type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE;
194- mempath[0].header.subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE;
195- mempath[0].header.length = grub_cpu_to_le16_compile_time (sizeof (*mempath));
196- mempath[0].memory_type = GRUB_EFI_LOADER_DATA;
197- mempath[0].start_address = addr;
198- mempath[0].end_address = addr + size;
199-
200- mempath[1].header.type = GRUB_EFI_END_DEVICE_PATH_TYPE;
201- mempath[1].header.subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE;
202- mempath[1].header.length = sizeof (grub_efi_device_path_t);
203-
204- b = grub_efi_system_table->boot_services;
205- status = b->load_image (0, grub_efi_image_handle,
206- (grub_efi_device_path_t *) mempath,
207- (void *) addr, size, &image_handle);
208- if (status != GRUB_EFI_SUCCESS)
209- return grub_error (GRUB_ERR_BAD_OS, "cannot load image");
210-
211- grub_dprintf ("linux", "linux command line: '%s'\n", args);
212-
213- /* Convert command line to UCS-2 */
214- loaded_image = grub_efi_get_loaded_image (image_handle);
215- loaded_image->load_options_size = len =
216- (grub_strlen (args) + 1) * sizeof (grub_efi_char16_t);
217- loaded_image->load_options =
218- grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
219- if (!loaded_image->load_options)
220- return grub_errno;
221-
222- loaded_image->load_options_size =
223- 2 * grub_utf8_to_utf16 (loaded_image->load_options, len,
224- (grub_uint8_t *) args, len, NULL);
225-
226- grub_dprintf ("linux", "starting image %p\n", image_handle);
227- status = b->start_image (image_handle, 0, NULL);
228-
229- /* When successful, not reached */
230- b->unload_image (image_handle);
231- grub_efi_free_pages ((grub_addr_t) loaded_image->load_options,
232- GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
233-
234- return grub_errno;
235-}
236-
237-static grub_err_t
238-grub_linux_boot (void)
239-{
240- if (finalize_params_linux () != GRUB_ERR_NONE)
241- return grub_errno;
242-
243- return (grub_arch_efi_linux_boot_image((grub_addr_t)kernel_addr,
244- kernel_size, linux_args));
245-}
246-
247-static grub_err_t
248-grub_linux_unload (void)
249-{
250- grub_dl_unref (my_mod);
251- loaded = 0;
252- if (initrd_start)
253- grub_efi_free_pages ((grub_efi_physical_address_t) initrd_start,
254- GRUB_EFI_BYTES_TO_PAGES (initrd_end - initrd_start));
255- initrd_start = initrd_end = 0;
256- grub_free (linux_args);
257- if (kernel_addr)
258- grub_efi_free_pages ((grub_addr_t) kernel_addr,
259- GRUB_EFI_BYTES_TO_PAGES (kernel_size));
260- grub_fdt_unload ();
261- return GRUB_ERR_NONE;
262-}
263-
264-/*
265- * As per linux/Documentation/arm/Booting
266- * ARM initrd needs to be covered by kernel linear mapping,
267- * so place it in the first 512MB of DRAM.
268- *
269- * As per linux/Documentation/arm64/booting.txt
270- * ARM64 initrd needs to be contained entirely within a 1GB aligned window
271- * of up to 32GB of size that covers the kernel image as well.
272- * Since the EFI stub loader will attempt to load the kernel near start of
273- * RAM, place the buffer in the first 32GB of RAM.
274- */
275-#ifdef __arm__
276-#define INITRD_MAX_ADDRESS_OFFSET (512U * 1024 * 1024)
277-#else /* __aarch64__ */
278-#define INITRD_MAX_ADDRESS_OFFSET (32ULL * 1024 * 1024 * 1024)
279-#endif
280-
281-/*
282- * This function returns a pointer to a legally allocated initrd buffer,
283- * or NULL if unsuccessful
284- */
285-static void *
286-allocate_initrd_mem (int initrd_pages)
287-{
288- grub_addr_t max_addr;
289-
290- if (grub_efi_get_ram_base (&max_addr) != GRUB_ERR_NONE)
291- return NULL;
292-
293- max_addr += INITRD_MAX_ADDRESS_OFFSET - 1;
294-
295- return grub_efi_allocate_pages_real (max_addr, initrd_pages,
296- GRUB_EFI_ALLOCATE_MAX_ADDRESS,
297- GRUB_EFI_LOADER_DATA);
298-}
299-
300-struct initrd_media_device_path {
301- grub_efi_vendor_media_device_path_t vendor;
302- grub_efi_device_path_t end;
303-} GRUB_PACKED;
304-
305-#define LINUX_EFI_INITRD_MEDIA_GUID \
306- { 0x5568e427, 0x68fc, 0x4f3d, \
307- { 0xac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68 } \
308- }
309-
310-static struct initrd_media_device_path initrd_lf2_device_path = {
311- {
312- {
313- GRUB_EFI_MEDIA_DEVICE_PATH_TYPE,
314- GRUB_EFI_VENDOR_MEDIA_DEVICE_PATH_SUBTYPE,
315- sizeof(grub_efi_vendor_media_device_path_t),
316- },
317- LINUX_EFI_INITRD_MEDIA_GUID
318- }, {
319- GRUB_EFI_END_DEVICE_PATH_TYPE,
320- GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE,
321- sizeof(grub_efi_device_path_t)
322- }
323-};
324-
325-static grub_efi_status_t
326-grub_efi_initrd_load_file2(grub_efi_load_file2_t *this,
327- grub_efi_device_path_t *device_path,
328- grub_efi_boolean_t boot_policy,
329- grub_efi_uintn_t *buffer_size,
330- void *buffer);
331-
332-static grub_efi_load_file2_t initrd_lf2 = {
333- grub_efi_initrd_load_file2
334-};
335-
336-static grub_efi_status_t
337-grub_efi_initrd_load_file2(grub_efi_load_file2_t *this,
338- grub_efi_device_path_t *device_path,
339- grub_efi_boolean_t boot_policy,
340- grub_efi_uintn_t *buffer_size,
341- void *buffer)
342-{
343- grub_efi_status_t status = GRUB_EFI_SUCCESS;
344- grub_efi_uintn_t initrd_size;
345-
346- if (!this || this != &initrd_lf2 || !buffer_size)
347- return GRUB_EFI_INVALID_PARAMETER;
348-
349- if (device_path->type != GRUB_EFI_END_DEVICE_PATH_TYPE ||
350- device_path->subtype != GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE)
351- return GRUB_EFI_NOT_FOUND;
352-
353- if (boot_policy)
354- return GRUB_EFI_UNSUPPORTED;
355-
356- initrd_size = grub_get_initrd_size (&initrd_ctx);
357- if (!buffer || *buffer_size < initrd_size)
358- {
359- *buffer_size = initrd_size;
360- return GRUB_EFI_BUFFER_TOO_SMALL;
361- }
362-
363- grub_dprintf ("linux", "Providing initrd via LOAD_FILE2_PROTOCOL\n");
364-
365- if (grub_initrd_load (&initrd_ctx, buffer))
366- status = GRUB_EFI_LOAD_ERROR;
367-
368- grub_initrd_close (&initrd_ctx);
369- return status;
370-}
371-
372-static grub_err_t
373-grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
374- int argc, char *argv[])
375-{
376- int initrd_size, initrd_pages;
377- void *initrd_mem = NULL;
378- grub_efi_boot_services_t *b;
379- grub_efi_status_t status;
380-
381- if (argc == 0)
382- {
383- grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
384- goto fail;
385- }
386-
387- if (!loaded)
388- {
389- grub_error (GRUB_ERR_BAD_ARGUMENT,
390- N_("you need to load the kernel first"));
391- goto fail;
392- }
393-
394- if (grub_initrd_init (argc, argv, &initrd_ctx))
395- goto fail;
396-
397- if (initrd_use_loadfile2 && !initrd_lf2_handle)
398- {
399- b = grub_efi_system_table->boot_services;
400- status = b->install_multiple_protocol_interfaces (&initrd_lf2_handle,
401- &load_file2_guid,
402- &initrd_lf2,
403- &device_path_guid,
404- &initrd_lf2_device_path,
405- NULL);
406- if (status == GRUB_EFI_OUT_OF_RESOURCES)
407- {
408- grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
409- return grub_errno;
410- }
411- grub_dprintf ("linux", "LoadFile2 initrd loading protocol installed\n");
412- return GRUB_ERR_NONE;
413- }
414-
415- initrd_size = grub_get_initrd_size (&initrd_ctx);
416- grub_dprintf ("linux", "Loading initrd\n");
417-
418- initrd_pages = (GRUB_EFI_BYTES_TO_PAGES (initrd_size));
419- initrd_mem = allocate_initrd_mem (initrd_pages);
420-
421- if (!initrd_mem)
422- {
423- grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
424- goto fail;
425- }
426-
427- if (grub_initrd_load (&initrd_ctx, initrd_mem))
428- goto fail;
429-
430- initrd_start = (grub_addr_t) initrd_mem;
431- initrd_end = initrd_start + initrd_size;
432- grub_dprintf ("linux", "[addr=%p, size=0x%x]\n",
433- (void *) initrd_start, initrd_size);
434-
435- fail:
436- grub_initrd_close (&initrd_ctx);
437- if (initrd_mem && !initrd_start)
438- grub_efi_free_pages ((grub_addr_t) initrd_mem, initrd_pages);
439-
440- return grub_errno;
441-}
442-
443-static grub_err_t
444-grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
445- int argc, char *argv[])
446-{
447- grub_file_t file = 0;
448- struct linux_arch_kernel_header lh;
449- grub_err_t err;
450-
451- grub_dl_ref (my_mod);
452-
453- if (argc == 0)
454- {
455- grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
456- goto fail;
457- }
458-
459- file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL);
460- if (!file)
461- goto fail;
462-
463- kernel_size = grub_file_size (file);
464-
465- if (grub_file_read (file, &lh, sizeof (lh)) < (long) sizeof (lh))
466- return grub_errno;
467-
468- if (grub_arch_efi_linux_check_image (&lh) != GRUB_ERR_NONE)
469- goto fail;
470-
471- grub_loader_unset();
472-
473- grub_dprintf ("linux", "kernel file size: %lld\n", (long long) kernel_size);
474- kernel_addr = grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (kernel_size));
475- grub_dprintf ("linux", "kernel numpages: %lld\n",
476- (long long) GRUB_EFI_BYTES_TO_PAGES (kernel_size));
477- if (!kernel_addr)
478- {
479- grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
480- goto fail;
481- }
482-
483- grub_file_seek (file, 0);
484- if (grub_file_read (file, kernel_addr, kernel_size)
485- < (grub_int64_t) kernel_size)
486- {
487- if (!grub_errno)
488- grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), argv[0]);
489- goto fail;
490- }
491-
492- grub_dprintf ("linux", "kernel @ %p\n", kernel_addr);
493-
494- cmdline_size = grub_loader_cmdline_size (argc, argv) + sizeof (LINUX_IMAGE);
495- linux_args = grub_malloc (cmdline_size);
496- if (!linux_args)
497- {
498- grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
499- goto fail;
500- }
501- grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE));
502- err = grub_create_loader_cmdline (argc, argv,
503- linux_args + sizeof (LINUX_IMAGE) - 1,
504- cmdline_size,
505- GRUB_VERIFY_KERNEL_CMDLINE);
506- if (err)
507- goto fail;
508-
509- if (grub_errno == GRUB_ERR_NONE)
510- {
511- grub_loader_set (grub_linux_boot, grub_linux_unload, 0);
512- loaded = 1;
513- }
514-
515-fail:
516- if (file)
517- grub_file_close (file);
518-
519- if (grub_errno != GRUB_ERR_NONE)
520- {
521- grub_dl_unref (my_mod);
522- loaded = 0;
523- }
524-
525- if (linux_args && !loaded)
526- grub_free (linux_args);
527-
528- if (kernel_addr && !loaded)
529- grub_efi_free_pages ((grub_addr_t) kernel_addr,
530- GRUB_EFI_BYTES_TO_PAGES (kernel_size));
531-
532- return grub_errno;
533-}
534-
535-
536-static grub_command_t cmd_linux, cmd_initrd;
537-
538-GRUB_MOD_INIT (linux)
539-{
540- cmd_linux = grub_register_command ("linux", grub_cmd_linux, 0,
541- N_("Load Linux."));
542- cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, 0,
543- N_("Load initrd."));
544- my_mod = mod;
545-}
546-
547-GRUB_MOD_FINI (linux)
548-{
549- grub_unregister_command (cmd_linux);
550- grub_unregister_command (cmd_initrd);
551-}
552diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c
553new file mode 100644
554index 0000000..3292cab
555--- /dev/null
556+++ b/grub-core/loader/efi/linux.c
557@@ -0,0 +1,508 @@
558+/*
559+ * GRUB -- GRand Unified Bootloader
560+ * Copyright (C) 2013 Free Software Foundation, Inc.
561+ *
562+ * GRUB is free software: you can redistribute it and/or modify
563+ * it under the terms of the GNU General Public License as published by
564+ * the Free Software Foundation, either version 3 of the License, or
565+ * (at your option) any later version.
566+ *
567+ * GRUB is distributed in the hope that it will be useful,
568+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
569+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
570+ * GNU General Public License for more details.
571+ *
572+ * You should have received a copy of the GNU General Public License
573+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
574+ */
575+
576+#include <grub/charset.h>
577+#include <grub/command.h>
578+#include <grub/err.h>
579+#include <grub/file.h>
580+#include <grub/fdt.h>
581+#include <grub/linux.h>
582+#include <grub/loader.h>
583+#include <grub/mm.h>
584+#include <grub/types.h>
585+#include <grub/cpu/linux.h>
586+#include <grub/efi/efi.h>
587+#include <grub/efi/fdtload.h>
588+#include <grub/efi/memory.h>
589+#include <grub/efi/pe32.h>
590+#include <grub/i18n.h>
591+#include <grub/lib/cmdline.h>
592+#include <grub/verify.h>
593+
594+GRUB_MOD_LICENSE ("GPLv3+");
595+
596+static grub_dl_t my_mod;
597+static int loaded;
598+
599+static void *kernel_addr;
600+static grub_uint64_t kernel_size;
601+
602+static char *linux_args;
603+static grub_uint32_t cmdline_size;
604+
605+static grub_addr_t initrd_start;
606+static grub_addr_t initrd_end;
607+
608+static struct grub_linux_initrd_context initrd_ctx = { 0, 0, 0 };
609+static grub_efi_handle_t initrd_lf2_handle;
610+static int initrd_use_loadfile2;
611+static grub_efi_guid_t load_file2_guid = GRUB_EFI_LOAD_FILE2_PROTOCOL_GUID;
612+static grub_efi_guid_t device_path_guid = GRUB_EFI_DEVICE_PATH_GUID;
613+
614+grub_err_t
615+grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh)
616+{
617+ struct grub_pe32_coff_header *coff_header;
618+ struct grub_pe32_optional_header *optional_header;
619+
620+ if (lh->magic != GRUB_LINUX_ARCH_MAGIC_SIGNATURE)
621+ return grub_error(GRUB_ERR_BAD_OS, "invalid magic number");
622+
623+ if ((lh->code0 & 0xffff) != GRUB_PE32_MAGIC)
624+ return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
625+ N_("plain image kernel not supported - rebuild with CONFIG_(U)EFI_STUB enabled"));
626+
627+ grub_dprintf ("linux", "UEFI stub kernel:\n");
628+ grub_dprintf ("linux", "PE/COFF header @ %08x\n", lh->hdr_offset);
629+
630+ coff_header = (struct grub_pe32_coff_header *)((unsigned long)lh + lh->hdr_offset);
631+ optional_header = (struct grub_pe32_optional_header *)(coff_header + 1);
632+
633+ /*
634+ * Linux kernels built for any architecture are guaranteed to support the
635+ * LoadFile2 based initrd loading protocol if the image version is >= 1.
636+ */
637+ if (optional_header->major_image_version >= 1)
638+ initrd_use_loadfile2 = 1;
639+ else
640+ initrd_use_loadfile2 = 0;
641+
642+ grub_dprintf ("linux", "LoadFile2 initrd loading %sabled\n",
643+ initrd_use_loadfile2 ? "en" : "dis");
644+
645+ return GRUB_ERR_NONE;
646+}
647+
648+static grub_err_t
649+finalize_params_linux (void)
650+{
651+ int node, retval;
652+
653+ void *fdt = NULL;
654+
655+ /* Set initrd info */
656+ if (initrd_start && initrd_end > initrd_start)
657+ {
658+ fdt = grub_fdt_load (GRUB_EFI_LINUX_FDT_EXTRA_SPACE);
659+
660+ if (!fdt)
661+ goto failure;
662+
663+ node = grub_fdt_find_subnode (fdt, 0, "chosen");
664+ if (node < 0)
665+ node = grub_fdt_add_subnode (fdt, 0, "chosen");
666+
667+ if (node < 1)
668+ goto failure;
669+
670+ grub_dprintf ("linux", "Initrd @ %p-%p\n",
671+ (void *) initrd_start, (void *) initrd_end);
672+
673+ retval = grub_fdt_set_prop64 (fdt, node, "linux,initrd-start",
674+ initrd_start);
675+ if (retval)
676+ goto failure;
677+ retval = grub_fdt_set_prop64 (fdt, node, "linux,initrd-end",
678+ initrd_end);
679+ if (retval)
680+ goto failure;
681+ }
682+
683+ if (grub_fdt_install() != GRUB_ERR_NONE)
684+ goto failure;
685+
686+ return GRUB_ERR_NONE;
687+
688+failure:
689+ grub_fdt_unload();
690+ return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT");
691+}
692+
693+grub_err_t
694+grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)
695+{
696+ grub_efi_memory_mapped_device_path_t *mempath;
697+ grub_efi_handle_t image_handle;
698+ grub_efi_boot_services_t *b;
699+ grub_efi_status_t status;
700+ grub_efi_loaded_image_t *loaded_image;
701+ int len;
702+
703+ mempath = grub_malloc (2 * sizeof (grub_efi_memory_mapped_device_path_t));
704+ if (!mempath)
705+ return grub_errno;
706+
707+ mempath[0].header.type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE;
708+ mempath[0].header.subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE;
709+ mempath[0].header.length = grub_cpu_to_le16_compile_time (sizeof (*mempath));
710+ mempath[0].memory_type = GRUB_EFI_LOADER_DATA;
711+ mempath[0].start_address = addr;
712+ mempath[0].end_address = addr + size;
713+
714+ mempath[1].header.type = GRUB_EFI_END_DEVICE_PATH_TYPE;
715+ mempath[1].header.subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE;
716+ mempath[1].header.length = sizeof (grub_efi_device_path_t);
717+
718+ b = grub_efi_system_table->boot_services;
719+ status = b->load_image (0, grub_efi_image_handle,
720+ (grub_efi_device_path_t *) mempath,
721+ (void *) addr, size, &image_handle);
722+ if (status != GRUB_EFI_SUCCESS)
723+ return grub_error (GRUB_ERR_BAD_OS, "cannot load image");
724+
725+ grub_dprintf ("linux", "linux command line: '%s'\n", args);
726+
727+ /* Convert command line to UCS-2 */
728+ loaded_image = grub_efi_get_loaded_image (image_handle);
729+ loaded_image->load_options_size = len =
730+ (grub_strlen (args) + 1) * sizeof (grub_efi_char16_t);
731+ loaded_image->load_options =
732+ grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
733+ if (!loaded_image->load_options)
734+ return grub_errno;
735+
736+ loaded_image->load_options_size =
737+ 2 * grub_utf8_to_utf16 (loaded_image->load_options, len,
738+ (grub_uint8_t *) args, len, NULL);
739+
740+ grub_dprintf ("linux", "starting image %p\n", image_handle);
741+ status = b->start_image (image_handle, 0, NULL);
742+
743+ /* When successful, not reached */
744+ b->unload_image (image_handle);
745+ grub_efi_free_pages ((grub_addr_t) loaded_image->load_options,
746+ GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
747+
748+ return grub_errno;
749+}
750+
751+static grub_err_t
752+grub_linux_boot (void)
753+{
754+ if (finalize_params_linux () != GRUB_ERR_NONE)
755+ return grub_errno;
756+
757+ return (grub_arch_efi_linux_boot_image((grub_addr_t)kernel_addr,
758+ kernel_size, linux_args));
759+}
760+
761+static grub_err_t
762+grub_linux_unload (void)
763+{
764+ grub_dl_unref (my_mod);
765+ loaded = 0;
766+ if (initrd_start)
767+ grub_efi_free_pages ((grub_efi_physical_address_t) initrd_start,
768+ GRUB_EFI_BYTES_TO_PAGES (initrd_end - initrd_start));
769+ initrd_start = initrd_end = 0;
770+ grub_free (linux_args);
771+ if (kernel_addr)
772+ grub_efi_free_pages ((grub_addr_t) kernel_addr,
773+ GRUB_EFI_BYTES_TO_PAGES (kernel_size));
774+ grub_fdt_unload ();
775+ return GRUB_ERR_NONE;
776+}
777+
778+/*
779+ * As per linux/Documentation/arm/Booting
780+ * ARM initrd needs to be covered by kernel linear mapping,
781+ * so place it in the first 512MB of DRAM.
782+ *
783+ * As per linux/Documentation/arm64/booting.txt
784+ * ARM64 initrd needs to be contained entirely within a 1GB aligned window
785+ * of up to 32GB of size that covers the kernel image as well.
786+ * Since the EFI stub loader will attempt to load the kernel near start of
787+ * RAM, place the buffer in the first 32GB of RAM.
788+ */
789+#ifdef __arm__
790+#define INITRD_MAX_ADDRESS_OFFSET (512U * 1024 * 1024)
791+#else /* __aarch64__ */
792+#define INITRD_MAX_ADDRESS_OFFSET (32ULL * 1024 * 1024 * 1024)
793+#endif
794+
795+/*
796+ * This function returns a pointer to a legally allocated initrd buffer,
797+ * or NULL if unsuccessful
798+ */
799+static void *
800+allocate_initrd_mem (int initrd_pages)
801+{
802+ grub_addr_t max_addr;
803+
804+ if (grub_efi_get_ram_base (&max_addr) != GRUB_ERR_NONE)
805+ return NULL;
806+
807+ max_addr += INITRD_MAX_ADDRESS_OFFSET - 1;
808+
809+ return grub_efi_allocate_pages_real (max_addr, initrd_pages,
810+ GRUB_EFI_ALLOCATE_MAX_ADDRESS,
811+ GRUB_EFI_LOADER_DATA);
812+}
813+
814+struct initrd_media_device_path {
815+ grub_efi_vendor_media_device_path_t vendor;
816+ grub_efi_device_path_t end;
817+} GRUB_PACKED;
818+
819+#define LINUX_EFI_INITRD_MEDIA_GUID \
820+ { 0x5568e427, 0x68fc, 0x4f3d, \
821+ { 0xac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68 } \
822+ }
823+
824+static struct initrd_media_device_path initrd_lf2_device_path = {
825+ {
826+ {
827+ GRUB_EFI_MEDIA_DEVICE_PATH_TYPE,
828+ GRUB_EFI_VENDOR_MEDIA_DEVICE_PATH_SUBTYPE,
829+ sizeof(grub_efi_vendor_media_device_path_t),
830+ },
831+ LINUX_EFI_INITRD_MEDIA_GUID
832+ }, {
833+ GRUB_EFI_END_DEVICE_PATH_TYPE,
834+ GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE,
835+ sizeof(grub_efi_device_path_t)
836+ }
837+};
838+
839+static grub_efi_status_t
840+grub_efi_initrd_load_file2(grub_efi_load_file2_t *this,
841+ grub_efi_device_path_t *device_path,
842+ grub_efi_boolean_t boot_policy,
843+ grub_efi_uintn_t *buffer_size,
844+ void *buffer);
845+
846+static grub_efi_load_file2_t initrd_lf2 = {
847+ grub_efi_initrd_load_file2
848+};
849+
850+static grub_efi_status_t
851+grub_efi_initrd_load_file2(grub_efi_load_file2_t *this,
852+ grub_efi_device_path_t *device_path,
853+ grub_efi_boolean_t boot_policy,
854+ grub_efi_uintn_t *buffer_size,
855+ void *buffer)
856+{
857+ grub_efi_status_t status = GRUB_EFI_SUCCESS;
858+ grub_efi_uintn_t initrd_size;
859+
860+ if (!this || this != &initrd_lf2 || !buffer_size)
861+ return GRUB_EFI_INVALID_PARAMETER;
862+
863+ if (device_path->type != GRUB_EFI_END_DEVICE_PATH_TYPE ||
864+ device_path->subtype != GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE)
865+ return GRUB_EFI_NOT_FOUND;
866+
867+ if (boot_policy)
868+ return GRUB_EFI_UNSUPPORTED;
869+
870+ initrd_size = grub_get_initrd_size (&initrd_ctx);
871+ if (!buffer || *buffer_size < initrd_size)
872+ {
873+ *buffer_size = initrd_size;
874+ return GRUB_EFI_BUFFER_TOO_SMALL;
875+ }
876+
877+ grub_dprintf ("linux", "Providing initrd via LOAD_FILE2_PROTOCOL\n");
878+
879+ if (grub_initrd_load (&initrd_ctx, buffer))
880+ status = GRUB_EFI_LOAD_ERROR;
881+
882+ grub_initrd_close (&initrd_ctx);
883+ return status;
884+}
885+
886+static grub_err_t
887+grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
888+ int argc, char *argv[])
889+{
890+ int initrd_size, initrd_pages;
891+ void *initrd_mem = NULL;
892+ grub_efi_boot_services_t *b;
893+ grub_efi_status_t status;
894+
895+ if (argc == 0)
896+ {
897+ grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
898+ goto fail;
899+ }
900+
901+ if (!loaded)
902+ {
903+ grub_error (GRUB_ERR_BAD_ARGUMENT,
904+ N_("you need to load the kernel first"));
905+ goto fail;
906+ }
907+
908+ if (grub_initrd_init (argc, argv, &initrd_ctx))
909+ goto fail;
910+
911+ if (initrd_use_loadfile2 && !initrd_lf2_handle)
912+ {
913+ b = grub_efi_system_table->boot_services;
914+ status = b->install_multiple_protocol_interfaces (&initrd_lf2_handle,
915+ &load_file2_guid,
916+ &initrd_lf2,
917+ &device_path_guid,
918+ &initrd_lf2_device_path,
919+ NULL);
920+ if (status == GRUB_EFI_OUT_OF_RESOURCES)
921+ {
922+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
923+ return grub_errno;
924+ }
925+ grub_dprintf ("linux", "LoadFile2 initrd loading protocol installed\n");
926+ return GRUB_ERR_NONE;
927+ }
928+
929+ initrd_size = grub_get_initrd_size (&initrd_ctx);
930+ grub_dprintf ("linux", "Loading initrd\n");
931+
932+ initrd_pages = (GRUB_EFI_BYTES_TO_PAGES (initrd_size));
933+ initrd_mem = allocate_initrd_mem (initrd_pages);
934+
935+ if (!initrd_mem)
936+ {
937+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
938+ goto fail;
939+ }
940+
941+ if (grub_initrd_load (&initrd_ctx, initrd_mem))
942+ goto fail;
943+
944+ initrd_start = (grub_addr_t) initrd_mem;
945+ initrd_end = initrd_start + initrd_size;
946+ grub_dprintf ("linux", "[addr=%p, size=0x%x]\n",
947+ (void *) initrd_start, initrd_size);
948+
949+ fail:
950+ grub_initrd_close (&initrd_ctx);
951+ if (initrd_mem && !initrd_start)
952+ grub_efi_free_pages ((grub_addr_t) initrd_mem, initrd_pages);
953+
954+ return grub_errno;
955+}
956+
957+static grub_err_t
958+grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
959+ int argc, char *argv[])
960+{
961+ grub_file_t file = 0;
962+ struct linux_arch_kernel_header lh;
963+ grub_err_t err;
964+
965+ grub_dl_ref (my_mod);
966+
967+ if (argc == 0)
968+ {
969+ grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
970+ goto fail;
971+ }
972+
973+ file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL);
974+ if (!file)
975+ goto fail;
976+
977+ kernel_size = grub_file_size (file);
978+
979+ if (grub_file_read (file, &lh, sizeof (lh)) < (long) sizeof (lh))
980+ return grub_errno;
981+
982+ if (grub_arch_efi_linux_check_image (&lh) != GRUB_ERR_NONE)
983+ goto fail;
984+
985+ grub_loader_unset();
986+
987+ grub_dprintf ("linux", "kernel file size: %lld\n", (long long) kernel_size);
988+ kernel_addr = grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (kernel_size));
989+ grub_dprintf ("linux", "kernel numpages: %lld\n",
990+ (long long) GRUB_EFI_BYTES_TO_PAGES (kernel_size));
991+ if (!kernel_addr)
992+ {
993+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
994+ goto fail;
995+ }
996+
997+ grub_file_seek (file, 0);
998+ if (grub_file_read (file, kernel_addr, kernel_size)
999+ < (grub_int64_t) kernel_size)
1000+ {
1001+ if (!grub_errno)
1002+ grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), argv[0]);
1003+ goto fail;
1004+ }
1005+
1006+ grub_dprintf ("linux", "kernel @ %p\n", kernel_addr);
1007+
1008+ cmdline_size = grub_loader_cmdline_size (argc, argv) + sizeof (LINUX_IMAGE);
1009+ linux_args = grub_malloc (cmdline_size);
1010+ if (!linux_args)
1011+ {
1012+ grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory"));
1013+ goto fail;
1014+ }
1015+ grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE));
1016+ err = grub_create_loader_cmdline (argc, argv,
1017+ linux_args + sizeof (LINUX_IMAGE) - 1,
1018+ cmdline_size,
1019+ GRUB_VERIFY_KERNEL_CMDLINE);
1020+ if (err)
1021+ goto fail;
1022+
1023+ if (grub_errno == GRUB_ERR_NONE)
1024+ {
1025+ grub_loader_set (grub_linux_boot, grub_linux_unload, 0);
1026+ loaded = 1;
1027+ }
1028+
1029+fail:
1030+ if (file)
1031+ grub_file_close (file);
1032+
1033+ if (grub_errno != GRUB_ERR_NONE)
1034+ {
1035+ grub_dl_unref (my_mod);
1036+ loaded = 0;
1037+ }
1038+
1039+ if (linux_args && !loaded)
1040+ grub_free (linux_args);
1041+
1042+ if (kernel_addr && !loaded)
1043+ grub_efi_free_pages ((grub_addr_t) kernel_addr,
1044+ GRUB_EFI_BYTES_TO_PAGES (kernel_size));
1045+
1046+ return grub_errno;
1047+}
1048+
1049+
1050+static grub_command_t cmd_linux, cmd_initrd;
1051+
1052+GRUB_MOD_INIT (linux)
1053+{
1054+ cmd_linux = grub_register_command ("linux", grub_cmd_linux, 0,
1055+ N_("Load Linux."));
1056+ cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, 0,
1057+ N_("Load initrd."));
1058+ my_mod = mod;
1059+}
1060+
1061+GRUB_MOD_FINI (linux)
1062+{
1063+ grub_unregister_command (cmd_linux);
1064+ grub_unregister_command (cmd_initrd);
1065+}
1066diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h
1067index bcd5a7e..8c13978 100644
1068--- a/include/grub/arm/linux.h
1069+++ b/include/grub/arm/linux.h
1070@@ -35,7 +35,7 @@ struct linux_arm_kernel_header {
1071 };
1072
1073 #if defined(__arm__)
1074-# define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM_MAGIC_SIGNATURE
1075+# define GRUB_LINUX_ARCH_MAGIC_SIGNATURE GRUB_LINUX_ARM_MAGIC_SIGNATURE
1076 # define linux_arch_kernel_header linux_arm_kernel_header
1077 #endif
1078
1079diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h
1080index 7e22b4a..effd870 100644
1081--- a/include/grub/arm64/linux.h
1082+++ b/include/grub/arm64/linux.h
1083@@ -39,7 +39,7 @@ struct linux_arm64_kernel_header
1084 };
1085
1086 #if defined(__aarch64__)
1087-# define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM64_MAGIC_SIGNATURE
1088+# define GRUB_LINUX_ARCH_MAGIC_SIGNATURE GRUB_LINUX_ARM64_MAGIC_SIGNATURE
1089 # define linux_arch_kernel_header linux_arm64_kernel_header
1090 #endif
1091
diff --git a/debian/patches/loader-drop-argv-argument-in-grub_initrd_load.patch b/debian/patches/loader-drop-argv-argument-in-grub_initrd_load.patch
0new file mode 1006441092new file mode 100644
index 0000000..a5af0f5
--- /dev/null
+++ b/debian/patches/loader-drop-argv-argument-in-grub_initrd_load.patch
@@ -0,0 +1,178 @@
1From: Nikita Ermakov <arei@altlinux.org>
2Date: Thu, 28 Oct 2021 23:31:13 +0300
3Subject: loader: drop argv[] argument in grub_initrd_load()
4
5In the case of an error grub_initrd_load() uses argv[] to print the
6filename that caused the error. It is also possible to obtain the
7filename from the file handles and there is no need to duplicate that
8information in argv[], so let's drop it.
9
10Signed-off-by: Nikita Ermakov <arei@altlinux.org>
11Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
12
13Last-Update: 2022-01-03
14Origin: https://lists.gnu.org/archive/html/grub-devel/2021-10/msg00212.html
15---
16 grub-core/loader/arm/linux.c | 2 +-
17 grub-core/loader/arm64/linux.c | 2 +-
18 grub-core/loader/i386/linux.c | 2 +-
19 grub-core/loader/i386/pc/linux.c | 2 +-
20 grub-core/loader/i386/xen.c | 3 +--
21 grub-core/loader/ia64/efi/linux.c | 2 +-
22 grub-core/loader/linux.c | 4 ++--
23 grub-core/loader/mips/linux.c | 2 +-
24 grub-core/loader/powerpc/ieee1275/linux.c | 2 +-
25 grub-core/loader/sparc64/ieee1275/linux.c | 2 +-
26 include/grub/linux.h | 2 +-
27 11 files changed, 12 insertions(+), 13 deletions(-)
28
29diff --git a/grub-core/loader/arm/linux.c b/grub-core/loader/arm/linux.c
30index ed23dc7..1f7ab75 100644
31--- a/grub-core/loader/arm/linux.c
32+++ b/grub-core/loader/arm/linux.c
33@@ -422,7 +422,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
34 grub_dprintf ("loader", "Loading initrd to 0x%08x\n",
35 (grub_addr_t) initrd_start);
36
37- if (grub_initrd_load (&initrd_ctx, argv, (void *) initrd_start))
38+ if (grub_initrd_load (&initrd_ctx, (void *) initrd_start))
39 goto fail;
40
41 initrd_end = initrd_start + size;
42diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c
43index ef3e9f9..aed7a20 100644
44--- a/grub-core/loader/arm64/linux.c
45+++ b/grub-core/loader/arm64/linux.c
46@@ -266,7 +266,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
47 goto fail;
48 }
49
50- if (grub_initrd_load (&initrd_ctx, argv, initrd_mem))
51+ if (grub_initrd_load (&initrd_ctx, initrd_mem))
52 goto fail;
53
54 initrd_start = (grub_addr_t) initrd_mem;
55diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c
56index 9f74a96..f30a158 100644
57--- a/grub-core/loader/i386/linux.c
58+++ b/grub-core/loader/i386/linux.c
59@@ -1107,7 +1107,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
60 initrd_mem_target = get_physical_target_address (ch);
61 }
62
63- if (grub_initrd_load (&initrd_ctx, argv, initrd_mem))
64+ if (grub_initrd_load (&initrd_ctx, initrd_mem))
65 goto fail;
66
67 grub_dprintf ("linux", "Initrd, addr=0x%x, size=0x%x\n",
68diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c
69index 2a29952..efeeeb2 100644
70--- a/grub-core/loader/i386/pc/linux.c
71+++ b/grub-core/loader/i386/pc/linux.c
72@@ -462,7 +462,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
73 initrd_addr = get_physical_target_address (ch);
74 }
75
76- if (grub_initrd_load (&initrd_ctx, argv, initrd_chunk))
77+ if (grub_initrd_load (&initrd_ctx, initrd_chunk))
78 goto fail;
79
80 lh->ramdisk_image = initrd_addr;
81diff --git a/grub-core/loader/i386/xen.c b/grub-core/loader/i386/xen.c
82index cd24874..3b856e8 100644
83--- a/grub-core/loader/i386/xen.c
84+++ b/grub-core/loader/i386/xen.c
85@@ -809,8 +809,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
86 if (err)
87 goto fail;
88
89- if (grub_initrd_load (&initrd_ctx, argv,
90- get_virtual_current_address (ch)))
91+ if (grub_initrd_load (&initrd_ctx, get_virtual_current_address (ch)))
92 goto fail;
93 }
94
95diff --git a/grub-core/loader/ia64/efi/linux.c b/grub-core/loader/ia64/efi/linux.c
96index 7987fd1..8873b7a 100644
97--- a/grub-core/loader/ia64/efi/linux.c
98+++ b/grub-core/loader/ia64/efi/linux.c
99@@ -563,7 +563,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
100 grub_dprintf ("linux", "[addr=0x%lx, size=0x%lx]\n",
101 (grub_uint64_t) initrd_mem, initrd_size);
102
103- if (grub_initrd_load (&initrd_ctx, argv, initrd_mem))
104+ if (grub_initrd_load (&initrd_ctx, initrd_mem))
105 goto fail;
106 fail:
107 grub_initrd_close (&initrd_ctx);
108diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c
109index 3fe390f..d19df67 100644
110--- a/grub-core/loader/linux.c
111+++ b/grub-core/loader/linux.c
112@@ -271,7 +271,7 @@ grub_initrd_close (struct grub_linux_initrd_context *initrd_ctx)
113
114 grub_err_t
115 grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx,
116- char *argv[], void *target)
117+ void *target)
118 {
119 grub_uint8_t *ptr = target;
120 int i;
121@@ -317,7 +317,7 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx,
122 {
123 if (!grub_errno)
124 grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"),
125- argv[i]);
126+ initrd_ctx->components[i].file->name);
127 grub_initrd_close (initrd_ctx);
128 return grub_errno;
129 }
130diff --git a/grub-core/loader/mips/linux.c b/grub-core/loader/mips/linux.c
131index e4ed959..9459472 100644
132--- a/grub-core/loader/mips/linux.c
133+++ b/grub-core/loader/mips/linux.c
134@@ -452,7 +452,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
135 initrd_dest = get_physical_target_address (ch) | 0x80000000;
136 }
137
138- if (grub_initrd_load (&initrd_ctx, argv, initrd_src))
139+ if (grub_initrd_load (&initrd_ctx, initrd_src))
140 goto fail;
141
142 #ifdef GRUB_MACHINE_MIPS_QEMU_MIPS
143diff --git a/grub-core/loader/powerpc/ieee1275/linux.c b/grub-core/loader/powerpc/ieee1275/linux.c
144index 818b2a8..a51e7a7 100644
145--- a/grub-core/loader/powerpc/ieee1275/linux.c
146+++ b/grub-core/loader/powerpc/ieee1275/linux.c
147@@ -363,7 +363,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
148
149 grub_dprintf ("loader", "Loading initrd at 0x%x, size 0x%x\n", addr, size);
150
151- if (grub_initrd_load (&initrd_ctx, argv, (void *) addr))
152+ if (grub_initrd_load (&initrd_ctx, (void *) addr))
153 goto fail;
154
155 initrd_addr = addr;
156diff --git a/grub-core/loader/sparc64/ieee1275/linux.c b/grub-core/loader/sparc64/ieee1275/linux.c
157index bb47ee0..ac2206f 100644
158--- a/grub-core/loader/sparc64/ieee1275/linux.c
159+++ b/grub-core/loader/sparc64/ieee1275/linux.c
160@@ -413,7 +413,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)),
161 grub_dprintf ("loader", "Loading initrd at vaddr 0x%lx, paddr 0x%lx, size 0x%lx\n",
162 addr, paddr, size);
163
164- if (grub_initrd_load (&initrd_ctx, argv, (void *) addr))
165+ if (grub_initrd_load (&initrd_ctx, (void *) addr))
166 goto fail;
167
168 initrd_addr = addr;
169diff --git a/include/grub/linux.h b/include/grub/linux.h
170index 594a3f3..a96ac20 100644
171--- a/include/grub/linux.h
172+++ b/include/grub/linux.h
173@@ -21,4 +21,4 @@ grub_initrd_close (struct grub_linux_initrd_context *initrd_ctx);
174
175 grub_err_t
176 grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx,
177- char *argv[], void *target);
178+ void *target);
diff --git a/debian/patches/maybe-quiet.patch b/debian/patches/maybe-quiet.patch
index 819d9ca..5833f08 100644
--- a/debian/patches/maybe-quiet.patch
+++ b/debian/patches/maybe-quiet.patch
@@ -58,10 +58,10 @@ index 9e8f991..d2c4ce8 100644
58 /* We don't need those. */58 /* We don't need those. */
59 #define MINILZO_CFG_SKIP_LZO_PTR 159 #define MINILZO_CFG_SKIP_LZO_PTR 1
60diff --git a/configure.ac b/configure.ac60diff --git a/configure.ac b/configure.ac
61index 74778a6..256fc44 10064461index fb980fd..2869155 100644
62--- a/configure.ac62--- a/configure.ac
63+++ b/configure.ac63+++ b/configure.ac
64@@ -1915,6 +1915,17 @@ else64@@ -1923,6 +1923,17 @@ else
65 fi65 fi
66 AC_SUBST([UBUNTU_RECOVERY])66 AC_SUBST([UBUNTU_RECOVERY])
67 67
@@ -79,7 +79,7 @@ index 74778a6..256fc44 100644
79 LIBS=""79 LIBS=""
80 80
81 AC_SUBST([FONT_SOURCE])81 AC_SUBST([FONT_SOURCE])
82@@ -2177,5 +2188,10 @@ echo "With stack smashing protector: Yes"82@@ -2185,5 +2196,10 @@ echo "With stack smashing protector: Yes"
83 else83 else
84 echo "With stack smashing protector: No"84 echo "With stack smashing protector: No"
85 fi85 fi
diff --git a/debian/patches/mkconfig-ubuntu-recovery.patch b/debian/patches/mkconfig-ubuntu-recovery.patch
index 43beada..4d7a67d 100644
--- a/debian/patches/mkconfig-ubuntu-recovery.patch
+++ b/debian/patches/mkconfig-ubuntu-recovery.patch
@@ -22,10 +22,10 @@ Patch-Name: mkconfig-ubuntu-recovery.patch
22 3 files changed, 26 insertions(+), 3 deletions(-)22 3 files changed, 26 insertions(+), 3 deletions(-)
2323
24diff --git a/configure.ac b/configure.ac24diff --git a/configure.ac b/configure.ac
25index 7517fc4..74778a6 10064425index e3d4d72..fb980fd 100644
26--- a/configure.ac26--- a/configure.ac
27+++ b/configure.ac27+++ b/configure.ac
28@@ -1904,6 +1904,17 @@ fi28@@ -1912,6 +1912,17 @@ fi
29 AC_SUBST([LIBZFS])29 AC_SUBST([LIBZFS])
30 AC_SUBST([LIBNVPAIR])30 AC_SUBST([LIBNVPAIR])
31 31
diff --git a/debian/patches/no-devicetree-if-secure-boot.patch b/debian/patches/no-devicetree-if-secure-boot.patch
index 3659f2d..50baa90 100644
--- a/debian/patches/no-devicetree-if-secure-boot.patch
+++ b/debian/patches/no-devicetree-if-secure-boot.patch
@@ -16,7 +16,7 @@ Patch-Name: no-devicetree-if-secure-boot.patch
16 2 files changed, 20 insertions(+)16 2 files changed, 20 insertions(+)
1717
18diff --git a/grub-core/loader/arm/linux.c b/grub-core/loader/arm/linux.c18diff --git a/grub-core/loader/arm/linux.c b/grub-core/loader/arm/linux.c
19index ed23dc7..2c85ca8 10064419index 1f7ab75..feb707b 100644
20--- a/grub-core/loader/arm/linux.c20--- a/grub-core/loader/arm/linux.c
21+++ b/grub-core/loader/arm/linux.c21+++ b/grub-core/loader/arm/linux.c
22@@ -30,6 +30,10 @@22@@ -30,6 +30,10 @@
@@ -46,10 +46,10 @@ index ed23dc7..2c85ca8 100644
46 if (!dtb)46 if (!dtb)
47 return grub_errno;47 return grub_errno;
48diff --git a/grub-core/loader/efi/fdt.c b/grub-core/loader/efi/fdt.c48diff --git a/grub-core/loader/efi/fdt.c b/grub-core/loader/efi/fdt.c
49index 7858d35..9b05e7e 10064449index 971e84d..b846bf3 100644
50--- a/grub-core/loader/efi/fdt.c50--- a/grub-core/loader/efi/fdt.c
51+++ b/grub-core/loader/efi/fdt.c51+++ b/grub-core/loader/efi/fdt.c
52@@ -128,6 +128,14 @@ grub_cmd_devicetree (grub_command_t cmd __attribute__ ((unused)),52@@ -131,6 +131,14 @@ grub_cmd_devicetree (grub_command_t cmd __attribute__ ((unused)),
53 return GRUB_ERR_NONE;53 return GRUB_ERR_NONE;
54 }54 }
55 55
diff --git a/debian/patches/pc-verifiers-module.patch b/debian/patches/pc-verifiers-module.patch
index 089e9e9..f372dda 100644
--- a/debian/patches/pc-verifiers-module.patch
+++ b/debian/patches/pc-verifiers-module.patch
@@ -52,7 +52,7 @@ index ee88e44..b6872d2 100644
52 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/net.h52 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/net.h
53 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/memory.h53 KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/memory.h
54diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def54diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
55index 10f839b..f953817 10064455index 0d7bce1..f252725 100644
56--- a/grub-core/Makefile.core.def56--- a/grub-core/Makefile.core.def
57+++ b/grub-core/Makefile.core.def57+++ b/grub-core/Makefile.core.def
58@@ -141,7 +141,7 @@ kernel = {58@@ -141,7 +141,7 @@ kernel = {
diff --git a/debian/patches/quick-boot.patch b/debian/patches/quick-boot.patch
index b94aadc..a3675ac 100644
--- a/debian/patches/quick-boot.patch
+++ b/debian/patches/quick-boot.patch
@@ -32,10 +32,10 @@ Patch-Name: quick-boot.patch
32 7 files changed, 141 insertions(+), 13 deletions(-)32 7 files changed, 141 insertions(+), 13 deletions(-)
3333
34diff --git a/configure.ac b/configure.ac34diff --git a/configure.ac b/configure.ac
35index 256fc44..c42e4c7 10064435index 2869155..4882eba 100644
36--- a/configure.ac36--- a/configure.ac
37+++ b/configure.ac37+++ b/configure.ac
38@@ -1926,6 +1926,17 @@ else38@@ -1934,6 +1934,17 @@ else
39 fi39 fi
40 AC_SUBST([QUIET_BOOT])40 AC_SUBST([QUIET_BOOT])
41 41
diff --git a/debian/patches/riscv-adjust-march-flags-for-binutils-2.38.patch b/debian/patches/riscv-adjust-march-flags-for-binutils-2.38.patch
42new file mode 10064442new file mode 100644
index 0000000..afddd6c
--- /dev/null
+++ b/debian/patches/riscv-adjust-march-flags-for-binutils-2.38.patch
@@ -0,0 +1,43 @@
1From: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2Date: Sat, 29 Jan 2022 11:26:58 +0100
3Subject: riscv: adjust -march flags for binutils 2.38
4
5As of version 2.38 binutils defaults to ISA specification version
62019-12-13. This version of the specification has has separated the
7the csr read/write (csrr*/csrw*) instructions and the fence.i from
8the I extension and put them into separate Zicsr and Zifencei
9extensions.
10
11This implies that we have to adjust the -march flag passed to the
12compiler accordingly.
13
14Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
15Origin: https://lists.gnu.org/archive/html/grub-devel/2022-01/msg00173.html
16---
17 configure.ac | 8 ++++++++
18 1 file changed, 8 insertions(+)
19
20diff --git a/configure.ac b/configure.ac
21index 7517fc4..e3d4d72 100644
22--- a/configure.ac
23+++ b/configure.ac
24@@ -852,11 +852,19 @@ if test x"$platform" != xemu ; then
25 CFLAGS="$TARGET_CFLAGS -march=rv32imac -mabi=ilp32 -Werror"
26 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
27 [grub_cv_target_cc_soft_float="-march=rv32imac -mabi=ilp32"], [])
28+ # ISA spec version 20191213 factored out extensions Zicsr and Zifencei
29+ CFLAGS="$TARGET_CFLAGS -march=rv32imac_zicsr_zifencei -mabi=ilp32 -Werror"
30+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
31+ [grub_cv_target_cc_soft_float="-march=rv32imac_zicsr_zifencei -mabi=ilp32"], [])
32 fi
33 if test "x$target_cpu" = xriscv64; then
34 CFLAGS="$TARGET_CFLAGS -march=rv64imac -mabi=lp64 -Werror"
35 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
36 [grub_cv_target_cc_soft_float="-march=rv64imac -mabi=lp64"], [])
37+ # ISA spec version 20191213 factored out extensions Zicsr and Zifencei
38+ CFLAGS="$TARGET_CFLAGS -march=rv64imac_zicsr_zifencei -mabi=lp64 -Werror"
39+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
40+ [grub_cv_target_cc_soft_float="-march=rv64imac_zicsr_zifencei -mabi=lp64"], [])
41 fi
42 if test "x$target_cpu" = xia64; then
43 CFLAGS="$TARGET_CFLAGS -mno-inline-float-divide -mno-inline-sqrt -Werror"
diff --git a/debian/patches/series b/debian/patches/series
index 0f2405b..9e6fc4f 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,3 +1,11 @@
1riscv-adjust-march-flags-for-binutils-2.38.patch
2loader-drop-argv-argument-in-grub_initrd_load.patch
3efi-add-definition-of-LoadFile2-protocol.patch
4efi-implemented-LoadFile2-initrd-loading-protocol-fo.patch
5linux-ignore-FDT-unless-we-need-to-modify-it.patch
6loader-Move-arm64-linux-loader-to-common-code.patch
7RISC-V-Update-image-header.patch
8RISC-V-Use-common-linux-loader.patch
1olpc-prefix-hack.patch9olpc-prefix-hack.patch
2core-in-fs.patch10core-in-fs.patch
3dpkg-version-comparison.patch11dpkg-version-comparison.patch
@@ -108,4 +116,10 @@ no-devicetree-if-secure-boot.patch
1080099-chainloader-Avoid-a-double-free-when-validation-fail.patch1160099-chainloader-Avoid-a-double-free-when-validation-fail.patch
1090105-efilinux-Fix-integer-overflows-in-grub_cmd_initrd.patch1170105-efilinux-Fix-integer-overflows-in-grub_cmd_initrd.patch
110ubuntu-verifiers-last.patch118ubuntu-verifiers-last.patch
119<<<<<<< debian/patches/series
111ubuntu-fuse3.patch120ubuntu-fuse3.patch
121=======
122efi-correct-struct-grub_efi_boot_services.patch
123efi-implement-grub_efi_run_image.patch
124fat-fix-listing-the-root-directory.patch
125>>>>>>> debian/patches/series
diff --git a/debian/patches/suse-add-support-for-UEFI-network-protocols.patch b/debian/patches/suse-add-support-for-UEFI-network-protocols.patch
index 9724f73..262f4d0 100644
--- a/debian/patches/suse-add-support-for-UEFI-network-protocols.patch
+++ b/debian/patches/suse-add-support-for-UEFI-network-protocols.patch
@@ -64,10 +64,10 @@ V6:
64 create mode 100644 include/grub/net/efi.h64 create mode 100644 include/grub/net/efi.h
6565
66diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def66diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
67index 98cda49..a47c403 10064467index 0b5b4e7..3b06462 100644
68--- a/grub-core/Makefile.core.def68--- a/grub-core/Makefile.core.def
69+++ b/grub-core/Makefile.core.def69+++ b/grub-core/Makefile.core.def
70@@ -2322,6 +2322,12 @@ module = {70@@ -2324,6 +2324,12 @@ module = {
71 common = net/ethernet.c;71 common = net/ethernet.c;
72 common = net/arp.c;72 common = net/arp.c;
73 common = net/netbuff.c;73 common = net/netbuff.c;
@@ -3969,10 +3969,10 @@ index 15a2f29..34bf04f 100644
3969+#endif3969+#endif
3970 }3970 }
3971diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h3971diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h
3972index 9cab1a5..3b2f2e3 1006443972index 479c2a8..3211f04 100644
3973--- a/include/grub/efi/api.h3973--- a/include/grub/efi/api.h
3974+++ b/include/grub/efi/api.h3974+++ b/include/grub/efi/api.h
3975@@ -608,6 +608,23 @@ typedef grub_uint16_t grub_efi_ipv6_address_t[8];3975@@ -613,6 +613,23 @@ typedef grub_uint16_t grub_efi_ipv6_address_t[8];
3976 typedef grub_uint8_t grub_efi_ip_address_t[8] __attribute__ ((aligned(4)));3976 typedef grub_uint8_t grub_efi_ip_address_t[8] __attribute__ ((aligned(4)));
3977 typedef grub_efi_uint64_t grub_efi_physical_address_t;3977 typedef grub_efi_uint64_t grub_efi_physical_address_t;
3978 typedef grub_efi_uint64_t grub_efi_virtual_address_t;3978 typedef grub_efi_uint64_t grub_efi_virtual_address_t;
@@ -3996,7 +3996,7 @@ index 9cab1a5..3b2f2e3 100644
3996 3996
3997 struct grub_efi_guid3997 struct grub_efi_guid
3998 {3998 {
3999@@ -875,6 +892,8 @@ struct grub_efi_ipv6_device_path3999@@ -880,6 +897,8 @@ struct grub_efi_ipv6_device_path
4000 grub_efi_uint16_t remote_port;4000 grub_efi_uint16_t remote_port;
4001 grub_efi_uint16_t protocol;4001 grub_efi_uint16_t protocol;
4002 grub_efi_uint8_t static_ip_address;4002 grub_efi_uint8_t static_ip_address;
@@ -4005,7 +4005,7 @@ index 9cab1a5..3b2f2e3 100644
4005 } GRUB_PACKED;4005 } GRUB_PACKED;
4006 typedef struct grub_efi_ipv6_device_path grub_efi_ipv6_device_path_t;4006 typedef struct grub_efi_ipv6_device_path grub_efi_ipv6_device_path_t;
4007 4007
4008@@ -924,6 +943,15 @@ struct grub_efi_uri_device_path4008@@ -929,6 +948,15 @@ struct grub_efi_uri_device_path
4009 } GRUB_PACKED;4009 } GRUB_PACKED;
4010 typedef struct grub_efi_uri_device_path grub_efi_uri_device_path_t;4010 typedef struct grub_efi_uri_device_path grub_efi_uri_device_path_t;
4011 4011
@@ -4021,7 +4021,7 @@ index 9cab1a5..3b2f2e3 100644
4021 #define GRUB_EFI_VENDOR_MESSAGING_DEVICE_PATH_SUBTYPE 104021 #define GRUB_EFI_VENDOR_MESSAGING_DEVICE_PATH_SUBTYPE 10
4022 4022
4023 /* Media Device Path. */4023 /* Media Device Path. */
4024@@ -1006,6 +1034,23 @@ struct grub_efi_bios_device_path4024@@ -1011,6 +1039,23 @@ struct grub_efi_bios_device_path
4025 } GRUB_PACKED;4025 } GRUB_PACKED;
4026 typedef struct grub_efi_bios_device_path grub_efi_bios_device_path_t;4026 typedef struct grub_efi_bios_device_path grub_efi_bios_device_path_t;
4027 4027
@@ -4045,7 +4045,7 @@ index 9cab1a5..3b2f2e3 100644
4045 struct grub_efi_open_protocol_information_entry4045 struct grub_efi_open_protocol_information_entry
4046 {4046 {
4047 grub_efi_handle_t agent_handle;4047 grub_efi_handle_t agent_handle;
4048@@ -1497,23 +1542,28 @@ typedef struct grub_efi_simple_text_output_interface grub_efi_simple_text_output4048@@ -1502,23 +1547,28 @@ typedef struct grub_efi_simple_text_output_interface grub_efi_simple_text_output
4049 4049
4050 typedef grub_uint8_t grub_efi_pxe_packet_t[1472];4050 typedef grub_uint8_t grub_efi_pxe_packet_t[1472];
4051 4051
@@ -4088,7 +4088,7 @@ index 9cab1a5..3b2f2e3 100644
4088 4088
4089 #define GRUB_EFI_PXE_BASE_CODE_MAX_IPCNT 84089 #define GRUB_EFI_PXE_BASE_CODE_MAX_IPCNT 8
4090 typedef struct {4090 typedef struct {
4091@@ -1563,17 +1613,31 @@ typedef struct grub_efi_pxe_mode4091@@ -1568,17 +1618,31 @@ typedef struct grub_efi_pxe_mode
4092 typedef struct grub_efi_pxe4092 typedef struct grub_efi_pxe
4093 {4093 {
4094 grub_uint64_t rev;4094 grub_uint64_t rev;
@@ -4124,7 +4124,7 @@ index 9cab1a5..3b2f2e3 100644
4124 void (*setpackets) (void);4124 void (*setpackets) (void);
4125 struct grub_efi_pxe_mode *mode;4125 struct grub_efi_pxe_mode *mode;
4126 } grub_efi_pxe_t;4126 } grub_efi_pxe_t;
4127@@ -1835,6 +1899,44 @@ struct grub_efi_ip4_config2_protocol4127@@ -1850,6 +1914,44 @@ struct grub_efi_ip4_config2_protocol
4128 };4128 };
4129 typedef struct grub_efi_ip4_config2_protocol grub_efi_ip4_config2_protocol_t;4129 typedef struct grub_efi_ip4_config2_protocol grub_efi_ip4_config2_protocol_t;
4130 4130
@@ -4169,7 +4169,7 @@ index 9cab1a5..3b2f2e3 100644
4169 enum grub_efi_ip6_config_data_type {4169 enum grub_efi_ip6_config_data_type {
4170 GRUB_EFI_IP6_CONFIG_DATA_TYPE_INTERFACEINFO,4170 GRUB_EFI_IP6_CONFIG_DATA_TYPE_INTERFACEINFO,
4171 GRUB_EFI_IP6_CONFIG_DATA_TYPE_ALT_INTERFACEID,4171 GRUB_EFI_IP6_CONFIG_DATA_TYPE_ALT_INTERFACEID,
4172@@ -1869,6 +1971,49 @@ struct grub_efi_ip6_config_protocol4172@@ -1884,6 +1986,49 @@ struct grub_efi_ip6_config_protocol
4173 };4173 };
4174 typedef struct grub_efi_ip6_config_protocol grub_efi_ip6_config_protocol_t;4174 typedef struct grub_efi_ip6_config_protocol grub_efi_ip6_config_protocol_t;
4175 4175
diff --git a/debian/patches/ubuntu-add-initrd-less-boot-fallback.patch b/debian/patches/ubuntu-add-initrd-less-boot-fallback.patch
index 6dc4335..9a0ed6c 100644
--- a/debian/patches/ubuntu-add-initrd-less-boot-fallback.patch
+++ b/debian/patches/ubuntu-add-initrd-less-boot-fallback.patch
@@ -32,7 +32,7 @@ index bf9c1ba..353061e 100644
32 32
33 syslinux_test: $(top_builddir)/config.status tests/syslinux/ubuntu10.04_grub.cfg33 syslinux_test: $(top_builddir)/config.status tests/syslinux/ubuntu10.04_grub.cfg
34diff --git a/configure.ac b/configure.ac34diff --git a/configure.ac b/configure.ac
35index 22c6cf7..3c87596 10064435index a29beb9..15a2a50 100644
36--- a/configure.ac36--- a/configure.ac
37+++ b/configure.ac37+++ b/configure.ac
38@@ -314,6 +314,16 @@ AC_SUBST(grubdirname)38@@ -314,6 +314,16 @@ AC_SUBST(grubdirname)
diff --git a/debian/patches/ubuntu-efi-allow-loopmount-chainload.patch b/debian/patches/ubuntu-efi-allow-loopmount-chainload.patch
index b0e49aa..7ab0799 100644
--- a/debian/patches/ubuntu-efi-allow-loopmount-chainload.patch
+++ b/debian/patches/ubuntu-efi-allow-loopmount-chainload.patch
@@ -40,7 +40,7 @@ index 41bebd1..99f4792 100644
40 static unsigned long last_id = 0;40 static unsigned long last_id = 0;
41 41
42diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c42diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c
43index 9e301f2..cf76f48 10064443index c3144de..2b74d79 100644
44--- a/grub-core/loader/efi/chainloader.c44--- a/grub-core/loader/efi/chainloader.c
45+++ b/grub-core/loader/efi/chainloader.c45+++ b/grub-core/loader/efi/chainloader.c
46@@ -24,6 +24,7 @@46@@ -24,6 +24,7 @@
@@ -51,7 +51,7 @@ index 9e301f2..cf76f48 100644
51 #include <grub/misc.h>51 #include <grub/misc.h>
52 #include <grub/charset.h>52 #include <grub/charset.h>
53 #include <grub/mm.h>53 #include <grub/mm.h>
54@@ -906,6 +907,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),54@@ -905,6 +906,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
55 grub_efi_status_t status;55 grub_efi_status_t status;
56 grub_efi_boot_services_t *b;56 grub_efi_boot_services_t *b;
57 grub_device_t dev = 0;57 grub_device_t dev = 0;
@@ -59,7 +59,7 @@ index 9e301f2..cf76f48 100644
59 grub_efi_device_path_t *dp = 0;59 grub_efi_device_path_t *dp = 0;
60 char *filename;60 char *filename;
61 void *boot_image = 0;61 void *boot_image = 0;
62@@ -963,6 +965,15 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),62@@ -962,6 +964,15 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
63 if (! dev)63 if (! dev)
64 goto fail;64 goto fail;
65 65
@@ -75,7 +75,7 @@ index 9e301f2..cf76f48 100644
75 if (dev->disk)75 if (dev->disk)
76 dev_handle = grub_efidisk_get_device_handle (dev->disk);76 dev_handle = grub_efidisk_get_device_handle (dev->disk);
77 else if (dev->net && dev->net->server)77 else if (dev->net && dev->net->server)
78@@ -1092,6 +1103,12 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),78@@ -1091,6 +1102,12 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
79 grub_device_close (dev);79 grub_device_close (dev);
80 80
81 fail:81 fail:
diff --git a/debian/patches/ubuntu-fix-lzma-decompressor-objcopy.patch b/debian/patches/ubuntu-fix-lzma-decompressor-objcopy.patch
index 75ab70c..2c1a376 100644
--- a/debian/patches/ubuntu-fix-lzma-decompressor-objcopy.patch
+++ b/debian/patches/ubuntu-fix-lzma-decompressor-objcopy.patch
@@ -15,7 +15,7 @@ Signed-off-by: Mathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>
15 1 file changed, 1 insertion(+), 1 deletion(-)15 1 file changed, 1 insertion(+), 1 deletion(-)
1616
17diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def17diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
18index f953817..98cda49 10064418index f252725..0b5b4e7 100644
19--- a/grub-core/Makefile.core.def19--- a/grub-core/Makefile.core.def
20+++ b/grub-core/Makefile.core.def20+++ b/grub-core/Makefile.core.def
21@@ -550,7 +550,7 @@ image = {21@@ -550,7 +550,7 @@ image = {
diff --git a/debian/patches/ubuntu-linuxefi-arm64-set-base-addr.patch b/debian/patches/ubuntu-linuxefi-arm64-set-base-addr.patch
index e00ae03..9b5e997 100644
--- a/debian/patches/ubuntu-linuxefi-arm64-set-base-addr.patch
+++ b/debian/patches/ubuntu-linuxefi-arm64-set-base-addr.patch
@@ -30,13 +30,13 @@ Origin: https://github.com/rhboot/grub2/commit/1d5ef08216edec4d31d0e10cfdb30b5eb
30Last-Updated: 2020-11-0930Last-Updated: 2020-11-09
31Patch-Name: ubuntu-linuxefi-arm64-set-base-addr.patch31Patch-Name: ubuntu-linuxefi-arm64-set-base-addr.patch
32---32---
33 grub-core/loader/efi/linux.c | 15 +++++++++++++++33 grub-core/loader/efi/linux_sb.c | 15 +++++++++++++++
34 1 file changed, 15 insertions(+)34 1 file changed, 15 insertions(+)
3535
36diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c36diff --git a/grub-core/loader/efi/linux_sb.c b/grub-core/loader/efi/linux_sb.c
37index e372b26..73a7196 10064437index e372b26..73a7196 100644
38--- a/grub-core/loader/efi/linux.c38--- a/grub-core/loader/efi/linux_sb.c
39+++ b/grub-core/loader/efi/linux.c39+++ b/grub-core/loader/efi/linux_sb.c
40@@ -71,6 +71,7 @@ grub_err_t40@@ -71,6 +71,7 @@ grub_err_t
41 grub_efi_linux_boot (void *kernel_addr, grub_off_t handover_offset,41 grub_efi_linux_boot (void *kernel_addr, grub_off_t handover_offset,
42 void *kernel_params)42 void *kernel_params)
diff --git a/debian/patches/ubuntu-linuxefi-arm64.patch b/debian/patches/ubuntu-linuxefi-arm64.patch
index e7f4e71..7789a5a 100644
--- a/debian/patches/ubuntu-linuxefi-arm64.patch
+++ b/debian/patches/ubuntu-linuxefi-arm64.patch
@@ -12,23 +12,22 @@ Bug-Ubuntu: https://bugs.launchpad.net/1862279
12Origin: vendor, https://github.com/rhboot/grub2/commit/2786ab864cf00c15123320671f653e9a36ba12b412Origin: vendor, https://github.com/rhboot/grub2/commit/2786ab864cf00c15123320671f653e9a36ba12b4
13Patch-Name: ubuntu-linuxefi-arm64.patch13Patch-Name: ubuntu-linuxefi-arm64.patch
14---14---
15 grub-core/loader/arm64/linux.c | 106 ++++++++++++++++++++++-------------------15 grub-core/loader/efi/linux.c | 101 ++++++++++++++++++++++---------------------
16 1 file changed, 56 insertions(+), 50 deletions(-)16 1 file changed, 51 insertions(+), 50 deletions(-)
1717
18diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c18diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c
19index 1a5296a..4e9eac3 10064419index d81e7be..93e4cfc 100644
20--- a/grub-core/loader/arm64/linux.c20--- a/grub-core/loader/efi/linux.c
21+++ b/grub-core/loader/arm64/linux.c21+++ b/grub-core/loader/efi/linux.c
22@@ -42,6 +42,8 @@ static int loaded;22@@ -42,6 +42,7 @@ static int loaded;
23 23
24 static void *kernel_addr;24 static void *kernel_addr;
25 static grub_uint64_t kernel_size;25 static grub_uint64_t kernel_size;
26+static grub_uint32_t handover_offset;26+static grub_uint32_t handover_offset;
27+
28 27
29 static char *linux_args;28 static char *linux_args;
30 static grub_uint32_t cmdline_size;29 static grub_uint32_t cmdline_size;
31@@ -75,7 +77,8 @@ grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh)30@@ -99,7 +100,8 @@ grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh)
32 static grub_err_t31 static grub_err_t
33 finalize_params_linux (void)32 finalize_params_linux (void)
34 {33 {
@@ -36,9 +35,9 @@ index 1a5296a..4e9eac3 100644
36+ grub_efi_loaded_image_t *loaded_image = NULL;35+ grub_efi_loaded_image_t *loaded_image = NULL;
37+ int node, retval, len;36+ int node, retval, len;
38 37
39 void *fdt;38 void *fdt = NULL;
40 39
41@@ -110,6 +113,27 @@ finalize_params_linux (void)40@@ -134,6 +136,27 @@ finalize_params_linux (void)
42 if (grub_fdt_install() != GRUB_ERR_NONE)41 if (grub_fdt_install() != GRUB_ERR_NONE)
43 goto failure;42 goto failure;
44 43
@@ -66,28 +65,14 @@ index 1a5296a..4e9eac3 100644
66 return GRUB_ERR_NONE;65 return GRUB_ERR_NONE;
67 66
68 failure:67 failure:
69@@ -117,70 +141,48 @@ failure:68@@ -141,62 +164,36 @@ failure:
70 return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT");69 return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT");
71 }70 }
72 71
72-grub_err_t
73-grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)
73+static void74+static void
74+free_params (void)75+free_params (void)
75+{
76+ grub_efi_loaded_image_t *loaded_image = NULL;
77+ loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle);
78+ if (loaded_image)
79+ {
80+ if (loaded_image->load_options)
81+ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_efi_uintn_t)
82+ loaded_image->load_options,
83+ GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
84+ loaded_image->load_options = NULL;
85+ loaded_image->load_options_size = 0;
86+ }
87+}
88+
89 grub_err_t
90 grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args)
91 {76 {
92- grub_efi_memory_mapped_device_path_t *mempath;77- grub_efi_memory_mapped_device_path_t *mempath;
93- grub_efi_handle_t image_handle;78- grub_efi_handle_t image_handle;
@@ -106,21 +91,35 @@ index 1a5296a..4e9eac3 100644
106- mempath[0].memory_type = GRUB_EFI_LOADER_DATA;91- mempath[0].memory_type = GRUB_EFI_LOADER_DATA;
107- mempath[0].start_address = addr;92- mempath[0].start_address = addr;
108- mempath[0].end_address = addr + size;93- mempath[0].end_address = addr + size;
109+ grub_err_t retval;94-
110
111- mempath[1].header.type = GRUB_EFI_END_DEVICE_PATH_TYPE;95- mempath[1].header.type = GRUB_EFI_END_DEVICE_PATH_TYPE;
112- mempath[1].header.subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE;96- mempath[1].header.subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE;
113- mempath[1].header.length = sizeof (grub_efi_device_path_t);97- mempath[1].header.length = sizeof (grub_efi_device_path_t);
114-98+ grub_efi_loaded_image_t *loaded_image = NULL;
99+ loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle);
100+ if (loaded_image)
101+ {
102+ if (loaded_image->load_options)
103+ grub_efi_free_pages ((grub_efi_physical_address_t)(grub_efi_uintn_t)
104+ loaded_image->load_options,
105+ GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
106+ loaded_image->load_options = NULL;
107+ loaded_image->load_options_size = 0;
108+ }
109+}
110
115- b = grub_efi_system_table->boot_services;111- b = grub_efi_system_table->boot_services;
116- status = b->load_image (0, grub_efi_image_handle,112- status = b->load_image (0, grub_efi_image_handle,
117- (grub_efi_device_path_t *) mempath,113- (grub_efi_device_path_t *) mempath,
118- (void *) addr, size, &image_handle);114- (void *) addr, size, &image_handle);
119- if (status != GRUB_EFI_SUCCESS)115- if (status != GRUB_EFI_SUCCESS)
120- return grub_error (GRUB_ERR_BAD_OS, "cannot load image");116- return grub_error (GRUB_ERR_BAD_OS, "cannot load image");
121+ retval = finalize_params_linux ();117+grub_err_t
122+ if (retval != GRUB_ERR_NONE)118+grub_arch_efi_linux_boot_image (grub_addr_t addr __attribute__((unused)),
123+ return grub_errno;119+ grub_size_t size __attribute__((unused)),
120+ char *args)
121+{
122+ grub_err_t retval;
124 123
125 grub_dprintf ("linux", "linux command line: '%s'\n", args);124 grub_dprintf ("linux", "linux command line: '%s'\n", args);
126 125
@@ -136,35 +135,23 @@ index 1a5296a..4e9eac3 100644
136- loaded_image->load_options_size =135- loaded_image->load_options_size =
137- 2 * grub_utf8_to_utf16 (loaded_image->load_options, len,136- 2 * grub_utf8_to_utf16 (loaded_image->load_options, len,
138- (grub_uint8_t *) args, len, NULL);137- (grub_uint8_t *) args, len, NULL);
139+ (void) addr;138-
140+ (void) size;
141
142- grub_dprintf ("linux", "starting image %p\n", image_handle);139- grub_dprintf ("linux", "starting image %p\n", image_handle);
143- status = b->start_image (image_handle, 0, NULL);140- status = b->start_image (image_handle, 0, NULL);
141+ retval = grub_efi_linux_boot (kernel_addr, handover_offset, kernel_addr);
144 142
145- /* When successful, not reached */143 /* When successful, not reached */
146- b->unload_image (image_handle);144- b->unload_image (image_handle);
147- grub_efi_free_pages ((grub_addr_t) loaded_image->load_options,145- grub_efi_free_pages ((grub_addr_t) loaded_image->load_options,
148- GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));146- GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size));
149+ retval = grub_efi_linux_boot ((char *)kernel_addr, handover_offset,147-
150+ kernel_addr);
151
152- return grub_errno;148- return grub_errno;
153+ /* Never reached... */
154+ free_params();149+ free_params();
155+ return retval;150+ return retval;
156 }151 }
157 152
158 static grub_err_t153 static grub_err_t
159 grub_linux_boot (void)154@@ -411,6 +408,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
160 {
161- if (finalize_params_linux () != GRUB_ERR_NONE)
162- return grub_errno;
163-
164 return (grub_arch_efi_linux_boot_image((grub_addr_t)kernel_addr,
165 kernel_size, linux_args));
166 }
167@@ -296,6 +298,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
168 {155 {
169 grub_file_t file = 0;156 grub_file_t file = 0;
170 struct linux_arch_kernel_header lh;157 struct linux_arch_kernel_header lh;
@@ -172,7 +159,7 @@ index 1a5296a..4e9eac3 100644
172 grub_err_t err;159 grub_err_t err;
173 int rc;160 int rc;
174 161
175@@ -349,6 +352,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),162@@ -464,6 +462,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
176 goto fail;163 goto fail;
177 }164 }
178 165
diff --git a/debian/patches/ubuntu-linuxefi.patch b/debian/patches/ubuntu-linuxefi.patch
index eb99d16..533b900 100644
--- a/debian/patches/ubuntu-linuxefi.patch
+++ b/debian/patches/ubuntu-linuxefi.patch
@@ -318,17 +318,17 @@ Last-Update: 2018-12-07
318Updated 2021-12-13: If we cannot allocate kernel at preferred address,318Updated 2021-12-13: If we cannot allocate kernel at preferred address,
319reset errno so that we do not fail erroneously with out of memory.319reset errno so that we do not fail erroneously with out of memory.
320---320---
321 grub-core/Makefile.core.def | 15 +-321 grub-core/Makefile.core.def | 17 +-
322 grub-core/commands/iorw.c | 7 +322 grub-core/commands/iorw.c | 7 +
323 grub-core/commands/memrw.c | 7 +323 grub-core/commands/memrw.c | 7 +
324 grub-core/kern/arm/coreboot/coreboot.S | 6 +324 grub-core/kern/arm/coreboot/coreboot.S | 6 +
325 grub-core/kern/dl.c | 1 +325 grub-core/kern/dl.c | 1 +
326 grub-core/kern/efi/mm.c | 32 ++326 grub-core/kern/efi/mm.c | 32 ++
327 grub-core/loader/arm64/linux.c | 16 +
328 grub-core/loader/efi/appleloader.c | 7 +327 grub-core/loader/efi/appleloader.c | 7 +
329 grub-core/loader/efi/chainloader.c | 816 ++++++++++++++++++++++++++++++---328 grub-core/loader/efi/chainloader.c | 815 ++++++++++++++++++++++++++++++---
330 grub-core/loader/efi/fdt.c | 1 +329 grub-core/loader/efi/fdt.c | 1 +
331 grub-core/loader/efi/linux.c | 86 ++++330 grub-core/loader/efi/linux.c | 16 +
331 grub-core/loader/efi/linux_sb.c | 86 ++++
332 grub-core/loader/i386/bsd.c | 7 +332 grub-core/loader/i386/bsd.c | 7 +
333 grub-core/loader/i386/efi/linux.c | 382 +++++++++++++++333 grub-core/loader/i386/efi/linux.c | 382 +++++++++++++++
334 grub-core/loader/i386/linux.c | 78 +++-334 grub-core/loader/i386/linux.c | 78 +++-
@@ -344,8 +344,8 @@ reset errno so that we do not fail erroneously with out of memory.
344 include/grub/mips/linux.h | 0344 include/grub/mips/linux.h | 0
345 include/grub/powerpc/linux.h | 0345 include/grub/powerpc/linux.h | 0
346 include/grub/sparc64/linux.h | 0346 include/grub/sparc64/linux.h | 0
347 26 files changed, 1510 insertions(+), 100 deletions(-)347 26 files changed, 1511 insertions(+), 100 deletions(-)
348 create mode 100644 grub-core/loader/efi/linux.c348 create mode 100644 grub-core/loader/efi/linux_sb.c
349 create mode 100644 grub-core/loader/i386/efi/linux.c349 create mode 100644 grub-core/loader/i386/efi/linux.c
350 create mode 100644 include/grub/efi/linux.h350 create mode 100644 include/grub/efi/linux.h
351 create mode 100644 include/grub/ia64/linux.h351 create mode 100644 include/grub/ia64/linux.h
@@ -354,24 +354,26 @@ reset errno so that we do not fail erroneously with out of memory.
354 create mode 100644 include/grub/sparc64/linux.h354 create mode 100644 include/grub/sparc64/linux.h
355355
356diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def356diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
357index 8022e1c..715d137 100644357index 0536575..1a3ead6 100644
358--- a/grub-core/Makefile.core.def358--- a/grub-core/Makefile.core.def
359+++ b/grub-core/Makefile.core.def359+++ b/grub-core/Makefile.core.def
360@@ -1807,10 +1807,13 @@ module = {360@@ -1807,10 +1807,15 @@ module = {
361 ia64_efi = loader/ia64/efi/linux.c;361 ia64_efi = loader/ia64/efi/linux.c;
362 arm_coreboot = loader/arm/linux.c;362 arm_coreboot = loader/arm/linux.c;
363 arm_efi = loader/arm64/linux.c;363 arm_efi = loader/efi/linux.c;
364+ arm_efi = loader/efi/linux.c;364+ arm_efi = loader/efi/linux_sb.c;
365 arm_uboot = loader/arm/linux.c;365 arm_uboot = loader/arm/linux.c;
366 arm64 = loader/arm64/linux.c;366 arm64 = loader/efi/linux.c;
367+ arm64 = loader/efi/linux.c;367+ arm64 = loader/efi/linux_sb.c;
368 riscv32 = loader/riscv/linux.c;368 riscv32 = loader/efi/linux.c;
369 riscv64 = loader/riscv/linux.c;369+ riscv32 = loader/efi/linux_sb.c;
370 riscv64 = loader/efi/linux.c;
371+ riscv64 = loader/efi/linux_sb.c;
370+ cflags = '-Wno-error=cast-align';372+ cflags = '-Wno-error=cast-align';
371 common = loader/linux.c;373 common = loader/linux.c;
372 common = lib/cmdline.c;374 common = lib/cmdline.c;
373 enable = noemu;375 enable = noemu;
374@@ -1819,7 +1822,7 @@ module = {376@@ -1819,7 +1824,7 @@ module = {
375 module = {377 module = {
376 name = fdt;378 name = fdt;
377 efi = loader/efi/fdt.c;379 efi = loader/efi/fdt.c;
@@ -380,14 +382,14 @@ index 8022e1c..715d137 100644
380 enable = fdt;382 enable = fdt;
381 };383 };
382 384
383@@ -1874,12 +1877,22 @@ module = {385@@ -1874,12 +1879,22 @@ module = {
384 enable = x86_64_efi;386 enable = x86_64_efi;
385 };387 };
386 388
387+module = {389+module = {
388+ name = linuxefi;390+ name = linuxefi;
389+ efi = loader/i386/efi/linux.c;391+ efi = loader/i386/efi/linux.c;
390+ efi = loader/efi/linux.c;392+ efi = loader/efi/linux_sb.c;
391+ cflags = '-Wno-error=cast-align';393+ cflags = '-Wno-error=cast-align';
392+ enable = i386_efi;394+ enable = i386_efi;
393+ enable = x86_64_efi;395+ enable = x86_64_efi;
@@ -536,54 +538,6 @@ index 9838fb2..f6aef0e 100644
536 /* Allocate pages. Return the pointer to the first of allocated pages. */538 /* Allocate pages. Return the pointer to the first of allocated pages. */
537 void *539 void *
538 grub_efi_allocate_pages_real (grub_efi_physical_address_t address,540 grub_efi_allocate_pages_real (grub_efi_physical_address_t address,
539diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c
540index ef3e9f9..1a5296a 100644
541--- a/grub-core/loader/arm64/linux.c
542+++ b/grub-core/loader/arm64/linux.c
543@@ -27,6 +27,7 @@
544 #include <grub/types.h>
545 #include <grub/cpu/linux.h>
546 #include <grub/efi/efi.h>
547+#include <grub/efi/linux.h>
548 #include <grub/efi/fdtload.h>
549 #include <grub/efi/memory.h>
550 #include <grub/efi/pe32.h>
551@@ -48,6 +49,13 @@ static grub_uint32_t cmdline_size;
552 static grub_addr_t initrd_start;
553 static grub_addr_t initrd_end;
554
555+struct grub_arm64_linux_pe_header
556+{
557+ grub_uint32_t magic;
558+ struct grub_pe32_coff_header coff;
559+ struct grub_pe64_optional_header opt;
560+};
561+
562 grub_err_t
563 grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh)
564 {
565@@ -289,6 +297,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
566 grub_file_t file = 0;
567 struct linux_arch_kernel_header lh;
568 grub_err_t err;
569+ int rc;
570
571 grub_dl_ref (my_mod);
572
573@@ -333,6 +342,13 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
574
575 grub_dprintf ("linux", "kernel @ %p\n", kernel_addr);
576
577+ rc = grub_linuxefi_secure_validate (kernel_addr, kernel_size);
578+ if (rc < 0)
579+ {
580+ grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"), argv[0]);
581+ goto fail;
582+ }
583+
584 cmdline_size = grub_loader_cmdline_size (argc, argv) + sizeof (LINUX_IMAGE);
585 linux_args = grub_malloc (cmdline_size);
586 if (!linux_args)
587diff --git a/grub-core/loader/efi/appleloader.c b/grub-core/loader/efi/appleloader.c541diff --git a/grub-core/loader/efi/appleloader.c b/grub-core/loader/efi/appleloader.c
588index 74888c4..07677f0 100644542index 74888c4..07677f0 100644
589--- a/grub-core/loader/efi/appleloader.c543--- a/grub-core/loader/efi/appleloader.c
@@ -616,7 +570,7 @@ index 74888c4..07677f0 100644
616 grub_unregister_command (cmd);570 grub_unregister_command (cmd);
617 }571 }
618diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c572diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c
619index 2bd80f4..9e301f2 100644573index 2bd80f4..c3144de 100644
620--- a/grub-core/loader/efi/chainloader.c574--- a/grub-core/loader/efi/chainloader.c
621+++ b/grub-core/loader/efi/chainloader.c575+++ b/grub-core/loader/efi/chainloader.c
622@@ -32,6 +32,9 @@576@@ -32,6 +32,9 @@
@@ -652,7 +606,7 @@ index 2bd80f4..9e301f2 100644
652 606
653 grub_dl_unref (my_mod);607 grub_dl_unref (my_mod);
654 return GRUB_ERR_NONE;608 return GRUB_ERR_NONE;
655@@ -213,20 +222,694 @@ make_file_path (grub_efi_device_path_t *dp, const char *filename)609@@ -213,20 +222,693 @@ make_file_path (grub_efi_device_path_t *dp, const char *filename)
656 return file_path;610 return file_path;
657 }611 }
658 612
@@ -767,6 +721,8 @@ index 2bd80f4..9e301f2 100644
767+ GRUB_PE32_MACHINE_I386;721+ GRUB_PE32_MACHINE_I386;
768+#elif defined(__ia64__)722+#elif defined(__ia64__)
769+ GRUB_PE32_MACHINE_IA64;723+ GRUB_PE32_MACHINE_IA64;
724+#elif defined(__riscv) && __riscv_xlen == 64
725+ GRUB_PE32_MACHINE_RISCV64;
770+#else726+#else
771+#error this architecture is not supported by grub2727+#error this architecture is not supported by grub2
772+#endif728+#endif
@@ -782,9 +738,7 @@ index 2bd80f4..9e301f2 100644
782+ char *fixup, *fixup_base, *fixup_data = NULL;738+ char *fixup, *fixup_base, *fixup_data = NULL;
783+ grub_efi_uint16_t *fixup_16;739+ grub_efi_uint16_t *fixup_16;
784+ grub_efi_uint32_t *fixup_32;740+ grub_efi_uint32_t *fixup_32;
785+#if defined(__x86_64__) || defined(__aarch64__)
786+ grub_efi_uint64_t *fixup_64;741+ grub_efi_uint64_t *fixup_64;
787+#endif /* defined(__x86_64__) || defined(__aarch64__) */
788+ grub_efi_uint64_t size = context->image_size;742+ grub_efi_uint64_t size = context->image_size;
789+ void *image_end = (char *)orig + size;743+ void *image_end = (char *)orig + size;
790+ int n = 0;744+ int n = 0;
@@ -911,7 +865,6 @@ index 2bd80f4..9e301f2 100644
911+ fixup_data += sizeof (grub_uint32_t);865+ fixup_data += sizeof (grub_uint32_t);
912+ }866+ }
913+ break;867+ break;
914+#if defined(__x86_64__) || defined(__aarch64__)
915+ case GRUB_PE32_REL_BASED_DIR64:868+ case GRUB_PE32_REL_BASED_DIR64:
916+ fixup_64 = (grub_uint64_t *)fixup;869+ fixup_64 = (grub_uint64_t *)fixup;
917+ *fixup_64 = *fixup_64 + (grub_uint64_t)adjust;870+ *fixup_64 = *fixup_64 + (grub_uint64_t)adjust;
@@ -922,7 +875,7 @@ index 2bd80f4..9e301f2 100644
922+ fixup_data += sizeof (grub_uint64_t);875+ fixup_data += sizeof (grub_uint64_t);
923+ }876+ }
924+ break;877+ break;
925+#endif /* defined(__x86_64__) || defined(__aarch64__) */878+ /* TODO: GRUB_PE32_REL_BASED_RISCV_HI20, GRUB_PE32_REL_BASED_RISCV_LOW12I/S */
926+ default:879+ default:
927+ grub_error (GRUB_ERR_BAD_ARGUMENT,880+ grub_error (GRUB_ERR_BAD_ARGUMENT,
928+ "Reloc %d unknown relocation type %d",881+ "Reloc %d unknown relocation type %d",
@@ -1350,7 +1303,7 @@ index 2bd80f4..9e301f2 100644
1350 1303
1351 if (argc == 0)1304 if (argc == 0)
1352 return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));1305 return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
1353@@ -238,15 +921,45 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),1306@@ -238,15 +920,45 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
1354 address = 0;1307 address = 0;
1355 image_handle = 0;1308 image_handle = 0;
1356 file_path = 0;1309 file_path = 0;
@@ -1398,7 +1351,7 @@ index 2bd80f4..9e301f2 100644
1398 if (! dev)1351 if (! dev)
1399 goto fail;1352 goto fail;
1400 1353
1401@@ -283,17 +996,14 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),1354@@ -283,17 +995,14 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
1402 if (! file_path)1355 if (! file_path)
1403 goto fail;1356 goto fail;
1404 1357
@@ -1419,7 +1372,7 @@ index 2bd80f4..9e301f2 100644
1419 1372
1420 status = efi_call_4 (b->allocate_pages, GRUB_EFI_ALLOCATE_ANY_PAGES,1373 status = efi_call_4 (b->allocate_pages, GRUB_EFI_ALLOCATE_ANY_PAGES,
1421 GRUB_EFI_LOADER_CODE,1374 GRUB_EFI_LOADER_CODE,
1422@@ -307,7 +1017,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),1375@@ -307,7 +1016,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
1423 }1376 }
1424 1377
1425 boot_image = (void *) ((grub_addr_t) address);1378 boot_image = (void *) ((grub_addr_t) address);
@@ -1428,7 +1381,7 @@ index 2bd80f4..9e301f2 100644
1428 {1381 {
1429 if (grub_errno == GRUB_ERR_NONE)1382 if (grub_errno == GRUB_ERR_NONE)
1430 grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),1383 grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
1431@@ -317,7 +1027,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),1384@@ -317,7 +1026,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
1432 }1385 }
1433 1386
1434 #if defined (__i386__) || defined (__x86_64__)1387 #if defined (__i386__) || defined (__x86_64__)
@@ -1437,7 +1390,7 @@ index 2bd80f4..9e301f2 100644
1437 {1390 {
1438 struct grub_macho_fat_header *head = boot_image;1391 struct grub_macho_fat_header *head = boot_image;
1439 if (head->magic1392 if (head->magic
1440@@ -326,6 +1036,14 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),1393@@ -326,6 +1035,14 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
1441 grub_uint32_t i;1394 grub_uint32_t i;
1442 struct grub_macho_fat_arch *archs1395 struct grub_macho_fat_arch *archs
1443 = (struct grub_macho_fat_arch *) (head + 1);1396 = (struct grub_macho_fat_arch *) (head + 1);
@@ -1452,7 +1405,7 @@ index 2bd80f4..9e301f2 100644
1452 for (i = 0; i < grub_cpu_to_le32 (head->nfat_arch); i++)1405 for (i = 0; i < grub_cpu_to_le32 (head->nfat_arch); i++)
1453 {1406 {
1454 if (GRUB_MACHO_CPUTYPE_IS_HOST_CURRENT (archs[i].cputype))1407 if (GRUB_MACHO_CPUTYPE_IS_HOST_CURRENT (archs[i].cputype))
1455@@ -340,79 +1058,40 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),1408@@ -340,79 +1057,40 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
1456 > ~grub_cpu_to_le32 (archs[i].size)1409 > ~grub_cpu_to_le32 (archs[i].size)
1457 || grub_cpu_to_le32 (archs[i].offset)1410 || grub_cpu_to_le32 (archs[i].offset)
1458 + grub_cpu_to_le32 (archs[i].size)1411 + grub_cpu_to_le32 (archs[i].size)
@@ -1547,7 +1500,7 @@ index 2bd80f4..9e301f2 100644
1547 if (dev)1500 if (dev)
1548 grub_device_close (dev);1501 grub_device_close (dev);
1549 1502
1550@@ -424,6 +1103,9 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),1503@@ -424,6 +1102,9 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
1551 if (address)1504 if (address)
1552 efi_call_2 (b->free_pages, address, pages);1505 efi_call_2 (b->free_pages, address, pages);
1553 1506
@@ -1558,7 +1511,7 @@ index 2bd80f4..9e301f2 100644
1558 1511
1559 return grub_errno;1512 return grub_errno;
1560diff --git a/grub-core/loader/efi/fdt.c b/grub-core/loader/efi/fdt.c1513diff --git a/grub-core/loader/efi/fdt.c b/grub-core/loader/efi/fdt.c
1561index c86f283..7858d35 1006441514index 771d455..971e84d 100644
1562--- a/grub-core/loader/efi/fdt.c1515--- a/grub-core/loader/efi/fdt.c
1563+++ b/grub-core/loader/efi/fdt.c1516+++ b/grub-core/loader/efi/fdt.c
1564@@ -26,6 +26,7 @@1517@@ -26,6 +26,7 @@
@@ -1570,10 +1523,58 @@ index c86f283..7858d35 100644
1570 static void *loaded_fdt;1523 static void *loaded_fdt;
1571 static void *fdt;1524 static void *fdt;
1572diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c1525diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c
1526index 3292cab..d81e7be 100644
1527--- a/grub-core/loader/efi/linux.c
1528+++ b/grub-core/loader/efi/linux.c
1529@@ -27,6 +27,7 @@
1530 #include <grub/types.h>
1531 #include <grub/cpu/linux.h>
1532 #include <grub/efi/efi.h>
1533+#include <grub/efi/linux.h>
1534 #include <grub/efi/fdtload.h>
1535 #include <grub/efi/memory.h>
1536 #include <grub/efi/pe32.h>
1537@@ -54,6 +55,13 @@ static int initrd_use_loadfile2;
1538 static grub_efi_guid_t load_file2_guid = GRUB_EFI_LOAD_FILE2_PROTOCOL_GUID;
1539 static grub_efi_guid_t device_path_guid = GRUB_EFI_DEVICE_PATH_GUID;
1540
1541+struct grub_arm64_linux_pe_header
1542+{
1543+ grub_uint32_t magic;
1544+ struct grub_pe32_coff_header coff;
1545+ struct grub_pe64_optional_header opt;
1546+};
1547+
1548 grub_err_t
1549 grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh)
1550 {
1551@@ -404,6 +412,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
1552 grub_file_t file = 0;
1553 struct linux_arch_kernel_header lh;
1554 grub_err_t err;
1555+ int rc;
1556
1557 grub_dl_ref (my_mod);
1558
1559@@ -448,6 +457,13 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
1560
1561 grub_dprintf ("linux", "kernel @ %p\n", kernel_addr);
1562
1563+ rc = grub_linuxefi_secure_validate (kernel_addr, kernel_size);
1564+ if (rc < 0)
1565+ {
1566+ grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"), argv[0]);
1567+ goto fail;
1568+ }
1569+
1570 cmdline_size = grub_loader_cmdline_size (argc, argv) + sizeof (LINUX_IMAGE);
1571 linux_args = grub_malloc (cmdline_size);
1572 if (!linux_args)
1573diff --git a/grub-core/loader/efi/linux_sb.c b/grub-core/loader/efi/linux_sb.c
1573new file mode 1006441574new file mode 100644
1574index 0000000..e372b261575index 0000000..e372b26
1575--- /dev/null1576--- /dev/null
1576+++ b/grub-core/loader/efi/linux.c1577+++ b/grub-core/loader/efi/linux_sb.c
1577@@ -0,0 +1,86 @@1578@@ -0,0 +1,86 @@
1578+/*1579+/*
1579+ * GRUB -- GRand Unified Bootloader1580+ * GRUB -- GRand Unified Bootloader
@@ -2082,7 +2083,7 @@ index 0000000..382ff52
2082+ grub_unregister_command (cmd_initrd);2083+ grub_unregister_command (cmd_initrd);
2083+}2084+}
2084diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c2085diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c
2085index 9f74a96..d55b7cd 1006442086index f30a158..b6c13d7 100644
2086--- a/grub-core/loader/i386/linux.c2087--- a/grub-core/loader/i386/linux.c
2087+++ b/grub-core/loader/i386/linux.c2088+++ b/grub-core/loader/i386/linux.c
2088@@ -78,6 +78,8 @@ static grub_size_t maximal_cmdline_size;2089@@ -78,6 +78,8 @@ static grub_size_t maximal_cmdline_size;
@@ -2243,7 +2244,7 @@ index 9f74a96..d55b7cd 100644
2243 {2244 {
2244 grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));2245 grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
2245diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c2246diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c
2246index 2a29952..f4ab6ad 1006442247index efeeeb2..69db786 100644
2247--- a/grub-core/loader/i386/pc/linux.c2248--- a/grub-core/loader/i386/pc/linux.c
2248+++ b/grub-core/loader/i386/pc/linux.c2249+++ b/grub-core/loader/i386/pc/linux.c
2249@@ -36,6 +36,7 @@2250@@ -36,6 +36,7 @@
@@ -2420,7 +2421,7 @@ index 1c0cf6a..c5ba84c 100644
2420 grub_unregister_command (cmd_resume);2421 grub_unregister_command (cmd_resume);
2421 #endif2422 #endif
2422diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h2423diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h
2423index 7e22b4a..6785b78 1006442424index effd870..9efd37a 100644
2424--- a/include/grub/arm64/linux.h2425--- a/include/grub/arm64/linux.h
2425+++ b/include/grub/arm64/linux.h2426+++ b/include/grub/arm64/linux.h
2426@@ -22,6 +22,8 @@2427@@ -22,6 +22,8 @@
diff --git a/debian/patches/vt-handoff.patch b/debian/patches/vt-handoff.patch
index 94f8f4f..78c15da 100644
--- a/debian/patches/vt-handoff.patch
+++ b/debian/patches/vt-handoff.patch
@@ -17,10 +17,10 @@ Patch-Name: vt-handoff.patch
17 2 files changed, 38 insertions(+), 1 deletion(-)17 2 files changed, 38 insertions(+), 1 deletion(-)
1818
19diff --git a/configure.ac b/configure.ac19diff --git a/configure.ac b/configure.ac
20index 947fd52..e11df6b 10064420index 3203749..b4e33a6 100644
21--- a/configure.ac21--- a/configure.ac
22+++ b/configure.ac22+++ b/configure.ac
23@@ -1948,6 +1948,17 @@ else23@@ -1956,6 +1956,17 @@ else
24 fi24 fi
25 AC_SUBST([GFXPAYLOAD_DYNAMIC])25 AC_SUBST([GFXPAYLOAD_DYNAMIC])
26 26
diff --git a/debian/postinst.in b/debian/postinst.in
index 5a64439..98020ab 100644
--- a/debian/postinst.in
+++ b/debian/postinst.in
@@ -759,7 +759,7 @@ case "$1" in
759 fi759 fi
760 ;;760 ;;
761761
762 grub-efi-ia32|grub-efi-amd64|grub-efi-ia64|grub-efi-arm|grub-efi-arm64)762 grub-efi-ia32|grub-efi-amd64|grub-efi-ia64|grub-efi-arm|grub-efi-arm64|grub-efi-riscv64)
763 bootloader_id="$(config_item GRUB_DISTRIBUTOR | tr A-Z a-z | \763 bootloader_id="$(config_item GRUB_DISTRIBUTOR | tr A-Z a-z | \
764 cut -d' ' -f1)"764 cut -d' ' -f1)"
765 case $bootloader_id in765 case $bootloader_id in
@@ -787,6 +787,7 @@ case "$1" in
787 grub-efi-ia64) target=ia64-efi ;;787 grub-efi-ia64) target=ia64-efi ;;
788 grub-efi-arm) target=arm-efi ;;788 grub-efi-arm) target=arm-efi ;;
789 grub-efi-arm64) target=arm64-efi ;;789 grub-efi-arm64) target=arm64-efi ;;
790 grub-efi-riscv64) target=riscv64-efi ;;
790 esac791 esac
791 # Check /boot/grub to see if we previously installed to an ESP. We don't792 # Check /boot/grub to see if we previously installed to an ESP. We don't
792 # want to trigger the install code just by installing the package,793 # want to trigger the install code just by installing the package,
diff --git a/debian/rules b/debian/rules
index 9505998..90678d2 100755
--- a/debian/rules
+++ b/debian/rules
@@ -66,7 +66,7 @@ BUILD_PACKAGES := $(strip $(shell dh_listpackages))
66# REAL_PACKAGES build an actual grub variant (and therefore have both configure66# REAL_PACKAGES build an actual grub variant (and therefore have both configure
67# and build stages). EXTRA_PACKAGES do not build grub but may depend on a67# and build stages). EXTRA_PACKAGES do not build grub but may depend on a
68# REAL_PACKAGE (and therefore only have a build stage)68# REAL_PACKAGE (and therefore only have a build stage)
69REAL_PACKAGES = grub-common grub-emu grub-pc grub-coreboot grub-efi-ia32 grub-efi-amd64 grub-efi-ia64 grub-efi-arm grub-efi-arm64 grub-ieee1275 grub-firmware-qemu grub-uboot grub-xen grub-yeeloong69REAL_PACKAGES = grub-common grub-emu grub-pc grub-coreboot grub-efi-ia32 grub-efi-amd64 grub-efi-ia64 grub-efi-arm grub-efi-arm64 grub-efi-riscv64 grub-ieee1275 grub-firmware-qemu grub-uboot grub-xen grub-yeeloong
70EXTRA_PACKAGES = grub-rescue-pc grub-xen-host70EXTRA_PACKAGES = grub-rescue-pc grub-xen-host
7171
72ifneq (,$(filter amd64,$(DEB_HOST_ARCH_CPU)))72ifneq (,$(filter amd64,$(DEB_HOST_ARCH_CPU)))
@@ -85,6 +85,8 @@ else ifeq (arm,$(DEB_HOST_ARCH_CPU))
85COMMON_PLATFORM := uboot85COMMON_PLATFORM := uboot
86else ifeq (arm64,$(DEB_HOST_ARCH_CPU))86else ifeq (arm64,$(DEB_HOST_ARCH_CPU))
87COMMON_PLATFORM := efi-arm6487COMMON_PLATFORM := efi-arm64
88else ifeq (riscv64,$(DEB_HOST_ARCH_CPU))
89COMMON_PLATFORM := efi-riscv64
88else90else
89COMMON_PLATFORM := none91COMMON_PLATFORM := none
90BUILD_PACKAGES += grub-none92BUILD_PACKAGES += grub-none
@@ -95,6 +97,8 @@ DEFAULT_CMDLINE := quiet splash
95DEFAULT_TIMEOUT := 1097DEFAULT_TIMEOUT := 10
96ifeq ($(DEB_HOST_ARCH_CPU),ppc64el)98ifeq ($(DEB_HOST_ARCH_CPU),ppc64el)
97FLICKER_FREE_BOOT := no99FLICKER_FREE_BOOT := no
100else ifeq ($(DEB_HOST_ARCH_CPU),riscv64)
101FLICKER_FREE_BOOT := no
98else102else
99FLICKER_FREE_BOOT := yes103FLICKER_FREE_BOOT := yes
100endif104endif
@@ -263,7 +267,7 @@ debian/stamps/configure-grub-efi-amd64:
263 mkdir -p debian/stamps $(subst debian/stamps/configure-,obj/,$@)267 mkdir -p debian/stamps $(subst debian/stamps/configure-,obj/,$@)
264 dh_auto_configure -- $(confflags) --with-platform=efi --target=amd64-pe --program-prefix=""268 dh_auto_configure -- $(confflags) --with-platform=efi --target=amd64-pe --program-prefix=""
265 touch $@269 touch $@
266debian/stamps/configure-grub-efi-ia64 debian/stamps/configure-grub-efi-arm debian/stamps/configure-grub-efi-arm64:270debian/stamps/configure-grub-efi-ia64 debian/stamps/configure-grub-efi-arm debian/stamps/configure-grub-efi-arm64 debian/stamps/configure-grub-efi-riscv64:
267 mkdir -p debian/stamps $(subst debian/stamps/configure-,obj/,$@)271 mkdir -p debian/stamps $(subst debian/stamps/configure-,obj/,$@)
268 dh_auto_configure -- $(confflags) --with-platform=efi272 dh_auto_configure -- $(confflags) --with-platform=efi
269 touch $@273 touch $@
@@ -284,7 +288,7 @@ debian/stamps/configure-grub-firmware-qemu:
284 dh_auto_configure -- $(confflags) --with-platform=qemu288 dh_auto_configure -- $(confflags) --with-platform=qemu
285 touch $@289 touch $@
286290
287debian/stamps/build-grub-none debian/stamps/build-grub-efi-ia64 debian/stamps/build-grub-efi-arm debian/stamps/build-grub-coreboot debian/stamps/build-grub-emu debian/stamps/build-grub-uboot debian/stamps/build-grub-xen-i386 debian/stamps/build-grub-xen-amd64 debian/stamps/build-grub-xen-pvh-i386 debian/stamps/build-grub-yeeloong: debian/stamps/build-%: debian/stamps/configure-%291debian/stamps/build-grub-none debian/stamps/build-grub-efi-ia64 debian/stamps/build-grub-efi-arm debian/stamps/build-grub-efi-riscv64 debian/stamps/build-grub-coreboot debian/stamps/build-grub-emu debian/stamps/build-grub-uboot debian/stamps/build-grub-xen-i386 debian/stamps/build-grub-xen-amd64 debian/stamps/build-grub-xen-pvh-i386 debian/stamps/build-grub-yeeloong: debian/stamps/build-%: debian/stamps/configure-%
288 dh_auto_build292 dh_auto_build
289 touch $@293 touch $@
290294
@@ -426,7 +430,7 @@ install/grub-none:
426 # files.430 # files.
427 mkdir -p debian/tmp-$(package)/usr/share/locale431 mkdir -p debian/tmp-$(package)/usr/share/locale
428432
429install/grub-pc install/grub-efi-ia32 install/grub-efi-amd64 install/grub-efi-ia64 install/grub-efi-arm install/grub-efi-arm64 install/grub-ieee1275 install/grub-coreboot install/grub-emu install/grub-uboot install/grub-xen install/grub-yeeloong:433install/grub-pc install/grub-efi-ia32 install/grub-efi-amd64 install/grub-efi-ia64 install/grub-efi-arm install/grub-efi-arm64 install/grub-efi-riscv64 install/grub-ieee1275 install/grub-coreboot install/grub-emu install/grub-uboot install/grub-xen install/grub-yeeloong:
430 set -e ; \434 set -e ; \
431 if [ "$@" = "install/grub-xen" ] ; then \435 if [ "$@" = "install/grub-xen" ] ; then \
432 dh_auto_install -Bobj/grub-xen-i386 --destdir=debian/tmp-$(package); \436 dh_auto_install -Bobj/grub-xen-i386 --destdir=debian/tmp-$(package); \
@@ -571,7 +575,7 @@ endif
571575
572NON_PLATFORM_PACKAGES = $(filter grub2 grub-linuxbios grub-efi grub-rescue-pc grub-firmware-qemu grub-xen-host,$(BUILD_PACKAGES))576NON_PLATFORM_PACKAGES = $(filter grub2 grub-linuxbios grub-efi grub-rescue-pc grub-firmware-qemu grub-xen-host,$(BUILD_PACKAGES))
573COMMON_PLATFORM_PACKAGES = $(filter grub-common grub2-common grub-theme-starfield grub-mount-udeb,$(BUILD_PACKAGES))577COMMON_PLATFORM_PACKAGES = $(filter grub-common grub2-common grub-theme-starfield grub-mount-udeb,$(BUILD_PACKAGES))
574PLATFORM_PACKAGES = $(filter grub-pc grub-efi-ia32 grub-efi-amd64 grub-efi-ia64 grub-efi-arm grub-efi-arm64 grub-ieee1275 grub-coreboot grub-uboot grub-xen grub-yeeloong,$(BUILD_PACKAGES))578PLATFORM_PACKAGES = $(filter grub-pc grub-efi-ia32 grub-efi-amd64 grub-efi-ia64 grub-efi-arm grub-efi-arm64 grub-efi-riscv64 grub-ieee1275 grub-coreboot grub-uboot grub-xen grub-yeeloong,$(BUILD_PACKAGES))
575579
576override_dh_install:580override_dh_install:
577ifneq (,$(NON_PLATFORM_PACKAGES))581ifneq (,$(NON_PLATFORM_PACKAGES))

Subscribers

People subscribed via source and target branches