efi/libstub: Rewrite file I/O routine
The file I/O routine that is used to load initrd or dtb files from the EFI system partition suffers from a few issues: - it converts the u8[] command line back to a UTF-16 string, which is pointless since we only handle initrd or dtb arguments provided via the loaded image protocol anyway, which is where we got the UTF-16[] command line from in the first place when booting via the PE entry point, - in the far majority of cases, only a single initrd= option is present, but it optimizes for multiple options, by going over the command line twice, allocating heap buffers for dynamically sized arrays, etc. - the coding style is hard to follow, with few comments, and all logic including string parsing etc all combined in a single routine. Let's fix this by rewriting most of it, based on the idea that in the case of multiple initrds, we can just allocate a new, bigger buffer and copy over the data before freeing the old one. Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
This commit is contained in:
@@ -421,18 +421,14 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
|
||||
if (status != EFI_SUCCESS)
|
||||
goto fail2;
|
||||
|
||||
status = handle_cmdline_files(image,
|
||||
(char *)(unsigned long)hdr->cmd_line_ptr,
|
||||
"initrd=", hdr->initrd_addr_max,
|
||||
&ramdisk_addr, &ramdisk_size);
|
||||
status = efi_load_initrd(image, &ramdisk_addr, &ramdisk_size,
|
||||
hdr->initrd_addr_max);
|
||||
|
||||
if (status != EFI_SUCCESS &&
|
||||
hdr->xloadflags & XLF_CAN_BE_LOADED_ABOVE_4G) {
|
||||
efi_printk("Trying to load files to higher address\n");
|
||||
status = handle_cmdline_files(image,
|
||||
(char *)(unsigned long)hdr->cmd_line_ptr,
|
||||
"initrd=", -1UL,
|
||||
&ramdisk_addr, &ramdisk_size);
|
||||
status = efi_load_initrd(image, &ramdisk_addr, &ramdisk_size,
|
||||
ULONG_MAX);
|
||||
}
|
||||
|
||||
if (status != EFI_SUCCESS)
|
||||
|
Reference in New Issue
Block a user