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:32:34 -0600
commit58f55994a406694460767566395e7c160738d431 (patch)
tree4c1cdf29b4a78557e9d29579b525a5ace60d2278
parent435807b41ae99bb9f4e0b2c7b9e5287c2bd520c0 (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>
-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 d94c5d9a29..ab1aceac2a 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);