From patchwork Mon Feb 28 12:06:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 546687 Delivered-To: patch@linaro.org Received: by 2002:ac0:9f50:0:0:0:0:0 with SMTP id l16csp2674784imf; Mon, 28 Feb 2022 04:07:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJza6JMMlVX3JrKAiCG2vNFMimKlPXsnVgE+r1fe9Gj6s0niHmj34b7749FYEk1mBcDIt72U X-Received: by 2002:a05:6402:3549:b0:412:b31c:5509 with SMTP id f9-20020a056402354900b00412b31c5509mr19485199edd.224.1646050072151; Mon, 28 Feb 2022 04:07:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646050072; cv=none; d=google.com; s=arc-20160816; b=nbpxtU2tSicKguySRvQkzCFFEX2OIirw1tLBPjaCn7FVSdt2O6KRbkNa0m6aAAdxWA bdpAsVyM+So6vrMSf8OLz08pl7Mb2Ysn+yjvgWm1QyT+BRE0otpcsJQ/8Kzk+IGRM/b9 xtzRuZlkhV5FkGrmJryMDxdpt9QNzc7b+WwkSpqZKu5zDj4iTftnE2nmg+H4cszbA1yD RESVZrRGwU1nAprziRQdphKrT/YpvtGhyv/XU0vaq1SxVrP2XJ46MKxa3XARYVnmhv3Q dzuuN6n/XDc97zcQGs7EMVnqvECWgFshlBmvlUZ2ocmQQda/TUkWyLPseJudjtRO3bth tjPA== 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=bC83dxM8BwE9vqSRTgK/5Ut9aY6MZv+Fj2rlPw21hcw=; b=S2i0Yrr0Qg8MJN5iuA0uZ6vH/OjRHBoTUa2u0tg5qZLkfbvRhyABcUgiqmR4MTIhhG lJtrY3aK8Ua3BOGs0CVf/V+X2t9/ap27WR39bzTDrXA0hHJE1qx4WWBI7YWykyDvO6P+ 5edrNkrrFsZm+NwgmtXMQIDF0J0serE+SUfNAj1+eq1X9ansAxwBf6BAmcCwEblgxSeC XnQjltxPhLHnvgI0jos0XDt/lB0+OVDjVz328C581sazkWKSsEjN+egaeL5nFo30VAMF 6oOHn7lVhI3VPHv3KY8c0XO98NGeP80VJpCvesCmQF00IPnC+QFVoc+eOmqZEFXO8zBA FkLg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id a14-20020a1709063a4e00b006d0041847aasi6232643ejf.129.2022.02.28.04.07.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 04:07:52 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 3E48083C27; Mon, 28 Feb 2022 13:07:50 +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 8D12F83BE2; Mon, 28 Feb 2022 13:07:34 +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 44B1C83B61 for ; Mon, 28 Feb 2022 13:07:29 +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 724CAED1; Mon, 28 Feb 2022 04:07:28 -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 8D4193F73D; Mon, 28 Feb 2022 04:07:26 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Mario Six , Sughosh Ganu Subject: [PATCH v2 01/10] tpm: Move tpm-utils header under the include directory Date: Mon, 28 Feb 2022 17:36:29 +0530 Message-Id: <20220228120638.678137-2-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220228120638.678137-1-sughosh.ganu@linaro.org> References: <20220228120638.678137-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 random number generation functions of TPM will be moved under a dedicated driver. With this, the function declarations along with some other relevant macro definitions need to be moved under a common header file directory. Move the tpm-utils.h header file under the common include directory. Signed-off-by: Sughosh Ganu Reviewed-by: Heinrich Schuchardt --- Changes since V1: None {lib => include}/tpm-utils.h | 0 lib/tpm-common.c | 2 +- lib/tpm-v1.c | 2 +- lib/tpm-v2.c | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename {lib => include}/tpm-utils.h (100%) diff --git a/lib/tpm-utils.h b/include/tpm-utils.h similarity index 100% rename from lib/tpm-utils.h rename to include/tpm-utils.h diff --git a/lib/tpm-common.c b/lib/tpm-common.c index 82ffdc5341..26506f0b99 100644 --- a/lib/tpm-common.c +++ b/lib/tpm-common.c @@ -11,7 +11,7 @@ #include #include #include -#include "tpm-utils.h" +#include enum tpm_version tpm_get_version(struct udevice *dev) { diff --git a/lib/tpm-v1.c b/lib/tpm-v1.c index 22a769c587..467992e04e 100644 --- a/lib/tpm-v1.c +++ b/lib/tpm-v1.c @@ -13,7 +13,7 @@ #include #include #include -#include "tpm-utils.h" +#include #ifdef CONFIG_TPM_AUTH_SESSIONS diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c index 1bf627853a..2f16b0007b 100644 --- a/lib/tpm-v2.c +++ b/lib/tpm-v2.c @@ -9,7 +9,7 @@ #include #include #include -#include "tpm-utils.h" +#include u32 tpm2_startup(struct udevice *dev, enum tpm2_startup_types mode) { From patchwork Mon Feb 28 12:06:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 546688 Delivered-To: patch@linaro.org Received: by 2002:ac0:9f50:0:0:0:0:0 with SMTP id l16csp2675010imf; Mon, 28 Feb 2022 04:08:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJxwiZJ3lRX969X5Wspru7TEd9lYbk2eg/7jOLPxGj+MnW28bjen1BoP0sVF8UFb52MknuLD X-Received: by 2002:a17:906:1995:b0:6ce:6b78:f9ec with SMTP id g21-20020a170906199500b006ce6b78f9ecmr14910981ejd.459.1646050084161; Mon, 28 Feb 2022 04:08:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646050084; cv=none; d=google.com; s=arc-20160816; b=BaZi4SMNewb9lww46nSo5SMyPVjNGKHr4sHxvtTiUkeFGDU0xacNH7xntVlbaR5c77 t+1z8QlhAyc3OYjYne+7YK2lsUJLR1XQ74P/FOrJgBpMGdLTNEb7Vgj8VkEpeKC5TAEB Q3aGO/qKV4Ic6YWtPnyw4LalTkIgkvNaFLesmjpsmhf7hH6zY7AzkX7oY6vTbjUW7fIj t8tGdaJXplwGeW76wyBuwuzxYiG4SfVjQikjqM8B8PJI1+WBUsjD3L8uOsCYQ6tP4fYf zdtq54bxw9BWbHqEpw2jVpncZBV6sxPr4mCUhW32paRNCUb2BAh9rsSJmZzHimFwHF9P joAg== 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=T87P05tg4RT4VMYcEPAL9S70rQbPc3iU8AqlRGFeu04=; b=KGUyOayXrbrsNv+Wq/4GMY2npdfOxpkdBCKA0QbOVi84goos/fkqlhBcvXbcfUFMo3 X2R1TgZJXsb+sYAE3eK6mVbakj1KTvR/URhTQylmHdkNI3rv/HQIDX/euqsq+IxjPN8o ytNf2CsVCX4dFMWOmtCRi+Vq5IzKExaV+ynuEs/MS0tMVv7+yChmd2ZCZreYQGvpFsRZ Lb55GY5YqO0K2+0wggW2lyzvNJ0CVDuU41uBXA8ierYJfpTJXzZjo8sFAt7CgSNd1+yZ G+6vdnWGa9WoVn55xdBhQV9UqA51WpRgwl6lnh9HqpgOFzd7G3mdr92fu12m2Sl0wrHK Nfog== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id jz3-20020a170906bb0300b006cfd35fb687si5356560ejb.579.2022.02.28.04.08.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 04:08:04 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 6694183BF7; Mon, 28 Feb 2022 13:07:56 +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 7AF31838D6; Mon, 28 Feb 2022 13:07:35 +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 9458B81DD0 for ; Mon, 28 Feb 2022 13:07:31 +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 C6B18ED1; Mon, 28 Feb 2022 04:07:30 -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 E1A6C3F73D; Mon, 28 Feb 2022 04:07:28 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Mario Six , Sughosh Ganu Subject: [PATCH v2 02/10] tpm: rng: Change tpm_get_random to return an int Date: Mon, 28 Feb 2022 17:36:30 +0530 Message-Id: <20220228120638.678137-3-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220228120638.678137-1-sughosh.ganu@linaro.org> References: <20220228120638.678137-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 random number generation functionality will be moved to the driver model. With that, the tpm_get_random function will call the common driver model api instead of separate functions for tpmv1 and tpmv2. Return an int instead of a u32 to comply with the return value of the driver model function. Signed-off-by: Sughosh Ganu Reviewed-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- Changes since V1: None include/tpm_api.h | 4 ++-- lib/tpm_api.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/tpm_api.h b/include/tpm_api.h index ef45b43a8f..b9e3e8b5e6 100644 --- a/include/tpm_api.h +++ b/include/tpm_api.h @@ -274,9 +274,9 @@ u32 tpm_find_key_sha1(struct udevice *dev, const u8 auth[20], * @param dev TPM device * @param data output buffer for the random bytes * @param count size of output buffer - * Return: return code of the operation + * Return: 0 if OK, -ve on error */ -u32 tpm_get_random(struct udevice *dev, void *data, u32 count); +int tpm_get_random(struct udevice *dev, void *data, u32 count); /** * tpm_finalise_physical_presence() - Finalise physical presence diff --git a/lib/tpm_api.c b/lib/tpm_api.c index 4c662640a9..1bbe33a3fc 100644 --- a/lib/tpm_api.c +++ b/lib/tpm_api.c @@ -274,7 +274,7 @@ u32 tpm_get_permissions(struct udevice *dev, u32 index, u32 *perm) return -ENOSYS; } -u32 tpm_get_random(struct udevice *dev, void *data, u32 count) +int tpm_get_random(struct udevice *dev, void *data, u32 count) { if (is_tpm1(dev)) return tpm1_get_random(dev, data, count); From patchwork Mon Feb 28 12:06:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 546689 Delivered-To: patch@linaro.org Received: by 2002:ac0:9f50:0:0:0:0:0 with SMTP id l16csp2675163imf; Mon, 28 Feb 2022 04:08:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJzKe6E7+gomfz0wHebjOcflH938iuykqqpOSUESnYiCXk/pVBre3bbWI31Dtf45YSKs4a3g X-Received: by 2002:a05:6402:2922:b0:40f:7241:74d4 with SMTP id ee34-20020a056402292200b0040f724174d4mr19427137edb.43.1646050093101; Mon, 28 Feb 2022 04:08:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646050093; cv=none; d=google.com; s=arc-20160816; b=cbElnSIS8rcLZ5E3q+/Czgbo6TzHrFMKhKpMriHV3G5Ocf9LjwQCa1yexbPV5E+Sua DBOB+snt1LljCT0cnew4B4zHOhTsxa9FTd5vTNPZipM5paK9Dsnctm5q9FLPw9wWf+Td 65YGakIDooZ691ND0pqwaF0b+sX+JWomklSlxVy8uaTwLAZhrZzTZOIkgILdMjXaCsPe 74wnsbdDJXe9ybpcwHjwdAILySuOLlwCp9hnTpDig1BRyJO6FdCCXHJAkXQDABDNT58W F35zMW3pd7yBQk5012XlePc3z4Xq+BgxjY/kicxd53hP8vmGoy2k+/aElg6bOSx+lStR iBlg== 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=tSIXD+nDJIhtpHyDHMXcrtE9cSFjLIsQvVSihnzBiEc=; b=dFnAQKxO/0ljSRQuMx76mj/NVqCOvDpJ6ZHaSp0pe0mgBHVV73/PA0PPMU/V6CHqbK rd1m6NMm9//S2PAZJBm+FFE21YUB+9W+6b2KSRBDs2Txl2bdI1RD+d7NgrKLNefhRLkX W7H2Ct0EOnu0r5sJhtNPrsfiUze91J4LjOlhAq1PNXJSGgTPN+1qgbIUdyoQBv0x1RSH WEopr2eBJ0hEdzKe04zk9Kujl4I2mqnUdEgCNlbip3ljrzJpd2XpxIqPkbRINbCOrnXr uGDu1Ii9zS7b9CszroP1SLWssT37dEpgey96arCm+14rDB0Gy5HfGakMkXOh6v+2K5NT 5ebQ== 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 g1-20020a1709065d0100b006b9106ceab4si9702343ejt.743.2022.02.28.04.08.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 04:08:13 -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 54C2B83C29; Mon, 28 Feb 2022 13:08:05 +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 9247D838D6; Mon, 28 Feb 2022 13:07:39 +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 F2AFE83BCA for ; Mon, 28 Feb 2022 13:07:33 +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 2808BED1; Mon, 28 Feb 2022 04:07:33 -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 430643F73D; Mon, 28 Feb 2022 04:07:31 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Mario Six , Sughosh Ganu Subject: [PATCH v2 03/10] tpm: Fix the return type of tpm_startup Date: Mon, 28 Feb 2022 17:36:31 +0530 Message-Id: <20220228120638.678137-4-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220228120638.678137-1-sughosh.ganu@linaro.org> References: <20220228120638.678137-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_startup function returns negative values for error conditions. Fix the return type of the function to a signed int instead of a u32. Signed-off-by: Sughosh Ganu Reviewed-by: Simon Glass --- Changes since V1: None include/tpm_api.h | 2 +- lib/tpm_api.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/tpm_api.h b/include/tpm_api.h index b9e3e8b5e6..fb6ee14e23 100644 --- a/include/tpm_api.h +++ b/include/tpm_api.h @@ -18,7 +18,7 @@ * @param mode TPM startup mode * Return: return code of the operation */ -u32 tpm_startup(struct udevice *dev, enum tpm_startup_type mode); +int tpm_startup(struct udevice *dev, enum tpm_startup_type mode); /** * Issue a TPM_SelfTestFull command. diff --git a/lib/tpm_api.c b/lib/tpm_api.c index 1bbe33a3fc..b762202866 100644 --- a/lib/tpm_api.c +++ b/lib/tpm_api.c @@ -21,7 +21,7 @@ static bool is_tpm2(struct udevice *dev) return IS_ENABLED(CONFIG_TPM_V2) && tpm_get_version(dev) == TPM_V2; } -u32 tpm_startup(struct udevice *dev, enum tpm_startup_type mode) +int tpm_startup(struct udevice *dev, enum tpm_startup_type mode) { if (is_tpm1(dev)) { return tpm1_startup(dev, mode); From patchwork Mon Feb 28 12:06:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 546690 Delivered-To: patch@linaro.org Received: by 2002:ac0:9f50:0:0:0:0:0 with SMTP id l16csp2675341imf; Mon, 28 Feb 2022 04:08:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJxL9p8l0GVf/p2f1ejq/XOCGlAxnsmDGKSD26bzxcHcXOx/7WpFeV3OJsOMufDJ1+egBByk X-Received: by 2002:a17:906:5597:b0:6ce:f3cc:14e8 with SMTP id y23-20020a170906559700b006cef3cc14e8mr14987641ejp.426.1646050102335; Mon, 28 Feb 2022 04:08:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646050102; cv=none; d=google.com; s=arc-20160816; b=zMtEzxiTkL8trqy+z4TIonfGJMF7wgiuvdoQO9tsdkwa5Wg8Klb1KTKoGfUi8bq8y9 s+QPK2EHPj2hOyFg74q1iKZ5sORIsBBWBY1evWPBjBk/aIU9l4v5LREb/s69WbgdYiO3 JflDhWdqrWqo36gzxvPPKe3mr1rCjmYQoaoty9v/uQ6T7cTFnApRErXbes/slLgBbI94 95liuRVn8iWtSUqaPM38syOe9yWBD01u11i0PUw6QbyQIZyH0NQ0M6xh8ErjbftAZEs8 B014RrzxtGcXSTB+vFc++IRkRITFNEKKZ+GgEqN8J/+4ucOQrzU31IoSwhExaKwg+h+X utXw== 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=Ciy3sS56azmcMDILPDGK7PlF8SA88R/QZx4aAUd5ZcU=; b=nIYro6AzlY5PMvC4jtRaS6uS1vEvHFagE7RIYRPUKrYsjf/K4EvwtV6UcE/JC1zdIv 57JNPSl0piGTogYoJWuC+LtijwsFum0DCFg0WhboLZ+mcm3lfJZ2maB22iDWd6tTkHzT sWW0TTlym1Ct5FOxp07wv9/oRzP3+C7nYOGH11BoaVrA6q1am9vDtKwri6Fag07Q3DI5 Z/m924Hm1xERQH268082t0Lw3zywLqd943mHdkHGdr5G3VgaBhEboLmBT/mvLHX5xdM+ YuonJuLJSvnznBp8hmM4GID0XZ6aP2ovm0nqI4EzWBF7bQU7/oGTezhvHN43tjOTP+J9 Io5Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id l21-20020a50d6d5000000b00412a7ccf5fesi7250414edj.418.2022.02.28.04.08.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 04:08:22 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 6918183C55; Mon, 28 Feb 2022 13:08:11 +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 BEADC83C5D; Mon, 28 Feb 2022 13:07:46 +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 561078309E for ; Mon, 28 Feb 2022 13:07:36 +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 7CFFEED1; Mon, 28 Feb 2022 04:07:35 -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 982153F73D; Mon, 28 Feb 2022 04:07:33 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Mario Six , Sughosh Ganu Subject: [PATCH v2 04/10] tpm: Move the TPM version detection functions to the uclass driver Date: Mon, 28 Feb 2022 17:36:32 +0530 Message-Id: <20220228120638.678137-5-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220228120638.678137-1-sughosh.ganu@linaro.org> References: <20220228120638.678137-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 Make the TPM version detection functions as external symbols and move them to the TPM uclass driver. These are useful functions to check the TPM device version and should not be static functions. Signed-off-by: Sughosh Ganu Reviewed-by: Heinrich Schuchardt --- Changes since V1: None drivers/tpm/tpm-uclass.c | 11 +++++++++++ include/tpm_api.h | 20 ++++++++++++++++++++ lib/tpm_api.c | 10 ---------- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/drivers/tpm/tpm-uclass.c b/drivers/tpm/tpm-uclass.c index f67fe1019b..8619da89d8 100644 --- a/drivers/tpm/tpm-uclass.c +++ b/drivers/tpm/tpm-uclass.c @@ -11,10 +11,21 @@ #include #include #include +#include #include #include #include "tpm_internal.h" +bool is_tpm1(struct udevice *dev) +{ + return IS_ENABLED(CONFIG_TPM_V1) && tpm_get_version(dev) == TPM_V1; +} + +bool is_tpm2(struct udevice *dev) +{ + return IS_ENABLED(CONFIG_TPM_V2) && tpm_get_version(dev) == TPM_V2; +} + int tpm_open(struct udevice *dev) { struct tpm_ops *ops = tpm_get_ops(dev); diff --git a/include/tpm_api.h b/include/tpm_api.h index fb6ee14e23..c19639a688 100644 --- a/include/tpm_api.h +++ b/include/tpm_api.h @@ -11,6 +11,26 @@ #include #include +/** + * is_tpm1() - Check if it is a tpmv1 device + * @param dev TPM device + * + * Check if the TPM device is a TPMv1 device + * + * Return: 1 if TPMv1, 0 otherwise + */ +bool is_tpm1(struct udevice *dev); + +/** + * is_tpm2() - Check if it is a tpmv2 device + * @param dev TPM device + * + * Check if the TPM device is a TPMv2 device + * + * Return: 1 if TPMv2, 0 otherwise + */ +bool is_tpm2(struct udevice *dev); + /** * Issue a TPM_Startup command. * diff --git a/lib/tpm_api.c b/lib/tpm_api.c index b762202866..9dd9606fa8 100644 --- a/lib/tpm_api.c +++ b/lib/tpm_api.c @@ -11,16 +11,6 @@ #include #include -static bool is_tpm1(struct udevice *dev) -{ - return IS_ENABLED(CONFIG_TPM_V1) && tpm_get_version(dev) == TPM_V1; -} - -static bool is_tpm2(struct udevice *dev) -{ - return IS_ENABLED(CONFIG_TPM_V2) && tpm_get_version(dev) == TPM_V2; -} - int tpm_startup(struct udevice *dev, enum tpm_startup_type mode) { if (is_tpm1(dev)) { From patchwork Mon Feb 28 12:06:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 546691 Delivered-To: patch@linaro.org Received: by 2002:ac0:9f50:0:0:0:0:0 with SMTP id l16csp2675498imf; Mon, 28 Feb 2022 04:08:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJwy6hoSY9LhO+KU6mIXkfvwFlIeCdr3P8konPkq85M8tJJ4GlZktiXCWOJ5sadT4F/V7knN X-Received: by 2002:a50:9f64:0:b0:413:2e49:5bc2 with SMTP id b91-20020a509f64000000b004132e495bc2mr19274775edf.47.1646050112331; Mon, 28 Feb 2022 04:08:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646050112; cv=none; d=google.com; s=arc-20160816; b=Jw9x55t6XYR8MOIO/+Da2wG8xN8ir59srrWjmpeZ+sIlBSdPEjbyncfWtv8py0zQ/d 9/RqVzp+UeNtWvfkOlzyhGl5xeFHns/MXUi8GM1Hz4qXuIJF226NB436EQo+TKvidDcI Or0tezDtsTgP0Vy950rlMpMS5HhCTnAvduv+8F+QEBvtzdBU+dK+QhKp4F9avvEtwnny vatuuSvsZbn7dFd9Rnl7LgVs0H11ZCOBVuaFd+/gX0OJ/oE/dpQTgAC+KRZD/Y9cNnA7 1ATN+X2GUuyo1sREpmwg0fuEV/Gm0GWrcC568kl59wOe9mWUgbDFwypKzGsKkSHpqfW3 8HuA== 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=Eh8sQWWU2VP3Zm+ExxJt0xNQPPWs77GEXvnq4K1e91g=; b=gXIgtTRL4BuQrV7TsqVpkZrpUbTDwEBgoHCX7o4zJu1Gf2gHB+PR66epXpwyFnJnkO +ABr+X1qpOiG5HbcQerSFCFdLT2beVbKqg2RL/UxMjH/S42sMyjYBl1olzdh5gvXIvdL +L4ptS0YNfZs6ugJx6Cxtq3eupSRTfZe667vZAoMEo3b4Hu2y93HeutU3K9zNaw4dOi0 7phyLvSoMDhXYvXGt5sCIYL9gk1qT/H7Ywch/gojcerGJL59LpJpF0eYw4BZfMARevN1 7GRu1YfJ1iVZ59pl0J6LrENuqQ2517LvfxrF9t68j7b5h8rj7C9V2fULjtTJC0wiRhv/ uF+A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id j18-20020a170906535200b006b27a6cae2bsi5649673ejo.762.2022.02.28.04.08.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 04:08:32 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 21F9A83CBC; Mon, 28 Feb 2022 13:08:16 +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 6206983C00; Mon, 28 Feb 2022 13:07:44 +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 B72E683B74 for ; Mon, 28 Feb 2022 13:07:38 +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 D38AAED1; Mon, 28 Feb 2022 04:07:37 -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 EC27D3F73D; Mon, 28 Feb 2022 04:07:35 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Mario Six , Sughosh Ganu Subject: [PATCH v2 05/10] configs: gazerbeam: Build TPMV2 library routines Date: Mon, 28 Feb 2022 17:36:33 +0530 Message-Id: <20220228120638.678137-6-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220228120638.678137-1-sughosh.ganu@linaro.org> References: <20220228120638.678137-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 code currently does a runtime detection of the TPM version and calls appropriate functions. Gazerbeam is one of the platforms where the TPMV2 code is disabled at build time. With this, calling TPM api's from the TPM uclass driver results in link errors. Enable TPMV2 library routines and determine the TPM version at runtime like other platforms. Signed-off-by: Sughosh Ganu --- Changes since V1: None configs/gazerbeam_defconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/configs/gazerbeam_defconfig b/configs/gazerbeam_defconfig index 199afb4d16..b18194aa0f 100644 --- a/configs/gazerbeam_defconfig +++ b/configs/gazerbeam_defconfig @@ -213,7 +213,6 @@ CONFIG_TIMER=y CONFIG_MPC83XX_TIMER=y CONFIG_TPM_ATMEL_TWI=y CONFIG_TPM_AUTH_SESSIONS=y -# CONFIG_TPM_V2 is not set CONFIG_DM_VIDEO=y CONFIG_DISPLAY=y CONFIG_LOGICORE_DP_TX=y From patchwork Mon Feb 28 12:06:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 546693 Delivered-To: patch@linaro.org Received: by 2002:ac0:9f50:0:0:0:0:0 with SMTP id l16csp2675823imf; Mon, 28 Feb 2022 04:08:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJwGpko2YhB77I9xdkcCfU0CNFjeD/TmsHSVJFU0a+/1WGf93GtBK66GEZDrK4UoFxZA1ED+ X-Received: by 2002:a17:906:18b2:b0:6d0:ee54:1add with SMTP id c18-20020a17090618b200b006d0ee541addmr15037414ejf.499.1646050134290; Mon, 28 Feb 2022 04:08:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646050134; cv=none; d=google.com; s=arc-20160816; b=pZjEZAiPH00y4OCCxH7Y5BAmL9RkLbQTjsJb8veRHN7thKurVGWLU5OIuYZuSjL3GF eCG315C6hqEiWXTv8uQU5Hvz4Xid8kB5clFKgDJ9PCGwJDWm+/R2TupsEyIJYj3qeH5E N7tWnYwKLfRIykpg51L1z85j/N22FMaU1QZLpU9oSnsrZ7ec2C+kYZnM1BDhGxK1gfNV xZRDfNViIgetRE6zjaC9GZefSl+LdjIthkyzMj6y7HQL74AfgLPgbtCfYHfptHce4JWe oWwXQoyfPWdKRM16iweCM+NTRkuJo8tn94cyuum3LT96WjKtEnmOatBVIQ5CofRacUWF vpWQ== 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=1kWL7I/TGJOHSEtlW/v8vqkEQG7OoUsEJfvP2qFycSo=; b=X5Zv30PDgTDtUPVCrpAbLzdTvCOjaVrJQ0YgwKHP9F6MwcN50C1tVQ9FM4dGiZMg+9 tw6RbrGlqNUfZPm8fwcgW5LL4NzFscEzVkbUdJ11I9lw60/0jdp4yZ+C15IuDxP3fwIz QpK2F7q3UBp8MBcqg0UNhOSGwylnkbPMN/2G01bsPOopMR5o0dVEJ0D92R+i0MeXa6EV iwGq+mEEBjBcMfzEToD4RBSqJaNOpYN9b0Fa7aOK9xpeTlPK2oZsOLQGG04dqNvbe+rZ pvYF9JLhKRG6Cm8SMURejBkqRe9ZdqqeKFJqYalQzlNgkqehSShhoVQ49lzjcxufn+O4 B28w== 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 f7-20020a50a6c7000000b0041357fadae3si6929042edc.367.2022.02.28.04.08.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 04:08:54 -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 4C37283C29; Mon, 28 Feb 2022 13:08:45 +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 E449C83BDE; Mon, 28 Feb 2022 13:07:49 +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 BB2B183BDE for ; Mon, 28 Feb 2022 13:07:40 +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 31F79ED1; Mon, 28 Feb 2022 04:07:40 -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 4D1AF3F73D; Mon, 28 Feb 2022 04:07:38 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Mario Six , Sughosh Ganu Subject: [PATCH v2 06/10] configs: chromebook_coral: Build TPMV1 library routines Date: Mon, 28 Feb 2022 17:36:34 +0530 Message-Id: <20220228120638.678137-7-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220228120638.678137-1-sughosh.ganu@linaro.org> References: <20220228120638.678137-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 code currently does a runtime detection of the TPM version and calls appropriate functions. Chromebook Coral is one of the platforms where the TPMV1 code is disabled at build time. With this, calling TPM api's from the TPM uclass driver results in link errors. Enable TPMV1 library routines and determine the TPM version at runtime like other platforms. Signed-off-by: Sughosh Ganu --- Changes since V1: None configs/chromebook_coral_defconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/configs/chromebook_coral_defconfig b/configs/chromebook_coral_defconfig index 0cd8f39aa3..4704ce25c8 100644 --- a/configs/chromebook_coral_defconfig +++ b/configs/chromebook_coral_defconfig @@ -104,7 +104,6 @@ CONFIG_SPI=y CONFIG_ICH_SPI=y # CONFIG_SYSINFO_SMBIOS is not set CONFIG_TPL_SYSRESET=y -# CONFIG_TPM_V1 is not set CONFIG_TPM2_CR50_I2C=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_STORAGE=y From patchwork Mon Feb 28 12:06:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 546695 Delivered-To: patch@linaro.org Received: by 2002:ac0:9f50:0:0:0:0:0 with SMTP id l16csp2676145imf; Mon, 28 Feb 2022 04:09:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJz2SvqdqI9TngKUauz5b2kZiw/ZLyEJSB5922zV8a0Q/HB5JahER4BvWwMHqx0Rhrqmh015 X-Received: by 2002:a17:906:b887:b0:6ce:36cb:1e18 with SMTP id hb7-20020a170906b88700b006ce36cb1e18mr15099296ejb.95.1646050158945; Mon, 28 Feb 2022 04:09:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646050158; cv=none; d=google.com; s=arc-20160816; b=c4m02K8k13qUSd+JbYq0yqfT/4W54Ojxml46ilZAlP/S8gZzkYefqQ31wh/87mfu7p 28jyoCXCKgM/8dWhEiWyAC6nnAxvblqWmjZ/HaQxo3RGpfX5MXINiXeqzoInGZFdlBEO B3CeOQc8zRRQ8UlmZA0UJuPmfIH47S4+X23YINTWja0HtteJM8YQAWl3csAoiSy5xEnC CaP/HDmTFW+hREUVvLnlb0Ls/CqvV+kgsGNv4GOfi/DlQBe6IkNH03wVWZxW81kjaI/8 oOUFRDOnY31TXgcq+n+S8on8h11hEvUZ8BD2+NBJq+Kuun7bLEIQdRVAjAtbgJ8h70g9 2YaA== 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=GTqkQ+DZCAnVVBJ5BzQziF6p1rJu/aa09LP083eMvuE=; b=J6cmKGJpgm+fnGRmxrZ6qoSLfJq8uoKLmjVr6Np3NU91g1PbVYbfzQwzVhk9CuRvzS 368jNnHkhEiG8khtYTGI6RkmQJgbHDB7ncHfQq6leXUKnmbBIKjIRdVjQ6y09/6pqQWO XhI62KpayOwtClo5/wHrg7574RetW0r3+OzcWyQ7Iz/LBMFp9z1UaJicmTFC5n29Xw+2 ECeD8mwa6mxjZUHfYo14SmRbb6tva6uNyWodSb5l4kQcaslTwdvhWFUMV5I6ww0mDTud 4RNCsjzqUqgscSI0D5yMm/TTkHKE9BKM+fQlw1LpK79O+QlEk/TTVaWAtl59ZTZSMCmu U13g== 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 a13-20020a1709065f8d00b006d08ca424b4si6047826eju.46.2022.02.28.04.09.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 04:09:18 -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 6762583C8E; Mon, 28 Feb 2022 13:08:55 +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 A25DD838D6; Mon, 28 Feb 2022 13:08:07 +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 C817883C63 for ; Mon, 28 Feb 2022 13:07:43 +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 C04A1ED1; Mon, 28 Feb 2022 04:07:42 -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 A24ED3F73D; Mon, 28 Feb 2022 04:07:40 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Mario Six , Sughosh Ganu Subject: [PATCH v2 07/10] tpm: rng: Move the TPM RNG functionality to driver model Date: Mon, 28 Feb 2022 17:36:35 +0530 Message-Id: <20220228120638.678137-8-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220228120638.678137-1-sughosh.ganu@linaro.org> References: <20220228120638.678137-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 Currently, the TPM random number generator(RNG) functions are defined as part of the library functions under the corresponding tpm files for tpmv1 and tpmv2. Move the RNG functionality under TPM RNG drivers complying with the driver model. Also make changes to the tpm_get_random function to have it call the TPM RNG driver functions instead of the library functions. Signed-off-by: Sughosh Ganu --- Changes since V1: * Added existing copyrights for the rng functions taken from the tpm library routines * Return -EIO for TPM command returning an error * Simplify the logic in tpm_get_random based on the review comments from Ilias drivers/rng/Makefile | 1 + drivers/rng/tpm1_rng.c | 87 ++++++++++++++++++++++++++++++++++++++++++ drivers/rng/tpm2_rng.c | 86 +++++++++++++++++++++++++++++++++++++++++ lib/tpm-v1.c | 44 --------------------- lib/tpm-v2.c | 44 --------------------- lib/tpm_api.c | 23 +++++++++-- 6 files changed, 193 insertions(+), 92 deletions(-) create mode 100644 drivers/rng/tpm1_rng.c create mode 100644 drivers/rng/tpm2_rng.c diff --git a/drivers/rng/Makefile b/drivers/rng/Makefile index 39f7ee3f03..129cfbd006 100644 --- a/drivers/rng/Makefile +++ b/drivers/rng/Makefile @@ -10,3 +10,4 @@ obj-$(CONFIG_RNG_MSM) += msm_rng.o obj-$(CONFIG_RNG_STM32MP1) += stm32mp1_rng.o obj-$(CONFIG_RNG_ROCKCHIP) += rockchip_rng.o obj-$(CONFIG_RNG_IPROC200) += iproc_rng200.o +obj-$(CONFIG_TPM) += tpm1_rng.o tpm2_rng.o diff --git a/drivers/rng/tpm1_rng.c b/drivers/rng/tpm1_rng.c new file mode 100644 index 0000000000..7e629756b3 --- /dev/null +++ b/drivers/rng/tpm1_rng.c @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2013 The Chromium OS Authors. + * Coypright (c) 2013 Guntermann & Drunck GmbH + * Copyright (c) 2022, Linaro Limited + */ + +#include +#include +#include +#include +#include + +#include + +#define TPM_HEADER_SIZE 10 + +#define TPMV1_DATA_OFFSET 14 + +/** + * tpm1_rng_read() - Read the random bytes from TPMv1 device + * @param dev TPMv1 RNG device + * @param data data buffer to write random bytes + * @param count number of random bytes to read from + * the device + * + * Function to read the random bytes from the RNG pseudo device + * built into the TPMv1 device. Reads 'count' number of bytes + * from the random number generator and copies them into the + * 'data' buffer. + * + * Return: 0 if OK, -ve on error. + * + */ +static int tpm1_rng_read(struct udevice *dev, void *data, size_t count) +{ + const u8 command[14] = { + 0x0, 0xc1, /* TPM_TAG */ + 0x0, 0x0, 0x0, 0xe, /* parameter size */ + 0x0, 0x0, 0x0, 0x46, /* TPM_COMMAND_CODE */ + }; + const size_t length_offset = TPM_HEADER_SIZE; + const size_t data_size_offset = TPM_HEADER_SIZE; + const size_t data_offset = TPMV1_DATA_OFFSET; + u8 buf[COMMAND_BUFFER_SIZE], response[COMMAND_BUFFER_SIZE]; + size_t response_length = sizeof(response); + u32 data_size; + u8 *out = data; + + while (count > 0) { + u32 this_bytes = min(count, + sizeof(response) - data_offset); + u32 err; + + if (pack_byte_string(buf, sizeof(buf), "sd", + 0, command, sizeof(command), + length_offset, this_bytes)) + return -EIO; + err = tpm_sendrecv_command(dev->parent, buf, response, + &response_length); + if (err) + return err; + if (unpack_byte_string(response, response_length, "d", + data_size_offset, &data_size)) + return -EIO; + if (data_size > count) + return TPM_LIB_ERROR; + if (unpack_byte_string(response, response_length, "s", + data_offset, out, data_size)) + return -EIO; + + count -= data_size; + out += data_size; + } + + return 0; +} + +static const struct dm_rng_ops tpm1_rng_ops = { + .read = tpm1_rng_read, +}; + +U_BOOT_DRIVER(tpm1_rng) = { + .name = "tpm1-rng", + .id = UCLASS_RNG, + .ops = &tpm1_rng_ops, +}; diff --git a/drivers/rng/tpm2_rng.c b/drivers/rng/tpm2_rng.c new file mode 100644 index 0000000000..e7f6be46e4 --- /dev/null +++ b/drivers/rng/tpm2_rng.c @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2018 Bootlin + * Copyright (c) 2022, Linaro Limited + */ + +#include +#include +#include +#include +#include + +#include + +#define TPM_HEADER_SIZE 10 + +#define TPMV2_DATA_OFFSET 12 + +/** + * tpm2_rng_read() - Read the random bytes from TPMv2 device + * @param dev TPMv2 RNG device + * @param data data buffer to write random bytes + * @param count number of random bytes to read from + * the device + * + * Function to read the random bytes from the RNG pseudo device + * built into the TPMv2 device. Reads 'count' number of bytes + * from the random number generator and copies them into the + * 'data' buffer. + * + * Return: 0 if OK, -ve on error. + * + */ +static int tpm2_rng_read(struct udevice *dev, void *data, size_t count) +{ + const u8 command_v2[10] = { + tpm_u16(TPM2_ST_NO_SESSIONS), + tpm_u32(12), + tpm_u32(TPM2_CC_GET_RANDOM), + }; + u8 buf[COMMAND_BUFFER_SIZE], response[COMMAND_BUFFER_SIZE]; + + const size_t data_size_offset = TPM_HEADER_SIZE; + const size_t data_offset = TPMV2_DATA_OFFSET; + size_t response_length = sizeof(response); + u32 data_size; + u8 *out = data; + + while (count > 0) { + u32 this_bytes = min((size_t)count, + sizeof(response) - data_offset); + u32 err; + + if (pack_byte_string(buf, sizeof(buf), "sw", + 0, command_v2, sizeof(command_v2), + sizeof(command_v2), this_bytes)) + return -EIO; + err = tpm_sendrecv_command(dev->parent, buf, response, + &response_length); + if (err) + return err; + if (unpack_byte_string(response, response_length, "w", + data_size_offset, &data_size)) + return -EIO; + if (data_size > this_bytes) + return TPM_LIB_ERROR; + if (unpack_byte_string(response, response_length, "s", + data_offset, out, data_size)) + return -EIO; + + count -= data_size; + out += data_size; + } + + return 0; +} + +static const struct dm_rng_ops tpm2_rng_ops = { + .read = tpm2_rng_read, +}; + +U_BOOT_DRIVER(tpm2_rng) = { + .name = "tpm2-rng", + .id = UCLASS_RNG, + .ops = &tpm2_rng_ops, +}; diff --git a/lib/tpm-v1.c b/lib/tpm-v1.c index 467992e04e..71cc90a2ab 100644 --- a/lib/tpm-v1.c +++ b/lib/tpm-v1.c @@ -868,47 +868,3 @@ u32 tpm1_find_key_sha1(struct udevice *dev, const u8 auth[20], #endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */ #endif /* CONFIG_TPM_AUTH_SESSIONS */ - -u32 tpm1_get_random(struct udevice *dev, void *data, u32 count) -{ - const u8 command[14] = { - 0x0, 0xc1, /* TPM_TAG */ - 0x0, 0x0, 0x0, 0xe, /* parameter size */ - 0x0, 0x0, 0x0, 0x46, /* TPM_COMMAND_CODE */ - }; - const size_t length_offset = 10; - const size_t data_size_offset = 10; - const size_t data_offset = 14; - u8 buf[COMMAND_BUFFER_SIZE], response[COMMAND_BUFFER_SIZE]; - size_t response_length = sizeof(response); - u32 data_size; - u8 *out = data; - - while (count > 0) { - u32 this_bytes = min((size_t)count, - sizeof(response) - data_offset); - u32 err; - - if (pack_byte_string(buf, sizeof(buf), "sd", - 0, command, sizeof(command), - length_offset, this_bytes)) - return TPM_LIB_ERROR; - err = tpm_sendrecv_command(dev, buf, response, - &response_length); - if (err) - return err; - if (unpack_byte_string(response, response_length, "d", - data_size_offset, &data_size)) - return TPM_LIB_ERROR; - if (data_size > count) - return TPM_LIB_ERROR; - if (unpack_byte_string(response, response_length, "s", - data_offset, out, data_size)) - return TPM_LIB_ERROR; - - count -= data_size; - out += data_size; - } - - return 0; -} diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c index 2f16b0007b..c1456c1974 100644 --- a/lib/tpm-v2.c +++ b/lib/tpm-v2.c @@ -562,50 +562,6 @@ u32 tpm2_pcr_setauthvalue(struct udevice *dev, const char *pw, return tpm_sendrecv_command(dev, command_v2, NULL, NULL); } -u32 tpm2_get_random(struct udevice *dev, void *data, u32 count) -{ - const u8 command_v2[10] = { - tpm_u16(TPM2_ST_NO_SESSIONS), - tpm_u32(12), - tpm_u32(TPM2_CC_GET_RANDOM), - }; - u8 buf[COMMAND_BUFFER_SIZE], response[COMMAND_BUFFER_SIZE]; - - const size_t data_size_offset = 10; - const size_t data_offset = 12; - size_t response_length = sizeof(response); - u32 data_size; - u8 *out = data; - - while (count > 0) { - u32 this_bytes = min((size_t)count, - sizeof(response) - data_offset); - u32 err; - - if (pack_byte_string(buf, sizeof(buf), "sw", - 0, command_v2, sizeof(command_v2), - sizeof(command_v2), this_bytes)) - return TPM_LIB_ERROR; - err = tpm_sendrecv_command(dev, buf, response, - &response_length); - if (err) - return err; - if (unpack_byte_string(response, response_length, "w", - data_size_offset, &data_size)) - return TPM_LIB_ERROR; - if (data_size > this_bytes) - return TPM_LIB_ERROR; - if (unpack_byte_string(response, response_length, "s", - data_offset, out, data_size)) - return TPM_LIB_ERROR; - - count -= data_size; - out += data_size; - } - - return 0; -} - u32 tpm2_write_lock(struct udevice *dev, u32 index) { u8 command_v2[COMMAND_BUFFER_SIZE] = { diff --git a/lib/tpm_api.c b/lib/tpm_api.c index 9dd9606fa8..5492f89959 100644 --- a/lib/tpm_api.c +++ b/lib/tpm_api.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -264,12 +265,26 @@ u32 tpm_get_permissions(struct udevice *dev, u32 index, u32 *perm) return -ENOSYS; } +#if CONFIG_IS_ENABLED(DM_RNG) int tpm_get_random(struct udevice *dev, void *data, u32 count) { + int ret = -ENOSYS; + struct udevice *rng_dev; + if (is_tpm1(dev)) - return tpm1_get_random(dev, data, count); + ret = uclass_get_device_by_driver(UCLASS_RNG, + DM_DRIVER_GET(tpm1_rng), + &rng_dev); else if (is_tpm2(dev)) - return -ENOSYS; /* not implemented yet */ - else - return -ENOSYS; + ret = uclass_get_device_by_driver(UCLASS_RNG, + DM_DRIVER_GET(tpm2_rng), + &rng_dev); + + if (ret) { + log_err("Getting tpm rng device failed\n"); + return ret; + } + + return dm_rng_read(rng_dev, data, (size_t)count); } +#endif /* DM_RNG */ From patchwork Mon Feb 28 12:06:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 546694 Delivered-To: patch@linaro.org Received: by 2002:ac0:9f50:0:0:0:0:0 with SMTP id l16csp2675997imf; Mon, 28 Feb 2022 04:09:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJwaU2eHbf/vEcJ3dAB3G0LLqd7urG4D/5/HPEbGnfPb3xJVcZKD1VIUnhKx56d+7L8SxQar X-Received: by 2002:a05:6402:13cb:b0:410:820f:4e8 with SMTP id a11-20020a05640213cb00b00410820f04e8mr18734290edx.352.1646050147553; Mon, 28 Feb 2022 04:09:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646050147; cv=none; d=google.com; s=arc-20160816; b=doKM2L8m4cbU2lFTR48R7eugaTV333y1S5zJdnyRyabmWuS165YI7SGOfO32LILlHq GLzky7wO5zqhqWOanHQUgHNqlluK1XqnhyzmTFtDJOapoqBWiAgBLn5GCp42auZEIr34 Y1iu41YJxQgTMhpFZwWZOhWxuiZE/nk9T+Sn35I5hnBPcg9YXuWEpNYO+RWVcaMq2WuW OJAoDaQmPyUce3g6QYb26ZiZtOfO/2Vjo5wXpig68wse9R5mF1v52dXtgx3tpjHlefS6 7wIlfEUK2EUP7gf0YN2joluPKnYEPQzDtopJrWTuMSJQQGwFMc9PL+2Ukn1TERxDd+Nj /K4Q== 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=N4kjjGijcazVdsC0uEglXoxTBYuwwU1LeDLT1rZdqC4=; b=qto7JBIuu80QED89okq7mH6wDJg9X7QYKhBDnKd0Fz5QyJVB3tACeXa5zKUcgmF3Kz JwtI+/oqYmbo9/EpmL0d9M5QwpCM5/y0UzrV3cPc5TtksSYajctpRRA+HCFYaj699yj7 UJAzjUPQn/qkEK4xyZRbL6j/rBVEmCbm/oBGnHJGl2/oOPSHxT9Yv9337VNXqq+b0F6U rxqN7l+kWSCtg9RUpvlXuxGpiMmlLhyo9gShpodg34pfG2AXUb3/GSNSSpdmUEV48/OQ Dsk4GjmnHoFR9yEMtEDqJtHSW1jhX9/WcKENa3saY7ivSLDNltFtY8IUac1Akf7ovQzs TvWA== 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 q19-20020a056402519300b00410ed6741d9si7013154edd.465.2022.02.28.04.09.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 04:09:07 -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 7B14583C71; Mon, 28 Feb 2022 13:08:52 +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 3FBD383B74; Mon, 28 Feb 2022 13:08:03 +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 B9EB0838D6 for ; Mon, 28 Feb 2022 13:07:45 +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 213E8ED1; Mon, 28 Feb 2022 04:07:45 -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 3CBB73F73D; Mon, 28 Feb 2022 04:07:43 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Mario Six , Sughosh Ganu Subject: [PATCH v2 08/10] tpm: Add the RNG child device Date: Mon, 28 Feb 2022 17:36:36 +0530 Message-Id: <20220228120638.678137-9-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220228120638.678137-1-sughosh.ganu@linaro.org> References: <20220228120638.678137-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 V1: None drivers/tpm/tpm-uclass.c | 58 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/drivers/tpm/tpm-uclass.c b/drivers/tpm/tpm-uclass.c index 8619da89d8..383cc7bc48 100644 --- a/drivers/tpm/tpm-uclass.c +++ b/drivers/tpm/tpm-uclass.c @@ -16,6 +16,11 @@ #include #include "tpm_internal.h" +#include + +#define TPM_RNG1_DRV_NAME "tpm1-rng" +#define TPM_RNG2_DRV_NAME "tpm2-rng" + bool is_tpm1(struct udevice *dev) { return IS_ENABLED(CONFIG_TPM_V1) && tpm_get_version(dev) == TPM_V1; @@ -147,12 +152,57 @@ int tpm_xfer(struct udevice *dev, const uint8_t *sendbuf, size_t send_size, return 0; } +#if IS_ENABLED(CONFIG_TPM) +static int tpm_uclass_post_probe(struct udevice *dev) +{ + int ret; + const char *drv = is_tpm1(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; +} + +static int tpm_uclass_child_pre_probe(struct udevice *dev) +{ + int ret; + + ret = tpm_open(dev->parent); + if (ret == -EBUSY) { + log_info("TPM device already opened\n"); + } else if (ret) { + log_err("Unable to open TPM device\n"); + return ret; + } + + ret = tpm_startup(dev->parent, TPM_ST_CLEAR); + if (ret) + log_err("Unable to start TPM device\n"); + + return ret; +} +#endif /* CONFIG_TPM */ + 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_TPM) + .post_probe = tpm_uclass_post_probe, + .child_pre_probe = tpm_uclass_child_pre_probe, #endif .per_device_auto = sizeof(struct tpm_chip_priv), }; From patchwork Mon Feb 28 12:06:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 546692 Delivered-To: patch@linaro.org Received: by 2002:ac0:9f50:0:0:0:0:0 with SMTP id l16csp2675651imf; Mon, 28 Feb 2022 04:08:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJzoIInZCm9e8C0bfXPkg9DsUbLcQsOiQonRUm2mLZspv7Al1qOZvxArva/Nrif/pcPQp09O X-Received: by 2002:a17:906:b845:b0:6cf:37d1:f246 with SMTP id ga5-20020a170906b84500b006cf37d1f246mr15143152ejb.280.1646050122335; Mon, 28 Feb 2022 04:08:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646050122; cv=none; d=google.com; s=arc-20160816; b=n5ShdQO9qNhnmGmEhz9BI3yqKI1i8C/+hIU8I5IFdicl41T+1P75Epq0tPE9nF0ez6 a/+Y4knhU0qg3uPE20qIzcnfNpI+YYRcSa5BVVrP8RnU0Sdfu+gOjk1mycjQIgfby9Wy BFHXXsyqJaFOV16U59MjVlu9XEEGqotS0tKI54WyrTBb1d1p3zC8htrGs6TXAT1OdBSz 7DmalCjDbvdGOaOqcRo3LdNeyrBd8OPOKN7RW74PWMy0FbhOBB4noCMwTeBUrgBw/IGz R2tR4sONV8EjUCsYxyMqpmGW8khhDSA0rARM4AQDOrSCP15YUuq9UqhePKWigV13BB59 UjlA== 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=3GuJ93PcEi0e1UOlnER8/NYSkoJnVKXQS40GmAtz2oQ=; b=A4PAMqKmEZ9CwTb221Vyn1AHHHUm/m2yLKb9ylggwjI5y2zeruM/koa4ib/DaBPcvw osMeXcHKu2h30atoGNlZ061/IuaIBdXLH1MyTX35fRYYlngSCRij5rJWOCtlwbnlAUiK aran6EYNwxYnFjZ3LpjaDyiHMAYx/FJpdF32GeUFxRp9Id6Hv3F4ZiNbqiBsus1qsW5U 4vE0LRptBNiLUHtWkDdYiAQnnimOZ5tXFxcvEHoc8RIsgd2lbW4OZF80tFx9g8EBedRE SoTt2mf6rtcTPSxumFeTDa3k9rTmYO9IBELKnWGl6nl13o+KAnpjciMYnhTQMT957hj0 7G1A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id q24-20020aa7cc18000000b00410b96067e0si6445856edt.446.2022.02.28.04.08.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 04:08:42 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 9D06D83C27; Mon, 28 Feb 2022 13:08:40 +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 C75AB83C2D; Mon, 28 Feb 2022 13:08:07 +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 0A70B8309E for ; Mon, 28 Feb 2022 13:07:48 +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 76555ED1; Mon, 28 Feb 2022 04:07:47 -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 916533F73D; Mon, 28 Feb 2022 04:07:45 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Mario Six , Sughosh Ganu Subject: [PATCH v2 09/10] qemu: arm: Remove platform specific function to get RNG device Date: Mon, 28 Feb 2022 17:36:37 +0530 Message-Id: <20220228120638.678137-10-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220228120638.678137-1-sughosh.ganu@linaro.org> References: <20220228120638.678137-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 Qemu platform has a function defined to get the random number generator(RNG) device. However, the RNG device can be obtained simply by searching for a device belonging to the RNG uclass. Remove the superfluous platform function defined for the Qemu platform for getting the RNG device. Signed-off-by: Sughosh Ganu Tested-by: Heinrich Schuchardt --- Changes since V1: None board/emulation/qemu-arm/qemu-arm.c | 42 ----------------------------- 1 file changed, 42 deletions(-) diff --git a/board/emulation/qemu-arm/qemu-arm.c b/board/emulation/qemu-arm/qemu-arm.c index 16d5a97167..c9e886e44a 100644 --- a/board/emulation/qemu-arm/qemu-arm.c +++ b/board/emulation/qemu-arm/qemu-arm.c @@ -107,48 +107,6 @@ void enable_caches(void) dcache_enable(); } -#if defined(CONFIG_EFI_RNG_PROTOCOL) -#include -#include - -#include - -efi_status_t platform_get_rng_device(struct udevice **dev) -{ - int ret; - efi_status_t status = EFI_DEVICE_ERROR; - struct udevice *bus, *devp; - - for (uclass_first_device(UCLASS_VIRTIO, &bus); bus; - uclass_next_device(&bus)) { - for (device_find_first_child(bus, &devp); devp; - device_find_next_child(&devp)) { - if (device_get_uclass_id(devp) == UCLASS_RNG) { - *dev = devp; - status = EFI_SUCCESS; - break; - } - } - } - - if (status != EFI_SUCCESS) { - debug("No rng device found\n"); - return EFI_DEVICE_ERROR; - } - - if (*dev) { - ret = device_probe(*dev); - if (ret) - return EFI_DEVICE_ERROR; - } else { - debug("Couldn't get child device\n"); - return EFI_DEVICE_ERROR; - } - - return EFI_SUCCESS; -} -#endif /* CONFIG_EFI_RNG_PROTOCOL */ - #ifdef CONFIG_ARM64 #define __W "w" #else From patchwork Mon Feb 28 12:06:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 546696 Delivered-To: patch@linaro.org Received: by 2002:ac0:9f50:0:0:0:0:0 with SMTP id l16csp2676260imf; Mon, 28 Feb 2022 04:09:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJwTW867gecH+Kk3ldW8fHaCvNyruR0wCgUEExesRmrKPTemieRTAWh5PEPT5KxLdYdvRWGT X-Received: by 2002:aa7:c7c4:0:b0:407:52cc:3b32 with SMTP id o4-20020aa7c7c4000000b0040752cc3b32mr19014220eds.397.1646050169063; Mon, 28 Feb 2022 04:09:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646050169; cv=none; d=google.com; s=arc-20160816; b=unVRmw2WefPslE5yDP3Mep1dAdPJeeJvahYRps3ww1ZLPRAfqOV2CKA4V4xcOgXtB9 2OWwY6FDIg+q+aJxYwL5mgL2GEcEPyP0UoeKAwbB9Cqa3sjflRfZHBQnAWIJnuF8kmpL Z9ogWX6Pz0Fb/Vro2ZNCKSr90yHdrdK+V/mdcN11uVKRGrFlqGdRexulhS/C/BoKkn7J ziOGFiw/lZNupObOu/bZKxLWm8tnZsVx/QVdu9fPHTmn91RaQT6uEizyxcKswnt99MV9 2Q1ajfmZT8t/nw5RW9tnH76SpFw06kqHNEBVYudUMsZrpfZqwgYtt60aMf5Tuf+1ff7n gWSA== 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=GQClj6TZVSVZxjTrOusPngtJfWb/xE8IUG3ZsSnjG/8=; b=dpcNnNbKW3X05x2/S54HrwxD7Wb7cuG19y/O7FEmIy3qIunNW71ldUmEB2dj6JVJER 0RIzIiVtwawzy09EyHaLXgIyVEX1oEgSGloYiaLmHzUCGPLfzXspzptrkgG04kmm0/CM l9U70U6Q9RG1pCq3HEPoDCkrHwMDlCLkdhxzFXuALMq5qgP/qt/8etD/Fu3iaIkYRXd0 uCIvivvWBb0JmEkSSrZE7Y9DXfvDyqN8LmmHQAsyvy6AD2Nd8DDXXoIlX1g+3AobTgUd 44cVUOWYSL27/0wFnPAulDJhdxK+gFWACF2WzivlMOrl+eG5SqCxpU/6u/cWrdYP1axx tvaw== 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 hk8-20020a170906c9c800b006d128a5b1e0si6392819ejb.144.2022.02.28.04.09.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 04:09:29 -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 C161983CCE; Mon, 28 Feb 2022 13:08:59 +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 B9CD983C88; Mon, 28 Feb 2022 13:08:16 +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 7116F83C5D for ; Mon, 28 Feb 2022 13:07:50 +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 CAFAFED1; Mon, 28 Feb 2022 04:07:49 -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 E65CC3F73D; Mon, 28 Feb 2022 04:07:47 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Mario Six , Sughosh Ganu Subject: [PATCH v2 10/10] cmd: rng: Add support for selecting RNG device Date: Mon, 28 Feb 2022 17:36:38 +0530 Message-Id: <20220228120638.678137-11-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220228120638.678137-1-sughosh.ganu@linaro.org> References: <20220228120638.678137-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 'rng' u-boot command is used for printing a select number of random bytes on the console. Currently, the RNG device from which the random bytes are read is fixed. However, a platform can have multiple RNG devices, one example being qemu, which has a virtio RNG device and the RNG pseudo device through the TPM chip. Extend the 'rng' command so that the user can provide the RNG device number from which the random bytes are to be read. This will be the device index under the RNG uclass. Signed-off-by: Sughosh Ganu Tested-by: Heinrich Schuchardt --- Changes since V1: * Changed the help text to show order of the parameters passed to the rng command, based on review comment from Heinrich cmd/rng.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/cmd/rng.c b/cmd/rng.c index 1ad5a096c0..bb89cfa784 100644 --- a/cmd/rng.c +++ b/cmd/rng.c @@ -13,19 +13,34 @@ static int do_rng(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { - size_t n = 0x40; + size_t n; struct udevice *dev; void *buf; + int devnum; int ret = CMD_RET_SUCCESS; - if (uclass_get_device(UCLASS_RNG, 0, &dev) || !dev) { + switch (argc) { + case 1: + devnum = 0; + n = 0x40; + break; + case 2: + devnum = hextoul(argv[1], NULL); + n = 0x40; + break; + case 3: + devnum = hextoul(argv[1], NULL); + n = hextoul(argv[2], NULL); + break; + default: + return CMD_RET_USAGE; + } + + if (uclass_get_device(UCLASS_RNG, devnum, &dev) || !dev) { printf("No RNG device\n"); return CMD_RET_FAILURE; } - if (argc >= 2) - n = hextoul(argv[1], NULL); - buf = malloc(n); if (!buf) { printf("Out of memory\n"); @@ -46,12 +61,12 @@ static int do_rng(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) #ifdef CONFIG_SYS_LONGHELP static char rng_help_text[] = - "[n]\n" - " - print n random bytes\n"; + "[dev [n]]\n" + " - print n random bytes read from dev\n"; #endif U_BOOT_CMD( - rng, 2, 0, do_rng, + rng, 3, 0, do_rng, "print bytes from the hardware random number generator", rng_help_text );