From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Wed, 28 May 2025 16:20:38 +0200 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by lore.white.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uKHe2-001DSD-0P for lore@lore.pengutronix.de; Wed, 28 May 2025 16:20:38 +0200 Received: from bombadil.infradead.org ([2607:7c80:54:3::133]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1uKHe0-0007mo-TD for lore@pengutronix.de; Wed, 28 May 2025 16:20:37 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+dzarbSftHAGnDukl61sPBNKqg248g1jHJeHEhWx88I=; b=dRfwtocoTUBxERUttuhM3iZUsg Bd/HApBJQaYgs2cv/hIKlmSrmPkmemiY96gctGv1540olfkrSapSuRQ8HN6EMrzsOh3pFaX37lSpV U9WOi+Xww2QJPve7QPNLkz2txbhDaHX4V5BRskqR3ZnpPpPdHHDWn6Ad7gerUL3XF11wNfJzkGT7t veWZwlF2WHtwP9x0ZSPGUPFnyl/TzhX7j5sOAsPFZJixU7bOyz9XoqzcHV5pW7l1a2Sc9zxX1u5ax jK56Y7yQ9xIwxAqcYVXahuHayHMDB0sTz8fpPymj8exwzcyH2u3qvw3+4NUz+mzuBokwFWkzJL5e6 HT4ltuNA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uKHdV-0000000DNIY-35nV; Wed, 28 May 2025 14:20:05 +0000 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uKHVL-0000000DKyF-2WcF for barebox@lists.infradead.org; Wed, 28 May 2025 14:11:43 +0000 Received: from dude05.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::54]) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1uKHVI-00011O-Vo; Wed, 28 May 2025 16:11:36 +0200 From: Michael Tretter Date: Wed, 28 May 2025 16:11:26 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20250528-rk3588-optee-v2-8-63070238dd13@pengutronix.de> References: <20250528-rk3588-optee-v2-0-63070238dd13@pengutronix.de> In-Reply-To: <20250528-rk3588-optee-v2-0-63070238dd13@pengutronix.de> To: BAREBOX , Sascha Hauer , Marco Felsch Cc: Michael Tretter X-Mailer: b4 0.14.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250528_071139_745201_F2186238 X-CRM114-Status: GOOD ( 27.88 ) X-BeenThere: barebox@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "barebox" X-SA-Exim-Connect-IP: 2607:7c80:54:3::133 X-SA-Exim-Mail-From: barebox-bounces+lore=pengutronix.de@lists.infradead.org X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on metis.whiteo.stw.pengutronix.de X-Spam-Level: X-Spam-Status: No, score=-6.3 required=4.0 tests=AWL,BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.2 Subject: [PATCH v2 8/9] ARM: rockchip: pass device tree to TF-A X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on metis.whiteo.stw.pengutronix.de) The upstream OP-TEE expects a device tree to be able to initialize the dynamic shared memory. Therefore, barebox should pass a device tree that contains memory nodes through the TF-A to OP-TEE. OP-TEE may modify the passed fdt. Thus, barebox copies the fdt from the fixed size rodata area to the rk_scratch area and allocates a configurable memory area for the fdt to allow fdt modification. OP-TEE has the CFG_DTB_MAX_SIZE config option for the maximum size of the fdt. barebox must reserve at least that much memory for the fdt to avoid out of bounds accesses from OP-TEE. Unfortunately, the downstream TF-A fails to start if barebox passes its device tree and it is not possible to detect if the loaded TF-A is able to handle the device tree. Add a config option to pass the device tree if it is possible. Signed-off-by: Michael Tretter --- Changes in v2: - pass copy of fdt in scratch space to TF-A - add config option for fdt size - add documentation for CONFIG_ARCH_ROCKCHIP_ATF_PASS_FDT --- Documentation/boards/rockchip.rst | 4 ++++ arch/arm/mach-rockchip/Kconfig | 23 +++++++++++++++++++++++ arch/arm/mach-rockchip/atf.c | 24 ++++++++++++------------ include/mach/rockchip/bootrom.h | 3 +++ 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/Documentation/boards/rockchip.rst b/Documentation/boards/rockchip.rst index b2b04abb03cd1926bb59799af5f6a8c11d410cc2..8bce92865e3eda193412180c7295b5a35b3531e8 100644 --- a/Documentation/boards/rockchip.rst +++ b/Documentation/boards/rockchip.rst @@ -94,6 +94,10 @@ With these barebox can be compiled as: .. note:: The RK3566 and RK3568 seem to share the bl31 and bl32 firmware files, whereas the memory initialization blob is different. +.. note:: The bl31 from the rkbin repository seems to be unable to handle + device trees of a larger size (for example, if CONFIG_OF_OVERLAY_LIVE is + enabled). Disable CONFIG_ARCH_ROCKCHIP_ATF_PASS_FDT in this case. + Creating a bootable SD card --------------------------- diff --git a/arch/arm/mach-rockchip/Kconfig b/arch/arm/mach-rockchip/Kconfig index 98dfd11c182b9fee6e3c958653ad4fa8a7d98d84..1b72dc4b8a16ce9dca742ff1173fc2208a0e619d 100644 --- a/arch/arm/mach-rockchip/Kconfig +++ b/arch/arm/mach-rockchip/Kconfig @@ -141,6 +141,29 @@ config ARCH_ROCKCHIP_ATF useful for debugging early startup, but for all other cases, say y here. +config ARCH_ROCKCHIP_ATF_PASS_FDT + bool "Pass device tree to TF-A" + depends on ARCH_ROCKCHIP_ATF + help + Enable this option if you are using an upstream OP-TEE that uses the + device tree to initialize dynamic shared memory, which is passed + through the upstream TF-A. + + Disable the option if you are using a downstream TF-A since it + doesn't always cope with device trees. Supposedly this happens if the + device tree is too large, for example if CONFIG_OF_OVERLAY_LIVE is + enabled. + +config ARCH_ROCKCHIP_ATF_FDT_SIZE + hex + default 0x0 + default 0x60000 if ARCH_ROCKCHIP_ATF_PASS_FDT + prompt "Reserved size for the FDT blob passed to the TF-A" + help + Set this size to CFG_DTB_MAX_SIZE in the OP-TEE configuration. OP-TEE + may modify the passed device tree and increase it's size. This + ensures that barebox reserves enough memory for the modifications. + config ARCH_ROCKCHIP_OPTEE bool "Build rockchip OP-TEE binary into barebox" depends on ARCH_ROCKCHIP_ATF diff --git a/arch/arm/mach-rockchip/atf.c b/arch/arm/mach-rockchip/atf.c index cfa6df043b34c0f36919048237c7ecf33dfe0724..f4a71ef2dc8dffc6ceb4f97ee542f5b83858120b 100644 --- a/arch/arm/mach-rockchip/atf.c +++ b/arch/arm/mach-rockchip/atf.c @@ -183,21 +183,21 @@ void __noreturn rk3588_barebox_entry(void *fdt) rk_scratch = (void *)arm_mem_scratch(endmem); if (current_el() == 3) { + void *fdt_scratch = NULL; + rk3588_lowlevel_init(); rockchip_store_bootrom_iram(IOMEM(RK3588_IRAM_BASE)); - /* - * The downstream TF-A doesn't cope with our device tree when - * CONFIG_OF_OVERLAY_LIVE is enabled, supposedly because it is - * too big for some reason. Otherwise it doesn't have any visible - * effect if we pass a device tree or not, except that the TF-A - * fills in the ethernet MAC address into the device tree. - * The upstream TF-A doesn't use the device tree at all. - * - * Pass NULL for now until we have a good reason to pass a real - * device tree. - */ - rk3588_atf_load_bl31(NULL); +#ifdef 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 (fdt_open_into(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"); +#endif + + rk3588_atf_load_bl31(fdt_scratch); /* not reached when CONFIG_ARCH_ROCKCHIP_ATF */ } diff --git a/include/mach/rockchip/bootrom.h b/include/mach/rockchip/bootrom.h index 6776ac5ef9813de903f936e340afd72ecd417c82..586008a78505943c968301a9ce90ed5e4aa9b18b 100644 --- a/include/mach/rockchip/bootrom.h +++ b/include/mach/rockchip/bootrom.h @@ -13,7 +13,10 @@ struct rockchip_scratch_space { u32 irom[16]; struct optee_header optee_hdr; + /* FDT needs an 8 byte alignment */ + u8 fdt[CONFIG_ARCH_ROCKCHIP_ATF_FDT_SIZE] __aligned(8); }; +static_assert(sizeof(struct rockchip_scratch_space) <= CONFIG_SCRATCH_SIZE); extern struct rockchip_scratch_space *rk_scratch; -- 2.39.5