xref: /linux/arch/x86/include/asm/bootparam_utils.h (revision ca55b2fef3a9373fcfc30f82fd26bc7fccbda732)
1 #ifndef _ASM_X86_BOOTPARAM_UTILS_H
2 #define _ASM_X86_BOOTPARAM_UTILS_H
3 
4 #include <asm/bootparam.h>
5 
6 /*
7  * This file is included from multiple environments.  Do not
8  * add completing #includes to make it standalone.
9  */
10 
11 /*
12  * Deal with bootloaders which fail to initialize unknown fields in
13  * boot_params to zero.  The list fields in this list are taken from
14  * analysis of kexec-tools; if other broken bootloaders initialize a
15  * different set of fields we will need to figure out how to disambiguate.
16  *
17  * Note: efi_info is commonly left uninitialized, but that field has a
18  * private magic, so it is better to leave it unchanged.
19  */
20 static void sanitize_boot_params(struct boot_params *boot_params)
21 {
22 	/*
23 	 * IMPORTANT NOTE TO BOOTLOADER AUTHORS: do not simply clear
24 	 * this field.  The purpose of this field is to guarantee
25 	 * compliance with the x86 boot spec located in
26 	 * Documentation/x86/boot.txt .  That spec says that the
27 	 * *whole* structure should be cleared, after which only the
28 	 * portion defined by struct setup_header (boot_params->hdr)
29 	 * should be copied in.
30 	 *
31 	 * If you're having an issue because the sentinel is set, you
32 	 * need to change the whole structure to be cleared, not this
33 	 * (or any other) individual field, or you will soon have
34 	 * problems again.
35 	 */
36 	if (boot_params->sentinel) {
37 		/* fields in boot_params are left uninitialized, clear them */
38 		memset(&boot_params->ext_ramdisk_image, 0,
39 		       (char *)&boot_params->efi_info -
40 			(char *)&boot_params->ext_ramdisk_image);
41 		memset(&boot_params->kbd_status, 0,
42 		       (char *)&boot_params->hdr -
43 		       (char *)&boot_params->kbd_status);
44 		memset(&boot_params->_pad7[0], 0,
45 		       (char *)&boot_params->edd_mbr_sig_buffer[0] -
46 			(char *)&boot_params->_pad7[0]);
47 		memset(&boot_params->_pad8[0], 0,
48 		       (char *)&boot_params->eddbuf[0] -
49 			(char *)&boot_params->_pad8[0]);
50 		memset(&boot_params->_pad9[0], 0, sizeof(boot_params->_pad9));
51 	}
52 }
53 
54 #endif /* _ASM_X86_BOOTPARAM_UTILS_H */
55