Skip to contentSkip to conversation

grub2: add support for arm and aarch64

PATCH New Erico Nunes 2 participants 11 messages Sep 26, 2018 – Nov 26, 2018

lore
Share & tools
lore
#0 lore raw

v3 cover grub2: add support for arm and aarch64

This series adds arm and aarch64 support to grub2.
First, a refactor of the recipe is performed, to better separate the host and target builds, which right now are happening in the same step and are confusing to deal with.
This is achieved by introducing host-grub2 to build the host tools and just build everything to the target on the target grub2 package.

Then support is added for arm and aarch64, along with a new defconfig that makes it used somewhere, and some documentation.

I've had this branch for such a long time, v2 was over a year ago, we even discussed about this in last year's developer meeting. I had already done some improvements there but unfortunately I don't recall if all of the suggestions are here.
I finally took the time to rebase it and retest, sorry for the delay. The most significant improvement since v2 is to drop grub2-tools and concentrate everything on the grub2 package.

This time it was runtime tested with qemu and the aarch64_efi, pc_x86_64_bios and pc_x86_64_efi defconfigs, as well as build tested with test-pkg using all available configurations:

$ cat grub-test.config
BR2_TARGET_GRUB2=y
BR2_TARGET_GRUB2_INSTALL_TOOLS=y
$ utils/test-pkg -a -c grub-test.config -p grub2
                armv5-ctng-linux-gnueabi [ 1/47]: OK
              armv7-ctng-linux-gnueabihf [ 2/47]: OK
                        br-aarch64-glibc [ 3/47]: OK
                           br-arcle-hs38 [ 4/47]: SKIPPED
                            br-arm-basic [ 5/47]: SKIPPED
                  br-arm-cortex-a9-glibc [ 6/47]: OK
                   br-arm-cortex-a9-musl [ 7/47]: OK
                   br-arm-cortex-m4-full [ 8/47]: SKIPPED
                             br-arm-full [ 9/47]: OK
                    br-arm-full-nothread [10/47]: OK
                      br-arm-full-static [11/47]: OK
                   br-i386-pentium4-full [12/47]: OK
                br-i386-pentium-mmx-musl [13/47]: OK
                       br-m68k-5208-full [14/47]: SKIPPED
                      br-m68k-68040-full [15/47]: SKIPPED
                    br-microblazeel-full [16/47]: SKIPPED
                 br-mips32r6-el-hf-glibc [17/47]: SKIPPED
                      br-mips64-n64-full [18/47]: SKIPPED
                 br-mips64r6-el-hf-glibc [19/47]: SKIPPED
                      br-mipsel-o32-full [20/47]: SKIPPED
                          br-nios2-glibc [21/47]: SKIPPED
                      br-openrisc-uclibc [22/47]: SKIPPED
               br-powerpc-603e-basic-cpp [23/47]: SKIPPED
             br-powerpc64le-power8-glibc [24/47]: SKIPPED
               br-powerpc64-power7-glibc [25/47]: SKIPPED
                  br-powerpc-e500mc-full [26/47]: SKIPPED
                             br-sh4-full [27/47]: SKIPPED
                        br-sparc64-glibc [28/47]: SKIPPED
                         br-sparc-uclibc [29/47]: SKIPPED
                    br-x86-64-core2-full [30/47]: OK
                          br-x86-64-musl [31/47]: OK
                          br-xtensa-full [32/47]: SKIPPED
                     i686-ctng-linux-gnu [33/47]: OK
                       linaro-aarch64-be [34/47]: SKIPPED
                          linaro-aarch64 [35/47]: OK
                              linaro-arm [36/47]: OK
             mips64el-ctng_n32-linux-gnu [37/47]: SKIPPED
             mips64el-ctng_n64-linux-gnu [38/47]: SKIPPED
        powerpc-ctng_e500v2-linux-gnuspe [39/47]: SKIPPED
                     sourcery-arm-armv4t [40/47]: OK
                            sourcery-arm [41/47]: OK
                     sourcery-arm-thumb2 [42/47]: OK
                         sourcery-mips64 [43/47]: SKIPPED
                           sourcery-mips [44/47]: SKIPPED
                          sourcery-nios2 [45/47]: SKIPPED
                         sourcery-x86-64 [46/47]: OK
           x86_64-ctng_locales-linux-gnu [47/47]: OK
