rockchip_create_optee_fdt() builds a device tree with just the memory
nodes, but fdt_create_empty_tree() sets its totalsize to the size of the
whole scratch buffer, i.e. CONFIG_ARCH_ROCKCHIP_ATF_FDT_SIZE (384 KiB).

TF-A and OP-TEE both call fdt_open_into() on the device tree, which
copies totalsize bytes regardless of the actual content. TF-A does this
with the MMU disabled and OP-TEE through an uncached mapping. On an
RK3588 this takes 185 ms in TF-A and another 182 ms in OP-TEE.

Pack the device tree so that totalsize matches its content. OP-TEE can
still expand it in place, the scratch buffer keeps its size.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Sascha Hauer <[email protected]>
---
 arch/arm/mach-rockchip/atf.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-rockchip/atf.c b/arch/arm/mach-rockchip/atf.c
index e1ca197430..4b88de8317 100644
--- a/arch/arm/mach-rockchip/atf.c
+++ b/arch/arm/mach-rockchip/atf.c
@@ -172,7 +172,7 @@ 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;
+       int i, root, ret;
 
        if (fdt_create_empty_tree(buf, bufsize) != 0)
                return -EINVAL;
@@ -187,7 +187,12 @@ static int rockchip_create_optee_fdt(void *buf, int 
bufsize)
                size[i] = memsize[i];
        }
 
-       return fdt_fixup_mem(buf, base, size, n_mem_resources);
+       ret = fdt_fixup_mem(buf, base, size, n_mem_resources);
+       if (ret)
+               return ret;
+
+       /* TF-A and OP-TEE copy the whole totalsize, keep it small */
+       return fdt_pack(buf);
 }
 
 static void rockchip_atf_load_bl31(void *fdt)

-- 
2.47.3


Reply via email to