The device tree loaded for the OS may contain a static memory description that does not match the layout determined by the firmware. RISC-V currently relies on board-specific fixups to pass that layout to the OS.
Update the OS memory nodes from gd->dram[] in arch_fixup_fdt(), as ARM already does. Platforms that need to keep the memory description in the OS device tree unchanged can disable CONFIG_ARCH_FIXUP_FDT_MEMORY. Disable this option for the generic Microchip MPFS configuration. The supported Icicle Kit device tree uses multiple memory nodes, whereas fdt_fixup_memory_banks() writes all banks into the first node and leaves the others untouched. This would duplicate memory ranges, so preserve the existing memory description for this configuration. Signed-off-by: Junhui Liu <[email protected]> --- arch/riscv/lib/fdt_fixup.c | 16 ++++++++++++++++ configs/microchip_mpfs_generic_defconfig | 1 + 2 files changed, 17 insertions(+) diff --git a/arch/riscv/lib/fdt_fixup.c b/arch/riscv/lib/fdt_fixup.c index 6dfd1a2d5b8f..0786a03e58cd 100644 --- a/arch/riscv/lib/fdt_fixup.c +++ b/arch/riscv/lib/fdt_fixup.c @@ -160,6 +160,22 @@ int arch_fixup_fdt(void *blob) return log_msg_ret("could not set boot-hartid", err); #endif + if (IS_ENABLED(CONFIG_ARCH_FIXUP_FDT_MEMORY)) { + u64 start[CONFIG_NR_DRAM_BANKS]; + u64 size[CONFIG_NR_DRAM_BANKS]; + int i; + + for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { + start[i] = gd->dram[i].start; + size[i] = gd->dram[i].size; + } + + err = fdt_fixup_memory_banks(blob, start, size, + CONFIG_NR_DRAM_BANKS); + if (err) + return err; + } + /* Copy the reserved-memory node to the DT used by OS */ err = riscv_fdt_copy_resv_mem_node(gd->fdt_blob, blob); if (err < 0) diff --git a/configs/microchip_mpfs_generic_defconfig b/configs/microchip_mpfs_generic_defconfig index e3d794f08b9d..bd62f630828e 100644 --- a/configs/microchip_mpfs_generic_defconfig +++ b/configs/microchip_mpfs_generic_defconfig @@ -15,6 +15,7 @@ CONFIG_RISCV_SMODE=y CONFIG_FIT=y CONFIG_DISTRO_DEFAULTS=y CONFIG_OF_BOARD_SETUP=y +# CONFIG_ARCH_FIXUP_FDT_MEMORY is not set CONFIG_DEFAULT_FDT_FILE="microchip/mpfs-icicle-kit.dtb" CONFIG_SYS_CBSIZE=256 CONFIG_SYS_PBSIZE=282 -- 2.55.0