47 builds, 27 skipped, 0 build failed, 0 legal-info failed

Some references:

[1] https://www.hellion.org.uk/blog/posts/grub-on-uboot-on-qemu/
[2] https://www.kraxel.org/repos/jenkins/edk2/
[3] https://www.youtube.com/watch?v=bNL1pd-rwCU

Changes v2 -> v3:
- grub2 version bump patch dropped as it was already applied in v2.
- Dropped the grub2-tools separate package and host-grub2-tools, in favour of just host-grub2. In the previous proposal, everything was built twice and it was confusing because grub2-tools also installed modules to the target. The new proposal is probably simpler as everything is built once and only the installation of optional bits to the target is optional, in case the user wants to save space.
- Added aarch64_efi_defconfig config so that we have a qemu-bootable defconfig to catch build issues with grub2 for aarch64.
- Added dependency on BR2_USE_MMU to skip builds on arm nommu.

Changes v1 -> v2:
- Update to the 2.02 release, this settles the questions about using git master or a beta release, as it is now an official release.
- Moved the grub2 additional documentation from its Config.in to a readme.txt in the package directory as it was discussed in v1.
- Added grub2 extra documentation for arm and aarch64.
- Fixed small bugs such as the lack of depends on wchar.
- Re-tested everything, including pc_* defconfigs, except BeagleBone (lots of extra work, not my primary target, and nothing changed on the arm-efi part).
Odroid-C2 works much more nicely with u-boot bootefi + grub2 aarch64-efi now that it has better u-boot/kernel upstream support.
- The Image.gz format for linux aarch64.

Erico Nunes (5):
grub2: separate target and host builds
grub2: add option to install tools
grub2: enable support for arm and aarch64 targets configs/aarch64_efi_defconfig: new defconfig
grub2: add usage notes for grub2 arm and aarch64

 board/aarch64-efi/genimage-efi.cfg |  30 +++++++
 board/aarch64-efi/grub.cfg         |   6 ++
 board/aarch64-efi/post-image.sh    |   5 ++
 board/aarch64-efi/readme.txt       |  17 ++++
 boot/grub2/Config.in               |  50 ++++++++++-
 boot/grub2/grub2.mk                |  74 ++++++++++-----
 boot/grub2/readme.txt              | 140 ++++++++++++++++++++++++++++-
 configs/aarch64_efi_defconfig      |  33 +++++++
 support/scripts/check-bin-arch     |   4 +
 9 files changed, 328 insertions(+), 31 deletions(-)
 create mode 100644 board/aarch64-efi/genimage-efi.cfg
 create mode 100644 board/aarch64-efi/grub.cfg
 create mode 100755 board/aarch64-efi/post-image.sh
 create mode 100644 board/aarch64-efi/readme.txt
 create mode 100644 configs/aarch64_efi_defconfig
Signature · 1 line
2.17.1
#1 lore raw

PATCH v3 1/5 grub2: separate target and host builds

grub2 requires the host grub2-mkimage tool to build some of its target images. The current way of building this tool in the grub2 package is to perform a simultaneous host-tools/target-bootloader build during the grub2 build step.
This method makes the recipe complex to understand, and proved to be a complication during work to enable grub2 support for other architectures than x86.
This patch tries to do a better separation between the build of grub2 host tools and target boot loader image, as a partial step to enable grub2 to build for other architectures.

---
 boot/grub2/grub2.mk | 48 +++++++++++++++++++++++----------------------
 1 file changed, 25 insertions(+), 23 deletions(-)
boot/grub2/grub2.mk +25 -23
index 35aea41287..1b366d0407 100644
@@ -9,7 +9,10 @@ GRUB2_SITE = http://ftp.gnu.org/gnu/grub
 GRUB2_SOURCE = grub-$(GRUB2_VERSION).tar.xz
 GRUB2_LICENSE = GPL-3.0+
 GRUB2_LICENSE_FILES = COPYING
