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);