[PATCH] ARM: stm32mp: Correct sign extension for memory address in dram_bank_mmu_setup()

Lukasz Majewski lukma at denx.de
Sat May 10 08:52:56 CEST 2025


On a system based on stm32mp157c, with 1GiB SDRAM (starting from
0xC0000000) and CONFIG_PHYS_64BIT enabled (so the phys_addr_t becomes
'unsigned long long') the mainline u-boot hangs.

It is caused by marking for this memory region the TLB entry as invalid
in the dram_bank_mmu_setup().

To be more specific the condition of 'addr >= gd->ram_top' is met
in this case.

The reason for it is that the 'addr' variable in that function has sign
extension from 'int' typed i automatic variable:
addr = i << MMU_SECTION_SHIFT;

For example i = 0xc01 causes addr = 0xffffffffc0000000 as int typed i
variable (with MSB bit set) is sign extended to unsigned long long addr.

The proposed fix is to change i type from 'int' to 'unsigned int', so the
sign extension will not take place and addr = 0xc0000000, which is smaller
than gd->ram_top = 0x100000000.

This change shall be safe as i shall not be negative as it represents the
SDRAM areas (in granularity of 1MiB areas).

Fixes: 25fb58e88aba ("ARM: stm32mp: Fix dram_bank_mmu_setup() for LMB located above ram_top")

Signed-off-by: Lukasz Majewski <lukma at denx.de>
---
 arch/arm/mach-stm32mp/stm32mp1/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-stm32mp/stm32mp1/cpu.c b/arch/arm/mach-stm32mp/stm32mp1/cpu.c
index d5eaf6711b6..0ed5eda47d0 100644
--- a/arch/arm/mach-stm32mp/stm32mp1/cpu.c
+++ b/arch/arm/mach-stm32mp/stm32mp1/cpu.c
@@ -51,7 +51,7 @@ u32 get_bootauth(void)
 void dram_bank_mmu_setup(int bank)
 {
 	struct bd_info *bd = gd->bd;
-	int	i;
+	unsigned int i;
 	phys_addr_t start;
 	phys_addr_t addr;
 	phys_size_t size;
-- 
2.39.5



More information about the U-Boot mailing list