diff mbox series

[v2,1/3] arm: caches: protect dram_bank_mmu_setup access to bi_dram

Message ID 20200424201957.v2.1.I64599059b66bacb531db38c67273754a145dbad8@changeid
State Accepted
Commit c8ec1e3ff505a6ce44ec36e77d0579f5d01ed6b8
Delegated to: Tom Rini
Headers show
Series arm: caches: allow to activate dcache in SPL and in U-Boot pre-reloc | expand

Commit Message

Patrick DELAUNAY April 24, 2020, 6:20 p.m. UTC
Add protection in dram_bank_mmu_setup() to avoid access to bd->bi_dram
before relocation.

This patch allow to use the generic weak function dram_bank_mmu_setup
to activate the MMU and the data cache in SPL or in U-Boot before
relocation, when bd->bi_dram is not yet initialized.

In this cases, the MMU must be initialized explicitly with
mmu_set_region_dcache_behaviour function.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
---

Changes in v2: None

 arch/arm/lib/cache-cp15.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Tom Rini May 1, 2020, 9:56 p.m. UTC | #1
On Fri, Apr 24, 2020 at 08:20:15PM +0200, Patrick Delaunay wrote:

> Add protection in dram_bank_mmu_setup() to avoid access to bd->bi_dram
> before relocation.
> 
> This patch allow to use the generic weak function dram_bank_mmu_setup
> to activate the MMU and the data cache in SPL or in U-Boot before
> relocation, when bd->bi_dram is not yet initialized.
> 
> In this cases, the MMU must be initialized explicitly with
> mmu_set_region_dcache_behaviour function.
> 
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/arch/arm/lib/cache-cp15.c b/arch/arm/lib/cache-cp15.c
index f8d20960da..54509f11c3 100644
--- a/arch/arm/lib/cache-cp15.c
+++ b/arch/arm/lib/cache-cp15.c
@@ -91,6 +91,10 @@  __weak void dram_bank_mmu_setup(int bank)
 	bd_t *bd = gd->bd;
 	int	i;
 
+	/* bd->bi_dram is available only after relocation */
+	if ((gd->flags & GD_FLG_RELOC) == 0)
+		return;
+
 	debug("%s: bank: %d\n", __func__, bank);
 	for (i = bd->bi_dram[bank].start >> MMU_SECTION_SHIFT;
 	     i < (bd->bi_dram[bank].start >> MMU_SECTION_SHIFT) +