[PATCH] efi_loader: expand disk device names with drive details

Padmarao Begari padmarao.begari at amd.com
Mon Apr 20 09:28:41 CEST 2026


Increase the boot menu device name buffer so we can append extra
metadata. Append the disk capacity and trimmed vendor/product strings
to the device name so users can differentiate drives in the EFI boot
menu. Also tighten the parameter validation and pull in linux/string.h
for strl* helpers.

For example, the U-Boot boot menu now shows entries such as:

    usb 0 (29.7 GiB, Generic Ultra HS-COMBO)
    usb 1 (28.6 GiB, USB SanDisk 3.2Gen1)
    scsi 0 (1 GiB, MICRON MT064GBCAV1U31AA)

Signed-off-by: Padmarao Begari <padmarao.begari at amd.com>
---
 include/efi_loader.h      |  2 +-
 lib/efi_loader/efi_disk.c | 86 ++++++++++++++++++++++++++++++++++++++-
 2 files changed, 85 insertions(+), 3 deletions(-)

diff --git a/include/efi_loader.h b/include/efi_loader.h
index 3a4d502631c..b6065cfdab7 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -290,7 +290,7 @@ const char *__efi_nesting_dec(void);
 #endif
 
 /* max bootmenu title size for volume selection */
-#define BOOTMENU_DEVICE_NAME_MAX 16
+#define BOOTMENU_DEVICE_NAME_MAX 128
 
 /* Key identifying current memory map */
 extern efi_uintn_t efi_memory_map_key;
diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
index f8a57539ec6..e0b613065d5 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -19,6 +19,8 @@
 #include <log.h>
 #include <part.h>
 #include <malloc.h>
+#include <linux/sizes.h>
+#include <linux/string.h>
 
 struct efi_system_partition efi_system_partition = {
 	.uclass_id = UCLASS_INVALID,
@@ -813,9 +815,87 @@ int efi_disk_remove(void *ctx, struct event *event)
 
 }
 
+#define EFI_DISK_SIZE_TENTHS		10
+#define EFI_DISK_CAPACITY_STR_MAX	sizeof("17179869183.9 GiB")
+#define EFI_DISK_DETAIL_MAX		(BLK_VEN_SIZE + BLK_PRD_SIZE + \
+					 EFI_DISK_CAPACITY_STR_MAX + \
+					 sizeof(" (, )"))
+
+/**
+ * efi_disk_append_detail() - append capacity and vendor info to a device label
+ *
+ * Appends a " (size, vendor product)" suffix to @buf when the block
+ * descriptor carries readable capacity or identification strings.
+ *
+ * @desc:	block device descriptor
+ * @buf:	label buffer to append to (already contains base name)
+ * @size:	total size of @buf in bytes
+ */
+static void efi_disk_append_detail(const struct blk_desc *desc,
+				   char *buf, int size)
+{
+	u64 capacity = (u64)desc->lba * desc->blksz;
+	char capacity_str[EFI_DISK_CAPACITY_STR_MAX];
+	char vendor_buf[BLK_VEN_SIZE + 1];
+	char product_buf[BLK_PRD_SIZE + 1];
+	char detail[EFI_DISK_DETAIL_MAX];
+	char *vendor, *product;
+
+	capacity_str[0] = '\0';
+
+	if (capacity >= SZ_1G) {
+		u64 gib = capacity / SZ_1G;
+		u64 tenths = ((capacity % SZ_1G) * EFI_DISK_SIZE_TENTHS) /
+			     SZ_1G;
+
+		if (tenths)
+			snprintf(capacity_str, sizeof(capacity_str),
+				 "%llu.%u GiB", gib,
+				 (unsigned int)tenths);
+		else
+			snprintf(capacity_str, sizeof(capacity_str),
+				 "%llu GiB", gib);
+	} else if (capacity >= SZ_1M) {
+		snprintf(capacity_str, sizeof(capacity_str), "%llu MiB",
+			 capacity / SZ_1M);
+	} else if (capacity >= SZ_1K) {
+		snprintf(capacity_str, sizeof(capacity_str), "%llu KiB",
+			 capacity / SZ_1K);
+	} else if (capacity) {
+		snprintf(capacity_str, sizeof(capacity_str), "%llu B", capacity);
+	}
+
+	strlcpy(vendor_buf, desc->vendor, sizeof(vendor_buf));
+	strlcpy(product_buf, desc->product, sizeof(product_buf));
+	vendor = strim(vendor_buf);
+	product = strim(product_buf);
+
+	if (!capacity_str[0] && !vendor[0] && !product[0])
+		return;
+
+	detail[0] = '\0';
+	strlcat(detail, " (", sizeof(detail));
+	if (capacity_str[0]) {
+		strlcat(detail, capacity_str, sizeof(detail));
+		if (vendor[0] || product[0])
+			strlcat(detail, ", ", sizeof(detail));
+	}
+	strlcat(detail, vendor, sizeof(detail));
+	if (vendor[0] && product[0])
+		strlcat(detail, " ", sizeof(detail));
+	strlcat(detail, product, sizeof(detail));
+	strlcat(detail, ")", sizeof(detail));
+
+	strlcat(buf, detail, size);
+}
+
 /**
  * efi_disk_get_device_name() - get U-Boot device name associated with EFI handle
  *
+ * Fills @buf with a human-readable label such as "mmc 0 (7.5 GiB, SanDisk
+ * AJTD4R)". Capacity and trimmed vendor/product strings are appended when
+ * available.
+ *
  * @handle:	pointer to the EFI handle
  * @buf:	pointer to the buffer to store the string
  * @size:	size of buffer
@@ -833,7 +913,7 @@ efi_status_t efi_disk_get_device_name(const efi_handle_t handle, char *buf, int
 	bool is_partition = false;
 	struct disk_part *part_data;
 
-	if (!handle || !buf || !size)
+	if (!handle || !buf || size <= 0)
 		return EFI_INVALID_PARAMETER;
 
 	dev = handle->dev;
@@ -858,9 +938,11 @@ efi_status_t efi_disk_get_device_name(const efi_handle_t handle, char *buf, int
 		count = snprintf(buf, size, "%s %d", if_typename, diskid);
 	}
 
-	if (count < 0 || (count + 1) > size)
+	if (count < 0 || count >= size)
 		return EFI_INVALID_PARAMETER;
 
+	efi_disk_append_detail(desc, buf, size);
+
 	return EFI_SUCCESS;
 }
 
-- 
2.34.1



More information about the U-Boot mailing list