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 C96B7C32771 for ; Fri, 19 Aug 2022 13:48:32 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 379E984B88; Fri, 19 Aug 2022 15:47:41 +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="Eu0SR5/o"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3FC7784B62; Fri, 19 Aug 2022 15:47:24 +0200 (CEST) Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) (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 16FB484B5A for ; Fri, 19 Aug 2022 15:47:20 +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-oi1-x229.google.com with SMTP id v125so4854651oie.0 for ; Fri, 19 Aug 2022 06:47:20 -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; bh=icZ97ir7wTu6em7dHxP+n2xdox0rVjBp9kdYkk4VRjQ=; b=Eu0SR5/otwBnekROk45UI5kMKaca8fxLHnDLTVDSFYsm16L+1T5fCnZce3xADkPyCY gxtQvtqeUJhuhtuiIOjoWvKU/YJtX/YyLyAglkyUII14Vg0qnU3KXN22pw2HXcjeMTWd nwueCksrRCoW1/4mmAyePowjHY9VMQhV5jt9w= 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; bh=icZ97ir7wTu6em7dHxP+n2xdox0rVjBp9kdYkk4VRjQ=; b=upKUeP7ViN6fAGhtlasZJr5C7LfbdeyA3PDbgwVYK2beryLEsXL2kRIKJqQxF7cD5N eJrDMMOt177kWxDzsujnkf/LJtf8lvOdjINrj6AzV9VT2dJX8NZoOG30LVM/HqrLZo33 zi/yy6ReVMzqZ4GTYRPBLQ8ZX3NGBzeNMEuL/WZaXHdfBRNRIiHcSCJrISWpX5dj3ovB OBdfBLDgyvrm/6pUQ34wWnzOFrKsU3Jek1Wqt7AH/QdJd64gVKiPhTxvNwDBbgowP0ag 20HCqqryKtkgQF93/jnpIoI8vyJCka7lSvKKkhza3zfHPP8UvhLds04BDx2x/QgbvjHw c6Tg== X-Gm-Message-State: ACgBeo2td3iQYZ5IyBxnTAImruOFsfnM26bdctvMfXx60XvKJb2yVRAV 42Ygv3cv3zHQuBtuPX0kKmsWG0mvTbHWaQ== X-Google-Smtp-Source: AA6agR7ziTt75D+hhrbFH4/PRa+wt7iylwJhqp4uvglXq8qQfbDQb2U7tmtGmCyUO/0xglj85A6zbQ== X-Received: by 2002:a05:6808:2024:b0:344:7ff8:54ed with SMTP id q36-20020a056808202400b003447ff854edmr3371034oiw.155.1660916838361; Fri, 19 Aug 2022 06:47:18 -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 z36-20020a056870d6a400b0011856117469sm1309429oap.10.2022.08.19.06.47.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Aug 2022 06:47:18 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima , Ruchika Gupta Subject: [PATCH v3 7/7] tpm: Allow committing non-volatile data Date: Fri, 19 Aug 2022 07:46:47 -0600 Message-Id: <20220819134647.269563-8-sjg@chromium.org> X-Mailer: git-send-email 2.37.1.595.g718a3a8f04-goog In-Reply-To: <20220819134647.269563-1-sjg@chromium.org> References: <20220819134647.269563-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 v1) include/tpm-v2.h | 14 ++++++++++++++ lib/tpm-v2.c | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/tpm-v2.h b/include/tpm-v2.h index 8e90a616220..0a03994740d 100644 --- a/include/tpm-v2.h +++ b/include/tpm-v2.h @@ -712,4 +712,18 @@ u32 tpm2_submit_command(struct udevice *dev, const u8 *sendbuf, */ u32 tpm2_cr50_report_state(struct udevice *dev, u8 *recvbuf, size_t *recv_size); +/* + * tpm2_cr50_enable_nvcommits() - Tell Cr50 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 + * Return: result of the operation + */ +u32 tpm2_cr50_enable_nvcommits(struct udevice *dev); + #endif /* __TPM_V2_H */ diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c index 3de4841974a..d68c311651b 100644 --- a/lib/tpm-v2.c +++ b/lib/tpm-v2.c @@ -703,3 +703,23 @@ u32 tpm2_cr50_report_state(struct udevice *dev, u8 *recvbuf, size_t *recv_size) return 0; } + +u32 tpm2_cr50_enable_nvcommits(struct udevice *dev) +{ + u8 command_v2[COMMAND_BUFFER_SIZE] = { + /* header 10 bytes */ + tpm_u16(TPM2_ST_NO_SESSIONS), /* TAG */ + tpm_u32(10 + 2), /* Length */ + tpm_u32(TPM2_CR50_VENDOR_COMMAND), /* Command code */ + + tpm_u16(TPM2_CR50_SUB_CMD_NVMEM_ENABLE_COMMITS), + }; + 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.1.595.g718a3a8f04-goog