From patchwork Fri Jul 22 16:02:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 592468 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b811:0:0:0:0 with SMTP id fc17csp634779mab; Fri, 22 Jul 2022 09:02:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vgmP61upLlygEfqCffVJkN9zSgiMKmLByCEG3hyFWWCvo33k4aV/yOOh8tSC4hLFUE0et5 X-Received: by 2002:a05:6e02:1686:b0:2dc:7a0a:2f81 with SMTP id f6-20020a056e02168600b002dc7a0a2f81mr295822ila.8.1658505772094; Fri, 22 Jul 2022 09:02:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658505772; cv=none; d=google.com; s=arc-20160816; b=TcwyywGiHS/5yEgoX6Hz8MBGKNHJCB8f1k+qMe33c2pTSsKrQ2XpzF3P6iHtJZnmd8 GDN9XEPDJc6dEG1vTgybx8RMqqpfsveoL5Lsuk8ddQXz9umKgefMwLnMACzZUzfS/APW hpQGzmPiqsOd5U2bB5p6W9GzmR+8W30l1NyrVYjUTWoQRf81OX7/TKBQ7fauqVXmdc9H mVuBv1cQ6/vwsaGZ6wD0monSTvJseBV/qJ67rUAvKP4f9D7rVqm7Qgaz7thMkptuVOz5 oT0n803346FA49JAMWSKiEgMoyyRhue+h3DWAYhHjOUvd3O3GY//FX9KSCQ5Z/DdRjuY lVQw== 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=awPQbrjafUvi+OpfVNyzLyXb2M7Qlg8J3NRysQ2SIs0=; b=dqu7xHWaWpxgOkwSD7H/MfAfZxr84z0KlW9WKVlgBJqmrNEh01CrmbjVMcYCoz9cym x37ZCNv7e/9/rDnPdYMzZLAP3X91Cf9tLaA/owZDz1qg8RDQg4TkDmXXaQpsQfQClTHM Z5DHZ4yRvXa2XhCXx+wLyHKGuVvKtampulYxRPD7ys0AljPO+3Eq2fBCf7nxtRG9xoqz jHaAvGwxyzgrJS+q9G034S+N6WVE/ZgrLrZB3eb0H2FUVThnj5jMR9Ju4OWvpgWBKA+3 vQU03OHz5aJFMkKrChbIez7JP4XiS+UI7ugcuE0pY64Qw8JFuo+0WBN+IZo2kYb06Kjl yMEA== 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 k44-20020a056638372c00b0033cbd707ab1si5492732jav.10.2022.07.22.09.02.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 09:02:52 -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 4CCB783FA0; Fri, 22 Jul 2022 18:02:40 +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 6A08B83F9B; Fri, 22 Jul 2022 18:02:35 +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 D44FC83AC3 for ; Fri, 22 Jul 2022 18:02:30 +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 68A23106F; Fri, 22 Jul 2022 09:02:30 -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 E519A3F73D; Fri, 22 Jul 2022 09:02:27 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Tom Rini Subject: [PATCH v8 1/8] tpm: Export the TPM-version functions Date: Fri, 22 Jul 2022 21:32:02 +0530 Message-Id: <20220722160209.863840-2-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220722160209.863840-1-sughosh.ganu@linaro.org> References: <20220722160209.863840-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 V7: 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 Fri Jul 22 16:02:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 592469 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b811:0:0:0:0 with SMTP id fc17csp635067mab; Fri, 22 Jul 2022 09:03:06 -0700 (PDT) X-Google-Smtp-Source: AGRyM1syuQBQzcvONEhdW2j0dGSVPHlc4YpDq8Vu1myCDcsdPacJ3sd+stg/y1OqiVfDEn3+6Kg/ X-Received: by 2002:a05:6638:1386:b0:33f:7dc7:bd98 with SMTP id w6-20020a056638138600b0033f7dc7bd98mr330746jad.281.1658505786348; Fri, 22 Jul 2022 09:03:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658505786; cv=none; d=google.com; s=arc-20160816; b=H/vdkoP9+jXpAuMwE2z5WZjs6i7eKIClGut9l4fd73v0JtRfbPSNEjlLaEJYm6S4gK Y5ugVyz8uSIfaRLBUrAovkUD3F3mjTA9sM0J/sBdX87XVJ/Qo8UysLJEiG1yzoqeDSLX BFytrSp0oGt/FKf9Z+tDOwK0/XFi1tC1gShsvAbyOOuLu6cr/YzbgOUpCxEu6oBSsTzq JlTJF8gT8VVg5+9zkbcniKpiNk+ywOxKglhfRcFjBYqNxi46r1kEHvA/o1Z8VcXdd9Fb iSBF9K4XEhk4/TtFm2sqLCsyynoFjYogpPDJsnAq1hXWWPuAPfowmc18MdlQYV5zUEip nVPg== 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=edddUpnWQ2H3mz5zUpTRygXjoHe1nd/CiZIKGjPC7q8=; b=TVQt3fTyyFb1pSQPHVc+QR7Wyh1QkH+p1ykqgvauVEhPUDXNg3WlDnp7meynAYA1cR D7OquTT8xXaxdHilSmL9WG08aVWk7PuDzk42eqADZRiJUJsO6K9ZGUQC2tOZ9NpcC2JZ He6xFLDEnGcWTA3w9EaCe743G9SODpRMh3FQJSkXzOlwUBIgO3qeqkp6KxgujwPRX/qK ZPChbxz3eYlB2Pipn/CvnpN2/8+kTc3jVelX6Cm49UKL6A3NqBc9jlyLvRIGaWOHAB5Z PgD/F9ynZNipEA/DcGIefMtEezq7PWiv7iNORN1GUDnZLnVop7bVqypTKa94H4lM7mau XaEw== 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 h15-20020a056e021b8f00b002dab273202asi4507478ili.107.2022.07.22.09.03.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 09:03:06 -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 9C2F083FB3; Fri, 22 Jul 2022 18:02:43 +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 73DED83AC3; Fri, 22 Jul 2022 18:02:36 +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 986CC82142 for ; Fri, 22 Jul 2022 18:02:32 +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 971181063; Fri, 22 Jul 2022 09:02:32 -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 5ADDA3F73D; Fri, 22 Jul 2022 09:02:30 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Tom Rini Subject: [PATCH v8 2/8] efi_loader: initialize the RNG protocol after the TCC2 Date: Fri, 22 Jul 2022 21:32:03 +0530 Message-Id: <20220722160209.863840-3-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220722160209.863840-1-sughosh.ganu@linaro.org> References: <20220722160209.863840-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: Ilias Apalodimas Due to U-Boot's lazy binding the RNG presented by the TCG is not available until the EFI_TCG2 protocol has been initialized. Since the TPM has a built-in RNG device we can use for the OS randomization, move the RNG protocol installation after the TCG. Signed-off-by: Ilias Apalodimas --- Changes since V7: New patch lib/efi_loader/efi_setup.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index 492ecf4cb1..751beda590 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -246,13 +246,6 @@ efi_status_t efi_init_obj_list(void) /* Set up console modes */ efi_setup_console_size(); - /* Install EFI_RNG_PROTOCOL */ - if (IS_ENABLED(CONFIG_EFI_RNG_PROTOCOL)) { - ret = efi_rng_register(); - if (ret != EFI_SUCCESS) - goto out; - } - /* Initialize variable services */ ret = efi_init_variables(); if (ret != EFI_SUCCESS) @@ -289,6 +282,13 @@ efi_status_t efi_init_obj_list(void) goto out; } + /* Install EFI_RNG_PROTOCOL */ + if (IS_ENABLED(CONFIG_EFI_RNG_PROTOCOL)) { + ret = efi_rng_register(); + if (ret != EFI_SUCCESS) + goto out; + } + if (IS_ENABLED(CONFIG_EFI_RISCV_BOOT_PROTOCOL)) { ret = efi_riscv_register(); if (ret != EFI_SUCCESS) From patchwork Fri Jul 22 16:02:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 592470 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b811:0:0:0:0 with SMTP id fc17csp635287mab; Fri, 22 Jul 2022 09:03:19 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vLlK79S1xmTsiubKs3+Cx8ZBOYjNEQrOr7dPPxcw63FRWy5i0ElU491hSFTvf2Etvpi5G0 X-Received: by 2002:a05:6e02:1a87:b0:2dc:8bda:119d with SMTP id k7-20020a056e021a8700b002dc8bda119dmr283100ilv.42.1658505799269; Fri, 22 Jul 2022 09:03:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658505799; cv=none; d=google.com; s=arc-20160816; b=PPD+SMgdblqfHoSBAh52wfh5GFcpjv2D7l+UEGd1GtGyN4gYFNucfNu/o6G0NsxrRq 5Z9mzN7aPT1Wag+FoUCjAx12ZFGLzZf+JsSU1H6ccvK3VnJGwSpu+1T/X38fp9NAuGDI Gs+op14luKztiFy8EKu4TVq2J5COYlqckxedzOv67szy5YOMa4E4voRnG50u13VL4wyN uHtTmOX3ms8rZqhyU/Eywpvcae0zg5gl+gcKKSBjdWYjfk+aPbgsPxoUZfBKEZUPNfWA dGZpXmoUDpEp0Xe1x7YJbmVXPiDe4NZ76HJa10uFSIl1r0ycTiIllrbex2O77bs2HBUz lHuA== 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=bmwFZzfj93F8BfHLa1plmyPvVkiv73Ox5Gb+V+xdidA=; b=TWCdCtu4o/8Z0aUlMdOB+Oi0HctiGhvbksMnbn7JSWAA/Q3QuC4o8IMQdrW5kv49// 7P6fgdq2FgqD8RteuYj0Xpczc6MJv6Bs3TMi5f/JyEPVlceExTuRLSD4jvxMhYlDRDZL 0QK8SI1+iR1KxdmrLLEBER37fDa6UL1P7fjN1QBQdXb7lsbrMHMQTEnvSPNZp5ZaUwRS nudGAJ6uJ0Jl9qXfRmgGmXdLGVEiNb5mO1/DlDSkBI40SrDOs6lfKlbu6wgUMzQJtr1m 6KlKjaeQ9SqoBPV5Ocb2grJA93Pfs91DIRYad20xE4djyjd4EGPHRcwGOkJQPkwwa9Iz StjA== 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 v7-20020a056e02164700b002dd1182050fsi4412588ilu.144.2022.07.22.09.03.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 09:03:19 -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 D2FAB8032B; Fri, 22 Jul 2022 18:02:51 +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 9528183AC3; Fri, 22 Jul 2022 18:02:39 +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 211AE83F92 for ; Fri, 22 Jul 2022 18:02:35 +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 0BD561063; Fri, 22 Jul 2022 09:02:35 -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 887483F73D; Fri, 22 Jul 2022 09:02:32 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Tom Rini , Sughosh Ganu Subject: [PATCH v8 3/8] tpm: rng: Add driver model interface for TPM RNG device Date: Fri, 22 Jul 2022 21:32:04 +0530 Message-Id: <20220722160209.863840-4-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220722160209.863840-1-sughosh.ganu@linaro.org> References: <20220722160209.863840-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 V7: None 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 Fri Jul 22 16:02:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 592471 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b811:0:0:0:0 with SMTP id fc17csp635468mab; Fri, 22 Jul 2022 09:03:31 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vLg7Yp2JdALgK7QNdf2iahMEZjfIoWsR93Ww6iywZQEHJaoJ4JbriQceG9Xf951HMKATZN X-Received: by 2002:a05:6638:4883:b0:33f:7948:e685 with SMTP id ct3-20020a056638488300b0033f7948e685mr351063jab.138.1658505811032; Fri, 22 Jul 2022 09:03:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658505811; cv=none; d=google.com; s=arc-20160816; b=pYp/QAEJ6pNn0iizovklF6w17Ycl8RgUAuiLdTvg8oawxJNRpxd1Ejj7CIZsu5GxxI o0ybbJgH0YqgYYFBuI4agp6d3Ww2oSoKCtUyOAodRO1R48rXeigEMwGLxOFTHzV0I4du gMnfD9F0H4Fp+l0FpDZfB36hj09qqvAIt7oTJGILATzR4LXp7LdU1ZlXB4X6mRB8m4xM ZAdh4xm6CWPU1x/CH5XOYLDRbLKWI+MpzXJk9w78BfRvU6CYWf6LMlQ83xgWPxY2NuJK /TqrzOHcFNzc0GbJFoj6h8POBdrcp4SvRnXlQ3RGAsmgcHOG3iaCpuCYRQ7hS7CDckJK PRfw== 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=hhIEDv824oFbwoUzUhAli043EaCj59KWEUNXVzvKBTA=; b=CyqBb/zpZ5SCqkxZqMrB+ILX9Cl5znbDcWg/K7otZ9M2Eugdga1gaax845OODg8eLQ OiPhQHutq/Qynf99l39h1ayLRgYYrbYCN+eWvbX8osA2GFFAcIkDU9dtYLHaFgSFF6fL 1D8fYKBWZJKFf5HVGkuV5ep4esSB1f3Kgo/emqDvh+GH3PtgQAQEDm1uoBEx7oaPdL8U n3voNd4QZ4IgmcPatCinHz8pEHgARuSCGuY8ez2NfW7NzSV4HP9qg4L6OHE6k0ceKfvx DFxItP0H0coiQZ6b5HyBXEx3ITOOfm0wx57CmxN8EvapF0xRGISZ0ddvlsjR3SBoQYPC 5Y4A== 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 s12-20020a056e0218cc00b002ca96391aa1si4498298ilu.142.2022.07.22.09.03.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 09:03:31 -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 9753C83FB5; Fri, 22 Jul 2022 18:02:54 +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 B72EE83FB2; Fri, 22 Jul 2022 18:02:41 +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 8E9E083F9B for ; Fri, 22 Jul 2022 18:02:37 +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 7557E106F; Fri, 22 Jul 2022 09:02:37 -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 F21033F73D; Fri, 22 Jul 2022 09:02:34 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Tom Rini , Sughosh Ganu Subject: [PATCH v8 4/8] tpm: Add the RNG child device Date: Fri, 22 Jul 2022 21:32:05 +0530 Message-Id: <20220722160209.863840-5-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220722160209.863840-1-sughosh.ganu@linaro.org> References: <20220722160209.863840-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. No compatible string is provided because this is not available in the binding defined by Linux. If multiple rand devices are in the system, then some method of selecting them (other than device tree) will need to be used, or a binding will need to be added. Signed-off-by: Sughosh Ganu Reviewed-by: Ilias Apalodimas --- Changes since V7: * Added a paragraph in the commit message highlighting the absence of the compatible string in the RNG driver, as suggested by Simon. * Rearranged the inclusion of headers as per the coding style guidelines, as suggested by Simon. * Use TPM_RNG_DRV_NAME for the RNG child name as suggested by Simon. drivers/tpm/tpm-uclass.c | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/drivers/tpm/tpm-uclass.c b/drivers/tpm/tpm-uclass.c index f67fe1019b..0eb35f50c4 100644 --- a/drivers/tpm/tpm-uclass.c +++ b/drivers/tpm/tpm-uclass.c @@ -9,12 +9,16 @@ #include #include #include -#include -#include +#include #include #include +#include +#include +#include #include "tpm_internal.h" +#define TPM_RNG_DRV_NAME "tpm-rng" + int tpm_open(struct udevice *dev) { struct tpm_ops *ops = tpm_get_ops(dev); @@ -136,12 +140,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_RNG_DRV_NAME, &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 Fri Jul 22 16:02:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 592472 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b811:0:0:0:0 with SMTP id fc17csp635718mab; Fri, 22 Jul 2022 09:03:43 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sTUtaeKbuThD4nk3nG7QVDLCFwNanTne7VweZNklTpQo8MNfVNsMoY3LbDrSriEeUqV59r X-Received: by 2002:a05:6638:251:b0:33f:6d6e:d8e0 with SMTP id w17-20020a056638025100b0033f6d6ed8e0mr351721jaq.200.1658505823250; Fri, 22 Jul 2022 09:03:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658505823; cv=none; d=google.com; s=arc-20160816; b=QGCZ4Y7vs8QW+XKMmfVf0fNhtfbZvGwRcQlrPTBFi8qX1qAzwQhOH1JcoDxYzr73RT y4a59mu0EuhvlfrfurxoLUHvK/6b8ntlgCg0ts7I2E4SYgF7+f63tJfvg8EjMLEUWByB UEUHtCNSCS1nxvTeHAzciwKyyqX57s9gyZcY66zgIgYX5tVSDbwXpD7il5eWtHIqGGll gN8GtiHt3max1jrhUw8Urq+Zil3p4x4FMkvHyPnL7m23V84EV8qJ+bir+zvkcIj2/Faw bae+UdzhlZdynxAE1z3VADtS5dTYpZUJuo+/0NyNdTqcqlNncDv5S+Mf3/xTTYeUttR6 DHuw== 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=zAuFoK+IiIuMt00MGFNqHuCUADr8dOM6K+7ktSf/yWg=; b=HjNZYWP9MFKepk7ChhLesBLLeVkPyRaEH3qJceohph4y28nk1hR4eTvLN9anKpWSz0 UL21kSaJyekPnGO8kyirl8yyCuiBftRBIqMlPrcUwrVwUDNSY9OZJjLae+SH9v6SuZ7e kDjWfDHIR3JLF+5cIlPHe8kqJ/4EF3P1/Kp4aZZD3yLEEHFxjNeLJ3+QspFcirkWxwHY odua6QtpaUQOo/HFclT9u6MDlbGeevs2CcEUIpmf4QLL/QN2bomZAfYvxfjeDCPEnPL8 oRAKRHWOJIdl+doi5RhxRFabc0VM02J0QGIZAxG+XpyL7Adls117Colx4Bp/4epgwQel wGkw== 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 n24-20020a02a198000000b0033e148ee4dcsi4362331jah.91.2022.07.22.09.03.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 09:03:43 -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 1D530840A6; Fri, 22 Jul 2022 18:02:57 +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 F254B83FB5; Fri, 22 Jul 2022 18:02:43 +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 0CFBA838DD for ; Fri, 22 Jul 2022 18:02:40 +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 E099B1063; Fri, 22 Jul 2022 09:02:39 -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 691D33F73D; Fri, 22 Jul 2022 09:02:37 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Tom Rini , Sughosh Ganu Subject: [PATCH v8 5/8] cmd: rng: Add support for selecting RNG device Date: Fri, 22 Jul 2022 21:32:06 +0530 Message-Id: <20220722160209.863840-6-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220722160209.863840-1-sughosh.ganu@linaro.org> References: <20220722160209.863840-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 V7: 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 Fri Jul 22 16:02:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 592473 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b811:0:0:0:0 with SMTP id fc17csp635999mab; Fri, 22 Jul 2022 09:03:56 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uy0GRRS6/T4JT+OQP10CFGO+eAr6CX3A9PfCNyIQzXFxQDjmwe8iUyvHlDuLcwSNCzcd54 X-Received: by 2002:a6b:d90d:0:b0:67c:a0:dc42 with SMTP id r13-20020a6bd90d000000b0067c00a0dc42mr161128ioc.103.1658505836345; Fri, 22 Jul 2022 09:03:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658505836; cv=none; d=google.com; s=arc-20160816; b=facNfKKRpIcaeV326nQEL+HS744BNndpweiDQL/HZBeq70X4Vr5yNGhZubmIdf0K9K ZIsElQPH43hB3ynaCxiNSzu/VQX0fes1ckmi99/aa5qBJ9/MFvBV1t+GQtTvnYeFRHwT UuPv0H9YOhJezDbZGM8omPAMW52LgHcFYpNHYzoi1sHfYOgroIfBjV7qPfc6dx0X+C+n TgCsFf9WppghAWKkAk+SGORXm2y/Vfi5W4vPUNWVuzNvGDtzGzr609bkCut0V8iV1tlJ Hx2J+Qr+FrpZhWAiyMvRs7VooLe8MffbYOW1Rr+zJqFJpI24QszgsHBLcU9LdO1HpNQr rdnQ== 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=t/AyOdEgU5xamN/K6PJVC9OLRerfA+RGhFW9F3PrYfM=; b=eD/BfgvH5hk71RaRMDQW/fAsPUitP7HgLOSxMyeZzLblEm3oMjAKlA1/NbESdXHiQh FAnmK1jMsCV3eWkcNFAOJ+snEPo1cT9+1MC8MHt4GM1jkW71UECTEWdLGxX5hmpcDKhW 1WBDw3gae3c1b7tH73bOYoXJLmT/RJCe5Oy8OzOZH1OyONQI9GDkWy1R5M5x8dg8QKjD 0kkJTMLgf8vyvCIKY7AR0iEC4SIfZHLSD3DbRr3d3qMGQqWmi4cE8wVOpxTN7xaWdRRG 9PKaO/FFJZ6VDwec2bu4g9mcqwWj/oj35TPwJAxkjjvU89xHQxcmXRLewLIF8VNk/syX Jd2w== 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 d5-20020a056e021c4500b002dce2d8dc07si4821060ilg.57.2022.07.22.09.03.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 09:03:56 -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 B35A484106; Fri, 22 Jul 2022 18:03:00 +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 A09A1840BE; Fri, 22 Jul 2022 18:02:47 +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 6CAB983F9B for ; Fri, 22 Jul 2022 18:02:42 +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 5646D1063; Fri, 22 Jul 2022 09:02:42 -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 D2D493F73D; Fri, 22 Jul 2022 09:02:39 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Tom Rini , Sughosh Ganu Subject: [PATCH v8 6/8] cmd: rng: Use a statically allocated array for random bytes Date: Fri, 22 Jul 2022 21:32:07 +0530 Message-Id: <20220722160209.863840-7-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220722160209.863840-1-sughosh.ganu@linaro.org> References: <20220722160209.863840-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 Reviewed-by: Ilias Apalodimas Reviewed-by: Simon Glass --- Changes since V7: 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 Fri Jul 22 16:02:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 592474 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b811:0:0:0:0 with SMTP id fc17csp636200mab; Fri, 22 Jul 2022 09:04:08 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s+LaXGBAUQzqpiyYeAWlUR++LbL9DuGgGI4OOuvIon4W7+2pXZT8T3N1AzwvwZ1UghHuzQ X-Received: by 2002:a05:6e02:1a46:b0:2dc:de84:6d3d with SMTP id u6-20020a056e021a4600b002dcde846d3dmr289106ilv.102.1658505848407; Fri, 22 Jul 2022 09:04:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658505848; cv=none; d=google.com; s=arc-20160816; b=pLDse9lxK+KYOuyZrURadbeJyDV8RrgrtlCpTSBhbMDRIHkM5Pv5HB3J6TeeeRkmmv UQD+Kj1IMLQ9zUfhEaQ+99xGrt+YprfVWw/rHsFoySPYjDyapnI4rhY8MRbyv7Nagz6N nFSsgMR4HQR1I6eXsF6r6e5gi7NdxYUlJd+6Ha8XxrgM2suDG9rJFIgJAZnXh87nvMYF SDNOlauopYA4FUTLjL61P2Lk3CqYcqRcMAqQqzWhjnObnOvLSNzykCG1Is6S9ow3z6lA RHn51DS+mpZQuVyqlC06pk465Z8DODAQEbSl8aVN5Osf0jaFtuDfg8W6LM8QuMOdgymq tQmg== 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=HI8Vjzu1bcK0wq2FDNvNbOPfeFGs0MI+5/1t6Q87RFk=; b=CKxRMHJeGL+i9rYwDZ5nthF7ikkvzrzs/xyAhBXVXK3AKYw7zATkUJLcRDm9iflFbz xi4sZ4E1osWBlkpFFbHs/ZZT6BgVTi6Z03AsnKmwfDSrDLZS8KQE0bRvnMJaWCQchlNv 7UfrgRqile9DbAHSrmX9KkL4Gn4GXsSwVjK5A42fdvyzpGdL0IWzD501a2/HSTJdiIcX aU1e9/A3oQWDWYOYbigH8IgQe9vKB4aQPJaw9gAucf+8HxQDSJhO9Wzxm70EbFwqWbrF BVJMwvzhRs0d8Q9dEW9nPQl5Ad239+yVewooTGCH1XusIrNuNOUU4TjMJ/66hftteGB9 9AtA== 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 c7-20020a023f47000000b00341a089e85asi3018365jaf.88.2022.07.22.09.04.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 09:04:08 -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 484B4840B3; Fri, 22 Jul 2022 18:03:04 +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 739F3840A6; Fri, 22 Jul 2022 18:02:49 +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 B3D5B83FA7 for ; Fri, 22 Jul 2022 18:02:44 +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 BF7F51063; Fri, 22 Jul 2022 09:02:44 -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 486DC3F73D; Fri, 22 Jul 2022 09:02:42 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Tom Rini , Sughosh Ganu Subject: [PATCH v8 7/8] doc: rng: Add documentation for the rng command Date: Fri, 22 Jul 2022 21:32:08 +0530 Message-Id: <20220722160209.863840-8-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220722160209.863840-1-sughosh.ganu@linaro.org> References: <20220722160209.863840-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 V7: 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 Fri Jul 22 16:02:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 592475 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b811:0:0:0:0 with SMTP id fc17csp636406mab; Fri, 22 Jul 2022 09:04:20 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uMGUyudmeR6tT5ZLW1AvsJllyz/0eBcR76QbSPfWMSGc6FShT03vHOBP/ZNJSkPBHllUEc X-Received: by 2002:a92:cbc5:0:b0:2da:d35b:c06b with SMTP id s5-20020a92cbc5000000b002dad35bc06bmr282757ilq.37.1658505860518; Fri, 22 Jul 2022 09:04:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658505860; cv=none; d=google.com; s=arc-20160816; b=OAg2V/cK16QotN6Zrv6+gvo+sEeA8kGBFHbSniXo8dT3Jg/lmRBf99iKJ2RfJLFw4W RbIq+e0bMr+nPUcdHTgmA7mUWKEVEVoC3o4dqiy2fOq6wXyw4XdoZEXVK5Ok8ISQQl56 Y7SfyhaXgjrYt07v5mdsLGmCTA3iUxqHVWu9XYDolg9sCI0IDrOxJXmvdQJH4AV5tpSV 8zdRlatZuV9mAnda8qC9bHnULpHBEIEzheHGSsCPK+aOR0kGLshOBcSppM1B7YplmgF5 5JHyqAmK+d1URZ6XD/JKRh4Rkryhxs7L2sxGhV/KBfFzlgOZn4HRJiu5fQ7F4iXAYrdz IimQ== 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=c16b5L0KHWThO0l29lQy91niMcdecLKCg3Fy5IUEN4k=; b=m2MGixRJyxDhWE+37sKj4On6CtyqHZukIq6kcjqh/9r0bvYV7cIgGP2KGp4gAfIbA5 VTEy7Og2JsgPOxjcHMUIalqWUDncyFbNQYan028kaGDXnnhEF8/nQURsdnXksKtKvjBD zzrJggNpi+RlFlUOF/DWBZd48O4sVyM5gc1fpZxKZXYGsSJXjGN4r0woz9z+neaC2JJD +XQQ+wmT3Y9sa5mcioYTQyzpwAthvF3d1sBc4d8RU67FeiTDe/gfhpcq+gM9zIzhFQ4i gKtkl4iOSdyPkzg/RK3Z2s6eG7epjODuK5uELMjs+KXG5VLY8xxS3HdDuIRa7Z2HIJMv U0jA== 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 a8-20020a92d588000000b002dcebc7608fsi3617307iln.47.2022.07.22.09.04.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 09:04:20 -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 07F39840E6; Fri, 22 Jul 2022 18:03:09 +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 5352B83FC0; Fri, 22 Jul 2022 18:02:52 +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 773E68406A for ; Fri, 22 Jul 2022 18:02:47 +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 3496D106F; Fri, 22 Jul 2022 09:02:47 -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 B13DE3F73D; Fri, 22 Jul 2022 09:02:44 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Tom Rini , Sughosh Ganu Subject: [PATCH v8 8/8] test: rng: Add a UT testcase for the rng command Date: Fri, 22 Jul 2022 21:32:09 +0530 Message-Id: <20220722160209.863840-9-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220722160209.863840-1-sughosh.ganu@linaro.org> References: <20220722160209.863840-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 V7: None cmd/Kconfig | 1 + test/dm/rng.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/cmd/Kconfig b/cmd/Kconfig index b3820f1e04..b4bf207a2d 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1963,6 +1963,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);