grub: support build on x86-64, and misc other improvements

This commit brings a number of improvements to the grub packaging:

 * It builds grub with the host compiler, which is needed so that we
   can build a 32 bits grub even if the target architecture is
   x86-64. To make sure we have a host compiler capable of generating
   32 bits code, grub now selects the BR2_HOSTARCH_NEEDS_IA32_COMPILER
   option. Building with the host compiler is done by cheating and
   passing $(HOST_CONFIGURE_OPTS) in GRUB_CONF_ENV.

 * Some additional CFLAGS are added to make sure grub builds properly
   with modern compilers (-O0, --build-id=none, -fno-stack-protector).

 * Removal of the GRUB_INSTALL_STAGING_CMDS which were not used, since
   GRUB_INSTALL_STAGING was not set to YES.

 * Installation of the "grub" binary in $(HOST_DIR) instead of
   $(TARGET_DIR) since it's actually used only on the host to install
   grub into an image or device.

 * Removal of the grub uninstall commands, since they are generally
   considered useless.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
This commit is contained in:
Thomas Petazzoni 2013-11-11 17:47:28 +01:00 committed by Peter Korsgaard
parent 76422721f7
commit da60753a43
2 changed files with 18 additions and 19 deletions

View File

@ -1,6 +1,7 @@
config BR2_TARGET_GRUB
bool "grub"
depends on BR2_i386 || BR2_x86_64
select BR2_HOSTARCH_NEEDS_IA32_COMPILER
help
The GRand Unified Bootloader for x86 systems.

View File

@ -12,10 +12,15 @@ GRUB_SITE = http://snapshot.debian.org/archive/debian/20080329T000000Z/pool/ma
GRUB_LICENSE = GPLv2+
GRUB_LICENSE_FILES = COPYING
GRUB_CFLAGS=-DSUPPORT_LOOPDEV
ifeq ($(BR2_LARGEFILE),)
GRUB_CFLAGS+=-U_FILE_OFFSET_BITS
endif
# Passing -O0 since the default -O2 passed by Buildroot generates
# non-working stage2. Passing --build-id=none to the linker, because
# the ".note.gnu.build-id" ELF sections generated by default confuse
# objcopy when generating raw binaries. Passing -fno-stack-protector
# to avoid undefined references to __stack_chk_fail.
GRUB_CFLAGS = \
-DSUPPORT_LOOPDEV \
-O0 -Wl,--build-id=none \
-fno-stack-protector
GRUB_CONFIG-$(BR2_TARGET_GRUB_SPLASH) += --enable-graphics
GRUB_CONFIG-$(BR2_TARGET_GRUB_DISKLESS) += --enable-diskless
@ -51,24 +56,26 @@ endef
GRUB_POST_PATCH_HOOKS += GRUB_DEBIAN_PATCHES
GRUB_CONF_ENV = \
CFLAGS="$(TARGET_CFLAGS) $(GRUB_CFLAGS)"
$(HOST_CONFIGURE_OPTS) \
CFLAGS="$(HOST_CFLAGS) $(GRUB_CFLAGS)"
GRUB_CONF_OPT = \
--disable-auto-linux-mem-opt \
$(GRUB_CONFIG-y)
define GRUB_INSTALL_STAGING_CMDS
install -m 0755 -D $(@D)/grub/grub $(STAGING_DIR)/sbin/grub
endef
ifeq ($(BR2_TARGET_GRUB_SPLASH),y)
define GRUB_INSTALL_SPLASH
cp boot/grub/splash.xpm.gz $(TARGET_DIR)/boot/grub/
endef
endif
# We're cheating here as we're installing the grub binary not in the
# target directory (where it is useless), but in the host
# directory. This grub binary can be used to install grub into the MBR
# of a disk or disk image.
define GRUB_INSTALL_TARGET_CMDS
install -m 0755 -D $(@D)/grub/grub $(TARGET_DIR)/sbin/grub
install -m 0755 -D $(@D)/grub/grub $(HOST_DIR)/sbin/grub
mkdir -p $(TARGET_DIR)/boot/grub
cp $(@D)/stage1/stage1 $(TARGET_DIR)/boot/grub
cp $(@D)/stage2/*1_5 $(TARGET_DIR)/boot/grub
@ -76,13 +83,4 @@ define GRUB_INSTALL_TARGET_CMDS
$(GRUB_INSTALL_SPLASH)
endef
define GRUB_UNINSTALL_STAGING_CMDS
rm -f $(STAGING_DIR)/sbin/grub
endef
define GRUB_UNINSTALL_TARGET_CMDS
rm -f $(TARGET_DIR)/sbin/grub
rm -rf $(TARGET_DIR)/boot/grub
endef
$(eval $(autotools-package))