efi/loongarch: libstub: Split off kernel image relocation for builtin stub
authorArd Biesheuvel <ardb@kernel.org>
Thu, 13 Oct 2022 10:39:37 +0000 (12:39 +0200)
committerArd Biesheuvel <ardb@kernel.org>
Wed, 9 Nov 2022 11:42:03 +0000 (12:42 +0100)
The LoongArch build of the EFI stub is part of the core kernel image, and
therefore accesses section markers directly when it needs to figure out
the size of the various section.

The zboot decompressor does not have access to those symbols, but
doesn't really need that either. So let's move handle_kernel_image()
into a separate file (or rather, move everything else into a separate
file) so that the zboot build does not pull in unused code that links to
symbols that it does not define.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
drivers/firmware/efi/libstub/Makefile
drivers/firmware/efi/libstub/loongarch-stub.c
drivers/firmware/efi/libstub/loongarch.c [new file with mode: 0644]

index 63e1eddf996b021ac02c30a6a5a3903d30265a37..402dfb30ddc7a01ef81b3df42638423802c9528b 100644 (file)
@@ -89,7 +89,7 @@ lib-$(CONFIG_ARM)             += arm32-stub.o
 lib-$(CONFIG_ARM64)            += arm64.o arm64-stub.o arm64-entry.o
 lib-$(CONFIG_X86)              += x86-stub.o
 lib-$(CONFIG_RISCV)            += riscv.o riscv-stub.o
-lib-$(CONFIG_LOONGARCH)                += loongarch-stub.o
+lib-$(CONFIG_LOONGARCH)                += loongarch.o loongarch-stub.o
 
 CFLAGS_arm32-stub.o            := -DTEXT_OFFSET=$(TEXT_OFFSET)
 
index 6b30fc281458b7ed77b2e5bdad7213c6dbee048b..eee7ed43cdfb43dca8b82488788b6737ed436ad1 100644 (file)
@@ -9,18 +9,10 @@
 #include <asm/addrspace.h>
 #include "efistub.h"
 
-typedef void __noreturn (*kernel_entry_t)(bool efi, unsigned long cmdline,
-                                         unsigned long systab);
-
 extern int kernel_asize;
 extern int kernel_fsize;
 extern int kernel_offset;
-extern kernel_entry_t kernel_entry;
-
-efi_status_t check_platform_features(void)
-{
-       return EFI_SUCCESS;
-}
+extern int kernel_entry;
 
 efi_status_t handle_kernel_image(unsigned long *image_addr,
                                 unsigned long *image_size,
@@ -53,66 +45,9 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
        return status;
 }
 
-struct exit_boot_struct {
-       efi_memory_desc_t       *runtime_map;
-       int                     runtime_entry_count;
-};
-
-static efi_status_t exit_boot_func(struct efi_boot_memmap *map, void *priv)
-{
-       struct exit_boot_struct *p = priv;
-
-       /*
-        * Update the memory map with virtual addresses. The function will also
-        * populate @runtime_map with copies of just the EFI_MEMORY_RUNTIME
-        * entries so that we can pass it straight to SetVirtualAddressMap()
-        */
-       efi_get_virtmap(map->map, map->map_size, map->desc_size,
-                       p->runtime_map, &p->runtime_entry_count);
-
-       return EFI_SUCCESS;
-}
-
 unsigned long kernel_entry_address(void)
 {
        unsigned long base = (unsigned long)&kernel_offset - kernel_offset;
 
        return (unsigned long)&kernel_entry - base + VMLINUX_LOAD_ADDRESS;
 }
