diff --git a/common/fdt_fixup.c b/common/fdt_fixup.c index 1bad74fe6..59b754359 100644 --- a/common/fdt_fixup.c +++ b/common/fdt_fixup.c @@ -197,6 +197,7 @@ int fdt_add_reserved_memory(void *dtb, const char *node_name, uintptr_t base, size_t size) { int offs = fdt_path_offset(dtb, "/reserved-memory"); + int node; uint32_t addresses[4]; int ac, sc; unsigned int idx = 0; @@ -213,6 +214,24 @@ int fdt_add_reserved_memory(void *dtb, const char *node_name, fdt_setprop(dtb, offs, "ranges", NULL, 0); } + /* Check for existing regions */ + fdt_for_each_subnode(node, dtb, offs) { + uintptr_t c_base; + size_t c_size; + int ret; + + ret = fdt_get_reg_props_by_index(dtb, node, 0, &c_base, &c_size); + /* Ignore illegal subnodes */ + if (ret != 0) { + continue; + } + + /* existing region entirely contains the new region */ + if (base >= c_base && (base + size) <= (c_base + c_size)) { + return 0; + } + } + if (ac > 1) { addresses[idx] = cpu_to_fdt32(HIGH_BITS(base)); idx++; diff --git a/plat/amd/versal2/platform.mk b/plat/amd/versal2/platform.mk index c07fc36a8..1c977a309 100644 --- a/plat/amd/versal2/platform.mk +++ b/plat/amd/versal2/platform.mk @@ -116,6 +116,7 @@ BL31_SOURCES += plat/xilinx/common/plat_fdt.c \ plat/xilinx/common/versal.c \ ${PLAT_PATH}/bl31_setup.c \ common/fdt_fixup.c \ + common/fdt_wrappers.c \ ${LIBFDT_SRCS} \ ${PLAT_PATH}/sip_svc_setup.c \ ${PLAT_PATH}/gicv3.c diff --git a/plat/rpi/rpi4/platform.mk b/plat/rpi/rpi4/platform.mk index cbfa6f2fd..c39a58776 100644 --- a/plat/rpi/rpi4/platform.mk +++ b/plat/rpi/rpi4/platform.mk @@ -31,6 +31,7 @@ BL31_SOURCES += lib/cpus/aarch64/cortex_a72.S \ plat/common/plat_psci_common.c \ plat/rpi/common/rpi3_topology.c \ common/fdt_fixup.c \ + common/fdt_wrappers.c \ ${LIBFDT_SRCS} \ ${GICV2_SOURCES}