
On Thu, Mar 28, 2024 at 8:07 PM Heinrich Schuchardt xypron.glpk@gmx.de wrote:
On 3/28/24 23:29, Sam Protsenko wrote:
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:
- Partition type GUID will be all-zero ("unused")
- 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)
The UEFI specification is defining what a GPT partition table has to look like.
According the specification partition type GUID 00000000-0000-0000-0000-000000000000 marks an "unused entry" in the partition table.
An unused partition table entry cannot define a partition. It is one of the entries, that you skip over when enumerating via your patch 1/2.
With this patch 128 partition table entries are printed for an image having a single partition.
=> part list host 0
Partition Map for HOST device 0 -- Partition Type: EFI
Part Start LBA End LBA Name Attributes Type GUID Partition GUID 1 0x00000800 0x0001f7ff "EFI system partition" attrs: 0x0000000000000005 type: c12a7328-f81f-11d2-ba4b-00a0c93ec93b (system) guid: ee474198-4601-4d5c-81f0-54acf904dd40 2 0x00000000 0x00000000 "" attrs: 0x0000000000000000 type: 00000000-0000-0000-0000-000000000000 (00000000-0000-0000-0000-000000000000) guid: 00000000-0000-0000-0000-000000000000 ...
128 0x00000000 0x00000000 "" attrs: 0x0000000000000000 type: 00000000-0000-0000-0000-000000000000 (00000000-0000-0000-0000-000000000000) guid: 00000000-0000-0000-0000-000000000000
This is definitively wrong.
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).
You cannot interact with a non-existing partition.
You may create a new partition in any empty slot that Samsung's tool has left in the partition table and then write to it. No patch is needed for this.
Thanks for reviewing! In case of Samsung's way of creating GPT tables, those are actually real partitions (they just "hide" those by means of setting their type GUIDs to 0), and it's possible to flash those and interact with them in other ways. But I can see how it's not a standard way of doing things. And because (as you pointed out) this patch leads to undesirable effects on other platforms, I also think it should be NAKed. That of course means it won't be possible to access all partitions on downstream Samsung devices, but with upstream U-Boot people will probably want to create an appropriate GPT table anyways.
Best regards
Heinrich
[snip]