summaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorGabe Black <gabeblack@chromium.org>2012-01-11 22:26:09 -0800
committerGerrit <chrome-bot@google.com>2012-01-13 21:44:34 -0800
commit51746130a41284ceb487da9220ec707bd025e198 (patch)
treecd767dd8da005ee8d69b90a7b89b798aad609a75 /arch
parent4252c8c013bb44c4efb5104e0336d5d63c0b5aa3 (diff)
X86: Override calculate_relocation_address to use the e820 map
Because calculate_relocation_address now uses the e820 map, it will be able to avoid addresses over 32 bits and regions that are at high addresses but not big enough for U-Boot. It also means we can remove the hack which limitted U-Boot's idea of the size of memory to less than 4GB. BUG=None TEST=Built and booted on Lumpy. Built on Kaen. Change-Id: I3ada4e5325ae3a0e652cf79486970e967aef6da6 Signed-off-by: Gabe Black <gabeblack@google.com> Reviewed-on: https://gerrit.chromium.org/gerrit/14152
Diffstat (limited to 'arch')
-rw-r--r--arch/x86/cpu/coreboot/sdram.c51
1 files changed, 47 insertions, 4 deletions
diff --git a/arch/x86/cpu/coreboot/sdram.c b/arch/x86/cpu/coreboot/sdram.c
index 5fa799ea68..f9693b1bfe 100644
--- a/arch/x86/cpu/coreboot/sdram.c
+++ b/arch/x86/cpu/coreboot/sdram.c
@@ -54,6 +54,53 @@ unsigned install_e820_map(unsigned max_entries, struct e820entry *entries)
extern uint8_t __text_start;
extern uint8_t __bss_end;
+int __calculate_relocation_address(void);
+
+/*
+ * 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.
+ */
+int calculate_relocation_address(void)
+{
+ uint64_t uboot_size = &__bss_end - &__text_start;
+ uintptr_t dest_addr = 0;
+ int i;
+
+ for (i = 0; i < lib_sysinfo.n_memranges; i++) {
+ struct memrange *memrange = &lib_sysinfo.memrange[i];
+ /* Force U-Boot to relocate to a page aligned address. */
+ uint64_t start = roundup(memrange->base, 1 << 12);
+ uint64_t end = memrange->base + memrange->size;
+
+ /* Ignore non-memory regions. */
+ if (memrange->type != CB_MEM_RAM)
+ continue;
+
+ /* Filter memory over 4GB and regions that are too small. */
+ if (end > 0xffffffffULL)
+ end = 0x100000000ULL;
+ if (end - start < uboot_size)
+ continue;
+
+ if (end - uboot_size > dest_addr)
+ dest_addr = ROUND((end - uboot_size), 1 << 12);
+ }
+
+ /* If no suitable area was found, return an error. */
+ if (!dest_addr)
+ return 1;
+
+ gd->start_addr_sp = dest_addr - CONFIG_SYS_MALLOC_LEN;
+ gd->relocaddr = dest_addr;
+ gd->reloc_off = dest_addr - (uintptr_t)&__text_start;
+
+ return 0;
+}
+
int dram_init_f(void) {
int i;
phys_size_t ram_size = 0;
@@ -62,10 +109,6 @@ int dram_init_f(void) {
struct memrange *memrange = &lib_sysinfo.memrange[i];
unsigned long long end = memrange->base + memrange->size;
- /* Ignore memory over 4GB, we can't use it. */
- if (memrange->base > 0xffffffff)
- continue;
-
if (memrange->type == CB_MEM_RAM && end > ram_size)
ram_size = end;
}