GRUB on AArch64

Currently, development is taking place cross-compiled on amd64, running under the freely (as in beer, with registration) available Foundation Model. GRUB on AArch64 is currently supported only when run under UEFI.

Setting up the model environment

The Foundation model is available for download from ARM (with registration) here. The version used here is 'build 0.8.5206', released November 2013. Register and download the foundation model to an amd64 Linux computer.

$ tar xzf ~/FM000-KT-00035-r0p8-52rel06.tgz
$

Done - you now have a directory called Foundation_v8pkg containing the model components.

Obtaining a UEFI image

Build your own

You can build your own image from mainline TianoCore sources by following Olivier Martin's guide at: http://sourceforge.net/apps/mediawiki/tianocore/index.php?title=ArmPlatformPkg/AArch64

Download a prebuilt Linaro image

Linaro provides prebuilt binary UEFI images for various platforms, created from pure upstream Tianocore EDK2 plus some platform support and other not-yet-merged features. The set of images for December 2013 contain all support required to run GRUB on the foundation model, and can be found here.

Download uefi_foundation.bin and uefi-bootstrap-el3-foundation.axf.

Testing your setup

If run locally, or there is a working X forwarding session, the foundation model launches an xterm providing the output of the emulated serial console (ttyAMA0). If not, it listens to telnet connections on port 5000 (or 5004, or 5008 ... if taken by other processes) where it will present its serial console.

Launch the foundation model:

Foundation_v8pkg/models/Linux64_GCC-4.1/Foundation_v8 --cores=2 --no-secure-memory --image=uefi-bootstrap-el3-foundation.axf --data=uefi_foundation.bin@0xa0000000

Building GRUB

You need to have an aarch64-linux-gnu- cross-compiling toolchain installed on your system. There will also be various build dependencies to install (on a Debian-based system, simply run "sudo apt-get build-dep grub"). Then retreive the latest upstream sources and build:

$ git clone git://git.savannah.gnu.org/grub.git
...
$ cd grub
$ ./autogen.sh
...
$ ./configure --prefix=<install directory> --target=aarch64-linux-gnu
...
$ make -j8 install
...

Installing GRUB

Prepare a disk image with at least one EFI System Partition (we'll call that gpt1) and one Linux root filesystem partition (gpt2). Make the partitions directly accessible and mount them with:

$ sudo kpartx -a disk.img
$ sudo mount /dev/mapper/loop0p2 /mnt
$ sudo mount /dev/mapper/loop0p1 /mnt/boot/efi

and then install GRUB with:

$ sudo <install directory>/sbin/grub-install --target=arm64-efi --removable --boot-directory=/mnt/boot --efi-directory=/mnt/boot/efi
$ sudo umount /mnt/boot/efi
$ sudo umount /mnt
$ sudo kpartx -d disk.img

Running GRUB

$ Foundation_v8pkg/models/Linux64_GCC-4.1/Foundation_v8 --cores=2 --no-secure-memory --image=uefi-bootstrap-el3-foundation.axf --data=uefi_foundation.bin@0xa0000000 --block-device=disk.img
<connect to serial console, press enter to abort countdown>
The default boot selection will start in   9 seconds
[1] Linux from SemiHosting
        - VenHw(C5B9C74A-6D72-4719-99AB-C59F199091EB)/Image
        - Arguments: root=/dev/vda2 rw console=ttyAMA0 earlyprintk=pl011,0x1c090000 maxcpus=4 debug user_debug=31 loglevel=9
        - LoaderType: Linux kernel with global FDT support
-----------------------
Global FDT Config
        - VenHw(C5B9C74A-6D72-4719-99AB-C59F199091EB)/foundation-v8.dtb
-----------------------
[a] Boot Manager
[b] Shell
[c] Reboot
[d] Shutdown
Start: b
<screen clears>
UEFI Interactive Shell v2.0. UEFI v2.40 (ARM Foundation Model EFI Dec 17 2013 20:43:14, 0x00000000). Revision 1.02
Mapping table
      FS0: Alias(s):F2:
          VenHw(C5B9C74A-6D72-4719-99AB-C59F199091EB)
      FS1: Alias(s):HD4b:;BLK1:
          VenHw(FE61BB5F-1B67-4C24-B346-73DB42E873E5)/HD(1,GPT,2F972E52-F7E0-4504-9FE7-F60E66352266,0x800,0x32000)
     BLK0: Alias(s):
          VenHw(FE61BB5F-1B67-4C24-B346-73DB42E873E5)
     BLK2: Alias(s):
          VenHw(FE61BB5F-1B67-4C24-B346-73DB42E873E5)/HD(2,GPT,3F1C1949-DC68-4026-A265-68977D675DE9,0x32800,0x12C0000)
     BLK3: Alias(s):
          VenHw(FE61BB5F-1B67-4C24-B346-73DB42E873E5)/HD(3,GPT,810BD693-077D-4E5D-A0ED-18B98E059629,0x12F2800,0x3E8000)
Press ESC in 0 seconds to skip startup.nsh or any other key to continue.
Shell> \EFI\BOOT\BOOTAARCH64.EFI
<screen clears>
                          GNU GRUB  version 2.02~beta1

   Minimal BASH-like line editing is supported. For the first word, TAB   
   lists possible command completions. Anywhere else TAB lists possible   
   device or file completions.                                            


grub> 

LEG/ServerArchitecture/GRUBonAArch64 (last modified 2017-08-17 12:13:05)