Skip to content

Commit

Permalink
image-hd: do not use first partition offset for GPT's first usable LBA
Browse files Browse the repository at this point in the history
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] pengutronix#262

Signed-off-by: Jan Čermák <[email protected]>
  • Loading branch information
sairon committed Nov 5, 2024
1 parent 92cc7c5 commit 8608a6b
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions image-hd.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,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;
Expand All @@ -475,7 +474,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);
Expand All @@ -488,9 +487,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);
Expand All @@ -505,10 +501,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)));

Expand Down

0 comments on commit 8608a6b

Please sign in to comment.