Skip to content

Commit a3dec73

Browse files
rucoderclaude
andcommitted
pkg/grub: migrate to GRUB 2.12
Upgrade from GRUB 2.06 (amd64) / 2.06 (arm64, riscv64) to GRUB 2.12 for all architectures using a single unified patch set. Key changes: - All archs now use GRUB_COMMIT=grub-2.12 and GRUB_PATCHES=patches-2.12 - New patches-2.12/ with 15 shared patches (no arch-specific patch dirs needed: riscv64 linux loader and arm64 search are upstream in 2.12) - coreutils added to base BUILD_PKGS (gnulib bootstrap needs `join`) - GNULIB_REVISION updated to match grub-2.12 bootstrap.conf - Removed modules dropped in 2.12: linuxefi (merged into linux), verify, gcry_sha256 (standalone) - Added search_part_uuid to GRUB_MODULES_PORT (all archs) - Added getenv to arm64 GRUB_MODULES (was already in amd64) Patch set carries forward all EVE-specific features: export-vars, cat-to-var, cmddevice, removable-drives, gpt, gptprio, search_part_{label,uuid,disk_uuid}, watchdog timeout, measurefs, no-measurefs-without-TPM, dt-fixup, getenv, probe-partuuid, tpm-status-code (EFI status in unknown TPM error messages). API fixes for 2.12 compatibility: - grub_efi_guid_t -> grub_guid_t (type renamed) - grub_efi_get_variable() gained a void** output parameter - efi_call_4() removed; replaced with direct function pointer calls (fdt.c: only compiled for arm/riscv EFI, not x86) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Mikhail Malyshev <mike.malyshev@gmail.com>
1 parent 8565593 commit a3dec73

16 files changed

+2733
-18
lines changed

pkg/grub/Dockerfile

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,52 +19,48 @@ ENV BUILD_PKGS="automake \
1919
patch \
2020
gettext-dev \
2121
bash \
22-
gawk"
23-
ENV BUILD_PKGS_arm64=coreutils
24-
ENV BUILD_PKGS_riscv64=coreutils
22+
gawk \
23+
coreutils"
2524
RUN eve-alpine-deploy.sh
2625

2726
# list of grub modules that are portable between x86_64 and aarch64
2827
ENV GRUB_MODULES_PORT="part_gpt fat ext2 iso9660 squash4 gzio linux acpi normal cpio crypto disk boot crc64 \
29-
search_disk_uuid search_part_label search_label xzio xfs video gfxterm serial gptprio chain probe reboot regexp smbios \
28+
search_disk_uuid search_part_uuid search_part_label search_label xzio xfs video gfxterm serial gptprio chain probe reboot regexp smbios \
3029
part_msdos cat echo test configfile loopback net tftp http true"
3130

3231
FROM grub-build-base AS grub-build-amd64
33-
ENV GRUB_MODULES="multiboot multiboot2 efi_uga efi_gop linuxefi gpt verify gcry_sha256 measurefs efinet getenv"
34-
ENV GRUB_MODULES_i386_pc="multiboot multiboot2 biosdisk gpt verify"
35-
ENV GRUB_COMMIT=71f9e4ac44142af52c3fc1860436cf9e432bf764
36-
ENV GRUB_PATCHES=patches
32+
ENV GRUB_MODULES="multiboot multiboot2 efi_uga efi_gop gpt measurefs efinet getenv"
33+
ENV GRUB_MODULES_i386_pc="multiboot multiboot2 biosdisk gpt"
34+
ENV GRUB_COMMIT=grub-2.12
35+
ENV GRUB_PATCHES=patches-2.12
3736
# colon separates a platform from an additional option.
3837
# this is far from perfect, but it works for now.
3938
ENV GRUB_PLATFORM="efi pc:--disable-efiemu"
4039

4140
FROM grub-build-base AS grub-build-arm64
42-
ENV GRUB_MODULES="xen_boot efi_gop gpt gcry_sha256 measurefs efinet"
43-
ENV GRUB_COMMIT=grub-2.06
44-
ENV GRUB_PATCHES="patches-2.06 patches-aarch64-2.06"
41+
ENV GRUB_MODULES="xen_boot efi_gop gpt measurefs efinet getenv"
42+
ENV GRUB_COMMIT=grub-2.12
43+
ENV GRUB_PATCHES=patches-2.12
4544
ENV GRUB_PLATFORM=efi
4645

