On rk3588, OP-TEE uses the device tree to detect the available SDRAM
that should be used for dynamic shared memory. Since the amount of SDRAM
is detected during boot, the rk3588 device tree doesn't contain memory
nodes. Therefore, barebox has to detect the memory and add memory nodes
the device tree in the PBL before passing the device tree to the TF-A,
which passes it on to OP-TEE.

Adding nodes to the fdt increases the size of the fdt. As OP-TEE also
modifies and extends the passed device tree, the fdt grows even further
in OP-TEE. Therefore, barebox must add some extra space for fdt
modification. OP-TEE has CFG_DTB_MAX_SIZE as limit, which is the minimum
amount of space that must be reserved by barebox. The
ARCH_ROCKCHIP_ATF_FDT_SIZE option allows to configure this size as
minimum Rockchip machines.

If the device tree fixup function finds memory nodes with the detected
addresses, it ensures that the nodes have the correct size and are
enabled. If a matching memory node is missing from the device tree, it
adds a new node.

The downstream TF-A may crash if barebox passes a device tree to it.
barebox cannot detect, if the loaded TF-A is downstream or upstream.
Therefore, add a config item to enable passing the device tree.

Patches 1 and 2 are some cleanup as preparation for actual changes.

Patches 3 to 5 extend the libfdt integration with helpers to modify and
add memory dt nodes.

Patch 6 introduces CONFIG_SCRATCH_SIZE to configure the size of the
arm_mem_scratch area.

Patches 7 to 9 add the rockchip specific code to read the memory size
from the DRAM controller, add memory dt nodes to the fdt, and pass the
fdt to the TF-A and OP-TEE.

Signed-off-by: Michael Tretter <m.tret...@pengutronix.de>
---
Changes in v2:
- pass a copy of fdt in scratch space instead of original fdt to TF-A
- drop config option to reserve space in dtb
- change fdt_fixup_mem to possibly update existing memory nodes
- Link to v1: 
https://lore.kernel.org/r/20250526-rk3588-optee-v1-0-5004995cb...@pengutronix.de

---
Michael Tretter (9):
      ARM: rockchip: fix formatting
      ARM: rockchip: dmc: use RK3588_INT_REG_START for rk3588
      lib: fdt: add fdt_addresses
      PBL: fdt: refactor helper for reading nr of cells
      PBL: fdt: add fdt_fixup_mem to fixup memory nodes
      ARM: add CONFIG_SCRATCH_SIZE
      ARM: rockchip: dmc: add rk3588_ram_sizes to get full ram size
      ARM: rockchip: pass device tree to TF-A
      ARM: rockchip: fixup memory in device tree for TF-A

 Documentation/boards/rockchip.rst   |  4 ++
 arch/arm/include/asm/barebox-arm.h  |  4 +-
 arch/arm/mach-rockchip/Kconfig      | 23 +++++++++
 arch/arm/mach-rockchip/atf.c        | 69 +++++++++++++++++----------
 arch/arm/mach-rockchip/dmc.c        | 37 +++++++++++++--
 common/Kconfig                      |  5 ++
 include/asm-generic/memory_layout.h |  1 +
 include/mach/rockchip/bootrom.h     |  3 ++
 include/mach/rockchip/dmc.h         |  2 +
 include/pbl.h                       |  1 +
 lib/Makefile                        |  2 +-
 lib/fdt_addresses.c                 |  4 ++
 pbl/fdt.c                           | 93 +++++++++++++++++++++++++++++++++----
 13 files changed, 209 insertions(+), 39 deletions(-)
---
base-commit: fb35d7a2fe800260ca1ce2e189731e48ccefcf7b
change-id: 20250515-rk3588-optee-08cc33320963

Best regards,
-- 
Michael Tretter <m.tret...@pengutronix.de>


Reply via email to