Skip to contentSkip to conversation

arm: imx: imx8m: imx9: Fix DRAM size calculation due to rom_pointer

PATCH In review Elena Popa 4 participants 4 messages Aug 8, 2023 – Sep 4, 2023

Subsystems (3)
lore
Share & tools
lore

Elena Popa

author
#0 lore raw

PATCH v2 1/1 arm: imx: imx8m: imx9: Fix DRAM size calculation due to rom_pointer

If dram_init_banksize() is called from SPL, the rom_pointer, at that point, is not correctly initialized. This causes wrong calculation of DRAM start and size in dram_init_banksize(). The issue became apparent only in Falcon Mode. Added an extra condition to prevent using rom_pointer in SPL.

---
V2: Added the extra condition also in dram_init() and get_effective_memsize() for consistency.

---
 arch/arm/mach-imx/imx8m/soc.c | 7 ++++---
 arch/arm/mach-imx/imx9/soc.c  | 6 +++---
 2 files changed, 7 insertions(+), 6 deletions(-)
arch/arm/mach-imx/imx8m/soc.c +4 -3
index d5254886be..7bc788acab 100644
@@ -244,7 +244,7 @@ int dram_init(void)
 		return ret;
 
 	/* rom_pointer[1] contains the size of TEE occupies */
-	if (!IS_ENABLED(CONFIG_ARMV8_PSCI) && rom_pointer[1])
+	if (!IS_ENABLED(CONFIG_ARMV8_PSCI) && !IS_ENABLED(CONFIG_SPL_BUILD) && rom_pointer[1])
 		gd->ram_size = sdram_size - rom_pointer[1];
 	else
 		gd->ram_size = sdram_size;
@@ -273,7 +273,7 @@ int dram_init_banksize(void)
 	}
 
 	gd->bd->bi_dram[bank].start = PHYS_SDRAM;
-	if (!IS_ENABLED(CONFIG_ARMV8_PSCI) && rom_pointer[1]) {
+	if (!IS_ENABLED(CONFIG_ARMV8_PSCI) && !IS_ENABLED(CONFIG_SPL_BUILD) && rom_pointer[1]) {
 		phys_addr_t optee_start = (phys_addr_t)rom_pointer[0];
 		phys_size_t optee_size = (size_t)rom_pointer[1];
 
@@ -318,7 +318,8 @@ phys_size_t get_effective_memsize(void)
 			sdram_b1_size = sdram_size;
 		}
 
-		if (!IS_ENABLED(CONFIG_ARMV8_PSCI) && rom_pointer[1]) {
+		if (!IS_ENABLED(CONFIG_ARMV8_PSCI) && !IS_ENABLED(CONFIG_SPL_BUILD) &&
+		    rom_pointer[1]) {
 			/* We will relocate u-boot to Top of dram1. Tee position has two cases:
 			 * 1. At the top of dram1,  Then return the size removed optee size.
 			 * 2. In the middle of dram1, return the size of dram1.
arch/arm/mach-imx/imx9/soc.c +3 -3
index f43b73a6c2..55c280188b 100644
@@ -361,7 +361,7 @@ int dram_init(void)
 		return ret;
 
 	/* rom_pointer[1] contains the size of TEE occupies */
-	if (rom_pointer[1])
+	if (!IS_ENABLED(CONFIG_SPL_BUILD) && rom_pointer[1])
 		gd->ram_size = sdram_size - rom_pointer[1];
 	else
 		gd->ram_size = sdram_size;
@@ -390,7 +390,7 @@ int dram_init_banksize(void)
 	}
 
 	gd->bd->bi_dram[bank].start = PHYS_SDRAM;
-	if (rom_pointer[1]) {
+	if (!IS_ENABLED(CONFIG_SPL_BUILD) && rom_pointer[1]) {
 		phys_addr_t optee_start = (phys_addr_t)rom_pointer[0];
 		phys_size_t optee_size = (size_t)rom_pointer[1];
 
@@ -435,7 +435,7 @@ phys_size_t get_effective_memsize(void)
 		else
 			sdram_b1_size = sdram_size;
 
-		if (rom_pointer[1]) {
+		if (!IS_ENABLED(CONFIG_SPL_BUILD) && rom_pointer[1]) {
 			/* We will relocate u-boot to top of dram1. TEE position has two cases:
 			 * 1. At the top of dram1,  Then return the size removed optee size.
 			 * 2. In the middle of dram1, return the size of dram1.
Signature · 1 line
2.25.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Elena Popa

If dram_init_banksize() is called from SPL, the rom_pointer, at that point, is not correctly initialized. This causes wrong calculation of DRAM start and size in dram_init_banksize(). The issue became apparent only in Falcon Mode. Added an extra condition to prevent using rom_pointer in SPL.

Thanks

Reviewed-by on v2 1/1
#2 lore raw
In reply to Elena Popa

Hi Elena,

Quoted 10 lines · Elena Popa

If dram_init_banksize() is called from SPL, the rom_pointer, at that point, is not correctly initialized. This causes wrong calculation of DRAM start and size in dram_init_banksize(). The issue became apparent only in Falcon Mode. Added an extra condition to prevent using rom_pointer in SPL.

---
V2: Added the extra condition also in dram_init() and get_effective_memsize() for consistency.

Thanks for the fix.

#3 lore raw

PATCH v2 1/1 arm: imx: imx8m: imx9: Fix DRAM size calculation due to rom_pointer

In reply to Elena Popa
Quoted 8 lines

If dram_init_banksize() is called from SPL, the rom_pointer, at that point, is not correctly initialized. This causes wrong calculation of DRAM start and size in dram_init_banksize(). The issue became apparent only in Falcon Mode. Added an extra condition to prevent using rom_pointer in SPL.

Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,        Managing Director: Erika Unter  
HRB 165235 Munich,   Office: Kirchenstr.5, 82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: [email protected]
=====================================================================