]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
plat/kvm/arm: Enable the Unikernel to be built as an UEFI application
authorSergiu Moga <sergiu.moga@protonmail.com>
Mon, 27 Mar 2023 10:00:30 +0000 (13:00 +0300)
committerUnikraft <monkey@unikraft.io>
Fri, 11 Aug 2023 10:47:30 +0000 (10:47 +0000)
If `CONFIG_EFI_STUB` is enabled, add to the build system the ARM UEFI
entry stub and the ARM specific post-EFI stub that applies finishing
touches to the platform initialization.

Add a configuration entry `KVM_BOOT_QEMU_VIRT` to explicitly
indicate that we are booting from the default `QEMU virt`
environment. This will help us differentiate between UEFI and
non-UEFI ARM builds.

Signed-off-by: Sergiu Moga <sergiu.moga@protonmail.com>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #909

plat/kvm/Config.uk
plat/kvm/Linker.uk
plat/kvm/Makefile.uk
plat/kvm/arm/efi_arm.c [deleted file]
plat/kvm/arm/efi_post.c [new file with mode: 0644]
plat/kvm/arm/link64.lds.S

index de5fa22ca19d89383168b2e6294132438a6a52de..5fa58e3667f2968e4df4125fb37a1ea4d29c51e8 100644 (file)
@@ -29,6 +29,12 @@ config KVM_BOOT_PROTO_LXBOOT
        help
                Linux 64-bit Boot Protocol
 
+config KVM_BOOT_PROTOCOL_QEMU_VIRT
+       bool "QEMU virt"
+       depends on KVM_VMM_QEMU && !KVM_VMM_FIRECRACKER && ARCH_ARM_64
+       help
+               Default QEMU virt environment
+
 config KVM_BOOT_EFI_STUB
        bool "EFI stub"
        depends on KVM_VMM_QEMU && !KVM_VMM_FIRECRACKER
index 35d53a60affa24ba3f2228065b04bc357ab30d75..b2c5196b874cd12619e0174c72cb9763ef2336b6 100644 (file)
@@ -10,8 +10,15 @@ KVM_LDFLAGS-y += -Wl,--entry=uk_efi_entry64
 KVM_LDFLAGS-y += -Wl,-m,elf_x86_64
 endif
 else ifeq (arm64,$(CONFIG_UK_ARCH))
+ifeq ($(CONFIG_KVM_BOOT_PROTOCOL_QEMU_VIRT),y)
+KVM_LDFLAGS-y += -Wl,--entry=_libkvmplat_entry
 KVM_LDFLAGS-y += -Wl,-m,aarch64elf
 KVM_LINK_LIBGCC_FLAG := -lgcc
+else ifeq ($(CONFIG_KVM_BOOT_EFI_STUB),y)
+KVM_LDFLAGS-y += -Wl,--entry=uk_efi_entry64
+KVM_LDFLAGS-y += -Wl,-m,aarch64elf
+KVM_LINK_LIBGCC_FLAG := -lgcc
+endif
 endif
 
 ##
index 98a4744ef94c8c33ce4d68fa0e4838758f7fbaf6..a33fc9a0e5c46e99c0cc25f1df7827e5be5ac7d7 100644 (file)
@@ -114,7 +114,12 @@ ifeq ($(CONFIG_HAVE_SMP),y)
 LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(UK_PLAT_COMMON_BASE)/arm/lcpu_start.S
 endif
 LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBKVMPLAT_BASE)/arm/bpt64.S|arm
+ifeq ($(CONFIG_KVM_BOOT_EFI_STUB),y)
+LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBKVMPLAT_BASE)/arm/efi_post.c
+LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBKVMPLAT_BASE)/arm/efi_entry64.S|arm
+else
 LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBKVMPLAT_BASE)/arm/entry64.S|isr
+endif
 LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBKVMPLAT_BASE)/arm/exceptions.S|isr
 LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBKVMPLAT_BASE)/arm/pagetable64.S|isr
 LIBKVMPLAT_SRCS-$(CONFIG_ARCH_ARM_64) += $(LIBKVMPLAT_BASE)/arm/setup.c
