efi_loader: Initial EFI_DEVICE_PATH_UTILITIES_PROTOCOL
authorLeif Lindholm <leif.lindholm@linaro.org>
Fri, 9 Mar 2018 16:43:21 +0000 (17:43 +0100)
committerAlexander Graf <agraf@suse.de>
Wed, 4 Apr 2018 09:00:06 +0000 (11:00 +0200)
Not complete, but enough for Shell.efi and SCT.efi.  We'll implement the
rest as needed or once we have SCT running properly so there is a way to
validate the interface against the conformance test suite.

Initial skeleton written by Leif, and then implementation by Rob.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
[Fill initial skeleton]
Signed-off-by: Rob Clark <robdclark@gmail.com>
[Rebase on v2018.03-rc1]
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
include/efi_api.h
include/efi_loader.h
lib/efi_loader/Makefile
lib/efi_loader/efi_boottime.c
lib/efi_loader/efi_device_path_utilities.c [new file with mode: 0644]

index 8559656bad965b20f4af675c84f218066781bfa4..827a192620b699f6f7f1f54f751493422fc58f1a 100644 (file)
@@ -587,6 +587,35 @@ struct efi_device_path_to_text_protocol
                        bool allow_shortcuts);
 };
 
+#define EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID \
+       EFI_GUID(0x0379be4e, 0xd706, 0x437d, \
+                0xb0, 0x37, 0xed, 0xb8, 0x2f, 0xb7, 0x72, 0xa4)
+
+struct efi_device_path_utilities_protocol {
+       efi_uintn_t (EFIAPI *get_device_path_size)(
+               const struct efi_device_path *device_path);
+       struct efi_device_path *(EFIAPI *duplicate_device_path)(
+               const struct efi_device_path *device_path);
+       struct efi_device_path *(EFIAPI *append_device_path)(
+               const struct efi_device_path *src1,
+               const struct efi_device_path *src2);
+       struct efi_device_path *(EFIAPI *append_device_node)(
+               const struct efi_device_path *device_path,
+               const struct efi_device_path *device_node);
+       struct efi_device_path *(EFIAPI *append_device_path_instance)(
+               const struct efi_device_path *device_path,
+               const struct efi_device_path *device_path_instance);
+       struct efi_device_path *(EFIAPI *get_next_device_path_instance)(
+               struct efi_device_path **device_path_instance,
+               efi_uintn_t *device_path_instance_size);
+       bool (EFIAPI *is_device_path_multi_instance)(
+               const struct efi_device_path *device_path);
+       struct efi_device_path *(EFIAPI *create_device_node)(
+               uint8_t node_type,
+               uint8_t node_sub_type,
+               uint16_t node_length);
+};
+
 #define EFI_GOP_GUID \
        EFI_GUID(0x9042a9de, 0x23dc, 0x4a38, \
                 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a)
index 07730c3f3941de2287cd697122c93905a3b10f13..39d02669524d65478542c25e0d2ebff99af3e6a6 100644 (file)
@@ -83,6 +83,9 @@ extern struct efi_simple_text_output_protocol efi_con_out;
 extern struct efi_simple_input_interface efi_con_in;
 extern struct efi_console_control_protocol efi_console_control;
 extern const struct efi_device_path_to_text_protocol efi_device_path_to_text;
+/* implementation of the EFI_DEVICE_PATH_UTILITIES_PROTOCOL */
+extern const struct efi_device_path_utilities_protocol
+                                       efi_device_path_utilities;
 
 uint16_t *efi_dp_str(struct efi_device_path *dp);
 
@@ -97,6 +100,7 @@ extern const efi_guid_t efi_guid_loaded_image;
 extern const efi_guid_t efi_guid_device_path_to_text_protocol;
 extern const efi_guid_t efi_simple_file_system_protocol_guid;
 extern const efi_guid_t efi_file_info_guid;
+extern const efi_guid_t efi_guid_device_path_utilities_protocol;
 
 extern unsigned int __efi_runtime_start, __efi_runtime_stop;
 extern unsigned int __efi_runtime_rel_start, __efi_runtime_rel_stop;
index 2a87d9ed7760ed896c0a9010246e87ada524d91b..d2ce89713ec737036fddcfc6fbab98e19467b6b1 100644 (file)
@@ -17,7 +17,8 @@ endif
 obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o
 obj-y += efi_image_loader.o efi_boottime.o efi_runtime.o efi_console.o
 obj-y += efi_memory.o efi_device_path_to_text.o efi_device_path.o
