blob: 8589daeb0a3c4381a848fd9ca941452f5f4dfb11 [file] [log] [blame]
Miquel Raynalf3b43502018-05-15 11:57:08 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (c) 2018 Bootlin
4 * Author: Miquel Raynal <miquel.raynal@bootlin.com>
5 */
6
7#include <common.h>
8#include <dm.h>
9#include <log.h>
10#include <tpm-common.h>
11#include <tpm-v2.h>
12#include "tpm-user-utils.h"
13
Miquel Raynal65a1a6c2018-05-15 11:57:12 +020014static int do_tpm2_startup(cmd_tbl_t *cmdtp, int flag, int argc,
15 char * const argv[])
16{
17 enum tpm2_startup_types mode;
18
19 if (argc != 2)
20 return CMD_RET_USAGE;
21
22 if (!strcasecmp("TPM2_SU_CLEAR", argv[1])) {
23 mode = TPM2_SU_CLEAR;
24 } else if (!strcasecmp("TPM2_SU_STATE", argv[1])) {
25 mode = TPM2_SU_STATE;
26 } else {
27 printf("Couldn't recognize mode string: %s\n", argv[1]);
28 return CMD_RET_FAILURE;
29 }
30
31 return report_return_code(tpm2_startup(mode));
32}
33
Miquel Raynalf3b43502018-05-15 11:57:08 +020034static cmd_tbl_t tpm2_commands[] = {
35 U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
36 U_BOOT_CMD_MKENT(init, 0, 1, do_tpm_init, "", ""),
Miquel Raynal65a1a6c2018-05-15 11:57:12 +020037 U_BOOT_CMD_MKENT(startup, 0, 1, do_tpm2_startup, "", ""),
Miquel Raynalf3b43502018-05-15 11:57:08 +020038};
39
40cmd_tbl_t *get_tpm_commands(unsigned int *size)
41{
42 *size = ARRAY_SIZE(tpm2_commands);
43
44 return tpm2_commands;
45}
46
47U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm, "Issue a TPMv2.x command",
48"<command> [<arguments>]\n"
49"\n"
50"info\n"
51" Show information about the TPM.\n"
52"init\n"
53" Initialize the software stack. Always the first command to issue.\n"
Miquel Raynal65a1a6c2018-05-15 11:57:12 +020054"startup <mode>\n"
55" Issue a TPM2_Startup command.\n"
56" <mode> is one of:\n"
57" * TPM2_SU_CLEAR (reset state)\n"
58" * TPM2_SU_STATE (preserved state)\n"
Miquel Raynalf3b43502018-05-15 11:57:08 +020059);