summaryrefslogtreecommitdiff
path: root/lib/efi_loader/efi_device_path_to_text.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2017-07-31 07:27:45 -0400
committerTom Rini <trini@konsulko.com>2017-07-31 07:27:45 -0400
commit2218b32d88f9b4b4484cea9a8b034ddab0be298b (patch)
tree828c2f1d58b3c16046198afbe8c1338fa255a805 /lib/efi_loader/efi_device_path_to_text.c
parent55f228b07e2d84938a88737445441e736de41340 (diff)
parentaf65db85b82b161f037e0889ae58bf461217b3f1 (diff)
Merge tag 'signed-efi-next' of git://github.com/agraf/u-boot
Patch queue for efi - 2017-07-29 A lot of EFI greatness this time around. Thanks a lot to the two amazing new contributors Heinrich Schuchardt and Rob Clark we now gain - stable objects across multiple bootefi invocations - fixes for shim - fixes for ipxe - protocol installation - device path conversion to/from text - working "lsefi" support in grub - working notifiers - various bug fixes
Diffstat (limited to 'lib/efi_loader/efi_device_path_to_text.c')
-rw-r--r--lib/efi_loader/efi_device_path_to_text.c130
1 files changed, 130 insertions, 0 deletions
diff --git a/lib/efi_loader/efi_device_path_to_text.c b/lib/efi_loader/efi_device_path_to_text.c
new file mode 100644
index 00000000000..4b2f43f0c8a
--- /dev/null
+++ b/lib/efi_loader/efi_device_path_to_text.c
@@ -0,0 +1,130 @@
+/*
+ * EFI device path interface
+ *
+ * Copyright (c) 2017 Heinrich Schuchardt
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <efi_loader.h>
+
+#define MAC_OUTPUT_LEN 22
+#define UNKNOWN_OUTPUT_LEN 23
+
+const efi_guid_t efi_guid_device_path_to_text_protocol =
+ EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID;
+
+static uint16_t *efi_convert_device_node_to_text(
+ struct efi_device_path_protocol *device_node,
+ bool display_only,
+ bool allow_shortcuts)
+{
+ unsigned long buffer_size;
+ efi_status_t r;
+ uint16_t *buffer = NULL;
+ int i;
+
+ switch (device_node->type) {
+ case DEVICE_PATH_TYPE_END:
+ return NULL;
+ case DEVICE_PATH_TYPE_MESSAGING_DEVICE:
+ switch (device_node->sub_type) {
+ case DEVICE_PATH_SUB_TYPE_MSG_MAC_ADDR: {
+ struct efi_device_path_mac_addr *dp =
+ (struct efi_device_path_mac_addr *)device_node;
+
+ if (dp->if_type != 0 && dp->if_type != 1)
+ break;
+ r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES,
+ 2 * MAC_OUTPUT_LEN,
+ (void **)&buffer);
+ if (r != EFI_SUCCESS)
+ return NULL;
+ sprintf((char *)buffer,
+ "MAC(%02x%02x%02x%02x%02x%02x,0x%1x)",
+ dp->mac.addr[0], dp->mac.addr[1],
+ dp->mac.addr[2], dp->mac.addr[3],
+ dp->mac.addr[4], dp->mac.addr[5],
+ dp->if_type);
+ for (i = MAC_OUTPUT_LEN - 1; i >= 0; --i)
+ buffer[i] = ((uint8_t *)buffer)[i];
+ break;
+ }
+ }
+ break;
+ case DEVICE_PATH_TYPE_MEDIA_DEVICE:
+ switch (device_node->sub_type) {
+ case DEVICE_PATH_SUB_TYPE_FILE_PATH:
+ buffer_size = device_node->length - 4;
+ r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES,
+ buffer_size, (void **) &buffer);
+ if (r != EFI_SUCCESS)
+ return NULL;
+ memcpy(buffer, device_node->data, buffer_size);
+ break;
+ }
+ break;
+ }
+
+ /*
+ * For all node types that we do not yet support return
+ * 'UNKNOWN(type,subtype)'.
+ */
+ if (!buffer) {
+ r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES,
+ 2 * UNKNOWN_OUTPUT_LEN,
+ (void **)&buffer);
+ if (r != EFI_SUCCESS)
+ return NULL;
+ sprintf((char *)buffer,
+ "UNKNOWN(%04x,%04x)",
+ device_node->type,
+ device_node->sub_type);
+ for (i = UNKNOWN_OUTPUT_LEN - 1; i >= 0; --i)
+ buffer[i] = ((uint8_t *)buffer)[i];
+ }
+
+ return buffer;
+}
+
+static uint16_t EFIAPI *efi_convert_device_node_to_text_ext(
+ struct efi_device_path_protocol *device_node,
+ bool display_only,
+ bool allow_shortcuts)
+{
+ uint16_t *buffer;
+
+ EFI_ENTRY("%p, %d, %d", device_node, display_only, allow_shortcuts);
+
+ buffer = efi_convert_device_node_to_text(device_node, display_only,
+ allow_shortcuts);
+
+ EFI_EXIT(EFI_SUCCESS);
+ return buffer;
+}
+
+static uint16_t EFIAPI *efi_convert_device_path_to_text(
+ struct efi_device_path_protocol *device_path,
+ bool display_only,
+ bool allow_shortcuts)
+{
+ uint16_t *buffer;
+
+ EFI_ENTRY("%p, %d, %d", device_path, display_only, allow_shortcuts);
+
+ /*
+ * Our device paths are all of depth one. So its is sufficient to
+ * to convert the first node.
+ */
+ buffer = efi_convert_device_node_to_text(device_path, display_only,
+ allow_shortcuts);
+
+ EFI_EXIT(EFI_SUCCESS);
+ return buffer;
+}
+
+const struct efi_device_path_to_text_protocol efi_device_path_to_text = {
+ .convert_device_node_to_text = efi_convert_device_node_to_text_ext,
+ .convert_device_path_to_text = efi_convert_device_path_to_text,
+};