diff --git a/plat/kvm/arm/efi_arm.c b/plat/kvm/arm/efi_arm.c
deleted file mode 100644 (file)
index e28beba..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause */
-/* Copyright (c) 2023, Unikraft GmbH and The Unikraft Authors.
- * Licensed under the BSD-3-Clause License (the "License").
- * You may not use this file except in compliance with the License.
- */
-#include <kvm/efi.h>
-#include <uk/arch/paging.h>
-#include <uk/plat/common/bootinfo.h>
-#include <uk/plat/lcpu.h>
-#include <uk/plat/common/sections.h>
-
-extern void clean_and_invalidate_dcache_range(unsigned long, unsigned long);
-extern void _ukplat_entry(void *) __noreturn;
-extern __paddr_t vector_table;
-extern void start_mmu(void);
-
-static __u8 __align(16) uk_efi_bootstack[__PAGE_SIZE];
-
-/* We cannot set the system register directly */
-#define uk_efi_set_sp_el1(sp)                                          \
-       __asm__ __volatile__("mov sp, %0\n" ::"r" (sp))
-
-void __noreturn uk_efi_jmp_to_kern(void)
-{
-       ukplat_lcpu_disable_irq();
-
-       /* Invalidate the image from the data cache */
-       clean_and_invalidate_dcache_range(__BASE_ADDR, __END);
-
-       SYSREG_WRITE64(sctlr_el1, SCTLR_SET_BITS);
-       SYSREG_WRITE64(contextidr_el1, 0);
-       SYSREG_WRITE64(VBAR_EL1, &vector_table);
-       SYSREG_WRITE64(spsr_el1, 0);
-       SYSREG_WRITE64(elr_el1, 0);
-       SYSREG_WRITE64(cntv_cval_el0, 0);
-       /* EDKII's backtrace and dump register code is written in C, so
-        * it requires a stack. If SP_EL1 is corrupted before an exception
-        * is taken, they rely on SP_EL0 which is set to a backup stack.
-        * Thus, reset it to 0 to avoid any back reference to firmware.
-        */
-       SYSREG_WRITE64(sp_el0, 0);
-       SYSREG_WRITE64(tpidr_el0, 0);
-
-       start_mmu();
-       uk_efi_set_sp_el1(uk_efi_bootstack + __PAGE_SIZE);
-       _ukplat_entry(ukplat_bootinfo_get());
-}
diff --git a/plat/kvm/arm/efi_post.c b/plat/kvm/arm/efi_post.c
new file mode 100644 (file)
index 0000000..e28beba
--- /dev/null
@@ -0,0 +1,47 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+/* Copyright (c) 2023, Unikraft GmbH and The Unikraft Authors.
+ * Licensed under the BSD-3-Clause License (the "License").
+ * You may not use this file except in compliance with the License.
+ */
+#include <kvm/efi.h>
+#include <uk/arch/paging.h>
+#include <uk/plat/common/bootinfo.h>
+#include <uk/plat/lcpu.h>
+#include <uk/plat/common/sections.h>
+
+extern void clean_and_invalidate_dcache_range(unsigned long, unsigned long);
+extern void _ukplat_entry(void *) __noreturn;
+extern __paddr_t vector_table;
+extern void start_mmu(void);
+
+static __u8 __align(16) uk_efi_bootstack[__PAGE_SIZE];
+
+/* We cannot set the system register directly */
+#define uk_efi_set_sp_el1(sp)                                          \
+       __asm__ __volatile__("mov sp, %0\n" ::"r" (sp))
+
+void __noreturn uk_efi_jmp_to_kern(void)
+{
+       ukplat_lcpu_disable_irq();
+
+       /* Invalidate the image from the data cache */
+       clean_and_invalidate_dcache_range(__BASE_ADDR, __END);
+
+       SYSREG_WRITE64(sctlr_el1, SCTLR_SET_BITS);
+       SYSREG_WRITE64(contextidr_el1, 0);
+       SYSREG_WRITE64(VBAR_EL1, &vector_table);
+       SYSREG_WRITE64(spsr_el1, 0);
+       SYSREG_WRITE64(elr_el1, 0);
+       SYSREG_WRITE64(cntv_cval_el0, 0);
+       /* EDKII's backtrace and dump register code is written in C, so
+        * it requires a stack. If SP_EL1 is corrupted before an exception
+        * is taken, they rely on SP_EL0 which is set to a backup stack.
+        * Thus, reset it to 0 to avoid any back reference to firmware.
+        */
+       SYSREG_WRITE64(sp_el0, 0);
+       SYSREG_WRITE64(tpidr_el0, 0);
+
+       start_mmu();
+       uk_efi_set_sp_el1(uk_efi_bootstack + __PAGE_SIZE);
+       _ukplat_entry(ukplat_bootinfo_get());
+}
index 8bff6ab62a55c747f138cac721558ec817ef2e00..07180eebf8222ebea2e8dd4bb666f042774367cf 100644 (file)
@@ -40,7 +40,6 @@
 
 OUTPUT_FORMAT("elf64-littleaarch64")
 OUTPUT_ARCH(aarch64)
-ENTRY(_libkvmplat_entry)
 
 PHDRS
 {