From patchwork Wed Jan 20 17:55:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Opaniuk X-Patchwork-Id: 1429385 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=g5+ivhcB; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DLYBC0fySz9sW0 for ; Thu, 21 Jan 2021 04:56:51 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id F3B40829B9; Wed, 20 Jan 2021 18:56:29 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="g5+ivhcB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B2BC28285E; Wed, 20 Jan 2021 18:56:26 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E28AB8286D for ; Wed, 20 Jan 2021 18:56:19 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=igor.opaniuk@gmail.com Received: by mail-lf1-x131.google.com with SMTP id u25so35309191lfc.2 for ; Wed, 20 Jan 2021 09:56:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CLOQa92FT5pFo5tz8BSi8OWbCQodksajS5D4t2HjoYw=; b=g5+ivhcB28DTPm5lW4ziZircfmK+69Sq4Ua/Ma/ZdO/LK+tC15JU4jqhEAxc5ekuaN Hppvf/q5q3mNQW6Dg4xeUdME1Gp3cIsJaF7vv3OqN1RjXQNz9o18i7abgXON5iPovlEi iLygTUpsaeykJDxKY5tsc7deCBYMgl0hZIGT0bvRZYc9JgJg7Qw69zwxzHW+KetTKfhi Op+i8p/a95/rTaNJiHF7BZ46HJ4SPLnBAyUemOeyLKPFYC5/qGrbQcH0FdsqfhWZmMSk QuOQNUeYG3uS36PGpnfFpw7XqOn2r0fMpt7IOc6V4SJ1sOn0M/6YkUgqLG2tDcxTGhgO uyuA== 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:mime-version:content-transfer-encoding; bh=CLOQa92FT5pFo5tz8BSi8OWbCQodksajS5D4t2HjoYw=; b=DpF8rNLnUqCRPCsgc3lSL/uTPWF5xW1qg0I6bvVV1pc3cfGhVjNhQhHNi8SqThaeEN LYvMqzAoWYlAqy0ESopG3x6TQ/zGFTZTDd9cwz7Jzp0bXdo4gjE9xOBRsXY+KcbAht44 UV76ABsWy6IYxP/q8HVIuKROBjFKI25vqTJKOkzdnOb3FkkkSYMkaZV4VgXRQF07OesV 0LJ0CKDVNecVGyaiZefCWNJ1vvYXZ6ogKSNuPr6FJXmpP7UfdPhixy8QV5lAhpZ6vfQw zNi7nxIJtCBkAvBfDi2H5x5LVKo1pwDGtCFB0rPULrXCZT8VlkkwGqt7CTOxw+viuPep BLAQ== X-Gm-Message-State: AOAM532ZBI5IP9M6UVHDzctw7u74dgqePo7Tne8gpbKtjYp0bDxaNE9W suntvrftwKUcsRQ+SdD7L9TwLI5QcTmp8nni X-Google-Smtp-Source: ABdhPJzU9wjKCInWH3a6uVeWjuKmK5z73NpikeDn9XU9LwfMKv6T+l8M3n1bg1FxVT9TPXA/AuwBnw== X-Received: by 2002:a19:b4d:: with SMTP id 74mr4778839lfl.162.1611165378518; Wed, 20 Jan 2021 09:56:18 -0800 (PST) Received: from localhost ([109.108.76.111]) by smtp.gmail.com with ESMTPSA id w21sm258664lfu.132.2021.01.20.09.56.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 09:56:10 -0800 (PST) From: Igor Opaniuk To: u-boot@lists.denx.de Cc: vikas.gupta@broadcom.com, ricardo@foundries.io, jens.wiklander@linaro.org, sjg@chromium.org, trini@konsulko.com, jorge@foundries.io, seanga2@gmail.com, mike@foundries.io, Igor Opaniuk Subject: [PATCH v5 4/4] test: dm: tee: extend with RPC test Date: Wed, 20 Jan 2021 19:55:30 +0200 Message-Id: <20210120175530.92057-5-igor.opaniuk@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210120175530.92057-1-igor.opaniuk@gmail.com> References: <20210120175530.92057-1-igor.opaniuk@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean From: Igor Opaniuk Extend existing DM tee tests adding test coverage for reverse RPC calls. Currently this commit only adds tests for I2C requests from TEE driver to TEE supplicant, for instance reading/writing data to emulated i2c eeprom defines in standard sandbox test device tree (arch/sandbox/dts/test.dtb): => i2c bus Bus 0: i2c@0 (active 0) 2c: eeprom@2c, offset len 1, flags 0 ... Running TEE tests: => ut dm tee Test: dm_test_tee: tee.c Test: dm_test_tee: tee.c (flat tree) Failures: 0 Signed-off-by: Igor Opaniuk Reviewed-by: Simon Glass --- (no changes since v1) test/dm/tee.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 102 insertions(+), 5 deletions(-) diff --git a/test/dm/tee.c b/test/dm/tee.c index ddbdcfb0cf..51ffb4e4a9 100644 --- a/test/dm/tee.c +++ b/test/dm/tee.c @@ -13,11 +13,12 @@ #include #include #include +#include -static int open_session(struct udevice *dev, u32 *session) +static int open_session(struct udevice *dev, u32 *session, + struct tee_optee_ta_uuid uuid) { struct tee_open_session_arg arg; - const struct tee_optee_ta_uuid uuid = TA_AVB_UUID; int rc; memset(&arg, 0, sizeof(arg)); @@ -32,7 +33,7 @@ static int open_session(struct udevice *dev, u32 *session) return 0; } -static int invoke_func(struct udevice *dev, u32 session) +static int invoke_func_avb(struct udevice *dev, u32 session) { struct tee_param param = { .attr = TEE_PARAM_ATTR_TYPE_VALUE_OUTPUT }; struct tee_invoke_arg arg; @@ -47,6 +48,47 @@ static int invoke_func(struct udevice *dev, u32 session) return 0; } +static int invoke_func_rpc_test(struct udevice *dev, u32 session, + u64 op, u64 busnum, u64 chip_addr, + u8 *buf, size_t buf_size) +{ + struct tee_param param[2]; + struct tee_invoke_arg arg; + struct tee_shm *shm_buf; + int rc; + + memset(&arg, 0, sizeof(arg)); + arg.session = session; + arg.func = op; + + rc = tee_shm_alloc(dev, buf_size, + TEE_SHM_ALLOC, &shm_buf); + if (rc) + return rc; + + if (op == TA_RPC_TEST_CMD_I2C_WRITE) + memcpy(shm_buf->addr, buf, buf_size); + + memset(param, 0, sizeof(param)); + param[0].attr = TEE_PARAM_ATTR_TYPE_VALUE_INPUT; + param[0].u.value.a = busnum; + param[0].u.value.b = chip_addr; + param[1].attr = TEE_PARAM_ATTR_TYPE_MEMREF_INOUT; + param[1].u.memref.shm = shm_buf; + param[1].u.memref.size = buf_size; + + if (tee_invoke_func(dev, &arg, 2, param) || arg.ret) { + goto out; + rc = -1; + } + + if (op == TA_RPC_TEST_CMD_I2C_READ) + memcpy(buf, shm_buf->addr, buf_size); +out: + tee_shm_free(shm_buf); + return rc; +} + static int match(struct tee_version_data *vers, const void *data) { return vers->gen_caps & TEE_GEN_CAP_GP; @@ -62,6 +104,7 @@ static int test_tee(struct unit_test_state *uts, struct test_tee_vars *vars) struct tee_version_data vers; struct udevice *dev; struct sandbox_tee_state *state; + struct tee_optee_ta_uuid avb_uuid = TA_AVB_UUID; u32 session = 0; int rc; u8 data[128]; @@ -71,11 +114,11 @@ static int test_tee(struct unit_test_state *uts, struct test_tee_vars *vars) state = dev_get_priv(dev); ut_assert(!state->session); - rc = open_session(dev, &session); + rc = open_session(dev, &session, avb_uuid); ut_assert(!rc); ut_assert(session == state->session); - rc = invoke_func(dev, session); + rc = invoke_func_avb(dev, session); ut_assert(!rc); rc = tee_close_session(dev, session); @@ -103,11 +146,65 @@ static int test_tee(struct unit_test_state *uts, struct test_tee_vars *vars) return 0; } +#define I2C_BUF_SIZE 64 + +static int test_tee_rpc(struct unit_test_state *uts) +{ + struct tee_version_data vers; + struct udevice *dev; + struct sandbox_tee_state *state; + struct tee_optee_ta_uuid rpc_test_uuid = TA_RPC_TEST_UUID; + u32 session = 0; + int rc; + + char *test_str = "Test string"; + u8 data[I2C_BUF_SIZE] = {0}; + u8 data_from_eeprom[I2C_BUF_SIZE] = {0}; + + /* Use sandbox I2C EEPROM emulation; bus: 0, chip: 0x2c */ + u64 bus = 0; + u64 chip = 0x2c; + + dev = tee_find_device(NULL, match, NULL, &vers); + ut_assert(dev); + state = dev_get_priv(dev); + ut_assert(!state->session); + + /* Test RPC call asking for I2C sevice */ + rc = open_session(dev, &session, rpc_test_uuid); + ut_assert(!rc); + ut_assert(session == state->session); + + /* Write buffer */ + strncpy((char *)data, test_str, strlen(test_str)); + rc = invoke_func_rpc_test(dev, session, TA_RPC_TEST_CMD_I2C_WRITE, + bus, chip, data, sizeof(data)); + ut_assert(!rc); + + /* Read buffer */ + rc = invoke_func_rpc_test(dev, session, TA_RPC_TEST_CMD_I2C_READ, + bus, chip, data_from_eeprom, + sizeof(data_from_eeprom)); + ut_assert(!rc); + + /* Compare */ + ut_assert(!memcmp(data, data_from_eeprom, sizeof(data))); + + rc = tee_close_session(dev, session); + ut_assert(!rc); + ut_assert(!state->session); + + return 0; +} + static int dm_test_tee(struct unit_test_state *uts) { struct test_tee_vars vars = { NULL, NULL }; int rc = test_tee(uts, &vars); + if (IS_ENABLED(CONFIG_OPTEE_TA_RPC_TEST)) + rc = test_tee_rpc(uts); + /* In case test_tee() asserts these may still remain allocated */ tee_shm_free(vars.reg_shm); tee_shm_free(vars.alloc_shm);