From patchwork Wed Jan 25 11:39:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 646557 Delivered-To: patch@linaro.org Received: by 2002:a17:522:b9de:b0:4b9:b062:db3b with SMTP id fj30csp221378pvb; Wed, 25 Jan 2023 03:39:33 -0800 (PST) X-Google-Smtp-Source: AK7set+CWdoNyS4LwiOqZJlaoZIFoKBAPDvwK+YWcjquGOT0lyYysSIcnlkWLiXt4ExvWypBs+K2 X-Received: by 2002:a05:6870:a408:b0:163:1969:1ae1 with SMTP id m8-20020a056870a40800b0016319691ae1mr2830471oal.0.1674646773591; Wed, 25 Jan 2023 03:39:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674646773; cv=none; d=google.com; s=arc-20160816; b=APXAg98VjAQKOb1lXEpFEpOl1kdEwHRoeh9wRyRrhGuSxVJzq/r8+hfVWwuFfiyG2i XER9OncnWM/E2U2Aetn7Co0ziet8Hn0u/T8bzTuG5N5bZ6NEYq9zQmdj6Bdj8ospp3LR kEPyW9F+tM7qkCbLzDg7oZyZbp1lI+GctjARH86VeOt2XIiOPWmylRJtJ6in2TqwSV1N SBbFb8jI35oHcjMHEcaqdjYshI700Z2I4apSGqjBYywIVXPK1rmuinoW5O/D3BAMHvPX W42FTkjkvfB4NYZvbxJsAA/4DHH9fzMzpOGhrNWSz9LLsORkPYChys3MxT1p9pzlv7y8 DiDw== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=fqqxM+OONfQHliw+seZpRPyYSHaD+WY9Ca/T6ZwZvsc=; b=Tgw59nrEKQEysaezt94YTOwtjJ0oZ1Fmld0anJvNCxwAMFOjSAuh+uhyVb/+98nXMP OE4Gt240j9xwxLvErf2yXRnymBinTeH7i32jtHT3sxl2GIZMTqj8s+w9phApYk/hPBW8 obFUQ9YiE7/CMOhsJTNHc7O/BQLRaO2B2wC0Q9H0UH3eWiTsag2hBN8EVSi0YXviKlQr 0ai7bafPdlEKCG1LDIxh3ajg1UbvvqxGuG4HUwEvtSx71HM0hoWALVWqRvzkEwQpkqdf wvDghs0AZ8vto5nzyaY4B8VEKKdgSwoxlUZUk4xtGrFyRqD9SlVvb/8CDMloF3lJDtSl aMGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W3k50qca; 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=pass (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 ce13-20020a056830628d00b006884a8a57cdsi2078935otb.134.2023.01.25.03.39.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 03:39:33 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W3k50qca; 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=pass (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 09C3B85615; Wed, 25 Jan 2023 12:39:29 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="W3k50qca"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5982885688; Wed, 25 Jan 2023 12:39:27 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 09A5C84EEF for ; Wed, 25 Jan 2023 12:39:24 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-ed1-x531.google.com with SMTP id w11so6156377edv.0 for ; Wed, 25 Jan 2023 03:39:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=fqqxM+OONfQHliw+seZpRPyYSHaD+WY9Ca/T6ZwZvsc=; b=W3k50qcaKFMtTt6vSxV9kzuPAAhrEDEE+gy9Y5XwgfZdRny7nApHKixAPstua56xIX ebel9B0HXLTx/giMUvNGCD/F53OkjIeIhq1Cvih0yjWaqHFzcLRcfvZSrpQqlzpSKbIf g57tUA+X7VO6UKzVzF0aBL8Mdr8iElfvusoeUEj9GHzXJFXvqZtbW09aJMjMcU8mSl7+ Tvhi0a++YPnP0f0ixjNhDAY/UBlPlcpna49PVXN81Pyel9+RAMI8ZmlktxTZ63v5hDxy JzM744jjqSXcphw5ob40fe52pMssVJdfh5cTNJTv5DpzEzCphXfRD5uETtX4ipfEh4JC m6wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fqqxM+OONfQHliw+seZpRPyYSHaD+WY9Ca/T6ZwZvsc=; b=W7PbiO9JK/wBlqKkf56msW68NZBf+NXlptjuVD8PP92AMBnFR0CG6tNkKa4Vqy1l6u V7skHoUDi3P56Hs+OzR3bk5DbA7Qcr1y0Qzos6gmBE/lSuj6YsX0H3FBWEI7cWQK9Rzi kTynLs3Py5kChrAeHTzoPRvBw231LqAlahub3JuwMItgXRUNvCOMYWaRwc7A6SCWcn7x YkCK2CApZUEegQ5kWh1zrP8/+jGga/a0qho4JjMDvTRJuWtQmSvknCvgirPsZmw5PqLy lg227Bupcq567YWHu3bYao/bQg5NJxArUmWSKYtGnyHDCzpMKuykIjik52A/4Bun2ai9 lnbw== X-Gm-Message-State: AFqh2korTTneX2IIEG5/5VBaY/qZW/EAJDxP+EVHCUWj+HSBQV94Mb0p ozV/6xYLdGcAVM0dEpdZ31+nU45i4qJgCMR+ X-Received: by 2002:a05:6402:2990:b0:499:8849:5fb8 with SMTP id eq16-20020a056402299000b0049988495fb8mr35648123edb.30.1674646763593; Wed, 25 Jan 2023 03:39:23 -0800 (PST) Received: from localhost.localdomain ([2a02:85f:fc9d:e4b5:f0f6:e48b:8d50:ecb2]) by smtp.gmail.com with ESMTPSA id c10-20020a056402100a00b0049dfd6bdc25sm2261794edu.84.2023.01.25.03.39.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 03:39:23 -0800 (PST) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Heinrich Schuchardt , Simon Glass , Sughosh Ganu Subject: [PATCH 1/2] tpm: add a function that performs selftest + startup Date: Wed, 25 Jan 2023 13:39:03 +0200 Message-Id: <20230125113904.517057-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.38.1 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 As described in [0] if a command requires use of an untested algorithm or functional module, the TPM performs the test and then completes the command actions. Since we don't check for TPM_RC_NEEDS_TEST (which is the return code of the TPM in that case) and even if we would, it would complicate our TPM code for no apparent reason, add a wrapper function that performs both the selftest and the startup sequence of the TPM. It's worth noting that this is implemented on TPMv2.0. The code for 1.2 would look similar, but I don't have a device available to test. [0] https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-1-Architecture-01.07-2014-03-13.pdf ยง12.3 Self-test modes Signed-off-by: Ilias Apalodimas --- include/tpm-v2.h | 8 ++++++++ include/tpm_api.h | 8 ++++++++ lib/tpm-v2.c | 29 +++++++++++++++++++++++++++++ lib/tpm_api.c | 8 ++++++++ 4 files changed, 53 insertions(+) diff --git a/include/tpm-v2.h b/include/tpm-v2.h index 737e57551d73..3013f69a90ed 100644 --- a/include/tpm-v2.h +++ b/include/tpm-v2.h @@ -688,4 +688,12 @@ u32 tpm2_report_state(struct udevice *dev, uint vendor_cmd, uint vendor_subcmd, u32 tpm2_enable_nvcommits(struct udevice *dev, uint vendor_cmd, uint vendor_subcmd); +/** + * tpm2_auto_start() - start up the TPM and perform selftests + * + * @param dev TPM device + * Return: return code of the operation (0 = success) + */ +u32 tpm2_auto_start(struct udevice *dev); + #endif /* __TPM_V2_H */ diff --git a/include/tpm_api.h b/include/tpm_api.h index 8979d9d6df7e..022a8bbaeca6 100644 --- a/include/tpm_api.h +++ b/include/tpm_api.h @@ -331,4 +331,12 @@ static inline bool tpm_is_v2(struct udevice *dev) return IS_ENABLED(CONFIG_TPM_V2) && tpm_get_version(dev) == TPM_V2; } +/** + * tpm_auto_start() - start up the TPM and perform selftests + * + * @param dev TPM device + * Return: return code of the operation (0 = success) + */ +u32 tpm_auto_start(struct udevice *dev); + #endif /* __TPM_API_H */ diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c index 697b982e079f..c34e158e2bb4 100644 --- a/lib/tpm-v2.c +++ b/lib/tpm-v2.c @@ -44,6 +44,35 @@ u32 tpm2_self_test(struct udevice *dev, enum tpm2_yes_no full_test) return tpm_sendrecv_command(dev, command_v2, NULL, NULL); } +/* + * - If a testable function has not been tested and is requested the TPM2 will return + * TPM_RC_NEEDS_TEST. + * - If TPM2 self-test has been received and the tests are not complete the + * result will be TPM_RC_TESTING. + * - If testing of all functions is complete without functional failures the result + * will be TPM_RC_SUCCESS. + * - If any test failed, the result will be TPM2_RC_FAILURE. + * - if the TPM hasn't started it will return TPM2_RC_INITIALIZE. + */ +u32 tpm2_auto_start(struct udevice *dev) +{ + u32 rc; + + rc = tpm2_self_test(dev, TPMI_YES); + if (rc && rc != TPM2_RC_INITIALIZE) + return rc; + + if (rc == TPM2_RC_INITIALIZE) { + rc = tpm2_startup(dev, TPM2_SU_CLEAR); + if (rc) + return rc; + + rc = tpm2_self_test(dev, TPMI_YES); + } + + return rc; +} + u32 tpm2_clear(struct udevice *dev, u32 handle, const char *pw, const ssize_t pw_sz) { diff --git a/lib/tpm_api.c b/lib/tpm_api.c index 7e8df8795ef3..5b2c11a277cc 100644 --- a/lib/tpm_api.c +++ b/lib/tpm_api.c @@ -35,6 +35,14 @@ u32 tpm_startup(struct udevice *dev, enum tpm_startup_type mode) } } +u32 tpm_auto_start(struct udevice *dev) +{ + if (tpm_is_v2(dev)) + return tpm2_auto_start(dev); + + return -ENOSYS; +} + u32 tpm_resume(struct udevice *dev) { if (tpm_is_v1(dev))