[PATCH 2/6] partitions: gpt: refresh also when primary or alternate is invalid

Sascha Hauer s.hauer at pengutronix.de
Wed Jul 1 02:27:35 PDT 2026


Currently we only refresh/repair when primary and alternate GPT differ. When
either of them is missing, we should repair as well.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/partitions/efi.c | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/common/partitions/efi.c b/common/partitions/efi.c
index 28198f25b1..98172672ff 100644
--- a/common/partitions/efi.c
+++ b/common/partitions/efi.c
@@ -385,10 +385,20 @@ compare_gpts(struct block_device *blk, gpt_header *pgpt, gpt_header *agpt,
 	     u64 lastlba)
 {
 	struct device *dev = blk->dev;
-
 	int error_found = 0;
-	if (!pgpt || !agpt)
-		return;
+
+	if (!pgpt) {
+		dev_warn(dev, "GPT:Primary GPT not found\n");
+		error_found++;
+		goto refresh;
+	}
+
+	if (!agpt) {
+		dev_warn(dev, "GPT:Alternate GPT not found\n");
+		error_found++;
+		goto refresh;
+	}
+
 	if (le64_to_cpu(pgpt->my_lba) != le64_to_cpu(agpt->alternate_lba)) {
 		dev_warn(dev,
 		       "GPT:Primary header LBA != Alt. header alternate_lba\n");
@@ -469,15 +479,15 @@ compare_gpts(struct block_device *blk, gpt_header *pgpt, gpt_header *agpt,
 		error_found++;
 	}
 
-	if (error_found) {
-		add_gpt_refresh(blk);
-		if (!IS_ENABLED(CONFIG_PARTITION_DISK_EFI_REFRESH))
-			dev_info(dev, "GPT: will repair later if global.system.gpt_refresh=1\n");
-		else
-			dev_warn(dev, "GPT: Use parted to correct GPT errors.\n");
-	}
+	if (!error_found)
+		return;
 
-	return;
+refresh:
+	add_gpt_refresh(blk);
+	if (!IS_ENABLED(CONFIG_PARTITION_DISK_EFI_REFRESH))
+		dev_info(dev, "GPT: will repair later if global.system.gpt_refresh=1\n");
+	else
+		dev_warn(dev, "GPT: Use parted to correct GPT errors.\n");
 }
 
 /**

-- 
2.47.3




More information about the barebox mailing list