bootstage: Correct relocation algorithm
[oweals/u-boot.git] / common / board_f.c
index c25eb188fb2506b8399edc25571998baafae64e6..e3591cbaebdbf48aa9fd65ddafdd26c1a167b530 100644 (file)
 #include <console.h>
 #include <cpu.h>
 #include <dm.h>
-#include <environment.h>
+#include <env.h>
+#include <env_internal.h>
 #include <fdtdec.h>
 #include <fs.h>
 #include <i2c.h>
 #include <initcall.h>
+#include <lcd.h>
 #include <malloc.h>
 #include <mapmem.h>
 #include <os.h>
@@ -425,13 +427,6 @@ static int reserve_video(void)
        gd->relocaddr = lcd_setmem(gd->relocaddr);
        gd->fb_base = gd->relocaddr;
 #  endif /* CONFIG_FB_ADDR */
-#elif defined(CONFIG_VIDEO) && \
-               (!defined(CONFIG_PPC)) && \
-               !defined(CONFIG_ARM) && !defined(CONFIG_X86) && \
-               !defined(CONFIG_M68K)
-       /* reserve memory for video display (always full pages) */
-       gd->relocaddr = video_setmem(gd->relocaddr);
-       gd->fb_base = gd->relocaddr;
 #endif
 
        return 0;
@@ -442,8 +437,8 @@ static int reserve_trace(void)
 #ifdef CONFIG_TRACE
        gd->relocaddr -= CONFIG_TRACE_BUFFER_SIZE;
        gd->trace_buff = map_sysmem(gd->relocaddr, CONFIG_TRACE_BUFFER_SIZE);
-       debug("Reserving %dk for trace data at: %08lx\n",
-             CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr);
+       debug("Reserving %luk for trace data at: %08lx\n",
+             (unsigned long)CONFIG_TRACE_BUFFER_SIZE >> 10, gd->relocaddr);
 #endif
 
        return 0;
@@ -472,12 +467,38 @@ static int reserve_uboot(void)
        return 0;
 }
 
+#ifdef CONFIG_SYS_NONCACHED_MEMORY
+static int reserve_noncached(void)
+{
+       /*
+        * The value of gd->start_addr_sp must match the value of malloc_start
+        * calculated in boatrd_f.c:initr_malloc(), which is passed to
+        * board_r.c:mem_malloc_init() and then used by
+        * cache.c:noncached_init()
+        *
+        * These calculations must match the code in cache.c:noncached_init()
+        */
+       gd->start_addr_sp = ALIGN(gd->start_addr_sp, MMU_SECTION_SIZE) -
+               MMU_SECTION_SIZE;
+       gd->start_addr_sp -= ALIGN(CONFIG_SYS_NONCACHED_MEMORY,
+                                  MMU_SECTION_SIZE);
+       debug("Reserving %dM for noncached_alloc() at: %08lx\n",
+             CONFIG_SYS_NONCACHED_MEMORY >> 20, gd->start_addr_sp);
+
+       return 0;
+}
+#endif
+
 /* reserve memory for malloc() area */
 static int reserve_malloc(void)
 {
        gd->start_addr_sp = gd->start_addr_sp - TOTAL_MALLOC_LEN;
        debug("Reserving %dk for malloc() at: %08lx\n",
              TOTAL_MALLOC_LEN >> 10, gd->start_addr_sp);
+#ifdef CONFIG_SYS_NONCACHED_MEMORY
+       reserve_noncached();
+#endif
+
        return 0;
 }
 
@@ -567,6 +588,7 @@ static int reserve_stacks(void)
 static int reserve_bloblist(void)
 {
 #ifdef CONFIG_BLOBLIST
+       gd->start_addr_sp &= ~0xf;
        gd->start_addr_sp -= CONFIG_BLOBLIST_SIZE;
        gd->new_bloblist = map_sysmem(gd->start_addr_sp, CONFIG_BLOBLIST_SIZE);
 #endif
@@ -674,6 +696,7 @@ static int reloc_bootstage(void)
                      gd->bootstage, gd->new_bootstage, size);
                memcpy(gd->new_bootstage, gd->bootstage, size);
                gd->bootstage = gd->new_bootstage;
+               bootstage_relocate();
        }
 #endif
 
@@ -839,7 +862,7 @@ static const init_fnc_t init_sequence_f[] = {
 #ifdef CONFIG_OF_CONTROL
        fdtdec_setup,
 #endif
-#ifdef CONFIG_TRACE
+#ifdef CONFIG_TRACE_EARLY
        trace_early_init,
 #endif
        initf_malloc,