All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ARM: stm32mp: Correct sign extension for memory address in dram_bank_mmu_setup()
@ 2025-05-10  6:52 Lukasz Majewski
  2025-05-11 20:57 ` Marek Vasut
  0 siblings, 1 reply; 3+ messages in thread
From: Lukasz Majewski @ 2025-05-10  6:52 UTC (permalink / raw)
  To: Tom Rini, Patrick Delaunay, Patrice Chotard, Marek Vasut
  Cc: Sughosh Ganu, Simon Glass, uboot-stm32, u-boot, Lukasz Majewski

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@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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ARM: stm32mp: Correct sign extension for memory address in dram_bank_mmu_setup()
  2025-05-10  6:52 [PATCH] ARM: stm32mp: Correct sign extension for memory address in dram_bank_mmu_setup() Lukasz Majewski
@ 2025-05-11 20:57 ` Marek Vasut
  2025-05-12  8:25   ` Lukasz Majewski
  0 siblings, 1 reply; 3+ messages in thread
From: Marek Vasut @ 2025-05-11 20:57 UTC (permalink / raw)
  To: Lukasz Majewski, Tom Rini, Patrick Delaunay, Patrice Chotard
  Cc: Sughosh Ganu, Simon Glass, uboot-stm32, u-boot

On 5/10/25 8:52 AM, Lukasz Majewski wrote:
> On a system based on stm32mp157c, with 1GiB SDRAM (starting from
> 0xC0000000) and CONFIG_PHYS_64BIT enabled

STM32MP15xx does not have 64bit PA range , why is CONFIG_PHYS_64BIT 
enabled ?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ARM: stm32mp: Correct sign extension for memory address in dram_bank_mmu_setup()
  2025-05-11 20:57 ` Marek Vasut
@ 2025-05-12  8:25   ` Lukasz Majewski
  0 siblings, 0 replies; 3+ messages in thread
From: Lukasz Majewski @ 2025-05-12  8:25 UTC (permalink / raw)
  To: Marek Vasut
  Cc: Tom Rini, Patrick Delaunay, Patrice Chotard, Sughosh Ganu,
	Simon Glass, uboot-stm32, u-boot

[-- Attachment #1: Type: text/plain, Size: 807 bytes --]

Hi Marek,

> On 5/10/25 8:52 AM, Lukasz Majewski wrote:
> > On a system based on stm32mp157c, with 1GiB SDRAM (starting from
> > 0xC0000000) and CONFIG_PHYS_64BIT enabled  
> 
> STM32MP15xx does not have 64bit PA range , why is CONFIG_PHYS_64BIT 
> enabled ?

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: lukma@denx.de

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-05-12  8:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-10  6:52 [PATCH] ARM: stm32mp: Correct sign extension for memory address in dram_bank_mmu_setup() Lukasz Majewski
2025-05-11 20:57 ` Marek Vasut
2025-05-12  8:25   ` Lukasz Majewski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.