]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
arm: mach-k3: am62: Fixup TF-A/OP-TEE reserved-memory node in FDT
authorAndrew Davis <afd@ti.com>
Wed, 14 Feb 2024 16:30:07 +0000 (10:30 -0600)
committerTom Rini <trini@konsulko.com>
Wed, 6 Mar 2024 14:09:00 +0000 (09:09 -0500)
The address we load TF-A and OP-TEE to is configurable by Kconfig
CONFIG_K3_{ATF,OPTEE}_LOAD_ADDR, but the DT nodes reserving this memory
are often statically defined. As these binaries are dynamically loadable,
and in the case of OP-TEE may not even be loaded at all, hard-coding these
addresses is not a hardware description, but rather a configuration.

If the address that U-Boot loaded TF-A or OP-TEE does not match the
address in hard-coded in DT, then fix that node address. This also handles
the case when no reserved memory for these is provided by DT, which is
more correct as explained above.

Add this fixup function, and enable it for AM62.

Signed-off-by: Andrew Davis <afd@ti.com>
Acked-by: Bryan Brattlof <bb@ti.com>
Reviewed-by: Neha Malcom Francis <n-francis@ti.com>
arch/arm/mach-k3/am625_fdt.c
arch/arm/mach-k3/common_fdt.c
arch/arm/mach-k3/common_fdt.h

index 970dd3447dec4b2d2c6d33551ec99e9427d5c574..b26186456f38812defee2b674592d6f676aba527 100644 (file)
@@ -43,6 +43,8 @@ int ft_system_setup(void *blob, struct bd_info *bd)
        fdt_fixup_cores_nodes_am625(blob, k3_get_core_nr());
        fdt_fixup_gpu_nodes_am625(blob, k3_has_gpu());
        fdt_fixup_pru_node_am625(blob, k3_has_pru());
+       fdt_fixup_reserved(blob, "tfa", CONFIG_K3_ATF_LOAD_ADDR, 0x80000);
+       fdt_fixup_reserved(blob, "optee", CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000);
 
        return 0;
 }
index 645c4de42f706dcc394ef6cf5f3eec1475e22b00..3bdedd7b5093ab0fefccc6131701040e16a2c538 100644 (file)
@@ -112,3 +112,55 @@ 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)
+{
+       int nodeoffset, subnode;
+       int ret;
+
+       /* Find reserved-memory */
+       nodeoffset = fdt_subnode_offset(blob, 0, "reserved-memory");
+       if (nodeoffset < 0) {
+               debug("Could not find reserved-memory node\n");
+               return 0;
+       }
+
+       /* Find existing matching subnode and remove it */
+       fdt_for_each_subnode(subnode, blob, nodeoffset) {
+               const char *node_name;
+               fdt_addr_t addr;
+               fdt_size_t size;
+
+               /* Name matching */
+               node_name = fdt_get_name(blob, subnode, NULL);
+               if (!name)
+                       return -EINVAL;
+               if (!strncmp(node_name, name, strlen(name))) {
+                       /* Read out old size first */
+                       addr = fdtdec_get_addr_size(blob, subnode, "reg", &size);
+                       if (addr == FDT_ADDR_T_NONE)
+                               return -EINVAL;
+                       new_size = size;
+
+                       /* Delete node */
+                       ret = fdt_del_node(blob, subnode);
+                       if (ret < 0)
+                               return ret;
+
+                       /* Only one matching node */
+                       break;
+               }
+       }
+
+       struct fdt_memory carveout = {
+               .start = new_address,
+               .end = new_address + new_size - 1,
+       };
+       ret = fdtdec_add_reserved_memory(blob, name, &carveout, NULL, 0, NULL,
+                                        FDTDEC_RESERVED_MEMORY_NO_MAP);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
index 4d23ae638ca69670297ccc63303da3d04bfbb73e..52c0795748389be46d6ba23aaab7065a930ba248 100644 (file)
@@ -8,5 +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);
 
 #endif /* _COMMON_FDT_H */