Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/965496/?format=api
{ "id": 965496, "url": "http://patchwork.ozlabs.org/api/patches/965496/?format=api", "web_url": "http://patchwork.ozlabs.org/project/uboot/patch/20180903144711.31585-12-jens.wiklander@linaro.org/", "project": { "id": 18, "url": "http://patchwork.ozlabs.org/api/projects/18/?format=api", "name": "U-Boot", "link_name": "uboot", "list_id": "u-boot.lists.denx.de", "list_email": "u-boot@lists.denx.de", "web_url": null, "scm_url": null, "webscm_url": null, "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20180903144711.31585-12-jens.wiklander@linaro.org>", "list_archive_url": null, "date": "2018-09-03T14:47:02", "name": "[U-Boot,v3,11/20] optee: support routing of rpmb data frames to mmc", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "2c5737b9b4f51be438a242ae9940ddca9a83cae3", "submitter": { "id": 66201, "url": "http://patchwork.ozlabs.org/api/people/66201/?format=api", "name": "Jens Wiklander", "email": "jens.wiklander@linaro.org" }, "delegate": { "id": 3651, "url": "http://patchwork.ozlabs.org/api/users/3651/?format=api", "username": "trini", "first_name": "Tom", "last_name": "Rini", "email": "trini@ti.com" }, "mbox": "http://patchwork.ozlabs.org/project/uboot/patch/20180903144711.31585-12-jens.wiklander@linaro.org/mbox/", "series": [ { "id": 63875, "url": "http://patchwork.ozlabs.org/api/series/63875/?format=api", "web_url": "http://patchwork.ozlabs.org/project/uboot/list/?series=63875", "date": "2018-09-03T14:46:51", "name": "AVB using OP-TEE", "version": 3, "mbox": "http://patchwork.ozlabs.org/series/63875/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/965496/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/965496/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<u-boot-bounces@lists.denx.de>", "X-Original-To": "incoming@patchwork.ozlabs.org", "Delivered-To": "patchwork-incoming@bilbo.ozlabs.org", "Authentication-Results": [ "ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=lists.denx.de\n\t(client-ip=81.169.180.215; helo=lists.denx.de;\n\tenvelope-from=u-boot-bounces@lists.denx.de;\n\treceiver=<UNKNOWN>)", "ozlabs.org;\n\tdmarc=fail (p=none dis=none) header.from=linaro.org", "ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=linaro.org header.i=@linaro.org\n\theader.b=\"Owz3Vg1q\"; dkim-atps=neutral" ], "Received": [ "from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 423tT55c11z9s3x\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 4 Sep 2018 01:01:13 +1000 (AEST)", "by lists.denx.de (Postfix, from userid 105)\n\tid 87617C21E53; Mon, 3 Sep 2018 14:54:24 +0000 (UTC)", "from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id D07BDC21E0B;\n\tMon, 3 Sep 2018 14:47:58 +0000 (UTC)", "by lists.denx.de (Postfix, from userid 105)\n\tid 9CBB1C21DF9; Mon, 3 Sep 2018 14:47:43 +0000 (UTC)", "from mail-lf1-f45.google.com (mail-lf1-f45.google.com\n\t[209.85.167.45])\n\tby lists.denx.de (Postfix) with ESMTPS id E1044C21EE4\n\tfor <u-boot@lists.denx.de>; Mon, 3 Sep 2018 14:47:35 +0000 (UTC)", "by mail-lf1-f45.google.com with SMTP id l26-v6so642857lfc.8\n\tfor <u-boot@lists.denx.de>; Mon, 03 Sep 2018 07:47:35 -0700 (PDT)", "from jax.ideon.se ([85.235.10.227])\n\tby smtp.gmail.com with ESMTPSA id\n\tw18-v6sm3343431ljd.73.2018.09.03.07.47.33\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tMon, 03 Sep 2018 07:47:34 -0700 (PDT)" ], "X-Spam-Checker-Version": "SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de", "X-Spam-Level": "", "X-Spam-Status": "No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2,\n\tT_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references;\n\tbh=tBbBJe8/MVi9pxS8uyiw1IWis6hb4TT0xsmEuxzdBB8=;\n\tb=Owz3Vg1qWf2tJDUExvAPE7oWvQB1lE8BNyWBLsbYdYBzmn/vKEJ1Y0AK0+9g4kM40s\n\tZR4fY2O30j24lTNRuKSTV3u/n7mFBzSWJm9ojKXPBNomIFjItsqTV+WfempbaB9obNIM\n\tSdSlDdGxXeRjhyGOqTSTbnc7UBnaZhSMG0tCw=", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=tBbBJe8/MVi9pxS8uyiw1IWis6hb4TT0xsmEuxzdBB8=;\n\tb=EFCx4gEcD+rZpKeSgzxUD+3XdaIgOKGEmR5tCt7O2+3yyKbT0CvvksX837sfVRlDxf\n\tody0NPlTCI1NsrMxBimUKMxHEK1piM6KlUdT4dYkgRsAcum83AL2j5A8wzrpSreOB8MD\n\tg0lp3IFgKfzEk7sC7vIqr7cBT42DKqh0/c87OzRe/9DXBrT7Tq01jNk+ttakdGxk0Hcw\n\to5q5q9yKGgXgQLMz96geW4t5oFTezAIWTzPPHUaW0ZL7r4OgJfpj9vQ1Gm1JITIq3kAq\n\tD5vWuht/wM8Lec18PzXgi5Tq3onROw3P8nzJBv/jop82Th2M14oegSJF8B5nQbJPeyLD\n\tbDNA==", "X-Gm-Message-State": "APzg51DzDk2gxq2/p99EU0g2sgtivApPlXdpGfrIakr8hxzwBfDo8e1+\n\tB8ifoMBmUt30jRAq0Rp4cCt7tHdg6YQ=", "X-Google-Smtp-Source": "ANB0VdZNyFwX3XPwtNYVEKsOxlOOG5sb4WMUUTUhC6xZ+Usoi8MTuZHfPUh/+s9jt0JxZnzB2TDuSw==", "X-Received": "by 2002:a19:a141:: with SMTP id\n\tk62-v6mr11379940lfe.18.1535986054960; \n\tMon, 03 Sep 2018 07:47:34 -0700 (PDT)", "From": "Jens Wiklander <jens.wiklander@linaro.org>", "To": "u-boot@lists.denx.de", "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>", "Cc": "Tom Rini <trini@konsulko.com>, Pierre Aubert <p.aubert@staubli.com>", "Subject": "[U-Boot] [PATCH v3 11/20] optee: support routing of rpmb data\n\tframes to mmc", "X-BeenThere": "u-boot@lists.denx.de", "X-Mailman-Version": "2.1.18", "Precedence": "list", "List-Id": "U-Boot discussion <u-boot.lists.denx.de>", "List-Unsubscribe": "<https://lists.denx.de/options/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=unsubscribe>", "List-Archive": "<http://lists.denx.de/pipermail/u-boot/>", "List-Post": "<mailto:u-boot@lists.denx.de>", "List-Help": "<mailto:u-boot-request@lists.denx.de?subject=help>", "List-Subscribe": "<https://lists.denx.de/listinfo/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=subscribe>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=\"utf-8\"", "Content-Transfer-Encoding": "base64", "Errors-To": "u-boot-bounces@lists.denx.de", "Sender": "\"U-Boot\" <u-boot-bounces@lists.denx.de>" }, "content": "Adds support in optee supplicant to route signed (MACed) RPMB frames\nfrom OP-TEE Secure OS to MMC and vice versa to manipulate the RPMB\npartition.\n\nTested-by: Igor Opaniuk <igor.opaniuk@linaro.org>\nSigned-off-by: Jens Wiklander <jens.wiklander@linaro.org>\n---\n drivers/tee/optee/Makefile | 1 +\n drivers/tee/optee/core.c | 8 ++\n drivers/tee/optee/optee_private.h | 55 ++++++++-\n drivers/tee/optee/rpmb.c | 181 ++++++++++++++++++++++++++++++\n drivers/tee/optee/supplicant.c | 3 +\n 5 files changed, 247 insertions(+), 1 deletion(-)\n create mode 100644 drivers/tee/optee/rpmb.c", "diff": "diff --git a/drivers/tee/optee/Makefile b/drivers/tee/optee/Makefile\nindex 6148feb474a5..928d3f80027f 100644\n--- a/drivers/tee/optee/Makefile\n+++ b/drivers/tee/optee/Makefile\n@@ -2,3 +2,4 @@\n \n obj-y += core.o\n obj-y += supplicant.o\n+obj-$(CONFIG_SUPPORT_EMMC_RPMB) += rpmb.o\ndiff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c\nindex 726382da9bb8..7f870f2f735d 100644\n--- a/drivers/tee/optee/core.c\n+++ b/drivers/tee/optee/core.c\n@@ -315,6 +315,13 @@ static u32 do_call_with_arg(struct udevice *dev, struct optee_msg_arg *arg)\n \t\t\tparam.a3 = res.a3;\n \t\t\thandle_rpc(dev, ¶m, &page_list);\n \t\t} else {\n+\t\t\t/*\n+\t\t\t * In case we've accessed RPMB to serve an RPC\n+\t\t\t * request we need to restore the previously\n+\t\t\t * selected partition as the caller may expect it\n+\t\t\t * to remain unchanged.\n+\t\t\t */\n+\t\t\toptee_suppl_rpmb_release(dev);\n \t\t\treturn call_err_to_res(res.a0);\n \t\t}\n \t}\n@@ -651,4 +658,5 @@ U_BOOT_DRIVER(optee) = {\n \t.probe = optee_probe,\n \t.ops = &optee_ops,\n \t.platdata_auto_alloc_size = sizeof(struct optee_pdata),\n+\t.priv_auto_alloc_size = sizeof(struct optee_private),\n };\ndiff --git a/drivers/tee/optee/optee_private.h b/drivers/tee/optee/optee_private.h\nindex 35adb83afcc7..9442d1c176bc 100644\n--- a/drivers/tee/optee/optee_private.h\n+++ b/drivers/tee/optee/optee_private.h\n@@ -6,7 +6,60 @@\n #ifndef __OPTEE_PRIVATE_H\n #define __OPTEE_PRIVATE_H\n \n+#include <tee.h>\n+#include <log.h>\n+\n+/**\n+ * struct optee_private - OP-TEE driver private data\n+ * @rpmb_mmc:\t\tmmc device for the RPMB partition\n+ * @rpmb_dev_id:\tmmc device id matching @rpmb_mmc\n+ * @rpmb_original_part:\tthe previosly active partition on the mmc device,\n+ *\t\t\tused to restore active the partition when the RPMB\n+ *\t\t\taccesses are finished\n+ */\n+struct optee_private {\n+\tstruct mmc *rpmb_mmc;\n+\tint rpmb_dev_id;\n+\tint rpmb_original_part;\n+};\n+\n+struct optee_msg_arg;\n+\n+void optee_suppl_cmd(struct udevice *dev, struct tee_shm *shm_arg,\n+\t\t void **page_list);\n+\n+#ifdef CONFIG_SUPPORT_EMMC_RPMB\n+/**\n+ * optee_suppl_cmd_rpmb() - route RPMB frames to mmc\n+ * @dev:\tdevice with the selected RPMB partition\n+ * @arg:\tOP-TEE message holding the frames to transmit to the mmc\n+ *\t\tand space for the response frames.\n+ *\n+ * Routes signed (MACed) RPMB frames from OP-TEE Secure OS to MMC and vice\n+ * versa to manipulate the RPMB partition.\n+ */\n+void optee_suppl_cmd_rpmb(struct udevice *dev, struct optee_msg_arg *arg);\n+\n+/**\n+ * optee_suppl_rpmb_release() - release mmc device\n+ * @dev:\tmmc device\n+ *\n+ * Releases the mmc device and restores the previously selected partition.\n+ */\n+void optee_suppl_rpmb_release(struct udevice *dev);\n+#else\n+static inline void optee_suppl_cmd_rpmb(struct udevice *dev,\n+\t\t\t\t\tstruct optee_msg_arg *arg)\n+{\n+\tdebug(\"OPTEE_MSG_RPC_CMD_RPMB not implemented\\n\");\n+\targ->ret = TEE_ERROR_NOT_IMPLEMENTED;\n+}\n+\n+static inline void optee_suppl_rpmb_release(struct udevice *dev)\n+{\n+}\n+#endif\n+\n void *optee_alloc_and_init_page_list(void *buf, ulong len, u64 *phys_buf_ptr);\n-void optee_suppl_cmd(struct udevice *dev, void *shm, void **page_list);\n \n #endif /* __OPTEE_PRIVATE_H */\ndiff --git a/drivers/tee/optee/rpmb.c b/drivers/tee/optee/rpmb.c\nnew file mode 100644\nindex 000000000000..955155b3f8b1\n--- /dev/null\n+++ b/drivers/tee/optee/rpmb.c\n@@ -0,0 +1,181 @@\n+// SPDX-License-Identifier: BSD-2-Clause\n+/*\n+ * Copyright (c) 2018 Linaro Limited\n+ */\n+\n+#include <common.h>\n+#include <dm.h>\n+#include <log.h>\n+#include <tee.h>\n+#include <mmc.h>\n+\n+#include \"optee_msg.h\"\n+#include \"optee_private.h\"\n+\n+/*\n+ * Request and response definitions must be in sync with the secure side of\n+ * OP-TEE.\n+ */\n+\n+/* Request */\n+struct rpmb_req {\n+\tu16 cmd;\n+#define RPMB_CMD_DATA_REQ 0x00\n+#define RPMB_CMD_GET_DEV_INFO 0x01\n+\tu16 dev_id;\n+\tu16 block_count;\n+\t/* Optional data frames (rpmb_data_frame) follow */\n+};\n+\n+#define RPMB_REQ_DATA(req) ((void *)((struct rpmb_req *)(req) + 1))\n+\n+/* Response to device info request */\n+struct rpmb_dev_info {\n+\tu8 cid[16];\n+\tu8 rpmb_size_mult;\t/* EXT CSD-slice 168: RPMB Size */\n+\tu8 rel_wr_sec_c;\t/* EXT CSD-slice 222: Reliable Write Sector */\n+\t\t\t\t/* Count */\n+\tu8 ret_code;\n+#define RPMB_CMD_GET_DEV_INFO_RET_OK 0x00\n+#define RPMB_CMD_GET_DEV_INFO_RET_ERROR 0x01\n+};\n+\n+static void release_mmc(struct optee_private *priv)\n+{\n+\tint rc;\n+\n+\tif (!priv->rpmb_mmc)\n+\t\treturn;\n+\n+\trc = blk_select_hwpart_devnum(IF_TYPE_MMC, priv->rpmb_dev_id,\n+\t\t\t\t priv->rpmb_original_part);\n+\tif (rc)\n+\t\tdebug(\"%s: blk_select_hwpart_devnum() failed: %d\\n\",\n+\t\t __func__, rc);\n+\n+\tpriv->rpmb_mmc = NULL;\n+}\n+\n+static struct mmc *get_mmc(struct optee_private *priv, int dev_id)\n+{\n+\tstruct mmc *mmc;\n+\tint rc;\n+\n+\tif (priv->rpmb_mmc && priv->rpmb_dev_id == dev_id)\n+\t\treturn priv->rpmb_mmc;\n+\n+\trelease_mmc(priv);\n+\n+\tmmc = find_mmc_device(dev_id);\n+\tif (!mmc) {\n+\t\tdebug(\"Cannot find RPMB device\\n\");\n+\t\treturn NULL;\n+\t}\n+\tif (!(mmc->version & MMC_VERSION_MMC)) {\n+\t\tdebug(\"Device id %d is not an eMMC device\\n\", dev_id);\n+\t\treturn NULL;\n+\t}\n+\tif (mmc->version < MMC_VERSION_4_41) {\n+\t\tdebug(\"Device id %d: RPMB not supported before version 4.41\\n\",\n+\t\t dev_id);\n+\t\treturn NULL;\n+\t}\n+\n+\tpriv->rpmb_original_part = mmc_get_blk_desc(mmc)->hwpart;\n+\n+\trc = blk_select_hwpart_devnum(IF_TYPE_MMC, dev_id, MMC_PART_RPMB);\n+\tif (rc) {\n+\t\tdebug(\"Device id %d: cannot select RPMB partition: %d\\n\",\n+\t\t dev_id, rc);\n+\t\treturn NULL;\n+\t}\n+\n+\tpriv->rpmb_mmc = mmc;\n+\tpriv->rpmb_dev_id = dev_id;\n+\treturn mmc;\n+}\n+\n+static u32 rpmb_get_dev_info(u16 dev_id, struct rpmb_dev_info *info)\n+{\n+\tstruct mmc *mmc = find_mmc_device(dev_id);\n+\n+\tif (!mmc)\n+\t\treturn TEE_ERROR_ITEM_NOT_FOUND;\n+\n+\tif (!mmc->ext_csd)\n+\t\treturn TEE_ERROR_GENERIC;\n+\n+\tmemcpy(info->cid, mmc->cid, sizeof(info->cid));\n+\tinfo->rel_wr_sec_c = mmc->ext_csd[222];\n+\tinfo->rpmb_size_mult = mmc->ext_csd[168];\n+\tinfo->ret_code = RPMB_CMD_GET_DEV_INFO_RET_OK;\n+\n+\treturn TEE_SUCCESS;\n+}\n+\n+static u32 rpmb_process_request(struct optee_private *priv, void *req,\n+\t\t\t\tulong req_size, void *rsp, ulong rsp_size)\n+{\n+\tstruct rpmb_req *sreq = req;\n+\tstruct mmc *mmc;\n+\n+\tif (req_size < sizeof(*sreq))\n+\t\treturn TEE_ERROR_BAD_PARAMETERS;\n+\n+\tswitch (sreq->cmd) {\n+\tcase RPMB_CMD_DATA_REQ:\n+\t\tmmc = get_mmc(priv, sreq->dev_id);\n+\t\tif (!mmc)\n+\t\t\treturn TEE_ERROR_ITEM_NOT_FOUND;\n+\t\tif (mmc_rpmb_route_frames(mmc, RPMB_REQ_DATA(req),\n+\t\t\t\t\t req_size - sizeof(struct rpmb_req),\n+\t\t\t\t\t rsp, rsp_size))\n+\t\t\treturn TEE_ERROR_BAD_PARAMETERS;\n+\t\treturn TEE_SUCCESS;\n+\n+\tcase RPMB_CMD_GET_DEV_INFO:\n+\t\tif (req_size != sizeof(struct rpmb_req) ||\n+\t\t rsp_size != sizeof(struct rpmb_dev_info)) {\n+\t\t\tdebug(\"Invalid req/rsp size\\n\");\n+\t\t\treturn TEE_ERROR_BAD_PARAMETERS;\n+\t\t}\n+\t\treturn rpmb_get_dev_info(sreq->dev_id, rsp);\n+\n+\tdefault:\n+\t\tdebug(\"Unsupported RPMB command: %d\\n\", sreq->cmd);\n+\t\treturn TEE_ERROR_BAD_PARAMETERS;\n+\t}\n+}\n+\n+void optee_suppl_cmd_rpmb(struct udevice *dev, struct optee_msg_arg *arg)\n+{\n+\tstruct tee_shm *req_shm;\n+\tstruct tee_shm *rsp_shm;\n+\tvoid *req_buf;\n+\tvoid *rsp_buf;\n+\tulong req_size;\n+\tulong rsp_size;\n+\n+\tif (arg->num_params != 2 ||\n+\t arg->params[0].attr != OPTEE_MSG_ATTR_TYPE_RMEM_INPUT ||\n+\t arg->params[1].attr != OPTEE_MSG_ATTR_TYPE_RMEM_OUTPUT) {\n+\t\targ->ret = TEE_ERROR_BAD_PARAMETERS;\n+\t\treturn;\n+\t}\n+\n+\treq_shm = (struct tee_shm *)(ulong)arg->params[0].u.rmem.shm_ref;\n+\treq_buf = (u8 *)req_shm->addr + arg->params[0].u.rmem.offs;\n+\treq_size = arg->params[0].u.rmem.size;\n+\n+\trsp_shm = (struct tee_shm *)(ulong)arg->params[1].u.rmem.shm_ref;\n+\trsp_buf = (u8 *)rsp_shm->addr + arg->params[1].u.rmem.offs;\n+\trsp_size = arg->params[1].u.rmem.size;\n+\n+\targ->ret = rpmb_process_request(dev_get_priv(dev), req_buf, req_size,\n+\t\t\t\t\trsp_buf, rsp_size);\n+}\n+\n+void optee_suppl_rpmb_release(struct udevice *dev)\n+{\n+\trelease_mmc(dev_get_priv(dev));\n+}\ndiff --git a/drivers/tee/optee/supplicant.c b/drivers/tee/optee/supplicant.c\nindex 2239b1bf7b37..b1ea65bdb2e3 100644\n--- a/drivers/tee/optee/supplicant.c\n+++ b/drivers/tee/optee/supplicant.c\n@@ -85,6 +85,9 @@ void optee_suppl_cmd(struct udevice *dev, struct tee_shm *shm_arg,\n \t\tdebug(\"OPTEE_MSG_RPC_CMD_FS not implemented\\n\");\n \t\targ->ret = TEE_ERROR_NOT_IMPLEMENTED;\n \t\tbreak;\n+\tcase OPTEE_MSG_RPC_CMD_RPMB:\n+\t\toptee_suppl_cmd_rpmb(dev, arg);\n+\t\tbreak;\n \tdefault:\n \t\targ->ret = TEE_ERROR_NOT_IMPLEMENTED;\n \t}\n", "prefixes": [ "U-Boot", "v3", "11/20" ] }