diff mbox series

part: efi: Rely on a definition to specify the primary GPT position

Message ID 20240519153542.2572014-1-r.stratiienko@gmail.com
State New
Delegated to: Heinrich Schuchardt
Headers show
Series part: efi: Rely on a definition to specify the primary GPT position | expand

Commit Message

Roman Stratiienko May 19, 2024, 3:35 p.m. UTC
Use GPT_PRIMARY_PARTITION_TABLE_LBA as the only source for a primary GPT
location instead of hardcoding it every time.

Sometimes, we need to shift the primary GPT location.
Having the location in the single place simplifies such shifting.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
---
 disk/part_efi.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/disk/part_efi.c b/disk/part_efi.c
index 4ce9243ef2..b55e251ea1 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -387,7 +387,7 @@  int write_gpt_table(struct blk_desc *desc, gpt_header *gpt_h, gpt_entry *gpt_e)
 	gpt_h->header_crc32 = cpu_to_le32(calc_crc32);
 
 	/* Write the First GPT to the block right after the Legacy MBR */
-	if (blk_dwrite(desc, 1, 1, gpt_h) != 1)
+	if (blk_dwrite(desc, (lbaint_t)le64_to_cpu(gpt_h->my_lba), 1, gpt_h) != 1)
 		goto err;
 
 	if (blk_dwrite(desc, le64_to_cpu(gpt_h->partition_entry_lba),
@@ -534,7 +534,7 @@  int gpt_fill_pte(struct blk_desc *desc,
 
 static uint32_t partition_entries_offset(struct blk_desc *desc)
 {
-	uint32_t offset_blks = 2;
+	uint32_t offset_blks = GPT_PRIMARY_PARTITION_TABLE_LBA + 1;
 	uint32_t __maybe_unused offset_bytes;
 	int __maybe_unused config_offset;
 
@@ -572,8 +572,8 @@  static uint32_t partition_entries_offset(struct blk_desc *desc)
 	 * The earliest LBA this can be at is LBA#2 (i.e. right behind
 	 * the (protective) MBR and the GPT header.
 	 */
-	if (offset_blks < 2)
-		offset_blks = 2;
+	if (offset_blks < (GPT_PRIMARY_PARTITION_TABLE_LBA + 1))
+		offset_blks = GPT_PRIMARY_PARTITION_TABLE_LBA + 1;
 
 	return offset_blks;
 }
@@ -584,7 +584,7 @@  int gpt_fill_header(struct blk_desc *desc, gpt_header *gpt_h, char *str_guid,
 	gpt_h->signature = cpu_to_le64(GPT_HEADER_SIGNATURE_UBOOT);
 	gpt_h->revision = cpu_to_le32(GPT_HEADER_REVISION_V1);
 	gpt_h->header_size = cpu_to_le32(sizeof(gpt_header));
-	gpt_h->my_lba = cpu_to_le64(1);
+	gpt_h->my_lba = cpu_to_le64(GPT_PRIMARY_PARTITION_TABLE_LBA);
 	gpt_h->alternate_lba = cpu_to_le64(desc->lba - 1);
 	gpt_h->last_usable_lba = cpu_to_le64(desc->lba - 34);
 	gpt_h->partition_entry_lba =