[SLOF] [PATCH v4 29/33] tpm2: Implement TPM 2 menu with choice to clear the TPM 2

Stefan Berger stefanb at linux.vnet.ibm.com
Thu Dec 12 07:27:24 AEDT 2019


Implement a TPM 2 menu with one item to be able to clear the TPM.

Signed-off-by: Stefan Berger <stefanb at linux.vnet.ibm.com>
---
 board-qemu/slof/vtpm-sml.fs |  9 +++++++++
 lib/libtpm/tcgbios.c        | 35 +++++++++++++++++++++++++++++++++++
 lib/libtpm/tcgbios.h        |  1 +
 lib/libtpm/tpm.code         |  9 +++++++++
 lib/libtpm/tpm.in           |  1 +
 5 files changed, 55 insertions(+)

diff --git a/board-qemu/slof/vtpm-sml.fs b/board-qemu/slof/vtpm-sml.fs
index 25918b8..1e0c41a 100644
--- a/board-qemu/slof/vtpm-sml.fs
+++ b/board-qemu/slof/vtpm-sml.fs
@@ -363,11 +363,20 @@ log-base LOG-SIZE tpm-set-log-parameters
     THEN
 ;
 
+: vtpm20-menu
+    tpm-is-working IF
+        tpm20-menu
+    THEN
+;
+
 : vtpm-menu
     tpm-get-tpm-version CASE
     1 OF
         vtpm12-menu
       ENDOF
+    2 OF
+        vtpm20-menu
+      ENDOF
     ENDCASE
 ;
 
diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c
index ea00c9f..c28385e 100644
--- a/lib/libtpm/tcgbios.c
+++ b/lib/libtpm/tcgbios.c
@@ -1547,3 +1547,38 @@ uint32_t tpm_get_tpm_version(void)
 {
 	return TPM_version;
 }
+
+void tpm20_menu(void)
+{
+	int key_code;
+	int waitkey;
+	tpm_ppi_op msgCode;
+
+	for (;;) {
+		printf("1. Clear TPM\n");
+
+		printf("\nIf not change is desired or if this menu was reached by "
+		       "mistake, press ESC to\ncontinue the boot.\n");
+
+		msgCode = TPM_PPI_OP_NOOP;
+
+		waitkey = 1;
+
+		while (waitkey) {
+			key_code = SLOF_get_keystroke();
+			switch (key_code) {
+			case 27:
+				// ESC
+				return;
+			case '1':
+				msgCode = TPM_PPI_OP_CLEAR;
+				break;
+			default:
+				continue;
+			}
+
+			tpm20_process_cfg(msgCode, 0);
+			waitkey = 0;
+		}
+	}
+}
diff --git a/lib/libtpm/tcgbios.h b/lib/libtpm/tcgbios.h
index 398834a..35631e0 100644
--- a/lib/libtpm/tcgbios.h
+++ b/lib/libtpm/tcgbios.h
@@ -40,6 +40,7 @@ uint32_t tpm_driver_get_state(void);
 uint32_t tpm_driver_get_failure_reason(void);
 void tpm_driver_set_failure_reason(uint32_t errcode);
 uint32_t tpm_get_tpm_version(void);
+void tpm20_menu(void);
 
 /* flags returned by tpm_get_state */
 #define TPM_STATE_ENABLED        1
diff --git a/lib/libtpm/tpm.code b/lib/libtpm/tpm.code
index c63b21c..2e8edad 100644
--- a/lib/libtpm/tpm.code
+++ b/lib/libtpm/tpm.code
@@ -223,3 +223,12 @@ PRIM(tpm_X2d_get_X2d_tpm_X2d_version)
 	PUSH;
 	TOS.n = tpm_get_tpm_version();
 MIRP
+
+/*******************************************************************/
+/* Firmware API                                                    */
+/* SLOF:   tpm20-menu ( -- tpm-version )                           */
+/* LIBTPM: tpm20_menu()                                            */
+/*******************************************************************/
+PRIM(tpm20_X2d_menu)
+	tpm20_menu();
+MIRP
diff --git a/lib/libtpm/tpm.in b/lib/libtpm/tpm.in
index 1261ac8..cac261f 100644
--- a/lib/libtpm/tpm.in
+++ b/lib/libtpm/tpm.in
@@ -33,3 +33,4 @@ cod(tpm-driver-get-state)
 cod(tpm-driver-get-failure-reason)
 cod(tpm-driver-set-failure-reason)
 cod(tpm-get-tpm-version)
+cod(tpm20-menu)
-- 
2.17.1



More information about the SLOF mailing list