From patchwork Wed Jul 20 12:29:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 591861 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp4892914max; Wed, 20 Jul 2022 05:30:29 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tuTJ2t3QuishDgo/BEGPMJ5pvNm+YC3xgL+SPOWJ7KohEaCAN7WzPdvhl3ADh4Q15umTjK X-Received: by 2002:a05:6638:2103:b0:341:4a1b:c551 with SMTP id n3-20020a056638210300b003414a1bc551mr13957015jaj.87.1658320228844; Wed, 20 Jul 2022 05:30:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658320228; cv=none; d=google.com; s=arc-20160816; b=enT3569RrxFGTW9Ed3xV66XyUmgAaSGy+Wsygg+yMtMQTwl/wpdLz0gY6Zq0MqUvG3 nllUufqOKFySNdDcAan8su1kpJOlhzK7ZNZBLUq8jJWGyxRDFsDlzTwF28GAEO2a29KM r9ZS/vHKXNi/9O8DqcIGVi3bVID+D341sGiFNGKu+NdaAKtnuZsirH5a9j1J76un9oDY aWqoDsa+5rWpuL6F47V5kgmsNTLHn2COz3v6cBRT1A6Cp0/u9sMjDkuEQWWWRAwCr/WO MB25aeMCAq2d+wnXOJHXTh+L+OKQTAI68+1LEcPtP252IDWKzsq9RAMF3g0LWHOd6z5G O38g== 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=ZelEw5dYLjB4k+NeUV/m0Cu0j3nzsYXuOkSt9NEyFF8=; b=dOigSt3Y6F/hqy4n5eUfQbRI9wncB58zrzsWWN5i1BjdQcUDjKa+UDyuzTmpjK1sJp VaHLGlRrQryckZtcDHoLxcv/i5PWAkbQKvN+9b5ots7c7AKVhF7Q3oGd6Oi65CX7dOOG pkTYUW/7Lh2bVnROCSaXOzM+t2hLLoCoKpaucZH6J/PwPCBTWbKFu7qic+i/5CFTP4I+ 25WkHRUo4USK/6JYuVI82c6F/tVtXK550E0NIJRML6LufTLSy3dkA2klKqjBL/tF6vpL t7smlNtPEG4OuxyWbihdp6+rlfc3LbYru2WsB5BsIwThZ6txlIOV6xBilC7Ko+g2u4ZG Qr7A== 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 p8-20020a056e02144800b002d1cf555f6bsi18225173ilo.50.2022.07.20.05.30.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 05:30:28 -0700 (PDT) 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 A581384068; Wed, 20 Jul 2022 14:30:14 +0200 (CEST) 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 8305C84068; Wed, 20 Jul 2022 14:30:09 +0200 (CEST) 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 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 E4D2883FEE for ; Wed, 20 Jul 2022 14:30:05 +0200 (CEST) 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 6A9E71576; Wed, 20 Jul 2022 05:30:05 -0700 (PDT) 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 ED0283F73D; Wed, 20 Jul 2022 05:30:02 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Tom Rini Subject: [PATCH v7 1/7] tpm: Export the TPM-version functions Date: Wed, 20 Jul 2022 17:59:20 +0530 Message-Id: <20220720122926.415659-2-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220720122926.415659-1-sughosh.ganu@linaro.org> References: <20220720122926.415659-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.6 at phobos.denx.de X-Virus-Status: Clean From: Simon Glass These functions should really be available outside the TPM code, so that other callers can find out which version the TPM is. Rename them to have a tpm_ prefix() and add them to the header file. Signed-off-by: Simon Glass Reviewed-by: Ilias Apalodimas --- Changes since V6: None include/tpm_api.h | 10 ++++++ lib/tpm_api.c | 92 +++++++++++++++++++++-------------------------- 2 files changed, 51 insertions(+), 51 deletions(-) diff --git a/include/tpm_api.h b/include/tpm_api.h index ef45b43a8f..11aa14eb79 100644 --- a/include/tpm_api.h +++ b/include/tpm_api.h @@ -319,4 +319,14 @@ u32 tpm_write_lock(struct udevice *dev, u32 index); */ u32 tpm_resume(struct udevice *dev); +static inline bool tpm_is_v1(struct udevice *dev) +{ + return IS_ENABLED(CONFIG_TPM_V1) && tpm_get_version(dev) == TPM_V1; +} + +static inline bool tpm_is_v2(struct udevice *dev) +{ + return IS_ENABLED(CONFIG_TPM_V2) && tpm_get_version(dev) == TPM_V2; +} + #endif /* __TPM_API_H */ diff --git a/lib/tpm_api.c b/lib/tpm_api.c index 4c662640a9..4ac4612c81 100644 --- a/lib/tpm_api.c +++ b/lib/tpm_api.c @@ -11,21 +11,11 @@ #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; -} - u32 tpm_startup(struct udevice *dev, enum tpm_startup_type mode) { - if (is_tpm1(dev)) { + if (tpm_is_v1(dev)) { return tpm1_startup(dev, mode); - } else if (is_tpm2(dev)) { + } else if (tpm_is_v2(dev)) { enum tpm2_startup_types type; switch (mode) { @@ -47,9 +37,9 @@ u32 tpm_startup(struct udevice *dev, enum tpm_startup_type mode) u32 tpm_resume(struct udevice *dev) { - if (is_tpm1(dev)) + if (tpm_is_v1(dev)) return tpm1_startup(dev, TPM_ST_STATE); - else if (is_tpm2(dev)) + else if (tpm_is_v2(dev)) return tpm2_startup(dev, TPM2_SU_STATE); else return -ENOSYS; @@ -57,9 +47,9 @@ u32 tpm_resume(struct udevice *dev) u32 tpm_self_test_full(struct udevice *dev) { - if (is_tpm1(dev)) + if (tpm_is_v1(dev)) return tpm1_self_test_full(dev); - else if (is_tpm2(dev)) + else if (tpm_is_v2(dev)) return tpm2_self_test(dev, TPMI_YES); else return -ENOSYS; @@ -67,9 +57,9 @@ u32 tpm_self_test_full(struct udevice *dev) u32 tpm_continue_self_test(struct udevice *dev) { - if (is_tpm1(dev)) + if (tpm_is_v1(dev)) return tpm1_continue_self_test(dev); - else if (is_tpm2(dev)) + else if (tpm_is_v2(dev)) return tpm2_self_test(dev, TPMI_NO); else return -ENOSYS; @@ -86,7 +76,7 @@ u32 tpm_clear_and_reenable(struct udevice *dev) return ret; } - if (is_tpm1(dev)) { + if (tpm_is_v1(dev)) { ret = tpm1_physical_enable(dev); if (ret != TPM_SUCCESS) { log_err("TPM: Can't set enabled state\n"); @@ -105,9 +95,9 @@ u32 tpm_clear_and_reenable(struct udevice *dev) u32 tpm_nv_enable_locking(struct udevice *dev) { - if (is_tpm1(dev)) + if (tpm_is_v1(dev)) return tpm1_nv_define_space(dev, TPM_NV_INDEX_LOCK, 0, 0); - else if (is_tpm2(dev)) + else if (tpm_is_v2(dev)) return -ENOSYS; else return -ENOSYS; @@ -115,9 +105,9 @@ u32 tpm_nv_enable_locking(struct udevice *dev) u32 tpm_nv_read_value(struct udevice *dev, u32 index, void *data, u32 count) { - if (is_tpm1(dev)) + if (tpm_is_v1(dev)) return tpm1_nv_read_value(dev, index, data, count); - else if (is_tpm2(dev)) + else if (tpm_is_v2(dev)) return tpm2_nv_read_value(dev, index, data, count); else return -ENOSYS; @@ -126,9 +116,9 @@ u32 tpm_nv_read_value(struct udevice *dev, u32 index, void *data, u32 count) u32 tpm_nv_write_value(struct udevice *dev, u32 index, const void *data, u32 count) { - if (is_tpm1(dev)) + if (tpm_is_v1(dev)) return tpm1_nv_write_value(dev, index, data, count); - else if (is_tpm2(dev)) + else if (tpm_is_v2(dev)) return tpm2_nv_write_value(dev, index, data, count); else return -ENOSYS; @@ -141,9 +131,9 @@ u32 tpm_set_global_lock(struct udevice *dev) u32 tpm_write_lock(struct udevice *dev, u32 index) { - if (is_tpm1(dev)) + if (tpm_is_v1(dev)) return -ENOSYS; - else if (is_tpm2(dev)) + else if (tpm_is_v2(dev)) return tpm2_write_lock(dev, index); else return -ENOSYS; @@ -152,9 +142,9 @@ u32 tpm_write_lock(struct udevice *dev, u32 index) u32 tpm_pcr_extend(struct udevice *dev, u32 index, const void *in_digest, void *out_digest) { - if (is_tpm1(dev)) + if (tpm_is_v1(dev)) return tpm1_extend(dev, index, in_digest, out_digest); - else if (is_tpm2(dev)) + else if (tpm_is_v2(dev)) return tpm2_pcr_extend(dev, index, TPM2_ALG_SHA256, in_digest, TPM2_DIGEST_LEN); else @@ -163,9 +153,9 @@ u32 tpm_pcr_extend(struct udevice *dev, u32 index, const void *in_digest, u32 tpm_pcr_read(struct udevice *dev, u32 index, void *data, size_t count) { - if (is_tpm1(dev)) + if (tpm_is_v1(dev)) return tpm1_pcr_read(dev, index, data, count); - else if (is_tpm2(dev)) + else if (tpm_is_v2(dev)) return -ENOSYS; else return -ENOSYS; @@ -173,14 +163,14 @@ u32 tpm_pcr_read(struct udevice *dev, u32 index, void *data, size_t count) u32 tpm_tsc_physical_presence(struct udevice *dev, u16 presence) { - if (is_tpm1(dev)) + if (tpm_is_v1(dev)) return tpm1_tsc_physical_presence(dev, presence); /* * Nothing to do on TPM2 for this; use platform hierarchy availability * instead. */ - else if (is_tpm2(dev)) + else if (tpm_is_v2(dev)) return 0; else return -ENOSYS; @@ -188,11 +178,11 @@ u32 tpm_tsc_physical_presence(struct udevice *dev, u16 presence) u32 tpm_finalise_physical_presence(struct udevice *dev) { - if (is_tpm1(dev)) + if (tpm_is_v1(dev)) return tpm1_finalise_physical_presence(dev); /* Nothing needs to be done with tpm2 */ - else if (is_tpm2(dev)) + else if (tpm_is_v2(dev)) return 0; else return -ENOSYS; @@ -200,9 +190,9 @@ u32 tpm_finalise_physical_presence(struct udevice *dev) u32 tpm_read_pubek(struct udevice *dev, void *data, size_t count) { - if (is_tpm1(dev)) + if (tpm_is_v1(dev)) return tpm1_read_pubek(dev, data, count); - else if (is_tpm2(dev)) + else if (tpm_is_v2(dev)) return -ENOSYS; /* not implemented yet */ else return -ENOSYS; @@ -210,9 +200,9 @@ u32 tpm_read_pubek(struct udevice *dev, void *data, size_t count) u32 tpm_force_clear(struct udevice *dev) { - if (is_tpm1(dev)) + if (tpm_is_v1(dev)) return tpm1_force_clear(dev); - else if (is_tpm2(dev)) + else if (tpm_is_v2(dev)) return tpm2_clear(dev, TPM2_RH_PLATFORM, NULL, 0); else return -ENOSYS; @@ -220,11 +210,11 @@ u32 tpm_force_clear(struct udevice *dev) u32 tpm_physical_enable(struct udevice *dev) { - if (is_tpm1(dev)) + if (tpm_is_v1(dev)) return tpm1_physical_enable(dev); /* Nothing needs to be done with tpm2 */ - else if (is_tpm2(dev)) + else if (tpm_is_v2(dev)) return 0; else return -ENOSYS; @@ -232,11 +222,11 @@ u32 tpm_physical_enable(struct udevice *dev) u32 tpm_physical_disable(struct udevice *dev) { - if (is_tpm1(dev)) + if (tpm_is_v1(dev)) return tpm1_physical_disable(dev); /* Nothing needs to be done with tpm2 */ - else if (is_tpm2(dev)) + else if (tpm_is_v2(dev)) return 0; else return -ENOSYS; @@ -244,10 +234,10 @@ u32 tpm_physical_disable(struct udevice *dev) u32 tpm_physical_set_deactivated(struct udevice *dev, u8 state) { - if (is_tpm1(dev)) + if (tpm_is_v1(dev)) return tpm1_physical_set_deactivated(dev, state); /* Nothing needs to be done with tpm2 */ - else if (is_tpm2(dev)) + else if (tpm_is_v2(dev)) return 0; else return -ENOSYS; @@ -256,9 +246,9 @@ u32 tpm_physical_set_deactivated(struct udevice *dev, u8 state) u32 tpm_get_capability(struct udevice *dev, u32 cap_area, u32 sub_cap, void *cap, size_t count) { - if (is_tpm1(dev)) + if (tpm_is_v1(dev)) return tpm1_get_capability(dev, cap_area, sub_cap, cap, count); - else if (is_tpm2(dev)) + else if (tpm_is_v2(dev)) return tpm2_get_capability(dev, cap_area, sub_cap, cap, count); else return -ENOSYS; @@ -266,9 +256,9 @@ u32 tpm_get_capability(struct udevice *dev, u32 cap_area, u32 sub_cap, u32 tpm_get_permissions(struct udevice *dev, u32 index, u32 *perm) { - if (is_tpm1(dev)) + if (tpm_is_v1(dev)) return tpm1_get_permissions(dev, index, perm); - else if (is_tpm2(dev)) + else if (tpm_is_v2(dev)) return -ENOSYS; /* not implemented yet */ else return -ENOSYS; @@ -276,9 +266,9 @@ u32 tpm_get_permissions(struct udevice *dev, u32 index, u32 *perm) u32 tpm_get_random(struct udevice *dev, void *data, u32 count) { - if (is_tpm1(dev)) + if (tpm_is_v1(dev)) return tpm1_get_random(dev, data, count); - else if (is_tpm2(dev)) + else if (tpm_is_v2(dev)) return -ENOSYS; /* not implemented yet */ else return -ENOSYS; From patchwork Wed Jul 20 12:29:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 591862 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp4893083max; Wed, 20 Jul 2022 05:30:40 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uibILlgQgvejnEbWEP3TF4XmyQcSYrHLtiJcZtfEjfhS6u8JLBHKkZn/7pPKcOo9XceWO1 X-Received: by 2002:a05:6638:150e:b0:33f:8717:9fc5 with SMTP id b14-20020a056638150e00b0033f87179fc5mr18880129jat.205.1658320240480; Wed, 20 Jul 2022 05:30:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658320240; cv=none; d=google.com; s=arc-20160816; b=B4J+tC4W6Ert9XiaDGW5S05MA3ciQx+NapkrXHwkmGqlTKc12Dq6mcBjkYa6N3BgWo mIBRb+XfHToQwWQ9zGV0CN1iqn6qib3AL0OsUbTHq4ZPrgTAoLHROUohMMKSamMyO7Li Kn3zNWlJCDlc26u4mY9/0vL1ZC28fbgG9dBz1QKEQc18rAq/5j0YA+BUhf1a0QmdUu8s UOfji9+EJACroRxFeD71O+U/25gTbRgUK2IyL1WfHa2cofkq2Dpai1UNFu7DiTfnP+lP TYIWBcDAkp+0vDNJJrXExvjFcE0Fc7+bar1vp5adPNiADHqjInLPb5HqAEsI48FpzSMU n5Rw== 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=2fhoVrtzs6Aptg/TI7morIVw/eY2QKos9W6/a/B8wKQ=; b=WeQ6b3dIFf+WbaCOkT7wwmIuYeBm7zlXB+DLI75YV1IuME9wjYXos5le3JMDZ611fy S+vh/K78ck12wcZxYoqS2wKhBAD9cFgNXCVfznMYZQvM9fI4Dm1VNwt34td71zyNljiW wo1I8ToLG2gJx/2sdfO6dIOcWQVn5O9x7fhHWQ2cahl1H8hXHZIqkvXOn5VE9Rx92l7z MWZHztmCama5FltDwW4LkY9SBXhhy1H+N21dnnCZMyhrxyk9vRpC4Ox+M/I2jskRTbAH dHCFyBm8+Z6AJ9soMI+n+7Sb91oM5TotcwT1HGDTSqFwJrWCrZokBNfL0KfpIzpBwZpn S93A== 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 b190-20020a0219c7000000b0034166823f5esi9141822jab.17.2022.07.20.05.30.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 05:30:40 -0700 (PDT) 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 E5476840A6; Wed, 20 Jul 2022 14:30:18 +0200 (CEST) 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 ECE9E84079; Wed, 20 Jul 2022 14:30:10 +0200 (CEST) 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 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 ED1C680361 for ; Wed, 20 Jul 2022 14:30:07 +0200 (CEST) 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 D48861576; Wed, 20 Jul 2022 05:30:07 -0700 (PDT) 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 62E3A3F73D; Wed, 20 Jul 2022 05:30:05 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Tom Rini , Sughosh Ganu Subject: [PATCH v7 2/7] tpm: rng: Add driver model interface for TPM RNG device Date: Wed, 20 Jul 2022 17:59:21 +0530 Message-Id: <20220720122926.415659-3-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220720122926.415659-1-sughosh.ganu@linaro.org> References: <20220720122926.415659-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.6 at phobos.denx.de X-Virus-Status: Clean The TPM device has a builtin random number generator(RNG) functionality. Expose the RNG functions of the TPM device to the driver model so that they can be used by the EFI_RNG_PROTOCOL if the protocol is installed. Also change the function arguments and return type of the random number functions to comply with the driver model api. Signed-off-by: Sughosh Ganu Reviewed-by: Ilias Apalodimas --- Changes since V6: * Remove the changes made in tpm-v[12].c to return -EIO instead of TPM_LIB_ERROR as suggested by Simon drivers/rng/Kconfig | 9 +++++++++ drivers/rng/Makefile | 1 + drivers/rng/tpm_rng.c | 23 +++++++++++++++++++++++ lib/Kconfig | 1 + lib/tpm_api.c | 6 +++--- 5 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 drivers/rng/tpm_rng.c diff --git a/drivers/rng/Kconfig b/drivers/rng/Kconfig index 21a9ff0195..16143681da 100644 --- a/drivers/rng/Kconfig +++ b/drivers/rng/Kconfig @@ -74,4 +74,13 @@ config RNG_SMCCC_TRNG Enable random number generator for platforms that support Arm SMCCC TRNG interface. +config TPM_RNG + bool "Enable random number generator on TPM device" + depends on TPM + default y + help + The TPM device has an inbuilt random number generator + functionality. Enable random number generator on TPM + devices. + endif diff --git a/drivers/rng/Makefile b/drivers/rng/Makefile index 2494717d7c..78f61051ac 100644 --- a/drivers/rng/Makefile +++ b/drivers/rng/Makefile @@ -13,3 +13,4 @@ obj-$(CONFIG_RNG_STM32MP1) += stm32mp1_rng.o obj-$(CONFIG_RNG_ROCKCHIP) += rockchip_rng.o obj-$(CONFIG_RNG_IPROC200) += iproc_rng200.o obj-$(CONFIG_RNG_SMCCC_TRNG) += smccc_trng.o +obj-$(CONFIG_TPM_RNG) += tpm_rng.o diff --git a/drivers/rng/tpm_rng.c b/drivers/rng/tpm_rng.c new file mode 100644 index 0000000000..1a5e9e2e4b --- /dev/null +++ b/drivers/rng/tpm_rng.c @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2022, Linaro Limited + */ + +#include +#include +#include + +static int rng_tpm_random_read(struct udevice *dev, void *data, size_t count) +{ + return tpm_get_random(dev_get_parent(dev), data, count); +} + +static const struct dm_rng_ops tpm_rng_ops = { + .read = rng_tpm_random_read, +}; + +U_BOOT_DRIVER(tpm_rng) = { + .name = "tpm-rng", + .id = UCLASS_RNG, + .ops = &tpm_rng_ops, +}; diff --git a/lib/Kconfig b/lib/Kconfig index 7dd777b56a..e888c29245 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -360,6 +360,7 @@ source lib/crypt/Kconfig config TPM bool "Trusted Platform Module (TPM) Support" depends on DM + imply DM_RNG help This enables support for TPMs which can be used to provide security features for your board. The TPM can be connected via LPC or I2C diff --git a/lib/tpm_api.c b/lib/tpm_api.c index 4ac4612c81..032f383ca0 100644 --- a/lib/tpm_api.c +++ b/lib/tpm_api.c @@ -269,7 +269,7 @@ u32 tpm_get_random(struct udevice *dev, void *data, u32 count) if (tpm_is_v1(dev)) return tpm1_get_random(dev, data, count); else if (tpm_is_v2(dev)) - return -ENOSYS; /* not implemented yet */ - else - return -ENOSYS; + return tpm2_get_random(dev, data, count); + + return -ENOSYS; } From patchwork Wed Jul 20 12:29:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 591863 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp4893259max; Wed, 20 Jul 2022 05:30:51 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sF74QiKnDWpwHYxxu2rgzHmrC4xTv7XO3Mdo2SXopjk2r3+S28pPhsMN6CxrDaUZ2y+UHn X-Received: by 2002:a05:6638:1654:b0:341:6650:df93 with SMTP id a20-20020a056638165400b003416650df93mr8517915jat.287.1658320251462; Wed, 20 Jul 2022 05:30:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658320251; cv=none; d=google.com; s=arc-20160816; b=JP7WMhwswPMcA0gxj1YP2/DDaqASZku3kIG9JJCIqInlqsNRRbPJazHrmOoFpgz+4u Y3mL0I3llB9tavQPXdXB8l465x7ixPMysy1UEWVbZlSUcrF9R1NUT6mu0JZkTa+/XTZQ z6G+SAS5dQLqDAczCxK6S0y0zDoYZrN6La/IBEs9eKuxS2IVQnJiO3qq67SJKmDwyJwW Wep6Vaqnm5DB5fF5NaFbgC3aeEN0veWxoUnvwVp7QyaQzh4LsnWtq9GdVSGme51RQFCK wMNr6iUD3vjGtEJo1UTuSjS0R6Z2r7GEHN3ye29+ZEs4iDRslFz7w0D8xGYteh0UheDE 2bMA== 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=T1A2ldxjKhcFJ5bLm4n4nXZ2S1mwzYZRlR10/0Lb2RM=; b=uyvxEQdammgOpyAy5KlNjaTMvWxPg3SuPKuQDkrUSe7gPRIe2LZHIx3iRDXRRCkXqn YxJ9RaVATZaUeWjQFHk0beGY8VfDFGBgTMsrUjBORaFVSubKoWdueR5yKo1NVnpLzzG9 ObhK06H5LV8IR7fzP3B61CN/+R5/lX/NLIXJ95wBuSd7oftJLEVpY/zBnGO8ZAnj4NaH kc7nYXepq/WXASfN1w8lCUAUn3UTosE+AxcmkdvlIMbVVXuUP+Bsk1ZK1D/R6cakhguV ihCqEAsZCMsgqfy4i1Pm2WCkG3aX3QvKhv5T6KxqQTu8y20gYhjddk4CdwhGMtm+8ntg 09xw== 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 188-20020a6b14c5000000b0067b898f1230si15717536iou.43.2022.07.20.05.30.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 05:30:51 -0700 (PDT) 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 EB2AE84079; Wed, 20 Jul 2022 14:30:28 +0200 (CEST) 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 92D1E84094; Wed, 20 Jul 2022 14:30:14 +0200 (CEST) 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 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 6E16584068 for ; Wed, 20 Jul 2022 14:30:10 +0200 (CEST) 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 4A14C1576; Wed, 20 Jul 2022 05:30:10 -0700 (PDT) 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 CCDE43F73D; Wed, 20 Jul 2022 05:30:07 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Tom Rini , Sughosh Ganu Subject: [PATCH v7 3/7] tpm: Add the RNG child device Date: Wed, 20 Jul 2022 17:59:22 +0530 Message-Id: <20220720122926.415659-4-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220720122926.415659-1-sughosh.ganu@linaro.org> References: <20220720122926.415659-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.6 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 Reviewed-by: Ilias Apalodimas --- Changes since V6: None drivers/tpm/tpm-uclass.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/drivers/tpm/tpm-uclass.c b/drivers/tpm/tpm-uclass.c index f67fe1019b..e1f1ef01e1 100644 --- a/drivers/tpm/tpm-uclass.c +++ b/drivers/tpm/tpm-uclass.c @@ -11,10 +11,15 @@ #include #include #include +#include #include #include #include "tpm_internal.h" +#include + +#define TPM_RNG_DRV_NAME "tpm-rng" + int tpm_open(struct udevice *dev) { struct tpm_ops *ops = tpm_get_ops(dev); @@ -136,12 +141,36 @@ int tpm_xfer(struct udevice *dev, const uint8_t *sendbuf, size_t send_size, return 0; } +static int tpm_uclass_post_probe(struct udevice *dev) +{ + int ret; + const char *drv = TPM_RNG_DRV_NAME; + struct udevice *child; + + if (CONFIG_IS_ENABLED(TPM_RNG)) { + ret = device_find_first_child_by_uclass(dev, UCLASS_RNG, + &child); + + if (ret != -ENODEV) { + log_debug("RNG child already added to the TPM device\n"); + return ret; + } + + ret = device_bind_driver(dev, drv, "tpm-rng0", &child); + if (ret) + return log_msg_ret("bind", ret); + } + + return 0; +} + 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 + .post_probe = tpm_uclass_post_probe, .per_device_auto = sizeof(struct tpm_chip_priv), }; From patchwork Wed Jul 20 12:29:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 591864 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp4893428max; Wed, 20 Jul 2022 05:31:02 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sBcOZLwj0FKAAYLuU9us5ltQzGEtEif2rn4wE5sWA9cF98YcBykD/1X4xOCZlgR18lGZw9 X-Received: by 2002:a05:6602:26c7:b0:67b:72ef:b87b with SMTP id g7-20020a05660226c700b0067b72efb87bmr17922399ioo.175.1658320262726; Wed, 20 Jul 2022 05:31:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658320262; cv=none; d=google.com; s=arc-20160816; b=ctAJz/7Zu1s3baUcoGuuNZNOmR7UFtjtmOorqyMZm+6TKVB41FkKFBXbvNARittuXc SOGscQ2iuPxv/7lw06MgqZIbGV6tt/bPd1EZn6xH+UJ2l/O5/M1N7zPISVaOzuCwGyY4 R5CMO6/VSTj+FlmNKZw4NFplq/um7uGIXYaPipRcGGy9LZ1GddbHOylQzDcOyp2iicDf 8P8IUDxO/bEUVJTAhd+n3SwSppNeAgcYo8nNDMCynYNSD502hEr3l5sabmPxQCCGt1A8 eJWOfOrX6ePox8DQB6Bkiqw7FBvhDEdU8DoMhSUacLFJSY6r4DMu3doo4FJjzMfETN2A 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=fnz0Z43OlrEdChYvEszugT72HoE/lrMV6pcu3mDQ0Cs=; b=d/OKkysGwgb1O8pDiFjn0nMXT6jIGYCEKiGmYYftg2YSS8EPAwaQeUDJcDbldzV69W 9+LKgKC+tfrxGeL9MYTao+Wl2NLAtzJJDBe8MLwg5kReu3iLQA2oGEdN6Zd+ibhB/ZLh qytfwMX4+EVi5c+0qV233vBDuAgqqLqJSrmn8qK/9PZsAX3oR73EnYa/7j5Zo6z3+z4C +JQJpPoUjXfk603X2GNglgR4imgfNoxvRXxJqaaM8QKhmxJMX339miAvM+iHpR4NwIfo zIPcWB53T1CRNQCF+1JIZM4Izq+GNHyBhDT9ocUoOWlsiVUDSEU9gs51o8lcwWfRF6gR ROug== 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 l8-20020a026648000000b0032ec51298fesi15635164jaf.13.2022.07.20.05.31.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 05:31:02 -0700 (PDT) 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 B0EE5840B1; Wed, 20 Jul 2022 14:30:31 +0200 (CEST) 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 F34F484094; Wed, 20 Jul 2022 14:30:16 +0200 (CEST) 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 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 379F5839F6 for ; Wed, 20 Jul 2022 14:30:13 +0200 (CEST) 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 B3F7C1576; Wed, 20 Jul 2022 05:30:12 -0700 (PDT) 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 4282E3F73D; Wed, 20 Jul 2022 05:30:10 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Tom Rini , Sughosh Ganu Subject: [PATCH v7 4/7] cmd: rng: Add support for selecting RNG device Date: Wed, 20 Jul 2022 17:59:23 +0530 Message-Id: <20220720122926.415659-5-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220720122926.415659-1-sughosh.ganu@linaro.org> References: <20220720122926.415659-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.6 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 Reviewed-by: Ilias Apalodimas --- Changes since V6: None cmd/rng.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/cmd/rng.c b/cmd/rng.c index 1ad5a096c0..2ddf27545f 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_by_seq(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 ); From patchwork Wed Jul 20 12:29:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 591865 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp4893617max; Wed, 20 Jul 2022 05:31:14 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vzcGyIEB4NGYPeqNOnpKKeG8KH7VJ76+Ts4ruofY/jaH9tR7VGz8ySDC33t4/EVACbiUB/ X-Received: by 2002:a02:a918:0:b0:33f:2a28:a2c6 with SMTP id n24-20020a02a918000000b0033f2a28a2c6mr20017358jam.8.1658320274794; Wed, 20 Jul 2022 05:31:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658320274; cv=none; d=google.com; s=arc-20160816; b=xpbxkbf74d5kNxRQjtSg0YfXeVe+jmEmbzOAyfdn+lWzmzKlmQVVB5iM76VV4yxbuT /1vdOOokzIqpTPxRTtIZSWXSTjb7G9+Lf/mF/nHhG8HZQBbnqV5+9mfIGh+mIVRALCFX SEndTLCgpcilASSjPACZCCX2xl+xk5nmSvo8yaljgwNAGf7aF0FhJr+uWtFJvqoJVz01 2OYRlg8kZ+r9YTfJtDh9B6U0ipd3ZcKqvZsL8heRJpxt0IFpRqMPGbFor9ztkjso0uPj MkoQtbIMwyjY94j4HUdsifr73iRlM6RhmoGL5Z5RTp5K2f6/4A29GnoZC4K5G/hQKuGr Mi5g== 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=EIE0Dl8alStccCZIBhOAOzjBtdJ/t5yzdV6ktawK4kc=; b=uC36DnbFtk+swnWrKN5S0sBCzNtpPuhQtPGAX4EXI64BQ3WQKhEZgKiiIiBcglOLFo oXrEPGYp1bicUctOyU2GP4EvTM9qp1qh2Wnk+Ogp9RXvMchjhEzxt+THrP5m5LJE/ERz 5+93tlEa/DQNBKEwrgaNLmgeuPLwmPIUS36wFv+SWCOAq7lzI0mkNOoTV6usa+Ni9x5u sYJP181/XcD2uzYudTPZVhnnl9NazRtUHmx8ZYOzkeUiIqxvOhu9+FKU7SpepkHL/nPE MQV3zbO33bSLipvD3IlsEs+XhdU4X5vTEqVZjsETg5KhvWH/BA1MeDQg72IVf2TO8Fu3 M99g== 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 t2-20020a056638204200b00339e612b77fsi27173983jaj.29.2022.07.20.05.31.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 05:31:14 -0700 (PDT) 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 D3CAC840CB; Wed, 20 Jul 2022 14:30:34 +0200 (CEST) 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 219D9840A8; Wed, 20 Jul 2022 14:30:19 +0200 (CEST) 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 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 3103984084 for ; Wed, 20 Jul 2022 14:30:15 +0200 (CEST) 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 29F811576; Wed, 20 Jul 2022 05:30:15 -0700 (PDT) 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 AC5EE3F73D; Wed, 20 Jul 2022 05:30:12 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Tom Rini , Sughosh Ganu Subject: [PATCH v7 5/7] cmd: rng: Use a statically allocated array for random bytes Date: Wed, 20 Jul 2022 17:59:24 +0530 Message-Id: <20220720122926.415659-6-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220720122926.415659-1-sughosh.ganu@linaro.org> References: <20220720122926.415659-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.6 at phobos.denx.de X-Virus-Status: Clean Use a statically allocated buffer on stack instead of using malloc for reading the random bytes. Using a local array is faster than allocating heap memory on every initiation of the command. Signed-off-by: Sughosh Ganu --- Changes since V6: None cmd/rng.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/cmd/rng.c b/cmd/rng.c index 2ddf27545f..81a23964b8 100644 --- a/cmd/rng.c +++ b/cmd/rng.c @@ -14,9 +14,9 @@ static int do_rng(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { size_t n; - struct udevice *dev; - void *buf; + u8 buf[64]; int devnum; + struct udevice *dev; int ret = CMD_RET_SUCCESS; switch (argc) { @@ -41,11 +41,10 @@ static int do_rng(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) return CMD_RET_FAILURE; } - buf = malloc(n); - if (!buf) { - printf("Out of memory\n"); - return CMD_RET_FAILURE; - } + if (!n) + return 0; + + n = min(n, sizeof(buf)); if (dm_rng_read(dev, buf, n)) { printf("Reading RNG failed\n"); @@ -54,15 +53,13 @@ static int do_rng(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, buf, n); } - free(buf); - return ret; } #ifdef CONFIG_SYS_LONGHELP static char rng_help_text[] = "[dev [n]]\n" - " - print n random bytes read from dev\n"; + " - print n random bytes(max 64) read from dev\n"; #endif U_BOOT_CMD( From patchwork Wed Jul 20 12:29:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 591866 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp4893758max; Wed, 20 Jul 2022 05:31:26 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ubN2Xc/UoyDplaL3TFDDYivL719b77tYnVE07BGvhe7ou1n/Xdq1QsGZvWDxQfVLlbDZKs X-Received: by 2002:a05:6e02:160a:b0:2dc:12db:121 with SMTP id t10-20020a056e02160a00b002dc12db0121mr20391241ilu.117.1658320285934; Wed, 20 Jul 2022 05:31:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658320285; cv=none; d=google.com; s=arc-20160816; b=Ls5DyUcD4z5W035cVCuRpPWqbuG0iIMMF/xQQ0k6nnD6oAkEV/PJDMCeGBicZ00UVl 2sVoc4V4DRIvgOhdE4petl6jNcquP08YloMsVI22fvgfLyhx40K1eRAXPKHf7nKXcc4r SdhAb9WIQ2lhikC0rq1sjib0dlLePDpW87QMXzQzagxIsEMBO3o8G9sn5/y10y+fd274 oInA/qdrVIF85RSiIafeabn93ulvbqeobA4QX/W9g4cAR/3eWTSBSqY0PQc8XbBjHI7X c74SF9i1O908DGLPYfGbz5vpsXPsPiWA/4BzL6uGZPvTu5vZ0EKVB+7q4Xq0/L90tbs6 divA== 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=Q0Js4Ejh1VYoekzDlkai0yXSl8wbawxtqsePaCY3DmM=; b=KbjKtV7QgTD0MmQ8M6q8VY9KXKIlgqYe2keuJW/GDtK/A8I+gOVp+BHlPw9xgQcYCu +sLCPApopxAW0ah4jF5zYCh86dzNkWhp1zM/UJdvUEOBYq4Vi3Gk33ptu6ie6xroZ2as KTApSuR7bs9MQit0FuPSF0oAAS0ICH9tBBeA8Y6L75LrK+m4+DQzVYorBXYbZQrZlzDe WoULywde8B1hH6b8jYqeyjPN9dGdoRYPnLAGIdJW2JX/6LhtrzvT7yf44A2jWBdL5/DT 6XtVRsfujW53eYQAjLA7QCvDkuYHgAzWJtVAMXrs3rRpp0MtIn3VrxiULP2bWiNi36vA dzDg== 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 k186-20020a6bbac3000000b0067baa752be4si14681296iof.97.2022.07.20.05.31.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 05:31:25 -0700 (PDT) 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 8DF43840EE; Wed, 20 Jul 2022 14:30:36 +0200 (CEST) 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 23D9B840B3; Wed, 20 Jul 2022 14:30:22 +0200 (CEST) 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 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 B9F0D839F6 for ; Wed, 20 Jul 2022 14:30:17 +0200 (CEST) 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 940911576; Wed, 20 Jul 2022 05:30:17 -0700 (PDT) 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 228DE3F73D; Wed, 20 Jul 2022 05:30:14 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Tom Rini , Sughosh Ganu Subject: [PATCH v7 6/7] doc: rng: Add documentation for the rng command Date: Wed, 20 Jul 2022 17:59:25 +0530 Message-Id: <20220720122926.415659-7-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220720122926.415659-1-sughosh.ganu@linaro.org> References: <20220720122926.415659-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.6 at phobos.denx.de X-Virus-Status: Clean Add a usage document for the 'rng' u-boot command. Signed-off-by: Sughosh Ganu Reviewed-by: Ilias Apalodimas Reviewed-by: Simon Glass --- Changes since V6: None doc/usage/cmd/rng.rst | 26 ++++++++++++++++++++++++++ doc/usage/index.rst | 1 + 2 files changed, 27 insertions(+) create mode 100644 doc/usage/cmd/rng.rst diff --git a/doc/usage/cmd/rng.rst b/doc/usage/cmd/rng.rst new file mode 100644 index 0000000000..1a352da41a --- /dev/null +++ b/doc/usage/cmd/rng.rst @@ -0,0 +1,26 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +rng command +=========== + +Synopsis +-------- + +:: + + rng [devnum [n]] + +Description +----------- + +The *rng* command reads the random number generator(RNG) device and +prints the random bytes read on the console. A maximum of 64 bytes can +be read in one invocation of the command. + +devnum + The RNG device from which the random bytes are to be + read. Defaults to 0. + +n + Number of random bytes to be read and displayed on the + console. Default value is 0x40. Max value is 0x40. diff --git a/doc/usage/index.rst b/doc/usage/index.rst index 8b98629d6b..366c8bb4b0 100644 --- a/doc/usage/index.rst +++ b/doc/usage/index.rst @@ -55,6 +55,7 @@ Shell commands cmd/pstore cmd/qfw cmd/reset + cmd/rng cmd/sbi cmd/sf cmd/scp03 From patchwork Wed Jul 20 12:29:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 591867 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp4893959max; Wed, 20 Jul 2022 05:31:38 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vfdNeq6FJACCrRammFUErMkhz0xN3eMxlI/uVhncBqNZypfa6rzs7RGKb88LMDRXi7Uz+9 X-Received: by 2002:a05:6638:339b:b0:33f:5a4c:4d8e with SMTP id h27-20020a056638339b00b0033f5a4c4d8emr19252723jav.93.1658320298058; Wed, 20 Jul 2022 05:31:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658320298; cv=none; d=google.com; s=arc-20160816; b=KHHw4UIzDi9QmzJ/LewK+s6AC8EXp/Su7JJoO9yWlAnvdmibIoJ7eiCi95Mpdz/gEQ SrWASyyB9U83xM8kwNobQ9Fu0cc7bGdxRqagniZCbJ08JYSxMwdAe1sdyCyEipgtY/YO 5Yochn7LDURwWTgkhclJlLcNNZ0b/xeVZOPJcgh2ekYIsQfK78O5eSVcOweQRQTB0Zu0 Y8Jh4gOYinaXos1fUmiAL9O7bOmemskPxMLSI5fyboXaD4KTgsiVnbQ88jQ1XxfhYt6I iXk0zVlkL/uZke55WuFia6L6ViNwlD6dk8+eRkEIsXoRF66qUvYPMccsin3A/OTxNZ8E oFqw== 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=lRLTn+taxP3AkyBpe1JM5LEZL1H8yvQNvOGKsOrTLEE=; b=Ps+B/tjPwi2AYcVgoG2sqD7xr83Hn9K4HrHR3bbfXjVGEgfsQHe+ophEYeIrw4rxqm 7Y9ebfsaBV7g4cu8HAVxzpKp8nIkrfIVGphnOeMs5eQZrqvSR/A1Vsj4A6gKHv7gj97u qCj+uRqu6xhh90LDfX47CKqZrUu9CxbekmFmr6guSlUD4kd1IQbWrt9pKm+z0T+Fw0My mWPm2dL0d2cwBo2ijHtuT50KVsQXehR9J81VZsCpZHEZ4suuQvOBKAenXEJFmiq4lDP0 unPOGIznr8xn0lbSJaHaOJXKe6uH8IterFNijLrfbEb4145EEcJdB2ww3TIPbCgge1RK UJWA== 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 l9-20020a056638220900b0033ebec78473si17698062jas.58.2022.07.20.05.31.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 05:31:38 -0700 (PDT) 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 0E31284103; Wed, 20 Jul 2022 14:30:39 +0200 (CEST) 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 DB12F840B3; Wed, 20 Jul 2022 14:30:24 +0200 (CEST) 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 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 4BDAC840A8 for ; Wed, 20 Jul 2022 14:30:20 +0200 (CEST) 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 0B3391576; Wed, 20 Jul 2022 05:30:20 -0700 (PDT) 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 8C6083F73D; Wed, 20 Jul 2022 05:30:17 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Tom Rini , Sughosh Ganu Subject: [PATCH v7 7/7] test: rng: Add a UT testcase for the rng command Date: Wed, 20 Jul 2022 17:59:26 +0530 Message-Id: <20220720122926.415659-8-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220720122926.415659-1-sughosh.ganu@linaro.org> References: <20220720122926.415659-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.6 at phobos.denx.de X-Virus-Status: Clean The 'rng' command dumps a number of random bytes on the console. Add a set of tests for the 'rng' command. The test function performs basic sanity testing of the command. Since a unit test is being added for the command, enable it by default in the sandbox platforms. Signed-off-by: Sughosh Ganu Reviewed-by: Simon Glass Acked-by: Ilias Apalodimas --- Changes since V6: None cmd/Kconfig | 1 + test/dm/rng.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/cmd/Kconfig b/cmd/Kconfig index d5f842136c..76878ce307 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1961,6 +1961,7 @@ config CMD_GETTIME config CMD_RNG bool "rng command" depends on DM_RNG + default y if SANDBOX select HEXDUMP help Print bytes from the hardware random number generator. diff --git a/test/dm/rng.c b/test/dm/rng.c index 5b34c93ed6..6d1f68848d 100644 --- a/test/dm/rng.c +++ b/test/dm/rng.c @@ -25,3 +25,32 @@ static int dm_test_rng_read(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_rng_read, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); + +/* Test the rng command */ +static int dm_test_rng_cmd(struct unit_test_state *uts) +{ + struct udevice *dev; + + ut_assertok(uclass_get_device(UCLASS_RNG, 0, &dev)); + ut_assertnonnull(dev); + + ut_assertok(console_record_reset_enable()); + + run_command("rng", 0); + ut_assert_nextlinen("00000000:"); + ut_assert_nextlinen("00000010:"); + ut_assert_nextlinen("00000020:"); + ut_assert_nextlinen("00000030:"); + ut_assert_console_end(); + + run_command("rng 0 10", 0); + ut_assert_nextlinen("00000000:"); + ut_assert_console_end(); + + run_command("rng 20", 0); + ut_assert_nextlinen("No RNG device"); + ut_assert_console_end(); + + return 0; +} +DM_TEST(dm_test_rng_cmd, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC);