[PATCH v1] qemu-arm: round down memory to multiple of 2MB

Heinrich Schuchardt xypron.glpk at gmx.de
Thu Feb 11 15:18:13 CET 2021


On 11.02.21 13:04, Igor Opaniuk wrote:
> From: Igor Opaniuk <igor.opaniuk at foundries.io>
>
> When LPAE is enabled, 1:1 mapping is created using 2 MB blocks.
> In case amount of memory provided to QEMU is not multiple
> of 2 MB, round down the amount of available memory to avoid hang
> during MMU initialization.
>
> How to reproduce:
> qemu-system-arm -machine virt -m 1058 -nographic -bios u-boot.bin - boots
> qemu-system-arm -machine virt -m 1057 -nographic -bios u-boot.bin - hangs
>
> DRAM:  1 GiB
> initcall: 60011df8
> initcall: 60011904
> New Stack Pointer is: 80fffe90
> initcall: 60011a20
> initcall: 60011bcc
> initcall: 60011bd4
> initcall: 600119b4
> Relocation Offset is: 22042000
> Relocating to 82042000, new gd at 81001ed0, sp at 80fffe90
> initcall: 60011b8c
> initcall: 82053ea0
> initcall: 82053ea8
> initcall: 60012040 (relocated to 82054040)
> dram_bank_mmu_setup: bank: 0
> --- hang here during mmu init ---
>
> Fixes: 3fa914af82("arm: qemu: implement enable_caches()")
> Signed-off-by: Igor Opaniuk <igor.opaniuk at foundries.io>
>
> ---
>
>  board/emulation/qemu-arm/qemu-arm.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
>
> diff --git a/board/emulation/qemu-arm/qemu-arm.c b/board/emulation/qemu-arm/qemu-arm.c
> index aa68bef469..841dd7af0e 100644
> --- a/board/emulation/qemu-arm/qemu-arm.c
> +++ b/board/emulation/qemu-arm/qemu-arm.c
> @@ -84,6 +84,18 @@ int dram_init(void)
>  	if (fdtdec_setup_mem_size_base() != 0)
>  		return -EINVAL;
>
> +	/*
> +	 * When LPAE is enabled (ARMv7),
> +	 * 1:1 mapping is created using 2 MB blocks.
> +	 *
> +	 * In case amount of memory provided to QEMU
> +	 * is not multiple of 2 MB, round down the amount
> +	 * of available memory to avoid hang during MMU
> +	 * initialization.
> +	 */
> +	if (CONFIG_IS_ENABLED(ARMV7_LPAE))
> +		gd->ram_size -= (gd->ram_size % 0x200000);

Is the problem LPAE specific?
Couldn't you provoke same problem using an odd memory size without LPAE,
e.g qemu-system-arm -m 536870908 (512 MiB - 4)?

Best regards

Heinrich

> +
>  	return 0;
>  }
>
>



More information about the U-Boot mailing list