summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYe Li <ye.li@nxp.com>2017-11-10 01:49:56 -0600
committerYe Li <ye.li@nxp.com>2017-11-10 02:38:53 -0600
commit106258e89a1f6c10534c13becdfbd52c6acfc955 (patch)
treebe4306b095346773a2e4ceb2c85c1db9b9e95f4a
parentd09f5db72fa4335bd85a2bff0b889a6b24f8a295 (diff)
MLK-16797 imx8qm/qxp: Fix memory bank size calculation issue
The calculation of memory bank size is wrong when the memory on the board is less than 2GB. It causes memory bank exceeding the real DDR end, and cause crash in kernel. Fix the issue in this patch. Signed-off-by: Ye Li <ye.li@nxp.com> Reviewed-by: Peng Fan <peng.fan@nxp.com> (cherry picked from commit 58f55994a406694460767566395e7c160738d431)
-rw-r--r--arch/arm/cpu/armv8/imx8/cpu.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/arch/arm/cpu/armv8/imx8/cpu.c b/arch/arm/cpu/armv8/imx8/cpu.c
index 9f290258b8..06cd49aa34 100644
--- a/arch/arm/cpu/armv8/imx8/cpu.c
+++ b/arch/arm/cpu/armv8/imx8/cpu.c
@@ -1105,7 +1105,7 @@ phys_size_t get_effective_memsize(void)
if (start >= PHYS_SDRAM_1 && start <= ((sc_faddr_t)PHYS_SDRAM_1 + PHYS_SDRAM_1_SIZE)
&& (start <= CONFIG_SYS_TEXT_BASE && CONFIG_SYS_TEXT_BASE <= end)){
if ((end + 1) <= ((sc_faddr_t)PHYS_SDRAM_1 + PHYS_SDRAM_1_SIZE))
- return (end - start + 1);
+ return (end - PHYS_SDRAM_1 + 1);
else
return PHYS_SDRAM_1_SIZE;
}
@@ -1133,14 +1133,14 @@ int dram_init(void)
if ((end + 1) <= ((sc_faddr_t)PHYS_SDRAM_1 + PHYS_SDRAM_1_SIZE))
gd->ram_size += end - start + 1;
else
- gd->ram_size += PHYS_SDRAM_1_SIZE;
+ gd->ram_size += ((sc_faddr_t)PHYS_SDRAM_1 + PHYS_SDRAM_1_SIZE) - start;
} else if (start >= PHYS_SDRAM_2 && start <= ((sc_faddr_t)PHYS_SDRAM_2 + PHYS_SDRAM_2_SIZE)) {
if ((end + 1) <= ((sc_faddr_t)PHYS_SDRAM_2 + PHYS_SDRAM_2_SIZE))
gd->ram_size += end - start + 1;
else
- gd->ram_size += PHYS_SDRAM_2_SIZE;
+ gd->ram_size += ((sc_faddr_t)PHYS_SDRAM_2 + PHYS_SDRAM_2_SIZE) - start;
}
}
}
@@ -1193,7 +1193,7 @@ void dram_init_banksize(void)
if ((end + 1) <= ((sc_faddr_t)PHYS_SDRAM_1 + PHYS_SDRAM_1_SIZE))
gd->bd->bi_dram[i].size = end - start + 1;
else
- gd->bd->bi_dram[i].size = PHYS_SDRAM_1_SIZE;
+ gd->bd->bi_dram[i].size = ((sc_faddr_t)PHYS_SDRAM_1 + PHYS_SDRAM_1_SIZE) - start;
dram_bank_sort(i);
i++;
@@ -1203,7 +1203,7 @@ void dram_init_banksize(void)
if ((end + 1) <= ((sc_faddr_t)PHYS_SDRAM_2 + PHYS_SDRAM_2_SIZE))
gd->bd->bi_dram[i].size = end - start + 1;
else
- gd->bd->bi_dram[i].size = PHYS_SDRAM_2_SIZE;
+ gd->bd->bi_dram[i].size = ((sc_faddr_t)PHYS_SDRAM_2 + PHYS_SDRAM_2_SIZE) - start;
dram_bank_sort(i);
i++;
@@ -1234,12 +1234,12 @@ static u64 get_block_size(sc_faddr_t addr_start, sc_faddr_t addr_end)
{
if (addr_start >= PHYS_SDRAM_1 && addr_start <= ((sc_faddr_t)PHYS_SDRAM_1 + PHYS_SDRAM_1_SIZE)) {
if ((addr_end + 1) > ((sc_faddr_t)PHYS_SDRAM_1 + PHYS_SDRAM_1_SIZE))
- return PHYS_SDRAM_1_SIZE;
+ return ((sc_faddr_t)PHYS_SDRAM_1 + PHYS_SDRAM_1_SIZE) - addr_start;
} else if (addr_start >= PHYS_SDRAM_2 && addr_start <= ((sc_faddr_t)PHYS_SDRAM_2 + PHYS_SDRAM_2_SIZE)) {
if ((addr_end + 1) > ((sc_faddr_t)PHYS_SDRAM_2 + PHYS_SDRAM_2_SIZE))
- return PHYS_SDRAM_2_SIZE;
+ return ((sc_faddr_t)PHYS_SDRAM_2 + PHYS_SDRAM_2_SIZE) - addr_start;
}
return (addr_end - addr_start + 1);