1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2018 Bootlin
4 * Author: Miquel Raynal <miquel.raynal@bootlin.com>
9 #include <tpm-common.h>
11 #include "tpm-utils.h"
13 u32 tpm2_startup(enum tpm2_startup_types mode)
15 const u8 command_v2[12] = {
16 tpm_u16(TPM2_ST_NO_SESSIONS),
18 tpm_u32(TPM2_CC_STARTUP),
24 * Note TPM2_Startup command will return RC_SUCCESS the first time,
25 * but will return RC_INITIALIZE otherwise.
27 ret = tpm_sendrecv_command(command_v2, NULL, NULL);
28 if (ret && ret != TPM2_RC_INITIALIZE)
34 u32 tpm2_self_test(enum tpm2_yes_no full_test)
36 const u8 command_v2[12] = {
37 tpm_u16(TPM2_ST_NO_SESSIONS),
39 tpm_u32(TPM2_CC_SELF_TEST),
43 return tpm_sendrecv_command(command_v2, NULL, NULL);
46 u32 tpm2_clear(u32 handle, const char *pw, const ssize_t pw_sz)
48 u8 command_v2[COMMAND_BUFFER_SIZE] = {
49 tpm_u16(TPM2_ST_SESSIONS), /* TAG */
50 tpm_u32(27 + pw_sz), /* Length */
51 tpm_u32(TPM2_CC_CLEAR), /* Command code */
54 tpm_u32(handle), /* TPM resource handle */
57 tpm_u32(9 + pw_sz), /* Authorization size */
58 tpm_u32(TPM2_RS_PW), /* Session handle */
59 tpm_u16(0), /* Size of <nonce> */
60 /* <nonce> (if any) */
61 0, /* Attributes: Cont/Excl/Rst */
62 tpm_u16(pw_sz), /* Size of <hmac/password> */
63 /* STRING(pw) <hmac/password> (if any) */
65 unsigned int offset = 27;
69 * Fill the command structure starting from the first buffer:
70 * - the password (if any)
72 ret = pack_byte_string(command_v2, sizeof(command_v2), "s",
78 return tpm_sendrecv_command(command_v2, NULL, NULL);