Skip to contentSkip to conversation

disk: update partition type reporting

PATCH In review [email protected] 2 participants 2 messages Sep 1 – Sep 15

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 disk: update partition type reporting

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").

---
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(-)
disk/part.c +3 -10
index 316a0b09a097..0fcf3af0efbd 100644
@@ -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);
 
disk/part_dos.c +2 -3
index 4e1d01b2f21e..4b560fde1fba 100644
@@ -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;
 	}
disk/part_efi.c +4 -1
index d8b17ec2e91a..de7048639a6d 100644
@@ -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,
disk/part_iso.c +1 -1
index 6e05b2feffba..7b4e61f2099e 100644
@@ -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) */
include/part.h +7 -0
index a9d0039a522d..48ed4f21f1d5 100644
@@ -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
test/dm/scsi.c +1 -1
index fbc36a742446..66859c991df1 100644
@@ -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;
Signature · 1 line
2.54.0
#1 lore raw
Quoted 8 lines · On Tue, 01 Sep 2026 15:11:15 -0700, [email protected] wrote:

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.

[...]

Applied to u-boot/next, thanks!

[1/1] disk: update partition type reporting

      commit: 11cde642ee8309597832875aca105c91f846cfbc
Signature · 1 line
Tom