From patchwork Thu Feb 24 18:05:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 545591 Delivered-To: patch@linaro.org Received: by 2002:ac0:d8d1:0:0:0:0:0 with SMTP id b17csp437079imj; Thu, 24 Feb 2022 10:06:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJyJHh6hhlrVctBYLcx8aYu/i3BNhlyNTHQCq0mkNq5mqu+5JAlzx5jT6H0nyT77EuDZXyU9 X-Received: by 2002:a17:907:98a5:b0:6ce:8c66:e75e with SMTP id ju5-20020a17090798a500b006ce8c66e75emr3401069ejc.239.1645726001609; Thu, 24 Feb 2022 10:06:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645726001; cv=none; d=google.com; s=arc-20160816; b=0sWypNvkzgzeBtCtC55sGj+S8A1P6ayQvGFvd55YAalXCu0W8aeOrumk2KPDun5vf1 A+mM4WAvys40b3EGg/DGhTPD0C2BezobkTCwLQC376oYz0DF1McyVqPjwCEnoDpZJ27H y4gwEieEOD28tAoMMBraxMrYYn/pg4PUiMHGD8zII1mcSVbr1F4PyrdnIGgxzRew5yas xAFJhp76lj120cqZIYMkNS9+wGBE+Vw/NAsZ8Br7JXl06fhNdZS7rRLn1la1xjiIkWlV AU6ygLqFr8njBi1c7mLd6Ig+CtwV1/aU3Gf21NLkVMVcgBIE3vn5Zpm2ei3a8MWgvvap DsaA== 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:references:in-reply-to :message-id:date:subject:cc:to:from; bh=wKA3oVaXl9pS5RsgOACJw7LcXV93L02qUMS6iUBUxrM=; b=xqo0gW55NuLQhFtrlD86ov3VrIA/YHJWc584XggdHeydIkihkSjxJDrNDc1uIQBPaa K2797fiHi6iJlvrkAq+g9n6cB1CTQMxsSlOXamrsu+EHqDNL1s36CjUTfv2pB37lH9X0 gom2V16Qp/2S3a8BcU9QLuI1Zk+NXJMBZ5F4Qj2gt86vi74vVgLQEQJCqYBp9XmjhZFA T4fiLQKr5LAaHcEsyNrsQqf9I4IPIRglTgycNL8QZouaLTWW4eRlCxwODrEsWawxtCMz opyX6Za2cFzdoIFTEzMQmYmM5PoTisVDUlGS6GJ/wh+fE+KnkDQF3kZFoOQPcc6+eEfn CCfQ== 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 k7-20020a170906578700b006d5dcacfed1si76624ejq.297.2022.02.24.10.06.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 10:06:41 -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 E064983C90; Thu, 24 Feb 2022 19:06:23 +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 3F0D183CB1; Thu, 24 Feb 2022 19:06:20 +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 8A95483C1C for ; Thu, 24 Feb 2022 19:06:16 +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 ED379106F; Thu, 24 Feb 2022 10:06:15 -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 8CBB13F70D; Thu, 24 Feb 2022 10:06:13 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Mario Six , Sughosh Ganu Subject: [PATCH 01/10] tpm: Move tpm-utils header under the include directory Date: Thu, 24 Feb 2022 23:35:43 +0530 Message-Id: <20220224180552.26901-2-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220224180552.26901-1-sughosh.ganu@linaro.org> References: <20220224180552.26901-1-sughosh.ganu@linaro.org> 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 Reviewed-by: Ilias Apalodimas --- {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 Thu Feb 24 18:05:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 545592 Delivered-To: patch@linaro.org Received: by 2002:ac0:d8d1:0:0:0:0:0 with SMTP id b17csp437164imj; Thu, 24 Feb 2022 10:06:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJxm+GPUq3z5xJ6xQfQolSxReg2MxdWSB7r7J9VeJU7W/gHgBnTSwDt4LPhaGTboFG2ZXBvg X-Received: by 2002:a17:906:fa02:b0:6ce:78fb:2b94 with SMTP id lo2-20020a170906fa0200b006ce78fb2b94mr3235831ejb.396.1645726007370; Thu, 24 Feb 2022 10:06:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645726007; cv=none; d=google.com; s=arc-20160816; b=ULTLtt8yry+cRrcqlEEQ4Bzu3hhdag9qytNuM3NBLRJU8mF4/rzGh5IeyZX3pno4bd mWkYsU6f+igMGpphRvx5MQEEvgnyLnvwNyKlp0M9C+oGQdMKTfwjA1lyX1YDB5eQZrIN DOUxwlDtibK07z96Ke4+G2TbB+HNd00ejiMOhZ98EfxMS4/h5kq8UdiXpgorIYXrlSFo y0kDvdDW5ii/+/Y8boKvZYKkHOsxKF+qEfiEQVztv5cn8sYKRHhEYp14L5McHaJEwd9L h0ffEkHRRmP/799KFDuOAmohbVa1jKp9Idwsn5vlOwhanSIVT5M8kf+hnjFhDQMpJsXB Kzng== 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:references:in-reply-to :message-id:date:subject:cc:to:from; bh=htoleddqkwlHbvr0aPNGgckK3YjwQ5yRuamQ07tJ8q0=; b=SQqsVo2XIlSK3DLLR+ZwN83oZF6RNwgqmwVVfy9ugH9mbqewAnqL3fm3qMnyXWwhfa 8xLooh0Mu5iCXuzcPj0Jd2vargtzxJLqP/dzJCmEfPTyxNE/2mHvilDM6IhUa9qD62E1 CD2cxSXfPeuRygPHL4jhY4G7OsA0QL+uuNYHUdEUCNm9D3vcu3LZywnWvgQ1PrZUDktd eOEfbnKgVJU9bmb9IQXtM1eLBuk/p13bGdtTChBqIauMrTrjCx7m2ypT6uuXD43KEwqO Jm08aiQ1zZPdaf0jYxCvQqqITOUddOLqfy2i5jYqqUOegvKufCwG82y6QYLzZiAgzcl+ 86fw== 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 n9-20020aa7c689000000b00410ee833c70si147615edq.596.2022.02.24.10.06.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 10:06:47 -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 EB3E883CC5; Thu, 24 Feb 2022 19:06:26 +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 3038F83C23; Thu, 24 Feb 2022 19:06:23 +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 87F1283C90 for ; Thu, 24 Feb 2022 19:06:19 +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 E8634106F; Thu, 24 Feb 2022 10:06:18 -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 87E2A3F70D; Thu, 24 Feb 2022 10:06:16 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Mario Six , Sughosh Ganu Subject: [PATCH 02/10] tpm: rng: Change tpm_get_random to return an int Date: Thu, 24 Feb 2022 23:35:44 +0530 Message-Id: <20220224180552.26901-3-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220224180552.26901-1-sughosh.ganu@linaro.org> References: <20220224180552.26901-1-sughosh.ganu@linaro.org> 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: Ilias Apalodimas --- 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 Thu Feb 24 18:05:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 545593 Delivered-To: patch@linaro.org Received: by 2002:ac0:d8d1:0:0:0:0:0 with SMTP id b17csp437311imj; Thu, 24 Feb 2022 10:06:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJxXq2+tnyzTwz65ESW6fPnoYqVAu+Sr7WDe2P53rAe6SB2Vh6W4ACIzSYghcB2u9k+isoS/ X-Received: by 2002:a17:906:53d2:b0:6ce:791a:31a0 with SMTP id p18-20020a17090653d200b006ce791a31a0mr3254222ejo.59.1645726018016; Thu, 24 Feb 2022 10:06:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645726018; cv=none; d=google.com; s=arc-20160816; b=kaDl+jEg6s4M5zXOlenvvpO6XwfJs4JuTkcMf0wsUZNyCNDO5VSQMXt7Sbf8X5MJfz OYoABkzYytiUa0q3TupcppLOeVY7sLCWaxn+FATmrybnTEXJoAHWz1N0DMoqRDpyVdSy vPPi8FIuAFpAdeMXwxDcHQh18rEK+Fs+I8k1TbkEL0PWEVMwoFzlputs/V4vAibO+3KM 047b9Z9KT4a1Wv1u9eFkTaG4KxITVJf4iIJzwFAu0F3Wqexm2rHkCJ1ncfk1b1sPUgYi hlSCD3dG6fz8eopfSZX4DKDqpxeFMCwZvXb58N0XQ308cQO0qdIvWbgfwt6O0VgGRE3j fPZg== 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:references:in-reply-to :message-id:date:subject:cc:to:from; bh=7YL5Yly0/WO/dgWvaYLJkY22NZbsFwZDto8wvTX91sE=; b=Slz9aeHzWHdjM2O6qNEDYu4eOC1XWdOsq01ct7e+L3DDycecU1Y47/lKpcq8f+xKsw G27Umxf7YjP+vEW2tnYFuKvni3zqXscomwgCiq/ktn1CogJpZ7O/GwMn8a3nq3oK+Obp uPz0OaNdObqBoT5uzUi4nW6P93IojAjOlMgc+V+3AaS2DK7f0tExTIv6eYPN0CF/h2N9 KYumDwnewImbBzyYbWty9k2ggnhRTCTFpvlRvQnB9Qn+gPXIWHGV8GvkYND+tfhoJTH5 nr7VMaaM0XDPOyHFRgGeLZFDIsOE+LEHql3badNjtjrPmlVbBFdoCSljXxuA1TMQUj5R wUaQ== 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 gz10-20020a170906f2ca00b006d6325d9c58si49289ejb.679.2022.02.24.10.06.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 10:06:58 -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 28BDA83CD1; Thu, 24 Feb 2022 19:06:35 +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 A1AF783CBC; Thu, 24 Feb 2022 19:06:25 +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 75D8583CB1 for ; Thu, 24 Feb 2022 19:06:22 +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 E363C106F; Thu, 24 Feb 2022 10:06:21 -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 830293F70D; Thu, 24 Feb 2022 10:06:19 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Mario Six , Sughosh Ganu Subject: [PATCH 03/10] tpm: Fix the return type of tpm_startup Date: Thu, 24 Feb 2022 23:35:45 +0530 Message-Id: <20220224180552.26901-4-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220224180552.26901-1-sughosh.ganu@linaro.org> References: <20220224180552.26901-1-sughosh.ganu@linaro.org> 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 --- 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 Thu Feb 24 18:05:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 545594 Delivered-To: patch@linaro.org Received: by 2002:ac0:d8d1:0:0:0:0:0 with SMTP id b17csp437416imj; Thu, 24 Feb 2022 10:07:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJwVtvULvWaMl0R9xrXpiqXEAqdc3QLVTAmrl1YLXgKFlY3e73sKSwdq9BWi2Z4/zYGvar3G X-Received: by 2002:a50:bf0f:0:b0:410:c512:cb6f with SMTP id f15-20020a50bf0f000000b00410c512cb6fmr3449121edk.262.1645726024352; Thu, 24 Feb 2022 10:07:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645726024; cv=none; d=google.com; s=arc-20160816; b=LRLAGWt1YW6FSW1nyc4sJ+xwlA42afMs3Oxlpe8szxwvSMIpWf8iFOpu5jkwTHOOdN 1fsW7HZKmTj2wrGwNJiYp/8OqB0zr1QsIxnIKQVrjkQrCXZXZZUnv3NC+OYv7EWZfXLS RdjJSSuXN+XwADXCqr2EmkcR2FOwutjV8r3Ah+qaM3MykYSijA6rBxRXAfpaLF5u0vqI nUmHXXiVWjBcaao634CWwudoopPdI80cseMJa3URu59YT9VS0sfRIr9Ga457gdNjrDzw ZZTzPtLwh1Rf1E4pCfcZ6ebj8OeBVkkQ+MKgzQN/wOnJnJM9znEMoEoR2qWZAy/NOAht MGPw== 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:references:in-reply-to :message-id:date:subject:cc:to:from; bh=16cl6pk7oJ1dQ1nXgAzUcaj5tWZKPmyhlSRQRQopPTQ=; b=ZlccJpfJuuq9ScvzFWppKog/S4TYxoQdN2Jg1uXAwfZ1TJUo3bSgxjRmMO5zniC5Pu QYuaSGq3VFL3Yfd1A23qqbVQD14m4sTsLhE7R8ZtweAmDC5V3qszAVc8SzCFeM1gVLXf WRf02v7jY5NdRAID/Qxk88G/Z5Cw05SKYvMVi+4P2/RAgOVw/dFtMwo+aHExqRIlVRi+ mVtD90JXZrPqyEQTumYGgykkWvLya8HWbjmCQwwFZwAFN4HkYKbhDEWT5a80KeCb7OMt PLFgHpHy/iFytGP4qKsDqspFPnCpMbJ8SlL+XrYzmG2gHcOBUiOctw9Q+zNHBV7sgWP4 dnpg== 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 k12-20020a170906970c00b006d12c094e63si37446ejx.735.2022.02.24.10.07.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 10:07: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 765DB83CE3; Thu, 24 Feb 2022 19:06:38 +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 1537483CBA; Thu, 24 Feb 2022 19:06:31 +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 AC35383CB1 for ; Thu, 24 Feb 2022 19:06:25 +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 E08EA106F; Thu, 24 Feb 2022 10:06:24 -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 7E2C93F70D; Thu, 24 Feb 2022 10:06:22 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Mario Six , Sughosh Ganu Subject: [PATCH 04/10] tpm: Move the TPM version detection functions to the uclass driver Date: Thu, 24 Feb 2022 23:35:46 +0530 Message-Id: <20220224180552.26901-5-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220224180552.26901-1-sughosh.ganu@linaro.org> References: <20220224180552.26901-1-sughosh.ganu@linaro.org> 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 --- 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 Thu Feb 24 18:05:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 545595 Delivered-To: patch@linaro.org Received: by 2002:ac0:d8d1:0:0:0:0:0 with SMTP id b17csp437666imj; Thu, 24 Feb 2022 10:07:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJxeVa8InD7nl7a332JQVqZPytf4HQtqTrLmUdvNvr2wywPJAbXFHxV1j/8Jql9m4gwKKOSp X-Received: by 2002:a50:ef09:0:b0:412:e8d5:5c9d with SMTP id m9-20020a50ef09000000b00412e8d55c9dmr3472095eds.57.1645726041515; Thu, 24 Feb 2022 10:07:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645726041; cv=none; d=google.com; s=arc-20160816; b=unLddzySWYI3NylXMlfsVRTDX5Y31pbTDFhg29/51jtUAGFCIN+F0AjI0a0QFOehk+ m14vbDLjoe5gCD3r2cV24cS2IBRCHW2onMbVBvnQ31d+wUBuyFHMNBbJ+YSQdDNKW3ui Hkdimjq6Bcqp5a9GPb/1qEcunXbCa7U+sZzkq2N6mj9c0mPJKbOvbwPUIibRNQdfqo53 yJruHcI7GPcwuwRS+z3Ik91anH6zQtsH7dJPmG9bpVMdIGA0ekyqEP2C9acXUfFCV+qU DG4IMZ59RejkaqtdMuNJcSbpePtw5AhKk140AFQohBhjd0YCwq7kVKLNl1X/ejNrAYaT Grkg== 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:references:in-reply-to :message-id:date:subject:cc:to:from; bh=TuGc8kqZDtMYiAHwbIfIhCwYyEJG74tkpuaWRP0FLwE=; b=t3w03pzDqWKujouhImt73HDt0ni0hkLSU4p80EyjtlEtq5tt9EuOtWZ2kFeLClnImZ 2EgQP3KwRLO9zHUuylMySnudJAcjvYQP8soH4TlbKRGYy0ZKCMRnQ8CFFTXjagGrulv5 MKS7tq6LCVtm28JT7hYJ+r61q4/r1HyQbxxJ/DKYoK727hK7sB0Ie6x8ll70ioWVZyIr +0ryMa1s7tI20xPGUSzkztReCvxj8p6YXqUQAbX01OUDAEA5mBewvAR2UbjUZqgiikXl JIL41fYIKNP+OHykKjn/W691Kir+935cBsvUkOoe6PQFlVngG2ZINMoHYAVlRd9Qs4jr nrzw== 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 f18-20020a50a6d2000000b0040aa9eefc2dsi175579edc.310.2022.02.24.10.07.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 10:07:21 -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 9C7BE83CE1; Thu, 24 Feb 2022 19:06: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 51BED83CE0; Thu, 24 Feb 2022 19:06: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 AA4EC83CE1 for ; Thu, 24 Feb 2022 19:06:28 +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 DCC9F106F; Thu, 24 Feb 2022 10:06:27 -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 7B3F33F70D; Thu, 24 Feb 2022 10:06:25 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Mario Six , Sughosh Ganu Subject: [PATCH 05/10] configs: gazerbeam: Build TPMV2 library routines Date: Thu, 24 Feb 2022 23:35:47 +0530 Message-Id: <20220224180552.26901-6-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220224180552.26901-1-sughosh.ganu@linaro.org> References: <20220224180552.26901-1-sughosh.ganu@linaro.org> 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 --- configs/gazerbeam_defconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/configs/gazerbeam_defconfig b/configs/gazerbeam_defconfig index 5d8d1998d6..505cd49843 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 Thu Feb 24 18:05:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 545596 Delivered-To: patch@linaro.org Received: by 2002:ac0:d8d1:0:0:0:0:0 with SMTP id b17csp437774imj; Thu, 24 Feb 2022 10:07:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJxq91WPG1R2mvPw2qaYWWX1983awS6pBm4t1Gcyj7EJ3wRWSLMc+xUwbDxOBFoEbbmVLVy8 X-Received: by 2002:a17:906:1e13:b0:6d1:5042:e8c1 with SMTP id g19-20020a1709061e1300b006d15042e8c1mr3280891ejj.354.1645726047678; Thu, 24 Feb 2022 10:07:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645726047; cv=none; d=google.com; s=arc-20160816; b=rggio2kxdVc8OqtPyMxWlGyOOQnrnp2Mvn6UJL25E3Y6orPae6tmHa9Oow1zY8fhM0 S04ynF+jhVrf0+5HMllZvkJm/TUEFI0c9rVPOiOTF7vVU2AOMcUV3vgJlZZzFfOLJ0FD qVJLn5+fPtuL2vgZR4LuJcd8c9Dn+mHky0nnPEYJ2Y1q0DM8rkeBGLO/vfVQdjmGOo4M LP92yHmfHJ58lvhowPoJA9V98jaFMnygkChTPIgeGfi/E5NDoI47SAc2lb8/1NGLhLPZ Fzjfyhu4/utg+ISrVCHef44ktx/YKJd7StavRJdMSBr9ftyRUcaGDARs9b/BZ/ZiK6X1 NXJA== 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:references:in-reply-to :message-id:date:subject:cc:to:from; bh=yqyEj5av+V8ogbF4xRgDw7myihYckdxfh1QMiuc9iPs=; b=tUKrDt7eF5hPWd8W1kwntyMSuhpba2CR1NsG8zcmcRmlbToua0yl971iRLE64lkLKB w9DPvFGex1QS/+4nUTx0jz2TCxgabLmcI0wJhKtSn75NvsOYzKTBMNO5pApQtl+tYw89 cNBTHIB4lo6V4maJuD5BvrdIEfPi2nKHe9dQXxmwueP3pdzf4KSkxMuE31Yh0yQ2QRqW ODUezR0TF7szr6cisXT/r7Bgjsnu59T9IoUIBJUUUTr4JJFX4LqIEhEvkyjPY/87z8s6 u4V3H7DiqMwjO2QCZfpXHoBhS0mm1eNH75mDKy8dB1VKAb3jMQJ3Ydo73i3GnmoPIk3J 6hWA== 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 s8-20020a50dac8000000b00412e72fc6d1si227222edj.178.2022.02.24.10.07.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 10:07:27 -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 9769F83CBF; Thu, 24 Feb 2022 19:06: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 7F1E783CE4; Thu, 24 Feb 2022 19:06:38 +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 9176883CB1 for ; Thu, 24 Feb 2022 19:06: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 D8045106F; Thu, 24 Feb 2022 10:06: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 765F73F70D; Thu, 24 Feb 2022 10:06: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 06/10] configs: chromebook_coral: Build TPMV1 library routines Date: Thu, 24 Feb 2022 23:35:48 +0530 Message-Id: <20220224180552.26901-7-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220224180552.26901-1-sughosh.ganu@linaro.org> References: <20220224180552.26901-1-sughosh.ganu@linaro.org> 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 --- 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 Thu Feb 24 18:05:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 545597 Delivered-To: patch@linaro.org Received: by 2002:ac0:d8d1:0:0:0:0:0 with SMTP id b17csp437952imj; Thu, 24 Feb 2022 10:07:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJx6KQvxyIZnxsgzbe4FNqEDi0HGDL6JffkRzlKvXDmz7U1DPT2RPOqRIpNpXfsNt1Ql5IOu X-Received: by 2002:a50:c318:0:b0:413:3b2e:832 with SMTP id a24-20020a50c318000000b004133b2e0832mr3569196edb.156.1645726056953; Thu, 24 Feb 2022 10:07:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645726056; cv=none; d=google.com; s=arc-20160816; b=LiCB/9p1jZToQAhhKeGV5WPlamGL85kTQVn8WBHERv6snVT6QROXWzDN0iYA99AsNX qjHdzHxx6IATsIfPSeYnH68+bPiYnWHb+1ExpttmVyT0vJlHDDhcBbLpxpSceaNIHAon Ybj0DhtcyadfVHLjFR/kGVHizeWEyLkSkni6epjNbXoXBN+WTGr44WOMhCBBaOkbGfoM rHBOTbFBTU8ly8g32yBLzSjsjfCiQgs1qcfj5yFjEVT4J53VUduT+5aOG3gPqfvpBgix JkS/7hjvjiAsMlNK+KiTEJt49xTqZsgbK+j+TTMv5b3wz3eL5iTd0DVnMQ/jChppNjsG KlDA== 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:references:in-reply-to :message-id:date:subject:cc:to:from; bh=bVMS8Q22wwdcFlY9OCWjUvX3FL6il476yzLFh9ZBSMg=; b=RjBqjL91ZiSvMxCwlaIj8HOeocauwAcOaJ5lIjJvjQ7l64ZUeooZ10aq/qqQIrTrqx DmD165tEMrjqIhLdrU2xNb686WE0Z2/RragyxhVJm8YFbJRxJBjBL13PUnMk6Tp5+L1K DYYnpf0Tt28RHW5rzkPn7dTxQT6JvRPnG5aXSqM0KKp/AEqz72rFZo31S0beLQA0Lf1l aW88Q9L2zTKzHxpzwpSk3FqdRtZg5dm/z5du2sNmdj4ZLgv6/S2nX4Wy+XX7/Uc0nm8n JPimCG/mRE86jNfA/dWDQ3+QTmkbPjsXa/YOnDRSTHkuir5ZHb2OUIGnND55lzJJYgWk PRIw== 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 m8-20020a1709062b8800b006cf723aeb54si51981ejg.667.2022.02.24.10.07.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 10:07:36 -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 EB0A483CCE; Thu, 24 Feb 2022 19:06:53 +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 B7A9283CCE; Thu, 24 Feb 2022 19:06:40 +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 B4F1383CCE for ; Thu, 24 Feb 2022 19:06:34 +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 27CF3106F; Thu, 24 Feb 2022 10:06:34 -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 72C463F70D; Thu, 24 Feb 2022 10:06: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 07/10] tpm: rng: Move the TPM RNG functionality to driver model Date: Thu, 24 Feb 2022 23:35:49 +0530 Message-Id: <20220224180552.26901-8-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220224180552.26901-1-sughosh.ganu@linaro.org> References: <20220224180552.26901-1-sughosh.ganu@linaro.org> 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 --- drivers/rng/Makefile | 1 + drivers/rng/tpm1_rng.c | 68 ++++++++++++++++++++++++++++++++++++++++++ drivers/rng/tpm2_rng.c | 68 ++++++++++++++++++++++++++++++++++++++++++ lib/tpm-v1.c | 44 --------------------------- lib/tpm-v2.c | 44 --------------------------- lib/tpm_api.c | 28 +++++++++++++---- 6 files changed, 160 insertions(+), 93 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..ddb20b008d --- /dev/null +++ b/drivers/rng/tpm1_rng.c @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2022, Linaro Limited + */ + +#include +#include +#include +#include +#include + +#define TPM_HEADER_SIZE 10 + +#define TPMV1_DATA_OFFSET 14 + +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 TPM_LIB_ERROR; + 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 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; +} + +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..f14528f751 --- /dev/null +++ b/drivers/rng/tpm2_rng.c @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2022, Linaro Limited + */ + +#include +#include +#include +#include +#include + +#define TPM_HEADER_SIZE 10 + +#define TPMV2_DATA_OFFSET 12 + +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 TPM_LIB_ERROR; + 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 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; +} + +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..de822113b0 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,29 @@ 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) { - if (is_tpm1(dev)) - return tpm1_get_random(dev, data, count); - else if (is_tpm2(dev)) - return -ENOSYS; /* not implemented yet */ - else + int ret; + struct udevice *rng_dev; + + if (is_tpm1(dev)) { + ret = uclass_get_device_by_driver(UCLASS_RNG, + DM_DRIVER_GET(tpm1_rng), + &rng_dev); + } else if (is_tpm2(dev)) { + ret = uclass_get_device_by_driver(UCLASS_RNG, + DM_DRIVER_GET(tpm2_rng), + &rng_dev); + } else { return -ENOSYS; + } + + 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 Thu Feb 24 18:05:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 545598 Delivered-To: patch@linaro.org Received: by 2002:ac0:d8d1:0:0:0:0:0 with SMTP id b17csp438110imj; Thu, 24 Feb 2022 10:07:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJwKACXAqin5pdZKZsv+3kAHHtltPwlux2y37zitgjyry0kOm0AqFE73mGLV4+Nn2tv6yRkT X-Received: by 2002:a05:6402:1d4f:b0:412:81a5:8bef with SMTP id dz15-20020a0564021d4f00b0041281a58befmr3424569edb.163.1645726067601; Thu, 24 Feb 2022 10:07:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645726067; cv=none; d=google.com; s=arc-20160816; b=Yzd+mYLw3K+5JZjsm3Hym3ISanFlZXp/BQ1byae9tHvmuiSIogodza687nJBZGu1f3 V7UtEWe7XxRRQFSakWeITm0qdx7MuvikLvlhZpDaMoM7MLcGGAwzdA+aPymv3c7NJACx bKMkAwe1thNjBXu1SFbHpfbktQ3YunL/A9qWIl+hFIza2DUh1bohTjOR+999djd6gj+p cOf62KA+IJVC+YW8AUwDXLmAkEvEm7tShoz0ZO5SzRLQOP3uzS7esPiRNvBsv2SRwDKm cDMmVKA5NWjsBoU/7Qv3tSxuTHGw5c9BQ6M3PbA7uaQgPLkJFud62BhG+V6QWmVmyKyl aWpQ== 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:references:in-reply-to :message-id:date:subject:cc:to:from; bh=yDdfWA/q/TFtCsqB/WJAZv87KhoAfFq8zLDliasTdqQ=; b=AVMHnmvegX2w1JeZQZbV2wV0QQIruCs/FSiPxeOhiU/p0sz7X4a3Ry3Jd9jZ8XKs0P rWRU4swUCqSNgmMt7+RXEcpMuN25jNRPAUo/djlxvtmiQplbuSKAjaB4+ny2YzQX68+C Sr/hfkmuMI8Y/OQQofpmlHsv5K4GtIWJCIqUvJJK3zWnX0n4UnbSK6jzbqPvDoMbve2V qlkF8vesvJhfHbo2Bod9kYVUsRY9rfwOYMIrVRHLzVzjALrMokvJZMrq8h+m8ZqzYXAq YGbMS/EYV+65I5jDfPYty8SUv8D7K1pq4kDjnS8ICyTc2naBbyIX7vMCHtJ229qcBYR9 Tyng== 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 bi3-20020a170906a24300b006c9e73f6967si88123ejb.45.2022.02.24.10.07.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 10:07:47 -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 1BAFE83CF7; Thu, 24 Feb 2022 19:06:57 +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 0975383CCE; Thu, 24 Feb 2022 19:06:42 +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 D1CB083CB8 for ; Thu, 24 Feb 2022 19:06:37 +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 2559F106F; Thu, 24 Feb 2022 10:06: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 B6A093F70D; Thu, 24 Feb 2022 10:06:34 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Mario Six , Sughosh Ganu Subject: [PATCH 08/10] tpm: Add the RNG child device Date: Thu, 24 Feb 2022 23:35:50 +0530 Message-Id: <20220224180552.26901-9-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220224180552.26901-1-sughosh.ganu@linaro.org> References: <20220224180552.26901-1-sughosh.ganu@linaro.org> 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 --- 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 Thu Feb 24 18:05:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 545599 Delivered-To: patch@linaro.org Received: by 2002:ac0:d8d1:0:0:0:0:0 with SMTP id b17csp438233imj; Thu, 24 Feb 2022 10:07:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJwjtJ37pOyUMcE7JQh4Op2bxdaCzz6QBe687AZYR5kqPa8xz3cgoj5u1oAHnfSIqqjCqjHi X-Received: by 2002:a50:fe08:0:b0:40f:932a:47b0 with SMTP id f8-20020a50fe08000000b0040f932a47b0mr3601027edt.64.1645726076691; Thu, 24 Feb 2022 10:07:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645726076; cv=none; d=google.com; s=arc-20160816; b=VBlFYULv7Is8AczrRc2J15FZsyefNA1x1IkXX+skRuLgfrmDE2/9If6P9zm5N+pEQf DTJxkcV0AAd7hku6RNdslu9DPSptYPDlx+C7c4NwnxibvK32iTMB3yEl02NgbscCkHkV XAL/SEScjpO8tZeAZIkfG6e//rcMU5yNGLpH0hd/u3Szwwa3cKknKXnIDwuIKtQOQiKO +hDXoV30m9yMfoGJh3xwnHH/wjYOn0MpBuEUbKkyjmLT3GHZVedwn3h1CT6Rt6CqApVO p8w2Qrw+7VVH5MSPvN5NF2EiEF1SVHSayymRYsINkTciprhWY1HNwZhJJYy/7sxE0/Ko KksA== 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:references:in-reply-to :message-id:date:subject:cc:to:from; bh=jYdrG0lDFs0BpEvHifZM7R8y2jrqz/Qm8Ot5lh98QBI=; b=j7K9FO++Jkx2IS1oqV10yCuvuqqvOUmyrdVngEQqlGbGHx21zvIb0zIHEMMoUP7Ypl n8UpEuOCFvRCk0wdQ6/p+Z+8OQNl0eb53SqUfIRSZCATFBBn1cnQvIUQtd0jSO9fIsvR NQ59jzC+NGnC49wUlsO7c19g5TlLpV6Fi6PjATSViJi8cqFfkksXPcTi1WjANSQ3oTGB OE3x4u0cVDW3MKVw2mTXSU+5n4Im9bAbQO2EZFxvvY3IhzqkFV+r6T7ILhEVQ0t3cvIm cxZmuJ2luOaFxJWaZI0NekncvTh/4E9BtKS4HwO3xyX9EvGYXt21Z1YeVsG491oA7ICx PuBw== 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 dr14-20020a170907720e00b006d03ab2b4dcsi58901ejc.712.2022.02.24.10.07.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 10:07:56 -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 2562083CDE; Thu, 24 Feb 2022 19:07:10 +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 26E1283C9B; Thu, 24 Feb 2022 19:06: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 9FFF983CF4 for ; Thu, 24 Feb 2022 19:06: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 2098F106F; Thu, 24 Feb 2022 10:06: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 B468F3F70D; Thu, 24 Feb 2022 10:06:37 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Mario Six , Sughosh Ganu Subject: [PATCH 09/10] qemu: arm: Remove platform specific function to get RNG device Date: Thu, 24 Feb 2022 23:35:51 +0530 Message-Id: <20220224180552.26901-10-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220224180552.26901-1-sughosh.ganu@linaro.org> References: <20220224180552.26901-1-sughosh.ganu@linaro.org> 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 --- 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 Thu Feb 24 18:05:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 545600 Delivered-To: patch@linaro.org Received: by 2002:ac0:d8d1:0:0:0:0:0 with SMTP id b17csp438324imj; Thu, 24 Feb 2022 10:08:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJwJ1tdXCN1pPuDTQwjPyTsJS0X2EYipApDtjflDrFX6yTMp082YiRfjQ0BzC6HnzesmeM6d X-Received: by 2002:a17:906:2608:b0:6ce:60fa:12ad with SMTP id h8-20020a170906260800b006ce60fa12admr3335113ejc.231.1645726083256; Thu, 24 Feb 2022 10:08:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645726083; cv=none; d=google.com; s=arc-20160816; b=yO3HzAz9zSB84W3DXh/JMNZPgyvOEF0JLwcE6wnmzyG/4ep79XUC/qeNRtuzB54mWI 27y2ZCkg+VFSg56KDx5qWqwtXo3mPHTH2kMgExmb8HSdBKVhCDIyUNP/xMwN18jx81i6 rZgGcPGSGLbrXc9l5R8iT6BkpsOb1BZQy1CyEfAGoVss0q3KjgH1fCUuPnrwYVASkCq3 rgakhrNgMoSPFtUYk9Lmra/gSw49njB/4c0Xs3grbKXefGUANm94LF3LNx1Thzy03ZdL +/gMIskbwLs5i2ugzhVOnG4sy2WZF/UNqeZnj4c/8VeAoLq6UMDG4bORlRiIKjX0e9J6 5anw== 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:references:in-reply-to :message-id:date:subject:cc:to:from; bh=nBp81m+aDuG8A8lbRPjVYjW7mUTOuRI7ZUmJMuSZBeM=; b=s/TAVqlBrBODkzQqw/IVcFzLwW86wypHX9PsyrxLlgjzkFwNuMqE96IHd5tbBxP6Ed aJBEGrH/4MRhLAVDogkFQvnZbCa2e35l+DQlWkfJCv4lrmCMPVkK8zscY1FL6Z+3FZK2 mdpguK17qIF29FSnzuBcnyIO9qtB9XIVNXnjHBWI60XUoLVLFvZolV42lL7d/KcYXguU OkmtJNK8ML5ZgOmeYPNYQhxWeXecksAiZyJgzvRmn3eKTkLwRg9JZnZXyHI8baEUcO4d 87kPExwICQJ3A04BnGca0CnC16hLUdxPeG7ILeWo8bmegHDCJPjNfTt3jTpWJC5s2xKy 5hwA== 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 dm28-20020a05640222dc00b004109b9fa7ddsi190243edb.306.2022.02.24.10.08.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Feb 2022 10:08:03 -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 354AF83CF4; Thu, 24 Feb 2022 19:07:13 +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 2282383CE2; Thu, 24 Feb 2022 19:06:47 +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 A703983CB1 for ; Thu, 24 Feb 2022 19:06: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 1E4AA106F; Thu, 24 Feb 2022 10:06:43 -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 AFB2D3F70D; Thu, 24 Feb 2022 10:06: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 10/10] cmd: rng: Add support for selecting RNG device Date: Thu, 24 Feb 2022 23:35:52 +0530 Message-Id: <20220224180552.26901-11-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220224180552.26901-1-sughosh.ganu@linaro.org> References: <20220224180552.26901-1-sughosh.ganu@linaro.org> 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 --- cmd/rng.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/cmd/rng.c b/cmd/rng.c index 1ad5a096c0..2b197e322e 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 );