diff options
Diffstat (limited to 'arch/x86/lib')
-rw-r--r-- | arch/x86/lib/Makefile | 3 | ||||
-rw-r--r-- | arch/x86/lib/asm-offsets.c | 1 | ||||
-rw-r--r-- | arch/x86/lib/bootm.c | 7 | ||||
-rw-r--r-- | arch/x86/lib/efi/Kconfig | 11 | ||||
-rw-r--r-- | arch/x86/lib/efi/Makefile | 27 | ||||
-rw-r--r-- | arch/x86/lib/efi/car.S | 10 | ||||
-rw-r--r-- | arch/x86/lib/efi/crt0-efi-ia32.S | 52 | ||||
-rw-r--r-- | arch/x86/lib/efi/crt0-efi-x86_64.S | 51 | ||||
-rw-r--r-- | arch/x86/lib/efi/efi.c | 151 | ||||
-rw-r--r-- | arch/x86/lib/efi/reloc_ia32.c | 72 | ||||
-rw-r--r-- | arch/x86/lib/efi/reloc_x86_64.c | 66 | ||||
-rw-r--r-- | arch/x86/lib/fsp/fsp_common.c | 2 | ||||
-rw-r--r-- | arch/x86/lib/lpc-uclass.c | 2 | ||||
-rw-r--r-- | arch/x86/lib/pch-uclass.c | 2 | ||||
-rw-r--r-- | arch/x86/lib/relocate.c | 41 | ||||
-rw-r--r-- | arch/x86/lib/tsc_timer.c | 8 |
16 files changed, 481 insertions, 25 deletions
diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile index 43489fdc1f..dcfe9ee85c 100644 --- a/arch/x86/lib/Makefile +++ b/arch/x86/lib/Makefile @@ -11,6 +11,7 @@ obj-y += bios_interrupts.o obj-$(CONFIG_CMD_BOOTM) += bootm.o obj-y += cmd_boot.o obj-$(CONFIG_HAVE_FSP) += cmd_hob.o +obj-$(CONFIG_EFI) += efi/ obj-y += gcc.o obj-y += init_helpers.o obj-y += interrupts.o @@ -34,7 +35,7 @@ obj-$(CONFIG_SYS_X86_TSC_TIMER) += tsc_timer.o obj-$(CONFIG_CMD_ZBOOT) += zimage.o obj-$(CONFIG_HAVE_FSP) += fsp/ -extra-$(CONFIG_USE_PRIVATE_LIBGCC) := lib.a +extra-$(CONFIG_USE_PRIVATE_LIBGCC) += lib.a NORMAL_LIBGCC = $(shell $(CC) $(PLATFORM_CPPFLAGS) -print-libgcc-file-name) OBJCOPYFLAGS := --prefix-symbols=__normal_ diff --git a/arch/x86/lib/asm-offsets.c b/arch/x86/lib/asm-offsets.c index 70ccf1b0b0..9da04dd875 100644 --- a/arch/x86/lib/asm-offsets.c +++ b/arch/x86/lib/asm-offsets.c @@ -21,5 +21,6 @@ int main(void) #ifdef CONFIG_HAVE_FSP DEFINE(GD_HOB_LIST, offsetof(gd_t, arch.hob_list)); #endif + DEFINE(GD_TABLE, offsetof(gd_t, arch.table)); return 0; } diff --git a/arch/x86/lib/bootm.c b/arch/x86/lib/bootm.c index 86030cf52a..f441c84df5 100644 --- a/arch/x86/lib/bootm.c +++ b/arch/x86/lib/bootm.c @@ -22,6 +22,8 @@ #include <asm/arch/timestamp.h> #endif +DECLARE_GLOBAL_DATA_PTR; + #define COMMAND_LINE_OFFSET 0x9000 /* @@ -162,7 +164,11 @@ int boot_linux_kernel(ulong setup_base, ulong load_address, bool image_64bit) * the data segments are 0x18, 4GB flat, and read/write. * U-boot is setting them up that way for itself in * arch/i386/cpu/cpu.c. + * + * Note that we cannot currently boot a kernel while running as + * an EFI application. Please use the payload option for that. */ +#ifndef CONFIG_EFI_APP __asm__ __volatile__ ( "movl $0, %%ebp\n" "cli\n" @@ -171,6 +177,7 @@ int boot_linux_kernel(ulong setup_base, ulong load_address, bool image_64bit) [boot_params] "S"(setup_base), "b"(0), "D"(0) ); +#endif } /* We can't get to here */ diff --git a/arch/x86/lib/efi/Kconfig b/arch/x86/lib/efi/Kconfig new file mode 100644 index 0000000000..e0975d34d3 --- /dev/null +++ b/arch/x86/lib/efi/Kconfig @@ -0,0 +1,11 @@ +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 new file mode 100644 index 0000000000..af4503e1c2 --- /dev/null +++ b/arch/x86/lib/efi/Makefile @@ -0,0 +1,27 @@ +# +# (C) Copyright 2002-2006 +# Wolfgang Denk, DENX Software Engineering, wd@denx.de. +# +# SPDX-License-Identifier: GPL-2.0+ +# + +obj-$(CONFIG_EFI_STUB) += car.o +obj-$(CONFIG_EFI_STUB) += efi.o + +obj-$(CONFIG_EFI_APP) += crt0-efi-ia32.o reloc_ia32.o + +ifneq ($(CONFIG_EFI_STUB),) + +CFLAGS_REMOVE_reloc_ia32.o += -mregparm=3 +CFLAGS_reloc_ia32.o += -fpic -fshort-wchar + +# When building for 64-bit we must remove the i386-specific flags +CFLAGS_REMOVE_reloc_x86_64.o += -mregparm=3 -march=i386 -m32 +CFLAGS_reloc_x86_64.o += -fpic -fshort-wchar + +AFLAGS_REMOVE_crt0-efi-x86_64.o += -mregparm=3 -march=i386 -m32 +AFLAGS_crt0-efi-x86_64.o += -fpic -fshort-wchar + +extra-$(CONFIG_EFI_STUB_32BIT) += crt0-efi-ia32.o reloc_ia32.o +extra-$(CONFIG_EFI_STUB_64BIT) += crt0-efi-x86_64.o reloc_x86_64.o +endif diff --git a/arch/x86/lib/efi/car.S b/arch/x86/lib/efi/car.S new file mode 100644 index 0000000000..613af9ac8a --- /dev/null +++ b/arch/x86/lib/efi/car.S @@ -0,0 +1,10 @@ +/* + * Copyright (c) 2015 Google, Inc + * Written by Simon Glass <sjg@chromium.org> + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +.globl car_init +car_init: + jmp car_init_ret diff --git a/arch/x86/lib/efi/crt0-efi-ia32.S b/arch/x86/lib/efi/crt0-efi-ia32.S new file mode 100644 index 0000000000..30e5eb0c1a --- /dev/null +++ b/arch/x86/lib/efi/crt0-efi-ia32.S @@ -0,0 +1,52 @@ +/* + * crt0-efi-ia32.S - x86 EFI startup code. + * + * Copyright (C) 1999 Hewlett-Packard Co. + * Contributed by David Mosberger <davidm@hpl.hp.com>. + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + + .text + .align 4 + + .globl _start +_start: + pushl %ebp + movl %esp,%ebp + + pushl 12(%ebp) # copy "image" argument + pushl 8(%ebp) # copy "systab" argument + + call 0f +0: popl %eax + movl %eax,%ebx + + addl $image_base-0b,%eax # %eax = ldbase + addl $_DYNAMIC-0b,%ebx # %ebx = _DYNAMIC + + pushl %ebx # pass _DYNAMIC as second argument + pushl %eax # pass ldbase as first argument + call _relocate + popl %ebx + popl %ebx + testl %eax,%eax + jne .exit + call efi_main # call app with "image" and "systab" argument + +.exit: leave + ret + + /* + * hand-craft a dummy .reloc section so EFI knows it's a relocatable + * executable: + */ + .data +dummy: .long 0 + +#define IMAGE_REL_ABSOLUTE 0 + .section .reloc + .long dummy /* Page RVA */ + .long 10 /* Block Size (2*4+2) */ + .word (IMAGE_REL_ABSOLUTE << 12) + 0 /* reloc for dummy */ diff --git a/arch/x86/lib/efi/crt0-efi-x86_64.S b/arch/x86/lib/efi/crt0-efi-x86_64.S new file mode 100644 index 0000000000..c5cbf4108b --- /dev/null +++ b/arch/x86/lib/efi/crt0-efi-x86_64.S @@ -0,0 +1,51 @@ +/* + * crt0-efi-x86_64.S - x86_64 EFI startup code. + * Copyright (C) 1999 Hewlett-Packard Co. + * Contributed by David Mosberger <davidm@hpl.hp.com>. + * Copyright (C) 2005 Intel Co. + * Contributed by Fenghua Yu <fenghua.yu@intel.com>. + * + * All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause + */ + .text + .align 4 + + .globl _start +_start: + subq $8, %rsp + pushq %rcx + pushq %rdx + +0: + lea image_base(%rip), %rdi + lea _DYNAMIC(%rip), %rsi + + popq %rcx + popq %rdx + pushq %rcx + pushq %rdx + call _relocate + + popq %rdi + popq %rsi + + call efi_main + addq $8, %rsp + +.exit: + ret + + /* + * hand-craft a dummy .reloc section so EFI knows it's a relocatable + * executable: + */ + .data +dummy: .long 0 + +#define IMAGE_REL_ABSOLUTE 0 + .section .reloc, "a" +label1: + .long dummy-label1 /* Page RVA */ + .long 10 /* Block Size (2*4+2) */ + .word (IMAGE_REL_ABSOLUTE << 12) + 0 /* reloc for dummy */ diff --git a/arch/x86/lib/efi/efi.c b/arch/x86/lib/efi/efi.c new file mode 100644 index 0000000000..ede5d5676b --- /dev/null +++ b/arch/x86/lib/efi/efi.c @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2015 Google, Inc + * Written by Simon Glass <sjg@chromium.org> + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#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; +} + +void 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; + } + 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++; + } +} + +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; +} diff --git a/arch/x86/lib/efi/reloc_ia32.c b/arch/x86/lib/efi/reloc_ia32.c new file mode 100644 index 0000000000..4d6825515d --- /dev/null +++ b/arch/x86/lib/efi/reloc_ia32.c @@ -0,0 +1,72 @@ +/* + * reloc_ia32.c - position independent x86 ELF shared object relocator + * Copyright (C) 1999 Hewlett-Packard Co. + * Contributed by David Mosberger <davidm@hpl.hp.com>. + * + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include <common.h> +#include <efi.h> +#include <elf.h> +#include <asm/elf.h> + +efi_status_t _relocate(long ldbase, Elf32_Dyn *dyn, efi_handle_t image, + struct efi_system_table *systab) +{ + long relsz = 0, relent = 0; + Elf32_Rel *rel = 0; + unsigned long *addr; + int i; + + for (i = 0; dyn[i].d_tag != DT_NULL; ++i) { + switch (dyn[i].d_tag) { + case DT_REL: + rel = (Elf32_Rel *)((unsigned long)dyn[i].d_un.d_ptr + + ldbase); + break; + + case DT_RELSZ: + relsz = dyn[i].d_un.d_val; + break; + + case DT_RELENT: + relent = dyn[i].d_un.d_val; + break; + + case DT_RELA: + break; + + default: + break; + } + } + + if (!rel && relent == 0) + return EFI_SUCCESS; + + if (!rel || relent == 0) + return EFI_LOAD_ERROR; + + while (relsz > 0) { + /* apply the relocs */ + switch (ELF32_R_TYPE(rel->r_info)) { + case R_386_NONE: + break; + + case R_386_RELATIVE: + addr = (unsigned long *)(ldbase + rel->r_offset); + *addr += ldbase; + break; + + default: + break; + } + rel = (Elf32_Rel *)((char *)rel + relent); + relsz -= relent; + } + + return EFI_SUCCESS; +} diff --git a/arch/x86/lib/efi/reloc_x86_64.c b/arch/x86/lib/efi/reloc_x86_64.c new file mode 100644 index 0000000000..5f71f2ac8a --- /dev/null +++ b/arch/x86/lib/efi/reloc_x86_64.c @@ -0,0 +1,66 @@ +/* + * reloc_x86_64.c - position independent x86_64 ELF shared object relocator + * Copyright (C) 1999 Hewlett-Packard Co. + * Contributed by David Mosberger <davidm@hpl.hp.com>. + * Copyright (C) 2005 Intel Co. + * Contributed by Fenghua Yu <fenghua.yu@intel.com>. + * + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include <common.h> +#include <efi.h> +#include <elf.h> +#include <asm/elf.h> + +efi_status_t _relocate(long ldbase, Elf64_Dyn *dyn, efi_handle_t image, + struct efi_system_table *systab) +{ + long relsz = 0, relent = 0; + Elf64_Rel *rel = 0; + unsigned long *addr; + int i; + + for (i = 0; dyn[i].d_tag != DT_NULL; ++i) { + switch (dyn[i].d_tag) { + case DT_RELA: + rel = (Elf64_Rel *) + ((unsigned long)dyn[i].d_un.d_ptr + ldbase); + break; + case DT_RELASZ: + relsz = dyn[i].d_un.d_val; + break; + case DT_RELAENT: + relent = dyn[i].d_un.d_val; + break; + default: + break; + } + } + + if (!rel && relent == 0) + return EFI_SUCCESS; + + if (!rel || relent == 0) + return EFI_LOAD_ERROR; + + while (relsz > 0) { + /* apply the relocs */ + switch (ELF64_R_TYPE(rel->r_info)) { + case R_X86_64_NONE: + break; + case R_X86_64_RELATIVE: + addr = (unsigned long *)(ldbase + rel->r_offset); + *addr += ldbase; + break; + default: + break; + } + rel = (Elf64_Rel *)((char *)rel + relent); + relsz -= relent; + } + + return EFI_SUCCESS; +} diff --git a/arch/x86/lib/fsp/fsp_common.c b/arch/x86/lib/fsp/fsp_common.c index 5b256324e1..c585710824 100644 --- a/arch/x86/lib/fsp/fsp_common.c +++ b/arch/x86/lib/fsp/fsp_common.c @@ -11,6 +11,8 @@ #include <asm/processor.h> #include <asm/fsp/fsp_support.h> +DECLARE_GLOBAL_DATA_PTR; + int print_cpuinfo(void) { post_code(POST_CPU_INFO); diff --git a/arch/x86/lib/lpc-uclass.c b/arch/x86/lib/lpc-uclass.c index 6aeb4d461a..c6e8f73d22 100644 --- a/arch/x86/lib/lpc-uclass.c +++ b/arch/x86/lib/lpc-uclass.c @@ -9,6 +9,8 @@ #include <dm.h> #include <dm/root.h> +DECLARE_GLOBAL_DATA_PTR; + static int lpc_uclass_post_bind(struct udevice *bus) { /* diff --git a/arch/x86/lib/pch-uclass.c b/arch/x86/lib/pch-uclass.c index d1082e1a47..20dfa815d2 100644 --- a/arch/x86/lib/pch-uclass.c +++ b/arch/x86/lib/pch-uclass.c @@ -9,6 +9,8 @@ #include <dm.h> #include <dm/root.h> +DECLARE_GLOBAL_DATA_PTR; + static int pch_uclass_post_bind(struct udevice *bus) { /* diff --git a/arch/x86/lib/relocate.c b/arch/x86/lib/relocate.c index b33586b54c..0d683bfc12 100644 --- a/arch/x86/lib/relocate.c +++ b/arch/x86/lib/relocate.c @@ -17,8 +17,6 @@ #include <common.h> #include <inttypes.h> -#include <libfdt.h> -#include <malloc.h> #include <asm/u-boot-x86.h> #include <asm/relocate.h> #include <asm/sections.h> @@ -30,32 +28,20 @@ int copy_uboot_to_ram(void) { size_t len = (size_t)&__data_end - (size_t)&__text_start; + if (gd->flags & GD_FLG_SKIP_RELOC) + return 0; memcpy((void *)gd->relocaddr, (void *)&__text_start, len); return 0; } -int copy_fdt_to_ram(void) -{ - if (gd->new_fdt) { - ulong fdt_size; - - fdt_size = ALIGN(fdt_totalsize(gd->fdt_blob) + 0x1000, 32); - - memcpy(gd->new_fdt, gd->fdt_blob, fdt_size); - debug("Relocated fdt from %p to %p, size %lx\n", - gd->fdt_blob, gd->new_fdt, fdt_size); - gd->fdt_blob = gd->new_fdt; - } - - return 0; -} - int clear_bss(void) { ulong dst_addr = (ulong)&__bss_start + gd->reloc_off; size_t len = (size_t)&__bss_end - (size_t)&__bss_start; + if (gd->flags & GD_FLG_SKIP_RELOC) + return 0; memset((void *)dst_addr, 0x00, len); return 0; @@ -72,36 +58,43 @@ int do_elf_reloc_fixups(void) Elf32_Addr *offset_ptr_rom, *last_offset = NULL; Elf32_Addr *offset_ptr_ram; + unsigned int text_base = 0; /* The size of the region of u-boot that runs out of RAM. */ uintptr_t size = (uintptr_t)&__bss_end - (uintptr_t)&__text_start; + if (gd->flags & GD_FLG_SKIP_RELOC) + return 0; if (re_src == re_end) panic("No relocation data"); +#ifdef CONFIG_SYS_TEXT_BASE + text_base = CONFIG_SYS_TEXT_BASE; +#else + panic("No CONFIG_SYS_TEXT_BASE"); +#endif do { /* Get the location from the relocation entry */ offset_ptr_rom = (Elf32_Addr *)re_src->r_offset; /* Check that the location of the relocation is in .text */ - if (offset_ptr_rom >= (Elf32_Addr *)CONFIG_SYS_TEXT_BASE && - offset_ptr_rom > last_offset) { + if (offset_ptr_rom >= (Elf32_Addr *)text_base && + offset_ptr_rom > last_offset) { /* Switch to the in-RAM version */ offset_ptr_ram = (Elf32_Addr *)((ulong)offset_ptr_rom + gd->reloc_off); /* Check that the target points into .text */ - if (*offset_ptr_ram >= CONFIG_SYS_TEXT_BASE && - *offset_ptr_ram <= - (CONFIG_SYS_TEXT_BASE + size)) { + if (*offset_ptr_ram >= text_base && + *offset_ptr_ram <= text_base + size) { *offset_ptr_ram += gd->reloc_off; } else { debug(" %p: rom reloc %x, ram %p, value %x," " limit %" PRIXPTR "\n", re_src, re_src->r_offset, offset_ptr_ram, *offset_ptr_ram, - CONFIG_SYS_TEXT_BASE + size); + text_base + size); } } else { debug(" %p: rom reloc %x, last %p\n", re_src, diff --git a/arch/x86/lib/tsc_timer.c b/arch/x86/lib/tsc_timer.c index 7f5ba2ca6f..0df1af238c 100644 --- a/arch/x86/lib/tsc_timer.c +++ b/arch/x86/lib/tsc_timer.c @@ -355,7 +355,15 @@ void __udelay(unsigned long usec) stop = now + usec * get_tbclk_mhz(); while ((int64_t)(stop - get_ticks()) > 0) +#if defined(CONFIG_QEMU) && defined(CONFIG_SMP) + /* + * Add a 'pause' instruction on qemu target, + * to give other VCPUs a chance to run. + */ + asm volatile("pause"); +#else ; +#endif } int timer_init(void) |