Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 70191ECAAD8 for ; Wed, 31 Aug 2022 03:07:08 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 06DED849D8; Wed, 31 Aug 2022 05:06:24 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="l1CmspyZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E68FD849B4; Wed, 31 Aug 2022 05:06:07 +0200 (CEST) Received: from mail-oa1-x2d.google.com (mail-oa1-x2d.google.com [IPv6:2001:4860:4864:20::2d]) (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 56499849AD for ; Wed, 31 Aug 2022 05:06:00 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-oa1-x2d.google.com with SMTP id 586e51a60fabf-11ba6e79dd1so21301977fac.12 for ; Tue, 30 Aug 2022 20:06:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=mpKQTShbxMoNdeQ6gypLOo+4mqJCLoXvnVsJGWgRRlk=; b=l1CmspyZLtk5wMjqcJ6+2I5YFK4vrrm77AB+fAQYOOEa52dxGb2yyaVcPtsF5Ocr4h SxRqIag4tOhoy8R08loHFiPwkSwOLYfrLEyIubPjPd+SpBaEJ0oAw6Pqj/RMU0xHJmW1 tnobu5B7KOjGSNqlDklWj016/mQyBe4MGVUao= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=mpKQTShbxMoNdeQ6gypLOo+4mqJCLoXvnVsJGWgRRlk=; b=OlFN2kEO0Ae407IzsAcYu1MzVo1ChPLy0HbLEEARFjfcKdn1elw7EFKa1aL4KZjJd9 C9yzcwq9z3TcQ+d/uPWEplu99NHh629b+S/E5EMC8mj5Qk4Y+NOWwpxrtBG7qWNNu53j WZFei7kaN8tWDeGAC1R7gBPWMeacYoYK4E+MeBBRH5J3GCqHfbXx6UMmgL93RAJMlVSS JjjpVGo93kQTKcESGKM5EpBEgoc2wnx9TNUnqCsruIiW1rPTaDCVzswld8N2O6FD0zXh cpaitWvfjtrRbEqNpfsPj7uKpQIzO3cn/wfEpTCtjnhYteGm7M8qKXmpHODR/GZY+Wi2 jviw== X-Gm-Message-State: ACgBeo3ZyddxF3fEiEcryWGTUSQ9tY66uZW96gXRjsbihS6ahn27+IAv GRhlZahnFRhR1wnrpV+W2xllPmtKQg2JGA== X-Google-Smtp-Source: AA6agR4li4OKfD6KOpPYRmyQ55k70BM+9zlryStNDgLE0laOcuQHpv8/06/AIDPIlHKjbbyU6sn6rw== X-Received: by 2002:a05:6871:829:b0:11e:58fd:6eb3 with SMTP id q41-20020a056871082900b0011e58fd6eb3mr504089oap.186.1661915158743; Tue, 30 Aug 2022 20:05:58 -0700 (PDT) Received: from sjg1.roam.corp.google.com (c-67-190-102-125.hsd1.co.comcast.net. [67.190.102.125]) by smtp.gmail.com with ESMTPSA id cp6-20020a056830660600b0063b34c35575sm2888129otb.42.2022.08.30.20.05.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Aug 2022 20:05:58 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass Subject: [PATCH v5 7/7] tpm: Allow committing non-volatile data Date: Tue, 30 Aug 2022 21:05:38 -0600 Message-Id: <20220831030538.26742-8-sjg@chromium.org> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog In-Reply-To: <20220831030538.26742-1-sjg@chromium.org> References: <20220831030538.26742-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 an option to tell the TPM to commit non-volatile data immediately it is changed, rather than waiting until later. This is needed in some situations, since if the device reboots it may not write the data. Add definitions for the rest of the Cr50 commands while we are here. Signed-off-by: Simon Glass --- (no changes since v4) Changes in v4: - Rename function and add arguments for the command/subcmd include/tpm-v2.h | 17 +++++++++++++++++ lib/tpm-v2.c | 21 +++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/tpm-v2.h b/include/tpm-v2.h index 36c6ac0be6e..737e57551d7 100644 --- a/include/tpm-v2.h +++ b/include/tpm-v2.h @@ -671,4 +671,21 @@ u32 tpm2_submit_command(struct udevice *dev, const u8 *sendbuf, u32 tpm2_report_state(struct udevice *dev, uint vendor_cmd, uint vendor_subcmd, u8 *recvbuf, size_t *recv_size); +/** + * tpm2_enable_nvcommits() - Tell TPM to commit NV data immediately + * + * For Chromium OS verified boot, we may reboot or reset at different times, + * possibly leaving non-volatile data unwritten by the TPM. + * + * This vendor command is used to indicate that non-volatile data should be + * written to its store immediately. + * + * @dev TPM device + * @vendor_cmd: Vendor command number to send + * @vendor_subcmd: Vendor sub-command number to send + * Return: result of the operation + */ +u32 tpm2_enable_nvcommits(struct udevice *dev, uint vendor_cmd, + uint vendor_subcmd); + #endif /* __TPM_V2_H */ diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c index edee9854a7c..697b982e079 100644 --- a/lib/tpm-v2.c +++ b/lib/tpm-v2.c @@ -704,3 +704,24 @@ u32 tpm2_report_state(struct udevice *dev, uint vendor_cmd, uint vendor_subcmd, return 0; } + +u32 tpm2_enable_nvcommits(struct udevice *dev, uint vendor_cmd, + uint vendor_subcmd) +{ + u8 command_v2[COMMAND_BUFFER_SIZE] = { + /* header 10 bytes */ + tpm_u16(TPM2_ST_NO_SESSIONS), /* TAG */ + tpm_u32(10 + 2), /* Length */ + tpm_u32(vendor_cmd), /* Command code */ + + tpm_u16(vendor_subcmd), + }; + int ret; + + ret = tpm_sendrecv_command(dev, command_v2, NULL, NULL); + log_debug("ret=%s, %x\n", dev->name, ret); + if (ret) + return ret; + + return 0; +} -- 2.37.2.672.g94769d06f0-goog