From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Thu, 26 Jun 2025 16:46:12 +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 1uUnrg-00BIkz-1D for lore@lore.pengutronix.de; Thu, 26 Jun 2025 16:46:12 +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 1uUnrf-0007vl-Ba for lore@pengutronix.de; Thu, 26 Jun 2025 16:46:12 +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:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+M1lmikr9dG6r6I5rOZ0vCMOepTgXsYviBPLykYFxAM=; b=xLnAr2NRq5x4jeOhk4L7MS58cQ 5pZH68i11pc9/lAX0dT1Bqzy99fOHU/mAM0VDTuZxqyQDgl1EvxOFAQiKHP3yyBqD3Pb7iYQ7pMCV IsN/Vvo+zRMtbLiQmXROXOUB9nqlxvVuVBrE20XFoq92kKTZyFsPEeQo7o0cs96avxmUOOy1CnKkG +MOm4wyXuTN5rDV3UVKt1lVGeYvwLZuAbXQjFns4xY65kmpbOJst6pKuzY4l/eODD+h3+qoKFv2PM srSbSaixEMt5b2UpWmuPAmoA2MeiMVtqAk4TFjsNlpjt+V6oCLj1pzovSjJwUegVPFDYyuRlLMvgJ ZrUtordw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uUnrC-0000000ByTS-43P7; Thu, 26 Jun 2025 14:45:42 +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 1uUnr8-0000000ByPs-0CUP for barebox@lists.infradead.org; Thu, 26 Jun 2025 14:45:40 +0000 Received: from dude02.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::28]) by metis.whiteo.stw.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1uUnr5-0006pw-1l for barebox@lists.infradead.org; Thu, 26 Jun 2025 16:45:35 +0200 From: Marco Felsch To: barebox@lists.infradead.org Date: Thu, 26 Jun 2025 16:45:27 +0200 Message-Id: <20250626144527.416697-7-m.felsch@pengutronix.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250626144527.416697-1-m.felsch@pengutronix.de> References: <20250626144527.416697-1-m.felsch@pengutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250626_074538_120263_747E3E0D X-CRM114-Status: GOOD ( 17.07 ) 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=-5.2 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 6/6] ARM: optee-early: add mx6_start_optee_early helper 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) Add a i.MX6 specific helper function which covers most of the steps usually done within the board lowlevel code. All new i.MX6 boards are encouraged to use this helper to load OP-TEE since the helper validates that the TZC380 is enabled and setup the TZC380 region properly. Signed-off-by: Marco Felsch --- Changelog: v2: - new in this series Documentation/user/optee.rst | 19 ++++++++++++------- arch/arm/lib32/optee-early.c | 30 ++++++++++++++++++++++++++++++ include/tee/optee.h | 2 ++ 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/Documentation/user/optee.rst b/Documentation/user/optee.rst index 2729d21d2e44..451f9ad264bb 100644 --- a/Documentation/user/optee.rst +++ b/Documentation/user/optee.rst @@ -19,14 +19,19 @@ During the PBL ^^^^^^^^^^^^^^ To start OP-TEE during the lowlevel initialization of your board in the ``PBL``, -enable the ``CONFIG_PBL_OPTEE`` configuration variable. your board should then +enable the ``CONFIG_PBL_OPTEE`` configuration variable. Your board should then call the function ``start_optee_early(void* tee, void* fdt)`` with a valid tee -and FDT. Ensure that your OP-TEE is compiled with ``CFG_NS_ENTRY_ADDR`` unset, -otherwise OP-TEE will not correctly return to barebox after startup. -Since OP-TEE in the default configuration also modifies the device tree, don't -pass the barebox internal device tree, instead copy it into a different memory -location and pass it to OP-TEE afterwards. -The modified device tree can then be passed to the main barebox start function. +and FDT. If you're running on an i.MX6 platform your board code should call +``int mx6_start_optee_early(void *fdt, void *tee, void *data_location, unsigned +int data_location_size)`` instead since it validates that the TZASC is running +and configured as expected by OP-TEE. + +Ensure that your OP-TEE is compiled with ``CFG_NS_ENTRY_ADDR`` unset, otherwise +OP-TEE will not correctly return to barebox after startup. Since OP-TEE in the +default configuration also modifies the device tree, don't pass the barebox +internal device tree, instead copy it into a different memory location and pass +it to OP-TEE afterwards. The modified device tree can then be passed to the +main barebox start function. Before Linux start ^^^^^^^^^^^^^^^^^^ diff --git a/arch/arm/lib32/optee-early.c b/arch/arm/lib32/optee-early.c index 735d829c99fb..a3e2892a3291 100644 --- a/arch/arm/lib32/optee-early.c +++ b/arch/arm/lib32/optee-early.c @@ -10,6 +10,8 @@ #include #include #include +#include +#include static jmp_buf tee_buf; @@ -37,3 +39,31 @@ int start_optee_early(void *fdt, void *tee) return 0; } + +int mx6_start_optee_early(void *fdt, void *tee, void *data_location, + unsigned int data_location_size) +{ + switch (__imx6_cpu_type()) { + case IMX6_CPUTYPE_IMX6D: + case IMX6_CPUTYPE_IMX6Q: + if (!imx6q_tzc380_is_enabled()) + panic("TZC380 is not enabled, abort OP-TEE loading\n"); + + /* Add early non-secure TZASC region1 to pass DTO */ + imx6q_tzc380_early_ns_region1(); + + /* + * Set the OP-TEE <-> barebox exchange data location to zero. + * This is optional since recent OP-TEE versions perform the + * memset too. + */ + if (data_location) + memset(data_location, 0, data_location_size); + + break; + default: + panic("Unknown CPU type\n"); + } + + return start_optee_early(fdt, tee); +} diff --git a/include/tee/optee.h b/include/tee/optee.h index f52775dab5b4..19d9a20c7cdc 100644 --- a/include/tee/optee.h +++ b/include/tee/optee.h @@ -54,6 +54,8 @@ static inline int optee_get_membase(u64 *membase) #ifdef __PBL__ int start_optee_early(void* fdt, void* tee); +int mx6_start_optee_early(void *fdt, void *tee, void *data_location, + unsigned int data_location_size); #endif /* __PBL__ */ -- 2.39.5