bootparam_utils.h 2.0 KB

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