grub2.mk 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. ################################################################################
  2. #
  3. # grub2
  4. #
  5. ################################################################################
  6. GRUB2_VERSION = 2.02
  7. GRUB2_SITE = http://ftp.gnu.org/gnu/grub
  8. GRUB2_SOURCE = grub-$(GRUB2_VERSION).tar.xz
  9. GRUB2_LICENSE = GPL-3.0+
  10. GRUB2_LICENSE_FILES = COPYING
  11. GRUB2_DEPENDENCIES = host-bison host-flex host-grub2
  12. HOST_GRUB2_DEPENDENCIES = host-bison host-flex
  13. GRUB2_INSTALL_IMAGES = YES
  14. ifeq ($(BR2_TARGET_GRUB2_INSTALL_TOOLS),y)
  15. GRUB2_INSTALL_TARGET = YES
  16. else
  17. GRUB2_INSTALL_TARGET = NO
  18. endif
  19. GRUB2_BUILTIN_MODULES = $(call qstrip,$(BR2_TARGET_GRUB2_BUILTIN_MODULES))
  20. GRUB2_BUILTIN_CONFIG = $(call qstrip,$(BR2_TARGET_GRUB2_BUILTIN_CONFIG))
  21. GRUB2_BOOT_PARTITION = $(call qstrip,$(BR2_TARGET_GRUB2_BOOT_PARTITION))
  22. ifeq ($(BR2_TARGET_GRUB2_I386_PC),y)
  23. GRUB2_IMAGE = $(BINARIES_DIR)/grub.img
  24. GRUB2_CFG = $(TARGET_DIR)/boot/grub/grub.cfg
  25. GRUB2_PREFIX = ($(GRUB2_BOOT_PARTITION))/boot/grub
  26. GRUB2_TUPLE = i386-pc
  27. GRUB2_TARGET = i386
  28. GRUB2_PLATFORM = pc
  29. else ifeq ($(BR2_TARGET_GRUB2_I386_EFI),y)
  30. GRUB2_IMAGE = $(BINARIES_DIR)/efi-part/EFI/BOOT/bootia32.efi
  31. GRUB2_CFG = $(BINARIES_DIR)/efi-part/EFI/BOOT/grub.cfg
  32. GRUB2_PREFIX = /EFI/BOOT
  33. GRUB2_TUPLE = i386-efi
  34. GRUB2_TARGET = i386
  35. GRUB2_PLATFORM = efi
  36. else ifeq ($(BR2_TARGET_GRUB2_X86_64_EFI),y)
  37. GRUB2_IMAGE = $(BINARIES_DIR)/efi-part/EFI/BOOT/bootx64.efi
  38. GRUB2_CFG = $(BINARIES_DIR)/efi-part/EFI/BOOT/grub.cfg
  39. GRUB2_PREFIX = /EFI/BOOT
  40. GRUB2_TUPLE = x86_64-efi
  41. GRUB2_TARGET = x86_64
  42. GRUB2_PLATFORM = efi
  43. else ifeq ($(BR2_TARGET_GRUB2_ARM_UBOOT),y)
  44. GRUB2_IMAGE = $(BINARIES_DIR)/boot-part/grub/grub.img
  45. GRUB2_CFG = $(BINARIES_DIR)/boot-part/grub/grub.cfg
  46. GRUB2_PREFIX = ($(GRUB2_BOOT_PARTITION))/boot/grub
  47. GRUB2_TUPLE = arm-uboot
  48. GRUB2_TARGET = arm
  49. GRUB2_PLATFORM = uboot
  50. else ifeq ($(BR2_TARGET_GRUB2_ARM_EFI),y)
  51. GRUB2_IMAGE = $(BINARIES_DIR)/efi-part/EFI/BOOT/bootarm.efi
  52. GRUB2_CFG = $(BINARIES_DIR)/efi-part/EFI/BOOT/grub.cfg
  53. GRUB2_PREFIX = /EFI/BOOT
  54. GRUB2_TUPLE = arm-efi
  55. GRUB2_TARGET = arm
  56. GRUB2_PLATFORM = efi
  57. else ifeq ($(BR2_TARGET_GRUB2_ARM64_EFI),y)
  58. GRUB2_IMAGE = $(BINARIES_DIR)/efi-part/EFI/BOOT/bootaa64.efi
  59. GRUB2_CFG = $(BINARIES_DIR)/efi-part/EFI/BOOT/grub.cfg
  60. GRUB2_PREFIX = /EFI/BOOT
  61. GRUB2_TUPLE = arm64-efi
  62. GRUB2_TARGET = aarch64
  63. GRUB2_PLATFORM = efi
  64. endif
  65. # Grub2 is kind of special: it considers CC, LD and so on to be the
  66. # tools to build the host programs and uses TARGET_CC, TARGET_CFLAGS,
  67. # TARGET_CPPFLAGS, TARGET_LDFLAGS to build the bootloader itself.
  68. #
  69. # NOTE: TARGET_STRIP is overridden by !BR2_STRIP_strip, so always
  70. # use the cross compile variant to ensure grub2 builds
  71. HOST_GRUB2_CONF_ENV = \
  72. CPP="$(HOSTCC) -E"
  73. GRUB2_CONF_ENV = \
  74. CPP="$(TARGET_CC) -E" \
  75. TARGET_CC="$(TARGET_CC)" \
  76. TARGET_CFLAGS="$(TARGET_CFLAGS)" \
  77. TARGET_CPPFLAGS="$(TARGET_CPPFLAGS) -fno-stack-protector" \
  78. TARGET_LDFLAGS="$(TARGET_LDFLAGS)" \
  79. TARGET_NM="$(TARGET_NM)" \
  80. TARGET_OBJCOPY="$(TARGET_OBJCOPY)" \
  81. TARGET_STRIP="$(TARGET_CROSS)strip"
  82. GRUB2_CONF_OPTS = \
  83. --target=$(GRUB2_TARGET) \
  84. --with-platform=$(GRUB2_PLATFORM) \
  85. --prefix=/ \
  86. --exec-prefix=/ \
  87. --disable-grub-mkfont \
  88. --enable-efiemu=no \
  89. ac_cv_lib_lzma_lzma_code=no \
  90. --enable-device-mapper=no \
  91. --enable-libzfs=no \
  92. --disable-werror
  93. HOST_GRUB2_CONF_OPTS = \
  94. --disable-grub-mkfont \
  95. --enable-efiemu=no \
  96. ac_cv_lib_lzma_lzma_code=no \
  97. --enable-device-mapper=no \
  98. --enable-libzfs=no \
  99. --disable-werror
  100. ifeq ($(BR2_TARGET_GRUB2_I386_PC),y)
  101. define GRUB2_IMAGE_INSTALL_ELTORITO
  102. cat $(HOST_DIR)/lib/grub/$(GRUB2_TUPLE)/cdboot.img $(GRUB2_IMAGE) > \
  103. $(BINARIES_DIR)/grub-eltorito.img
  104. endef
  105. endif
  106. define GRUB2_INSTALL_IMAGES_CMDS
  107. mkdir -p $(dir $(GRUB2_IMAGE))
  108. $(HOST_DIR)/usr/bin/grub-mkimage \
  109. -d $(@D)/grub-core/ \
  110. -O $(GRUB2_TUPLE) \
  111. -o $(GRUB2_IMAGE) \
  112. -p "$(GRUB2_PREFIX)" \
  113. $(if $(GRUB2_BUILTIN_CONFIG),-c $(GRUB2_BUILTIN_CONFIG)) \
  114. $(GRUB2_BUILTIN_MODULES)
  115. mkdir -p $(dir $(GRUB2_CFG))
  116. $(INSTALL) -D -m 0644 boot/grub2/grub.cfg $(GRUB2_CFG)
  117. $(GRUB2_IMAGE_INSTALL_ELTORITO)
  118. endef
  119. ifeq ($(GRUB2_PLATFORM),efi)
  120. define GRUB2_EFI_STARTUP_NSH
  121. echo $(notdir $(GRUB2_IMAGE)) > \
  122. $(BINARIES_DIR)/efi-part/startup.nsh
  123. endef
  124. GRUB2_POST_INSTALL_IMAGES_HOOKS += GRUB2_EFI_STARTUP_NSH
  125. endif
  126. $(eval $(autotools-package))
  127. $(eval $(host-autotools-package))