summaryrefslogtreecommitdiffstats
path: root/lib/efi_loader/efi_file.c
diff options
context:
space:
mode:
authorIlias Apalodimas <ilias.apalodimas@linaro.org>2021-03-17 21:54:59 +0200
committerHeinrich Schuchardt <xypron.glpk@gmx.de>2021-03-25 20:14:25 +0100
commit37c3ca5c0b1a449356279efdcaca346b3eae84fd (patch)
treef2148b2140f74289665143c3c995179b705dad05 /lib/efi_loader/efi_file.c
parent76e8acce12fe6e914fdab422c8af44956c1dac04 (diff)
downloadu-boot-37c3ca5c0b1a449356279efdcaca346b3eae84fd.tar.gz
u-boot-37c3ca5c0b1a449356279efdcaca346b3eae84fd.tar.xz
u-boot-37c3ca5c0b1a449356279efdcaca346b3eae84fd.zip
efi_loader: Add helper functions for EFI
A following patch introduces a different logic for loading initrd's based on the EFI_LOAD_FILE2_PROTOCOL. Since similar logic can be applied in the future for other system files (i.e DTBs), let's add some helper functions which will retrieve and parse file paths stored in EFI variables. Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Diffstat (limited to 'lib/efi_loader/efi_file.c')
-rw-r--r--lib/efi_loader/efi_file.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c
index 8ece8e71ee..204105e25a 100644
--- a/lib/efi_loader/efi_file.c
+++ b/lib/efi_loader/efi_file.c
@@ -409,6 +409,45 @@ static efi_status_t efi_get_file_size(struct file_handle *fh,
return EFI_SUCCESS;
}
+/**
+ * efi_file_size() - Get the size of a file using an EFI file handle
+ *
+ * @fh: EFI file handle
+ * @size: buffer to fill in the discovered size
+ *
+ * Return: size of the file
+ */
+efi_status_t efi_file_size(struct efi_file_handle *fh, efi_uintn_t *size)
+{
+ struct efi_file_info *info = NULL;
+ efi_uintn_t bs = 0;
+ efi_status_t ret;
+
+ *size = 0;
+ ret = EFI_CALL(fh->getinfo(fh, (efi_guid_t *)&efi_file_info_guid, &bs,
+ info));
+ if (ret != EFI_BUFFER_TOO_SMALL) {
+ ret = EFI_DEVICE_ERROR;
+ goto out;
+ }
+
+ info = malloc(bs);
+ if (!info) {
+ ret = EFI_OUT_OF_RESOURCES;
+ goto out;
+ }
+ ret = EFI_CALL(fh->getinfo(fh, (efi_guid_t *)&efi_file_info_guid, &bs,
+ info));
+ if (ret != EFI_SUCCESS)
+ goto out;
+
+ *size = info->file_size;
+
+out:
+ free(info);
+ return ret;
+}
+
static efi_status_t file_read(struct file_handle *fh, u64 *buffer_size,
void *buffer)
{