ARM: stm32mp: Correct sign extension for memory address in dram_bank_mmu_setup()
Subsystems (3)
PATCH 1/1 ARM: stm32mp: Correct sign extension for memory address in dram_bank_mmu_setup()
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).
--- arch/arm/mach-stm32mp/stm32mp1/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mach-stm32mp/stm32mp1/cpu.c +1 -1
@@ -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;
Signature · 1 line
2.39.5
Quoted 2 lines · Lukasz Majewski
On a system based on stm32mp157c, with 1GiB SDRAM (starting from
0xC0000000) andCONFIG_PHYS_64BITenabled
STM32MP15xx does not have 64bit PA range , why is CONFIG_PHYS_64BIT enabled ?
Hi Marek,
Quoted 6 lines · Lukasz Majewski
Quoted 2 lines
On a system based on stm32mp157c, with 1GiB SDRAM (starting from
0xC0000000) andCONFIG_PHYS_64BITenabledSTM32MP15xx does not have 64bit PA range , why is
CONFIG_PHYS_64BITenabled ?
I've wrongly looked on defconfigs - Patrice has enabled CONFIG_SYS_64BIT_LBA=y, not PA 64 bit range...
It looks like I've prepared a fix for a problem, which I've created ...
Sorry for the fuzz - please drop this patch :-/
And of course thanks for pointing this out...
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: [email protected]