[PATCH next v2] ti: k3: abstract common fdt api for reserved mem fixups

Anshul Dalal anshuld at ti.com
Thu Dec 4 12:11:55 CET 2025


The usage of fdt_fixup_reserved is repeated for ATF and OP-TEE for
multiple platforms, this patch creates a single fdt API for fixing up
the reserved-memory node with added error handling.

All k3 platforms already share a common tispl template which ensures
binaries are loaded as per the respective CONFIG_*_LOAD_ADDR. And the
provided new_size for the fixup is overridden by the size from fdt node
anyways. This allows for safe abstraction of the reserved memory fixups
for all current platforms.

fdt_fixup_reserved now abstracts the ATF and OP-TEE fixups by calling
the renamed static fdt_fixup_reserved_memory function with the required
parameters.

Signed-off-by: Anshul Dalal <anshuld at ti.com>
---
Unlike the other fdt_fixup_* APIs such as fdt_fixup_cores_nodes_am625
which can silently fail and still proceed to a successful kernel boot,
the APIs to fix reserved-memory node have to succeed to ensure the kernel
doesn't overwrite the TFA and TEE's memory. Which is why we return an
int instead of void here.
---
Changes in v2:
- Rebase to next
- Minor fix as per reviewer comments
- Link to v1: https://lore.kernel.org/u-boot/20250522150941.563959-1-anshuld@ti.com/
---
 arch/arm/mach-k3/am62ax/am62a7_fdt.c          |  5 +----
 arch/arm/mach-k3/am62px/am62p5_fdt.c          |  4 +---
 arch/arm/mach-k3/am62x/am625_fdt.c            |  4 +---
 arch/arm/mach-k3/common.c                     | 18 ++++++------------
 arch/arm/mach-k3/common_fdt.c                 | 18 ++++++++++++++++--
 arch/arm/mach-k3/include/mach/k3-common-fdt.h |  3 +--
 arch/arm/mach-k3/j722s/j722s_fdt.c            |  5 +----
 7 files changed, 27 insertions(+), 30 deletions(-)

diff --git a/arch/arm/mach-k3/am62ax/am62a7_fdt.c b/arch/arm/mach-k3/am62ax/am62a7_fdt.c
index c7c5d2f0885..bdc1747fd75 100644
--- a/arch/arm/mach-k3/am62ax/am62a7_fdt.c
+++ b/arch/arm/mach-k3/am62ax/am62a7_fdt.c
@@ -9,8 +9,5 @@
 
 int ft_system_setup(void *blob, struct bd_info *bd)
 {
-	fdt_fixup_reserved(blob, "tfa", CONFIG_K3_ATF_LOAD_ADDR, 0x80000);
-	fdt_fixup_reserved(blob, "optee", CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000);
-
-	return 0;
+	return fdt_fixup_reserved(blob);
 }
diff --git a/arch/arm/mach-k3/am62px/am62p5_fdt.c b/arch/arm/mach-k3/am62px/am62p5_fdt.c
index 03f56cfd9fc..68172ae9a5d 100644
--- a/arch/arm/mach-k3/am62px/am62p5_fdt.c
+++ b/arch/arm/mach-k3/am62px/am62p5_fdt.c
@@ -81,8 +81,6 @@ int ft_system_setup(void *blob, struct bd_info *bd)
 	fdt_fixup_canfd_nodes_am62p(blob, k3_has_canfd());
 	fdt_fixup_thermal_critical_trips_k3(blob, k3_get_max_temp());
 	fdt_fixup_thermal_cooling_device_cpus_am62p(blob, k3_get_core_nr());
-	fdt_fixup_reserved(blob, "tfa", CONFIG_K3_ATF_LOAD_ADDR, 0x80000);
-	fdt_fixup_reserved(blob, "optee", CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000);
 
-	return 0;
+	return fdt_fixup_reserved(blob);
 }
diff --git a/arch/arm/mach-k3/am62x/am625_fdt.c b/arch/arm/mach-k3/am62x/am625_fdt.c
index e5d95ab7dd1..d666d88b7f4 100644
--- a/arch/arm/mach-k3/am62x/am625_fdt.c
+++ b/arch/arm/mach-k3/am62x/am625_fdt.c
@@ -80,8 +80,6 @@ int ft_system_setup(void *blob, struct bd_info *bd)
 	fdt_fixup_pru_node_am625(blob, k3_has_pru());
 	fdt_fixup_thermal_critical_trips_k3(blob, k3_get_max_temp());
 	fdt_fixup_thermal_cooling_device_cpus_am625(blob, k3_get_core_nr());
-	fdt_fixup_reserved(blob, "tfa", CONFIG_K3_ATF_LOAD_ADDR, 0x80000);
-	fdt_fixup_reserved(blob, "optee", CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000);
 
-	return 0;
+	return fdt_fixup_reserved(blob);
 }
diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
index 8d804f18a1f..0a686efa131 100644
--- a/arch/arm/mach-k3/common.c
+++ b/arch/arm/mach-k3/common.c
@@ -273,14 +273,14 @@ void enable_caches(void)
 	if (ret)
 		debug("%s: Failed to setup dram banks\n", __func__);
 
