summaryrefslogtreecommitdiff
path: root/lib/efi_loader/efi_bootmgr.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2022-05-04 12:08:40 -0400
committerTom Rini <trini@konsulko.com>2022-05-04 12:08:40 -0400
commit1739a6db5403d187902dcebca548de0644c8078f (patch)
tree62e9a921915bbd79cec42f528b6c454e8488f862 /lib/efi_loader/efi_bootmgr.c
parentc3d451d5e6b7c2ea6d83397d5b6c986ff6ab4ee3 (diff)
parent2158b0da220ccbe969bc18668263141d9a89f13e (diff)
Merge tag 'efi-2022-07-rc2-2' of https://source.denx.de/u-boot/custodians/u-boot-efi
Pull request for efi-2022-07-rc2-2 * Test Unit test for 'bootmenu' command * UEFI Preparatory patches for implementing a UEFI boot options based menu
Diffstat (limited to 'lib/efi_loader/efi_bootmgr.c')
-rw-r--r--lib/efi_loader/efi_bootmgr.c51
1 files changed, 50 insertions, 1 deletions
diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c
index 52bea4d5411..631a25d76e9 100644
--- a/lib/efi_loader/efi_bootmgr.c
+++ b/lib/efi_loader/efi_bootmgr.c
@@ -11,6 +11,7 @@
#include <charset.h>
#include <log.h>
#include <malloc.h>
+#include <efi_default_filename.h>
#include <efi_loader.h>
#include <efi_variable.h>
#include <asm/unaligned.h>
@@ -31,6 +32,51 @@ static const struct efi_runtime_services *rs;
*/
/**
+ * expand_media_path() - expand a device path for default file name
+ * @device_path: device path to check against
+ *
+ * If @device_path is a media or disk partition which houses a file
+ * system, this function returns a full device path which contains
+ * an architecture-specific default file name for removable media.
+ *
+ * Return: a newly allocated device path
+ */
+static
+struct efi_device_path *expand_media_path(struct efi_device_path *device_path)
+{
+ struct efi_device_path *dp, *full_path;
+ efi_handle_t handle;
+ efi_status_t ret;
+
+ if (!device_path)
+ return NULL;
+
+ /*
+ * If device_path is a (removable) media or partition which provides
+ * simple file system protocol, append a default file name to support
+ * booting from removable media.
+ */
+ dp = device_path;
+ ret = EFI_CALL(efi_locate_device_path(
+ &efi_simple_file_system_protocol_guid,
+ &dp, &handle));
+ if (ret == EFI_SUCCESS) {
+ if (dp->type == DEVICE_PATH_TYPE_END) {
+ dp = efi_dp_from_file(NULL, 0,
+ "/EFI/BOOT/" BOOTEFI_NAME);
+ full_path = efi_dp_append(device_path, dp);
+ efi_free_pool(dp);
+ } else {
+ full_path = efi_dp_dup(device_path);
+ }
+ } else {
+ full_path = efi_dp_dup(device_path);
+ }
+
+ return full_path;
+}
+
+/**
* try_load_entry() - try to load image for boot option
*
* Attempt to load load-option number 'n', returning device_path and file_path
@@ -64,13 +110,16 @@ static efi_status_t try_load_entry(u16 n, efi_handle_t *handle,
}
if (lo.attributes & LOAD_OPTION_ACTIVE) {
+ struct efi_device_path *file_path;
u32 attributes;
log_debug("trying to load \"%ls\" from %pD\n", lo.label,
lo.file_path);
- ret = EFI_CALL(efi_load_image(true, efi_root, lo.file_path,
+ file_path = expand_media_path(lo.file_path);
+ ret = EFI_CALL(efi_load_image(true, efi_root, file_path,
NULL, 0, handle));
+ efi_free_pool(file_path);
if (ret != EFI_SUCCESS) {
log_warning("Loading %ls '%ls' failed\n",
varname, lo.label);