Fix booting on certain UEFI systems (#1830) (#1881)

This commit is contained in:
Stefan Agner 2022-05-05 16:53:26 +02:00 committed by GitHub
parent 87319b6e29
commit fdf7823887
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 8 deletions

View File

@ -1,8 +1,8 @@
From 184b6a054e04bb4c7fb4885a30d62314229dc551 Mon Sep 17 00:00:00 2001 From 184b6a054e04bb4c7fb4885a30d62314229dc551 Mon Sep 17 00:00:00 2001
Message-Id: <184b6a054e04bb4c7fb4885a30d62314229dc551.1650445464.git.stefan@agner.ch> Message-Id: <184b6a054e04bb4c7fb4885a30d62314229dc551.1651759401.git.stefan@agner.ch>
From: Stefan Agner <stefan@agner.ch> From: Stefan Agner <stefan@agner.ch>
Date: Thu, 24 Feb 2022 12:38:48 +0100 Date: Thu, 24 Feb 2022 12:38:48 +0100
Subject: [PATCH 1/2] loadenv: add file_env to load var from file Subject: [PATCH] loadenv: add file_env to load var from file
Introduce file_env which allows to load the value of a variable from a Introduce file_env which allows to load the value of a variable from a
file. The variable value is terminated at the first non-printable file. The variable value is terminated at the first non-printable
@ -115,5 +115,5 @@ index 3fd664aac..7e7b18139 100644
+ grub_unregister_extcmd (cmd_file); + grub_unregister_extcmd (cmd_file);
} }
-- --
2.35.3 2.36.0

View File

@ -1,10 +1,10 @@
From 3b2b7d0c9a886d913062ed5a9ffa8b764d882540 Mon Sep 17 00:00:00 2001 From 3b2b7d0c9a886d913062ed5a9ffa8b764d882540 Mon Sep 17 00:00:00 2001
Message-Id: <3b2b7d0c9a886d913062ed5a9ffa8b764d882540.1650445464.git.stefan@agner.ch> Message-Id: <3b2b7d0c9a886d913062ed5a9ffa8b764d882540.1651759401.git.stefan@agner.ch>
In-Reply-To: <184b6a054e04bb4c7fb4885a30d62314229dc551.1650445464.git.stefan@agner.ch> In-Reply-To: <184b6a054e04bb4c7fb4885a30d62314229dc551.1651759401.git.stefan@agner.ch>
References: <184b6a054e04bb4c7fb4885a30d62314229dc551.1650445464.git.stefan@agner.ch> References: <184b6a054e04bb4c7fb4885a30d62314229dc551.1651759401.git.stefan@agner.ch>
From: Peter Jones <pjones@redhat.com> From: Peter Jones <pjones@redhat.com>
Date: Mon, 27 Jan 2020 15:01:16 -0500 Date: Mon, 27 Jan 2020 15:01:16 -0500
Subject: [PATCH 2/2] squash4: Fix an uninitialized variable Subject: [PATCH] squash4: Fix an uninitialized variable
MIME-Version: 1.0 MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8 Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit Content-Transfer-Encoding: 8bit
@ -40,5 +40,5 @@ index 95d5c1e1f..82704f966 100644
grub_uint64_t a = 0; grub_uint64_t a = 0;
grub_size_t i; grub_size_t i;
-- --
2.35.3 2.36.0

View File

@ -0,0 +1,58 @@
From 74d815143bb9b504fb54d3eaf0ed3e382b26000a Mon Sep 17 00:00:00 2001
Message-Id: <74d815143bb9b504fb54d3eaf0ed3e382b26000a.1651759401.git.stefan@agner.ch>
In-Reply-To: <184b6a054e04bb4c7fb4885a30d62314229dc551.1651759401.git.stefan@agner.ch>
References: <184b6a054e04bb4c7fb4885a30d62314229dc551.1651759401.git.stefan@agner.ch>
From: Stefan Agner <stefan@agner.ch>
Date: Thu, 5 May 2022 15:46:51 +0200
Subject: [PATCH] efidisk: pass buffers with higher alignment
Despite the UEFI specification saying "the requirement is that the
start address of a buffer must be evenly divisible by IoAlign with
no remainder.", it seems that a higher alignment requirement is
neecssary on some system (e.g. a Intel NUC system with NVMe SSD).
That particular system has IoAlign set to 2, and sometimes returns
status 7 when buffers with alignment of 2 are passed. Things seem
to work fine with buffers aligned to 4 bytes.
It seems that IoAlign > 1 means 2 ^ IoAlign. There is also such a hint
in an example printed in the Driver Writer's Guide:
ScsiPassThruMode.IoAlign = 2; // Data must be alligned on 4-byte boundary
Pass 2 ^ IoAlign aligned buffers to make sure GRUB2 works properly on
all systems.
Note: The problem has only noticed with compressed squashfs. It seems
that ext4 (and presumably other file system drivers) pass buffers with
a higher alignment already.
Signed-off-by: Stefan Agner <stefan@agner.ch>
---
grub-core/disk/efi/efidisk.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c
index 9e20af70e..eaf22367f 100644
--- a/grub-core/disk/efi/efidisk.c
+++ b/grub-core/disk/efi/efidisk.c
@@ -553,8 +553,16 @@ grub_efidisk_readwrite (struct grub_disk *disk, grub_disk_addr_t sector,
d = disk->data;
bio = d->block_io;
- /* Set alignment to 1 if 0 specified */
- io_align = bio->media->io_align ? bio->media->io_align : 1;
+ /*
+ * If IoAlign is > 1, it means alignment by 2^IoAlign
+ * Note: UEFI spec claims alignment by IoAlign. But there are systems
+ * with IoAlign=2 which return status 7 if 2 bytes aligned buffers are
+ * passed.
+ */
+ if (bio->media->io_align > 1)
+ io_align = 1 << bio->media->io_align;
+ else
+ io_align = 1;
num_bytes = size << disk->log_sector_size;
if ((grub_addr_t) buf & (io_align - 1))
--
2.36.0