From: Rob Clark <robdclark@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC 10/10] efi_loader: support load_image() from a file-path
Date: Thu, 27 Jul 2017 17:38:07 -0400 [thread overview]
Message-ID: <20170727213807.7523-11-robdclark@gmail.com> (raw)
In-Reply-To: <20170727213807.7523-1-robdclark@gmail.com>
Previously we only supported the case when the EFI application loaded
the image into memory for us. But fallback.efi does not do this.
Signed-off-by: Rob Clark <robdclark@gmail.com>
---
lib/efi_loader/efi_boottime.c | 91 ++++++++++++++++++++++++++++++++++++-------
1 file changed, 76 insertions(+), 15 deletions(-)
diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
index aa342670c2..326a428a57 100644
--- a/lib/efi_loader/efi_boottime.c
+++ b/lib/efi_loader/efi_boottime.c
@@ -749,6 +749,45 @@ void efi_setup_loaded_image(struct efi_loaded_image *info, struct efi_object *ob
list_add_tail(&obj->link, &efi_obj_list);
}
+static efi_status_t load_image_from_path(struct efi_device_path *file_path,
+ void **buffer)
+{
+ struct efi_file_info *info = NULL;
+ struct efi_file_handle *f;
+ static efi_status_t ret;
+ uint64_t bs;
+
+ f = efi_file_from_path(file_path);
+ if (!f)
+ return EFI_DEVICE_ERROR;
+
+ bs = sizeof(info);
+ EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid, &bs, info));
+ if (ret == EFI_BUFFER_TOO_SMALL) {
+ info = malloc(bs);
+ EFI_CALL(ret = f->getinfo(f, (efi_guid_t *)&efi_file_info_guid, &bs, info));
+ }
+ if (ret != EFI_SUCCESS)
+ goto error;
+
+ ret = efi_allocate_pool(EFI_LOADER_DATA, info->file_size, buffer);
+ if (ret)
+ goto error;
+
+ EFI_CALL(ret = f->read(f, &info->file_size, *buffer));
+
+error:
+ free(info);
+ EFI_CALL(f->close(f));
+
+ if (ret != EFI_SUCCESS) {
+ efi_free_pool(*buffer);
+ *buffer = NULL;
+ }
+
+ return ret;
+}
+
static efi_status_t EFIAPI efi_load_image(bool boot_policy,
efi_handle_t parent_image,
struct efi_device_path *file_path,
@@ -756,25 +795,48 @@ static efi_status_t EFIAPI efi_load_image(bool boot_policy,
unsigned long source_size,
efi_handle_t *image_handle)
{
- static struct efi_object loaded_image_info_obj = {
- .protocols = {
- {
- .guid = &efi_guid_loaded_image,
- },
- },
- };
struct efi_loaded_image *info;
struct efi_object *obj;
EFI_ENTRY("%d, %p, %p, %p, %ld, %p", boot_policy, parent_image,
file_path, source_buffer, source_size, image_handle);
- info = malloc(sizeof(*info));
- loaded_image_info_obj.protocols[0].protocol_interface = info;
- obj = malloc(sizeof(loaded_image_info_obj));
- memset(info, 0, sizeof(*info));
- memcpy(obj, &loaded_image_info_obj, sizeof(loaded_image_info_obj));
- obj->handle = info;
- info->file_path = file_path;
+
+ info = calloc(1, sizeof(*info));
+ obj = calloc(1, sizeof(*obj));
+
+ if (!source_buffer) {
+ struct efi_device_path *dp, *fp, *p;
+ efi_status_t ret;
+
+ ret = load_image_from_path(file_path, &source_buffer);
+ if (ret != EFI_SUCCESS) {
+ free(info);
+ free(obj);
+ return EFI_EXIT(ret);
+ }
+
+ /*
+ * split file_path which contains both the device and
+ * file parts:
+ */
+ dp = efi_dp_dup(file_path);
+ p = dp;
+ while (!EFI_DP_TYPE(p, MEDIA_DEVICE, FILE_PATH))
+ p = efi_dp_next(p);
+ fp = efi_dp_dup(p);
+
+ p->type = DEVICE_PATH_TYPE_END;
+ p->sub_type = DEVICE_PATH_SUB_TYPE_END;
+ p->length = sizeof(*p);
+
+ efi_setup_loaded_image(info, obj, dp, fp);
+ } else {
+ /* In this case, file_path is the "device" path, ie.
+ * something like a HARDWARE_DEVICE:MEMORY_MAPPED
+ */
+ efi_setup_loaded_image(info, obj, file_path, NULL);
+ }
+
info->reserved = efi_load_pe(source_buffer, info);
if (!info->reserved) {
free(info);
@@ -783,7 +845,6 @@ static efi_status_t EFIAPI efi_load_image(bool boot_policy,
}
*image_handle = info;
- list_add_tail(&obj->link, &efi_obj_list);
return EFI_EXIT(EFI_SUCCESS);
}
--
2.13.0
next prev parent reply other threads:[~2017-07-27 21:38 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-27 21:37 [U-Boot] [RFC 00/10] efi_loader: bunch of EFI work for distro boot Rob Clark
2017-07-27 21:37 ` [U-Boot] [RFC 01/10] efi_loader: add back optional efi_handler::open() Rob Clark
2017-07-27 21:37 ` [U-Boot] [RFC 02/10] efi: fill in disk signature bits of hard drive device path Rob Clark
2017-07-27 21:38 ` [U-Boot] [RFC 03/10] efi: add some more device path structures Rob Clark
2017-07-27 21:38 ` [U-Boot] [RFC 04/10] fs: add fs_readdir() Rob Clark
2017-07-27 21:38 ` [U-Boot] [RFC 05/10] efi_loader: add device-path utils Rob Clark
2017-07-27 21:38 ` [U-Boot] [RFC 06/10] efi_loader: use proper device-paths for partitions Rob Clark
2017-07-27 21:38 ` [U-Boot] [RFC 07/10] efi_loader: use proper device-paths for net Rob Clark
2017-07-27 21:38 ` [U-Boot] [RFC 08/10] efi_loader: refactor boot device and loaded_image handling Rob Clark
2017-07-27 21:38 ` [U-Boot] [RFC 09/10] efi_loader: add file/filesys support Rob Clark
2017-07-27 21:38 ` Rob Clark [this message]
2017-07-27 22:50 ` [U-Boot] [RFC 10/10] efi_loader: support load_image() from a file-path Rob Clark
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170727213807.7523-11-robdclark@gmail.com \
--to=robdclark@gmail.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox