Skip to content

Commit e663b2f

Browse files
committed
tpm: Add 'tpm autostart' shell command
For a TPM device to be operational we need to initialize it and perform its startup sequence. The 'tpm init' command currently calls tpm_init() which ends up calling the ->open() per-device callback and performs the initial hardware configuration as well as requesting locality 0 for the caller. There no code that currently calls tpm_init() without following up with a tpm_startup() and tpm_self_test_full() or tpm_continue_self_test(). So let's add a 'tpm autostart' command and call tpm_auto_start() which leaves the device in an operational state. It's worth noting that calling tpm_init() only, doesn't allow a someone to use the TPM since the startup sequence is mandatory. We always repeat the pattern of calling - tpm_init() - tpm_startup() - tpm_self_test_full() or tpm_continue_self_test() Reviewed-by: Simon Glass <[email protected]> Signed-off-by: Ilias Apalodimas <[email protected]>
1 parent 260d496 commit e663b2f

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

cmd/tpm-common.c

+16
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <asm/unaligned.h>
1212
#include <linux/string.h>
1313
#include <tpm-common.h>
14+
#include <tpm_api.h>
1415
#include "tpm-user-utils.h"
1516

1617
static struct udevice *tpm_dev;
@@ -367,6 +368,21 @@ int do_tpm_init(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
367368
return report_return_code(tpm_init(dev));
368369
}
369370

371+
int do_tpm_autostart(struct cmd_tbl *cmdtp, int flag, int argc,
372+
char *const argv[])
373+
{
374+
struct udevice *dev;
375+
int rc;
376+
377+
if (argc != 1)
378+
return CMD_RET_USAGE;
379+
rc = get_tpm(&dev);
380+
if (rc)
381+
return rc;
382+
383+
return report_return_code(tpm_auto_start(dev));
384+
}
385+
370386
int do_tpm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
371387
{
372388
struct cmd_tbl *tpm_commands, *cmd;

cmd/tpm-user-utils.h

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ int get_tpm(struct udevice **devp);
2020
int do_tpm_device(struct cmd_tbl *cmdtp, int flag, int argc,
2121
char *const argv[]);
2222
int do_tpm_init(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
23+
int do_tpm_autostart(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
2324
int do_tpm_info(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
2425
int do_tpm_report_state(struct cmd_tbl *cmdtp, int flag, int argc,
2526
char *const argv[]);

cmd/tpm-v1.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ TPM_COMMAND_NO_ARG(tpm_physical_disable)
655655
static struct cmd_tbl tpm1_commands[] = {
656656
U_BOOT_CMD_MKENT(device, 0, 1, do_tpm_device, "", ""),
657657
U_BOOT_CMD_MKENT(info, 0, 1, do_tpm_info, "", ""),
658+
U_BOOT_CMD_MKENT(init, 0, 1, do_tpm_autostart, "", ""),
658659
U_BOOT_CMD_MKENT(init, 0, 1, do_tpm_init, "", ""),
659660
U_BOOT_CMD_MKENT(startup, 0, 1,
660661
do_tpm_startup, "", ""),
@@ -733,9 +734,12 @@ U_BOOT_CMD(tpm, CONFIG_SYS_MAXARGS, 1, do_tpm,
733734
" device [num device]\n"
734735
" - Show all devices or set the specified device\n"
735736
" info - Show information about the TPM\n"
737+
" autostart\n"
738+
" - Initalize the tpm, perform a Startup(clear) and run a full selftest\n"
739+
" sequence\n"
736740
" init\n"
737741
" - Put TPM into a state where it waits for 'startup' command.\n"
738-
" startup mode\n"
742+
" startup mode\n"
739743
" - Issue TPM_Starup command. <mode> is one of TPM_ST_CLEAR,\n"
740744
" TPM_ST_STATE, and TPM_ST_DEACTIVATED.\n"
741745
"Admin Testing Commands:\n"

cmd/tpm-v2.c

+6
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ static struct cmd_tbl tpm2_commands[] = {
370370
U_BOOT_CMD_MKENT(dam_reset, 0, 1, do_tpm_dam_reset, "", ""),
371371
U_BOOT_CMD_MKENT(dam_parameters, 0, 1, do_tpm_dam_parameters, "", ""),
372372
U_BOOT_CMD_MKENT(change_auth, 0, 1, do_tpm_change_auth, "", ""),
373+
U_BOOT_CMD_MKENT(autostart, 0, 1, do_tpm_autostart, "", ""),
373374
U_BOOT_CMD_MKENT(pcr_setauthpolicy, 0, 1,
374375
do_tpm_pcr_setauthpolicy, "", ""),
375376
U_BOOT_CMD_MKENT(pcr_setauthvalue, 0, 1,
@@ -392,8 +393,13 @@ U_BOOT_CMD(tpm2, CONFIG_SYS_MAXARGS, 1, do_tpm, "Issue a TPMv2.x command",
392393
" Show information about the TPM.\n"
393394
"state\n"
394395
" Show internal state from the TPM (if available)\n"
396+
"autostart\n"
397+
" Initalize the tpm, perform a Startup(clear) and run a full selftest\n"
398+
" sequence\n"
395399
"init\n"
396400
" Initialize the software stack. Always the first command to issue.\n"
401+
" 'tpm startup' is the only acceptable command after a 'tpm init' has been\n"
402+
" issued\n"
397403
"startup <mode>\n"
398404
" Issue a TPM2_Startup command.\n"
399405
" <mode> is one of:\n"

0 commit comments

Comments
 (0)