summaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorYe Li <ye.li@nxp.com>2018-09-05 02:46:02 -0700
committerYe Li <ye.li@nxp.com>2018-09-05 18:52:46 -0700
commite701efe4f0c8730f964b6ff62673b3860c6a7a7d (patch)
treecddcc79c69548bc2e9f3c5d63d179c317b0e12b9 /arch
parent5d746216871b477dc32b477a0f1d75f7007a543f (diff)
MLK-19457 imx: Fix potential lmb memory overwrite by stack
At default, u-boot reserves the memory from SP-4KB to DRAM end for lmb in arch_lmb_reserve. So lmb won't allocate any memory from it. But we found the 4K gap for SP is not enough now, because some FDT updating operations are added in our u-boot before jumping to kernel, which needs large stack. This causes the lmb allocated memory is overwritten by stack. Fix the issue by implementing the board_lmb_reserve to reserve from SP-16KB to memory end for lmb. Signed-off-by: Ye Li <ye.li@nxp.com> (cherry picked from commit 37835dc6c8dc797f5848cd696ab8a494aa93262d)
Diffstat (limited to 'arch')
-rw-r--r--arch/arm/mach-imx/misc.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/arch/arm/mach-imx/misc.c b/arch/arm/mach-imx/misc.c
index 466b30ac1d..356e5f6fce 100644
--- a/arch/arm/mach-imx/misc.c
+++ b/arch/arm/mach-imx/misc.c
@@ -12,6 +12,8 @@
#include <asm/mach-imx/regs-common.h>
#include <fsl_caam.h>
+DECLARE_GLOBAL_DATA_PTR;
+
/* 1 second delay should be plenty of time for block reset. */
#define RESET_MAX_TIMEOUT 1000000
@@ -82,3 +84,32 @@ void imx_sec_init(void)
#endif
}
+static ulong get_sp(void)
+{
+ ulong ret;
+
+ asm("mov %0, sp" : "=r"(ret) : );
+ return ret;
+}
+
+void board_lmb_reserve(struct lmb *lmb)
+{
+ ulong sp, bank_end;
+ int bank;
+
+ sp = get_sp();
+ debug("## Current stack ends at 0x%08lx ", sp);
+
+ /* adjust sp by 16K to be safe */
+ sp -= 4096 << 2;
+ for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
+ if (sp < gd->bd->bi_dram[bank].start)
+ continue;
+ bank_end = gd->bd->bi_dram[bank].start +
+ gd->bd->bi_dram[bank].size;
+ if (sp >= bank_end)
+ continue;
+ lmb_reserve(lmb, sp, bank_end - sp);
+ break;
+ }
+}