Skip to contentSkip to conversation

grub2: add support for arm and aarch64

PATCH New Erico Nunes 4 participants 15 messages Sep 13, 2016 – Sep 17, 2016

lore
Share & tools
lore
#0 lore raw

cover grub2: add support for arm and aarch64

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] https://www.youtube.com/watch?v=bNL1pd-rwCU

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
Signature · 1 line
2.9.3
#1 lore raw

PATCH 1/5 grub2: bump up version

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.

Patch boot/grub2/0001-remove-gets.patch doesn't seem to be required anymore as grub-core/gnulib/stdio.in.h has changed significantly since "053cfcd Import new gnulib." and has another treatment for gets. Patch boot/grub2/0002-grub-core-gettext-gettext.c-main_context-secondary_c.patch was a backport which is present after the bump and therefore is also no longer necessary.

---
 boot/grub2/0001-remove-gets.patch                  | 21 ------------
 ...ettext-gettext.c-main_context-secondary_c.patch | 39 ----------------------
 boot/grub2/grub2.hash                              |  4 +--
 boot/grub2/grub2.mk                                | 11 ++++--
 4 files changed, 10 insertions(+), 65 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
boot/grub2/0001-remove-gets.patch deleted +0 -21
deleted file mode 100644
index 0da71b3..0000000
@@ -1,21 +0,0 @@
-ISO C11 removes the specification of gets() from the C language, eglibc 2.16+ removed it
-
-Signed-off-by: Khem Raj <[email protected]>
-Signed-off-by: Thomas Petazzoni <[email protected]>
-
-Upstream-Status: Pending
-Index: grub-1.99/grub-core/gnulib/stdio.in.h
-===================================================================
---- grub-1.99.orig/grub-core/gnulib/stdio.in.h	2010-12-01 06:45:43.000000000 -0800
-+++ grub-1.99/grub-core/gnulib/stdio.in.h	2012-07-04 12:25:02.057099107 -0700
-@@ -140,8 +140,10 @@
- /* It is very rare that the developer ever has full control of stdin,
-    so any use of gets warrants an unconditional warning.  Assume it is
-    always declared, since it is required by C89.  */
-+#if defined gets
- #undef gets
- _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
-+#endif
- 
- #if @GNULIB_FOPEN@
- # if @REPLACE_FOPEN@
boot/grub2/0002-grub-core-gettext-gettext.c-main_context-secondary_c.patch deleted +0 -39
deleted file mode 100644
index 94be092..0000000
@@ -1,39 +0,0 @@
-From f30c692c1f9ef0e93bee2b408a24baa017f1ca9d Mon Sep 17 00:00:00 2001
-From: Vladimir Serbinenko <[email protected]>
-Date: Thu, 7 Nov 2013 01:01:47 +0100
-Subject: [PATCH] 	* grub-core/gettext/gettext.c (main_context),
- (secondary_context): 	Define after defining type and not before.
-
-[Thomas: backport from upstream commit
-f30c692c1f9ef0e93bee2b408a24baa017f1ca9d, and remove ChangeLog
-modifications to avoid conflicts.]
-Signed-off-by: Thomas Petazzoni <[email protected]>
----
- grub-core/gettext/gettext.c | 4 ++--
- 2 files changed, 7 insertions(+), 2 deletions(-)
-
-diff --git a/grub-core/gettext/gettext.c b/grub-core/gettext/gettext.c
-index df73570..4880cef 100644
---- a/grub-core/gettext/gettext.c
-+++ b/grub-core/gettext/gettext.c
-@@ -34,8 +34,6 @@ GRUB_MOD_LICENSE ("GPLv3+");
-    http://www.gnu.org/software/autoconf/manual/gettext/MO-Files.html .
- */
- 
--static struct grub_gettext_context main_context, secondary_context;
--
- static const char *(*grub_gettext_original) (const char *s);
- 
- struct grub_gettext_msg
-@@ -69,6 +67,8 @@ struct grub_gettext_context
-   struct grub_gettext_msg *grub_gettext_msg_list;
- };
- 
-+static struct grub_gettext_context main_context, secondary_context;
-+
- #define MO_MAGIC_NUMBER 		0x950412de
- 
- static grub_err_t
--- 
-2.7.4
-
boot/grub2/grub2.hash +2 -2
index 8883905..051a9ab 100644
@@ -1,2 +1,2 @@
-# Locally calculated after checking pgp signature
-sha256	784ec38e7edc32239ad75b8e66df04dc8bfb26d88681bc9f627133a6eb85c458	grub-2.00.tar.xz
+# Locally computed:
+sha256 680f584995cf318adb1ff8c40caef30d0ec7c03e16e88ba60bf5aa5b5a6e26ed grub2-4e0f8f66e321cf1051c0e01f6fbcc6fc35a807b6.tar.gz
boot/grub2/grub2.mk +8 -3
index dc4e51e..ecdf421 100644
@@ -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
+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
+	cd $(@D) && PATH=$(BR_PATH) ./autogen.sh
+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
Signature · 1 line
2.9.3
#2 lore raw

