summaryrefslogtreecommitdiff
path: root/lib/efi_loader/efi_load_initrd.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2020-10-06 08:36:38 -0400
committerTom Rini <trini@konsulko.com>2020-10-06 08:36:38 -0400
commit5dcf7cc590b348f1e730ec38242df64c179f10a8 (patch)
tree7ba5948897352b913338be6cf27061570e96a128 /lib/efi_loader/efi_load_initrd.c
parent987ab49366f3fcd25039eab431bf099b587b3265 (diff)
parent4cbb2930bd8c67f40f848528941930cf4c2a1841 (diff)
Merge tag 'efi-2021-01-rc1' of https://gitlab.denx.de/u-boot/custodians/u-boot-efi
Pull request for UEFI sub-system for efi-2021-01-rc1 The following bugs in the UEFI system are resolved: * illegal free in EFI_LOAD_FILE2_PROTOCOL implementation * incorrect documentation of EFI_LOAD_FILE2_PROTOCOL implementation * output of CRC32 as decimal instead hexadecimal in unit test * use EfiReservedMemoryType for no-map reserved memory * avoid unnecessary resets in UEFI unit tests * call EFI bootmgr even without having /EFI/boot
Diffstat (limited to 'lib/efi_loader/efi_load_initrd.c')
-rw-r--r--lib/efi_loader/efi_load_initrd.c59
1 files changed, 32 insertions, 27 deletions
diff --git a/lib/efi_loader/efi_load_initrd.c b/lib/efi_loader/efi_load_initrd.c
index 574a83d7e30..d517d686c33 100644
--- a/lib/efi_loader/efi_load_initrd.c
+++ b/lib/efi_loader/efi_load_initrd.c
@@ -47,9 +47,9 @@ static const struct efi_initrd_dp dp = {
/**
* get_file_size() - retrieve the size of initramfs, set efi status on error
*
- * @dev: device to read from. i.e "mmc"
- * @part: device partition. i.e "0:1"
- * @file: name fo file
+ * @dev: device to read from, e.g. "mmc"
+ * @part: device partition, e.g. "0:1"
+ * @file: name of file
* @status: EFI exit code in case of failure
*
* Return: size of file
@@ -78,15 +78,16 @@ out:
}
/**
- * load_file2() - get information about random number generation
+ * efi_load_file2initrd() - load initial RAM disk
+ *
+ * This function implements the LoadFile service of the EFI_LOAD_FILE2_PROTOCOL
+ * in order to load an initial RAM disk requested by the Linux kernel stub.
*
- * This function implement the LoadFile2() service in order to load an initram
- * disk requested by the Linux kernel stub.
* See the UEFI spec for details.
*
- * @this: loadfile2 protocol instance
- * @file_path: relative path of the file. "" in this case
- * @boot_policy: must be false for Loadfile2
+ * @this: EFI_LOAD_FILE2_PROTOCOL instance
+ * @file_path: media device path of the file, "" in this case
+ * @boot_policy: must be false
* @buffer_size: size of allocated buffer
* @buffer: buffer to load the file
*
@@ -97,19 +98,20 @@ efi_load_file2_initrd(struct efi_load_file_protocol *this,
struct efi_device_path *file_path, bool boot_policy,
efi_uintn_t *buffer_size, void *buffer)
{
- const char *filespec = CONFIG_EFI_INITRD_FILESPEC;
+ char *filespec;
efi_status_t status = EFI_NOT_FOUND;
loff_t file_sz = 0, read_sz = 0;
char *dev, *part, *file;
- char *s;
+ char *pos;
int ret;
EFI_ENTRY("%p, %p, %d, %p, %p", this, file_path, boot_policy,
buffer_size, buffer);
- s = strdup(filespec);
- if (!s)
+ filespec = strdup(CONFIG_EFI_INITRD_FILESPEC);
+ if (!filespec)
goto out;
+ pos = filespec;
if (!this || this != &efi_lf2_protocol ||
!buffer_size) {
@@ -128,14 +130,20 @@ efi_load_file2_initrd(struct efi_load_file_protocol *this,
goto out;
}
- /* expect something like 'mmc 0:1 initrd.cpio.gz' */
- dev = strsep(&s, " ");
+ /*
+ * expect a string with three space separated parts:
+ *
+ * * a block device type, e.g. "mmc"
+ * * a device and partition identifier, e.g. "0:1"
+ * * a file path on the block device, e.g. "/boot/initrd.cpio.gz"
+ */
+ dev = strsep(&pos, " ");
if (!dev)
goto out;
- part = strsep(&s, " ");
+ part = strsep(&pos, " ");
if (!part)
goto out;
- file = strsep(&s, " ");
+ file = strsep(&pos, " ");
if (!file)
goto out;
@@ -163,28 +171,25 @@ efi_load_file2_initrd(struct efi_load_file_protocol *this,
}
out:
- free(s);
+ free(filespec);
return EFI_EXIT(status);
}
/**
- * efi_initrd_register() - Register a handle and loadfile2 protocol
+ * efi_initrd_register() - create handle for loading initial RAM disk
*
- * This function creates a new handle and installs a linux specific GUID
- * to handle initram disk loading during boot.
- * See the UEFI spec for details.
+ * This function creates a new handle and installs a Linux specific vendor
+ * device path and an EFI_LOAD_FILE_2_PROTOCOL. Linux uses the device path
+ * to identify the handle and then calls the LoadFile service of the
+ * EFI_LOAD_FILE_2_PROTOCOL to read the initial RAM disk.
*
- * Return: status code
+ * Return: status code
*/
efi_status_t efi_initrd_register(void)
{
efi_handle_t efi_initrd_handle = NULL;
efi_status_t ret;
- /*
- * Set up the handle with the EFI_LOAD_FILE2_PROTOCOL which Linux may
- * use to load the initial ramdisk.
- */
ret = EFI_CALL(efi_install_multiple_protocol_interfaces
(&efi_initrd_handle,
/* initramfs */