-GRUB2_DEPENDENCIES = host-bison host-flex
+GRUB2_DEPENDENCIES = host-bison host-flex host-grub2
+HOST_GRUB2_DEPENDENCIES = host-bison host-flex
+GRUB2_INSTALL_IMAGES = YES
+GRUB2_INSTALL_TARGET = NO
 
 GRUB2_BUILTIN_MODULES = $(call qstrip,$(BR2_TARGET_GRUB2_BUILTIN_MODULES))
 GRUB2_BUILTIN_CONFIG = $(call qstrip,$(BR2_TARGET_GRUB2_BUILTIN_CONFIG))
@@ -39,26 +42,24 @@ GRUB2_PLATFORM = efi
 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.
+# tools to build the host programs and uses TARGET_CC, TARGET_CFLAGS,
+# TARGET_CPPFLAGS, TARGET_LDFLAGS to build the bootloader itself.
 #
 # NOTE: TARGET_STRIP is overridden by !BR2_STRIP_strip, so always
 # use the cross compile variant to ensure grub2 builds
 
+HOST_GRUB2_CONF_ENV = \
+	CPP="$(HOSTCC) -E"
+
 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) -fno-stack-protector" \
 	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) \
@@ -72,12 +73,13 @@ GRUB2_CONF_OPTS = \
 	--enable-libzfs=no \
 	--disable-werror
 
-# 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
+HOST_GRUB2_CONF_OPTS = \
+	--disable-grub-mkfont \
+	--enable-efiemu=no \
+	ac_cv_lib_lzma_lzma_code=no \
+	--enable-device-mapper=no \
+	--enable-libzfs=no \
+	--disable-werror
 
 ifeq ($(BR2_TARGET_GRUB2_I386_PC),y)
 define GRUB2_IMAGE_INSTALL_ELTORITO
@@ -86,10 +88,10 @@ define GRUB2_IMAGE_INSTALL_ELTORITO
 endef
 endif
 
-define GRUB2_IMAGE_INSTALLATION
+define GRUB2_INSTALL_IMAGES_CMDS
 	mkdir -p $(dir $(GRUB2_IMAGE))
-	$(HOST_DIR)/bin/grub-mkimage \
-		-d $(HOST_DIR)/lib/grub/$(GRUB2_TUPLE) \
+	$(HOST_DIR)/usr/bin/grub-mkimage \
+		-d $(@D)/grub-core/ \
 		-O $(GRUB2_TUPLE) \
 		-o $(GRUB2_IMAGE) \
 		-p "$(GRUB2_PREFIX)" \
@@ -99,14 +101,14 @@ 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))
+$(eval $(host-autotools-package))
Signature · 1 line
2.17.1
#2 lore raw

PATCH v3 1/5 grub2: separate target and host builds

Hello,

Quoted 11 lines · Erico Nunes

grub2 requires the host grub2-mkimage tool to build some of its target images. The current way of building this tool in the grub2 package is to perform a simultaneous host-tools/target-bootloader build during the grub2 build step.
This method makes the recipe complex to understand, and proved to be a complication during work to enable grub2 support for other architectures than x86.
This patch tries to do a better separation between the build of grub2 host tools and target boot loader image, as a partial step to enable grub2 to build for other architectures.

Quoted 4 lines
---
 boot/grub2/grub2.mk | 48 +++++++++++++++++++++++----------------------
 1 file changed, 25 insertions(+), 23 deletions(-)

Applied to next, thanks.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#3 lore raw

PATCH v3 2/5 grub2: add option to install tools

In reply to Erico Nunes

Add an option to install grub2 support tools to the target.

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

---
 boot/grub2/Config.in           | 8 ++++++++
 boot/grub2/grub2.mk            | 5 +++++
 support/scripts/check-bin-arch | 4 ++++
 3 files changed, 17 insertions(+)