PATCH 1/5 grub2: bump up version

Quoted 8 lines · 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]

boot/grub2/grub2.mk line 8

Quoted 13 lines
boot/grub2/grub2.mk +2 -3
index dc4e51e..ecdf421 100644
@@ -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?

boot/grub2/grub2.mk GRUB2_CONF_OPTS = \ · line 76

Quoted 12 lines
boot/grub2/grub2.mk +5 -0
+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
+	cd $(@D) && PATH=$(BR_PATH) ./autogen.sh
+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

Quoted 5 lines
boot/grub2/grub2.mk +1 -0
+
 # 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
Signature · 6 lines
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
#3 lore raw

PATCH 1/5 grub2: bump up version

Hi Arnout,

thanks for the review!

Quoted 27 lines · Arnout Vandecappelle
Quoted 8 lines · 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]

boot/grub2/grub2.mk line 8

Quoted 13 lines
boot/grub2/grub2.mk +2 -3
index dc4e51e..ecdf421 100644
@@ -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...

Quoted 1 line

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.

Quoted 15 lines

boot/grub2/grub2.mk GRUB2_CONF_OPTS = \ · line 76

Quoted 12 lines
boot/grub2/grub2.mk +5 -0
+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
+     cd $(@D) && PATH=$(BR_PATH) ./autogen.sh
+endef
+GRUB2_PRE_CONFIGURE_HOOKS += GRUB2_RUN_AUTOGEN

Isn't there a possibility to use GRUB2_AUTORECONF = YES?

Quoted 6 lines

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.

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

#4 lore raw

PATCH 1/5 grub2: bump up version

Erico, Arnout, All,

On 2016-09-15 23:29 +0200, Erico Nunes spake thusly:

Quoted 19 lines · Arnout Vandecappelle
Quoted 18 lines · Erico Nunes
Quoted 8 lines

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]

Quoted 8 lines
boot/grub2/grub2.mk +0 -0
index dc4e51e..ecdf421 100644
@@ -4,9 +4,9 @@
 #
 ################################################################################
 
Quoted 8 lines
Quoted 8 lines

boot/grub2/grub2.mk line 8

Quoted 5 lines
boot/grub2/grub2.mk +2 -3
-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.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  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.  |
'------------------------------^-------^------------------^--------------------'
#5 lore raw

PATCH 2/5 grub2-tools: new package

In reply to Erico Nunes

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.

---
 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
package/Config.in +1 -0
index 332f05d..e8f90df 100644
@@ -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"
package/grub2-tools/Config.in new file +6 -0
new file mode 100644
index 0000000..9cc9e9c
@@ -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/
package/grub2-tools/grub2-tools.hash new file +2 -0
new file mode 100644
index 0000000..051a9ab
@@ -0,0 +1,2 @@
+# Locally computed:
+sha256 680f584995cf318adb1ff8c40caef30d0ec7c03e16e88ba60bf5aa5b5a6e26ed grub2-4e0f8f66e321cf1051c0e01f6fbcc6fc35a807b6.tar.gz
package/grub2-tools/grub2-tools.mk new file +44 -0

44 lines not on this page · raw message

Signature · 1 line
2.9.3
#6 lore raw

PATCH 3/5 grub2: use grub2-tools as a host package

In reply to Erico Nunes

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.

---
 boot/grub2/grub2.mk                | 30 ++++++++++--------------------
 package/grub2-tools/grub2-tools.mk |  1 +
 2 files changed, 11 insertions(+), 20 deletions(-)
boot/grub2/grub2.mk +10 -20
index ecdf421..8a063f1 100644
@@ -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))
package/grub2-tools/grub2-tools.mk +1 -0
index 8ed23f3..4dbd7ad 100644
@@ -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))
Signature · 1 line
2.9.3
#7 lore raw

PATCH 4/5 grub2: enable support for arm and aarch64 targets

In reply to 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.

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

---
 boot/grub2/Config.in | 48 +++++++++++++++++++++++++++++++++++++++---------
 boot/grub2/grub2.mk  | 23 ++++++++++++++++++++++-
 2 files changed, 61 insertions(+), 10 deletions(-)
