From patchwork Mon Sep 3 14:46:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 145798 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp2575370ljw; Mon, 3 Sep 2018 07:47:20 -0700 (PDT) X-Received: by 2002:a2e:7113:: with SMTP id m19-v6mr17498237ljc.66.1535986040523; Mon, 03 Sep 2018 07:47:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535986040; cv=none; d=google.com; s=arc-20160816; b=m85eFvsJNuD8vbrA3VzAfB66qkTKFAWKy9quCxP6S+RjZAzwe7Zf9oD4AMDgA3og4k RT7xqkl2yyt0yBK2hEdwt8slA1xJqL41Wr7OM9KvH0jc4MndLBK9VL44RlZ6rNVIQYSi u8tqoYDvX2ag6s0Spk7ulAcGhhPT2N4F2vXBxA6FNI7ZLAoqjON62bkhaLA6Ydvz6mDT mSnWkHT7N5Dnn19YM3vRF5KuFm16poVitOUs3ginJvqt2lPNXEARMNk/69eASp00T4mK 3AoKuFgjyw+F02b/tSrPnbYcaVR+t/hZqRFnEQ62Wp9YSlGrqpmvkpAXUZXvwhWSUXXu 72KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=iQSx05HMMUi4xwXlVR+Lc/rZdgi5IRf7YE6TG4glvE8=; b=qcUWVdGzZQd9qkQw/PZFw/fkQQdkVwXH/RpvVDdha9N0aOjfiF1HGiTeIbhnR2dfpY phgmW54rFcZVSRCVzHVsBmpxbcrm9FOxHkbvl3xUK4i+Wptkdir5Gg789b/x1lEacqpS xdhxyaqqkLcda9a+8S/iA7xD7ScMzkjcYH/CJaP4Hc1lzhUwflP/tLIDus9DRK1MHAgx y9hsSgC6rKeyI57Uu5dw42NFoHZvxeVA6aRu1J6T+3Ms+AOTsBWs05T6CgkWJB6+64Hn AH5gUC0y4VUDY54Oz7wfXgfZdRdW7ZAYlRT3AyBxqSl6cUEcY8sCuQd0AophAAqdByQK 6SfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eoWk0O2r; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id h126-v6sor4184024lfg.22.2018.09.03.07.47.20 for (Google Transport Security); Mon, 03 Sep 2018 07:47:20 -0700 (PDT) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eoWk0O2r; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=iQSx05HMMUi4xwXlVR+Lc/rZdgi5IRf7YE6TG4glvE8=; b=eoWk0O2ra0hW580skXb9KIYU5DkdUDkea23UyGWNiuMl8lQM8A8Piyn1Y3xsrgELo7 a0DXAQPC9LyjaE9+MpWg2r87IAl6IycnL1Yen2bz8hp31MaMFcyoxp2rb4VqcOml1Eit mWW3t7rY0Vb49Vuf3MRI2EiX0Z97lwdfLUFeM= 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=iQSx05HMMUi4xwXlVR+Lc/rZdgi5IRf7YE6TG4glvE8=; b=beqDKB7Sh/kBfzEO3FjipcTdYk3OFz6hoJUw0GK3pNaXV5QNB06IInEfvlMkhHfgNZ d1LIrVKkRC6C2UuEj3Sx7xNOZpyPxeUvWHQRt00qTpnWCjTrrmJGGM0FktqOwEzD3GNQ POglqMQiDNDZL/lSnbDaDqD7IChB7YeXmY5+1NAHP4ZCnps3zmju152W9jjG2RNdPbyi NrD4lYKfb9PGbCPgEIZVzHEU3q8FC6YA2yJ4mQlb0HG8d7OLZE+ApW7SReMcDQk8PCag KAiIdNATPncXqdelSfNRfrlAv17R2zi1dbYeHxDFbIbT3U0Xy3SMVMQ2RAUZTTCnlDNM 8vkQ== X-Gm-Message-State: APzg51A4M1U8Cvk9vQvQnmwJlOZFc2992sll2kBNWdcQDktXnuFlO6Lj OGLqgLWSnjRqs0F0mouHd2kCSGm6 X-Google-Smtp-Source: ANB0Vdb0Y7anrxdlsHhesqYIkbY0k2JSxlfvrfU7YJMfmZRYN4Ah5FfufwUp5Vwyvn3XUAKUh8OkXA== X-Received: by 2002:a19:94c3:: with SMTP id o64-v6mr17730433lfk.70.1535986040235; Mon, 03 Sep 2018 07:47:20 -0700 (PDT) Return-Path: Received: from jax.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id w18-v6sm3343431ljd.73.2018.09.03.07.47.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Sep 2018 07:47:19 -0700 (PDT) From: Jens Wiklander To: u-boot@lists.denx.de Cc: Simon Glass , Igor Opaniuk , Tom Rini , Jaehoon Chung , Pierre Aubert , Albert Aribaud , Peter Griffin , Michal Simek , Jens Wiklander Subject: [PATCH v3 01/20] dm: fdt: scan for devices under /firmware too Date: Mon, 3 Sep 2018 16:46:52 +0200 Message-Id: <20180903144711.31585-2-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180903144711.31585-1-jens.wiklander@linaro.org> References: <20180903144711.31585-1-jens.wiklander@linaro.org> Just as /chosen may contain devices /firmware may contain devices, scan for devices under /firmware too. Reviewed-by: Simon Glass Signed-off-by: Jens Wiklander --- drivers/core/root.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) -- 2.17.1 diff --git a/drivers/core/root.c b/drivers/core/root.c index 72bcc7d7f2a3..0dca507e1187 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -265,9 +265,15 @@ static int dm_scan_fdt_node(struct udevice *parent, const void *blob, for (offset = fdt_first_subnode(blob, offset); offset > 0; offset = fdt_next_subnode(blob, offset)) { - /* "chosen" node isn't a device itself but may contain some: */ - if (!strcmp(fdt_get_name(blob, offset, NULL), "chosen")) { - pr_debug("parsing subnodes of \"chosen\"\n"); + const char *node_name = fdt_get_name(blob, offset, NULL); + + /* + * The "chosen" and "firmware" nodes aren't devices + * themselves but may contain some: + */ + if (!strcmp(node_name, "chosen") || + !strcmp(node_name, "firmware")) { + pr_debug("parsing subnodes of \"%s\"\n", node_name); err = dm_scan_fdt_node(parent, blob, offset, pre_reloc_only); @@ -286,8 +292,7 @@ static int dm_scan_fdt_node(struct udevice *parent, const void *blob, err = lists_bind_fdt(parent, offset_to_ofnode(offset), NULL); if (err && !ret) { ret = err; - debug("%s: ret=%d\n", fdt_get_name(blob, offset, NULL), - ret); + debug("%s: ret=%d\n", node_name, ret); } } From patchwork Mon Sep 3 14:46:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 145799 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp2575393ljw; Mon, 3 Sep 2018 07:47:21 -0700 (PDT) X-Received: by 2002:a2e:9113:: with SMTP id m19-v6mr18557178ljg.23.1535986041756; Mon, 03 Sep 2018 07:47:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535986041; cv=none; d=google.com; s=arc-20160816; b=i4KOXyo9isaYMAwbRW9XcfWsCuAimoqU4lV0N1QTcZk+ztdN5DFaeI5poM0bO+LYGw tJZZjUSs+/wgWwyKf2c6f21HXeoQ2PqPz3PqDwZDB8M+XIVEg4IN0F8f56MEc1OX+wC0 tx5iieE6GrbxZhmLedRmRsThK+oEVqTQMW4F3A5frsrjFladYRhX+nYveZ3bhY6Y++wK SJ5IdIKt5b+r//ZU7K7E088YFqJB9/+BYDhJCihHo5XpmTaYJ4XcM3+3qhG5o0KRho9b cERTlZ6GCxb5dxAGoyWnzvk/VasBIjB+CEhcX2wGylXcS+jB4IiVwfVSDBWXb1d+L6u3 vQoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=z51+B07mGdgmDlGBn5B/4PkJsIHxax8VTG0YmWy/lZA=; b=uNqVUcct8NsWUyzjmll6pxQE7PhM6i+OkWx5kVXA5tJBc8FtqD44nJa0VVyC5xTJhP 9xMSnvcvNNZiQZsLaV7Nslw9YMZXFA8JbY1beW6+qEdl9o1M/Jgq95n6+K2BzEpakvrJ O0GCd9I0weZ6LQ6pP250KWZGZjNdQcOU2tVx36SsPPzMY5JMEaorvD2Joc5s3xJzctCi S6gnkR1zdALrA76YGgvXFg2XF2NWAYfYa1Y9HzojMsJe+ZZU95ESG6HWFNGUhfEJ37ES ryrcpT5yeuPqbLCeBnfgnq6XBYDz4h0idOceJatxnsl6w0r5PCGtj6lzySNWkmM6yiOc frtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g1K1fS4i; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id d2-v6sor5515651lfg.14.2018.09.03.07.47.21 for (Google Transport Security); Mon, 03 Sep 2018 07:47:21 -0700 (PDT) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g1K1fS4i; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=z51+B07mGdgmDlGBn5B/4PkJsIHxax8VTG0YmWy/lZA=; b=g1K1fS4i4Ygp5em2TqNDcwoKk/MepyDfGXJJ0Kq0KajqqRus23wMUEDlhp8+wiR3B4 jJF1rpm237Omt3W5ZKzlfzYozC6f9WDdCivWN7GQiuqF03mf3bbeKPZKtUXSyMIqqph3 4iBtP4H6oLpBzc3X8QHq1wPTpNWrIKDCkEeGM= 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=z51+B07mGdgmDlGBn5B/4PkJsIHxax8VTG0YmWy/lZA=; b=ROL7BuGG0AkSWwtq/ivwtfmf31i33QDHupGXoljgNCpiDNpBw13xlUBO79jAbXQfjI tEC/Kf1ytjBElqkOAE54aeXS/gx+09fwlOKsUjnRH6DVN3PQTrV2i1CW57QcCqRA8eic sme451462mbeBNo+nUpzzWWkJJjaB9LMVZ8Xh1JIt3/MyOH+rjRzcKprue3PDufGMtKf mG71V5QHYuc0AuVPNeZE+f4FvN0S0BAXvCxNSq+vYWIrkFm8QcrmpLaSBdj+gYzbQ3EK Ach3Y/w3tTk7+ArFm03vXzS4E6akvR6AxYvMfyQQ1DNG3RavE64Lz+/Tb7ananCxx8Fb 1WIQ== X-Gm-Message-State: APzg51BIudtn34rRTgXLXzV+h2FZrE8z8MITsN82lsGw9zNo2juLo9CA pYYC9zKUm+1t0ejclN2eQn9F3sQf X-Google-Smtp-Source: ANB0VdaLK3aDya7Im6++b03EWMRkcWRoYRSXJ1V34AdjHTszI15U/Got/7+4/wcK598+Nlq7PyC+1w== X-Received: by 2002:a19:cc08:: with SMTP id c8-v6mr18986918lfg.145.1535986041592; Mon, 03 Sep 2018 07:47:21 -0700 (PDT) Return-Path: Received: from jax.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id w18-v6sm3343431ljd.73.2018.09.03.07.47.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Sep 2018 07:47:20 -0700 (PDT) From: Jens Wiklander To: u-boot@lists.denx.de Cc: Simon Glass , Igor Opaniuk , Tom Rini , Jaehoon Chung , Pierre Aubert , Albert Aribaud , Peter Griffin , Michal Simek , Jens Wiklander Subject: [PATCH v3 02/20] cmd: avb read_rb: print rb_idx in hexadecimal Date: Mon, 3 Sep 2018 16:46:53 +0200 Message-Id: <20180903144711.31585-3-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180903144711.31585-1-jens.wiklander@linaro.org> References: <20180903144711.31585-1-jens.wiklander@linaro.org> Prior to this patch was do_avb_write_rb() reading supplied rb_idx as a hexadecimal number while do_avb_read_rb() printed the read out rb_idx as decimal number. For consistency change do_avb_read_rb() to print rb_idx as a hexadecimal number too. Reviewed-by: Simon Glass Reviewed-by: Igor Opaniuk Signed-off-by: Jens Wiklander --- cmd/avb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.17.1 diff --git a/cmd/avb.c b/cmd/avb.c index f045a0c64c4a..ca4b26d5d7b3 100644 --- a/cmd/avb.c +++ b/cmd/avb.c @@ -158,7 +158,7 @@ int do_avb_read_rb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (avb_ops->read_rollback_index(avb_ops, index, &rb_idx) == AVB_IO_RESULT_OK) { - printf("Rollback index: %llu\n", rb_idx); + printf("Rollback index: %llx\n", rb_idx); return CMD_RET_SUCCESS; } return CMD_RET_FAILURE; From patchwork Mon Sep 3 14:46:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 145800 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp2575417ljw; Mon, 3 Sep 2018 07:47:23 -0700 (PDT) X-Received: by 2002:a2e:7c12:: with SMTP id x18-v6mr4932987ljc.71.1535986043296; Mon, 03 Sep 2018 07:47:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535986043; cv=none; d=google.com; s=arc-20160816; b=NXImKWZbcO2naUXawg6+hpzgMDidQ3bn/tQ1YLvGDScr19i5Zpgep9QdlDyuYSwvWU 3FR55exIJJUqxw3+AOLzRQD1SNgPRkesojOdynlZubxBigZaHNm6Z3VZcq3JyIYX9c6S CsVUzxZm/bKOx/hciXeNIIMC/gY2Ed57Ce+nzXy+UWFDF/CQGNIMayBvuqqBvqR18hdV lVYpPbLmQ8Q/kQjrkpN8FGuvhjPwzUMH2VvFicXXaosdiFQZYcdpv3xChkCX+RwGxDFq oRsNYSGHRxhEF90lnsPqYPTCq+3ECdRdZIlyJsWtG6NdOWw0E3L14U9KJgw6dIGsClQE MWUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=h6g+h+ZtnoYTDzdxUc+VajLlQroiy/9mFI7V8zec+L0=; b=xYzOcAmYww2WjH2XwA7tgYvgIPnpyK3TtBj0all4F/IaOge/gSqr4EJiT2Nev2MCJt BHbGEd40f21j1IyHp4tnV7QaXc2EN18f2jeU55t8nDW+Dbml2mgXZAW7SGo8f5nLkopi JV0Hk+lPnc1EvBeEsb83d16De1zBbK5lI5+gYQGOMh+M3wj0xcV6r5QMZkODEXC6tT/b NU32k2dkthGs6yTcOTof/6cfx8lMnUgTWFhWwKTVJ+aX4rjDQgztdlJntiSk5xyWqQ+l p4qfGvzgd0mHgvFqKBJKgVczbuBRIRwkwkRJennVL8rUqrLWjN9rUkwcgqrM/dlDZq31 2pRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bdS2U6W9; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id 17-v6sor7841251ljs.22.2018.09.03.07.47.23 for (Google Transport Security); Mon, 03 Sep 2018 07:47:23 -0700 (PDT) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bdS2U6W9; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=h6g+h+ZtnoYTDzdxUc+VajLlQroiy/9mFI7V8zec+L0=; b=bdS2U6W9BvJ5G+uj1zd2oPxOI8j7ddbGtL3QM0os2NjSj/Ufhq2PmrVHuZYHqIphci rKdY24dIBITlMYUcZMB/EEpbANUcGMUgxow+hRalRjdp8odZZJRfg9O9Ec2eIvhuiObt ZKoQQ0uV77KNzBn041qzjbMxtOeVZnYGzaqXI= 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=h6g+h+ZtnoYTDzdxUc+VajLlQroiy/9mFI7V8zec+L0=; b=lluOmSjHgW2Guwxv5waSnCF5wIIPIFr/woru1G5OSOoUXsmbT5TYOxoDYEKZ7sew2l Jki5X5mRNwJcusy+gSastBRgZAnlFKg+TjeW1g0yeEYj8mQ9IfFnvYJktKFUh+d8CN6H JVwoSDexmsJgVtDhqSkGWft/0OoRc3lJrTnU5sYFOvltiMpqBGLSX6qQojfFG2xbGFfK aC8XrbQCR7XRtIqRsdTTFUwZBSGvwKzNDohuBMLXF0OS9D+rD1zikb+qVe89j+vEgAYa 9G0ccVpAwNEPSxRKJw/XsSToeApoeHcnsMIaUGRH1nWA+8/AGrwpa3ljyRxJzaYKSWTZ Km/A== X-Gm-Message-State: APzg51AjzN/4DJpb5mm2Yb8m583yhWVz2q88Dw6zLCF7hzms5FH64Zyh c0UZE+OWnDqTmkganCFzm7KSesic X-Google-Smtp-Source: ANB0VdZPX4LbUIvAGwEvM4XblKfAcOih+j72zizr4CcneGZ8HN8EvDMnYAvMQ8V4o2yEgT5YjHwezg== X-Received: by 2002:a2e:990b:: with SMTP id v11-v6mr17578691lji.87.1535986043117; Mon, 03 Sep 2018 07:47:23 -0700 (PDT) Return-Path: Received: from jax.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id w18-v6sm3343431ljd.73.2018.09.03.07.47.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Sep 2018 07:47:22 -0700 (PDT) From: Jens Wiklander To: u-boot@lists.denx.de Cc: Simon Glass , Igor Opaniuk , Tom Rini , Jaehoon Chung , Pierre Aubert , Albert Aribaud , Peter Griffin , Michal Simek , Jens Wiklander Subject: [PATCH v3 03/20] cmd: avb: print error message if command fails Date: Mon, 3 Sep 2018 16:46:54 +0200 Message-Id: <20180903144711.31585-4-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180903144711.31585-1-jens.wiklander@linaro.org> References: <20180903144711.31585-1-jens.wiklander@linaro.org> Reviewed-by: Simon Glass Signed-off-by: Jens Wiklander --- cmd/avb.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) -- 2.17.1 diff --git a/cmd/avb.c b/cmd/avb.c index ca4b26d5d7b3..ff00be4cee38 100644 --- a/cmd/avb.c +++ b/cmd/avb.c @@ -35,6 +35,8 @@ int do_avb_init(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (avb_ops) return CMD_RET_SUCCESS; + printf("Failed to initialize avb2\n"); + return CMD_RET_FAILURE; } @@ -65,6 +67,8 @@ int do_avb_read_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return CMD_RET_SUCCESS; } + printf("Failed to read from partition\n"); + return CMD_RET_FAILURE; } @@ -108,6 +112,8 @@ int do_avb_read_part_hex(cmd_tbl_t *cmdtp, int flag, int argc, return CMD_RET_SUCCESS; } + printf("Failed to read from partition\n"); + free(buffer); return CMD_RET_FAILURE; } @@ -138,6 +144,8 @@ int do_avb_write_part(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return CMD_RET_SUCCESS; } + printf("Failed to write in partition\n"); + return CMD_RET_FAILURE; } @@ -161,6 +169,9 @@ int do_avb_read_rb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) printf("Rollback index: %llx\n", rb_idx); return CMD_RET_SUCCESS; } + + printf("Failed to read rollback index\n"); + return CMD_RET_FAILURE; } @@ -184,6 +195,8 @@ int do_avb_write_rb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) AVB_IO_RESULT_OK) return CMD_RET_SUCCESS; + printf("Failed to write rollback index\n"); + return CMD_RET_FAILURE; } @@ -210,6 +223,8 @@ int do_avb_get_uuid(cmd_tbl_t *cmdtp, int flag, return CMD_RET_SUCCESS; } + printf("Failed to read UUID\n"); + return CMD_RET_FAILURE; } @@ -320,6 +335,8 @@ int do_avb_is_unlocked(cmd_tbl_t *cmdtp, int flag, return CMD_RET_SUCCESS; } + printf("Can't determine device lock state.\n"); + return CMD_RET_FAILURE; } From patchwork Mon Sep 3 14:46:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 145801 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp2575444ljw; Mon, 3 Sep 2018 07:47:25 -0700 (PDT) X-Received: by 2002:a2e:4557:: with SMTP id s84-v6mr17440881lja.47.1535986045281; Mon, 03 Sep 2018 07:47:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535986045; cv=none; d=google.com; s=arc-20160816; b=xFOJ5+Z1gGath+1VdSsrtMY6ditUgnN/75eF+7d96hKSM5ebpI7qQhbKuo9Z/xeDxN lG7UTdbnKVkB5c/3WVaejR4wHK72d5va3gejDxc/BITVG5R/+tIl6K8TpjDpQPogLjnx LvdTy6+TXaYkDuPNsT1+6/+Ln7aGelhoEuTopglx3uDGoE9LOSDC1/MwReDHPzOK4t8R 8eoqrlKAOkYywj+675w7U1SKXwfodgYkPdAfcOUL3k1u8gk6ssrIJpy8nFX8TKge7g4H CEMPESMnE8okKgnlUreazaXhY2KU4QsCdMenNfTECVd/xR4L9Jvg//Pr5kXm2u4kkCnf 1amw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=MvAIS+ckxlGzE9N89gxX0Q94LGWzUIHA2MGYL9i3jeA=; b=YGa6a7JUF2cE1KhB3pYGM5RbBkU3BkxmS3Y4IMxwEUL76MDHQybLjNXkDqZybQuiLP oQlN1Pa58rDFaWf3QtGkfGU3v5mYSfg1YIf51DlNL5s1qvjKOdb233404pU+h7iZkT0d 41M50SYx4tWmZBWRqHZxwYOojRlHA3orn8c4fW2s8Bn0cHa/M3YY/td9wb6FW/jSnpd2 HPUS3zjXoVNlmwfdWlT0VwtIc5DdceM9mh770Z6z8vBzWxsmhtcz6nMSGYKVawJIcgYd GPnFHkMOBkORl3JuTLnKk16m6DRKC3q1Q7tSQRAknV9xbajxgQ+WnZjhUsaDq6y6BEQA vLEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Je9z2NVv; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id f17-v6sor5460854lfi.43.2018.09.03.07.47.25 for (Google Transport Security); Mon, 03 Sep 2018 07:47:25 -0700 (PDT) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Je9z2NVv; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=MvAIS+ckxlGzE9N89gxX0Q94LGWzUIHA2MGYL9i3jeA=; b=Je9z2NVvDh2mt84SXikl5j5E2SrdqMeMmeAQ662lxwe8sRcRmT7+lKr4CKWVSa59CG 4/BeK6Z1LvrDJRJNAmJqtabIJDfyRwPFGpt8FdgYNkLc1hEIb1iEfCQtsSbNeMv7C0kx 61idAR66GsCchUyJOS8EPAxnjjE/dBp8oIbpg= 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=MvAIS+ckxlGzE9N89gxX0Q94LGWzUIHA2MGYL9i3jeA=; b=KDlF6bn61KGvya3eS8B08QucmaRkMZTEStpn0HVCjfNrv10fbWN6YGkr3jYbso7W7a sJ/gtBaDjHaRG884+bLey0pbB41h7TNWRTgkPBKm/VfVU4nSKFS4AAAhfRuQkGXZDMyz 0foIpuVTvUiNhnYQmzScLCLtXBwMZa8ZlgqReIyIF2HosYCBBRyVBKm46Wo2e1TKNzH9 nloCxuZpjONeymr/1qye1we1Thx/PvOE3+Ebpl1OQMiHgrBBGtlHY9qg5bRUy4PaHPf0 UC7yOf8+Uy9ReLbJ7mllAOBuMJb/ko7/8wSDaQ3J7XPLFpVVjNEzO+P2VzbQHXr8lcxh ZdHw== X-Gm-Message-State: APzg51DIJlDh8PCGnh/eNybx5ZPw9u+kyr5dQETNsUQpBWuquaMkwrXV qyUUD/tTw5wQqKbBMZ92TbKu1khm X-Google-Smtp-Source: ANB0VdZeKKjZ6ijDugXlUy5DQPBoFVo54hkDYmg1BSF+UOiZIkfCanPgT8Fd8YaX5juHpu+Y/i0z2g== X-Received: by 2002:a19:a549:: with SMTP id o70-v6mr14942043lfe.147.1535986044457; Mon, 03 Sep 2018 07:47:24 -0700 (PDT) Return-Path: Received: from jax.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id w18-v6sm3343431ljd.73.2018.09.03.07.47.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Sep 2018 07:47:23 -0700 (PDT) From: Jens Wiklander To: u-boot@lists.denx.de Cc: Simon Glass , Igor Opaniuk , Tom Rini , Jaehoon Chung , Pierre Aubert , Albert Aribaud , Peter Griffin , Michal Simek , Jens Wiklander Subject: [PATCH v3 04/20] avb_verify: bugfix avb_ops_free() skipping free Date: Mon, 3 Sep 2018 16:46:55 +0200 Message-Id: <20180903144711.31585-5-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180903144711.31585-1-jens.wiklander@linaro.org> References: <20180903144711.31585-1-jens.wiklander@linaro.org> Before this patch avb_ops_free() was returning early if supplied "ops" argument was not NULL. This patch fixes this by inverting the condition. Signed-off-by: Jens Wiklander --- common/avb_verify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.17.1 Reviewed-by: Simon Glass diff --git a/common/avb_verify.c b/common/avb_verify.c index 20e35ade3029..3a1282a09204 100644 --- a/common/avb_verify.c +++ b/common/avb_verify.c @@ -732,7 +732,7 @@ void avb_ops_free(AvbOps *ops) { struct AvbOpsData *ops_data; - if (ops) + if (!ops) return; ops_data = ops->user_data; From patchwork Mon Sep 3 14:46:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 145802 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp2575457ljw; Mon, 3 Sep 2018 07:47:26 -0700 (PDT) X-Received: by 2002:a2e:5bd5:: with SMTP id m82-v6mr18908197lje.115.1535986046022; Mon, 03 Sep 2018 07:47:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535986046; cv=none; d=google.com; s=arc-20160816; b=coMNNqGKBu9/EnHb279NPfO4z8Q/XxfYKJUG3pCUhipHtfNANL0Ffyk83ZKu7WGD6S Y0eKPJ9SYBVbf9V8SyswakTWIeb0EiKXsh9UNtV9u5hR3ArsPpUZA8YWUPQA7+Vu3YQ6 Yrr5Y5ZNA8ovJRRkhQdsYG6ykaPUGc+U2v1t4kueQUXldXIOp1D+eFX4ILiSm4+JYpes JjPsC6ZgTx5jlXuNwRWmCopLiF72Os9aw+B9CdIJjmsGRL0Au7RCw+Hpk0I36z70TwYC RWvaMbWs0takmwIK7rtKy2Y5M/fk0nC+BVh83CYpVvV3ND/BQn8ft3BDU697cJkIdUyg MdyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=u/0UF/7NtCAZYvPhEOE+mzk3+7xY9MuJlAagyF0alyw=; b=Em58ebE9k0S1j2jQ9JoG/j5vRtl1DZ7y2S9EfBNYed1cW/D7q9QR96jM+4XI9YJYy+ FojbxO/Nt26xEHWNPC3zrvlTUkyOzGj9Turn2YesKY4irgAf8xhoIFP/wYUC8qJj7QBA ZVzwxmJdITEi8RWPrE6LXZK9MeJQ2jzYIQvIvJeNkrvaR9NAIo2eCEIE8nfFrvTc13JT 0FQPLbVAP6JfWqRglNtwgVLbyceRatT7d9T7NGB5S7jsufBRKuECd+kFn8xRmOI+ZeYI TcpFxIeRnDWWP7Vpg3QxT+GVcG3dua8yECja3faj5dsdHKyL560xukgueHecX4xrvgsb xT0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TemU7UBD; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id m23-v6sor7899662ljj.33.2018.09.03.07.47.25 for (Google Transport Security); Mon, 03 Sep 2018 07:47:26 -0700 (PDT) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TemU7UBD; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=u/0UF/7NtCAZYvPhEOE+mzk3+7xY9MuJlAagyF0alyw=; b=TemU7UBDxXtLNW+uQNXowqsMXNhjZMyo0a0PAAqDjb8BBuii3ZZpfpJYk+4gonX66G tuuSSTTvVc5IoPXggp5agRnDXi2JT5alvRTD1f3aagR6zy4RUl5AwN5sQXaLObTUigVn 6YVjdK0MFGdN3zMrUJ8I5rKDt9sK9spWXxfO4= 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=u/0UF/7NtCAZYvPhEOE+mzk3+7xY9MuJlAagyF0alyw=; b=Ryb1U+RVQgDlwdkjgw7w9iu5iZsJ6Fut8gdblZwjUO2pAmJUJ/RuGGHX/jsVOa9rDc fdntD5IbOVcpsLPLfhrSn0HcOztkc8Clhwu8OlTGFlsPYBk6Ei1pj0PHPNsJvwjEGzIJ n2+926S+Op2KUpURinSAD1JpOpoEQ4hyNBo/GcLXqnTkRGhMWO8dqeddDw8m1uPjmfq6 TiXK+bjJRke6iXpG5XcUXiBX5buzS0UAkS5gjDLMNuUbYld+p1X9/7/WVwfgZh+fGFu0 T28ty/1Qhmpc+UwB5WyYvvLhbRMi6+/5SBK7/ZC9tEOx+LNd5N7mGDfn/g6S6tIoRj+/ lL2A== X-Gm-Message-State: APzg51BO+yLOOEbOys6dEjl86NnqgNFxeYLkopANsNzqjG6kPRJL7FBE E70+H2y+abfFxljmCqwSsTTqyHPq X-Google-Smtp-Source: ANB0VdakHXkWiMfAQC+31JnfmrhuMv8sw6oujCAE8CNnnDCYPqHpui6sAy35pa+jTKfLLjs4Zx8xGw== X-Received: by 2002:a2e:89c5:: with SMTP id c5-v6mr12333058ljk.19.1535986045782; Mon, 03 Sep 2018 07:47:25 -0700 (PDT) Return-Path: Received: from jax.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id w18-v6sm3343431ljd.73.2018.09.03.07.47.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Sep 2018 07:47:25 -0700 (PDT) From: Jens Wiklander To: u-boot@lists.denx.de Cc: Simon Glass , Igor Opaniuk , Tom Rini , Jaehoon Chung , Pierre Aubert , Albert Aribaud , Peter Griffin , Michal Simek , Jens Wiklander Subject: [PATCH v3 05/20] mmc: rpmb: add mmc_rpmb_route_frames() Date: Mon, 3 Sep 2018 16:46:56 +0200 Message-Id: <20180903144711.31585-6-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180903144711.31585-1-jens.wiklander@linaro.org> References: <20180903144711.31585-1-jens.wiklander@linaro.org> Adds mmc_rpmb_route_frames() to route RPMB data frames from/to an external entity. Tested-by: Igor Opaniuk Signed-off-by: Jens Wiklander --- drivers/mmc/rpmb.c | 160 +++++++++++++++++++++++++++++++++++++++++++++ include/mmc.h | 2 + 2 files changed, 162 insertions(+) -- 2.17.1 diff --git a/drivers/mmc/rpmb.c b/drivers/mmc/rpmb.c index dfbdb0deb107..908f19208955 100644 --- a/drivers/mmc/rpmb.c +++ b/drivers/mmc/rpmb.c @@ -321,3 +321,163 @@ int mmc_rpmb_write(struct mmc *mmc, void *addr, unsigned short blk, } return i; } + +static int send_write_mult_block(struct mmc *mmc, const struct s_rpmb *frm, + unsigned short cnt) +{ + struct mmc_cmd cmd = { + .cmdidx = MMC_CMD_WRITE_MULTIPLE_BLOCK, + .resp_type = MMC_RSP_R1b, + }; + struct mmc_data data = { + .src = (const void *)frm, + .blocks = cnt, + .blocksize = sizeof(*frm), + .flags = MMC_DATA_WRITE, + }; + + return mmc_send_cmd(mmc, &cmd, &data); +} + +static int send_read_mult_block(struct mmc *mmc, struct s_rpmb *frm, + unsigned short cnt) +{ + struct mmc_cmd cmd = { + .cmdidx = MMC_CMD_READ_MULTIPLE_BLOCK, + .resp_type = MMC_RSP_R1, + }; + struct mmc_data data = { + .dest = (void *)frm, + .blocks = cnt, + .blocksize = sizeof(*frm), + .flags = MMC_DATA_READ, + }; + + return mmc_send_cmd(mmc, &cmd, &data); +} + +static int rpmb_route_write_req(struct mmc *mmc, struct s_rpmb *req, + unsigned short req_cnt, struct s_rpmb *rsp, + unsigned short rsp_cnt) +{ + int ret; + + /* + * Send the write request. + */ + ret = mmc_set_blockcount(mmc, req_cnt, true); + if (ret) + return ret; + + ret = send_write_mult_block(mmc, req, req_cnt); + if (ret) + return ret; + + /* + * Read the result of the request. + */ + ret = mmc_set_blockcount(mmc, 1, false); + if (ret) + return ret; + + memset(rsp, 0, sizeof(*rsp)); + rsp->request = cpu_to_be16(RPMB_REQ_STATUS); + ret = send_write_mult_block(mmc, rsp, 1); + if (ret) + return ret; + + ret = mmc_set_blockcount(mmc, 1, false); + if (ret) + return ret; + + return send_read_mult_block(mmc, rsp, 1); +} + +static int rpmb_route_read_req(struct mmc *mmc, struct s_rpmb *req, + unsigned short req_cnt, struct s_rpmb *rsp, + unsigned short rsp_cnt) +{ + int ret; + + /* + * Send the read request. + */ + ret = mmc_set_blockcount(mmc, 1, false); + if (ret) + return ret; + + ret = send_write_mult_block(mmc, req, 1); + if (ret) + return ret; + + /* + * Read the result of the request. + */ + + ret = mmc_set_blockcount(mmc, rsp_cnt, false); + if (ret) + return ret; + + return send_read_mult_block(mmc, rsp, rsp_cnt); +} + +static int rpmb_route_frames(struct mmc *mmc, struct s_rpmb *req, + unsigned short req_cnt, struct s_rpmb *rsp, + unsigned short rsp_cnt) +{ + unsigned short n; + + /* + * If multiple request frames are provided, make sure that all are + * of the same type. + */ + for (n = 1; n < req_cnt; n++) + if (req[n].request != req->request) + return -EINVAL; + + switch (be16_to_cpu(req->request)) { + case RPMB_REQ_KEY: + if (req_cnt != 1 || rsp_cnt != 1) + return -EINVAL; + return rpmb_route_write_req(mmc, req, req_cnt, rsp, rsp_cnt); + + case RPMB_REQ_WRITE_DATA: + if (!req_cnt || rsp_cnt != 1) + return -EINVAL; + return rpmb_route_write_req(mmc, req, req_cnt, rsp, rsp_cnt); + + case RPMB_REQ_WCOUNTER: + if (req_cnt != 1 || rsp_cnt != 1) + return -EINVAL; + return rpmb_route_read_req(mmc, req, req_cnt, rsp, rsp_cnt); + + case RPMB_REQ_READ_DATA: + if (req_cnt != 1 || !req_cnt) + return -EINVAL; + return rpmb_route_read_req(mmc, req, req_cnt, rsp, rsp_cnt); + + default: + debug("Unsupported message type: %d\n", + be16_to_cpu(req->request)); + return -EINVAL; + } +} + +int mmc_rpmb_route_frames(struct mmc *mmc, void *req, unsigned long reqlen, + void *rsp, unsigned long rsplen) +{ + /* + * Whoever crafted the data supplied to this function knows how to + * format the PRMB frames and which response is expected. If + * there's some unexpected mismatch it's more helpful to report an + * error immediately than trying to guess what was the intention + * and possibly just delay an eventual error which will be harder + * to track down. + */ + + if (reqlen % sizeof(struct s_rpmb) || rsplen % sizeof(struct s_rpmb)) + return -EINVAL; + + return rpmb_route_frames(mmc, req, reqlen / sizeof(struct s_rpmb), + rsp, rsplen / sizeof(struct s_rpmb)); +} diff --git a/include/mmc.h b/include/mmc.h index df4255b828a7..d6e02af4edea 100644 --- a/include/mmc.h +++ b/include/mmc.h @@ -748,6 +748,8 @@ int mmc_rpmb_read(struct mmc *mmc, void *addr, unsigned short blk, unsigned short cnt, unsigned char *key); int mmc_rpmb_write(struct mmc *mmc, void *addr, unsigned short blk, unsigned short cnt, unsigned char *key); +int mmc_rpmb_route_frames(struct mmc *mmc, void *req, unsigned long reqlen, + void *rsp, unsigned long rsplen); #ifdef CONFIG_CMD_BKOPS_ENABLE int mmc_set_bkops_enable(struct mmc *mmc); #endif From patchwork Mon Sep 3 14:46:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 145803 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp2575491ljw; Mon, 3 Sep 2018 07:47:28 -0700 (PDT) X-Received: by 2002:a2e:9b04:: with SMTP id u4-v6mr17441820lji.78.1535986047943; Mon, 03 Sep 2018 07:47:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535986047; cv=none; d=google.com; s=arc-20160816; b=DB+XZqTdPND/72Hj4ZC3eQD236XbdLO86OOod/Wpoa5BqKYxrx5VPZCuYnHVCoYoZk 6DVF1PAVOspDWVb4p6qIA2Db5u8kUIikoDHFzU75Km/X3ngFjJ8ozJyapGxZrspcB+6g E7wgeqFPBSITIxYasusBTpE8IbmKkqF7OCN93KJg9blcaFlOFeIpX50v0/1jTokada/Q kVCCSxLHJRQh4EI0BDiKDn5LcYRPaQ/tV/I8psHoIY21c72Eguv0P/JXi647ADBtAx4C Kf3rasvJWl3dObeWQGFPGqcpQUULZOj7IwdQeQhjpOqeMlIQL/Dz4rqubarq4/WbLoYz s/gA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=QxlYcu5pNMU9EByveXU4SfbTHqW8o+fuW7xpqj+jA/M=; b=cfteuKaliXRsIMhfvmlUUFTHJ8xoWnJPSTXrdSxYik3qvV8F1fmChLE02239Q1DUAc wWtdP0wgpYKjkLrEOja4wHzZjCZzupq2Gixw3Kax/BfV6iWOPOX1kLzEjBIVOWwXUz2S JdUJgvuMgPnmxZwqsmK62oHltKYJbM7p7EPa8yU91q0Z7/MPmP1lLLryu0HJ1ELIlquV vt8nYHshqddnqgLMSgjyJuFNazN2W+Nbw/ts7OpD9RvRNswDTVKR4C5ElHp7DKqzdTzf ncQ8dEsk7abeNO1gTG6QQhBsvRqch44qiyRH2K7B6mv5zVFYEr+ltTxsTghoDXQKC2cU boxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=czeSarBb; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id c70-v6sor5029315lfe.41.2018.09.03.07.47.27 for (Google Transport Security); Mon, 03 Sep 2018 07:47:27 -0700 (PDT) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=czeSarBb; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=QxlYcu5pNMU9EByveXU4SfbTHqW8o+fuW7xpqj+jA/M=; b=czeSarBbdrZWDSDeordioktvtOFpx7ErDvr9TAfHJEsirEbwKCm/qiSx7Gek9WTTV6 fU7s1nkv1t3SYnAxPtn0KxFOs0iG2ZhMrpMovIapTI7fAaXOWGsleIDzzNVKFim2h/ee yDjgUZ9EqMjGRIWphMlP583xMTtB3QfK33/Gk= 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=QxlYcu5pNMU9EByveXU4SfbTHqW8o+fuW7xpqj+jA/M=; b=XVPC0soHPTvWjvXxCZ8/Bq53WWq96saRydWir4lYy8A2VTA9mhWTKEGplqu7IMpccg u7heRIsaSRP2dg0mRGoGsdCa8u2/pVYyczsbhQ9BB2dz8p+EMYl6Aj26mbDFyV9p4ljs CJC1Pl7aSY9gcmXhkZ4JHsLsyCR3RHWNpxaaDyC0XrmGt6LaMYyP8lm8zSM4L9SX48t8 xSw0VT5zsQQ9mt7H4EztnadPUuS9+0/gxH7zUIhu4K5d9peqbo2iST27aL/WFSNQlPM1 uUxIogzMinY2RkeEkrzz7Sk+AHMs8NTtxZOfKzvR7LEcxrKb1kM8tqZQXOfJncA7ubJQ H99Q== X-Gm-Message-State: APzg51Dwite9tkx3wZ/9UinHcj9rsn3JgmWPimQSMmlDZ7N0ovf1yqXk Vu6FJeh49AlnPIbyqE49Jinr/2wz X-Google-Smtp-Source: ANB0VdY5IrX4XzMngAKZvwkN3a+FJhv+/6N9JN22DqOA9tS/rBz64MjFx8Md/9kiEWIuiAsUrejC1w== X-Received: by 2002:a19:aa52:: with SMTP id t79-v6mr18562119lfe.85.1535986047354; Mon, 03 Sep 2018 07:47:27 -0700 (PDT) Return-Path: Received: from jax.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id w18-v6sm3343431ljd.73.2018.09.03.07.47.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Sep 2018 07:47:26 -0700 (PDT) From: Jens Wiklander To: u-boot@lists.denx.de Cc: Simon Glass , Igor Opaniuk , Tom Rini , Jaehoon Chung , Pierre Aubert , Albert Aribaud , Peter Griffin , Michal Simek , Jens Wiklander Subject: [PATCH v3 06/20] Add UCLASS_TEE for Trusted Execution Environment Date: Mon, 3 Sep 2018 16:46:57 +0200 Message-Id: <20180903144711.31585-7-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180903144711.31585-1-jens.wiklander@linaro.org> References: <20180903144711.31585-1-jens.wiklander@linaro.org> Adds a uclass to interface with a TEE (Trusted Execution Environment). A TEE driver is a driver that interfaces with a trusted OS running in some secure environment, for example, TrustZone on ARM cpus, or a separate secure co-processor etc. The TEE subsystem can serve a TEE driver for a Global Platform compliant TEE, but it's not limited to only Global Platform TEEs. The over all design is based on the TEE subsystem in the Linux kernel, tailored for U-Boot. Reviewed-by: Simon Glass Tested-by: Igor Opaniuk Signed-off-by: Jens Wiklander --- MAINTAINERS | 6 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/tee/Kconfig | 11 ++ drivers/tee/Makefile | 3 + drivers/tee/tee-uclass.c | 209 ++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/tee.h | 336 +++++++++++++++++++++++++++++++++++++++ 8 files changed, 569 insertions(+) create mode 100644 drivers/tee/Kconfig create mode 100644 drivers/tee/Makefile create mode 100644 drivers/tee/tee-uclass.c create mode 100644 include/tee.h -- 2.17.1 diff --git a/MAINTAINERS b/MAINTAINERS index 58b61ac05882..7458c606ee92 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -571,6 +571,12 @@ TQ GROUP S: Orphaned (Since 2016-02) T: git git://git.denx.de/u-boot-tq-group.git +TEE +M: Jens Wiklander +S: Maintained +F: drivers/tee/ +F: include/tee.h + UBI M: Kyungmin Park M: Heiko Schocher diff --git a/drivers/Kconfig b/drivers/Kconfig index c72abf893297..f3249ab1d143 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -94,6 +94,8 @@ source "drivers/spmi/Kconfig" source "drivers/sysreset/Kconfig" +source "drivers/tee/Kconfig" + source "drivers/thermal/Kconfig" source "drivers/timer/Kconfig" diff --git a/drivers/Makefile b/drivers/Makefile index d53208540ea6..0fcae36f50f7 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -103,6 +103,7 @@ obj-y += smem/ obj-y += soc/ obj-$(CONFIG_REMOTEPROC) += remoteproc/ obj-y += thermal/ +obj-$(CONFIG_TEE) += tee/ obj-$(CONFIG_MACH_PIC32) += ddr/microchip/ endif diff --git a/drivers/tee/Kconfig b/drivers/tee/Kconfig new file mode 100644 index 000000000000..f3fc3c2ca790 --- /dev/null +++ b/drivers/tee/Kconfig @@ -0,0 +1,11 @@ +# Generic Trusted Execution Environment Configuration +config TEE + bool "Trusted Execution Environment support" + depends on ARM && (ARM64 || CPU_V7A) + select ARM_SMCCC + help + This implements a generic interface towards a Trusted Execution + Environment (TEE). A TEE is a trusted OS running in some secure + environment, for example, TrustZone on ARM cpus, or a separate + secure co-processor etc. See also: + https://en.wikipedia.org/wiki/Trusted_execution_environment diff --git a/drivers/tee/Makefile b/drivers/tee/Makefile new file mode 100644 index 000000000000..b6d8e16e6211 --- /dev/null +++ b/drivers/tee/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0+ + +obj-y += tee-uclass.o diff --git a/drivers/tee/tee-uclass.c b/drivers/tee/tee-uclass.c new file mode 100644 index 000000000000..1bee54ebf4af --- /dev/null +++ b/drivers/tee/tee-uclass.c @@ -0,0 +1,209 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2018 Linaro Limited + */ + +#include +#include +#include +#include +#include + +/** + * struct tee_uclass_priv - information of a TEE, stored by the uclass + * + * @list_shm: list of structe tee_shm representing memory blocks shared + * with the TEE. + */ +struct tee_uclass_priv { + struct list_head list_shm; +}; + +static const struct tee_driver_ops *tee_get_ops(struct udevice *dev) +{ + return device_get_ops(dev); +} + +void tee_get_version(struct udevice *dev, struct tee_version_data *vers) +{ + tee_get_ops(dev)->get_version(dev, vers); +} + +int tee_open_session(struct udevice *dev, struct tee_open_session_arg *arg, + uint num_param, struct tee_param *param) +{ + return tee_get_ops(dev)->open_session(dev, arg, num_param, param); +} + +int tee_close_session(struct udevice *dev, u32 session) +{ + return tee_get_ops(dev)->close_session(dev, session); +} + +int tee_invoke_func(struct udevice *dev, struct tee_invoke_arg *arg, + uint num_param, struct tee_param *param) +{ + return tee_get_ops(dev)->invoke_func(dev, arg, num_param, param); +} + +int __tee_shm_add(struct udevice *dev, ulong align, void *addr, ulong size, + u32 flags, struct tee_shm **shmp) +{ + struct tee_shm *shm; + void *p = addr; + int rc; + + if (flags & TEE_SHM_ALLOC) { + if (align) + p = memalign(align, size); + else + p = malloc(size); + } + if (!p) + return -ENOMEM; + + shm = calloc(1, sizeof(*shm)); + if (!shm) { + rc = -ENOMEM; + goto err; + } + + shm->dev = dev; + shm->addr = p; + shm->size = size; + shm->flags = flags; + + if (flags & TEE_SHM_SEC_REGISTER) { + rc = tee_get_ops(dev)->shm_register(dev, shm); + if (rc) + goto err; + } + + if (flags & TEE_SHM_REGISTER) { + struct tee_uclass_priv *priv = dev_get_uclass_priv(dev); + + list_add(&shm->link, &priv->list_shm); + } + + *shmp = shm; + + return 0; +err: + free(shm); + if (flags & TEE_SHM_ALLOC) + free(p); + + return rc; +} + +int tee_shm_alloc(struct udevice *dev, ulong size, u32 flags, + struct tee_shm **shmp) +{ + u32 f = flags; + + f |= TEE_SHM_SEC_REGISTER | TEE_SHM_REGISTER | TEE_SHM_ALLOC; + + return __tee_shm_add(dev, 0, NULL, size, f, shmp); +} + +int tee_shm_register(struct udevice *dev, void *addr, ulong size, u32 flags, + struct tee_shm **shmp) +{ + u32 f = flags & ~TEE_SHM_ALLOC; + + f |= TEE_SHM_SEC_REGISTER | TEE_SHM_REGISTER; + + return __tee_shm_add(dev, 0, addr, size, f, shmp); +} + +void tee_shm_free(struct tee_shm *shm) +{ + if (!shm) + return; + + if (shm->flags & TEE_SHM_SEC_REGISTER) + tee_get_ops(shm->dev)->shm_unregister(shm->dev, shm); + + if (shm->flags & TEE_SHM_REGISTER) + list_del(&shm->link); + + if (shm->flags & TEE_SHM_ALLOC) + free(shm->addr); + + free(shm); +} + +bool tee_shm_is_registered(struct tee_shm *shm, struct udevice *dev) +{ + struct tee_uclass_priv *priv = dev_get_uclass_priv(dev); + struct tee_shm *s; + + list_for_each_entry(s, &priv->list_shm, link) + if (s == shm) + return true; + + return false; +} + +struct udevice *tee_find_device(struct udevice *start, + int (*match)(struct tee_version_data *vers, + const void *data), + const void *data, + struct tee_version_data *vers) +{ + struct udevice *dev = start; + struct tee_version_data lv; + struct tee_version_data *v = vers ? vers : &lv; + + if (!dev) + uclass_find_first_device(UCLASS_TEE, &dev); + else + uclass_find_next_device(&dev); + + for (; dev; uclass_find_next_device(&dev)) { + if (device_probe(dev)) + continue; + tee_get_ops(dev)->get_version(dev, v); + if (!match || match(v, data)) + return dev; + } + + return NULL; +} + +static int tee_pre_probe(struct udevice *dev) +{ + struct tee_uclass_priv *priv = dev_get_uclass_priv(dev); + + INIT_LIST_HEAD(&priv->list_shm); + + return 0; +} + +static int tee_pre_remove(struct udevice *dev) +{ + struct tee_uclass_priv *priv = dev_get_uclass_priv(dev); + struct tee_shm *shm; + + /* + * Any remaining shared memory must be unregistered now as U-Boot + * is about to hand over to the next stage and that memory will be + * reused. + */ + while (!list_empty(&priv->list_shm)) { + shm = list_first_entry(&priv->list_shm, struct tee_shm, link); + debug("%s: freeing leftover shm %p (size %lu, flags %#x)\n", + __func__, (void *)shm, shm->size, shm->flags); + tee_shm_free(shm); + } + + return 0; +} + +UCLASS_DRIVER(tee) = { + .id = UCLASS_TEE, + .name = "tee", + .per_device_auto_alloc_size = sizeof(struct tee_uclass_priv), + .pre_probe = tee_pre_probe, + .pre_remove = tee_pre_remove, +}; diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index a39643ec5eef..955e0a915b87 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -81,6 +81,7 @@ enum uclass_id { UCLASS_SPI_GENERIC, /* Generic SPI flash target */ UCLASS_SYSCON, /* System configuration device */ UCLASS_SYSRESET, /* System reset device */ + UCLASS_TEE, /* Trusted Execution Environment device */ UCLASS_THERMAL, /* Thermal sensor */ UCLASS_TIMER, /* Timer device */ UCLASS_TPM, /* Trusted Platform Module TIS interface */ diff --git a/include/tee.h b/include/tee.h new file mode 100644 index 000000000000..b86dbec257b4 --- /dev/null +++ b/include/tee.h @@ -0,0 +1,336 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2018 Linaro Limited + */ + +#ifndef __TEE_H +#define __TEE_H + +#define TEE_UUID_LEN 16 + +#define TEE_GEN_CAP_GP BIT(0) /* GlobalPlatform compliant TEE */ +#define TEE_GEN_CAP_REG_MEM BIT(1) /* Supports registering shared memory */ + +#define TEE_SHM_REGISTER BIT(0) /* In list of shared memory */ +#define TEE_SHM_SEC_REGISTER BIT(1) /* TEE notified of this memory */ +#define TEE_SHM_ALLOC BIT(2) /* The memory is malloced() and must */ + /* be freed() */ + +#define TEE_PARAM_ATTR_TYPE_NONE 0 /* parameter not used */ +#define TEE_PARAM_ATTR_TYPE_VALUE_INPUT 1 +#define TEE_PARAM_ATTR_TYPE_VALUE_OUTPUT 2 +#define TEE_PARAM_ATTR_TYPE_VALUE_INOUT 3 /* input and output */ +#define TEE_PARAM_ATTR_TYPE_MEMREF_INPUT 5 +#define TEE_PARAM_ATTR_TYPE_MEMREF_OUTPUT 6 +#define TEE_PARAM_ATTR_TYPE_MEMREF_INOUT 7 /* input and output */ +#define TEE_PARAM_ATTR_TYPE_MASK 0xff +#define TEE_PARAM_ATTR_META 0x100 +#define TEE_PARAM_ATTR_MASK (TEE_PARAM_ATTR_TYPE_MASK | \ + TEE_PARAM_ATTR_META) + +/* + * Some Global Platform error codes which has a meaning if the + * TEE_GEN_CAP_GP bit is returned by the driver in + * struct tee_version_data::gen_caps + */ +#define TEE_SUCCESS 0x00000000 +#define TEE_ERROR_GENERIC 0xffff0000 +#define TEE_ERROR_BAD_PARAMETERS 0xffff0006 +#define TEE_ERROR_ITEM_NOT_FOUND 0xffff0008 +#define TEE_ERROR_NOT_IMPLEMENTED 0xffff0009 +#define TEE_ERROR_NOT_SUPPORTED 0xffff000a +#define TEE_ERROR_COMMUNICATION 0xffff000e +#define TEE_ERROR_SECURITY 0xffff000f +#define TEE_ERROR_OUT_OF_MEMORY 0xffff000c +#define TEE_ERROR_TARGET_DEAD 0xffff3024 + +#define TEE_ORIGIN_COMMS 0x00000002 +#define TEE_ORIGIN_TEE 0x00000003 +#define TEE_ORIGIN_TRUSTED_APP 0x00000004 + +struct udevice; +/** + * struct tee_shm - memory shared with the TEE + * @dev: The TEE device + * @link: List node in the list in struct struct tee_uclass_priv + * @addr: Pointer to the shared memory + * @size: Size of the the shared memory + * @flags: TEE_SHM_* above + */ +struct tee_shm { + struct udevice *dev; + struct list_head link; + void *addr; + ulong size; + u32 flags; +}; + +/** + * struct tee_param_memref - memory reference for a Trusted Application + * @shm_offs: Offset in bytes into the shared memory object @shm + * @size: Size in bytes of the memory reference + * @shm: Pointer to a shared memory object for the buffer + * + * Used as a part of struct tee_param, see that for more information. + */ +struct tee_param_memref { + ulong shm_offs; + ulong size; + struct tee_shm *shm; +}; + +/** + * struct tee_param_value - value parameter for a Trusted Application + * @a, @b, @c: Parameters passed by value + * + * Used as a part of struct tee_param, see that for more information. + */ +struct tee_param_value { + u64 a; + u64 b; + u64 c; +}; + +/** + * struct tee_param - invoke parameter for a Trusted Application + * @attr: Attributes + * @u.memref: Memref parameter if (@attr & TEE_PARAM_ATTR_MASK) is one of + * TEE_PARAM_ATTR_TYPE_MEMREF_* above + * @u.value: Value parameter if (@attr & TEE_PARAM_ATTR_MASK) is one of + * TEE_PARAM_ATTR_TYPE_VALUE_* above + * + * Parameters to TA are passed using an array of this struct, for + * flexibility both value parameters and memory refereces can be used. + */ +struct tee_param { + u64 attr; + union { + struct tee_param_memref memref; + struct tee_param_value value; + } u; +}; + +/** + * struct tee_open_session_arg - extra arguments for tee_open_session() + * @uuid: [in] UUID of the Trusted Application + * @clnt_uuid: [in] Normally zeroes + * @clnt_login: [in] Normally 0 + * @session: [out] Session id + * @ret: [out] return value + * @ret_origin: [out] origin of the return value + */ +struct tee_open_session_arg { + u8 uuid[TEE_UUID_LEN]; + u8 clnt_uuid[TEE_UUID_LEN]; + u32 clnt_login; + u32 session; + u32 ret; + u32 ret_origin; +}; + +/** + * struct tee_invoke_arg - extra arguments for tee_invoke_func() + * @func: [in] Trusted Application function, specific to the TA + * @session: [in] Session id, from open session + * @ret: [out] return value + * @ret_origin: [out] origin of the return value + */ +struct tee_invoke_arg { + u32 func; + u32 session; + u32 ret; + u32 ret_origin; +}; + +/** + * struct tee_version_data - description of TEE + * @gen_caps: Generic capabilities, TEE_GEN_CAP_* above + */ +struct tee_version_data { + u32 gen_caps; +}; + +/** + * struct tee_driver_ops - TEE driver operations + * @get_version: Query capabilities of TEE device, + * @open_session: Opens a session to a Trusted Application in the TEE, + * @close_session: Closes a session to Trusted Application, + * @invoke_func: Invokes a function in a Trusted Application, + * @shm_register: Registers memory shared with the TEE + * @shm_unregister: Unregisters memory shared with the TEE + */ +struct tee_driver_ops { + /** + * get_version() - Query capabilities of TEE device + * @dev: The TEE device + * @vers: Pointer to version data + */ + void (*get_version)(struct udevice *dev, struct tee_version_data *vers); + /** + * open_session() - Open a session to a Trusted Application + * @dev: The TEE device + * @arg: Open session arguments + * @num_param: Number of elements in @param + * @param: Parameters for Trusted Application + * + * Returns < 0 on error else see @arg->ret for result. If @arg->ret is + * TEE_SUCCESS the session identifier is available in @arg->session. + */ + int (*open_session)(struct udevice *dev, + struct tee_open_session_arg *arg, uint num_param, + struct tee_param *param); + /** + * close_session() - Close a session to a Trusted Application + * @dev: The TEE device + * @session: Session id + * + * Return < 0 on error else 0, regardless the session will not be valid + * after this function has returned. + */ + int (*close_session)(struct udevice *dev, u32 session); + /** + * tee_invoke_func() - Invoke a function in a Trusted Application + * @dev: The TEE device + * @arg: Invoke arguments + * @num_param: Number of elements in @param + * @param: Parameters for Trusted Application + * + * Returns < 0 on error else see @arg->ret for result. + */ + int (*invoke_func)(struct udevice *dev, struct tee_invoke_arg *arg, + uint num_param, struct tee_param *param); + /** + * shm_register() - Registers memory shared with the TEE + * @dev: The TEE device + * @shm: Pointer to a shared memory object + * Returns 0 on success or < 0 on failure. + */ + int (*shm_register)(struct udevice *dev, struct tee_shm *shm); + /** + * shm_unregister() - Unregisters memory shared with the TEE + * @dev: The TEE device + * @shm: Pointer to a shared memory object + * Returns 0 on success or < 0 on failure. + */ + int (*shm_unregister)(struct udevice *dev, struct tee_shm *shm); +}; + +/** + * __tee_shm_add() - Internal helper function to register shared memory + * @dev: The TEE device + * @align: Required alignment of allocated memory block if + * (@flags & TEE_SHM_ALLOC) + * @addr: Address of memory block, ignored if (@flags & TEE_SHM_ALLOC) + * @size: Size of memory block + * @flags: TEE_SHM_* above + * @shmp: If the function return 0, this holds the allocated + * struct tee_shm + * + * returns 0 on success or < 0 on failure. + */ +int __tee_shm_add(struct udevice *dev, ulong align, void *addr, ulong size, + u32 flags, struct tee_shm **shmp); + +/** + * tee_shm_alloc() - Allocate shared memory + * @dev: The TEE device + * @size: Size of memory block + * @flags: TEE_SHM_* above + * @shmp: If the function return 0, this holds the allocated + * struct tee_shm + * + * returns 0 on success or < 0 on failure. + */ +int tee_shm_alloc(struct udevice *dev, ulong size, u32 flags, + struct tee_shm **shmp); + +/** + * tee_shm_register() - Registers shared memory + * @dev: The TEE device + * @addr: Address of memory block + * @size: Size of memory block + * @flags: TEE_SHM_* above + * @shmp: If the function return 0, this holds the allocated + * struct tee_shm + * + * returns 0 on success or < 0 on failure. + */ +int tee_shm_register(struct udevice *dev, void *addr, ulong size, u32 flags, + struct tee_shm **shmp); + +/** + * tee_shm_free() - Frees shared memory + * @shm: Shared memory object + */ +void tee_shm_free(struct tee_shm *shm); + +/** + * tee_shm_is_registered() - Check register status of shared memory object + * @shm: Pointer to shared memory object + * @dev: The TEE device + * + * Returns true if the shared memory object is registered for the supplied + * TEE device + */ +bool tee_shm_is_registered(struct tee_shm *shm, struct udevice *dev); + +/** + * tee_find_device() - Look up a TEE device + * @start: if not NULL, continue search after this device + * @match: function to check TEE device, returns != 0 if the device + * matches + * @data: data for match function + * @vers: if not NULL, version data of TEE device of the device returned + * + * Returns a probed TEE device of the first TEE device matched by the + * match() callback or NULL. + */ +struct udevice *tee_find_device(struct udevice *start, + int (*match)(struct tee_version_data *vers, + const void *data), + const void *data, + struct tee_version_data *vers); + +/** + * tee_get_version() - Query capabilities of TEE device + * @dev: The TEE device + * @vers: Pointer to version data + */ +void tee_get_version(struct udevice *dev, struct tee_version_data *vers); + +/** + * tee_open_session() - Open a session to a Trusted Application + * @dev: The TEE device + * @arg: Open session arguments + * @num_param: Number of elements in @param + * @param: Parameters for Trusted Application + * + * Returns < 0 on error else see @arg->ret for result. If @arg->ret is + * TEE_SUCCESS the session identifier is available in @arg->session. + */ +int tee_open_session(struct udevice *dev, struct tee_open_session_arg *arg, + uint num_param, struct tee_param *param); + +/** + * tee_close_session() - Close a session to a Trusted Application + * @dev: The TEE device + * @session: Session id + * + * Return < 0 on error else 0, regardless the session will not be valid + * after this function has returned. + */ +int tee_close_session(struct udevice *dev, u32 session); + +/** + * tee_invoke_func() - Invoke a function in a Trusted Application + * @dev: The TEE device + * @arg: Invoke arguments + * @num_param: Number of elements in @param + * @param: Parameters for Trusted Application + * + * Returns < 0 on error else see @arg->ret for result. + */ +int tee_invoke_func(struct udevice *dev, struct tee_invoke_arg *arg, + uint num_param, struct tee_param *param); + +#endif /* __TEE_H */ From patchwork Mon Sep 3 14:46:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 145804 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp2575507ljw; Mon, 3 Sep 2018 07:47:29 -0700 (PDT) X-Received: by 2002:a2e:5719:: with SMTP id l25-v6mr17628504ljb.125.1535986049033; Mon, 03 Sep 2018 07:47:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535986049; cv=none; d=google.com; s=arc-20160816; b=onZqLspp5fSlUBSKlZh6iJMyrn8sKptpj7WGcS0UpaGe1HReSE/+WWf0/FPLTnjJRM eflb4/LBhGId+TPQ/nlDiKkShF/LWlsLwegpZ8njlR/Ucdsr5CHb49r3yjqIL73r4P91 2So4jWimlt5fR7XcA7nyi17FJ/MJaAjVoWA2/vE2CdAK0Om1TGBYmrIyp/Arlb8KGdB4 puqVwyF7ickWK4Yr3j4V5Mq8sjUJ1fy//yg9TOLcN7O2dC0Hx2hgAV1gb8Z1OSkgOuXo PNwAVMuAf6/IpGJQLdemONmZxgJEBuYXn9Bq9OVN4Ypdm4bTnCPqX1TH/FCC45uq3Tq2 xABw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=4IE86cb3LJqqnw69+nNkWX3MjSAstndpuaRV8lGh8zc=; b=E9C35QBlmaHPDw1Pv2AICA91WFxgHfaBSFpAYnzPY9Mvl1sRQxhCw0qxSBWomcrYWX Qdh6bXd9X/MrJMXOmN7oLXUGe7taJW+IyxBLfRJht7qRH9UsjV5SRU5tze+pWW788lza nDv7mOqYN9ItPSi0PUqz9Z42N5z7Ez5V/MjBH1KxB/dSxM75qv17w3AByfu13WDlkFbX ZTnuCauyUmkANugQfFASa7wDGNzJcaeYqwPTcbHL5s/7xa7G3GrtR7exyNBvWG/RC4yg kzI9TxA2YF609gGMJpCeLeIDAeN+SZCr6A+tS8Q1Cn0qnGFCkNTZeZKwgEgsFXoUUqHe e2Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=G4ktFGN0; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id d17-v6sor7846680lji.40.2018.09.03.07.47.28 for (Google Transport Security); Mon, 03 Sep 2018 07:47:29 -0700 (PDT) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=G4ktFGN0; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=4IE86cb3LJqqnw69+nNkWX3MjSAstndpuaRV8lGh8zc=; b=G4ktFGN0WIFDDb37+OD3bFvq/KEMaFYHWj3EPgcK/5SmvtZ/8QKBYw0siD7PCiOTS7 wzl9MmNYk7DI28uYI71WmMDm1zpKfgNaPEv+rtlgzg89MImrUCcyjdwKcnBVbpHoi7nW OBR13CRhIyqIM6DtoocxmMl3+6rVJ/1uKPPMw= 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=4IE86cb3LJqqnw69+nNkWX3MjSAstndpuaRV8lGh8zc=; b=e6UIk80hWWznbW/gJV7CrTdPpntqZ2ZHzYY8yVR+UPj5OCtS6BLAAIaQxS7zOyi/fY R++9CjwotVWllCtjoJ23RQbR0PDz9kVtYiXon/nt7/QApDV9xoX2k7CK+LsctdVgEFjJ hCy/kQCWb1BrodEcQfbSXfNtu6OzOQzteMZanzQJTWyaiPOeeVaGzxPsot9I4kbOL0MM BqWeXHX5DvJUXM6rJu0WvVdDxClLdtdkjrc6azhh8PsK0VgBlcNUvS25IaUxTeEUJjUg z1bMeysOsiq5QRpnBjGj0pe9GZ6mXUeZfUZkcLRrVc8k5n/Q/ekUFVYkXT77GJF05mKC emYQ== X-Gm-Message-State: APzg51Dfl1WeCPn9PqJxSoalRTjxH3PupLmM1NSrMJiKRNvzs9Vo5aMr x7AUijTWl7MGKY9GHj7FwtyMkKSI X-Google-Smtp-Source: ANB0VdZnjhcbHtBG9zUChzzjTcAKFnqRfEQXoU/GW6lwSzxsZLzHlJOs3kNiWUBfSxTh3Rnn9qLjFg== X-Received: by 2002:a2e:2bd3:: with SMTP id r80-v6mr18626354ljr.57.1535986048785; Mon, 03 Sep 2018 07:47:28 -0700 (PDT) Return-Path: Received: from jax.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id w18-v6sm3343431ljd.73.2018.09.03.07.47.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Sep 2018 07:47:28 -0700 (PDT) From: Jens Wiklander To: u-boot@lists.denx.de Cc: Simon Glass , Igor Opaniuk , Tom Rini , Jaehoon Chung , Pierre Aubert , Albert Aribaud , Peter Griffin , Michal Simek , Jens Wiklander Subject: [PATCH v3 07/20] dt/bindings: add bindings for optee Date: Mon, 3 Sep 2018 16:46:58 +0200 Message-Id: <20180903144711.31585-8-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180903144711.31585-1-jens.wiklander@linaro.org> References: <20180903144711.31585-1-jens.wiklander@linaro.org> Sync with c8bfafb15944 ("dt/bindings: add bindings for optee") from Linux kernel. Introduces linaro prefix and adds bindings for ARM TrustZone based OP-TEE implementation. Signed-off-by: Jens Wiklander --- .../firmware/linaro,optee-tz.txt | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 doc/device-tree-bindings/firmware/linaro,optee-tz.txt -- 2.17.1 Reviewed-by: Simon Glass diff --git a/doc/device-tree-bindings/firmware/linaro,optee-tz.txt b/doc/device-tree-bindings/firmware/linaro,optee-tz.txt new file mode 100644 index 000000000000..d38834c67dff --- /dev/null +++ b/doc/device-tree-bindings/firmware/linaro,optee-tz.txt @@ -0,0 +1,31 @@ +OP-TEE Device Tree Bindings + +OP-TEE is a piece of software using hardware features to provide a Trusted +Execution Environment. The security can be provided with ARM TrustZone, but +also by virtualization or a separate chip. + +We're using "linaro" as the first part of the compatible property for +the reference implementation maintained by Linaro. + +* OP-TEE based on ARM TrustZone required properties: + +- compatible : should contain "linaro,optee-tz" + +- method : The method of calling the OP-TEE Trusted OS. Permitted + values are: + + "smc" : SMC #0, with the register assignments specified + in drivers/tee/optee/optee_smc.h + + "hvc" : HVC #0, with the register assignments specified + in drivers/tee/optee/optee_smc.h + + + +Example: + firmware { + optee { + compatible = "linaro,optee-tz"; + method = "smc"; + }; + }; From patchwork Mon Sep 3 14:46:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 145807 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp2575567ljw; Mon, 3 Sep 2018 07:47:31 -0700 (PDT) X-Received: by 2002:a2e:5b4a:: with SMTP id p71-v6mr17146675ljb.91.1535986051793; Mon, 03 Sep 2018 07:47:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535986051; cv=none; d=google.com; s=arc-20160816; b=xtRz5ACfmiztvcaKfFNhjuINOrzuk/B2EEa4uAeOnEcFs5hb9WZN/BmqneDR9niFZj S4/WNeza0CmNQoxsNbnm01e6vYv8gBSfy+/qpm8SD5Y3TQAkrsfGgkIVdE4Kwj3HMklQ m411xT+drbnIyzrpgvZu02QHKyTYMDKZVnC1bmySwDZrPxjVtCKvzSqyWeElhbiSaF6L +iag66MU8BbpTjRIRqv8UGGJwbRBkOHBz5zVlX+8/SVw8C0MocecN7HV5Obb+gptJHt0 deuMkdV4MZW4SZ+haAjHTzgyGkUnfHFtDf/20jOFfG6ILyr7yYq7W0R4WikLOVYPzBQO bwIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=+aYzxaNc54A+WKMiR6L76LXtg5y45W7MAT73Y1x0rR8=; b=dlkYjM0fywQUnlqd+9DxfUU6AUpOSGGP9xZL4FGFSicPq2AAg5w4jaevaUyIEgz/0l 12/DkRP2oFeFwCCt16fNJBunRBtNXg8/rDbReAwte9wQrnW3AYtRD1fAbRqfNlI4MGxN f/MbNurPkGbtOJuQ/dREuw9zgEMvrC3Wjrfz/zpUoOSHKsamNwmJ9VJRoV+EUVUecFX2 R7vdiVIYoz3rJ4R/lrBlq3j//kI0vE5Uxsm3rJhLXym+HRIGBxsMGUq6Jig94ftcQLbg DGW9GeepXbOidexeVj/LFNVNOHg2nmykZQZUjXmz8QMJFXG/2t25pyS3NuDWClBwbec+ 3kuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RDaOlw3J; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id o131-v6sor5026080lfo.68.2018.09.03.07.47.31 for (Google Transport Security); Mon, 03 Sep 2018 07:47:31 -0700 (PDT) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RDaOlw3J; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=+aYzxaNc54A+WKMiR6L76LXtg5y45W7MAT73Y1x0rR8=; b=RDaOlw3JQfDmIDf+QPws0kFfLGA2U827K0ElnxD8ykjTOT/HSFO53OA62CmVJEE4Vw KeqL31T0Rocm+SI3eldhj3tzE1+AjIykdYYO/HRZCBvNrmLW8Eem7tOXSvjI8WJJ8Gmz 1VYusU02PrblD9bdVl/uJZ3tRBEh+IYKmnuB0= 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=+aYzxaNc54A+WKMiR6L76LXtg5y45W7MAT73Y1x0rR8=; b=gqnkXzfksF1XKccu/hEHlgvHI6Uo865cU8qN8jxDxVuHQwHpqP2cTJBEmrEPzArUp2 rQLLzMlhujtJq9Dq4qgsNrZFeLOW7H/E1iMxf93ZApYTKbSuIh9TGZh9THfshUKSjHSO NfU2x5+DcHInQamo5Qv7MsVX3/emClercM8S0JxrIPJHpI6AFAsyMh3GLHl8ScYBsuu4 MgPalLLnUHKfT/EwZVGbtDPHBJnSqigOmhIi2tfRrofMAVqwOxcef4bNVgFPr2qTSQJq sKCVqS0CzwTgXxR+WdeyV338Bpgu42n6Z2dTiV+LtNUf8KCNDKuh9azcqL4Ykkrnrwxr rJZg== X-Gm-Message-State: APzg51DdrtWd6VNPeOw/vdD64zKzGhKs2p/unj08ZHmsiLbucbH23H0g XQX9Ue8diXaGxRMYQ8qsmMVXH/c1 X-Google-Smtp-Source: ANB0VdbZc0xl1I7R6KUWkajEFlz445TDfEoYFGhxh2HKycHA9yxUJovXyWZRBl84qbxIMPUxaIxoSw== X-Received: by 2002:a19:290c:: with SMTP id p12-v6mr17636534lfp.124.1535986050605; Mon, 03 Sep 2018 07:47:30 -0700 (PDT) Return-Path: Received: from jax.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id w18-v6sm3343431ljd.73.2018.09.03.07.47.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Sep 2018 07:47:29 -0700 (PDT) From: Jens Wiklander To: u-boot@lists.denx.de Cc: Simon Glass , Igor Opaniuk , Tom Rini , Jaehoon Chung , Pierre Aubert , Albert Aribaud , Peter Griffin , Michal Simek , Jens Wiklander Subject: [PATCH v3 08/20] tee: add OP-TEE driver Date: Mon, 3 Sep 2018 16:46:59 +0200 Message-Id: <20180903144711.31585-9-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180903144711.31585-1-jens.wiklander@linaro.org> References: <20180903144711.31585-1-jens.wiklander@linaro.org> Adds a OP-TEE driver. * Targets ARM and ARM64 * Supports using any U-Boot memory as shared memory * Probes OP-TEE version using SMCs * Uses OPTEE message protocol version 2 to communicate with secure world Reviewed-by: Simon Glass Tested-by: Igor Opaniuk Signed-off-by: Jens Wiklander --- drivers/tee/Kconfig | 10 + drivers/tee/Makefile | 1 + drivers/tee/optee/Kconfig | 11 + drivers/tee/optee/Makefile | 4 + drivers/tee/optee/core.c | 654 +++++++++++++++++++++++ drivers/tee/optee/optee_msg.h | 425 +++++++++++++++ drivers/tee/optee/optee_msg_supplicant.h | 240 +++++++++ drivers/tee/optee/optee_private.h | 12 + drivers/tee/optee/optee_smc.h | 450 ++++++++++++++++ drivers/tee/optee/supplicant.c | 93 ++++ 10 files changed, 1900 insertions(+) create mode 100644 drivers/tee/optee/Kconfig create mode 100644 drivers/tee/optee/Makefile create mode 100644 drivers/tee/optee/core.c create mode 100644 drivers/tee/optee/optee_msg.h create mode 100644 drivers/tee/optee/optee_msg_supplicant.h create mode 100644 drivers/tee/optee/optee_private.h create mode 100644 drivers/tee/optee/optee_smc.h create mode 100644 drivers/tee/optee/supplicant.c -- 2.17.1 diff --git a/drivers/tee/Kconfig b/drivers/tee/Kconfig index f3fc3c2ca790..835c256e9239 100644 --- a/drivers/tee/Kconfig +++ b/drivers/tee/Kconfig @@ -9,3 +9,13 @@ config TEE environment, for example, TrustZone on ARM cpus, or a separate secure co-processor etc. See also: https://en.wikipedia.org/wiki/Trusted_execution_environment + +if TEE + +menu "TEE drivers" + +source "drivers/tee/optee/Kconfig" + +endmenu + +endif diff --git a/drivers/tee/Makefile b/drivers/tee/Makefile index b6d8e16e6211..19633b60f235 100644 --- a/drivers/tee/Makefile +++ b/drivers/tee/Makefile @@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0+ obj-y += tee-uclass.o +obj-$(CONFIG_OPTEE) += optee/ diff --git a/drivers/tee/optee/Kconfig b/drivers/tee/optee/Kconfig new file mode 100644 index 000000000000..7484e6fea114 --- /dev/null +++ b/drivers/tee/optee/Kconfig @@ -0,0 +1,11 @@ +# OP-TEE Trusted Execution Environment Configuration +config OPTEE + bool "OP-TEE" + depends on ARM_SMCCC + help + This implements the OP-TEE Trusted Execution Environment (TEE) + driver. OP-TEE is a Trusted OS designed primarily to rely on the + ARM TrustZone(R) technology as the underlying hardware isolation + mechanism. This driver can request services from OP-TEE, but also + handle Remote Procedure Calls (RPC) from OP-TEE needed to + execute a service. For more information see: https://www.op-tee.org diff --git a/drivers/tee/optee/Makefile b/drivers/tee/optee/Makefile new file mode 100644 index 000000000000..6148feb474a5 --- /dev/null +++ b/drivers/tee/optee/Makefile @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0+ + +obj-y += core.o +obj-y += supplicant.o diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c new file mode 100644 index 000000000000..726382da9bb8 --- /dev/null +++ b/drivers/tee/optee/core.c @@ -0,0 +1,654 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2018 Linaro Limited + */ + +#include +#include +#include +#include +#include +#include + +#include "optee_smc.h" +#include "optee_msg.h" +#include "optee_private.h" + +#define PAGELIST_ENTRIES_PER_PAGE \ + ((OPTEE_MSG_NONCONTIG_PAGE_SIZE / sizeof(u64)) - 1) + +typedef void (optee_invoke_fn)(unsigned long, unsigned long, unsigned long, + unsigned long, unsigned long, unsigned long, + unsigned long, unsigned long, + struct arm_smccc_res *); + +struct optee_pdata { + optee_invoke_fn *invoke_fn; +}; + +struct rpc_param { + u32 a0; + u32 a1; + u32 a2; + u32 a3; + u32 a4; + u32 a5; + u32 a6; + u32 a7; +}; + +/** + * reg_pair_to_ptr() - Make a pointer of 2 32-bit values + * @reg0: High bits of the pointer + * @reg1: Low bits of the pointer + * + * Returns the combined result, note that if a pointer is 32-bit wide @reg0 + * will be discarded. + */ +static void *reg_pair_to_ptr(u32 reg0, u32 reg1) +{ + return (void *)(ulong)(((u64)reg0 << 32) | reg1); +} + +/** + * reg_pair_from_64() - Split a 64-bit value into two 32-bit values + * @reg0: High bits of @val + * @reg1: Low bits of @val + * @val: The value to split + */ +static void reg_pair_from_64(u32 *reg0, u32 *reg1, u64 val) +{ + *reg0 = val >> 32; + *reg1 = val; +} + +/** + * optee_alloc_and_init_page_list() - Provide page list of memory buffer + * @buf: Start of buffer + * @len: Length of buffer + * @phys_buf_ptr Physical pointer with coded offset to page list + * + * Secure world doesn't share mapping with Normal world (U-Boot in this case) + * so physical pointers are needed when sharing pointers. + * + * Returns a pointer page list on success or NULL on failure + */ +void *optee_alloc_and_init_page_list(void *buf, ulong len, u64 *phys_buf_ptr) +{ + const unsigned int page_size = OPTEE_MSG_NONCONTIG_PAGE_SIZE; + const phys_addr_t page_mask = page_size - 1; + u8 *buf_base; + unsigned int page_offset; + unsigned int num_pages; + unsigned int list_size; + unsigned int n; + void *page_list; + struct { + u64 pages_list[PAGELIST_ENTRIES_PER_PAGE]; + u64 next_page_data; + } *pages_data; + + /* + * A Memory buffer is described in chunks of 4k. The list of + * physical addresses has to be represented by a physical pointer + * too and a single list has to start at a 4k page and fit into + * that page. In order to be able to describe large memory buffers + * these 4k pages carrying physical addresses are linked together + * in a list. See OPTEE_MSG_ATTR_NONCONTIG in + * drivers/tee/optee/optee_msg.h for more information. + */ + + page_offset = (ulong)buf & page_mask; + num_pages = roundup(page_offset + len, page_size) / page_size; + list_size = DIV_ROUND_UP(num_pages, PAGELIST_ENTRIES_PER_PAGE) * + page_size; + page_list = memalign(page_size, list_size); + if (!page_list) + return NULL; + + pages_data = page_list; + buf_base = (u8 *)rounddown((ulong)buf, page_size); + n = 0; + while (num_pages) { + pages_data->pages_list[n] = virt_to_phys(buf_base); + n++; + buf_base += page_size; + num_pages--; + + if (n == PAGELIST_ENTRIES_PER_PAGE) { + pages_data->next_page_data = + virt_to_phys(pages_data + 1); + pages_data++; + n = 0; + } + } + + *phys_buf_ptr = virt_to_phys(page_list) | page_offset; + return page_list; +} + +static void optee_get_version(struct udevice *dev, + struct tee_version_data *vers) +{ + struct tee_version_data v = { + .gen_caps = TEE_GEN_CAP_GP | TEE_GEN_CAP_REG_MEM, + }; + + *vers = v; +} + +static int get_msg_arg(struct udevice *dev, uint num_params, + struct tee_shm **shmp, struct optee_msg_arg **msg_arg) +{ + int rc; + struct optee_msg_arg *ma; + + rc = __tee_shm_add(dev, OPTEE_MSG_NONCONTIG_PAGE_SIZE, NULL, + OPTEE_MSG_GET_ARG_SIZE(num_params), TEE_SHM_ALLOC, + shmp); + if (rc) + return rc; + + ma = (*shmp)->addr; + memset(ma, 0, OPTEE_MSG_GET_ARG_SIZE(num_params)); + ma->num_params = num_params; + *msg_arg = ma; + + return 0; +} + +static int to_msg_param(struct optee_msg_param *msg_params, uint num_params, + const struct tee_param *params) +{ + uint n; + + for (n = 0; n < num_params; n++) { + const struct tee_param *p = params + n; + struct optee_msg_param *mp = msg_params + n; + + switch (p->attr) { + case TEE_PARAM_ATTR_TYPE_NONE: + mp->attr = OPTEE_MSG_ATTR_TYPE_NONE; + memset(&mp->u, 0, sizeof(mp->u)); + break; + case TEE_PARAM_ATTR_TYPE_VALUE_INPUT: + case TEE_PARAM_ATTR_TYPE_VALUE_OUTPUT: + case TEE_PARAM_ATTR_TYPE_VALUE_INOUT: + mp->attr = OPTEE_MSG_ATTR_TYPE_VALUE_INPUT + p->attr - + TEE_PARAM_ATTR_TYPE_VALUE_INPUT; + mp->u.value.a = p->u.value.a; + mp->u.value.b = p->u.value.b; + mp->u.value.c = p->u.value.c; + break; + case TEE_PARAM_ATTR_TYPE_MEMREF_INPUT: + case TEE_PARAM_ATTR_TYPE_MEMREF_OUTPUT: + case TEE_PARAM_ATTR_TYPE_MEMREF_INOUT: + mp->attr = OPTEE_MSG_ATTR_TYPE_RMEM_INPUT + p->attr - + TEE_PARAM_ATTR_TYPE_MEMREF_INPUT; + mp->u.rmem.shm_ref = (ulong)p->u.memref.shm; + mp->u.rmem.size = p->u.memref.size; + mp->u.rmem.offs = p->u.memref.shm_offs; + break; + default: + return -EINVAL; + } + } + return 0; +} + +static int from_msg_param(struct tee_param *params, uint num_params, + const struct optee_msg_param *msg_params) +{ + uint n; + struct tee_shm *shm; + + for (n = 0; n < num_params; n++) { + struct tee_param *p = params + n; + const struct optee_msg_param *mp = msg_params + n; + u32 attr = mp->attr & OPTEE_MSG_ATTR_TYPE_MASK; + + switch (attr) { + case OPTEE_MSG_ATTR_TYPE_NONE: + p->attr = TEE_PARAM_ATTR_TYPE_NONE; + memset(&p->u, 0, sizeof(p->u)); + break; + case OPTEE_MSG_ATTR_TYPE_VALUE_INPUT: + case OPTEE_MSG_ATTR_TYPE_VALUE_OUTPUT: + case OPTEE_MSG_ATTR_TYPE_VALUE_INOUT: + p->attr = TEE_PARAM_ATTR_TYPE_VALUE_INPUT + attr - + OPTEE_MSG_ATTR_TYPE_VALUE_INPUT; + p->u.value.a = mp->u.value.a; + p->u.value.b = mp->u.value.b; + p->u.value.c = mp->u.value.c; + break; + case OPTEE_MSG_ATTR_TYPE_RMEM_INPUT: + case OPTEE_MSG_ATTR_TYPE_RMEM_OUTPUT: + case OPTEE_MSG_ATTR_TYPE_RMEM_INOUT: + p->attr = TEE_PARAM_ATTR_TYPE_MEMREF_INPUT + attr - + OPTEE_MSG_ATTR_TYPE_RMEM_INPUT; + p->u.memref.size = mp->u.rmem.size; + shm = (struct tee_shm *)(ulong)mp->u.rmem.shm_ref; + + if (!shm) { + p->u.memref.shm_offs = 0; + p->u.memref.shm = NULL; + break; + } + p->u.memref.shm_offs = mp->u.rmem.offs; + p->u.memref.shm = shm; + break; + default: + return -EINVAL; + } + } + return 0; +} + +static void handle_rpc(struct udevice *dev, struct rpc_param *param, + void *page_list) +{ + struct tee_shm *shm; + + switch (OPTEE_SMC_RETURN_GET_RPC_FUNC(param->a0)) { + case OPTEE_SMC_RPC_FUNC_ALLOC: + if (!__tee_shm_add(dev, OPTEE_MSG_NONCONTIG_PAGE_SIZE, NULL, + param->a1, TEE_SHM_ALLOC | TEE_SHM_REGISTER, + &shm)) { + reg_pair_from_64(¶m->a1, ¶m->a2, + virt_to_phys(shm->addr)); + /* "cookie" */ + reg_pair_from_64(¶m->a4, ¶m->a5, (ulong)shm); + } else { + param->a1 = 0; + param->a2 = 0; + param->a4 = 0; + param->a5 = 0; + } + break; + case OPTEE_SMC_RPC_FUNC_FREE: + shm = reg_pair_to_ptr(param->a1, param->a2); + tee_shm_free(shm); + break; + case OPTEE_SMC_RPC_FUNC_FOREIGN_INTR: + break; + case OPTEE_SMC_RPC_FUNC_CMD: + shm = reg_pair_to_ptr(param->a1, param->a2); + optee_suppl_cmd(dev, shm, page_list); + break; + default: + break; + } + + param->a0 = OPTEE_SMC_CALL_RETURN_FROM_RPC; +} + +static u32 call_err_to_res(u32 call_err) +{ + switch (call_err) { + case OPTEE_SMC_RETURN_OK: + return TEE_SUCCESS; + default: + return TEE_ERROR_BAD_PARAMETERS; + } +} + +static u32 do_call_with_arg(struct udevice *dev, struct optee_msg_arg *arg) +{ + struct optee_pdata *pdata = dev_get_platdata(dev); + struct rpc_param param = { .a0 = OPTEE_SMC_CALL_WITH_ARG }; + void *page_list = NULL; + + reg_pair_from_64(¶m.a1, ¶m.a2, virt_to_phys(arg)); + while (true) { + struct arm_smccc_res res; + + pdata->invoke_fn(param.a0, param.a1, param.a2, param.a3, + param.a4, param.a5, param.a6, param.a7, &res); + + free(page_list); + page_list = NULL; + + if (OPTEE_SMC_RETURN_IS_RPC(res.a0)) { + param.a0 = res.a0; + param.a1 = res.a1; + param.a2 = res.a2; + param.a3 = res.a3; + handle_rpc(dev, ¶m, &page_list); + } else { + return call_err_to_res(res.a0); + } + } +} + +static int optee_close_session(struct udevice *dev, u32 session) +{ + int rc; + struct tee_shm *shm; + struct optee_msg_arg *msg_arg; + + rc = get_msg_arg(dev, 0, &shm, &msg_arg); + if (rc) + return rc; + + msg_arg->cmd = OPTEE_MSG_CMD_CLOSE_SESSION; + msg_arg->session = session; + do_call_with_arg(dev, msg_arg); + + tee_shm_free(shm); + + return 0; +} + +static int optee_open_session(struct udevice *dev, + struct tee_open_session_arg *arg, + uint num_params, struct tee_param *params) +{ + int rc; + struct tee_shm *shm; + struct optee_msg_arg *msg_arg; + + rc = get_msg_arg(dev, num_params + 2, &shm, &msg_arg); + if (rc) + return rc; + + msg_arg->cmd = OPTEE_MSG_CMD_OPEN_SESSION; + /* + * Initialize and add the meta parameters needed when opening a + * session. + */ + msg_arg->params[0].attr = OPTEE_MSG_ATTR_TYPE_VALUE_INPUT | + OPTEE_MSG_ATTR_META; + msg_arg->params[1].attr = OPTEE_MSG_ATTR_TYPE_VALUE_INPUT | + OPTEE_MSG_ATTR_META; + memcpy(&msg_arg->params[0].u.value, arg->uuid, sizeof(arg->uuid)); + memcpy(&msg_arg->params[1].u.value, arg->uuid, sizeof(arg->clnt_uuid)); + msg_arg->params[1].u.value.c = arg->clnt_login; + + rc = to_msg_param(msg_arg->params + 2, num_params, params); + if (rc) + goto out; + + arg->ret = do_call_with_arg(dev, msg_arg); + if (arg->ret) { + arg->ret_origin = TEE_ORIGIN_COMMS; + goto out; + } + + if (from_msg_param(params, num_params, msg_arg->params + 2)) { + arg->ret = TEE_ERROR_COMMUNICATION; + arg->ret_origin = TEE_ORIGIN_COMMS; + /* Close session again to avoid leakage */ + optee_close_session(dev, msg_arg->session); + goto out; + } + + arg->session = msg_arg->session; + arg->ret = msg_arg->ret; + arg->ret_origin = msg_arg->ret_origin; +out: + tee_shm_free(shm); + + return rc; +} + +static int optee_invoke_func(struct udevice *dev, struct tee_invoke_arg *arg, + uint num_params, struct tee_param *params) +{ + struct tee_shm *shm; + struct optee_msg_arg *msg_arg; + int rc; + + rc = get_msg_arg(dev, num_params, &shm, &msg_arg); + if (rc) + return rc; + msg_arg->cmd = OPTEE_MSG_CMD_INVOKE_COMMAND; + msg_arg->func = arg->func; + msg_arg->session = arg->session; + + rc = to_msg_param(msg_arg->params, num_params, params); + if (rc) + goto out; + + arg->ret = do_call_with_arg(dev, msg_arg); + if (arg->ret) { + arg->ret_origin = TEE_ORIGIN_COMMS; + goto out; + } + + if (from_msg_param(params, num_params, msg_arg->params)) { + arg->ret = TEE_ERROR_COMMUNICATION; + arg->ret_origin = TEE_ORIGIN_COMMS; + goto out; + } + + arg->ret = msg_arg->ret; + arg->ret_origin = msg_arg->ret_origin; +out: + tee_shm_free(shm); + return rc; +} + +static int optee_shm_register(struct udevice *dev, struct tee_shm *shm) +{ + struct tee_shm *shm_arg; + struct optee_msg_arg *msg_arg; + void *pl; + u64 ph_ptr; + int rc; + + rc = get_msg_arg(dev, 1, &shm_arg, &msg_arg); + if (rc) + return rc; + + pl = optee_alloc_and_init_page_list(shm->addr, shm->size, &ph_ptr); + if (!pl) { + rc = -ENOMEM; + goto out; + } + + msg_arg->cmd = OPTEE_MSG_CMD_REGISTER_SHM; + msg_arg->params->attr = OPTEE_MSG_ATTR_TYPE_TMEM_OUTPUT | + OPTEE_MSG_ATTR_NONCONTIG; + msg_arg->params->u.tmem.buf_ptr = ph_ptr; + msg_arg->params->u.tmem.shm_ref = (ulong)shm; + msg_arg->params->u.tmem.size = shm->size; + + if (do_call_with_arg(dev, msg_arg) || msg_arg->ret) + rc = -EINVAL; + + free(pl); +out: + tee_shm_free(shm_arg); + + return rc; +} + +static int optee_shm_unregister(struct udevice *dev, struct tee_shm *shm) +{ + struct tee_shm *shm_arg; + struct optee_msg_arg *msg_arg; + int rc; + + rc = get_msg_arg(dev, 1, &shm_arg, &msg_arg); + if (rc) + return rc; + + msg_arg->cmd = OPTEE_MSG_CMD_UNREGISTER_SHM; + msg_arg->params[0].attr = OPTEE_MSG_ATTR_TYPE_RMEM_INPUT; + msg_arg->params[0].u.rmem.shm_ref = (ulong)shm; + + if (do_call_with_arg(dev, msg_arg) || msg_arg->ret) + rc = -EINVAL; + tee_shm_free(shm_arg); + + return rc; +} + +static const struct tee_driver_ops optee_ops = { + .get_version = optee_get_version, + .open_session = optee_open_session, + .close_session = optee_close_session, + .invoke_func = optee_invoke_func, + .shm_register = optee_shm_register, + .shm_unregister = optee_shm_unregister, +}; + +static bool is_optee_api(optee_invoke_fn *invoke_fn) +{ + struct arm_smccc_res res; + + invoke_fn(OPTEE_SMC_CALLS_UID, 0, 0, 0, 0, 0, 0, 0, &res); + + return res.a0 == OPTEE_MSG_UID_0 && res.a1 == OPTEE_MSG_UID_1 && + res.a2 == OPTEE_MSG_UID_2 && res.a3 == OPTEE_MSG_UID_3; +} + +static void print_os_revision(optee_invoke_fn *invoke_fn) +{ + union { + struct arm_smccc_res smccc; + struct optee_smc_call_get_os_revision_result result; + } res = { + .result = { + .build_id = 0 + } + }; + + invoke_fn(OPTEE_SMC_CALL_GET_OS_REVISION, 0, 0, 0, 0, 0, 0, 0, + &res.smccc); + + if (res.result.build_id) + debug("OP-TEE revision %lu.%lu (%08lx)\n", res.result.major, + res.result.minor, res.result.build_id); + else + debug("OP-TEE revision %lu.%lu\n", res.result.major, + res.result.minor); +} + +static bool api_revision_is_compatible(optee_invoke_fn *invoke_fn) +{ + union { + struct arm_smccc_res smccc; + struct optee_smc_calls_revision_result result; + } res; + + invoke_fn(OPTEE_SMC_CALLS_REVISION, 0, 0, 0, 0, 0, 0, 0, &res.smccc); + + return res.result.major == OPTEE_MSG_REVISION_MAJOR && + (int)res.result.minor >= OPTEE_MSG_REVISION_MINOR; +} + +static bool exchange_capabilities(optee_invoke_fn *invoke_fn, u32 *sec_caps) +{ + union { + struct arm_smccc_res smccc; + struct optee_smc_exchange_capabilities_result result; + } res; + + invoke_fn(OPTEE_SMC_EXCHANGE_CAPABILITIES, + OPTEE_SMC_NSEC_CAP_UNIPROCESSOR, 0, 0, 0, 0, 0, 0, + &res.smccc); + + if (res.result.status != OPTEE_SMC_RETURN_OK) + return false; + + *sec_caps = res.result.capabilities; + + return true; +} + +/* Simple wrapper functions to be able to use a function pointer */ +static void optee_smccc_smc(unsigned long a0, unsigned long a1, + unsigned long a2, unsigned long a3, + unsigned long a4, unsigned long a5, + unsigned long a6, unsigned long a7, + struct arm_smccc_res *res) +{ + arm_smccc_smc(a0, a1, a2, a3, a4, a5, a6, a7, res); +} + +static void optee_smccc_hvc(unsigned long a0, unsigned long a1, + unsigned long a2, unsigned long a3, + unsigned long a4, unsigned long a5, + unsigned long a6, unsigned long a7, + struct arm_smccc_res *res) +{ + arm_smccc_hvc(a0, a1, a2, a3, a4, a5, a6, a7, res); +} + +static optee_invoke_fn *get_invoke_func(struct udevice *dev) +{ + const char *method; + + debug("optee: looking for conduit method in DT.\n"); + method = ofnode_get_property(dev->node, "method", NULL); + if (!method) { + debug("optee: missing \"method\" property\n"); + return ERR_PTR(-ENXIO); + } + + if (!strcmp("hvc", method)) + return optee_smccc_hvc; + else if (!strcmp("smc", method)) + return optee_smccc_smc; + + debug("optee: invalid \"method\" property: %s\n", method); + return ERR_PTR(-EINVAL); +} + +static int optee_ofdata_to_platdata(struct udevice *dev) +{ + struct optee_pdata *pdata = dev_get_platdata(dev); + + pdata->invoke_fn = get_invoke_func(dev); + if (IS_ERR(pdata->invoke_fn)) + return PTR_ERR(pdata->invoke_fn); + + return 0; +} + +static int optee_probe(struct udevice *dev) +{ + struct optee_pdata *pdata = dev_get_platdata(dev); + u32 sec_caps; + + if (!is_optee_api(pdata->invoke_fn)) { + debug("%s: OP-TEE api uid mismatch\n", __func__); + return -ENOENT; + } + + print_os_revision(pdata->invoke_fn); + + if (!api_revision_is_compatible(pdata->invoke_fn)) { + debug("%s: OP-TEE api revision mismatch\n", __func__); + return -ENOENT; + } + + /* + * OP-TEE can use both shared memory via predefined pool or as + * dynamic shared memory provided by normal world. To keep things + * simple we're only using dynamic shared memory in this driver. + */ + if (!exchange_capabilities(pdata->invoke_fn, &sec_caps) || + !(sec_caps & OPTEE_SMC_SEC_CAP_DYNAMIC_SHM)) { + debug("%s: OP-TEE capabilities mismatch\n", __func__); + return -ENOENT; + } + + return 0; +} + +static const struct udevice_id optee_match[] = { + { .compatible = "linaro,optee-tz" }, + {}, +}; + +U_BOOT_DRIVER(optee) = { + .name = "optee", + .id = UCLASS_TEE, + .of_match = optee_match, + .ofdata_to_platdata = optee_ofdata_to_platdata, + .probe = optee_probe, + .ops = &optee_ops, + .platdata_auto_alloc_size = sizeof(struct optee_pdata), +}; diff --git a/drivers/tee/optee/optee_msg.h b/drivers/tee/optee/optee_msg.h new file mode 100644 index 000000000000..24c60960fc47 --- /dev/null +++ b/drivers/tee/optee/optee_msg.h @@ -0,0 +1,425 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (c) 2015-2018, Linaro Limited + */ + +#ifndef _OPTEE_MSG_H +#define _OPTEE_MSG_H + +#include +#include + +/* + * This file defines the OP-TEE message protocol used to communicate with + * an instance of OP-TEE running in secure world. This file is based on + * https://github.com/OP-TEE/optee_os/blob/master/core/include/optee_msg.h + * and may need to be updated when introducing new features. + * + * This file is divided into three sections. + * 1. Formatting of messages. + * 2. Requests from normal world + * 3. Requests from secure world, Remote Procedure Call (RPC), handled by + * tee-supplicant. + */ + +/***************************************************************************** + * Part 1 - formatting of messages + *****************************************************************************/ + +#define OPTEE_MSG_ATTR_TYPE_NONE 0x0 +#define OPTEE_MSG_ATTR_TYPE_VALUE_INPUT 0x1 +#define OPTEE_MSG_ATTR_TYPE_VALUE_OUTPUT 0x2 +#define OPTEE_MSG_ATTR_TYPE_VALUE_INOUT 0x3 +#define OPTEE_MSG_ATTR_TYPE_RMEM_INPUT 0x5 +#define OPTEE_MSG_ATTR_TYPE_RMEM_OUTPUT 0x6 +#define OPTEE_MSG_ATTR_TYPE_RMEM_INOUT 0x7 +#define OPTEE_MSG_ATTR_TYPE_TMEM_INPUT 0x9 +#define OPTEE_MSG_ATTR_TYPE_TMEM_OUTPUT 0xa +#define OPTEE_MSG_ATTR_TYPE_TMEM_INOUT 0xb + +#define OPTEE_MSG_ATTR_TYPE_MASK GENMASK(7, 0) + +/* + * Meta parameter to be absorbed by the Secure OS and not passed + * to the Trusted Application. + * + * Currently only used with OPTEE_MSG_CMD_OPEN_SESSION. + */ +#define OPTEE_MSG_ATTR_META BIT(8) + +/* + * Pointer to a list of pages used to register user-defined SHM buffer. + * Used with OPTEE_MSG_ATTR_TYPE_TMEM_*. + * buf_ptr should point to the beginning of the buffer. Buffer will contain + * list of page addresses. OP-TEE core can reconstruct contiguous buffer from + * that page addresses list. Page addresses are stored as 64 bit values. + * Last entry on a page should point to the next page of buffer. + * Every entry in buffer should point to a 4k page beginning (12 least + * significant bits must be equal to zero). + * + * 12 least significant bints of optee_msg_param.u.tmem.buf_ptr should hold page + * offset of the user buffer. + * + * So, entries should be placed like members of this structure: + * + * struct page_data { + * uint64_t pages_array[OPTEE_MSG_NONCONTIG_PAGE_SIZE/sizeof(uint64_t) - 1]; + * uint64_t next_page_data; + * }; + * + * Structure is designed to exactly fit into the page size + * OPTEE_MSG_NONCONTIG_PAGE_SIZE which is a standard 4KB page. + * + * The size of 4KB is chosen because this is the smallest page size for ARM + * architectures. If REE uses larger pages, it should divide them to 4KB ones. + */ +#define OPTEE_MSG_ATTR_NONCONTIG BIT(9) + +/* + * Memory attributes for caching passed with temp memrefs. The actual value + * used is defined outside the message protocol with the exception of + * OPTEE_MSG_ATTR_CACHE_PREDEFINED which means the attributes already + * defined for the memory range should be used. If optee_smc.h is used as + * bearer of this protocol OPTEE_SMC_SHM_* is used for values. + */ +#define OPTEE_MSG_ATTR_CACHE_SHIFT 16 +#define OPTEE_MSG_ATTR_CACHE_MASK GENMASK(2, 0) +#define OPTEE_MSG_ATTR_CACHE_PREDEFINED 0 + +/* + * Same values as TEE_LOGIN_* from TEE Internal API + */ +#define OPTEE_MSG_LOGIN_PUBLIC 0x00000000 +#define OPTEE_MSG_LOGIN_USER 0x00000001 +#define OPTEE_MSG_LOGIN_GROUP 0x00000002 +#define OPTEE_MSG_LOGIN_APPLICATION 0x00000004 +#define OPTEE_MSG_LOGIN_APPLICATION_USER 0x00000005 +#define OPTEE_MSG_LOGIN_APPLICATION_GROUP 0x00000006 + +/* + * Page size used in non-contiguous buffer entries + */ +#define OPTEE_MSG_NONCONTIG_PAGE_SIZE 4096 + +/** + * struct optee_msg_param_tmem - temporary memory reference parameter + * @buf_ptr: Address of the buffer + * @size: Size of the buffer + * @shm_ref: Temporary shared memory reference, pointer to a struct tee_shm + * + * Secure and normal world communicates pointers as physical address + * instead of the virtual address. This is because secure and normal world + * have completely independent memory mapping. Normal world can even have a + * hypervisor which need to translate the guest physical address (AKA IPA + * in ARM documentation) to a real physical address before passing the + * structure to secure world. + */ +struct optee_msg_param_tmem { + u64 buf_ptr; + u64 size; + u64 shm_ref; +}; + +/** + * struct optee_msg_param_rmem - registered memory reference parameter + * @offs: Offset into shared memory reference + * @size: Size of the buffer + * @shm_ref: Shared memory reference, pointer to a struct tee_shm + */ +struct optee_msg_param_rmem { + u64 offs; + u64 size; + u64 shm_ref; +}; + +/** + * struct optee_msg_param_value - opaque value parameter + * + * Value parameters are passed unchecked between normal and secure world. + */ +struct optee_msg_param_value { + u64 a; + u64 b; + u64 c; +}; + +/** + * struct optee_msg_param - parameter used together with struct optee_msg_arg + * @attr: attributes + * @tmem: parameter by temporary memory reference + * @rmem: parameter by registered memory reference + * @value: parameter by opaque value + * + * @attr & OPTEE_MSG_ATTR_TYPE_MASK indicates if tmem, rmem or value is used in + * the union. OPTEE_MSG_ATTR_TYPE_VALUE_* indicates value, + * OPTEE_MSG_ATTR_TYPE_TMEM_* indicates @tmem and + * OPTEE_MSG_ATTR_TYPE_RMEM_* indicates @rmem, + * OPTEE_MSG_ATTR_TYPE_NONE indicates that none of the members are used. + */ +struct optee_msg_param { + u64 attr; + union { + struct optee_msg_param_tmem tmem; + struct optee_msg_param_rmem rmem; + struct optee_msg_param_value value; + } u; +}; + +/** + * struct optee_msg_arg - call argument + * @cmd: Command, one of OPTEE_MSG_CMD_* or OPTEE_MSG_RPC_CMD_* + * @func: Trusted Application function, specific to the Trusted Application, + * used if cmd == OPTEE_MSG_CMD_INVOKE_COMMAND + * @session: In parameter for all OPTEE_MSG_CMD_* except + * OPTEE_MSG_CMD_OPEN_SESSION where it's an output parameter instead + * @cancel_id: Cancellation id, a unique value to identify this request + * @ret: return value + * @ret_origin: origin of the return value + * @num_params: number of parameters supplied to the OS Command + * @params: the parameters supplied to the OS Command + * + * All normal calls to Trusted OS uses this struct. If cmd requires further + * information than what these field holds it can be passed as a parameter + * tagged as meta (setting the OPTEE_MSG_ATTR_META bit in corresponding + * attrs field). All parameters tagged as meta has to come first. + * + * Temp memref parameters can be fragmented if supported by the Trusted OS + * (when optee_smc.h is bearer of this protocol this is indicated with + * OPTEE_SMC_SEC_CAP_UNREGISTERED_SHM). If a logical memref parameter is + * fragmented then has all but the last fragment the + * OPTEE_MSG_ATTR_FRAGMENT bit set in attrs. Even if a memref is fragmented + * it will still be presented as a single logical memref to the Trusted + * Application. + */ +struct optee_msg_arg { + u32 cmd; + u32 func; + u32 session; + u32 cancel_id; + u32 pad; + u32 ret; + u32 ret_origin; + u32 num_params; + + /* num_params tells the actual number of element in params */ + struct optee_msg_param params[0]; +}; + +/** + * OPTEE_MSG_GET_ARG_SIZE - return size of struct optee_msg_arg + * + * @num_params: Number of parameters embedded in the struct optee_msg_arg + * + * Returns the size of the struct optee_msg_arg together with the number + * of embedded parameters. + */ +#define OPTEE_MSG_GET_ARG_SIZE(num_params) \ + (sizeof(struct optee_msg_arg) + \ + sizeof(struct optee_msg_param) * (num_params)) + +/***************************************************************************** + * Part 2 - requests from normal world + *****************************************************************************/ + +/* + * Return the following UID if using API specified in this file without + * further extensions: + * 384fb3e0-e7f8-11e3-af63-0002a5d5c51b. + * Represented in 4 32-bit words in OPTEE_MSG_UID_0, OPTEE_MSG_UID_1, + * OPTEE_MSG_UID_2, OPTEE_MSG_UID_3. + */ +#define OPTEE_MSG_UID_0 0x384fb3e0 +#define OPTEE_MSG_UID_1 0xe7f811e3 +#define OPTEE_MSG_UID_2 0xaf630002 +#define OPTEE_MSG_UID_3 0xa5d5c51b +#define OPTEE_MSG_FUNCID_CALLS_UID 0xFF01 + +/* + * Returns 2.0 if using API specified in this file without further + * extensions. Represented in 2 32-bit words in OPTEE_MSG_REVISION_MAJOR + * and OPTEE_MSG_REVISION_MINOR + */ +#define OPTEE_MSG_REVISION_MAJOR 2 +#define OPTEE_MSG_REVISION_MINOR 0 +#define OPTEE_MSG_FUNCID_CALLS_REVISION 0xFF03 + +/* + * Get UUID of Trusted OS. + * + * Used by non-secure world to figure out which Trusted OS is installed. + * Note that returned UUID is the UUID of the Trusted OS, not of the API. + * + * Returns UUID in 4 32-bit words in the same way as + * OPTEE_MSG_FUNCID_CALLS_UID described above. + */ +#define OPTEE_MSG_OS_OPTEE_UUID_0 0x486178e0 +#define OPTEE_MSG_OS_OPTEE_UUID_1 0xe7f811e3 +#define OPTEE_MSG_OS_OPTEE_UUID_2 0xbc5e0002 +#define OPTEE_MSG_OS_OPTEE_UUID_3 0xa5d5c51b +#define OPTEE_MSG_FUNCID_GET_OS_UUID 0x0000 + +/* + * Get revision of Trusted OS. + * + * Used by non-secure world to figure out which version of the Trusted OS + * is installed. Note that the returned revision is the revision of the + * Trusted OS, not of the API. + * + * Returns revision in 2 32-bit words in the same way as + * OPTEE_MSG_CALLS_REVISION described above. + */ +#define OPTEE_MSG_FUNCID_GET_OS_REVISION 0x0001 + +/* + * Do a secure call with struct optee_msg_arg as argument + * The OPTEE_MSG_CMD_* below defines what goes in struct optee_msg_arg::cmd + * + * OPTEE_MSG_CMD_OPEN_SESSION opens a session to a Trusted Application. + * The first two parameters are tagged as meta, holding two value + * parameters to pass the following information: + * param[0].u.value.a-b uuid of Trusted Application + * param[1].u.value.a-b uuid of Client + * param[1].u.value.c Login class of client OPTEE_MSG_LOGIN_* + * + * OPTEE_MSG_CMD_INVOKE_COMMAND invokes a command a previously opened + * session to a Trusted Application. struct optee_msg_arg::func is Trusted + * Application function, specific to the Trusted Application. + * + * OPTEE_MSG_CMD_CLOSE_SESSION closes a previously opened session to + * Trusted Application. + * + * OPTEE_MSG_CMD_CANCEL cancels a currently invoked command. + * + * OPTEE_MSG_CMD_REGISTER_SHM registers a shared memory reference. The + * information is passed as: + * [in] param[0].attr OPTEE_MSG_ATTR_TYPE_TMEM_INPUT + * [| OPTEE_MSG_ATTR_FRAGMENT] + * [in] param[0].u.tmem.buf_ptr physical address (of first fragment) + * [in] param[0].u.tmem.size size (of first fragment) + * [in] param[0].u.tmem.shm_ref holds shared memory reference + * ... + * The shared memory can optionally be fragmented, temp memrefs can follow + * each other with all but the last with the OPTEE_MSG_ATTR_FRAGMENT bit set. + * + * OPTEE_MSG_CMD_UNREGISTER_SHM unregisteres a previously registered shared + * memory reference. The information is passed as: + * [in] param[0].attr OPTEE_MSG_ATTR_TYPE_RMEM_INPUT + * [in] param[0].u.rmem.shm_ref holds shared memory reference + * [in] param[0].u.rmem.offs 0 + * [in] param[0].u.rmem.size 0 + */ +#define OPTEE_MSG_CMD_OPEN_SESSION 0 +#define OPTEE_MSG_CMD_INVOKE_COMMAND 1 +#define OPTEE_MSG_CMD_CLOSE_SESSION 2 +#define OPTEE_MSG_CMD_CANCEL 3 +#define OPTEE_MSG_CMD_REGISTER_SHM 4 +#define OPTEE_MSG_CMD_UNREGISTER_SHM 5 +#define OPTEE_MSG_FUNCID_CALL_WITH_ARG 0x0004 + +/***************************************************************************** + * Part 3 - Requests from secure world, RPC + *****************************************************************************/ + +/* + * All RPC is done with a struct optee_msg_arg as bearer of information, + * struct optee_msg_arg::arg holds values defined by OPTEE_MSG_RPC_CMD_* below + * + * RPC communication with tee-supplicant is reversed compared to normal + * client communication desribed above. The supplicant receives requests + * and sends responses. + */ + +/* + * Load a TA into memory, defined in tee-supplicant + */ +#define OPTEE_MSG_RPC_CMD_LOAD_TA 0 + +/* + * Reserved + */ +#define OPTEE_MSG_RPC_CMD_RPMB 1 + +/* + * File system access, defined in tee-supplicant + */ +#define OPTEE_MSG_RPC_CMD_FS 2 + +/* + * Get time + * + * Returns number of seconds and nano seconds since the Epoch, + * 1970-01-01 00:00:00 +0000 (UTC). + * + * [out] param[0].u.value.a Number of seconds + * [out] param[0].u.value.b Number of nano seconds. + */ +#define OPTEE_MSG_RPC_CMD_GET_TIME 3 + +/* + * Wait queue primitive, helper for secure world to implement a wait queue. + * + * If secure world need to wait for a secure world mutex it issues a sleep + * request instead of spinning in secure world. Conversely is a wakeup + * request issued when a secure world mutex with a thread waiting thread is + * unlocked. + * + * Waiting on a key + * [in] param[0].u.value.a OPTEE_MSG_RPC_WAIT_QUEUE_SLEEP + * [in] param[0].u.value.b wait key + * + * Waking up a key + * [in] param[0].u.value.a OPTEE_MSG_RPC_WAIT_QUEUE_WAKEUP + * [in] param[0].u.value.b wakeup key + */ +#define OPTEE_MSG_RPC_CMD_WAIT_QUEUE 4 +#define OPTEE_MSG_RPC_WAIT_QUEUE_SLEEP 0 +#define OPTEE_MSG_RPC_WAIT_QUEUE_WAKEUP 1 + +/* + * Suspend execution + * + * [in] param[0].value .a number of milliseconds to suspend + */ +#define OPTEE_MSG_RPC_CMD_SUSPEND 5 + +/* + * Allocate a piece of shared memory + * + * Shared memory can optionally be fragmented, to support that additional + * spare param entries are allocated to make room for eventual fragments. + * The spare param entries has .attr = OPTEE_MSG_ATTR_TYPE_NONE when + * unused. All returned temp memrefs except the last should have the + * OPTEE_MSG_ATTR_FRAGMENT bit set in the attr field. + * + * [in] param[0].u.value.a type of memory one of + * OPTEE_MSG_RPC_SHM_TYPE_* below + * [in] param[0].u.value.b requested size + * [in] param[0].u.value.c required alignment + * + * [out] param[0].u.tmem.buf_ptr physical address (of first fragment) + * [out] param[0].u.tmem.size size (of first fragment) + * [out] param[0].u.tmem.shm_ref shared memory reference + * ... + * [out] param[n].u.tmem.buf_ptr physical address + * [out] param[n].u.tmem.size size + * [out] param[n].u.tmem.shm_ref shared memory reference (same value + * as in param[n-1].u.tmem.shm_ref) + */ +#define OPTEE_MSG_RPC_CMD_SHM_ALLOC 6 +/* Memory that can be shared with a non-secure user space application */ +#define OPTEE_MSG_RPC_SHM_TYPE_APPL 0 +/* Memory only shared with non-secure kernel */ +#define OPTEE_MSG_RPC_SHM_TYPE_KERNEL 1 + +/* + * Free shared memory previously allocated with OPTEE_MSG_RPC_CMD_SHM_ALLOC + * + * [in] param[0].u.value.a type of memory one of + * OPTEE_MSG_RPC_SHM_TYPE_* above + * [in] param[0].u.value.b value of shared memory reference + * returned in param[0].u.tmem.shm_ref + * above + */ +#define OPTEE_MSG_RPC_CMD_SHM_FREE 7 + +#endif /* _OPTEE_MSG_H */ diff --git a/drivers/tee/optee/optee_msg_supplicant.h b/drivers/tee/optee/optee_msg_supplicant.h new file mode 100644 index 000000000000..a0fb8063c818 --- /dev/null +++ b/drivers/tee/optee/optee_msg_supplicant.h @@ -0,0 +1,240 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (c) 2016-2018, Linaro Limited + */ + +#ifndef __OPTEE_MSG_SUPPLICANT_H +#define __OPTEE_MSG_SUPPLICANT_H + +/* + * This file is based on + * https://github.com/OP-TEE/optee_os/blob/master/core/include/optee_msg_supplicant.h + * and may need to be updated when introducing new features. + */ + +/* + * Load a TA into memory + */ +#define OPTEE_MSG_RPC_CMD_LOAD_TA 0 + +/* + * Replay Protected Memory Block access + */ +#define OPTEE_MSG_RPC_CMD_RPMB 1 + +/* + * File system access + */ +#define OPTEE_MSG_RPC_CMD_FS 2 + +/* + * Define protocol for messages with .cmd == OPTEE_MSG_RPC_CMD_FS and first + * parameter has the attribute OPTEE_MSG_ATTR_TYPE_VALUE_INPUT. + */ + +/* + * Open a file + * + * [in] param[0].u.value.a OPTEE_MRF_OPEN + * [in] param[1].u.tmem a string holding the file name + * [out] param[2].u.value.a file descriptor of open file + */ +#define OPTEE_MRF_OPEN 0 + +/* + * Create a file + * + * [in] param[0].u.value.a OPTEE_MRF_CREATE + * [in] param[1].u.tmem a string holding the file name + * [out] param[2].u.value.a file descriptor of open file + */ +#define OPTEE_MRF_CREATE 1 + +/* + * Close a file + * + * [in] param[0].u.value.a OPTEE_MRF_CLOSE + * [in] param[0].u.value.b file descriptor of open file. + */ +#define OPTEE_MRF_CLOSE 2 + +/* + * Read from a file + * + * [in] param[0].u.value.a OPTEE_MRF_READ + * [in] param[0].u.value.b file descriptor of open file + * [in] param[0].u.value.c offset into file + * [out] param[1].u.tmem buffer to hold returned data + */ +#define OPTEE_MRF_READ 3 + +/* + * Write to a file + * + * [in] param[0].u.value.a OPTEE_MRF_WRITE + * [in] param[0].u.value.b file descriptor of open file + * [in] param[0].u.value.c offset into file + * [in] param[1].u.tmem buffer holding data to be written + */ +#define OPTEE_MRF_WRITE 4 + +/* + * Truncate a file + * + * [in] param[0].u.value.a OPTEE_MRF_TRUNCATE + * [in] param[0].u.value.b file descriptor of open file + * [in] param[0].u.value.c length of file. + */ +#define OPTEE_MRF_TRUNCATE 5 + +/* + * Remove a file + * + * [in] param[0].u.value.a OPTEE_MRF_REMOVE + * [in] param[1].u.tmem a string holding the file name + */ +#define OPTEE_MRF_REMOVE 6 + +/* + * Rename a file + * + * [in] param[0].u.value.a OPTEE_MRF_RENAME + * [in] param[0].u.value.b true if existing target should be removed + * [in] param[1].u.tmem a string holding the old file name + * [in] param[2].u.tmem a string holding the new file name + */ +#define OPTEE_MRF_RENAME 7 + +/* + * Opens a directory for file listing + * + * [in] param[0].u.value.a OPTEE_MRF_OPENDIR + * [in] param[1].u.tmem a string holding the name of the directory + * [out] param[2].u.value.a handle to open directory + */ +#define OPTEE_MRF_OPENDIR 8 + +/* + * Closes a directory handle + * + * [in] param[0].u.value.a OPTEE_MRF_CLOSEDIR + * [in] param[0].u.value.b handle to open directory + */ +#define OPTEE_MRF_CLOSEDIR 9 + +/* + * Read next file name of directory + * + * + * [in] param[0].u.value.a OPTEE_MRF_READDIR + * [in] param[0].u.value.b handle to open directory + * [out] param[1].u.tmem a string holding the file name + */ +#define OPTEE_MRF_READDIR 10 + +/* + * End of definitions for messages with .cmd == OPTEE_MSG_RPC_CMD_FS + */ + +/* + * Command Ids 3, 4 and 5 of OPTEE_MSG_RPC_CMD_xxx macros are reserved for use + * by the kernel driver. + */ + +/* + * Shared memory allocation + */ +#define OPTEE_MSG_RPC_CMD_SHM_ALLOC 6 +#define OPTEE_MSG_RPC_CMD_SHM_FREE 7 + +/* + * Was OPTEE_MSG_RPC_CMD_SQL_FS, which isn't supported any longer + */ +#define OPTEE_MSG_RPC_CMD_SQL_FS_RESERVED 8 + +/* + * GPROF support management commands + */ +#define OPTEE_MSG_RPC_CMD_GPROF 9 + +/* + * Socket commands + */ +#define OPTEE_MSG_RPC_CMD_SOCKET 10 + +/* + * Define protocol for messages with .cmd == OPTEE_MSG_RPC_CMD_SOCKET + */ + +#define OPTEE_MRC_SOCKET_TIMEOUT_NONBLOCKING 0 +#define OPTEE_MRC_SOCKET_TIMEOUT_BLOCKING 0xffffffff + +/* + * Open socket + * + * [in] param[0].u.value.a OPTEE_MRC_SOCKET_OPEN + * [in] param[0].u.value.b TA instance id + * [in] param[1].u.value.a server port number + * [in] param[1].u.value.b protocol, TEE_ISOCKET_PROTOCOLID_* + * [in] param[1].u.value.c ip version TEE_IP_VERSION_* from tee_ipsocket.h + * [in] param[2].u.tmem server address + * [out] param[3].u.value.a socket handle (32-bit) + */ +#define OPTEE_MRC_SOCKET_OPEN 0 + +/* + * Close socket + * + * [in] param[0].u.value.a OPTEE_MRC_SOCKET_CLOSE + * [in] param[0].u.value.b TA instance id + * [in] param[0].u.value.c socket handle + */ +#define OPTEE_MRC_SOCKET_CLOSE 1 + +/* + * Close all sockets + * + * [in] param[0].u.value.a OPTEE_MRC_SOCKET_CLOSE_ALL + * [in] param[0].u.value.b TA instance id + */ +#define OPTEE_MRC_SOCKET_CLOSE_ALL 2 + +/* + * Send data on socket + * + * [in] param[0].u.value.a OPTEE_MRC_SOCKET_SEND + * [in] param[0].u.value.b TA instance id + * [in] param[0].u.value.c socket handle + * [in] param[1].u.tmem buffer to transmit + * [in] param[2].u.value.a timeout ms or OPTEE_MRC_SOCKET_TIMEOUT_* + * [out] param[2].u.value.b number of transmitted bytes + */ +#define OPTEE_MRC_SOCKET_SEND 3 + +/* + * Receive data on socket + * + * [in] param[0].u.value.a OPTEE_MRC_SOCKET_RECV + * [in] param[0].u.value.b TA instance id + * [in] param[0].u.value.c socket handle + * [out] param[1].u.tmem buffer to receive + * [in] param[2].u.value.a timeout ms or OPTEE_MRC_SOCKET_TIMEOUT_* + */ +#define OPTEE_MRC_SOCKET_RECV 4 + +/* + * Perform IOCTL on socket + * + * [in] param[0].u.value.a OPTEE_MRC_SOCKET_IOCTL + * [in] param[0].u.value.b TA instance id + * [in] param[0].u.value.c socket handle + * [in/out] param[1].u.tmem buffer + * [in] param[2].u.value.a ioctl command + */ +#define OPTEE_MRC_SOCKET_IOCTL 5 + +/* + * End of definitions for messages with .cmd == OPTEE_MSG_RPC_CMD_SOCKET + */ + +#endif /* __OPTEE_MSG_SUPPLICANT_H */ diff --git a/drivers/tee/optee/optee_private.h b/drivers/tee/optee/optee_private.h new file mode 100644 index 000000000000..35adb83afcc7 --- /dev/null +++ b/drivers/tee/optee/optee_private.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (c) 2018 Linaro Limited + */ + +#ifndef __OPTEE_PRIVATE_H +#define __OPTEE_PRIVATE_H + +void *optee_alloc_and_init_page_list(void *buf, ulong len, u64 *phys_buf_ptr); +void optee_suppl_cmd(struct udevice *dev, void *shm, void **page_list); + +#endif /* __OPTEE_PRIVATE_H */ diff --git a/drivers/tee/optee/optee_smc.h b/drivers/tee/optee/optee_smc.h new file mode 100644 index 000000000000..4d643b2599d6 --- /dev/null +++ b/drivers/tee/optee/optee_smc.h @@ -0,0 +1,450 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* + * Copyright (c) 2015-2018, Linaro Limited + */ + +#ifndef OPTEE_SMC_H +#define OPTEE_SMC_H + +#include +#include + +/* + * This file is based on + * https://github.com/OP-TEE/optee_os/blob/master/core/arch/arm/include/sm/optee_smc.h + * and may need to be updated when introducing new features. + */ + +#define OPTEE_SMC_STD_CALL_VAL(func_num) \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_STD_CALL, ARM_SMCCC_SMC_32, \ + ARM_SMCCC_OWNER_TRUSTED_OS, (func_num)) +#define OPTEE_SMC_FAST_CALL_VAL(func_num) \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \ + ARM_SMCCC_OWNER_TRUSTED_OS, (func_num)) + +/* + * Function specified by SMC Calling convention. + */ +#define OPTEE_SMC_FUNCID_CALLS_COUNT 0xFF00 +#define OPTEE_SMC_CALLS_COUNT \ + ARM_SMCCC_CALL_VAL(OPTEE_SMC_FAST_CALL, SMCCC_SMC_32, \ + SMCCC_OWNER_TRUSTED_OS_END, \ + OPTEE_SMC_FUNCID_CALLS_COUNT) + +/* + * Normal cached memory (write-back), shareable for SMP systems and not + * shareable for UP systems. + */ +#define OPTEE_SMC_SHM_CACHED 1 + +/* + * a0..a7 is used as register names in the descriptions below, on arm32 + * that translates to r0..r7 and on arm64 to w0..w7. In both cases it's + * 32-bit registers. + */ + +/* + * Function specified by SMC Calling convention + * + * Return one of the following UIDs if using API specified in this file + * without further extentions: + * 65cb6b93-af0c-4617-8ed6-644a8d1140f8 + * see also OPTEE_SMC_UID_* in optee_msg.h + */ +#define OPTEE_SMC_FUNCID_CALLS_UID OPTEE_MSG_FUNCID_CALLS_UID +#define OPTEE_SMC_CALLS_UID \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \ + ARM_SMCCC_OWNER_TRUSTED_OS_END, \ + OPTEE_SMC_FUNCID_CALLS_UID) + +/* + * Function specified by SMC Calling convention + * + * Returns 2.0 if using API specified in this file without further extentions. + * see also OPTEE_MSG_REVISION_* in optee_msg.h + */ +#define OPTEE_SMC_FUNCID_CALLS_REVISION OPTEE_MSG_FUNCID_CALLS_REVISION +#define OPTEE_SMC_CALLS_REVISION \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \ + ARM_SMCCC_OWNER_TRUSTED_OS_END, \ + OPTEE_SMC_FUNCID_CALLS_REVISION) + +struct optee_smc_calls_revision_result { + unsigned long major; + unsigned long minor; + unsigned long reserved0; + unsigned long reserved1; +}; + +/* + * Get UUID of Trusted OS. + * + * Used by non-secure world to figure out which Trusted OS is installed. + * Note that returned UUID is the UUID of the Trusted OS, not of the API. + * + * Returns UUID in a0-4 in the same way as OPTEE_SMC_CALLS_UID + * described above. + */ +#define OPTEE_SMC_FUNCID_GET_OS_UUID OPTEE_MSG_FUNCID_GET_OS_UUID +#define OPTEE_SMC_CALL_GET_OS_UUID \ + OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_OS_UUID) + +/* + * Get revision of Trusted OS. + * + * Used by non-secure world to figure out which version of the Trusted OS + * is installed. Note that the returned revision is the revision of the + * Trusted OS, not of the API. + * + * Returns revision in a0-1 in the same way as OPTEE_SMC_CALLS_REVISION + * described above. May optionally return a 32-bit build identifier in a2, + * with zero meaning unspecified. + */ +#define OPTEE_SMC_FUNCID_GET_OS_REVISION OPTEE_MSG_FUNCID_GET_OS_REVISION +#define OPTEE_SMC_CALL_GET_OS_REVISION \ + OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_OS_REVISION) + +struct optee_smc_call_get_os_revision_result { + unsigned long major; + unsigned long minor; + unsigned long build_id; + unsigned long reserved1; +}; + +/* + * Call with struct optee_msg_arg as argument + * + * Call register usage: + * a0 SMC Function ID, OPTEE_SMC*CALL_WITH_ARG + * a1 Upper 32bit of a 64bit physical pointer to a struct optee_msg_arg + * a2 Lower 32bit of a 64bit physical pointer to a struct optee_msg_arg + * a3 Cache settings, not used if physical pointer is in a predefined shared + * memory area else per OPTEE_SMC_SHM_* + * a4-6 Not used + * a7 Hypervisor Client ID register + * + * Normal return register usage: + * a0 Return value, OPTEE_SMC_RETURN_* + * a1-3 Not used + * a4-7 Preserved + * + * OPTEE_SMC_RETURN_ETHREAD_LIMIT return register usage: + * a0 Return value, OPTEE_SMC_RETURN_ETHREAD_LIMIT + * a1-3 Preserved + * a4-7 Preserved + * + * RPC return register usage: + * a0 Return value, OPTEE_SMC_RETURN_IS_RPC(val) + * a1-2 RPC parameters + * a3-7 Resume information, must be preserved + * + * Possible return values: + * OPTEE_SMC_RETURN_UNKNOWN_FUNCTION Trusted OS does not recognize this + * function. + * OPTEE_SMC_RETURN_OK Call completed, result updated in + * the previously supplied struct + * optee_msg_arg. + * OPTEE_SMC_RETURN_ETHREAD_LIMIT Number of Trusted OS threads exceeded, + * try again later. + * OPTEE_SMC_RETURN_EBADADDR Bad physcial pointer to struct + * optee_msg_arg. + * OPTEE_SMC_RETURN_EBADCMD Bad/unknown cmd in struct optee_msg_arg + * OPTEE_SMC_RETURN_IS_RPC() Call suspended by RPC call to normal + * world. + */ +#define OPTEE_SMC_FUNCID_CALL_WITH_ARG OPTEE_MSG_FUNCID_CALL_WITH_ARG +#define OPTEE_SMC_CALL_WITH_ARG \ + OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_CALL_WITH_ARG) + +/* + * Get Shared Memory Config + * + * Returns the Secure/Non-secure shared memory config. + * + * Call register usage: + * a0 SMC Function ID, OPTEE_SMC_GET_SHM_CONFIG + * a1-6 Not used + * a7 Hypervisor Client ID register + * + * Have config return register usage: + * a0 OPTEE_SMC_RETURN_OK + * a1 Physical address of start of SHM + * a2 Size of of SHM + * a3 Cache settings of memory, as defined by the + * OPTEE_SMC_SHM_* values above + * a4-7 Preserved + * + * Not available register usage: + * a0 OPTEE_SMC_RETURN_ENOTAVAIL + * a1-3 Not used + * a4-7 Preserved + */ +#define OPTEE_SMC_FUNCID_GET_SHM_CONFIG 7 +#define OPTEE_SMC_GET_SHM_CONFIG \ + OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_GET_SHM_CONFIG) + +struct optee_smc_get_shm_config_result { + unsigned long status; + unsigned long start; + unsigned long size; + unsigned long settings; +}; + +/* + * Exchanges capabilities between normal world and secure world + * + * Call register usage: + * a0 SMC Function ID, OPTEE_SMC_EXCHANGE_CAPABILITIES + * a1 bitfield of normal world capabilities OPTEE_SMC_NSEC_CAP_* + * a2-6 Not used + * a7 Hypervisor Client ID register + * + * Normal return register usage: + * a0 OPTEE_SMC_RETURN_OK + * a1 bitfield of secure world capabilities OPTEE_SMC_SEC_CAP_* + * a2-7 Preserved + * + * Error return register usage: + * a0 OPTEE_SMC_RETURN_ENOTAVAIL, can't use the capabilities from normal world + * a1 bitfield of secure world capabilities OPTEE_SMC_SEC_CAP_* + * a2-7 Preserved + */ +/* Normal world works as a uniprocessor system */ +#define OPTEE_SMC_NSEC_CAP_UNIPROCESSOR BIT(0) +/* Secure world has reserved shared memory for normal world to use */ +#define OPTEE_SMC_SEC_CAP_HAVE_RESERVED_SHM BIT(0) +/* Secure world can communicate via previously unregistered shared memory */ +#define OPTEE_SMC_SEC_CAP_UNREGISTERED_SHM BIT(1) + +/* + * Secure world supports commands "register/unregister shared memory", + * secure world accepts command buffers located in any parts of non-secure RAM + */ +#define OPTEE_SMC_SEC_CAP_DYNAMIC_SHM BIT(2) + +#define OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES 9 +#define OPTEE_SMC_EXCHANGE_CAPABILITIES \ + OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_EXCHANGE_CAPABILITIES) + +struct optee_smc_exchange_capabilities_result { + unsigned long status; + unsigned long capabilities; + unsigned long reserved0; + unsigned long reserved1; +}; + +/* + * Disable and empties cache of shared memory objects + * + * Secure world can cache frequently used shared memory objects, for + * example objects used as RPC arguments. When secure world is idle this + * function returns one shared memory reference to free. To disable the + * cache and free all cached objects this function has to be called until + * it returns OPTEE_SMC_RETURN_ENOTAVAIL. + * + * Call register usage: + * a0 SMC Function ID, OPTEE_SMC_DISABLE_SHM_CACHE + * a1-6 Not used + * a7 Hypervisor Client ID register + * + * Normal return register usage: + * a0 OPTEE_SMC_RETURN_OK + * a1 Upper 32bit of a 64bit Shared memory cookie + * a2 Lower 32bit of a 64bit Shared memory cookie + * a3-7 Preserved + * + * Cache empty return register usage: + * a0 OPTEE_SMC_RETURN_ENOTAVAIL + * a1-7 Preserved + * + * Not idle return register usage: + * a0 OPTEE_SMC_RETURN_EBUSY + * a1-7 Preserved + */ +#define OPTEE_SMC_FUNCID_DISABLE_SHM_CACHE 10 +#define OPTEE_SMC_DISABLE_SHM_CACHE \ + OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_DISABLE_SHM_CACHE) + +struct optee_smc_disable_shm_cache_result { + unsigned long status; + unsigned long shm_upper32; + unsigned long shm_lower32; + unsigned long reserved0; +}; + +/* + * Enable cache of shared memory objects + * + * Secure world can cache frequently used shared memory objects, for + * example objects used as RPC arguments. When secure world is idle this + * function returns OPTEE_SMC_RETURN_OK and the cache is enabled. If + * secure world isn't idle OPTEE_SMC_RETURN_EBUSY is returned. + * + * Call register usage: + * a0 SMC Function ID, OPTEE_SMC_ENABLE_SHM_CACHE + * a1-6 Not used + * a7 Hypervisor Client ID register + * + * Normal return register usage: + * a0 OPTEE_SMC_RETURN_OK + * a1-7 Preserved + * + * Not idle return register usage: + * a0 OPTEE_SMC_RETURN_EBUSY + * a1-7 Preserved + */ +#define OPTEE_SMC_FUNCID_ENABLE_SHM_CACHE 11 +#define OPTEE_SMC_ENABLE_SHM_CACHE \ + OPTEE_SMC_FAST_CALL_VAL(OPTEE_SMC_FUNCID_ENABLE_SHM_CACHE) + +/* + * Resume from RPC (for example after processing a foreign interrupt) + * + * Call register usage: + * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC + * a1-3 Value of a1-3 when OPTEE_SMC_CALL_WITH_ARG returned + * OPTEE_SMC_RETURN_RPC in a0 + * + * Return register usage is the same as for OPTEE_SMC_*CALL_WITH_ARG above. + * + * Possible return values + * OPTEE_SMC_RETURN_UNKNOWN_FUNCTION Trusted OS does not recognize this + * function. + * OPTEE_SMC_RETURN_OK Original call completed, result + * updated in the previously supplied. + * struct optee_msg_arg + * OPTEE_SMC_RETURN_RPC Call suspended by RPC call to normal + * world. + * OPTEE_SMC_RETURN_ERESUME Resume failed, the opaque resume + * information was corrupt. + */ +#define OPTEE_SMC_FUNCID_RETURN_FROM_RPC 3 +#define OPTEE_SMC_CALL_RETURN_FROM_RPC \ + OPTEE_SMC_STD_CALL_VAL(OPTEE_SMC_FUNCID_RETURN_FROM_RPC) + +#define OPTEE_SMC_RETURN_RPC_PREFIX_MASK 0xFFFF0000 +#define OPTEE_SMC_RETURN_RPC_PREFIX 0xFFFF0000 +#define OPTEE_SMC_RETURN_RPC_FUNC_MASK 0x0000FFFF + +#define OPTEE_SMC_RETURN_GET_RPC_FUNC(ret) \ + ((ret) & OPTEE_SMC_RETURN_RPC_FUNC_MASK) + +#define OPTEE_SMC_RPC_VAL(func) ((func) | OPTEE_SMC_RETURN_RPC_PREFIX) + +/* + * Allocate memory for RPC parameter passing. The memory is used to hold a + * struct optee_msg_arg. + * + * "Call" register usage: + * a0 This value, OPTEE_SMC_RETURN_RPC_ALLOC + * a1 Size in bytes of required argument memory + * a2 Not used + * a3 Resume information, must be preserved + * a4-5 Not used + * a6-7 Resume information, must be preserved + * + * "Return" register usage: + * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC. + * a1 Upper 32bits of 64bit physical pointer to allocated + * memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't + * be allocated. + * a2 Lower 32bits of 64bit physical pointer to allocated + * memory, (a1 == 0 && a2 == 0) if size was 0 or if memory can't + * be allocated + * a3 Preserved + * a4 Upper 32bits of 64bit Shared memory cookie used when freeing + * the memory or doing an RPC + * a5 Lower 32bits of 64bit Shared memory cookie used when freeing + * the memory or doing an RPC + * a6-7 Preserved + */ +#define OPTEE_SMC_RPC_FUNC_ALLOC 0 +#define OPTEE_SMC_RETURN_RPC_ALLOC \ + OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_ALLOC) + +/* + * Free memory previously allocated by OPTEE_SMC_RETURN_RPC_ALLOC + * + * "Call" register usage: + * a0 This value, OPTEE_SMC_RETURN_RPC_FREE + * a1 Upper 32bits of 64bit shared memory cookie belonging to this + * argument memory + * a2 Lower 32bits of 64bit shared memory cookie belonging to this + * argument memory + * a3-7 Resume information, must be preserved + * + * "Return" register usage: + * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC. + * a1-2 Not used + * a3-7 Preserved + */ +#define OPTEE_SMC_RPC_FUNC_FREE 2 +#define OPTEE_SMC_RETURN_RPC_FREE \ + OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_FREE) + +/* + * Deliver foreign interrupt to normal world. + * + * "Call" register usage: + * a0 OPTEE_SMC_RETURN_RPC_FOREIGN_INTR + * a1-7 Resume information, must be preserved + * + * "Return" register usage: + * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC. + * a1-7 Preserved + */ +#define OPTEE_SMC_RPC_FUNC_FOREIGN_INTR 4 +#define OPTEE_SMC_RETURN_RPC_FOREIGN_INTR \ + OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_FOREIGN_INTR) + +/* + * Do an RPC request. The supplied struct optee_msg_arg tells which + * request to do and the parameters for the request. The following fields + * are used (the rest are unused): + * - cmd the Request ID + * - ret return value of the request, filled in by normal world + * - num_params number of parameters for the request + * - params the parameters + * - param_attrs attributes of the parameters + * + * "Call" register usage: + * a0 OPTEE_SMC_RETURN_RPC_CMD + * a1 Upper 32bit of a 64bit Shared memory cookie holding a + * struct optee_msg_arg, must be preserved, only the data should + * be updated + * a2 Lower 32bit of a 64bit Shared memory cookie holding a + * struct optee_msg_arg, must be preserved, only the data should + * be updated + * a3-7 Resume information, must be preserved + * + * "Return" register usage: + * a0 SMC Function ID, OPTEE_SMC_CALL_RETURN_FROM_RPC. + * a1-2 Not used + * a3-7 Preserved + */ +#define OPTEE_SMC_RPC_FUNC_CMD 5 +#define OPTEE_SMC_RETURN_RPC_CMD \ + OPTEE_SMC_RPC_VAL(OPTEE_SMC_RPC_FUNC_CMD) + +/* Returned in a0 */ +#define OPTEE_SMC_RETURN_UNKNOWN_FUNCTION 0xFFFFFFFF + +/* Returned in a0 only from Trusted OS functions */ +#define OPTEE_SMC_RETURN_OK 0x0 +#define OPTEE_SMC_RETURN_ETHREAD_LIMIT 0x1 +#define OPTEE_SMC_RETURN_EBUSY 0x2 +#define OPTEE_SMC_RETURN_ERESUME 0x3 +#define OPTEE_SMC_RETURN_EBADADDR 0x4 +#define OPTEE_SMC_RETURN_EBADCMD 0x5 +#define OPTEE_SMC_RETURN_ENOMEM 0x6 +#define OPTEE_SMC_RETURN_ENOTAVAIL 0x7 +#define OPTEE_SMC_RETURN_IS_RPC(ret) __optee_smc_return_is_rpc((ret)) + +static inline bool __optee_smc_return_is_rpc(u32 ret) +{ + return ret != OPTEE_SMC_RETURN_UNKNOWN_FUNCTION && + (ret & OPTEE_SMC_RETURN_RPC_PREFIX_MASK) == + OPTEE_SMC_RETURN_RPC_PREFIX; +} + +#endif /* OPTEE_SMC_H */ diff --git a/drivers/tee/optee/supplicant.c b/drivers/tee/optee/supplicant.c new file mode 100644 index 000000000000..2239b1bf7b37 --- /dev/null +++ b/drivers/tee/optee/supplicant.c @@ -0,0 +1,93 @@ +// SPDX-License-Identifier: BSD-2-Clause +/* + * Copyright (c) 2018, Linaro Limited + */ + +#include +#include +#include +#include + +#include "optee_msg.h" +#include "optee_msg_supplicant.h" +#include "optee_private.h" +#include "optee_smc.h" + +static void cmd_shm_alloc(struct udevice *dev, struct optee_msg_arg *arg, + void **page_list) +{ + int rc; + struct tee_shm *shm; + void *pl; + u64 ph_ptr; + + arg->ret_origin = TEE_ORIGIN_COMMS; + + if (arg->num_params != 1 || + arg->params[0].attr != OPTEE_MSG_ATTR_TYPE_VALUE_INPUT) { + arg->ret = TEE_ERROR_BAD_PARAMETERS; + return; + } + + rc = __tee_shm_add(dev, 0, NULL, arg->params[0].u.value.b, + TEE_SHM_REGISTER | TEE_SHM_ALLOC, &shm); + if (rc) { + if (rc == -ENOMEM) + arg->ret = TEE_ERROR_OUT_OF_MEMORY; + else + arg->ret = TEE_ERROR_GENERIC; + return; + } + + pl = optee_alloc_and_init_page_list(shm->addr, shm->size, &ph_ptr); + if (!pl) { + arg->ret = TEE_ERROR_OUT_OF_MEMORY; + tee_shm_free(shm); + return; + } + + *page_list = pl; + arg->params[0].attr = OPTEE_MSG_ATTR_TYPE_TMEM_OUTPUT | + OPTEE_MSG_ATTR_NONCONTIG; + arg->params[0].u.tmem.buf_ptr = ph_ptr; + arg->params[0].u.tmem.size = shm->size; + arg->params[0].u.tmem.shm_ref = (ulong)shm; + arg->ret = TEE_SUCCESS; +} + +static void cmd_shm_free(struct optee_msg_arg *arg) +{ + arg->ret_origin = TEE_ORIGIN_COMMS; + + if (arg->num_params != 1 || + arg->params[0].attr != OPTEE_MSG_ATTR_TYPE_VALUE_INPUT) { + arg->ret = TEE_ERROR_BAD_PARAMETERS; + return; + } + + tee_shm_free((struct tee_shm *)(ulong)arg->params[0].u.value.b); + arg->ret = TEE_SUCCESS; +} + +void optee_suppl_cmd(struct udevice *dev, struct tee_shm *shm_arg, + void **page_list) +{ + struct optee_msg_arg *arg = shm_arg->addr; + + switch (arg->cmd) { + case OPTEE_MSG_RPC_CMD_SHM_ALLOC: + cmd_shm_alloc(dev, arg, page_list); + break; + case OPTEE_MSG_RPC_CMD_SHM_FREE: + cmd_shm_free(arg); + break; + case OPTEE_MSG_RPC_CMD_FS: + debug("OPTEE_MSG_RPC_CMD_FS not implemented\n"); + arg->ret = TEE_ERROR_NOT_IMPLEMENTED; + break; + default: + arg->ret = TEE_ERROR_NOT_IMPLEMENTED; + } + + arg->ret_origin = TEE_ORIGIN_COMMS; +} From patchwork Mon Sep 3 14:47:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 145805 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp2575574ljw; Mon, 3 Sep 2018 07:47:32 -0700 (PDT) X-Received: by 2002:a2e:7406:: with SMTP id p6-v6mr7852696ljc.5.1535986052280; Mon, 03 Sep 2018 07:47:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535986052; cv=none; d=google.com; s=arc-20160816; b=ko7wX/0WYUpSAWkFQO/Y80eRwKoZQkUbMT6V+kXip0o9gVOATZc9hcPAlY7Q7IOBaF MYh/9iDwtuqyLt60CRRJD52AkKMqrp1eyJgJ6Xgoxae4eKEGf11vYtqJVJu/3zoltJyl p0INyKAxgOlDP9obp7XX8p6/SrwRloGgBC5bZb22naLv2e1VzO0KbU+njNIYrWxVwnBZ Leg4LdC0F9nTgEKly0/8hi++1Y+tG3pHJ6yNDYXuQSi6QAmRL/7hXAEkGaG+SgqnDrar WmY67SX5zHZh9eKDSSgVyxde1j7tjcIzP0yqkzCuKP8XHnLj+42bZmcs8Fb7BNCZZiNy ek/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=lgCdUmBufLy6+xjFvNL7oyDbBWl5csz7nRRV9iomFaE=; b=XD79C+VUM63kbro+wKjbq86xy5RvDA0XHrDGZjNlHmBr6Cu+g5sEGQXxmkbmCJIMcz v7Zzf0982zT8K5HSJmfk1lXfwBHisSrchPopLbdRbA1pdNgsZaKUhv1T/EZgbR03eXNY s+jWCHrb1wAImqPH+32p8PrfhC1L+CJrdFE3AnOARZ2JXmgfQchxXQRiqH48RmKs3Xhl YWg2mXPzCz/GhuUzzUNyyAIzJcjTbDaexhheXEMHr9YcWSLUfha2EUQ5RxQROdWSlFud rwmhb5jUy2X66bQf0Q61CM5D0dfyaqZcBTw4Eqsgc6D+JXOAA6l7BePHaeftukB2A/Pm ZJdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=U0L0cGkg; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id r16-v6sor5338621lff.13.2018.09.03.07.47.32 for (Google Transport Security); Mon, 03 Sep 2018 07:47:32 -0700 (PDT) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=U0L0cGkg; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=lgCdUmBufLy6+xjFvNL7oyDbBWl5csz7nRRV9iomFaE=; b=U0L0cGkgD5movJSm59seJ5277rX2Sii1JOxKYRiOhyRhv5HIYQDCQxwyZBecCbFUdG FvGA0zy4K7yDvJPyKehO/8ZUJl5KuUBNdfxCBRwJ3DPLidGZAL0JrJm7/QEE1enz6H1w NsVElzoThgFJb7/gZJ+HLwi/HhPRNen0sU64o= 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=lgCdUmBufLy6+xjFvNL7oyDbBWl5csz7nRRV9iomFaE=; b=CAuZrG+G6HsXxbjd7vhQdmgbMv36qi4WhaAYosPRc8QLC3pSmK0G/HL4hV1t5jwDZC /CcDnLarlqd5hkiTLeMc6ZUVlc9wyN2exauEGtHFqsKS3cLQvRKGmuOfVzBfpKrITex3 VpVCi1ITAKLch3N1UHxI107KqHArnFWDd1qIyCueAWTJTrJWW19v6uY4jmgAFfjcHBfg yH9l4+x+aWBEVxSl/+sLga5m5ApqTxTcY9EKb8WgHI6YpytSq7M93aMMRKDRJeft55Sl Qj7FazP0tejBGj37ZUjNU0OsNah+ZaeeRbRYZP5h+kES1a7WqkeDjEKcQd6XxDcafeFj vtIw== X-Gm-Message-State: APzg51CJbUpygbUobcSQkZN8qMW8pbga0G2rq0NVrBn8lMyv6I18O027 AJI5edA3Dx/zMg9VKc5PfGbEDCEy X-Google-Smtp-Source: ANB0VdYoFPTvjnCXfu6An4nloiHygv5hUaAoZX+bd1g1vI5woq8deUG6lNBEhrMGGdG8FPJfkPm9CA== X-Received: by 2002:a19:a2c1:: with SMTP id l184-v6mr14591020lfe.129.1535986052043; Mon, 03 Sep 2018 07:47:32 -0700 (PDT) Return-Path: Received: from jax.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id w18-v6sm3343431ljd.73.2018.09.03.07.47.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Sep 2018 07:47:31 -0700 (PDT) From: Jens Wiklander To: u-boot@lists.denx.de Cc: Simon Glass , Igor Opaniuk , Tom Rini , Jaehoon Chung , Pierre Aubert , Albert Aribaud , Peter Griffin , Michal Simek , Jens Wiklander Subject: [PATCH v3 09/20] Documentation: tee uclass and op-tee driver Date: Mon, 3 Sep 2018 16:47:00 +0200 Message-Id: <20180903144711.31585-10-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180903144711.31585-1-jens.wiklander@linaro.org> References: <20180903144711.31585-1-jens.wiklander@linaro.org> Reviewed-by: Simon Glass Signed-off-by: Jens Wiklander --- doc/README.tee | 112 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 doc/README.tee -- 2.17.1 diff --git a/doc/README.tee b/doc/README.tee new file mode 100644 index 000000000000..79e7996a6f5f --- /dev/null +++ b/doc/README.tee @@ -0,0 +1,112 @@ +============= +TEE uclass +============= + +This document describes the TEE uclass in U-Boot + +A TEE (Trusted Execution Environment) is a trusted OS running in some +secure environment, for example, TrustZone on ARM CPUs, or a separate +secure co-processor etc. A TEE driver handles the details needed to +communicate with the TEE. + +This uclass deals with: + +- Registration of TEE drivers + +- Managing shared memory between U-Boot and the TEE + +- Providing a generic API to the TEE + +The TEE interface +================= + +include/tee.h defines the generic interface to a TEE. + +A client finds the TEE device via tee_find_device(). Other important functions +when interfacing with a TEE are: + +- tee_shm_alloc(), tee_shm_register() and tee_shm_free() to manage shared + memory objects often needed when communicating with the TEE. + +- tee_get_version() lets the client know which the capabilities of the TEE + device. + +- tee_open_session() opens a session to a Trusted Application + +- tee_invoke_func() invokes a function in a Trusted Application + +- tee_close_session() closes a session to a Trusted Application + +Much of the communication between clients and the TEE is opaque to the +driver. The main job for the driver is to receive requests from the +clients, forward them to the TEE and send back the results. + +OP-TEE driver +============= + +The OP-TEE driver handles OP-TEE [1] based TEEs. Currently it is only the ARM +TrustZone based OP-TEE solution that is supported. + +Lowest level of communication with OP-TEE builds on ARM SMC Calling +Convention (SMCCC) [2], which is the foundation for OP-TEE's SMC interface +[3] used internally by the driver. Stacked on top of that is OP-TEE Message +Protocol [4]. + +OP-TEE SMC interface provides the basic functions required by SMCCC and some +additional functions specific for OP-TEE. The most interesting functions are: + +- OPTEE_SMC_FUNCID_CALLS_UID (part of SMCCC) returns the version information + which is then returned by TEE_IOC_VERSION + +- OPTEE_SMC_CALL_GET_OS_UUID returns the particular OP-TEE implementation, used + to tell, for instance, a TrustZone OP-TEE apart from an OP-TEE running on a + separate secure co-processor. + +- OPTEE_SMC_CALL_WITH_ARG drives the OP-TEE message protocol + +- OPTEE_SMC_GET_SHM_CONFIG lets the driver and OP-TEE agree on which memory + range to used for shared memory between Linux and OP-TEE. + +The GlobalPlatform TEE Client API [5] is implemented on top of the generic +TEE API. + +Picture of the relationship between the different components in the +OP-TEE architecture: + + U-Boot Secure world + ~~~~~~ ~~~~~~~~~~~~ + +------------+ +-------------+ + | Client | | Trusted | + | | | Application | + +------------+ +-------------+ + /\ /\ + || || + \/ \/ + +------------+ +-------------+ + | TEE | | TEE Internal| + | uclass | | API | + +------------+ +-------------+ + | OP-TEE | | OP-TEE | + | driver | | Trusted OS | + +------------+-----------+-------------+ + | OP-TEE MSG | + | SMCCC (OPTEE_SMC_CALL_*) | + +--------------------------------------+ + +RPC (Remote Procedure Call) are requests from secure world to the driver. +An RPC is identified by a special range of SMCCC return values from +OPTEE_SMC_CALL_WITH_ARG. + +References +========== + +[1] https://github.com/OP-TEE/optee_os + +[2] http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html + +[3] drivers/tee/optee/optee_smc.h + +[4] drivers/tee/optee/optee_msg.h + +[5] http://www.globalplatform.org/specificationsdevice.asp look for + "TEE Client API Specification v1.0" and click download. From patchwork Mon Sep 3 14:47:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 145806 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp2575595ljw; Mon, 3 Sep 2018 07:47:33 -0700 (PDT) X-Received: by 2002:a2e:888d:: with SMTP id k13-v6mr17815356lji.38.1535986053690; Mon, 03 Sep 2018 07:47:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535986053; cv=none; d=google.com; s=arc-20160816; b=dBhrATNFJmtxwXmGtulVyAXFlLHER8TNHzYj6mOtNegcFsiOaEVjgLxKERrHt9AnM6 A66gwQDtKoHFJtc7GaROBjzgT+5fggvTv810rT3X7fkxB7jd+5aQeKoFyr5EEJ4ufirP Dw52dAHCcpQlKEKr+q/7wZw8ckd5QG4kcxgn7CvFFiSCcqn06FZTJFxWLjGnqkF6DJzT FzPVxR3o5GF7lNkn3XFexgjgco1cMSx47s1sAsdYwNksT9Lqgl3jYpObPb9RWX/Ys5Kf OCD2QRcr41g21qivNuD3huYDl5KzrAapRtSDApMIFB2XFyno9AlURmK8zf1IkgWgNtCq 0+4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=Lo0wjllGNW4/iM0v8kOJHE5aBnbim/dVCgLScr1WZQ0=; b=DAPHZF4UgsQMtu+bIYp2A4NJGUz16FoaewA4vDYtA2FRBwkZpRczpzdCAn4K6fjjFT 1nrKVAjydcp/HCf6ndpNdvNRG7ak9aXYTKp0iryXJAykIuMUdm7og+FEQP7AlvIBjwkp +uHPI3+3snGB6WW55YbztdwTLqoAKj4ruVfmg0vLnkla4ko8qeWAxUv0sEPqNZ0moX8j FPPXEa9ucV6vny42UXf8ghVoYnc+7StqpFr4pMBGo1US7RavCpI4XmsBKlLN9wPvr2h3 2d/RUIt9VMS7WvPk0IvU68g6k46x7edhBUpPds189SyaabtJWq5FNUFvVdahSNfGBtbv 5u3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IgUAVzrE; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id i123-v6sor7813332lji.27.2018.09.03.07.47.33 for (Google Transport Security); Mon, 03 Sep 2018 07:47:33 -0700 (PDT) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IgUAVzrE; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=Lo0wjllGNW4/iM0v8kOJHE5aBnbim/dVCgLScr1WZQ0=; b=IgUAVzrEyTarb26UmQD2oX/EVwwq1OilnxwtRZotAWEtU5Ttxg0r6rm6IUkbyaQigB qY98AITsVoNGObc4WMGw4rakwHuWuje+uBE9djNPjmRiFTy+T+J31SZL2YJqrpM7JXeL Icw1AWHOkP91mFqfKLkdH2El48RD6lQeniL0Y= 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=Lo0wjllGNW4/iM0v8kOJHE5aBnbim/dVCgLScr1WZQ0=; b=gzbqudmD5M5+TKOEmx5K/xz7QMmRjcWPypbirxGhtP8XeikaojA+XWMWB1/1Uh3LvA GbkoCDstP+mEUYQ6SUdYfxcQ6SyfPj9B3anbda1P+Ov8UNc3kUUgZCuaklG0BqlHRcVT AKpSW8axY3wq/vaJ5IhdP0lHRdU9qKAPantK7h+nFNgKYEWYoMaCv48jSU/QeFQsgnaL +CleN6pSbS7QIvVWnHilc6p7PtbsjnrWc0QZ6IczbNEKKZck/o7mDgRmxuzSJRvjiINc 8bEhMxlPyLqaU0tH2LGHZ3HEbe0zoogOJ1l64U7so2byfNdHTPurGrZkzzcJhs4mnu/6 EOcw== X-Gm-Message-State: APzg51Cibv74Gpkqip3KYLRrpLyjsVXeM4jnqqyUt4Te1zEAHVCZrduK wYKeYcUUPbelpLMyte1yPBanliq3 X-Google-Smtp-Source: ANB0VdbfpAPgj+xOmY54DvLOIvY1nLh3L5zHXIcoMTs7XWK/D0Ae8sRjL+WzV9CLLRt+vQY8ns1qew== X-Received: by 2002:a2e:8103:: with SMTP id d3-v6mr9372193ljg.3.1535986053531; Mon, 03 Sep 2018 07:47:33 -0700 (PDT) Return-Path: Received: from jax.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id w18-v6sm3343431ljd.73.2018.09.03.07.47.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Sep 2018 07:47:32 -0700 (PDT) From: Jens Wiklander To: u-boot@lists.denx.de Cc: Simon Glass , Igor Opaniuk , Tom Rini , Jaehoon Chung , Pierre Aubert , Albert Aribaud , Peter Griffin , Michal Simek , Jens Wiklander Subject: [PATCH v3 10/20] arm: dt: hikey: Add optee node Date: Mon, 3 Sep 2018 16:47:01 +0200 Message-Id: <20180903144711.31585-11-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180903144711.31585-1-jens.wiklander@linaro.org> References: <20180903144711.31585-1-jens.wiklander@linaro.org> Sync with 14e21cb8f811 ("arm64: dt: hikey: Add optee node" from Linux kernel. Reviewed-by: Simon Glass Signed-off-by: Jens Wiklander --- arch/arm/dts/hi6220-hikey.dts | 7 +++++++ 1 file changed, 7 insertions(+) -- 2.17.1 diff --git a/arch/arm/dts/hi6220-hikey.dts b/arch/arm/dts/hi6220-hikey.dts index 818525197508..24f09257af00 100644 --- a/arch/arm/dts/hi6220-hikey.dts +++ b/arch/arm/dts/hi6220-hikey.dts @@ -31,6 +31,13 @@ device_type = "memory"; reg = <0x0 0x0 0x0 0x40000000>; }; + + firmware { + optee { + compatible = "linaro,optee-tz"; + method = "smc"; + }; + }; }; &uart2 { From patchwork Mon Sep 3 14:47:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 145808 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp2575619ljw; Mon, 3 Sep 2018 07:47:35 -0700 (PDT) X-Received: by 2002:ac2:418b:: with SMTP id z11-v6mr17057994lfh.3.1535986055296; Mon, 03 Sep 2018 07:47:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535986055; cv=none; d=google.com; s=arc-20160816; b=dNl/rvssBygj0/kDsyvcE4teayviXeVcQhAw/HH908rDjGHN+WpuO2A166F1+zELJ0 Bc0nTXA40Wh8FsvS0bbnHpXwPrNSzB9FfZN89CFF82kZHsd4aIP0LdTo4EsJFcZXqTMq Anf3+JmSPWpcFq8dv6/lVU9wE0rRsQ1Q+CsAQAD6vNoW/VgDqDAtBQ3irOvadeGUxOmd pWdK9js/WpbZwz5q6UUj5a5eYck7nyNbtlmwBS1PZgwNVVxzQtUzNAviowUHC4P0gVoF I8mScmURD1+ua/81lw9PN+8ZZpfjIlnePVKBOReKxL+qpaKi56AmLkCUFimMPQfmYXO8 XKPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=tBbBJe8/MVi9pxS8uyiw1IWis6hb4TT0xsmEuxzdBB8=; b=gebPresZO4TQdl9z909t0HNO6nwg/7d0l4MeoDGRWyC9kKqDMaC0ssVkqTNfRGqA+R zROLRNhOGwi1/Kbkc9pYTaYGm8s7qqqxIH+5WeF6pVDnPuB+leHxWI4YLH785M9g0cW3 oGs30bjgdmiM2H46nR6l+ROzKc8l4KKhZZ3vDcA4duinFe68u95rPb2dc/hXh6BhpgLA tRjLqWFpR9DXHneGS807Rw9mfuwUHH0WiNvxKgO3cSom+wEaiGEDUWOrTFviGpPfM1HP +mGQVJ4mkufcM7SuY4OlSYF/MYUY+e5vK7B2Gd93v0ziLgGGqWX4dXQx48e5uvGBcJxK ji+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Owz3Vg1q; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id i11-v6sor5454669lfb.56.2018.09.03.07.47.35 for (Google Transport Security); Mon, 03 Sep 2018 07:47:35 -0700 (PDT) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Owz3Vg1q; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=tBbBJe8/MVi9pxS8uyiw1IWis6hb4TT0xsmEuxzdBB8=; b=Owz3Vg1qWf2tJDUExvAPE7oWvQB1lE8BNyWBLsbYdYBzmn/vKEJ1Y0AK0+9g4kM40s ZR4fY2O30j24lTNRuKSTV3u/n7mFBzSWJm9ojKXPBNomIFjItsqTV+WfempbaB9obNIM SdSlDdGxXeRjhyGOqTSTbnc7UBnaZhSMG0tCw= 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=tBbBJe8/MVi9pxS8uyiw1IWis6hb4TT0xsmEuxzdBB8=; b=fSV/vCNGkJiYxbRbyJBsDwRB13q39RicUyPQQJ6hd64aPFJ3StaGZ2PALJvaFIE4kP GXcOaX7C2m2rsC4hfReDBp+Nd67kCott3M3GyTKQbgkf3GDu9Oq0cTA+w+7Kk9Fqujpf m69MKTkOiSXX4lfDgL5m6XxAqmhwOr2MReziDe1nM1vDLQMgg4sALYbP6BywP1/LPCV+ OhAlgZojLE7eWpBHWOb55f8WT0zmiitReh/eXPNIBLplswQ/uY5bAgP51OtzxvgU0f/0 lXRhKpQHK20tUYVG9SQ97H3F1EawSqIk6zC3i/iQxf9b1cskb7Q+BBN5hDbMGD4+GFS5 xRSw== X-Gm-Message-State: APzg51Bkdf9TGiSfUvSJmlFEt+KyjZkp17XFcCoZxvJszFJN7YzXlTGX or3VVzneVDwfPM8AZ7BTw84oDi2y X-Google-Smtp-Source: ANB0VdZNyFwX3XPwtNYVEKsOxlOOG5sb4WMUUTUhC6xZ+Usoi8MTuZHfPUh/+s9jt0JxZnzB2TDuSw== X-Received: by 2002:a19:a141:: with SMTP id k62-v6mr11379940lfe.18.1535986054960; Mon, 03 Sep 2018 07:47:34 -0700 (PDT) Return-Path: Received: from jax.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id w18-v6sm3343431ljd.73.2018.09.03.07.47.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Sep 2018 07:47:34 -0700 (PDT) From: Jens Wiklander To: u-boot@lists.denx.de Cc: Simon Glass , Igor Opaniuk , Tom Rini , Jaehoon Chung , Pierre Aubert , Albert Aribaud , Peter Griffin , Michal Simek , Jens Wiklander Subject: [PATCH v3 11/20] optee: support routing of rpmb data frames to mmc Date: Mon, 3 Sep 2018 16:47:02 +0200 Message-Id: <20180903144711.31585-12-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180903144711.31585-1-jens.wiklander@linaro.org> References: <20180903144711.31585-1-jens.wiklander@linaro.org> Adds support in optee supplicant to route signed (MACed) RPMB frames from OP-TEE Secure OS to MMC and vice versa to manipulate the RPMB partition. Tested-by: Igor Opaniuk Signed-off-by: Jens Wiklander --- drivers/tee/optee/Makefile | 1 + drivers/tee/optee/core.c | 8 ++ drivers/tee/optee/optee_private.h | 55 ++++++++- drivers/tee/optee/rpmb.c | 181 ++++++++++++++++++++++++++++++ drivers/tee/optee/supplicant.c | 3 + 5 files changed, 247 insertions(+), 1 deletion(-) create mode 100644 drivers/tee/optee/rpmb.c -- 2.17.1 diff --git a/drivers/tee/optee/Makefile b/drivers/tee/optee/Makefile index 6148feb474a5..928d3f80027f 100644 --- a/drivers/tee/optee/Makefile +++ b/drivers/tee/optee/Makefile @@ -2,3 +2,4 @@ obj-y += core.o obj-y += supplicant.o +obj-$(CONFIG_SUPPORT_EMMC_RPMB) += rpmb.o diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c index 726382da9bb8..7f870f2f735d 100644 --- a/drivers/tee/optee/core.c +++ b/drivers/tee/optee/core.c @@ -315,6 +315,13 @@ static u32 do_call_with_arg(struct udevice *dev, struct optee_msg_arg *arg) param.a3 = res.a3; handle_rpc(dev, ¶m, &page_list); } else { + /* + * In case we've accessed RPMB to serve an RPC + * request we need to restore the previously + * selected partition as the caller may expect it + * to remain unchanged. + */ + optee_suppl_rpmb_release(dev); return call_err_to_res(res.a0); } } @@ -651,4 +658,5 @@ U_BOOT_DRIVER(optee) = { .probe = optee_probe, .ops = &optee_ops, .platdata_auto_alloc_size = sizeof(struct optee_pdata), + .priv_auto_alloc_size = sizeof(struct optee_private), }; diff --git a/drivers/tee/optee/optee_private.h b/drivers/tee/optee/optee_private.h index 35adb83afcc7..9442d1c176bc 100644 --- a/drivers/tee/optee/optee_private.h +++ b/drivers/tee/optee/optee_private.h @@ -6,7 +6,60 @@ #ifndef __OPTEE_PRIVATE_H #define __OPTEE_PRIVATE_H +#include +#include + +/** + * struct optee_private - OP-TEE driver private data + * @rpmb_mmc: mmc device for the RPMB partition + * @rpmb_dev_id: mmc device id matching @rpmb_mmc + * @rpmb_original_part: the previosly active partition on the mmc device, + * used to restore active the partition when the RPMB + * accesses are finished + */ +struct optee_private { + struct mmc *rpmb_mmc; + int rpmb_dev_id; + int rpmb_original_part; +}; + +struct optee_msg_arg; + +void optee_suppl_cmd(struct udevice *dev, struct tee_shm *shm_arg, + void **page_list); + +#ifdef CONFIG_SUPPORT_EMMC_RPMB +/** + * optee_suppl_cmd_rpmb() - route RPMB frames to mmc + * @dev: device with the selected RPMB partition + * @arg: OP-TEE message holding the frames to transmit to the mmc + * and space for the response frames. + * + * Routes signed (MACed) RPMB frames from OP-TEE Secure OS to MMC and vice + * versa to manipulate the RPMB partition. + */ +void optee_suppl_cmd_rpmb(struct udevice *dev, struct optee_msg_arg *arg); + +/** + * optee_suppl_rpmb_release() - release mmc device + * @dev: mmc device + * + * Releases the mmc device and restores the previously selected partition. + */ +void optee_suppl_rpmb_release(struct udevice *dev); +#else +static inline void optee_suppl_cmd_rpmb(struct udevice *dev, + struct optee_msg_arg *arg) +{ + debug("OPTEE_MSG_RPC_CMD_RPMB not implemented\n"); + arg->ret = TEE_ERROR_NOT_IMPLEMENTED; +} + +static inline void optee_suppl_rpmb_release(struct udevice *dev) +{ +} +#endif + void *optee_alloc_and_init_page_list(void *buf, ulong len, u64 *phys_buf_ptr); -void optee_suppl_cmd(struct udevice *dev, void *shm, void **page_list); #endif /* __OPTEE_PRIVATE_H */ diff --git a/drivers/tee/optee/rpmb.c b/drivers/tee/optee/rpmb.c new file mode 100644 index 000000000000..955155b3f8b1 --- /dev/null +++ b/drivers/tee/optee/rpmb.c @@ -0,0 +1,181 @@ +// SPDX-License-Identifier: BSD-2-Clause +/* + * Copyright (c) 2018 Linaro Limited + */ + +#include +#include +#include +#include +#include + +#include "optee_msg.h" +#include "optee_private.h" + +/* + * Request and response definitions must be in sync with the secure side of + * OP-TEE. + */ + +/* Request */ +struct rpmb_req { + u16 cmd; +#define RPMB_CMD_DATA_REQ 0x00 +#define RPMB_CMD_GET_DEV_INFO 0x01 + u16 dev_id; + u16 block_count; + /* Optional data frames (rpmb_data_frame) follow */ +}; + +#define RPMB_REQ_DATA(req) ((void *)((struct rpmb_req *)(req) + 1)) + +/* Response to device info request */ +struct rpmb_dev_info { + u8 cid[16]; + u8 rpmb_size_mult; /* EXT CSD-slice 168: RPMB Size */ + u8 rel_wr_sec_c; /* EXT CSD-slice 222: Reliable Write Sector */ + /* Count */ + u8 ret_code; +#define RPMB_CMD_GET_DEV_INFO_RET_OK 0x00 +#define RPMB_CMD_GET_DEV_INFO_RET_ERROR 0x01 +}; + +static void release_mmc(struct optee_private *priv) +{ + int rc; + + if (!priv->rpmb_mmc) + return; + + rc = blk_select_hwpart_devnum(IF_TYPE_MMC, priv->rpmb_dev_id, + priv->rpmb_original_part); + if (rc) + debug("%s: blk_select_hwpart_devnum() failed: %d\n", + __func__, rc); + + priv->rpmb_mmc = NULL; +} + +static struct mmc *get_mmc(struct optee_private *priv, int dev_id) +{ + struct mmc *mmc; + int rc; + + if (priv->rpmb_mmc && priv->rpmb_dev_id == dev_id) + return priv->rpmb_mmc; + + release_mmc(priv); + + mmc = find_mmc_device(dev_id); + if (!mmc) { + debug("Cannot find RPMB device\n"); + return NULL; + } + if (!(mmc->version & MMC_VERSION_MMC)) { + debug("Device id %d is not an eMMC device\n", dev_id); + return NULL; + } + if (mmc->version < MMC_VERSION_4_41) { + debug("Device id %d: RPMB not supported before version 4.41\n", + dev_id); + return NULL; + } + + priv->rpmb_original_part = mmc_get_blk_desc(mmc)->hwpart; + + rc = blk_select_hwpart_devnum(IF_TYPE_MMC, dev_id, MMC_PART_RPMB); + if (rc) { + debug("Device id %d: cannot select RPMB partition: %d\n", + dev_id, rc); + return NULL; + } + + priv->rpmb_mmc = mmc; + priv->rpmb_dev_id = dev_id; + return mmc; +} + +static u32 rpmb_get_dev_info(u16 dev_id, struct rpmb_dev_info *info) +{ + struct mmc *mmc = find_mmc_device(dev_id); + + if (!mmc) + return TEE_ERROR_ITEM_NOT_FOUND; + + if (!mmc->ext_csd) + return TEE_ERROR_GENERIC; + + memcpy(info->cid, mmc->cid, sizeof(info->cid)); + info->rel_wr_sec_c = mmc->ext_csd[222]; + info->rpmb_size_mult = mmc->ext_csd[168]; + info->ret_code = RPMB_CMD_GET_DEV_INFO_RET_OK; + + return TEE_SUCCESS; +} + +static u32 rpmb_process_request(struct optee_private *priv, void *req, + ulong req_size, void *rsp, ulong rsp_size) +{ + struct rpmb_req *sreq = req; + struct mmc *mmc; + + if (req_size < sizeof(*sreq)) + return TEE_ERROR_BAD_PARAMETERS; + + switch (sreq->cmd) { + case RPMB_CMD_DATA_REQ: + mmc = get_mmc(priv, sreq->dev_id); + if (!mmc) + return TEE_ERROR_ITEM_NOT_FOUND; + if (mmc_rpmb_route_frames(mmc, RPMB_REQ_DATA(req), + req_size - sizeof(struct rpmb_req), + rsp, rsp_size)) + return TEE_ERROR_BAD_PARAMETERS; + return TEE_SUCCESS; + + case RPMB_CMD_GET_DEV_INFO: + if (req_size != sizeof(struct rpmb_req) || + rsp_size != sizeof(struct rpmb_dev_info)) { + debug("Invalid req/rsp size\n"); + return TEE_ERROR_BAD_PARAMETERS; + } + return rpmb_get_dev_info(sreq->dev_id, rsp); + + default: + debug("Unsupported RPMB command: %d\n", sreq->cmd); + return TEE_ERROR_BAD_PARAMETERS; + } +} + +void optee_suppl_cmd_rpmb(struct udevice *dev, struct optee_msg_arg *arg) +{ + struct tee_shm *req_shm; + struct tee_shm *rsp_shm; + void *req_buf; + void *rsp_buf; + ulong req_size; + ulong rsp_size; + + if (arg->num_params != 2 || + arg->params[0].attr != OPTEE_MSG_ATTR_TYPE_RMEM_INPUT || + arg->params[1].attr != OPTEE_MSG_ATTR_TYPE_RMEM_OUTPUT) { + arg->ret = TEE_ERROR_BAD_PARAMETERS; + return; + } + + req_shm = (struct tee_shm *)(ulong)arg->params[0].u.rmem.shm_ref; + req_buf = (u8 *)req_shm->addr + arg->params[0].u.rmem.offs; + req_size = arg->params[0].u.rmem.size; + + rsp_shm = (struct tee_shm *)(ulong)arg->params[1].u.rmem.shm_ref; + rsp_buf = (u8 *)rsp_shm->addr + arg->params[1].u.rmem.offs; + rsp_size = arg->params[1].u.rmem.size; + + arg->ret = rpmb_process_request(dev_get_priv(dev), req_buf, req_size, + rsp_buf, rsp_size); +} + +void optee_suppl_rpmb_release(struct udevice *dev) +{ + release_mmc(dev_get_priv(dev)); +} diff --git a/drivers/tee/optee/supplicant.c b/drivers/tee/optee/supplicant.c index 2239b1bf7b37..b1ea65bdb2e3 100644 --- a/drivers/tee/optee/supplicant.c +++ b/drivers/tee/optee/supplicant.c @@ -85,6 +85,9 @@ void optee_suppl_cmd(struct udevice *dev, struct tee_shm *shm_arg, debug("OPTEE_MSG_RPC_CMD_FS not implemented\n"); arg->ret = TEE_ERROR_NOT_IMPLEMENTED; break; + case OPTEE_MSG_RPC_CMD_RPMB: + optee_suppl_cmd_rpmb(dev, arg); + break; default: arg->ret = TEE_ERROR_NOT_IMPLEMENTED; } From patchwork Mon Sep 3 14:47:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 145809 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp2575647ljw; Mon, 3 Sep 2018 07:47:36 -0700 (PDT) X-Received: by 2002:a19:e21b:: with SMTP id z27-v6mr18819399lfg.68.1535986056647; Mon, 03 Sep 2018 07:47:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535986056; cv=none; d=google.com; s=arc-20160816; b=lCmC6D6tcaGVGaWf1efh7hSKUKlWOaXXhofMnoSpW/K/pHXnu5oNJFmk83JvvdhQ9z 0mAtXBg/9bKpo5MhfIvkn5GIgcmHOGixbzTRVp8vMnAopxfi+tqbUH+BW3uw/X+KLjcw Xk3oP0wmx5iYivqXejAAnba1Xl/HdwBhjUHOYmQUN8+CU1qYynMrWKGeDWvKqao6yV/D K9xF0HasFfiErdx2LfTkUMHRdsthVDLCqW1cOTpXwu7DI2+FyjC9SZ1Pz/o97TZEZRy9 p7pLN2wVQbw//EgFRvSSb+GGGJcvEfVB5sYq+eN+Rx2jRTlEQfZ85q6EQi3axukILeMi OG4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=HKRdv0vIuma6DXsuxi4vmfMTcUGzLZl5eXvJIao3sRA=; b=rKDsMMR/UEOZ5QKTyJGo73qwL1FVEm+3Wu/+lCP+2DHPpVUzfFdhFVRuKHQH24wL/1 aOZq4oSjsJjGggRvBYDtfyrQXX6FJESsXG9rnMzXG2P2Dk+OznVpvQqrGXmoBjCdU99F TkUXvza/Vrh1S6HMVW9oT83vFzpVhvt+d+7UO0kGY0mZgogFnRztYT5TqpLRlcGzyEWN q++W+0zNuw42CjLNBWLw8nM809cvjNqHCCRVlCB7WVWhP32czeQV5yhALFiaS/pu91Rj 3wX1zPdKRL151C6UyqpreCw8NmJT5/yZwF4G+svMslid1nFMFnT8a6fwuG0bZPgx/LLd gpYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DZ+nR3FH; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id 91-v6sor5082642lfs.27.2018.09.03.07.47.36 for (Google Transport Security); Mon, 03 Sep 2018 07:47:36 -0700 (PDT) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DZ+nR3FH; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=HKRdv0vIuma6DXsuxi4vmfMTcUGzLZl5eXvJIao3sRA=; b=DZ+nR3FHxgYra7PZLUeVA7i1L0ivgvmU8Kkxrv23V3cCc/FCdNuwx/xrtAm0yHfJHL 0R1IiJJVb/MvDhF/Sct/28vaHQnW4hdCNTN2ATeFsEmBnwJXuHFtnACEi9lkbKf7CWc8 IDKgAnMYAFqWkQg3i5Z/+2Wfm097dDlJP3iN8= 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=HKRdv0vIuma6DXsuxi4vmfMTcUGzLZl5eXvJIao3sRA=; b=lEaBHqoRL8H57AzS+ZzKox/nzlDYvsyBQC4bG12jwbbLoSJoB1uLzaY7UetepnSAdL p3/N1uNwx2Ap8QvGKqlZDB54P4xjwKqeJIbBHQSUA8s9JrJD4+zZVHqwqKISTOUphiUx vqwMohKw/cAq3vcLrv2V8w/RiJXkCY7rw3ugL2i6BtOrEXfQQkNUtf56YwG9qY5N5bMn kufbiLS+cf4uBdYX7OZs24At7UHKApGgRXsE7Kj4r4ej8PsKzBeBh7/fiAFq555J6lzv 0eAkaM+eLw2DfiYLtpnglmxvQIu3KDMs9eU+Gr4eKNbrimP5mwsvN8C4cxK5K5/ASkZ9 ++eg== X-Gm-Message-State: APzg51ApCuXTOinjks03s5nWcR7QKxI+lvrrZCT3uDyXUIMMAZgIA2Wq og5nqWWVr2sPYORWdHj3OHh4vh+2 X-Google-Smtp-Source: ANB0VdYKlaK4gOY/+uNfSrmzzpIrlwrt0MhlHuCD9uKutlxT4EfCj0qUE6Bk5C8k9HlKmEZgQ2m5fg== X-Received: by 2002:a19:655d:: with SMTP id c29-v6mr6099906lfj.138.1535986056365; Mon, 03 Sep 2018 07:47:36 -0700 (PDT) Return-Path: Received: from jax.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id w18-v6sm3343431ljd.73.2018.09.03.07.47.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Sep 2018 07:47:35 -0700 (PDT) From: Jens Wiklander To: u-boot@lists.denx.de Cc: Simon Glass , Igor Opaniuk , Tom Rini , Jaehoon Chung , Pierre Aubert , Albert Aribaud , Peter Griffin , Michal Simek , Jens Wiklander Subject: [PATCH v3 12/20] tee: optee: support AVB trusted application Date: Mon, 3 Sep 2018 16:47:03 +0200 Message-Id: <20180903144711.31585-13-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180903144711.31585-1-jens.wiklander@linaro.org> References: <20180903144711.31585-1-jens.wiklander@linaro.org> Adds configuration option OPTEE_TA_AVB and a header file describing the interface to the Android Verified Boot 2.0 (AVB) trusted application provided by OP-TEE. Tested-by: Igor Opaniuk Reviewed-by: Igor Opaniuk Signed-off-by: Jens Wiklander --- MAINTAINERS | 1 + drivers/tee/optee/Kconfig | 16 +++++++++++++ drivers/tee/tee-uclass.c | 24 +++++++++++++++++++ include/tee.h | 38 ++++++++++++++++++++++++++++++ include/tee/optee_ta_avb.h | 48 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 127 insertions(+) create mode 100644 include/tee/optee_ta_avb.h -- 2.17.1 diff --git a/MAINTAINERS b/MAINTAINERS index 7458c606ee92..cb36c45d74ea 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -576,6 +576,7 @@ M: Jens Wiklander S: Maintained F: drivers/tee/ F: include/tee.h +F: include/tee/ UBI M: Kyungmin Park diff --git a/drivers/tee/optee/Kconfig b/drivers/tee/optee/Kconfig index 7484e6fea114..dbfa7846a30f 100644 --- a/drivers/tee/optee/Kconfig +++ b/drivers/tee/optee/Kconfig @@ -9,3 +9,19 @@ config OPTEE mechanism. This driver can request services from OP-TEE, but also handle Remote Procedure Calls (RPC) from OP-TEE needed to execute a service. For more information see: https://www.op-tee.org + +if OPTEE + +menu "OP-TEE options" + +config OPTEE_TA_AVB + bool "Support AVB TA" + default y + help + Enables support for the AVB Trusted Application (TA) in OP-TEE. + The TA can support the "avb" subcommands "read_rb", "write"rb" + and "is_unlocked". + +endmenu + +endif diff --git a/drivers/tee/tee-uclass.c b/drivers/tee/tee-uclass.c index 1bee54ebf4af..abb88c0fee53 100644 --- a/drivers/tee/tee-uclass.c +++ b/drivers/tee/tee-uclass.c @@ -207,3 +207,27 @@ UCLASS_DRIVER(tee) = { .pre_probe = tee_pre_probe, .pre_remove = tee_pre_remove, }; + +void tee_optee_ta_uuid_from_octets(struct tee_optee_ta_uuid *d, + const u8 s[TEE_UUID_LEN]) +{ + d->time_low = ((u32)s[0] << 24) | ((u32)s[1] << 16) | + ((u32)s[2] << 8) | s[3], + d->time_mid = ((u32)s[4] << 8) | s[5]; + d->time_hi_and_version = ((u32)s[6] << 8) | s[7]; + memcpy(d->clock_seq_and_node, s + 8, sizeof(d->clock_seq_and_node)); +} + +void tee_optee_ta_uuid_to_octets(u8 d[TEE_UUID_LEN], + const struct tee_optee_ta_uuid *s) +{ + d[0] = s->time_low >> 24; + d[1] = s->time_low >> 16; + d[2] = s->time_low >> 8; + d[3] = s->time_low; + d[4] = s->time_mid >> 8; + d[5] = s->time_mid; + d[6] = s->time_hi_and_version >> 8; + d[7] = s->time_hi_and_version; + memcpy(d + 8, s->clock_seq_and_node, sizeof(s->clock_seq_and_node)); +} diff --git a/include/tee.h b/include/tee.h index b86dbec257b4..98b1c9cc693a 100644 --- a/include/tee.h +++ b/include/tee.h @@ -49,6 +49,22 @@ #define TEE_ORIGIN_TRUSTED_APP 0x00000004 struct udevice; + +/** + * struct tee_optee_ta_uuid - OP-TEE Trusted Application (TA) UUID format + * + * Used to identify an OP-TEE TA and define suitable to initialize structs + * of this format is distributed with the interface of the TA. The + * individual fields of this struct doesn't have any special meaning in + * OP-TEE. See RFC4122 for details on the format. + */ +struct tee_optee_ta_uuid { + u32 time_low; + u16 time_mid; + u16 time_hi_and_version; + u8 clock_seq_and_node[8]; +}; + /** * struct tee_shm - memory shared with the TEE * @dev: The TEE device @@ -333,4 +349,26 @@ int tee_close_session(struct udevice *dev, u32 session); int tee_invoke_func(struct udevice *dev, struct tee_invoke_arg *arg, uint num_param, struct tee_param *param); +/** + * tee_optee_ta_uuid_from_octets() - Converts to struct tee_optee_ta_uuid + * @d: Destination struct + * @s: Source UUID octets + * + * Conversion to a struct tee_optee_ta_uuid represantion from binary octet + * representation. + */ +void tee_optee_ta_uuid_from_octets(struct tee_optee_ta_uuid *d, + const u8 s[TEE_UUID_LEN]); + +/** + * tee_optee_ta_uuid_to_octets() - Converts from struct tee_optee_ta_uuid + * @d: Destination UUID octets + * @s: Source struct + * + * Conversion from a struct tee_optee_ta_uuid represantion to binary octet + * representation. + */ +void tee_optee_ta_uuid_to_octets(u8 d[TEE_UUID_LEN], + const struct tee_optee_ta_uuid *s); + #endif /* __TEE_H */ diff --git a/include/tee/optee_ta_avb.h b/include/tee/optee_ta_avb.h new file mode 100644 index 000000000000..074386af19a1 --- /dev/null +++ b/include/tee/optee_ta_avb.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ +/* Copyright (c) 2018, Linaro Limited */ + +#ifndef __TA_AVB_H +#define __TA_AVB_H + +#define TA_AVB_UUID { 0x023f8f1a, 0x292a, 0x432b, \ + { 0x8f, 0xc4, 0xde, 0x84, 0x71, 0x35, 0x80, 0x67 } } + +#define TA_AVB_MAX_ROLLBACK_LOCATIONS 256 + +/* + * Gets the rollback index corresponding to the given rollback index slot. + * + * in params[0].value.a: rollback index slot + * out params[1].value.a: upper 32 bits of rollback index + * out params[1].value.b: lower 32 bits of rollback index + */ +#define TA_AVB_CMD_READ_ROLLBACK_INDEX 0 + +/* + * Updates the rollback index corresponding to the given rollback index slot. + * + * Will refuse to update a slot with a lower value. + * + * in params[0].value.a: rollback index slot + * in params[1].value.a: upper 32 bits of rollback index + * in params[1].value.b: lower 32 bits of rollback index + */ +#define TA_AVB_CMD_WRITE_ROLLBACK_INDEX 1 + +/* + * Gets the lock state of the device. + * + * out params[0].value.a: lock state + */ +#define TA_AVB_CMD_READ_LOCK_STATE 2 + +/* + * Sets the lock state of the device. + * + * If the lock state is changed all rollback slots will be reset to 0 + * + * in params[0].value.a: lock state + */ +#define TA_AVB_CMD_WRITE_LOCK_STATE 3 + +#endif /* __TA_AVB_H */ From patchwork Mon Sep 3 14:47:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 145810 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp2575668ljw; Mon, 3 Sep 2018 07:47:38 -0700 (PDT) X-Received: by 2002:a2e:752:: with SMTP id i18-v6mr17416733ljd.118.1535986058411; Mon, 03 Sep 2018 07:47:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535986058; cv=none; d=google.com; s=arc-20160816; b=Ssg+XCuKjdt6hJ0yuW3dZj7J1gWDnOz8ozyW8HR+79XjrJCjUI/kFV7cZx5sGD1Wxa UsGsc+uQrKHIb8F/YYgSUTpOzJU81FIC5IyINpcX/R2buisvo+fuQ6AJU81ZlViPBQVj ENOjlyQDLAAPTiloAl7WBAJLkzeSdoqY3Arnjk1299xtFGdl1WEGV6voAwdyEVmDek0A JmcSAeUUM/I8dCQZO+QNoGtNHkE0xeeoPzZwQB5wORLKe3YVrIBh2Vzyz/RwDvU8ZTHJ VMmmuS5N4XZ6hlCzhOL5/Cz0KV6oqPskTk5n9N+dxdI1keZ4L4JoZqusY74rM24VRaHi ZC1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=50xX2VlUmb4Y590MzumVgkhXU2ANE/Vt33TiQ8iGDl8=; b=ADeq/c7TRdXktmtkk41qitwDD3RDVAt03ta82PBM6MIKKMI2wpi9SPmn6zfaZg1hPi LeLBwFOW9BAuVTUNGOGXJvq7SahMATZNqMFeTtA6j7yku5kD5AXPykQOS/S8ZIRdfBHx sRf4N+vEbfkA3wrPmsN4rUnWNOF1s4Bar/p4Qb9vAoGtPczRKADhiLyBT/3OO8NVGz0L MpYCVxjWRjsmTnjI3CnKLH/SKAca5gZYSXTQokYApdRdAH9iYg1IUJNKzxmkG0ZnB8Fz E74RB5F+HrW1nPw98pZoSEn0uteWY9ggGfaEJVOc5kKlFG/gZ2m6xNhzn/PKrFq+aiNR DULA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="PLNH/KTZ"; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id v16-v6sor7910243ljc.12.2018.09.03.07.47.38 for (Google Transport Security); Mon, 03 Sep 2018 07:47:38 -0700 (PDT) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="PLNH/KTZ"; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=50xX2VlUmb4Y590MzumVgkhXU2ANE/Vt33TiQ8iGDl8=; b=PLNH/KTZXurMSIEDSQfIca42AM40O3EEsLkwT2Nn6aUBuonG67GIO76zr9qOAAJDW0 7rWv70MHHnD8FKcm2DOEl8RIgCEgZi9xC/vtLEqltc5aiDIT8/DCNXOTVGCYEKKkha4R K7wiv1rw7E/CYnrbwXbjuyxtZ/xyV7T+4Sf0M= 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=50xX2VlUmb4Y590MzumVgkhXU2ANE/Vt33TiQ8iGDl8=; b=mcecxM1VCVp3XL+ln3ZBGihoCYC3sn5czt4BL5rnF9tDQ7WvG1XmiPcV/0fP1J2hXS wfGPxJ4UKdY96muT8zj90I+cupY8RTBuUyWKrb6RQntv6CI/ScjX8MrBHdStAZxpBGno ekh6mdSHoW6uW6sLrmneZuDqbc3Dk8Fd8mQ/GAwMEOfZyC3U/jW2VxyXNQ9CyJwAD2cT IeZzemPr00s1oL3k4UK9tJEjbJhtzzkElr+AOcdAY5g+9pnMwCyEmRdJpzXtBiiy/Cp+ JZQI+2Huc4ySijZzFduX0bauWCY40SLVFkzvneat/VD5WN5WyZqHSHKeE4vN4KeMWr+y +cfA== X-Gm-Message-State: APzg51AwpCoPRZIPEqo65ZskdOHj6T0/7fD0cBBEaKeQMi525n5w9N8L EPH5wPmGTOvXS6v9mTSbszEgW3KI X-Google-Smtp-Source: ANB0VdaefNmU9gGjUjnsM2vgSXkfDIWIIyM/odSZ7qp3vktIPEXKcmb3+aDVlCGk/myCoewK8zgvJQ== X-Received: by 2002:a2e:720e:: with SMTP id n14-v6mr18571101ljc.93.1535986058257; Mon, 03 Sep 2018 07:47:38 -0700 (PDT) Return-Path: Received: from jax.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id w18-v6sm3343431ljd.73.2018.09.03.07.47.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Sep 2018 07:47:37 -0700 (PDT) From: Jens Wiklander To: u-boot@lists.denx.de Cc: Simon Glass , Igor Opaniuk , Tom Rini , Jaehoon Chung , Pierre Aubert , Albert Aribaud , Peter Griffin , Michal Simek , Jens Wiklander Subject: [PATCH v3 13/20] sandbox: dt: add sandbox_tee node Date: Mon, 3 Sep 2018 16:47:04 +0200 Message-Id: <20180903144711.31585-14-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180903144711.31585-1-jens.wiklander@linaro.org> References: <20180903144711.31585-1-jens.wiklander@linaro.org> Adds a sandbox_tee node to enable the sandbox tee driver in all the sandbox dts files. Reviewed-by: Simon Glass Signed-off-by: Jens Wiklander --- arch/sandbox/dts/sandbox.dts | 4 ++++ arch/sandbox/dts/sandbox64.dts | 4 ++++ arch/sandbox/dts/test.dts | 4 ++++ 3 files changed, 12 insertions(+) -- 2.17.1 diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts index 9f444c96a9ec..f5c02e5396ff 100644 --- a/arch/sandbox/dts/sandbox.dts +++ b/arch/sandbox/dts/sandbox.dts @@ -311,6 +311,10 @@ }; }; }; + + sandbox_tee { + compatible = "sandbox,tee"; + }; }; #include "cros-ec-keyboard.dtsi" diff --git a/arch/sandbox/dts/sandbox64.dts b/arch/sandbox/dts/sandbox64.dts index 9e65d2fda3d3..0e32fdad9d81 100644 --- a/arch/sandbox/dts/sandbox64.dts +++ b/arch/sandbox/dts/sandbox64.dts @@ -311,6 +311,10 @@ }; }; }; + + sandbox_tee { + compatible = "sandbox,tee"; + }; }; #include "cros-ec-keyboard.dtsi" diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 70356461959d..eee7518be823 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -604,6 +604,10 @@ }; }; }; + + sandbox_tee { + compatible = "sandbox,tee"; + }; }; #include "sandbox_pmic.dtsi" From patchwork Mon Sep 3 14:47:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 145811 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp2575701ljw; Mon, 3 Sep 2018 07:47:40 -0700 (PDT) X-Received: by 2002:a19:9601:: with SMTP id y1-v6mr18390075lfd.91.1535986060067; Mon, 03 Sep 2018 07:47:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535986060; cv=none; d=google.com; s=arc-20160816; b=kfurA3WUDI9sA52zbVT5wWLPsRdGPxJaosfZvHka0Yzd1V1gkcYTvEFdrTrTXgF/Ez lSG6Blny435A7hECnOO9GbyVN50WCwyUCeoIk7rvcXMYMx2xYGu7id7+uky5vcjThtW5 XNMupFDDQMf7zr3QiffDS2e9OK+VBAFTUG0lNkvmQSWvO4SUXGbuhrsFv8D8bksVCBtn PZ60CXxD5AoR+MD0mDI69B2e4O2j0jBWO7nTM1AUMnr8JvoYOw3PvHjF6ucwJ7INEzZJ kROZ0QVGmlWvhnn/2ucLEVPUmJmOOJz6SMZNcW3aWjs5HLmXy7wQ8Y6RVqiBibjHisnv qonA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=gxemLh22a7a/msteJv1XCdpNxbHm3cLszcS6rSOYHKg=; b=ApjFGlJJGpJtyVfMxHDVT0qV7MjwYWcytY882z5JoKf3I5o4ISDwrulvLPYI/6/pT5 8HoKbLhlkE+oFC+CNQfazYXhFJrgfpVE3HunE9AvhsUQhSY/0kXX0C2wlUWzZq9BF3us dzFh6zxQiy2/rZjfBb7w9TsFTSmIR/fBwXjjgad0WWSZZFQ3V38M4+F/fRAmXvvCm4U2 IA8ArrTZhAXZ3T1MxdYXTPc49acLNPZL8iOhCYHeKg4DABwTR/AkWhvvDSahS6YSm/zN uN5vVmtjW+9ugrIBn0f6TcoVggVXATYj9gV6E1wE+DwpzS0IsReC9PNiHNFQAP2WHvHN 70WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M+rWlt0H; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id t73-v6sor7764587ljb.28.2018.09.03.07.47.40 for (Google Transport Security); Mon, 03 Sep 2018 07:47:40 -0700 (PDT) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M+rWlt0H; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=gxemLh22a7a/msteJv1XCdpNxbHm3cLszcS6rSOYHKg=; b=M+rWlt0Hxmvg2/sgtAUQy+ke31QSdxBgAtJTzG04zNSKHgGZRhuHtvKd5XD2mHPpfg ri2T6bI5dq+G0fUfmskjjt+j5GcCMrrA3VtVTGFUtO29xgbJoyWVrdEGzyE3ypbQSUdY 57cyoAB+JxxeiAv6ib1A7Bbe6tJHsMvpComnE= 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=gxemLh22a7a/msteJv1XCdpNxbHm3cLszcS6rSOYHKg=; b=TuBgGt6HM0Ey/QXVM0qksa99V8ZBhbCB9tGVVWPvAstwPVd4N3OiZkqjeh4zDAnBa2 V1rCWCU9O63rQkSI6xRR774e+E/P1lf/ibWgrmxVGS4laQKMigTvCx+XzestZ8MbM4u7 KDrP1RV3NG2l4XGABhxBLS3lXjb13dQa0rlMq9ObhrEu1tmM8JtiFL1UQC1doW2OtH9G 0YowPYItF8djNot4i6wwii8JfZKiP567Ee2r8AmawP3JcczwRjBO7oYMTH3FnMow5+qI 8ASBssSCZxrerJXDE8cHyd/ZmUT1k7MSx+X7IWJQGx/CmuBJeqqAAjmq3IacnWOrduhM wtZg== X-Gm-Message-State: APzg51CgSb0fP936xg1KA3Ebw7AjjolHhcxqblxodmZQo7JI8mI03lb/ Q+IHU3TQ0POXSP7XH4Dl18HnQJBx X-Google-Smtp-Source: ANB0VdaQLl7p9eOBDjCdrjKkSpdMJnAq3yxwo/mz0CvXOscaF7wF+pab6yQgUPEPQwur9Ah8j9dMGQ== X-Received: by 2002:a2e:5687:: with SMTP id k7-v6mr18940504lje.105.1535986059888; Mon, 03 Sep 2018 07:47:39 -0700 (PDT) Return-Path: Received: from jax.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id w18-v6sm3343431ljd.73.2018.09.03.07.47.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Sep 2018 07:47:39 -0700 (PDT) From: Jens Wiklander To: u-boot@lists.denx.de Cc: Simon Glass , Igor Opaniuk , Tom Rini , Jaehoon Chung , Pierre Aubert , Albert Aribaud , Peter Griffin , Michal Simek , Jens Wiklander Subject: [PATCH v3 14/20] sandbox: imply CONFIG_TEE (TEE uclass) Date: Mon, 3 Sep 2018 16:47:05 +0200 Message-Id: <20180903144711.31585-15-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180903144711.31585-1-jens.wiklander@linaro.org> References: <20180903144711.31585-1-jens.wiklander@linaro.org> Signed-off-by: Jens Wiklander --- arch/Kconfig | 1 + 1 file changed, 1 insertion(+) -- 2.17.1 Reviewed-by: Simon Glass diff --git a/arch/Kconfig b/arch/Kconfig index bf1b4a9afac6..8f10f3fc06e8 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -91,6 +91,7 @@ config SANDBOX imply HASH_VERIFY imply LZMA imply SCSI + imply TEE config SH bool "SuperH architecture" From patchwork Mon Sep 3 14:47:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 145812 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp2575723ljw; Mon, 3 Sep 2018 07:47:41 -0700 (PDT) X-Received: by 2002:a2e:2282:: with SMTP id i124-v6mr18831486lji.11.1535986061646; Mon, 03 Sep 2018 07:47:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535986061; cv=none; d=google.com; s=arc-20160816; b=w+RL8hT9TDY9BYXLz+4G48isec3+AaPxdM+lOUNxGp5mxUS9EpU3aSiZCrmhfqdK2M dx7u546lV2ht8/MzGp04xeKLwvCpMCXRFtHF5JVEWOxGx+k+yFpFFFk1NZcnK4CUh5UG TRwZYSPQSyxZLJXLJQhNVQnSBAp8AyMFw6dqM6BtxxCpwPfSGiH9sxwqNqgrWdJ1R8bZ 1WA/aUoCfJVXCS5xWl9HjcNeih1qnRO1GwzmtktwRZ7pVYU6edzr4jyAua0i4EuhGYIM 6y9tDXkCUPvDjCGdtyI8LR+kAyEBsOitRgCyf2fqPmavSuVXmK4Ijt+ulqtn9MEeG7Rz UP8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=DE5UbGuAWy9+9xJuZejUYyn0HTlzAq9WbDrzOK2AI20=; b=gz+1EWS3g8D/JaWu2nJgq5V7AKWR4LCfuS8a21U+B24raVZdqEuGiuaRK/s6DCFaKE JGus/fvPIchaRjrBrPKNJx4efbtrBgZQw5pd1rKxq0LxEzBAE5Cu4ntvLOuSmUD6tert ANQmEzdbMZTbVH/KZyRi4oBJrX/YIOtbgChyEtsETmyzyNr6ODQuiJGpbSJJPcs6Ft+6 7rmDe9YhA5TWVxXs9gVNZvPAsaBCne//JCVSiP+M4/7rxWYEFoWcuoijLpsg/EAKEKi0 KDKELnlF71q+GBIHeiU3xWOvC/VBeEwsgv7SlQZ7tPxaZy6/LmyH2ieYCh790DfVtksV ZiSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SyAgUHk6; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id u4-v6sor7783076lju.20.2018.09.03.07.47.41 for (Google Transport Security); Mon, 03 Sep 2018 07:47:41 -0700 (PDT) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SyAgUHk6; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=DE5UbGuAWy9+9xJuZejUYyn0HTlzAq9WbDrzOK2AI20=; b=SyAgUHk6PKJs/wJ1SInHXsvsaY4iUfNtfYvirWf3YMsdbQnM9yf04f62yW3Q94qUMa 95SEezeNVoZbOX6Tia08ot6pCyZLAAfNnZfkzLKqCMZdA2jOCSIvDNc/B9DKh6CvUcRa BjKMrW6mWopq/vOzq57H77uhNErGYCdtUj5mU= 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=DE5UbGuAWy9+9xJuZejUYyn0HTlzAq9WbDrzOK2AI20=; b=QjddXkAbF7aD3HPEgW2+uTjrlDieB/+0WcV3RgS6ZsCa97jF40ZB0CztMxmr1Wp+2Y uDlFzT1FH+H2prk1+X2ay21a2GxQOZtgdaMPfe8RgbUso7frTRznXhlm1ugNIfAwM2cr GMp4HrKiWtFuxa3mTz3fo66I7GtI9XtplDZcji/cx8ciGU21MKNrxCLrktAlThy+8/mR kzi/OnXMISZ3rLuy+mvNstQfBOkmj7bh6S+5ikXEzYPyBhmq+4eX3vwZps8FSeWjutxq O46XUaOgx6mjyuwUPpgG6Tz972FRIXMrGvbBptf5pUnYqqJ01cc1YHpZLczoTQNBDAOC gRBw== X-Gm-Message-State: APzg51B19kw/JbMUmHZ4ZJvNVnRSaW/BIoHbn2mv8ubpI3dtCyqw/ljP nBDMcMFdzjsNNrsy6hSBsWfUNoSU X-Google-Smtp-Source: ANB0VdYhLl7R/c5w/lKfJaMOmv0Mv80QrV2a7ld/+mC6Sw007M2BDXA3xnQCnlHVSfa2bkyeRLM5vw== X-Received: by 2002:a2e:80d3:: with SMTP id r19-v6mr926241ljg.85.1535986061300; Mon, 03 Sep 2018 07:47:41 -0700 (PDT) Return-Path: Received: from jax.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id w18-v6sm3343431ljd.73.2018.09.03.07.47.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Sep 2018 07:47:40 -0700 (PDT) From: Jens Wiklander To: u-boot@lists.denx.de Cc: Simon Glass , Igor Opaniuk , Tom Rini , Jaehoon Chung , Pierre Aubert , Albert Aribaud , Peter Griffin , Michal Simek , Jens Wiklander Subject: [PATCH v3 15/20] tee: add sandbox driver Date: Mon, 3 Sep 2018 16:47:06 +0200 Message-Id: <20180903144711.31585-16-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180903144711.31585-1-jens.wiklander@linaro.org> References: <20180903144711.31585-1-jens.wiklander@linaro.org> Adds a sandboxtee driver which emulates a generic TEE with the OP-TEE AVB TA. Signed-off-by: Jens Wiklander --- drivers/tee/Kconfig | 12 +- drivers/tee/Makefile | 1 + drivers/tee/optee/Kconfig | 2 +- drivers/tee/sandbox.c | 299 ++++++++++++++++++++++++++++++++++++++ include/sandboxtee.h | 15 ++ 5 files changed, 326 insertions(+), 3 deletions(-) create mode 100644 drivers/tee/sandbox.c create mode 100644 include/sandboxtee.h -- 2.17.1 Reviewed-by: Simon Glass diff --git a/drivers/tee/Kconfig b/drivers/tee/Kconfig index 835c256e9239..4697b80913d6 100644 --- a/drivers/tee/Kconfig +++ b/drivers/tee/Kconfig @@ -1,8 +1,8 @@ # Generic Trusted Execution Environment Configuration config TEE bool "Trusted Execution Environment support" - depends on ARM && (ARM64 || CPU_V7A) - select ARM_SMCCC + depends on (ARM && (ARM64 || CPU_V7A)) || SANDBOX + select ARM_SMCCC if ARM help This implements a generic interface towards a Trusted Execution Environment (TEE). A TEE is a trusted OS running in some secure @@ -14,6 +14,14 @@ if TEE menu "TEE drivers" +config SANDBOX_TEE + bool "Sandbox TEE emulator" + depends on SANDBOX + default y + help + This emulates a generic TEE needed for testing including the AVB + TA. + source "drivers/tee/optee/Kconfig" endmenu diff --git a/drivers/tee/Makefile b/drivers/tee/Makefile index 19633b60f235..f72c68c09f33 100644 --- a/drivers/tee/Makefile +++ b/drivers/tee/Makefile @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0+ obj-y += tee-uclass.o +obj-$(CONFIG_SANDBOX) += sandbox.o obj-$(CONFIG_OPTEE) += optee/ diff --git a/drivers/tee/optee/Kconfig b/drivers/tee/optee/Kconfig index dbfa7846a30f..d489834df926 100644 --- a/drivers/tee/optee/Kconfig +++ b/drivers/tee/optee/Kconfig @@ -10,7 +10,7 @@ config OPTEE handle Remote Procedure Calls (RPC) from OP-TEE needed to execute a service. For more information see: https://www.op-tee.org -if OPTEE +if OPTEE || SANDBOX menu "OP-TEE options" diff --git a/drivers/tee/sandbox.c b/drivers/tee/sandbox.c new file mode 100644 index 000000000000..cd073497615f --- /dev/null +++ b/drivers/tee/sandbox.c @@ -0,0 +1,299 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2018 Linaro Limited + */ +#include +#include +#include +#include +#include + +/* + * The sandbox tee driver tries to emulate a generic TEE with the TA + * OPTEE_TA_AVB available. + */ + +struct ta_entry { + struct tee_optee_ta_uuid uuid; + u32 (*open_session)(uint num_params, struct tee_param *params); + u32 (*invoke_func)(u32 func, uint num_params, struct tee_param *params); +}; + +#ifdef CONFIG_OPTEE_TA_AVB +static u32 get_attr(uint n, uint num_params, struct tee_param *params) +{ + if (n >= num_params) + return TEE_PARAM_ATTR_TYPE_NONE; + + return params[n].attr; +} + +static u32 check_params(u8 p0, u8 p1, u8 p2, u8 p3, uint num_params, + struct tee_param *params) +{ + u8 p[] = { p0, p1, p2, p3}; + uint n; + + for (n = 0; n < ARRAY_SIZE(p); n++) + if (p[n] != get_attr(n, num_params, params)) + goto bad_params; + + for (; n < num_params; n++) + if (get_attr(n, num_params, params)) + goto bad_params; + + return TEE_SUCCESS; + +bad_params: + printf("Bad param attrs\n"); + + return TEE_ERROR_BAD_PARAMETERS; +} + +static u64 ta_avb_rollback_indexes[TA_AVB_MAX_ROLLBACK_LOCATIONS]; +static u32 ta_avb_lock_state; + +static u32 ta_avb_open_session(uint num_params, struct tee_param *params) +{ + /* + * We don't expect additional parameters when opening a session to + * this TA. + */ + return check_params(TEE_PARAM_ATTR_TYPE_NONE, TEE_PARAM_ATTR_TYPE_NONE, + TEE_PARAM_ATTR_TYPE_NONE, TEE_PARAM_ATTR_TYPE_NONE, + num_params, params); +} + +static u32 ta_avb_invoke_func(u32 func, uint num_params, + struct tee_param *params) +{ + u32 res; + uint slot; + u64 val; + + switch (func) { + case TA_AVB_CMD_READ_ROLLBACK_INDEX: + res = check_params(TEE_PARAM_ATTR_TYPE_VALUE_INPUT, + TEE_PARAM_ATTR_TYPE_VALUE_OUTPUT, + TEE_PARAM_ATTR_TYPE_NONE, + TEE_PARAM_ATTR_TYPE_NONE, + num_params, params); + if (res) + return res; + + slot = params[0].u.value.a; + if (slot >= ARRAY_SIZE(ta_avb_rollback_indexes)) { + printf("Rollback index slot out of bounds %lu\n", slot); + return TEE_ERROR_BAD_PARAMETERS; + } + + val = ta_avb_rollback_indexes[slot]; + params[1].u.value.a = val >> 32; + params[1].u.value.b = val; + return TEE_SUCCESS; + + case TA_AVB_CMD_WRITE_ROLLBACK_INDEX: + res = check_params(TEE_PARAM_ATTR_TYPE_VALUE_INPUT, + TEE_PARAM_ATTR_TYPE_VALUE_INPUT, + TEE_PARAM_ATTR_TYPE_NONE, + TEE_PARAM_ATTR_TYPE_NONE, + num_params, params); + if (res) + return res; + + slot = params[0].u.value.a; + if (slot >= ARRAY_SIZE(ta_avb_rollback_indexes)) { + printf("Rollback index slot out of bounds %lu\n", slot); + return TEE_ERROR_BAD_PARAMETERS; + } + + val = (u64)params[1].u.value.a << 32 | params[1].u.value.b; + if (val < ta_avb_rollback_indexes[slot]) + return TEE_ERROR_SECURITY; + + ta_avb_rollback_indexes[slot] = val; + return TEE_SUCCESS; + + case TA_AVB_CMD_READ_LOCK_STATE: + res = check_params(TEE_PARAM_ATTR_TYPE_VALUE_OUTPUT, + TEE_PARAM_ATTR_TYPE_NONE, + TEE_PARAM_ATTR_TYPE_NONE, + TEE_PARAM_ATTR_TYPE_NONE, + num_params, params); + if (res) + return res; + + params[0].u.value.a = ta_avb_lock_state; + return TEE_SUCCESS; + + case TA_AVB_CMD_WRITE_LOCK_STATE: + res = check_params(TEE_PARAM_ATTR_TYPE_VALUE_INPUT, + TEE_PARAM_ATTR_TYPE_NONE, + TEE_PARAM_ATTR_TYPE_NONE, + TEE_PARAM_ATTR_TYPE_NONE, + num_params, params); + if (res) + return res; + + if (ta_avb_lock_state != params[0].u.value.a) { + ta_avb_lock_state = params[0].u.value.a; + memset(ta_avb_rollback_indexes, 0, + sizeof(ta_avb_rollback_indexes)); + } + + return TEE_SUCCESS; + + default: + return TEE_ERROR_NOT_SUPPORTED; + } +} +#endif /*OPTEE_TA_AVB*/ + +static const struct ta_entry ta_entries[] = { +#ifdef CONFIG_OPTEE_TA_AVB + { .uuid = TA_AVB_UUID, + .open_session = ta_avb_open_session, + .invoke_func = ta_avb_invoke_func, + }, +#endif +}; + +static void sandbox_tee_get_version(struct udevice *dev, + struct tee_version_data *vers) +{ + struct tee_version_data v = { + .gen_caps = TEE_GEN_CAP_GP | TEE_GEN_CAP_REG_MEM, + }; + + *vers = v; +} + +static int sandbox_tee_close_session(struct udevice *dev, u32 session) +{ + struct sandbox_tee_state *state = dev_get_priv(dev); + + if (!state->ta || state->session != session) + return -EINVAL; + + state->session = 0; + state->ta = NULL; + + return 0; +} + +static const struct ta_entry *find_ta_entry(u8 uuid[TEE_UUID_LEN]) +{ + struct tee_optee_ta_uuid u; + uint n; + + tee_optee_ta_uuid_from_octets(&u, uuid); + + for (n = 0; n < ARRAY_SIZE(ta_entries); n++) + if (!memcmp(&u, &ta_entries[n].uuid, sizeof(u))) + return ta_entries + n; + + return NULL; +} + +static int sandbox_tee_open_session(struct udevice *dev, + struct tee_open_session_arg *arg, + uint num_params, struct tee_param *params) +{ + struct sandbox_tee_state *state = dev_get_priv(dev); + const struct ta_entry *ta; + + if (state->ta) { + printf("A session is already open\n"); + return -EBUSY; + } + + ta = find_ta_entry(arg->uuid); + if (!ta) { + printf("Cannot find TA\n"); + arg->ret = TEE_ERROR_ITEM_NOT_FOUND; + arg->ret_origin = TEE_ORIGIN_TEE; + + return 0; + } + + arg->ret = ta->open_session(num_params, params); + arg->ret_origin = TEE_ORIGIN_TRUSTED_APP; + + if (!arg->ret) { + state->ta = (void *)ta; + state->session = 1; + arg->session = state->session; + } else { + printf("Cannot open session, TA returns error\n"); + } + + return 0; +} + +static int sandbox_tee_invoke_func(struct udevice *dev, + struct tee_invoke_arg *arg, + uint num_params, struct tee_param *params) +{ + struct sandbox_tee_state *state = dev_get_priv(dev); + struct ta_entry *ta = state->ta; + + if (!arg->session) { + printf("Missing session\n"); + return -EINVAL; + } + + if (!ta) { + printf("TA session not available\n"); + return -EINVAL; + } + + if (arg->session != state->session) { + printf("Session mismatch\n"); + return -EINVAL; + } + + arg->ret = ta->invoke_func(arg->func, num_params, params); + arg->ret_origin = TEE_ORIGIN_TRUSTED_APP; + + return 0; +} + +static int sandbox_tee_shm_register(struct udevice *dev, struct tee_shm *shm) +{ + struct sandbox_tee_state *state = dev_get_priv(dev); + + state->num_shms++; + + return 0; +} + +static int sandbox_tee_shm_unregister(struct udevice *dev, struct tee_shm *shm) +{ + struct sandbox_tee_state *state = dev_get_priv(dev); + + state->num_shms--; + + return 0; +} + +static const struct tee_driver_ops sandbox_tee_ops = { + .get_version = sandbox_tee_get_version, + .open_session = sandbox_tee_open_session, + .close_session = sandbox_tee_close_session, + .invoke_func = sandbox_tee_invoke_func, + .shm_register = sandbox_tee_shm_register, + .shm_unregister = sandbox_tee_shm_unregister, +}; + +static const struct udevice_id sandbox_tee_match[] = { + { .compatible = "sandbox,tee" }, + {}, +}; + +U_BOOT_DRIVER(sandbox_tee) = { + .name = "sandbox_tee", + .id = UCLASS_TEE, + .of_match = sandbox_tee_match, + .ops = &sandbox_tee_ops, + .priv_auto_alloc_size = sizeof(struct sandbox_tee_state), +}; diff --git a/include/sandboxtee.h b/include/sandboxtee.h new file mode 100644 index 000000000000..59cbb621820b --- /dev/null +++ b/include/sandboxtee.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright (C) 2018 Linaro Limited + */ + +#ifndef __SANDBOXTEE_H +#define __SANDBOXTEE_H + +struct sandbox_tee_state { + u32 session; + int num_shms; + void *ta; +}; + +#endif /*__SANDBOXTEE_H*/ From patchwork Mon Sep 3 14:47:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 145813 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp2575746ljw; Mon, 3 Sep 2018 07:47:43 -0700 (PDT) X-Received: by 2002:a19:d8e8:: with SMTP id r101-v6mr15135018lfi.37.1535986063076; Mon, 03 Sep 2018 07:47:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535986063; cv=none; d=google.com; s=arc-20160816; b=l2XElDcYr9RfN27YrqOPTd7RQqmhx/PU0Pvh91jxhYYozelRE3OGgt9Smbqffo8Nj3 zhnj4/Wz16ktZ2+Q8NnzXFh9ZRFb/weVWOLCgh8+14icHRXfB4aPXkcp/NJEGrsyg6jM JDGQtpjBVrOgZelTMrGH1Z5ARUjmrGwhmXgDiO3xyNCZLFRbaOkFc8/v+YXKKJ+5kW3p lHIPW0gN4GXZ+3277adDxmjkwr5gJnlWN9Ka6jL+R8LdKGMq4qndKFQE9NdexQAg8Mbi rudWLb9ush2Cv0CVOakugrfhI0GBJLab7Rcmf6Q9/BPuG0USWJvHMMv2wfyp+YZEzWD8 Kf1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=FcKSr3CcUrmQby50WWO6yYfiPcftKiNgb0CZ3KdNkSM=; b=ZoRbvtPyaz34sJBXQLPMCFhDkeC+pUthuLuWqxGa2CQkThsFpiL50jlZ5J5KMc6C1E XqRe2UPCPt0cGGWBHq04xL0BXWF+uVrEZkmIr2CQwsOuAg/Xes4sZQLZ4leRo4J9SgAs DudwSu7epAun2+TuXDNU9IlmNU1SWHkCk+EZHpTnzCwakkKSVIZzVV9hPiEMsXK22IaA xnnuzYIoGBRVHKDBDF6FkvvqK31Y7AlgwOFGjKNSZUjmFgf6vQRUf5pRqd2hNvolMD4p KkY2F3bA6isAn8TFibZXikGheUU4XraTrtk+bCtNgVWohQgDAruvXwlVFZB9q+X9pygg ZbiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W04cEQ5R; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id c4-v6sor7957990lja.3.2018.09.03.07.47.42 for (Google Transport Security); Mon, 03 Sep 2018 07:47:43 -0700 (PDT) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W04cEQ5R; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=FcKSr3CcUrmQby50WWO6yYfiPcftKiNgb0CZ3KdNkSM=; b=W04cEQ5R0O6c/H5ZjEpU6uxqeboIhz1b4vC4LUHawR8Veq5f0ij50TF1EiRyXFN/Hb gj9QNr2aXcX6LuRTwyX9ocKm3g+g1iJCJ3qwpy8bAD5rlM6pHzTGb5aXCKAh112ngOqQ gHOJvyfopK9Hk9QaL8p4bpKldsYW5RaKhajgM= 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=FcKSr3CcUrmQby50WWO6yYfiPcftKiNgb0CZ3KdNkSM=; b=gcqud8K0kT98GXOggomp3s3+ZQP9m9zKR4AGE+2+8o3ektjtEONPVQJoOuNd1X+cnf x8PknLOeskljuvFCch/FB+F9Eke/hu+jBjSzmeUBYmeySxtIXN5eP51lJHz/0u8PQuGj hiLl+Tf9VE/O3vMj2HjSD/YOCzh+0kyqXLV3Edny8B8+O81RJryU+M959Q4pkwt/GmeM pfr2MG0sLHtBn22JBxIubqNhdv3gdHteKRD4Crh5XcpAGY91G/wlhI44WauS7gZ2pcSJ WpZ/q46gGQCwZpFXVp/p7ZtMtWMR7/l1opLxu0JtnBsaMKlCsVJBTnaMzDfL9t5uh7b7 Cp0g== X-Gm-Message-State: APzg51DaxL6VZHtjkDbLPRwaYK3J/2hHX6iUHT3TPg0fHrk23DsITt3c sH9Y9FXBCMfAYywiJWyGdnNO3tJp X-Google-Smtp-Source: ANB0VdY3ROUO14RnczTIPC45eE59pczrOTcUGSErLtGUhkOuHC0BXAQ2ebXoHscZYBoVX87bQjyHqg== X-Received: by 2002:a2e:8098:: with SMTP id i24-v6mr17489911ljg.36.1535986062807; Mon, 03 Sep 2018 07:47:42 -0700 (PDT) Return-Path: Received: from jax.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id w18-v6sm3343431ljd.73.2018.09.03.07.47.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Sep 2018 07:47:42 -0700 (PDT) From: Jens Wiklander To: u-boot@lists.denx.de Cc: Simon Glass , Igor Opaniuk , Tom Rini , Jaehoon Chung , Pierre Aubert , Albert Aribaud , Peter Griffin , Michal Simek , Jens Wiklander Subject: [PATCH v3 16/20] test: tee: test TEE uclass Date: Mon, 3 Sep 2018 16:47:07 +0200 Message-Id: <20180903144711.31585-17-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180903144711.31585-1-jens.wiklander@linaro.org> References: <20180903144711.31585-1-jens.wiklander@linaro.org> Tests the TEE uclass with a sandbox tee driver. Reviewed-by: Simon Glass Signed-off-by: Jens Wiklander --- test/dm/Makefile | 1 + test/dm/tee.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 test/dm/tee.c -- 2.17.1 diff --git a/test/dm/Makefile b/test/dm/Makefile index d2ed96c61533..272374b92fb0 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -44,4 +44,5 @@ obj-$(CONFIG_DM_VIDEO) += video.o obj-$(CONFIG_ADC) += adc.o obj-$(CONFIG_SPMI) += spmi.o obj-$(CONFIG_WDT) += wdt.o +obj-$(CONFIG_TEE) += tee.o endif diff --git a/test/dm/tee.c b/test/dm/tee.c new file mode 100644 index 000000000000..ab1c7da9d2d3 --- /dev/null +++ b/test/dm/tee.c @@ -0,0 +1,98 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2018 Linaro Limited + */ + +#include +#include +#include +#include +#include +#include +#include + +static int open_session(struct udevice *dev, u32 *session) +{ + struct tee_open_session_arg arg; + const struct tee_optee_ta_uuid uuid = TA_AVB_UUID; + int rc; + + memset(&arg, 0, sizeof(arg)); + tee_optee_ta_uuid_to_octets(arg.uuid, &uuid); + rc = tee_open_session(dev, &arg, 0, NULL); + if (rc) + return rc; + if (arg.ret) + return -EIO; + *session = arg.session; + + return 0; +} + +static int invoke_func(struct udevice *dev, u32 session) +{ + struct tee_param param = { .attr = TEE_PARAM_ATTR_TYPE_VALUE_OUTPUT }; + struct tee_invoke_arg arg; + + memset(&arg, 0, sizeof(arg)); + arg.session = session; + arg.func = TA_AVB_CMD_READ_LOCK_STATE; + + if (tee_invoke_func(dev, &arg, 1, ¶m) || arg.ret) + return -1; + + return 0; +} + +static int match(struct tee_version_data *vers, const void *data) +{ + return vers->gen_caps & TEE_GEN_CAP_GP; +} + +static int dm_test_tee(struct unit_test_state *uts) +{ + struct tee_version_data vers; + struct udevice *dev; + struct sandbox_tee_state *state; + u32 session; + int rc; + u8 data[128]; + struct tee_shm *reg_shm; + struct tee_shm *alloc_shm; + + dev = tee_find_device(NULL, match, NULL, &vers); + ut_assert(dev); + state = dev_get_priv(dev); + ut_assert(!state->session); + + rc = open_session(dev, &session); + ut_assert(!rc); + ut_assert(session == state->session); + + rc = invoke_func(dev, session); + ut_assert(!rc); + + rc = tee_close_session(dev, session); + ut_assert(!rc); + ut_assert(!state->session); + + ut_assert(!state->num_shms); + rc = tee_shm_register(dev, data, sizeof(data), 0, ®_shm); + ut_assert(!rc); + ut_assert(state->num_shms == 1); + + rc = tee_shm_alloc(dev, 256, 0, &alloc_shm); + ut_assert(!rc); + ut_assert(state->num_shms == 2); + + ut_assert(tee_shm_is_registered(reg_shm, dev)); + ut_assert(tee_shm_is_registered(alloc_shm, dev)); + + tee_shm_free(reg_shm); + tee_shm_free(alloc_shm); + ut_assert(!state->num_shms); + + return 0; +} + +DM_TEST(dm_test_tee, DM_TESTF_SCAN_FDT); From patchwork Mon Sep 3 14:47:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 145814 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp2575778ljw; Mon, 3 Sep 2018 07:47:44 -0700 (PDT) X-Received: by 2002:a2e:29da:: with SMTP id p87-v6mr16981352ljp.12.1535986064541; Mon, 03 Sep 2018 07:47:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535986064; cv=none; d=google.com; s=arc-20160816; b=tm1wboLtcUPjW+zbvrWCjU2fJ4V5ntHid6ulI8yH/91dcr4LdLOsi2a4akXxHzqvOD oiD6OPyfKO+EMw6tw+zjngpqMp/fleUnRsx/EHM2rp/Ebp6DnlNBKt/HYWCeR/YxVFPf TgvF8wrce01FXhNIKG5PkqkiOa/NEaXEnIs5unR/umGJfO89CGcJ4OiRVgRUd9xt/8es PHAsLYSUoULvLrwB+BfGa1W62PB0Irfk0ox7wS6rBG5C2Tbpiqbf1+MKCltCzSd0QJL5 GpbYoNKEnW1BASZmY6sL08s0z0QBauk9eyuWJKMXWPL/yKy5Ue+NqcaG9FOHVjFI2goc cj6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=XTd773w5P/Vj46SmIQFS3d5zP1Ly1I9xPhd1cY5R27M=; b=mA4WBr1/ZDmaDOzv4J3pBFxVCAvLs04443szdh2nmjm7GR/f7pOrt6l/7abFNXcFjX gXCf0lRfcvCvwmdKgUGNSlIjKFMFDAjQofRCuYg/qC/hPK97nDsaM9eS/LLfwJ3d/H++ /685VZXrdXhvOSlh43dysiVuDi2mTpg6Hgf9LzGYnX778LRpywh9k2FwNjYHrf6vtTz4 tYczD8fGumeyRrMRCje9eWD/Gi+2zT7kJWwwd/0ETWxOuoi7jEKn/yg1hquKwYwFor6U 9vGo2ZdpuU2CWPRjSQlQCNT9w2JxKPkB7GsrHsND+3ZbuKeMJv96hd0G8RfaY2WGa2ZL BfAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H0k1F+j6; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id x15-v6sor5176970lfb.12.2018.09.03.07.47.44 for (Google Transport Security); Mon, 03 Sep 2018 07:47:44 -0700 (PDT) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H0k1F+j6; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=XTd773w5P/Vj46SmIQFS3d5zP1Ly1I9xPhd1cY5R27M=; b=H0k1F+j6UZKmlcnquFAyZEfoW3mZRuy4fodoIw27XK4KitFaqnn9XE7mZ41YqT2/KZ d8WeItLOD69bym0z2/VhowRTmrRpz/z3JMfoDH5pE0mNAdwNBBn7kz9oXL9WFUSomlvG Hr1BGfdULiQUyRb4afM6St2MMbz/HeAjjUq9Q= 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=XTd773w5P/Vj46SmIQFS3d5zP1Ly1I9xPhd1cY5R27M=; b=s6SKPHtgqWbWwIBliqHaVWtMCnytLUZZt78v6AtVQW9mKkHq2ql/iNdu6kmNq2HS4g AUHZw9lJmvNVN42gvPpOb04+sR8vZ1PY/YfVgtSXZjQ183GF//no1bzdY13xxcizr1zc k9Y+AsudklGvT+7gYg3qlU+HKqN6A+QzQ/OygW2kIHRa9lohLm65UHKG21f/Q4eh3kCW uukk3iWw22T60pZX+UVialD4RoSCuhebHiSCXSXl5ROrMWvCyCm7xkHfd69Tnk/eQn0Q PVknTSiQrcNfY5cTeB0cyrSY7SgWMlspXgILG3o5mluDI1GFER+vAv8ZDdMNhYVcFLTy dWUw== X-Gm-Message-State: APzg51C1GMt+DeviYzjaeH/q9ciLCsItPRFR6XrZHwybo+uZQtEbYP5w cRqCh9+/okulljdWLXAIFjV9C2iu X-Google-Smtp-Source: ANB0VdbsK0kEnw8ffZzliZrGc4gPiZzkOswfDvj0n+9IacVjgq9JgT87sPlQBBohctA+TSQLyLU+rg== X-Received: by 2002:a19:3bd4:: with SMTP id d81-v6mr17052195lfl.96.1535986064258; Mon, 03 Sep 2018 07:47:44 -0700 (PDT) Return-Path: Received: from jax.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id w18-v6sm3343431ljd.73.2018.09.03.07.47.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Sep 2018 07:47:43 -0700 (PDT) From: Jens Wiklander To: u-boot@lists.denx.de Cc: Simon Glass , Igor Opaniuk , Tom Rini , Jaehoon Chung , Pierre Aubert , Albert Aribaud , Peter Griffin , Michal Simek , Jens Wiklander Subject: [PATCH v3 17/20] avb_verify: support using OP-TEE TA AVB Date: Mon, 3 Sep 2018 16:47:08 +0200 Message-Id: <20180903144711.31585-18-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180903144711.31585-1-jens.wiklander@linaro.org> References: <20180903144711.31585-1-jens.wiklander@linaro.org> With CONFIG_OPTEE_TA_AVB use the trusted application AVB provided by OP-TEE to manage rollback indexes and device lock status. Signed-off-by: Jens Wiklander --- common/avb_verify.c | 118 ++++++++++++++++++++++++++++++++++++++++++- doc/README.avb2 | 13 +++++ include/avb_verify.h | 4 ++ 3 files changed, 134 insertions(+), 1 deletion(-) -- 2.17.1 Reviewed-by: Simon Glass diff --git a/common/avb_verify.c b/common/avb_verify.c index 3a1282a09204..c2248c92514e 100644 --- a/common/avb_verify.c +++ b/common/avb_verify.c @@ -10,6 +10,8 @@ #include #include #include +#include +#include const unsigned char avb_root_pub[1032] = { 0x0, 0x0, 0x10, 0x0, 0x55, 0xd9, 0x4, 0xad, 0xd8, 0x4, @@ -594,6 +596,65 @@ static AvbIOResult validate_vbmeta_public_key(AvbOps *ops, return AVB_IO_RESULT_OK; } +#ifdef CONFIG_OPTEE_TA_AVB +static int get_open_session(struct AvbOpsData *ops_data) +{ + struct udevice *tee = NULL; + + while (!ops_data->tee) { + const struct tee_optee_ta_uuid uuid = TA_AVB_UUID; + struct tee_open_session_arg arg; + int rc; + + tee = tee_find_device(tee, NULL, NULL, NULL); + if (!tee) + return -ENODEV; + + memset(&arg, 0, sizeof(arg)); + tee_optee_ta_uuid_to_octets(arg.uuid, &uuid); + rc = tee_open_session(tee, &arg, 0, NULL); + if (!rc) { + ops_data->tee = tee; + ops_data->session = arg.session; + } + } + + return 0; +} + +static AvbIOResult invoke_func(struct AvbOpsData *ops_data, u32 func, + ulong num_param, struct tee_param *param) +{ + struct tee_invoke_arg arg; + + if (get_open_session(ops_data)) + return AVB_IO_RESULT_ERROR_IO; + + memset(&arg, 0, sizeof(arg)); + arg.func = func; + arg.session = ops_data->session; + + if (tee_invoke_func(ops_data->tee, &arg, num_param, param)) + return AVB_IO_RESULT_ERROR_IO; + switch (arg.ret) { + case TEE_SUCCESS: + return AVB_IO_RESULT_OK; + case TEE_ERROR_OUT_OF_MEMORY: + return AVB_IO_RESULT_ERROR_OOM; + case TEE_ERROR_TARGET_DEAD: + /* + * The TA has paniced, close the session to reload the TA + * for the next request. + */ + tee_close_session(ops_data->tee, ops_data->session); + ops_data->tee = NULL; + return AVB_IO_RESULT_ERROR_IO; + default: + return AVB_IO_RESULT_ERROR_IO; + } +} +#endif + /** * read_rollback_index() - gets the rollback index corresponding to the * location of given by @out_rollback_index. @@ -609,6 +670,7 @@ static AvbIOResult read_rollback_index(AvbOps *ops, size_t rollback_index_slot, u64 *out_rollback_index) { +#ifndef CONFIG_OPTEE_TA_AVB /* For now we always return 0 as the stored rollback index. */ printf("%s not supported yet\n", __func__); @@ -616,6 +678,27 @@ static AvbIOResult read_rollback_index(AvbOps *ops, *out_rollback_index = 0; return AVB_IO_RESULT_OK; +#else + AvbIOResult rc; + struct tee_param param[2]; + + if (rollback_index_slot >= TA_AVB_MAX_ROLLBACK_LOCATIONS) + return AVB_IO_RESULT_ERROR_NO_SUCH_VALUE; + + memset(param, 0, sizeof(param)); + param[0].attr = TEE_PARAM_ATTR_TYPE_VALUE_INPUT; + param[0].u.value.a = rollback_index_slot; + param[1].attr = TEE_PARAM_ATTR_TYPE_VALUE_OUTPUT; + + rc = invoke_func(ops->user_data, TA_AVB_CMD_READ_ROLLBACK_INDEX, + ARRAY_SIZE(param), param); + if (rc) + return rc; + + *out_rollback_index = (u64)param[1].u.value.a << 32 | + (u32)param[1].u.value.b; + return AVB_IO_RESULT_OK; +#endif } /** @@ -633,10 +716,27 @@ static AvbIOResult write_rollback_index(AvbOps *ops, size_t rollback_index_slot, u64 rollback_index) { +#ifndef CONFIG_OPTEE_TA_AVB /* For now this is a no-op. */ printf("%s not supported yet\n", __func__); return AVB_IO_RESULT_OK; +#else + struct tee_param param[2]; + + if (rollback_index_slot >= TA_AVB_MAX_ROLLBACK_LOCATIONS) + return AVB_IO_RESULT_ERROR_NO_SUCH_VALUE; + + memset(param, 0, sizeof(param)); + param[0].attr = TEE_PARAM_ATTR_TYPE_VALUE_INPUT; + param[0].u.value.a = rollback_index_slot; + param[1].attr = TEE_PARAM_ATTR_TYPE_VALUE_INPUT; + param[1].u.value.a = (u32)(rollback_index >> 32); + param[1].u.value.b = (u32)rollback_index; + + return invoke_func(ops->user_data, TA_AVB_CMD_WRITE_ROLLBACK_INDEX, + ARRAY_SIZE(param), param); +#endif } /** @@ -652,6 +752,7 @@ static AvbIOResult write_rollback_index(AvbOps *ops, */ static AvbIOResult read_is_device_unlocked(AvbOps *ops, bool *out_is_unlocked) { +#ifndef CONFIG_OPTEE_TA_AVB /* For now we always return that the device is unlocked. */ printf("%s not supported yet\n", __func__); @@ -659,6 +760,16 @@ static AvbIOResult read_is_device_unlocked(AvbOps *ops, bool *out_is_unlocked) *out_is_unlocked = true; return AVB_IO_RESULT_OK; +#else + AvbIOResult rc; + struct tee_param param = { .attr = TEE_PARAM_ATTR_TYPE_VALUE_OUTPUT }; + + rc = invoke_func(ops->user_data, TA_AVB_CMD_READ_LOCK_STATE, 1, ¶m); + if (rc) + return rc; + *out_is_unlocked = !param.u.value.a; + return AVB_IO_RESULT_OK; +#endif } /** @@ -737,6 +848,11 @@ void avb_ops_free(AvbOps *ops) ops_data = ops->user_data; - if (ops_data) + if (ops_data) { +#ifdef CONFIG_OPTEE_TA_AVB + if (ops_data->tee) + tee_close_session(ops_data->tee, ops_data->session); +#endif avb_free(ops_data); + } } diff --git a/doc/README.avb2 b/doc/README.avb2 index 120279fedbe2..a29cee1b6f50 100644 --- a/doc/README.avb2 +++ b/doc/README.avb2 @@ -18,6 +18,13 @@ Integrity of the bootloader (U-boot BLOB and environment) is out of scope. For additional details check: https://android.googlesource.com/platform/external/avb/+/master/README.md +1.1. AVB using OP-TEE (optional) +--------------------------------- +If AVB is configured to use OP-TEE (see 4. below) rollback indexes and +device lock state are stored in RPMB. The RPMB partition is managed by +OP-TEE (https://www.op-tee.org/) which is a secure OS leveraging ARM +TrustZone. + 2. AVB 2.0 U-BOOT SHELL COMMANDS ----------------------------------- @@ -61,6 +68,12 @@ CONFIG_LIBAVB=y CONFIG_AVB_VERIFY=y CONFIG_CMD_AVB=y +In addtion optionally if storing rollback indexes in RPMB with help of +OP-TEE: +CONFIG_TEE=y +CONFIG_OPTEE=y +CONFIG_OPTEE_TA_AVB=y +CONFIG_SUPPORT_EMMC_RPMB=y Then add `avb verify` invocation to your android boot sequence of commands, e.g.: diff --git a/include/avb_verify.h b/include/avb_verify.h index eaa60f5393ef..a532a2331aea 100644 --- a/include/avb_verify.h +++ b/include/avb_verify.h @@ -27,6 +27,10 @@ struct AvbOpsData { struct AvbOps ops; int mmc_dev; enum avb_boot_state boot_state; +#ifdef CONFIG_OPTEE_TA_AVB + struct udevice *tee; + u32 session; +#endif }; struct mmc_part { From patchwork Mon Sep 3 14:47:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 145815 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp2575803ljw; Mon, 3 Sep 2018 07:47:45 -0700 (PDT) X-Received: by 2002:a19:518a:: with SMTP id g10-v6mr19071833lfl.136.1535986065903; Mon, 03 Sep 2018 07:47:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535986065; cv=none; d=google.com; s=arc-20160816; b=HphnLo8SOMdAks9DHd1Lo6f/qqbudinBk7mekD9od4ALJcCB6xnZ/b7nKJvwKn6WOi vS0aJKsoFOb4LdvIgCD0BL5uVIgPGYgVNk7jJMlRcv56Gr5A61sUCOsRp+ddiKRtKCJP A6ayaflQSiwIKdrDT7ZgcilKfiwgqR8g/bTmNEBeGScdswvPshWgJkwvxJ5a4O9L03EX eeuE3YVkfPAhk4bzWj3Kr4Gsi4a0zvfElHgCd1zAkJXyqUfd9webYoLLKIbIA+Af2cJj i9lpagb/tF/LIN0T02wp7IcsHWMBbuo8wYHVfjaKSrNKfjfbisouCSPPI1gMYztR90aU K5hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=03hhEu2LryTx21ANDAijIfGtWXxx5DEz2AuJb6OPMvg=; b=mIW340/2VBatRmWEt1WfAu7tPnCRqA7PQKFyRCw4AyURZXEx7syL9OC9oq28G0g2/y kQyOmOzCXuj9gxyiScIdf1oHqyo98R79zU9FRVYD2MTz0heytfMiR3HeYsOgFO/qUf7c JeTYb97iIV89lmRCzdQwmd82h+nWOUfQAnCq9wp+VA0gQomi16U8IKpPV0/mcnM04X1V JL54fcRcCzKemMeIyhtRyGIAV9QYiBbbrjiFwbZ2QyenU+UtNolN4P2GQQKBDITKelDa WTOTR4DTtctu+0r++sGq+1xBdf7b7wcUuiMDIQ46IOzwbaFYh3/ptAB4zzNSUQ8qt+82 Q83w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ds1QY3VH; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id g95-v6sor7936231ljg.32.2018.09.03.07.47.45 for (Google Transport Security); Mon, 03 Sep 2018 07:47:45 -0700 (PDT) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ds1QY3VH; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=03hhEu2LryTx21ANDAijIfGtWXxx5DEz2AuJb6OPMvg=; b=ds1QY3VHJ/l0m5f04sw36fhi9C/ZoMcOxqCefb0F+jwRx/bTDyqcyt1Xq/D34OXEtO hiPw3n0R1WrYYjoWk7YCSqg0U45HK/tcJ555A5wsmukEAp2Vda5wi5IDGfCoBJaEgvmi nlBE4XIDgzWnI38brXDywj6Bvxl6sokY4RXPM= 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=03hhEu2LryTx21ANDAijIfGtWXxx5DEz2AuJb6OPMvg=; b=fRpH72c3EWcPqY2ry5Ow2S/w6bVwCimT5dHNJ0z3lb0TPsbRoZ8hlyZ5RCYs4KHMA4 YC9kdqNJF3yTmOP7Zm2JpG3P8wJuf1//lUIpwPKx0GAbb71je2xBLB3LlsCPVXvnyBqx iaQMdM+PCTcpS3VEBMLNi/1Bdh0wEQMASu9Lm/NT357eB54l8w/aoQUilnAgpJZ326Ee n4SsPSUQYStb5OkVUoCVrWZ13+XnF3dFKBRoHXbDUrR/LLDAtyxPYGOk3YOss4Cq6AK5 yp5TS/1HbKlbX2hAdYlx9bU0YcQECyJrHlKVoOsId2oQ1Fasbu+pr57TPB7dDkWjRpNx AHSQ== X-Gm-Message-State: APzg51Bvqo8RJqZjn1It1duPBRMUL1h/8AzciLwVh4RtsJTyaU8wuAyU 68MY7pI+wfVohYHugejV+B63nGLB X-Google-Smtp-Source: ANB0VdbtY1oHs/omqU6ZX+BM+PaFUaa882d+HNBJ9I2pQ4N5B0Ov4gpJ2SXQ3lr70Y2OHEwSbezSQQ== X-Received: by 2002:a2e:8257:: with SMTP id j23-v6mr17292818ljh.49.1535986065709; Mon, 03 Sep 2018 07:47:45 -0700 (PDT) Return-Path: Received: from jax.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id w18-v6sm3343431ljd.73.2018.09.03.07.47.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Sep 2018 07:47:44 -0700 (PDT) From: Jens Wiklander To: u-boot@lists.denx.de Cc: Simon Glass , Igor Opaniuk , Tom Rini , Jaehoon Chung , Pierre Aubert , Albert Aribaud , Peter Griffin , Michal Simek , Jens Wiklander Subject: [PATCH v3 18/20] test_avb: Update pymark.buildconfigspec information for the AVB tests Date: Mon, 3 Sep 2018 16:47:09 +0200 Message-Id: <20180903144711.31585-19-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180903144711.31585-1-jens.wiklander@linaro.org> References: <20180903144711.31585-1-jens.wiklander@linaro.org> Update the pymark.buildconfigspec to depend on 'cmd_mmc' in addition to 'cmd_avb' for those tests that needs more a more complete MMC implementation or the "mmc" command. Signed-off-by: Jens Wiklander --- test/py/tests/test_avb.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) -- 2.17.1 Reviewed-by: Simon Glass diff --git a/test/py/tests/test_avb.py b/test/py/tests/test_avb.py index 7996e4845db3..9683fd80d074 100644 --- a/test/py/tests/test_avb.py +++ b/test/py/tests/test_avb.py @@ -23,7 +23,7 @@ mmc_dev = 1 temp_addr = 0x90000000 temp_addr2 = 0x90002000 -@pytest.mark.buildconfigspec('cmd_avb') +@pytest.mark.buildconfigspec('cmd_avb', 'cmd_mmc') def test_avb_verify(u_boot_console): """Run AVB 2.0 boot verification chain with avb subset of commands """ @@ -36,7 +36,7 @@ def test_avb_verify(u_boot_console): assert response.find(success_str) -@pytest.mark.buildconfigspec('cmd_avb') +@pytest.mark.buildconfigspec('cmd_avb', 'cmd_mmc') def test_avb_mmc_uuid(u_boot_console): """Check if 'avb get_uuid' works, compare results with 'part list mmc 1' output @@ -78,6 +78,7 @@ def test_avb_read_rb(u_boot_console): assert response == '' response = u_boot_console.run_command('avb read_rb 1') + assert response == 'Rollback index: 0' @pytest.mark.buildconfigspec('cmd_avb') @@ -89,9 +90,10 @@ def test_avb_is_unlocked(u_boot_console): assert response == '' response = u_boot_console.run_command('avb is_unlocked') + assert response == 'Unlocked = 1' -@pytest.mark.buildconfigspec('cmd_avb') +@pytest.mark.buildconfigspec('cmd_avb', 'cmd_mmc') def test_avb_mmc_read(u_boot_console): """Test mmc read operation """ From patchwork Mon Sep 3 14:47:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 145816 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp2575819ljw; Mon, 3 Sep 2018 07:47:47 -0700 (PDT) X-Received: by 2002:a19:a401:: with SMTP id q1-v6mr18888158lfc.111.1535986067917; Mon, 03 Sep 2018 07:47:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535986067; cv=none; d=google.com; s=arc-20160816; b=UU9qYpVUNiTgH4rQb7ODJHAcMXdXN/UHMcqhWKQxSjVS/f4xkHBK5I3yS0ys8dlB9C wUJSDxQiVJMo+gDUgtCU5cmL2HirY0ChrepGrYOBM4zSDKOcgILIsXeobphqXERBe9Y9 9AZ+KxOQ+f/ad9vI7vd74WH8t4PPq37WSHdPWlTZbGjzzoXs6eIARyVUu4DJ96u61dIw KXGZAFiANgA3KvkdiKVQHU2sp1IFRytSR/Y2+f50C7tDcXlPlValN/+rRvZsu0TNDa3r 4rQo1hy2TojYbrIEfKrF27l3x38xr+mAljdL621JYbv464H0TIiDHzLnRqFPik2MR750 zfDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=+9FSrqWNL25MdQ9/5naOwcGq3yhUTI1TrXp3fXXUVJ0=; b=OMfyAM5aD8lmvaCcLk6HhyruXOAEESiBd0nnxSKdcRmh1v4XGAFThGbbfyy0n06Wek bAO2q2MhMZfMaIkR4ePnGzpb0MfkH2p+O6jFB972fk6O+9X7dno4G161qiqOSZBoTUw1 vW5perQEaDil23q4zoa79I50tvxaUXfBZQ1p8r39tEbDkxXnM28wXHkvWzskOmg1gJp/ RfTBFgMTfv0BLarvyTfyzxk3DszGXa2TKy6sx7cExgEQNfDA2A+NxhQgUA5QTRF2iUAY SE4fJqwi1rDqkm/eJg8YZrSR/TraYdH9G+8WwmV5F5SqE5GdoKm7YakD0bYXpQ5+Hahj EM1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RxnWZdrv; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id q5-v6sor5309770lff.24.2018.09.03.07.47.47 for (Google Transport Security); Mon, 03 Sep 2018 07:47:47 -0700 (PDT) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RxnWZdrv; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=+9FSrqWNL25MdQ9/5naOwcGq3yhUTI1TrXp3fXXUVJ0=; b=RxnWZdrvNuPSQ/nCdH5DcM92yH/qCtcWXmcnRisPjZKTA5Y3qw0nNHa6YMd76rpcEX lBpsoeBhMAyHMNwLAD7iqANBARxLWfWb5TFXRXoZL1+cMTHv1sjw2nvco3Dpw6AbWFhX Ddq9K8FY7vYIwpLLcoG8ybBikfDe5xvG0pEyM= 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=+9FSrqWNL25MdQ9/5naOwcGq3yhUTI1TrXp3fXXUVJ0=; b=pgxqXO2WvAwhf4VwNud8J6FuyKlhkyVhuMXpMyjHoJvGayyKpQJh+jYNtX48LQ9i3k 9Ao+3+giFl/f0rCzfQYpaQqTf6Wj7B1kD4XmqZT+Wbgtl7KJy+BJzMesgo0QNdBbTo0u qaaSEdJFHMsewoHwxWnVeF1buSRlg0Xg6uFuhDPdMb5qwrIuHHtcYqbL8Ox5Oh5tsemG v/zFLNams+tgzbwPIuSg37yhbWmXXLTgkm1MAbqPadSYUNESXyOrMXnizROULRBSbNfO Ca9sbiKFwVqLKo/SpMFCBT9n/nHia+St/pZV/ALti3vPhbsee18gEa7CPHh8ciRCxitZ OqDg== X-Gm-Message-State: APzg51DGrMBqvEMPQh2d/ZKsJpOTdkVji1Syo4cfwDpsuhF7rO1ox7lO D5J1AmxAztZ2gKZ9C4sAwj59xLER5kk9Vw== X-Google-Smtp-Source: ANB0Vda255/mLWrKJC0UH5QBc2DqudIF5D/1yRY7HeVYQPbKvrgBRI5cRCsXCw3fMYSji771Smz/9g== X-Received: by 2002:a19:c5:: with SMTP id 188-v6mr17565350lfa.45.1535986067739; Mon, 03 Sep 2018 07:47:47 -0700 (PDT) Return-Path: Received: from jax.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id w18-v6sm3343431ljd.73.2018.09.03.07.47.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Sep 2018 07:47:46 -0700 (PDT) From: Jens Wiklander To: u-boot@lists.denx.de Cc: Simon Glass , Igor Opaniuk , Tom Rini , Jaehoon Chung , Pierre Aubert , Albert Aribaud , Peter Griffin , Michal Simek , Jens Wiklander Subject: [PATCH v3 19/20] avb_verify: support sandbox configuration Date: Mon, 3 Sep 2018 16:47:10 +0200 Message-Id: <20180903144711.31585-20-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180903144711.31585-1-jens.wiklander@linaro.org> References: <20180903144711.31585-1-jens.wiklander@linaro.org> With CONFIG_SANDBOX malloc a buffer in get_sector_buf() and return that instead of returning CONFIG_FASTBOOT_BUF_ADDR since there's no such buffer reserved. Signed-off-by: Jens Wiklander --- include/avb_verify.h | 9 +++++++++ 1 file changed, 9 insertions(+) -- 2.17.1 diff --git a/include/avb_verify.h b/include/avb_verify.h index a532a2331aea..7b95409d247e 100644 --- a/include/avb_verify.h +++ b/include/avb_verify.h @@ -76,7 +76,16 @@ static inline size_t get_sector_buf_size(void) static inline void *get_sector_buf(void) { +#ifdef CONFIG_SANDBOX + static void *p; + + if (!p) + p = avb_malloc_(get_sector_buf_size()); + + return p; +#else return (void *)CONFIG_FASTBOOT_BUF_ADDR; +#endif } static inline bool is_buf_unaligned(void *buffer) From patchwork Mon Sep 3 14:47:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 145817 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp2575846ljw; Mon, 3 Sep 2018 07:47:49 -0700 (PDT) X-Received: by 2002:a2e:29da:: with SMTP id p87-v6mr16981519ljp.12.1535986069345; Mon, 03 Sep 2018 07:47:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535986069; cv=none; d=google.com; s=arc-20160816; b=Xr2bDpoziIU13dhky1A5qGrHcJtP88zWC+0nAXTSSL8K2xtC7+nsXrZdpAVctXltMf C9we9sFzQyn+Gupt8FnML4cBEQ7dyRwYw6dgkmtIiE/zs6CvfgFZ1ewT8BnteA0KVEck j/HU7/R/7uR5B66esPFc+aELXmnge8mgxcN6koLOWWuBOCrlB2WvhLo5IrwScx2UBOQD aqN4ox1A8oBeYie2foFHK6CeQ/tOKDvkuD5KWySPnaZ9WQEDka9nrBCpKF8vK1zUfrnp xmyYVOEfaXQK7ySw2uDcScPbdvlb5Ym+Tcrhne4az5g0xGrr8xZSKnirw5VH4EBZPGyH Wsmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=B3m3A8x8wolPCQH4hOAZm8+mwNYz8NUD+xg0ib/lAuk=; b=dfMKA6nmR5/QwzwyFePIWuq+a8w2ZVxsHP9IZwDGzFimpz84sL2SKt1PouIrmRvxxa 7pYndcFpbr27jrmCa0vWeSqOX1RNFgK5tfFqJusst7sjjARNyH8zHy5cx7AO0TtFq+hM GYPyqPR7JxRYw+8U8nAnPySI4L6LHeParpOzwlC1I/xXeJgzf6cMXrtMwsIlhQR60OUc tz2hEqc0FjruoLS6y/GXB7US+z4q4u3oHvjzK676TlQJct+1mB8mDoQN3du2zMbUyIQY nPncc2gehugWMEjAwHO+gV5BdsXivIAl1Om0i9LYzg5jtkYXZdSBUSQ6pn8ZXY489+JU qp/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i2oCMvI3; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id x15-v6sor5177034lfb.12.2018.09.03.07.47.49 for (Google Transport Security); Mon, 03 Sep 2018 07:47:49 -0700 (PDT) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i2oCMvI3; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=B3m3A8x8wolPCQH4hOAZm8+mwNYz8NUD+xg0ib/lAuk=; b=i2oCMvI3Ygj80CrxxWEmjRTJOXzVrJREQcuuWHYvJW35gACo0Ax1yuwmHVFNVoCnWj TZHbgESBw1SbjO+bR5o6MC4Rw9a319YVvU51z4ordNVLJML1Qh0a/42ztsCIKlcNeiv7 +DMLT6PSQU7iWWW926DvCRtK8LBXMovhW4DLw= 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=B3m3A8x8wolPCQH4hOAZm8+mwNYz8NUD+xg0ib/lAuk=; b=A/8dWDBfu4Evo0XN09qLqXiIVMiWQ/Lj6G1TEhSk8coAMUkWAtjgZaEcNCG6p/FltQ Xe87069xIR2eR8iVmYMbiZnU2s3xBSH/VWcmdXjmVTBi6VWLZGmuB9RZA/yoN7a/rz3v yIZ3UF0FouR/M91ikuywd4OEAHstcrUoUXvtJC9FNckc8HslkKYHtFbTOKK02cONHaOX QKCh2ruNAYgIRLLsW7y/0myGoE7f0pJ15B2/YfvJamk76JdfJLl4cBMPJRY5QZoqytSc LHC8dtE4TMEg2cdn2BJwYztpkZElXeSibTel7aomfbcL/yC+gUHPNJmTIlONXLYvB+RY xpTA== X-Gm-Message-State: APzg51C6QAWrZa+KuFdcn+jDgUPzmh2j3EfQgZjMpMr8A/uezJFdKmfE wRDrQzq3OGSc7qP9wtxOuT1Qxx0x X-Google-Smtp-Source: ANB0VdYUm2xq0upvryqc9254K/lW4aK5NVpK+xiy6AbmyddbbvWyRAgLBVeCVgjN5tQ99VrlIm+CvA== X-Received: by 2002:a19:5e12:: with SMTP id s18-v6mr17356264lfb.5.1535986069165; Mon, 03 Sep 2018 07:47:49 -0700 (PDT) Return-Path: Received: from jax.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id w18-v6sm3343431ljd.73.2018.09.03.07.47.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Sep 2018 07:47:48 -0700 (PDT) From: Jens Wiklander To: u-boot@lists.denx.de Cc: Simon Glass , Igor Opaniuk , Tom Rini , Jaehoon Chung , Pierre Aubert , Albert Aribaud , Peter Griffin , Michal Simek , Jens Wiklander Subject: [PATCH v3 20/20] Kconfig: sandbox: enable cmd_avb and dependencies Date: Mon, 3 Sep 2018 16:47:11 +0200 Message-Id: <20180903144711.31585-21-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180903144711.31585-1-jens.wiklander@linaro.org> References: <20180903144711.31585-1-jens.wiklander@linaro.org> Enables cmd_avb and its dependencies need to run the AVB tests. Signed-off-by: Jens Wiklander --- arch/Kconfig | 4 ++++ drivers/fastboot/Kconfig | 2 ++ 2 files changed, 6 insertions(+) -- 2.17.1 Reviewed-by: Simon Glass diff --git a/arch/Kconfig b/arch/Kconfig index 8f10f3fc06e8..543362578f50 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -92,6 +92,10 @@ config SANDBOX imply LZMA imply SCSI imply TEE + imply AVB_VERIFY + imply LIBAVB + imply CMD_AVB + imply UDP_FUNCTION_FASTBOOT config SH bool "SuperH architecture" diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig index bc25ea1d9c7a..d63ecdd27e4b 100644 --- a/drivers/fastboot/Kconfig +++ b/drivers/fastboot/Kconfig @@ -35,6 +35,7 @@ config FASTBOOT_BUF_ADDR ROCKCHIP_RK3399 default 0x280000 if ROCKCHIP_RK3368 default 0x100000 if ARCH_ZYNQMP + default 0 if SANDBOX help The fastboot protocol requires a large memory buffer for downloads. Define this to the starting RAM address to use for @@ -45,6 +46,7 @@ config FASTBOOT_BUF_SIZE default 0x8000000 if ARCH_ROCKCHIP default 0x6000000 if ARCH_ZYNQMP default 0x2000000 if ARCH_SUNXI + default 0x8192 if SANDBOX default 0x7000000 help The fastboot protocol requires a large memory buffer for