U-boot Archive mirror
 help / color / mirror / Atom feed
From: Roman Stratiienko <r.stratiienko@gmail.com>
To: sjg@chromium.org, xypron.glpk@gmx.de, r.stratiienko@gmail.com,
	u-boot@lists.denx.de
Subject: [PATCH] part: efi: Rely on a definition to specify the primary GPT position
Date: Sun, 19 May 2024 15:35:42 +0000	[thread overview]
Message-ID: <20240519153542.2572014-1-r.stratiienko@gmail.com> (raw)

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 --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 =
-- 
2.40.1


                 reply	other threads:[~2024-05-19 15:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240519153542.2572014-1-r.stratiienko@gmail.com \
    --to=r.stratiienko@gmail.com \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).