From patchwork Mon Jan 25 12:28:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Opaniuk X-Patchwork-Id: 1431189 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=foundries.io header.i=@foundries.io header.a=rsa-sha256 header.s=google header.b=ECcd+Myc; 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 4DPTgp6fn4z9sS8 for ; Mon, 25 Jan 2021 23:29:10 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C37FB82690; Mon, 25 Jan 2021 13:29:04 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=foundries.io 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=foundries.io header.i=@foundries.io header.b="ECcd+Myc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9CCC382690; Mon, 25 Jan 2021 13:29:01 +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,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) (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 34C6982666 for ; Mon, 25 Jan 2021 13:28:58 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=foundries.io Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=igor.opaniuk@foundries.io Received: by mail-lf1-x12c.google.com with SMTP id q12so17415845lfo.12 for ; Mon, 25 Jan 2021 04:28:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foundries.io; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/uqe2IDHYgdSBYKmuH4Wcw4JIYDLznjQgASNhR6/i0A=; b=ECcd+Mycc8ioPbjSryxEfRwkLf2jJrL1VLnlU//47xGeiNFsPbxFWpSletb7PdLoT8 jPRFvLKGPEwuA/jyeI2umg8/LrhToZJI4AACO7OJA8rQIdNpODkGviZuRfLddsfSm2Lh FVVfDogRkSJ/aguPu7jdNuWM3wTAgKSu9tgMAWQDovcJdSLy/Mc2sfofD3mZrTgOZsDe bhORBrF42LMzqAs6ahKlQqeo7QMcEX1tL3THs1WfJHlMdZoTFsxGWLDZFARQYVcWjkdr KhcSJ4dVmpPL+UAqi+sOCdL95GuATQGApuZq5JF3hwt4zKApxWur7TtA+nYChxtBfiue IpZQ== 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:mime-version :content-transfer-encoding; bh=/uqe2IDHYgdSBYKmuH4Wcw4JIYDLznjQgASNhR6/i0A=; b=V8sfu1P6QXTjx6bKfLS3ZhKDud9ZoTfEoEJDcyrz8qa7W0fFqiTrvfNuW58G1QjMY1 87cIgQS0m6oFXd/xPiJ7ZRD6q4nYi0K/8yrJq0krLr7Bh3Mtb/eajJuUPKJz5jGd7UZw 0F5O9ANFnYyzpJpQ76ndoh9JVMZXT4Sq6st1J1JD3pSyGOrRgZgarZOZ180/Yz/XdLrF hjFIeAXRypCSk9/HgQ9nOBlRkE+kJZp66ssQsCAHHvrXgJmXCeibTDP0/XZxlx3yffmK +63kh3Xbe3BhJ3DD+76N+5GJay/fgjHdrzEq/jAFtqyMvCRk/W6O/5vijb1EDF2y9yG+ 9RwA== X-Gm-Message-State: AOAM531DjraP73edThAYbugZMHwQkhrnPapn0WyJ/mL2YC7KBb/8rx0U 62BksjaAAXzhMbRj02MuwNnNGghsF5GBXpbY X-Google-Smtp-Source: ABdhPJzVr+CmQlj2Gf6+ZV5EEhd9fc/900JKodxXv8lmHZIIaHRMKHRfE9FuvnM+u0eLsvtUQ7wPpA== X-Received: by 2002:ac2:592b:: with SMTP id v11mr163660lfi.512.1611577737309; Mon, 25 Jan 2021 04:28:57 -0800 (PST) Received: from localhost ([109.108.76.111]) by smtp.gmail.com with ESMTPSA id m16sm1875097lfb.248.2021.01.25.04.28.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jan 2021 04:28:56 -0800 (PST) From: Igor Opaniuk X-Google-Original-From: Igor Opaniuk To: u-boot@lists.denx.de Cc: etienne.carriere@linaro.org, jorge@foundries.io, jens.wiklander@linaro.org, seanga2@gmail.com, trini@konsulko.com, vikas.gupta@broadcom.com, mike@foundries.io, ricardo@foundries.io, sjg@chromium.org, Igor Opaniuk Subject: [PATCH v8 0/4] OP-TEE I2C trampoline and associated tests Date: Mon, 25 Jan 2021 14:28:39 +0200 Message-Id: <20210125122843.253275-1-igor.opaniuk@gmail.com> X-Mailer: git-send-email 2.25.1 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 This patchset allows OP-TEE to communicate with I2C devices; a typical use case would be servicing U-Boot requests that require underlying cryptographic operations implemented by an I2C chip. On a board fitted with the NXP SE050 I2C secure element, OP-TEE can route some of the cryptographic operations it needs to that device (ie RSA, ECC, CTR..). Before the REE executes, OP-TEE would use its own I2C drivers to communicate with the device on the bus; later on, once the REE is up, accesses to the I2C bus should be coordinated with the REE to avoid collisions. However instead of implementing such a synchronization mechanism, this trampoline service permits OP-TEE to route those I2C requests back to U-boot without then having to worry about collisions. Lets suppose that U-Boot executes the trusted application Android Verified Boot; when OP-TEE receives the request - and before executing the application - it uses RSA to verify it. So on the back of the TA function invocation, OP-TEE returns to U-boot with a sequence of RPC calls requesting I2C transfers (check carefully the implementation in do_call_with_arg(...) implemented in drivers/tee/optee/core.c and notice the while loop) When using sandbox testing, RPC is called directly to validate its actual implementation; however as succintly described above, these calls will always be originated in OP-TEE. Changes v8: * [Etienne Carriere] extended TA param description (missed one param) Changes v7: * [Etienne Carriere] extended TA param description, adding info about i2c xfer flags. Applied A-b and R-b tags * [Jens Wiklander] applied R-b tag Changes v6: * [Etienne Carriere] fixed func return code handling * [Etienne Carriere] tee_optee_ta_uuid passing a pointer instead of full struct * [Etienne Carriere] pass additionally i2c control flags in tests * Fixed mispelling in the comments Changes v5: * [Jens Wiklander] Addressed comment about optee_alloc_and_init_page_list(): drop inline, proper return value and comment Changes v4: * [Simon Glass] Reduced amount ifdefs warnings and move to if (IS_ENABLED(CONFIG_*)) where possible * Fixed pointer-sign warnings Changes v3: * [Simon Glass] Added RPC I2C test coverage Changes v2: * [Simon Glass] Adjusted the usage of DM internal api (dev_get_parent_platdata) * [Simon Glass] Added additional comments to functions * [Jens Wiklander] s/tmem/rmem/g Igor Opaniuk (3): test: py: add pygit2 and pyelftools to requirements.txt drivers: tee: sandbox: add rpc test ta emulation test: dm: tee: extend with RPC test Jorge Ramirez-Ortiz (1): drivers: tee: i2c trampoline driver drivers/tee/Makefile | 2 + drivers/tee/optee/Kconfig | 9 ++ drivers/tee/optee/Makefile | 1 + drivers/tee/optee/i2c.c | 90 ++++++++++++++ drivers/tee/optee/optee_msg.h | 21 ++++ drivers/tee/optee/optee_msg_supplicant.h | 5 + drivers/tee/optee/optee_private.h | 17 +++ drivers/tee/optee/supplicant.c | 3 + drivers/tee/sandbox.c | 142 ++++++++++++++++++++++- include/tee/optee_ta_rpc_test.h | 30 +++++ test/dm/tee.c | 116 ++++++++++++++++-- test/py/requirements.txt | 2 + 12 files changed, 427 insertions(+), 11 deletions(-) create mode 100644 drivers/tee/optee/i2c.c create mode 100644 include/tee/optee_ta_rpc_test.h