From: Svyatoslav Ryhel <clamor95@gmail.com>
Date: Wed, 31 Jul 2024 08:22:54 +0000 (+0300)
Subject: disk: add TegraPT support
X-Git-Tag: v2025.01-rc5-pxa1908~267^2~15
X-Git-Url: http://git.dujemihanovic.xyz/html/%7B%7B%20.RelPermalink%20%7D%7D?a=commitdiff_plain;h=83b5f6367941f0f1c1904e4fde895fceedb75437;p=u-boot.git

disk: add TegraPT support

TegraPT is compatible with EFI part but it can't pass Protective MBR check.
Skip this check if CONFIG_TEGRA_PARTITION is enabled, storage uclass is MMC
and devnum is 0. Note, eMMC on supported devices MUST be aliased to mmc0.

Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---

diff --git a/disk/Kconfig b/disk/Kconfig
index ffa835eb35..b0bd02539e 100644
--- a/disk/Kconfig
+++ b/disk/Kconfig
@@ -49,6 +49,16 @@ config SPL_MAC_PARTITION
 	default y if MAC_PARTITION
 	select SPL_PARTITIONS
 
+config TEGRA_PARTITION
+	bool "Enable Nvidia Tegra partition table"
+	select PARTITIONS
+	select EFI_PARTITION
+	help
+	  Say Y here if you would like to use U-Boot on a device that
+	  is using the Nvidia Tegra partition table and cannot alter it.
+
+	  If unsure, say N.
+
 config DOS_PARTITION
 	bool "Enable MS Dos partition table"
 	default y if BOOT_DEFAULTS
diff --git a/disk/part_efi.c b/disk/part_efi.c
index 580821a6ee..12f28aec92 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -318,6 +318,19 @@ static int part_test_efi(struct blk_desc *desc)
 	/* Read legacy MBR from block 0 and validate it */
 	if ((blk_dread(desc, 0, 1, (ulong *)legacymbr) != 1)
 		|| (is_pmbr_valid(legacymbr) != 1)) {
+
+		/*
+		 * TegraPT is compatible with EFI part, but it
+		 * cannot pass the Protective MBR check. Skip it
+		 * if CONFIG_TEGRA_PARTITION is enabled and the
+		 * device in question is eMMC.
+		 */
+		if (IS_ENABLED(CONFIG_TEGRA_PARTITION))
+			if (!is_pmbr_valid(legacymbr) &&
+			    desc->uclass_id == UCLASS_MMC &&
+			    !desc->devnum)
+				return 0;
+
 		return -1;
 	}
 	return 0;