From fdf782388722a6799b94838599156f1950f417d5 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Thu, 5 May 2022 16:53:26 +0200 Subject: [PATCH] Fix booting on certain UEFI systems (#1830) (#1881) --- ...v-add-file_env-to-load-var-from-file.patch | 6 +- ...quash4-Fix-an-uninitialized-variable.patch | 10 ++-- ...k-pass-buffers-with-higher-alignment.patch | 58 +++++++++++++++++++ 3 files changed, 66 insertions(+), 8 deletions(-) create mode 100644 buildroot-external/patches/grub2/0003-efidisk-pass-buffers-with-higher-alignment.patch diff --git a/buildroot-external/patches/grub2/0001-loadenv-add-file_env-to-load-var-from-file.patch b/buildroot-external/patches/grub2/0001-loadenv-add-file_env-to-load-var-from-file.patch index 3978e0f5c..89613b89c 100644 --- a/buildroot-external/patches/grub2/0001-loadenv-add-file_env-to-load-var-from-file.patch +++ b/buildroot-external/patches/grub2/0001-loadenv-add-file_env-to-load-var-from-file.patch @@ -1,8 +1,8 @@ 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 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 file. The variable value is terminated at the first non-printable @@ -115,5 +115,5 @@ index 3fd664aac..7e7b18139 100644 + grub_unregister_extcmd (cmd_file); } -- -2.35.3 +2.36.0 diff --git a/buildroot-external/patches/grub2/0002-squash4-Fix-an-uninitialized-variable.patch b/buildroot-external/patches/grub2/0002-squash4-Fix-an-uninitialized-variable.patch index 95f7716ad..c9d213767 100644 --- a/buildroot-external/patches/grub2/0002-squash4-Fix-an-uninitialized-variable.patch +++ b/buildroot-external/patches/grub2/0002-squash4-Fix-an-uninitialized-variable.patch @@ -1,10 +1,10 @@ From 3b2b7d0c9a886d913062ed5a9ffa8b764d882540 Mon Sep 17 00:00:00 2001 -Message-Id: <3b2b7d0c9a886d913062ed5a9ffa8b764d882540.1650445464.git.stefan@agner.ch> -In-Reply-To: <184b6a054e04bb4c7fb4885a30d62314229dc551.1650445464.git.stefan@agner.ch> -References: <184b6a054e04bb4c7fb4885a30d62314229dc551.1650445464.git.stefan@agner.ch> +Message-Id: <3b2b7d0c9a886d913062ed5a9ffa8b764d882540.1651759401.git.stefan@agner.ch> +In-Reply-To: <184b6a054e04bb4c7fb4885a30d62314229dc551.1651759401.git.stefan@agner.ch> +References: <184b6a054e04bb4c7fb4885a30d62314229dc551.1651759401.git.stefan@agner.ch> From: Peter Jones 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @@ -40,5 +40,5 @@ index 95d5c1e1f..82704f966 100644 grub_uint64_t a = 0; grub_size_t i; -- -2.35.3 +2.36.0 diff --git a/buildroot-external/patches/grub2/0003-efidisk-pass-buffers-with-higher-alignment.patch b/buildroot-external/patches/grub2/0003-efidisk-pass-buffers-with-higher-alignment.patch new file mode 100644 index 000000000..2d3be553c --- /dev/null +++ b/buildroot-external/patches/grub2/0003-efidisk-pass-buffers-with-higher-alignment.patch @@ -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 +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 +--- + 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 +