boot/grub2/Config.in +8 -0
index 9a61b3b633..f760f95e84 100644
@@ -76,6 +76,14 @@ 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_INSTALL_TOOLS
+	bool "install grub2 tools"
+	help
+	  Install support tools to interact with GNU GRUB Multiboot boot
+	  loader.
+	  This will also install the Grub 2 loadable modules to the
+	  target.
+
 endif # BR2_TARGET_GRUB2
 
 comment "grub2 needs a toolchain w/ wchar"
boot/grub2/grub2.mk +5 -0
index 1b366d0407..bb678ef5de 100644
@@ -12,7 +12,12 @@ GRUB2_LICENSE_FILES = COPYING
 GRUB2_DEPENDENCIES = host-bison host-flex host-grub2
 HOST_GRUB2_DEPENDENCIES = host-bison host-flex
 GRUB2_INSTALL_IMAGES = YES
+
+ifeq ($(BR2_TARGET_GRUB2_INSTALL_TOOLS),y)
+GRUB2_INSTALL_TARGET = YES
+else
 GRUB2_INSTALL_TARGET = NO
+endif
 
 GRUB2_BUILTIN_MODULES = $(call qstrip,$(BR2_TARGET_GRUB2_BUILTIN_MODULES))
 GRUB2_BUILTIN_CONFIG = $(call qstrip,$(BR2_TARGET_GRUB2_BUILTIN_CONFIG))
support/scripts/check-bin-arch +4 -0
index 7f97696735..66b8d89932 100755
@@ -20,6 +20,10 @@ declare -a IGNORES=(
 	# pru-software-support) legitimately install ELF binaries that
 	# are not for the target architecture
 	"/usr/share"
+
+	# Skip files in /lib/grub, since it is possible to have it
+	# for a different architecture (e.g. i386 grub on x86_64).
+	"/lib/grub"
 )
 
 while getopts p:l:r:a:i: OPT ; do
Signature · 1 line
2.17.1
#4 lore raw

PATCH v3 2/5 grub2: add option to install tools

Hello,

Quoted 6 lines · Erico Nunes

Add an option to install grub2 support tools to the target.

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

Quoted 6 lines
---
 boot/grub2/Config.in           | 8 ++++++++
 boot/grub2/grub2.mk            | 5 +++++
 support/scripts/check-bin-arch | 4 ++++
 3 files changed, 17 insertions(+)

Applied to next, thanks.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#5 lore raw

PATCH v3 3/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 grub2 platforms in Buildroot.

With the uboot platform, the grub2 image gets built as a u-boot image and is loaded from u-boot through a regular "bootm". The only requirement from the 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).

With the efi platform, grub2 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 uboot 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.

---
 boot/grub2/Config.in | 42 ++++++++++++++++++++++++++++++++++++++----
 boot/grub2/grub2.mk  | 21 +++++++++++++++++++++
 2 files changed, 59 insertions(+), 4 deletions(-)
boot/grub2/Config.in +38 -4
index f760f95e84..5e0e47a5bb 100644
@@ -2,10 +2,13 @@ config BR2_TARGET_GRUB2_ARCH_SUPPORTS
 	bool
 	default y if BR2_i386
 	default y if BR2_x86_64
+	default y if BR2_arm
+	default y if BR2_aarch64
 
 config BR2_TARGET_GRUB2
 	bool "grub2"
 	depends on BR2_TARGET_GRUB2_ARCH_SUPPORTS
+	depends on BR2_USE_MMU
 	depends on BR2_USE_WCHAR
 	help
 	  GNU GRUB is a Multiboot boot loader. It was derived from
@@ -29,12 +32,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
@@ -42,14 +47,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"
@@ -60,13 +89,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"
@@ -88,4 +121,5 @@ endif # BR2_TARGET_GRUB2
 
 comment "grub2 needs a toolchain w/ wchar"
 	depends on BR2_TARGET_GRUB2_ARCH_SUPPORTS
+	depends on BR2_USE_MMU
 	depends on !BR2_USE_WCHAR
