[U-Boot] [PATCH v2 10/19] tpm: add TPM2_SelfTest command support
Miquel Raynal
miquel.raynal at bootlin.com
Thu Mar 29 07:43:52 UTC 2018
Add support for the TPM2_Selftest command.
Change the command file and the help accordingly.
Signed-off-by: Miquel Raynal <miquel.raynal at bootlin.com>
---
include/tpm.h | 9 +++++++--
lib/tpm.c | 36 ++++++++++++++++++++++++++++--------
2 files changed, 35 insertions(+), 10 deletions(-)
diff --git a/include/tpm.h b/include/tpm.h
index ba71bac885..38d7cb899d 100644
--- a/include/tpm.h
+++ b/include/tpm.h
@@ -31,6 +31,11 @@ enum tpm2_structures {
TPM2_ST_SESSIONS = 0x8002,
};
+enum tpm2_yes_no {
+ TPMI_YES = 1,
+ TPMI_NO = 0,
+};
+
enum tpm_startup_type {
TPM_ST_CLEAR = 0x0001,
TPM_ST_STATE = 0x0002,
@@ -476,14 +481,14 @@ int tpm_startup(enum tpm_startup_type mode);
*
* @return return code of the operation
*/
-uint32_t tpm_self_test_full(void);
+int tpm_self_test_full(void);
/**
* Issue a TPM_ContinueSelfTest command.
*
* @return return code of the operation
*/
-uint32_t tpm_continue_self_test(void);
+int tpm_continue_self_test(void);
/**
* Issue a TPM_NV_DefineSpace command. The implementation is limited
diff --git a/lib/tpm.c b/lib/tpm.c
index 0c57ef8dc7..3cc2888267 100644
--- a/lib/tpm.c
+++ b/lib/tpm.c
@@ -341,20 +341,40 @@ int tpm_startup(enum tpm_startup_type mode)
return 0;
}
-uint32_t tpm_self_test_full(void)
+int tpm_self_test_full(void)
{
- const uint8_t command[10] = {
- 0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x50,
+ const u8 command_v1[10] = {
+ U16_TO_ARRAY(0xc1),
+ U32_TO_ARRAY(10),
+ U32_TO_ARRAY(0x50),
};
- return tpm_sendrecv_command(command, NULL, NULL);
+ const u8 command_v2[12] = {
+ U16_TO_ARRAY(TPM2_ST_NO_SESSIONS),
+ U32_TO_ARRAY(11),
+ U32_TO_ARRAY(TPM2_CC_SELF_TEST),
+ TPMI_YES,
+ };
+
+ return tpm_sendrecv_command(is_tpmv2 ? command_v2 : command_v1, NULL,
+ NULL);
}
-uint32_t tpm_continue_self_test(void)
+int tpm_continue_self_test(void)
{
- const uint8_t command[10] = {
- 0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x53,
+ const u8 command_v1[10] = {
+ U16_TO_ARRAY(0xc1),
+ U32_TO_ARRAY(10),
+ U32_TO_ARRAY(0x53),
};
- return tpm_sendrecv_command(command, NULL, NULL);
+ const u8 command_v2[12] = {
+ U16_TO_ARRAY(TPM2_ST_NO_SESSIONS),
+ U32_TO_ARRAY(11),
+ U32_TO_ARRAY(TPM2_CC_SELF_TEST),
+ TPMI_NO,
+ };
+
+ return tpm_sendrecv_command(is_tpmv2 ? command_v2 : command_v1, NULL,
+ NULL);
}
uint32_t tpm_nv_define_space(uint32_t index, uint32_t perm, uint32_t size)
--
2.14.1
More information about the U-Boot
mailing list