Merge ~xypron/grub:riscv into ~ubuntu-core-dev/grub/+git/ubuntu:ubuntu
- Git
- lp:~xypron/grub
- riscv
- Merge into 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 |
Related bugs: |
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:/
Description of the change
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
1 | diff --git a/debian/control b/debian/control | |||
2 | index cdcb96f..f88631f 100644 | |||
3 | --- a/debian/control | |||
4 | +++ b/debian/control | |||
5 | @@ -34,8 +34,8 @@ Build-Depends: debhelper-compat (= 10), | |||
6 | 34 | libparted-dev [any-powerpc any-ppc64 any-ppc64el], | 34 | libparted-dev [any-powerpc any-ppc64 any-ppc64el], |
7 | 35 | pkg-config, | 35 | pkg-config, |
8 | 36 | bash-completion, | 36 | bash-completion, |
11 | 37 | libefiboot-dev [i386 amd64 ia64 x32 armel armhf arm64], | 37 | libefiboot-dev [i386 amd64 ia64 x32 armel armhf arm64 riscv64], |
12 | 38 | libefivar-dev [i386 amd64 ia64 x32 armel armhf arm64], | 38 | libefivar-dev [i386 amd64 ia64 x32 armel armhf arm64 riscv64], |
13 | 39 | Build-Conflicts: autoconf2.13, libzfs-dev, libnvpair-dev | 39 | Build-Conflicts: autoconf2.13, libzfs-dev, libnvpair-dev |
14 | 40 | Standards-Version: 3.9.6 | 40 | Standards-Version: 3.9.6 |
15 | 41 | Homepage: https://www.gnu.org/software/grub/ | 41 | Homepage: https://www.gnu.org/software/grub/ |
16 | @@ -63,9 +63,9 @@ Description: GRand Unified Bootloader, version 2 (dummy package) | |||
17 | 63 | This is a dummy transitional package that depends on grub-coreboot. | 63 | This is a dummy transitional package that depends on grub-coreboot. |
18 | 64 | 64 | ||
19 | 65 | Package: grub-efi | 65 | Package: grub-efi |
21 | 66 | Architecture: any-i386 any-amd64 any-arm64 any-ia64 any-arm | 66 | Architecture: any-i386 any-amd64 any-arm64 any-ia64 any-arm any-riscv64 |
22 | 67 | Pre-Depends: ${misc:Pre-Depends} | 67 | Pre-Depends: ${misc:Pre-Depends} |
24 | 68 | Depends: ${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] | 68 | Depends: ${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] |
25 | 69 | Multi-Arch: foreign | 69 | Multi-Arch: foreign |
26 | 70 | Description: GRand Unified Bootloader, version 2 (dummy package) | 70 | Description: GRand Unified Bootloader, version 2 (dummy package) |
27 | 71 | This is a dummy package that depends on the grub-efi-$ARCH package most likely | 71 | This is a dummy package that depends on the grub-efi-$ARCH package most likely |
28 | @@ -77,7 +77,7 @@ Built-Using: ${Built-Using} | |||
29 | 77 | Depends: ${shlibs:Depends}, ${misc:Depends}, gettext-base, ${lsb-base-depends} | 77 | Depends: ${shlibs:Depends}, ${misc:Depends}, gettext-base, ${lsb-base-depends} |
30 | 78 | Replaces: 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 | 78 | Replaces: 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 |
31 | 79 | Recommends: os-prober (>= 1.33) | 79 | Recommends: os-prober (>= 1.33) |
33 | 80 | Suggests: 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-setup | 80 | Suggests: 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 |
34 | 81 | Conflicts: init-select | 81 | Conflicts: init-select |
35 | 82 | # mdadm: See bugs #435983 and #455746 | 82 | # mdadm: See bugs #435983 and #455746 |
36 | 83 | Breaks: mdadm (<< 2.6.7-2), lupin-support (<< 0.55), friendly-recovery (<< 0.2.13), apport (<< 2.1.1) | 83 | Breaks: mdadm (<< 2.6.7-2), lupin-support (<< 0.55), friendly-recovery (<< 0.2.13), apport (<< 2.1.1) |
37 | @@ -94,7 +94,7 @@ Package: grub2-common | |||
38 | 94 | # Not Architecture: any because this package contains some things which are | 94 | # Not Architecture: any because this package contains some things which are |
39 | 95 | # only built when there is a real platform (e.g. grub-install), and the rest | 95 | # only built when there is a real platform (e.g. grub-install), and the rest |
40 | 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. |
42 | 97 | Architecture: any-i386 any-amd64 any-powerpc any-ppc64 any-ppc64el any-sparc any-sparc64 any-mipsel any-ia64 any-arm any-arm64 | 97 | Architecture: any-i386 any-amd64 any-powerpc any-ppc64 any-ppc64el any-sparc any-sparc64 any-mipsel any-ia64 any-arm any-arm64 any-riscv64 |
43 | 98 | Depends: grub-common (= ${binary:Version}), dpkg (>= 1.15.4) | install-info, ${shlibs:Depends}, ${misc:Depends} | 98 | Depends: grub-common (= ${binary:Version}), dpkg (>= 1.15.4) | install-info, ${shlibs:Depends}, ${misc:Depends} |
44 | 99 | Replaces: 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) | 99 | Replaces: 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) |
45 | 100 | Conflicts: grub-legacy | 100 | Conflicts: grub-legacy |
46 | @@ -526,6 +526,56 @@ Description: GRand Unified Bootloader, version 2 (ARM64 UEFI signing template) | |||
47 | 526 | This package contains template files for grub-efi-arm64-signed. | 526 | This package contains template files for grub-efi-arm64-signed. |
48 | 527 | This is only needed for Secure Boot signing. | 527 | This is only needed for Secure Boot signing. |
49 | 528 | 528 | ||
50 | 529 | Package: grub-efi-riscv64-bin | ||
51 | 530 | Architecture: any-riscv64 | ||
52 | 531 | Depends: ${shlibs:Depends}, ${misc:Depends}, grub-common (>= 2.02~beta2-9) | ||
53 | 532 | Recommends: efibootmgr [linux-any] | ||
54 | 533 | Multi-Arch: foreign | ||
55 | 534 | XB-Efi-Vendor: ${efi:Vendor} | ||
56 | 535 | Description: GRand Unified Bootloader, version 2 (riscv64 UEFI modules) | ||
57 | 536 | GRUB is a portable, powerful bootloader. This version of GRUB is based on a | ||
58 | 537 | cleaner design than its predecessors, and provides the following new features: | ||
59 | 538 | . | ||
60 | 539 | - Scripting in grub.cfg using BASH-like syntax. | ||
61 | 540 | - Support for modern partition maps such as GPT. | ||
62 | 541 | - Modular generation of grub.cfg via update-grub. Packages providing GRUB | ||
63 | 542 | add-ons can plug in their own script rules and trigger updates by invoking | ||
64 | 543 | update-grub. | ||
65 | 544 | . | ||
66 | 545 | This package contains GRUB modules that have been built for use on riscv64 | ||
67 | 546 | systems with UEFI. It can be installed in parallel with other flavours, | ||
68 | 547 | but will not automatically install GRUB as the active boot loader nor | ||
69 | 548 | automatically update grub.cfg on upgrade unless grub-efi-riscv64 is also | ||
70 | 549 | installed. | ||
71 | 550 | |||
72 | 551 | Package: grub-efi-riscv64-dbg | ||
73 | 552 | Section: debug | ||
74 | 553 | Architecture: any-riscv64 | ||
75 | 554 | Depends: ${misc:Depends}, grub-efi-riscv64-bin (= ${binary:Version}) | ||
76 | 555 | Multi-Arch: foreign | ||
77 | 556 | Description: GRand Unified Bootloader, version 2 (riscv64 UEFI debug files) | ||
78 | 557 | This package contains debugging files for grub-efi-riscv64-bin. You only | ||
79 | 558 | need these if you are trying to debug GRUB using its GDB stub. | ||
80 | 559 | |||
81 | 560 | Package: grub-efi-riscv64 | ||
82 | 561 | Architecture: any-riscv64 | ||
83 | 562 | Pre-Depends: ${misc:Pre-Depends} | ||
84 | 563 | Depends: ${shlibs:Depends}, ${misc:Depends}, grub2-common (>= 2.02~beta2-9), grub-efi-riscv64-bin (= ${binary:Version}), ucf | ||
85 | 564 | Multi-Arch: foreign | ||
86 | 565 | Description: GRand Unified Bootloader, version 2 (riscv64 UEFI version) | ||
87 | 566 | GRUB is a portable, powerful bootloader. This version of GRUB is based on a | ||
88 | 567 | cleaner design than its predecessors, and provides the following new features: | ||
89 | 568 | . | ||
90 | 569 | - Scripting in grub.cfg using BASH-like syntax. | ||
91 | 570 | - Support for modern partition maps such as GPT. | ||
92 | 571 | - Modular generation of grub.cfg via update-grub. Packages providing GRUB | ||
93 | 572 | add-ons can plug in their own script rules and trigger updates by invoking | ||
94 | 573 | update-grub. | ||
95 | 574 | . | ||
96 | 575 | This is a dependency package for a version of GRUB that has been built for | ||
97 | 576 | use on RISC-V 64-bit systems with UEFI. Installing this package indicates that | ||
98 | 577 | this version of GRUB should be the active boot loader. | ||
99 | 578 | |||
100 | 529 | Package: grub-ieee1275-bin | 579 | Package: grub-ieee1275-bin |
101 | 530 | Architecture: any-i386 any-amd64 any-powerpc any-ppc64 any-ppc64el any-sparc any-sparc64 | 580 | Architecture: any-i386 any-amd64 any-powerpc any-ppc64 any-ppc64el any-sparc any-sparc64 |
102 | 531 | Depends: ${shlibs:Depends}, ${misc:Depends}, grub-common (= ${binary:Version}) | 581 | Depends: ${shlibs:Depends}, ${misc:Depends}, grub-common (= ${binary:Version}) |
103 | @@ -765,7 +815,7 @@ Description: GRand Unified Bootloader, version 2 (Yeeloong version) | |||
104 | 765 | Package: grub-theme-starfield | 815 | Package: grub-theme-starfield |
105 | 766 | # Could be Architecture: any, but in practice this package is useless in a | 816 | # Could be Architecture: any, but in practice this package is useless in a |
106 | 767 | # utilities-only build. | 817 | # utilities-only build. |
108 | 768 | Architecture: any-i386 any-amd64 any-powerpc any-ppc64 any-ppc64el any-sparc any-sparc64 any-mipsel any-ia64 any-arm any-arm64 | 818 | Architecture: any-i386 any-amd64 any-powerpc any-ppc64 any-ppc64el any-sparc any-sparc64 any-mipsel any-ia64 any-arm any-arm64 any-riscv64 |
109 | 769 | Depends: ${misc:Depends}, grub-common (= ${binary:Version}) | 819 | Depends: ${misc:Depends}, grub-common (= ${binary:Version}) |
110 | 770 | Multi-Arch: foreign | 820 | Multi-Arch: foreign |
111 | 771 | Description: GRand Unified Bootloader, version 2 (starfield theme) | 821 | Description: GRand Unified Bootloader, version 2 (starfield theme) |
112 | 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 | |||
113 | index 53b5557..c225492 100644 | |||
114 | --- a/debian/patches/0076-ubuntu-Make-the-linux-command-in-EFI-grub-always-try.patch | |||
115 | +++ b/debian/patches/0076-ubuntu-Make-the-linux-command-in-EFI-grub-always-try.patch | |||
116 | @@ -50,7 +50,7 @@ index 382ff52..9241fed 100644 | |||
117 | 50 | 50 | ||
118 | 51 | params = grub_efi_allocate_pages_max (0x3fffffff, | 51 | params = grub_efi_allocate_pages_max (0x3fffffff, |
119 | 52 | diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c | 52 | diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c |
121 | 53 | index d55b7cd..1649342 100644 | 53 | index b6c13d7..e764e2a 100644 |
122 | 54 | --- a/grub-core/loader/i386/linux.c | 54 | --- a/grub-core/loader/i386/linux.c |
123 | 55 | +++ b/grub-core/loader/i386/linux.c | 55 | +++ b/grub-core/loader/i386/linux.c |
124 | 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)), |
125 | 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 | |||
126 | index 433780e..360e21c 100644 | |||
127 | --- a/debian/patches/0096-linuxefi-fail-kernel-validation-without-shim-protoco.patch | |||
128 | +++ b/debian/patches/0096-linuxefi-fail-kernel-validation-without-shim-protoco.patch | |||
129 | @@ -12,16 +12,28 @@ CVE-2020-15705 | |||
130 | 12 | Reported-by: Mathieu Trudel-Lapierre <cyphermox@ubuntu.com> | 12 | Reported-by: Mathieu Trudel-Lapierre <cyphermox@ubuntu.com> |
131 | 13 | Signed-off-by: Dimitri John Ledkov <xnox@ubuntu.com> | 13 | Signed-off-by: Dimitri John Ledkov <xnox@ubuntu.com> |
132 | 14 | --- | 14 | --- |
133 | 15 | grub-core/loader/arm64/linux.c | 13 +++++++++---- | ||
134 | 16 | grub-core/loader/efi/chainloader.c | 1 + | 15 | grub-core/loader/efi/chainloader.c | 1 + |
136 | 17 | grub-core/loader/efi/linux.c | 1 + | 16 | grub-core/loader/efi/linux.c | 13 +++++++++---- |
137 | 17 | grub-core/loader/efi/linux_sb.c | 1 + | ||
138 | 18 | grub-core/loader/i386/efi/linux.c | 2 +- | 18 | grub-core/loader/i386/efi/linux.c | 2 +- |
139 | 19 | 4 files changed, 12 insertions(+), 5 deletions(-) | 19 | 4 files changed, 12 insertions(+), 5 deletions(-) |
140 | 20 | 20 | ||
145 | 21 | diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c | 21 | diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c |
146 | 22 | index 4e9eac3..f60ca2f 100644 | 22 | index 2b74d79..9042603 100644 |
147 | 23 | --- a/grub-core/loader/arm64/linux.c | 23 | --- a/grub-core/loader/efi/chainloader.c |
148 | 24 | +++ b/grub-core/loader/arm64/linux.c | 24 | +++ b/grub-core/loader/efi/chainloader.c |
149 | 25 | @@ -1097,6 +1097,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), | ||
150 | 26 | |||
151 | 27 | return 0; | ||
152 | 28 | } | ||
153 | 29 | + // -1 fall-through to fail | ||
154 | 30 | |||
155 | 31 | grub_file_close (file); | ||
156 | 32 | grub_device_close (dev); | ||
157 | 33 | diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c | ||
158 | 34 | index 93e4cfc..56d6745 100644 | ||
159 | 35 | --- a/grub-core/loader/efi/linux.c | ||
160 | 36 | +++ b/grub-core/loader/efi/linux.c | ||
161 | 25 | @@ -34,6 +34,7 @@ | 37 | @@ -34,6 +34,7 @@ |
162 | 26 | #include <grub/i18n.h> | 38 | #include <grub/i18n.h> |
163 | 27 | #include <grub/lib/cmdline.h> | 39 | #include <grub/lib/cmdline.h> |
164 | @@ -30,7 +42,7 @@ index 4e9eac3..f60ca2f 100644 | |||
165 | 30 | 42 | ||
166 | 31 | GRUB_MOD_LICENSE ("GPLv3+"); | 43 | GRUB_MOD_LICENSE ("GPLv3+"); |
167 | 32 | 44 | ||
169 | 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)), |
170 | 34 | 46 | ||
171 | 35 | grub_dprintf ("linux", "kernel @ %p\n", kernel_addr); | 47 | grub_dprintf ("linux", "kernel @ %p\n", kernel_addr); |
172 | 36 | 48 | ||
173 | @@ -50,22 +62,10 @@ index 4e9eac3..f60ca2f 100644 | |||
174 | 50 | } | 62 | } |
175 | 51 | 63 | ||
176 | 52 | pe = (void *)((unsigned long)kernel_addr + lh.hdr_offset); | 64 | pe = (void *)((unsigned long)kernel_addr + lh.hdr_offset); |
190 | 53 | diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c | 65 | diff --git a/grub-core/loader/efi/linux_sb.c b/grub-core/loader/efi/linux_sb.c |
178 | 54 | index cf76f48..d64c851 100644 | ||
179 | 55 | --- a/grub-core/loader/efi/chainloader.c | ||
180 | 56 | +++ b/grub-core/loader/efi/chainloader.c | ||
181 | 57 | @@ -1098,6 +1098,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)), | ||
182 | 58 | |||
183 | 59 | return 0; | ||
184 | 60 | } | ||
185 | 61 | + // -1 fall-through to fail | ||
186 | 62 | |||
187 | 63 | grub_file_close (file); | ||
188 | 64 | grub_device_close (dev); | ||
189 | 65 | diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c | ||
191 | 66 | index 73a7196..a09479c 100644 | 66 | index 73a7196..a09479c 100644 |
194 | 67 | --- a/grub-core/loader/efi/linux.c | 67 | --- a/grub-core/loader/efi/linux_sb.c |
195 | 68 | +++ b/grub-core/loader/efi/linux.c | 68 | +++ b/grub-core/loader/efi/linux_sb.c |
196 | 69 | @@ -34,6 +34,7 @@ struct grub_efi_shim_lock | 69 | @@ -34,6 +34,7 @@ struct grub_efi_shim_lock |
197 | 70 | }; | 70 | }; |
198 | 71 | typedef struct grub_efi_shim_lock grub_efi_shim_lock_t; | 71 | typedef struct grub_efi_shim_lock grub_efi_shim_lock_t; |
199 | 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 | |||
200 | index 73748a8..defec76 100644 | |||
201 | --- a/debian/patches/0099-chainloader-Avoid-a-double-free-when-validation-fail.patch | |||
202 | +++ b/debian/patches/0099-chainloader-Avoid-a-double-free-when-validation-fail.patch | |||
203 | @@ -7,10 +7,10 @@ Subject: chainloader: Avoid a double free when validation fails | |||
204 | 7 | 1 file changed, 6 insertions(+), 3 deletions(-) | 7 | 1 file changed, 6 insertions(+), 3 deletions(-) |
205 | 8 | 8 | ||
206 | 9 | diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c | 9 | diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c |
208 | 10 | index d64c851..8515f89 100644 | 10 | index 9042603..4a85f41 100644 |
209 | 11 | --- a/grub-core/loader/efi/chainloader.c | 11 | --- a/grub-core/loader/efi/chainloader.c |
210 | 12 | +++ b/grub-core/loader/efi/chainloader.c | 12 | +++ b/grub-core/loader/efi/chainloader.c |
212 | 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)), |
213 | 14 | if (rc > 0) | 14 | if (rc > 0) |
214 | 15 | { | 15 | { |
215 | 16 | grub_file_close (file); | 16 | grub_file_close (file); |
216 | @@ -20,7 +20,7 @@ index d64c851..8515f89 100644 | |||
217 | 20 | grub_loader_set (grub_secureboot_chainloader_boot, | 20 | grub_loader_set (grub_secureboot_chainloader_boot, |
218 | 21 | grub_secureboot_chainloader_unload, 0); | 21 | grub_secureboot_chainloader_unload, 0); |
219 | 22 | return 0; | 22 | return 0; |
221 | 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)), |
222 | 24 | { | 24 | { |
223 | 25 | grub_load_and_start_image(boot_image); | 25 | grub_load_and_start_image(boot_image); |
224 | 26 | grub_file_close (file); | 26 | grub_file_close (file); |
225 | diff --git a/debian/patches/RISC-V-Update-image-header.patch b/debian/patches/RISC-V-Update-image-header.patch | |||
226 | 27 | new file mode 100644 | 27 | new file mode 100644 |
227 | index 0000000..224165a | |||
228 | --- /dev/null | |||
229 | +++ b/debian/patches/RISC-V-Update-image-header.patch | |||
230 | @@ -0,0 +1,84 @@ | |||
231 | 1 | From: Atish Patra <atish.patra@wdc.com> | ||
232 | 2 | Date: Thu, 28 Oct 2021 23:31:19 +0300 | ||
233 | 3 | Subject: RISC-V: Update image header | ||
234 | 4 | |||
235 | 5 | Update the RISC-V Linux kernel image headers as per the current header. | ||
236 | 6 | |||
237 | 7 | Reference: | ||
238 | 8 | <Linux kernel source>/Documentation/riscv/boot-image-header.rst | ||
239 | 9 | |||
240 | 10 | Signed-off-by: Atish Patra <atish.patra@wdc.com> | ||
241 | 11 | Origin: https://lists.gnu.org/archive/html/grub-devel/2021-10/msg00213.html | ||
242 | 12 | --- | ||
243 | 13 | include/grub/riscv32/linux.h | 15 ++++++++------- | ||
244 | 14 | include/grub/riscv64/linux.h | 15 ++++++++------- | ||
245 | 15 | 2 files changed, 16 insertions(+), 14 deletions(-) | ||
246 | 16 | |||
247 | 17 | diff --git a/include/grub/riscv32/linux.h b/include/grub/riscv32/linux.h | ||
248 | 18 | index 512b777..de0dbdc 100644 | ||
249 | 19 | --- a/include/grub/riscv32/linux.h | ||
250 | 20 | +++ b/include/grub/riscv32/linux.h | ||
251 | 21 | @@ -19,20 +19,21 @@ | ||
252 | 22 | #ifndef GRUB_RISCV32_LINUX_HEADER | ||
253 | 23 | #define GRUB_RISCV32_LINUX_HEADER 1 | ||
254 | 24 | |||
255 | 25 | -#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x52534356 /* 'RSCV' */ | ||
256 | 26 | +#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x05435352 /* 'RSC\0x5' */ | ||
257 | 27 | |||
258 | 28 | -/* From linux/Documentation/riscv/booting.txt */ | ||
259 | 29 | +/* From linux/Documentation/riscv/boot-image-header.rst */ | ||
260 | 30 | struct linux_riscv_kernel_header | ||
261 | 31 | { | ||
262 | 32 | grub_uint32_t code0; /* Executable code */ | ||
263 | 33 | grub_uint32_t code1; /* Executable code */ | ||
264 | 34 | - grub_uint64_t text_offset; /* Image load offset */ | ||
265 | 35 | - grub_uint64_t res0; /* reserved */ | ||
266 | 36 | - grub_uint64_t res1; /* reserved */ | ||
267 | 37 | + grub_uint64_t text_offset; /* Image load offset, little endian */ | ||
268 | 38 | + grub_uint64_t image_size; /* Effective Image size, little endian */ | ||
269 | 39 | + grub_uint64_t flags; /* kernel flags, little endian */ | ||
270 | 40 | + grub_uint32_t version; /* Version of this header */ | ||
271 | 41 | + grub_uint32_t res1; /* reserved */ | ||
272 | 42 | grub_uint64_t res2; /* reserved */ | ||
273 | 43 | grub_uint64_t res3; /* reserved */ | ||
274 | 44 | - grub_uint64_t res4; /* reserved */ | ||
275 | 45 | - grub_uint32_t magic; /* Magic number, little endian, "RSCV" */ | ||
276 | 46 | + grub_uint32_t magic; /* Magic number, little endian, "RSC\x05" */ | ||
277 | 47 | grub_uint32_t hdr_offset; /* Offset of PE/COFF header */ | ||
278 | 48 | }; | ||
279 | 49 | |||
280 | 50 | diff --git a/include/grub/riscv64/linux.h b/include/grub/riscv64/linux.h | ||
281 | 51 | index 3630c30..7c28bc9 100644 | ||
282 | 52 | --- a/include/grub/riscv64/linux.h | ||
283 | 53 | +++ b/include/grub/riscv64/linux.h | ||
284 | 54 | @@ -19,22 +19,23 @@ | ||
285 | 55 | #ifndef GRUB_RISCV64_LINUX_HEADER | ||
286 | 56 | #define GRUB_RISCV64_LINUX_HEADER 1 | ||
287 | 57 | |||
288 | 58 | -#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x52534356 /* 'RSCV' */ | ||
289 | 59 | +#define GRUB_LINUX_RISCV_MAGIC_SIGNATURE 0x05435352 /* 'RSC\0x5' */ | ||
290 | 60 | |||
291 | 61 | #define GRUB_EFI_PE_MAGIC 0x5A4D | ||
292 | 62 | |||
293 | 63 | -/* From linux/Documentation/riscv/booting.txt */ | ||
294 | 64 | +/* From linux/Documentation/riscv/boot-image-header.rst */ | ||
295 | 65 | struct linux_riscv_kernel_header | ||
296 | 66 | { | ||
297 | 67 | grub_uint32_t code0; /* Executable code */ | ||
298 | 68 | grub_uint32_t code1; /* Executable code */ | ||
299 | 69 | - grub_uint64_t text_offset; /* Image load offset */ | ||
300 | 70 | - grub_uint64_t res0; /* reserved */ | ||
301 | 71 | - grub_uint64_t res1; /* reserved */ | ||
302 | 72 | + grub_uint64_t text_offset; /* Image load offset, little endian */ | ||
303 | 73 | + grub_uint64_t image_size; /* Effective Image size, little endian */ | ||
304 | 74 | + grub_uint64_t flags; /* kernel flags, little endian */ | ||
305 | 75 | + grub_uint32_t version; /* Version of this header */ | ||
306 | 76 | + grub_uint32_t res1; /* reserved */ | ||
307 | 77 | grub_uint64_t res2; /* reserved */ | ||
308 | 78 | grub_uint64_t res3; /* reserved */ | ||
309 | 79 | - grub_uint64_t res4; /* reserved */ | ||
310 | 80 | - grub_uint32_t magic; /* Magic number, little endian, "RSCV" */ | ||
311 | 81 | + grub_uint32_t magic; /* Magic number, little endian, "RSC\x05" */ | ||
312 | 82 | grub_uint32_t hdr_offset; /* Offset of PE/COFF header */ | ||
313 | 83 | }; | ||
314 | 84 | |||
315 | diff --git a/debian/patches/RISC-V-Use-common-linux-loader.patch b/debian/patches/RISC-V-Use-common-linux-loader.patch | |||
316 | 0 | new file mode 100644 | 85 | new file mode 100644 |
317 | index 0000000..de50acc | |||
318 | --- /dev/null | |||
319 | +++ b/debian/patches/RISC-V-Use-common-linux-loader.patch | |||
320 | @@ -0,0 +1,120 @@ | |||
321 | 1 | From: Atish Patra <atish.patra@wdc.com> | ||
322 | 2 | Date: Thu, 28 Oct 2021 23:31:20 +0300 | ||
323 | 3 | Subject: RISC-V: Use common linux loader | ||
324 | 4 | |||
325 | 5 | RISC-V doesn't have to do anything very different from other architectures | ||
326 | 6 | to loader EFI stub linux kernel. As a result, just use the common linux | ||
327 | 7 | loader instead of defining a RISC-V specific linux loader. | ||
328 | 8 | |||
329 | 9 | Signed-off-by: Atish Patra <atish.patra@wdc.com> | ||
330 | 10 | Origin: https://lists.gnu.org/archive/html/grub-devel/2021-10/msg00211.html | ||
331 | 11 | --- | ||
332 | 12 | grub-core/Makefile.core.def | 4 +-- | ||
333 | 13 | grub-core/loader/riscv/linux.c | 59 ------------------------------------------ | ||
334 | 14 | include/grub/riscv32/linux.h | 1 + | ||
335 | 15 | include/grub/riscv64/linux.h | 1 + | ||
336 | 16 | 4 files changed, 4 insertions(+), 61 deletions(-) | ||
337 | 17 | delete mode 100644 grub-core/loader/riscv/linux.c | ||
338 | 18 | |||
339 | 19 | diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def | ||
340 | 20 | index b36cf66..0536575 100644 | ||
341 | 21 | --- a/grub-core/Makefile.core.def | ||
342 | 22 | +++ b/grub-core/Makefile.core.def | ||
343 | 23 | @@ -1809,8 +1809,8 @@ module = { | ||
344 | 24 | arm_efi = loader/efi/linux.c; | ||
345 | 25 | arm_uboot = loader/arm/linux.c; | ||
346 | 26 | arm64 = loader/efi/linux.c; | ||
347 | 27 | - riscv32 = loader/riscv/linux.c; | ||
348 | 28 | - riscv64 = loader/riscv/linux.c; | ||
349 | 29 | + riscv32 = loader/efi/linux.c; | ||
350 | 30 | + riscv64 = loader/efi/linux.c; | ||
351 | 31 | common = loader/linux.c; | ||
352 | 32 | common = lib/cmdline.c; | ||
353 | 33 | enable = noemu; | ||
354 | 34 | diff --git a/grub-core/loader/riscv/linux.c b/grub-core/loader/riscv/linux.c | ||
355 | 35 | deleted file mode 100644 | ||
356 | 36 | index d17c488..0000000 | ||
357 | 37 | --- a/grub-core/loader/riscv/linux.c | ||
358 | 38 | +++ /dev/null | ||
359 | 39 | @@ -1,59 +0,0 @@ | ||
360 | 40 | -/* | ||
361 | 41 | - * GRUB -- GRand Unified Bootloader | ||
362 | 42 | - * Copyright (C) 2018 Free Software Foundation, Inc. | ||
363 | 43 | - * | ||
364 | 44 | - * GRUB is free software: you can redistribute it and/or modify | ||
365 | 45 | - * it under the terms of the GNU General Public License as published by | ||
366 | 46 | - * the Free Software Foundation, either version 3 of the License, or | ||
367 | 47 | - * (at your option) any later version. | ||
368 | 48 | - * | ||
369 | 49 | - * GRUB is distributed in the hope that it will be useful, | ||
370 | 50 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
371 | 51 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
372 | 52 | - * GNU General Public License for more details. | ||
373 | 53 | - * | ||
374 | 54 | - * You should have received a copy of the GNU General Public License | ||
375 | 55 | - * along with GRUB. If not, see <http://www.gnu.org/licenses/>. | ||
376 | 56 | - */ | ||
377 | 57 | - | ||
378 | 58 | -#include <grub/command.h> | ||
379 | 59 | -#include <grub/dl.h> | ||
380 | 60 | -#include <grub/lib/cmdline.h> | ||
381 | 61 | - | ||
382 | 62 | -GRUB_MOD_LICENSE ("GPLv3+"); | ||
383 | 63 | - | ||
384 | 64 | -static grub_err_t | ||
385 | 65 | -grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), | ||
386 | 66 | - int argc __attribute__ ((unused)), | ||
387 | 67 | - char *argv[] __attribute__ ((unused))) | ||
388 | 68 | -{ | ||
389 | 69 | - grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("Linux not supported yet")); | ||
390 | 70 | - | ||
391 | 71 | - return grub_errno; | ||
392 | 72 | -} | ||
393 | 73 | - | ||
394 | 74 | -static grub_err_t | ||
395 | 75 | -grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), | ||
396 | 76 | - int argc __attribute__ ((unused)), | ||
397 | 77 | - char *argv[] __attribute__ ((unused))) | ||
398 | 78 | -{ | ||
399 | 79 | - grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, N_("Linux not supported yet")); | ||
400 | 80 | - | ||
401 | 81 | - return grub_errno; | ||
402 | 82 | -} | ||
403 | 83 | - | ||
404 | 84 | -static grub_command_t cmd_linux, cmd_initrd; | ||
405 | 85 | - | ||
406 | 86 | -GRUB_MOD_INIT (linux) | ||
407 | 87 | -{ | ||
408 | 88 | - cmd_linux = grub_register_command ("linux", grub_cmd_linux, 0, | ||
409 | 89 | - N_("Load Linux.")); | ||
410 | 90 | - cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, 0, | ||
411 | 91 | - N_("Load initrd.")); | ||
412 | 92 | -} | ||
413 | 93 | - | ||
414 | 94 | -GRUB_MOD_FINI (linux) | ||
415 | 95 | -{ | ||
416 | 96 | - grub_unregister_command (cmd_linux); | ||
417 | 97 | - grub_unregister_command (cmd_initrd); | ||
418 | 98 | -} | ||
419 | 99 | diff --git a/include/grub/riscv32/linux.h b/include/grub/riscv32/linux.h | ||
420 | 100 | index de0dbdc..706c690 100644 | ||
421 | 101 | --- a/include/grub/riscv32/linux.h | ||
422 | 102 | +++ b/include/grub/riscv32/linux.h | ||
423 | 103 | @@ -38,5 +38,6 @@ struct linux_riscv_kernel_header | ||
424 | 104 | }; | ||
425 | 105 | |||
426 | 106 | #define linux_arch_kernel_header linux_riscv_kernel_header | ||
427 | 107 | +# define GRUB_LINUX_ARCH_MAGIC_SIGNATURE GRUB_LINUX_RISCV_MAGIC_SIGNATURE | ||
428 | 108 | |||
429 | 109 | #endif /* ! GRUB_RISCV32_LINUX_HEADER */ | ||
430 | 110 | diff --git a/include/grub/riscv64/linux.h b/include/grub/riscv64/linux.h | ||
431 | 111 | index 7c28bc9..88d5df7 100644 | ||
432 | 112 | --- a/include/grub/riscv64/linux.h | ||
433 | 113 | +++ b/include/grub/riscv64/linux.h | ||
434 | 114 | @@ -40,5 +40,6 @@ struct linux_riscv_kernel_header | ||
435 | 115 | }; | ||
436 | 116 | |||
437 | 117 | #define linux_arch_kernel_header linux_riscv_kernel_header | ||
438 | 118 | +# define GRUB_LINUX_ARCH_MAGIC_SIGNATURE GRUB_LINUX_RISCV_MAGIC_SIGNATURE | ||
439 | 119 | |||
440 | 120 | #endif /* ! GRUB_RISCV64_LINUX_HEADER */ | ||
441 | diff --git a/debian/patches/dejavu-font-path.patch b/debian/patches/dejavu-font-path.patch | |||
442 | index 18b8376..2d9d197 100644 | |||
443 | --- a/debian/patches/dejavu-font-path.patch | |||
444 | +++ b/debian/patches/dejavu-font-path.patch | |||
445 | @@ -8,10 +8,10 @@ Patch-Name: dejavu-font-path.patch | |||
446 | 8 | 1 file changed, 1 insertion(+), 1 deletion(-) | 8 | 1 file changed, 1 insertion(+), 1 deletion(-) |
447 | 9 | 9 | ||
448 | 10 | diff --git a/configure.ac b/configure.ac | 10 | diff --git a/configure.ac b/configure.ac |
450 | 11 | index b3fb743..22c6cf7 100644 | 11 | index d422626..a29beb9 100644 |
451 | 12 | --- a/configure.ac | 12 | --- a/configure.ac |
452 | 13 | +++ b/configure.ac | 13 | +++ b/configure.ac |
454 | 14 | @@ -1719,7 +1719,7 @@ fi | 14 | @@ -1727,7 +1727,7 @@ fi |
455 | 15 | 15 | ||
456 | 16 | if test x"$starfield_excuse" = x; then | 16 | if test x"$starfield_excuse" = x; then |
457 | 17 | for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz; do | 17 | for ext in pcf pcf.gz bdf bdf.gz ttf ttf.gz; do |
458 | diff --git a/debian/patches/efi-add-definition-of-LoadFile2-protocol.patch b/debian/patches/efi-add-definition-of-LoadFile2-protocol.patch | |||
459 | 18 | new file mode 100644 | 18 | new file mode 100644 |
460 | index 0000000..d2263d3 | |||
461 | --- /dev/null | |||
462 | +++ b/debian/patches/efi-add-definition-of-LoadFile2-protocol.patch | |||
463 | @@ -0,0 +1,61 @@ | |||
464 | 1 | From: Ard Biesheuvel <ard.biesheuvel@arm.com> | ||
465 | 2 | Date: Thu, 28 Oct 2021 23:31:15 +0300 | ||
466 | 3 | Subject: efi: add definition of LoadFile2 protocol | ||
467 | 4 | |||
468 | 5 | Incorporate the EFI_LOAD_FILE2_PROTOCOL GUID and C types from the | ||
469 | 6 | UEFI spec. | ||
470 | 7 | |||
471 | 8 | Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> | ||
472 | 9 | Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de> | ||
473 | 10 | Signed-off-by: Nikita Ermakov <arei@altlinux.org> | ||
474 | 11 | Origin: https://lists.gnu.org/archive/html/grub-devel/2021-10/msg00210.html | ||
475 | 12 | --- | ||
476 | 13 | grub-core/commands/efi/lsefi.c | 1 + | ||
477 | 14 | include/grub/efi/api.h | 15 +++++++++++++++ | ||
478 | 15 | 2 files changed, 16 insertions(+) | ||
479 | 16 | |||
480 | 17 | diff --git a/grub-core/commands/efi/lsefi.c b/grub-core/commands/efi/lsefi.c | ||
481 | 18 | index d1ce99a..4085f5d 100644 | ||
482 | 19 | --- a/grub-core/commands/efi/lsefi.c | ||
483 | 20 | +++ b/grub-core/commands/efi/lsefi.c | ||
484 | 21 | @@ -55,6 +55,7 @@ struct known_protocol | ||
485 | 22 | { GRUB_EFI_ABSOLUTE_POINTER_PROTOCOL_GUID, "absolute pointer" }, | ||
486 | 23 | { GRUB_EFI_DRIVER_BINDING_PROTOCOL_GUID, "EFI driver binding" }, | ||
487 | 24 | { GRUB_EFI_LOAD_FILE_PROTOCOL_GUID, "load file" }, | ||
488 | 25 | + { GRUB_EFI_LOAD_FILE2_PROTOCOL_GUID, "load file2" }, | ||
489 | 26 | { GRUB_EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID, "simple FS" }, | ||
490 | 27 | { GRUB_EFI_TAPE_IO_PROTOCOL_GUID, "tape I/O" }, | ||
491 | 28 | { GRUB_EFI_UNICODE_COLLATION_PROTOCOL_GUID, "unicode collation" }, | ||
492 | 29 | diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h | ||
493 | 30 | index f1a5221..3de0a7d 100644 | ||
494 | 31 | --- a/include/grub/efi/api.h | ||
495 | 32 | +++ b/include/grub/efi/api.h | ||
496 | 33 | @@ -149,6 +149,11 @@ | ||
497 | 34 | { 0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B } \ | ||
498 | 35 | } | ||
499 | 36 | |||
500 | 37 | +#define GRUB_EFI_LOAD_FILE2_PROTOCOL_GUID \ | ||
501 | 38 | + { 0x4006c0c1, 0xfcb3, 0x403e, \ | ||
502 | 39 | + { 0x99, 0x6d, 0x4a, 0x6c, 0x87, 0x24, 0xe0, 0x6d } \ | ||
503 | 40 | + } | ||
504 | 41 | + | ||
505 | 42 | #define GRUB_EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID \ | ||
506 | 43 | { 0x0964e5b22, 0x6459, 0x11d2, \ | ||
507 | 44 | { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } \ | ||
508 | 45 | @@ -1729,6 +1734,16 @@ struct grub_efi_rng_protocol | ||
509 | 46 | }; | ||
510 | 47 | typedef struct grub_efi_rng_protocol grub_efi_rng_protocol_t; | ||
511 | 48 | |||
512 | 49 | +struct grub_efi_load_file2 | ||
513 | 50 | +{ | ||
514 | 51 | + grub_efi_status_t (*load_file)(struct grub_efi_load_file2 *this, | ||
515 | 52 | + grub_efi_device_path_t *file_path, | ||
516 | 53 | + grub_efi_boolean_t boot_policy, | ||
517 | 54 | + grub_efi_uintn_t *buffer_size, | ||
518 | 55 | + void *buffer); | ||
519 | 56 | +}; | ||
520 | 57 | +typedef struct grub_efi_load_file2 grub_efi_load_file2_t; | ||
521 | 58 | + | ||
522 | 59 | #if (GRUB_TARGET_SIZEOF_VOID_P == 4) || defined (__ia64__) \ | ||
523 | 60 | || defined (__aarch64__) || defined (__MINGW64__) || defined (__CYGWIN__) \ | ||
524 | 61 | || defined(__riscv) | ||
525 | diff --git a/debian/patches/efi-correct-struct-grub_efi_boot_services.patch b/debian/patches/efi-correct-struct-grub_efi_boot_services.patch | |||
526 | 0 | new file mode 100644 | 62 | new file mode 100644 |
527 | index 0000000..a4bf2c2 | |||
528 | --- /dev/null | |||
529 | +++ b/debian/patches/efi-correct-struct-grub_efi_boot_services.patch | |||
530 | @@ -0,0 +1,28 @@ | |||
531 | 1 | From: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> | ||
532 | 2 | Date: Sat, 22 Jan 2022 11:11:32 +0100 | ||
533 | 3 | Subject: efi: correct struct grub_efi_boot_services | ||
534 | 4 | |||
535 | 5 | The UEFI specification defines that the EFI_BOOT_SERVICES.Exit(() service | ||
536 | 6 | may return EFI_SUCCESS or EFI_INVALID_PARAMETER. So it cannot be | ||
537 | 7 | __attribute__((noreturn)). | ||
538 | 8 | |||
539 | 9 | Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> | ||
540 | 10 | Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com> | ||
541 | 11 | Origin: https://lists.gnu.org/archive/html/grub-devel/2022-01/msg00121.html | ||
542 | 12 | --- | ||
543 | 13 | include/grub/efi/api.h | 2 +- | ||
544 | 14 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
545 | 15 | |||
546 | 16 | diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h | ||
547 | 17 | index 3211f04..c5dd4af 100644 | ||
548 | 18 | --- a/include/grub/efi/api.h | ||
549 | 19 | +++ b/include/grub/efi/api.h | ||
550 | 20 | @@ -1267,7 +1267,7 @@ struct grub_efi_boot_services | ||
551 | 21 | (*exit) (grub_efi_handle_t image_handle, | ||
552 | 22 | grub_efi_status_t exit_status, | ||
553 | 23 | grub_efi_uintn_t exit_data_size, | ||
554 | 24 | - grub_efi_char16_t *exit_data) __attribute__((noreturn)); | ||
555 | 25 | + grub_efi_char16_t *exit_data); | ||
556 | 26 | |||
557 | 27 | grub_efi_status_t | ||
558 | 28 | (*unload_image) (grub_efi_handle_t image_handle); | ||
559 | diff --git a/debian/patches/efi-implement-grub_efi_run_image.patch b/debian/patches/efi-implement-grub_efi_run_image.patch | |||
560 | 0 | new file mode 100644 | 29 | new file mode 100644 |
561 | index 0000000..1ab5ba0 | |||
562 | --- /dev/null | |||
563 | +++ b/debian/patches/efi-implement-grub_efi_run_image.patch | |||
564 | @@ -0,0 +1,898 @@ | |||
565 | 1 | From: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> | ||
566 | 2 | Date: Tue, 18 Jan 2022 11:55:56 +0100 | ||
567 | 3 | Subject: efi: implement grub_efi_run_image | ||
568 | 4 | |||
569 | 5 | Provide function grub_efi_run_image() which consumes a PE-COFF image | ||
570 | 6 | loaded into memory. The function | ||
571 | 7 | |||
572 | 8 | * checks validity of header | ||
573 | 9 | * copies the sections | ||
574 | 10 | * relocates the code | ||
575 | 11 | * invalidates the instruction cache | ||
576 | 12 | * executes the image | ||
577 | 13 | * returns to caller | ||
578 | 14 | |||
579 | 15 | Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> | ||
580 | 16 | --- | ||
581 | 17 | grub-core/Makefile.core.def | 4 + | ||
582 | 18 | grub-core/loader/efi/linux.c | 21 ++ | ||
583 | 19 | grub-core/loader/efi/peimage.c | 765 +++++++++++++++++++++++++++++++++++++++++ | ||
584 | 20 | include/grub/efi/linux.h | 3 + | ||
585 | 21 | include/grub/efi/peimage.h | 28 ++ | ||
586 | 22 | 5 files changed, 821 insertions(+) | ||
587 | 23 | create mode 100644 grub-core/loader/efi/peimage.c | ||
588 | 24 | create mode 100644 include/grub/efi/peimage.h | ||
589 | 25 | |||
590 | 26 | diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def | ||
591 | 27 | index 3b06462..2cfea95 100644 | ||
592 | 28 | --- a/grub-core/Makefile.core.def | ||
593 | 29 | +++ b/grub-core/Makefile.core.def | ||
594 | 30 | @@ -1822,13 +1822,17 @@ module = { | ||
595 | 31 | arm_coreboot = loader/arm/linux.c; | ||
596 | 32 | arm_efi = loader/efi/linux.c; | ||
597 | 33 | arm_efi = loader/efi/linux_sb.c; | ||
598 | 34 | + arm_efi = loader/efi/peimage.c; | ||
599 | 35 | arm_uboot = loader/arm/linux.c; | ||
600 | 36 | arm64 = loader/efi/linux.c; | ||
601 | 37 | arm64 = loader/efi/linux_sb.c; | ||
602 | 38 | + arm64 = loader/efi/peimage.c; | ||
603 | 39 | riscv32 = loader/efi/linux.c; | ||
604 | 40 | riscv32 = loader/efi/linux_sb.c; | ||
605 | 41 | + riscv32 = loader/efi/peimage.c; | ||
606 | 42 | riscv64 = loader/efi/linux.c; | ||
607 | 43 | riscv64 = loader/efi/linux_sb.c; | ||
608 | 44 | + riscv64 = loader/efi/peimage.c; | ||
609 | 45 | cflags = '-Wno-error=cast-align'; | ||
610 | 46 | common = loader/linux.c; | ||
611 | 47 | common = lib/cmdline.c; | ||
612 | 48 | diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c | ||
613 | 49 | index 56d6745..18e7fe2 100644 | ||
614 | 50 | --- a/grub-core/loader/efi/linux.c | ||
615 | 51 | +++ b/grub-core/loader/efi/linux.c | ||
616 | 52 | @@ -190,7 +190,28 @@ grub_arch_efi_linux_boot_image (grub_addr_t addr __attribute__((unused)), | ||
617 | 53 | |||
618 | 54 | grub_dprintf ("linux", "linux command line: '%s'\n", args); | ||
619 | 55 | |||
620 | 56 | +/* | ||
621 | 57 | + * FIXME: | ||
622 | 58 | + * | ||
623 | 59 | + * We know that grub_efi_linux_boot() is broken: | ||
624 | 60 | + * | ||
625 | 61 | + * - The entry point address is not correctly determined. | ||
626 | 62 | + * - Section addresses are ignored. | ||
627 | 63 | + * - Sections having a raw size that is smaller than the virtual size are not | ||
628 | 64 | + * filled up with zeros. | ||
629 | 65 | + * - Relocations are ignored. | ||
630 | 66 | + * - Binaries calling Exit() quit GRUB. | ||
631 | 67 | + * | ||
632 | 68 | + * Thus we expect kernels to fail badly. | ||
633 | 69 | + * | ||
634 | 70 | + * Yet reviewers suggested to only change the code path for RISC-V until a | ||
635 | 71 | + * security audit of the code in grub_efi_run_image() is completed. | ||
636 | 72 | + */ | ||
637 | 73 | +#ifndef __riscv | ||
638 | 74 | retval = grub_efi_linux_boot (kernel_addr, handover_offset, kernel_addr); | ||
639 | 75 | +#else | ||
640 | 76 | + retval = grub_efi_run_image (kernel_addr, kernel_size, linux_args); | ||
641 | 77 | +#endif | ||
642 | 78 | |||
643 | 79 | /* When successful, not reached */ | ||
644 | 80 | free_params(); | ||
645 | 81 | diff --git a/grub-core/loader/efi/peimage.c b/grub-core/loader/efi/peimage.c | ||
646 | 82 | new file mode 100644 | ||
647 | 83 | index 0000000..f9735ab | ||
648 | 84 | --- /dev/null | ||
649 | 85 | +++ b/grub-core/loader/efi/peimage.c | ||
650 | 86 | @@ -0,0 +1,765 @@ | ||
651 | 87 | +// SPDX-License-Identifier: GPL-3.0+ | ||
652 | 88 | + | ||
653 | 89 | +#include <grub/cache.h> | ||
654 | 90 | +#include <grub/cpu/efi/memory.h> | ||
655 | 91 | +#include <grub/efi/efi.h> | ||
656 | 92 | +#include <grub/efi/linux.h> | ||
657 | 93 | +#include <grub/efi/pe32.h> | ||
658 | 94 | +#include <grub/efi/peimage.h> | ||
659 | 95 | +#include <grub/env.h> | ||
660 | 96 | +#include <grub/misc.h> | ||
661 | 97 | +#include <grub/mm.h> | ||
662 | 98 | +#include <grub/setjmp.h> | ||
663 | 99 | + | ||
664 | 100 | +struct image_info { | ||
665 | 101 | + void *data; | ||
666 | 102 | + grub_efi_uint32_t data_size; | ||
667 | 103 | + grub_efi_uint16_t machine; | ||
668 | 104 | + grub_efi_uint16_t num_sections; | ||
669 | 105 | + struct grub_pe32_section_table *section; | ||
670 | 106 | + struct grub_pe32_data_directory *reloc; | ||
671 | 107 | + grub_uint64_t image_base; | ||
672 | 108 | + grub_uint32_t section_alignment; | ||
673 | 109 | + grub_uint32_t image_size; | ||
674 | 110 | + void *alloc_addr; | ||
675 | 111 | + grub_uint32_t alloc_pages; | ||
676 | 112 | + void *image_addr; | ||
677 | 113 | + grub_efi_entry_point entry_point; | ||
678 | 114 | +}; | ||
679 | 115 | + | ||
680 | 116 | +static struct { | ||
681 | 117 | + grub_jmp_buf jmp; | ||
682 | 118 | + grub_efi_handle_t image_handle; | ||
683 | 119 | + grub_efi_status_t exit_status; | ||
684 | 120 | + grub_efi_status_t EFIAPI (*exit)(grub_efi_handle_t image_handle, | ||
685 | 121 | + grub_efi_status_t exit_status, | ||
686 | 122 | + grub_efi_uintn_t exit_data_size, | ||
687 | 123 | + grub_efi_char16_t *exit_data); | ||
688 | 124 | +} started_image; | ||
689 | 125 | + | ||
690 | 126 | +static int | ||
691 | 127 | +debug_enabled(const char *condition) | ||
692 | 128 | +{ | ||
693 | 129 | + const char *debug; | ||
694 | 130 | + | ||
695 | 131 | + debug = grub_env_get ("debug"); | ||
696 | 132 | + if (!debug || !grub_strword(debug, condition)) | ||
697 | 133 | + return 0; | ||
698 | 134 | + | ||
699 | 135 | + return 1; | ||
700 | 136 | +} | ||
701 | 137 | + | ||
702 | 138 | +static void | ||
703 | 139 | +debug(const char *constraint) | ||
704 | 140 | +{ | ||
705 | 141 | + volatile grub_uint64_t x; | ||
706 | 142 | + | ||
707 | 143 | + if (!debug_enabled(constraint)) | ||
708 | 144 | + return; | ||
709 | 145 | + | ||
710 | 146 | + grub_printf("Attach debugger\n"); | ||
711 | 147 | + for (x = 1; x; ++x) | ||
712 | 148 | + ; | ||
713 | 149 | +} | ||
714 | 150 | + | ||
715 | 151 | +__attribute__((unused)) static void | ||
716 | 152 | +dump(const char *text, void *addr, unsigned int size) | ||
717 | 153 | +{ | ||
718 | 154 | + char *pos = addr; | ||
719 | 155 | + | ||
720 | 156 | + grub_printf("%s @ 0x%lx\n", text, (unsigned long)addr); | ||
721 | 157 | + for (unsigned int i = 0; i < size; i += 16) | ||
722 | 158 | + grub_printf("%04x: %02x%02x %02x%02x %02x%02x %02x%02x " | ||
723 | 159 | + "%02x%02x %02x%02x %02x%02x %02x%02x\n", i, | ||
724 | 160 | + pos[i + 0], pos[i + 1], pos[i + 2], pos[i + 3], | ||
725 | 161 | + pos[i + 4], pos[i + 5], pos[i + 6], pos[i + 7], | ||
726 | 162 | + pos[i + 8], pos[i + 9], pos[i + 10], pos[i + 11], | ||
727 | 163 | + pos[i + 12], pos[i + 13], pos[i + 14], pos[i + 15]); | ||
728 | 164 | +} | ||
729 | 165 | + | ||
730 | 166 | +static grub_uint16_t machines[] = { | ||
731 | 167 | +#if defined(__x86_64__) | ||
732 | 168 | + GRUB_PE32_MACHINE_AMD64, | ||
733 | 169 | +#elif defined(__i386__) || defined(__i486__) || defined(__i686__) | ||
734 | 170 | + GRUB_PE32_MACHINE_AMD64, | ||
735 | 171 | + GRUB_PE32_MACHINE_I386, | ||
736 | 172 | +#elif defined(__aarch64__) | ||
737 | 173 | + GRUB_PE32_MACHINE_ARM64, | ||
738 | 174 | +#elif defined(__arm__) | ||
739 | 175 | + GRUB_PE32_MACHINE_ARMTHUMB_MIXED, | ||
740 | 176 | +#elif defined(__riscv) && __riscv_xlen == 32 | ||
741 | 177 | + GRUB_PE32_MACHINE_RISCV32, | ||
742 | 178 | +#elif defined(__riscv) && __riscv_xlen == 64 | ||
743 | 179 | + GRUB_PE32_MACHINE_RISCV64, | ||
744 | 180 | +#endif | ||
745 | 181 | +}; | ||
746 | 182 | + | ||
747 | 183 | +/** | ||
748 | 184 | + * check_machine_type() - check if the machine type matches the architecture | ||
749 | 185 | + * | ||
750 | 186 | + * @machine: the value of the Machine field of the COFF file header. | ||
751 | 187 | + * Return: status code | ||
752 | 188 | + */ | ||
753 | 189 | +static grub_efi_status_t check_machine_type(grub_uint16_t machine) | ||
754 | 190 | +{ | ||
755 | 191 | + for (grub_size_t i = 0; i < sizeof(machines) / sizeof(*machines); ++i) { | ||
756 | 192 | + if (machine == machines[i]) | ||
757 | 193 | + return GRUB_EFI_SUCCESS; | ||
758 | 194 | + } | ||
759 | 195 | + | ||
760 | 196 | + return GRUB_EFI_LOAD_ERROR; | ||
761 | 197 | +} | ||
762 | 198 | + | ||
763 | 199 | +/** | ||
764 | 200 | + * check_pe_header() - check the headers of a PE-COFF image | ||
765 | 201 | + * | ||
766 | 202 | + * @info: information about the image | ||
767 | 203 | + */ | ||
768 | 204 | +static grub_efi_status_t check_pe_header(struct image_info *info) | ||
769 | 205 | +{ | ||
770 | 206 | + struct grub_dos_stub *dos_stub = info->data; | ||
771 | 207 | + void *pe_magic; | ||
772 | 208 | + struct grub_pe32_coff_header *coff_header; | ||
773 | 209 | + struct grub_pe32_optional_header *pe32_header; | ||
774 | 210 | + struct grub_pe64_optional_header *pe64_header; | ||
775 | 211 | + grub_uint32_t header_size; | ||
776 | 212 | + | ||
777 | 213 | + if (info->data_size < sizeof(struct grub_dos_stub)) { | ||
778 | 214 | + grub_error(GRUB_ERR_BAD_OS, "truncated image"); | ||
779 | 215 | + return GRUB_EFI_LOAD_ERROR; | ||
780 | 216 | + } | ||
781 | 217 | + if (dos_stub->magic != GRUB_PE32_MAGIC) { | ||
782 | 218 | + grub_error(GRUB_ERR_BAD_OS, "not a PE-COFF file"); | ||
783 | 219 | + return GRUB_EFI_UNSUPPORTED; | ||
784 | 220 | + } | ||
785 | 221 | + if (info->data_size < dos_stub->pe_addr + sizeof(GRUB_PE_MAGIC) + | ||
786 | 222 | + sizeof(struct grub_pe32_coff_header) + | ||
787 | 223 | + sizeof(struct grub_pe64_optional_header)) { | ||
788 | 224 | + grub_error(GRUB_ERR_BAD_OS, "truncated image"); | ||
789 | 225 | + return GRUB_EFI_LOAD_ERROR; | ||
790 | 226 | + } | ||
791 | 227 | + pe_magic = (void *)((unsigned long)info->data + dos_stub->pe_addr); | ||
792 | 228 | + if (grub_memcmp(pe_magic, GRUB_PE_MAGIC, sizeof(GRUB_PE_MAGIC))) { | ||
793 | 229 | + grub_error(GRUB_ERR_BAD_OS, "not a PE-COFF file"); | ||
794 | 230 | + return GRUB_EFI_LOAD_ERROR; | ||
795 | 231 | + } | ||
796 | 232 | + | ||
797 | 233 | + coff_header = (void *)((unsigned long)pe_magic + sizeof(GRUB_PE_MAGIC)); | ||
798 | 234 | + info->machine = coff_header->machine; | ||
799 | 235 | + info->num_sections = coff_header->num_sections; | ||
800 | 236 | + | ||
801 | 237 | + if (check_machine_type(info->machine) != GRUB_EFI_SUCCESS) { | ||
802 | 238 | + grub_error(GRUB_ERR_BAD_OS, "wrong machine type %u", | ||
803 | 239 | + coff_header->machine); | ||
804 | 240 | + return GRUB_EFI_LOAD_ERROR; | ||
805 | 241 | + } | ||
806 | 242 | + | ||
807 | 243 | + pe32_header = (void *)((unsigned long)coff_header + | ||
808 | 244 | + sizeof(*coff_header)); | ||
809 | 245 | + pe64_header = (void *)((unsigned long)coff_header + | ||
810 | 246 | + sizeof(*coff_header)); | ||
811 | 247 | + | ||
812 | 248 | + switch (pe32_header->magic) { | ||
813 | 249 | + case GRUB_PE32_PE32_MAGIC: | ||
814 | 250 | + info->section_alignment = pe32_header->section_alignment; | ||
815 | 251 | + info->image_base = pe32_header->image_base; | ||
816 | 252 | + info->image_size = pe32_header->image_size; | ||
817 | 253 | + info->entry_point = | ||
818 | 254 | + (void *)(unsigned long)pe32_header->entry_addr; | ||
819 | 255 | + header_size = pe32_header->header_size; | ||
820 | 256 | + if (info->data_size < header_size) { | ||
821 | 257 | + grub_error(GRUB_ERR_BAD_OS, "truncated image"); | ||
822 | 258 | + return GRUB_EFI_LOAD_ERROR; | ||
823 | 259 | + } | ||
824 | 260 | + | ||
825 | 261 | + if (pe32_header->num_data_directories >= 6 && | ||
826 | 262 | + pe32_header->base_relocation_table.size) | ||
827 | 263 | + info->reloc = &pe32_header->base_relocation_table; | ||
828 | 264 | + | ||
829 | 265 | + info->section = (void *)((unsigned long)&pe32_header->export_table + | ||
830 | 266 | + pe32_header->num_data_directories * | ||
831 | 267 | + sizeof(struct grub_pe32_data_directory)); | ||
832 | 268 | + break; | ||
833 | 269 | + case GRUB_PE32_PE64_MAGIC: | ||
834 | 270 | + info->section_alignment = pe64_header->section_alignment; | ||
835 | 271 | + info->image_base = pe64_header->image_base; | ||
836 | 272 | + info->image_size = pe64_header->image_size; | ||
837 | 273 | + info->entry_point = | ||
838 | 274 | + (void *)(unsigned long)pe64_header->entry_addr; | ||
839 | 275 | + header_size = pe64_header->header_size; | ||
840 | 276 | + if (info->data_size < header_size) { | ||
841 | 277 | + grub_error(GRUB_ERR_BAD_OS, "truncated image"); | ||
842 | 278 | + return GRUB_EFI_LOAD_ERROR; | ||
843 | 279 | + } | ||
844 | 280 | + | ||
845 | 281 | + if (pe64_header->num_data_directories >= 6 && | ||
846 | 282 | + pe64_header->base_relocation_table.size) | ||
847 | 283 | + info->reloc = &pe64_header->base_relocation_table; | ||
848 | 284 | + | ||
849 | 285 | + info->section = (void *)((unsigned long)&pe64_header->export_table + | ||
850 | 286 | + pe64_header->num_data_directories * | ||
851 | 287 | + sizeof(struct grub_pe32_data_directory)); | ||
852 | 288 | + break; | ||
853 | 289 | + default: | ||
854 | 290 | + grub_error(GRUB_ERR_BAD_OS, "not a PE-COFF file"); | ||
855 | 291 | + return GRUB_EFI_LOAD_ERROR; | ||
856 | 292 | + } | ||
857 | 293 | + | ||
858 | 294 | + if ((unsigned long)info->section + | ||
859 | 295 | + info->num_sections * sizeof(*info->section) > | ||
860 | 296 | + (unsigned long)info->data + info->data_size) { | ||
861 | 297 | + grub_error(GRUB_ERR_BAD_OS, "truncated image"); | ||
862 | 298 | + return GRUB_EFI_LOAD_ERROR; | ||
863 | 299 | + } | ||
864 | 300 | + | ||
865 | 301 | + grub_dprintf("linux", "PE-COFF header checked\n"); | ||
866 | 302 | + | ||
867 | 303 | + return GRUB_EFI_SUCCESS; | ||
868 | 304 | +} | ||
869 | 305 | + | ||
870 | 306 | +/** | ||
871 | 307 | + * load_sections() - load image sections into memory | ||
872 | 308 | + * | ||
873 | 309 | + * Allocate fresh memory and copy the image sections there. | ||
874 | 310 | + * | ||
875 | 311 | + * @info: image information | ||
876 | 312 | + */ | ||
877 | 313 | +static grub_efi_status_t load_sections(struct image_info *info) | ||
878 | 314 | +{ | ||
879 | 315 | + struct grub_pe32_section_table *section; | ||
880 | 316 | + unsigned long align_mask = 0xfff; | ||
881 | 317 | + | ||
882 | 318 | + /* Section alignment must be a power of two */ | ||
883 | 319 | + if (info->section_alignment & (info->section_alignment - 1)) { | ||
884 | 320 | + grub_error(GRUB_ERR_BAD_OS, "invalid section alignment"); | ||
885 | 321 | + return GRUB_EFI_LOAD_ERROR; | ||
886 | 322 | + } | ||
887 | 323 | + | ||
888 | 324 | + if (info->section_alignment > align_mask) | ||
889 | 325 | + align_mask = info->section_alignment - 1; | ||
890 | 326 | + | ||
891 | 327 | + info->alloc_pages = GRUB_EFI_BYTES_TO_PAGES(info->image_size + | ||
892 | 328 | + (align_mask & ~0xfffUL)); | ||
893 | 329 | + | ||
894 | 330 | + info->alloc_addr = grub_efi_allocate_pages_real( | ||
895 | 331 | + GRUB_EFI_MAX_USABLE_ADDRESS, info->alloc_pages, | ||
896 | 332 | + GRUB_EFI_ALLOCATE_MAX_ADDRESS, GRUB_EFI_LOADER_DATA); | ||
897 | 333 | + if (!info->alloc_addr) | ||
898 | 334 | + return GRUB_EFI_OUT_OF_RESOURCES; | ||
899 | 335 | + | ||
900 | 336 | + info->image_addr = | ||
901 | 337 | + (void *)(((unsigned long)info->alloc_addr + align_mask) & | ||
902 | 338 | + ~align_mask); | ||
903 | 339 | + | ||
904 | 340 | + for (section = &info->section[0]; | ||
905 | 341 | + section < &info->section[info->num_sections]; ++section) { | ||
906 | 342 | + if (section->raw_data_offset + section->raw_data_size > | ||
907 | 343 | + info->data_size) { | ||
908 | 344 | + grub_error(GRUB_ERR_BAD_OS, "truncated image"); | ||
909 | 345 | + return GRUB_EFI_LOAD_ERROR; | ||
910 | 346 | + } | ||
911 | 347 | + if (section->virtual_address + section->virtual_size > | ||
912 | 348 | + info->image_size) { | ||
913 | 349 | + grub_error(GRUB_ERR_BAD_OS, "section outside image"); | ||
914 | 350 | + return GRUB_EFI_LOAD_ERROR; | ||
915 | 351 | + } | ||
916 | 352 | + | ||
917 | 353 | + grub_memset( | ||
918 | 354 | + (void *)((unsigned long)info->image_addr + | ||
919 | 355 | + section->virtual_address), 0, | ||
920 | 356 | + section->virtual_size); | ||
921 | 357 | + grub_memcpy( | ||
922 | 358 | + (void *)((unsigned long)info->image_addr + | ||
923 | 359 | + section->virtual_address), | ||
924 | 360 | + (void *)((unsigned long)info->data + | ||
925 | 361 | + section->raw_data_offset), | ||
926 | 362 | + section->raw_data_size); | ||
927 | 363 | + } | ||
928 | 364 | + | ||
929 | 365 | + info->entry_point = (void *)((unsigned long)info->entry_point + | ||
930 | 366 | + (unsigned long)info->image_addr); | ||
931 | 367 | + | ||
932 | 368 | + grub_dprintf("linux", "sections loaded\n"); | ||
933 | 369 | + | ||
934 | 370 | + return GRUB_EFI_SUCCESS; | ||
935 | 371 | +} | ||
936 | 372 | + | ||
937 | 373 | +/** | ||
938 | 374 | + * lo12i_get() - get the immediate value of a format I instruction | ||
939 | 375 | + * | ||
940 | 376 | + * Instruction format I:: | ||
941 | 377 | + * | ||
942 | 378 | + * +---------------------------------------------------------------+ | ||
943 | 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| | ||
944 | 380 | + * +-----------------------+---------+-----+---------+-------------+ | ||
945 | 381 | + * | imm[11:0] | rs1 |fun3 | rd | opcode | | ||
946 | 382 | + * +-----------------------+---------+-----+---------+-------------+ | ||
947 | 383 | + * | ||
948 | 384 | + * @instr: pointer to instruction | ||
949 | 385 | + * Return: immediate value | ||
950 | 386 | + */ | ||
951 | 387 | +static grub_uint16_t | ||
952 | 388 | +lo12i_get(grub_uint32_t *instr) | ||
953 | 389 | +{ | ||
954 | 390 | + return ((*instr & 0xfff00000) >> 20); | ||
955 | 391 | +} | ||
956 | 392 | + | ||
957 | 393 | +/** | ||
958 | 394 | + * lo12i_set() - set the immediate value of a format I instruction | ||
959 | 395 | + * | ||
960 | 396 | + * Instruction format I:: | ||
961 | 397 | + * | ||
962 | 398 | + * +---------------------------------------------------------------+ | ||
963 | 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| | ||
964 | 400 | + * +-----------------------+---------+-----+---------+-------------+ | ||
965 | 401 | + * | imm[11:0] | rs1 |fun3 | rd | opcode | | ||
966 | 402 | + * +-----------------------+---------+-----+---------+-------------+ | ||
967 | 403 | + * | ||
968 | 404 | + * @instr: pointer to instruction | ||
969 | 405 | + * @imm: immediate value | ||
970 | 406 | + */ | ||
971 | 407 | +static void | ||
972 | 408 | +lo12i_set(grub_uint32_t *instr, grub_uint32_t imm) | ||
973 | 409 | +{ | ||
974 | 410 | + *instr = (*instr & 0x000fffff) | | ||
975 | 411 | + (imm & 0x00000fff << 20); | ||
976 | 412 | +} | ||
977 | 413 | + | ||
978 | 414 | +/** | ||
979 | 415 | + * hi20_get() - get the immediate value of a format I instruction | ||
980 | 416 | + * | ||
981 | 417 | + * Instruction format U:: | ||
982 | 418 | + * | ||
983 | 419 | + * +---------------------------------------------------------------+ | ||
984 | 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| | ||
985 | 421 | + * +---------------------------------------+---------+-------------+ | ||
986 | 422 | + * | imm[31:12] | rd | opcode | | ||
987 | 423 | + * +---------------------------------------+---------+-------------+ | ||
988 | 424 | + * | ||
989 | 425 | + * @instr: pointer to instruction | ||
990 | 426 | + * Return: immediate value | ||
991 | 427 | + */ | ||
992 | 428 | +static grub_uint16_t | ||
993 | 429 | +hi20_get(grub_uint32_t *instr) | ||
994 | 430 | +{ | ||
995 | 431 | + return *instr & 0xfffff000; | ||
996 | 432 | +} | ||
997 | 433 | + | ||
998 | 434 | +/** | ||
999 | 435 | + * hi20_set() - set the immediate value of a format I instruction | ||
1000 | 436 | + * | ||
1001 | 437 | + * Instruction format U:: | ||
1002 | 438 | + * | ||
1003 | 439 | + * +---------------------------------------------------------------+ | ||
1004 | 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| | ||
1005 | 441 | + * +---------------------------------------+---------+-------------+ | ||
1006 | 442 | + * | imm[31:12] | rd | opcode | | ||
1007 | 443 | + * +---------------------------------------+---------+-------------+ | ||
1008 | 444 | + * | ||
1009 | 445 | + * @instr: pointer to instruction | ||
1010 | 446 | + * @imm: immediate value | ||
1011 | 447 | + */ | ||
1012 | 448 | +static void | ||
1013 | 449 | +hi20_set(grub_uint32_t *instr, grub_uint32_t imm) | ||
1014 | 450 | +{ | ||
1015 | 451 | + *instr = (*instr & 0x00000fff) | | ||
1016 | 452 | + (imm & 0xfffff000); | ||
1017 | 453 | +} | ||
1018 | 454 | + | ||
1019 | 455 | +/** | ||
1020 | 456 | + * lo12s_get() - get the immediate value of a format I instruction | ||
1021 | 457 | + * | ||
1022 | 458 | + * Instruction format S:: | ||
1023 | 459 | + * | ||
1024 | 460 | + * +---------------------------------------------------------------+ | ||
1025 | 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| | ||
1026 | 462 | + * +-------------+---------+---------+-----+----+----+-------------+ | ||
1027 | 463 | + * | imm[11:5] | rs2 | rs1 |fun3 |imm[4:0] | opcode | | ||
1028 | 464 | + * +-------------+---------+---------+-----+----+----+-------------+ | ||
1029 | 465 | + * | ||
1030 | 466 | + * @instr: pointer to instruction | ||
1031 | 467 | + * Return: immediate value | ||
1032 | 468 | + */ | ||
1033 | 469 | +static grub_uint16_t | ||
1034 | 470 | +lo12s_get(grub_uint32_t *instr) | ||
1035 | 471 | +{ | ||
1036 | 472 | + return ((*instr & 0x00000f80) >> 7) | | ||
1037 | 473 | + ((*instr & 0xfe000000) >> 20); | ||
1038 | 474 | +} | ||
1039 | 475 | + | ||
1040 | 476 | +/** | ||
1041 | 477 | + * lo12s_set() - set the immediate value of a format I instruction | ||
1042 | 478 | + * | ||
1043 | 479 | + * Instruction format S:: | ||
1044 | 480 | + * | ||
1045 | 481 | + * +---------------------------------------------------------------+ | ||
1046 | 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| | ||
1047 | 483 | + * +-------------+---------+---------+-----+----+----+-------------+ | ||
1048 | 484 | + * | imm[11:5] | rs2 | rs1 |fun3 |imm[4:0] | opcode | | ||
1049 | 485 | + * +-------------+---------+---------+-----+----+----+-------------+ | ||
1050 | 486 | + * | ||
1051 | 487 | + * @instr: pointer to instruction | ||
1052 | 488 | + * @imm: immediate value | ||
1053 | 489 | + */ | ||
1054 | 490 | +static void | ||
1055 | 491 | +lo12s_set(grub_uint32_t *instr, grub_uint32_t imm) | ||
1056 | 492 | +{ | ||
1057 | 493 | + *instr = (*instr & 0x01fff07f) | | ||
1058 | 494 | + (imm & 0x00000fe0 << 20) | | ||
1059 | 495 | + (imm & 0x0000001f << 7); | ||
1060 | 496 | +} | ||
1061 | 497 | + | ||
1062 | 498 | +/** | ||
1063 | 499 | + * movw_get_imm() - get the immediate value of MOVT and MOVT instructions | ||
1064 | 500 | + * | ||
1065 | 501 | + * MOVT:: | ||
1066 | 502 | + * | ||
1067 | 503 | + * +-------------------------------+-------------------------------+ | ||
1068 | 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| | ||
1069 | 505 | + * +---------+-+-----------+-------+-+-----+-------+---------------+ | ||
1070 | 506 | + * |1 1 1 1 0|i|1 0 1 1 0 0| imm4 |0| imm3| Rd | imm8 | | ||
1071 | 507 | + * +---------+-+-----------+-------+-+-----+-------+---------------+ | ||
1072 | 508 | + * | ||
1073 | 509 | + * MOVW:: | ||
1074 | 510 | + * | ||
1075 | 511 | + * +-------------------------------+-------------------------------+ | ||
1076 | 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| | ||
1077 | 513 | + * +---------+-+-----------+-------+-+-----+-------+---------------+ | ||
1078 | 514 | + * |1 1 1 1 0|i|1 0 0 1 0 0| imm4 |0| imm3| Rd | imm8 | | ||
1079 | 515 | + * +---------+-+-----------+-------+-+-----+-------+---------------+ | ||
1080 | 516 | + * | ||
1081 | 517 | + * @instr: pointer to instruction | ||
1082 | 518 | + * Return: immediate value | ||
1083 | 519 | + */ | ||
1084 | 520 | +static grub_uint16_t | ||
1085 | 521 | +movw_get_imm(grub_uint16_t *instr) | ||
1086 | 522 | +{ | ||
1087 | 523 | + /* imm16 = imm4:i:imm3:imm8; */ | ||
1088 | 524 | + return (instr[1] & 0x00ff) | | ||
1089 | 525 | + ((instr[1] & 0x7000) >> 3) | | ||
1090 | 526 | + ((instr[0] & 0x0400) >> 8) | | ||
1091 | 527 | + ((instr[0] & 0x000f) << 12); | ||
1092 | 528 | +} | ||
1093 | 529 | + | ||
1094 | 530 | +/** | ||
1095 | 531 | + * movw_set_imm() - set the immediate value of MOVT and MOVT instructions | ||
1096 | 532 | + * | ||
1097 | 533 | + * MOVT:: | ||
1098 | 534 | + * | ||
1099 | 535 | + * +-------------------------------+-------------------------------+ | ||
1100 | 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| | ||
1101 | 537 | + * +---------+-+-----------+-------+-+-----+-------+---------------+ | ||
1102 | 538 | + * |1 1 1 1 0|i|1 0 1 1 0 0| imm4 |0| imm3| Rd | imm8 | | ||
1103 | 539 | + * +---------+-+-----------+-------+-+-----+-------+---------------+ | ||
1104 | 540 | + * | ||
1105 | 541 | + * MOVW:: | ||
1106 | 542 | + * | ||
1107 | 543 | + * +-------------------------------+-------------------------------+ | ||
1108 | 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| | ||
1109 | 545 | + * +---------+-+-----------+-------+-+-----+-------+---------------+ | ||
1110 | 546 | + * |1 1 1 1 0|i|1 0 0 1 0 0| imm4 |0| imm3| Rd | imm8 | | ||
1111 | 547 | + * +---------+-+-----------+-------+-+-----+-------+---------------+ | ||
1112 | 548 | + * | ||
1113 | 549 | + * @instr: pointer to instruction | ||
1114 | 550 | + * @imm immediate value | ||
1115 | 551 | + */ | ||
1116 | 552 | +static void | ||
1117 | 553 | +movw_set_imm(grub_uint16_t *instr, grub_uint16_t imm) | ||
1118 | 554 | +{ | ||
1119 | 555 | + /* imm16 = imm4:i:imm3:imm8; */ | ||
1120 | 556 | + instr[0] = (instr[0] & 0xfbf0) | | ||
1121 | 557 | + (imm & 0xf000) >> 12 | | ||
1122 | 558 | + (imm & 0x0800) << 3; | ||
1123 | 559 | + instr[1] = (instr[0] & 0x8f00) | | ||
1124 | 560 | + (imm & 0xff) | | ||
1125 | 561 | + (imm & 0x0700) >> 4; | ||
1126 | 562 | +} | ||
1127 | 563 | + | ||
1128 | 564 | +/** | ||
1129 | 565 | + * relocate() - apply relocations to the image | ||
1130 | 566 | + * | ||
1131 | 567 | + * @info: information about the loaded image | ||
1132 | 568 | + */ | ||
1133 | 569 | +static grub_efi_status_t | ||
1134 | 570 | +relocate(struct image_info *info) | ||
1135 | 571 | +{ | ||
1136 | 572 | + struct grub_pe32_fixup_block *block, *reloc_end; | ||
1137 | 573 | + unsigned long offset; | ||
1138 | 574 | + grub_uint16_t reloc_type; | ||
1139 | 575 | + grub_uint16_t *reloc_entry; | ||
1140 | 576 | + grub_uint32_t *rvhi20_addr = NULL; | ||
1141 | 577 | + | ||
1142 | 578 | + if (!info->reloc || !(info->reloc->size)) { | ||
1143 | 579 | + grub_dprintf("linux", "no relocations\n"); | ||
1144 | 580 | + return GRUB_EFI_SUCCESS; | ||
1145 | 581 | + } | ||
1146 | 582 | + | ||
1147 | 583 | + if (info->reloc->rva + info->reloc->size > info->image_size) { | ||
1148 | 584 | + grub_error(GRUB_ERR_BAD_OS, "relocation block outside image"); | ||
1149 | 585 | + return GRUB_EFI_LOAD_ERROR; | ||
1150 | 586 | + } | ||
1151 | 587 | + | ||
1152 | 588 | + /* | ||
1153 | 589 | + * The relocations are based on the difference between | ||
1154 | 590 | + * actual load address and the preferred base address. | ||
1155 | 591 | + */ | ||
1156 | 592 | + offset = (unsigned long)info->image_addr - info->image_base; | ||
1157 | 593 | + | ||
1158 | 594 | + block = (void *)((unsigned long)info->image_addr + info->reloc->rva); | ||
1159 | 595 | + reloc_end = (void *)((unsigned long)block + info->reloc->size); | ||
1160 | 596 | + | ||
1161 | 597 | + for (; block < reloc_end; | ||
1162 | 598 | + block = (void *)((unsigned long)block + block->block_size)) { | ||
1163 | 599 | + reloc_entry = block->entries; | ||
1164 | 600 | + grub_uint16_t *block_end = | ||
1165 | 601 | + (void *)((unsigned long)block + block->block_size); | ||
1166 | 602 | + | ||
1167 | 603 | + for (; reloc_entry < block_end; ++reloc_entry) { | ||
1168 | 604 | + void *addr = (void *)((unsigned long)info->image_addr + | ||
1169 | 605 | + block->page_rva + | ||
1170 | 606 | + (*reloc_entry & 0xfff)); | ||
1171 | 607 | + | ||
1172 | 608 | + reloc_type = *reloc_entry >> 12; | ||
1173 | 609 | + | ||
1174 | 610 | + switch (reloc_type) { | ||
1175 | 611 | + case GRUB_PE32_REL_BASED_ABSOLUTE: | ||
1176 | 612 | + /* skip */ | ||
1177 | 613 | + break; | ||
1178 | 614 | + case GRUB_PE32_REL_BASED_HIGH: | ||
1179 | 615 | + *(grub_uint16_t *)addr += offset >> 16; | ||
1180 | 616 | + break; | ||
1181 | 617 | + case GRUB_PE32_REL_BASED_LOW: | ||
1182 | 618 | + *(grub_uint16_t *)addr += offset; | ||
1183 | 619 | + break; | ||
1184 | 620 | + case GRUB_PE32_REL_BASED_HIGHLOW: | ||
1185 | 621 | + *(grub_uint32_t *)addr += offset; | ||
1186 | 622 | + break; | ||
1187 | 623 | + case GRUB_PE32_REL_BASED_RISCV_HI20: | ||
1188 | 624 | + switch (info->machine) { | ||
1189 | 625 | + case GRUB_PE32_MACHINE_RISCV32: | ||
1190 | 626 | + case GRUB_PE32_MACHINE_RISCV64: | ||
1191 | 627 | + rvhi20_addr = addr; | ||
1192 | 628 | + break; | ||
1193 | 629 | + default: | ||
1194 | 630 | + goto bad_reloc; | ||
1195 | 631 | + } | ||
1196 | 632 | + break; | ||
1197 | 633 | + case GRUB_PE32_REL_BASED_ARM_MOV32T: | ||
1198 | 634 | + /* = GRUB_PE32_REL_BASED_RISCV_LOW12I */ | ||
1199 | 635 | + switch (info->machine) { | ||
1200 | 636 | + case GRUB_PE32_MACHINE_ARMTHUMB_MIXED: { | ||
1201 | 637 | + grub_uint16_t *instr = addr; | ||
1202 | 638 | + grub_uint32_t val; | ||
1203 | 639 | + | ||
1204 | 640 | + val = movw_get_imm(&instr[0]) + | ||
1205 | 641 | + (movw_get_imm(&instr[2]) << 16) + | ||
1206 | 642 | + offset; | ||
1207 | 643 | + movw_set_imm(&instr[0], val); | ||
1208 | 644 | + movw_set_imm(&instr[2], val >> 16); | ||
1209 | 645 | + break; | ||
1210 | 646 | + } | ||
1211 | 647 | + case GRUB_PE32_MACHINE_RISCV32: | ||
1212 | 648 | + case GRUB_PE32_MACHINE_RISCV64: | ||
1213 | 649 | + if (rvhi20_addr) { | ||
1214 | 650 | + grub_uint32_t val = | ||
1215 | 651 | + hi20_get(rvhi20_addr) + | ||
1216 | 652 | + lo12i_get(addr) + | ||
1217 | 653 | + offset; | ||
1218 | 654 | + hi20_set(rvhi20_addr, val); | ||
1219 | 655 | + lo12i_set(addr, val); | ||
1220 | 656 | + rvhi20_addr = NULL; | ||
1221 | 657 | + } else { | ||
1222 | 658 | + goto bad_reloc; | ||
1223 | 659 | + } | ||
1224 | 660 | + break; | ||
1225 | 661 | + default: | ||
1226 | 662 | + goto bad_reloc; | ||
1227 | 663 | + } | ||
1228 | 664 | + break; | ||
1229 | 665 | + case GRUB_PE32_REL_BASED_RISCV_LOW12S: | ||
1230 | 666 | + switch (info->machine) { | ||
1231 | 667 | + case GRUB_PE32_MACHINE_RISCV32: | ||
1232 | 668 | + case GRUB_PE32_MACHINE_RISCV64: | ||
1233 | 669 | + if (rvhi20_addr) { | ||
1234 | 670 | + grub_uint32_t val = | ||
1235 | 671 | + hi20_get(rvhi20_addr) + | ||
1236 | 672 | + lo12s_get(addr) + | ||
1237 | 673 | + offset; | ||
1238 | 674 | + hi20_set(rvhi20_addr, val); | ||
1239 | 675 | + lo12s_set(addr, val); | ||
1240 | 676 | + rvhi20_addr = NULL; | ||
1241 | 677 | + } else { | ||
1242 | 678 | + goto bad_reloc; | ||
1243 | 679 | + } | ||
1244 | 680 | + break; | ||
1245 | 681 | + default: | ||
1246 | 682 | + goto bad_reloc; | ||
1247 | 683 | + } | ||
1248 | 684 | + break; | ||
1249 | 685 | + case GRUB_PE32_REL_BASED_DIR64: | ||
1250 | 686 | + *(grub_uint64_t *)addr += offset; | ||
1251 | 687 | + break; | ||
1252 | 688 | + default: | ||
1253 | 689 | + goto bad_reloc; | ||
1254 | 690 | + } | ||
1255 | 691 | + } | ||
1256 | 692 | + } | ||
1257 | 693 | + | ||
1258 | 694 | + grub_dprintf("linux", "image relocated\n"); | ||
1259 | 695 | + | ||
1260 | 696 | + return GRUB_EFI_SUCCESS; | ||
1261 | 697 | + | ||
1262 | 698 | +bad_reloc: | ||
1263 | 699 | + grub_error(GRUB_ERR_BAD_OS, | ||
1264 | 700 | + "unsupported relocation type %d, rva 0x%08lx\n", | ||
1265 | 701 | + *reloc_entry >> 12, | ||
1266 | 702 | + (unsigned long)reloc_entry - | ||
1267 | 703 | + (unsigned long)info->image_addr); | ||
1268 | 704 | + return GRUB_EFI_LOAD_ERROR; | ||
1269 | 705 | +} | ||
1270 | 706 | + | ||
1271 | 707 | +/** | ||
1272 | 708 | + * efi_exit() - replacement for EFI_BOOT_SERVICES.Exit() | ||
1273 | 709 | + * | ||
1274 | 710 | + * This function is inserted into system table to trap invocations of | ||
1275 | 711 | + * EFI_BOOT_SERVICES.Exit(). If Exit() is called with our handle | ||
1276 | 712 | + * return to our start routine using a long jump. | ||
1277 | 713 | + * | ||
1278 | 714 | + * @image_handle: handle of the application as passed on entry | ||
1279 | 715 | + * @exit_status: the images exit code | ||
1280 | 716 | + * @exit_data_size: size of @exit_data | ||
1281 | 717 | + * @exit_data: null terminated string followed by optional data | ||
1282 | 718 | + */ | ||
1283 | 719 | +static grub_efi_status_t EFIAPI | ||
1284 | 720 | +efi_exit(grub_efi_handle_t image_handle, | ||
1285 | 721 | + grub_efi_status_t exit_status, | ||
1286 | 722 | + grub_efi_uintn_t exit_data_size, | ||
1287 | 723 | + grub_efi_char16_t *exit_data) | ||
1288 | 724 | +{ | ||
1289 | 725 | + grub_efi_system_table->boot_services->exit = started_image.exit; | ||
1290 | 726 | + | ||
1291 | 727 | + if (!image_handle) | ||
1292 | 728 | + return GRUB_EFI_INVALID_PARAMETER; | ||
1293 | 729 | + | ||
1294 | 730 | + if (image_handle != started_image.image_handle) { | ||
1295 | 731 | + grub_dprintf("linux", "delegating Exit()\n"); | ||
1296 | 732 | + return efi_call_4(started_image.exit, image_handle, | ||
1297 | 733 | + exit_status, exit_data_size, | ||
1298 | 734 | + (grub_efi_char16_t *)exit_data); | ||
1299 | 735 | + } | ||
1300 | 736 | + | ||
1301 | 737 | + started_image.exit_status = exit_status; | ||
1302 | 738 | + | ||
1303 | 739 | + if (exit_status != GRUB_EFI_SUCCESS) { | ||
1304 | 740 | + grub_printf("Application failed, r = %d\n", | ||
1305 | 741 | + (int)exit_status & 0x7fffffff); | ||
1306 | 742 | + if (exit_data_size && exit_data) { | ||
1307 | 743 | + grub_printf("exit message: "); | ||
1308 | 744 | + for (grub_efi_uintn_t pos = 0; | ||
1309 | 745 | + exit_data[pos] && pos < exit_data_size / 2; ++pos) | ||
1310 | 746 | + grub_printf("%C", exit_data[pos]); | ||
1311 | 747 | + grub_printf("\n"); | ||
1312 | 748 | + } | ||
1313 | 749 | + } | ||
1314 | 750 | + if (exit_data_size && exit_data) { | ||
1315 | 751 | + /* exit data must be freed by the caller */ | ||
1316 | 752 | + efi_call_1(grub_efi_system_table->boot_services->free_pool, | ||
1317 | 753 | + exit_data); | ||
1318 | 754 | + } | ||
1319 | 755 | + grub_longjmp(started_image.jmp, 1); | ||
1320 | 756 | +} | ||
1321 | 757 | + | ||
1322 | 758 | +/** | ||
1323 | 759 | + * start_image() - our implementation of StartImage() | ||
1324 | 760 | + * | ||
1325 | 761 | + * As we do not load the image via LoadImage() we need our own implementation | ||
1326 | 762 | + * of StartImage() to launch the PE-COFF image. | ||
1327 | 763 | + */ | ||
1328 | 764 | +static grub_efi_status_t | ||
1329 | 765 | +start_image(struct image_info *info) | ||
1330 | 766 | +{ | ||
1331 | 767 | + int ret; | ||
1332 | 768 | + grub_efi_status_t status; | ||
1333 | 769 | + grub_efi_loaded_image_t *loaded_image; | ||
1334 | 770 | + | ||
1335 | 771 | + /* | ||
1336 | 772 | + * TODO: It would better comply to the UEFI specification to | ||
1337 | 773 | + * use a separate handle for the image we are running. | ||
1338 | 774 | + */ | ||
1339 | 775 | + started_image.image_handle = grub_efi_image_handle; | ||
1340 | 776 | + | ||
1341 | 777 | + loaded_image = grub_efi_get_loaded_image(grub_efi_image_handle); | ||
1342 | 778 | + if (loaded_image) { | ||
1343 | 779 | + loaded_image->image_base = info->image_addr; | ||
1344 | 780 | + loaded_image->image_size = info->image_size; | ||
1345 | 781 | + } else { | ||
1346 | 782 | + grub_dprintf ("linux", "Loaded image protocol missing\n"); | ||
1347 | 783 | + } | ||
1348 | 784 | + | ||
1349 | 785 | + ret = grub_setjmp(started_image.jmp); | ||
1350 | 786 | + if (ret) { | ||
1351 | 787 | + started_image.image_handle = NULL; | ||
1352 | 788 | + | ||
1353 | 789 | + return started_image.exit_status; | ||
1354 | 790 | + } | ||
1355 | 791 | + | ||
1356 | 792 | + started_image.exit = grub_efi_system_table->boot_services->exit; | ||
1357 | 793 | + grub_efi_system_table->boot_services->exit = efi_exit; | ||
1358 | 794 | + | ||
1359 | 795 | + grub_dprintf("linux", | ||
1360 | 796 | + "Executing image loaded at 0x%lx\nEntry point 0x%lx\nSize 0x%08x\n", | ||
1361 | 797 | + (unsigned long)info->image_addr, | ||
1362 | 798 | + (unsigned long)info->entry_point, | ||
1363 | 799 | + info->image_size); | ||
1364 | 800 | + | ||
1365 | 801 | + /* Invalidate the instruction cache */ | ||
1366 | 802 | + grub_arch_sync_caches(info->image_addr, info->image_size); | ||
1367 | 803 | + | ||
1368 | 804 | + debug("pestart"); | ||
1369 | 805 | + status = efi_call_2(info->entry_point, started_image.image_handle, | ||
1370 | 806 | + grub_efi_system_table); | ||
1371 | 807 | + | ||
1372 | 808 | + grub_dprintf("linux", "Application returned\n"); | ||
1373 | 809 | + | ||
1374 | 810 | + return efi_exit(started_image.image_handle, status, 0, NULL); | ||
1375 | 811 | +} | ||
1376 | 812 | + | ||
1377 | 813 | +/** | ||
1378 | 814 | + * grub_efi_run_image() - run a PE-COFF image from memory | ||
1379 | 815 | + * | ||
1380 | 816 | + * TODO: move the creation of the load options here | ||
1381 | 817 | + * | ||
1382 | 818 | + * @data: buffer with PE-COFF image | ||
1383 | 819 | + * @data_size: size of the buffer | ||
1384 | 820 | + * @args: command line to be passed as load options | ||
1385 | 821 | + */ | ||
1386 | 822 | +grub_efi_boolean_t | ||
1387 | 823 | +grub_efi_run_image(void *data, grub_efi_uint32_t data_size, | ||
1388 | 824 | + const char *args __attribute__((unused))) | ||
1389 | 825 | +{ | ||
1390 | 826 | + struct image_info info = { | ||
1391 | 827 | + .data = data, | ||
1392 | 828 | + .data_size = data_size, | ||
1393 | 829 | + }; | ||
1394 | 830 | + | ||
1395 | 831 | + /* read and check header */ | ||
1396 | 832 | + if (check_pe_header(&info) != GRUB_EFI_SUCCESS) | ||
1397 | 833 | + goto err; | ||
1398 | 834 | + /* load sections */ | ||
1399 | 835 | + if (load_sections(&info) != GRUB_EFI_SUCCESS) | ||
1400 | 836 | + goto err; | ||
1401 | 837 | + | ||
1402 | 838 | + if (relocate(&info) != GRUB_EFI_SUCCESS) | ||
1403 | 839 | + goto err; | ||
1404 | 840 | + | ||
1405 | 841 | + if (start_image(&info) != GRUB_EFI_SUCCESS) | ||
1406 | 842 | + goto err; | ||
1407 | 843 | + | ||
1408 | 844 | +err: | ||
1409 | 845 | + /* free allocated memory */ | ||
1410 | 846 | + if (info.alloc_addr) | ||
1411 | 847 | + grub_efi_free_pages((unsigned long)info.alloc_addr, | ||
1412 | 848 | + info.alloc_pages); | ||
1413 | 849 | + | ||
1414 | 850 | + return 0; | ||
1415 | 851 | +} | ||
1416 | 852 | diff --git a/include/grub/efi/linux.h b/include/grub/efi/linux.h | ||
1417 | 853 | index 0033d93..39f5a9a 100644 | ||
1418 | 854 | --- a/include/grub/efi/linux.h | ||
1419 | 855 | +++ b/include/grub/efi/linux.h | ||
1420 | 856 | @@ -27,5 +27,8 @@ EXPORT_FUNC(grub_linuxefi_secure_validate) (void *data, grub_uint32_t size); | ||
1421 | 857 | grub_err_t | ||
1422 | 858 | EXPORT_FUNC(grub_efi_linux_boot) (void *kernel_address, grub_off_t offset, | ||
1423 | 859 | void *kernel_param); | ||
1424 | 860 | +grub_efi_boolean_t | ||
1425 | 861 | +EXPORT_FUNC(grub_efi_run_image) (void *data, grub_efi_uint32_t data_size, | ||
1426 | 862 | + const char *args); | ||
1427 | 863 | |||
1428 | 864 | #endif /* ! GRUB_EFI_LINUX_HEADER */ | ||
1429 | 865 | diff --git a/include/grub/efi/peimage.h b/include/grub/efi/peimage.h | ||
1430 | 866 | new file mode 100644 | ||
1431 | 867 | index 0000000..70bfdc7 | ||
1432 | 868 | --- /dev/null | ||
1433 | 869 | +++ b/include/grub/efi/peimage.h | ||
1434 | 870 | @@ -0,0 +1,28 @@ | ||
1435 | 871 | +/* SPDX-License-Identifier: GPL-3.0+ */ | ||
1436 | 872 | + | ||
1437 | 873 | +#define GRUB_PE_MAGIC "PE\0" | ||
1438 | 874 | + | ||
1439 | 875 | +#ifdef __x86_64__ | ||
1440 | 876 | +#define EFIAPI __attribute__((ms_abi)) | ||
1441 | 877 | +#else | ||
1442 | 878 | +#define EFIAPI | ||
1443 | 879 | +#endif | ||
1444 | 880 | + | ||
1445 | 881 | +#define EFI_LOADED_IMAGE_PROTOCOL_REVISION (0x1000) | ||
1446 | 882 | + | ||
1447 | 883 | +typedef grub_efi_status_t (*grub_efi_entry_point) | ||
1448 | 884 | + (grub_efi_handle_t image_handle, grub_efi_system_table_t *system_table); | ||
1449 | 885 | + | ||
1450 | 886 | +struct grub_dos_stub { | ||
1451 | 887 | + grub_uint16_t magic; /* MZ magic */ | ||
1452 | 888 | + grub_uint16_t lbsize; /* size of last block */ | ||
1453 | 889 | + grub_uint32_t res0; /* reserved */ | ||
1454 | 890 | + grub_uint64_t res1; /* reserved */ | ||
1455 | 891 | + grub_uint64_t res2; /* reserved */ | ||
1456 | 892 | + grub_uint64_t res3; /* reserved */ | ||
1457 | 893 | + grub_uint64_t res4; /* reserved */ | ||
1458 | 894 | + grub_uint64_t res5; /* reserved */ | ||
1459 | 895 | + grub_uint64_t res6; /* reserved */ | ||
1460 | 896 | + grub_uint32_t linux_arch; /* linux architecture */ | ||
1461 | 897 | + grub_uint32_t pe_addr; /* offset of PE/COFF header */ | ||
1462 | 898 | +}; | ||
1463 | diff --git a/debian/patches/efi-implemented-LoadFile2-initrd-loading-protocol-fo.patch b/debian/patches/efi-implemented-LoadFile2-initrd-loading-protocol-fo.patch | |||
1464 | 0 | new file mode 100644 | 899 | new file mode 100644 |
1465 | index 0000000..be73410 | |||
1466 | --- /dev/null | |||
1467 | +++ b/debian/patches/efi-implemented-LoadFile2-initrd-loading-protocol-fo.patch | |||
1468 | @@ -0,0 +1,183 @@ | |||
1469 | 1 | From: Ard Biesheuvel <ard.biesheuvel@arm.com> | ||
1470 | 2 | Date: Thu, 28 Oct 2021 23:31:16 +0300 | ||
1471 | 3 | Subject: efi: implemented LoadFile2 initrd loading protocol for Linux | ||
1472 | 4 | |||
1473 | 5 | Recent Linux kernels will invoke the LoadFile2 protocol installed on | ||
1474 | 6 | a well-known vendor media path to load the initrd if it is exposed by | ||
1475 | 7 | the firmware. Using this method is preferred for two reasons: | ||
1476 | 8 | - the Linux kernel is in charge of allocating the memory, and so it can | ||
1477 | 9 | implement any placement policy it wants (given that these tend to | ||
1478 | 10 | change between kernel versions), | ||
1479 | 11 | - it is no longer necessary to modify the device tree provided by the | ||
1480 | 12 | firmware. | ||
1481 | 13 | |||
1482 | 14 | So let's install this protocol when handling the 'initrd' command if | ||
1483 | 15 | such a recent kernel was detected (based on the PE/COFF image version), | ||
1484 | 16 | and defer loading the initrd contents until the point where the kernel | ||
1485 | 17 | invokes the LoadFile2 protocol. | ||
1486 | 18 | |||
1487 | 19 | Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> | ||
1488 | 20 | Signed-off-by: Nikita Ermakov <arei@altlinux.org> | ||
1489 | 21 | Origin: https://lists.gnu.org/archive/html/grub-devel/2021-10/msg00214.html | ||
1490 | 22 | --- | ||
1491 | 23 | grub-core/loader/arm64/linux.c | 117 ++++++++++++++++++++++++++++++++++++++++- | ||
1492 | 24 | 1 file changed, 116 insertions(+), 1 deletion(-) | ||
1493 | 25 | |||
1494 | 26 | diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c | ||
1495 | 27 | index aed7a20..6b03455 100644 | ||
1496 | 28 | --- a/grub-core/loader/arm64/linux.c | ||
1497 | 29 | +++ b/grub-core/loader/arm64/linux.c | ||
1498 | 30 | @@ -48,9 +48,18 @@ static grub_uint32_t cmdline_size; | ||
1499 | 31 | static grub_addr_t initrd_start; | ||
1500 | 32 | static grub_addr_t initrd_end; | ||
1501 | 33 | |||
1502 | 34 | +static struct grub_linux_initrd_context initrd_ctx = { 0, 0, 0 }; | ||
1503 | 35 | +static grub_efi_handle_t initrd_lf2_handle; | ||
1504 | 36 | +static int initrd_use_loadfile2; | ||
1505 | 37 | +static grub_efi_guid_t load_file2_guid = GRUB_EFI_LOAD_FILE2_PROTOCOL_GUID; | ||
1506 | 38 | +static grub_efi_guid_t device_path_guid = GRUB_EFI_DEVICE_PATH_GUID; | ||
1507 | 39 | + | ||
1508 | 40 | grub_err_t | ||
1509 | 41 | grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh) | ||
1510 | 42 | { | ||
1511 | 43 | + struct grub_pe32_coff_header *coff_header; | ||
1512 | 44 | + struct grub_pe32_optional_header *optional_header; | ||
1513 | 45 | + | ||
1514 | 46 | if (lh->magic != GRUB_LINUX_ARMXX_MAGIC_SIGNATURE) | ||
1515 | 47 | return grub_error(GRUB_ERR_BAD_OS, "invalid magic number"); | ||
1516 | 48 | |||
1517 | 49 | @@ -61,6 +70,21 @@ grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh) | ||
1518 | 50 | grub_dprintf ("linux", "UEFI stub kernel:\n"); | ||
1519 | 51 | grub_dprintf ("linux", "PE/COFF header @ %08x\n", lh->hdr_offset); | ||
1520 | 52 | |||
1521 | 53 | + coff_header = (struct grub_pe32_coff_header *)((unsigned long)lh + lh->hdr_offset); | ||
1522 | 54 | + optional_header = (struct grub_pe32_optional_header *)(coff_header + 1); | ||
1523 | 55 | + | ||
1524 | 56 | + /* | ||
1525 | 57 | + * Linux kernels built for any architecture are guaranteed to support the | ||
1526 | 58 | + * LoadFile2 based initrd loading protocol if the image version is >= 1. | ||
1527 | 59 | + */ | ||
1528 | 60 | + if (optional_header->major_image_version >= 1) | ||
1529 | 61 | + initrd_use_loadfile2 = 1; | ||
1530 | 62 | + else | ||
1531 | 63 | + initrd_use_loadfile2 = 0; | ||
1532 | 64 | + | ||
1533 | 65 | + grub_dprintf ("linux", "LoadFile2 initrd loading %sabled\n", | ||
1534 | 66 | + initrd_use_loadfile2 ? "en" : "dis"); | ||
1535 | 67 | + | ||
1536 | 68 | return GRUB_ERR_NONE; | ||
1537 | 69 | } | ||
1538 | 70 | |||
1539 | 71 | @@ -230,13 +254,86 @@ allocate_initrd_mem (int initrd_pages) | ||
1540 | 72 | GRUB_EFI_LOADER_DATA); | ||
1541 | 73 | } | ||
1542 | 74 | |||
1543 | 75 | +struct initrd_media_device_path { | ||
1544 | 76 | + grub_efi_vendor_media_device_path_t vendor; | ||
1545 | 77 | + grub_efi_device_path_t end; | ||
1546 | 78 | +} GRUB_PACKED; | ||
1547 | 79 | + | ||
1548 | 80 | +#define LINUX_EFI_INITRD_MEDIA_GUID \ | ||
1549 | 81 | + { 0x5568e427, 0x68fc, 0x4f3d, \ | ||
1550 | 82 | + { 0xac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68 } \ | ||
1551 | 83 | + } | ||
1552 | 84 | + | ||
1553 | 85 | +static struct initrd_media_device_path initrd_lf2_device_path = { | ||
1554 | 86 | + { | ||
1555 | 87 | + { | ||
1556 | 88 | + GRUB_EFI_MEDIA_DEVICE_PATH_TYPE, | ||
1557 | 89 | + GRUB_EFI_VENDOR_MEDIA_DEVICE_PATH_SUBTYPE, | ||
1558 | 90 | + sizeof(grub_efi_vendor_media_device_path_t), | ||
1559 | 91 | + }, | ||
1560 | 92 | + LINUX_EFI_INITRD_MEDIA_GUID | ||
1561 | 93 | + }, { | ||
1562 | 94 | + GRUB_EFI_END_DEVICE_PATH_TYPE, | ||
1563 | 95 | + GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE, | ||
1564 | 96 | + sizeof(grub_efi_device_path_t) | ||
1565 | 97 | + } | ||
1566 | 98 | +}; | ||
1567 | 99 | + | ||
1568 | 100 | +static grub_efi_status_t | ||
1569 | 101 | +grub_efi_initrd_load_file2(grub_efi_load_file2_t *this, | ||
1570 | 102 | + grub_efi_device_path_t *device_path, | ||
1571 | 103 | + grub_efi_boolean_t boot_policy, | ||
1572 | 104 | + grub_efi_uintn_t *buffer_size, | ||
1573 | 105 | + void *buffer); | ||
1574 | 106 | + | ||
1575 | 107 | +static grub_efi_load_file2_t initrd_lf2 = { | ||
1576 | 108 | + grub_efi_initrd_load_file2 | ||
1577 | 109 | +}; | ||
1578 | 110 | + | ||
1579 | 111 | +static grub_efi_status_t | ||
1580 | 112 | +grub_efi_initrd_load_file2(grub_efi_load_file2_t *this, | ||
1581 | 113 | + grub_efi_device_path_t *device_path, | ||
1582 | 114 | + grub_efi_boolean_t boot_policy, | ||
1583 | 115 | + grub_efi_uintn_t *buffer_size, | ||
1584 | 116 | + void *buffer) | ||
1585 | 117 | +{ | ||
1586 | 118 | + grub_efi_status_t status = GRUB_EFI_SUCCESS; | ||
1587 | 119 | + grub_efi_uintn_t initrd_size; | ||
1588 | 120 | + | ||
1589 | 121 | + if (!this || this != &initrd_lf2 || !buffer_size) | ||
1590 | 122 | + return GRUB_EFI_INVALID_PARAMETER; | ||
1591 | 123 | + | ||
1592 | 124 | + if (device_path->type != GRUB_EFI_END_DEVICE_PATH_TYPE || | ||
1593 | 125 | + device_path->subtype != GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE) | ||
1594 | 126 | + return GRUB_EFI_NOT_FOUND; | ||
1595 | 127 | + | ||
1596 | 128 | + if (boot_policy) | ||
1597 | 129 | + return GRUB_EFI_UNSUPPORTED; | ||
1598 | 130 | + | ||
1599 | 131 | + initrd_size = grub_get_initrd_size (&initrd_ctx); | ||
1600 | 132 | + if (!buffer || *buffer_size < initrd_size) | ||
1601 | 133 | + { | ||
1602 | 134 | + *buffer_size = initrd_size; | ||
1603 | 135 | + return GRUB_EFI_BUFFER_TOO_SMALL; | ||
1604 | 136 | + } | ||
1605 | 137 | + | ||
1606 | 138 | + grub_dprintf ("linux", "Providing initrd via LOAD_FILE2_PROTOCOL\n"); | ||
1607 | 139 | + | ||
1608 | 140 | + if (grub_initrd_load (&initrd_ctx, buffer)) | ||
1609 | 141 | + status = GRUB_EFI_LOAD_ERROR; | ||
1610 | 142 | + | ||
1611 | 143 | + grub_initrd_close (&initrd_ctx); | ||
1612 | 144 | + return status; | ||
1613 | 145 | +} | ||
1614 | 146 | + | ||
1615 | 147 | static grub_err_t | ||
1616 | 148 | grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), | ||
1617 | 149 | int argc, char *argv[]) | ||
1618 | 150 | { | ||
1619 | 151 | - struct grub_linux_initrd_context initrd_ctx = { 0, 0, 0 }; | ||
1620 | 152 | int initrd_size, initrd_pages; | ||
1621 | 153 | void *initrd_mem = NULL; | ||
1622 | 154 | + grub_efi_boot_services_t *b; | ||
1623 | 155 | + grub_efi_status_t status; | ||
1624 | 156 | |||
1625 | 157 | if (argc == 0) | ||
1626 | 158 | { | ||
1627 | 159 | @@ -254,6 +351,24 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), | ||
1628 | 160 | if (grub_initrd_init (argc, argv, &initrd_ctx)) | ||
1629 | 161 | goto fail; | ||
1630 | 162 | |||
1631 | 163 | + if (initrd_use_loadfile2 && !initrd_lf2_handle) | ||
1632 | 164 | + { | ||
1633 | 165 | + b = grub_efi_system_table->boot_services; | ||
1634 | 166 | + status = b->install_multiple_protocol_interfaces (&initrd_lf2_handle, | ||
1635 | 167 | + &load_file2_guid, | ||
1636 | 168 | + &initrd_lf2, | ||
1637 | 169 | + &device_path_guid, | ||
1638 | 170 | + &initrd_lf2_device_path, | ||
1639 | 171 | + NULL); | ||
1640 | 172 | + if (status == GRUB_EFI_OUT_OF_RESOURCES) | ||
1641 | 173 | + { | ||
1642 | 174 | + grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); | ||
1643 | 175 | + return grub_errno; | ||
1644 | 176 | + } | ||
1645 | 177 | + grub_dprintf ("linux", "LoadFile2 initrd loading protocol installed\n"); | ||
1646 | 178 | + return GRUB_ERR_NONE; | ||
1647 | 179 | + } | ||
1648 | 180 | + | ||
1649 | 181 | initrd_size = grub_get_initrd_size (&initrd_ctx); | ||
1650 | 182 | grub_dprintf ("linux", "Loading initrd\n"); | ||
1651 | 183 | |||
1652 | diff --git a/debian/patches/efi-variable-storage-minimise-writes.patch b/debian/patches/efi-variable-storage-minimise-writes.patch | |||
1653 | index 4d3d134..7609e21 100644 | |||
1654 | --- a/debian/patches/efi-variable-storage-minimise-writes.patch | |||
1655 | +++ b/debian/patches/efi-variable-storage-minimise-writes.patch | |||
1656 | @@ -179,7 +179,7 @@ index 27f9482..a3d134b 100644 | |||
1657 | 179 | 179 | ||
1658 | 180 | script = { | 180 | script = { |
1659 | 181 | diff --git a/configure.ac b/configure.ac | 181 | diff --git a/configure.ac b/configure.ac |
1661 | 182 | index e11df6b..b3fb743 100644 | 182 | index b4e33a6..d422626 100644 |
1662 | 183 | --- a/configure.ac | 183 | --- a/configure.ac |
1663 | 184 | +++ b/configure.ac | 184 | +++ b/configure.ac |
1664 | 185 | @@ -452,6 +452,18 @@ AC_CHECK_HEADER([util.h], [ | 185 | @@ -452,6 +452,18 @@ AC_CHECK_HEADER([util.h], [ |
1665 | diff --git a/debian/patches/efinet-set-dns-from-uefi-proto.patch b/debian/patches/efinet-set-dns-from-uefi-proto.patch | |||
1666 | index 4588309..03da490 100644 | |||
1667 | --- a/debian/patches/efinet-set-dns-from-uefi-proto.patch | |||
1668 | +++ b/debian/patches/efinet-set-dns-from-uefi-proto.patch | |||
1669 | @@ -245,10 +245,10 @@ index 2d3b00f..82a28fb 100644 | |||
1670 | 245 | } | 245 | } |
1671 | 246 | 246 | ||
1672 | 247 | diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h | 247 | diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h |
1674 | 248 | index 4b4652c..9cab1a5 100644 | 248 | index d67c3f1..479c2a8 100644 |
1675 | 249 | --- a/include/grub/efi/api.h | 249 | --- a/include/grub/efi/api.h |
1676 | 250 | +++ b/include/grub/efi/api.h | 250 | +++ b/include/grub/efi/api.h |
1678 | 251 | @@ -354,6 +354,16 @@ | 251 | @@ -359,6 +359,16 @@ |
1679 | 252 | { 0x86, 0x2e, 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44 } \ | 252 | { 0x86, 0x2e, 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44 } \ |
1680 | 253 | } | 253 | } |
1681 | 254 | 254 | ||
1682 | @@ -265,9 +265,9 @@ index 4b4652c..9cab1a5 100644 | |||
1683 | 265 | struct grub_efi_sal_system_table | 265 | struct grub_efi_sal_system_table |
1684 | 266 | { | 266 | { |
1685 | 267 | grub_uint32_t signature; | 267 | grub_uint32_t signature; |
1687 | 268 | @@ -1793,6 +1803,72 @@ struct grub_efi_rng_protocol | 268 | @@ -1808,6 +1818,72 @@ struct grub_efi_load_file2 |
1688 | 269 | }; | 269 | }; |
1690 | 270 | typedef struct grub_efi_rng_protocol grub_efi_rng_protocol_t; | 270 | typedef struct grub_efi_load_file2 grub_efi_load_file2_t; |
1691 | 271 | 271 | ||
1692 | 272 | +enum grub_efi_ip4_config2_data_type { | 272 | +enum grub_efi_ip4_config2_data_type { |
1693 | 273 | + GRUB_EFI_IP4_CONFIG2_DATA_TYPE_INTERFACEINFO, | 273 | + GRUB_EFI_IP4_CONFIG2_DATA_TYPE_INTERFACEINFO, |
1694 | diff --git a/debian/patches/efinet-set-network-from-uefi-devpath.patch b/debian/patches/efinet-set-network-from-uefi-devpath.patch | |||
1695 | index af95c63..bd19f83 100644 | |||
1696 | --- a/debian/patches/efinet-set-network-from-uefi-devpath.patch | |||
1697 | +++ b/debian/patches/efinet-set-network-from-uefi-devpath.patch | |||
1698 | @@ -357,10 +357,10 @@ index fc90415..2d3b00f 100644 | |||
1699 | 357 | } | 357 | } |
1700 | 358 | } | 358 | } |
1701 | 359 | diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h | 359 | diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h |
1703 | 360 | index 50ab8e8..4b4652c 100644 | 360 | index 2c649cf..d67c3f1 100644 |
1704 | 361 | --- a/include/grub/efi/api.h | 361 | --- a/include/grub/efi/api.h |
1705 | 362 | +++ b/include/grub/efi/api.h | 362 | +++ b/include/grub/efi/api.h |
1707 | 363 | @@ -849,6 +849,8 @@ struct grub_efi_ipv4_device_path | 363 | @@ -854,6 +854,8 @@ struct grub_efi_ipv4_device_path |
1708 | 364 | grub_efi_uint16_t remote_port; | 364 | grub_efi_uint16_t remote_port; |
1709 | 365 | grub_efi_uint16_t protocol; | 365 | grub_efi_uint16_t protocol; |
1710 | 366 | grub_efi_uint8_t static_ip_address; | 366 | grub_efi_uint8_t static_ip_address; |
1711 | @@ -369,7 +369,7 @@ index 50ab8e8..4b4652c 100644 | |||
1712 | 369 | } GRUB_PACKED; | 369 | } GRUB_PACKED; |
1713 | 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; |
1714 | 371 | 371 | ||
1716 | 372 | @@ -903,6 +905,15 @@ struct grub_efi_sata_device_path | 372 | @@ -908,6 +910,15 @@ struct grub_efi_sata_device_path |
1717 | 373 | } GRUB_PACKED; | 373 | } GRUB_PACKED; |
1718 | 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; |
1719 | 375 | 375 | ||
1720 | diff --git a/debian/patches/efinet-uefi-ipv6-pxe-support.patch b/debian/patches/efinet-uefi-ipv6-pxe-support.patch | |||
1721 | index 13f69ed..d256127 100644 | |||
1722 | --- a/debian/patches/efinet-uefi-ipv6-pxe-support.patch | |||
1723 | +++ b/debian/patches/efinet-uefi-ipv6-pxe-support.patch | |||
1724 | @@ -51,10 +51,10 @@ index 5388f95..fc90415 100644 | |||
1725 | 51 | } | 51 | } |
1726 | 52 | } | 52 | } |
1727 | 53 | diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h | 53 | diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h |
1729 | 54 | index f1a5221..50ab8e8 100644 | 54 | index 3de0a7d..2c649cf 100644 |
1730 | 55 | --- a/include/grub/efi/api.h | 55 | --- a/include/grub/efi/api.h |
1731 | 56 | +++ b/include/grub/efi/api.h | 56 | +++ b/include/grub/efi/api.h |
1733 | 57 | @@ -1476,14 +1476,67 @@ typedef struct grub_efi_simple_text_output_interface grub_efi_simple_text_output | 57 | @@ -1481,14 +1481,67 @@ typedef struct grub_efi_simple_text_output_interface grub_efi_simple_text_output |
1734 | 58 | 58 | ||
1735 | 59 | typedef grub_uint8_t grub_efi_pxe_packet_t[1472]; | 59 | typedef grub_uint8_t grub_efi_pxe_packet_t[1472]; |
1736 | 60 | 60 | ||
1737 | diff --git a/debian/patches/fat-fix-listing-the-root-directory.patch b/debian/patches/fat-fix-listing-the-root-directory.patch | |||
1738 | 61 | new file mode 100644 | 61 | new file mode 100644 |
1739 | index 0000000..335ec4c | |||
1740 | --- /dev/null | |||
1741 | +++ b/debian/patches/fat-fix-listing-the-root-directory.patch | |||
1742 | @@ -0,0 +1,46 @@ | |||
1743 | 1 | From: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> | ||
1744 | 2 | Date: Fri, 21 Jan 2022 20:15:41 +0100 | ||
1745 | 3 | Subject: fat: fix listing the root directory | ||
1746 | 4 | |||
1747 | 5 | ls / for a FAT partition leads to | ||
1748 | 6 | |||
1749 | 7 | error: invalid modification timestamp for /. | ||
1750 | 8 | |||
1751 | 9 | Not all entries of the directory are displayed. | ||
1752 | 10 | |||
1753 | 11 | Linux never updates the modification timestamp of the /. directory entry. | ||
1754 | 12 | The FAT specification allows the access and creation date fields to be | ||
1755 | 13 | zero. | ||
1756 | 14 | |||
1757 | 15 | We should follow Linux and render initial FAT timestamps as start of | ||
1758 | 16 | the epoch. | ||
1759 | 17 | |||
1760 | 18 | Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> | ||
1761 | 19 | Origin: https://lists.gnu.org/archive/html/grub-devel/2022-01/msg00116.html | ||
1762 | 20 | --- | ||
1763 | 21 | grub-core/fs/fat.c | 12 ++++++++++++ | ||
1764 | 22 | 1 file changed, 12 insertions(+) | ||
1765 | 23 | |||
1766 | 24 | diff --git a/grub-core/fs/fat.c b/grub-core/fs/fat.c | ||
1767 | 25 | index dd82e4e..35ff0b2 100644 | ||
1768 | 26 | --- a/grub-core/fs/fat.c | ||
1769 | 27 | +++ b/grub-core/fs/fat.c | ||
1770 | 28 | @@ -901,6 +901,18 @@ grub_fat_timestamp (grub_uint16_t time, grub_uint16_t date, grub_int64_t *nix) { | ||
1771 | 29 | .second = (time & 0x001F) * 2, | ||
1772 | 30 | }; | ||
1773 | 31 | |||
1774 | 32 | + /* | ||
1775 | 33 | + * The modification time of the root directory is never set by Linux. | ||
1776 | 34 | + * Creation and access time are optional and can be zero. | ||
1777 | 35 | + * Follow Linux and render FAT initial timestamps as the start of the epoch. | ||
1778 | 36 | + */ | ||
1779 | 37 | + if (date == 0 && time == 0) | ||
1780 | 38 | + { | ||
1781 | 39 | + datetime.year = 1970; | ||
1782 | 40 | + datetime.month = 1; | ||
1783 | 41 | + datetime.day = 1; | ||
1784 | 42 | + } | ||
1785 | 43 | + | ||
1786 | 44 | /* The conversion below allows seconds=60, so don't trust its validation. */ | ||
1787 | 45 | if ((time & 0x1F) > 29) | ||
1788 | 46 | return 0; | ||
1789 | diff --git a/debian/patches/gfxpayload-dynamic.patch b/debian/patches/gfxpayload-dynamic.patch | |||
1790 | index 0148257..e59cb02 100644 | |||
1791 | --- a/debian/patches/gfxpayload-dynamic.patch | |||
1792 | +++ b/debian/patches/gfxpayload-dynamic.patch | |||
1793 | @@ -21,10 +21,10 @@ Patch-Name: gfxpayload-dynamic.patch | |||
1794 | 21 | create mode 100644 grub-core/commands/i386/pc/hwmatch.c | 21 | create mode 100644 grub-core/commands/i386/pc/hwmatch.c |
1795 | 22 | 22 | ||
1796 | 23 | diff --git a/configure.ac b/configure.ac | 23 | diff --git a/configure.ac b/configure.ac |
1798 | 24 | index c42e4c7..947fd52 100644 | 24 | index 4882eba..3203749 100644 |
1799 | 25 | --- a/configure.ac | 25 | --- a/configure.ac |
1800 | 26 | +++ b/configure.ac | 26 | +++ b/configure.ac |
1802 | 27 | @@ -1937,6 +1937,17 @@ else | 27 | @@ -1945,6 +1945,17 @@ else |
1803 | 28 | fi | 28 | fi |
1804 | 29 | AC_SUBST([QUICK_BOOT]) | 29 | AC_SUBST([QUICK_BOOT]) |
1805 | 30 | 30 | ||
1806 | @@ -43,7 +43,7 @@ index c42e4c7..947fd52 100644 | |||
1807 | 43 | 43 | ||
1808 | 44 | AC_SUBST([FONT_SOURCE]) | 44 | AC_SUBST([FONT_SOURCE]) |
1809 | 45 | diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def | 45 | diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def |
1811 | 46 | index 715d137..10f839b 100644 | 46 | index 1a3ead6..0d7bce1 100644 |
1812 | 47 | --- a/grub-core/Makefile.core.def | 47 | --- a/grub-core/Makefile.core.def |
1813 | 48 | +++ b/grub-core/Makefile.core.def | 48 | +++ b/grub-core/Makefile.core.def |
1814 | 49 | @@ -964,6 +964,14 @@ module = { | 49 | @@ -964,6 +964,14 @@ module = { |
1815 | 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 | |||
1816 | 50 | new file mode 100644 | 50 | new file mode 100644 |
1817 | index 0000000..a37aea4 | |||
1818 | --- /dev/null | |||
1819 | +++ b/debian/patches/linux-ignore-FDT-unless-we-need-to-modify-it.patch | |||
1820 | @@ -0,0 +1,80 @@ | |||
1821 | 1 | From: Ard Biesheuvel <ard.biesheuvel@arm.com> | ||
1822 | 2 | Date: Thu, 28 Oct 2021 23:31:17 +0300 | ||
1823 | 3 | Subject: linux: ignore FDT unless we need to modify it | ||
1824 | 4 | |||
1825 | 5 | Now that we implemented supported for the LoadFile2 protocol for initrd | ||
1826 | 6 | loading, there is no longer a need to pass the initrd parameters via | ||
1827 | 7 | the device tree. This means there is no longer a reason to update the | ||
1828 | 8 | device tree in the first place, and so we can ignore it entirely. | ||
1829 | 9 | |||
1830 | 10 | The only remaining reason to deal with the devicetree is if we are | ||
1831 | 11 | using the 'devicetree' command to load one from disk, so tweak the | ||
1832 | 12 | logic in grub_fdt_install() to take that into account. | ||
1833 | 13 | |||
1834 | 14 | Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com> | ||
1835 | 15 | Origin: https://lists.gnu.org/archive/html/grub-devel/2021-10/msg00216.html | ||
1836 | 16 | --- | ||
1837 | 17 | grub-core/loader/arm64/linux.c | 22 +++++++++++----------- | ||
1838 | 18 | grub-core/loader/efi/fdt.c | 7 +++++-- | ||
1839 | 19 | 2 files changed, 16 insertions(+), 13 deletions(-) | ||
1840 | 20 | |||
1841 | 21 | diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c | ||
1842 | 22 | index 6b03455..65f1275 100644 | ||
1843 | 23 | --- a/grub-core/loader/arm64/linux.c | ||
1844 | 24 | +++ b/grub-core/loader/arm64/linux.c | ||
1845 | 25 | @@ -95,21 +95,21 @@ finalize_params_linux (void) | ||
1846 | 26 | |||
1847 | 27 | void *fdt; | ||
1848 | 28 | |||
1849 | 29 | - fdt = grub_fdt_load (GRUB_EFI_LINUX_FDT_EXTRA_SPACE); | ||
1850 | 30 | + /* Set initrd info */ | ||
1851 | 31 | + if (initrd_start && initrd_end > initrd_start) | ||
1852 | 32 | + { | ||
1853 | 33 | + fdt = grub_fdt_load (GRUB_EFI_LINUX_FDT_EXTRA_SPACE); | ||
1854 | 34 | |||
1855 | 35 | - if (!fdt) | ||
1856 | 36 | - goto failure; | ||
1857 | 37 | + if (!fdt) | ||
1858 | 38 | + goto failure; | ||
1859 | 39 | |||
1860 | 40 | - node = grub_fdt_find_subnode (fdt, 0, "chosen"); | ||
1861 | 41 | - if (node < 0) | ||
1862 | 42 | - node = grub_fdt_add_subnode (fdt, 0, "chosen"); | ||
1863 | 43 | + node = grub_fdt_find_subnode (fdt, 0, "chosen"); | ||
1864 | 44 | + if (node < 0) | ||
1865 | 45 | + node = grub_fdt_add_subnode (fdt, 0, "chosen"); | ||
1866 | 46 | |||
1867 | 47 | - if (node < 1) | ||
1868 | 48 | - goto failure; | ||
1869 | 49 | + if (node < 1) | ||
1870 | 50 | + goto failure; | ||
1871 | 51 | |||
1872 | 52 | - /* Set initrd info */ | ||
1873 | 53 | - if (initrd_start && initrd_end > initrd_start) | ||
1874 | 54 | - { | ||
1875 | 55 | grub_dprintf ("linux", "Initrd @ %p-%p\n", | ||
1876 | 56 | (void *) initrd_start, (void *) initrd_end); | ||
1877 | 57 | |||
1878 | 58 | diff --git a/grub-core/loader/efi/fdt.c b/grub-core/loader/efi/fdt.c | ||
1879 | 59 | index c86f283..771d455 100644 | ||
1880 | 60 | --- a/grub-core/loader/efi/fdt.c | ||
1881 | 61 | +++ b/grub-core/loader/efi/fdt.c | ||
1882 | 62 | @@ -89,13 +89,16 @@ grub_fdt_install (void) | ||
1883 | 63 | grub_efi_guid_t fdt_guid = GRUB_EFI_DEVICE_TREE_GUID; | ||
1884 | 64 | grub_efi_status_t status; | ||
1885 | 65 | |||
1886 | 66 | + if (!fdt && !loaded_fdt) | ||
1887 | 67 | + return GRUB_ERR_NONE; | ||
1888 | 68 | + | ||
1889 | 69 | b = grub_efi_system_table->boot_services; | ||
1890 | 70 | - status = b->install_configuration_table (&fdt_guid, fdt); | ||
1891 | 71 | + status = b->install_configuration_table (&fdt_guid, fdt ?: loaded_fdt); | ||
1892 | 72 | if (status != GRUB_EFI_SUCCESS) | ||
1893 | 73 | return grub_error (GRUB_ERR_IO, "failed to install FDT"); | ||
1894 | 74 | |||
1895 | 75 | grub_dprintf ("fdt", "Installed/updated FDT configuration table @ %p\n", | ||
1896 | 76 | - fdt); | ||
1897 | 77 | + fdt ?: loaded_fdt); | ||
1898 | 78 | return GRUB_ERR_NONE; | ||
1899 | 79 | } | ||
1900 | 80 | |||
1901 | 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 | |||
1902 | 0 | new file mode 100644 | 81 | new file mode 100644 |
1903 | index 0000000..0cf0470 | |||
1904 | --- /dev/null | |||
1905 | +++ b/debian/patches/loader-Move-arm64-linux-loader-to-common-code.patch | |||
1906 | @@ -0,0 +1,1091 @@ | |||
1907 | 1 | From: Atish Patra <atish.patra@wdc.com> | ||
1908 | 2 | Date: Thu, 28 Oct 2021 23:31:18 +0300 | ||
1909 | 3 | Subject: loader: Move arm64 linux loader to common code | ||
1910 | 4 | |||
1911 | 5 | ARM64 linux loader code is written in such a way that it can be reused | ||
1912 | 6 | across different architectures without much change. Move it to common | ||
1913 | 7 | code so that RISC-V doesn't have to define a separate loader. | ||
1914 | 8 | |||
1915 | 9 | Signed-off-by: Atish Patra <atish.patra@wdc.com> | ||
1916 | 10 | Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com> | ||
1917 | 11 | Origin: https://lists.gnu.org/archive/html/grub-devel/2021-10/msg00215.html | ||
1918 | 12 | --- | ||
1919 | 13 | grub-core/Makefile.core.def | 4 +- | ||
1920 | 14 | grub-core/loader/arm64/linux.c | 508 ----------------------------------------- | ||
1921 | 15 | grub-core/loader/efi/linux.c | 508 +++++++++++++++++++++++++++++++++++++++++ | ||
1922 | 16 | include/grub/arm/linux.h | 2 +- | ||
1923 | 17 | include/grub/arm64/linux.h | 2 +- | ||
1924 | 18 | 5 files changed, 512 insertions(+), 512 deletions(-) | ||
1925 | 19 | delete mode 100644 grub-core/loader/arm64/linux.c | ||
1926 | 20 | create mode 100644 grub-core/loader/efi/linux.c | ||
1927 | 21 | |||
1928 | 22 | diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def | ||
1929 | 23 | index 8022e1c..b36cf66 100644 | ||
1930 | 24 | --- a/grub-core/Makefile.core.def | ||
1931 | 25 | +++ b/grub-core/Makefile.core.def | ||
1932 | 26 | @@ -1806,9 +1806,9 @@ module = { | ||
1933 | 27 | sparc64_ieee1275 = loader/sparc64/ieee1275/linux.c; | ||
1934 | 28 | ia64_efi = loader/ia64/efi/linux.c; | ||
1935 | 29 | arm_coreboot = loader/arm/linux.c; | ||
1936 | 30 | - arm_efi = loader/arm64/linux.c; | ||
1937 | 31 | + arm_efi = loader/efi/linux.c; | ||
1938 | 32 | arm_uboot = loader/arm/linux.c; | ||
1939 | 33 | - arm64 = loader/arm64/linux.c; | ||
1940 | 34 | + arm64 = loader/efi/linux.c; | ||
1941 | 35 | riscv32 = loader/riscv/linux.c; | ||
1942 | 36 | riscv64 = loader/riscv/linux.c; | ||
1943 | 37 | common = loader/linux.c; | ||
1944 | 38 | diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c | ||
1945 | 39 | deleted file mode 100644 | ||
1946 | 40 | index 65f1275..0000000 | ||
1947 | 41 | --- a/grub-core/loader/arm64/linux.c | ||
1948 | 42 | +++ /dev/null | ||
1949 | 43 | @@ -1,508 +0,0 @@ | ||
1950 | 44 | -/* | ||
1951 | 45 | - * GRUB -- GRand Unified Bootloader | ||
1952 | 46 | - * Copyright (C) 2013 Free Software Foundation, Inc. | ||
1953 | 47 | - * | ||
1954 | 48 | - * GRUB is free software: you can redistribute it and/or modify | ||
1955 | 49 | - * it under the terms of the GNU General Public License as published by | ||
1956 | 50 | - * the Free Software Foundation, either version 3 of the License, or | ||
1957 | 51 | - * (at your option) any later version. | ||
1958 | 52 | - * | ||
1959 | 53 | - * GRUB is distributed in the hope that it will be useful, | ||
1960 | 54 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1961 | 55 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1962 | 56 | - * GNU General Public License for more details. | ||
1963 | 57 | - * | ||
1964 | 58 | - * You should have received a copy of the GNU General Public License | ||
1965 | 59 | - * along with GRUB. If not, see <http://www.gnu.org/licenses/>. | ||
1966 | 60 | - */ | ||
1967 | 61 | - | ||
1968 | 62 | -#include <grub/charset.h> | ||
1969 | 63 | -#include <grub/command.h> | ||
1970 | 64 | -#include <grub/err.h> | ||
1971 | 65 | -#include <grub/file.h> | ||
1972 | 66 | -#include <grub/fdt.h> | ||
1973 | 67 | -#include <grub/linux.h> | ||
1974 | 68 | -#include <grub/loader.h> | ||
1975 | 69 | -#include <grub/mm.h> | ||
1976 | 70 | -#include <grub/types.h> | ||
1977 | 71 | -#include <grub/cpu/linux.h> | ||
1978 | 72 | -#include <grub/efi/efi.h> | ||
1979 | 73 | -#include <grub/efi/fdtload.h> | ||
1980 | 74 | -#include <grub/efi/memory.h> | ||
1981 | 75 | -#include <grub/efi/pe32.h> | ||
1982 | 76 | -#include <grub/i18n.h> | ||
1983 | 77 | -#include <grub/lib/cmdline.h> | ||
1984 | 78 | -#include <grub/verify.h> | ||
1985 | 79 | - | ||
1986 | 80 | -GRUB_MOD_LICENSE ("GPLv3+"); | ||
1987 | 81 | - | ||
1988 | 82 | -static grub_dl_t my_mod; | ||
1989 | 83 | -static int loaded; | ||
1990 | 84 | - | ||
1991 | 85 | -static void *kernel_addr; | ||
1992 | 86 | -static grub_uint64_t kernel_size; | ||
1993 | 87 | - | ||
1994 | 88 | -static char *linux_args; | ||
1995 | 89 | -static grub_uint32_t cmdline_size; | ||
1996 | 90 | - | ||
1997 | 91 | -static grub_addr_t initrd_start; | ||
1998 | 92 | -static grub_addr_t initrd_end; | ||
1999 | 93 | - | ||
2000 | 94 | -static struct grub_linux_initrd_context initrd_ctx = { 0, 0, 0 }; | ||
2001 | 95 | -static grub_efi_handle_t initrd_lf2_handle; | ||
2002 | 96 | -static int initrd_use_loadfile2; | ||
2003 | 97 | -static grub_efi_guid_t load_file2_guid = GRUB_EFI_LOAD_FILE2_PROTOCOL_GUID; | ||
2004 | 98 | -static grub_efi_guid_t device_path_guid = GRUB_EFI_DEVICE_PATH_GUID; | ||
2005 | 99 | - | ||
2006 | 100 | -grub_err_t | ||
2007 | 101 | -grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh) | ||
2008 | 102 | -{ | ||
2009 | 103 | - struct grub_pe32_coff_header *coff_header; | ||
2010 | 104 | - struct grub_pe32_optional_header *optional_header; | ||
2011 | 105 | - | ||
2012 | 106 | - if (lh->magic != GRUB_LINUX_ARMXX_MAGIC_SIGNATURE) | ||
2013 | 107 | - return grub_error(GRUB_ERR_BAD_OS, "invalid magic number"); | ||
2014 | 108 | - | ||
2015 | 109 | - if ((lh->code0 & 0xffff) != GRUB_PE32_MAGIC) | ||
2016 | 110 | - return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, | ||
2017 | 111 | - N_("plain image kernel not supported - rebuild with CONFIG_(U)EFI_STUB enabled")); | ||
2018 | 112 | - | ||
2019 | 113 | - grub_dprintf ("linux", "UEFI stub kernel:\n"); | ||
2020 | 114 | - grub_dprintf ("linux", "PE/COFF header @ %08x\n", lh->hdr_offset); | ||
2021 | 115 | - | ||
2022 | 116 | - coff_header = (struct grub_pe32_coff_header *)((unsigned long)lh + lh->hdr_offset); | ||
2023 | 117 | - optional_header = (struct grub_pe32_optional_header *)(coff_header + 1); | ||
2024 | 118 | - | ||
2025 | 119 | - /* | ||
2026 | 120 | - * Linux kernels built for any architecture are guaranteed to support the | ||
2027 | 121 | - * LoadFile2 based initrd loading protocol if the image version is >= 1. | ||
2028 | 122 | - */ | ||
2029 | 123 | - if (optional_header->major_image_version >= 1) | ||
2030 | 124 | - initrd_use_loadfile2 = 1; | ||
2031 | 125 | - else | ||
2032 | 126 | - initrd_use_loadfile2 = 0; | ||
2033 | 127 | - | ||
2034 | 128 | - grub_dprintf ("linux", "LoadFile2 initrd loading %sabled\n", | ||
2035 | 129 | - initrd_use_loadfile2 ? "en" : "dis"); | ||
2036 | 130 | - | ||
2037 | 131 | - return GRUB_ERR_NONE; | ||
2038 | 132 | -} | ||
2039 | 133 | - | ||
2040 | 134 | -static grub_err_t | ||
2041 | 135 | -finalize_params_linux (void) | ||
2042 | 136 | -{ | ||
2043 | 137 | - int node, retval; | ||
2044 | 138 | - | ||
2045 | 139 | - void *fdt; | ||
2046 | 140 | - | ||
2047 | 141 | - /* Set initrd info */ | ||
2048 | 142 | - if (initrd_start && initrd_end > initrd_start) | ||
2049 | 143 | - { | ||
2050 | 144 | - fdt = grub_fdt_load (GRUB_EFI_LINUX_FDT_EXTRA_SPACE); | ||
2051 | 145 | - | ||
2052 | 146 | - if (!fdt) | ||
2053 | 147 | - goto failure; | ||
2054 | 148 | - | ||
2055 | 149 | - node = grub_fdt_find_subnode (fdt, 0, "chosen"); | ||
2056 | 150 | - if (node < 0) | ||
2057 | 151 | - node = grub_fdt_add_subnode (fdt, 0, "chosen"); | ||
2058 | 152 | - | ||
2059 | 153 | - if (node < 1) | ||
2060 | 154 | - goto failure; | ||
2061 | 155 | - | ||
2062 | 156 | - grub_dprintf ("linux", "Initrd @ %p-%p\n", | ||
2063 | 157 | - (void *) initrd_start, (void *) initrd_end); | ||
2064 | 158 | - | ||
2065 | 159 | - retval = grub_fdt_set_prop64 (fdt, node, "linux,initrd-start", | ||
2066 | 160 | - initrd_start); | ||
2067 | 161 | - if (retval) | ||
2068 | 162 | - goto failure; | ||
2069 | 163 | - retval = grub_fdt_set_prop64 (fdt, node, "linux,initrd-end", | ||
2070 | 164 | - initrd_end); | ||
2071 | 165 | - if (retval) | ||
2072 | 166 | - goto failure; | ||
2073 | 167 | - } | ||
2074 | 168 | - | ||
2075 | 169 | - if (grub_fdt_install() != GRUB_ERR_NONE) | ||
2076 | 170 | - goto failure; | ||
2077 | 171 | - | ||
2078 | 172 | - return GRUB_ERR_NONE; | ||
2079 | 173 | - | ||
2080 | 174 | -failure: | ||
2081 | 175 | - grub_fdt_unload(); | ||
2082 | 176 | - return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT"); | ||
2083 | 177 | -} | ||
2084 | 178 | - | ||
2085 | 179 | -grub_err_t | ||
2086 | 180 | -grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args) | ||
2087 | 181 | -{ | ||
2088 | 182 | - grub_efi_memory_mapped_device_path_t *mempath; | ||
2089 | 183 | - grub_efi_handle_t image_handle; | ||
2090 | 184 | - grub_efi_boot_services_t *b; | ||
2091 | 185 | - grub_efi_status_t status; | ||
2092 | 186 | - grub_efi_loaded_image_t *loaded_image; | ||
2093 | 187 | - int len; | ||
2094 | 188 | - | ||
2095 | 189 | - mempath = grub_malloc (2 * sizeof (grub_efi_memory_mapped_device_path_t)); | ||
2096 | 190 | - if (!mempath) | ||
2097 | 191 | - return grub_errno; | ||
2098 | 192 | - | ||
2099 | 193 | - mempath[0].header.type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE; | ||
2100 | 194 | - mempath[0].header.subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE; | ||
2101 | 195 | - mempath[0].header.length = grub_cpu_to_le16_compile_time (sizeof (*mempath)); | ||
2102 | 196 | - mempath[0].memory_type = GRUB_EFI_LOADER_DATA; | ||
2103 | 197 | - mempath[0].start_address = addr; | ||
2104 | 198 | - mempath[0].end_address = addr + size; | ||
2105 | 199 | - | ||
2106 | 200 | - mempath[1].header.type = GRUB_EFI_END_DEVICE_PATH_TYPE; | ||
2107 | 201 | - mempath[1].header.subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; | ||
2108 | 202 | - mempath[1].header.length = sizeof (grub_efi_device_path_t); | ||
2109 | 203 | - | ||
2110 | 204 | - b = grub_efi_system_table->boot_services; | ||
2111 | 205 | - status = b->load_image (0, grub_efi_image_handle, | ||
2112 | 206 | - (grub_efi_device_path_t *) mempath, | ||
2113 | 207 | - (void *) addr, size, &image_handle); | ||
2114 | 208 | - if (status != GRUB_EFI_SUCCESS) | ||
2115 | 209 | - return grub_error (GRUB_ERR_BAD_OS, "cannot load image"); | ||
2116 | 210 | - | ||
2117 | 211 | - grub_dprintf ("linux", "linux command line: '%s'\n", args); | ||
2118 | 212 | - | ||
2119 | 213 | - /* Convert command line to UCS-2 */ | ||
2120 | 214 | - loaded_image = grub_efi_get_loaded_image (image_handle); | ||
2121 | 215 | - loaded_image->load_options_size = len = | ||
2122 | 216 | - (grub_strlen (args) + 1) * sizeof (grub_efi_char16_t); | ||
2123 | 217 | - loaded_image->load_options = | ||
2124 | 218 | - grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); | ||
2125 | 219 | - if (!loaded_image->load_options) | ||
2126 | 220 | - return grub_errno; | ||
2127 | 221 | - | ||
2128 | 222 | - loaded_image->load_options_size = | ||
2129 | 223 | - 2 * grub_utf8_to_utf16 (loaded_image->load_options, len, | ||
2130 | 224 | - (grub_uint8_t *) args, len, NULL); | ||
2131 | 225 | - | ||
2132 | 226 | - grub_dprintf ("linux", "starting image %p\n", image_handle); | ||
2133 | 227 | - status = b->start_image (image_handle, 0, NULL); | ||
2134 | 228 | - | ||
2135 | 229 | - /* When successful, not reached */ | ||
2136 | 230 | - b->unload_image (image_handle); | ||
2137 | 231 | - grub_efi_free_pages ((grub_addr_t) loaded_image->load_options, | ||
2138 | 232 | - GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); | ||
2139 | 233 | - | ||
2140 | 234 | - return grub_errno; | ||
2141 | 235 | -} | ||
2142 | 236 | - | ||
2143 | 237 | -static grub_err_t | ||
2144 | 238 | -grub_linux_boot (void) | ||
2145 | 239 | -{ | ||
2146 | 240 | - if (finalize_params_linux () != GRUB_ERR_NONE) | ||
2147 | 241 | - return grub_errno; | ||
2148 | 242 | - | ||
2149 | 243 | - return (grub_arch_efi_linux_boot_image((grub_addr_t)kernel_addr, | ||
2150 | 244 | - kernel_size, linux_args)); | ||
2151 | 245 | -} | ||
2152 | 246 | - | ||
2153 | 247 | -static grub_err_t | ||
2154 | 248 | -grub_linux_unload (void) | ||
2155 | 249 | -{ | ||
2156 | 250 | - grub_dl_unref (my_mod); | ||
2157 | 251 | - loaded = 0; | ||
2158 | 252 | - if (initrd_start) | ||
2159 | 253 | - grub_efi_free_pages ((grub_efi_physical_address_t) initrd_start, | ||
2160 | 254 | - GRUB_EFI_BYTES_TO_PAGES (initrd_end - initrd_start)); | ||
2161 | 255 | - initrd_start = initrd_end = 0; | ||
2162 | 256 | - grub_free (linux_args); | ||
2163 | 257 | - if (kernel_addr) | ||
2164 | 258 | - grub_efi_free_pages ((grub_addr_t) kernel_addr, | ||
2165 | 259 | - GRUB_EFI_BYTES_TO_PAGES (kernel_size)); | ||
2166 | 260 | - grub_fdt_unload (); | ||
2167 | 261 | - return GRUB_ERR_NONE; | ||
2168 | 262 | -} | ||
2169 | 263 | - | ||
2170 | 264 | -/* | ||
2171 | 265 | - * As per linux/Documentation/arm/Booting | ||
2172 | 266 | - * ARM initrd needs to be covered by kernel linear mapping, | ||
2173 | 267 | - * so place it in the first 512MB of DRAM. | ||
2174 | 268 | - * | ||
2175 | 269 | - * As per linux/Documentation/arm64/booting.txt | ||
2176 | 270 | - * ARM64 initrd needs to be contained entirely within a 1GB aligned window | ||
2177 | 271 | - * of up to 32GB of size that covers the kernel image as well. | ||
2178 | 272 | - * Since the EFI stub loader will attempt to load the kernel near start of | ||
2179 | 273 | - * RAM, place the buffer in the first 32GB of RAM. | ||
2180 | 274 | - */ | ||
2181 | 275 | -#ifdef __arm__ | ||
2182 | 276 | -#define INITRD_MAX_ADDRESS_OFFSET (512U * 1024 * 1024) | ||
2183 | 277 | -#else /* __aarch64__ */ | ||
2184 | 278 | -#define INITRD_MAX_ADDRESS_OFFSET (32ULL * 1024 * 1024 * 1024) | ||
2185 | 279 | -#endif | ||
2186 | 280 | - | ||
2187 | 281 | -/* | ||
2188 | 282 | - * This function returns a pointer to a legally allocated initrd buffer, | ||
2189 | 283 | - * or NULL if unsuccessful | ||
2190 | 284 | - */ | ||
2191 | 285 | -static void * | ||
2192 | 286 | -allocate_initrd_mem (int initrd_pages) | ||
2193 | 287 | -{ | ||
2194 | 288 | - grub_addr_t max_addr; | ||
2195 | 289 | - | ||
2196 | 290 | - if (grub_efi_get_ram_base (&max_addr) != GRUB_ERR_NONE) | ||
2197 | 291 | - return NULL; | ||
2198 | 292 | - | ||
2199 | 293 | - max_addr += INITRD_MAX_ADDRESS_OFFSET - 1; | ||
2200 | 294 | - | ||
2201 | 295 | - return grub_efi_allocate_pages_real (max_addr, initrd_pages, | ||
2202 | 296 | - GRUB_EFI_ALLOCATE_MAX_ADDRESS, | ||
2203 | 297 | - GRUB_EFI_LOADER_DATA); | ||
2204 | 298 | -} | ||
2205 | 299 | - | ||
2206 | 300 | -struct initrd_media_device_path { | ||
2207 | 301 | - grub_efi_vendor_media_device_path_t vendor; | ||
2208 | 302 | - grub_efi_device_path_t end; | ||
2209 | 303 | -} GRUB_PACKED; | ||
2210 | 304 | - | ||
2211 | 305 | -#define LINUX_EFI_INITRD_MEDIA_GUID \ | ||
2212 | 306 | - { 0x5568e427, 0x68fc, 0x4f3d, \ | ||
2213 | 307 | - { 0xac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68 } \ | ||
2214 | 308 | - } | ||
2215 | 309 | - | ||
2216 | 310 | -static struct initrd_media_device_path initrd_lf2_device_path = { | ||
2217 | 311 | - { | ||
2218 | 312 | - { | ||
2219 | 313 | - GRUB_EFI_MEDIA_DEVICE_PATH_TYPE, | ||
2220 | 314 | - GRUB_EFI_VENDOR_MEDIA_DEVICE_PATH_SUBTYPE, | ||
2221 | 315 | - sizeof(grub_efi_vendor_media_device_path_t), | ||
2222 | 316 | - }, | ||
2223 | 317 | - LINUX_EFI_INITRD_MEDIA_GUID | ||
2224 | 318 | - }, { | ||
2225 | 319 | - GRUB_EFI_END_DEVICE_PATH_TYPE, | ||
2226 | 320 | - GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE, | ||
2227 | 321 | - sizeof(grub_efi_device_path_t) | ||
2228 | 322 | - } | ||
2229 | 323 | -}; | ||
2230 | 324 | - | ||
2231 | 325 | -static grub_efi_status_t | ||
2232 | 326 | -grub_efi_initrd_load_file2(grub_efi_load_file2_t *this, | ||
2233 | 327 | - grub_efi_device_path_t *device_path, | ||
2234 | 328 | - grub_efi_boolean_t boot_policy, | ||
2235 | 329 | - grub_efi_uintn_t *buffer_size, | ||
2236 | 330 | - void *buffer); | ||
2237 | 331 | - | ||
2238 | 332 | -static grub_efi_load_file2_t initrd_lf2 = { | ||
2239 | 333 | - grub_efi_initrd_load_file2 | ||
2240 | 334 | -}; | ||
2241 | 335 | - | ||
2242 | 336 | -static grub_efi_status_t | ||
2243 | 337 | -grub_efi_initrd_load_file2(grub_efi_load_file2_t *this, | ||
2244 | 338 | - grub_efi_device_path_t *device_path, | ||
2245 | 339 | - grub_efi_boolean_t boot_policy, | ||
2246 | 340 | - grub_efi_uintn_t *buffer_size, | ||
2247 | 341 | - void *buffer) | ||
2248 | 342 | -{ | ||
2249 | 343 | - grub_efi_status_t status = GRUB_EFI_SUCCESS; | ||
2250 | 344 | - grub_efi_uintn_t initrd_size; | ||
2251 | 345 | - | ||
2252 | 346 | - if (!this || this != &initrd_lf2 || !buffer_size) | ||
2253 | 347 | - return GRUB_EFI_INVALID_PARAMETER; | ||
2254 | 348 | - | ||
2255 | 349 | - if (device_path->type != GRUB_EFI_END_DEVICE_PATH_TYPE || | ||
2256 | 350 | - device_path->subtype != GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE) | ||
2257 | 351 | - return GRUB_EFI_NOT_FOUND; | ||
2258 | 352 | - | ||
2259 | 353 | - if (boot_policy) | ||
2260 | 354 | - return GRUB_EFI_UNSUPPORTED; | ||
2261 | 355 | - | ||
2262 | 356 | - initrd_size = grub_get_initrd_size (&initrd_ctx); | ||
2263 | 357 | - if (!buffer || *buffer_size < initrd_size) | ||
2264 | 358 | - { | ||
2265 | 359 | - *buffer_size = initrd_size; | ||
2266 | 360 | - return GRUB_EFI_BUFFER_TOO_SMALL; | ||
2267 | 361 | - } | ||
2268 | 362 | - | ||
2269 | 363 | - grub_dprintf ("linux", "Providing initrd via LOAD_FILE2_PROTOCOL\n"); | ||
2270 | 364 | - | ||
2271 | 365 | - if (grub_initrd_load (&initrd_ctx, buffer)) | ||
2272 | 366 | - status = GRUB_EFI_LOAD_ERROR; | ||
2273 | 367 | - | ||
2274 | 368 | - grub_initrd_close (&initrd_ctx); | ||
2275 | 369 | - return status; | ||
2276 | 370 | -} | ||
2277 | 371 | - | ||
2278 | 372 | -static grub_err_t | ||
2279 | 373 | -grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), | ||
2280 | 374 | - int argc, char *argv[]) | ||
2281 | 375 | -{ | ||
2282 | 376 | - int initrd_size, initrd_pages; | ||
2283 | 377 | - void *initrd_mem = NULL; | ||
2284 | 378 | - grub_efi_boot_services_t *b; | ||
2285 | 379 | - grub_efi_status_t status; | ||
2286 | 380 | - | ||
2287 | 381 | - if (argc == 0) | ||
2288 | 382 | - { | ||
2289 | 383 | - grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); | ||
2290 | 384 | - goto fail; | ||
2291 | 385 | - } | ||
2292 | 386 | - | ||
2293 | 387 | - if (!loaded) | ||
2294 | 388 | - { | ||
2295 | 389 | - grub_error (GRUB_ERR_BAD_ARGUMENT, | ||
2296 | 390 | - N_("you need to load the kernel first")); | ||
2297 | 391 | - goto fail; | ||
2298 | 392 | - } | ||
2299 | 393 | - | ||
2300 | 394 | - if (grub_initrd_init (argc, argv, &initrd_ctx)) | ||
2301 | 395 | - goto fail; | ||
2302 | 396 | - | ||
2303 | 397 | - if (initrd_use_loadfile2 && !initrd_lf2_handle) | ||
2304 | 398 | - { | ||
2305 | 399 | - b = grub_efi_system_table->boot_services; | ||
2306 | 400 | - status = b->install_multiple_protocol_interfaces (&initrd_lf2_handle, | ||
2307 | 401 | - &load_file2_guid, | ||
2308 | 402 | - &initrd_lf2, | ||
2309 | 403 | - &device_path_guid, | ||
2310 | 404 | - &initrd_lf2_device_path, | ||
2311 | 405 | - NULL); | ||
2312 | 406 | - if (status == GRUB_EFI_OUT_OF_RESOURCES) | ||
2313 | 407 | - { | ||
2314 | 408 | - grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); | ||
2315 | 409 | - return grub_errno; | ||
2316 | 410 | - } | ||
2317 | 411 | - grub_dprintf ("linux", "LoadFile2 initrd loading protocol installed\n"); | ||
2318 | 412 | - return GRUB_ERR_NONE; | ||
2319 | 413 | - } | ||
2320 | 414 | - | ||
2321 | 415 | - initrd_size = grub_get_initrd_size (&initrd_ctx); | ||
2322 | 416 | - grub_dprintf ("linux", "Loading initrd\n"); | ||
2323 | 417 | - | ||
2324 | 418 | - initrd_pages = (GRUB_EFI_BYTES_TO_PAGES (initrd_size)); | ||
2325 | 419 | - initrd_mem = allocate_initrd_mem (initrd_pages); | ||
2326 | 420 | - | ||
2327 | 421 | - if (!initrd_mem) | ||
2328 | 422 | - { | ||
2329 | 423 | - grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); | ||
2330 | 424 | - goto fail; | ||
2331 | 425 | - } | ||
2332 | 426 | - | ||
2333 | 427 | - if (grub_initrd_load (&initrd_ctx, initrd_mem)) | ||
2334 | 428 | - goto fail; | ||
2335 | 429 | - | ||
2336 | 430 | - initrd_start = (grub_addr_t) initrd_mem; | ||
2337 | 431 | - initrd_end = initrd_start + initrd_size; | ||
2338 | 432 | - grub_dprintf ("linux", "[addr=%p, size=0x%x]\n", | ||
2339 | 433 | - (void *) initrd_start, initrd_size); | ||
2340 | 434 | - | ||
2341 | 435 | - fail: | ||
2342 | 436 | - grub_initrd_close (&initrd_ctx); | ||
2343 | 437 | - if (initrd_mem && !initrd_start) | ||
2344 | 438 | - grub_efi_free_pages ((grub_addr_t) initrd_mem, initrd_pages); | ||
2345 | 439 | - | ||
2346 | 440 | - return grub_errno; | ||
2347 | 441 | -} | ||
2348 | 442 | - | ||
2349 | 443 | -static grub_err_t | ||
2350 | 444 | -grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), | ||
2351 | 445 | - int argc, char *argv[]) | ||
2352 | 446 | -{ | ||
2353 | 447 | - grub_file_t file = 0; | ||
2354 | 448 | - struct linux_arch_kernel_header lh; | ||
2355 | 449 | - grub_err_t err; | ||
2356 | 450 | - | ||
2357 | 451 | - grub_dl_ref (my_mod); | ||
2358 | 452 | - | ||
2359 | 453 | - if (argc == 0) | ||
2360 | 454 | - { | ||
2361 | 455 | - grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); | ||
2362 | 456 | - goto fail; | ||
2363 | 457 | - } | ||
2364 | 458 | - | ||
2365 | 459 | - file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL); | ||
2366 | 460 | - if (!file) | ||
2367 | 461 | - goto fail; | ||
2368 | 462 | - | ||
2369 | 463 | - kernel_size = grub_file_size (file); | ||
2370 | 464 | - | ||
2371 | 465 | - if (grub_file_read (file, &lh, sizeof (lh)) < (long) sizeof (lh)) | ||
2372 | 466 | - return grub_errno; | ||
2373 | 467 | - | ||
2374 | 468 | - if (grub_arch_efi_linux_check_image (&lh) != GRUB_ERR_NONE) | ||
2375 | 469 | - goto fail; | ||
2376 | 470 | - | ||
2377 | 471 | - grub_loader_unset(); | ||
2378 | 472 | - | ||
2379 | 473 | - grub_dprintf ("linux", "kernel file size: %lld\n", (long long) kernel_size); | ||
2380 | 474 | - kernel_addr = grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (kernel_size)); | ||
2381 | 475 | - grub_dprintf ("linux", "kernel numpages: %lld\n", | ||
2382 | 476 | - (long long) GRUB_EFI_BYTES_TO_PAGES (kernel_size)); | ||
2383 | 477 | - if (!kernel_addr) | ||
2384 | 478 | - { | ||
2385 | 479 | - grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); | ||
2386 | 480 | - goto fail; | ||
2387 | 481 | - } | ||
2388 | 482 | - | ||
2389 | 483 | - grub_file_seek (file, 0); | ||
2390 | 484 | - if (grub_file_read (file, kernel_addr, kernel_size) | ||
2391 | 485 | - < (grub_int64_t) kernel_size) | ||
2392 | 486 | - { | ||
2393 | 487 | - if (!grub_errno) | ||
2394 | 488 | - grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), argv[0]); | ||
2395 | 489 | - goto fail; | ||
2396 | 490 | - } | ||
2397 | 491 | - | ||
2398 | 492 | - grub_dprintf ("linux", "kernel @ %p\n", kernel_addr); | ||
2399 | 493 | - | ||
2400 | 494 | - cmdline_size = grub_loader_cmdline_size (argc, argv) + sizeof (LINUX_IMAGE); | ||
2401 | 495 | - linux_args = grub_malloc (cmdline_size); | ||
2402 | 496 | - if (!linux_args) | ||
2403 | 497 | - { | ||
2404 | 498 | - grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); | ||
2405 | 499 | - goto fail; | ||
2406 | 500 | - } | ||
2407 | 501 | - grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE)); | ||
2408 | 502 | - err = grub_create_loader_cmdline (argc, argv, | ||
2409 | 503 | - linux_args + sizeof (LINUX_IMAGE) - 1, | ||
2410 | 504 | - cmdline_size, | ||
2411 | 505 | - GRUB_VERIFY_KERNEL_CMDLINE); | ||
2412 | 506 | - if (err) | ||
2413 | 507 | - goto fail; | ||
2414 | 508 | - | ||
2415 | 509 | - if (grub_errno == GRUB_ERR_NONE) | ||
2416 | 510 | - { | ||
2417 | 511 | - grub_loader_set (grub_linux_boot, grub_linux_unload, 0); | ||
2418 | 512 | - loaded = 1; | ||
2419 | 513 | - } | ||
2420 | 514 | - | ||
2421 | 515 | -fail: | ||
2422 | 516 | - if (file) | ||
2423 | 517 | - grub_file_close (file); | ||
2424 | 518 | - | ||
2425 | 519 | - if (grub_errno != GRUB_ERR_NONE) | ||
2426 | 520 | - { | ||
2427 | 521 | - grub_dl_unref (my_mod); | ||
2428 | 522 | - loaded = 0; | ||
2429 | 523 | - } | ||
2430 | 524 | - | ||
2431 | 525 | - if (linux_args && !loaded) | ||
2432 | 526 | - grub_free (linux_args); | ||
2433 | 527 | - | ||
2434 | 528 | - if (kernel_addr && !loaded) | ||
2435 | 529 | - grub_efi_free_pages ((grub_addr_t) kernel_addr, | ||
2436 | 530 | - GRUB_EFI_BYTES_TO_PAGES (kernel_size)); | ||
2437 | 531 | - | ||
2438 | 532 | - return grub_errno; | ||
2439 | 533 | -} | ||
2440 | 534 | - | ||
2441 | 535 | - | ||
2442 | 536 | -static grub_command_t cmd_linux, cmd_initrd; | ||
2443 | 537 | - | ||
2444 | 538 | -GRUB_MOD_INIT (linux) | ||
2445 | 539 | -{ | ||
2446 | 540 | - cmd_linux = grub_register_command ("linux", grub_cmd_linux, 0, | ||
2447 | 541 | - N_("Load Linux.")); | ||
2448 | 542 | - cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, 0, | ||
2449 | 543 | - N_("Load initrd.")); | ||
2450 | 544 | - my_mod = mod; | ||
2451 | 545 | -} | ||
2452 | 546 | - | ||
2453 | 547 | -GRUB_MOD_FINI (linux) | ||
2454 | 548 | -{ | ||
2455 | 549 | - grub_unregister_command (cmd_linux); | ||
2456 | 550 | - grub_unregister_command (cmd_initrd); | ||
2457 | 551 | -} | ||
2458 | 552 | diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c | ||
2459 | 553 | new file mode 100644 | ||
2460 | 554 | index 0000000..3292cab | ||
2461 | 555 | --- /dev/null | ||
2462 | 556 | +++ b/grub-core/loader/efi/linux.c | ||
2463 | 557 | @@ -0,0 +1,508 @@ | ||
2464 | 558 | +/* | ||
2465 | 559 | + * GRUB -- GRand Unified Bootloader | ||
2466 | 560 | + * Copyright (C) 2013 Free Software Foundation, Inc. | ||
2467 | 561 | + * | ||
2468 | 562 | + * GRUB is free software: you can redistribute it and/or modify | ||
2469 | 563 | + * it under the terms of the GNU General Public License as published by | ||
2470 | 564 | + * the Free Software Foundation, either version 3 of the License, or | ||
2471 | 565 | + * (at your option) any later version. | ||
2472 | 566 | + * | ||
2473 | 567 | + * GRUB is distributed in the hope that it will be useful, | ||
2474 | 568 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
2475 | 569 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
2476 | 570 | + * GNU General Public License for more details. | ||
2477 | 571 | + * | ||
2478 | 572 | + * You should have received a copy of the GNU General Public License | ||
2479 | 573 | + * along with GRUB. If not, see <http://www.gnu.org/licenses/>. | ||
2480 | 574 | + */ | ||
2481 | 575 | + | ||
2482 | 576 | +#include <grub/charset.h> | ||
2483 | 577 | +#include <grub/command.h> | ||
2484 | 578 | +#include <grub/err.h> | ||
2485 | 579 | +#include <grub/file.h> | ||
2486 | 580 | +#include <grub/fdt.h> | ||
2487 | 581 | +#include <grub/linux.h> | ||
2488 | 582 | +#include <grub/loader.h> | ||
2489 | 583 | +#include <grub/mm.h> | ||
2490 | 584 | +#include <grub/types.h> | ||
2491 | 585 | +#include <grub/cpu/linux.h> | ||
2492 | 586 | +#include <grub/efi/efi.h> | ||
2493 | 587 | +#include <grub/efi/fdtload.h> | ||
2494 | 588 | +#include <grub/efi/memory.h> | ||
2495 | 589 | +#include <grub/efi/pe32.h> | ||
2496 | 590 | +#include <grub/i18n.h> | ||
2497 | 591 | +#include <grub/lib/cmdline.h> | ||
2498 | 592 | +#include <grub/verify.h> | ||
2499 | 593 | + | ||
2500 | 594 | +GRUB_MOD_LICENSE ("GPLv3+"); | ||
2501 | 595 | + | ||
2502 | 596 | +static grub_dl_t my_mod; | ||
2503 | 597 | +static int loaded; | ||
2504 | 598 | + | ||
2505 | 599 | +static void *kernel_addr; | ||
2506 | 600 | +static grub_uint64_t kernel_size; | ||
2507 | 601 | + | ||
2508 | 602 | +static char *linux_args; | ||
2509 | 603 | +static grub_uint32_t cmdline_size; | ||
2510 | 604 | + | ||
2511 | 605 | +static grub_addr_t initrd_start; | ||
2512 | 606 | +static grub_addr_t initrd_end; | ||
2513 | 607 | + | ||
2514 | 608 | +static struct grub_linux_initrd_context initrd_ctx = { 0, 0, 0 }; | ||
2515 | 609 | +static grub_efi_handle_t initrd_lf2_handle; | ||
2516 | 610 | +static int initrd_use_loadfile2; | ||
2517 | 611 | +static grub_efi_guid_t load_file2_guid = GRUB_EFI_LOAD_FILE2_PROTOCOL_GUID; | ||
2518 | 612 | +static grub_efi_guid_t device_path_guid = GRUB_EFI_DEVICE_PATH_GUID; | ||
2519 | 613 | + | ||
2520 | 614 | +grub_err_t | ||
2521 | 615 | +grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh) | ||
2522 | 616 | +{ | ||
2523 | 617 | + struct grub_pe32_coff_header *coff_header; | ||
2524 | 618 | + struct grub_pe32_optional_header *optional_header; | ||
2525 | 619 | + | ||
2526 | 620 | + if (lh->magic != GRUB_LINUX_ARCH_MAGIC_SIGNATURE) | ||
2527 | 621 | + return grub_error(GRUB_ERR_BAD_OS, "invalid magic number"); | ||
2528 | 622 | + | ||
2529 | 623 | + if ((lh->code0 & 0xffff) != GRUB_PE32_MAGIC) | ||
2530 | 624 | + return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, | ||
2531 | 625 | + N_("plain image kernel not supported - rebuild with CONFIG_(U)EFI_STUB enabled")); | ||
2532 | 626 | + | ||
2533 | 627 | + grub_dprintf ("linux", "UEFI stub kernel:\n"); | ||
2534 | 628 | + grub_dprintf ("linux", "PE/COFF header @ %08x\n", lh->hdr_offset); | ||
2535 | 629 | + | ||
2536 | 630 | + coff_header = (struct grub_pe32_coff_header *)((unsigned long)lh + lh->hdr_offset); | ||
2537 | 631 | + optional_header = (struct grub_pe32_optional_header *)(coff_header + 1); | ||
2538 | 632 | + | ||
2539 | 633 | + /* | ||
2540 | 634 | + * Linux kernels built for any architecture are guaranteed to support the | ||
2541 | 635 | + * LoadFile2 based initrd loading protocol if the image version is >= 1. | ||
2542 | 636 | + */ | ||
2543 | 637 | + if (optional_header->major_image_version >= 1) | ||
2544 | 638 | + initrd_use_loadfile2 = 1; | ||
2545 | 639 | + else | ||
2546 | 640 | + initrd_use_loadfile2 = 0; | ||
2547 | 641 | + | ||
2548 | 642 | + grub_dprintf ("linux", "LoadFile2 initrd loading %sabled\n", | ||
2549 | 643 | + initrd_use_loadfile2 ? "en" : "dis"); | ||
2550 | 644 | + | ||
2551 | 645 | + return GRUB_ERR_NONE; | ||
2552 | 646 | +} | ||
2553 | 647 | + | ||
2554 | 648 | +static grub_err_t | ||
2555 | 649 | +finalize_params_linux (void) | ||
2556 | 650 | +{ | ||
2557 | 651 | + int node, retval; | ||
2558 | 652 | + | ||
2559 | 653 | + void *fdt = NULL; | ||
2560 | 654 | + | ||
2561 | 655 | + /* Set initrd info */ | ||
2562 | 656 | + if (initrd_start && initrd_end > initrd_start) | ||
2563 | 657 | + { | ||
2564 | 658 | + fdt = grub_fdt_load (GRUB_EFI_LINUX_FDT_EXTRA_SPACE); | ||
2565 | 659 | + | ||
2566 | 660 | + if (!fdt) | ||
2567 | 661 | + goto failure; | ||
2568 | 662 | + | ||
2569 | 663 | + node = grub_fdt_find_subnode (fdt, 0, "chosen"); | ||
2570 | 664 | + if (node < 0) | ||
2571 | 665 | + node = grub_fdt_add_subnode (fdt, 0, "chosen"); | ||
2572 | 666 | + | ||
2573 | 667 | + if (node < 1) | ||
2574 | 668 | + goto failure; | ||
2575 | 669 | + | ||
2576 | 670 | + grub_dprintf ("linux", "Initrd @ %p-%p\n", | ||
2577 | 671 | + (void *) initrd_start, (void *) initrd_end); | ||
2578 | 672 | + | ||
2579 | 673 | + retval = grub_fdt_set_prop64 (fdt, node, "linux,initrd-start", | ||
2580 | 674 | + initrd_start); | ||
2581 | 675 | + if (retval) | ||
2582 | 676 | + goto failure; | ||
2583 | 677 | + retval = grub_fdt_set_prop64 (fdt, node, "linux,initrd-end", | ||
2584 | 678 | + initrd_end); | ||
2585 | 679 | + if (retval) | ||
2586 | 680 | + goto failure; | ||
2587 | 681 | + } | ||
2588 | 682 | + | ||
2589 | 683 | + if (grub_fdt_install() != GRUB_ERR_NONE) | ||
2590 | 684 | + goto failure; | ||
2591 | 685 | + | ||
2592 | 686 | + return GRUB_ERR_NONE; | ||
2593 | 687 | + | ||
2594 | 688 | +failure: | ||
2595 | 689 | + grub_fdt_unload(); | ||
2596 | 690 | + return grub_error(GRUB_ERR_BAD_OS, "failed to install/update FDT"); | ||
2597 | 691 | +} | ||
2598 | 692 | + | ||
2599 | 693 | +grub_err_t | ||
2600 | 694 | +grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args) | ||
2601 | 695 | +{ | ||
2602 | 696 | + grub_efi_memory_mapped_device_path_t *mempath; | ||
2603 | 697 | + grub_efi_handle_t image_handle; | ||
2604 | 698 | + grub_efi_boot_services_t *b; | ||
2605 | 699 | + grub_efi_status_t status; | ||
2606 | 700 | + grub_efi_loaded_image_t *loaded_image; | ||
2607 | 701 | + int len; | ||
2608 | 702 | + | ||
2609 | 703 | + mempath = grub_malloc (2 * sizeof (grub_efi_memory_mapped_device_path_t)); | ||
2610 | 704 | + if (!mempath) | ||
2611 | 705 | + return grub_errno; | ||
2612 | 706 | + | ||
2613 | 707 | + mempath[0].header.type = GRUB_EFI_HARDWARE_DEVICE_PATH_TYPE; | ||
2614 | 708 | + mempath[0].header.subtype = GRUB_EFI_MEMORY_MAPPED_DEVICE_PATH_SUBTYPE; | ||
2615 | 709 | + mempath[0].header.length = grub_cpu_to_le16_compile_time (sizeof (*mempath)); | ||
2616 | 710 | + mempath[0].memory_type = GRUB_EFI_LOADER_DATA; | ||
2617 | 711 | + mempath[0].start_address = addr; | ||
2618 | 712 | + mempath[0].end_address = addr + size; | ||
2619 | 713 | + | ||
2620 | 714 | + mempath[1].header.type = GRUB_EFI_END_DEVICE_PATH_TYPE; | ||
2621 | 715 | + mempath[1].header.subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; | ||
2622 | 716 | + mempath[1].header.length = sizeof (grub_efi_device_path_t); | ||
2623 | 717 | + | ||
2624 | 718 | + b = grub_efi_system_table->boot_services; | ||
2625 | 719 | + status = b->load_image (0, grub_efi_image_handle, | ||
2626 | 720 | + (grub_efi_device_path_t *) mempath, | ||
2627 | 721 | + (void *) addr, size, &image_handle); | ||
2628 | 722 | + if (status != GRUB_EFI_SUCCESS) | ||
2629 | 723 | + return grub_error (GRUB_ERR_BAD_OS, "cannot load image"); | ||
2630 | 724 | + | ||
2631 | 725 | + grub_dprintf ("linux", "linux command line: '%s'\n", args); | ||
2632 | 726 | + | ||
2633 | 727 | + /* Convert command line to UCS-2 */ | ||
2634 | 728 | + loaded_image = grub_efi_get_loaded_image (image_handle); | ||
2635 | 729 | + loaded_image->load_options_size = len = | ||
2636 | 730 | + (grub_strlen (args) + 1) * sizeof (grub_efi_char16_t); | ||
2637 | 731 | + loaded_image->load_options = | ||
2638 | 732 | + grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); | ||
2639 | 733 | + if (!loaded_image->load_options) | ||
2640 | 734 | + return grub_errno; | ||
2641 | 735 | + | ||
2642 | 736 | + loaded_image->load_options_size = | ||
2643 | 737 | + 2 * grub_utf8_to_utf16 (loaded_image->load_options, len, | ||
2644 | 738 | + (grub_uint8_t *) args, len, NULL); | ||
2645 | 739 | + | ||
2646 | 740 | + grub_dprintf ("linux", "starting image %p\n", image_handle); | ||
2647 | 741 | + status = b->start_image (image_handle, 0, NULL); | ||
2648 | 742 | + | ||
2649 | 743 | + /* When successful, not reached */ | ||
2650 | 744 | + b->unload_image (image_handle); | ||
2651 | 745 | + grub_efi_free_pages ((grub_addr_t) loaded_image->load_options, | ||
2652 | 746 | + GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); | ||
2653 | 747 | + | ||
2654 | 748 | + return grub_errno; | ||
2655 | 749 | +} | ||
2656 | 750 | + | ||
2657 | 751 | +static grub_err_t | ||
2658 | 752 | +grub_linux_boot (void) | ||
2659 | 753 | +{ | ||
2660 | 754 | + if (finalize_params_linux () != GRUB_ERR_NONE) | ||
2661 | 755 | + return grub_errno; | ||
2662 | 756 | + | ||
2663 | 757 | + return (grub_arch_efi_linux_boot_image((grub_addr_t)kernel_addr, | ||
2664 | 758 | + kernel_size, linux_args)); | ||
2665 | 759 | +} | ||
2666 | 760 | + | ||
2667 | 761 | +static grub_err_t | ||
2668 | 762 | +grub_linux_unload (void) | ||
2669 | 763 | +{ | ||
2670 | 764 | + grub_dl_unref (my_mod); | ||
2671 | 765 | + loaded = 0; | ||
2672 | 766 | + if (initrd_start) | ||
2673 | 767 | + grub_efi_free_pages ((grub_efi_physical_address_t) initrd_start, | ||
2674 | 768 | + GRUB_EFI_BYTES_TO_PAGES (initrd_end - initrd_start)); | ||
2675 | 769 | + initrd_start = initrd_end = 0; | ||
2676 | 770 | + grub_free (linux_args); | ||
2677 | 771 | + if (kernel_addr) | ||
2678 | 772 | + grub_efi_free_pages ((grub_addr_t) kernel_addr, | ||
2679 | 773 | + GRUB_EFI_BYTES_TO_PAGES (kernel_size)); | ||
2680 | 774 | + grub_fdt_unload (); | ||
2681 | 775 | + return GRUB_ERR_NONE; | ||
2682 | 776 | +} | ||
2683 | 777 | + | ||
2684 | 778 | +/* | ||
2685 | 779 | + * As per linux/Documentation/arm/Booting | ||
2686 | 780 | + * ARM initrd needs to be covered by kernel linear mapping, | ||
2687 | 781 | + * so place it in the first 512MB of DRAM. | ||
2688 | 782 | + * | ||
2689 | 783 | + * As per linux/Documentation/arm64/booting.txt | ||
2690 | 784 | + * ARM64 initrd needs to be contained entirely within a 1GB aligned window | ||
2691 | 785 | + * of up to 32GB of size that covers the kernel image as well. | ||
2692 | 786 | + * Since the EFI stub loader will attempt to load the kernel near start of | ||
2693 | 787 | + * RAM, place the buffer in the first 32GB of RAM. | ||
2694 | 788 | + */ | ||
2695 | 789 | +#ifdef __arm__ | ||
2696 | 790 | +#define INITRD_MAX_ADDRESS_OFFSET (512U * 1024 * 1024) | ||
2697 | 791 | +#else /* __aarch64__ */ | ||
2698 | 792 | +#define INITRD_MAX_ADDRESS_OFFSET (32ULL * 1024 * 1024 * 1024) | ||
2699 | 793 | +#endif | ||
2700 | 794 | + | ||
2701 | 795 | +/* | ||
2702 | 796 | + * This function returns a pointer to a legally allocated initrd buffer, | ||
2703 | 797 | + * or NULL if unsuccessful | ||
2704 | 798 | + */ | ||
2705 | 799 | +static void * | ||
2706 | 800 | +allocate_initrd_mem (int initrd_pages) | ||
2707 | 801 | +{ | ||
2708 | 802 | + grub_addr_t max_addr; | ||
2709 | 803 | + | ||
2710 | 804 | + if (grub_efi_get_ram_base (&max_addr) != GRUB_ERR_NONE) | ||
2711 | 805 | + return NULL; | ||
2712 | 806 | + | ||
2713 | 807 | + max_addr += INITRD_MAX_ADDRESS_OFFSET - 1; | ||
2714 | 808 | + | ||
2715 | 809 | + return grub_efi_allocate_pages_real (max_addr, initrd_pages, | ||
2716 | 810 | + GRUB_EFI_ALLOCATE_MAX_ADDRESS, | ||
2717 | 811 | + GRUB_EFI_LOADER_DATA); | ||
2718 | 812 | +} | ||
2719 | 813 | + | ||
2720 | 814 | +struct initrd_media_device_path { | ||
2721 | 815 | + grub_efi_vendor_media_device_path_t vendor; | ||
2722 | 816 | + grub_efi_device_path_t end; | ||
2723 | 817 | +} GRUB_PACKED; | ||
2724 | 818 | + | ||
2725 | 819 | +#define LINUX_EFI_INITRD_MEDIA_GUID \ | ||
2726 | 820 | + { 0x5568e427, 0x68fc, 0x4f3d, \ | ||
2727 | 821 | + { 0xac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68 } \ | ||
2728 | 822 | + } | ||
2729 | 823 | + | ||
2730 | 824 | +static struct initrd_media_device_path initrd_lf2_device_path = { | ||
2731 | 825 | + { | ||
2732 | 826 | + { | ||
2733 | 827 | + GRUB_EFI_MEDIA_DEVICE_PATH_TYPE, | ||
2734 | 828 | + GRUB_EFI_VENDOR_MEDIA_DEVICE_PATH_SUBTYPE, | ||
2735 | 829 | + sizeof(grub_efi_vendor_media_device_path_t), | ||
2736 | 830 | + }, | ||
2737 | 831 | + LINUX_EFI_INITRD_MEDIA_GUID | ||
2738 | 832 | + }, { | ||
2739 | 833 | + GRUB_EFI_END_DEVICE_PATH_TYPE, | ||
2740 | 834 | + GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE, | ||
2741 | 835 | + sizeof(grub_efi_device_path_t) | ||
2742 | 836 | + } | ||
2743 | 837 | +}; | ||
2744 | 838 | + | ||
2745 | 839 | +static grub_efi_status_t | ||
2746 | 840 | +grub_efi_initrd_load_file2(grub_efi_load_file2_t *this, | ||
2747 | 841 | + grub_efi_device_path_t *device_path, | ||
2748 | 842 | + grub_efi_boolean_t boot_policy, | ||
2749 | 843 | + grub_efi_uintn_t *buffer_size, | ||
2750 | 844 | + void *buffer); | ||
2751 | 845 | + | ||
2752 | 846 | +static grub_efi_load_file2_t initrd_lf2 = { | ||
2753 | 847 | + grub_efi_initrd_load_file2 | ||
2754 | 848 | +}; | ||
2755 | 849 | + | ||
2756 | 850 | +static grub_efi_status_t | ||
2757 | 851 | +grub_efi_initrd_load_file2(grub_efi_load_file2_t *this, | ||
2758 | 852 | + grub_efi_device_path_t *device_path, | ||
2759 | 853 | + grub_efi_boolean_t boot_policy, | ||
2760 | 854 | + grub_efi_uintn_t *buffer_size, | ||
2761 | 855 | + void *buffer) | ||
2762 | 856 | +{ | ||
2763 | 857 | + grub_efi_status_t status = GRUB_EFI_SUCCESS; | ||
2764 | 858 | + grub_efi_uintn_t initrd_size; | ||
2765 | 859 | + | ||
2766 | 860 | + if (!this || this != &initrd_lf2 || !buffer_size) | ||
2767 | 861 | + return GRUB_EFI_INVALID_PARAMETER; | ||
2768 | 862 | + | ||
2769 | 863 | + if (device_path->type != GRUB_EFI_END_DEVICE_PATH_TYPE || | ||
2770 | 864 | + device_path->subtype != GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE) | ||
2771 | 865 | + return GRUB_EFI_NOT_FOUND; | ||
2772 | 866 | + | ||
2773 | 867 | + if (boot_policy) | ||
2774 | 868 | + return GRUB_EFI_UNSUPPORTED; | ||
2775 | 869 | + | ||
2776 | 870 | + initrd_size = grub_get_initrd_size (&initrd_ctx); | ||
2777 | 871 | + if (!buffer || *buffer_size < initrd_size) | ||
2778 | 872 | + { | ||
2779 | 873 | + *buffer_size = initrd_size; | ||
2780 | 874 | + return GRUB_EFI_BUFFER_TOO_SMALL; | ||
2781 | 875 | + } | ||
2782 | 876 | + | ||
2783 | 877 | + grub_dprintf ("linux", "Providing initrd via LOAD_FILE2_PROTOCOL\n"); | ||
2784 | 878 | + | ||
2785 | 879 | + if (grub_initrd_load (&initrd_ctx, buffer)) | ||
2786 | 880 | + status = GRUB_EFI_LOAD_ERROR; | ||
2787 | 881 | + | ||
2788 | 882 | + grub_initrd_close (&initrd_ctx); | ||
2789 | 883 | + return status; | ||
2790 | 884 | +} | ||
2791 | 885 | + | ||
2792 | 886 | +static grub_err_t | ||
2793 | 887 | +grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), | ||
2794 | 888 | + int argc, char *argv[]) | ||
2795 | 889 | +{ | ||
2796 | 890 | + int initrd_size, initrd_pages; | ||
2797 | 891 | + void *initrd_mem = NULL; | ||
2798 | 892 | + grub_efi_boot_services_t *b; | ||
2799 | 893 | + grub_efi_status_t status; | ||
2800 | 894 | + | ||
2801 | 895 | + if (argc == 0) | ||
2802 | 896 | + { | ||
2803 | 897 | + grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); | ||
2804 | 898 | + goto fail; | ||
2805 | 899 | + } | ||
2806 | 900 | + | ||
2807 | 901 | + if (!loaded) | ||
2808 | 902 | + { | ||
2809 | 903 | + grub_error (GRUB_ERR_BAD_ARGUMENT, | ||
2810 | 904 | + N_("you need to load the kernel first")); | ||
2811 | 905 | + goto fail; | ||
2812 | 906 | + } | ||
2813 | 907 | + | ||
2814 | 908 | + if (grub_initrd_init (argc, argv, &initrd_ctx)) | ||
2815 | 909 | + goto fail; | ||
2816 | 910 | + | ||
2817 | 911 | + if (initrd_use_loadfile2 && !initrd_lf2_handle) | ||
2818 | 912 | + { | ||
2819 | 913 | + b = grub_efi_system_table->boot_services; | ||
2820 | 914 | + status = b->install_multiple_protocol_interfaces (&initrd_lf2_handle, | ||
2821 | 915 | + &load_file2_guid, | ||
2822 | 916 | + &initrd_lf2, | ||
2823 | 917 | + &device_path_guid, | ||
2824 | 918 | + &initrd_lf2_device_path, | ||
2825 | 919 | + NULL); | ||
2826 | 920 | + if (status == GRUB_EFI_OUT_OF_RESOURCES) | ||
2827 | 921 | + { | ||
2828 | 922 | + grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); | ||
2829 | 923 | + return grub_errno; | ||
2830 | 924 | + } | ||
2831 | 925 | + grub_dprintf ("linux", "LoadFile2 initrd loading protocol installed\n"); | ||
2832 | 926 | + return GRUB_ERR_NONE; | ||
2833 | 927 | + } | ||
2834 | 928 | + | ||
2835 | 929 | + initrd_size = grub_get_initrd_size (&initrd_ctx); | ||
2836 | 930 | + grub_dprintf ("linux", "Loading initrd\n"); | ||
2837 | 931 | + | ||
2838 | 932 | + initrd_pages = (GRUB_EFI_BYTES_TO_PAGES (initrd_size)); | ||
2839 | 933 | + initrd_mem = allocate_initrd_mem (initrd_pages); | ||
2840 | 934 | + | ||
2841 | 935 | + if (!initrd_mem) | ||
2842 | 936 | + { | ||
2843 | 937 | + grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); | ||
2844 | 938 | + goto fail; | ||
2845 | 939 | + } | ||
2846 | 940 | + | ||
2847 | 941 | + if (grub_initrd_load (&initrd_ctx, initrd_mem)) | ||
2848 | 942 | + goto fail; | ||
2849 | 943 | + | ||
2850 | 944 | + initrd_start = (grub_addr_t) initrd_mem; | ||
2851 | 945 | + initrd_end = initrd_start + initrd_size; | ||
2852 | 946 | + grub_dprintf ("linux", "[addr=%p, size=0x%x]\n", | ||
2853 | 947 | + (void *) initrd_start, initrd_size); | ||
2854 | 948 | + | ||
2855 | 949 | + fail: | ||
2856 | 950 | + grub_initrd_close (&initrd_ctx); | ||
2857 | 951 | + if (initrd_mem && !initrd_start) | ||
2858 | 952 | + grub_efi_free_pages ((grub_addr_t) initrd_mem, initrd_pages); | ||
2859 | 953 | + | ||
2860 | 954 | + return grub_errno; | ||
2861 | 955 | +} | ||
2862 | 956 | + | ||
2863 | 957 | +static grub_err_t | ||
2864 | 958 | +grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), | ||
2865 | 959 | + int argc, char *argv[]) | ||
2866 | 960 | +{ | ||
2867 | 961 | + grub_file_t file = 0; | ||
2868 | 962 | + struct linux_arch_kernel_header lh; | ||
2869 | 963 | + grub_err_t err; | ||
2870 | 964 | + | ||
2871 | 965 | + grub_dl_ref (my_mod); | ||
2872 | 966 | + | ||
2873 | 967 | + if (argc == 0) | ||
2874 | 968 | + { | ||
2875 | 969 | + grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); | ||
2876 | 970 | + goto fail; | ||
2877 | 971 | + } | ||
2878 | 972 | + | ||
2879 | 973 | + file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL); | ||
2880 | 974 | + if (!file) | ||
2881 | 975 | + goto fail; | ||
2882 | 976 | + | ||
2883 | 977 | + kernel_size = grub_file_size (file); | ||
2884 | 978 | + | ||
2885 | 979 | + if (grub_file_read (file, &lh, sizeof (lh)) < (long) sizeof (lh)) | ||
2886 | 980 | + return grub_errno; | ||
2887 | 981 | + | ||
2888 | 982 | + if (grub_arch_efi_linux_check_image (&lh) != GRUB_ERR_NONE) | ||
2889 | 983 | + goto fail; | ||
2890 | 984 | + | ||
2891 | 985 | + grub_loader_unset(); | ||
2892 | 986 | + | ||
2893 | 987 | + grub_dprintf ("linux", "kernel file size: %lld\n", (long long) kernel_size); | ||
2894 | 988 | + kernel_addr = grub_efi_allocate_any_pages (GRUB_EFI_BYTES_TO_PAGES (kernel_size)); | ||
2895 | 989 | + grub_dprintf ("linux", "kernel numpages: %lld\n", | ||
2896 | 990 | + (long long) GRUB_EFI_BYTES_TO_PAGES (kernel_size)); | ||
2897 | 991 | + if (!kernel_addr) | ||
2898 | 992 | + { | ||
2899 | 993 | + grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); | ||
2900 | 994 | + goto fail; | ||
2901 | 995 | + } | ||
2902 | 996 | + | ||
2903 | 997 | + grub_file_seek (file, 0); | ||
2904 | 998 | + if (grub_file_read (file, kernel_addr, kernel_size) | ||
2905 | 999 | + < (grub_int64_t) kernel_size) | ||
2906 | 1000 | + { | ||
2907 | 1001 | + if (!grub_errno) | ||
2908 | 1002 | + grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"), argv[0]); | ||
2909 | 1003 | + goto fail; | ||
2910 | 1004 | + } | ||
2911 | 1005 | + | ||
2912 | 1006 | + grub_dprintf ("linux", "kernel @ %p\n", kernel_addr); | ||
2913 | 1007 | + | ||
2914 | 1008 | + cmdline_size = grub_loader_cmdline_size (argc, argv) + sizeof (LINUX_IMAGE); | ||
2915 | 1009 | + linux_args = grub_malloc (cmdline_size); | ||
2916 | 1010 | + if (!linux_args) | ||
2917 | 1011 | + { | ||
2918 | 1012 | + grub_error (GRUB_ERR_OUT_OF_MEMORY, N_("out of memory")); | ||
2919 | 1013 | + goto fail; | ||
2920 | 1014 | + } | ||
2921 | 1015 | + grub_memcpy (linux_args, LINUX_IMAGE, sizeof (LINUX_IMAGE)); | ||
2922 | 1016 | + err = grub_create_loader_cmdline (argc, argv, | ||
2923 | 1017 | + linux_args + sizeof (LINUX_IMAGE) - 1, | ||
2924 | 1018 | + cmdline_size, | ||
2925 | 1019 | + GRUB_VERIFY_KERNEL_CMDLINE); | ||
2926 | 1020 | + if (err) | ||
2927 | 1021 | + goto fail; | ||
2928 | 1022 | + | ||
2929 | 1023 | + if (grub_errno == GRUB_ERR_NONE) | ||
2930 | 1024 | + { | ||
2931 | 1025 | + grub_loader_set (grub_linux_boot, grub_linux_unload, 0); | ||
2932 | 1026 | + loaded = 1; | ||
2933 | 1027 | + } | ||
2934 | 1028 | + | ||
2935 | 1029 | +fail: | ||
2936 | 1030 | + if (file) | ||
2937 | 1031 | + grub_file_close (file); | ||
2938 | 1032 | + | ||
2939 | 1033 | + if (grub_errno != GRUB_ERR_NONE) | ||
2940 | 1034 | + { | ||
2941 | 1035 | + grub_dl_unref (my_mod); | ||
2942 | 1036 | + loaded = 0; | ||
2943 | 1037 | + } | ||
2944 | 1038 | + | ||
2945 | 1039 | + if (linux_args && !loaded) | ||
2946 | 1040 | + grub_free (linux_args); | ||
2947 | 1041 | + | ||
2948 | 1042 | + if (kernel_addr && !loaded) | ||
2949 | 1043 | + grub_efi_free_pages ((grub_addr_t) kernel_addr, | ||
2950 | 1044 | + GRUB_EFI_BYTES_TO_PAGES (kernel_size)); | ||
2951 | 1045 | + | ||
2952 | 1046 | + return grub_errno; | ||
2953 | 1047 | +} | ||
2954 | 1048 | + | ||
2955 | 1049 | + | ||
2956 | 1050 | +static grub_command_t cmd_linux, cmd_initrd; | ||
2957 | 1051 | + | ||
2958 | 1052 | +GRUB_MOD_INIT (linux) | ||
2959 | 1053 | +{ | ||
2960 | 1054 | + cmd_linux = grub_register_command ("linux", grub_cmd_linux, 0, | ||
2961 | 1055 | + N_("Load Linux.")); | ||
2962 | 1056 | + cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, 0, | ||
2963 | 1057 | + N_("Load initrd.")); | ||
2964 | 1058 | + my_mod = mod; | ||
2965 | 1059 | +} | ||
2966 | 1060 | + | ||
2967 | 1061 | +GRUB_MOD_FINI (linux) | ||
2968 | 1062 | +{ | ||
2969 | 1063 | + grub_unregister_command (cmd_linux); | ||
2970 | 1064 | + grub_unregister_command (cmd_initrd); | ||
2971 | 1065 | +} | ||
2972 | 1066 | diff --git a/include/grub/arm/linux.h b/include/grub/arm/linux.h | ||
2973 | 1067 | index bcd5a7e..8c13978 100644 | ||
2974 | 1068 | --- a/include/grub/arm/linux.h | ||
2975 | 1069 | +++ b/include/grub/arm/linux.h | ||
2976 | 1070 | @@ -35,7 +35,7 @@ struct linux_arm_kernel_header { | ||
2977 | 1071 | }; | ||
2978 | 1072 | |||
2979 | 1073 | #if defined(__arm__) | ||
2980 | 1074 | -# define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM_MAGIC_SIGNATURE | ||
2981 | 1075 | +# define GRUB_LINUX_ARCH_MAGIC_SIGNATURE GRUB_LINUX_ARM_MAGIC_SIGNATURE | ||
2982 | 1076 | # define linux_arch_kernel_header linux_arm_kernel_header | ||
2983 | 1077 | #endif | ||
2984 | 1078 | |||
2985 | 1079 | diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h | ||
2986 | 1080 | index 7e22b4a..effd870 100644 | ||
2987 | 1081 | --- a/include/grub/arm64/linux.h | ||
2988 | 1082 | +++ b/include/grub/arm64/linux.h | ||
2989 | 1083 | @@ -39,7 +39,7 @@ struct linux_arm64_kernel_header | ||
2990 | 1084 | }; | ||
2991 | 1085 | |||
2992 | 1086 | #if defined(__aarch64__) | ||
2993 | 1087 | -# define GRUB_LINUX_ARMXX_MAGIC_SIGNATURE GRUB_LINUX_ARM64_MAGIC_SIGNATURE | ||
2994 | 1088 | +# define GRUB_LINUX_ARCH_MAGIC_SIGNATURE GRUB_LINUX_ARM64_MAGIC_SIGNATURE | ||
2995 | 1089 | # define linux_arch_kernel_header linux_arm64_kernel_header | ||
2996 | 1090 | #endif | ||
2997 | 1091 | |||
2998 | 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 | |||
2999 | 0 | new file mode 100644 | 1092 | new file mode 100644 |
3000 | index 0000000..a5af0f5 | |||
3001 | --- /dev/null | |||
3002 | +++ b/debian/patches/loader-drop-argv-argument-in-grub_initrd_load.patch | |||
3003 | @@ -0,0 +1,178 @@ | |||
3004 | 1 | From: Nikita Ermakov <arei@altlinux.org> | ||
3005 | 2 | Date: Thu, 28 Oct 2021 23:31:13 +0300 | ||
3006 | 3 | Subject: loader: drop argv[] argument in grub_initrd_load() | ||
3007 | 4 | |||
3008 | 5 | In the case of an error grub_initrd_load() uses argv[] to print the | ||
3009 | 6 | filename that caused the error. It is also possible to obtain the | ||
3010 | 7 | filename from the file handles and there is no need to duplicate that | ||
3011 | 8 | information in argv[], so let's drop it. | ||
3012 | 9 | |||
3013 | 10 | Signed-off-by: Nikita Ermakov <arei@altlinux.org> | ||
3014 | 11 | Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com> | ||
3015 | 12 | |||
3016 | 13 | Last-Update: 2022-01-03 | ||
3017 | 14 | Origin: https://lists.gnu.org/archive/html/grub-devel/2021-10/msg00212.html | ||
3018 | 15 | --- | ||
3019 | 16 | grub-core/loader/arm/linux.c | 2 +- | ||
3020 | 17 | grub-core/loader/arm64/linux.c | 2 +- | ||
3021 | 18 | grub-core/loader/i386/linux.c | 2 +- | ||
3022 | 19 | grub-core/loader/i386/pc/linux.c | 2 +- | ||
3023 | 20 | grub-core/loader/i386/xen.c | 3 +-- | ||
3024 | 21 | grub-core/loader/ia64/efi/linux.c | 2 +- | ||
3025 | 22 | grub-core/loader/linux.c | 4 ++-- | ||
3026 | 23 | grub-core/loader/mips/linux.c | 2 +- | ||
3027 | 24 | grub-core/loader/powerpc/ieee1275/linux.c | 2 +- | ||
3028 | 25 | grub-core/loader/sparc64/ieee1275/linux.c | 2 +- | ||
3029 | 26 | include/grub/linux.h | 2 +- | ||
3030 | 27 | 11 files changed, 12 insertions(+), 13 deletions(-) | ||
3031 | 28 | |||
3032 | 29 | diff --git a/grub-core/loader/arm/linux.c b/grub-core/loader/arm/linux.c | ||
3033 | 30 | index ed23dc7..1f7ab75 100644 | ||
3034 | 31 | --- a/grub-core/loader/arm/linux.c | ||
3035 | 32 | +++ b/grub-core/loader/arm/linux.c | ||
3036 | 33 | @@ -422,7 +422,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), | ||
3037 | 34 | grub_dprintf ("loader", "Loading initrd to 0x%08x\n", | ||
3038 | 35 | (grub_addr_t) initrd_start); | ||
3039 | 36 | |||
3040 | 37 | - if (grub_initrd_load (&initrd_ctx, argv, (void *) initrd_start)) | ||
3041 | 38 | + if (grub_initrd_load (&initrd_ctx, (void *) initrd_start)) | ||
3042 | 39 | goto fail; | ||
3043 | 40 | |||
3044 | 41 | initrd_end = initrd_start + size; | ||
3045 | 42 | diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c | ||
3046 | 43 | index ef3e9f9..aed7a20 100644 | ||
3047 | 44 | --- a/grub-core/loader/arm64/linux.c | ||
3048 | 45 | +++ b/grub-core/loader/arm64/linux.c | ||
3049 | 46 | @@ -266,7 +266,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), | ||
3050 | 47 | goto fail; | ||
3051 | 48 | } | ||
3052 | 49 | |||
3053 | 50 | - if (grub_initrd_load (&initrd_ctx, argv, initrd_mem)) | ||
3054 | 51 | + if (grub_initrd_load (&initrd_ctx, initrd_mem)) | ||
3055 | 52 | goto fail; | ||
3056 | 53 | |||
3057 | 54 | initrd_start = (grub_addr_t) initrd_mem; | ||
3058 | 55 | diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c | ||
3059 | 56 | index 9f74a96..f30a158 100644 | ||
3060 | 57 | --- a/grub-core/loader/i386/linux.c | ||
3061 | 58 | +++ b/grub-core/loader/i386/linux.c | ||
3062 | 59 | @@ -1107,7 +1107,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), | ||
3063 | 60 | initrd_mem_target = get_physical_target_address (ch); | ||
3064 | 61 | } | ||
3065 | 62 | |||
3066 | 63 | - if (grub_initrd_load (&initrd_ctx, argv, initrd_mem)) | ||
3067 | 64 | + if (grub_initrd_load (&initrd_ctx, initrd_mem)) | ||
3068 | 65 | goto fail; | ||
3069 | 66 | |||
3070 | 67 | grub_dprintf ("linux", "Initrd, addr=0x%x, size=0x%x\n", | ||
3071 | 68 | diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c | ||
3072 | 69 | index 2a29952..efeeeb2 100644 | ||
3073 | 70 | --- a/grub-core/loader/i386/pc/linux.c | ||
3074 | 71 | +++ b/grub-core/loader/i386/pc/linux.c | ||
3075 | 72 | @@ -462,7 +462,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), | ||
3076 | 73 | initrd_addr = get_physical_target_address (ch); | ||
3077 | 74 | } | ||
3078 | 75 | |||
3079 | 76 | - if (grub_initrd_load (&initrd_ctx, argv, initrd_chunk)) | ||
3080 | 77 | + if (grub_initrd_load (&initrd_ctx, initrd_chunk)) | ||
3081 | 78 | goto fail; | ||
3082 | 79 | |||
3083 | 80 | lh->ramdisk_image = initrd_addr; | ||
3084 | 81 | diff --git a/grub-core/loader/i386/xen.c b/grub-core/loader/i386/xen.c | ||
3085 | 82 | index cd24874..3b856e8 100644 | ||
3086 | 83 | --- a/grub-core/loader/i386/xen.c | ||
3087 | 84 | +++ b/grub-core/loader/i386/xen.c | ||
3088 | 85 | @@ -809,8 +809,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), | ||
3089 | 86 | if (err) | ||
3090 | 87 | goto fail; | ||
3091 | 88 | |||
3092 | 89 | - if (grub_initrd_load (&initrd_ctx, argv, | ||
3093 | 90 | - get_virtual_current_address (ch))) | ||
3094 | 91 | + if (grub_initrd_load (&initrd_ctx, get_virtual_current_address (ch))) | ||
3095 | 92 | goto fail; | ||
3096 | 93 | } | ||
3097 | 94 | |||
3098 | 95 | diff --git a/grub-core/loader/ia64/efi/linux.c b/grub-core/loader/ia64/efi/linux.c | ||
3099 | 96 | index 7987fd1..8873b7a 100644 | ||
3100 | 97 | --- a/grub-core/loader/ia64/efi/linux.c | ||
3101 | 98 | +++ b/grub-core/loader/ia64/efi/linux.c | ||
3102 | 99 | @@ -563,7 +563,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), | ||
3103 | 100 | grub_dprintf ("linux", "[addr=0x%lx, size=0x%lx]\n", | ||
3104 | 101 | (grub_uint64_t) initrd_mem, initrd_size); | ||
3105 | 102 | |||
3106 | 103 | - if (grub_initrd_load (&initrd_ctx, argv, initrd_mem)) | ||
3107 | 104 | + if (grub_initrd_load (&initrd_ctx, initrd_mem)) | ||
3108 | 105 | goto fail; | ||
3109 | 106 | fail: | ||
3110 | 107 | grub_initrd_close (&initrd_ctx); | ||
3111 | 108 | diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c | ||
3112 | 109 | index 3fe390f..d19df67 100644 | ||
3113 | 110 | --- a/grub-core/loader/linux.c | ||
3114 | 111 | +++ b/grub-core/loader/linux.c | ||
3115 | 112 | @@ -271,7 +271,7 @@ grub_initrd_close (struct grub_linux_initrd_context *initrd_ctx) | ||
3116 | 113 | |||
3117 | 114 | grub_err_t | ||
3118 | 115 | grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx, | ||
3119 | 116 | - char *argv[], void *target) | ||
3120 | 117 | + void *target) | ||
3121 | 118 | { | ||
3122 | 119 | grub_uint8_t *ptr = target; | ||
3123 | 120 | int i; | ||
3124 | 121 | @@ -317,7 +317,7 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx, | ||
3125 | 122 | { | ||
3126 | 123 | if (!grub_errno) | ||
3127 | 124 | grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"), | ||
3128 | 125 | - argv[i]); | ||
3129 | 126 | + initrd_ctx->components[i].file->name); | ||
3130 | 127 | grub_initrd_close (initrd_ctx); | ||
3131 | 128 | return grub_errno; | ||
3132 | 129 | } | ||
3133 | 130 | diff --git a/grub-core/loader/mips/linux.c b/grub-core/loader/mips/linux.c | ||
3134 | 131 | index e4ed959..9459472 100644 | ||
3135 | 132 | --- a/grub-core/loader/mips/linux.c | ||
3136 | 133 | +++ b/grub-core/loader/mips/linux.c | ||
3137 | 134 | @@ -452,7 +452,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), | ||
3138 | 135 | initrd_dest = get_physical_target_address (ch) | 0x80000000; | ||
3139 | 136 | } | ||
3140 | 137 | |||
3141 | 138 | - if (grub_initrd_load (&initrd_ctx, argv, initrd_src)) | ||
3142 | 139 | + if (grub_initrd_load (&initrd_ctx, initrd_src)) | ||
3143 | 140 | goto fail; | ||
3144 | 141 | |||
3145 | 142 | #ifdef GRUB_MACHINE_MIPS_QEMU_MIPS | ||
3146 | 143 | diff --git a/grub-core/loader/powerpc/ieee1275/linux.c b/grub-core/loader/powerpc/ieee1275/linux.c | ||
3147 | 144 | index 818b2a8..a51e7a7 100644 | ||
3148 | 145 | --- a/grub-core/loader/powerpc/ieee1275/linux.c | ||
3149 | 146 | +++ b/grub-core/loader/powerpc/ieee1275/linux.c | ||
3150 | 147 | @@ -363,7 +363,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), | ||
3151 | 148 | |||
3152 | 149 | grub_dprintf ("loader", "Loading initrd at 0x%x, size 0x%x\n", addr, size); | ||
3153 | 150 | |||
3154 | 151 | - if (grub_initrd_load (&initrd_ctx, argv, (void *) addr)) | ||
3155 | 152 | + if (grub_initrd_load (&initrd_ctx, (void *) addr)) | ||
3156 | 153 | goto fail; | ||
3157 | 154 | |||
3158 | 155 | initrd_addr = addr; | ||
3159 | 156 | diff --git a/grub-core/loader/sparc64/ieee1275/linux.c b/grub-core/loader/sparc64/ieee1275/linux.c | ||
3160 | 157 | index bb47ee0..ac2206f 100644 | ||
3161 | 158 | --- a/grub-core/loader/sparc64/ieee1275/linux.c | ||
3162 | 159 | +++ b/grub-core/loader/sparc64/ieee1275/linux.c | ||
3163 | 160 | @@ -413,7 +413,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), | ||
3164 | 161 | grub_dprintf ("loader", "Loading initrd at vaddr 0x%lx, paddr 0x%lx, size 0x%lx\n", | ||
3165 | 162 | addr, paddr, size); | ||
3166 | 163 | |||
3167 | 164 | - if (grub_initrd_load (&initrd_ctx, argv, (void *) addr)) | ||
3168 | 165 | + if (grub_initrd_load (&initrd_ctx, (void *) addr)) | ||
3169 | 166 | goto fail; | ||
3170 | 167 | |||
3171 | 168 | initrd_addr = addr; | ||
3172 | 169 | diff --git a/include/grub/linux.h b/include/grub/linux.h | ||
3173 | 170 | index 594a3f3..a96ac20 100644 | ||
3174 | 171 | --- a/include/grub/linux.h | ||
3175 | 172 | +++ b/include/grub/linux.h | ||
3176 | 173 | @@ -21,4 +21,4 @@ grub_initrd_close (struct grub_linux_initrd_context *initrd_ctx); | ||
3177 | 174 | |||
3178 | 175 | grub_err_t | ||
3179 | 176 | grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx, | ||
3180 | 177 | - char *argv[], void *target); | ||
3181 | 178 | + void *target); | ||
3182 | diff --git a/debian/patches/maybe-quiet.patch b/debian/patches/maybe-quiet.patch | |||
3183 | index 819d9ca..5833f08 100644 | |||
3184 | --- a/debian/patches/maybe-quiet.patch | |||
3185 | +++ b/debian/patches/maybe-quiet.patch | |||
3186 | @@ -58,10 +58,10 @@ index 9e8f991..d2c4ce8 100644 | |||
3187 | 58 | /* We don't need those. */ | 58 | /* We don't need those. */ |
3188 | 59 | #define MINILZO_CFG_SKIP_LZO_PTR 1 | 59 | #define MINILZO_CFG_SKIP_LZO_PTR 1 |
3189 | 60 | diff --git a/configure.ac b/configure.ac | 60 | diff --git a/configure.ac b/configure.ac |
3191 | 61 | index 74778a6..256fc44 100644 | 61 | index fb980fd..2869155 100644 |
3192 | 62 | --- a/configure.ac | 62 | --- a/configure.ac |
3193 | 63 | +++ b/configure.ac | 63 | +++ b/configure.ac |
3195 | 64 | @@ -1915,6 +1915,17 @@ else | 64 | @@ -1923,6 +1923,17 @@ else |
3196 | 65 | fi | 65 | fi |
3197 | 66 | AC_SUBST([UBUNTU_RECOVERY]) | 66 | AC_SUBST([UBUNTU_RECOVERY]) |
3198 | 67 | 67 | ||
3199 | @@ -79,7 +79,7 @@ index 74778a6..256fc44 100644 | |||
3200 | 79 | LIBS="" | 79 | LIBS="" |
3201 | 80 | 80 | ||
3202 | 81 | AC_SUBST([FONT_SOURCE]) | 81 | AC_SUBST([FONT_SOURCE]) |
3204 | 82 | @@ -2177,5 +2188,10 @@ echo "With stack smashing protector: Yes" | 82 | @@ -2185,5 +2196,10 @@ echo "With stack smashing protector: Yes" |
3205 | 83 | else | 83 | else |
3206 | 84 | echo "With stack smashing protector: No" | 84 | echo "With stack smashing protector: No" |
3207 | 85 | fi | 85 | fi |
3208 | diff --git a/debian/patches/mkconfig-ubuntu-recovery.patch b/debian/patches/mkconfig-ubuntu-recovery.patch | |||
3209 | index 43beada..4d7a67d 100644 | |||
3210 | --- a/debian/patches/mkconfig-ubuntu-recovery.patch | |||
3211 | +++ b/debian/patches/mkconfig-ubuntu-recovery.patch | |||
3212 | @@ -22,10 +22,10 @@ Patch-Name: mkconfig-ubuntu-recovery.patch | |||
3213 | 22 | 3 files changed, 26 insertions(+), 3 deletions(-) | 22 | 3 files changed, 26 insertions(+), 3 deletions(-) |
3214 | 23 | 23 | ||
3215 | 24 | diff --git a/configure.ac b/configure.ac | 24 | diff --git a/configure.ac b/configure.ac |
3217 | 25 | index 7517fc4..74778a6 100644 | 25 | index e3d4d72..fb980fd 100644 |
3218 | 26 | --- a/configure.ac | 26 | --- a/configure.ac |
3219 | 27 | +++ b/configure.ac | 27 | +++ b/configure.ac |
3221 | 28 | @@ -1904,6 +1904,17 @@ fi | 28 | @@ -1912,6 +1912,17 @@ fi |
3222 | 29 | AC_SUBST([LIBZFS]) | 29 | AC_SUBST([LIBZFS]) |
3223 | 30 | AC_SUBST([LIBNVPAIR]) | 30 | AC_SUBST([LIBNVPAIR]) |
3224 | 31 | 31 | ||
3225 | diff --git a/debian/patches/no-devicetree-if-secure-boot.patch b/debian/patches/no-devicetree-if-secure-boot.patch | |||
3226 | index 3659f2d..50baa90 100644 | |||
3227 | --- a/debian/patches/no-devicetree-if-secure-boot.patch | |||
3228 | +++ b/debian/patches/no-devicetree-if-secure-boot.patch | |||
3229 | @@ -16,7 +16,7 @@ Patch-Name: no-devicetree-if-secure-boot.patch | |||
3230 | 16 | 2 files changed, 20 insertions(+) | 16 | 2 files changed, 20 insertions(+) |
3231 | 17 | 17 | ||
3232 | 18 | diff --git a/grub-core/loader/arm/linux.c b/grub-core/loader/arm/linux.c | 18 | diff --git a/grub-core/loader/arm/linux.c b/grub-core/loader/arm/linux.c |
3234 | 19 | index ed23dc7..2c85ca8 100644 | 19 | index 1f7ab75..feb707b 100644 |
3235 | 20 | --- a/grub-core/loader/arm/linux.c | 20 | --- a/grub-core/loader/arm/linux.c |
3236 | 21 | +++ b/grub-core/loader/arm/linux.c | 21 | +++ b/grub-core/loader/arm/linux.c |
3237 | 22 | @@ -30,6 +30,10 @@ | 22 | @@ -30,6 +30,10 @@ |
3238 | @@ -46,10 +46,10 @@ index ed23dc7..2c85ca8 100644 | |||
3239 | 46 | if (!dtb) | 46 | if (!dtb) |
3240 | 47 | return grub_errno; | 47 | return grub_errno; |
3241 | 48 | diff --git a/grub-core/loader/efi/fdt.c b/grub-core/loader/efi/fdt.c | 48 | diff --git a/grub-core/loader/efi/fdt.c b/grub-core/loader/efi/fdt.c |
3243 | 49 | index 7858d35..9b05e7e 100644 | 49 | index 971e84d..b846bf3 100644 |
3244 | 50 | --- a/grub-core/loader/efi/fdt.c | 50 | --- a/grub-core/loader/efi/fdt.c |
3245 | 51 | +++ b/grub-core/loader/efi/fdt.c | 51 | +++ b/grub-core/loader/efi/fdt.c |
3247 | 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)), |
3248 | 53 | return GRUB_ERR_NONE; | 53 | return GRUB_ERR_NONE; |
3249 | 54 | } | 54 | } |
3250 | 55 | 55 | ||
3251 | diff --git a/debian/patches/pc-verifiers-module.patch b/debian/patches/pc-verifiers-module.patch | |||
3252 | index 089e9e9..f372dda 100644 | |||
3253 | --- a/debian/patches/pc-verifiers-module.patch | |||
3254 | +++ b/debian/patches/pc-verifiers-module.patch | |||
3255 | @@ -52,7 +52,7 @@ index ee88e44..b6872d2 100644 | |||
3256 | 52 | KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/net.h | 52 | KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/net.h |
3257 | 53 | KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/memory.h | 53 | KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/memory.h |
3258 | 54 | diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def | 54 | diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def |
3260 | 55 | index 10f839b..f953817 100644 | 55 | index 0d7bce1..f252725 100644 |
3261 | 56 | --- a/grub-core/Makefile.core.def | 56 | --- a/grub-core/Makefile.core.def |
3262 | 57 | +++ b/grub-core/Makefile.core.def | 57 | +++ b/grub-core/Makefile.core.def |
3263 | 58 | @@ -141,7 +141,7 @@ kernel = { | 58 | @@ -141,7 +141,7 @@ kernel = { |
3264 | diff --git a/debian/patches/quick-boot.patch b/debian/patches/quick-boot.patch | |||
3265 | index b94aadc..a3675ac 100644 | |||
3266 | --- a/debian/patches/quick-boot.patch | |||
3267 | +++ b/debian/patches/quick-boot.patch | |||
3268 | @@ -32,10 +32,10 @@ Patch-Name: quick-boot.patch | |||
3269 | 32 | 7 files changed, 141 insertions(+), 13 deletions(-) | 32 | 7 files changed, 141 insertions(+), 13 deletions(-) |
3270 | 33 | 33 | ||
3271 | 34 | diff --git a/configure.ac b/configure.ac | 34 | diff --git a/configure.ac b/configure.ac |
3273 | 35 | index 256fc44..c42e4c7 100644 | 35 | index 2869155..4882eba 100644 |
3274 | 36 | --- a/configure.ac | 36 | --- a/configure.ac |
3275 | 37 | +++ b/configure.ac | 37 | +++ b/configure.ac |
3277 | 38 | @@ -1926,6 +1926,17 @@ else | 38 | @@ -1934,6 +1934,17 @@ else |
3278 | 39 | fi | 39 | fi |
3279 | 40 | AC_SUBST([QUIET_BOOT]) | 40 | AC_SUBST([QUIET_BOOT]) |
3280 | 41 | 41 | ||
3281 | 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 | |||
3282 | 42 | new file mode 100644 | 42 | new file mode 100644 |
3283 | index 0000000..afddd6c | |||
3284 | --- /dev/null | |||
3285 | +++ b/debian/patches/riscv-adjust-march-flags-for-binutils-2.38.patch | |||
3286 | @@ -0,0 +1,43 @@ | |||
3287 | 1 | From: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> | ||
3288 | 2 | Date: Sat, 29 Jan 2022 11:26:58 +0100 | ||
3289 | 3 | Subject: riscv: adjust -march flags for binutils 2.38 | ||
3290 | 4 | |||
3291 | 5 | As of version 2.38 binutils defaults to ISA specification version | ||
3292 | 6 | 2019-12-13. This version of the specification has has separated the | ||
3293 | 7 | the csr read/write (csrr*/csrw*) instructions and the fence.i from | ||
3294 | 8 | the I extension and put them into separate Zicsr and Zifencei | ||
3295 | 9 | extensions. | ||
3296 | 10 | |||
3297 | 11 | This implies that we have to adjust the -march flag passed to the | ||
3298 | 12 | compiler accordingly. | ||
3299 | 13 | |||
3300 | 14 | Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> | ||
3301 | 15 | Origin: https://lists.gnu.org/archive/html/grub-devel/2022-01/msg00173.html | ||
3302 | 16 | --- | ||
3303 | 17 | configure.ac | 8 ++++++++ | ||
3304 | 18 | 1 file changed, 8 insertions(+) | ||
3305 | 19 | |||
3306 | 20 | diff --git a/configure.ac b/configure.ac | ||
3307 | 21 | index 7517fc4..e3d4d72 100644 | ||
3308 | 22 | --- a/configure.ac | ||
3309 | 23 | +++ b/configure.ac | ||
3310 | 24 | @@ -852,11 +852,19 @@ if test x"$platform" != xemu ; then | ||
3311 | 25 | CFLAGS="$TARGET_CFLAGS -march=rv32imac -mabi=ilp32 -Werror" | ||
3312 | 26 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], | ||
3313 | 27 | [grub_cv_target_cc_soft_float="-march=rv32imac -mabi=ilp32"], []) | ||
3314 | 28 | + # ISA spec version 20191213 factored out extensions Zicsr and Zifencei | ||
3315 | 29 | + CFLAGS="$TARGET_CFLAGS -march=rv32imac_zicsr_zifencei -mabi=ilp32 -Werror" | ||
3316 | 30 | + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], | ||
3317 | 31 | + [grub_cv_target_cc_soft_float="-march=rv32imac_zicsr_zifencei -mabi=ilp32"], []) | ||
3318 | 32 | fi | ||
3319 | 33 | if test "x$target_cpu" = xriscv64; then | ||
3320 | 34 | CFLAGS="$TARGET_CFLAGS -march=rv64imac -mabi=lp64 -Werror" | ||
3321 | 35 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], | ||
3322 | 36 | [grub_cv_target_cc_soft_float="-march=rv64imac -mabi=lp64"], []) | ||
3323 | 37 | + # ISA spec version 20191213 factored out extensions Zicsr and Zifencei | ||
3324 | 38 | + CFLAGS="$TARGET_CFLAGS -march=rv64imac_zicsr_zifencei -mabi=lp64 -Werror" | ||
3325 | 39 | + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])], | ||
3326 | 40 | + [grub_cv_target_cc_soft_float="-march=rv64imac_zicsr_zifencei -mabi=lp64"], []) | ||
3327 | 41 | fi | ||
3328 | 42 | if test "x$target_cpu" = xia64; then | ||
3329 | 43 | CFLAGS="$TARGET_CFLAGS -mno-inline-float-divide -mno-inline-sqrt -Werror" | ||
3330 | diff --git a/debian/patches/series b/debian/patches/series | |||
3331 | index 0f2405b..9e6fc4f 100644 | |||
3332 | --- a/debian/patches/series | |||
3333 | +++ b/debian/patches/series | |||
3334 | @@ -1,3 +1,11 @@ | |||
3335 | 1 | riscv-adjust-march-flags-for-binutils-2.38.patch | ||
3336 | 2 | loader-drop-argv-argument-in-grub_initrd_load.patch | ||
3337 | 3 | efi-add-definition-of-LoadFile2-protocol.patch | ||
3338 | 4 | efi-implemented-LoadFile2-initrd-loading-protocol-fo.patch | ||
3339 | 5 | linux-ignore-FDT-unless-we-need-to-modify-it.patch | ||
3340 | 6 | loader-Move-arm64-linux-loader-to-common-code.patch | ||
3341 | 7 | RISC-V-Update-image-header.patch | ||
3342 | 8 | RISC-V-Use-common-linux-loader.patch | ||
3343 | 1 | olpc-prefix-hack.patch | 9 | olpc-prefix-hack.patch |
3344 | 2 | core-in-fs.patch | 10 | core-in-fs.patch |
3345 | 3 | dpkg-version-comparison.patch | 11 | dpkg-version-comparison.patch |
3346 | @@ -108,4 +116,10 @@ no-devicetree-if-secure-boot.patch | |||
3347 | 108 | 0099-chainloader-Avoid-a-double-free-when-validation-fail.patch | 116 | 0099-chainloader-Avoid-a-double-free-when-validation-fail.patch |
3348 | 109 | 0105-efilinux-Fix-integer-overflows-in-grub_cmd_initrd.patch | 117 | 0105-efilinux-Fix-integer-overflows-in-grub_cmd_initrd.patch |
3349 | 110 | ubuntu-verifiers-last.patch | 118 | ubuntu-verifiers-last.patch |
3350 | 119 | <<<<<<< debian/patches/series | ||
3351 | 111 | ubuntu-fuse3.patch | 120 | ubuntu-fuse3.patch |
3352 | 121 | ======= | ||
3353 | 122 | efi-correct-struct-grub_efi_boot_services.patch | ||
3354 | 123 | efi-implement-grub_efi_run_image.patch | ||
3355 | 124 | fat-fix-listing-the-root-directory.patch | ||
3356 | 125 | >>>>>>> debian/patches/series | ||
3357 | diff --git a/debian/patches/suse-add-support-for-UEFI-network-protocols.patch b/debian/patches/suse-add-support-for-UEFI-network-protocols.patch | |||
3358 | index 9724f73..262f4d0 100644 | |||
3359 | --- a/debian/patches/suse-add-support-for-UEFI-network-protocols.patch | |||
3360 | +++ b/debian/patches/suse-add-support-for-UEFI-network-protocols.patch | |||
3361 | @@ -64,10 +64,10 @@ V6: | |||
3362 | 64 | create mode 100644 include/grub/net/efi.h | 64 | create mode 100644 include/grub/net/efi.h |
3363 | 65 | 65 | ||
3364 | 66 | diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def | 66 | diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def |
3366 | 67 | index 98cda49..a47c403 100644 | 67 | index 0b5b4e7..3b06462 100644 |
3367 | 68 | --- a/grub-core/Makefile.core.def | 68 | --- a/grub-core/Makefile.core.def |
3368 | 69 | +++ b/grub-core/Makefile.core.def | 69 | +++ b/grub-core/Makefile.core.def |
3370 | 70 | @@ -2322,6 +2322,12 @@ module = { | 70 | @@ -2324,6 +2324,12 @@ module = { |
3371 | 71 | common = net/ethernet.c; | 71 | common = net/ethernet.c; |
3372 | 72 | common = net/arp.c; | 72 | common = net/arp.c; |
3373 | 73 | common = net/netbuff.c; | 73 | common = net/netbuff.c; |
3374 | @@ -3969,10 +3969,10 @@ index 15a2f29..34bf04f 100644 | |||
3375 | 3969 | +#endif | 3969 | +#endif |
3376 | 3970 | } | 3970 | } |
3377 | 3971 | diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h | 3971 | diff --git a/include/grub/efi/api.h b/include/grub/efi/api.h |
3379 | 3972 | index 9cab1a5..3b2f2e3 100644 | 3972 | index 479c2a8..3211f04 100644 |
3380 | 3973 | --- a/include/grub/efi/api.h | 3973 | --- a/include/grub/efi/api.h |
3381 | 3974 | +++ b/include/grub/efi/api.h | 3974 | +++ b/include/grub/efi/api.h |
3383 | 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]; |
3384 | 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))); |
3385 | 3977 | typedef grub_efi_uint64_t grub_efi_physical_address_t; | 3977 | typedef grub_efi_uint64_t grub_efi_physical_address_t; |
3386 | 3978 | typedef grub_efi_uint64_t grub_efi_virtual_address_t; | 3978 | typedef grub_efi_uint64_t grub_efi_virtual_address_t; |
3387 | @@ -3996,7 +3996,7 @@ index 9cab1a5..3b2f2e3 100644 | |||
3388 | 3996 | 3996 | ||
3389 | 3997 | struct grub_efi_guid | 3997 | struct grub_efi_guid |
3390 | 3998 | { | 3998 | { |
3392 | 3999 | @@ -875,6 +892,8 @@ struct grub_efi_ipv6_device_path | 3999 | @@ -880,6 +897,8 @@ struct grub_efi_ipv6_device_path |
3393 | 4000 | grub_efi_uint16_t remote_port; | 4000 | grub_efi_uint16_t remote_port; |
3394 | 4001 | grub_efi_uint16_t protocol; | 4001 | grub_efi_uint16_t protocol; |
3395 | 4002 | grub_efi_uint8_t static_ip_address; | 4002 | grub_efi_uint8_t static_ip_address; |
3396 | @@ -4005,7 +4005,7 @@ index 9cab1a5..3b2f2e3 100644 | |||
3397 | 4005 | } GRUB_PACKED; | 4005 | } GRUB_PACKED; |
3398 | 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; |
3399 | 4007 | 4007 | ||
3401 | 4008 | @@ -924,6 +943,15 @@ struct grub_efi_uri_device_path | 4008 | @@ -929,6 +948,15 @@ struct grub_efi_uri_device_path |
3402 | 4009 | } GRUB_PACKED; | 4009 | } GRUB_PACKED; |
3403 | 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; |
3404 | 4011 | 4011 | ||
3405 | @@ -4021,7 +4021,7 @@ index 9cab1a5..3b2f2e3 100644 | |||
3406 | 4021 | #define GRUB_EFI_VENDOR_MESSAGING_DEVICE_PATH_SUBTYPE 10 | 4021 | #define GRUB_EFI_VENDOR_MESSAGING_DEVICE_PATH_SUBTYPE 10 |
3407 | 4022 | 4022 | ||
3408 | 4023 | /* Media Device Path. */ | 4023 | /* Media Device Path. */ |
3410 | 4024 | @@ -1006,6 +1034,23 @@ struct grub_efi_bios_device_path | 4024 | @@ -1011,6 +1039,23 @@ struct grub_efi_bios_device_path |
3411 | 4025 | } GRUB_PACKED; | 4025 | } GRUB_PACKED; |
3412 | 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; |
3413 | 4027 | 4027 | ||
3414 | @@ -4045,7 +4045,7 @@ index 9cab1a5..3b2f2e3 100644 | |||
3415 | 4045 | struct grub_efi_open_protocol_information_entry | 4045 | struct grub_efi_open_protocol_information_entry |
3416 | 4046 | { | 4046 | { |
3417 | 4047 | grub_efi_handle_t agent_handle; | 4047 | grub_efi_handle_t agent_handle; |
3419 | 4048 | @@ -1497,23 +1542,28 @@ typedef struct grub_efi_simple_text_output_interface grub_efi_simple_text_output | 4048 | @@ -1502,23 +1547,28 @@ typedef struct grub_efi_simple_text_output_interface grub_efi_simple_text_output |
3420 | 4049 | 4049 | ||
3421 | 4050 | typedef grub_uint8_t grub_efi_pxe_packet_t[1472]; | 4050 | typedef grub_uint8_t grub_efi_pxe_packet_t[1472]; |
3422 | 4051 | 4051 | ||
3423 | @@ -4088,7 +4088,7 @@ index 9cab1a5..3b2f2e3 100644 | |||
3424 | 4088 | 4088 | ||
3425 | 4089 | #define GRUB_EFI_PXE_BASE_CODE_MAX_IPCNT 8 | 4089 | #define GRUB_EFI_PXE_BASE_CODE_MAX_IPCNT 8 |
3426 | 4090 | typedef struct { | 4090 | typedef struct { |
3428 | 4091 | @@ -1563,17 +1613,31 @@ typedef struct grub_efi_pxe_mode | 4091 | @@ -1568,17 +1618,31 @@ typedef struct grub_efi_pxe_mode |
3429 | 4092 | typedef struct grub_efi_pxe | 4092 | typedef struct grub_efi_pxe |
3430 | 4093 | { | 4093 | { |
3431 | 4094 | grub_uint64_t rev; | 4094 | grub_uint64_t rev; |
3432 | @@ -4124,7 +4124,7 @@ index 9cab1a5..3b2f2e3 100644 | |||
3433 | 4124 | void (*setpackets) (void); | 4124 | void (*setpackets) (void); |
3434 | 4125 | struct grub_efi_pxe_mode *mode; | 4125 | struct grub_efi_pxe_mode *mode; |
3435 | 4126 | } grub_efi_pxe_t; | 4126 | } grub_efi_pxe_t; |
3437 | 4127 | @@ -1835,6 +1899,44 @@ struct grub_efi_ip4_config2_protocol | 4127 | @@ -1850,6 +1914,44 @@ struct grub_efi_ip4_config2_protocol |
3438 | 4128 | }; | 4128 | }; |
3439 | 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; |
3440 | 4130 | 4130 | ||
3441 | @@ -4169,7 +4169,7 @@ index 9cab1a5..3b2f2e3 100644 | |||
3442 | 4169 | enum grub_efi_ip6_config_data_type { | 4169 | enum grub_efi_ip6_config_data_type { |
3443 | 4170 | GRUB_EFI_IP6_CONFIG_DATA_TYPE_INTERFACEINFO, | 4170 | GRUB_EFI_IP6_CONFIG_DATA_TYPE_INTERFACEINFO, |
3444 | 4171 | GRUB_EFI_IP6_CONFIG_DATA_TYPE_ALT_INTERFACEID, | 4171 | GRUB_EFI_IP6_CONFIG_DATA_TYPE_ALT_INTERFACEID, |
3446 | 4172 | @@ -1869,6 +1971,49 @@ struct grub_efi_ip6_config_protocol | 4172 | @@ -1884,6 +1986,49 @@ struct grub_efi_ip6_config_protocol |
3447 | 4173 | }; | 4173 | }; |
3448 | 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; |
3449 | 4175 | 4175 | ||
3450 | diff --git a/debian/patches/ubuntu-add-initrd-less-boot-fallback.patch b/debian/patches/ubuntu-add-initrd-less-boot-fallback.patch | |||
3451 | index 6dc4335..9a0ed6c 100644 | |||
3452 | --- a/debian/patches/ubuntu-add-initrd-less-boot-fallback.patch | |||
3453 | +++ b/debian/patches/ubuntu-add-initrd-less-boot-fallback.patch | |||
3454 | @@ -32,7 +32,7 @@ index bf9c1ba..353061e 100644 | |||
3455 | 32 | 32 | ||
3456 | 33 | syslinux_test: $(top_builddir)/config.status tests/syslinux/ubuntu10.04_grub.cfg | 33 | syslinux_test: $(top_builddir)/config.status tests/syslinux/ubuntu10.04_grub.cfg |
3457 | 34 | diff --git a/configure.ac b/configure.ac | 34 | diff --git a/configure.ac b/configure.ac |
3459 | 35 | index 22c6cf7..3c87596 100644 | 35 | index a29beb9..15a2a50 100644 |
3460 | 36 | --- a/configure.ac | 36 | --- a/configure.ac |
3461 | 37 | +++ b/configure.ac | 37 | +++ b/configure.ac |
3462 | 38 | @@ -314,6 +314,16 @@ AC_SUBST(grubdirname) | 38 | @@ -314,6 +314,16 @@ AC_SUBST(grubdirname) |
3463 | diff --git a/debian/patches/ubuntu-efi-allow-loopmount-chainload.patch b/debian/patches/ubuntu-efi-allow-loopmount-chainload.patch | |||
3464 | index b0e49aa..7ab0799 100644 | |||
3465 | --- a/debian/patches/ubuntu-efi-allow-loopmount-chainload.patch | |||
3466 | +++ b/debian/patches/ubuntu-efi-allow-loopmount-chainload.patch | |||
3467 | @@ -40,7 +40,7 @@ index 41bebd1..99f4792 100644 | |||
3468 | 40 | static unsigned long last_id = 0; | 40 | static unsigned long last_id = 0; |
3469 | 41 | 41 | ||
3470 | 42 | diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c | 42 | diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c |
3472 | 43 | index 9e301f2..cf76f48 100644 | 43 | index c3144de..2b74d79 100644 |
3473 | 44 | --- a/grub-core/loader/efi/chainloader.c | 44 | --- a/grub-core/loader/efi/chainloader.c |
3474 | 45 | +++ b/grub-core/loader/efi/chainloader.c | 45 | +++ b/grub-core/loader/efi/chainloader.c |
3475 | 46 | @@ -24,6 +24,7 @@ | 46 | @@ -24,6 +24,7 @@ |
3476 | @@ -51,7 +51,7 @@ index 9e301f2..cf76f48 100644 | |||
3477 | 51 | #include <grub/misc.h> | 51 | #include <grub/misc.h> |
3478 | 52 | #include <grub/charset.h> | 52 | #include <grub/charset.h> |
3479 | 53 | #include <grub/mm.h> | 53 | #include <grub/mm.h> |
3481 | 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)), |
3482 | 55 | grub_efi_status_t status; | 55 | grub_efi_status_t status; |
3483 | 56 | grub_efi_boot_services_t *b; | 56 | grub_efi_boot_services_t *b; |
3484 | 57 | grub_device_t dev = 0; | 57 | grub_device_t dev = 0; |
3485 | @@ -59,7 +59,7 @@ index 9e301f2..cf76f48 100644 | |||
3486 | 59 | grub_efi_device_path_t *dp = 0; | 59 | grub_efi_device_path_t *dp = 0; |
3487 | 60 | char *filename; | 60 | char *filename; |
3488 | 61 | void *boot_image = 0; | 61 | void *boot_image = 0; |
3490 | 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)), |
3491 | 63 | if (! dev) | 63 | if (! dev) |
3492 | 64 | goto fail; | 64 | goto fail; |
3493 | 65 | 65 | ||
3494 | @@ -75,7 +75,7 @@ index 9e301f2..cf76f48 100644 | |||
3495 | 75 | if (dev->disk) | 75 | if (dev->disk) |
3496 | 76 | dev_handle = grub_efidisk_get_device_handle (dev->disk); | 76 | dev_handle = grub_efidisk_get_device_handle (dev->disk); |
3497 | 77 | else if (dev->net && dev->net->server) | 77 | else if (dev->net && dev->net->server) |
3499 | 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)), |
3500 | 79 | grub_device_close (dev); | 79 | grub_device_close (dev); |
3501 | 80 | 80 | ||
3502 | 81 | fail: | 81 | fail: |
3503 | diff --git a/debian/patches/ubuntu-fix-lzma-decompressor-objcopy.patch b/debian/patches/ubuntu-fix-lzma-decompressor-objcopy.patch | |||
3504 | index 75ab70c..2c1a376 100644 | |||
3505 | --- a/debian/patches/ubuntu-fix-lzma-decompressor-objcopy.patch | |||
3506 | +++ b/debian/patches/ubuntu-fix-lzma-decompressor-objcopy.patch | |||
3507 | @@ -15,7 +15,7 @@ Signed-off-by: Mathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com> | |||
3508 | 15 | 1 file changed, 1 insertion(+), 1 deletion(-) | 15 | 1 file changed, 1 insertion(+), 1 deletion(-) |
3509 | 16 | 16 | ||
3510 | 17 | diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def | 17 | diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def |
3512 | 18 | index f953817..98cda49 100644 | 18 | index f252725..0b5b4e7 100644 |
3513 | 19 | --- a/grub-core/Makefile.core.def | 19 | --- a/grub-core/Makefile.core.def |
3514 | 20 | +++ b/grub-core/Makefile.core.def | 20 | +++ b/grub-core/Makefile.core.def |
3515 | 21 | @@ -550,7 +550,7 @@ image = { | 21 | @@ -550,7 +550,7 @@ image = { |
3516 | diff --git a/debian/patches/ubuntu-linuxefi-arm64-set-base-addr.patch b/debian/patches/ubuntu-linuxefi-arm64-set-base-addr.patch | |||
3517 | index e00ae03..9b5e997 100644 | |||
3518 | --- a/debian/patches/ubuntu-linuxefi-arm64-set-base-addr.patch | |||
3519 | +++ b/debian/patches/ubuntu-linuxefi-arm64-set-base-addr.patch | |||
3520 | @@ -30,13 +30,13 @@ Origin: https://github.com/rhboot/grub2/commit/1d5ef08216edec4d31d0e10cfdb30b5eb | |||
3521 | 30 | Last-Updated: 2020-11-09 | 30 | Last-Updated: 2020-11-09 |
3522 | 31 | Patch-Name: ubuntu-linuxefi-arm64-set-base-addr.patch | 31 | Patch-Name: ubuntu-linuxefi-arm64-set-base-addr.patch |
3523 | 32 | --- | 32 | --- |
3525 | 33 | grub-core/loader/efi/linux.c | 15 +++++++++++++++ | 33 | grub-core/loader/efi/linux_sb.c | 15 +++++++++++++++ |
3526 | 34 | 1 file changed, 15 insertions(+) | 34 | 1 file changed, 15 insertions(+) |
3527 | 35 | 35 | ||
3529 | 36 | diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c | 36 | diff --git a/grub-core/loader/efi/linux_sb.c b/grub-core/loader/efi/linux_sb.c |
3530 | 37 | index e372b26..73a7196 100644 | 37 | index e372b26..73a7196 100644 |
3533 | 38 | --- a/grub-core/loader/efi/linux.c | 38 | --- a/grub-core/loader/efi/linux_sb.c |
3534 | 39 | +++ b/grub-core/loader/efi/linux.c | 39 | +++ b/grub-core/loader/efi/linux_sb.c |
3535 | 40 | @@ -71,6 +71,7 @@ grub_err_t | 40 | @@ -71,6 +71,7 @@ grub_err_t |
3536 | 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, |
3537 | 42 | void *kernel_params) | 42 | void *kernel_params) |
3538 | diff --git a/debian/patches/ubuntu-linuxefi-arm64.patch b/debian/patches/ubuntu-linuxefi-arm64.patch | |||
3539 | index e7f4e71..7789a5a 100644 | |||
3540 | --- a/debian/patches/ubuntu-linuxefi-arm64.patch | |||
3541 | +++ b/debian/patches/ubuntu-linuxefi-arm64.patch | |||
3542 | @@ -12,23 +12,22 @@ Bug-Ubuntu: https://bugs.launchpad.net/1862279 | |||
3543 | 12 | Origin: vendor, https://github.com/rhboot/grub2/commit/2786ab864cf00c15123320671f653e9a36ba12b4 | 12 | Origin: vendor, https://github.com/rhboot/grub2/commit/2786ab864cf00c15123320671f653e9a36ba12b4 |
3544 | 13 | Patch-Name: ubuntu-linuxefi-arm64.patch | 13 | Patch-Name: ubuntu-linuxefi-arm64.patch |
3545 | 14 | --- | 14 | --- |
3548 | 15 | grub-core/loader/arm64/linux.c | 106 ++++++++++++++++++++++------------------- | 15 | grub-core/loader/efi/linux.c | 101 ++++++++++++++++++++++--------------------- |
3549 | 16 | 1 file changed, 56 insertions(+), 50 deletions(-) | 16 | 1 file changed, 51 insertions(+), 50 deletions(-) |
3550 | 17 | 17 | ||
3556 | 18 | diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c | 18 | diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c |
3557 | 19 | index 1a5296a..4e9eac3 100644 | 19 | index d81e7be..93e4cfc 100644 |
3558 | 20 | --- a/grub-core/loader/arm64/linux.c | 20 | --- a/grub-core/loader/efi/linux.c |
3559 | 21 | +++ b/grub-core/loader/arm64/linux.c | 21 | +++ b/grub-core/loader/efi/linux.c |
3560 | 22 | @@ -42,6 +42,8 @@ static int loaded; | 22 | @@ -42,6 +42,7 @@ static int loaded; |
3561 | 23 | 23 | ||
3562 | 24 | static void *kernel_addr; | 24 | static void *kernel_addr; |
3563 | 25 | static grub_uint64_t kernel_size; | 25 | static grub_uint64_t kernel_size; |
3564 | 26 | +static grub_uint32_t handover_offset; | 26 | +static grub_uint32_t handover_offset; |
3565 | 27 | + | ||
3566 | 28 | 27 | ||
3567 | 29 | static char *linux_args; | 28 | static char *linux_args; |
3568 | 30 | static grub_uint32_t cmdline_size; | 29 | static grub_uint32_t cmdline_size; |
3570 | 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) |
3571 | 32 | static grub_err_t | 31 | static grub_err_t |
3572 | 33 | finalize_params_linux (void) | 32 | finalize_params_linux (void) |
3573 | 34 | { | 33 | { |
3574 | @@ -36,9 +35,9 @@ index 1a5296a..4e9eac3 100644 | |||
3575 | 36 | + grub_efi_loaded_image_t *loaded_image = NULL; | 35 | + grub_efi_loaded_image_t *loaded_image = NULL; |
3576 | 37 | + int node, retval, len; | 36 | + int node, retval, len; |
3577 | 38 | 37 | ||
3579 | 39 | void *fdt; | 38 | void *fdt = NULL; |
3580 | 40 | 39 | ||
3582 | 41 | @@ -110,6 +113,27 @@ finalize_params_linux (void) | 40 | @@ -134,6 +136,27 @@ finalize_params_linux (void) |
3583 | 42 | if (grub_fdt_install() != GRUB_ERR_NONE) | 41 | if (grub_fdt_install() != GRUB_ERR_NONE) |
3584 | 43 | goto failure; | 42 | goto failure; |
3585 | 44 | 43 | ||
3586 | @@ -66,28 +65,14 @@ index 1a5296a..4e9eac3 100644 | |||
3587 | 66 | return GRUB_ERR_NONE; | 65 | return GRUB_ERR_NONE; |
3588 | 67 | 66 | ||
3589 | 68 | failure: | 67 | failure: |
3591 | 69 | @@ -117,70 +141,48 @@ failure: | 68 | @@ -141,62 +164,36 @@ failure: |
3592 | 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"); |
3593 | 71 | } | 70 | } |
3594 | 72 | 71 | ||
3595 | 72 | -grub_err_t | ||
3596 | 73 | -grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args) | ||
3597 | 73 | +static void | 74 | +static void |
3598 | 74 | +free_params (void) | 75 | +free_params (void) |
3599 | 75 | +{ | ||
3600 | 76 | + grub_efi_loaded_image_t *loaded_image = NULL; | ||
3601 | 77 | + loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle); | ||
3602 | 78 | + if (loaded_image) | ||
3603 | 79 | + { | ||
3604 | 80 | + if (loaded_image->load_options) | ||
3605 | 81 | + grub_efi_free_pages ((grub_efi_physical_address_t)(grub_efi_uintn_t) | ||
3606 | 82 | + loaded_image->load_options, | ||
3607 | 83 | + GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); | ||
3608 | 84 | + loaded_image->load_options = NULL; | ||
3609 | 85 | + loaded_image->load_options_size = 0; | ||
3610 | 86 | + } | ||
3611 | 87 | +} | ||
3612 | 88 | + | ||
3613 | 89 | grub_err_t | ||
3614 | 90 | grub_arch_efi_linux_boot_image (grub_addr_t addr, grub_size_t size, char *args) | ||
3615 | 91 | { | 76 | { |
3616 | 92 | - grub_efi_memory_mapped_device_path_t *mempath; | 77 | - grub_efi_memory_mapped_device_path_t *mempath; |
3617 | 93 | - grub_efi_handle_t image_handle; | 78 | - grub_efi_handle_t image_handle; |
3618 | @@ -106,21 +91,35 @@ index 1a5296a..4e9eac3 100644 | |||
3619 | 106 | - mempath[0].memory_type = GRUB_EFI_LOADER_DATA; | 91 | - mempath[0].memory_type = GRUB_EFI_LOADER_DATA; |
3620 | 107 | - mempath[0].start_address = addr; | 92 | - mempath[0].start_address = addr; |
3621 | 108 | - mempath[0].end_address = addr + size; | 93 | - mempath[0].end_address = addr + size; |
3624 | 109 | + grub_err_t retval; | 94 | - |
3623 | 110 | |||
3625 | 111 | - mempath[1].header.type = GRUB_EFI_END_DEVICE_PATH_TYPE; | 95 | - mempath[1].header.type = GRUB_EFI_END_DEVICE_PATH_TYPE; |
3626 | 112 | - mempath[1].header.subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; | 96 | - mempath[1].header.subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; |
3627 | 113 | - mempath[1].header.length = sizeof (grub_efi_device_path_t); | 97 | - mempath[1].header.length = sizeof (grub_efi_device_path_t); |
3629 | 114 | - | 98 | + grub_efi_loaded_image_t *loaded_image = NULL; |
3630 | 99 | + loaded_image = grub_efi_get_loaded_image (grub_efi_image_handle); | ||
3631 | 100 | + if (loaded_image) | ||
3632 | 101 | + { | ||
3633 | 102 | + if (loaded_image->load_options) | ||
3634 | 103 | + grub_efi_free_pages ((grub_efi_physical_address_t)(grub_efi_uintn_t) | ||
3635 | 104 | + loaded_image->load_options, | ||
3636 | 105 | + GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); | ||
3637 | 106 | + loaded_image->load_options = NULL; | ||
3638 | 107 | + loaded_image->load_options_size = 0; | ||
3639 | 108 | + } | ||
3640 | 109 | +} | ||
3641 | 110 | |||
3642 | 115 | - b = grub_efi_system_table->boot_services; | 111 | - b = grub_efi_system_table->boot_services; |
3643 | 116 | - status = b->load_image (0, grub_efi_image_handle, | 112 | - status = b->load_image (0, grub_efi_image_handle, |
3644 | 117 | - (grub_efi_device_path_t *) mempath, | 113 | - (grub_efi_device_path_t *) mempath, |
3645 | 118 | - (void *) addr, size, &image_handle); | 114 | - (void *) addr, size, &image_handle); |
3646 | 119 | - if (status != GRUB_EFI_SUCCESS) | 115 | - if (status != GRUB_EFI_SUCCESS) |
3647 | 120 | - return grub_error (GRUB_ERR_BAD_OS, "cannot load image"); | 116 | - return grub_error (GRUB_ERR_BAD_OS, "cannot load image"); |
3651 | 121 | + retval = finalize_params_linux (); | 117 | +grub_err_t |
3652 | 122 | + if (retval != GRUB_ERR_NONE) | 118 | +grub_arch_efi_linux_boot_image (grub_addr_t addr __attribute__((unused)), |
3653 | 123 | + return grub_errno; | 119 | + grub_size_t size __attribute__((unused)), |
3654 | 120 | + char *args) | ||
3655 | 121 | +{ | ||
3656 | 122 | + grub_err_t retval; | ||
3657 | 124 | 123 | ||
3658 | 125 | grub_dprintf ("linux", "linux command line: '%s'\n", args); | 124 | grub_dprintf ("linux", "linux command line: '%s'\n", args); |
3659 | 126 | 125 | ||
3660 | @@ -136,35 +135,23 @@ index 1a5296a..4e9eac3 100644 | |||
3661 | 136 | - loaded_image->load_options_size = | 135 | - loaded_image->load_options_size = |
3662 | 137 | - 2 * grub_utf8_to_utf16 (loaded_image->load_options, len, | 136 | - 2 * grub_utf8_to_utf16 (loaded_image->load_options, len, |
3663 | 138 | - (grub_uint8_t *) args, len, NULL); | 137 | - (grub_uint8_t *) args, len, NULL); |
3667 | 139 | + (void) addr; | 138 | - |
3665 | 140 | + (void) size; | ||
3666 | 141 | |||
3668 | 142 | - grub_dprintf ("linux", "starting image %p\n", image_handle); | 139 | - grub_dprintf ("linux", "starting image %p\n", image_handle); |
3669 | 143 | - status = b->start_image (image_handle, 0, NULL); | 140 | - status = b->start_image (image_handle, 0, NULL); |
3670 | 141 | + retval = grub_efi_linux_boot (kernel_addr, handover_offset, kernel_addr); | ||
3671 | 144 | 142 | ||
3673 | 145 | - /* When successful, not reached */ | 143 | /* When successful, not reached */ |
3674 | 146 | - b->unload_image (image_handle); | 144 | - b->unload_image (image_handle); |
3675 | 147 | - grub_efi_free_pages ((grub_addr_t) loaded_image->load_options, | 145 | - grub_efi_free_pages ((grub_addr_t) loaded_image->load_options, |
3676 | 148 | - GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); | 146 | - GRUB_EFI_BYTES_TO_PAGES (loaded_image->load_options_size)); |
3680 | 149 | + retval = grub_efi_linux_boot ((char *)kernel_addr, handover_offset, | 147 | - |
3678 | 150 | + kernel_addr); | ||
3679 | 151 | |||
3681 | 152 | - return grub_errno; | 148 | - return grub_errno; |
3682 | 153 | + /* Never reached... */ | ||
3683 | 154 | + free_params(); | 149 | + free_params(); |
3684 | 155 | + return retval; | 150 | + return retval; |
3685 | 156 | } | 151 | } |
3686 | 157 | 152 | ||
3687 | 158 | static grub_err_t | 153 | static grub_err_t |
3697 | 159 | grub_linux_boot (void) | 154 | @@ -411,6 +408,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), |
3689 | 160 | { | ||
3690 | 161 | - if (finalize_params_linux () != GRUB_ERR_NONE) | ||
3691 | 162 | - return grub_errno; | ||
3692 | 163 | - | ||
3693 | 164 | return (grub_arch_efi_linux_boot_image((grub_addr_t)kernel_addr, | ||
3694 | 165 | kernel_size, linux_args)); | ||
3695 | 166 | } | ||
3696 | 167 | @@ -296,6 +298,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), | ||
3698 | 168 | { | 155 | { |
3699 | 169 | grub_file_t file = 0; | 156 | grub_file_t file = 0; |
3700 | 170 | struct linux_arch_kernel_header lh; | 157 | struct linux_arch_kernel_header lh; |
3701 | @@ -172,7 +159,7 @@ index 1a5296a..4e9eac3 100644 | |||
3702 | 172 | grub_err_t err; | 159 | grub_err_t err; |
3703 | 173 | int rc; | 160 | int rc; |
3704 | 174 | 161 | ||
3706 | 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)), |
3707 | 176 | goto fail; | 163 | goto fail; |
3708 | 177 | } | 164 | } |
3709 | 178 | 165 | ||
3710 | diff --git a/debian/patches/ubuntu-linuxefi.patch b/debian/patches/ubuntu-linuxefi.patch | |||
3711 | index eb99d16..533b900 100644 | |||
3712 | --- a/debian/patches/ubuntu-linuxefi.patch | |||
3713 | +++ b/debian/patches/ubuntu-linuxefi.patch | |||
3714 | @@ -318,17 +318,17 @@ Last-Update: 2018-12-07 | |||
3715 | 318 | Updated 2021-12-13: If we cannot allocate kernel at preferred address, | 318 | Updated 2021-12-13: If we cannot allocate kernel at preferred address, |
3716 | 319 | reset errno so that we do not fail erroneously with out of memory. | 319 | reset errno so that we do not fail erroneously with out of memory. |
3717 | 320 | --- | 320 | --- |
3719 | 321 | grub-core/Makefile.core.def | 15 +- | 321 | grub-core/Makefile.core.def | 17 +- |
3720 | 322 | grub-core/commands/iorw.c | 7 + | 322 | grub-core/commands/iorw.c | 7 + |
3721 | 323 | grub-core/commands/memrw.c | 7 + | 323 | grub-core/commands/memrw.c | 7 + |
3722 | 324 | grub-core/kern/arm/coreboot/coreboot.S | 6 + | 324 | grub-core/kern/arm/coreboot/coreboot.S | 6 + |
3723 | 325 | grub-core/kern/dl.c | 1 + | 325 | grub-core/kern/dl.c | 1 + |
3724 | 326 | grub-core/kern/efi/mm.c | 32 ++ | 326 | grub-core/kern/efi/mm.c | 32 ++ |
3725 | 327 | grub-core/loader/arm64/linux.c | 16 + | ||
3726 | 328 | grub-core/loader/efi/appleloader.c | 7 + | 327 | grub-core/loader/efi/appleloader.c | 7 + |
3728 | 329 | grub-core/loader/efi/chainloader.c | 816 ++++++++++++++++++++++++++++++--- | 328 | grub-core/loader/efi/chainloader.c | 815 ++++++++++++++++++++++++++++++--- |
3729 | 330 | grub-core/loader/efi/fdt.c | 1 + | 329 | grub-core/loader/efi/fdt.c | 1 + |
3731 | 331 | grub-core/loader/efi/linux.c | 86 ++++ | 330 | grub-core/loader/efi/linux.c | 16 + |
3732 | 331 | grub-core/loader/efi/linux_sb.c | 86 ++++ | ||
3733 | 332 | grub-core/loader/i386/bsd.c | 7 + | 332 | grub-core/loader/i386/bsd.c | 7 + |
3734 | 333 | grub-core/loader/i386/efi/linux.c | 382 +++++++++++++++ | 333 | grub-core/loader/i386/efi/linux.c | 382 +++++++++++++++ |
3735 | 334 | grub-core/loader/i386/linux.c | 78 +++- | 334 | grub-core/loader/i386/linux.c | 78 +++- |
3736 | @@ -344,8 +344,8 @@ reset errno so that we do not fail erroneously with out of memory. | |||
3737 | 344 | include/grub/mips/linux.h | 0 | 344 | include/grub/mips/linux.h | 0 |
3738 | 345 | include/grub/powerpc/linux.h | 0 | 345 | include/grub/powerpc/linux.h | 0 |
3739 | 346 | include/grub/sparc64/linux.h | 0 | 346 | include/grub/sparc64/linux.h | 0 |
3742 | 347 | 26 files changed, 1510 insertions(+), 100 deletions(-) | 347 | 26 files changed, 1511 insertions(+), 100 deletions(-) |
3743 | 348 | create mode 100644 grub-core/loader/efi/linux.c | 348 | create mode 100644 grub-core/loader/efi/linux_sb.c |
3744 | 349 | create mode 100644 grub-core/loader/i386/efi/linux.c | 349 | create mode 100644 grub-core/loader/i386/efi/linux.c |
3745 | 350 | create mode 100644 include/grub/efi/linux.h | 350 | create mode 100644 include/grub/efi/linux.h |
3746 | 351 | create mode 100644 include/grub/ia64/linux.h | 351 | create mode 100644 include/grub/ia64/linux.h |
3747 | @@ -354,24 +354,26 @@ reset errno so that we do not fail erroneously with out of memory. | |||
3748 | 354 | create mode 100644 include/grub/sparc64/linux.h | 354 | create mode 100644 include/grub/sparc64/linux.h |
3749 | 355 | 355 | ||
3750 | 356 | diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def | 356 | diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def |
3752 | 357 | index 8022e1c..715d137 100644 | 357 | index 0536575..1a3ead6 100644 |
3753 | 358 | --- a/grub-core/Makefile.core.def | 358 | --- a/grub-core/Makefile.core.def |
3754 | 359 | +++ b/grub-core/Makefile.core.def | 359 | +++ b/grub-core/Makefile.core.def |
3756 | 360 | @@ -1807,10 +1807,13 @@ module = { | 360 | @@ -1807,10 +1807,15 @@ module = { |
3757 | 361 | ia64_efi = loader/ia64/efi/linux.c; | 361 | ia64_efi = loader/ia64/efi/linux.c; |
3758 | 362 | arm_coreboot = loader/arm/linux.c; | 362 | arm_coreboot = loader/arm/linux.c; |
3761 | 363 | arm_efi = loader/arm64/linux.c; | 363 | arm_efi = loader/efi/linux.c; |
3762 | 364 | + arm_efi = loader/efi/linux.c; | 364 | + arm_efi = loader/efi/linux_sb.c; |
3763 | 365 | arm_uboot = loader/arm/linux.c; | 365 | arm_uboot = loader/arm/linux.c; |
3768 | 366 | arm64 = loader/arm64/linux.c; | 366 | arm64 = loader/efi/linux.c; |
3769 | 367 | + arm64 = loader/efi/linux.c; | 367 | + arm64 = loader/efi/linux_sb.c; |
3770 | 368 | riscv32 = loader/riscv/linux.c; | 368 | riscv32 = loader/efi/linux.c; |
3771 | 369 | riscv64 = loader/riscv/linux.c; | 369 | + riscv32 = loader/efi/linux_sb.c; |
3772 | 370 | riscv64 = loader/efi/linux.c; | ||
3773 | 371 | + riscv64 = loader/efi/linux_sb.c; | ||
3774 | 370 | + cflags = '-Wno-error=cast-align'; | 372 | + cflags = '-Wno-error=cast-align'; |
3775 | 371 | common = loader/linux.c; | 373 | common = loader/linux.c; |
3776 | 372 | common = lib/cmdline.c; | 374 | common = lib/cmdline.c; |
3777 | 373 | enable = noemu; | 375 | enable = noemu; |
3779 | 374 | @@ -1819,7 +1822,7 @@ module = { | 376 | @@ -1819,7 +1824,7 @@ module = { |
3780 | 375 | module = { | 377 | module = { |
3781 | 376 | name = fdt; | 378 | name = fdt; |
3782 | 377 | efi = loader/efi/fdt.c; | 379 | efi = loader/efi/fdt.c; |
3783 | @@ -380,14 +382,14 @@ index 8022e1c..715d137 100644 | |||
3784 | 380 | enable = fdt; | 382 | enable = fdt; |
3785 | 381 | }; | 383 | }; |
3786 | 382 | 384 | ||
3788 | 383 | @@ -1874,12 +1877,22 @@ module = { | 385 | @@ -1874,12 +1879,22 @@ module = { |
3789 | 384 | enable = x86_64_efi; | 386 | enable = x86_64_efi; |
3790 | 385 | }; | 387 | }; |
3791 | 386 | 388 | ||
3792 | 387 | +module = { | 389 | +module = { |
3793 | 388 | + name = linuxefi; | 390 | + name = linuxefi; |
3794 | 389 | + efi = loader/i386/efi/linux.c; | 391 | + efi = loader/i386/efi/linux.c; |
3796 | 390 | + efi = loader/efi/linux.c; | 392 | + efi = loader/efi/linux_sb.c; |
3797 | 391 | + cflags = '-Wno-error=cast-align'; | 393 | + cflags = '-Wno-error=cast-align'; |
3798 | 392 | + enable = i386_efi; | 394 | + enable = i386_efi; |
3799 | 393 | + enable = x86_64_efi; | 395 | + enable = x86_64_efi; |
3800 | @@ -536,54 +538,6 @@ index 9838fb2..f6aef0e 100644 | |||
3801 | 536 | /* Allocate pages. Return the pointer to the first of allocated pages. */ | 538 | /* Allocate pages. Return the pointer to the first of allocated pages. */ |
3802 | 537 | void * | 539 | void * |
3803 | 538 | grub_efi_allocate_pages_real (grub_efi_physical_address_t address, | 540 | grub_efi_allocate_pages_real (grub_efi_physical_address_t address, |
3804 | 539 | diff --git a/grub-core/loader/arm64/linux.c b/grub-core/loader/arm64/linux.c | ||
3805 | 540 | index ef3e9f9..1a5296a 100644 | ||
3806 | 541 | --- a/grub-core/loader/arm64/linux.c | ||
3807 | 542 | +++ b/grub-core/loader/arm64/linux.c | ||
3808 | 543 | @@ -27,6 +27,7 @@ | ||
3809 | 544 | #include <grub/types.h> | ||
3810 | 545 | #include <grub/cpu/linux.h> | ||
3811 | 546 | #include <grub/efi/efi.h> | ||
3812 | 547 | +#include <grub/efi/linux.h> | ||
3813 | 548 | #include <grub/efi/fdtload.h> | ||
3814 | 549 | #include <grub/efi/memory.h> | ||
3815 | 550 | #include <grub/efi/pe32.h> | ||
3816 | 551 | @@ -48,6 +49,13 @@ static grub_uint32_t cmdline_size; | ||
3817 | 552 | static grub_addr_t initrd_start; | ||
3818 | 553 | static grub_addr_t initrd_end; | ||
3819 | 554 | |||
3820 | 555 | +struct grub_arm64_linux_pe_header | ||
3821 | 556 | +{ | ||
3822 | 557 | + grub_uint32_t magic; | ||
3823 | 558 | + struct grub_pe32_coff_header coff; | ||
3824 | 559 | + struct grub_pe64_optional_header opt; | ||
3825 | 560 | +}; | ||
3826 | 561 | + | ||
3827 | 562 | grub_err_t | ||
3828 | 563 | grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh) | ||
3829 | 564 | { | ||
3830 | 565 | @@ -289,6 +297,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), | ||
3831 | 566 | grub_file_t file = 0; | ||
3832 | 567 | struct linux_arch_kernel_header lh; | ||
3833 | 568 | grub_err_t err; | ||
3834 | 569 | + int rc; | ||
3835 | 570 | |||
3836 | 571 | grub_dl_ref (my_mod); | ||
3837 | 572 | |||
3838 | 573 | @@ -333,6 +342,13 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), | ||
3839 | 574 | |||
3840 | 575 | grub_dprintf ("linux", "kernel @ %p\n", kernel_addr); | ||
3841 | 576 | |||
3842 | 577 | + rc = grub_linuxefi_secure_validate (kernel_addr, kernel_size); | ||
3843 | 578 | + if (rc < 0) | ||
3844 | 579 | + { | ||
3845 | 580 | + grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"), argv[0]); | ||
3846 | 581 | + goto fail; | ||
3847 | 582 | + } | ||
3848 | 583 | + | ||
3849 | 584 | cmdline_size = grub_loader_cmdline_size (argc, argv) + sizeof (LINUX_IMAGE); | ||
3850 | 585 | linux_args = grub_malloc (cmdline_size); | ||
3851 | 586 | if (!linux_args) | ||
3852 | 587 | diff --git a/grub-core/loader/efi/appleloader.c b/grub-core/loader/efi/appleloader.c | 541 | diff --git a/grub-core/loader/efi/appleloader.c b/grub-core/loader/efi/appleloader.c |
3853 | 588 | index 74888c4..07677f0 100644 | 542 | index 74888c4..07677f0 100644 |
3854 | 589 | --- a/grub-core/loader/efi/appleloader.c | 543 | --- a/grub-core/loader/efi/appleloader.c |
3855 | @@ -616,7 +570,7 @@ index 74888c4..07677f0 100644 | |||
3856 | 616 | grub_unregister_command (cmd); | 570 | grub_unregister_command (cmd); |
3857 | 617 | } | 571 | } |
3858 | 618 | diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c | 572 | diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c |
3860 | 619 | index 2bd80f4..9e301f2 100644 | 573 | index 2bd80f4..c3144de 100644 |
3861 | 620 | --- a/grub-core/loader/efi/chainloader.c | 574 | --- a/grub-core/loader/efi/chainloader.c |
3862 | 621 | +++ b/grub-core/loader/efi/chainloader.c | 575 | +++ b/grub-core/loader/efi/chainloader.c |
3863 | 622 | @@ -32,6 +32,9 @@ | 576 | @@ -32,6 +32,9 @@ |
3864 | @@ -652,7 +606,7 @@ index 2bd80f4..9e301f2 100644 | |||
3865 | 652 | 606 | ||
3866 | 653 | grub_dl_unref (my_mod); | 607 | grub_dl_unref (my_mod); |
3867 | 654 | return GRUB_ERR_NONE; | 608 | return GRUB_ERR_NONE; |
3869 | 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) |
3870 | 656 | return file_path; | 610 | return file_path; |
3871 | 657 | } | 611 | } |
3872 | 658 | 612 | ||
3873 | @@ -767,6 +721,8 @@ index 2bd80f4..9e301f2 100644 | |||
3874 | 767 | + GRUB_PE32_MACHINE_I386; | 721 | + GRUB_PE32_MACHINE_I386; |
3875 | 768 | +#elif defined(__ia64__) | 722 | +#elif defined(__ia64__) |
3876 | 769 | + GRUB_PE32_MACHINE_IA64; | 723 | + GRUB_PE32_MACHINE_IA64; |
3877 | 724 | +#elif defined(__riscv) && __riscv_xlen == 64 | ||
3878 | 725 | + GRUB_PE32_MACHINE_RISCV64; | ||
3879 | 770 | +#else | 726 | +#else |
3880 | 771 | +#error this architecture is not supported by grub2 | 727 | +#error this architecture is not supported by grub2 |
3881 | 772 | +#endif | 728 | +#endif |
3882 | @@ -782,9 +738,7 @@ index 2bd80f4..9e301f2 100644 | |||
3883 | 782 | + char *fixup, *fixup_base, *fixup_data = NULL; | 738 | + char *fixup, *fixup_base, *fixup_data = NULL; |
3884 | 783 | + grub_efi_uint16_t *fixup_16; | 739 | + grub_efi_uint16_t *fixup_16; |
3885 | 784 | + grub_efi_uint32_t *fixup_32; | 740 | + grub_efi_uint32_t *fixup_32; |
3886 | 785 | +#if defined(__x86_64__) || defined(__aarch64__) | ||
3887 | 786 | + grub_efi_uint64_t *fixup_64; | 741 | + grub_efi_uint64_t *fixup_64; |
3888 | 787 | +#endif /* defined(__x86_64__) || defined(__aarch64__) */ | ||
3889 | 788 | + grub_efi_uint64_t size = context->image_size; | 742 | + grub_efi_uint64_t size = context->image_size; |
3890 | 789 | + void *image_end = (char *)orig + size; | 743 | + void *image_end = (char *)orig + size; |
3891 | 790 | + int n = 0; | 744 | + int n = 0; |
3892 | @@ -911,7 +865,6 @@ index 2bd80f4..9e301f2 100644 | |||
3893 | 911 | + fixup_data += sizeof (grub_uint32_t); | 865 | + fixup_data += sizeof (grub_uint32_t); |
3894 | 912 | + } | 866 | + } |
3895 | 913 | + break; | 867 | + break; |
3896 | 914 | +#if defined(__x86_64__) || defined(__aarch64__) | ||
3897 | 915 | + case GRUB_PE32_REL_BASED_DIR64: | 868 | + case GRUB_PE32_REL_BASED_DIR64: |
3898 | 916 | + fixup_64 = (grub_uint64_t *)fixup; | 869 | + fixup_64 = (grub_uint64_t *)fixup; |
3899 | 917 | + *fixup_64 = *fixup_64 + (grub_uint64_t)adjust; | 870 | + *fixup_64 = *fixup_64 + (grub_uint64_t)adjust; |
3900 | @@ -922,7 +875,7 @@ index 2bd80f4..9e301f2 100644 | |||
3901 | 922 | + fixup_data += sizeof (grub_uint64_t); | 875 | + fixup_data += sizeof (grub_uint64_t); |
3902 | 923 | + } | 876 | + } |
3903 | 924 | + break; | 877 | + break; |
3905 | 925 | +#endif /* defined(__x86_64__) || defined(__aarch64__) */ | 878 | + /* TODO: GRUB_PE32_REL_BASED_RISCV_HI20, GRUB_PE32_REL_BASED_RISCV_LOW12I/S */ |
3906 | 926 | + default: | 879 | + default: |
3907 | 927 | + grub_error (GRUB_ERR_BAD_ARGUMENT, | 880 | + grub_error (GRUB_ERR_BAD_ARGUMENT, |
3908 | 928 | + "Reloc %d unknown relocation type %d", | 881 | + "Reloc %d unknown relocation type %d", |
3909 | @@ -1350,7 +1303,7 @@ index 2bd80f4..9e301f2 100644 | |||
3910 | 1350 | 1303 | ||
3911 | 1351 | if (argc == 0) | 1304 | if (argc == 0) |
3912 | 1352 | return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); | 1305 | return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); |
3914 | 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)), |
3915 | 1354 | address = 0; | 1307 | address = 0; |
3916 | 1355 | image_handle = 0; | 1308 | image_handle = 0; |
3917 | 1356 | file_path = 0; | 1309 | file_path = 0; |
3918 | @@ -1398,7 +1351,7 @@ index 2bd80f4..9e301f2 100644 | |||
3919 | 1398 | if (! dev) | 1351 | if (! dev) |
3920 | 1399 | goto fail; | 1352 | goto fail; |
3921 | 1400 | 1353 | ||
3923 | 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)), |
3924 | 1402 | if (! file_path) | 1355 | if (! file_path) |
3925 | 1403 | goto fail; | 1356 | goto fail; |
3926 | 1404 | 1357 | ||
3927 | @@ -1419,7 +1372,7 @@ index 2bd80f4..9e301f2 100644 | |||
3928 | 1419 | 1372 | ||
3929 | 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, |
3930 | 1421 | GRUB_EFI_LOADER_CODE, | 1374 | GRUB_EFI_LOADER_CODE, |
3932 | 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)), |
3933 | 1423 | } | 1376 | } |
3934 | 1424 | 1377 | ||
3935 | 1425 | boot_image = (void *) ((grub_addr_t) address); | 1378 | boot_image = (void *) ((grub_addr_t) address); |
3936 | @@ -1428,7 +1381,7 @@ index 2bd80f4..9e301f2 100644 | |||
3937 | 1428 | { | 1381 | { |
3938 | 1429 | if (grub_errno == GRUB_ERR_NONE) | 1382 | if (grub_errno == GRUB_ERR_NONE) |
3939 | 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"), |
3941 | 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)), |
3942 | 1432 | } | 1385 | } |
3943 | 1433 | 1386 | ||
3944 | 1434 | #if defined (__i386__) || defined (__x86_64__) | 1387 | #if defined (__i386__) || defined (__x86_64__) |
3945 | @@ -1437,7 +1390,7 @@ index 2bd80f4..9e301f2 100644 | |||
3946 | 1437 | { | 1390 | { |
3947 | 1438 | struct grub_macho_fat_header *head = boot_image; | 1391 | struct grub_macho_fat_header *head = boot_image; |
3948 | 1439 | if (head->magic | 1392 | if (head->magic |
3950 | 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)), |
3951 | 1441 | grub_uint32_t i; | 1394 | grub_uint32_t i; |
3952 | 1442 | struct grub_macho_fat_arch *archs | 1395 | struct grub_macho_fat_arch *archs |
3953 | 1443 | = (struct grub_macho_fat_arch *) (head + 1); | 1396 | = (struct grub_macho_fat_arch *) (head + 1); |
3954 | @@ -1452,7 +1405,7 @@ index 2bd80f4..9e301f2 100644 | |||
3955 | 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++) |
3956 | 1453 | { | 1406 | { |
3957 | 1454 | if (GRUB_MACHO_CPUTYPE_IS_HOST_CURRENT (archs[i].cputype)) | 1407 | if (GRUB_MACHO_CPUTYPE_IS_HOST_CURRENT (archs[i].cputype)) |
3959 | 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)), |
3960 | 1456 | > ~grub_cpu_to_le32 (archs[i].size) | 1409 | > ~grub_cpu_to_le32 (archs[i].size) |
3961 | 1457 | || grub_cpu_to_le32 (archs[i].offset) | 1410 | || grub_cpu_to_le32 (archs[i].offset) |
3962 | 1458 | + grub_cpu_to_le32 (archs[i].size) | 1411 | + grub_cpu_to_le32 (archs[i].size) |
3963 | @@ -1547,7 +1500,7 @@ index 2bd80f4..9e301f2 100644 | |||
3964 | 1547 | if (dev) | 1500 | if (dev) |
3965 | 1548 | grub_device_close (dev); | 1501 | grub_device_close (dev); |
3966 | 1549 | 1502 | ||
3968 | 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)), |
3969 | 1551 | if (address) | 1504 | if (address) |
3970 | 1552 | efi_call_2 (b->free_pages, address, pages); | 1505 | efi_call_2 (b->free_pages, address, pages); |
3971 | 1553 | 1506 | ||
3972 | @@ -1558,7 +1511,7 @@ index 2bd80f4..9e301f2 100644 | |||
3973 | 1558 | 1511 | ||
3974 | 1559 | return grub_errno; | 1512 | return grub_errno; |
3975 | 1560 | diff --git a/grub-core/loader/efi/fdt.c b/grub-core/loader/efi/fdt.c | 1513 | diff --git a/grub-core/loader/efi/fdt.c b/grub-core/loader/efi/fdt.c |
3977 | 1561 | index c86f283..7858d35 100644 | 1514 | index 771d455..971e84d 100644 |
3978 | 1562 | --- a/grub-core/loader/efi/fdt.c | 1515 | --- a/grub-core/loader/efi/fdt.c |
3979 | 1563 | +++ b/grub-core/loader/efi/fdt.c | 1516 | +++ b/grub-core/loader/efi/fdt.c |
3980 | 1564 | @@ -26,6 +26,7 @@ | 1517 | @@ -26,6 +26,7 @@ |
3981 | @@ -1570,10 +1523,58 @@ index c86f283..7858d35 100644 | |||
3982 | 1570 | static void *loaded_fdt; | 1523 | static void *loaded_fdt; |
3983 | 1571 | static void *fdt; | 1524 | static void *fdt; |
3984 | 1572 | diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c | 1525 | diff --git a/grub-core/loader/efi/linux.c b/grub-core/loader/efi/linux.c |
3985 | 1526 | index 3292cab..d81e7be 100644 | ||
3986 | 1527 | --- a/grub-core/loader/efi/linux.c | ||
3987 | 1528 | +++ b/grub-core/loader/efi/linux.c | ||
3988 | 1529 | @@ -27,6 +27,7 @@ | ||
3989 | 1530 | #include <grub/types.h> | ||
3990 | 1531 | #include <grub/cpu/linux.h> | ||
3991 | 1532 | #include <grub/efi/efi.h> | ||
3992 | 1533 | +#include <grub/efi/linux.h> | ||
3993 | 1534 | #include <grub/efi/fdtload.h> | ||
3994 | 1535 | #include <grub/efi/memory.h> | ||
3995 | 1536 | #include <grub/efi/pe32.h> | ||
3996 | 1537 | @@ -54,6 +55,13 @@ static int initrd_use_loadfile2; | ||
3997 | 1538 | static grub_efi_guid_t load_file2_guid = GRUB_EFI_LOAD_FILE2_PROTOCOL_GUID; | ||
3998 | 1539 | static grub_efi_guid_t device_path_guid = GRUB_EFI_DEVICE_PATH_GUID; | ||
3999 | 1540 | |||
4000 | 1541 | +struct grub_arm64_linux_pe_header | ||
4001 | 1542 | +{ | ||
4002 | 1543 | + grub_uint32_t magic; | ||
4003 | 1544 | + struct grub_pe32_coff_header coff; | ||
4004 | 1545 | + struct grub_pe64_optional_header opt; | ||
4005 | 1546 | +}; | ||
4006 | 1547 | + | ||
4007 | 1548 | grub_err_t | ||
4008 | 1549 | grub_arch_efi_linux_check_image (struct linux_arch_kernel_header * lh) | ||
4009 | 1550 | { | ||
4010 | 1551 | @@ -404,6 +412,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), | ||
4011 | 1552 | grub_file_t file = 0; | ||
4012 | 1553 | struct linux_arch_kernel_header lh; | ||
4013 | 1554 | grub_err_t err; | ||
4014 | 1555 | + int rc; | ||
4015 | 1556 | |||
4016 | 1557 | grub_dl_ref (my_mod); | ||
4017 | 1558 | |||
4018 | 1559 | @@ -448,6 +457,13 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), | ||
4019 | 1560 | |||
4020 | 1561 | grub_dprintf ("linux", "kernel @ %p\n", kernel_addr); | ||
4021 | 1562 | |||
4022 | 1563 | + rc = grub_linuxefi_secure_validate (kernel_addr, kernel_size); | ||
4023 | 1564 | + if (rc < 0) | ||
4024 | 1565 | + { | ||
4025 | 1566 | + grub_error (GRUB_ERR_INVALID_COMMAND, N_("%s has invalid signature"), argv[0]); | ||
4026 | 1567 | + goto fail; | ||
4027 | 1568 | + } | ||
4028 | 1569 | + | ||
4029 | 1570 | cmdline_size = grub_loader_cmdline_size (argc, argv) + sizeof (LINUX_IMAGE); | ||
4030 | 1571 | linux_args = grub_malloc (cmdline_size); | ||
4031 | 1572 | if (!linux_args) | ||
4032 | 1573 | diff --git a/grub-core/loader/efi/linux_sb.c b/grub-core/loader/efi/linux_sb.c | ||
4033 | 1573 | new file mode 100644 | 1574 | new file mode 100644 |
4034 | 1574 | index 0000000..e372b26 | 1575 | index 0000000..e372b26 |
4035 | 1575 | --- /dev/null | 1576 | --- /dev/null |
4037 | 1576 | +++ b/grub-core/loader/efi/linux.c | 1577 | +++ b/grub-core/loader/efi/linux_sb.c |
4038 | 1577 | @@ -0,0 +1,86 @@ | 1578 | @@ -0,0 +1,86 @@ |
4039 | 1578 | +/* | 1579 | +/* |
4040 | 1579 | + * GRUB -- GRand Unified Bootloader | 1580 | + * GRUB -- GRand Unified Bootloader |
4041 | @@ -2082,7 +2083,7 @@ index 0000000..382ff52 | |||
4042 | 2082 | + grub_unregister_command (cmd_initrd); | 2083 | + grub_unregister_command (cmd_initrd); |
4043 | 2083 | +} | 2084 | +} |
4044 | 2084 | diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c | 2085 | diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c |
4046 | 2085 | index 9f74a96..d55b7cd 100644 | 2086 | index f30a158..b6c13d7 100644 |
4047 | 2086 | --- a/grub-core/loader/i386/linux.c | 2087 | --- a/grub-core/loader/i386/linux.c |
4048 | 2087 | +++ b/grub-core/loader/i386/linux.c | 2088 | +++ b/grub-core/loader/i386/linux.c |
4049 | 2088 | @@ -78,6 +78,8 @@ static grub_size_t maximal_cmdline_size; | 2089 | @@ -78,6 +78,8 @@ static grub_size_t maximal_cmdline_size; |
4050 | @@ -2243,7 +2244,7 @@ index 9f74a96..d55b7cd 100644 | |||
4051 | 2243 | { | 2244 | { |
4052 | 2244 | grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); | 2245 | grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); |
4053 | 2245 | diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c | 2246 | diff --git a/grub-core/loader/i386/pc/linux.c b/grub-core/loader/i386/pc/linux.c |
4055 | 2246 | index 2a29952..f4ab6ad 100644 | 2247 | index efeeeb2..69db786 100644 |
4056 | 2247 | --- a/grub-core/loader/i386/pc/linux.c | 2248 | --- a/grub-core/loader/i386/pc/linux.c |
4057 | 2248 | +++ b/grub-core/loader/i386/pc/linux.c | 2249 | +++ b/grub-core/loader/i386/pc/linux.c |
4058 | 2249 | @@ -36,6 +36,7 @@ | 2250 | @@ -36,6 +36,7 @@ |
4059 | @@ -2420,7 +2421,7 @@ index 1c0cf6a..c5ba84c 100644 | |||
4060 | 2420 | grub_unregister_command (cmd_resume); | 2421 | grub_unregister_command (cmd_resume); |
4061 | 2421 | #endif | 2422 | #endif |
4062 | 2422 | diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h | 2423 | diff --git a/include/grub/arm64/linux.h b/include/grub/arm64/linux.h |
4064 | 2423 | index 7e22b4a..6785b78 100644 | 2424 | index effd870..9efd37a 100644 |
4065 | 2424 | --- a/include/grub/arm64/linux.h | 2425 | --- a/include/grub/arm64/linux.h |
4066 | 2425 | +++ b/include/grub/arm64/linux.h | 2426 | +++ b/include/grub/arm64/linux.h |
4067 | 2426 | @@ -22,6 +22,8 @@ | 2427 | @@ -22,6 +22,8 @@ |
4068 | diff --git a/debian/patches/vt-handoff.patch b/debian/patches/vt-handoff.patch | |||
4069 | index 94f8f4f..78c15da 100644 | |||
4070 | --- a/debian/patches/vt-handoff.patch | |||
4071 | +++ b/debian/patches/vt-handoff.patch | |||
4072 | @@ -17,10 +17,10 @@ Patch-Name: vt-handoff.patch | |||
4073 | 17 | 2 files changed, 38 insertions(+), 1 deletion(-) | 17 | 2 files changed, 38 insertions(+), 1 deletion(-) |
4074 | 18 | 18 | ||
4075 | 19 | diff --git a/configure.ac b/configure.ac | 19 | diff --git a/configure.ac b/configure.ac |
4077 | 20 | index 947fd52..e11df6b 100644 | 20 | index 3203749..b4e33a6 100644 |
4078 | 21 | --- a/configure.ac | 21 | --- a/configure.ac |
4079 | 22 | +++ b/configure.ac | 22 | +++ b/configure.ac |
4081 | 23 | @@ -1948,6 +1948,17 @@ else | 23 | @@ -1956,6 +1956,17 @@ else |
4082 | 24 | fi | 24 | fi |
4083 | 25 | AC_SUBST([GFXPAYLOAD_DYNAMIC]) | 25 | AC_SUBST([GFXPAYLOAD_DYNAMIC]) |
4084 | 26 | 26 | ||
4085 | diff --git a/debian/postinst.in b/debian/postinst.in | |||
4086 | index 5a64439..98020ab 100644 | |||
4087 | --- a/debian/postinst.in | |||
4088 | +++ b/debian/postinst.in | |||
4089 | @@ -759,7 +759,7 @@ case "$1" in | |||
4090 | 759 | fi | 759 | fi |
4091 | 760 | ;; | 760 | ;; |
4092 | 761 | 761 | ||
4094 | 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) |
4095 | 763 | bootloader_id="$(config_item GRUB_DISTRIBUTOR | tr A-Z a-z | \ | 763 | bootloader_id="$(config_item GRUB_DISTRIBUTOR | tr A-Z a-z | \ |
4096 | 764 | cut -d' ' -f1)" | 764 | cut -d' ' -f1)" |
4097 | 765 | case $bootloader_id in | 765 | case $bootloader_id in |
4098 | @@ -787,6 +787,7 @@ case "$1" in | |||
4099 | 787 | grub-efi-ia64) target=ia64-efi ;; | 787 | grub-efi-ia64) target=ia64-efi ;; |
4100 | 788 | grub-efi-arm) target=arm-efi ;; | 788 | grub-efi-arm) target=arm-efi ;; |
4101 | 789 | grub-efi-arm64) target=arm64-efi ;; | 789 | grub-efi-arm64) target=arm64-efi ;; |
4102 | 790 | grub-efi-riscv64) target=riscv64-efi ;; | ||
4103 | 790 | esac | 791 | esac |
4104 | 791 | # Check /boot/grub to see if we previously installed to an ESP. We don't | 792 | # Check /boot/grub to see if we previously installed to an ESP. We don't |
4105 | 792 | # want to trigger the install code just by installing the package, | 793 | # want to trigger the install code just by installing the package, |
4106 | diff --git a/debian/rules b/debian/rules | |||
4107 | index 9505998..90678d2 100755 | |||
4108 | --- a/debian/rules | |||
4109 | +++ b/debian/rules | |||
4110 | @@ -66,7 +66,7 @@ BUILD_PACKAGES := $(strip $(shell dh_listpackages)) | |||
4111 | 66 | # REAL_PACKAGES build an actual grub variant (and therefore have both configure | 66 | # REAL_PACKAGES build an actual grub variant (and therefore have both configure |
4112 | 67 | # and build stages). EXTRA_PACKAGES do not build grub but may depend on a | 67 | # and build stages). EXTRA_PACKAGES do not build grub but may depend on a |
4113 | 68 | # REAL_PACKAGE (and therefore only have a build stage) | 68 | # REAL_PACKAGE (and therefore only have a build stage) |
4115 | 69 | REAL_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-yeeloong | 69 | REAL_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 |
4116 | 70 | EXTRA_PACKAGES = grub-rescue-pc grub-xen-host | 70 | EXTRA_PACKAGES = grub-rescue-pc grub-xen-host |
4117 | 71 | 71 | ||
4118 | 72 | ifneq (,$(filter amd64,$(DEB_HOST_ARCH_CPU))) | 72 | ifneq (,$(filter amd64,$(DEB_HOST_ARCH_CPU))) |
4119 | @@ -85,6 +85,8 @@ else ifeq (arm,$(DEB_HOST_ARCH_CPU)) | |||
4120 | 85 | COMMON_PLATFORM := uboot | 85 | COMMON_PLATFORM := uboot |
4121 | 86 | else ifeq (arm64,$(DEB_HOST_ARCH_CPU)) | 86 | else ifeq (arm64,$(DEB_HOST_ARCH_CPU)) |
4122 | 87 | COMMON_PLATFORM := efi-arm64 | 87 | COMMON_PLATFORM := efi-arm64 |
4123 | 88 | else ifeq (riscv64,$(DEB_HOST_ARCH_CPU)) | ||
4124 | 89 | COMMON_PLATFORM := efi-riscv64 | ||
4125 | 88 | else | 90 | else |
4126 | 89 | COMMON_PLATFORM := none | 91 | COMMON_PLATFORM := none |
4127 | 90 | BUILD_PACKAGES += grub-none | 92 | BUILD_PACKAGES += grub-none |
4128 | @@ -95,6 +97,8 @@ DEFAULT_CMDLINE := quiet splash | |||
4129 | 95 | DEFAULT_TIMEOUT := 10 | 97 | DEFAULT_TIMEOUT := 10 |
4130 | 96 | ifeq ($(DEB_HOST_ARCH_CPU),ppc64el) | 98 | ifeq ($(DEB_HOST_ARCH_CPU),ppc64el) |
4131 | 97 | FLICKER_FREE_BOOT := no | 99 | FLICKER_FREE_BOOT := no |
4132 | 100 | else ifeq ($(DEB_HOST_ARCH_CPU),riscv64) | ||
4133 | 101 | FLICKER_FREE_BOOT := no | ||
4134 | 98 | else | 102 | else |
4135 | 99 | FLICKER_FREE_BOOT := yes | 103 | FLICKER_FREE_BOOT := yes |
4136 | 100 | endif | 104 | endif |
4137 | @@ -263,7 +267,7 @@ debian/stamps/configure-grub-efi-amd64: | |||
4138 | 263 | mkdir -p debian/stamps $(subst debian/stamps/configure-,obj/,$@) | 267 | mkdir -p debian/stamps $(subst debian/stamps/configure-,obj/,$@) |
4139 | 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="" |
4140 | 265 | touch $@ | 269 | touch $@ |
4142 | 266 | debian/stamps/configure-grub-efi-ia64 debian/stamps/configure-grub-efi-arm debian/stamps/configure-grub-efi-arm64: | 270 | debian/stamps/configure-grub-efi-ia64 debian/stamps/configure-grub-efi-arm debian/stamps/configure-grub-efi-arm64 debian/stamps/configure-grub-efi-riscv64: |
4143 | 267 | mkdir -p debian/stamps $(subst debian/stamps/configure-,obj/,$@) | 271 | mkdir -p debian/stamps $(subst debian/stamps/configure-,obj/,$@) |
4144 | 268 | dh_auto_configure -- $(confflags) --with-platform=efi | 272 | dh_auto_configure -- $(confflags) --with-platform=efi |
4145 | 269 | touch $@ | 273 | touch $@ |
4146 | @@ -284,7 +288,7 @@ debian/stamps/configure-grub-firmware-qemu: | |||
4147 | 284 | dh_auto_configure -- $(confflags) --with-platform=qemu | 288 | dh_auto_configure -- $(confflags) --with-platform=qemu |
4148 | 285 | touch $@ | 289 | touch $@ |
4149 | 286 | 290 | ||
4151 | 287 | debian/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-% | 291 | debian/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-% |
4152 | 288 | dh_auto_build | 292 | dh_auto_build |
4153 | 289 | touch $@ | 293 | touch $@ |
4154 | 290 | 294 | ||
4155 | @@ -426,7 +430,7 @@ install/grub-none: | |||
4156 | 426 | # files. | 430 | # files. |
4157 | 427 | mkdir -p debian/tmp-$(package)/usr/share/locale | 431 | mkdir -p debian/tmp-$(package)/usr/share/locale |
4158 | 428 | 432 | ||
4160 | 429 | install/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: | 433 | install/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: |
4161 | 430 | set -e ; \ | 434 | set -e ; \ |
4162 | 431 | if [ "$@" = "install/grub-xen" ] ; then \ | 435 | if [ "$@" = "install/grub-xen" ] ; then \ |
4163 | 432 | dh_auto_install -Bobj/grub-xen-i386 --destdir=debian/tmp-$(package); \ | 436 | dh_auto_install -Bobj/grub-xen-i386 --destdir=debian/tmp-$(package); \ |
4164 | @@ -571,7 +575,7 @@ endif | |||
4165 | 571 | 575 | ||
4166 | 572 | NON_PLATFORM_PACKAGES = $(filter grub2 grub-linuxbios grub-efi grub-rescue-pc grub-firmware-qemu grub-xen-host,$(BUILD_PACKAGES)) | 576 | NON_PLATFORM_PACKAGES = $(filter grub2 grub-linuxbios grub-efi grub-rescue-pc grub-firmware-qemu grub-xen-host,$(BUILD_PACKAGES)) |
4167 | 573 | COMMON_PLATFORM_PACKAGES = $(filter grub-common grub2-common grub-theme-starfield grub-mount-udeb,$(BUILD_PACKAGES)) | 577 | COMMON_PLATFORM_PACKAGES = $(filter grub-common grub2-common grub-theme-starfield grub-mount-udeb,$(BUILD_PACKAGES)) |
4169 | 574 | PLATFORM_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)) | 578 | PLATFORM_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)) |
4170 | 575 | 579 | ||
4171 | 576 | override_dh_install: | 580 | override_dh_install: |
4172 | 577 | ifneq (,$(NON_PLATFORM_PACKAGES)) | 581 | ifneq (,$(NON_PLATFORM_PACKAGES)) |