From patchwork Wed Mar 9 12:27:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 549706 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6713:0:0:0:0 with SMTP id u19csp3514688mag; Wed, 9 Mar 2022 04:29:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJwdxqWjkfjjcLAp/ndwxk7Yy+aJ5YAn/yGJQUE9GubzaNv9EgFbTs0TvCvnSfA6FRXRQ+hR X-Received: by 2002:a05:6402:1747:b0:415:ee04:47e1 with SMTP id v7-20020a056402174700b00415ee0447e1mr20649982edx.229.1646828980633; Wed, 09 Mar 2022 04:29:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646828980; cv=none; d=google.com; s=arc-20160816; b=H3z5Vj5hNr5B+tPPscFC0BeIgJUKQWUOmLNU71Az8vMW0/6knt3xScUHr7nU8uGwWT 6yXGpgCFAdLtDLJkTpg2V0ttCDM9eklP0q3zOOI8R1zh7XFv7cBFn4bbF9gzf8ndfWzW afmLwL15DE1PJOPhwfGJAuODlzfOWsBblQOWfs5kM77ZUmDMTbgJhHvNeW2zIwBEi5uI q7LQGRjGoZIoU+y/RCDMtXweCR/WIXmYfcF6V2n7btionIk8llmTS4KSQWPCcxAflqFX 4gIaj/UdKapjNQqfHSLHPon0q62hjXastyt2HGgMRIOe8enUxKoLkBFOQ2ij+Yb1SHUu 65pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=CZ30paeRDgxA/i9GkhviuuIw3PYziW3wIUJlCxP3Lc4=; b=IOkOufhIyMSCBVAN6cswDR1C6L1S+BjTo4R/pcBItG1JhanTpn+BN9SAxfFPYKHgom B8pY9RpWTNCk2bcg9mzPkNrctBFAZFGXRY3hTov6QRInxx/yLiCoN/6W+noWSuA7pCka U/kLgK7Q1+sPziJebXuLtl1aQ9eCEjApvBx1R84/3Ydka9F/8KuHVuloDKcjzfG7c3by 9ROet5h+yAaUx3dUf34xmEPNy0Vja944Nxz2S+fxkJTg6C1QU+jRNx19rIDVmAlhVEp4 BMes3W1GOhgHk8SgWXQ1sPaCL/NYI+F3g236H3I3OBbPdBNnXrhJM7LXWISHK2R1zcJT ykSQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id j26-20020a50ed1a000000b0041616b790ecsi1091379eds.335.2022.03.09.04.29.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Mar 2022 04:29:40 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 18AAF8399E; Wed, 9 Mar 2022 13:29:34 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id B03EE83999; Wed, 9 Mar 2022 13:28:58 +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=-1.2 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 7534D83981 for ; Wed, 9 Mar 2022 13:28:42 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id ED7FB1688; Wed, 9 Mar 2022 04:28:41 -0800 (PST) Received: from a076522.blr.arm.com (a076522.blr.arm.com [10.162.16.44]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2DBA03FA4D; Wed, 9 Mar 2022 04:28:39 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH v4 4/8] tpm: Add the RNG child device Date: Wed, 9 Mar 2022 17:57:56 +0530 Message-Id: <20220309122800.3940001-5-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220309122800.3940001-1-sughosh.ganu@linaro.org> References: <20220309122800.3940001-1-sughosh.ganu@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.5 at phobos.denx.de X-Virus-Status: Clean The TPM device comes with the random number generator(RNG) functionality which is built into the TPM device. Add logic to add the RNG child device in the TPM uclass post probe callback. The RNG device can then be used to pass a set of random bytes to the linux kernel, need for address space randomisation through the EFI_RNG_PROTOCOL interface. Signed-off-by: Sughosh Ganu --- Changes since V3: * Build the RNG child addition only for the u-boot proper stage using the CONFIG_{SPL,TPL}_BUILD guards instead of CONFIG_TPM config which gets included in all stages. * Remove the child_pre_probe callback which was starting the TPM device based on review from Simon. drivers/tpm/tpm-uclass.c | 40 ++++++++++++++++++++++++++++++++++++---- lib/Kconfig | 1 + 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/drivers/tpm/tpm-uclass.c b/drivers/tpm/tpm-uclass.c index f67fe1019b..241ed01e68 100644 --- a/drivers/tpm/tpm-uclass.c +++ b/drivers/tpm/tpm-uclass.c @@ -11,10 +11,16 @@ #include #include #include +#include #include #include #include "tpm_internal.h" +#include + +#define TPM_RNG1_DRV_NAME "tpm1-rng" +#define TPM_RNG2_DRV_NAME "tpm2-rng" + int tpm_open(struct udevice *dev) { struct tpm_ops *ops = tpm_get_ops(dev); @@ -136,12 +142,38 @@ int tpm_xfer(struct udevice *dev, const uint8_t *sendbuf, size_t send_size, return 0; } +#if !IS_ENABLED(CONFIG_SPL_BUILD) && !IS_ENABLED(CONFIG_TPL_BUILD) +static int tpm_uclass_post_probe(struct udevice *dev) +{ + int ret; + const char *drv = tpm_is_v1(dev) ? + TPM_RNG1_DRV_NAME : TPM_RNG2_DRV_NAME; + struct udevice *child; + + ret = device_bind_driver(dev, drv, "tpm-rng0", &child); + if (ret == -ENOENT) { + log_err("No driver configured for tpm-rng device\n"); + return 0; + } + + if (ret) { + log_err("Unable to bind rng driver with the tpm-rng device\n"); + return ret; + } + + return 0; +} +#endif /* !CONFIG_SPL_BUILD && !CONFIG_TPL_BUILD */ + UCLASS_DRIVER(tpm) = { - .id = UCLASS_TPM, - .name = "tpm", - .flags = DM_UC_FLAG_SEQ_ALIAS, + .id = UCLASS_TPM, + .name = "tpm", + .flags = DM_UC_FLAG_SEQ_ALIAS, #if CONFIG_IS_ENABLED(OF_REAL) - .post_bind = dm_scan_fdt_dev, + .post_bind = dm_scan_fdt_dev, +#endif +#if !IS_ENABLED(CONFIG_SPL_BUILD) && !IS_ENABLED(CONFIG_TPL_BUILD) + .post_probe = tpm_uclass_post_probe, #endif .per_device_auto = sizeof(struct tpm_chip_priv), }; diff --git a/lib/Kconfig b/lib/Kconfig index 3c6fa99b1a..0f05c97afc 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -341,6 +341,7 @@ source lib/crypt/Kconfig config TPM bool "Trusted Platform Module (TPM) Support" depends on DM + select DM_RNG help This enables support for TPMs which can be used to provide security features for your board. The TPM can be connected via LPC or I2C