On 8/26/23 04:04, Simon Glass wrote:
Hi Heinrich,

On Fri, 25 Aug 2023 at 19:53, Heinrich Schuchardt
<heinrich.schucha...@canonical.com> wrote:

Do not assume that partitions are numbered continuously starting at 1.

Only a single partition table type can exist on a block device. If we found
a GPT partition table, we must not re-enumerate with the MBR partition
driver which would find the protective partition.

Does it really? My understand is that it sets desc->part_type and it
stays like that from then on?

Prior to my patch with printf statements added:

=> gpt enumerate host 0
enumeration by driver EFI
  partition 'EFI system partition'
enumeration by driver AMIGA
enumeration by driver DOS
  partition 'xxa1'
enumeration by driver ISO
enumeration by driver MAC
setenv gpt_partition_list EFI system partition xxa1
success!

Of course the value of $gpt_partition_list is useless because you do not even know how many partitions were discovered 'EFI', 'system', 'partition' could be the names of three different partitions or there could be one partition 'EFI system partition'.

I wonder how Broadcom can use this in their update scripts. See 12fc1f3bb223 ("cmd: gpt: add eMMC and GPT support").

For something usable we would have to add quotations marks, escape quotation marks in the string, and the do-for command would need to support a string with quotation marks like

"'Heinrich\'s partition one' 'EFI system partition'"

The "xxa1" string is generated in part_set_generic_name() because MBR partitions don't have a name.

xx = other block device type
a = device number 0
1 = partition number 0

Best regards

Heinrich



Signed-off-by: Heinrich Schuchardt <heinrich.schucha...@canonical.com>
---
  cmd/gpt.c | 14 ++++++++------
  1 file changed, 8 insertions(+), 6 deletions(-)


Reviewed-by: Simon Glass <s...@chromium.org>


diff --git a/cmd/gpt.c b/cmd/gpt.c
index d0e165d539..99ca0a6163 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -691,12 +691,13 @@ static int gpt_enumerate(struct blk_desc *desc)
                 int ret;
                 int i;

+               if (part_drv->test(desc))
+                       continue;
+
                 for (i = 1; i < part_drv->max_entries; i++) {
                         ret = part_drv->get_info(desc, i, &pinfo);
-                       if (ret) {
-                               /* no more entries in table */
-                               break;
-                       }
+                       if (ret)
+                               continue;

                         ptr = &part_list[str_len];
                         tmp_len = strlen((const char *)pinfo.name);
@@ -711,9 +712,10 @@ static int gpt_enumerate(struct blk_desc *desc)
                         /* One byte for space(" ") delimiter */
                         ptr[tmp_len] = ' ';
                 }
+               if (*part_list)
+                       part_list[strlen(part_list) - 1] = 0;
+               break;
         }
-       if (*part_list)
-               part_list[strlen(part_list) - 1] = 0;
         debug("setenv gpt_partition_list %s\n", part_list);

         return env_set("gpt_partition_list", part_list);
--
2.40.1

Reply via email to