+	ret = fdt_fixup_reserved(fdt);
+	if (ret)
+		printf("%s: Failed to perform reserved-memory fixups (%s)\n",
+		       __func__, fdt_strerror(ret));
+
 	mmu_setup();
 
 	if (CONFIG_K3_ATF_LOAD_ADDR >= CFG_SYS_SDRAM_BASE) {
-		ret = fdt_fixup_reserved(fdt, "tfa", CONFIG_K3_ATF_LOAD_ADDR,
-					 0x80000);
-		if (ret)
-			printf("%s: Failed to perform tfa fixups (%s)\n",
-			       __func__, fdt_strerror(ret));
 		ret = mmu_unmap_reserved_mem("tfa", true);
 		if (ret)
 			printf("%s: Failed to unmap tfa reserved mem (%d)\n",
@@ -288,11 +288,6 @@ void enable_caches(void)
 	}
 
 	if (CONFIG_K3_OPTEE_LOAD_ADDR >= CFG_SYS_SDRAM_BASE) {
-		ret = fdt_fixup_reserved(fdt, "optee",
-					 CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000);
-		if (ret)
-			printf("%s: Failed to perform optee fixups (%s)\n",
-			       __func__, fdt_strerror(ret));
 		ret = mmu_unmap_reserved_mem("optee", true);
 		if (ret)
 			printf("%s: Failed to unmap optee reserved mem (%d)\n",
@@ -463,8 +458,7 @@ void spl_perform_arch_fixups(struct spl_image_info *spl_image)
 	if (!fdt)
 		return;
 
-	fdt_fixup_reserved(fdt, "tfa", CONFIG_K3_ATF_LOAD_ADDR, 0x80000);
-	fdt_fixup_reserved(fdt, "optee", CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000);
+	fdt_fixup_reserved(fdt);
 }
 
 void spl_board_prepare_for_boot(void)
diff --git a/arch/arm/mach-k3/common_fdt.c b/arch/arm/mach-k3/common_fdt.c
index 1e6786f6c20..cb0fb8274a5 100644
--- a/arch/arm/mach-k3/common_fdt.c
+++ b/arch/arm/mach-k3/common_fdt.c
@@ -114,8 +114,9 @@ int fdt_del_node_path(void *blob, const char *path)
 	return ret;
 }
 
-int fdt_fixup_reserved(void *blob, const char *name,
-		       unsigned int new_address, unsigned int new_size)
+static int fdt_fixup_reserved_memory(void *blob, const char *name,
+				     unsigned int new_address,
+				     unsigned int new_size)
 {
 	int nodeoffset, subnode;
 	int ret;
@@ -167,6 +168,19 @@ add_carveout:
 	return 0;
 }
 
+int fdt_fixup_reserved(void *blob)
+{
+	int ret;
+
+	ret = fdt_fixup_reserved_memory(blob, "tfa", CONFIG_K3_ATF_LOAD_ADDR,
+					0x80000);
+	if (ret)
+		return ret;
+
+	return fdt_fixup_reserved_memory(blob, "optee",
+					 CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000);
+}
+
 static int fdt_fixup_critical_trips(void *blob, int zoneoffset, int maxc)
 {
 	int node, trip;
diff --git a/arch/arm/mach-k3/include/mach/k3-common-fdt.h b/arch/arm/mach-k3/include/mach/k3-common-fdt.h
index 38a5bb82d95..de4d5d117c5 100644
--- a/arch/arm/mach-k3/include/mach/k3-common-fdt.h
+++ b/arch/arm/mach-k3/include/mach/k3-common-fdt.h
@@ -8,8 +8,7 @@
 
 int fdt_fixup_msmc_ram_k3(void *blob);
 int fdt_del_node_path(void *blob, const char *path);
-int fdt_fixup_reserved(void *blob, const char *name,
-		       unsigned int new_address, unsigned int new_size);
+int fdt_fixup_reserved(void *blob);
 void fdt_fixup_thermal_critical_trips_k3(void *blob, int maxc);
 
 #endif /* _K3_COMMON_FDT_H */
diff --git a/arch/arm/mach-k3/j722s/j722s_fdt.c b/arch/arm/mach-k3/j722s/j722s_fdt.c
index c7c5d2f0885..bdc1747fd75 100644
--- a/arch/arm/mach-k3/j722s/j722s_fdt.c
+++ b/arch/arm/mach-k3/j722s/j722s_fdt.c
@@ -9,8 +9,5 @@
 
 int ft_system_setup(void *blob, struct bd_info *bd)
 {
-	fdt_fixup_reserved(blob, "tfa", CONFIG_K3_ATF_LOAD_ADDR, 0x80000);
-	fdt_fixup_reserved(blob, "optee", CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000);
-
-	return 0;
+	return fdt_fixup_reserved(blob);
 }

---
base-commit: d300702c5be5a846032834abe4f01dcd3f50b3a8
change-id: 20251204-fdt_refactor-cf1d166a3ae7

Best regards,
-- 
Anshul Dalal <anshuld at ti.com>



More information about the U-Boot mailing list