From patchwork Fri Jan 26 12:24:43 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: 125954 Delivered-To: patch@linaro.org Received: by 10.46.84.92 with SMTP id y28csp297656ljd; Fri, 26 Jan 2018 04:25:39 -0800 (PST) X-Google-Smtp-Source: AH8x225qflUaSXGuLybzqh7NABr5TPu6zG+UR5rqWOzBFrUy0CI80JIN4hbJBsre9sq7O0evV9qt X-Received: by 10.80.191.71 with SMTP id g7mr33810955edk.246.1516969539750; Fri, 26 Jan 2018 04:25:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516969539; cv=none; d=google.com; s=arc-20160816; b=PSpAbVPXiuc1Z0i2YYhVVQMSvxFfrbBRzaXCQLgmJGP+jEYP1WgDky1+PsjGfyrZt4 EH9jUEnJagnXB+76CSWWPgc4KB5Mv+CWlk+WmSpFv6By9JHwgrsQhSDT0iyH6RSyfrNo 8CUH6jxeJdEPKnEUYKdtFnO1JgeC8Jp9nGPjQ37gYGPD45AtVMfw4BvyZ6F0pphOVzv4 jebkg1i6jhJ73MAAh5Pap4G5NbIw3uZfWyGgIVtBU2SdRYW7xH36XQR+BafUh4e5LTrs mh+YXdzAlmQ1ICTVUlXiI2hEMGEPQikSSykM2Ce48ag7wUC0ZbMUGoIZJAHwwjSwRI78 so5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=ESb42AMR2CA7QFJ1E3josv6VS+cDVqLvWp2LTPpMmDA=; b=uMhdFauRTqHvXim4xQ1QVab4pYyHjw9b4Pi7SIau/qYnBjnoPWWlr7Ow2bC06Ldiu+ vcuX76HPPtZkhF4A+p92U2OpY9OagvTODSDNr2k7jcguVnnIj1IW0B7gTPV25OfLcBgT R070polxctKWf2WcN31i0FObJUG616weVNHvVtwPA4xkm7rwpEFXOe6Ys83KmrQqIGIx 2AlGLTkIDaBeBIWsRgCo2Rl+5Re88snzC5YamFH4UACpiKqj9yfH6vLkrPHpAjrDBPmQ YSWHr4YMMYtyae+poCrg8rLHkbJXoadZ1rdtdawA9hGFSFryZ3zOdN5VcMh33pU+YZ8o i0Jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=SK4BvQ5Q; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id b95si327484edf.239.2018.01.26.04.25.39; Fri, 26 Jan 2018 04:25:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=SK4BvQ5Q; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id 556D3C224E2; Fri, 26 Jan 2018 12:25:10 +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 B803EC224DF; Fri, 26 Jan 2018 12:24:53 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6F136C22487; Fri, 26 Jan 2018 12:24:50 +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 3AD82C21DA1 for ; Fri, 26 Jan 2018 12:24:49 +0000 (UTC) Received: by mail-wm0-f66.google.com with SMTP id r71so936363wmd.1 for ; Fri, 26 Jan 2018 04:24:49 -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=SK4BvQ5QLJ7zGVYFYTISWeA7Vck3ScmQLJU+H0MefO2TO2cMWvcXe8GvY3xqI7uHDc 5WCCwxo3GiUXtcIj3ZAYNb1Ie7Jenpe9FBrP4kHGYKMHCjoUQAsTjf8uuA72HwPvXFDV NaRsxKnB10+eipbl8DkhwPMIKTaPm2dOMP4p4= 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=n5Yw7YOVX97kh06KWo9oDUCgeTI4Mf4keO5SI7gDAEG+L48l9q8jIA8TWvxY1TqUsy lRBbe9NKsYRxcshRffys8KqyKO26aQpn89F73BHVkDkLPNTPohwGaMRIpBlAb/HG6BRF CBrNteCeiFb4J45i3e1QO2GVhb5y+JYLuYoO36CMxHlpO99h0qwkGvk00sbYG86c9ojk HiEk6KQs2u9c5QJahGOLcbOzF3c3kkn5WjNNq84R9ABQ3FLYbzgzF86oNVS6Kmyd46CQ +sDEudI7ZRZkC6xOGHaw65neQPGJ5mxgwR5kGvzqLu5V9GBItiEhtcOQl1QGsEElP6nK GaAw== X-Gm-Message-State: AKwxytdE5co4wPREw9uEiM70WHit9tfs1fdEE6ngQfPPZf5Jj6o9Ghwp MWHXaLxTx6s/kt1BZq8xDabep1O+OWo= X-Received: by 10.80.209.200 with SMTP id i8mr34732692edg.213.1516969488671; Fri, 26 Jan 2018 04:24:48 -0800 (PST) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id 15sm2546827eds.54.2018.01.26.04.24.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jan 2018 04:24:48 -0800 (PST) From: Bryan O'Donoghue To: u-boot@lists.denx.de, trini@konsulko.com Date: Fri, 26 Jan 2018 12:24:43 +0000 Message-Id: <1516969484-19409-2-git-send-email-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516969484-19409-1-git-send-email-bryan.odonoghue@linaro.org> References: <1516969484-19409-1-git-send-email-bryan.odonoghue@linaro.org> Cc: Aneesh Bansal , fabio.estevam@nxp.com, Ruchika Gupta Subject: [U-Boot] [RESEND PATCH v3 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 Reviewed-by: Ruchika Gupta --- 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 12:24:44 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: 125955 Delivered-To: patch@linaro.org Received: by 10.46.84.92 with SMTP id y28csp297918ljd; Fri, 26 Jan 2018 04:26:09 -0800 (PST) X-Google-Smtp-Source: AH8x2272toG6s5CZ6hq6KsFcrC+YSKDlBqreMGEGbXWMyY5NqXOuMNunmq2Q/Tnvofxy9Jrja3gB X-Received: by 10.80.146.81 with SMTP id j17mr34370476eda.205.1516969569237; Fri, 26 Jan 2018 04:26:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516969569; cv=none; d=google.com; s=arc-20160816; b=ZKd4RcShKd4bR/oUFz7N3etQDSxpJwBv/qDQ4IDzunmZAEq1RYabY0V1SswgFfcrBe +VcpF7t0wGdwzzxLl7uSyO+1VKezVPbffSxL+B5U3ETRGmyooAd115C9jj4j2MGZMkd/ 1t1xXDrIbpmGCu/b777DbE3/yz0Cpn5PMEVe2jL0y24Aw4YAsMPak8zcF7BjMduhsS2h CuQvbLv4MAqYwX0sdflz6ieA5ajhREdmvynMK25KEF/boEour+4DrTJzxkml/StywV4k 6LKYn310yKaQOPy1EQ16B2IYNAH8eKXBh8rfztFtBlrVtbKEXstdY+zI+ck9br0CfLKk QcFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=ZQ2P/GBhznLISP9nopfOiCst2kvgxE/W0pAfIvpnijI=; b=k+FBnfBwXOB1KvGKDOKjFsq4EX3vOftycfCEWPFG9HqOpm+Zsf02MkPYK+Uz60zi7f Ov6OLrGXudeMjWuPelZzS8aMVuucoy9OvZ+UWIdYOsXSkWTmRh6M3fcQ2o6TipUxekRD kzWnKOB88hgrQ/Atcrb6YuZVNTS3/gz3ND125f43chScWDTEnNBUzkt/InngMg/+PjPh bVHZox1YGIJpvIwKYBJP7w5KT/RLTejRRt3EtmKCTW7N4vDi7Q+dsU+NXjW7LWvTImQc fIrstuuyyIAz6gzGnFSzWYCbLWhaWAmqtQ9Jsi7KPKL/CGe4WzBOD5bdvyMRoj8z2t36 jJPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=QsSeJm/l; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id p4si304749edb.553.2018.01.26.04.26.09; Fri, 26 Jan 2018 04:26:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=QsSeJm/l; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id CC260C224EB; Fri, 26 Jan 2018 12:25:32 +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 622DBC224DF; Fri, 26 Jan 2018 12:25:12 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 29275C224F7; Fri, 26 Jan 2018 12:24:53 +0000 (UTC) Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by lists.denx.de (Postfix) with ESMTPS id 2D4CEC223F7 for ; Fri, 26 Jan 2018 12:24:50 +0000 (UTC) Received: by mail-wm0-f68.google.com with SMTP id f71so929308wmf.0 for ; Fri, 26 Jan 2018 04:24:50 -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=w0kqJaJq8InjIj0UbEvOWfr58m82ctIMeLrRPVOvRNU=; b=QsSeJm/lvxl7FViJsxAZct7G/tE6XeZLJc6Gh7aBj3E9vshEONXxURd0tre2A1oQov Ip8vgxhP/k8G9jlutUf5f7+2X+Joyfuu42LJ31z091h7Bk92O5tKf6NdxbKmOa9VMuUL 43aLPwWvli9C22cRZ2fLC7DiGT/3r5rPNA+ss= 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=w0kqJaJq8InjIj0UbEvOWfr58m82ctIMeLrRPVOvRNU=; b=gBdKqY0VEUVYzoEKCz3iyo3v2S5Xk2xpADo6okjMLshJCv29YsI5Fr5wk80sjlDDUO FO6e4UWMeRIDA203YGrbk1RzyQmTz79tUcsVrocNeUUkETJwQ/BUCCMlZX8CV0W1j9sA AehScBcnRNmNhcH6hhF4Ht3SJjt5+V1Bs0m+S2E3OUsLQ0LMza3+yPZL2TZflfcDOywT BWczuS3NvjAS/fPGCBOf5NPPk5qWscUsrY37QZyETm8c9JZqktubMIFAtnld95+0SF4c MwEASKmd+sTWf1uLFG9GZWWwJjgAzrJN/k8p/Q3ixEyxn69Iaw+dtH3Q0Ji3RAq7Ylg/ Ht+A== X-Gm-Message-State: AKwxyteSCYRz+ppRgyuHJW7K7Q0rVDqztrr5dUvLHaj/GQT7d6Fba95A fzMmndsq2bBHYWEsmqG89K7+409rJ8Y= X-Received: by 10.80.245.92 with SMTP id w28mr33856009edm.73.1516969489667; Fri, 26 Jan 2018 04:24:49 -0800 (PST) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id 15sm2546827eds.54.2018.01.26.04.24.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Jan 2018 04:24:49 -0800 (PST) From: Bryan O'Donoghue To: u-boot@lists.denx.de, trini@konsulko.com Date: Fri, 26 Jan 2018 12:24:44 +0000 Message-Id: <1516969484-19409-3-git-send-email-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516969484-19409-1-git-send-email-bryan.odonoghue@linaro.org> References: <1516969484-19409-1-git-send-email-bryan.odonoghue@linaro.org> Cc: Vanessa Maegima , fabio.estevam@nxp.com, Marco Franchi Subject: [U-Boot] [RESEND PATCH v3 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 --- arch/arm/mach-imx/mx7/soc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/arm/mach-imx/mx7/soc.c b/arch/arm/mach-imx/mx7/soc.c index d160e80..9023540 100644 --- a/arch/arm/mach-imx/mx7/soc.c +++ b/arch/arm/mach-imx/mx7/soc.c @@ -262,6 +262,10 @@ int arch_misc_init(void) env_set("soc", "imx7s"); #endif +#ifdef CONFIG_FSL_CAAM + sec_init(); +#endif + return 0; } #endif