From patchwork Tue Jan 23 21:10:52 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: 125599 Delivered-To: patch@linaro.org Received: by 10.46.66.141 with SMTP id h13csp2007685ljf; Tue, 23 Jan 2018 13:11:50 -0800 (PST) X-Google-Smtp-Source: AH8x226Pj101Rmp1k8xMZAh8VDHX5tDaHFZg84nrXgw6CkqHZVVuAJ1OyoaLerZ4Gdzj7YNM9tHK X-Received: by 10.80.204.140 with SMTP id q12mr21001676edi.176.1516741910042; Tue, 23 Jan 2018 13:11:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516741910; cv=none; d=google.com; s=arc-20160816; b=BURR3sTgCTbqqU/vUwucR65jcYTSx0t0GBA1wMzfAuQTLm0qoZBDLRQEsZx2U3VoXU aKdd+cM6uXqMQXxUsH8mgZvw6fC7iKgLvs+fMPiBu5E07tmFoKn2GX5MfAAVmmAFO1KV ZPS6BRl0A0BC1t5ctIwLwuz10RgOeeNQJbogaNaSTIJFOD4djMOomMPUoSc3NUp8LySb S/dlFyuUQSiV1e8br8ir1S+XXt2b8N9bKdMCuBariVAjLd8mvJgA15vZLuTgLI7lbZBK mLq8lwzL+NZHPwTLtR/1LjUSEuNJMob2NTkffnWKtM4SzOZBIgji6XNZWgvMTwSfZ5Zi Ku7A== 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=gBbDxyofD/l3Xi5XB2gtxjt+v1fSyjqdhWQCj+Og7F0=; b=LXGGyIVElzFQvxtlbUCVDvFlDHzpnSA3W9JzhEt1WXbvtisBhyDwO/TC8eZI42qEWC A6+y95jwtyCzZWCRkAVbgTiGqpLVZj7ZxHRBodBtkDiwzRbrd7GzIV/QgfGaBvvQ48Qz 8ZehjfjxZyWrbFEURVMN3t5cSDlhpzlp78YSoP/9tedwAvuVTqV8TBFtRhhDNnxWKiJF C0VvU5YzRmeyFYU4oBsEL7jY1fZAWbAEICH8jDr5R9k+hCPm/16PXr/795DjDNDnP15u qo/R7wH6vCwfeoiCPb/YAYq+R7mVRVM3v2/fQSEB6rVIsRO7235ihP0gRsJ8TZitE06Q +YNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=V83JMSCH; 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 i1si687165edc.272.2018.01.23.13.11.49; Tue, 23 Jan 2018 13:11:50 -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=V83JMSCH; 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 92F6BC21C93; Tue, 23 Jan 2018 21:11:18 +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 D57A5C22153; Tue, 23 Jan 2018 21:11:00 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E5447C21DD7; Tue, 23 Jan 2018 21:10:57 +0000 (UTC) Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by lists.denx.de (Postfix) with ESMTPS id 63038C21C93 for ; Tue, 23 Jan 2018 21:10:57 +0000 (UTC) Received: by mail-wm0-f67.google.com with SMTP id 143so4455240wma.5 for ; Tue, 23 Jan 2018 13:10:57 -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=RIE0jz9gICESbGu7eqat6IQ7Wv6u8cEXq2dTHRqU6ug=; b=V83JMSCHWdWHXOalPrizoqCKhq8q80zQHu+ZilEtm2UxB8A3t51yE9djmz0+uVBSBQ bzbNqKfFqtRKgj7yXA4jpVZEQkRCmKiW5RoUSzMviHkEcCZ63kzRo8/y40O/58kS7Xgm MZNVYGD9GfG88vqo9xHDsbv5rlRsTrr2Amj7o= 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=RIE0jz9gICESbGu7eqat6IQ7Wv6u8cEXq2dTHRqU6ug=; b=oUg7e+AD6wsX9l5LkhnRl4SMp4GKAkt/I7RGQunDGw6bQszpFPKwpE47v7mPQkOUT/ ocmQyzqBlVmS03QTyu9iRESD7QLZpGnfVh4Lt2ubKJC2Y4sOelLtFndq0e3ZlQJONPtG HMOTlekVfeNfcX1vAMXxn5Nk7BhVwM6THFtxHghY30VnQ6EyTtf/XBOqkqUyIuu6eex7 IZNuW5TBvSbhP1YY+VdyDh5E2yOxO4m8VrUQtoE0x0DBAATSCuk5POvqCkep/mMDL4ug zr1iisMi3IsX/uWOidvEOTl2SaI58m1u7kIp8yRpk4I06nNAQheBFJsCmz1MOkQ4xbwl ZA5A== X-Gm-Message-State: AKwxyteWzcHehyPNA6X4oLjjdweHdvbrYty/UygY+5SP1wQlqsj02LYg pxO/jB7ZjNTtcJ8dBoNLDHESnzHsp/k= X-Received: by 10.80.142.25 with SMTP id 25mr5226391edw.127.1516741856868; Tue, 23 Jan 2018 13:10:56 -0800 (PST) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id x25sm13860657eda.8.2018.01.23.13.10.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 23 Jan 2018 13:10:56 -0800 (PST) From: Bryan O'Donoghue To: u-boot@lists.denx.de, trini@konsulko.com Date: Tue, 23 Jan 2018 21:10:52 +0000 Message-Id: <1516741853-12458-2-git-send-email-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516741853-12458-1-git-send-email-bryan.odonoghue@linaro.org> References: <1516741853-12458-1-git-send-email-bryan.odonoghue@linaro.org> Cc: Aneesh Bansal , fabio.estevam@nxp.com, Ruchika Gupta Subject: [U-Boot] [PATCH 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. 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 --- drivers/crypto/fsl/jr.c | 9 +++++++++ drivers/crypto/fsl/jr.h | 1 + 2 files changed, 10 insertions(+) diff --git a/drivers/crypto/fsl/jr.c b/drivers/crypto/fsl/jr.c index 986eabf..cbf570d 100644 --- a/drivers/crypto/fsl/jr.c +++ b/drivers/crypto/fsl/jr.c @@ -566,6 +566,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 @@ -621,6 +623,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; + 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 d897e57..72f7501 100644 --- a/drivers/crypto/fsl/jr.h +++ b/drivers/crypto/fsl/jr.h @@ -34,6 +34,7 @@ #define JRNSLIODN_MASK 0x0fff0000 #define JRSLIODN_SHIFT 0 #define JRSLIODN_MASK 0x00000fff +#define JROWN_NS 0x00000008 #define JQ_DEQ_ERR -1 #define JQ_DEQ_TO_ERR -2 From patchwork Tue Jan 23 21:10:53 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: 125600 Delivered-To: patch@linaro.org Received: by 10.46.66.141 with SMTP id h13csp2008139ljf; Tue, 23 Jan 2018 13:12:46 -0800 (PST) X-Google-Smtp-Source: AH8x227xa4/CbRmL0wD5ox22A9RFPsJRsc9MPlBTs5Vp7yslCsyBlpNYAoQkBahPsDMkKM608mxT X-Received: by 10.80.194.194 with SMTP id u2mr20977811edf.84.1516741966047; Tue, 23 Jan 2018 13:12:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516741966; cv=none; d=google.com; s=arc-20160816; b=h2kykMlzuxNwAdrOSEdJ/bWgw9jJus2raZIi4E86l575xIeEoyz2ZYyglPLt1Bsckg BInABRxd3ixuaUz8jPqRTI8MuS98MwWUuChJpRnlGmrbGyrvG4NtZEAq68pgeHB0qlbS u6Bv8NDDD/n8svQtDnEK+71kSiKg87wo6fiGZVTwOFsusDRfX70J8MQ6xfJN6fIchHB0 BfREc98VBjS1UoGTdv0uFG/TZoDwx4nzeS98yGEVazbbskhRhvcyxSojFay9B8xJh2WV jQ4QnLSR+Swk3QFQcmNASQXhHCHvhTZYCYpDzQJQUzjDR4IolElzRZHE2Qy7aPq/piXe FYDA== 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=h8LOzhqaZ0pUu8uebyGss3sh0X0Ih+ssr+0UTowq8AMRkl64L6RaLdrfZiEqGBdhCR MWs00fbzn1Ttqu6zO22Pi9ySSy5uHWVFQMG25XGemHoVR4a2xwmPCer7aEw6dPl4/rPm 7yGa7AV+UhiwIUQSuMhWle4gHPNN+iySPSLaax1V1js9hBYDcCcEIJjjbRLnDPUeATQO MjYFgu6c4uRB9MM+zDxTd3agF1JcUWaTN42mJ0WyK+PF6moQ1qrCm7JvwQ8j4/D3xVpu xpvDzl2kutzQp2NW4bZT9HGiuZlQ9O+YhsXTZzJqsqqeBUaHZFBYBaxt9j2l9ENm4s5k Ru+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=crU6Y6pw; 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 g3si6833834eda.26.2018.01.23.13.12.45; Tue, 23 Jan 2018 13:12:46 -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=crU6Y6pw; 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 AA506C22103; Tue, 23 Jan 2018 21:11:38 +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 AA94DC21F0A; Tue, 23 Jan 2018 21:11:07 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 2160DC22174; Tue, 23 Jan 2018 21:11:03 +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 74D45C21EE5 for ; Tue, 23 Jan 2018 21:10:58 +0000 (UTC) Received: by mail-wm0-f68.google.com with SMTP id 141so4558409wme.3 for ; Tue, 23 Jan 2018 13:10:58 -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=crU6Y6pwH88EzoXyPivU6HsdAYgp2a+flelUItddcByzSiG0boh16jSwpO1kHymw9x 8L2x4FA117vGdacuM1GhNqUZTVQIKbn3jOxxoF7jyW282SK4AwlFej8Yml3Yhhs7Jlh/ WraVJKotJlRCrObWxc38ODZIL43Hl11E+sPTc= 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=LnPmjjS1mWnDx9a7jATxuBVFhK158kjhM0ZDfQ+a2PC5VQFrvF11nBABEZc4hhozYs 21nlxZ7XmmdKxVkgsUDj34YKA5HGA9C9mDqgbm/YH2qMfzXFF9mZzdNC9/DH2K5Fxtth aZBCiWFhkpbWKBINq7Cyk55khplBLvAtoLWGC0D6z/0ScQZSOGGVbOyJ4V1o8sJEeGRb zqFHWssG/QpX0lwu4nyrkrsfdvUW3vD5Go603DNGdIMzJXBvlVooc+ZxcDgLCZV1LTFa 01MB4OTgF9olKewYyNw6Y1vzyj/smGrhGuaz9IrgSesrK8iisxhA5k/tky/wXpvp7BoF tLyw== X-Gm-Message-State: AKwxyte/YyoiTctuSl4OFosO/xr58beL5GibS+9cg10/D8NZG+wJjZvl C9vYx5u0uOtv8SfbqygJt4U/+GAPL/8= X-Received: by 10.80.163.136 with SMTP id s8mr20369686edb.162.1516741857908; Tue, 23 Jan 2018 13:10:57 -0800 (PST) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id x25sm13860657eda.8.2018.01.23.13.10.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 23 Jan 2018 13:10:57 -0800 (PST) From: Bryan O'Donoghue To: u-boot@lists.denx.de, trini@konsulko.com Date: Tue, 23 Jan 2018 21:10:53 +0000 Message-Id: <1516741853-12458-3-git-send-email-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516741853-12458-1-git-send-email-bryan.odonoghue@linaro.org> References: <1516741853-12458-1-git-send-email-bryan.odonoghue@linaro.org> Cc: Vanessa Maegima , fabio.estevam@nxp.com, Marco Franchi Subject: [U-Boot] [PATCH 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 */