1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2018 Bootlin
4 * Author: Miquel Raynal <miquel.raynal@bootlin.com>
10 #include <tpm-common.h>
12 #include "tpm-user-utils.h"
14 static int do_tpm2_startup(cmd_tbl_t *cmdtp, int flag, int argc,
17 enum tpm2_startup_types mode;
22 if (!strcasecmp("TPM2_SU_CLEAR", argv[1])) {
24 } else if (!strcasecmp("TPM2_SU_STATE", argv[1])) {
27 printf("Couldn't recognize mode string: %s\n", argv[1]);
28 return CMD_RET_FAILURE;
31 return report_return_code(tpm2_startup(mode));
34 static int do_tpm2_self_test(cmd_tbl_t *cmdtp, int flag, int argc,
37 enum tpm2_yes_no full_test;
42 if (!strcasecmp("full", argv[1])) {
44 } else if (!strcasecmp("continue", argv[1])) {
47 printf("Couldn't recognize test mode: %s\n", argv[1]);
48 return CMD_RET_FAILURE;
51 return report_return_code(tpm2_self_test(full_test));
54 static cmd_tbl_t tpm2_commands[] = {
55 U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
56 U_BOOT_CMD_MKENT(init, 0, 1, do_tpm_init, "", ""),
57 U_BOOT_CMD_MKENT(startup, 0, 1, do_tpm2_startup, "", ""),
58 U_BOOT_CMD_MKENT(self_test, 0, 1, do_tpm2_self_test, "", ""),
61 cmd_tbl_t *get_tpm_commands(unsigned int *size)
63 *size = ARRAY_SIZE(tpm2_commands);
68 U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm, "Issue a TPMv2.x command",
69 "<command> [<arguments>]\n"
72 " Show information about the TPM.\n"
74 " Initialize the software stack. Always the first command to issue.\n"
76 " Issue a TPM2_Startup command.\n"
77 " <mode> is one of:\n"
78 " * TPM2_SU_CLEAR (reset state)\n"
79 " * TPM2_SU_STATE (preserved state)\n"
81 " Test the TPM capabilities.\n"
82 " <type> is one of:\n"
83 " * full (perform all tests)\n"
84 " * continue (only check untested tests)\n"