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