boot/grub2/grub2.mk +21 -0
index bb678ef5de..65371f0170 100644
@@ -44,6 +44,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/grub.img
+GRUB2_CFG = $(BINARIES_DIR)/boot-part/grub/grub.cfg
+GRUB2_PREFIX = ($(GRUB2_BOOT_PARTITION))/boot/grub
+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
Signature · 1 line
2.17.1
#6 lore raw

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

Hello,

boot/grub2/Config.in config BR2_TARGET_GRUB2_ARCH_SUPPORTS · line 6

Quoted 10 lines · Erico Nunes
boot/grub2/Config.in +2 -0
index f760f95e84..5e0e47a5bb 100644
@@ -2,10 +2,13 @@ config BR2_TARGET_GRUB2_ARCH_SUPPORTS
 	bool
 	default y if BR2_i386
 	default y if BR2_x86_64
+	default y if BR2_arm
+	default y if BR2_aarch64

... here!

boot/grub2/Config.in config BR2_TARGET_GRUB2_ARCH_SUPPORTS · line 11

Quoted 5 lines
boot/grub2/Config.in +1 -0
 config BR2_TARGET_GRUB2
 	bool "grub2"
 	depends on BR2_TARGET_GRUB2_ARCH_SUPPORTS
+	depends on BR2_USE_MMU

I have moved this architecture dependency up here...

boot/grub2/Config.in config BR2_TARGET_GRUB2_BOOT_PARTITION · line 100

Quoted 8 lines
boot/grub2/Config.in +3 -1
 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 || \\

There was a double backslash here, I simplified to a single backslash and also reformatted this a bit.

boot/grub2/Config.in

Quoted 3 lines

comment "grub2 needs a toolchain w/ wchar"

boot/grub2/Config.in +1 -0
 	depends on BR2_TARGET_GRUB2_ARCH_SUPPORTS
+	depends on BR2_USE_MMU

This dependency is no longer needed, since BR2_USE_MMU is now part of BR2_TARGET_GRUB2_ARCH_SUPPORTS.

Applied to next with those changes!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#7 lore raw

PATCH v3 4/5 configs/aarch64_efi_defconfig: new defconfig

In reply to Erico Nunes

New generic defconfig for aarch64, to run on aarch64 servers compliant with EFI firmware and ACPI.
This can also be tested with qemu, and is useful so that we have an arm defconfig with grub enabled.
Tested with qemu 2.11.2 and AAVMF, the aarch64 virtual machine UEFI firmware.

---
 board/aarch64-efi/genimage-efi.cfg | 30 +++++++++++++++++++++++++++
 board/aarch64-efi/grub.cfg         |  6 ++++++
 board/aarch64-efi/post-image.sh    |  5 +++++
 board/aarch64-efi/readme.txt       | 17 +++++++++++++++
 configs/aarch64_efi_defconfig      | 33 ++++++++++++++++++++++++++++++
 5 files changed, 91 insertions(+)
 create mode 100644 board/aarch64-efi/genimage-efi.cfg
 create mode 100644 board/aarch64-efi/grub.cfg
 create mode 100755 board/aarch64-efi/post-image.sh
 create mode 100644 board/aarch64-efi/readme.txt
 create mode 100644 configs/aarch64_efi_defconfig
