Some questions about UEFI


Elena WILLIS <elena.willis@...>
 

Hello,

 

I am using EDK2 https://github.com/tianocore/edk2 on a Raspberry PI 3B model.

Installation went fine and I can access the UEFI Shell interface, where the commands work.

 

But I’m now stuck and have a few questions :

-          Do you have a simple .efi script that I could use to test my setup ?

-          Once I am on the UEFI interface, I can’t seem to boot back onto my OS (Raspbian). Could you please explain how to do this?

 

Thank you for your help,

 

Cordialement,

Best regards,

 

 

Elena WILLIS  | TINA : 147 0641 | Tel: +33223470641

Microcontrollers and Digital ICs Group | TPM Applications Apprentice

 


Leif Lindholm
 

Hi Elena, (+cc Pete)

On Thu, Jul 18, 2019 at 11:54:38AM +0000, Elena WILLIS wrote:
I am using EDK2 https://github.com/tianocore/edk2 on a Raspberry PI 3B model.
Installation went fine and I can access the UEFI Shell interface, where the commands work.

But I'm now stuck and have a few questions :

- Do you have a simple .efi script that I could use to test
- my setup ?
.efi indicated an application (or driver), as opposed to a script.
My go-to test case is a standalone GRUB executable.
Generated with grub-mkstandalone -O arm64-efi -o grubstand.efi

- Once I am on the UEFI interface, I can't seem to boot
- back onto my OS (Raspbian). Could you please explain how
- to do this?
Does 'exit' bring you back to a "BIOS" menu system where you can
select boot options?

Best Regards,

Leif


Elena WILLIS
 

Hi Leif and Pete,



My answers in blue.



Best regards,



Elena

-----Original Message-----
From: Leif Lindholm <leif.lindholm@linaro.org>
Sent: vendredi 19 juillet 2019 11:11
To: discuss@edk2.groups.io; Elena WILLIS <elena.willis@st.com>
Cc: Pete Batard <pete@akeo.ie>
Subject: Re: [edk2-discuss] Some questions about UEFI



Hi Elena, (+cc Pete)



On Thu, Jul 18, 2019 at 11:54:38AM +0000, Elena WILLIS wrote:

I am using EDK2 https://github.com/tianocore/edk2 on a Raspberry PI 3B model.
Installation went fine and I can access the UEFI Shell interface, where the commands work.
But I'm now stuck and have a few questions :
- Do you have a simple .efi script that I could use to test
- my setup ?


.efi indicated an application (or driver), as opposed to a script.

My go-to test case is a standalone GRUB executable.

Generated with grub-mkstandalone -O arm64-efi -o grubstand.efi



Ok I will try this, thank you !



- Once I am on the UEFI interface, I can't seem to boot
- back onto my OS (Raspbian). Could you please explain how
- to do this?


Does 'exit' bring you back to a "BIOS" menu system where you can select boot options?



Yes, it does, but from there I can't get back onto my OS either. :(



Best Regards,



Leif


Pete Batard <pete@...>
 

Hi Elena, hi Leif,

I'll add the following comments:


1. Right now, the RPi3 firmware is set not to boot SD/USB by default, but boot into the UEFI Shell always. Therefore, if you want a /efi/boot/bootaa64.efi bootloader residing on an SD card to launch by default, you first have to go to Boot Maintenance Manager → Boot Options → Change Boot Order and then alter the setting to that SD/MMC is the first entry. Alternatively, you can also manually invoke the executable from the Shell (e.g. Navigate to fs0: and then launch /efi/boot/bootaa64.efi).

Obviously, since we agree this is not a very intuitive behaviour, there is a patch lined up (that has not yet been applied) to alter the above and make sure SD/MMC becomes the default for boot, as we reckon most users are likely to be thrown off by the current behaviour.


2. If it helps, please be aware that there exists a Systems.md in the edk2-platforms RPi3 directory where, for instance, the installation of Ubuntu 18.04 LTS on a Pi 3 Model B is described. See https://github.com/tianocore/edk2-platforms/blob/master/Platform/RaspberryPi/RPi3/Systems.md.

