From: Denis Mukhin <[email protected]> 

Partition drivers currently report "U-Boot" as the human-readable
partition type. This does not describe the actual partition and can be
misleading to the users of this information.

Update the human-readable partition type from "U-Boot" to
partition-specific type.

For GUID partitions, when CONFIG_PARTITION_TYPE_GUID is enabled, use
gpt_pte.partition_type_guid.b directly for type reporting.

Update the relevant tests and drop "U-Boot" check in
blk_get_device_part_str() since it can match against
gpt_pte.partition_type_guid.b (e.g. "linux").

Signed-off-by: Denis Mukhin <[email protected]>
---
Changes since v2:
- use gpt_pte.partition_type_guid.b for CONFIG_PARTITION_TYPE_GUID=y
- do not use BOOT_PART_TYPE
- add per-type partition string names
- rebased on tip of next

v2: https://lore.kernel.org/u-boot/[email protected]
CI: https://github.com/u-boot/u-boot/pull/1036
---
 disk/part.c     | 13 +++----------
 disk/part_dos.c |  5 ++---
 disk/part_efi.c |  5 ++++-
 disk/part_iso.c |  2 +-
 include/part.h  |  7 +++++++
 test/dm/scsi.c  |  2 +-
 6 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/disk/part.c b/disk/part.c