board/aarch64-efi/genimage-efi.cfg new file +30 -0
new file mode 100644
index 0000000000..f93ab9d64f
@@ -0,0 +1,30 @@
+image efi-part.vfat {
+  vfat {
+    file startup.nsh {
+      image = "efi-part/startup.nsh"
+    }
+    file EFI {
+      image = "efi-part/EFI"
+    }
+    file Image {
+      image = "Image"
+    }
+  }
+  size = 32M
+}
+
+image disk.img {
+
+  hdimage {
+  }
+
+  partition boot {
+    partition-type = 0xEF
+    image = "efi-part.vfat"
+  }
+
+  partition root {
+    partition-type = 0x83
+    image = "rootfs.ext2"
+  }
+}
board/aarch64-efi/grub.cfg new file +6 -0
new file mode 100644
index 0000000000..ab88da91b9
@@ -0,0 +1,6 @@
+set default="0"
+set timeout="5"
+
+menuentry "Buildroot" {
+	linux /Image root=/dev/vda2 rootwait console=ttyAMA0
+}
board/aarch64-efi/post-image.sh new file +5 -0
new file mode 100755
index 0000000000..f0214dc866
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+BOARD_DIR="$(dirname $0)"
+
+cp -f ${BOARD_DIR}/grub.cfg ${BINARIES_DIR}/efi-part/EFI/BOOT/grub.cfg
board/aarch64-efi/readme.txt new file +17 -0
new file mode 100644
index 0000000000..e62278f6d2
@@ -0,0 +1,17 @@
+Run the emulation with:
+
+qemu-system-aarch64 \
+	-M virt \
+	-cpu cortex-a57 \
+	-m 512 \
+	-nographic \
+	-bios </path/to/QEMU_EFI.fd> \
+	-drive file=output/images/disk.img,if=none,format=raw,id=hd0 \
+	-device virtio-blk-device,drive=hd0 \
+	-netdev user,id=eth0 \
+	-device virtio-net-device,netdev=eth0
+
+Note that </path/to/QEMU_EFI.fd> needs to point to a valid aarch64 UEFI
+firmware image for qemu.
+It may be provided by your distribution as a edk2-aarch64 or AAVMF
+package, in path such as /usr/share/edk2/aarch64/QEMU_EFI.fd .
configs/aarch64_efi_defconfig new file +33 -0
new file mode 100644
index 0000000000..e4e20b09ba
@@ -0,0 +1,33 @@
+# Architecture
+BR2_aarch64=y
+
+# Toolchain, required for eudev and grub
+BR2_TOOLCHAIN_BUILDROOT_WCHAR=y
+
+# System
+BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
+BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_EUDEV=y
+
+## Required tools to create bootable media
+BR2_PACKAGE_HOST_GENIMAGE=y
+
+# Bootloader
+BR2_TARGET_GRUB2=y
+BR2_TARGET_GRUB2_AARCH64_EFI=y
+
+# Filesystem / image
+BR2_TARGET_ROOTFS_EXT2=y
+BR2_TARGET_ROOTFS_EXT2_4=y
+BR2_TARGET_ROOTFS_EXT2_SIZE="200M"
+# BR2_TARGET_ROOTFS_TAR is not set
+BR2_ROOTFS_POST_IMAGE_SCRIPT="board/aarch64-efi/post-image.sh support/scripts/genimage.sh"
+BR2_ROOTFS_POST_SCRIPT_ARGS="-c board/aarch64-efi/genimage-efi.cfg"
+
+# Linux headers same as kernel, a 4.18 series
+BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_18=y
+
+# Kernel
+BR2_LINUX_KERNEL=y
+BR2_LINUX_KERNEL_CUSTOM_VERSION=y
+BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.18.10"
+BR2_LINUX_KERNEL_USE_ARCH_DEFAULT_CONFIG=y
Signature · 1 line
2.17.1
#8 lore raw

PATCH v3 4/5 configs/aarch64_efi_defconfig: new defconfig

Hello,

Quoted 8 lines · Erico Nunes

New generic defconfig for aarch64, to run on aarch64 servers compliant with EFI firmware and ACPI.
This can also be tested with qemu, and is useful so that we have an arm defconfig with grub enabled.
Tested with qemu 2.11.2 and AAVMF, the aarch64 virtual machine UEFI firmware.

Quoted 12 lines
---
 board/aarch64-efi/genimage-efi.cfg | 30 +++++++++++++++++++++++++++
 board/aarch64-efi/grub.cfg         |  6 ++++++
 board/aarch64-efi/post-image.sh    |  5 +++++
 board/aarch64-efi/readme.txt       | 17 +++++++++++++++
 configs/aarch64_efi_defconfig      | 33 ++++++++++++++++++++++++++++++
 5 files changed, 91 insertions(+)
 create mode 100644 board/aarch64-efi/genimage-efi.cfg
 create mode 100644 board/aarch64-efi/grub.cfg
 create mode 100755 board/aarch64-efi/post-image.sh
 create mode 100644 board/aarch64-efi/readme.txt
 create mode 100644 configs/aarch64_efi_defconfig

