From 729477fd86fc7c471fe44f81ed58e94d1656571f Mon Sep 17 00:00:00 2001 From: Maheedhar Bollapalli Date: Sun, 15 Sep 2024 22:09:00 -1200 Subject: [PATCH] fix(xilinx): warn if reserved memory pre-exists in DT Memory reservation for tf-a does not happen in runtime if memory reservation node pre-exists in DT. Presence of reserved area is checked and user is warned if it pre-exists. Change-Id: I50e18be942777747e9074bb9d8e0305a29c28178 Signed-off-by: Maheedhar Bollapalli --- plat/xilinx/common/plat_fdt.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/plat/xilinx/common/plat_fdt.c b/plat/xilinx/common/plat_fdt.c index ebcc31b11..4ad7b2d01 100644 --- a/plat/xilinx/common/plat_fdt.c +++ b/plat/xilinx/common/plat_fdt.c @@ -86,6 +86,18 @@ static int remove_mmap_dynamic_region(uintptr_t base_va, size_t size) } #endif +#if defined(XILINX_OF_BOARD_DTB_ADDR) +static int check_fdt_reserved_memory(void *dtb, const char *node_name) +{ + int offset = fdt_path_offset(dtb, "/reserved-memory"); + + if (offset >= 0) { + offset = fdt_subnode_offset(dtb, offset, node_name); + } + return offset; +} +#endif + void prepare_dtb(void) { #if defined(XILINX_OF_BOARD_DTB_ADDR) @@ -112,12 +124,19 @@ void prepare_dtb(void) WARN("Failed to add PSCI cpu enable methods in DT\n"); } - /* Reserve memory used by Trusted Firmware. */ - ret = fdt_add_reserved_memory(dtb, "tf-a", - BL31_BASE, - BL31_LIMIT - BL31_BASE); + /* Check reserved memory set in DT*/ + ret = check_fdt_reserved_memory(dtb, "tf-a"); if (ret < 0) { - WARN("Failed to add reserved memory nodes for BL31 to DT.\n"); + /* Reserve memory used by Trusted Firmware. */ + ret = fdt_add_reserved_memory(dtb, "tf-a", + BL31_BASE, + BL31_LIMIT - BL31_BASE); + if (ret < 0) { + WARN("Failed to add reserved memory nodes for BL31 to DT.\n"); + } + + } else { + WARN("Reserved memory pre-exists in DT.\n"); } ret = fdt_pack(dtb);