file.c (3b02a051d25d9600e9d403ad3043aed7de00160e) file.c (464fb126d98a047953040cc9c754801dbda54e5d)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Helper functions used by the EFI stub on multiple
4 * architectures. This should be #included by the EFI stub
5 * implementation files.
6 *
7 * Copyright 2011 Intel Corporation; author Matt Fleming
8 */

--- 15 unchanged lines hidden (view full) ---

24 *
25 * If you experience issues with initrd images being corrupt it's worth
26 * trying efi=nochunk, but chunking is enabled by default on x86 because
27 * there are far more machines that require the workaround than those that
28 * break with it enabled.
29 */
30#define EFI_READ_CHUNK_SIZE SZ_1M
31
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Helper functions used by the EFI stub on multiple
4 * architectures. This should be #included by the EFI stub
5 * implementation files.
6 *
7 * Copyright 2011 Intel Corporation; author Matt Fleming
8 */

--- 15 unchanged lines hidden (view full) ---

24 *
25 * If you experience issues with initrd images being corrupt it's worth
26 * trying efi=nochunk, but chunking is enabled by default on x86 because
27 * there are far more machines that require the workaround than those that
28 * break with it enabled.
29 */
30#define EFI_READ_CHUNK_SIZE SZ_1M
31
32struct finfo {
33 efi_file_info_t info;
34 efi_char16_t filename[MAX_FILENAME_SIZE];
35};
36
32static efi_status_t efi_open_file(efi_file_protocol_t *volume,
37static efi_status_t efi_open_file(efi_file_protocol_t *volume,
33 efi_char16_t *filename_16,
38 struct finfo *fi,
34 efi_file_protocol_t **handle,
35 unsigned long *file_size)
36{
39 efi_file_protocol_t **handle,
40 unsigned long *file_size)
41{
37 struct {
38 efi_file_info_t info;
39 efi_char16_t filename[MAX_FILENAME_SIZE];
40 } finfo;
41 efi_guid_t info_guid = EFI_FILE_INFO_ID;
42 efi_file_protocol_t *fh;
43 unsigned long info_sz;
44 efi_status_t status;
45
42 efi_guid_t info_guid = EFI_FILE_INFO_ID;
43 efi_file_protocol_t *fh;
44 unsigned long info_sz;
45 efi_status_t status;
46
46 status = volume->open(volume, &fh, filename_16, EFI_FILE_MODE_READ, 0);
47 status = volume->open(volume, &fh, fi->filename, EFI_FILE_MODE_READ, 0);
47 if (status != EFI_SUCCESS) {
48 pr_efi_err("Failed to open file: ");
48 if (status != EFI_SUCCESS) {
49 pr_efi_err("Failed to open file: ");
49 efi_char16_printk(filename_16);
50 efi_char16_printk(fi->filename);
50 efi_printk("\n");
51 return status;
52 }
53
51 efi_printk("\n");
52 return status;
53 }
54
54 info_sz = sizeof(finfo);
55 status = fh->get_info(fh, &info_guid, &info_sz, &finfo);
55 info_sz = sizeof(struct finfo);
56 status = fh->get_info(fh, &info_guid, &info_sz, fi);
56 if (status != EFI_SUCCESS) {
57 pr_efi_err("Failed to get file info\n");
58 fh->close(fh);
59 return status;
60 }
61
62 *handle = fh;
57 if (status != EFI_SUCCESS) {
58 pr_efi_err("Failed to get file info\n");
59 fh->close(fh);
60 return status;
61 }
62
63 *handle = fh;
63 *file_size = finfo.info.file_size;
64 *file_size = fi->info.file_size;
64 return EFI_SUCCESS;
65}
66
67static efi_status_t efi_open_volume(efi_loaded_image_t *image,
68 efi_file_protocol_t **fh)
69{
70 efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID;
71 efi_simple_file_system_protocol_t *io;

--- 69 unchanged lines hidden (view full) ---

141 if (!load_addr || !load_size)
142 return EFI_INVALID_PARAMETER;
143
144 if (IS_ENABLED(CONFIG_X86) && !nochunk())
145 efi_chunk_size = EFI_READ_CHUNK_SIZE;
146
147 alloc_addr = alloc_size = 0;
148 do {
65 return EFI_SUCCESS;
66}
67
68static efi_status_t efi_open_volume(efi_loaded_image_t *image,
69 efi_file_protocol_t **fh)
70{
71 efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID;
72 efi_simple_file_system_protocol_t *io;

--- 69 unchanged lines hidden (view full) ---

142 if (!load_addr || !load_size)
143 return EFI_INVALID_PARAMETER;
144
145 if (IS_ENABLED(CONFIG_X86) && !nochunk())
146 efi_chunk_size = EFI_READ_CHUNK_SIZE;
147
148 alloc_addr = alloc_size = 0;
149 do {
149 efi_char16_t filename[MAX_FILENAME_SIZE];
150 struct finfo fi;
150 unsigned long size;
151 void *addr;
152
153 offset = find_file_option(cmdline, cmdline_len,
154 optstr, optstr_size,
151 unsigned long size;
152 void *addr;
153
154 offset = find_file_option(cmdline, cmdline_len,
155 optstr, optstr_size,
155 filename, ARRAY_SIZE(filename));
156 fi.filename, ARRAY_SIZE(fi.filename));
156
157 if (!offset)
158 break;
159
160 cmdline += offset;
161 cmdline_len -= offset;
162
163 if (!volume) {
164 status = efi_open_volume(image, &volume);
165 if (status != EFI_SUCCESS)
166 return status;
167 }
168
157
158 if (!offset)
159 break;
160
161 cmdline += offset;
162 cmdline_len -= offset;
163
164 if (!volume) {
165 status = efi_open_volume(image, &volume);
166 if (status != EFI_SUCCESS)
167 return status;
168 }
169
169 status = efi_open_file(volume, filename, &file, &size);
170 status = efi_open_file(volume, &fi, &file, &size);
170 if (status != EFI_SUCCESS)
171 goto err_close_volume;
172
173 /*
174 * Check whether the existing allocation can contain the next
175 * file. This condition will also trigger naturally during the
176 * first (and typically only) iteration of the loop, given that
177 * alloc_size == 0 in that case.

--- 81 unchanged lines hidden ---
171 if (status != EFI_SUCCESS)
172 goto err_close_volume;
173
174 /*
175 * Check whether the existing allocation can contain the next
176 * file. This condition will also trigger naturally during the
177 * first (and typically only) iteration of the loop, given that
178 * alloc_size == 0 in that case.

--- 81 unchanged lines hidden ---