From mboxrd@z Thu Jan 1 00:00:00 1970 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 1DA0CC636D6 for ; Mon, 20 Feb 2023 16:31:41 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4C90B85103; Mon, 20 Feb 2023 17:31:39 +0100 (CET) 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="ZLDuUwLO"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 35C2485103; Mon, 20 Feb 2023 17:31:37 +0100 (CET) Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) (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 E59DC80FF7 for ; Mon, 20 Feb 2023 17:31:33 +0100 (CET) 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-il1-x12a.google.com with SMTP id z3so494467ilm.0 for ; Mon, 20 Feb 2023 08:31:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.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=ZSCl2EW9tauuGNYxd3HYrsOTO4OdAUqvkjuxKxlXwJ0=; b=ZLDuUwLOrJgWSbF4rAjqNidENxd54NwUFlosf0PzKS8tYHWz26P7QOKF6TjDsmD8bM UH4RdyVMwiXSbV+Ye/C/nq2072z6adTXfBy04sh0g4f1aTBpo/WXDrNoouWKjDxVcDnT ++wvVBvs2PWBwz3mFn9GJ04PlwakygkiiNr8c= 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=ZSCl2EW9tauuGNYxd3HYrsOTO4OdAUqvkjuxKxlXwJ0=; b=YKDYdOS1yEq4eh4e9m7VA+STvin2QjYqKEBLbKLPnaCbwzLHiXN+XZRDqWAasflkc+ bDmu7Nxuu20E58AkjUEbegavw6VGZZYRfeptiFVDOfdXzBK60+dfFC4XzP9J7kd+O2G5 Aeun7TkX3M1cwrCOlby4mYGt0X9FCG90TS2Tw8mz1QT0dXZLxjV1WjOp37TmJmPKMaK6 jnLuoH3Hajb1P3iMBkjhhI0HwZsxHx58fYzjnSXTR40WThTTEC00oHi1t1mjb4t6Kpbs PVaRJxukz+uJWF8AQ2nRi7fxjaZ5bXlblT0NVrUFSHoFQN/BDU0A1NKPfDJOB9M/HwIa eAOw== X-Gm-Message-State: AO0yUKXvPs1Uig9qBv+e5fuAjzvPYfahOBg9JYd9fl4qXs60Vp9QPNu7 MqAlDvWHtkaFZPvs1z62ecZZA6zyjW8NbgGz X-Google-Smtp-Source: AK7set8XssGqx4EClQcNWvckMhSeRx0DrmeASN9YGfuhs7wPgP2QoSWfzvQVpVp/NoYei+gA/Oj/hw== X-Received: by 2002:a05:6e02:20c8:b0:313:f9df:2f4d with SMTP id 8-20020a056e0220c800b00313f9df2f4dmr3225138ilq.29.1676910688515; Mon, 20 Feb 2023 08:31:28 -0800 (PST) Received: from kea.bld.corp.google.com ([2620:15c:183:200:36b5:3ff0:a644:eea5]) by smtp.gmail.com with ESMTPSA id z11-20020a056e02088b00b0031599ce31ccsm737105ils.86.2023.02.20.08.31.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Feb 2023 08:31:28 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass Subject: [PATCH v2] tpm: Allow committing non-volatile data Date: Mon, 20 Feb 2023 09:31:24 -0700 Message-Id: <20230220163124.299996-1-sjg@chromium.org> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog 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 --- I am resending this as I think it got lost. Changes in v2: - Rebase to master 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 bdf019b0f93..5fcd3649b74 100644 --- a/lib/tpm-v2.c +++ b/lib/tpm-v2.c @@ -699,3 +699,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.39.2.637.g21b0678d19-goog