grub2.mk 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ################################################################################
  2. #
  3. # grub2
  4. #
  5. ################################################################################
  6. GRUB2_VERSION = 2.00
  7. GRUB2_SITE = $(BR2_GNU_MIRROR)/grub
  8. GRUB2_SOURCE = grub-$(GRUB2_VERSION).tar.xz
  9. GRUB2_LICENSE = GPLv3+
  10. GRUB2_LICENSE_FILES = COPYING
  11. GRUB2_DEPENDENCIES = host-bison host-flex
  12. GRUB2_BUILTIN_MODULES = $(call qstrip,$(BR2_TARGET_GRUB2_BUILTIN_MODULES))
  13. GRUB2_BUILTIN_CONFIG = $(call qstrip,$(BR2_TARGET_GRUB2_BUILTIN_CONFIG))
  14. GRUB2_BOOT_PARTITION = $(call qstrip,$(BR2_TARGET_GRUB2_BOOT_PARTITION))
  15. ifeq ($(BR2_TARGET_GRUB2_I386_PC),y)
  16. GRUB2_IMAGE = $(BINARIES_DIR)/grub.img
  17. GRUB2_CFG = $(TARGET_DIR)/boot/grub/grub.cfg
  18. GRUB2_PREFIX = ($(GRUB2_BOOT_PARTITION))/boot/grub
  19. GRUB2_TUPLE = i386-pc
  20. GRUB2_TARGET = i386
  21. GRUB2_PLATFORM = pc
  22. else ifeq ($(BR2_TARGET_GRUB2_I386_EFI),y)
  23. GRUB2_IMAGE = $(BINARIES_DIR)/efi-part/EFI/BOOT/bootia32.efi
  24. GRUB2_CFG = $(BINARIES_DIR)/efi-part/EFI/BOOT/grub.cfg
  25. GRUB2_PREFIX = /EFI/BOOT
  26. GRUB2_TUPLE = i386-efi
  27. GRUB2_TARGET = i386
  28. GRUB2_PLATFORM = efi
  29. else ifeq ($(BR2_TARGET_GRUB2_X86_64_EFI),y)
  30. GRUB2_IMAGE = $(BINARIES_DIR)/efi-part/EFI/BOOT/bootx64.efi
  31. GRUB2_CFG = $(BINARIES_DIR)/efi-part/EFI/BOOT/grub.cfg
  32. GRUB2_PREFIX = /EFI/BOOT
  33. GRUB2_TUPLE = x86_64-efi
  34. GRUB2_TARGET = x86_64
  35. GRUB2_PLATFORM = efi
  36. endif
  37. # Grub2 is kind of special: it considers CC, LD and so on to be the
  38. # tools to build the native tools (i.e to be executed on the build
  39. # machine), and uses TARGET_CC, TARGET_CFLAGS, TARGET_CPPFLAGS,
  40. # TARGET_LDFLAGS to build the bootloader itself. However, to add to
  41. # the confusion, it also uses NM, OBJCOPY and STRIP to build the
  42. # bootloader itself; none of these are used to build the native
  43. # tools.
  44. GRUB2_CONF_ENV = \
  45. $(HOST_CONFIGURE_OPTS) \
  46. CPP="$(HOSTCC) -E" \
  47. TARGET_CC="$(TARGET_CC)" \
  48. TARGET_CFLAGS="$(TARGET_CFLAGS)" \
  49. TARGET_CPPFLAGS="$(TARGET_CPPFLAGS)" \
  50. TARGET_LDFLAGS="$(TARGET_LDFLAGS)" \
  51. NM="$(TARGET_NM)" \
  52. OBJCOPY="$(TARGET_OBJCOPY)" \
  53. STRIP="$(TARGET_STRIP)"
  54. GRUB2_CONF_OPTS = \
  55. --target=$(GRUB2_TARGET) \
  56. --with-platform=$(GRUB2_PLATFORM) \
  57. --disable-grub-mkfont \
  58. --enable-efiemu=no \
  59. --enable-liblzma=no \
  60. --enable-device-mapper=no \
  61. --enable-libzfs=no \
  62. --disable-werror
  63. # We don't want all the native tools and Grub2 modules to be installed
  64. # in the target. So we in fact install everything into the host
  65. # directory, and the image generation process (below) will use the
  66. # grub-mkimage tool and Grub2 modules from the host directory.
  67. GRUB2_INSTALL_TARGET_OPTS = DESTDIR=$(HOST_DIR) install
  68. ifeq ($(BR2_TARGET_GRUB2_I386_PC),y)
  69. define GRUB2_IMAGE_INSTALL_ELTORITO
  70. cat $(HOST_DIR)/usr/lib/grub/$(GRUB2_TUPLE)/cdboot.img $(GRUB2_IMAGE) > \
  71. $(BINARIES_DIR)/grub-eltorito.img
  72. endef
  73. endif
  74. define GRUB2_IMAGE_INSTALLATION
  75. mkdir -p $(dir $(GRUB2_IMAGE))
  76. $(HOST_DIR)/usr/bin/grub-mkimage \
  77. -d $(HOST_DIR)/usr/lib/grub/$(GRUB2_TUPLE) \
  78. -O $(GRUB2_TUPLE) \
  79. -o $(GRUB2_IMAGE) \
  80. -p "$(GRUB2_PREFIX)" \
  81. $(if $(GRUB2_BUILTIN_CONFIG),-c $(GRUB2_BUILTIN_CONFIG)) \
  82. $(GRUB2_BUILTIN_MODULES)
  83. mkdir -p $(dir $(GRUB2_CFG))
  84. $(INSTALL) -D -m 0644 boot/grub2/grub.cfg $(GRUB2_CFG)
  85. $(GRUB2_IMAGE_INSTALL_ELTORITO)
  86. endef
  87. GRUB2_POST_INSTALL_TARGET_HOOKS += GRUB2_IMAGE_INSTALLATION
  88. ifeq ($(GRUB2_PLATFORM),efi)
  89. define GRUB2_EFI_STARTUP_NSH
  90. echo $(notdir $(GRUB2_IMAGE)) > \
  91. $(BINARIES_DIR)/efi-part/startup.nsh
  92. endef
  93. GRUB2_POST_INSTALL_TARGET_HOOKS += GRUB2_EFI_STARTUP_NSH
  94. endif
  95. $(eval $(autotools-package))