Discussion:
[Buildroot] [PATCH 0/5] grub2: add support for arm and aarch64
Erico Nunes
2016-09-13 04:15:43 UTC
Permalink
This patch series enables Grub 2 to be built for arm and aarch64.

The patch series itself is not very complex, the most significant effort
put into this series was in testing that it actually works.
Unfortunately, not a lot of documentation or examples are available on
the subject, so some experimentation was required and testing was done
in a few different environments to ensure that enabling these in
Buildroot make sense at this moment.
Initial encouragement that this might be possible with Buildroot targets
came from [1].

Grub 2 for arm/aarch64 can be used either in a uboot platform or efi
platform.

As a uboot platform, Grub 2 image gets built as a u-boot image (i.e.
u-boot mkimage) and is loaded from u-boot through a regular "bootm". The
only requirement from u-boot side in order to allow this is that u-boot
is built with CONFIG_API enabled. CONFIG_API seems to not be enabled by
default in most in-tree configurations, however, it seems to be
available for quite some time now. So it might be possible to use this
even on older u-boot versions. This is available only for arm (32-bit).

As an efi platform, Grub 2 gets built as an EFI executable. This allows
EFI firmware to find and load it similarly as it can be done for x86_64.
It is possible to run aarch64 EFI firmware in qemu [2] and load Grub 2
to test it this way (I have actually used the aarch64 firmware
distributed with edk2-aarch64 from Fedora).
Also, there is a very cool recent u-boot feature which allows u-boot to
load and boot an EFI executable - bootefi [3] - so the Grub 2 efi
platform can also be used from u-boot in recent versions. This has been
released only in u-boot v2016.05 and is enabled (mostly) by default for
ARM u-boot.
efi platform is available for both arm and aarch64.

After enabling support for these Grub 2 platform in Buildroot, I have
tested them (and found to work) in the following environments:

arm-uboot:
- qemu arm vexpress, loaded through u-boot bootm as in [1], no patches
necessary.
- BeagleBone, loaded through u-boot bootm (worked after a small patch I
crafted for Grub 2 which I hope to sort out with upstream, possibly
platform specific).

arm-efi:
- BeagleBone, with u-boot v2016.05, loaded through u-boot bootefi as in
[3], no patches necessary.

aarch64-efi:
- qemu aarch64 virt, using EDK II firmware for aarch64, Grub 2 loaded
through usual UEFI path, no patches necessary.
- Odroid-C2, aarch64, using a patched together u-boot v2016.05 (since
upstream support for this board is not totally done yet), loaded through
u-boot bootefi as in [3].

I have also verified that pc_x86_64_bios_defconfig and
pc_x86_64_efi_defconfig build and boot correctly with Grub 2 without
modifications after applying this patch series.


During development, I split the grub2 package into (host-)grub2-tools
and grub2. I was having trouble in trying to make the existing grub2
package work for arm, getting some weird relocation errors when trying
to execute it on the target, despite it working as expected while
following [1] with recent grub2 and u-boot versions. I tracked it down
as much as to be something related to the use of $(HOST_CONFIGURE_OPTS)
in GRUB2_CONF_ENV, but didn't find the exact cause.
By spliting the packages into a host and target version, I didn't see
any of those errors anymore, it also made the grub2 recipe clearer (less
confusion about mixed host/target build variables) and we also get the
added benefit of enabling grub2-tools to be built for the target.
So I'm also proposing this change as part of the series.


I'm sure this can still be improved, so feedback on the series is very
welcome. For example I'm not sure on what to do with the grub2
documentation on boot/grub2/Config.in; it could start growing very big
for a Config.in documentation if I add more fully detailed instructions
for ARM.
We also now have defconfig examples which include grub2 for x86_64,
maybe the best would be to provide a defconfig instead of extending that
documentation (and possibly also removing all that from Config.in)?

[1] https://www.hellion.org.uk/blog/posts/grub-on-uboot-on-qemu/
[2] https://sourceforge.net/projects/edk2/files/ARM/
[3]


Erico Nunes (5):
grub2: bump up version
grub2-tools: new package
grub2: use grub2-tools as a host package
grub2: enable support for arm and aarch64 targets
grub2: introduce BR2_TARGET_GRUB2_CFG

boot/grub2/0001-remove-gets.patch | 21 -------
...ettext-gettext.c-main_context-secondary_c.patch | 39 -------------
boot/grub2/Config.in | 55 +++++++++++++++---
boot/grub2/grub2.hash | 4 +-
boot/grub2/grub2.mk | 67 ++++++++++++++--------
package/Config.in | 1 +
package/grub2-tools/Config.in | 6 ++
package/grub2-tools/grub2-tools.hash | 2 +
package/grub2-tools/grub2-tools.mk | 45 +++++++++++++++
9 files changed, 144 insertions(+), 96 deletions(-)
delete mode 100644 boot/grub2/0001-remove-gets.patch
delete mode 100644 boot/grub2/0002-grub-core-gettext-gettext.c-main_context-secondary_c.patch
create mode 100644 package/grub2-tools/Config.in
create mode 100644 package/grub2-tools/grub2-tools.hash
create mode 100644 package/grub2-tools/grub2-tools.mk
--
2.9.3
Erico Nunes
2016-09-13 04:15:44 UTC
Permalink
This post might be inappropriate. Click to display it.
Arnout Vandecappelle
2016-09-14 00:25:23 UTC
Permalink
Post by Erico Nunes
Grub 2 version 2.00 which exists in Buildroot dates back from 2012 and
does not support new interesting features such as ARM support.
Despite it being the last official non-beta release, it makes sense to
bump Grub 2 to current master HEAD as the project has not been providing
regular releases since then.
Other distributions such as Fedora have also been shipping variations of
the newer "beta" releases.
[snip]
Post by Erico Nunes
diff --git a/boot/grub2/grub2.mk b/boot/grub2/grub2.mk
index dc4e51e..ecdf421 100644
--- a/boot/grub2/grub2.mk
+++ b/boot/grub2/grub2.mk
@@ -4,9 +4,9 @@
#
################################################################################
-GRUB2_VERSION = 2.00
-GRUB2_SITE = $(BR2_GNU_MIRROR)/grub
-GRUB2_SOURCE = grub-$(GRUB2_VERSION).tar.xz
+GRUB2_VERSION = 4e0f8f66e321cf1051c0e01f6fbcc6fc35a807b6
+GRUB2_SITE = git://git.savannah.gnu.org/grub.git
It's not so nice that we have to download via git, no http protocol, we have to
autoregen, we can't check the signature...

Isn't it better to use grub-2.02~beta3.tar.xz which is just half a year old?
Post by Erico Nunes
+GRUB2_SITE_METHOD = git
GRUB2_LICENSE = GPLv3+
GRUB2_LICENSE_FILES = COPYING
GRUB2_DEPENDENCIES = host-bison host-flex
@@ -70,6 +70,11 @@ GRUB2_CONF_OPTS = \
--enable-libzfs=no \
--disable-werror
+define GRUB2_RUN_AUTOGEN
+endef
+GRUB2_PRE_CONFIGURE_HOOKS += GRUB2_RUN_AUTOGEN
Isn't there a possibility to use GRUB2_AUTORECONF = YES?

If not, you must:

* Explain in a comment why not.
* Add host-automake host-autoconf to GRUB2_DEPENDENCIES
* Normally also host-libtool and normally you have to run LIBTOOL_PATCH_HOOK,
but grub2 doesn't use libtool.


Regards,
Arnout
Post by Erico Nunes
+
# We don't want all the native tools and Grub2 modules to be installed
# in the target. So we in fact install everything into the host
# directory, and the image generation process (below) will use the
--
Arnout Vandecappelle arnout at mind be
Senior Embedded Software Architect +32-16-286500
Essensium/Mind http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint: 7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
Erico Nunes
2016-09-15 21:29:42 UTC
Permalink
Hi Arnout,

thanks for the review!
Post by Arnout Vandecappelle
Post by Erico Nunes
Grub 2 version 2.00 which exists in Buildroot dates back from 2012 and
does not support new interesting features such as ARM support.
Despite it being the last official non-beta release, it makes sense to
bump Grub 2 to current master HEAD as the project has not been providing
regular releases since then.
Other distributions such as Fedora have also been shipping variations of
the newer "beta" releases.
[snip]
Post by Erico Nunes
diff --git a/boot/grub2/grub2.mk b/boot/grub2/grub2.mk
index dc4e51e..ecdf421 100644
--- a/boot/grub2/grub2.mk
+++ b/boot/grub2/grub2.mk
@@ -4,9 +4,9 @@
#
################################################################################
-GRUB2_VERSION = 2.00
-GRUB2_SITE = $(BR2_GNU_MIRROR)/grub
-GRUB2_SOURCE = grub-$(GRUB2_VERSION).tar.xz
+GRUB2_VERSION = 4e0f8f66e321cf1051c0e01f6fbcc6fc35a807b6
+GRUB2_SITE = git://git.savannah.gnu.org/grub.git
It's not so nice that we have to download via git, no http protocol, we have to
autoregen, we can't check the signature...
Isn't it better to use grub-2.02~beta3.tar.xz which is just half a year old?
My initial intention was to use grub-2.02~beta3 tar, however I was
unsure about that too and had a brief chat with Yann and Thomas on IRC
about it before working on this. The conclusion was that it would be
better to juse use HEAD instead of that as it had a few extra bugfix
patches that we would probably want anyway. I guess beta3 would also
be compatible with the rest of the changes here, so it is just the
tradeoff of having no hash check, having to clone git, having to
autogen.sh, against losing some bugfixes. I think additional opinions
on this would be appreciated.
Post by Arnout Vandecappelle
Post by Erico Nunes
+GRUB2_SITE_METHOD = git
GRUB2_LICENSE = GPLv3+
GRUB2_LICENSE_FILES = COPYING
GRUB2_DEPENDENCIES = host-bison host-flex
@@ -70,6 +70,11 @@ GRUB2_CONF_OPTS = \
--enable-libzfs=no \
--disable-werror
+define GRUB2_RUN_AUTOGEN
+endef
+GRUB2_PRE_CONFIGURE_HOOKS += GRUB2_RUN_AUTOGEN
Isn't there a possibility to use GRUB2_AUTORECONF = YES?
* Explain in a comment why not.
* Add host-automake host-autoconf to GRUB2_DEPENDENCIES
* Normally also host-libtool and normally you have to run LIBTOOL_PATCH_HOOK,
but grub2 doesn't use libtool.
AUTORECONF=YES is not enough for this, it doesn't call autogen.sh. We
have other a few other packages in Buildroot which have the same hook.
I have checked now and it seems that all of them do have some comment
for that, so looks like indeed I should also add it. I missed those
extra dependencies, so I think they should probably be added as well.
But this will depend on the outcome of the previous item (about using
git or beta3 tarball), so there also exists a chance this may just
disappear.

Erico
Yann E. MORIN
2016-09-15 21:50:50 UTC
Permalink
Erico, Arnout, All,
Post by Arnout Vandecappelle
Post by Erico Nunes
Grub 2 version 2.00 which exists in Buildroot dates back from 2012 and
does not support new interesting features such as ARM support.
Despite it being the last official non-beta release, it makes sense to
bump Grub 2 to current master HEAD as the project has not been providing
regular releases since then.
Other distributions such as Fedora have also been shipping variations of
the newer "beta" releases.
[snip]
Post by Erico Nunes
diff --git a/boot/grub2/grub2.mk b/boot/grub2/grub2.mk
index dc4e51e..ecdf421 100644
--- a/boot/grub2/grub2.mk
+++ b/boot/grub2/grub2.mk
@@ -4,9 +4,9 @@
#
################################################################################
-GRUB2_VERSION = 2.00
-GRUB2_SITE = $(BR2_GNU_MIRROR)/grub
-GRUB2_SOURCE = grub-$(GRUB2_VERSION).tar.xz
+GRUB2_VERSION = 4e0f8f66e321cf1051c0e01f6fbcc6fc35a807b6
+GRUB2_SITE = git://git.savannah.gnu.org/grub.git
It's not so nice that we have to download via git, no http protocol, we have to
autoregen, we can't check the signature...
A few nits:
- http is available: http://git.savannah.gnu.org/r/grub.git
- it is possible to add a hash for a git download; one just has to
generate it manually locally

autogen.sh is ugly, really ugly: there is no way we can do without it.
They run a bunch of python scripts to "import" a few things: unicode (?)
and glib.

Then the copy/move files around.

Then again call other python scripts top generate some files.

They eventually call autoreconf -fi.

