[U-Boot] [PATCH v5 00/30] EFI payload / application support

Alexander Graf
2016-03-04T00:09:44Z

This is my (now very late) Christmas present for my openSUSE friends :).

U-Boot is a great project for embedded devices. However, convincing
everyone involved that only for "a few oddball ARM devices" we need to
support different configuration formats from grub2 when all other platforms
(PPC, System Z, x86) are standardized on a single format is a nightmare.

So we started to explore alternatives. At first, people tried to get
grub2 running using the u-boot api interface. However, that one didn't
support relocations, so you had to know where to link grub2 to at compile
time. It also seems to be broken more often than not. And on top of it all,
it's a one-off interface, so yet another thing to maintain.

That led to a nifty idea. What if we can just implement the EFI application
protocol on top of U-Boot? Then we could compile a single grub2 binary for
uEFI based systems and U-Boot based systems and as soon as that one's loaded,
everything looks and feels (almost) the same.

This patch set is the result of pursuing this endeavor.

- I am successfully able to run grub2 and Linux EFI binaries with this code.
- When enabled, the resulting U-Boot binary only grows by ~10kb,
so it's very light weight.
- It works on 32bit ARM and AArch64.
- All storage devices are directly accessible
- No EFI variables
- Removable media booting (search for /efi/boot/boota{a64,arm}.efi)
- Everything in place for runtime service support

Of course, there are still a few things one could do on top:

- Improve disk media detection (don't scan, use what information we have)
- Add EFI variable support using NVRAM
- Add GFX support
- Make EFI Shell work ;)
- Network device support
- Support for payload exit

But so far, I'm very happy with the state of the patches. They completely
eliminate potential arguments against U-Boot internally and give users the
chance to run with the same level of comfort on all firmware types.

Version 5 was successfully tested to boot grub2 and Linux from there on a
beagle-xm. Please apply the arm64 mmu patch set if you want to run this on an
AArch64 system.

If you read this far and want to try out the patches, feel free to grab
the source from git at:

https://github.com/agraf/u-boot efi-v5

v1 -> v2:
- move memory allocation to separate patch
- limit 32/64 to hosts that support it
- check 32bit optional nt header magic
- switch to GPLv2+
- Fix typo s/does now/does not/
- Add #ifdefs around header to allow inclusion when efi_loader is disabled
- Add stub efi_restore_gd() function when efi_loader is disabled
- Disable debug
- Mark runtime region as such
- Fix up memory map
- Allow efi_restore_gd to be called before first efi entry
- Add 32bit arm cache workaround
- Move memory map to separate patch
- Change BTS version to 2.5
- Fix return values for a few callbacks to more EFI compliant ones
- Change vendor to "Das U-Boot"
- Add warning when truncating timer trigger
- Add runtime detach
- Enable runtime relocations
- Add get_time
- Fix relocation
- Fix 32bit
- Add am335x support
- Move section definition to header
- Add systab to runtime section
- Add self-relocation hook table
- Relocate efi_runtime section early during bootup
- Fix return values for a number of callbacks to be more UEFI compliant
- Move to block_drvr array
- Fix header order
- Document efi block object struct
- Use calloc rather than malloc & memset
- Default to y
- New patches:
- disk/part.c: Expose list of available block drivers
- arm64: Allow exceptions to return
- arm64: Allow EFI payload code to take exceptions
- efi_loader: Add DCACHE_OFF support for arm64
- efi_loader: Add distro boot script for removable media

v2 -> v3:

- Add EFIAPI to notify_function
- Add access denied code
- use efi_alloc
- add EFIAPI to function prototypes
- remove unused macros
- reorder header inclusion
- split relocation code into function
- flush cache after loading
- Use external efi_memory helpers
- Add EFIAPI to function prototypes
- Initialize event timer to -1ULL to prevent early firing
- Document header
- Move obj list to lib
- Remove implicit guid table
- Add guid compare function
- Fix return values
- Implement efi_wait_for_event
- Add EFIAPI to function prototypes
- Patch reset to NULL
- Add EFIAPI to function prototypes
- Document header
- Add dm.h include
- Remove non-dm rtc support
- Return DEVICE_ERROR in rtc path
- Adapt to newer u-boot block API
- Add EFIAPI to function prototypes
- Document header
- Check for DEV_TYPE_UNKNOWN
- Document 16byte limit for dp string
- Move to new cmd directory
- Add kconfig option
- Fix comment style
- Add help text
- s/-1/-ENOENT
- Move obj list to lib
- Rewrite memory allocation and map
- Document header
- Add memory file
- New files:
- README patch
- MAINTAINERS patch

v3 -> v4:

- Add EFI_PAGE_MASK define
- Use EFI_PAGE_SHIFT define
- Flush icache after image load
- Fix white space in pe header
- s/polimorphic/polymorphic
- return EFI_SUCCESS in efi_cout_enable_cursor()
- Use EFI_PAGE_.* defines
- Return EFI_OUT_OF_RESOURCES in efi_allocate_pages
- Add readme section about config options
- s/10kb/10KB/

v4 -> v5:

- Provide icache flush stub for archs which don't have it
- Mark fdt memory as boot services data
- new patch: arm64: Replace fdt_name env variables with fdtfile
- new patch: arm: Allow EFI payload code to take exceptions
- new patch: efi_loader: Call fdt preparation functions
- new patch: efi_loader: Pass proper device path in on boot
- PoC converted JeOS-beagle and JeOS-beaglebone images to EFI
-> http://download.opensuse.org/repositories/home:/algraf:/arm-efi/images/

Alexander Graf (30):
thunderx: Calculate TCR dynamically
arm64: Disable TTBR1 maps in EL1
arm64: Make full va map code more dynamic
thunderx: Move mmu table into board file
zymqmp: Replace home grown mmu code with generic table approach
tegra: Replace home grown mmu code with generic table approach
vexpress64: Add MMU tables
dwmmc: Increase retry timeout
hikey: Add MMU tables
arm64: Remove non-full-va map code
arm64: Only allow dcache disabled in SPL builds
disk/part.c: Expose list of available block drivers
include/efi_api.h: Add more detailed API definitions
efi_loader: Add PE image loader
efi_loader: Add boot time services
efi_loader: Add console interface
efi_loader: Add runtime services
efi_loader: Add disk interfaces
efi_loader: Add "bootefi" command
efi_loader: Implement memory allocation and map
arm64: Allow exceptions to return
arm64: Allow EFI payload code to take exceptions
efi_loader: hook up in build environment
efi_loader: Add distro boot script for removable media
efi_loader: Add README section in README.efi
efi_loader: Add MAINTAINERS entry
arm64: Replace fdt_name env variables with fdtfile
arm: Allow EFI payload code to take exceptions
efi_loader: Call fdt preparation functions
efi_loader: Pass proper device path in on boot

MAINTAINERS | 7 +
arch/arm/config.mk | 4 +
arch/arm/cpu/armv8/cache.S | 54 ++
arch/arm/cpu/armv8/cache_v8.c | 551 +++++++++++++----
arch/arm/cpu/armv8/exceptions.S | 34 ++
arch/arm/cpu/armv8/fsl-layerscape/cpu.c | 37 +-
arch/arm/cpu/armv8/u-boot.lds | 16 +
arch/arm/cpu/armv8/zynqmp/cpu.c | 217 ++-----
arch/arm/cpu/u-boot.lds | 30 +
arch/arm/include/asm/arch-fsl-layerscape/cpu.h | 94 +--
arch/arm/include/asm/armv8/mmu.h | 123 +---
arch/arm/include/asm/global_data.h | 7 +-
arch/arm/include/asm/system.h | 12 +-
arch/arm/lib/interrupts.c | 8 +
arch/arm/lib/interrupts_64.c | 9 +
arch/arm/lib/sections.c | 4 +
arch/arm/mach-tegra/arm64-mmu.c | 132 +----
board/armltd/vexpress64/vexpress64.c | 21 +
board/cavium/thunderx/thunderx.c | 24 +
board/hisilicon/hikey/hikey.c | 21 +
board/ti/am335x/u-boot.lds | 30 +
cmd/Kconfig | 7 +
cmd/Makefile | 1 +
cmd/bootefi.c | 202 +++++++
cmd/fs.c | 2 +
common/board_r.c | 7 +
common/image-fdt.c | 8 +-
disk/part.c | 7 +-
doc/README.arm64 | 20 -
doc/README.efi | 83 ++-
drivers/mmc/dw_mmc.c | 2 +-
include/config_distro_bootcmd.h | 47 +-
include/configs/hikey.h | 6 +-
include/configs/thunderx_88xx.h | 30 -
include/configs/vexpress_aemv8a.h | 15 +-
include/efi.h | 2 +
include/efi_api.h | 198 +++++--
include/efi_loader.h | 157 +++++
include/part.h | 8 +
include/pe.h | 263 +++++++++
lib/Kconfig | 1 +
lib/Makefile | 1 +
lib/efi_loader/Kconfig | 9 +
lib/efi_loader/Makefile | 12 +
lib/efi_loader/efi_boottime.c | 781 +++++++++++++++++++++++++
lib/efi_loader/efi_console.c | 360 ++++++++++++
lib/efi_loader/efi_disk.c | 212 +++++++
lib/efi_loader/efi_image_loader.c | 188 ++++++
lib/efi_loader/efi_memory.c | 319 ++++++++++
lib/efi_loader/efi_runtime.c | 290 +++++++++
50 files changed, 4003 insertions(+), 670 deletions(-)
create mode 100644 cmd/bootefi.c
create mode 100644 include/efi_loader.h
create mode 100644 include/pe.h
create mode 100644 lib/efi_loader/Kconfig
create mode 100644 lib/efi_loader/Makefile
create mode 100644 lib/efi_loader/efi_boottime.c
create mode 100644 lib/efi_loader/efi_console.c
create mode 100644 lib/efi_loader/efi_disk.c
create mode 100644 lib/efi_loader/efi_image_loader.c
create mode 100644 lib/efi_loader/efi_memory.c
create mode 100644 lib/efi_loader/efi_runtime.c

--
1.8.5.6