ARM: bootm: take into account gd->ram_top
[oweals/u-boot.git] / arch / arm / lib / bootm.c
index c3c1d2fdfa2d8ab9d4eacd4a8218f3455fe3a8fc..f4b5ca6de004dec95d8b2924984bac040e33da6a 100644 (file)
 
 #include <common.h>
 #include <command.h>
+#include <cpu_func.h>
 #include <dm.h>
+#include <hang.h>
 #include <dm/root.h>
+#include <env.h>
 #include <image.h>
 #include <u-boot/zlib.h>
 #include <asm/byteorder.h>
@@ -64,13 +67,18 @@ void arch_lmb_reserve(struct lmb *lmb)
        /* adjust sp by 4K to be safe */
        sp -= 4096;
        for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
-               if (sp < gd->bd->bi_dram[bank].start)
+               if (!gd->bd->bi_dram[bank].size ||
+                   sp < gd->bd->bi_dram[bank].start)
                        continue;
+               /* Watch out for RAM at end of address space! */
                bank_end = gd->bd->bi_dram[bank].start +
-                       gd->bd->bi_dram[bank].size;
-               if (sp >= bank_end)
+                       gd->bd->bi_dram[bank].size - 1;
+               if (sp > bank_end)
                        continue;
-               lmb_reserve(lmb, sp, bank_end - sp);
+               if (bank_end > gd->ram_top)
+                       bank_end = gd->ram_top - 1;
+
+               lmb_reserve(lmb, sp, bank_end - sp + 1);
                break;
        }
 }
@@ -86,8 +94,6 @@ __weak void board_quiesce_devices(void)
  */
 static void announce_and_cleanup(int fake)
 {
-       printf("\nStarting kernel ...%s\n\n", fake ?
-               "(fake run for tracing)" : "");
        bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
 #ifdef CONFIG_BOOTSTAGE_FDT
        bootstage_fdt_add_report();
@@ -102,6 +108,8 @@ static void announce_and_cleanup(int fake)
 
        board_quiesce_devices();
 
+       printf("\nStarting kernel ...%s\n\n", fake ?
+               "(fake run for tracing)" : "");
        /*
         * Call remove function of all devices with a removal flag set.
         * This may be useful for last-stage operations, like cancelling
@@ -221,6 +229,8 @@ static void do_nonsec_virt_switch(void)
 }
 #endif
 
+__weak void board_prep_linux(bootm_headers_t *images) { }
+
 /* Subcommand: PREP */
 static void boot_prep_linux(bootm_headers_t *images)
 {
@@ -267,6 +277,8 @@ static void boot_prep_linux(bootm_headers_t *images)
                printf("FDT and ATAGS support not compiled in - hanging\n");
                hang();
        }
+
+       board_prep_linux(images);
 }
 
 __weak bool armv7_boot_nonsec_default(void)