summaryrefslogtreecommitdiff
path: root/drivers/firmware/efi/libstub/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/firmware/efi/libstub/file.c')
-rw-r--r--drivers/firmware/efi/libstub/file.c122
1 files changed, 80 insertions, 42 deletions
diff --git a/drivers/firmware/efi/libstub/file.c b/drivers/firmware/efi/libstub/file.c
index f756c61396e9..d6a025df07dc 100644
--- a/drivers/firmware/efi/libstub/file.c
+++ b/drivers/firmware/efi/libstub/file.c
@@ -43,18 +43,26 @@ static efi_status_t efi_open_file(efi_file_protocol_t *volume,
efi_file_protocol_t *fh;
unsigned long info_sz;
efi_status_t status;
+ efi_char16_t *c;
- status = volume->open(volume, &fh, fi->filename, EFI_FILE_MODE_READ, 0);
+ /* Replace UNIX dir separators with EFI standard ones */
+ for (c = fi->filename; *c != L'\0'; c++) {
+ if (*c == L'/')
+ *c = L'\\';
+ }
+
+ status = efi_call_proto(volume, open, &fh, fi->filename,
+ EFI_FILE_MODE_READ, 0);
if (status != EFI_SUCCESS) {
efi_err("Failed to open file: %ls\n", fi->filename);
return status;
}
info_sz = sizeof(struct finfo);
- status = fh->get_info(fh, &info_guid, &info_sz, fi);
+ status = efi_call_proto(fh, get_info, &info_guid, &info_sz, fi);
if (status != EFI_SUCCESS) {
efi_err("Failed to get file info\n");
- fh->close(fh);
+ efi_call_proto(fh, close);
return status;
}
@@ -66,36 +74,18 @@ static efi_status_t efi_open_file(efi_file_protocol_t *volume,
static efi_status_t efi_open_volume(efi_loaded_image_t *image,
efi_file_protocol_t **fh)
{
- struct efi_vendor_dev_path *dp = image->file_path;
- efi_guid_t li_proto = LOADED_IMAGE_PROTOCOL_GUID;
efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID;
efi_simple_file_system_protocol_t *io;
efi_status_t status;
- // If we are using EFI zboot, we should look for the file system
- // protocol on the parent image's handle instead
- if (IS_ENABLED(CONFIG_EFI_ZBOOT) &&
- image->parent_handle != NULL &&
- dp != NULL &&
- dp->header.type == EFI_DEV_MEDIA &&
- dp->header.sub_type == EFI_DEV_MEDIA_VENDOR &&
- !efi_guidcmp(dp->vendorguid, LINUX_EFI_ZBOOT_MEDIA_GUID)) {
- status = efi_bs_call(handle_protocol, image->parent_handle,
- &li_proto, (void *)&image);
- if (status != EFI_SUCCESS) {
- efi_err("Failed to locate parent image handle\n");
- return status;
- }
- }
-
- status = efi_bs_call(handle_protocol, image->device_handle, &fs_proto,
- (void **)&io);
+ status = efi_bs_call(handle_protocol, efi_table_attr(image, device_handle),
+ &fs_proto, (void **)&io);
if (status != EFI_SUCCESS) {
efi_err("Failed to handle fs_proto\n");
return status;
}
- status = io->open_volume(io, fh);
+ status = efi_call_proto(io, open_volume, fh);
if (status != EFI_SUCCESS)
efi_err("Failed to open volume\n");
@@ -129,16 +119,62 @@ static int find_file_option(const efi_char16_t *cmdline, int cmdline_len,
if (c == L'\0' || c == L'\n' || c == L' ')
break;
- else if (c == L'/')
- /* Replace UNIX dir separators with EFI standard ones */
- *result++ = L'\\';
- else
- *result++ = c;
+ *result++ = c;
}
*result = L'\0';
return i;
}
+static efi_status_t efi_open_device_path(efi_file_protocol_t **volume,
+ struct finfo *fi)
+{
+ efi_guid_t text_to_dp_guid = EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL_GUID;
+ static efi_device_path_from_text_protocol_t *text_to_dp = NULL;
+ efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID;
+ efi_device_path_protocol_t *initrd_dp;
+ efi_simple_file_system_protocol_t *io;
+ struct efi_file_path_dev_path *fpath;
+ efi_handle_t handle;
+ efi_status_t status;
+
+ /* See if the text to device path protocol exists */
+ if (!text_to_dp &&
+ efi_bs_call(locate_protocol, &text_to_dp_guid, NULL,
+ (void **)&text_to_dp) != EFI_SUCCESS)
+ return EFI_UNSUPPORTED;
+
+
+ /* Convert the filename wide string into a device path */
+ initrd_dp = efi_fn_call(text_to_dp, convert_text_to_device_path,
+ fi->filename);
+
+ /* Check whether the device path in question implements simple FS */
+ if ((efi_bs_call(locate_device_path, &fs_proto, &initrd_dp, &handle) ?:
+ efi_bs_call(handle_protocol, handle, &fs_proto, (void **)&io))
+ != EFI_SUCCESS)
+ return EFI_NOT_FOUND;
+
+ /* Check whether the remaining device path is a file device path */
+ if (initrd_dp->type != EFI_DEV_MEDIA ||
+ initrd_dp->sub_type != EFI_DEV_MEDIA_FILE) {
+ efi_warn("Unexpected device path node type: (%x, %x)\n",
+ initrd_dp->type, initrd_dp->sub_type);
+ return EFI_LOAD_ERROR;
+ }
+
+ /* Copy the remaining file path into the fi structure */
+ fpath = (struct efi_file_path_dev_path *)initrd_dp;
+ memcpy(fi->filename, fpath->filename,
+ min(sizeof(fi->filename),
+ fpath->header.length - sizeof(fpath->header)));
+
+ status = efi_call_proto(io, open_volume, volume);
+ if (status != EFI_SUCCESS)
+ efi_err("Failed to open volume\n");
+
+ return status;
+}
+
/*
* Check the cmdline for a LILO-style file= arguments.
*
@@ -153,8 +189,8 @@ efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
unsigned long *load_addr,
unsigned long *load_size)
{
- const efi_char16_t *cmdline = image->load_options;
- u32 cmdline_len = image->load_options_size;
+ const efi_char16_t *cmdline = efi_table_attr(image, load_options);
+ u32 cmdline_len = efi_table_attr(image, load_options_size);
unsigned long efi_chunk_size = ULONG_MAX;
efi_file_protocol_t *volume = NULL;
efi_file_protocol_t *file;
@@ -188,11 +224,13 @@ efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
cmdline += offset;
cmdline_len -= offset;
- if (!volume) {
+ status = efi_open_device_path(&volume, &fi);
+ if (status == EFI_UNSUPPORTED || status == EFI_NOT_FOUND)
+ /* try the volume that holds the kernel itself */
status = efi_open_volume(image, &volume);
- if (status != EFI_SUCCESS)
- return status;
- }
+
+ if (status != EFI_SUCCESS)
+ goto err_free_alloc;
status = efi_open_file(volume, &fi, &file, &size);
if (status != EFI_SUCCESS)
@@ -240,7 +278,7 @@ efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
while (size) {
unsigned long chunksize = min(size, efi_chunk_size);
- status = file->read(file, &chunksize, addr);
+ status = efi_call_proto(file, read, &chunksize, addr);
if (status != EFI_SUCCESS) {
efi_err("Failed to read file\n");
goto err_close_file;
@@ -248,24 +286,24 @@ efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
addr += chunksize;
size -= chunksize;
}
- file->close(file);
+ efi_call_proto(file, close);
+ efi_call_proto(volume, close);
} while (offset > 0);
*load_addr = alloc_addr;
*load_size = alloc_size;
- if (volume)
- volume->close(volume);
-
if (*load_size == 0)
return EFI_NOT_READY;
return EFI_SUCCESS;
err_close_file:
- file->close(file);
+ efi_call_proto(file, close);
err_close_volume:
- volume->close(volume);
+ efi_call_proto(volume, close);
+
+err_free_alloc:
efi_free(alloc_size, alloc_addr);
return status;
}