Blame SOURCES/0502-ibmvtpm-Backport-ibmvtpm-support-to-grub-2.02.patch

b9d01e
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
b9d01e
From: Stefan Berger <stefanb@linux.vnet.ibm.com>
b9d01e
Date: Fri, 11 Feb 2022 16:34:23 -0500
b9d01e
Subject: [PATCH] ibmvtpm: Backport ibmvtpm support to grub 2.02
b9d01e
b9d01e
Backport ibmvtpm support to grub 2.02 by making as few changes to the
b9d01e
source as possible and building it into the core.
b9d01e
b9d01e
Since ibmvtpm support is built into grub 2.02 do not print the error
b9d01e
message we would typically print if it was a module and the user had
b9d01e
a choice to not use vTPM support if there was no vTPM by avoiding
b9d01e
to use the module.
b9d01e
b9d01e
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
b9d01e
---
b9d01e
 grub-core/Makefile.core.def           |  8 +-------
b9d01e
 grub-core/commands/ieee1275/ibmvtpm.c | 13 ++++++++++---
b9d01e
 include/grub/tpm.h                    |  2 +-
b9d01e
 3 files changed, 12 insertions(+), 11 deletions(-)
b9d01e
b9d01e
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
b9d01e
index b11f74e6b2..637d7203e3 100644
b9d01e
--- a/grub-core/Makefile.core.def
b9d01e
+++ b/grub-core/Makefile.core.def
b9d01e
@@ -298,6 +298,7 @@ kernel = {
b9d01e
   powerpc_ieee1275 = kern/powerpc/cache.S;
b9d01e
   powerpc_ieee1275 = kern/powerpc/dl.c;
b9d01e
   powerpc_ieee1275 = kern/powerpc/compiler-rt.S;
b9d01e
+  powerpc_ieee1275 = commands/ieee1275/ibmvtpm.c;
b9d01e
 
b9d01e
   sparc64_ieee1275 = kern/sparc64/cache.S;
b9d01e
   sparc64_ieee1275 = kern/sparc64/dl.c;
b9d01e
@@ -1104,13 +1105,6 @@ module = {
b9d01e
   enable = powerpc_ieee1275;
b9d01e
 };
b9d01e
 
b9d01e
-module = {
b9d01e
-  name = tpm;
b9d01e
-  common = commands/tpm.c;
b9d01e
-  ieee1275 = commands/ieee1275/ibmvtpm.c;
b9d01e
-  enable = powerpc_ieee1275;
b9d01e
-};
b9d01e
-
b9d01e
 module = {
b9d01e
   name = terminal;
b9d01e
   common = commands/terminal.c;
b9d01e
diff --git a/grub-core/commands/ieee1275/ibmvtpm.c b/grub-core/commands/ieee1275/ibmvtpm.c
b9d01e
index e68b8448bc..728b2cbdcd 100644
b9d01e
--- a/grub-core/commands/ieee1275/ibmvtpm.c
b9d01e
+++ b/grub-core/commands/ieee1275/ibmvtpm.c
b9d01e
@@ -115,7 +115,8 @@ tpm2_log_event (unsigned char *buf,
b9d01e
 		grub_size_t size, grub_uint8_t pcr,
b9d01e
 		const char *description)
b9d01e
 {
b9d01e
-  static int error_displayed = 0;
b9d01e
+  /* Do not print error since vTPM support is built-in */
b9d01e
+  static int error_displayed = 1;
b9d01e
   int err;
b9d01e
 
b9d01e
   err = ibmvtpm_2hash_ext_log (pcr, EV_IPL,
b9d01e
@@ -132,8 +133,8 @@ tpm2_log_event (unsigned char *buf,
b9d01e
   return GRUB_ERR_NONE;
b9d01e
 }
b9d01e
 
b9d01e
-grub_err_t
b9d01e
-grub_tpm_measure (unsigned char *buf, grub_size_t size, grub_uint8_t pcr,
b9d01e
+static grub_err_t
b9d01e
+_grub_tpm_measure (unsigned char *buf, grub_size_t size, grub_uint8_t pcr,
b9d01e
 		  const char *description)
b9d01e
 {
b9d01e
   grub_err_t err = tpm_init();
b9d01e
@@ -150,3 +151,9 @@ grub_tpm_measure (unsigned char *buf, grub_size_t size, grub_uint8_t pcr,
b9d01e
 
b9d01e
   return GRUB_ERR_NONE;
b9d01e
 }
b9d01e
+
b9d01e
+grub_err_t grub_tpm_log_event(unsigned char *buf, grub_size_t size,
b9d01e
+			      grub_uint8_t pcr, const char *description)
b9d01e
+{
b9d01e
+   return _grub_tpm_measure(buf, size, pcr, description);
b9d01e
+}
b9d01e
diff --git a/include/grub/tpm.h b/include/grub/tpm.h
b9d01e
index ce52be4ff7..52af2b8448 100644
b9d01e
--- a/include/grub/tpm.h
b9d01e
+++ b/include/grub/tpm.h
b9d01e
@@ -69,7 +69,7 @@ typedef struct {
b9d01e
 grub_err_t EXPORT_FUNC(grub_tpm_measure) (unsigned char *buf, grub_size_t size,
b9d01e
 					  grub_uint8_t pcr, const char *kind,
b9d01e
 					  const char *description);
b9d01e
-#if defined (GRUB_MACHINE_EFI)
b9d01e
+#if defined (GRUB_MACHINE_EFI) || defined (GRUB_MACHINE_IEEE1275)
b9d01e
 grub_err_t grub_tpm_execute(PassThroughToTPM_InputParamBlock *inbuf,
b9d01e
 			    PassThroughToTPM_OutputParamBlock *outbuf);
b9d01e
 grub_err_t grub_tpm_log_event(unsigned char *buf, grub_size_t size,