Some platforms use the "unused" (all-zero) GUID as a partition type GUID
to make some partitions hidden from the OS. For example, Samsung phones
and other devices often have GPT partition tables like that, created by
their "gpt_builder" tool [1]. All partitions with FILESYS=0 value
(second column in [2] file) will be created in a way that:
  1. Partition type GUID will be all-zero ("unused")
  2. Attributes[48:49] bits will be set to 0 (whereas non-zero values
     mean the partition is visible to the OS: 1=raw, 2=ext4, 3=f2fs)

Although it's true that Linux kernel verifies the partition type GUID to
be non-zero (in block/partitions/efi.c, is_pte_valid() function), where
its U-Boot counterpart code was borrowed from originally, in case of
U-Boot we want to handle partitions with "unused" GUIDs the same way as
any other valid partitions, to allow the user to interact with those
(e.g. list partitions using "part list", be able to flash those via
fastboot, etc).

[1] https://gitlab.com/Linaro/96boards/e850-96/tools/gpt/
[2] 
https://gitlab.com/Linaro/96boards/e850-96/tools/gpt/-/blob/master/gpt_layout

Fixes: 07f3d789b9be ("Add support for CONFIG_EFI_PARTITION (GUID Partition 
Table)")
Signed-off-by: Sam Protsenko <semen.protse...@linaro.org>
---
 disk/part_efi.c | 21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)

diff --git a/disk/part_efi.c b/disk/part_efi.c
index 4ce9243ef25c..6b138abae0a6 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -1166,28 +1166,17 @@ static gpt_entry *alloc_read_gpt_entries(struct 
blk_desc *desc,
  */
 static int is_pte_valid(gpt_entry * pte)
 {
-       efi_guid_t unused_guid;
+       /*
+        * NOTE: Do not check unused (zero) GUIDs here, it's considered a valid
+        * case in U-Boot.
+        */
 
        if (!pte) {
                log_debug("Invalid Argument(s)\n");
                return 0;
        }
 
-       /* Only one validation for now:
-        * The GUID Partition Type != Unused Entry (ALL-ZERO)
-        */
-       memset(unused_guid.b, 0, sizeof(unused_guid.b));
-
-       if (memcmp(pte->partition_type_guid.b, unused_guid.b,
-               sizeof(unused_guid.b)) == 0) {
-
-               log_debug("Found an unused PTE GUID at 0x%08X\n",
-                         (unsigned int)(uintptr_t)pte);
-
-               return 0;
-       } else {
-               return 1;
-       }
+       return 1;
 }
 
 /*
-- 
2.39.2

Reply via email to