4746
FROM grub-build-base AS grub-build-riscv64
4847
ENV GRUB_MODULES="efinet"
49-
ENV GRUB_COMMIT=grub-2.06
50-
ENV GRUB_PATCHES="patches-2.06 patches-riscv64-2.06"
48+
ENV GRUB_COMMIT=grub-2.12
49+
ENV GRUB_PATCHES=patches-2.12
5150
ENV GRUB_PLATFORM=efi
5251

5352
# hadolint ignore=DL3006
5453
FROM grub-build-${TARGETARCH} AS grub-build
5554

5655
ENV GRUB_REPO=git://git.git.savannah.gnu.org/grub.git
5756

58-
COPY patches /patches
59-
COPY patches-2.06 /patches-2.06
60-
COPY patches-aarch64-2.06 /patches-aarch64-2.06
61-
COPY patches-riscv64-2.06 /patches-riscv64-2.06
57+
COPY patches-2.12 /patches-2.12
6258
# because python is not available
6359
RUN ln -s python3 /usr/bin/python && \
6460
mkdir /grub-lib
6561

6662
ADD --keep-git-dir ${GRUB_REPO}#${GRUB_COMMIT} /grub
67-
ENV GNULIB_REVISION=d271f868a8df9bbec29049d01e056481b7a1a263
63+
ENV GNULIB_REVISION=9f48fb992a3d7e96610c4ce8be969cff2d61a01b
6864
ADD --keep-git-dir https://github.com/coreutils/gnulib.git#${GNULIB_REVISION} /gnulib
6965

