From patchwork Fri Jan 26 16:27:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 866460 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="ZcJ1xdon"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3zSkq56sysz9s0g for ; Sat, 27 Jan 2018 03:28:17 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 9CD92C224CD; Fri, 26 Jan 2018 16:27:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id A59A6C223C2; Fri, 26 Jan 2018 16:27:21 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3FAE5C2236B; Fri, 26 Jan 2018 16:27:19 +0000 (UTC) Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by lists.denx.de (Postfix) with ESMTPS id C57EAC21C4F for ; Fri, 26 Jan 2018 16:27:18 +0000 (UTC) Received: by mail-wm0-f66.google.com with SMTP id t74so2386384wme.3 for ; Fri, 26 Jan 2018 08:27:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4dNx/TMrG7D8yi9QXj/S16kmmumBLJq2+LV+GS99h2c=; b=ZcJ1xdoncBMddIVHRflJUKwPqxZUskq9/q4mDVUemrvQXaXBl1LnMQ0IlOuLVVJLLE hKOinyX8o4F7gPc08WFBqoNjrQbIYSUQQFon4ej6/pdQFuH1/bzSDQ4v40145VxY6eKE Y7xgYIvQLsqWXuOQ7aZkBhHrpNsEe5zA30o3Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4dNx/TMrG7D8yi9QXj/S16kmmumBLJq2+LV+GS99h2c=; b=WN3QG8qh3N6QQtQh2Ir0lhJ4HQlRu87264ekI9ldHocaFNtOaDSDpIQtBi+OkBR5bX A/Byi9t4NVb1fiQxLdlqp/99LFoAsmCYoR9olR6bwU4aXr0LzWcpsBKIdtL4cXnb4z+N 8DlrJOrHPMTbrgdYJ5ebaRwxa4AVVT+EcV9NHr1kZo2Z+YDTTyd53tKjiGnq6Kdh//GM 5u+pNO9zhn1gOUrBv1yqcQBXoa/ny9Iz9oTKJxp1DPHmXI3rjAIZLF5FwndbY5AnJWDu P7/ii7zi1213iJWeTXXJaG6Wp3n5cngUDkqKNFMw+Goq7M97l3H3Rz0Qp8yj304Xef9U IepA== X-Gm-Message-State: AKwxytcxx9BhuX7HO5PPsKgspmEJvvW5W2Tul8hTxf3JRb/6k5KyKlO5 ApsD+LeYKAOOoGa48+DRq6qhhBu8W+I= X-Google-Smtp-Source: AH8x225GaZhD7ALmKomoMFnbctTG4xlz3aGRUinTom7vX3k0V9/FfF0wI1rO8fexq1Dxgr4YShziJg== X-Received: by 10.80.213.132 with SMTP id v4mr24804452edi.58.1516984038281; Fri, 26 Jan 2018 08:27:18 -0800 (PST) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id s5sm2758137eda.60.2018.01.26.08.27.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jan 2018 08:27:17 -0800 (PST) From: Bryan O'Donoghue To: u-boot@lists.denx.de, trini@konsulko.com Date: Fri, 26 Jan 2018 16:27:14 +0000 Message-Id: <1516984035-20929-2-git-send-email-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516984035-20929-1-git-send-email-bryan.odonoghue@linaro.org> References: <1516984035-20929-1-git-send-email-bryan.odonoghue@linaro.org> Cc: Aneesh Bansal , fabio.estevam@nxp.com, Ruchika Gupta Subject: [U-Boot] [PATCH v4 1/2] drivers/crypto/fsl: assign job-rings to non-TrustZone X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" After enabling TrustZone various parts of the CAAM silicon become inaccessible to non TrustZone contexts. The job-ring registers are designed to allow non TrustZone contexts like Linux to still submit jobs to CAAM even after TrustZone has been enabled. The default job-ring permissions after the BootROM look like this for job-ring zero. ms=0x00008001 ls=0x00008001 The MS field is JRaMIDR_MS (job ring MID most significant). Referring to "Security Reference Manual for i.MX 7Dual and 7Solo Applications Processors, Rev. 0, 03/2017" section 8.10.4 we see that JROWN_NS controls whether or not a job-ring is accessible from non TrustZone. Bit 15 (TrustZone) is the logical inverse of bit 3 hence the above value of 0x8001 shows that JROWN_NS=0 and TrustZone=1. Clearly then as soon as TrustZone becomes active the job-ring registers are no longer accessible from Linux, which is not what we want. This patch explicitly sets all job-ring registers to JROWN_NS=1 (non TrustZone) by default and to the Non-Secure MID 001. Both settings are required to successfully assign a job-ring to non-secure mode. If a piece of TrustZone firmware requires ownership of job-ring registers it can unset the JROWN_NS bit itself. This patch in conjunction with a modification of the Linux kernel to skip HWRNG initialisation makes CAAM usable to Linux with TrustZone enabled. Signed-off-by: Bryan O'Donoghue Cc: Fabio Estevam Cc: Peng Fan Cc: Alex Porosanu Cc: Ruchika Gupta Cc: Aneesh Bansal Link: https://github.com/OP-TEE/optee_os/issues/1408 Link: https://tinyurl.com/yam5gv9a Tested-by: Lukas Auer --- drivers/crypto/fsl/jr.c | 9 +++++++++ drivers/crypto/fsl/jr.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/drivers/crypto/fsl/jr.c b/drivers/crypto/fsl/jr.c index a6dad01..34bd070 100644 --- a/drivers/crypto/fsl/jr.c +++ b/drivers/crypto/fsl/jr.c @@ -579,6 +579,8 @@ int sec_init_idx(uint8_t sec_idx) { ccsr_sec_t *sec = (void *)SEC_ADDR(sec_idx); uint32_t mcr = sec_in32(&sec->mcfgr); + uint32_t jrown_ns; + int i; int ret = 0; #ifdef CONFIG_FSL_CORENET @@ -634,6 +636,13 @@ int sec_init_idx(uint8_t sec_idx) #endif #endif + /* Set ownership of job rings to non-TrustZone mode by default */ + for (i = 0; i < ARRAY_SIZE(sec->jrliodnr); i++) { + jrown_ns = sec_in32(&sec->jrliodnr[i].ms); + jrown_ns |= JROWN_NS | JRMID_NS; + sec_out32(&sec->jrliodnr[i].ms, jrown_ns); + } + ret = jr_init(sec_idx); if (ret < 0) { printf("SEC initialization failed\n"); diff --git a/drivers/crypto/fsl/jr.h b/drivers/crypto/fsl/jr.h index f546226..ef515e7 100644 --- a/drivers/crypto/fsl/jr.h +++ b/drivers/crypto/fsl/jr.h @@ -34,6 +34,8 @@ #define JRNSLIODN_MASK 0x0fff0000 #define JRSLIODN_SHIFT 0 #define JRSLIODN_MASK 0x00000fff +#define JROWN_NS 0x00000008 +#define JRMID_NS 0x00000001 #define JQ_DEQ_ERR -1 #define JQ_DEQ_TO_ERR -2 From patchwork Fri Jan 26 16:27:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 866462 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="ZDrRKBeM"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3zSkqW2sZ6z9s81 for ; Sat, 27 Jan 2018 03:28:39 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id B8DD1C223F5; Fri, 26 Jan 2018 16:28:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id D03CEC223E3; Fri, 26 Jan 2018 16:28:30 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 94E46C2202C; Fri, 26 Jan 2018 16:28:03 +0000 (UTC) Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by lists.denx.de (Postfix) with ESMTPS id 40249C21F7B for ; Fri, 26 Jan 2018 16:28:03 +0000 (UTC) Received: by mail-wm0-f65.google.com with SMTP id f3so22343166wmc.1 for ; Fri, 26 Jan 2018 08:28:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=UFektGUT0F8H8ofO36X+fxQvqJsjUkgfEn7jIDmCJ8U=; b=ZDrRKBeMxR655VLdv1BGajl9ppynVfC1P8SHosvs2/ETO5z0PC07JANOGMzVtRaAah 37kJBLXCRwTfk/gcfVGtyevehPSKFZL4RnX5Z6nU0uc3Sy917q7wmp+YlmuPmnovcLrJ StesYNOWLWhkzmzk3NrAInyJQdCPzW2rlnfA4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=UFektGUT0F8H8ofO36X+fxQvqJsjUkgfEn7jIDmCJ8U=; b=sOd3SGpStVl6sTlcUvkZFXVzd0+rVSynMNi0bI4x3BYtJXzFtCylmzuupWlyLFfQy+ HkX///1P3ECOGJE5ufzVNuRx3EGe2Tofc2Cacl/43oCGlla4828vKHLfc+/wF93M1+/0 r+rIm3Y1hBYe8Tu85fZDMLFWdErireS/a81oW3eoJlSctF2X3jqi+9TE03ZM80/eywtH WM2Wnn2Jx+6TBYTizJxRG9uPSBuS97sAQmyxsmSn4+q2y+tX2F8HudKJk9rGJdKwwA8o OrBMnMRPWO3oOhlLjwHzqDMtzKFa4hOe4A2D6WLfQR26eQIKm6iQ0kxjZYd0LskqeAXu uhoQ== X-Gm-Message-State: AKwxytfYAx8PdElyTawiqP2bhvL1f5hB+d3m6M/8ly0gldPQC8N+ZBgO uZGpnXqiU3oAvt8AHj08mLYFbZjwDEw= X-Google-Smtp-Source: AH8x224qsL04JhOlsgIvK41cszBZmUlaBdcV3AwjCPoiH4Utl49eY7V9Po8+qT08xJifCdMyWLkU1w== X-Received: by 10.80.215.222 with SMTP id m30mr35000226edj.296.1516984082745; Fri, 26 Jan 2018 08:28:02 -0800 (PST) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id z11sm1951741edh.94.2018.01.26.08.28.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jan 2018 08:28:02 -0800 (PST) From: Bryan O'Donoghue To: u-boot@lists.denx.de, trini@konsulko.com Date: Fri, 26 Jan 2018 16:27:58 +0000 Message-Id: <1516984078-21030-1-git-send-email-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.7.4 Cc: Vanessa Maegima , fabio.estevam@nxp.com, Marco Franchi Subject: [U-Boot] [PATCH v4 2/2] imx: mx7: run sec_init for CAAM RNG X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This patch adds a sec_init call into arch_misc_init(). Doing so in conjunction with the patch "drivers/crypto/fsl: assign job-rings to non-TrustZone" enables use of the CAAM in Linux when OPTEE/TrustZone is active. u-boot will initialise the RNG and assign ownership of the job-ring registers to a non-TrustZone context. With recent changes by Lukas Auer to fully initialize the RNG in sec_init() this means that u-boot will hand-off the CAAM in a state that Linux then can use the CAAM without touching the reserved DECO registers. This change is safe both for the OPTEE/TrustZone boot path and the regular non-OPTEE/TrustZone boot path. Signed-off-by: Bryan O'Donoghue Cc: Fabio Estevam Cc: Peng Fan Cc: Marco Franchi Cc: Vanessa Maegima Cc: Stefano Babic Cc: Lukas Auer Tested-by: Lukas Auer Reviewed-by: Fabio Estevam --- arch/arm/mach-imx/mx7/soc.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm/mach-imx/mx7/soc.c b/arch/arm/mach-imx/mx7/soc.c index d160e80..d444046 100644 --- a/arch/arm/mach-imx/mx7/soc.c +++ b/arch/arm/mach-imx/mx7/soc.c @@ -17,6 +17,7 @@ #include #include #include +#include #if defined(CONFIG_IMX_THERMAL) static const struct imx_thermal_plat imx7_thermal_plat = { @@ -262,6 +263,10 @@ int arch_misc_init(void) env_set("soc", "imx7s"); #endif +#ifdef CONFIG_FSL_CAAM + sec_init(); +#endif + return 0; } #endif