From patchwork Tue Sep 25 14:40:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 147480 Delivered-To: patches@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp812765lji; Tue, 25 Sep 2018 07:40:52 -0700 (PDT) X-Received: by 2002:a2e:4401:: with SMTP id r1-v6mr1199074lja.21.1537886452618; Tue, 25 Sep 2018 07:40:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537886452; cv=none; d=google.com; s=arc-20160816; b=JO7j6EwsEuS54z1WiO4avFMxzO+vRRMRdCgrHErrkvttkeCLKZI9XWd5BeJVUqTYhj 3uLEntnPyC2sIMgZ9dejdeFJoqLcCTxmR2v+9Kmi5lCTA9PV+RoREiFbOeVgY2ufSsHq /LE53IVLsctjRxvFskRrzRXWOSxTBN+Sm6g2chdzNXPl7Z6jqAO92vQCYgC03/sFCquX 689caxfXGLT5TnxjfbZd5ersTMeVOct2vTe8k+fFrGmjJDKaRok0UDnPjdzlXzf0KX8U ttEZlr62K6H3QU8lLtRdWDvyKDhylFT4F9SlTbe+OnE4F4J+JbnbhwSVOn52N1dYhc/r hXiA== 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; bh=ktzQP403lJmusbeWkq5N68FVynlEKFaTCHmHOeBqLCg=; b=tVNLxzTFMrt9sCzvpd+HE6b/GGeK2P8GcYDg+UHVptxsNLemycJcIRqmqLWhNyLFYR xUQqjiJ56DckzKefq1e6wbmZzU+7O1DDdRZjIRtKw0lmKWBg2dnARF1llvZBUTWNSrN6 vRc+EGa0ybh3K+/DPUutTrKrtcql2LWfP9oHKt6nm7eQoF9QHD+hJ26fEiBZRh1hYN0q as7F0lr6eEuaKKG2l3hjUIu/SexKGLJu5RrijZAWN+xsxWrPQaiQ4zefKHAR0+DCDh+c oYx0DZY/nk/jgjEHiWjSr8nABZwog6oldJIBCSlqw2ziiHx9WGIOzImKBxfHLyprdaOC 8cyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VLM0H8zf; 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 h82-v6sor1609638lji.24.2018.09.25.07.40.52 for (Google Transport Security); Tue, 25 Sep 2018 07:40:52 -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=VLM0H8zf; 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=ktzQP403lJmusbeWkq5N68FVynlEKFaTCHmHOeBqLCg=; b=VLM0H8zfWDmz7831kqQzjDxq3v26g0BTss9BRWIth1fB7XEf7/AHFouSrPAeAVk1va wS6F4409UK9DFjLuPW0X1PUqa7tSfDtwJp4QCajSrn26N1F/9tYQH6L0eu+M7iYZicSA HoiTrsM/PxA8B5784IYvl/28I8BXKvCbLplGY= 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=ktzQP403lJmusbeWkq5N68FVynlEKFaTCHmHOeBqLCg=; b=fV0g9k5W06AEb7OY6Qu5hg/DUOHAwn+ewq+FlfxMIMWCfKgmIC5hfl6FVC3JsTYAGk C2Z8LVkFs7B4Ma5Grpr2kMt6aYXP3qawGxiHC/xiqM+xmwD+fxTulVzOmoezcvmuLLW3 iZah2zJ/D1fBk0hvFy8Q74S3yqhPs8sGrnoGJluMCBMPGgGV6zc/DOogQz5/3iflqHUU HCJAdPIIBc0rsiGSoy0gnJkHoPw/OE0ZS+yZFQrmrfKkk3Ge1cxLWSLCOMGlHufehX3l dbIq6guePtHJz+PUeAo+HqdXSSP1S/Q1lKT9vkpBbhNwRi+yCfkcNTYBHw6A8iiJ4DAI llkA== X-Gm-Message-State: ABuFfoioE0mYagrvtx23yoMZwm6UqO5WgJ5viPiYhSVFyBp8L4xvCpRL wKH621zW/VNRlNXk+chGUiKTPVgI X-Google-Smtp-Source: ACcGV60p7275cAtoWhSgk50l2mZ0WT4EWJv72wC7jkedTcCkovu88VYQw8gDNDsfqAPoYXEmjdxA3Q== X-Received: by 2002:a2e:2bd5:: with SMTP id r82-v6mr1129765ljr.63.1537886452373; Tue, 25 Sep 2018 07:40:52 -0700 (PDT) Return-Path: Received: from jax.urgonet (h-84-105.A175.priv.bahnhof.se. [79.136.84.105]) by smtp.gmail.com with ESMTPSA id g14-v6sm14483lja.96.2018.09.25.07.40.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Sep 2018 07:40:51 -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 v4 15/19] test: tee: test TEE uclass Date: Tue, 25 Sep 2018 16:40:19 +0200 Message-Id: <20180925144023.24555-16-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180925144023.24555-1-jens.wiklander@linaro.org> References: <20180925144023.24555-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 67c1fe6d0142..b1eedf4a6ee2 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -46,4 +46,5 @@ obj-$(CONFIG_SPMI) += spmi.o obj-$(CONFIG_WDT) += wdt.o obj-$(CONFIG_AXI) += axi.o obj-$(CONFIG_MISC) += misc.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);