From patchwork Sat Jan 16 21:51:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1427599 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=NzErsxmJ; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DJBdL36Nlz9sWF for ; Sun, 17 Jan 2021 08:53:42 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DE34F829CD; Sat, 16 Jan 2021 22:52:19 +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="NzErsxmJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6A33D829B1; Sat, 16 Jan 2021 22:52:01 +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.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) (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 E3A4C829A5 for ; Sat, 16 Jan 2021 22:51:56 +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-io1-xd31.google.com with SMTP id w18so25427682iot.0 for ; Sat, 16 Jan 2021 13:51:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=q6+9CbHfQf9ntpcFtn9rAXSj9I2xCBmuUfLUrhSuTJE=; b=NzErsxmJPw+h2IWenJ0AReAIDBp+mMghXGIw+rqumkiqKXHyTTzgwIxlTZWrnjYwFo h0DzT8JGZBo4Q9fmQFfYLxYU9EZTZFSAcRGrrx/0hubY1ldl7r/XjhtsAI/HXrXLQiMQ 4GRKtm9Vh7uQ9OGKSjerJsd7KBkSsGMrAX+Bo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=q6+9CbHfQf9ntpcFtn9rAXSj9I2xCBmuUfLUrhSuTJE=; b=WEzO95jpTrE3WSpW4/efFAqJjmrwy3EsY5sEc0jh7nKmyoygRYpkkz/dLelVpR7JVz 7eYe3xjcguBnUVmEIq4mlZyBQZNdlNTr7XltlwdkGZOjr82fM3T0twd1cArEOFQ7FUf3 MMdiF7DXMEH3iIbDGbJvmKwBWoeaLAuljaENLaM6N0jzIioUQaXe8cCVw2PK3nlKD1JD 6LFalymFIG2CvAVOlHbA6shZodIzsBbRxXe5rcW7+2aBaV57N2dE+aqKqsCDIwBSE1jt prvl9TMhMezDqofA/hGU6oT3gkPDdjMJVzSjyPLB9RIsVibcYMgdaszMMhED9WxCvBkW LF0g== X-Gm-Message-State: AOAM532aHwh7fX1HqnZyK/QvsoS2aENg72KbaHcZM1EarNfH6P9wKjrS JXPqC/eWogw8J3OXQzP9RGoqNeUpXExKrYM4 X-Google-Smtp-Source: ABdhPJy+eFtef1955NTbcGJUEdJVLprCgiomkLeJnKyZ57FSrM2SoztJ5PjpqqbT4dsDgCBEZnaatQ== X-Received: by 2002:a92:1bda:: with SMTP id f87mr15718637ill.45.1610833915597; Sat, 16 Jan 2021 13:51:55 -0800 (PST) Received: from localhost.localdomain (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id r19sm7519665ila.70.2021.01.16.13.51.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Jan 2021 13:51:55 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Bin Meng , Dhananjay Phadke , Heinrich Schuchardt , Ilias Apalodimas Subject: [PATCH 10/11] tpm: Add TPM2 support for write_lock Date: Sat, 16 Jan 2021 14:51:37 -0700 Message-Id: <20210116215138.1218256-10-sjg@chromium.org> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog In-Reply-To: <20210116215138.1218256-1-sjg@chromium.org> References: <20210116215138.1218256-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.3 at phobos.denx.de X-Virus-Status: Clean Implement this API function for TPM2. Signed-off-by: Simon Glass --- include/tpm-v2.h | 12 ++++++++++++ lib/tpm-v2.c | 23 +++++++++++++++++++++++ lib/tpm_api.c | 2 +- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/include/tpm-v2.h b/include/tpm-v2.h index 6a400771af1..1ca1e7e2011 100644 --- a/include/tpm-v2.h +++ b/include/tpm-v2.h @@ -241,6 +241,7 @@ enum tpm2_command_codes { TPM2_CC_NV_DEFINE_SPACE = 0x012a, TPM2_CC_PCR_SETAUTHPOL = 0x012C, TPM2_CC_NV_WRITE = 0x0137, + TPM2_CC_NV_WRITELOCK = 0x0138, TPM2_CC_DAM_RESET = 0x0139, TPM2_CC_DAM_PARAMETERS = 0x013A, TPM2_CC_NV_READ = 0x014E, @@ -570,4 +571,15 @@ u32 tpm2_pcr_setauthvalue(struct udevice *dev, const char *pw, */ u32 tpm2_get_random(struct udevice *dev, void *data, u32 count); +/** + * Lock data in the TPM + * + * Once locked the data cannot be written until after a reboot + * + * @dev TPM device + * @index Index of data to lock + * @return code of the operation + */ +u32 tpm2_write_lock(struct udevice *dev, u32 index); + #endif /* __TPM_V2_H */ diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c index c0d1f3c5c7e..6bddafcc777 100644 --- a/lib/tpm-v2.c +++ b/lib/tpm-v2.c @@ -596,3 +596,26 @@ u32 tpm2_get_random(struct udevice *dev, void *data, u32 count) return 0; } + +u32 tpm2_write_lock(struct udevice *dev, u32 index) +{ + u8 command_v2[COMMAND_BUFFER_SIZE] = { + /* header 10 bytes */ + tpm_u16(TPM2_ST_SESSIONS), /* TAG */ + tpm_u32(10 + 8 + 13), /* Length */ + tpm_u32(TPM2_CC_NV_WRITELOCK), /* Command code */ + + /* handles 8 bytes */ + tpm_u32(TPM2_RH_PLATFORM), /* Primary platform seed */ + tpm_u32(HR_NV_INDEX + index), /* Password authorisation */ + + /* session header 9 bytes */ + tpm_u32(9), /* Header size */ + tpm_u32(TPM2_RS_PW), /* Password authorisation */ + tpm_u16(0), /* nonce_size */ + 0, /* session_attrs */ + tpm_u16(0), /* auth_size */ + }; + + return tpm_sendrecv_command(dev, command_v2, NULL, NULL); +} diff --git a/lib/tpm_api.c b/lib/tpm_api.c index 687fc8bc7ee..4c662640a92 100644 --- a/lib/tpm_api.c +++ b/lib/tpm_api.c @@ -144,7 +144,7 @@ u32 tpm_write_lock(struct udevice *dev, u32 index) if (is_tpm1(dev)) return -ENOSYS; else if (is_tpm2(dev)) - return -ENOSYS; + return tpm2_write_lock(dev, index); else return -ENOSYS; }