wok view linux/stuff/linux-efi.u @ rev 20334

Do not use efi shell (again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Jun 02 16:13:06 2018 +0200 (16 months ago)
parents 99a7a1e955d4
children 5546d3d1350b
line source
1 --- linux-3.16.53/drivers/firmware/efi/efi-stub-helper.c
2 +++ linux-3.16.53/drivers/firmware/efi/efi-stub-helper.c
3 @@ -321,6 +321,77 @@
6 /*
7 + *
8 + */
9 +static efi_status_t get_file_size(efi_system_table_t *sys_table_arg,
10 + efi_loaded_image_t *image,
11 + efi_char16_t *filename_16,
12 + struct file_info *file)
13 +{
14 + efi_status_t status;
15 + efi_file_handle_t *fh = NULL;
16 +#ifdef CONFIG_X86_64
17 + efi_char16_t *p, c;
18 +#endif
19 +
20 + /* Only open the volume once. */
21 + if (!fh) {
22 + status = efi_open_volume(sys_table_arg, image,
23 + (void **)&fh);
24 + if (status != EFI_SUCCESS)
25 + return status;
26 + }
27 +#ifdef CONFIG_X86_64
28 + for (p = filename_16; *p != '\0'; p++);
29 + c = p[-2];
30 + while (1) {
31 +#endif
32 + status = efi_file_size(sys_table_arg, fh, filename_16,
33 + (void **)&file->handle, &file->size);
34 +#ifdef CONFIG_X86_64
35 + if (status != EFI_SUCCESS && p[-2] != '\0') {
36 + p[-2] = '\0';
37 + continue;
38 + }
39 + break;
40 + }
41 + p[-2] = c;
42 +#endif
43 + return status;
44 +}
45 +
46 +/*
47 + *
48 + */
49 +static efi_status_t read_efi_file(efi_system_table_t *sys_table_arg,
50 + struct file_info *file,
51 + unsigned long addr,
52 + unsigned long size)
53 +{
54 + efi_status_t status;
55 +
56 + while (size) {
57 + unsigned long chunksize;
58 + if (size > EFI_READ_CHUNK_SIZE)
59 + chunksize = EFI_READ_CHUNK_SIZE;
60 + else
61 + chunksize = size;
62 +
63 + status = efi_file_read(file->handle,
64 + &chunksize,
65 + (void *)addr);
66 + if (status != EFI_SUCCESS) {
67 + pr_efi_err(sys_table_arg, "Failed to read file\n");
68 + break;
69 + }
70 + addr += chunksize;
71 + size -= chunksize;
72 + }
73 + efi_file_close(file->handle);
74 + return status;
75 +}
76 +
77 +/*
78 * Check the cmdline for a LILO-style file= arguments.
79 *
80 * We only support loading a file from the same filesystem as
81 @@ -414,18 +485,14 @@
82 }
83 }
85 +#ifdef CONFIG_X86_64
86 + *p++ = '6';
87 + *p++ = '4';
88 +#endif
89 *p = '\0';
91 - /* Only open the volume once. */
92 - if (!i) {
93 - status = efi_open_volume(sys_table_arg, image,
94 - (void **)&fh);
95 - if (status != EFI_SUCCESS)
96 - goto free_files;
97 - }
98 -
99 - status = efi_file_size(sys_table_arg, fh, filename_16,
100 - (void **)&file->handle, &file->size);
101 + status = get_file_size(sys_table_arg,image,filename_16,file);
102 +
103 if (status != EFI_SUCCESS)
104 goto close_handles;
106 @@ -456,28 +523,11 @@
108 addr = file_addr;
109 for (j = 0; j < nr_files; j++) {
110 - unsigned long size;
111 -
112 - size = files[j].size;
113 - while (size) {
114 - unsigned long chunksize;
115 - if (size > EFI_READ_CHUNK_SIZE)
116 - chunksize = EFI_READ_CHUNK_SIZE;
117 - else
118 - chunksize = size;
119 -
120 - status = efi_file_read(files[j].handle,
121 - &chunksize,
122 - (void *)addr);
123 - if (status != EFI_SUCCESS) {
124 - pr_efi_err(sys_table_arg, "Failed to read file\n");
125 - goto free_file_total;
126 - }
127 - addr += chunksize;
128 - size -= chunksize;
129 - }
130 -
131 - efi_file_close(files[j].handle);
132 + status = read_efi_file(sys_table_arg, &files[j], addr, files[j].size);
133 + if (status != EFI_SUCCESS)
134 + goto free_file_total;
135 + addr += files[j].size + 3;
136 + addr &= 0xFFFFFFFCUL;
137 }
139 }
140 @@ -649,6 +699,30 @@
141 }
143 if (!options_chars) {
144 + /* No command line options, look for linux.cmdline */
145 +#ifdef CONFIG_X86_64
146 +#define cmdline_name L"EFI\\BOOT\\linux.cmdline64"
147 +#else
148 +#define cmdline_name L"EFI\\BOOT\\linux.cmdline"
149 +#endif
150 + struct file_info file;
151 + efi_char16_t filename_16[sizeof(cmdline_name)];
152 +
153 + memcpy((void *)filename_16, (void *)cmdline_name, sizeof(cmdline_name));
154 + if (get_file_size(sys_table_arg, image, filename_16, &file) != EFI_SUCCESS)
155 + goto no_cmdline_file;
156 +
157 + options_bytes = file.size+1;
158 + if (efi_low_alloc(sys_table_arg, options_bytes, 0, &cmdline_addr) != EFI_SUCCESS)
159 + goto no_cmdline_file;
160 +
161 + *((u8 *)cmdline_addr + file.size) = '\0';
162 + if (read_efi_file(sys_table_arg, &file, cmdline_addr, file.size) == EFI_SUCCESS)
163 + goto return_cmdline;
164 + }
165 + no_cmdline_file:
166 +
167 + if (!options_chars) {
168 /* No command line options, so return empty string*/
169 options = &zero;
170 }
171 @@ -665,6 +739,7 @@
172 s1 = efi_utf16_to_utf8(s1, s2, options_chars);
173 *s1 = '\0';
175 +return_cmdline:
176 *cmd_line_len = options_bytes;
177 return (char *)cmdline_addr;
178 }