Path: blob/master/arch/x86/include/asm/bootparam_utils.h
26481 views
/* SPDX-License-Identifier: GPL-2.0 */1#ifndef _ASM_X86_BOOTPARAM_UTILS_H2#define _ASM_X86_BOOTPARAM_UTILS_H34#include <asm/bootparam.h>56/*7* This file is included from multiple environments. Do not8* add completing #includes to make it standalone.9*/1011/*12* Deal with bootloaders which fail to initialize unknown fields in13* boot_params to zero. The list fields in this list are taken from14* analysis of kexec-tools; if other broken bootloaders initialize a15* 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 a18* private magic, so it is better to leave it unchanged.19*/2021#define sizeof_mbr(type, member) ({ sizeof(((type *)0)->member); })2223#define BOOT_PARAM_PRESERVE(struct_member) \24{ \25.start = offsetof(struct boot_params, struct_member), \26.len = sizeof_mbr(struct boot_params, struct_member), \27}2829struct boot_params_to_save {30unsigned int start;31unsigned int len;32};3334static void sanitize_boot_params(struct boot_params *boot_params)35{36/*37* IMPORTANT NOTE TO BOOTLOADER AUTHORS: do not simply clear38* this field. The purpose of this field is to guarantee39* compliance with the x86 boot spec located in40* Documentation/arch/x86/boot.rst . That spec says that the41* *whole* structure should be cleared, after which only the42* portion defined by struct setup_header (boot_params->hdr)43* should be copied in.44*45* If you're having an issue because the sentinel is set, you46* need to change the whole structure to be cleared, not this47* (or any other) individual field, or you will soon have48* problems again.49*/50if (boot_params->sentinel) {51static struct boot_params scratch;52char *bp_base = (char *)boot_params;53char *save_base = (char *)&scratch;54int i;5556const struct boot_params_to_save to_save[] = {57BOOT_PARAM_PRESERVE(screen_info),58BOOT_PARAM_PRESERVE(apm_bios_info),59BOOT_PARAM_PRESERVE(tboot_addr),60BOOT_PARAM_PRESERVE(ist_info),61BOOT_PARAM_PRESERVE(hd0_info),62BOOT_PARAM_PRESERVE(hd1_info),63BOOT_PARAM_PRESERVE(sys_desc_table),64BOOT_PARAM_PRESERVE(olpc_ofw_header),65BOOT_PARAM_PRESERVE(efi_info),66BOOT_PARAM_PRESERVE(alt_mem_k),67BOOT_PARAM_PRESERVE(scratch),68BOOT_PARAM_PRESERVE(e820_entries),69BOOT_PARAM_PRESERVE(eddbuf_entries),70BOOT_PARAM_PRESERVE(edd_mbr_sig_buf_entries),71BOOT_PARAM_PRESERVE(edd_mbr_sig_buffer),72BOOT_PARAM_PRESERVE(secure_boot),73BOOT_PARAM_PRESERVE(hdr),74BOOT_PARAM_PRESERVE(e820_table),75BOOT_PARAM_PRESERVE(eddbuf),76BOOT_PARAM_PRESERVE(cc_blob_address),77};7879memset(&scratch, 0, sizeof(scratch));8081for (i = 0; i < ARRAY_SIZE(to_save); i++) {82memcpy(save_base + to_save[i].start,83bp_base + to_save[i].start, to_save[i].len);84}8586memcpy(boot_params, save_base, sizeof(*boot_params));87}88}8990#endif /* _ASM_X86_BOOTPARAM_UTILS_H */919293