-obj-y += efi_file.o efi_variable.o efi_bootmgr.o efi_watchdog.o
+obj-y += efi_device_path_utilities.o efi_file.o efi_variable.o efi_bootmgr.o
+obj-y += efi_watchdog.o
 obj-$(CONFIG_LCD) += efi_gop.o
 obj-$(CONFIG_DM_VIDEO) += efi_gop.o
 obj-$(CONFIG_PARTITIONS) += efi_disk.o
index 71c244ea805ebc2d27551894ac56dccb29cf9707..4e133e9b47d64cc2977ed4a143819b3a2335d7a5 100644 (file)
@@ -1426,6 +1426,12 @@ efi_status_t efi_setup_loaded_image(
        if (ret != EFI_SUCCESS)
                goto failure;
 
+       ret = efi_add_protocol(obj->handle,
+                              &efi_guid_device_path_utilities_protocol,
+                              (void *)&efi_device_path_utilities);
+       if (ret != EFI_SUCCESS)
+               goto failure;
+
        return ret;
 failure:
        printf("ERROR: Failure to install protocols for loaded image\n");
diff --git a/lib/efi_loader/efi_device_path_utilities.c b/lib/efi_loader/efi_device_path_utilities.c
new file mode 100644 (file)
index 0000000..bc97eee
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ *  EFI device path interface
+ *
+ *  Copyright (c) 2017 Leif Lindholm
+ *
+ *  SPDX-License-Identifier:     GPL-2.0+
+ */
+
+#include <common.h>
+#include <efi_loader.h>
+
+const efi_guid_t efi_guid_device_path_utilities_protocol =
+               EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID;
+
+static efi_uintn_t EFIAPI get_device_path_size(
+       const struct efi_device_path *device_path)
+{
+       efi_uintn_t sz = 0;
+
+       EFI_ENTRY("%p", device_path);
+       /* size includes the END node: */
+       if (device_path)
+               sz = efi_dp_size(device_path) + sizeof(struct efi_device_path);
+       return EFI_EXIT(sz);
+}
+
+static struct efi_device_path * EFIAPI duplicate_device_path(
+       const struct efi_device_path *device_path)
+{
+       EFI_ENTRY("%p", device_path);
+       return EFI_EXIT(efi_dp_dup(device_path));
+}
+
+static struct efi_device_path * EFIAPI append_device_path(
+       const struct efi_device_path *src1,
+       const struct efi_device_path *src2)
+{
+       EFI_ENTRY("%p, %p", src1, src2);
+       return EFI_EXIT(efi_dp_append(src1, src2));
+}
+
+static struct efi_device_path * EFIAPI append_device_node(
+       const struct efi_device_path *device_path,
+       const struct efi_device_path *device_node)
+{
+       EFI_ENTRY("%p, %p", device_path, device_node);
+       return EFI_EXIT(efi_dp_append_node(device_path, device_node));
+}
+
+static struct efi_device_path * EFIAPI append_device_path_instance(
+       const struct efi_device_path *device_path,
+       const struct efi_device_path *device_path_instance)
+{
+       EFI_ENTRY("%p, %p", device_path, device_path_instance);
+       return EFI_EXIT(NULL);
+}
+
+static struct efi_device_path * EFIAPI get_next_device_path_instance(
+       struct efi_device_path **device_path_instance,
+       efi_uintn_t *device_path_instance_size)
+{
+       EFI_ENTRY("%p, %p", device_path_instance, device_path_instance_size);
+       return EFI_EXIT(NULL);
+}
+
+static bool EFIAPI is_device_path_multi_instance(
+       const struct efi_device_path *device_path)
+{
+       EFI_ENTRY("%p", device_path);
+       return EFI_EXIT(false);
+}
+
+static struct efi_device_path * EFIAPI create_device_node(
+       uint8_t node_type, uint8_t node_sub_type, uint16_t node_length)
+{
+       EFI_ENTRY("%u, %u, %u", node_type, node_sub_type, node_length);
+       return EFI_EXIT(NULL);
+}
+
+const struct efi_device_path_utilities_protocol efi_device_path_utilities = {
+       .get_device_path_size = get_device_path_size,
+       .duplicate_device_path = duplicate_device_path,
+       .append_device_path = append_device_path,
+       .append_device_node = append_device_node,
+       .append_device_path_instance = append_device_path_instance,
+       .get_next_device_path_instance = get_next_device_path_instance,
+       .is_device_path_multi_instance = is_device_path_multi_instance,
+       .create_device_node = create_device_node,
+};