I haven't tested Raspbian (I believe this is designed specifically to use the default Pi bootloader, so, even if it's targetted for Pi, it might not be the best distribution to install when using the UEFI firmware) but you might be interested to know that I'm currently in the process of adding detailed information on how to install of *vanilla* Debian 10.0 ARM64 on a Pi 3 Model B+, and I am hoping to submit a patch to update Systems.md with these instructions some time next week.

In case you are interested, I am copy/pasting my current rough draft below.

Regards,

/Pete

------------------------------------------------------------------------

[Debian 10](https://cdimage.debian.org/debian-cd/current/arm64/iso-cd/) has been tested and
confirmed to work, on a Raspberry 3 Model B+, including the installation process.

Below are the steps you can follow to install Debian 10 onto SD:
* Partition the media as MBR and create a ~300 MB FAT32 partition on it with MBR type `0x0c`
* Copy the UEFI firmware files (`RPI_EFI.fd`, `bootcode.bin`, `fixup.dat` and `start.elf`)
as well as an appropriate `config.txt` onto the FAT partition. If needed you can download
the non UEFI binary files from https://github.com/raspberrypi/firmware/tree/master/boot.
If you are using a model B+, don't forget to copy the relevant `.dtb` and reference it in
your `config.txt`.
* Download [`debian-10.0.0-arm64-netinst.iso`](https://cdimage.debian.org/debian-cd/current/arm64/iso-cd/debian-10.0.0-arm64-netinst.iso)
* Extract the full content of the ISO onto the partition you created.
* Delete `EFI\boot\bootaa64.efi` and rename `EFI\boot\grubaa64.efi` to `EFI\boot\bootaa64.efi`
* Insert the media and power up the Raspberry Pi device.
* On the GRUB menu select `Install`
* Before selecting the language press <kbd>Alt</kbd>-<kbd>F2</kbd> and press <kbd>Enter</kbd>
to activate a console.
* Issue the commands:
```
mkdir /cdrom
mount -t vfat /dev/mmcblk0p1 /cdrom
```
This is needed as the Debian installer does not currently know how to detect SD based install
media.
* Go back to the main consolde (<kbd>Alt</kbd>-<kbd>F1</kbd>) and select your language and
keyboard as needed and proceed with the guide prompt with the rest of the installation.
The installer script should properly detect and set up your networking.
Continue until you get to `Partition disks`
* For `Partitioning method` select `Manual`

```
MMC/SD card #1 (mmcblk0) - 16.0 GB SD 2WCGO
#1 primary 314.6 MB fat16
pri/log FREE SPACE
```

- Select `#1 primary` and change `Use as:` to `EFI System Partition` then select
`Done setting the partition`.
- Select `FREE SPACE` &rarr; `Create a new partition` and create a `1 GB` swap partition.
- Select `FREE SPACE` &rarr; `Create a new partition` and allocate the rest to an `ext4`
root partition.
After doing this, your partition report should look like this:
```
MMC/SD card #1 (mmcblk0) - 16.0 GB SD 2WCGO
#1 primary 314.6 MB B K ESP
#2 primary 1.0 GB f swap swap
#3 primary 14.7 GB f ext4 /
```

* Select `Finish partitioning and write changes to disk` and let the installer continue.
* `Configure the package manager` and `Select and install software` appear to be broken
at this stage, so you should ignore them (you can configure them later).
* Select `Install the GRUB boot loader on a hard disk`
* When the system displays the message `Installation is complete, so it is time to boot into your new system (...)`
go to the other console *<kbd>Alt</kbd>-<kbd>F2</kbd>) and issue the following
(provided that Linux root is your 3rd partition, else you should change `mmcblk0p3`
to the proper value. Note that the first command might not be needed if the installer
still had `/target` properly mounted):
```
mount -t ext4 /dev/mmcblk0p3 /target
mount -o bind /dev /target/dev
chroot /target /sbin/fdisk /dev/mmcblk0
```
Then press <kbd>t</kbd>, <kbd>1</kbd>, <kbd>c</kbd> and <kbd>w</kbd> to change the
1st partition type to FAT32. This is needed because the hardcoded bootloader on the
CPU die does not handle type `0xef` (ESP) partitions for boot (but we needed to set
an ESP to keep the Debian installer happy).
* Go back to the installer and reboot the system. You should get the GRUB prompt and
the system should book into the installed Linux. If you don't see the multicoloured
screen when booting the Pi, it's probably because you didn't properly change the
type of the FAT partition back to `0xC`.
* You may want to edit `/etc/apt/sources.list` to:
```
deb http://httpredir.debian.org/debian buster main contrib non-free
deb http://httpredir.debian.org/debian buster-updates main contrib non-free
deb http://security.debian.org/ buster/updates main contrib non-free
```
* At this stage, you should be able to install additional software such as `openssh`
(which is not installed by default) or anything else you need.

------------------------------------------------------------------------

On 2019.07.19 10:15, Elena WILLIS wrote:
Hi Leif and Pete,
My answers in blue.
Best regards,
Elena
-----Original Message-----
From: Leif Lindholm <leif.lindholm@linaro.org>
Sent: vendredi 19 juillet 2019 11:11
To: discuss@edk2.groups.io; Elena WILLIS <elena.willis@st.com>
Cc: Pete Batard <pete@akeo.ie>
Subject: Re: [edk2-discuss] Some questions about UEFI
Hi Elena, (+cc Pete)
On Thu, Jul 18, 2019 at 11:54:38AM +0000, Elena WILLIS wrote:

> I am using EDK2 https://github.com/tianocore/edk2 on a Raspberry PI
3B model.

> Installation went fine and I can access the UEFI Shell interface,
where the commands work.

>

> But I'm now stuck and have a few questions :

>

> -          Do you have a simple .efi script that I could use to test

> -          my setup ?
.efi indicated an application (or driver), as opposed to a script.
My go-to test case is a standalone GRUB executable.
Generated with grub-mkstandalone -O arm64-efi -o grubstand.efi
Ok I will try this, thank you !

> -          Once I am on the UEFI interface, I can't seem to boot

> -          back onto my OS (Raspbian). Could you please explain how

> -          to do this?
Does 'exit' bring you back to a "BIOS" menu system where you can select boot options?
Yes, it does, but from there I can't get back onto my OS either. :(
Best Regards,
Leif


Elena WILLIS
 

Hi Leif and Pete,



I now have a working UEFI on my Raspberry PI model 3B, which can boot into Debian 10.

The standalone GRUB executable (grubstand.efi) works when I execute it in the UEFI Shell.



I have also installed EDKII (https://github.com/tianocore/edk2, the 2018 stable version) and followed build instructions to generate a simple HelloWorld.efi application.

But when I execute HelloWorld.efi in my UEFI Shell, I always get the same error :

Command Error Status : Unsupported.



* I am executing my application like this :

Ø fs0:

Ø HelloWorld.efi



* I have tried different TARGET_ARCH build options : ARM, X64 and IA32, but they all produce the same error when I try to execute HelloWorld.efi.



Do you have any idea how I could fix this?



Best Regards,



Elena

-----Original Message-----
From: Leif Lindholm <leif.lindholm@linaro.org>
Sent: vendredi 19 juillet 2019 11:11
To: discuss@edk2.groups.io; Elena WILLIS <elena.willis@st.com>
Cc: Pete Batard <pete@akeo.ie>
Subject: Re: [edk2-discuss] Some questions about UEFI



Hi Elena, (+cc Pete)



On Thu, Jul 18, 2019 at 11:54:38AM +0000, Elena WILLIS wrote:

I am using EDK2 https://github.com/tianocore/edk2 on a Raspberry PI 3B model.
Installation went fine and I can access the UEFI Shell interface, where the commands work.
But I'm now stuck and have a few questions :
- Do you have a simple .efi script that I could use to test
- my setup ?


.efi indicated an application (or driver), as opposed to a script.

My go-to test case is a standalone GRUB executable.

Generated with grub-mkstandalone -O arm64-efi -o grubstand.efi



- Once I am on the UEFI interface, I can't seem to boot
- back onto my OS (Raspbian). Could you please explain how
- to do this?


Does 'exit' bring you back to a "BIOS" menu system where you can select boot options?



Best Regards,



Leif


Pete Batard
 

Hi Elena,

Glad to hear that you got Debian 10 installed.

For the record, we should have finalized notes on how to install Debian 10 on the Pi 3 soon, in this platform's Systems.md [1] (I send a patch for that last week, that expands a bit more on the draft notes I sent you earlier, that has not been committed yet), and, if I may, I'm also going to point out that I posted a more informal but also more detailed guide on how to achieve this same installation on my blog too [2]. I have also recently started to produce binary releases of Rasbperry Pi 3 UEFI firmware packages [3] (built from the latest EDK2 sources through AppVeyor), that might be of interest to you as they include the non-free WLAN drivers that Debian asks for during install.

At any rate, to answer your question, if the actual architectures you tried are "ARM, X64 and IA32", then your issue is simple:

The Raspberry Pi 3 is using an Arm64 CPU, so the architecture you *must* use to compile any UEFI application is "AARCH64" (not ARM, which is only for 32-bit and therefore incompatible). By the looks of it, this is the one you haven't tried so far whereas this is the one that you should use.

Note that, for the sake of completeness, compiling for the EBC arch should also work, since we include the EBC interpreter in the firmware. But really, what you want to compile a UEFI application to run it on a Pi 3, you should only use AARCH64 for the architecture. If you do just that, I'm confident that you will find that it fixes your issue.

Regards,

/Pete

[1] https://github.com/tianocore/edk2-platforms/blob/master/Platform/RaspberryPi/RPi3/Systems.md
[2] https://pete.akeo.ie/2019/07/installing-debian-arm64-on-raspberry-pi.html
[3] https://github.com/pbatard/RPi3

On 2019.07.31 11:26, Elena WILLIS wrote:
Hi Leif and Pete,
I now have a working UEFI on my Raspberry PI model 3B, which can boot into Debian 10.
The standalone GRUB executable (grubstand.efi) works when I execute it in the UEFI Shell.
I have also installed EDKII (https://github.com/tianocore/edk2, the 2018 stable version) and followed build instructions to generate a simple HelloWorld.efi application.
But when I execute HelloWorld.efi in my UEFI Shell, I always get the same error :
*Command Error Status : Unsupported. *
**
• I am executing my application like this :
Øfs0:
ØHelloWorld.efi
• I have tried different TARGET_ARCH build options : ARM, X64 and IA32, but they all produce the same error when I try to execute HelloWorld.efi.
Do you have any idea how I could fix this?
Best Regards,
Elena**
-----Original Message-----
From: Leif Lindholm <leif.lindholm@linaro.org>
Sent: vendredi 19 juillet 2019 11:11
To: discuss@edk2.groups.io; Elena WILLIS <elena.willis@st.com>
Cc: Pete Batard <pete@akeo.ie>
Subject: Re: [edk2-discuss] Some questions about UEFI
Hi Elena, (+cc Pete)
On Thu, Jul 18, 2019 at 11:54:38AM +0000, Elena WILLIS wrote:

> I am using EDK2 https://github.com/tianocore/edk2 on a Raspberry PI
3B model.

> Installation went fine and I can access the UEFI Shell interface,
where the commands work.

>

> But I'm now stuck and have a few questions :

>

> -          Do you have a simple .efi script that I could use to test

> -          my setup ?
.efi indicated an application (or driver), as opposed to a script.
My go-to test case is a standalone GRUB executable.
Generated with grub-mkstandalone -O arm64-efi -o grubstand.efi

> -          Once I am on the UEFI interface, I can't seem to boot

> -          back onto my OS (Raspbian). Could you please explain how

> -          to do this?
Does 'exit' bring you back to a "BIOS" menu system where you can select boot options?
Best Regards,
Leif