^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Helper functions used by the EFI stub on multiple
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * architectures. This should be #included by the EFI stub
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * implementation files.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright 2011 Intel Corporation; author Matt Fleming
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/efi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <asm/efi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "efistub.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define MAX_FILENAME_SIZE 256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * Some firmware implementations have problems reading files in one go.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * A read chunk size of 1MB seems to work for most platforms.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * Unfortunately, reading files in chunks triggers *other* bugs on some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * platforms, so we provide a way to disable this workaround, which can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * be done by passing "efi=nochunk" on the EFI boot stub command line.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * If you experience issues with initrd images being corrupt it's worth
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * trying efi=nochunk, but chunking is enabled by default on x86 because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * there are far more machines that require the workaround than those that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * break with it enabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define EFI_READ_CHUNK_SIZE SZ_1M
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct finfo {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) efi_file_info_t info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) efi_char16_t filename[MAX_FILENAME_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static efi_status_t efi_open_file(efi_file_protocol_t *volume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct finfo *fi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) efi_file_protocol_t **handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) unsigned long *file_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) efi_guid_t info_guid = EFI_FILE_INFO_ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) efi_file_protocol_t *fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) unsigned long info_sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) efi_status_t status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) status = volume->open(volume, &fh, fi->filename, EFI_FILE_MODE_READ, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if (status != EFI_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) efi_err("Failed to open file: %ls\n", fi->filename);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) info_sz = sizeof(struct finfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) status = fh->get_info(fh, &info_guid, &info_sz, fi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (status != EFI_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) efi_err("Failed to get file info\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) fh->close(fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) *handle = fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) *file_size = fi->info.file_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return EFI_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static efi_status_t efi_open_volume(efi_loaded_image_t *image,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) efi_file_protocol_t **fh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) efi_simple_file_system_protocol_t *io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) efi_status_t status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) status = efi_bs_call(handle_protocol, image->device_handle, &fs_proto,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) (void **)&io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if (status != EFI_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) efi_err("Failed to handle fs_proto\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) status = io->open_volume(io, fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if (status != EFI_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) efi_err("Failed to open volume\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) static int find_file_option(const efi_char16_t *cmdline, int cmdline_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) const efi_char16_t *prefix, int prefix_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) efi_char16_t *result, int result_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) int prefix_len = prefix_size / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) bool found = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) for (i = prefix_len; i < cmdline_len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (!memcmp(&cmdline[i - prefix_len], prefix, prefix_size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) found = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (!found)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /* Skip any leading slashes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) while (i < cmdline_len && (cmdline[i] == L'/' || cmdline[i] == L'\\'))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) while (--result_len > 0 && i < cmdline_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) efi_char16_t c = cmdline[i++];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (c == L'\0' || c == L'\n' || c == L' ')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) else if (c == L'/')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /* Replace UNIX dir separators with EFI standard ones */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) *result++ = L'\\';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) *result++ = c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) *result = L'\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * Check the cmdline for a LILO-style file= arguments.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * We only support loading a file from the same filesystem as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * the kernel image.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) const efi_char16_t *optstr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) int optstr_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) unsigned long soft_limit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) unsigned long hard_limit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) unsigned long *load_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) unsigned long *load_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) const efi_char16_t *cmdline = image->load_options;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) int cmdline_len = image->load_options_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) unsigned long efi_chunk_size = ULONG_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) efi_file_protocol_t *volume = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) efi_file_protocol_t *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) unsigned long alloc_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) unsigned long alloc_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) efi_status_t status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (!load_addr || !load_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) return EFI_INVALID_PARAMETER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) efi_apply_loadoptions_quirk((const void **)&cmdline, &cmdline_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) cmdline_len /= sizeof(*cmdline);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (IS_ENABLED(CONFIG_X86) && !efi_nochunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) efi_chunk_size = EFI_READ_CHUNK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) alloc_addr = alloc_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct finfo fi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) unsigned long size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) void *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) offset = find_file_option(cmdline, cmdline_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) optstr, optstr_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) fi.filename, ARRAY_SIZE(fi.filename));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (!offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) cmdline += offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) cmdline_len -= offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (!volume) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) status = efi_open_volume(image, &volume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) if (status != EFI_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) status = efi_open_file(volume, &fi, &file, &size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (status != EFI_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) goto err_close_volume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) * Check whether the existing allocation can contain the next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * file. This condition will also trigger naturally during the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * first (and typically only) iteration of the loop, given that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * alloc_size == 0 in that case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (round_up(alloc_size + size, EFI_ALLOC_ALIGN) >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) round_up(alloc_size, EFI_ALLOC_ALIGN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) unsigned long old_addr = alloc_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) status = EFI_OUT_OF_RESOURCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if (soft_limit < hard_limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) status = efi_allocate_pages(alloc_size + size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) &alloc_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) soft_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (status == EFI_OUT_OF_RESOURCES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) status = efi_allocate_pages(alloc_size + size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) &alloc_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) hard_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if (status != EFI_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) efi_err("Failed to allocate memory for files\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) goto err_close_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) if (old_addr != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * This is not the first time we've gone
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * around this loop, and so we are loading
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * multiple files that need to be concatenated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) * and returned in a single buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) memcpy((void *)alloc_addr, (void *)old_addr, alloc_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) efi_free(alloc_size, old_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) addr = (void *)alloc_addr + alloc_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) alloc_size += size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) while (size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) unsigned long chunksize = min(size, efi_chunk_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) status = file->read(file, &chunksize, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) if (status != EFI_SUCCESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) efi_err("Failed to read file\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) goto err_close_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) addr += chunksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) size -= chunksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) file->close(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) } while (offset > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) *load_addr = alloc_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) *load_size = alloc_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (volume)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) volume->close(volume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) return EFI_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) err_close_file:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) file->close(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) err_close_volume:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) volume->close(volume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) efi_free(alloc_size, alloc_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }