payloads: Add leanefi payload

This adds another external payload to coreboot. The payload has been
heavily based on u-boots UEFI implementation.

The leanefi payload is basically a translator from coreboot to UEFI. It
takes the coreboot tables and transforms them into UEFI interfaces.
Although it can potentially load any efi application that can
handle the minimized interface that leanefi provides, it has only
been tested with LinuxBoot (v6.3.5) as a payload. It has been optimized
to support only those interfaces that Linux requires to start.

Among other leanefi does not support:
- efi capsule update (also efi system resource table)
- efi variables
- efi text input protocol (it can only output)
- most boot services. mostly memory services are left (e.g. alloc/free)
- all runtime services (although there is still a very small runtime
  footprint that is planned to be removed in the near future)
- TCG2/TPM (although that is mostly because of laziness)
The README.md currently provides more details on why.

The payload currently only supports arm64 and has only been tested
on emulation/simulator targets. The original motivation was to get ACPI
on arm64 published to the OS without using EDK2. It is however also
possible to supply the leanefi with a FDT that is published to the OS.
At that point one would however probably use coreboot only instead of
this shim layer on top. It would be way nicer to have Linux support
something else than UEFI to propagate the ACPI tables, but it requires
to get the Linux maintainer/community on board. So for now this shim
layer ciruimvents that.

LBBR Test:
// 1. dump FDT from QEMU like mentioned in aarch64 coreboot doc
// 2. compile u-root however you like (aarch64)
// 3. compile Linux (embed u-root initramfs via Kconfig)
// 4. copy Linux kernel to payloads/leanefi/Image
// 5. copy following coreboot defconfig to configs/defconfig:
CONFIG_BOARD_EMULATION_QEMU_AARCH64=y
CONFIG_PAYLOAD_NONE=n
CONFIG_PAYLOAD_LEANEFI=y
CONFIG_LEANEFI_PAYLOAD=y
CONFIG_LEANEFI_PAYLOAD_PATH="[path-to-linux]/arch/arm64/boot/Image"
CONFIG_LEANEFI_FDT=y
CONFIG_LEANEFI_FDT_PATH="[path-to-dumped-DTB]"
// 6. compile coreboot
make defconfig
make -j$(nproc)
// 7. run qemu like mentioned in coreboot doc (no FIT)
// 8. say hello to u-root and optionally kexec into the next kernel

Signed-off-by: Maximilian Brune <maximilian.brune@9elements.com>
Change-Id: I4093378e89c3cb43fb0846666de80a7da36b03f1
Reviewed-on: https://review.coreboot.org/c/coreboot/+/78913
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Ron Minnich <rminnich@gmail.com>
Reviewed-by: Felix Singer <service+coreboot-gerrit@felixsinger.de>
diff --git a/payloads/Makefile.mk b/payloads/Makefile.mk
index a2336aa..5f988da 100644
--- a/payloads/Makefile.mk
+++ b/payloads/Makefile.mk
@@ -28,6 +28,7 @@
 payloads/external/GRUB2 \
 payloads/external/LinuxBoot \
 payloads/external/skiboot \
+payloads/external/leanefi \
 payloads/external/coreDOOM \
 
 force-payload:
diff --git a/payloads/external/Makefile.mk b/payloads/external/Makefile.mk
index d497cf8..4a17791 100644
--- a/payloads/external/Makefile.mk
+++ b/payloads/external/Makefile.mk
@@ -436,6 +436,13 @@
 	$(MAKE) -C payloads/external/skiboot all \
 		CONFIG_SKIBOOT_GIT_REPO=$(CONFIG_SKIBOOT_GIT_REPO) \
 		CONFIG_SKIBOOT_REVISION=$(CONFIG_SKIBOOT_REVISION)
+
+# leanefi
+
+payloads/external/leanefi/leanefi/build/leanefi.elf: FORCE $(DOTCONFIG)
+	$(MAKE) -C payloads/external/leanefi
+FORCE: ;
+
 # COREDOOM
 
 payloads/external/coreDOOM/coredoom/doomgeneric/coredoom.elf coredoom:
diff --git a/payloads/external/leanefi/Kconfig b/payloads/external/leanefi/Kconfig
new file mode 100644
index 0000000..490cbcc
--- /dev/null
+++ b/payloads/external/leanefi/Kconfig
@@ -0,0 +1,58 @@
+if PAYLOAD_LEANEFI
+
+menu "leanEFI configuration"
+
+config PAYLOAD_FILE
+	string
+	default "payloads/external/leanefi/leanefi/build/leanefi.elf"
+
+config LEANEFI_EFI_ECPT
+	bool
+	default y if ARCH_ARM64
+
+config LEANEFI_HEAP_SIZE
+	int "Heap size"
+	default 131072
+	help
+	  This is the heap size (malloc'able size) available
+	  to the payload.
+
+	  If unsure, set to 131072 (128K)
+
+config LEANEFI_STACK_SIZE
+	int "Stack size"
+	default 16384
+	help
+	  This is the stack size available to the payload.
+
+	  If unsure, set to 16384 (16K)
+
+config LEANEFI_BASE_ADDRESS
+	hex "Base address"
+	default 0x62000000 if BOARD_EMULATION_QEMU_AARCH64
+	#default 0x10023300000 if BOARD_EMULATION_QEMU_SBSA
+	help
+	  This is the base address for the payload.
+
+config LEANEFI_PAYLOAD
+	bool "Add a payload"
+	default y
+	help
+	  If selected leanEFI will start a payload.
+	  This option should only be unselected for debug purposes.
+
+config LEANEFI_PAYLOAD_PATH
+	string "path to leanefi payload"
+	depends on LEANEFI_PAYLOAD
+
+config LEANEFI_FDT
+	bool "Add an FDT that is propagated as EFI configuration table"
+	default y if BOARD_EMULATION_QEMU_AARCH64
+
+config LEANEFI_FDT_PATH
+	string "path to FDT"
+	depends on LEANEFI_FDT
+
+endmenu
+
+endif
diff --git a/payloads/external/leanefi/Kconfig.name b/payloads/external/leanefi/Kconfig.name
new file mode 100644
index 0000000..1524d67
--- /dev/null
+++ b/payloads/external/leanefi/Kconfig.name
@@ -0,0 +1,6 @@
+config PAYLOAD_LEANEFI
+	bool "leanefi"
+	depends on ARCH_ARM64
+	help
+	  Select this option if you want to build a coreboot image
+	  with an leanefi payload.
diff --git a/payloads/external/leanefi/Makefile b/payloads/external/leanefi/Makefile
new file mode 100644
index 0000000..4edec32
--- /dev/null
+++ b/payloads/external/leanefi/Makefile
@@ -0,0 +1,22 @@
+
+unexport KCONFIG_AUTOHEADER
+unexport KCONFIG_AUTOCONFIG
+unexport KCONFIG_DEPENDENCIES
+unexport KCONFIG_SPLITCONFIG
+unexport KCONFIG_TRISTATE
+unexport KCONFIG_NEGATIVES
+unexport $(COREBOOT_EXPORTS)
+
+build: leanefi
+	$(MAKE) -C leanefi
+
+leanefi:
+	git clone "https://review.coreboot.org/leanefi"
+
+distclean:
+	rm -rf leanefi
+
+clean:
+	$(MAKE) -C leanefi clean
+
+.PHONY: build clean distclean