-
-efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
-                            unsigned long kernel_addr, char *cmdline_ptr)
-{
-       kernel_entry_t real_kernel_entry;
-       struct exit_boot_struct priv;
-       unsigned long desc_size;
-       efi_status_t status;
-       u32 desc_ver;
-
-       status = efi_alloc_virtmap(&priv.runtime_map, &desc_size, &desc_ver);
-       if (status != EFI_SUCCESS) {
-               efi_err("Unable to retrieve UEFI memory map.\n");
-               return status;
-       }
-
-       efi_info("Exiting boot services\n");
-
-       efi_novamap = false;
-       status = efi_exit_boot_services(handle, &priv, exit_boot_func);
-       if (status != EFI_SUCCESS)
-               return status;
-
-       /* Install the new virtual address map */
-       efi_rt_call(set_virtual_address_map,
-                   priv.runtime_entry_count * desc_size, desc_size,
-                   desc_ver, priv.runtime_map);
-
-       /* Config Direct Mapping */
-       csr_write64(CSR_DMW0_INIT, LOONGARCH_CSR_DMWIN0);
-       csr_write64(CSR_DMW1_INIT, LOONGARCH_CSR_DMWIN1);
-
-       real_kernel_entry = (void *)kernel_entry_address();
-
-       real_kernel_entry(true, (unsigned long)cmdline_ptr,
-                         (unsigned long)efi_system_table);
-}
diff --git a/drivers/firmware/efi/libstub/loongarch.c b/drivers/firmware/efi/libstub/loongarch.c
new file mode 100644 (file)
index 0000000..807cba2
--- /dev/null
@@ -0,0 +1,80 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Author: Yun Liu <liuyun@loongson.cn>
+ *         Huacai Chen <chenhuacai@loongson.cn>
+ * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
+ */
+
+#include <asm/efi.h>
+#include <asm/addrspace.h>
+#include "efistub.h"
+
+typedef void __noreturn (*kernel_entry_t)(bool efi, unsigned long cmdline,
+                                         unsigned long systab);
+
+efi_status_t check_platform_features(void)
+{
+       return EFI_SUCCESS;
+}
+
+struct exit_boot_struct {
+       efi_memory_desc_t       *runtime_map;
+       int                     runtime_entry_count;
+};
+
+static efi_status_t exit_boot_func(struct efi_boot_memmap *map, void *priv)
+{
+       struct exit_boot_struct *p = priv;
+
+       /*
+        * Update the memory map with virtual addresses. The function will also
+        * populate @runtime_map with copies of just the EFI_MEMORY_RUNTIME
+        * entries so that we can pass it straight to SetVirtualAddressMap()
+        */
+       efi_get_virtmap(map->map, map->map_size, map->desc_size,
+                       p->runtime_map, &p->runtime_entry_count);
+
+       return EFI_SUCCESS;
+}
+
+unsigned long __weak kernel_entry_address(void)
+{
+       return *(unsigned long *)(PHYSADDR(VMLINUX_LOAD_ADDRESS) + 8);
+}
+
+efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
+                            unsigned long kernel_addr, char *cmdline_ptr)
+{
+       kernel_entry_t real_kernel_entry;
+       struct exit_boot_struct priv;
+       unsigned long desc_size;
+       efi_status_t status;
+       u32 desc_ver;
+
+       status = efi_alloc_virtmap(&priv.runtime_map, &desc_size, &desc_ver);
+       if (status != EFI_SUCCESS) {
+               efi_err("Unable to retrieve UEFI memory map.\n");
+               return status;
+       }
+
+       efi_info("Exiting boot services\n");
+
+       efi_novamap = false;
+       status = efi_exit_boot_services(handle, &priv, exit_boot_func);
+       if (status != EFI_SUCCESS)
+               return status;
+
+       /* Install the new virtual address map */
+       efi_rt_call(set_virtual_address_map,
+                   priv.runtime_entry_count * desc_size, desc_size,
+                   desc_ver, priv.runtime_map);
+
+       /* Config Direct Mapping */
+       csr_write64(CSR_DMW0_INIT, LOONGARCH_CSR_DMWIN0);
+       csr_write64(CSR_DMW1_INIT, LOONGARCH_CSR_DMWIN1);
+
+       real_kernel_entry = (void *)kernel_entry_address();
+
+       real_kernel_entry(true, (unsigned long)cmdline_ptr,
+                         (unsigned long)efi_system_table);
+}