Skip to contentSkip to conversation

mach-k3: common: init gd->bd before dram_init_banksize

PATCH In review Anshul Dalal 3 participants 4 messages Mar 10 – Apr 25 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mach-k3: common: init gd->bd before dram_init_banksize

The dram_init_banksize API configures the dram banks inside gd->bd, so ensure bd is initialized by calling spl_set_bd as part of spl_enable_cache.

---
 arch/arm/mach-k3/common.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm/mach-k3/common.c +3 -0
index 2f3df5519c5..39467c21679 100644
@@ -418,6 +418,9 @@ void spl_enable_cache(void)
 	gd->ram_top = CFG_SYS_SDRAM_BASE;
 	int ret = 0;
 
+	/* dram_init_banksize populates bd, so init it first */
+	spl_set_bd();
+
 	dram_init();
 	dram_init_banksize();
 

---
base-commit: 1e240f7206fccde4ec73ea432ab8360d321c5fe5
change-id: 20260310-init_bd_before_dram_init-7a9c3ad0b311

Best regards,

Signature · 1 line
Anshul Dalal <[email protected]>
#1 lore raw

Hi Anshul

Quoted 14 lines · Anshul Dalal

The dram_init_banksize API configures the dram banks inside gd->bd, so ensure bd is initialized by calling spl_set_bd as part of spl_enable_cache.

---
 arch/arm/mach-k3/common.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm/mach-k3/common.c +0 -0
index 2f3df5519c5..39467c21679 100644

arch/arm/mach-k3/common.c void spl_enable_cache(void) · line 423

Quoted 6 lines
arch/arm/mach-k3/common.c +3 -0
@@ -418,6 +418,9 @@ void spl_enable_cache(void)
 	gd->ram_top = CFG_SYS_SDRAM_BASE;
 	int ret = 0;
 
+	/* dram_init_banksize populates bd, so init it first */
+	spl_set_bd();
+

I think we really need to evaluate where all we are calling dram_init_banksize, else we keep finding related debugs confusing [0]

We have to stick as closely as possible to the common SPL flow: board_init_r --> spl_set_bd .. dram_init_banksize

Problem is we need dram_init_banksize calls even before relocation because of spl_enable_cache. For my knowledge, do we have a specific reason why we are calling spl_enable_cache before relocation? I am guessing some MMU setup happening before we relocate partly to DDR as being the reason?

I think it's better you move calling spl_set_bd() up a level into board_init_f for now (similar to what arch/arm/cpu/armv8/fsl-layerscape/spl.c does). We should be calling this before we call dram_init (or in our case k3_mem_init) so that we are sure it is setup prior to any dram_init_banksize calls.

Quoted 9 lines
arch/arm/mach-k3/common.c +0 -1
 	dram_init();
 	dram_init_banksize();
 
 
---

base-commit: 1e240f7206fccde4ec73ea432ab8360d321c5fe5
change-id: 20260310-init_bd_before_dram_init-7a9c3ad0b311

Best regards,

[0] https://lore.kernel.org/u-boot/[email protected]/

Signature · 2 lines
Thanking You
Neha Malcom Francis
#2 lore raw
Quoted 27 lines · Neha Francis

Hi Anshul

Quoted 14 lines · Anshul Dalal

The dram_init_banksize API configures the dram banks inside gd->bd, so ensure bd is initialized by calling spl_set_bd as part of spl_enable_cache.

---
 arch/arm/mach-k3/common.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm/mach-k3/common.c +0 -0
index 2f3df5519c5..39467c21679 100644

arch/arm/mach-k3/common.c void spl_enable_cache(void) · line 423

Quoted 6 lines
arch/arm/mach-k3/common.c +3 -0
@@ -418,6 +418,9 @@ void spl_enable_cache(void)
 	gd->ram_top = CFG_SYS_SDRAM_BASE;
 	int ret = 0;
 
+	/* dram_init_banksize populates bd, so init it first */
+	spl_set_bd();
+

I think we really need to evaluate where all we are calling dram_init_banksize, else we keep finding related debugs confusing [0]

Quoted 2 lines

We have to stick as closely as possible to the common SPL flow: board_init_r --> spl_set_bd .. dram_init_banksize

spl_set_bd should not re-init bd if it has been initialized already so the second call to spl_set_bd as part of board_init_r shouldn't effect anything.

Quoted 6 lines

Problem is we need dram_init_banksize calls even before relocation because of spl_enable_cache. For my knowledge, do we have a specific reason why we are calling spl_enable_cache before relocation? I am guessing some MMU setup happening before we relocate partly to DDR as being the reason?

SPL does not relocate to my knowledge, we largely need spl_enable_cache to speed up boot especially in A-Core falcon mode where the large kernel image needs to be authenticated and uncompressed by the SPL.

Quoted 2 lines

I think it's better you move calling spl_set_bd() up a level into board_init_f for now (similar to what arch/arm/cpu/armv8/fsl-layerscape/spl.c does). We

We could do that too but it'd have to be change in every SoC's init file and the dependency between spl_set_bd and dram_init_banksize would not be enforced (i.e someone can call spl_enable_cache while not calling spl_set_bd first).

Quoted 15 lines

should be calling this before we call dram_init (or in our case k3_mem_init) so that we are sure it is setup prior to any dram_init_banksize calls.

Quoted 9 lines
arch/arm/mach-k3/common.c +0 -1
 	dram_init();
 	dram_init_banksize();
 
 
---

base-commit: 1e240f7206fccde4ec73ea432ab8360d321c5fe5
change-id: 20260310-init_bd_before_dram_init-7a9c3ad0b311

Best regards,

[0] https://lore.kernel.org/u-boot/[email protected]/

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

Thanks for ropping me in Anshul

Quoted 6 lines · Anshul Dalal
Quoted 4 lines · Anshul Dalal

The dram_init_banksize API configures the dram banks inside gd->bd, so ensure bd is initialized by calling spl_set_bd as part of spl_enable_cache.

Quoted 7 lines
Quoted 1 line

This patch can be dropped in favour of "treewide: move bi_dram[] from bd to gd"[1]. The patch fixes the issue since dram_init_banksize only modifies bi_dram field of bd which now gets moved to gd.

[1]: https://lore.kernel.org/u-boot/[email protected]/

Yes please.

/Ilias

Quoted 28 lines
CC + Ilias
Quoted 24 lines
---
 arch/arm/mach-k3/common.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm/mach-k3/common.c +3 -1
index 2f3df5519c5..39467c21679 100644
@@ -418,6 +418,9 @@ void spl_enable_cache(void)
      gd->ram_top = CFG_SYS_SDRAM_BASE;
      int ret = 0;
 
+     /* dram_init_banksize populates bd, so init it first */
+     spl_set_bd();
+
      dram_init();
      dram_init_banksize();
 
 
---

base-commit: 1e240f7206fccde4ec73ea432ab8360d321c5fe5
change-id: 20260310-init_bd_before_dram_init-7a9c3ad0b311

Best regards,