index 316a0b09a097..0fcf3af0efbd 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -381,7 +381,7 @@ int part_get_info_whole_disk(struct blk_desc *desc,
        info->size = desc->lba;
        info->blksz = desc->blksz;
        info->bootable = 0;
-       strcpy((char *)info->type, BOOT_PART_TYPE);
+       strcpy((char *)info->type, PART_TYPE_NAME_UNKNOWN);
        strcpy((char *)info->name, "Whole Disk");
        disk_partition_clr_uuid(info);
        disk_partition_clr_type_guid(info);
@@ -473,7 +473,7 @@ int blk_get_device_part_str(const char *ifname, const char 
*dev_part_str,
         * host's own filesystem.
         */
        if (!strcmp(ifname, "hostfs")) {
-               strcpy((char *)info->type, BOOT_PART_TYPE);
+               strcpy((char *)info->type, PART_TYPE_NAME_HOSTFS);
                strcpy((char *)info->name, "Host filesystem");
 
                return 0;
@@ -491,7 +491,7 @@ int blk_get_device_part_str(const char *ifname, const char 
*dev_part_str,
                        return -EINVAL;
                }
 
-               strcpy((char *)info->type, BOOT_PART_TYPE);
+               strcpy((char *)info->type, PART_TYPE_NAME_UBI);
                strcpy((char *)info->name, "UBI");
                return 0;
        }
@@ -643,13 +643,6 @@ int blk_get_device_part_str(const char *ifname, const char 
*dev_part_str,
                        goto cleanup;
                }
        }
-       if (strncmp((char *)info->type, BOOT_PART_TYPE, sizeof(info->type)) != 
0) {
-               printf("** Invalid partition type \"%.32s\""
-                       " (expect \"" BOOT_PART_TYPE "\")\n",
-                       info->type);
-               ret  = -EINVAL;
-               goto cleanup;
-       }
 
        (*desc)->log2blksz = LOG2((*desc)->blksz);
 
diff --git a/disk/part_dos.c b/disk/part_dos.c
index 4e1d01b2f21e..4b560fde1fba 100644
--- a/disk/part_dos.c
+++ b/disk/part_dos.c
@@ -273,8 +273,7 @@ static int part_get_info_extended(struct blk_desc *desc,
                                info->size  = 
(lbaint_t)get_unaligned_le32(&pt->nr_sects);
                                part_set_generic_name(desc, part_num,
                                                      (char *)info->name);
-                               /* sprintf(info->type, "%d, pt->sys_ind); */
-                               strcpy((char *)info->type, "U-Boot");
+                               snprintf(info->type, sizeof(info->type), 
"0x%x", pt->sys_ind);
                                info->bootable = get_bootable(pt);
                                if (CONFIG_IS_ENABLED(PARTITION_UUIDS)) {
                                        char str[12];
@@ -321,7 +320,7 @@ static int part_get_info_extended(struct blk_desc *desc,
                else
                        info->blksz = DOS_PART_DEFAULT_SECTOR;
                info->bootable = 0;
-               strcpy((char *)info->type, "U-Boot");
+               snprintf(info->type, sizeof(info->type), "0x%x", pt->sys_ind);
                disk_partition_clr_uuid(info);
                return 0;
        }
diff --git a/disk/part_efi.c b/disk/part_efi.c
index d8b17ec2e91a..de7048639a6d 100644
--- a/disk/part_efi.c
+++ b/disk/part_efi.c
@@ -304,7 +304,6 @@ static int __maybe_unused part_get_info_efi(struct blk_desc 
*desc, int part,
 
        snprintf((char *)info->name, sizeof(info->name), "%s",
                 print_efiname(&gpt_pte));
-       strcpy((char *)info->type, "U-Boot");
        info->bootable = get_bootable(&gpt_pte);
        info->type_flags = gpt_pte.attributes.fields.type_guid_specific;
        if (CONFIG_IS_ENABLED(PARTITION_UUIDS)) {
@@ -316,6 +315,10 @@ static int __maybe_unused part_get_info_efi(struct 
blk_desc *desc, int part,
                uuid_bin_to_str(gpt_pte.partition_type_guid.b,
                                (char *)disk_partition_type_guid(info),
                                UUID_STR_FORMAT_GUID);
+               snprintf((char *)info->type, sizeof(info->type), "%pUs",
+                        gpt_pte.partition_type_guid.b);
+       } else {
+               strcpy((char *)info->type, PART_TYPE_NAME_EFI);
        }
 
        log_debug("start 0x" LBAF ", size 0x" LBAF ", name %s\n", info->start,
diff --git a/disk/part_iso.c b/disk/part_iso.c
index 6e05b2feffba..7b4e61f2099e 100644
--- a/disk/part_iso.c
+++ b/disk/part_iso.c
@@ -135,7 +135,7 @@ int part_get_info_iso_verb(struct blk_desc *desc, int 
part_num,
        /* the validation entry seems to be ok, now search the "partition" */
        entry_num=1;
        offset=0x20;
-       strcpy((char *)info->type, "U-Boot");
+       strcpy((char *)info->type, PART_TYPE_NAME_ISO);
        part_set_generic_name(desc, part_num, (char *)info->name);
        /* the bootcatalog (including validation Entry) is limited to 2048Bytes
         * (63 boot entries + validation entry) */
diff --git a/include/part.h b/include/part.h
index a9d0039a522d..48ed4f21f1d5 100644
--- a/include/part.h
+++ b/include/part.h
@@ -29,6 +29,13 @@ struct block_drvr {
 #define PART_TYPE_MTD          0x06
 #define PART_TYPE_UBI          0x07
 
+#define PART_TYPE_NAME_UNKNOWN "unknown"
+#define PART_TYPE_NAME_ISO     "iso"
+#define PART_TYPE_NAME_EFI     "gpt"
+#define PART_TYPE_NAME_MTD     "mtd"
+#define PART_TYPE_NAME_UBI     "ubi"
+#define PART_TYPE_NAME_HOSTFS  "hostfs"
+
 /* maximum number of partition entries supported by search */
 #define DOS_ENTRY_NUMBERS      8
 #define ISO_ENTRY_NUMBERS      64
diff --git a/test/dm/scsi.c b/test/dm/scsi.c
index fbc36a742446..66859c991df1 100644
--- a/test/dm/scsi.c
+++ b/test/dm/scsi.c
@@ -30,7 +30,7 @@ static int dm_test_scsi_base(struct unit_test_state *uts)
 
        info = &part->gpt_part_info;
        ut_asserteq_str("sda1", info->name);
-       ut_asserteq_str("U-Boot", info->type);
+       ut_asserteq_str("0x83", info->type);
        ut_asserteq(0x83 /* linux */, info->sys_ind);
 
        return 0;
-- 
2.54.0

Reply via email to