boot/grub2/Config.in +39 -9
index 7dc5cae..527ff37 100644
@@ -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"
boot/grub2/grub2.mk +22 -1
index 8a063f1..910967e 100644
@@ -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)" \
Signature · 1 line
2.9.3
#8 lore raw

PATCH 4/5 grub2: enable support for arm and aarch64 targets

Quoted 55 lines · 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.

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

---
 boot/grub2/Config.in | 48 +++++++++++++++++++++++++++++++++++++++---------
 boot/grub2/grub2.mk  | 23 ++++++++++++++++++++++-
 2 files changed, 61 insertions(+), 10 deletions(-)
boot/grub2/Config.in +3 -3
index 7dc5cae..527ff37 100644
@@ -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

boot/grub2/Config.in config BR2_TARGET_GRUB2 · line 103

Quoted 10 lines
boot/grub2/Config.in +2 -2
@@ -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.

Quoted 18 lines
boot/grub2/Config.in +2 -0
@@ -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

boot/grub2/Config.in config BR2_TARGET_GRUB2_I386_EFI · line 144

Quoted 10 lines
boot/grub2/Config.in +4 -1
 	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.

Quoted 81 lines
boot/grub2/Config.in +28 -3
+	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"
boot/grub2/grub2.mk +21 -0
index 8a063f1..910967e 100644
@@ -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

boot/grub2/grub2.mk endif · line 107

Quoted 5 lines
boot/grub2/grub2.mk +1 -1
@@ -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/ \

Does this belong to this patch or the previous one?

Regards,
Arnout

Quoted 4 lines
boot/grub2/grub2.mk +0 -0
 		-O $(GRUB2_TUPLE) \
 		-o $(GRUB2_IMAGE) \
 		-p "$(GRUB2_PREFIX)" \
Signature · 6 lines
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
#9 lore raw

PATCH 4/5 grub2: enable support for arm and aarch64 targets

Hi Arnout,

thanks for the review!

Quoted 66 lines · Arnout Vandecappelle
Quoted 63 lines · 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.

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

---
 boot/grub2/Config.in | 48 +++++++++++++++++++++++++++++++++++++++---------
 boot/grub2/grub2.mk  | 23 ++++++++++++++++++++++-
 2 files changed, 61 insertions(+), 10 deletions(-)
boot/grub2/Config.in +5 -5
index 7dc5cae..527ff37 100644
@@ -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
+       ------------------------------------------
 
Quoted 7 lines

boot/grub2/Config.in config BR2_TARGET_GRUB2 · line 103

Quoted 2 lines
boot/grub2/Config.in +0 -0
        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.

Quoted 41 lines
Quoted 18 lines
boot/grub2/Config.in +2 -0
@@ -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

boot/grub2/Config.in config BR2_TARGET_GRUB2_I386_EFI · line 144

Quoted 10 lines
boot/grub2/Config.in +4 -1
      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
Quoted 5 lines

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?

Quoted 79 lines
Quoted 79 lines
boot/grub2/Config.in +28 -3
+     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"
boot/grub2/grub2.mk +21 -0
index 8a063f1..910967e 100644
@@ -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
 
Quoted 9 lines

boot/grub2/grub2.mk endif · line 107

Quoted 7 lines
boot/grub2/grub2.mk +1 -1
 # 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/ \

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

#10 lore raw

PATCH 4/5 grub2: enable support for arm and aarch64 targets

In reply to Arnout Vandecappelle

Hello,

Quoted 7 lines · Arnout Vandecappelle

boot/grub2/Config.in config BR2_TARGET_GRUB2 · line 103

Quoted 2 lines
boot/grub2/Config.in +0 -0
 	  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

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
#11 lore raw

PATCH 5/5 grub2: introduce BR2_TARGET_GRUB2_CFG

In reply to Erico Nunes

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.

---
 boot/grub2/Config.in | 7 +++++++
 boot/grub2/grub2.mk  | 5 +++--
 2 files changed, 10 insertions(+), 2 deletions(-)
boot/grub2/Config.in +7 -0
index 527ff37..94862a6 100644
@@ -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
boot/grub2/grub2.mk +3 -2
index 910967e..7a64b60 100644
@@ -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
 
Signature · 1 line
2.9.3
#12 lore raw

cover grub2: add support for arm and aarch64

In reply to Erico Nunes
Quoted 2 lines · 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

Signature · 6 lines
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
#13 lore raw

cover grub2: add support for arm and aarch64

Hi Arnout,

Quoted 6 lines · Arnout Vandecappelle
Quoted 2 lines · 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

#14 lore raw

cover grub2: add support for arm and aarch64

In reply to Erico Nunes

Hello,

Quoted 6 lines · Erico Nunes

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

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

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com