Meh... :-(

Seing that, I withdraw my suggestion to use the latest sha1: please use
the latest release tarball...

Regards,
Yann E. MORIN.
--
.-----------------.--------------------.------------------.--------------------.
| Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ |
| +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. |
'------------------------------^-------^------------------^--------------------'
Erico Nunes
2016-09-13 04:15:45 UTC
Permalink
Support tools to interact with GNU GRUB Multiboot boot loader.

In the context of Buildroot, some useful target tools provided by
grub2-tools are grub2-editenv, grub2-reboot, which provide means to
manage the Grub 2 environment, boot order, and others.

This package is also meant as a preparation step to be turned into a
host-package later and help decouple the target and host portions of the
actual Grub 2 boot loader package.

Signed-off-by: Erico Nunes <***@gmail.com>
---
package/Config.in | 1 +
package/grub2-tools/Config.in | 6 +++++
package/grub2-tools/grub2-tools.hash | 2 ++
package/grub2-tools/grub2-tools.mk | 44 ++++++++++++++++++++++++++++++++++++
4 files changed, 53 insertions(+)
create mode 100644 package/grub2-tools/Config.in
create mode 100644 package/grub2-tools/grub2-tools.hash
create mode 100644 package/grub2-tools/grub2-tools.mk

diff --git a/package/Config.in b/package/Config.in
index 332f05d..e8f90df 100644
--- a/package/Config.in
+++ b/package/Config.in
@@ -379,6 +379,7 @@ endmenu
source "package/gpm/Config.in"
source "package/gpsd/Config.in"
source "package/gptfdisk/Config.in"
+ source "package/grub2-tools/Config.in"
source "package/gvfs/Config.in"
source "package/hdparm/Config.in"
source "package/hwdata/Config.in"
diff --git a/package/grub2-tools/Config.in b/package/grub2-tools/Config.in
new file mode 100644
index 0000000..9cc9e9c
--- /dev/null
+++ b/package/grub2-tools/Config.in
@@ -0,0 +1,6 @@
+config BR2_PACKAGE_GRUB2_TOOLS
+ bool "grub2-tools"
+ help
+ Support tools to interact with GNU GRUB Multiboot boot loader.
+
+ http://www.gnu.org/software/grub/
diff --git a/package/grub2-tools/grub2-tools.hash b/package/grub2-tools/grub2-tools.hash
new file mode 100644
index 0000000..051a9ab
--- /dev/null
+++ b/package/grub2-tools/grub2-tools.hash
@@ -0,0 +1,2 @@
+# Locally computed:
+sha256 680f584995cf318adb1ff8c40caef30d0ec7c03e16e88ba60bf5aa5b5a6e26ed grub2-4e0f8f66e321cf1051c0e01f6fbcc6fc35a807b6.tar.gz
diff --git a/package/grub2-tools/grub2-tools.mk b/package/grub2-tools/grub2-tools.mk
new file mode 100644
index 0000000..8ed23f3
--- /dev/null
+++ b/package/grub2-tools/grub2-tools.mk
@@ -0,0 +1,44 @@
+################################################################################
+#
+# grub2-tools
+#
+################################################################################
+
+GRUB2_TOOLS_VERSION = 4e0f8f66e321cf1051c0e01f6fbcc6fc35a807b6
+GRUB2_TOOLS_SITE = git://git.savannah.gnu.org/grub.git
+GRUB2_TOOLS_SITE_METHOD = git
+GRUB2_TOOLS_LICENSE = GPLv3+
+GRUB2_TOOLS_LICENSE_FILES = COPYING
+GRUB2_TOOLS_DEPENDENCIES = host-bison host-flex
+HOST_GRUB2_TOOLS_DEPENDENCIES = host-bison host-flex
+
+HOST_GRUB2_TOOLS_CONF_ENV = \
+ CPP="$(HOSTCC) -E"
+
+GRUB2_TOOLS_CONF_ENV = \
+ CPP="$(TARGET_CC) -E" \
+ TARGET_CC="$(TARGET_CC)" \
+ TARGET_CFLAGS="$(TARGET_CFLAGS)" \
+ TARGET_CPPFLAGS="$(TARGET_CPPFLAGS)" \
+ TARGET_LDFLAGS="$(TARGET_LDFLAGS)" \
+ TARGET_NM="$(TARGET_NM)" \
+ TARGET_OBJCOPY="$(TARGET_OBJCOPY)" \
+ TARGET_STRIP="$(TARGET_CROSS)strip"
+
+GRUB2_TOOLS_CONF_OPTS = \
+ --disable-grub-mkfont \
+ --enable-efiemu=no \
+ ac_cv_lib_lzma_lzma_code=no \
+ --enable-device-mapper=no \
+ --enable-libzfs=no \
+ --disable-werror
+
+HOST_GRUB2_TOOLS_CONF_OPTS = $(GRUB2_TOOLS_CONF_OPTS)
+
+define GRUB2_TOOLS_RUN_AUTOGEN
+ cd $(@D) && PATH=$(BR_PATH) ./autogen.sh
+endef
+GRUB2_TOOLS_PRE_CONFIGURE_HOOKS += GRUB2_TOOLS_RUN_AUTOGEN
+HOST_GRUB2_TOOLS_PRE_CONFIGURE_HOOKS += GRUB2_TOOLS_RUN_AUTOGEN
+
+$(eval $(autotools-package))
--
2.9.3
Erico Nunes
2016-09-13 04:15:47 UTC
Permalink
This commit enables the arm-uboot, arm-efi and aarch64-efi Grub 2
platforms in Buildroot.

As a uboot platform, Grub 2 image gets built as a u-boot image (i.e.
u-boot mkimage) and is loaded from u-boot through a regular "bootm". The
only requirement from u-boot side in order to allow this is that u-boot
is built with CONFIG_API enabled. CONFIG_API seems to not be enabled by
default in most in-tree configurations, however, it seems to be
available for quite some time now. So it might be possible to use this
even on older u-boot versions. This is available only for arm (32-bit).

As an efi platform, Grub 2 gets built as an EFI executable. This allows
EFI firmware to find and load it similarly as it can be done for x86_64.
Also, since u-boot v2016.05, u-boot is able to load and boot an EFI
executable, so the Grub 2 efi platform can also be used from u-boot in
recent versions. This has been enabled (mostly) by default for ARM
u-boot.
efi platform is available for both arm and aarch64.

These targets have been tested in the following environments:

arm-uboot: qemu arm vexpress and BeagleBone
arm-efi: BeagleBone
aarch64-efi: qemu aarch64 virt and Odroid-C2

Signed-off-by: Erico Nunes <***@gmail.com>
---
boot/grub2/Config.in | 48 +++++++++++++++++++++++++++++++++++++++---------
boot/grub2/grub2.mk | 23 ++++++++++++++++++++++-
2 files changed, 61 insertions(+), 10 deletions(-)

diff --git a/boot/grub2/Config.in b/boot/grub2/Config.in
index 7dc5cae..527ff37 100644
--- a/boot/grub2/Config.in
+++ b/boot/grub2/Config.in
@@ -1,6 +1,6 @@
config BR2_TARGET_GRUB2
bool "grub2"
- depends on BR2_i386 || BR2_x86_64
+ depends on BR2_i386 || BR2_x86_64 || BR2_arm || BR2_aarch64
help
GNU GRUB is a Multiboot boot loader. It was derived from
GRUB, the GRand Unified Bootloader, which was originally
@@ -66,8 +66,8 @@ config BR2_TARGET_GRUB2

qemu-system-{i386,x86-64} -hda disk.img

- Notes on using Grub2 for EFI-based platforms
- ============================================
+ Notes on using Grub2 for i386/x86-64 EFI-based platforms
+ ========================================================

1. Create a disk image
dd if=/dev/zero of=disk.img bs=1M count=32
@@ -96,8 +96,8 @@ config BR2_TARGET_GRUB2
sudo losetup -d /dev/loop0
7. Your disk.img is ready!

- To test your EFI image in Qemu
- ------------------------------
+ To test your i386/x86-64 EFI image in Qemu
+ ------------------------------------------

1. Download the EFI BIOS for Qemu
Version IA32 or X64 depending on the chosen Grub2
@@ -119,12 +119,14 @@ choice

config BR2_TARGET_GRUB2_I386_PC
bool "i386-pc"
+ depends on BR2_i386 || BR2_x86_64
help
Select this option if the platform you're targetting is a
x86 or x86-64 legacy BIOS based platform.

config BR2_TARGET_GRUB2_I386_EFI
bool "i386-efi"
+ depends on BR2_i386 || BR2_x86_64
help
Select this option if the platform you're targetting has a
32 bits EFI BIOS. Note that some x86-64 platforms use a 32
@@ -132,14 +134,38 @@ config BR2_TARGET_GRUB2_I386_EFI

config BR2_TARGET_GRUB2_X86_64_EFI
bool "x86-64-efi"
- depends on BR2_ARCH_IS_64
+ depends on BR2_x86_64
help
Select this option if the platform you're targetting has a
64 bits EFI BIOS.

+config BR2_TARGET_GRUB2_ARM_UBOOT
+ bool "arm-uboot"
+ depends on BR2_arm
+ help
+ Select this option if the platform you're targetting is an
+ ARM u-boot platform, and you want to boot Grub 2 as an u-boot
+ compatible image.
+
+config BR2_TARGET_GRUB2_ARM_EFI
+ bool "arm-efi"
+ depends on BR2_arm
+ help
+ Select this option if the platform you're targetting is an
+ ARM platform and you want to boot Grub 2 as an EFI
+ application.
+
+config BR2_TARGET_GRUB2_ARM64_EFI
+ bool "arm64-efi"
+ depends on BR2_aarch64
+ help
+ Select this option if the platform you're targetting is an
+ Aarch64 platform and you want to boot Grub 2 as an EFI
+ application.
+
endchoice

-if BR2_TARGET_GRUB2_I386_PC
+if BR2_TARGET_GRUB2_I386_PC || BR2_TARGET_GRUB2_ARM_UBOOT

config BR2_TARGET_GRUB2_BOOT_PARTITION
string "boot partition"
@@ -150,13 +176,17 @@ config BR2_TARGET_GRUB2_BOOT_PARTITION
first disk if using a legacy partition table, or 'hd0,gpt1'
if using GPT partition table.

-endif # BR2_TARGET_GRUB2_I386_PC
+endif # BR2_TARGET_GRUB2_I386_PC || BR2_TARGET_GRUB2_ARM_UBOOT

config BR2_TARGET_GRUB2_BUILTIN_MODULES
string "builtin modules"
default "boot linux ext2 fat squash4 part_msdos part_gpt normal biosdisk" if BR2_TARGET_GRUB2_I386_PC
default "boot linux ext2 fat squash4 part_msdos part_gpt normal efi_gop" \
- if BR2_TARGET_GRUB2_I386_EFI || BR2_TARGET_GRUB2_X86_64_EFI
+ if BR2_TARGET_GRUB2_I386_EFI || \
+ BR2_TARGET_GRUB2_X86_64_EFI || \
+ BR2_TARGET_GRUB2_ARM_EFI || \\
+ BR2_TARGET_GRUB2_ARM64_EFI
+ default "linux ext2 fat part_msdos normal" if BR2_TARGET_GRUB2_ARM_UBOOT

config BR2_TARGET_GRUB2_BUILTIN_CONFIG
string "builtin config"
diff --git a/boot/grub2/grub2.mk b/boot/grub2/grub2.mk
index 8a063f1..910967e 100644
--- a/boot/grub2/grub2.mk
+++ b/boot/grub2/grub2.mk
@@ -38,6 +38,27 @@ GRUB2_PREFIX = /EFI/BOOT
GRUB2_TUPLE = x86_64-efi
GRUB2_TARGET = x86_64
GRUB2_PLATFORM = efi
+else ifeq ($(BR2_TARGET_GRUB2_ARM_UBOOT),y)
+GRUB2_IMAGE = $(BINARIES_DIR)/boot-part/grub.img
+GRUB2_CFG = $(BINARIES_DIR)/boot-part/grub.cfg
+GRUB2_PREFIX = ($(GRUB2_BOOT_PARTITION))
+GRUB2_TUPLE = arm-uboot
+GRUB2_TARGET = arm
+GRUB2_PLATFORM = uboot
+else ifeq ($(BR2_TARGET_GRUB2_ARM_EFI),y)
+GRUB2_IMAGE = $(BINARIES_DIR)/efi-part/EFI/BOOT/bootarm.efi
+GRUB2_CFG = $(BINARIES_DIR)/efi-part/EFI/BOOT/grub.cfg
+GRUB2_PREFIX = /EFI/BOOT
+GRUB2_TUPLE = arm-efi
+GRUB2_TARGET = arm
+GRUB2_PLATFORM = efi
+else ifeq ($(BR2_TARGET_GRUB2_ARM64_EFI),y)
+GRUB2_IMAGE = $(BINARIES_DIR)/efi-part/EFI/BOOT/bootaa64.efi
+GRUB2_CFG = $(BINARIES_DIR)/efi-part/EFI/BOOT/grub.cfg
+GRUB2_PREFIX = /EFI/BOOT
+GRUB2_TUPLE = arm64-efi
+GRUB2_TARGET = aarch64
+GRUB2_PLATFORM = efi
endif

# Grub2 is kind of special: it considers CC, LD and so on to be the
@@ -83,7 +104,7 @@ endif
define GRUB2_INSTALL_IMAGES_CMDS
mkdir -p $(dir $(GRUB2_IMAGE))
$(HOST_DIR)/usr/bin/grub-mkimage \
- -d $(HOST_DIR)/usr/lib/grub/$(GRUB2_TUPLE) \
+ -d $(@D)/grub-core/ \
-O $(GRUB2_TUPLE) \
-o $(GRUB2_IMAGE) \
-p "$(GRUB2_PREFIX)" \
--
2.9.3
Arnout Vandecappelle
2016-09-14 00:39:11 UTC
Permalink
Post by Erico Nunes
This commit enables the arm-uboot, arm-efi and aarch64-efi Grub 2
platforms in Buildroot.
As a uboot platform, Grub 2 image gets built as a u-boot image (i.e.
u-boot mkimage) and is loaded from u-boot through a regular "bootm". The
only requirement from u-boot side in order to allow this is that u-boot
is built with CONFIG_API enabled. CONFIG_API seems to not be enabled by
default in most in-tree configurations, however, it seems to be
available for quite some time now. So it might be possible to use this
even on older u-boot versions. This is available only for arm (32-bit).
As an efi platform, Grub 2 gets built as an EFI executable. This allows
EFI firmware to find and load it similarly as it can be done for x86_64.
Also, since u-boot v2016.05, u-boot is able to load and boot an EFI
executable, so the Grub 2 efi platform can also be used from u-boot in
recent versions. This has been enabled (mostly) by default for ARM
u-boot.
efi platform is available for both arm and aarch64.
arm-uboot: qemu arm vexpress and BeagleBone
arm-efi: BeagleBone
aarch64-efi: qemu aarch64 virt and Odroid-C2
---
boot/grub2/Config.in | 48 +++++++++++++++++++++++++++++++++++++++---------
boot/grub2/grub2.mk | 23 ++++++++++++++++++++++-
2 files changed, 61 insertions(+), 10 deletions(-)
diff --git a/boot/grub2/Config.in b/boot/grub2/Config.in
index 7dc5cae..527ff37 100644
--- a/boot/grub2/Config.in
+++ b/boot/grub2/Config.in
@@ -1,6 +1,6 @@
config BR2_TARGET_GRUB2
bool "grub2"
- depends on BR2_i386 || BR2_x86_64
+ depends on BR2_i386 || BR2_x86_64 || BR2_arm || BR2_aarch64
help
GNU GRUB is a Multiboot boot loader. It was derived from
GRUB, the GRand Unified Bootloader, which was originally
@@ -66,8 +66,8 @@ config BR2_TARGET_GRUB2
qemu-system-{i386,x86-64} -hda disk.img
- Notes on using Grub2 for EFI-based platforms
- ============================================
+ Notes on using Grub2 for i386/x86-64 EFI-based platforms
+ ========================================================
1. Create a disk image
dd if=/dev/zero of=disk.img bs=1M count=32
@@ -96,8 +96,8 @@ config BR2_TARGET_GRUB2
sudo losetup -d /dev/loop0
7. Your disk.img is ready!
- To test your EFI image in Qemu
- ------------------------------
+ To test your i386/x86-64 EFI image in Qemu
+ ------------------------------------------
1. Download the EFI BIOS for Qemu
Version IA32 or X64 depending on the chosen Grub2
You hinted at this in your cover letter: it would be better to move all this
documentation to e.g. boot/grub2/readme.txt and refer to it from the help text.
This would be a separate preparatory patch. Then you can also easily add all the
documentation for the ARM targets to that file.
Post by Erico Nunes
@@ -119,12 +119,14 @@ choice
config BR2_TARGET_GRUB2_I386_PC
bool "i386-pc"
+ depends on BR2_i386 || BR2_x86_64
help
Select this option if the platform you're targetting is a
x86 or x86-64 legacy BIOS based platform.
config BR2_TARGET_GRUB2_I386_EFI
bool "i386-efi"
+ depends on BR2_i386 || BR2_x86_64
help
Select this option if the platform you're targetting has a
32 bits EFI BIOS. Note that some x86-64 platforms use a 32
@@ -132,14 +134,38 @@ config BR2_TARGET_GRUB2_I386_EFI
config BR2_TARGET_GRUB2_X86_64_EFI
bool "x86-64-efi"
- depends on BR2_ARCH_IS_64
+ depends on BR2_x86_64
help
Select this option if the platform you're targetting has a
64 bits EFI BIOS.
+config BR2_TARGET_GRUB2_ARM_UBOOT
+ bool "arm-uboot"
+ depends on BR2_arm
I think this choice deserves a bit of refactoring. I think it could be:

choice

config BR2_TARGET_GRUB2_I386_PC
depends on BR2_i386 || BR2_x86_64
config BR2_TARGET_GRUB2_EFI
# possible on all platforms
config BR2_TARGET_GRUB2_UBOOT
depends on BR2_arm
endchoice

I think that that would also simplify the .mk file somewhat, because most of
the EFI options are the same for all arches.

The only problem with this change is that we don't have easy legacy handling
for it, because you can't select a choice option.
Post by Erico Nunes
+ help
+ Select this option if the platform you're targetting is an
+ ARM u-boot platform, and you want to boot Grub 2 as an u-boot
+ compatible image.
+
+config BR2_TARGET_GRUB2_ARM_EFI
+ bool "arm-efi"
+ depends on BR2_arm
+ help
+ Select this option if the platform you're targetting is an
+ ARM platform and you want to boot Grub 2 as an EFI
+ application.
+
+config BR2_TARGET_GRUB2_ARM64_EFI
+ bool "arm64-efi"
+ depends on BR2_aarch64
+ help
+ Select this option if the platform you're targetting is an
+ Aarch64 platform and you want to boot Grub 2 as an EFI
+ application.
+
endchoice
-if BR2_TARGET_GRUB2_I386_PC
+if BR2_TARGET_GRUB2_I386_PC || BR2_TARGET_GRUB2_ARM_UBOOT
config BR2_TARGET_GRUB2_BOOT_PARTITION
string "boot partition"
@@ -150,13 +176,17 @@ config BR2_TARGET_GRUB2_BOOT_PARTITION
first disk if using a legacy partition table, or 'hd0,gpt1'
if using GPT partition table.
-endif # BR2_TARGET_GRUB2_I386_PC
+endif # BR2_TARGET_GRUB2_I386_PC || BR2_TARGET_GRUB2_ARM_UBOOT
config BR2_TARGET_GRUB2_BUILTIN_MODULES
string "builtin modules"
default "boot linux ext2 fat squash4 part_msdos part_gpt normal biosdisk" if BR2_TARGET_GRUB2_I386_PC
default "boot linux ext2 fat squash4 part_msdos part_gpt normal efi_gop" \
- if BR2_TARGET_GRUB2_I386_EFI || BR2_TARGET_GRUB2_X86_64_EFI
+ if BR2_TARGET_GRUB2_I386_EFI || \
+ BR2_TARGET_GRUB2_X86_64_EFI || \
+ BR2_TARGET_GRUB2_ARM_EFI || \\
+ BR2_TARGET_GRUB2_ARM64_EFI
+ default "linux ext2 fat part_msdos normal" if BR2_TARGET_GRUB2_ARM_UBOOT
config BR2_TARGET_GRUB2_BUILTIN_CONFIG
string "builtin config"
diff --git a/boot/grub2/grub2.mk b/boot/grub2/grub2.mk
index 8a063f1..910967e 100644
--- a/boot/grub2/grub2.mk
+++ b/boot/grub2/grub2.mk
@@ -38,6 +38,27 @@ GRUB2_PREFIX = /EFI/BOOT
GRUB2_TUPLE = x86_64-efi
GRUB2_TARGET = x86_64
GRUB2_PLATFORM = efi
+else ifeq ($(BR2_TARGET_GRUB2_ARM_UBOOT),y)
+GRUB2_IMAGE = $(BINARIES_DIR)/boot-part/grub.img
+GRUB2_CFG = $(BINARIES_DIR)/boot-part/grub.cfg
+GRUB2_PREFIX = ($(GRUB2_BOOT_PARTITION))
+GRUB2_TUPLE = arm-uboot
+GRUB2_TARGET = arm
+GRUB2_PLATFORM = uboot
+else ifeq ($(BR2_TARGET_GRUB2_ARM_EFI),y)
+GRUB2_IMAGE = $(BINARIES_DIR)/efi-part/EFI/BOOT/bootarm.efi
+GRUB2_CFG = $(BINARIES_DIR)/efi-part/EFI/BOOT/grub.cfg
+GRUB2_PREFIX = /EFI/BOOT
+GRUB2_TUPLE = arm-efi
+GRUB2_TARGET = arm
+GRUB2_PLATFORM = efi
+else ifeq ($(BR2_TARGET_GRUB2_ARM64_EFI),y)
+GRUB2_IMAGE = $(BINARIES_DIR)/efi-part/EFI/BOOT/bootaa64.efi
+GRUB2_CFG = $(BINARIES_DIR)/efi-part/EFI/BOOT/grub.cfg
+GRUB2_PREFIX = /EFI/BOOT
+GRUB2_TUPLE = arm64-efi
+GRUB2_TARGET = aarch64
+GRUB2_PLATFORM = efi
endif
# Grub2 is kind of special: it considers CC, LD and so on to be the
@@ -83,7 +104,7 @@ endif
define GRUB2_INSTALL_IMAGES_CMDS
mkdir -p $(dir $(GRUB2_IMAGE))
$(HOST_DIR)/usr/bin/grub-mkimage \
- -d $(HOST_DIR)/usr/lib/grub/$(GRUB2_TUPLE) \
Does this belong to this patch or the previous one?

Regards,
Arnout
Post by Erico Nunes
-O $(GRUB2_TUPLE) \
-o $(GRUB2_IMAGE) \
-p "$(GRUB2_PREFIX)" \
--
Arnout Vandecappelle arnout at mind be
Senior Embedded Software Architect +32-16-286500
Essensium/Mind http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint: 7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
Erico Nunes
2016-09-15 21:43:15 UTC
Permalink
Hi Arnout,

thanks for the review!
Post by Arnout Vandecappelle
Post by Erico Nunes
This commit enables the arm-uboot, arm-efi and aarch64-efi Grub 2
platforms in Buildroot.
As a uboot platform, Grub 2 image gets built as a u-boot image (i.e.
u-boot mkimage) and is loaded from u-boot through a regular "bootm". The
only requirement from u-boot side in order to allow this is that u-boot
is built with CONFIG_API enabled. CONFIG_API seems to not be enabled by
default in most in-tree configurations, however, it seems to be
available for quite some time now. So it might be possible to use this
even on older u-boot versions. This is available only for arm (32-bit).
As an efi platform, Grub 2 gets built as an EFI executable. This allows
EFI firmware to find and load it similarly as it can be done for x86_64.
Also, since u-boot v2016.05, u-boot is able to load and boot an EFI
executable, so the Grub 2 efi platform can also be used from u-boot in
recent versions. This has been enabled (mostly) by default for ARM
u-boot.
efi platform is available for both arm and aarch64.
arm-uboot: qemu arm vexpress and BeagleBone
arm-efi: BeagleBone
aarch64-efi: qemu aarch64 virt and Odroid-C2
---
boot/grub2/Config.in | 48 +++++++++++++++++++++++++++++++++++++++---------
boot/grub2/grub2.mk | 23 ++++++++++++++++++++++-
2 files changed, 61 insertions(+), 10 deletions(-)
diff --git a/boot/grub2/Config.in b/boot/grub2/Config.in
index 7dc5cae..527ff37 100644
--- a/boot/grub2/Config.in
+++ b/boot/grub2/Config.in
@@ -1,6 +1,6 @@
config BR2_TARGET_GRUB2
bool "grub2"
- depends on BR2_i386 || BR2_x86_64
+ depends on BR2_i386 || BR2_x86_64 || BR2_arm || BR2_aarch64
help
GNU GRUB is a Multiboot boot loader. It was derived from
GRUB, the GRand Unified Bootloader, which was originally
@@ -66,8 +66,8 @@ config BR2_TARGET_GRUB2
qemu-system-{i386,x86-64} -hda disk.img
- Notes on using Grub2 for EFI-based platforms
- ============================================
+ Notes on using Grub2 for i386/x86-64 EFI-based platforms
+ ========================================================
1. Create a disk image
dd if=/dev/zero of=disk.img bs=1M count=32
@@ -96,8 +96,8 @@ config BR2_TARGET_GRUB2
sudo losetup -d /dev/loop0
7. Your disk.img is ready!
- To test your EFI image in Qemu
- ------------------------------
+ To test your i386/x86-64 EFI image in Qemu
+ ------------------------------------------
1. Download the EFI BIOS for Qemu
Version IA32 or X64 depending on the chosen Grub2
You hinted at this in your cover letter: it would be better to move all this
documentation to e.g. boot/grub2/readme.txt and refer to it from the help text.
This would be a separate preparatory patch. Then you can also easily add all the
documentation for the ARM targets to that file.
Sounds good, if there are no objections I can do that for v2.
Post by Arnout Vandecappelle
Post by Erico Nunes
@@ -119,12 +119,14 @@ choice
config BR2_TARGET_GRUB2_I386_PC
bool "i386-pc"
+ depends on BR2_i386 || BR2_x86_64
help
Select this option if the platform you're targetting is a
x86 or x86-64 legacy BIOS based platform.
config BR2_TARGET_GRUB2_I386_EFI
bool "i386-efi"
+ depends on BR2_i386 || BR2_x86_64
help
Select this option if the platform you're targetting has a
32 bits EFI BIOS. Note that some x86-64 platforms use a 32
@@ -132,14 +134,38 @@ config BR2_TARGET_GRUB2_I386_EFI
config BR2_TARGET_GRUB2_X86_64_EFI
bool "x86-64-efi"
- depends on BR2_ARCH_IS_64
+ depends on BR2_x86_64
help
Select this option if the platform you're targetting has a
64 bits EFI BIOS.
+config BR2_TARGET_GRUB2_ARM_UBOOT
+ bool "arm-uboot"
+ depends on BR2_arm
choice
config BR2_TARGET_GRUB2_I386_PC
depends on BR2_i386 || BR2_x86_64
config BR2_TARGET_GRUB2_EFI
# possible on all platforms
config BR2_TARGET_GRUB2_UBOOT
depends on BR2_arm
endchoice
I think that that would also simplify the .mk file somewhat, because most of
the EFI options are the same for all arches.
The only problem with this change is that we don't have easy legacy handling
for it, because you can't select a choice option.
I agree that this can use some refactor, however I was a little
conservative on this in order to not add much more complexity and
delay to this series. Maybe this could also come in a patch later on
after this series?
Post by Arnout Vandecappelle
Post by Erico Nunes
+ help
+ Select this option if the platform you're targetting is an
+ ARM u-boot platform, and you want to boot Grub 2 as an u-boot
+ compatible image.
+
+config BR2_TARGET_GRUB2_ARM_EFI
+ bool "arm-efi"
+ depends on BR2_arm
+ help
+ Select this option if the platform you're targetting is an
+ ARM platform and you want to boot Grub 2 as an EFI
+ application.
+
+config BR2_TARGET_GRUB2_ARM64_EFI
+ bool "arm64-efi"
+ depends on BR2_aarch64
+ help
+ Select this option if the platform you're targetting is an
+ Aarch64 platform and you want to boot Grub 2 as an EFI
+ application.
+
endchoice
-if BR2_TARGET_GRUB2_I386_PC
+if BR2_TARGET_GRUB2_I386_PC || BR2_TARGET_GRUB2_ARM_UBOOT
config BR2_TARGET_GRUB2_BOOT_PARTITION
string "boot partition"
@@ -150,13 +176,17 @@ config BR2_TARGET_GRUB2_BOOT_PARTITION
first disk if using a legacy partition table, or 'hd0,gpt1'
if using GPT partition table.
-endif # BR2_TARGET_GRUB2_I386_PC
+endif # BR2_TARGET_GRUB2_I386_PC || BR2_TARGET_GRUB2_ARM_UBOOT
config BR2_TARGET_GRUB2_BUILTIN_MODULES
string "builtin modules"
default "boot linux ext2 fat squash4 part_msdos part_gpt normal biosdisk" if BR2_TARGET_GRUB2_I386_PC
default "boot linux ext2 fat squash4 part_msdos part_gpt normal efi_gop" \
- if BR2_TARGET_GRUB2_I386_EFI || BR2_TARGET_GRUB2_X86_64_EFI
+ if BR2_TARGET_GRUB2_I386_EFI || \
+ BR2_TARGET_GRUB2_X86_64_EFI || \
+ BR2_TARGET_GRUB2_ARM_EFI || \\
+ BR2_TARGET_GRUB2_ARM64_EFI
+ default "linux ext2 fat part_msdos normal" if BR2_TARGET_GRUB2_ARM_UBOOT
config BR2_TARGET_GRUB2_BUILTIN_CONFIG
string "builtin config"
diff --git a/boot/grub2/grub2.mk b/boot/grub2/grub2.mk
index 8a063f1..910967e 100644
--- a/boot/grub2/grub2.mk
+++ b/boot/grub2/grub2.mk
@@ -38,6 +38,27 @@ GRUB2_PREFIX = /EFI/BOOT
GRUB2_TUPLE = x86_64-efi
GRUB2_TARGET = x86_64
GRUB2_PLATFORM = efi
+else ifeq ($(BR2_TARGET_GRUB2_ARM_UBOOT),y)
+GRUB2_IMAGE = $(BINARIES_DIR)/boot-part/grub.img
+GRUB2_CFG = $(BINARIES_DIR)/boot-part/grub.cfg
+GRUB2_PREFIX = ($(GRUB2_BOOT_PARTITION))
+GRUB2_TUPLE = arm-uboot
+GRUB2_TARGET = arm
+GRUB2_PLATFORM = uboot
+else ifeq ($(BR2_TARGET_GRUB2_ARM_EFI),y)
+GRUB2_IMAGE = $(BINARIES_DIR)/efi-part/EFI/BOOT/bootarm.efi
+GRUB2_CFG = $(BINARIES_DIR)/efi-part/EFI/BOOT/grub.cfg
+GRUB2_PREFIX = /EFI/BOOT
+GRUB2_TUPLE = arm-efi
+GRUB2_TARGET = arm
+GRUB2_PLATFORM = efi
+else ifeq ($(BR2_TARGET_GRUB2_ARM64_EFI),y)
+GRUB2_IMAGE = $(BINARIES_DIR)/efi-part/EFI/BOOT/bootaa64.efi
+GRUB2_CFG = $(BINARIES_DIR)/efi-part/EFI/BOOT/grub.cfg
+GRUB2_PREFIX = /EFI/BOOT
+GRUB2_TUPLE = arm64-efi
+GRUB2_TARGET = aarch64
+GRUB2_PLATFORM = efi
endif
# Grub2 is kind of special: it considers CC, LD and so on to be the
@@ -83,7 +104,7 @@ endif
define GRUB2_INSTALL_IMAGES_CMDS
mkdir -p $(dir $(GRUB2_IMAGE))
$(HOST_DIR)/usr/bin/grub-mkimage \
- -d $(HOST_DIR)/usr/lib/grub/$(GRUB2_TUPLE) \
Does this belong to this patch or the previous one?
I will check this again for v2. My first thought is that it doesn't
make much difference as it worked fine before without ARM support, and
this is the first patch in which ARM support gets added.

Thanks

Erico
Thomas Petazzoni
2016-09-17 14:24:05 UTC
Permalink
Hello,
Post by Arnout Vandecappelle
Post by Erico Nunes
1. Download the EFI BIOS for Qemu
Version IA32 or X64 depending on the chosen Grub2
You hinted at this in your cover letter: it would be better to move all this
documentation to e.g. boot/grub2/readme.txt and refer to it from the help text.
This would be a separate preparatory patch. Then you can also easily add all the
documentation for the ARM targets to that file.
Just wanted to say that I agree with the idea of a readme.txt in the
package directory. For quite some time we have been in a need of a
place to store some documentation/informations/details about different
packages, and we currently don't have a good place for that. The
manual? There's no chapter for it, and it puts the information a bit
"far" from the package itself. In the Config.in help text? Works fine
for short text, but not really suitable for longer explanations.

So, +1 for readme.txt in package directories, of course when there's
something useful to say about the package.

Thomas
--
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
Erico Nunes
2016-09-13 04:15:46 UTC
Permalink
Grub 2 requires the host grub2-mkimage tool to build some of its target
images.
The current way of obtaining this tool in the grub2 package is to
perform a simultaneous host-tools/target-bootloader build during the
grub2 build step.

During work to enable Grub 2 support for arm/aarch64 (to come in
upcoming patches), this flow was a complication and led to hard-to-debug
problems in the target image (i.e. strange relocation errors in
runtime).

By making a better separation between the build of grub2 host tools and
target boot loader image, these problems have not been observed and it
makes the grub2 recipe less complex to understand.

Signed-off-by: Erico Nunes <***@gmail.com>
---
boot/grub2/grub2.mk | 30 ++++++++++--------------------
package/grub2-tools/grub2-tools.mk | 1 +
2 files changed, 11 insertions(+), 20 deletions(-)

diff --git a/boot/grub2/grub2.mk b/boot/grub2/grub2.mk
index ecdf421..8a063f1 100644
--- a/boot/grub2/grub2.mk
+++ b/boot/grub2/grub2.mk
@@ -9,7 +9,9 @@ GRUB2_SITE = git://git.savannah.gnu.org/grub.git
GRUB2_SITE_METHOD = git
GRUB2_LICENSE = GPLv3+
GRUB2_LICENSE_FILES = COPYING
-GRUB2_DEPENDENCIES = host-bison host-flex
+GRUB2_DEPENDENCIES = host-bison host-flex host-grub2-tools
+GRUB2_INSTALL_TARGET = NO
+GRUB2_INSTALL_IMAGES = YES

GRUB2_BUILTIN_MODULES = $(call qstrip,$(BR2_TARGET_GRUB2_BUILTIN_MODULES))
GRUB2_BUILTIN_CONFIG = $(call qstrip,$(BR2_TARGET_GRUB2_BUILTIN_CONFIG))
@@ -41,24 +43,20 @@ endif
# Grub2 is kind of special: it considers CC, LD and so on to be the
# tools to build the native tools (i.e to be executed on the build
# machine), and uses TARGET_CC, TARGET_CFLAGS, TARGET_CPPFLAGS,
-# TARGET_LDFLAGS to build the bootloader itself. However, to add to
-# the confusion, it also uses NM, OBJCOPY and STRIP to build the
-# bootloader itself; none of these are used to build the native
-# tools.
+# TARGET_LDFLAGS to build the bootloader itself.
#
# NOTE: TARGET_STRIP is overridden by BR2_STRIP_none, so always
# use the cross compile variant to ensure grub2 builds

GRUB2_CONF_ENV = \
- $(HOST_CONFIGURE_OPTS) \
- CPP="$(HOSTCC) -E" \
+ CPP="$(TARGET_CC) -E" \
TARGET_CC="$(TARGET_CC)" \
TARGET_CFLAGS="$(TARGET_CFLAGS)" \
TARGET_CPPFLAGS="$(TARGET_CPPFLAGS)" \
TARGET_LDFLAGS="$(TARGET_LDFLAGS)" \
- NM="$(TARGET_NM)" \
- OBJCOPY="$(TARGET_OBJCOPY)" \
- STRIP="$(TARGET_CROSS)strip"
+ TARGET_NM="$(TARGET_NM)" \
+ TARGET_OBJCOPY="$(TARGET_OBJCOPY)" \
+ TARGET_STRIP="$(TARGET_CROSS)strip"

GRUB2_CONF_OPTS = \
--target=$(GRUB2_TARGET) \
@@ -75,13 +73,6 @@ define GRUB2_RUN_AUTOGEN
endef
GRUB2_PRE_CONFIGURE_HOOKS += GRUB2_RUN_AUTOGEN

-# We don't want all the native tools and Grub2 modules to be installed
-# in the target. So we in fact install everything into the host
-# directory, and the image generation process (below) will use the
-# grub-mkimage tool and Grub2 modules from the host directory.
-
-GRUB2_INSTALL_TARGET_OPTS = DESTDIR=$(HOST_DIR) install
-
ifeq ($(BR2_TARGET_GRUB2_I386_PC),y)
define GRUB2_IMAGE_INSTALL_ELTORITO
cat $(HOST_DIR)/usr/lib/grub/$(GRUB2_TUPLE)/cdboot.img $(GRUB2_IMAGE) > \
@@ -89,7 +80,7 @@ define GRUB2_IMAGE_INSTALL_ELTORITO
endef
endif

-define GRUB2_IMAGE_INSTALLATION
+define GRUB2_INSTALL_IMAGES_CMDS
mkdir -p $(dir $(GRUB2_IMAGE))
$(HOST_DIR)/usr/bin/grub-mkimage \
-d $(HOST_DIR)/usr/lib/grub/$(GRUB2_TUPLE) \
@@ -102,14 +93,13 @@ define GRUB2_IMAGE_INSTALLATION
$(INSTALL) -D -m 0644 boot/grub2/grub.cfg $(GRUB2_CFG)
$(GRUB2_IMAGE_INSTALL_ELTORITO)
endef
-GRUB2_POST_INSTALL_TARGET_HOOKS += GRUB2_IMAGE_INSTALLATION

ifeq ($(GRUB2_PLATFORM),efi)
define GRUB2_EFI_STARTUP_NSH
echo $(notdir $(GRUB2_IMAGE)) > \
$(BINARIES_DIR)/efi-part/startup.nsh
endef
-GRUB2_POST_INSTALL_TARGET_HOOKS += GRUB2_EFI_STARTUP_NSH
+GRUB2_POST_INSTALL_IMAGES_HOOKS += GRUB2_EFI_STARTUP_NSH
endif

$(eval $(autotools-package))
diff --git a/package/grub2-tools/grub2-tools.mk b/package/grub2-tools/grub2-tools.mk
index 8ed23f3..4dbd7ad 100644
--- a/package/grub2-tools/grub2-tools.mk
+++ b/package/grub2-tools/grub2-tools.mk
@@ -42,3 +42,4 @@ GRUB2_TOOLS_PRE_CONFIGURE_HOOKS += GRUB2_TOOLS_RUN_AUTOGEN
HOST_GRUB2_TOOLS_PRE_CONFIGURE_HOOKS += GRUB2_TOOLS_RUN_AUTOGEN

$(eval $(autotools-package))
+$(eval $(host-autotools-package))
--
2.9.3
Erico Nunes
2016-09-13 04:15:48 UTC
Permalink
This configuration can be used to provide a custom Grub 2 configuration
file containing menu entries. In the previous implementation, this had
to be always done by an external script, overwriting the defualt image.
This should be backwards compatible as the default value is the previous
hardcoded value.

Signed-off-by: Erico Nunes <***@gmail.com>
---
boot/grub2/Config.in | 7 +++++++
boot/grub2/grub2.mk | 5 +++--
2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/boot/grub2/Config.in b/boot/grub2/Config.in
index 527ff37..94862a6 100644
--- a/boot/grub2/Config.in
+++ b/boot/grub2/Config.in
@@ -196,4 +196,11 @@ config BR2_TARGET_GRUB2_BUILTIN_CONFIG
device and other configuration parameters, but however menu
entries cannot be described in this embedded configuration.

+config BR2_TARGET_GRUB2_CFG
+ string "grub2 menu entries config"
+ default "boot/grub2/grub.cfg"
+ help
+ Path to a Grub 2 configuration file containing the grub2 menu
+ entries.
+
endif # BR2_TARGET_GRUB2
diff --git a/boot/grub2/grub2.mk b/boot/grub2/grub2.mk
index 910967e..7a64b60 100644
--- a/boot/grub2/grub2.mk
+++ b/boot/grub2/grub2.mk
@@ -110,8 +110,9 @@ define GRUB2_INSTALL_IMAGES_CMDS
-p "$(GRUB2_PREFIX)" \
$(if $(GRUB2_BUILTIN_CONFIG),-c $(GRUB2_BUILTIN_CONFIG)) \
$(GRUB2_BUILTIN_MODULES)
- mkdir -p $(dir $(GRUB2_CFG))
- $(INSTALL) -D -m 0644 boot/grub2/grub.cfg $(GRUB2_CFG)
+ $(if $(BR2_TARGET_GRUB2_CFG), \
+ mkdir -p $(dir $(GRUB2_CFG)) && \
+ $(INSTALL) -D -m 0644 $(BR2_TARGET_GRUB2_CFG) $(GRUB2_CFG))
$(GRUB2_IMAGE_INSTALL_ELTORITO)
endef
--
2.9.3
Arnout Vandecappelle
2016-09-14 00:15:09 UTC
Permalink
Post by Erico Nunes
As a uboot platform, Grub 2 image gets built as a u-boot image (i.e.
u-boot mkimage) and is loaded from u-boot through a regular "bootm".
Perhaps a stupid question, but why would you want to do that? When you have a
working U-Boot, there is no need to stack Grub 2 on top of it, is there?

Regards,
Arnout
--
Arnout Vandecappelle arnout at mind be
Senior Embedded Software Architect +32-16-286500
Essensium/Mind http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint: 7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
Erico Nunes
2016-09-15 21:48:40 UTC
Permalink
Hi Arnout,
Post by Arnout Vandecappelle
Post by Erico Nunes
As a uboot platform, Grub 2 image gets built as a u-boot image (i.e.
u-boot mkimage) and is loaded from u-boot through a regular "bootm".
Perhaps a stupid question, but why would you want to do that? When you have a
working U-Boot, there is no need to stack Grub 2 on top of it, is there?
sounds like a valid question, as this was also a question in the video
in my third reference in this cover letter.
Depending on the case, if you can spare the bytes and effort to add
Grub 2 in the boot process, that makes it nicer for you to manage
different boot options, such as booting with different kernels or with
different bootargs. For example, at the very least with a common
Buildroot target you could have a menu entry to boot a kernel with
more verbose debug and another one to boot quietly. You don't even
have to choose it interactively in the serial console, with the
grub-reboot application you can tell grub to boot with a different
entry (such as the debug entry) just for the next boot. Of course that
you can do all that with u-boot only and make something similar with
the use of uboot-tools, but in my opinion this is much nicer to manage
with Grub 2 than having to mess with u-boot scripts or u-boot
environment variables for that. And there's the convenient menu too in
the serial, of course.

An additional reason is that the trend for new aarch64 server machines
is to standardize on EFI firmware, so certainly the aarch64-efi grub
platform can be useful for those.
And after we refactor our recipes for that (as in this patch series)
it is low effort to also have arm-uboot and arm-efi. arm-efi may more
convenient for boards that have mainline u-boot support as bootefi
will be there by default, but arm-uboot for now also has the advantage
that it doesn't require u-boot >= 2016.05.

My personal use case is that I'm interested in having other components
such as different kernel builds, and I want to be able to test them on
an aarch64 platform. In particular, I'd prefer to do that without
messing up too much with my working u-boot environment and without
having to stop in the u-boot shell for recovery in case something goes
wrong.

Erico
Thomas Petazzoni
2016-09-17 14:27:42 UTC
Permalink
Hello,
Post by Erico Nunes
grub2: bump up version
grub2-tools: new package
grub2: use grub2-tools as a host package
grub2: enable support for arm and aarch64 targets
grub2: introduce BR2_TARGET_GRUB2_CFG
Thanks for this work. Following all the comments received, I've marked
the patch series as Changes Requested in patchwork. Could you resend an
updated patch series that takes into account the comments?

Also, if you can post somewhere (in the new readme.txt file? or at
least in the commit log) how to test grub2 on ARM/AArch64, it would be
good.

Thanks a lot!

Thomas
--
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
Loading...