Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/htool.c
Original file line number Diff line number Diff line change
Expand Up @@ -2067,6 +2067,12 @@ static const struct htool_cmd CMDS[] = {
.params = (const struct htool_param[]){{}},
.func = htool_get_tpm_mode,
},
{
.verbs = (const char*[]){"tpm", "startup", NULL},
.desc = "Send TPM2_Startup(CLEAR) command to initialize the TPM.",
.params = (const struct htool_param[]){{}},
.func = htool_tpm_startup,
},
{
.verbs = (const char*[]){"tpm", "set_mode", "disabled", NULL},
.desc = "Set the TPM mode to DISABLED.",
Expand Down
28 changes: 28 additions & 0 deletions examples/htool_tpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,31 @@ int htool_get_tpm_mode(const struct htool_invocation* inv) {

return 0;
}

int htool_tpm_startup(const struct htool_invocation* inv) {
struct libhoth_device* dev = htool_libhoth_device();
if (!dev) {
return -1;
}

// Standard 12-byte TPM2_Startup(CLEAR) command packet
static const uint8_t req[12] = {
0x80, 0x01, // TPM_ST_NO_SESSIONS
0x00, 0x00, 0x00, 0x0c, // paramSize = 12
0x00, 0x00, 0x01, 0x44, // TPM_CC_Startup
0x00, 0x00 // TPM_SU_CLEAR
};

uint8_t resp[32];
size_t resp_size = 0;
int ret = libhoth_hostcmd_exec(
dev, HOTH_CMD_BOARD_SPECIFIC_BASE + HOTH_PRV_CMD_HAVEN_TPM, 0, req,
sizeof(req), resp, sizeof(resp), &resp_size);
if (ret) {
htool_report_error("tpm startup", ret);
return ret;
}

printf("TPM2_Startup(CLEAR) sent successfully.\n");
return 0;
}
2 changes: 2 additions & 0 deletions examples/htool_tpm.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ extern "C" {

#define HOTH_PRV_CMD_SET_TPM_MODE 0x0051
#define HOTH_PRV_CMD_GET_TPM_MODE 0x0052
#define HOTH_PRV_CMD_HAVEN_TPM 0x0033

enum ec_tpm_mode {
TPM_MODE_DISABLED = 0, // Turn the TPM off: typically used to turn off one
Expand All @@ -38,6 +39,7 @@ struct tpm_mode {

int htool_set_tpm_mode(const struct htool_invocation* inv);
int htool_get_tpm_mode(const struct htool_invocation* inv);
int htool_tpm_startup(const struct htool_invocation* inv);

#ifdef __cplusplus
}
Expand Down