From patchwork Fri Jan 26 02:09:37 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: 125886 Delivered-To: patch@linaro.org Received: by 10.46.89.16 with SMTP id n16csp39636ljb; Thu, 25 Jan 2018 18:10:11 -0800 (PST) X-Google-Smtp-Source: AH8x2278Lxa2lBCNXU5rGdwnYvD4p68+O3LZK89fyfZKWauWdSr9uIF9nCyL6ABjCBa+BHtyVInc X-Received: by 10.80.175.4 with SMTP id g4mr16914095edd.156.1516932611898; Thu, 25 Jan 2018 18:10:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516932611; cv=none; d=google.com; s=arc-20160816; b=AztaO+3VMXp5dsNPh536kDDZIbAq5nb3oBmp4UtbbezEOfFNz4tCNVroK8NvmVbs9Q NZFsH2wah1V1BlgEwlFXeX0J2NKTVa/IByqqNfrqGP8ouG8E9TFX8egSgaZYH+ZUh4bm +ugBmxAwH8LWtaAYWUKTHCD9/O/bgzsyw74aWUiSmX3mZFKWO7agF1IFA+Bgq6L9badz 8qdL+vUQyVpQOWcOVjxSDBvFLhsZLjlpnGxaeq+qsXQPBnQeKwbt+mZxm45VuDFMWU8D d8AwDuNaQvsEH/ae4eQjEDTcUFXRh78eww8PCVtsX4irpUBg0OLi0sx97RCXtMXEJQZF bZMQ== 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=uvxLGwMHXVuhQ2/nMv1PBa92AVun6Q4nC1ujp9r1bL8=; b=Cs1VtjV3xNM6d1ph5/lM9H6kxe9QEA75mZB0c7qvRW5/eEsE22sdfHXn/IiCMjuFi0 gvHEOPGVHq4a/2arxgHXxEQU6XjHGjPfsMDrtYUtQcr1cZLWrPFYEcAB1oxxLDEiFk90 25wyR6t2GJUOkwSJVGgCFr13FDuq0G98J/Rk1Rtmllv8ZjcSEQuU7ZWbesm/Od1ANr7f jpg8LSbVelCZ7jI/bW1kkRwlmhIsdnsPMILecmshpL9L1Fq5cmeVJLDuby48LmJmYJGn lr+ATc6AGwwG7eTsYxWb7zn7GYrSIEgDsBqOrdZ8Hzdf0Fe7g04nkvbGbxiymEcOVUEG S6wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=QXfyAQLN; 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 11si2710348edv.200.2018.01.25.18.10.11; Thu, 25 Jan 2018 18:10:11 -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=QXfyAQLN; 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 6C838C22351; Fri, 26 Jan 2018 02:10:02 +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_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 D63D7C223C0; Fri, 26 Jan 2018 02:09:47 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 7082AC222EB; Fri, 26 Jan 2018 02:09:40 +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 AA542C223C4 for ; Fri, 26 Jan 2018 02:09:40 +0000 (UTC) Received: by mail-wm0-f65.google.com with SMTP id 143so18150080wma.5 for ; Thu, 25 Jan 2018 18:09:40 -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=y8CgIMt2x9gBldWq7cPZH4XmwYJ4nKjFRnfkKkfQqv0=; b=QXfyAQLNlU19LDsn96y32eNdZInis6/5eRq4oEuMD9kGem103u6Vc/ckW9xo9G1XOE 2G6i6J4Ta/61nxQQfykWNFX228zOE9aAPlsSnO+yD8ZlLJ0hz9Wx1GhKqs3teFHuSgji hwfITmlCRXw3V46blt70je2f3+bwPCqN6LnW4= 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=y8CgIMt2x9gBldWq7cPZH4XmwYJ4nKjFRnfkKkfQqv0=; b=QrUQvF66JETLYGDaphO5II+IxMEvXCuFJZJnWxYtWX9yBwYkEEFCuP4emfYReT7+Zj Ix4zVcO81ohetzmwsIhJc6c5eXfU74R/GnTVZ5Ua1YfZI2bhsxYwuFj3Ho2RVsw1yr5F Pec8q6DLd4BVN1uQrpF/aqvGk526c7renTcd2JVvMlz6mKHksVQubRLdqzlFihMI6OYf qslANWhE28ZnXIRNAoovOvtygfA9BVbGZNvScP0YL8SoUfGwbKHVb4gFCivpBwoo84ib M9ObvJdrepe/ZqyxldvOiS1ZsZ35dhaZLSDmAf0AZycjwTr7JBi+zQZJPYbmdAsGI5en FeQg== X-Gm-Message-State: AKwxytdG7UaD6Zg8Ssf6q3mw9mIKL8jdJQSIX6EObgBUS37C1QrzvDIE 33ixCW4e9EFa9je//DCZar9ZGZdmbA8= X-Received: by 10.80.135.205 with SMTP id 13mr33358896edz.253.1516932580178; Thu, 25 Jan 2018 18:09:40 -0800 (PST) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id w41sm1935792edd.32.2018.01.25.18.09.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Jan 2018 18:09:39 -0800 (PST) From: Bryan O'Donoghue To: u-boot@lists.denx.de, trini@konsulko.com Date: Fri, 26 Jan 2018 02:09:37 +0000 Message-Id: <1516932578-19992-2-git-send-email-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516932578-19992-1-git-send-email-bryan.odonoghue@linaro.org> References: <1516932578-19992-1-git-send-email-bryan.odonoghue@linaro.org> Cc: Aneesh Bansal , fabio.estevam@nxp.com, Ruchika Gupta Subject: [U-Boot] [PATCH v2 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 02:09:38 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: 125887 Delivered-To: patch@linaro.org Received: by 10.46.89.16 with SMTP id n16csp40111ljb; Thu, 25 Jan 2018 18:11:10 -0800 (PST) X-Google-Smtp-Source: AH8x225l0lZ5/+kXlenO3kkgg0InSAQ4hFXT8GTLUfMSlV9mfK6CPwot3WM0RweMxDcBiyi13sTd X-Received: by 10.80.182.203 with SMTP id f11mr31792781ede.157.1516932670725; Thu, 25 Jan 2018 18:11:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516932670; cv=none; d=google.com; s=arc-20160816; b=bPBiwNSCrKbyW+SAXSt9+WUvqAVBs8grNWVJfY+cvTRcUl4Dhwfn2VjGGGUnMxddH6 x59IYVt2O5WH8+Iq+9lJ51r4OKxcI84+RaK2dge1lI1gCj5yXjHcz3wIrxBAGv4b3y56 Yp9mfBRbK7jpFv8hZ7KLqNszrhsDL5OrSG2Nj9T0fvfoxYpObO6inHsVvYqDzIuhS7rM V92c96INvOgladTbzClqqlxmk4xBD7S+K4rTYiPuanGnsLVu6W8yRrBBqIjP2ID0cZ2j h58bZGolqKMZm8kGHo4zRC/WDlmDk7o/Z7dyfyKAiig45hPbQ2QcyGlSwZ2O1G2de2gJ mmDQ== 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=3eLRq2mg8jJsQy01ZJ8r7VH6I1+dG63V9TtZ+upiCf8=; b=S4yDQ6xgOtq02AVuzOi1J1dl+djmmfXUCfxeAKwmexWGb1AkwI/EJ2K0vEEG59Kovp nlyuyS+byCnX9C31fp3vKKarYsbmzMbZFbEfNIpxbnMglRTBLxzyNOh8kuRm30U4Ebpz 6vpfwhKzLxc9ZdkWBd7qpzLoqMAC+LcXnmvEuvPl8UhUL0MxI1zYBS1+L0tjsExqmjD3 zr4/YLfRF3KYg9ERhyMOhqpkpq5ZVP5cOzGzS2kZvSto6RCXNm69/F4WylUVErBJIfKb hwQ+4y5+IIoTOAYK9VF43hbo00I+9OMY5mZ4duSXh9emKNgBjfzuFtUDQI+DZ81SpnQx etlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=e0SCd5I5; 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 c92si2416993edd.246.2018.01.25.18.11.10; Thu, 25 Jan 2018 18:11:10 -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=e0SCd5I5; 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 4EBE2C22397; Fri, 26 Jan 2018 02:10:23 +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_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 102D6C2236A; Fri, 26 Jan 2018 02:09:52 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6DA14C22022; Fri, 26 Jan 2018 02:09:41 +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 AEE74C2238A for ; Fri, 26 Jan 2018 02:09:41 +0000 (UTC) Received: by mail-wm0-f65.google.com with SMTP id f71so18177244wmf.0 for ; Thu, 25 Jan 2018 18:09:41 -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=B/Zqa5lgzBct4kH+K5aIDEn8JAK0hEBymM3BNPNEuAc=; b=e0SCd5I5jlnJfnjB21h81cfGYAn8zvyLEU57UGw0K1uvpiTowJEMUVvVysuYLa6PSw P/NTPAzyy225iBiT6eUbtAN+Hd24EKl974zpM2WIwTOb1PlU8bXy4mVmAVOwSF1cdNvs OCE5xn9pJci/vMa7Wo+BSHRJoltqvK+xdk+4U= 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=B/Zqa5lgzBct4kH+K5aIDEn8JAK0hEBymM3BNPNEuAc=; b=bL2zpg37yhiaivhspuDBFMkNfNNyRHzpGo+au1ZkpaEnN9sqzsO1b14yQbh+i/nIno /r6G18yHenbC8A9KfkJfcZJzGL7OGkO/2RQKBAgbPFOKTq1bNnRYsI7CBAcIfHnyFnbt DJlGX6mIv6FtxyKtF1KmZ4B1J2to7JLNpL7JJgSjDIHVz9KEqmpdhKOINFh9nuuKeYGx o5gegwgRrUBoTtkYW12RLSdCzwbdM9k56ZVh6HvKEX28tr6moXuOR93Jdl7a12SVx/gX t23Gjfb4KW2mMeGjfBRUVmVSALMdMvoz+RnPBLlCedASFDGm/TiRjedYFYRnSl9LADnD LwaA== X-Gm-Message-State: AKwxytc/iJv/JQPTUjZLqfJn3dIHJQbbf+U3C3ZLHU7kqNEaovrHsPH9 LvHB+hsNoLc3tJyFWmL0T2x/hmEy4mk= X-Received: by 10.80.245.10 with SMTP id t10mr31399529edm.168.1516932581217; Thu, 25 Jan 2018 18:09:41 -0800 (PST) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id w41sm1935792edd.32.2018.01.25.18.09.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Jan 2018 18:09:40 -0800 (PST) From: Bryan O'Donoghue To: u-boot@lists.denx.de, trini@konsulko.com Date: Fri, 26 Jan 2018 02:09:38 +0000 Message-Id: <1516932578-19992-3-git-send-email-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516932578-19992-1-git-send-email-bryan.odonoghue@linaro.org> References: <1516932578-19992-1-git-send-email-bryan.odonoghue@linaro.org> Cc: Vanessa Maegima , fabio.estevam@nxp.com, Marco Franchi Subject: [U-Boot] [PATCH v2 2/2] warp7 : 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 board_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. Linux then simply has to detect or be told to skip RNG initialisation. 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 --- board/warp7/warp7.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/board/warp7/warp7.c b/board/warp7/warp7.c index 337e76b..219ab6f 100644 --- a/board/warp7/warp7.c +++ b/board/warp7/warp7.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -225,6 +226,10 @@ int board_init(void) setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info1); #endif + #ifdef CONFIG_FSL_CAAM + sec_init(); + #endif + return 0; } @@ -366,5 +371,4 @@ int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name) return 0; } - #endif /* ifdef CONFIG_USB_GADGET */