bootstage: Correct relocation algorithm
[oweals/u-boot.git] / common / board_f.c
index 6867abc8e67936455760de0d0af652e28fdec7bf..e3591cbaebdbf48aa9fd65ddafdd26c1a167b530 100644 (file)
@@ -470,9 +470,18 @@ static int reserve_uboot(void)
 #ifdef CONFIG_SYS_NONCACHED_MEMORY
 static int reserve_noncached(void)
 {
-       /* round down to SECTION SIZE (typicaly 1MB) limit */
-       gd->start_addr_sp &= ~(MMU_SECTION_SIZE - 1);
-       gd->start_addr_sp -= CONFIG_SYS_NONCACHED_MEMORY;
+       /*
+        * 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);
 
@@ -579,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
@@ -686,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