[PATCH 1/4] arm: mach-k3: Fix phandle corruption in fdt fixup
Paresh Bhagat
p-bhagat at ti.com
Tue Jun 9 20:10:03 CEST 2026
Fix phandle corruption in fdt_fixup_reserved_memory()
The original implementation used a delete/recreate approach:
- Find existing reserved memory node (e.g. tfa at 80000000)
- Delete the entire node with fdt_del_node()
- Create new node with fdtdec_add_reserved_memory()
This worked fine for ATF and OPTEE nodes because no other device tree
nodes reference them via phandles but other nodes example DM are
referenced by R5 nodes.
If these nodes are deleted and recreated, it will not have any phandle
property but the nodes referencing it will still contain the old
phandle, causing initialization to fail.
Update nodes in-place instead of delete/recreate to update only the
"reg" property using fdt_setprop().
Fixes: 8b0fc29de0e3 ("arm: mach-k3: am62: Fixup TF-A/OP-TEE reserved-memory node in FDT")
Signed-off-by: Paresh Bhagat <p-bhagat at ti.com>
---
arch/arm/mach-k3/common_fdt.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/arch/arm/mach-k3/common_fdt.c b/arch/arm/mach-k3/common_fdt.c
index 39cb00c3f43..25e40f6a666 100644
--- a/arch/arm/mach-k3/common_fdt.c
+++ b/arch/arm/mach-k3/common_fdt.c
@@ -129,11 +129,12 @@ static int fdt_fixup_reserved_memory(void *blob, const char *name,
if (nodeoffset < 0)
goto add_carveout;
- /* Find existing matching subnode and remove it */
+ /* Find existing matching subnode and update it in place */
fdt_for_each_subnode(subnode, blob, nodeoffset) {
const char *node_name;
fdt_addr_t addr;
fdt_size_t size;
+ u64 reg[2];
/* Name matching */
node_name = fdt_get_name(blob, subnode, NULL);
@@ -146,15 +147,14 @@ static int fdt_fixup_reserved_memory(void *blob, const char *name,
false);
if (addr == FDT_ADDR_T_NONE)
return -EINVAL;
- new_size = size;
-
- /* Delete node */
- ret = fdt_del_node(blob, subnode);
+ /* Update the reg property in place */
+ reg[0] = cpu_to_fdt64(new_address);
+ reg[1] = cpu_to_fdt64(new_size);
+ ret = fdt_setprop(blob, subnode, "reg", reg, sizeof(reg));
if (ret < 0)
return ret;
- /* Only one matching node */
- break;
+ return 0;
}
}
--
2.34.1
More information about the U-Boot
mailing list