7066
# hadolint ignore=DL3003,SC2086
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
From c2b3f20ca867812a414199a9bf50d861f0869eb2 Mon Sep 17 00:00:00 2001
2+
From: Vedant Paranjape <22630228+VedantParanjape@users.noreply.github.com>
3+
Date: Tue, 26 Oct 2021 22:18:49 +0530
4+
Subject: [PATCH 01/15] Making it possible to export variables from inner
5+
contexts of GRUB
6+
7+
Signed-off-by: Roman Shaposhnik <rvs@zededa.com>
8+
---
9+
grub-core/normal/context.c | 14 ++++++++++++++
10+
1 file changed, 14 insertions(+)
11+
12+
diff --git a/grub-core/normal/context.c b/grub-core/normal/context.c
13+
index ba185e915..4f13186f1 100644
14+
--- a/grub-core/normal/context.c
15+
+++ b/grub-core/normal/context.c
16+
@@ -129,6 +129,20 @@ grub_env_context_close (void)
17+
18+
for (p = grub_current_context->vars[i]; p; p = q)
19+
{
20+
+ if (p->global)
21+
+ {
22+
+ /* Set and export all global variables inside
23+
+ the calling/previous context. */
24+
+ struct grub_env_context *tmp_context = grub_current_context;
25+
+ grub_current_context = grub_current_context->prev;
26+
+ if (grub_env_set (p->name, p->value) == GRUB_ERR_NONE)
27+
+ {
28+
+ grub_env_export (p->name);
29+
+ grub_register_variable_hook (p->name, p->read_hook, p->write_hook);
30+
+ }
31+
+ grub_current_context = tmp_context;
32+
+ }
33+
+
34+
q = p->next;
35+
grub_free (p->name);
36+
grub_free (p->value);
37+
--
38+
2.43.0
39+
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
From df8c8393afc5cd65440eb4ecca1d634968ab2da4 Mon Sep 17 00:00:00 2001
2+
From: Vedant Paranjape <22630228+VedantParanjape@users.noreply.github.com>
3+
Date: Tue, 26 Oct 2021 22:22:13 +0530
4+
Subject: [PATCH 02/15] Adding a capability of a GRUB cat command to deposit to
5+
a var, not stdout
6+
7+
Signed-off-by: Roman Shaposhnik <rvs@zededa.com>
8+
---
9+
grub-core/commands/cat.c | 18 ++++++++++++++++++
10+
1 file changed, 18 insertions(+)
11+
12+
diff --git a/grub-core/commands/cat.c b/grub-core/commands/cat.c
13+
index 2b67c1c7f..316d0c97d 100644
14+
--- a/grub-core/commands/cat.c
15+
+++ b/grub-core/commands/cat.c
16+
@@ -20,6 +20,7 @@
17+
#include <grub/dl.h>
18+
#include <grub/file.h>
19+
#include <grub/disk.h>
20+
+#include <grub/env.h>
21+
#include <grub/term.h>
22+
#include <grub/misc.h>
23+
#include <grub/extcmd.h>
24+
@@ -31,6 +32,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
25+
static const struct grub_arg_option options[] =
26+
{
27+
{"dos", -1, 0, N_("Accept DOS-style CR/NL line endings."), 0, 0},
28+
+ {"set", 's', 0, N_("Read content of the file into a variable."), N_("VARNAME"), ARG_TYPE_STRING },
29+
{0, 0, 0, 0, 0, 0}
30+
};
31+
32+
@@ -60,6 +62,20 @@ grub_cmd_cat (grub_extcmd_context_t ctxt, int argc, char **args)
33+
if (! file)
34+
return grub_errno;
35+
36+
+ if (ctxt->state[1].set) {
37+
+ size = grub_file_read (file, buf, sizeof (buf));
38+
+ if (size < 0 || (grub_size_t)size >= sizeof (buf)) {
39+
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("can't read more than disk block size into variable"));
40+
+ }
41+
+ buf[size]='\0';
42+
+ for (;size;size--) {
43+
+ if (buf[size] == '\n' || buf[size] == '\r')
44+
+ buf[size]=0;
45+
+ }
46+
+ grub_env_set(ctxt->state[1].arg, (const char *)buf);
47+
+ goto exit;
48+
+ }
49+
+
50+
while ((size = grub_file_read (file, buf, sizeof (buf))) > 0
51+
&& key != GRUB_TERM_ESC)
52+
{
53+
@@ -150,6 +166,8 @@ grub_cmd_cat (grub_extcmd_context_t ctxt, int argc, char **args)
54+
55+
grub_xputs ("\n");
56+
grub_refresh ();
57+
+
58+
+exit:
59+
grub_file_close (file);
60+
61+
return 0;
62+
--
63+
2.43.0
64+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
From 6950ceb177c23f6860f6b03f68c2e768ec124390 Mon Sep 17 00:00:00 2001
2+
From: Petr Fedchenkov <giggsoff@gmail.com>
3+
Date: Thu, 3 Mar 2022 13:00:27 +0100
4+
Subject: [PATCH 03/15] set cmddevice
5+
6+
---
7+
grub-core/kern/main.c | 3 +++
8+
1 file changed, 3 insertions(+)
9+
10+
diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c
11+
index 731c07c29..2eb9b4125 100644
12+
--- a/grub-core/kern/main.c
13+
+++ b/grub-core/kern/main.c
14+
@@ -132,6 +132,9 @@ grub_set_prefix_and_root (void)
15+
{
16+
char *cmdpath;
17+
18+
+ grub_env_set ("cmddevice", fwdevice);
19+
+ grub_env_export ("cmddevice");
20+
+
21+
cmdpath = grub_xasprintf ("(%s)%s", fwdevice, fwpath ? : "");
22+
if (cmdpath)
23+
{
24+
--
25+
2.43.0
26+
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
From 81a999c42425abd47b3ac195813367f46f659bcb Mon Sep 17 00:00:00 2001
2+
From: Mikhail Malyshev <mikem@zededa.com>
3+
Date: Tue, 30 May 2023 13:59:05 +0000
4+
Subject: [PATCH 04/15] Put removable hard drives detected by UEFI at the end
5+
of the drive list
6+
7+
When grub queries for available disks it doesn't take into account that
8+
the disk can be removable e.g. USB stick. The disk can appear in front of regular
9+
HDDs and the numbering will be different e.g. hd0 become hd1 when the
10+
USB stick is plugged in. It is not a problem for GRUB to find a correct
11+
partition in this case and the system can be booted just fine. However
12+
every command from grub.cfg is measured into PCR8 while being executed
13+
and HDD names appear in those commands e.g. 'set root=(hd2,gpt5)'. If
14+
any key is sealed into TPM using PCR8 then that key cannot be unsealed when a
15+
random USB stick is inserted (or removed if it was inserted when the key
16+
was sealed)
17+
18+
The original issue should not affect PC BIOS case because USB devices
19+
are usually emulated as either CD or floppy drives and have their unique
20+
numbering
21+
22+
The behaviour is controlled by reorder_removable_media flag set through
23+
eve_quirks environment variable
24+
25+
Signed-off-by: Mikhail Malyshev <mikem@zededa.com>
26+
---
27+
grub-core/disk/efi/efidisk.c | 49 ++++++++++++++++++++++++++++++------
28+
1 file changed, 41 insertions(+), 8 deletions(-)
29+
30+
diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c
31+
index 3b5ed5691..e8e102fcc 100644
32+
--- a/grub-core/disk/efi/efidisk.c
33+
+++ b/grub-core/disk/efi/efidisk.c
34+
@@ -41,6 +41,7 @@ static grub_guid_t block_io_guid = GRUB_EFI_BLOCK_IO_GUID;
35+
36+
static struct grub_efidisk_data *fd_devices;
37+
static struct grub_efidisk_data *hd_devices;
38+
+static struct grub_efidisk_data *hd_removable_devices;
39+
static struct grub_efidisk_data *cd_devices;
40+
41+
static struct grub_efidisk_data *
42+
@@ -262,14 +263,25 @@ name_devices (struct grub_efidisk_data *devices)
43+
}
44+
if (is_hard_drive)
45+
{
46+
+ if (parent->block_io->media->removable_media == 1)
47+
+ {
48+
#ifdef DEBUG_NAMES
49+
- grub_printf ("adding a hard drive by a partition: ");
50+
- grub_efi_print_device_path (parent->device_path);
51+
+ grub_printf("adding a REMOVABLE hard drive by a partition: ");
52+
+ grub_efi_print_device_path(parent->device_path);
53+
#endif
54+
- add_device (&hd_devices, parent);
55+
- }
56+
- else
57+
- {
58+
+ add_device(&hd_removable_devices, parent);
59+
+ }
60+
+ else
61+
+ {
62+
+#ifdef DEBUG_NAMES
63+
+ grub_printf("adding a hard drive by a partition: ");
64+
+ grub_efi_print_device_path(parent->device_path);
65+
+#endif
66+
+ add_device(&hd_devices, parent);
67+
+ }
68+
+ }
69+
+ else
70+
+ {
71+
#ifdef DEBUG_NAMES
72+
grub_printf ("adding a cdrom by a partition: ");
73+
grub_efi_print_device_path (parent->device_path);
74+
@@ -365,9 +377,28 @@ name_devices (struct grub_efidisk_data *devices)
75+
grub_printf ("adding a hard drive by guessing: ");
76+
grub_efi_print_device_path (d->device_path);
77+
#endif
78+
- add_device (&hd_devices, d);
79+
- }
80+
+ if (m->removable_media == 0)
81+
+ {
82+
+ add_device(&hd_devices, d);
83+
+ }
84+
+ else
85+
+ {
86+
+ add_device(&hd_removable_devices, d);
87+
+ }
88+
+ }
89+
}
90+
+ // link the removable devices to the end of the hd_devices list
91+
+ if (hd_devices)
92+
+ {
93+
+ struct grub_efidisk_data *p;
94+
+ for (p = hd_devices; p->next; p = p->next)
95+
+ ;
96+
+ p->next = hd_removable_devices;
97+
+ }
98+
+ else
99+
+ {
100+
+ hd_devices = hd_removable_devices;
101+
+ }
102+
}
103+
104+
static void
105+
@@ -657,8 +688,10 @@ grub_efidisk_fini (void)
106+
free_devices (fd_devices);
107+
free_devices (hd_devices);
108+
free_devices (cd_devices);
109+
+ // do not free hd_removable_devices, as it is a subset of hd_devices
110+
fd_devices = 0;
111+
hd_devices = 0;
112+
+ hd_removable_devices = 0;
113+
cd_devices = 0;
114+
grub_disk_dev_unregister (&grub_efidisk_dev);
115+
}
116+
--
117+
2.43.0
118+

0 commit comments

Comments
 (0)