mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Subject: [PATCH 3/6] ARM: rockchip: atf: add OP-TEE fdt creation function for all SoCs
Date: Fri, 20 Mar 2026 09:31:19 +0100	[thread overview]
Message-ID: <20260320-compressed-firmware-rockchip-v1-3-7d03c7e39d2f@pengutronix.de> (raw)
In-Reply-To: <20260320-compressed-firmware-rockchip-v1-0-7d03c7e39d2f@pengutronix.de>

We have rk3588_open_fdt() to create an empty flattened device tree and
rk3588_fixup_mem() to populate it with the memory banks, but there is
nothing rk3588 specific in it, so refactor the code to
rockchip_create_optee_fdt() which could be used by all rockchip SoCs.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-rockchip/atf.c | 68 ++++++++++++++++++--------------------------
 1 file changed, 27 insertions(+), 41 deletions(-)

diff --git a/arch/arm/mach-rockchip/atf.c b/arch/arm/mach-rockchip/atf.c
index 4d90aeff49..37802bfade 100644
--- a/arch/arm/mach-rockchip/atf.c
+++ b/arch/arm/mach-rockchip/atf.c
@@ -145,6 +145,28 @@ static struct fwobj bl32; /* OP-TEE in barebox image */
 	} while (0)
 
 
+static int rockchip_create_optee_fdt(void *buf, int bufsize)
+{
+	unsigned long base[ROCKCHIP_MAX_DRAM_RESOURCES];
+	unsigned long size[ARRAY_SIZE(base)];
+	int i, root;
+
+	if (fdt_create_empty_tree(buf, bufsize) != 0)
+		return -EINVAL;
+
+	root = fdt_path_offset(buf, "/");
+
+	fdt_setprop_u32(buf, root, "#address-cells", 2);
+	fdt_setprop_u32(buf, root, "#size-cells", 2);
+
+	for (i = 0; i < n_mem_resources; i++) {
+		base[i] = membase[i];
+		size[i] = memsize[i];
+	}
+
+	return fdt_fixup_mem(buf, base, size, n_mem_resources);
+}
+
 static void rockchip_atf_load_bl31(void *fdt)
 {
 	unsigned long bl31_ep;
@@ -247,41 +269,10 @@ void rk3588_atf_load_bl31(void *fdt)
 	rockchip_atf_load_bl31(fdt);
 }
 
-static int rk3588_fixup_mem(void *fdt)
-{
-	/* Use 4 blocks since rk3588 has 3 gaps in the address space */
-	unsigned long base[4];
-	unsigned long size[ARRAY_SIZE(base)];
-	phys_addr_t base_tmp[ARRAY_SIZE(base)];
-	resource_size_t size_tmp[ARRAY_SIZE(base_tmp)];
-	int i, n;
-
-	n = rk3588_ram_sizes(base_tmp, size_tmp, ARRAY_SIZE(base_tmp));
-	for (i = 0; i < n; i++) {
-		base[i] = base_tmp[i];
-		size[i] = size_tmp[i];
-	}
-
-	return fdt_fixup_mem(fdt, base, size, i);
-}
-
-static int rk3588_open_fdt(const void *fdt, void *buf, int bufsize)
-{
-	int root;
-
-	if (fdt_create_empty_tree(buf, bufsize) != 0)
-		return -1;
-	root = fdt_path_offset(buf, "/");
-
-	fdt_setprop_u32(buf, root, "#address-cells", 2);
-	fdt_setprop_u32(buf, root, "#size-cells", 2);
-
-	return 0;
-}
-
 void __noreturn rk3588_barebox_entry(void *fdt)
 {
 	phys_addr_t memend;
+	int ret;
 
 	n_mem_resources = rk3588_ram_sizes(membase, memsize, ROCKCHIP_MAX_DRAM_RESOURCES);
 
@@ -290,23 +281,18 @@ void __noreturn rk3588_barebox_entry(void *fdt)
 	rk_scratch = (void *)arm_mem_scratch(memend);
 
 	if (current_el() == 3) {
-		void *fdt_scratch = NULL;
-
 		rk3588_lowlevel_init();
 		rockchip_store_bootrom_iram(IOMEM(RK3588_IRAM_BASE));
 
 		if (IS_ENABLED(CONFIG_ARCH_ROCKCHIP_ATF_PASS_FDT)) {
 			pr_debug("Copy fdt to scratch area 0x%p (%zu bytes)\n",
 				 rk_scratch->fdt, sizeof(rk_scratch->fdt));
-			if (rk3588_open_fdt(fdt, rk_scratch->fdt, sizeof(rk_scratch->fdt)) == 0)
-				fdt_scratch = rk_scratch->fdt;
-			else
-				pr_warn("Failed to copy fdt to scratch: Continue without fdt\n");
-			if (fdt_scratch && rk3588_fixup_mem(fdt_scratch) != 0)
-				pr_warn("Failed to fixup memory nodes\n");
+			ret = rockchip_create_optee_fdt(rk_scratch->fdt, sizeof(rk_scratch->fdt));
+			if (ret)
+				pr_warn("Failed to create OP-TEE Device tree\n");
 		}
 
-		rk3588_atf_load_bl31(fdt_scratch);
+		rk3588_atf_load_bl31(rk_scratch->fdt);
 		/* not reached when CONFIG_ARCH_ROCKCHIP_ATF */
 	}
 

-- 
2.47.3




  parent reply	other threads:[~2026-03-20  8:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-20  8:31 [PATCH 0/6] Rockchip: Enable MMU before uncompressing TF-A and OP-TEE Sascha Hauer
2026-03-20  8:31 ` [PATCH 1/6] ARM: rockchip: dmc: rework DRAM functions Sascha Hauer
2026-03-20  8:31 ` [PATCH 2/6] ARM: rockchip: atf: make all memory banks available Sascha Hauer
2026-03-20  8:31 ` Sascha Hauer [this message]
2026-03-20  8:31 ` [PATCH 4/6] ARM: Rockchip: Drop rk3xxx_atf_load_bl31() Sascha Hauer
2026-03-20  8:31 ` [PATCH 5/6] ARM: rockchip: separate physical DRAM start from usable start Sascha Hauer
2026-03-20  8:31 ` [PATCH 6/6] ARM: rockchip: atf: enable MMU in PBL Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260320-compressed-firmware-rockchip-v1-3-7d03c7e39d2f@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox