aboutsummaryrefslogtreecommitdiff
path: root/lib/efi_loader/efi_disk.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2022-09-14 12:31:44 -0400
committerTom Rini <trini@konsulko.com>2022-09-14 12:31:44 -0400
commit1520af3f8450bb58168fe1cc827a56d435e9f74c (patch)
treec68826240a27e03c9edbbffdfc255d0ee6d51086 /lib/efi_loader/efi_disk.c
parent6541726ee92108935b97449ed28d8dd28c0ef001 (diff)
parentda4fb707ca095c223b67637e2525df4866e51c62 (diff)
Merge tag 'efi-next-2022-09-14' of https://source.denx.de/u-boot/custodians/u-boot-efi into next
Pull request for efi next UEFI: Implement a command eficonfig to maintain Load Options and boot order via menus.
Diffstat (limited to 'lib/efi_loader/efi_disk.c')
-rw-r--r--lib/efi_loader/efi_disk.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c
index f269abf135..a34ca46a11 100644
--- a/lib/efi_loader/efi_disk.c
+++ b/lib/efi_loader/efi_disk.c
@@ -760,3 +760,53 @@ efi_status_t efi_disk_init(void)
return EFI_SUCCESS;
}
+
+/**
+ * efi_disk_get_device_name() - get U-Boot device name associated with EFI handle
+ *
+ * @handle: pointer to the EFI handle
+ * @buf: pointer to the buffer to store the string
+ * @size: size of buffer
+ * Return: status code
+ */
+efi_status_t efi_disk_get_device_name(const efi_handle_t handle, char *buf, int size)
+{
+ int count;
+ int diskid;
+ enum uclass_id id;
+ unsigned int part;
+ struct udevice *dev;
+ struct blk_desc *desc;
+ const char *if_typename;
+ bool is_partition = false;
+ struct disk_part *part_data;
+
+ if (!handle || !buf || !size)
+ return EFI_INVALID_PARAMETER;
+
+ dev = handle->dev;
+ id = device_get_uclass_id(dev);
+ if (id == UCLASS_BLK) {
+ desc = dev_get_uclass_plat(dev);
+ } else if (id == UCLASS_PARTITION) {
+ desc = dev_get_uclass_plat(dev_get_parent(dev));
+ is_partition = true;
+ } else {
+ return EFI_INVALID_PARAMETER;
+ }
+ if_typename = blk_get_if_type_name(desc->if_type);
+ diskid = desc->devnum;
+
+ if (is_partition) {
+ part_data = dev_get_uclass_plat(dev);
+ part = part_data->partnum;
+ count = snprintf(buf, size, "%s %d:%d", if_typename, diskid, part);
+ } else {
+ count = snprintf(buf, size, "%s %d", if_typename, diskid);
+ }
+
+ if (count < 0 || (count + 1) > size)
+ return EFI_INVALID_PARAMETER;
+
+ return EFI_SUCCESS;
+}