From patchwork Thu Mar 29 07:43:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 892609 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=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bootlin.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40BcR847b9z9ry1 for ; Thu, 29 Mar 2018 18:52:20 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 41361C2200D; Thu, 29 Mar 2018 07:47:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 12048C21F8A; Thu, 29 Mar 2018 07:44:54 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6FD1BC21FFA; Thu, 29 Mar 2018 07:44:31 +0000 (UTC) Received: from mail.bootlin.com (mail.bootlin.com [62.4.15.54]) by lists.denx.de (Postfix) with ESMTP id D5339C22006 for ; Thu, 29 Mar 2018 07:44:24 +0000 (UTC) Received: by mail.bootlin.com (Postfix, from userid 110) id A78C520721; Thu, 29 Mar 2018 09:44:24 +0200 (CEST) Received: from localhost.localdomain (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.bootlin.com (Postfix) with ESMTPSA id 7ED27208A8; Thu, 29 Mar 2018 09:44:05 +0200 (CEST) From: Miquel Raynal To: Tom Rini , Simon Glass Date: Thu, 29 Mar 2018 09:43:52 +0200 Message-Id: <20180329074401.8691-11-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180329074401.8691-1-miquel.raynal@bootlin.com> References: <20180329074401.8691-1-miquel.raynal@bootlin.com> Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 10/19] tpm: add TPM2_SelfTest command support X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add support for the TPM2_Selftest command. Change the command file and the help accordingly. Signed-off-by: Miquel Raynal --- include/tpm.h | 9 +++++++-- lib/tpm.c | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/include/tpm.h b/include/tpm.h index ba71bac885..38d7cb899d 100644 --- a/include/tpm.h +++ b/include/tpm.h @@ -31,6 +31,11 @@ enum tpm2_structures { TPM2_ST_SESSIONS = 0x8002, }; +enum tpm2_yes_no { + TPMI_YES = 1, + TPMI_NO = 0, +}; + enum tpm_startup_type { TPM_ST_CLEAR = 0x0001, TPM_ST_STATE = 0x0002, @@ -476,14 +481,14 @@ int tpm_startup(enum tpm_startup_type mode); * * @return return code of the operation */ -uint32_t tpm_self_test_full(void); +int tpm_self_test_full(void); /** * Issue a TPM_ContinueSelfTest command. * * @return return code of the operation */ -uint32_t tpm_continue_self_test(void); +int tpm_continue_self_test(void); /** * Issue a TPM_NV_DefineSpace command. The implementation is limited diff --git a/lib/tpm.c b/lib/tpm.c index 0c57ef8dc7..3cc2888267 100644 --- a/lib/tpm.c +++ b/lib/tpm.c @@ -341,20 +341,40 @@ int tpm_startup(enum tpm_startup_type mode) return 0; } -uint32_t tpm_self_test_full(void) +int tpm_self_test_full(void) { - const uint8_t command[10] = { - 0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x50, + const u8 command_v1[10] = { + U16_TO_ARRAY(0xc1), + U32_TO_ARRAY(10), + U32_TO_ARRAY(0x50), }; - return tpm_sendrecv_command(command, NULL, NULL); + const u8 command_v2[12] = { + U16_TO_ARRAY(TPM2_ST_NO_SESSIONS), + U32_TO_ARRAY(11), + U32_TO_ARRAY(TPM2_CC_SELF_TEST), + TPMI_YES, + }; + + return tpm_sendrecv_command(is_tpmv2 ? command_v2 : command_v1, NULL, + NULL); } -uint32_t tpm_continue_self_test(void) +int tpm_continue_self_test(void) { - const uint8_t command[10] = { - 0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x53, + const u8 command_v1[10] = { + U16_TO_ARRAY(0xc1), + U32_TO_ARRAY(10), + U32_TO_ARRAY(0x53), }; - return tpm_sendrecv_command(command, NULL, NULL); + const u8 command_v2[12] = { + U16_TO_ARRAY(TPM2_ST_NO_SESSIONS), + U32_TO_ARRAY(11), + U32_TO_ARRAY(TPM2_CC_SELF_TEST), + TPMI_NO, + }; + + return tpm_sendrecv_command(is_tpmv2 ? command_v2 : command_v1, NULL, + NULL); } uint32_t tpm_nv_define_space(uint32_t index, uint32_t perm, uint32_t size)