Patch genimage to force first usable LBA @ 34 to fix RPi 5/Windows issues (#3497)

Genimage sets the first usable LBA to the offset of the first partition. While
it shouldn't be an issue in theory, Windows may do some nasty things with the
GPT header afterwards which breaks the Raspberry Pi bootloader, manifesting as

Before purpose of this behavior is clarified in [1], add a downstream patch
that sets the first usable LBA back to 34, which was the value that was used
before migrating to Genimage in #3388. Since changing this value (hopefully)
doesn't have any other consequences, and the images now should be closer to
pre-genimage builds, no more side-effects are expected from this change.

[1] https://www.github.com/pengutronix/genimage/issues/262

Fixes #3437
This commit is contained in:
Jan Čermák 2024-07-30 18:57:37 +02:00 committed by GitHub
parent 13c4bb56c0
commit d51a0d3cec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -0,0 +1,64 @@
From 9484103803a36783fe6f6a8ec762797cf962c9bf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20=C4=8Cerm=C3=A1k?= <sairon@sairon.cz>
Date: Mon, 29 Jul 2024 17:00:31 +0200
Subject: [PATCH] image-hd: do not use first partition offset for GPT's first
usable LBA
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Currently first usable LBA in the GPT header is pointing to offset of
the first partition, ignoring the gpt-location specified in the config.
This can lead to some issues as explained in [1]. Disabling this
behavior doesn't break any tests and allows for generating of images
that have same layout as those generated by sgdisk or other utilities.
[1] https://github.com/pengutronix/genimage/issues/262
Signed-off-by: Jan Čermák <sairon@sairon.cz>
---
image-hd.c | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/image-hd.c b/image-hd.c
index 6fb850f..4f965db 100644
--- a/image-hd.c
+++ b/image-hd.c
@@ -456,7 +456,6 @@ static int hdimage_insert_gpt(struct image *image, struct list_head *partitions)
const char *outfile = imageoutfile(image);
struct gpt_header header;
struct gpt_partition_entry table[GPT_ENTRIES];
- unsigned long long smallest_offset = ~0ULL;
struct partition *part;
unsigned i, j;
int ret;
@@ -469,7 +468,7 @@ static int hdimage_insert_gpt(struct image *image, struct list_head *partitions)
header.header_size = htole32(sizeof(struct gpt_header));
header.current_lba = htole64(1);
header.backup_lba = htole64(hd->gpt_no_backup ? 1 :image->size/512 - 1);
- header.first_usable_lba = htole64(~0ULL);
+ header.first_usable_lba = htole64(hd->gpt_location / 512 + GPT_SECTORS - 1);
header.last_usable_lba = htole64(image->size/512 - 1 - GPT_SECTORS);
uuid_parse(hd->disk_uuid, header.disk_uuid);
header.starting_lba = htole64(hd->gpt_location/512);
@@ -482,9 +481,6 @@ static int hdimage_insert_gpt(struct image *image, struct list_head *partitions)
if (!part->in_partition_table)
continue;
- if (part->offset < smallest_offset)
- smallest_offset = part->offset;
-
uuid_parse(part->partition_type_uuid, table[i].type_uuid);
uuid_parse(part->partition_uuid, table[i].uuid);
table[i].first_lba = htole64(part->offset/512);
@@ -499,10 +495,6 @@ static int hdimage_insert_gpt(struct image *image, struct list_head *partitions)
i++;
}
- if (smallest_offset == ~0ULL)
- smallest_offset = hd->gpt_location + (GPT_SECTORS - 1)*512;
- header.first_usable_lba = htole64(smallest_offset / 512);
-
header.table_crc = htole32(crc32(table, sizeof(table)));