wok-6.x view linux/stuff/linux-efi.u @ rev 20333

linux: read default cmdline from EFI\BOOT\linux.cmdline
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Jun 02 13:53:27 2018 +0200 (2018-06-02)
parents
children 02ed2446b480
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 @@ -433,8 +500,6 @@
107 }
109 if (file_size_total) {
110 - unsigned long addr;
111 -
112 /*
113 * Multiple files need to be at consecutive addresses in memory,
114 * so allocate enough memory for all the files. This is used
115 @@ -454,30 +519,10 @@
116 goto free_file_total;
117 }
119 - addr = file_addr;
120 for (j = 0; j < nr_files; j++) {
121 - unsigned long size;
122 -
123 - size = files[j].size;
124 - while (size) {
125 - unsigned long chunksize;
126 - if (size > EFI_READ_CHUNK_SIZE)
127 - chunksize = EFI_READ_CHUNK_SIZE;
128 - else
129 - chunksize = size;
130 -
131 - status = efi_file_read(files[j].handle,
132 - &chunksize,
133 - (void *)addr);
134 - if (status != EFI_SUCCESS) {
135 - pr_efi_err(sys_table_arg, "Failed to read file\n");
136 - goto free_file_total;
137 - }
138 - addr += chunksize;
139 - size -= chunksize;
140 - }
141 -
142 - efi_file_close(files[j].handle);
143 + status = read_efi_file(sys_table_arg, &files[j], file_addr, files[j].size);
144 + if (status != EFI_SUCCESS)
145 + goto free_file_total;
146 }
148 }
149 @@ -649,6 +694,30 @@
150 }
152 if (!options_chars) {
153 + /* No command line options, look for linux.cmdline */
154 +#ifdef CONFIG_X86_64
155 +#define cmdline_name L"EFI\\BOOT\\linux.cmdline64"
156 +#else
157 +#define cmdline_name L"EFI\\BOOT\\linux.cmdline"
158 +#endif
159 + struct file_info file;
160 + efi_char16_t filename_16[sizeof(cmdline_name)];
161 +
162 + memcpy((void *)filename_16, (void *)cmdline_name, sizeof(cmdline_name));
163 + if (get_file_size(sys_table_arg, image, filename_16, &file) != EFI_SUCCESS)
164 + goto no_cmdline_file;
165 +
166 + options_bytes = file.size+1;
167 + if (efi_low_alloc(sys_table_arg, options_bytes, 0, &cmdline_addr) != EFI_SUCCESS)
168 + goto no_cmdline_file;
169 +
170 + *((u8 *)cmdline_addr + file.size) = '\0';
171 + if (read_efi_file(sys_table_arg, &file, cmdline_addr, file.size) == EFI_SUCCESS)
172 + goto return_cmdline;
173 + }
174 + no_cmdline_file:
175 +
176 + if (!options_chars) {
177 /* No command line options, so return empty string*/
178 options = &zero;
179 }
180 @@ -665,6 +734,7 @@
181 s1 = efi_utf16_to_utf8(s1, s2, options_chars);
182 *s1 = '\0';
184 +return_cmdline:
185 *cmd_line_len = options_bytes;
186 return (char *)cmdline_addr;
187 }