diff options
author | Matt Fleming <matt.fleming@intel.com> | 2013-08-01 09:18:49 -0400 |
---|---|---|
committer | Matt Fleming <matt.fleming@intel.com> | 2014-03-04 16:23:35 -0500 |
commit | 993c30a04e205fb239c0875b25b43ddef0499845 (patch) | |
tree | 335934b76f4aa6b2ed1de688033a41d03e6ad62d /arch/x86/boot | |
parent | 86134a1b39fd056a7b6778608a5882f0ea1bc705 (diff) |
x86, tools: Consolidate #ifdef code
Instead of littering main() with #ifdef CONFIG_EFI_STUB, move the logic
into separate functions that do nothing if the config option isn't set.
This makes main() much easier to read.
Acked-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Diffstat (limited to 'arch/x86/boot')
-rw-r--r-- | arch/x86/boot/tools/build.c | 64 |
1 files changed, 42 insertions, 22 deletions
diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c index 8e15b22391fc..bf262077ec92 100644 --- a/arch/x86/boot/tools/build.c +++ b/arch/x86/boot/tools/build.c | |||
@@ -219,6 +219,45 @@ static void update_pecoff_text(unsigned int text_start, unsigned int file_sz) | |||
219 | update_pecoff_section_header(".text", text_start, text_sz); | 219 | update_pecoff_section_header(".text", text_start, text_sz); |
220 | } | 220 | } |
221 | 221 | ||
222 | static int reserve_pecoff_reloc_section(int c) | ||
223 | { | ||
224 | /* Reserve 0x20 bytes for .reloc section */ | ||
225 | memset(buf+c, 0, PECOFF_RELOC_RESERVE); | ||
226 | return PECOFF_RELOC_RESERVE; | ||
227 | } | ||
228 | |||
229 | static void efi_stub_defaults(void) | ||
230 | { | ||
231 | /* Defaults for old kernel */ | ||
232 | #ifdef CONFIG_X86_32 | ||
233 | efi_pe_entry = 0x10; | ||
234 | efi_stub_entry = 0x30; | ||
235 | #else | ||
236 | efi_pe_entry = 0x210; | ||
237 | efi_stub_entry = 0x230; | ||
238 | startup_64 = 0x200; | ||
239 | #endif | ||
240 | } | ||
241 | |||
242 | static void efi_stub_entry_update(void) | ||
243 | { | ||
244 | #ifdef CONFIG_X86_64 /* Yes, this is really how we defined it :( */ | ||
245 | efi_stub_entry -= 0x200; | ||
246 | #endif | ||
247 | put_unaligned_le32(efi_stub_entry, &buf[0x264]); | ||
248 | } | ||
249 | |||
250 | #else | ||
251 | |||
252 | static inline void update_pecoff_setup_and_reloc(unsigned int) {} | ||
253 | static inline void update_pecoff_text(unsigned int, unsigned int) {} | ||
254 | static inline void efi_stub_defaults(void) {} | ||
255 | static inline void efi_stup_entry_update(void) {} | ||
256 | |||
257 | static inline int reserve_pecoff_reloc_section(int c) | ||
258 | { | ||
259 | return 0; | ||
260 | } | ||
222 | #endif /* CONFIG_EFI_STUB */ | 261 | #endif /* CONFIG_EFI_STUB */ |
223 | 262 | ||
224 | 263 | ||
@@ -271,15 +310,7 @@ int main(int argc, char ** argv) | |||
271 | void *kernel; | 310 | void *kernel; |
272 | u32 crc = 0xffffffffUL; | 311 | u32 crc = 0xffffffffUL; |
273 | 312 | ||
274 | /* Defaults for old kernel */ | 313 | efi_stub_defaults(); |
275 | #ifdef CONFIG_X86_32 | ||
276 | efi_pe_entry = 0x10; | ||
277 | efi_stub_entry = 0x30; | ||
278 | #else | ||
279 | efi_pe_entry = 0x210; | ||
280 | efi_stub_entry = 0x230; | ||
281 | startup_64 = 0x200; | ||
282 | #endif | ||
283 | 314 | ||
284 | if (argc != 5) | 315 | if (argc != 5) |
285 | usage(); | 316 | usage(); |
@@ -302,11 +333,7 @@ int main(int argc, char ** argv) | |||
302 | die("Boot block hasn't got boot flag (0xAA55)"); | 333 | die("Boot block hasn't got boot flag (0xAA55)"); |
303 | fclose(file); | 334 | fclose(file); |
304 | 335 | ||
305 | #ifdef CONFIG_EFI_STUB | 336 | c += reserve_pecoff_reloc_section(c); |
306 | /* Reserve 0x20 bytes for .reloc section */ | ||
307 | memset(buf+c, 0, PECOFF_RELOC_RESERVE); | ||
308 | c += PECOFF_RELOC_RESERVE; | ||
309 | #endif | ||
310 | 337 | ||
311 | /* Pad unused space with zeros */ | 338 | /* Pad unused space with zeros */ |
312 | setup_sectors = (c + 511) / 512; | 339 | setup_sectors = (c + 511) / 512; |
@@ -315,9 +342,7 @@ int main(int argc, char ** argv) | |||
315 | i = setup_sectors*512; | 342 | i = setup_sectors*512; |
316 | memset(buf+c, 0, i-c); | 343 | memset(buf+c, 0, i-c); |
317 | 344 | ||
318 | #ifdef CONFIG_EFI_STUB | ||
319 | update_pecoff_setup_and_reloc(i); | 345 | update_pecoff_setup_and_reloc(i); |
320 | #endif | ||
321 | 346 | ||
322 | /* Set the default root device */ | 347 | /* Set the default root device */ |
323 | put_unaligned_le16(DEFAULT_ROOT_DEV, &buf[508]); | 348 | put_unaligned_le16(DEFAULT_ROOT_DEV, &buf[508]); |
@@ -342,14 +367,9 @@ int main(int argc, char ** argv) | |||
342 | buf[0x1f1] = setup_sectors-1; | 367 | buf[0x1f1] = setup_sectors-1; |
343 | put_unaligned_le32(sys_size, &buf[0x1f4]); | 368 | put_unaligned_le32(sys_size, &buf[0x1f4]); |
344 | 369 | ||
345 | #ifdef CONFIG_EFI_STUB | ||
346 | update_pecoff_text(setup_sectors * 512, sz + i + ((sys_size * 16) - sz)); | 370 | update_pecoff_text(setup_sectors * 512, sz + i + ((sys_size * 16) - sz)); |
347 | 371 | ||
348 | #ifdef CONFIG_X86_64 /* Yes, this is really how we defined it :( */ | 372 | efi_stub_entry_update(); |
349 | efi_stub_entry -= 0x200; | ||
350 | #endif | ||
351 | put_unaligned_le32(efi_stub_entry, &buf[0x264]); | ||
352 | #endif | ||
353 | 373 | ||
354 | crc = partial_crc32(buf, i, crc); | 374 | crc = partial_crc32(buf, i, crc); |
355 | if (fwrite(buf, 1, i, dest) != i) | 375 | if (fwrite(buf, 1, i, dest) != i) |