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 D81DEC32772 for ; Tue, 23 Aug 2022 17:14:15 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EDA848486D; Tue, 23 Aug 2022 19:13: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="ev2/q+hR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5D5268025C; Tue, 23 Aug 2022 19:13:11 +0200 (CEST) Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) (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 0B6908483C for ; Tue, 23 Aug 2022 19:13:08 +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-pg1-x52d.google.com with SMTP id bh13so12831422pgb.4 for ; Tue, 23 Aug 2022 10:13:07 -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=OUgrYJ4Ub+BkRIM768bcHdXOIO9+zjU7+YCzdARBryc=; b=ev2/q+hRID6R73Rs7ZuYd/VdCiIXeCbEl1wTrgT6l1Ye0IaiK+sXH2J3Vwz/ADSMuk a59SJ/dc6UOK6OsDVHr6PzorouNZk8NSlgSuirhzgnAmHsLFoPOxFE+guJRS69hQXJOo GGTH4lIbvo6uBPQCQ6BWH27m1LLV3ulZo3lh0= 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=OUgrYJ4Ub+BkRIM768bcHdXOIO9+zjU7+YCzdARBryc=; b=R7kJMgferlypcfzIvhssMTIxjIPBCCAJfl58NAKDWk/FKXkK00o1d1sZURywFiFxpx 1dF2JkaAbPjR9xf1lIRmr2MEeHbyo5kAxmTcrg694zZ+cnIbzdOVVnoZdOwoLXQ6PrnL 33fZev2vNwlLk9MN4q7z5Q6N3lveGEX7xBxAXcBi6BFQ/M7dXa1XSwmdVR1s8sJK0yHL KIJ6cBFy8mOO3yHnK2Rbx+86lNc1Evd5+Xq0KmIDvzDN5k7/bBCTcGmpgm1MdF0ozgC+ 4mHrXHuCD7CHpsOrT+P5HVXcHLjG/Vf75TQfTvImwoxzR2B5NQeMGYBHKlVrN6J//Gkd JMBQ== X-Gm-Message-State: ACgBeo2VrN+aWZma8RVGPLLnLWechSF6J0qYRtc4qntk5q9to4TbyFN1 cu6SxPaiqpOSU9+RC20+awDM+t1+zIRdgfRW X-Google-Smtp-Source: AA6agR6jWtmznEZBjUBEsdw4vnFf4rQmNmLHzxTmhqVVKz3ZTJEaHXzCwuwYy9BzXTzAxcHxJJR7dg== X-Received: by 2002:a63:eb49:0:b0:421:8c9b:4ab1 with SMTP id b9-20020a63eb49000000b004218c9b4ab1mr21398831pgk.339.1661274786141; Tue, 23 Aug 2022 10:13:06 -0700 (PDT) Received: from sjg1.corp.google.com ([2620:0:1000:2514:4cd7:64:5174:de80]) by smtp.gmail.com with ESMTPSA id x3-20020a170902a38300b0016f154c8910sm10759441pla.204.2022.08.23.10.13.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Aug 2022 10:13:05 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Heinrich Schuchardt , Ilias Apalodimas , Masahisa Kojima , Ruchika Gupta Subject: [PATCH v4 7/7] tpm: Allow committing non-volatile data Date: Tue, 23 Aug 2022 10:12:40 -0700 Message-Id: <20220823171240.386269-8-sjg@chromium.org> X-Mailer: git-send-email 2.37.2.609.g9ff673ca1a-goog In-Reply-To: <20220823171240.386269-1-sjg@chromium.org> References: <20220823171240.386269-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 --- 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.609.g9ff673ca1a-goog