x86: efi: Refactor the directory of EFI app and payload support
authorBin Meng <bmeng.cn@gmail.com>
Tue, 12 Jun 2018 15:36:16 +0000 (08:36 -0700)
committerBin Meng <bmeng.cn@gmail.com>
Sun, 17 Jun 2018 13:16:04 +0000 (21:16 +0800)
At present the EFI application and payload support codes in the x86
directory is distributed in a hybrid way. For example, the Kconfig
options for both app and payload are in arch/x86/lib/efi/Kconfig,
but the source codes in the same directory get built only for
CONFIG_EFI_STUB.

This refactors the codes by consolidating all the EFI support codes
into arch/x86/cpu/efi, just like other x86 targets.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
12 files changed:
arch/x86/Kconfig
arch/x86/cpu/Makefile
arch/x86/cpu/efi/Kconfig [new file with mode: 0644]
arch/x86/cpu/efi/Makefile
arch/x86/cpu/efi/car.S [new file with mode: 0644]
arch/x86/cpu/efi/payload.c [new file with mode: 0644]
arch/x86/lib/Makefile
arch/x86/lib/efi/Kconfig [deleted file]
arch/x86/lib/efi/Makefile [deleted file]
arch/x86/lib/efi/car.S [deleted file]
arch/x86/lib/efi/efi.c [deleted file]
doc/README.u-boot_on_efi

index 18c7fb2d496771a7abf58c56aa2053e2d348fd0a..a1c18d26e1d186c62034197c70a275e16a38bf4c 100644 (file)
@@ -112,6 +112,7 @@ source "arch/x86/cpu/braswell/Kconfig"
 source "arch/x86/cpu/broadwell/Kconfig"
 source "arch/x86/cpu/coreboot/Kconfig"
 source "arch/x86/cpu/ivybridge/Kconfig"
+source "arch/x86/cpu/efi/Kconfig"
 source "arch/x86/cpu/qemu/Kconfig"
 source "arch/x86/cpu/quark/Kconfig"
 source "arch/x86/cpu/queensbay/Kconfig"
@@ -772,6 +773,4 @@ config HIGH_TABLE_SIZE
          Increse it if the default size does not fit the board's needs.
          This is most likely due to a large ACPI DSDT table is used.
 
-source "arch/x86/lib/efi/Kconfig"
-
 endmenu
index af9e26caab18f0d0e5df0f6f39b79c14a0def0de..f862d8c071e7806427be760874e6ea3b7babb0b5 100644 (file)
@@ -29,7 +29,7 @@ obj-$(CONFIG_INTEL_BAYTRAIL) += baytrail/
 obj-$(CONFIG_INTEL_BRASWELL) += braswell/
 obj-$(CONFIG_INTEL_BROADWELL) += broadwell/
 obj-$(CONFIG_SYS_COREBOOT) += coreboot/
-obj-$(CONFIG_EFI_APP) += efi/
+obj-$(CONFIG_EFI) += efi/
 obj-$(CONFIG_QEMU) += qemu/
 obj-$(CONFIG_NORTHBRIDGE_INTEL_IVYBRIDGE) += ivybridge/
 obj-$(CONFIG_INTEL_QUARK) += quark/
diff --git a/arch/x86/cpu/efi/Kconfig b/arch/x86/cpu/efi/Kconfig
new file mode 100644 (file)
index 0000000..e0975d3
--- /dev/null
@@ -0,0 +1,11 @@
+if EFI
+
+config SYS_CAR_ADDR
+       hex
+       default 0x100000
+
+config SYS_CAR_SIZE
+       hex
+       default 0x20000
+
+endif
index 06d048044083f886ebca48ebe4c963273dfda4d9..32c2ddedb9469e86db322dcbf4ef1e90c2096190 100644 (file)
@@ -2,5 +2,12 @@
 #
 # Copyright (c) 2015 Google, Inc
 
+ifdef CONFIG_EFI_APP
 obj-y += efi.o
 obj-y += sdram.o