I've extended a bit the readme.txt to explain that this defconfig is not just for Qemu testing, but also for real HW, and applied to next. Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#9 lore raw

PATCH v3 5/5 grub2: add usage notes for grub2 arm and aarch64

In reply to Erico Nunes

Add notes to test grub2 running on ARM using qemu. The arm section describes how to run it using u-boot and aarch64 shows how to do it using efi, which is similar to what has to be done for x86_64.

The source for OVMF builds is also changed to
https://www.kraxel.org/repos/jenkins/edk2/ which is the source for nightly builds (as rpms but which can be extracted in any distribution), as the sourceforge link provided only very old builds.

---
 boot/grub2/readme.txt | 140 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 136 insertions(+), 4 deletions(-)
boot/grub2/readme.txt +136 -4
index f6fd4566fe..9d8448f866 100644
@@ -53,8 +53,8 @@ To test your BIOS image in Qemu
 
 qemu-system-{i386,x86-64} -hda disk.img
 
-Notes on using Grub2 for EFI-based platforms
-============================================
+Notes on using Grub2 for x86/x86_64 EFI-based platforms
+=======================================================
 
 1. Create a disk image
    dd if=/dev/zero of=disk.img bs=1M count=32
@@ -83,16 +83,148 @@ Notes on using Grub2 for EFI-based platforms
    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
    platform (i386-efi vs. x86-64-efi)
-   http://sourceforge.net/projects/edk2/files/OVMF/
+   https://www.kraxel.org/repos/jenkins/edk2/
+   (or use one provided by your distribution as OVMF)
 2. Extract, and rename OVMF.fd to bios.bin and
    CirrusLogic5446.rom to vgabios-cirrus.bin.
 3. qemu-system-{i386,x86-64} -L ovmf-dir/ -hda disk.img
 4. Make sure to pass pci=nocrs to the kernel command line,
    to workaround a bug in the EFI BIOS regarding the
    EFI framebuffer.
