nalika / rpms / grub2

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