+endif
+
+ifdef CONFIG_EFI_STUB
+obj-y += car.o
+obj-y += payload.o
+endif
diff --git a/arch/x86/cpu/efi/car.S b/arch/x86/cpu/efi/car.S
new file mode 100644 (file)
index 0000000..488dcde
--- /dev/null
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (c) 2015 Google, Inc
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+.globl car_init
+car_init:
+       jmp     car_init_ret
diff --git a/arch/x86/cpu/efi/payload.c b/arch/x86/cpu/efi/payload.c
new file mode 100644 (file)
index 0000000..81fb8b5
--- /dev/null
@@ -0,0 +1,157 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2015 Google, Inc
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <common.h>
+#include <debug_uart.h>
+#include <efi.h>
+#include <errno.h>
+#include <linux/err.h>
+#include <linux/types.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/*
+ * This function looks for the highest region of memory lower than 4GB which
+ * has enough space for U-Boot where U-Boot is aligned on a page boundary.
+ * It overrides the default implementation found elsewhere which simply
+ * picks the end of ram, wherever that may be. The location of the stack,
+ * the relocation address, and how far U-Boot is moved by relocation are
+ * set in the global data structure.
+ */
+ulong board_get_usable_ram_top(ulong total_size)
+{
+       struct efi_mem_desc *desc, *end;
+       struct efi_entry_memmap *map;
+       int ret, size;
+       uintptr_t dest_addr = 0;
+       struct efi_mem_desc *largest = NULL;
+
+       /*
+        * Find largest area of memory below 4GB. We could
+        * call efi_build_mem_table() for a more accurate picture since it
+        * merges areas together where possible. But that function uses more
+        * pre-relocation memory, and it's not critical that we find the
+        * absolute largest region.
+        */
+       ret = efi_info_get(EFIET_MEMORY_MAP, (void **)&map, &size);
+       if (ret) {
+               /* We should have stopped in dram_init(), something is wrong */
+               debug("%s: Missing memory map\n", __func__);
+               goto err;
+       }
+
+       end = (struct efi_mem_desc *)((ulong)map + size);
+       desc = map->desc;
+       for (; desc < end; desc = efi_get_next_mem_desc(map, desc)) {
+               if (desc->type != EFI_CONVENTIONAL_MEMORY ||
+                   desc->physical_start >= 1ULL << 32)
+                       continue;
+               if (!largest || desc->num_pages > largest->num_pages)
+                       largest = desc;
+       }
+
+       /* If no suitable area was found, return an error. */
+       assert(largest);
+       if (!largest || (largest->num_pages << EFI_PAGE_SHIFT) < (2 << 20))
+               goto err;
+
+       dest_addr = largest->physical_start + (largest->num_pages <<
+                       EFI_PAGE_SHIFT);
+
+       return (ulong)dest_addr;
+err:
+       panic("No available memory found for relocation");
+       return 0;
+}
+
+int dram_init(void)
+{
+       struct efi_mem_desc *desc, *end;
+       struct efi_entry_memmap *map;
+       int size, ret;
+
+       ret = efi_info_get(EFIET_MEMORY_MAP, (void **)&map, &size);
+       if (ret) {
+               printf("Cannot find EFI memory map tables, ret=%d\n", ret);
+
+               return -ENODEV;
+       }
+
+       end = (struct efi_mem_desc *)((ulong)map + size);
+       gd->ram_size = 0;
+       desc = map->desc;
+       for (; desc < end; desc = efi_get_next_mem_desc(map, desc)) {
+               if (desc->type < EFI_MMAP_IO)
+                       gd->ram_size += desc->num_pages << EFI_PAGE_SHIFT;
+       }
+
+       return 0;
+}
+
+int dram_init_banksize(void)
+{
+       struct efi_mem_desc *desc, *end;
+       struct efi_entry_memmap *map;
+       int ret, size;
+       int num_banks;
+
+       ret = efi_info_get(EFIET_MEMORY_MAP, (void **)&map, &size);
+       if (ret) {
+               /* We should have stopped in dram_init(), something is wrong */
+               debug("%s: Missing memory map\n", __func__);
+               return -ENXIO;
+       }
+       end = (struct efi_mem_desc *)((ulong)map + size);
+       desc = map->desc;
+       for (num_banks = 0;
+            desc < end && num_banks < CONFIG_NR_DRAM_BANKS;
+            desc = efi_get_next_mem_desc(map, desc)) {
+               /*
+                * We only use conventional memory below 4GB, and ignore
+                * anything less than 1MB.
+                */
+               if (desc->type != EFI_CONVENTIONAL_MEMORY ||
+                   desc->physical_start >= 1ULL << 32 ||
+                   (desc->num_pages << EFI_PAGE_SHIFT) < 1 << 20)
+                       continue;
+               gd->bd->bi_dram[num_banks].start = desc->physical_start;
+               gd->bd->bi_dram[num_banks].size = desc->num_pages <<
+                       EFI_PAGE_SHIFT;
+               num_banks++;
+       }
+
+       return 0;
+}
+
+int checkcpu(void)
+{
+       return 0;
+}
+
+int print_cpuinfo(void)
+{
+       return default_print_cpuinfo();
+}
+
+/* Find any available tables and copy them to a safe place */
+int reserve_arch(void)
+{
+       struct efi_info_hdr *hdr;
+
+       debug("table=%lx\n", gd->arch.table);
+       if (!gd->arch.table)
+               return 0;
+
+       hdr = (struct efi_info_hdr *)gd->arch.table;
+
+       gd->start_addr_sp -= hdr->total_size;
+       memcpy((void *)gd->start_addr_sp, hdr, hdr->total_size);
+       debug("Stashing EFI table at %lx to %lx, size %x\n",
+             gd->arch.table, gd->start_addr_sp, hdr->total_size);
+       gd->arch.table = gd->start_addr_sp;
+
+       return 0;
+}
index 0e054da1e9eaab1a24209b47c3342087680c9366..ba07ac728f62bcc788b8ed47563b44f66484f641 100644 (file)
@@ -14,7 +14,6 @@ endif
 obj-y  += cmd_boot.o
 obj-$(CONFIG_SEABIOS) += coreboot_table.o
 obj-y  += early_cmos.o