+
+Notes on using Grub2 for ARM u-boot-based platforms
+===================================================
+
+The following steps are used to exemplify the arm-uboot platform working in the
+simplest way possible and with a single buildroot-generated filesystem. The
+steps can of course be adapted to have a more common setup (i.e. with a
+separate boot partition).
+
+ 1. Load qemu_arm_vexpress_defconfig
+ 2. Enable u-boot with the vexpress_ca9x4 board name and with u-boot.elf image
+    format.
+ 3. Enable grub2 for the arm-uboot platform.
+ 4. Enable "Install kernel image to /boot in target" in the kernel menu to
+    populate a /boot directory with zImage in it.
+ 5. The upstream u-boot vexpress_ca9x4 doesn't have CONFIG_API enabled by
+    default, which is required.
+    Before building, patch u-boot (for example, make u-boot-extract to edit the
+    source before buildling) file include/configs/vexpress_common.h to define:
+
+    #define CONFIG_API
+    #define CONFIG_SYS_MMC_MAX_DEVICE   1
+
+ 6. Create a custom grub2 menu entries config file with the following contents
+    and set its path in BR2_TARGET_GRUB2_CFG:
+
+    set default="0"
+    set timeout="5"
+
+    menuentry "Buildroot" {
+        set root='(hd0)'
+        linux /boot/zImage root=/dev/mmcblk0 console=ttyAMA0
+        devicetree /boot/vexpress-v2p-ca9.dtb
+    }
+
+ 7. Create a custom builtin config file with the following contents and set its
+    path in BR2_TARGET_GRUB2_BUILTIN_CONFIG:
+
+    set root=(hd0)
+    set prefix=/boot/grub
+
+ 8. Create a custom post-build script which copies files from
+    ${BINARIES_DIR}/boot-part to $(TARGET_DIR)/boot (set its path in
+    BR2_ROOTFS_POST_BUILD_SCRIPT):
+
+    #!/bin/sh
+    cp -r ${BINARIES_DIR}/boot-part/* ${TARGET_DIR}/boot/
+
+ 9. make
+10. Run qemu with:
+
+    qemu-system-arm -M vexpress-a9 -kernel output/images/u-boot -m 1024 \
+    -nographic -sd output/images/rootfs.ext2
+
+11. In u-boot, stop at the prompt and run grub2 with:
+
+  => ext2load mmc 0:0 ${loadaddr} /boot/grub/grub.img
+  => bootm
+
+12. This should bring the grub2 menu, upon which selecting the "Buildroot"
+    entry should boot Linux.
+
+
+Notes on using Grub2 for Aarch64 EFI-based platforms
+====================================================
+
+The following steps are used to exemplify the arm64-efi platform with the use
+of qemu and EFI firmware built for qemu.
+
+ 1. Load qemu_aarch64_virt_defconfig
+ 2. Enable grub2 for the arm64-efi platform.
+ 3. Create a custom grub2 menu entries config file with the following contents
+    and set its path in BR2_TARGET_GRUB2_CFG:
+
+    set default="0"
+    set timeout="5"
+    menuentry "Buildroot" {
+        linux /Image console=ttyAMA0
+    }
+
+ 4. Enable host genimage and create a genimage.cfg script which creates the
+    disk image containing a EFI system partition:
+
+    image efi-part.vfat {
+      vfat {
+        file startup.nsh {
+          image = "efi-part/startup.nsh"
+        }
+        file EFI {
+          image = "efi-part/EFI"
+        }
+        file Image {
+          image = "Image"
+        }
+      }
+      size = 16M
+    }
+    image disk.img {
+      hdimage {
+      }
+      partition boot {
+        partition-type = 0xEF
+        image = "efi-part.vfat"
+      }
+    }
+
+ 5. Create a custom post-image script  (set its path in BR2_ROOTFS_POST_IMAGE_SCRIPT):
+
+    BOARD_DIR="$(dirname $0)"
+    GENIMAGE_CFG="${BOARD_DIR}/genimage.cfg"
+    GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"
+    rm -rf "${GENIMAGE_TMP}"
+    genimage                              \
+           --rootpath "${TARGET_DIR}"     \
+           --tmppath "${GENIMAGE_TMP}"    \
+           --inputpath "${BINARIES_DIR}"  \
+           --outputpath "${BINARIES_DIR}" \
+           --config "${GENIMAGE_CFG}"
+
+ 6. Download the EFI firmware for qemu aarch64
+    https://www.kraxel.org/repos/jenkins/edk2/
+    (or use one provided by your distribution as OVMF-aarch64 or AAVMF)
+
+ 7. Run qemu with:
+
+    qemu-system-aarch64 -M virt -cpu cortex-a57 -m 512 -nographic \
+    -bios <path/to/EDK2>/QEMU_EFI.fd -hda output/images/disk.img \
+    -netdev user,id=eth0 -device virtio-net-device,netdev=eth0
+
+ 8. This should bring the grub2 menu, upon which selecting the "Buildroot"
+    entry should boot Linux.
Signature · 1 line
2.17.1
#10 lore raw

PATCH v3 5/5 grub2: add usage notes for grub2 arm and aarch64

Hello,

Quoted 9 lines · Erico Nunes

Add notes to test grub2 running on ARM using qemu. The arm section describes how to run it using u-boot and aarch64 shows how to do it using efi, which is similar to what has to be done for x86_64.

The source for OVMF builds is also changed to
https://www.kraxel.org/repos/jenkins/edk2/ which is the source for nightly builds (as rpms but which can be extracted in any distribution), as the sourceforge link provided only very old builds.

Quoted 4 lines
---
 boot/grub2/readme.txt | 140 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 136 insertions(+), 4 deletions(-)

I'm not sure why you gave all those details for the AArch64/EFI case, instead of just pointing to your aarch64_efi_defconfig configuration. So I've simplified this part to use aarch64_efi_defconfig instead, did some minor formatting fixes here and there, and applied to next. Thanks!

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com