summaryrefslogtreecommitdiff
path: root/common/board_f.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/board_f.c')
-rw-r--r--common/board_f.c82
1 files changed, 62 insertions, 20 deletions
diff --git a/common/board_f.c b/common/board_f.c
index ce87c619e68..85b888d4bb8 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -31,6 +31,7 @@
#include <log.h>
#include <malloc.h>
#include <mapmem.h>
+#include <memtop.h>
#include <os.h>
#include <post.h>
#include <relocate.h>
@@ -50,6 +51,7 @@
#include <dm/root.h>
#include <linux/errno.h>
#include <linux/log2.h>
+#include <linux/sizes.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -222,11 +224,11 @@ static int show_dram_config(void)
debug("\nRAM Configuration:\n");
for (i = size = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
- size += gd->bd->bi_dram[i].size;
+ size += gd->dram[i].size;
debug("Bank #%d: %llx ", i,
- (unsigned long long)(gd->bd->bi_dram[i].start));
+ (unsigned long long)(gd->dram[i].start));
#ifdef DEBUG
- print_size(gd->bd->bi_dram[i].size, "\n");
+ print_size(gd->dram[i].size, "\n");
#endif
}
debug("\nDRAM: ");
@@ -244,8 +246,8 @@ static int show_dram_config(void)
__weak int dram_init_banksize(void)
{
- gd->bd->bi_dram[0].start = gd->ram_base;
- gd->bd->bi_dram[0].size = get_effective_memsize();
+ gd->dram[0].start = gd->ram_base;
+ gd->dram[0].size = get_effective_memsize();
return 0;
}
@@ -308,6 +310,9 @@ __weak int mach_cpu_init(void)
/* Get the top of usable RAM */
__weak phys_addr_t board_get_usable_ram_top(phys_size_t total_size)
{
+ if (CONFIG_IS_ENABLED(RELOC_ADDR_TOP))
+ return gd->ram_top;
+
#if defined(CFG_SYS_SDRAM_BASE) && CFG_SYS_SDRAM_BASE > 0
/*
* Detect whether we have so much RAM that it goes past the end of our
@@ -328,14 +333,34 @@ __weak int arch_setup_dest_addr(void)
return 0;
}
-static int setup_dest_addr(void)
+static int setup_ram_base(void)
+{
+#ifdef CFG_SYS_SDRAM_BASE
+ gd->ram_base = CFG_SYS_SDRAM_BASE;
+#endif
+ return 0;
+}
+
+static int setup_ram_config(void)
{
debug("Monitor len: %08x\n", gd->mon_len);
- /*
- * Ram is setup, size stored in gd !!
- */
- debug("Ram size: %08llX\n", (unsigned long long)gd->ram_size);
-#if CONFIG_VAL(SYS_MEM_TOP_HIDE)
+
+ if (CONFIG_IS_ENABLED(RELOC_ADDR_TOP)) {
+ int i;
+ phys_addr_t top;
+
+ gd->ram_size = 0;
+ for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
+ top = get_mem_top(gd->dram[i].start, gd->dram[i].size,
+ ALIGN(gd->mon_len, SZ_1M),
+ (void *)gd->fdt_blob);
+ gd->ram_top = max(top, gd->ram_top);
+ gd->ram_size += gd->dram[i].size;
+ }
+ } else {
+ gd->ram_top = gd->ram_base + get_effective_memsize();
+ }
+ gd->ram_top = board_get_usable_ram_top(gd->mon_len);
/*
* Subtract specified amount of memory to hide so that it won't
* get "touched" at all by U-Boot. By fixing up gd->ram_size
@@ -346,17 +371,30 @@ static int setup_dest_addr(void)
* memory size from the SDRAM controller setup will have to
* get fixed.
*/
+#if CONFIG_VAL(SYS_MEM_TOP_HIDE)
+ gd->ram_top -= CONFIG_SYS_MEM_TOP_HIDE;
gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
#endif
-#ifdef CFG_SYS_SDRAM_BASE
- gd->ram_base = CFG_SYS_SDRAM_BASE;
-#endif
- gd->ram_top = gd->ram_base + get_effective_memsize();
- gd->ram_top = board_get_usable_ram_top(gd->mon_len);
+
+ debug("Ram top: %08llx\n", (unsigned long long)gd->ram_top);
+ debug("Ram size: %08llx\n", (unsigned long long)gd->ram_size);
+
+ return 0;
+}
+
+static int setup_dest_addr(void)
+{
+ int ret;
+
gd->relocaddr = gd->ram_top;
- debug("Ram top: %08llX\n", (unsigned long long)gd->ram_top);
+ debug("Reloc addr: %08llX\n", (unsigned long long)gd->relocaddr);
+
+ ret = arch_setup_dest_addr();
+ if (ret)
+ return ret;
- return arch_setup_dest_addr();
+ gd->initial_relocaddr = gd->relocaddr;
+ return 0;
}
#ifdef CFG_PRAM
@@ -894,7 +932,9 @@ static void initcall_run_f(void)
INITCALL(log_init);
INITCALL(initf_bootstage); /* uses its own timer, so does not need DM */
INITCALL(event_init);
- INITCALL(bloblist_maybe_init);
+#if CONFIG_IS_ENABLED(BLOBLIST)
+ INITCALL(bloblist_init);
+#endif
INITCALL(setup_spl_handoff);
#if CONFIG_IS_ENABLED(CONSOLE_RECORD_INIT_F)
INITCALL(console_record_init);
@@ -968,6 +1008,9 @@ static void initcall_run_f(void)
* - monitor code
* - board info struct
*/
+ INITCALL(setup_ram_base);
+ INITCALL(dram_init_banksize);
+ INITCALL(setup_ram_config);
INITCALL(setup_dest_addr);
#if CONFIG_IS_ENABLED(OF_BOARD_FIXUP) && \
!CONFIG_IS_ENABLED(OF_INITIAL_DTB_READONLY)
@@ -995,7 +1038,6 @@ static void initcall_run_f(void)
INITCALL(reserve_bloblist);
INITCALL(reserve_arch);
INITCALL(reserve_stacks);
- INITCALL(dram_init_banksize);
INITCALL(show_dram_config);
WATCHDOG_RESET();
INITCALL(setup_bdinfo);