-obj-$(CONFIG_EFI) += efi/
 obj-y  += e820.o
 obj-y  += init_helpers.o
 obj-y  += interrupts.o
diff --git a/arch/x86/lib/efi/Kconfig b/arch/x86/lib/efi/Kconfig
deleted file mode 100644 (file)
index e0975d3..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-if EFI
-
-config SYS_CAR_ADDR
-       hex
-       default 0x100000
-
-config SYS_CAR_SIZE
-       hex
-       default 0x20000
-
-endif
diff --git a/arch/x86/lib/efi/Makefile b/arch/x86/lib/efi/Makefile
deleted file mode 100644 (file)
index f6c6523..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0+
-#
-# (C) Copyright 2002-2006
-# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
-
-obj-$(CONFIG_EFI_STUB) += car.o
-obj-$(CONFIG_EFI_STUB) += efi.o
diff --git a/arch/x86/lib/efi/car.S b/arch/x86/lib/efi/car.S
deleted file mode 100644 (file)
index 488dcde..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
-/*
- * Copyright (c) 2015 Google, Inc
- * Written by Simon Glass <sjg@chromium.org>
- */
-
-.globl car_init
-car_init:
-       jmp     car_init_ret
diff --git a/arch/x86/lib/efi/efi.c b/arch/x86/lib/efi/efi.c
deleted file mode 100644 (file)
index 81fb8b5..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0+
-/*
- * Copyright (c) 2015 Google, Inc
- * Written by Simon Glass <sjg@chromium.org>
- */
-
-#include <common.h>
-#include <debug_uart.h>
-#include <efi.h>
-#include <errno.h>
-#include <linux/err.h>
-#include <linux/types.h>
-
-DECLARE_GLOBAL_DATA_PTR;
-
-/*
- * This function looks for the highest region of memory lower than 4GB which
- * has enough space for U-Boot where U-Boot is aligned on a page boundary.
- * It overrides the default implementation found elsewhere which simply
- * picks the end of ram, wherever that may be. The location of the stack,
- * the relocation address, and how far U-Boot is moved by relocation are
- * set in the global data structure.
- */
-ulong board_get_usable_ram_top(ulong total_size)
-{
-       struct efi_mem_desc *desc, *end;
-       struct efi_entry_memmap *map;
-       int ret, size;
-       uintptr_t dest_addr = 0;
-       struct efi_mem_desc *largest = NULL;
-
-       /*
-        * Find largest area of memory below 4GB. We could
-        * call efi_build_mem_table() for a more accurate picture since it
-        * merges areas together where possible. But that function uses more
-        * pre-relocation memory, and it's not critical that we find the
-        * absolute largest region.
-        */
-       ret = efi_info_get(EFIET_MEMORY_MAP, (void **)&map, &size);
-       if (ret) {
-               /* We should have stopped in dram_init(), something is wrong */
-               debug("%s: Missing memory map\n", __func__);
-               goto err;
-       }
-
-       end = (struct efi_mem_desc *)((ulong)map + size);
-       desc = map->desc;
-       for (; desc < end; desc = efi_get_next_mem_desc(map, desc)) {
-               if (desc->type != EFI_CONVENTIONAL_MEMORY ||
-                   desc->physical_start >= 1ULL << 32)
-                       continue;
-               if (!largest || desc->num_pages > largest->num_pages)
-                       largest = desc;
-       }
-
-       /* If no suitable area was found, return an error. */
-       assert(largest);
-       if (!largest || (largest->num_pages << EFI_PAGE_SHIFT) < (2 << 20))
-               goto err;
-
-       dest_addr = largest->physical_start + (largest->num_pages <<
-                       EFI_PAGE_SHIFT);
-
-       return (ulong)dest_addr;
-err:
-       panic("No available memory found for relocation");
-       return 0;
-}
-
-int dram_init(void)
-{
-       struct efi_mem_desc *desc, *end;
-       struct efi_entry_memmap *map;
-       int size, ret;
-
-       ret = efi_info_get(EFIET_MEMORY_MAP, (void **)&map, &size);
-       if (ret) {
-               printf("Cannot find EFI memory map tables, ret=%d\n", ret);
-
-               return -ENODEV;
-       }
-
-       end = (struct efi_mem_desc *)((ulong)map + size);
-       gd->ram_size = 0;
-       desc = map->desc;
-       for (; desc < end; desc = efi_get_next_mem_desc(map, desc)) {
-               if (desc->type < EFI_MMAP_IO)
-                       gd->ram_size += desc->num_pages << EFI_PAGE_SHIFT;
-       }
-
-       return 0;
-}
-
-int dram_init_banksize(void)
-{
-       struct efi_mem_desc *desc, *end;
-       struct efi_entry_memmap *map;
-       int ret, size;
-       int num_banks;
-
-       ret = efi_info_get(EFIET_MEMORY_MAP, (void **)&map, &size);
-       if (ret) {
-               /* We should have stopped in dram_init(), something is wrong */
-               debug("%s: Missing memory map\n", __func__);
-               return -ENXIO;
-       }
-       end = (struct efi_mem_desc *)((ulong)map + size);
-       desc = map->desc;
-       for (num_banks = 0;
-            desc < end && num_banks < CONFIG_NR_DRAM_BANKS;
-            desc = efi_get_next_mem_desc(map, desc)) {
-               /*
-                * We only use conventional memory below 4GB, and ignore
-                * anything less than 1MB.
-                */
-               if (desc->type != EFI_CONVENTIONAL_MEMORY ||
-                   desc->physical_start >= 1ULL << 32 ||
-                   (desc->num_pages << EFI_PAGE_SHIFT) < 1 << 20)
-                       continue;
-               gd->bd->bi_dram[num_banks].start = desc->physical_start;
-               gd->bd->bi_dram[num_banks].size = desc->num_pages <<
-                       EFI_PAGE_SHIFT;
-               num_banks++;
-       }
-
-       return 0;
-}
-
-int checkcpu(void)
-{
-       return 0;
-}
-
-int print_cpuinfo(void)
-{
-       return default_print_cpuinfo();
-}
-
-/* Find any available tables and copy them to a safe place */
-int reserve_arch(void)
-{
-       struct efi_info_hdr *hdr;
-
-       debug("table=%lx\n", gd->arch.table);
-       if (!gd->arch.table)
-               return 0;
-
-       hdr = (struct efi_info_hdr *)gd->arch.table;
-
-       gd->start_addr_sp -= hdr->total_size;
-       memcpy((void *)gd->start_addr_sp, hdr, hdr->total_size);
-       debug("Stashing EFI table at %lx to %lx, size %x\n",
-             gd->arch.table, gd->start_addr_sp, hdr->total_size);
-       gd->arch.table = gd->start_addr_sp;
-
-       return 0;
-}
index d5903c7bd3be54e0cef9546ea7b033ffaee91f2c..0349c5663af04d54c322241cb014158e7ff22a91 100644 (file)
@@ -235,12 +235,8 @@ Where is the code?
 lib/efi
        payload stub, application, support code. Mostly arch-neutral
 
-arch/x86/lib/efi
-       helper functions for the fake DRAM init, etc. These can be used by
-       any board that runs as a payload.
-
 arch/x86/cpu/efi
-       x86 support code for running as an EFI application
+       x86 support code for running as an EFI application and payload
 
 board/efi/efi-x86/efi.c
        x86 board code for running as an EFI application