Date   

[PATCH v3 3/8] SecurityPkg: Store physical presence code by submitting to PreOS func

Stefan Berger
 

Modify SavePpRequest to look like its TPM 2 equivalent SaveTcg2PpRequest
and have it submit the physical presence opcode to the PreOS function so
that we can choose our own method for how to store it.

Move the existing code into DxeTcgPhysicalPresenceLib.c and adapt the
return codes.

Cc: Jiewen Yao <jiewen.yao@...>
Cc: Jian J Wang <jian.j.wang@...>
Cc: Marc-André Lureau <marcandre.lureau@...>
Signed-off-by: Stefan Berger <stefanb@...>
---
.../DxeTcgPhysicalPresenceLib.c | 55 +++++++++++++++++++
SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c | 41 +++++---------
2 files changed, 70 insertions(+), 26 deletions(-)

diff --git a/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c b/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c
index ba1abe9e08..aa0031dd77 100644
--- a/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c
+++ b/SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c
@@ -1398,3 +1398,58 @@ TcgPhysicalPresenceLibNeedUserConfirm(
return FALSE;
}

+/**
+ The handler for TPM physical presence function:
+ Submit TPM Operation Request to Pre-OS Environment and
+ Submit TPM Operation Request to Pre-OS Environment 2.
+
+ Caution: This function may receive untrusted input.
+
+ @param[in] OperationRequest TPM physical presence operation request.
+
+ @return Return Code for Submit TPM Operation Request to Pre-OS Environment and
+ Submit TPM Operation Request to Pre-OS Environment 2.
+**/
+UINT32
+EFIAPI
+TcgPhysicalPresenceLibSubmitRequestToPreOSFunction (
+ IN UINT32 OperationRequest
+ )
+{
+ EFI_STATUS Status;
+ UINTN DataSize;
+ EFI_PHYSICAL_PRESENCE PpData;
+
+ DEBUG ((DEBUG_INFO, "[TPM] SubmitRequestToPreOSFunction, Request = %x\n", OperationRequest));
+
+ //
+ // Get the Physical Presence variable
+ //
+ DataSize = sizeof (EFI_PHYSICAL_PRESENCE);
+ Status = gRT->GetVariable (
+ PHYSICAL_PRESENCE_VARIABLE,
+ &gEfiPhysicalPresenceGuid,
+ NULL,
+ &DataSize,
+ &PpData
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "[TPM] Get PP variable failure! Status = %r\n", Status));
+ return TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE;
+ }
+
+ PpData.PPRequest = (UINT8)OperationRequest;
+ Status = gRT->SetVariable (
+ PHYSICAL_PRESENCE_VARIABLE,
+ &gEfiPhysicalPresenceGuid,
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
+ DataSize,
+ &PpData
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "[TPM] Set PP variable failure! Status = %r\n", Status));
+ return TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE;
+ }
+
+ return TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS;
+}
diff --git a/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c b/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c
index 68cd62307c..61c072d1a3 100644
--- a/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c
+++ b/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c
@@ -8,6 +8,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent

#include "TcgConfigImpl.h"

+#include <IndustryStandard/TcgPhysicalPresence.h>
+#include <Library/TcgPhysicalPresenceLib.h>
+
CHAR16 mTcgStorageName[] = L"TCG_CONFIGURATION";

TCG_CONFIG_PRIVATE_DATA mTcgConfigPrivateDateTemplate = {
@@ -299,37 +302,23 @@ SavePpRequest (
)
{
EFI_STATUS Status;
- UINTN DataSize;
- EFI_PHYSICAL_PRESENCE PpData;
+ UINT32 ReturnCode;

//
- // Save TPM command to variable.
+ // Submit TPM command to PreOS fuction
//
- DataSize = sizeof (EFI_PHYSICAL_PRESENCE);
- Status = gRT->GetVariable (
- PHYSICAL_PRESENCE_VARIABLE,
- &gEfiPhysicalPresenceGuid,
- NULL,
- &DataSize,
- &PpData
- );
- if (EFI_ERROR (Status)) {
- return Status;
- }
-
- PpData.PPRequest = PpRequest;
- Status = gRT->SetVariable (
- PHYSICAL_PRESENCE_VARIABLE,
- &gEfiPhysicalPresenceGuid,
- EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
- DataSize,
- &PpData
- );
- if (EFI_ERROR(Status)) {
- return Status;
+ ReturnCode = TcgPhysicalPresenceLibSubmitRequestToPreOSFunction (PpRequest);
+ if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS) {
+ Status = EFI_SUCCESS;
+ } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE) {
+ Status = EFI_OUT_OF_RESOURCES;
+ } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED) {
+ Status = EFI_UNSUPPORTED;
+ } else {
+ Status = EFI_DEVICE_ERROR;
}

- return EFI_SUCCESS;
+ return Status;
}

/**
--
2.31.1


[PATCH v3 2/8] OvmfPkg: Check for TPM 2 early to leave function early

Stefan Berger
 

TPM 1.2 and TPM 2 share QEMU's PPI memory/device and for the TPM 2 code
not to initilize over the TPM 1.2 initilization, leave the init function
early without touching that memory.

Cc: Gerd Hoffmann <kraxel@...>
Cc: Marc-André Lureau <marcandre.lureau@...>
Signed-off-by: Stefan Berger <stefanb@...>
---
.../DxeTcg2PhysicalPresenceLib.c | 36 ++++++++++---------
1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c b/OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c
index 33a470f6d8..f46a047235 100644
--- a/OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c
+++ b/OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.c
@@ -94,7 +94,6 @@ QemuTpmInitPPI (
QEMU_FWCFG_TPM_CONFIG Config;
EFI_PHYSICAL_ADDRESS PpiAddress64;
EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
- UINTN Idx;

if (mPpi != NULL) {
return EFI_SUCCESS;
@@ -105,6 +104,11 @@ QemuTpmInitPPI (
return Status;
}

+ if (Config.TpmVersion != QEMU_TPM_VERSION_2) {
+ DEBUG ((DEBUG_ERROR, "[TPM2PP] Not setting up PPI. This is not a TPM 2.\n"));
+ return EFI_PROTOCOL_ERROR;
+ }
+
mPpi = (QEMU_TPM_PPI *)(UINTN)Config.PpiAddress;
if (mPpi == NULL) {
return EFI_PROTOCOL_ERROR;
@@ -131,21 +135,18 @@ QemuTpmInitPPI (
goto InvalidPpiAddress;
}

- for (Idx = 0; Idx < ARRAY_SIZE (mPpi->Func); Idx++) {
- mPpi->Func[Idx] = 0;
- }
- if (Config.TpmVersion == QEMU_TPM_VERSION_2) {
- mPpi->Func[TCG2_PHYSICAL_PRESENCE_NO_ACTION] = TPM_PPI_FLAGS;
- mPpi->Func[TCG2_PHYSICAL_PRESENCE_CLEAR] = TPM_PPI_FLAGS;
- mPpi->Func[TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR] = TPM_PPI_FLAGS;
- mPpi->Func[TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR_2] = TPM_PPI_FLAGS;
- mPpi->Func[TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR_3] = TPM_PPI_FLAGS;
- mPpi->Func[TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS] = TPM_PPI_FLAGS;
- mPpi->Func[TCG2_PHYSICAL_PRESENCE_CHANGE_EPS] = TPM_PPI_FLAGS;
- mPpi->Func[TCG2_PHYSICAL_PRESENCE_LOG_ALL_DIGESTS] = TPM_PPI_FLAGS;
- mPpi->Func[TCG2_PHYSICAL_PRESENCE_ENABLE_BLOCK_SID] = TPM_PPI_FLAGS;
- mPpi->Func[TCG2_PHYSICAL_PRESENCE_DISABLE_BLOCK_SID] = TPM_PPI_FLAGS;
- }
+ ZeroMem ((void *)mPpi->Func, sizeof(mPpi->Func));
+
+ mPpi->Func[TCG2_PHYSICAL_PRESENCE_NO_ACTION] = TPM_PPI_FLAGS;
+ mPpi->Func[TCG2_PHYSICAL_PRESENCE_CLEAR] = TPM_PPI_FLAGS;
+ mPpi->Func[TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR] = TPM_PPI_FLAGS;
+ mPpi->Func[TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR_2] = TPM_PPI_FLAGS;
+ mPpi->Func[TCG2_PHYSICAL_PRESENCE_ENABLE_CLEAR_3] = TPM_PPI_FLAGS;
+ mPpi->Func[TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS] = TPM_PPI_FLAGS;
+ mPpi->Func[TCG2_PHYSICAL_PRESENCE_CHANGE_EPS] = TPM_PPI_FLAGS;
+ mPpi->Func[TCG2_PHYSICAL_PRESENCE_LOG_ALL_DIGESTS] = TPM_PPI_FLAGS;
+ mPpi->Func[TCG2_PHYSICAL_PRESENCE_ENABLE_BLOCK_SID] = TPM_PPI_FLAGS;
+ mPpi->Func[TCG2_PHYSICAL_PRESENCE_DISABLE_BLOCK_SID] = TPM_PPI_FLAGS;

if (mPpi->In == 0) {
mPpi->In = 1;
@@ -833,10 +834,11 @@ Tcg2PhysicalPresenceLibProcessRequest (

Status = QemuTpmInitPPI ();
if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_INFO, "[TPM2PP] no PPI\n"));
return ;
}

+ DEBUG ((DEBUG_INFO, "[TPM2PP] Detected a TPM 2\n"));
+
//
// Check S4 resume
//
--
2.31.1


[PATCH v3 4/8] SecurityPkg: Declare PhysicalPresenceFlags variable and its properties

Stefan Berger
 

Declare the TPM 1.2 PhysicalPresenceFlags variable and its properties.

The effect of its properties is that once PhysicalPresenceFlags is
defined it cannot be deleted from Linux:

cd /sys/firmware/efi/efivars
chattr -i PhysicalPresenceFlags-*
rm -f PhysicalPresenceFlags-*

It will still be there:

ls PhysicalPresenceFlags-*

Signed-off-by: Stefan Berger <stefanb@...>
---
.../Library/AuthVariableLib/AuthServiceInternal.h | 1 +
SecurityPkg/Library/AuthVariableLib/AuthVariableLib.c | 11 +++++++++++
.../Library/AuthVariableLib/AuthVariableLib.inf | 4 ++++
3 files changed, 16 insertions(+)

diff --git a/SecurityPkg/Library/AuthVariableLib/AuthServiceInternal.h b/Se=
curityPkg/Library/AuthVariableLib/AuthServiceInternal.h
index 2bec637f75..fc2abdb96c 100644
--- a/SecurityPkg/Library/AuthVariableLib/AuthServiceInternal.h
+++ b/SecurityPkg/Library/AuthVariableLib/AuthServiceInternal.h
@@ -30,6 +30,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
=0D
#include <Guid/AuthenticatedVariableFormat.h>=0D
#include <Guid/ImageAuthentication.h>=0D
+#include <Guid/PhysicalPresenceData.h>=0D
=0D
#define TWO_BYTE_ENCODE 0x82=0D
=0D
diff --git a/SecurityPkg/Library/AuthVariableLib/AuthVariableLib.c b/Securi=
tyPkg/Library/AuthVariableLib/AuthVariableLib.c
index 122b3b0bf4..ae75f32d40 100644
--- a/SecurityPkg/Library/AuthVariableLib/AuthVariableLib.c
+++ b/SecurityPkg/Library/AuthVariableLib/AuthVariableLib.c
@@ -89,6 +89,17 @@ VARIABLE_ENTRY_PROPERTY mAuthVarEntry[] =3D {
MAX_UINTN=0D
}=0D
},=0D
+ {=0D
+ &gEfiPhysicalPresenceGuid,=0D
+ PHYSICAL_PRESENCE_FLAGS_VARIABLE,=0D
+ {=0D
+ VAR_CHECK_VARIABLE_PROPERTY_REVISION,=0D
+ VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY,=0D
+ VARIABLE_ATTRIBUTE_NV_BS,=0D
+ sizeof (EFI_PHYSICAL_PRESENCE_FLAGS),=0D
+ MAX_UINTN=0D
+ }=0D
+ }=0D
};=0D
=0D
VOID **mAuthVarAddressPointer[9];=0D
diff --git a/SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf b/Secu=
rityPkg/Library/AuthVariableLib/AuthVariableLib.inf
index 8eadeebceb..d0ced0792c 100644
--- a/SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf
+++ b/SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf
@@ -75,6 +75,10 @@
## PRODUCES ## Variable:L"certdbv"=0D
gEfiCertDbGuid=0D
=0D
+ ## CONSUMES ## Variable:L"PhysicalPresenceFlags"=0D
+ ## PRODUCES ## Variable:L"PhysicalPresenceFlags"=0D
+ gEfiPhysicalPresenceGuid=0D
+=0D
## CONSUMES ## Variable:L"VendorKeysNv"=0D
## PRODUCES ## Variable:L"VendorKeysNv"=0D
gEfiVendorKeysNvGuid=0D
--=20
2.31.1


[PATCH v3 7/8] OvmfPkg: Enable TPM 1.2 Physical Presence Opcode processing

Stefan Berger
 

Enable the processing of the TPM 1.2 physical presence opcodes.
This needs to be done before End-of-Dxe since otherwise the
creation of the variables doesn't work.

Signed-off-by: Stefan Berger <stefanb@...>
---
OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c | 2 ++
OvmfPkg/Library/PlatformBootManagerLibBhyve/BdsPlatform.c | 2 ++
OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c | 2 ++
3 files changed, 6 insertions(+)

diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c b/OvmfPkg=
/Library/PlatformBootManagerLib/BdsPlatform.c
index 1765026de2..9c96c0cf69 100644
--- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
+++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
@@ -379,7 +379,9 @@ PlatformBootManagerBeforeConsole (
=0D
//=0D
// Process TPM PPI request; this may require keyboard input=0D
+ // For variable creation and locking to work, this has to be done before=
End-of-Dxe.=0D
//=0D
+ TcgPhysicalPresenceLibProcessRequest ();=0D
Tcg2PhysicalPresenceLibProcessRequest (NULL);=0D
=0D
//=0D
diff --git a/OvmfPkg/Library/PlatformBootManagerLibBhyve/BdsPlatform.c b/Ov=
mfPkg/Library/PlatformBootManagerLibBhyve/BdsPlatform.c
index 950ab12c94..e9b4831bef 100644
--- a/OvmfPkg/Library/PlatformBootManagerLibBhyve/BdsPlatform.c
+++ b/OvmfPkg/Library/PlatformBootManagerLibBhyve/BdsPlatform.c
@@ -372,7 +372,9 @@ PlatformBootManagerBeforeConsole (
=0D
//=0D
// Process TPM PPI request=0D
+ // For variable creation and locking to work, this has to be done before=
End-of-Dxe.=0D
//=0D
+ TcgPhysicalPresenceLibProcessRequest ();=0D
Tcg2PhysicalPresenceLibProcessRequest (NULL);=0D
=0D
//=0D
diff --git a/OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c b/Ovm=
fPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c
index fbc40dcb68..a6a9374505 100644
--- a/OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c
+++ b/OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c
@@ -335,7 +335,9 @@ PlatformBootManagerBeforeConsole (
=0D
//=0D
// Process TPM PPI request=0D
+ // For variable creation and locking to work, this has to be done before=
End-of-Dxe.=0D
//=0D
+ TcgPhysicalPresenceLibProcessRequest ();=0D
Tcg2PhysicalPresenceLibProcessRequest (NULL);=0D
=0D
//=0D
--=20
2.31.1


[PATCH v3 8/8] OvmfPkg: add TPM 1.2 config menu

Stefan Berger
 

From: Gerd Hoffmann <kraxel@...>

When building OVMF with TPM 1.2 support enabled also include the
configuration menu.

Suggested-by: Stefan Berger <stefanb@...>
Signed-off-by: Gerd Hoffmann <kraxel@...>
Signed-off-by: Stefan Berger <stefanb@...>
---
OvmfPkg/OvmfTpmComponentsDxe.dsc.inc | 1 +
OvmfPkg/OvmfTpmDxe.fdf.inc | 1 +
2 files changed, 2 insertions(+)

diff --git a/OvmfPkg/OvmfTpmComponentsDxe.dsc.inc b/OvmfPkg/OvmfTpmComponen=
tsDxe.dsc.inc
index 75ae09571e..cdcae42ad1 100644
--- a/OvmfPkg/OvmfTpmComponentsDxe.dsc.inc
+++ b/OvmfPkg/OvmfTpmComponentsDxe.dsc.inc
@@ -20,6 +20,7 @@
<LibraryClasses>=0D
Tpm12DeviceLib|SecurityPkg/Library/Tpm12DeviceLibDTpm/Tpm12DeviceLib=
DTpm.inf=0D
}=0D
+ SecurityPkg/Tcg/TcgConfigDxe/TcgConfigDxe.inf=0D
!endif=0D
SecurityPkg/Tcg/Tcg2PlatformDxe/Tcg2PlatformDxe.inf {=0D
<LibraryClasses>=0D
diff --git a/OvmfPkg/OvmfTpmDxe.fdf.inc b/OvmfPkg/OvmfTpmDxe.fdf.inc
index 7fc2bf8590..5907d8a8f1 100644
--- a/OvmfPkg/OvmfTpmDxe.fdf.inc
+++ b/OvmfPkg/OvmfTpmDxe.fdf.inc
@@ -5,6 +5,7 @@
!if $(TPM2_ENABLE) =3D=3D TRUE=0D
!if $(TPM1_ENABLE) =3D=3D TRUE=0D
INF SecurityPkg/Tcg/TcgDxe/TcgDxe.inf=0D
+INF SecurityPkg/Tcg/TcgConfigDxe/TcgConfigDxe.inf=0D
!endif=0D
INF SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.inf=0D
INF SecurityPkg/Tcg/Tcg2PlatformDxe/Tcg2PlatformDxe.inf=0D
--=20
2.31.1


[PATCH v3 6/8] OvmfPkg: Enable physical presence interface for TPM 1.2

Stefan Berger
 

Enable the physical presence interface for TPM 1.2. It is required for the
TPM 1.2 menu to work.

The changes to DxeTcgPhysicalPresenceLib.c are due to the device we are
using in QEMU for presenting the supported PPI commands and results to the
OS via ACPI as well as to store the PPI opcode to execute.

Cc: Jiewen Yao <jiewen.yao@...>
Cc: Jian J Wang <jian.j.wang@...>
Cc: Ard Biesheuvel <ardb+tianocore@...>
Cc: Jordan Justen <jordan.l.justen@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: Marc-André Lureau <marcandre.lureau@...>
Signed-off-by: Stefan Berger <stefanb@...>
---
OvmfPkg/Bhyve/BhyveX64.dsc | 1 +
.../PlatformBootManagerLib/BdsPlatform.c | 1 +
.../PlatformBootManagerLib.inf | 1 +
.../DxeTcgPhysicalPresenceLib.c | 22 +
.../DxeTcgPhysicalPresenceLib.inf | 27 +
.../DxeTcgPhysicalPresenceLib.c | 481 +++++++++---------
.../DxeTcgPhysicalPresenceLib.inf | 14 +-
OvmfPkg/Microvm/MicrovmX64.dsc | 1 +
OvmfPkg/OvmfTpmLibs.dsc.inc | 4 +
OvmfPkg/OvmfXen.dsc | 1 +
.../Include/Library/TcgPhysicalPresenceLib.h | 39 ++
SecurityPkg/Tcg/TcgConfigDxe/TcgConfigDxe.inf | 1 +
12 files changed, 342 insertions(+), 251 deletions(-)
create mode 100644 OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.c
create mode 100644 OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.inf

diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc
index d8fe607d1c..c848451a2b 100644
--- a/OvmfPkg/Bhyve/BhyveX64.dsc
+++ b/OvmfPkg/Bhyve/BhyveX64.dsc
@@ -223,6 +223,7 @@
XenPlatformLib|OvmfPkg/Library/XenPlatformLib/XenPlatformLib.inf

Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf
+ TcgPhysicalPresenceLib|OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.inf
TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf

[LibraryClasses.common]
diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
index 2905356fc4..1765026de2 100644
--- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
+++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
@@ -12,6 +12,7 @@
#include <Protocol/FirmwareVolume2.h>
#include <Library/PlatformBmPrintScLib.h>
#include <Library/Tcg2PhysicalPresenceLib.h>
+#include <Library/TcgPhysicalPresenceLib.h>
#include <Library/XenPlatformLib.h>


diff --git a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
index c249a3cf1e..f12975d065 100644
--- a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
+++ b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
@@ -54,6 +54,7 @@
ReportStatusCodeLib
UefiLib
PlatformBmPrintScLib
+ TcgPhysicalPresenceLib
Tcg2PhysicalPresenceLib
XenPlatformLib

diff --git a/OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.c b/OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.c
new file mode 100644
index 0000000000..d434175717
--- /dev/null
+++ b/OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.c
@@ -0,0 +1,22 @@
+/** @file
+ NULL TcgPhysicalPresenceLib library instance
+
+ Copyright (C) 2021, IBM Corporation
+ Copyright (c) 2018, Red Hat, Inc.
+ Copyright (c) 2013 - 2016, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/TcgPhysicalPresenceLib.h>
+
+VOID
+EFIAPI
+TcgPhysicalPresenceLibProcessRequest (
+ VOID
+ )
+{
+ //
+ // do nothing
+ //
+}
diff --git a/OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.inf b/OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.inf
new file mode 100644
index 0000000000..4421c6c5b0
--- /dev/null
+++ b/OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.inf
@@ -0,0 +1,27 @@
+# NULL TcgPhysicalPresenceLib library instance
+#
+# Under SecurityPkg, the corresponding library instance will check and
+# execute TPM 1.2 request from OS or BIOS; the request may ask for user
+# confirmation before execution. This Null instance implements a no-op
+# Tcg2PhysicalPresenceLibProcessRequest(), without user interaction.
+#
+# Copyright (C) 2018, Red Hat, Inc.
+# Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = DxeTcgPhysicalPresenceLibNull
+ FILE_GUID = B648575C-ED00-4C0D-BD7F-B705B9B0CC93
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = TcgPhysicalPresenceLib|DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION UEFI_DRIVER
+
+[Sources]
+ DxeTcgPhysicalPresenceLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ SecurityPkg/SecurityPkg.dec
diff --git a/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.c b/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.c
index 8a3ae95012..df0d7b5c1a 100644
--- a/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.c
+++ b/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.c
@@ -15,18 +15,23 @@ SPDX-License-Identifier: BSD-2-Clause-Patent

#include <PiDxe.h>

+#include <IndustryStandard/QemuTpm.h>
+#include <IndustryStandard/TcgPhysicalPresence.h>
+
#include <Protocol/TcgService.h>
-#include <Protocol/VariableLock.h>
+#include <Library/HobLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
+#include <Library/DxeServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiBootManagerLib.h>
#include <Library/UefiLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PrintLib.h>
+#include <Library/QemuFwCfgLib.h>
#include <Library/HiiLib.h>
-#include <Guid/EventGroup.h>
#include <Guid/PhysicalPresenceData.h>
#include <Library/TcgPpVendorLib.h>

@@ -34,6 +39,168 @@ SPDX-License-Identifier: BSD-2-Clause-Patent

EFI_HII_HANDLE mPpStringPackHandle;

+STATIC volatile QEMU_TPM_PPI *mPpi;
+
+#define TPM_PPI_PROVISION_FLAGS(PpiFlags) \
+ ((PpiFlags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION) != 0) \
+ ? QEMU_TPM_PPI_FUNC_ALLOWED_USR_NOT_REQ \
+ : QEMU_TPM_PPI_FUNC_ALLOWED_USR_REQ
+
+#define TPM_PPI_CLEAR_FLAGS(PpiFlags) \
+ ((PpiFlags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_CLEAR) != 0) \
+ ? QEMU_TPM_PPI_FUNC_ALLOWED_USR_NOT_REQ \
+ : QEMU_TPM_PPI_FUNC_ALLOWED_USR_REQ
+
+#define TPM_PPI_CLEAR_MAINT_FLAGS(PpiFlags) \
+ ((PpiFlags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_CLEAR) != 0 && \
+ (PpiFlags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_MAINTENANCE) != 0) \
+ ? QEMU_TPM_PPI_FUNC_ALLOWED_USR_NOT_REQ \
+ : QEMU_TPM_PPI_FUNC_ALLOWED_USR_REQ
+
+/**
+ Reads QEMU PPI config from fw_cfg.
+
+ @param[out] The Config structure to read to.
+
+ @retval EFI_SUCCESS Operation completed successfully.
+ @retval EFI_PROTOCOL_ERROR Invalid fw_cfg entry size.
+**/
+STATIC
+EFI_STATUS
+QemuTpmReadConfig (
+ OUT QEMU_FWCFG_TPM_CONFIG *Config
+ )
+{
+ EFI_STATUS Status;
+ FIRMWARE_CONFIG_ITEM FwCfgItem;
+ UINTN FwCfgSize;
+
+ Status = QemuFwCfgFindFile ("etc/tpm/config", &FwCfgItem, &FwCfgSize);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ if (FwCfgSize != sizeof (*Config)) {
+ return EFI_PROTOCOL_ERROR;
+ }
+
+ QemuFwCfgSelectItem (FwCfgItem);
+ QemuFwCfgReadBytes (sizeof (*Config), Config);
+ return EFI_SUCCESS;
+}
+
+
+/**
+ Initilalize the QEMU PPI memory region's function array
+**/
+STATIC
+VOID
+QemuTpmInitPPIFunc(
+ EFI_PHYSICAL_PRESENCE_FLAGS PpiFlags
+ )
+{
+ ZeroMem ((void *)mPpi->Func, sizeof(mPpi->Func));
+
+ mPpi->Func[TCG_PHYSICAL_PRESENCE_ENABLE] = TPM_PPI_PROVISION_FLAGS(PpiFlags);
+ mPpi->Func[TCG_PHYSICAL_PRESENCE_DISABLE] = TPM_PPI_PROVISION_FLAGS(PpiFlags);
+ mPpi->Func[TCG_PHYSICAL_PRESENCE_ACTIVATE] = TPM_PPI_PROVISION_FLAGS(PpiFlags);
+ mPpi->Func[TCG_PHYSICAL_PRESENCE_DEACTIVATE] = TPM_PPI_PROVISION_FLAGS(PpiFlags);
+ mPpi->Func[TCG_PHYSICAL_PRESENCE_CLEAR] = TPM_PPI_CLEAR_FLAGS(PpiFlags);
+ mPpi->Func[TCG_PHYSICAL_PRESENCE_ENABLE_ACTIVATE] = TPM_PPI_PROVISION_FLAGS(PpiFlags);
+ mPpi->Func[TCG_PHYSICAL_PRESENCE_DEACTIVATE_DISABLE] = TPM_PPI_PROVISION_FLAGS(PpiFlags);
+ mPpi->Func[TCG_PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE] = TPM_PPI_PROVISION_FLAGS(PpiFlags);
+ mPpi->Func[TCG_PHYSICAL_PRESENCE_SET_OWNER_INSTALL_FALSE] = TPM_PPI_PROVISION_FLAGS(PpiFlags);
+ mPpi->Func[TCG_PHYSICAL_PRESENCE_ENABLE_ACTIVATE_OWNER_TRUE] = TPM_PPI_PROVISION_FLAGS(PpiFlags);
+ mPpi->Func[TCG_PHYSICAL_PRESENCE_DEACTIVATE_DISABLE_OWNER_FALSE] = TPM_PPI_PROVISION_FLAGS(PpiFlags);
+ mPpi->Func[TCG_PHYSICAL_PRESENCE_SET_OPERATOR_AUTH] = TPM_PPI_PROVISION_FLAGS(PpiFlags);
+ mPpi->Func[TCG_PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE] = TPM_PPI_CLEAR_FLAGS(PpiFlags);
+ mPpi->Func[TCG_PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_FALSE] = QEMU_TPM_PPI_FUNC_ALLOWED_USR_NOT_REQ;
+ mPpi->Func[TCG_PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_TRUE] = QEMU_TPM_PPI_FUNC_ALLOWED_USR_REQ;
+ mPpi->Func[TCG_PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_FALSE] = QEMU_TPM_PPI_FUNC_ALLOWED_USR_NOT_REQ;
+ mPpi->Func[TCG_PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_TRUE] = QEMU_TPM_PPI_FUNC_ALLOWED_USR_REQ;
+ mPpi->Func[TCG_PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_FALSE] = QEMU_TPM_PPI_FUNC_ALLOWED_USR_NOT_REQ;
+ mPpi->Func[TCG_PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_TRUE] = QEMU_TPM_PPI_FUNC_ALLOWED_USR_REQ;
+ mPpi->Func[TCG_PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR] = TPM_PPI_CLEAR_MAINT_FLAGS(PpiFlags);
+ mPpi->Func[TCG_PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE] = TPM_PPI_CLEAR_MAINT_FLAGS(PpiFlags);
+ mPpi->Func[TCG_PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR] = TPM_PPI_CLEAR_MAINT_FLAGS(PpiFlags);
+}
+
+
+/**
+ Initializes QEMU PPI memory region.
+
+ @retval EFI_SUCCESS Operation completed successfully.
+ @retval EFI_PROTOCOL_ERROR PPI address is invalid.
+**/
+STATIC
+EFI_STATUS
+QemuTpmInitPPI (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ QEMU_FWCFG_TPM_CONFIG Config;
+ EFI_PHYSICAL_ADDRESS PpiAddress64;
+ EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
+ EFI_PHYSICAL_PRESENCE_FLAGS PpiFlags;
+
+ if (mPpi != NULL) {
+ return EFI_SUCCESS;
+ }
+
+ Status = QemuTpmReadConfig (&Config);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ if (Config.TpmVersion != QEMU_TPM_VERSION_1_2) {
+ DEBUG ((DEBUG_ERROR, "[TPM] Not setting up PPI. This is not a TPM 1.2.\n"));
+ return EFI_PROTOCOL_ERROR;
+ }
+
+ mPpi = (QEMU_TPM_PPI *)(UINTN)Config.PpiAddress;
+ if (mPpi == NULL) {
+ return EFI_PROTOCOL_ERROR;
+ }
+
+ DEBUG ((DEBUG_INFO, "[TPM] mPpi=%p version=%d\n", mPpi, Config.TpmVersion));
+
+ PpiAddress64 = (UINTN)mPpi;
+ if ((PpiAddress64 & ~(UINT64)EFI_PAGE_MASK) !=
+ ((PpiAddress64 + sizeof *mPpi - 1) & ~(UINT64)EFI_PAGE_MASK)) {
+ DEBUG ((DEBUG_ERROR, "[TPM] mPpi crosses a page boundary\n"));
+ goto InvalidPpiAddress;
+ }
+
+ Status = gDS->GetMemorySpaceDescriptor (PpiAddress64, &Descriptor);
+ if (EFI_ERROR (Status) && Status != EFI_NOT_FOUND) {
+ ASSERT_EFI_ERROR (Status);
+ goto InvalidPpiAddress;
+ }
+ if (!EFI_ERROR (Status) &&
+ (Descriptor.GcdMemoryType != EfiGcdMemoryTypeMemoryMappedIo &&
+ Descriptor.GcdMemoryType != EfiGcdMemoryTypeNonExistent)) {
+ DEBUG ((DEBUG_ERROR, "[TPM] mPpi has an invalid memory type\n"));
+ goto InvalidPpiAddress;
+ }
+
+ PpiFlags.PPFlags = 0;
+ QemuTpmInitPPIFunc(PpiFlags);
+
+ if (mPpi->In == 0) {
+ mPpi->In = 1;
+ mPpi->Request = PHYSICAL_PRESENCE_NO_ACTION;
+ mPpi->LastRequest = PHYSICAL_PRESENCE_NO_ACTION;
+ mPpi->NextStep = PHYSICAL_PRESENCE_NO_ACTION;
+ }
+
+ return EFI_SUCCESS;
+
+InvalidPpiAddress:
+ mPpi = NULL;
+ return EFI_PROTOCOL_ERROR;
+}
+
/**
Get string by string id from HII Interface.

@@ -506,7 +673,7 @@ TcgPhysicalPresenceLibConstructor (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
- mPpStringPackHandle = HiiAddPackages (&gEfiPhysicalPresenceGuid, ImageHandle, DxeTcgPhysicalPresenceLibStrings, NULL);
+ mPpStringPackHandle = HiiAddPackages (&gEfiPhysicalPresenceGuid, ImageHandle, TcgPhysicalPresenceLibQemuStrings, NULL);
ASSERT (mPpStringPackHandle != NULL);

return EFI_SUCCESS;
@@ -875,6 +1042,10 @@ UserConfirm (
return FALSE;
}

+ // Console for user interaction
+ // We need to connect all trusted consoles for TCG PP. Here we treat all consoles in OVMF to be trusted consoles.
+ EfiBootManagerConnectAllDefaultConsoles ();
+
TmpStr1 = PhysicalPresenceGetStringById (STRING_TOKEN (TPM_REJECT_KEY));
BufSize -= StrSize (ConfirmText);
UnicodeSPrint (ConfirmText + StrLen (ConfirmText), BufSize, TmpStr1, TmpStr2);
@@ -975,7 +1146,7 @@ HaveValidTpmRequest (

default:
if (TcgPpData->PPRequest >= TCG_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) {
- IsRequestValid = TcgPpVendorLibHasValidRequest (TcgPpData->PPRequest, Flags.PPFlags, RequestConfirmed);
+ IsRequestValid = FALSE; // vendor-specifc commands are not supported
if (!IsRequestValid) {
return FALSE;
} else {
@@ -1015,60 +1186,47 @@ HaveValidTpmRequest (
@param[in] Flags The physical presence interface flags.

**/
+STATIC
VOID
ExecutePendingTpmRequest (
IN EFI_TCG_PROTOCOL *TcgProtocol,
- IN EFI_PHYSICAL_PRESENCE *TcgPpData,
IN EFI_PHYSICAL_PRESENCE_FLAGS Flags
)
{
EFI_STATUS Status;
- UINTN DataSize;
BOOLEAN RequestConfirmed;
+ EFI_PHYSICAL_PRESENCE TcgPpData;
EFI_PHYSICAL_PRESENCE_FLAGS NewFlags;
- BOOLEAN ResetRequired;
- UINT32 NewPPFlags;

- if (!HaveValidTpmRequest(TcgPpData, Flags, &RequestConfirmed)) {
+ DEBUG ((DEBUG_INFO, "[TPM] Flags=%x, PPRequest=%x\n", Flags.PPFlags, mPpi->Request));
+
+ TcgPpData.PPRequest = (UINT8)mPpi->Request;
+
+ if (!HaveValidTpmRequest(&TcgPpData, Flags, &RequestConfirmed)) {
//
// Invalid operation request.
//
- TcgPpData->PPResponse = TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE;
- TcgPpData->LastPPRequest = TcgPpData->PPRequest;
- TcgPpData->PPRequest = PHYSICAL_PRESENCE_NO_ACTION;
- DataSize = sizeof (EFI_PHYSICAL_PRESENCE);
- Status = gRT->SetVariable (
- PHYSICAL_PRESENCE_VARIABLE,
- &gEfiPhysicalPresenceGuid,
- EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
- DataSize,
- TcgPpData
- );
+ mPpi->Response = TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE;
+ mPpi->LastRequest = mPpi->Request;
+ mPpi->Request = TCG_PHYSICAL_PRESENCE_NO_ACTION;
+ mPpi->RequestParameter = 0;
return;
}

- ResetRequired = FALSE;
- if (TcgPpData->PPRequest >= TCG_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) {
- NewFlags = Flags;
- NewPPFlags = NewFlags.PPFlags;
- TcgPpData->PPResponse = TcgPpVendorLibExecutePendingRequest (TcgPpData->PPRequest, &NewPPFlags, &ResetRequired);
- NewFlags.PPFlags = (UINT8)NewPPFlags;
- } else {
- if (!RequestConfirmed) {
- //
- // Print confirm text and wait for approval.
- //
- RequestConfirmed = UserConfirm (TcgPpData->PPRequest);
- }
-
+ if (!RequestConfirmed) {
//
- // Execute requested physical presence command
+ // Print confirm text and wait for approval.
//
- TcgPpData->PPResponse = TCG_PP_OPERATION_RESPONSE_USER_ABORT;
- NewFlags = Flags;
- if (RequestConfirmed) {
- TcgPpData->PPResponse = ExecutePhysicalPresence (TcgProtocol, TcgPpData->PPRequest, &NewFlags);
- }
+ RequestConfirmed = UserConfirm (mPpi->Request);
+ }
+
+ //
+ // Execute requested physical presence command
+ //
+ mPpi->Response = TCG_PP_OPERATION_RESPONSE_USER_ABORT;
+ NewFlags = Flags;
+ if (RequestConfirmed) {
+ mPpi->Response = ExecutePhysicalPresence (TcgProtocol, mPpi->Request, &NewFlags);
}

//
@@ -1085,39 +1243,32 @@ ExecutePendingTpmRequest (
if (EFI_ERROR (Status)) {
return;
}
+
+ //
+ // Update the flags for the commands following PPFlags changes
+ //
+ QemuTpmInitPPIFunc(NewFlags);
+
+ DEBUG ((DEBUG_INFO, "[TPM] New PPFlags = %x\n", NewFlags.PPFlags));
}

//
// Clear request
//
if ((NewFlags.PPFlags & TCG_VENDOR_LIB_FLAG_RESET_TRACK) == 0) {
- TcgPpData->LastPPRequest = TcgPpData->PPRequest;
- TcgPpData->PPRequest = PHYSICAL_PRESENCE_NO_ACTION;
+ mPpi->LastRequest = mPpi->Request;
+ mPpi->Request = PHYSICAL_PRESENCE_NO_ACTION;
+ mPpi->RequestParameter = 0;
}

- //
- // Save changes
- //
- DataSize = sizeof (EFI_PHYSICAL_PRESENCE);
- Status = gRT->SetVariable (
- PHYSICAL_PRESENCE_VARIABLE,
- &gEfiPhysicalPresenceGuid,
- EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
- DataSize,
- TcgPpData
- );
- if (EFI_ERROR (Status)) {
- return;
- }
-
- if (TcgPpData->PPResponse == TCG_PP_OPERATION_RESPONSE_USER_ABORT) {
+ if (mPpi->Response == TCG_PP_OPERATION_RESPONSE_USER_ABORT) {
return;
}

//
// Reset system to make new TPM settings in effect
//
- switch (TcgPpData->LastPPRequest) {
+ switch (mPpi->LastRequest) {
case PHYSICAL_PRESENCE_ACTIVATE:
case PHYSICAL_PRESENCE_DEACTIVATE:
case PHYSICAL_PRESENCE_CLEAR:
@@ -1131,17 +1282,10 @@ ExecutePendingTpmRequest (
case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE:
break;
default:
- if (TcgPpData->LastPPRequest >= TCG_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPERATION) {
- if (ResetRequired) {
- break;
- } else {
- return ;
- }
- }
- if (TcgPpData->PPRequest != PHYSICAL_PRESENCE_NO_ACTION) {
- break;
- }
- return;
+ if (mPpi->Request != TCG_PHYSICAL_PRESENCE_NO_ACTION) {
+ break;
+ }
+ return;
}

Print (L"Rebooting system to make TPM settings in effect\n");
@@ -1172,11 +1316,24 @@ TcgPhysicalPresenceLibProcessRequest (
BOOLEAN LifetimeLock;
BOOLEAN CmdEnable;
UINTN DataSize;
- EFI_PHYSICAL_PRESENCE TcgPpData;
EFI_TCG_PROTOCOL *TcgProtocol;
- EDKII_VARIABLE_LOCK_PROTOCOL *VariableLockProtocol;
EFI_PHYSICAL_PRESENCE_FLAGS PpiFlags;

+ Status = QemuTpmInitPPI ();
+ if (EFI_ERROR (Status)) {
+ return ;
+ }
+
+ DEBUG ((DEBUG_INFO, "[TPM] Detected a TPM 1.2\n"));
+
+ //
+ // Check S4 resume
+ //
+ if (GetBootModeHob () == BOOT_ON_S4_RESUME) {
+ DEBUG ((DEBUG_INFO, "S4 Resume, Skip TPM PP process!\n"));
+ return ;
+ }
+
Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **)&TcgProtocol);
if (EFI_ERROR (Status)) {
return ;
@@ -1209,53 +1366,11 @@ TcgPhysicalPresenceLibProcessRequest (
}
DEBUG ((DEBUG_INFO, "[TPM] PpiFlags = %x\n", PpiFlags.PPFlags));

- //
- // This flags variable controls whether physical presence is required for TPM command.
- // It should be protected from malicious software. We set it as read-only variable here.
- //
- Status = gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (VOID **)&VariableLockProtocol);
- if (!EFI_ERROR (Status)) {
- Status = VariableLockProtocol->RequestToLock (
- VariableLockProtocol,
- PHYSICAL_PRESENCE_FLAGS_VARIABLE,
- &gEfiPhysicalPresenceGuid
- );
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "[TPM] Error when lock variable %s, Status = %r\n", PHYSICAL_PRESENCE_FLAGS_VARIABLE, Status));
- ASSERT_EFI_ERROR (Status);
- }
- }
-
- //
- // Initialize physical presence variable.
- //
- DataSize = sizeof (EFI_PHYSICAL_PRESENCE);
- Status = gRT->GetVariable (
- PHYSICAL_PRESENCE_VARIABLE,
- &gEfiPhysicalPresenceGuid,
- NULL,
- &DataSize,
- &TcgPpData
- );
- if (EFI_ERROR (Status)) {
- ZeroMem ((VOID*)&TcgPpData, sizeof (TcgPpData));
- DataSize = sizeof (EFI_PHYSICAL_PRESENCE);
- Status = gRT->SetVariable (
- PHYSICAL_PRESENCE_VARIABLE,
- &gEfiPhysicalPresenceGuid,
- EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
- DataSize,
- &TcgPpData
- );
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "[TPM] Set physical presence variable failed, Status = %r\n", Status));
- return;
- }
- }
+ QemuTpmInitPPIFunc(PpiFlags);

- DEBUG ((DEBUG_INFO, "[TPM] Flags=%x, PPRequest=%x\n", PpiFlags.PPFlags, TcgPpData.PPRequest));
+ DEBUG ((DEBUG_INFO, "[TPM] Flags=%x, PPRequest=%x\n", PpiFlags.PPFlags, mPpi->Request));

- if (TcgPpData.PPRequest == PHYSICAL_PRESENCE_NO_ACTION) {
+ if (mPpi->Request == PHYSICAL_PRESENCE_NO_ACTION) {
//
// No operation request
//
@@ -1291,8 +1406,8 @@ TcgPhysicalPresenceLibProcessRequest (
//
// Execute pending TPM request.
//
- ExecutePendingTpmRequest (TcgProtocol, &TcgPpData, PpiFlags);
- DEBUG ((DEBUG_INFO, "[TPM] PPResponse = %x\n", TcgPpData.PPResponse));
+ ExecutePendingTpmRequest (TcgProtocol, PpiFlags);
+ DEBUG ((DEBUG_INFO, "[TPM] PPResponse = %x\n", mPpi->Response));

//
// Lock physical presence.
@@ -1300,104 +1415,6 @@ TcgPhysicalPresenceLibProcessRequest (
TpmPhysicalPresence (TcgProtocol, TPM_PHYSICAL_PRESENCE_NOTPRESENT | TPM_PHYSICAL_PRESENCE_LOCK);
}

-/**
- Check if the pending TPM request needs user input to confirm.
-
- The TPM request may come from OS. This API will check if TPM request exists and need user
- input to confirmation.
-
- @retval TRUE TPM needs input to confirm user physical presence.
- @retval FALSE TPM doesn't need input to confirm user physical presence.
-
-**/
-BOOLEAN
-EFIAPI
-TcgPhysicalPresenceLibNeedUserConfirm(
- VOID
- )
-{
- EFI_STATUS Status;
- EFI_PHYSICAL_PRESENCE TcgPpData;
- UINTN DataSize;
- BOOLEAN RequestConfirmed;
- BOOLEAN LifetimeLock;
- BOOLEAN CmdEnable;
- EFI_TCG_PROTOCOL *TcgProtocol;
- EFI_PHYSICAL_PRESENCE_FLAGS PpiFlags;
-
- Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **)&TcgProtocol);
- if (EFI_ERROR (Status)) {
- return FALSE;
- }
-
- //
- // Check Tpm requests
- //
- DataSize = sizeof (EFI_PHYSICAL_PRESENCE);
- Status = gRT->GetVariable (
- PHYSICAL_PRESENCE_VARIABLE,
- &gEfiPhysicalPresenceGuid,
- NULL,
- &DataSize,
- &TcgPpData
- );
- if (EFI_ERROR (Status)) {
- return FALSE;
- }
-
- DataSize = sizeof (EFI_PHYSICAL_PRESENCE_FLAGS);
- Status = gRT->GetVariable (
- PHYSICAL_PRESENCE_FLAGS_VARIABLE,
- &gEfiPhysicalPresenceGuid,
- NULL,
- &DataSize,
- &PpiFlags
- );
- if (EFI_ERROR (Status)) {
- return FALSE;
- }
-
- if (TcgPpData.PPRequest == PHYSICAL_PRESENCE_NO_ACTION) {
- //
- // No operation request
- //
- return FALSE;
- }
-
- if (!HaveValidTpmRequest(&TcgPpData, PpiFlags, &RequestConfirmed)) {
- //
- // Invalid operation request.
- //
- return FALSE;
- }
-
- //
- // Check Tpm Capability
- //
- Status = GetTpmCapability (TcgProtocol, &LifetimeLock, &CmdEnable);
- if (EFI_ERROR (Status)) {
- return FALSE;
- }
-
- if (!CmdEnable) {
- if (LifetimeLock) {
- //
- // physicalPresenceCMDEnable is locked, can't execute physical presence command.
- //
- return FALSE;
- }
- }
-
- if (!RequestConfirmed) {
- //
- // Need UI to confirm
- //
- return TRUE;
- }
-
- return FALSE;
-}
-
/**
The handler for TPM physical presence function:
Submit TPM Operation Request to Pre-OS Environment and
@@ -1416,40 +1433,16 @@ TcgPhysicalPresenceLibSubmitRequestToPreOSFunction (
IN UINT32 OperationRequest
)
{
- EFI_STATUS Status;
- UINTN DataSize;
- EFI_PHYSICAL_PRESENCE PpData;
+ EFI_STATUS Status;

DEBUG ((DEBUG_INFO, "[TPM] SubmitRequestToPreOSFunction, Request = %x\n", OperationRequest));

- //
- // Get the Physical Presence variable
- //
- DataSize = sizeof (EFI_PHYSICAL_PRESENCE);
- Status = gRT->GetVariable (
- PHYSICAL_PRESENCE_VARIABLE,
- &gEfiPhysicalPresenceGuid,
- NULL,
- &DataSize,
- &PpData
- );
+ Status = QemuTpmInitPPI ();
if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "[TPM] Get PP variable failure! Status = %r\n", Status));
return TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE;
}

- PpData.PPRequest = (UINT8)OperationRequest;
- Status = gRT->SetVariable (
- PHYSICAL_PRESENCE_VARIABLE,
- &gEfiPhysicalPresenceGuid,
- EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
- DataSize,
- &PpData
- );
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "[TPM] Set PP variable failure! Status = %r\n", Status));
- return TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE;
- }
+ mPpi->Request = OperationRequest;

return TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS;
}
diff --git a/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.inf b/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.inf
index cfe14f20ca..a7f76d5918 100644
--- a/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.inf
+++ b/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.inf
@@ -16,9 +16,8 @@

[Defines]
INF_VERSION = 0x00010005
- BASE_NAME = DxeTcgPhysicalPresenceLib
- MODULE_UNI_FILE = DxeTcgPhysicalPresenceLib.uni
- FILE_GUID = EBC43A46-34AC-4F07-A7F5-A5394619361C
+ BASE_NAME = TcgPhysicalPresenceLibQemu
+ FILE_GUID = DA5A2055-ACD6-49A1-8277-857f3A47BB0C
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = TcgPhysicalPresenceLib|DXE_DRIVER DXE_RUNTIME_DRIVER UEFI_APPLICATION UEFI_DRIVER
@@ -37,19 +36,22 @@
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
+ OvmfPkg/OvmfPkg.dec
SecurityPkg/SecurityPkg.dec

[LibraryClasses]
MemoryAllocationLib
+ DxeServicesTableLib
+ HobLib
+ QemuFwCfgLib
+ UefiBootManagerLib
UefiLib
UefiBootServicesTableLib
- UefiDriverEntryPoint
UefiRuntimeServicesTableLib
BaseMemoryLib
DebugLib
PrintLib
HiiLib
- TcgPpVendorLib

[Protocols]
gEfiTcgProtocolGuid ## SOMETIMES_CONSUMES
@@ -57,8 +59,6 @@

[Guids]
## SOMETIMES_CONSUMES ## HII
- ## SOMETIMES_PRODUCES ## Variable:L"PhysicalPresence"
- ## SOMETIMES_CONSUMES ## Variable:L"PhysicalPresence"
## SOMETIMES_PRODUCES ## Variable:L"PhysicalPresenceFlags"
## SOMETIMES_CONSUMES ## Variable:L"PhysicalPresenceFlags"
gEfiPhysicalPresenceGuid
diff --git a/OvmfPkg/Microvm/MicrovmX64.dsc b/OvmfPkg/Microvm/MicrovmX64.dsc
index 617f925395..5561b17587 100644
--- a/OvmfPkg/Microvm/MicrovmX64.dsc
+++ b/OvmfPkg/Microvm/MicrovmX64.dsc
@@ -225,6 +225,7 @@
OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf

Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf
+ TcgPhysicalPresenceLib|OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.inf
TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf

[LibraryClasses.common]
diff --git a/OvmfPkg/OvmfTpmLibs.dsc.inc b/OvmfPkg/OvmfTpmLibs.dsc.inc
index 418747b134..24b54861ed 100644
--- a/OvmfPkg/OvmfTpmLibs.dsc.inc
+++ b/OvmfPkg/OvmfTpmLibs.dsc.inc
@@ -5,6 +5,9 @@
!if $(TPM2_ENABLE) == TRUE
!if $(TPM1_ENABLE) == TRUE
Tpm12CommandLib|SecurityPkg/Library/Tpm12CommandLib/Tpm12CommandLib.inf
+ TcgPhysicalPresenceLib|OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.inf
+!else
+ TcgPhysicalPresenceLib|OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.inf
!endif
Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf
Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibQemu/DxeTcg2PhysicalPresenceLib.inf
@@ -13,4 +16,5 @@
!else
Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf
TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf
+ TcgPhysicalPresenceLib|OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.inf
!endif
diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index a31519e356..82bc3ea4aa 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -215,6 +215,7 @@
XenIoMmioLib|OvmfPkg/Library/XenIoMmioLib/XenIoMmioLib.inf

Tcg2PhysicalPresenceLib|OvmfPkg/Library/Tcg2PhysicalPresenceLibNull/DxeTcg2PhysicalPresenceLib.inf
+ TcgPhysicalPresenceLib|OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.inf
TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf
RealTimeClockLib|OvmfPkg/Library/XenRealTimeClockLib/XenRealTimeClockLib.inf
TimeBaseLib|EmbeddedPkg/Library/TimeBaseLib/TimeBaseLib.inf
diff --git a/SecurityPkg/Include/Library/TcgPhysicalPresenceLib.h b/SecurityPkg/Include/Library/TcgPhysicalPresenceLib.h
index 9826a79742..6877c08e74 100644
--- a/SecurityPkg/Include/Library/TcgPhysicalPresenceLib.h
+++ b/SecurityPkg/Include/Library/TcgPhysicalPresenceLib.h
@@ -45,4 +45,43 @@ TcgPhysicalPresenceLibNeedUserConfirm(
VOID
);

+/**
+ The handler for TPM physical presence function:
+ Return TPM Operation Response to OS Environment.
+
+ This API should be invoked in OS runtime phase to interface with ACPI method.
+
+ @param[out] MostRecentRequest Most recent operation request.
+ @param[out] Response Response to the most recent operation request.
+
+ @return Return Code for Return TPM Operation Response to OS Environment.
+**/
+UINT32
+EFIAPI
+Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction (
+ OUT UINT32 *MostRecentRequest,
+ OUT UINT32 *Response
+ );
+
+/**
+ The handler for TPM physical presence function:
+ Submit TPM Operation Request to Pre-OS Environment and
+ Submit TPM Operation Request to Pre-OS Environment 2.
+
+ This API should be invoked in OS runtime phase to interface with ACPI method.
+
+ Caution: This function may receive untrusted input.
+
+ @param[in] OperationRequest TPM physical presence operation request.
+ @param[in] RequestParameter TPM physical presence operation request parameter.
+
+ @return Return Code for Submit TPM Operation Request to Pre-OS Environment and
+ Submit TPM Operation Request to Pre-OS Environment 2.
+**/
+UINT32
+EFIAPI
+TcgPhysicalPresenceLibSubmitRequestToPreOSFunction (
+ IN UINT32 OperationRequest
+ );
+
#endif
diff --git a/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigDxe.inf b/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigDxe.inf
index 24428e050c..b2f36fdbb2 100644
--- a/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigDxe.inf
+++ b/SecurityPkg/Tcg/TcgConfigDxe/TcgConfigDxe.inf
@@ -47,6 +47,7 @@
HiiLib
PcdLib
PrintLib
+ TcgPhysicalPresenceLib
Tpm12DeviceLib

[Guids]
--
2.31.1


[PATCH v3 5/8] OvmfPkg: Copy TPM 1.2 DxeTcgPhysicalPresenceLib.c from SecurityPkg

Stefan Berger
 

Copy the TPM 1.2 physical presence interface support from SecurityPkg
DxeTcgPhysicalPresenceLib.c along with its .inf and .uni files into
OvmfPkg.

Fix EFI_F_INFO and EFI_D_ERROR to meet code standards.

Signed-off-by: Stefan Berger <stefanb@...>
---
.../DxeTcgPhysicalPresenceLib.c | 1455 +++++++++++++++++
.../DxeTcgPhysicalPresenceLib.inf | 64 +
.../DxeTcgPhysicalPresenceLib.uni | 22 +
.../PhysicalPresenceStrings.uni | 46 +
4 files changed, 1587 insertions(+)
create mode 100644 OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysic=
alPresenceLib.c
create mode 100644 OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysic=
alPresenceLib.inf
create mode 100644 OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysic=
alPresenceLib.uni
create mode 100644 OvmfPkg/Library/TcgPhysicalPresenceLibQemu/PhysicalPres=
enceStrings.uni

diff --git a/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPrese=
nceLib.c b/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenc=
eLib.c
new file mode 100644
index 0000000000..8a3ae95012
--- /dev/null
+++ b/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.c
@@ -0,0 +1,1455 @@
+/** @file=0D
+=0D
+ Execute pending TPM requests from OS or BIOS and Lock TPM.=0D
+=0D
+ Caution: This module requires additional review when modified.=0D
+ This driver will have external input - variable.=0D
+ This external input must be validated carefully to avoid security issue.=
=0D
+=0D
+ ExecutePendingTpmRequest() will receive untrusted input and do validatio=
n.=0D
+=0D
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>=0D
+SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+=0D
+**/=0D
+=0D
+#include <PiDxe.h>=0D
+=0D
+#include <Protocol/TcgService.h>=0D
+#include <Protocol/VariableLock.h>=0D
+#include <Library/DebugLib.h>=0D
+#include <Library/BaseMemoryLib.h>=0D
+#include <Library/UefiRuntimeServicesTableLib.h>=0D
+#include <Library/UefiDriverEntryPoint.h>=0D
+#include <Library/UefiBootServicesTableLib.h>=0D
+#include <Library/UefiLib.h>=0D
+#include <Library/MemoryAllocationLib.h>=0D
+#include <Library/PrintLib.h>=0D
+#include <Library/HiiLib.h>=0D
+#include <Guid/EventGroup.h>=0D
+#include <Guid/PhysicalPresenceData.h>=0D
+#include <Library/TcgPpVendorLib.h>=0D
+=0D
+#define CONFIRM_BUFFER_SIZE 4096=0D
+=0D
+EFI_HII_HANDLE mPpStringPackHandle;=0D
+=0D
+/**=0D
+ Get string by string id from HII Interface.=0D
+=0D
+ @param[in] Id String ID.=0D
+=0D
+ @retval CHAR16 * String from ID.=0D
+ @retval NULL If error occurs.=0D
+=0D
+**/=0D
+CHAR16 *=0D
+PhysicalPresenceGetStringById (=0D
+ IN EFI_STRING_ID Id=0D
+ )=0D
+{=0D
+ return HiiGetString (mPpStringPackHandle, Id, NULL);=0D
+}=0D
+=0D
+/**=0D
+ Get TPM physical presence permanent flags.=0D
+=0D
+ @param[in] TcgProtocol EFI TCG Protocol instance.=0D
+ @param[out] LifetimeLock physicalPresenceLifetimeLock permanent flag.=0D
+ @param[out] CmdEnable physicalPresenceCMDEnable permanent flag.=0D
+=0D
+ @retval EFI_SUCCESS Flags were returns successfully.=0D
+ @retval other Failed to locate EFI TCG Protocol.=0D
+=0D
+**/=0D
+EFI_STATUS=0D
+GetTpmCapability (=0D
+ IN EFI_TCG_PROTOCOL *TcgProtocol,=0D
+ OUT BOOLEAN *LifetimeLock,=0D
+ OUT BOOLEAN *CmdEnable=0D
+ )=0D
+{=0D
+ EFI_STATUS Status;=0D
+ TPM_RQU_COMMAND_HDR *TpmRqu;=0D
+ TPM_RSP_COMMAND_HDR *TpmRsp;=0D
+ UINT32 *SendBufPtr;=0D
+ UINT8 SendBuffer[sizeof (*TpmRqu) + sizeof (=
UINT32) * 3];=0D
+ TPM_PERMANENT_FLAGS *TpmPermanentFlags;=0D
+ UINT8 RecvBuffer[40];=0D
+=0D
+ //=0D
+ // Fill request header=0D
+ //=0D
+ TpmRsp =3D (TPM_RSP_COMMAND_HDR*)RecvBuffer;=0D
+ TpmRqu =3D (TPM_RQU_COMMAND_HDR*)SendBuffer;=0D
+=0D
+ TpmRqu->tag =3D SwapBytes16 (TPM_TAG_RQU_COMMAND);=0D
+ TpmRqu->paramSize =3D SwapBytes32 (sizeof (SendBuffer));=0D
+ TpmRqu->ordinal =3D SwapBytes32 (TPM_ORD_GetCapability);=0D
+=0D
+ //=0D
+ // Set request parameter=0D
+ //=0D
+ SendBufPtr =3D (UINT32*)(TpmRqu + 1);=0D
+ WriteUnaligned32 (SendBufPtr++, SwapBytes32 (TPM_CAP_FLAG));=0D
+ WriteUnaligned32 (SendBufPtr++, SwapBytes32 (sizeof (TPM_CAP_FLAG_PERMAN=
ENT)));=0D
+ WriteUnaligned32 (SendBufPtr, SwapBytes32 (TPM_CAP_FLAG_PERMANENT));=0D
+=0D
+ Status =3D TcgProtocol->PassThroughToTpm (=0D
+ TcgProtocol,=0D
+ sizeof (SendBuffer),=0D
+ (UINT8*)TpmRqu,=0D
+ sizeof (RecvBuffer),=0D
+ (UINT8*)&RecvBuffer=0D
+ );=0D
+ if (EFI_ERROR (Status)) {=0D
+ return Status;=0D
+ }=0D
+=0D
+ if ((TpmRsp->tag !=3D SwapBytes16 (TPM_TAG_RSP_COMMAND)) || (TpmRsp->ret=
urnCode !=3D 0)) {=0D
+ return EFI_DEVICE_ERROR;=0D
+ }=0D
+=0D
+ TpmPermanentFlags =3D (TPM_PERMANENT_FLAGS *)&RecvBuffer[sizeof (TPM_RSP=
_COMMAND_HDR) + sizeof (UINT32)];=0D
+=0D
+ if (LifetimeLock !=3D NULL) {=0D
+ *LifetimeLock =3D TpmPermanentFlags->physicalPresenceLifetimeLock;=0D
+ }=0D
+=0D
+ if (CmdEnable !=3D NULL) {=0D
+ *CmdEnable =3D TpmPermanentFlags->physicalPresenceCMDEnable;=0D
+ }=0D
+=0D
+ return Status;=0D
+}=0D
+=0D
+/**=0D
+ Issue TSC_PhysicalPresence command to TPM.=0D
+=0D
+ @param[in] TcgProtocol EFI TCG Protocol instance.=0D
+ @param[in] PhysicalPresence The state to set the TPM's Physical Pres=
ence flags.=0D
+=0D
+ @retval EFI_SUCCESS TPM executed the command successfully.=0D
+ @retval EFI_SECURITY_VIOLATION TPM returned error when executing the co=
mmand.=0D
+ @retval other Failed to locate EFI TCG Protocol.=0D
+=0D
+**/=0D
+EFI_STATUS=0D
+TpmPhysicalPresence (=0D
+ IN EFI_TCG_PROTOCOL *TcgProtocol,=0D
+ IN TPM_PHYSICAL_PRESENCE PhysicalPresence=0D
+ )=0D
+{=0D
+ EFI_STATUS Status;=0D
+ TPM_RQU_COMMAND_HDR *TpmRqu;=0D
+ TPM_PHYSICAL_PRESENCE *TpmPp;=0D
+ TPM_RSP_COMMAND_HDR TpmRsp;=0D
+ UINT8 Buffer[sizeof (*TpmRqu) + sizeof (*Tpm=
Pp)];=0D
+=0D
+ TpmRqu =3D (TPM_RQU_COMMAND_HDR*)Buffer;=0D
+ TpmPp =3D (TPM_PHYSICAL_PRESENCE*)(TpmRqu + 1);=0D
+=0D
+ TpmRqu->tag =3D SwapBytes16 (TPM_TAG_RQU_COMMAND);=0D
+ TpmRqu->paramSize =3D SwapBytes32 (sizeof (Buffer));=0D
+ TpmRqu->ordinal =3D SwapBytes32 (TSC_ORD_PhysicalPresence);=0D
+ WriteUnaligned16 (TpmPp, (TPM_PHYSICAL_PRESENCE) SwapBytes16 (PhysicalPr=
esence));=0D
+=0D
+ Status =3D TcgProtocol->PassThroughToTpm (=0D
+ TcgProtocol,=0D
+ sizeof (Buffer),=0D
+ (UINT8*)TpmRqu,=0D
+ sizeof (TpmRsp),=0D
+ (UINT8*)&TpmRsp=0D
+ );=0D
+ if (EFI_ERROR (Status)) {=0D
+ return Status;=0D
+ }=0D
+=0D
+ if (TpmRsp.tag !=3D SwapBytes16 (TPM_TAG_RSP_COMMAND)) {=0D
+ return EFI_DEVICE_ERROR;=0D
+ }=0D
+=0D
+ if (TpmRsp.returnCode !=3D 0) {=0D
+ //=0D
+ // If it fails, some requirements may be needed for this command.=0D
+ //=0D
+ return EFI_SECURITY_VIOLATION;=0D
+ }=0D
+=0D
+ return Status;=0D
+}=0D
+=0D
+/**=0D
+ Issue a TPM command for which no additional output data will be returned=
.=0D
+=0D
+ @param[in] TcgProtocol EFI TCG Protocol instance.=0D
+ @param[in] Ordinal TPM command code.=0D
+ @param[in] AdditionalParameterSize Additional parameter size.=0D
+ @param[in] AdditionalParameters Pointer to the Additional parameters=
.=0D
+=0D
+ @retval TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE Error occurred during se=
nding command to TPM or=0D
+ receiving response from =
TPM.=0D
+ @retval Others Return code from the TPM=
device after command execution.=0D
+=0D
+**/=0D
+UINT32=0D
+TpmCommandNoReturnData (=0D
+ IN EFI_TCG_PROTOCOL *TcgProtocol,=0D
+ IN TPM_COMMAND_CODE Ordinal,=0D
+ IN UINTN AdditionalParameterSize,=0D
+ IN VOID *AdditionalParameters=0D
+ )=0D
+{=0D
+ EFI_STATUS Status;=0D
+ TPM_RQU_COMMAND_HDR *TpmRqu;=0D
+ TPM_RSP_COMMAND_HDR TpmRsp;=0D
+ UINT32 Size;=0D
+=0D
+ TpmRqu =3D (TPM_RQU_COMMAND_HDR*) AllocatePool (sizeof (*TpmRqu) + Addit=
ionalParameterSize);=0D
+ if (TpmRqu =3D=3D NULL) {=0D
+ return TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE;=0D
+ }=0D
+=0D
+ TpmRqu->tag =3D SwapBytes16 (TPM_TAG_RQU_COMMAND);=0D
+ Size =3D (UINT32)(sizeof (*TpmRqu) + AdditionalParameterSiz=
e);=0D
+ TpmRqu->paramSize =3D SwapBytes32 (Size);=0D
+ TpmRqu->ordinal =3D SwapBytes32 (Ordinal);=0D
+ CopyMem (TpmRqu + 1, AdditionalParameters, AdditionalParameterSize);=0D
+=0D
+ Status =3D TcgProtocol->PassThroughToTpm (=0D
+ TcgProtocol,=0D
+ Size,=0D
+ (UINT8*)TpmRqu,=0D
+ (UINT32)sizeof (TpmRsp),=0D
+ (UINT8*)&TpmRsp=0D
+ );=0D
+ FreePool (TpmRqu);=0D
+ if (EFI_ERROR (Status) || (TpmRsp.tag !=3D SwapBytes16 (TPM_TAG_RSP_COMM=
AND))) {=0D
+ return TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE;=0D
+ }=0D
+ return SwapBytes32 (TpmRsp.returnCode);=0D
+}=0D
+=0D
+/**=0D
+ Execute physical presence operation requested by the OS.=0D
+=0D
+ @param[in] TcgProtocol EFI TCG Protocol instance.=0D
+ @param[in] CommandCode Physical presence operation value.=0D
+ @param[in, out] PpiFlags The physical presence interface flag=
s.=0D
+=0D
+ @retval TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE Unknown physical presenc=
e operation.=0D
+ @retval TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE Error occurred during se=
nding command to TPM or=0D
+ receiving response from =
TPM.=0D
+ @retval Others Return code from the TPM=
device after command execution.=0D
+=0D
+**/=0D
+UINT32=0D
+ExecutePhysicalPresence (=0D
+ IN EFI_TCG_PROTOCOL *TcgProtocol,=0D
+ IN UINT32 CommandCode,=0D
+ IN OUT EFI_PHYSICAL_PRESENCE_FLAGS *PpiFlags=0D
+ )=0D
+{=0D
+ BOOLEAN BoolVal;=0D
+ UINT32 TpmResponse;=0D
+ UINT32 InData[5];=0D
+=0D
+ switch (CommandCode) {=0D
+ case PHYSICAL_PRESENCE_ENABLE:=0D
+ return TpmCommandNoReturnData (=0D
+ TcgProtocol,=0D
+ TPM_ORD_PhysicalEnable,=0D
+ 0,=0D
+ NULL=0D
+ );=0D
+=0D
+ case PHYSICAL_PRESENCE_DISABLE:=0D
+ return TpmCommandNoReturnData (=0D
+ TcgProtocol,=0D
+ TPM_ORD_PhysicalDisable,=0D
+ 0,=0D
+ NULL=0D
+ );=0D
+=0D
+ case PHYSICAL_PRESENCE_ACTIVATE:=0D
+ BoolVal =3D FALSE;=0D
+ return TpmCommandNoReturnData (=0D
+ TcgProtocol,=0D
+ TPM_ORD_PhysicalSetDeactivated,=0D
+ sizeof (BoolVal),=0D
+ &BoolVal=0D
+ );=0D
+=0D
+ case PHYSICAL_PRESENCE_DEACTIVATE:=0D
+ BoolVal =3D TRUE;=0D
+ return TpmCommandNoReturnData (=0D
+ TcgProtocol,=0D
+ TPM_ORD_PhysicalSetDeactivated,=0D
+ sizeof (BoolVal),=0D
+ &BoolVal=0D
+ );=0D
+=0D
+ case PHYSICAL_PRESENCE_CLEAR:=0D
+ return TpmCommandNoReturnData (=0D
+ TcgProtocol,=0D
+ TPM_ORD_ForceClear,=0D
+ 0,=0D
+ NULL=0D
+ );=0D
+=0D
+ case PHYSICAL_PRESENCE_ENABLE_ACTIVATE:=0D
+ TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESE=
NCE_ENABLE, PpiFlags);=0D
+ if (TpmResponse =3D=3D 0) {=0D
+ TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRE=
SENCE_ACTIVATE, PpiFlags);=0D
+ }=0D
+ return TpmResponse;=0D
+=0D
+ case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE:=0D
+ TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESE=
NCE_DEACTIVATE, PpiFlags);=0D
+ if (TpmResponse =3D=3D 0) {=0D
+ TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRE=
SENCE_DISABLE, PpiFlags);=0D
+ }=0D
+ return TpmResponse;=0D
+=0D
+ case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE:=0D
+ BoolVal =3D TRUE;=0D
+ return TpmCommandNoReturnData (=0D
+ TcgProtocol,=0D
+ TPM_ORD_SetOwnerInstall,=0D
+ sizeof (BoolVal),=0D
+ &BoolVal=0D
+ );=0D
+=0D
+ case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_FALSE:=0D
+ BoolVal =3D FALSE;=0D
+ return TpmCommandNoReturnData (=0D
+ TcgProtocol,=0D
+ TPM_ORD_SetOwnerInstall,=0D
+ sizeof (BoolVal),=0D
+ &BoolVal=0D
+ );=0D
+=0D
+ case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_OWNER_TRUE:=0D
+ //=0D
+ // PHYSICAL_PRESENCE_ENABLE_ACTIVATE + PHYSICAL_PRESENCE_SET_OWNER_I=
NSTALL_TRUE=0D
+ // PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE will be executed after r=
eboot=0D
+ //=0D
+ if ((PpiFlags->PPFlags & TCG_VENDOR_LIB_FLAG_RESET_TRACK) =3D=3D 0) =
{=0D
+ TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRE=
SENCE_ENABLE_ACTIVATE, PpiFlags);=0D
+ PpiFlags->PPFlags |=3D TCG_VENDOR_LIB_FLAG_RESET_TRACK;=0D
+ } else {=0D
+ TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRE=
SENCE_SET_OWNER_INSTALL_TRUE, PpiFlags);=0D
+ PpiFlags->PPFlags &=3D ~TCG_VENDOR_LIB_FLAG_RESET_TRACK;=0D
+ }=0D
+ return TpmResponse;=0D
+=0D
+ case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE_OWNER_FALSE:=0D
+ TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESE=
NCE_SET_OWNER_INSTALL_FALSE, PpiFlags);=0D
+ if (TpmResponse =3D=3D 0) {=0D
+ TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRE=
SENCE_DEACTIVATE_DISABLE, PpiFlags);=0D
+ }=0D
+ return TpmResponse;=0D
+=0D
+ case PHYSICAL_PRESENCE_DEFERRED_PP_UNOWNERED_FIELD_UPGRADE:=0D
+ InData[0] =3D SwapBytes32 (TPM_SET_STCLEAR_DATA); // Capa=
bilityArea=0D
+ InData[1] =3D SwapBytes32 (sizeof(UINT32)); // SubC=
apSize=0D
+ InData[2] =3D SwapBytes32 (TPM_SD_DEFERREDPHYSICALPRESENCE); // SubC=
ap=0D
+ InData[3] =3D SwapBytes32 (sizeof(UINT32)); // SetV=
alueSize=0D
+ InData[4] =3D SwapBytes32 (1); // Unow=
nedFieldUpgrade; bit0=0D
+ return TpmCommandNoReturnData (=0D
+ TcgProtocol,=0D
+ TPM_ORD_SetCapability,=0D
+ sizeof (UINT32) * 5,=0D
+ InData=0D
+ );=0D
+=0D
+ case PHYSICAL_PRESENCE_SET_OPERATOR_AUTH:=0D
+ //=0D
+ // TPM_SetOperatorAuth=0D
+ // This command requires UI to prompt user for Auth data=0D
+ // Here it is NOT implemented=0D
+ //=0D
+ return TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE;=0D
+=0D
+ case PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE:=0D
+ TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRESE=
NCE_CLEAR, PpiFlags);=0D
+ if (TpmResponse =3D=3D 0) {=0D
+ TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRE=
SENCE_ENABLE_ACTIVATE, PpiFlags);=0D
+ }=0D
+ return TpmResponse;=0D
+=0D
+ case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_FALSE:=0D
+ PpiFlags->PPFlags &=3D ~TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISIO=
N;=0D
+ return 0;=0D
+=0D
+ case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_TRUE:=0D
+ PpiFlags->PPFlags |=3D TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION=
;=0D
+ return 0;=0D
+=0D
+ case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_FALSE:=0D
+ PpiFlags->PPFlags &=3D ~TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_CLEAR;=0D
+ return 0;=0D
+=0D
+ case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_TRUE:=0D
+ PpiFlags->PPFlags |=3D TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_CLEAR;=0D
+ return 0;=0D
+=0D
+ case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_FALSE:=0D
+ PpiFlags->PPFlags &=3D ~TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_MAINTENA=
NCE;=0D
+ return 0;=0D
+=0D
+ case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_TRUE:=0D
+ PpiFlags->PPFlags |=3D TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_MAINTENAN=
CE;=0D
+ return 0;=0D
+=0D
+ case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR:=0D
+ //=0D
+ // PHYSICAL_PRESENCE_ENABLE_ACTIVATE + PHYSICAL_PRESENCE_CLEAR=0D
+ // PHYSICAL_PRESENCE_CLEAR will be executed after reboot.=0D
+ //=0D
+ if ((PpiFlags->PPFlags & TCG_VENDOR_LIB_FLAG_RESET_TRACK) =3D=3D 0) =
{=0D
+ TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRE=
SENCE_ENABLE_ACTIVATE, PpiFlags);=0D
+ PpiFlags->PPFlags |=3D TCG_VENDOR_LIB_FLAG_RESET_TRACK;=0D
+ } else {=0D
+ TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRE=
SENCE_CLEAR, PpiFlags);=0D
+ PpiFlags->PPFlags &=3D ~TCG_VENDOR_LIB_FLAG_RESET_TRACK;=0D
+ }=0D
+ return TpmResponse;=0D
+=0D
+ case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE:=0D
+ //=0D
+ // PHYSICAL_PRESENCE_ENABLE_ACTIVATE + PHYSICAL_PRESENCE_CLEAR_ENABL=
E_ACTIVATE=0D
+ // PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE will be executed after re=
boot.=0D
+ //=0D
+ if ((PpiFlags->PPFlags & TCG_VENDOR_LIB_FLAG_RESET_TRACK) =3D=3D 0) =
{=0D
+ TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRE=
SENCE_ENABLE_ACTIVATE, PpiFlags);=0D
+ PpiFlags->PPFlags |=3D TCG_VENDOR_LIB_FLAG_RESET_TRACK;=0D
+ } else {=0D
+ TpmResponse =3D ExecutePhysicalPresence (TcgProtocol, PHYSICAL_PRE=
SENCE_CLEAR_ENABLE_ACTIVATE, PpiFlags);=0D
+ PpiFlags->PPFlags &=3D ~TCG_VENDOR_LIB_FLAG_RESET_TRACK;=0D
+ }=0D
+ return TpmResponse;=0D
+=0D
+ default:=0D
+ ;=0D
+ }=0D
+ return TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE;=0D
+}=0D
+=0D
+=0D
+/**=0D
+ Read the specified key for user confirmation.=0D
+=0D
+ @param[in] CautionKey If true, F12 is used as confirm key;=0D
+ If false, F10 is used as confirm key.=0D
+=0D
+ @retval TRUE User confirmed the changes by input.=0D
+ @retval FALSE User discarded the changes or device error.=0D
+=0D
+**/=0D
+BOOLEAN=0D
+ReadUserKey (=0D
+ IN BOOLEAN CautionKey=0D
+ )=0D
+{=0D
+ EFI_STATUS Status;=0D
+ EFI_INPUT_KEY Key;=0D
+ UINT16 InputKey;=0D
+ UINTN Index;=0D
+=0D
+ InputKey =3D 0;=0D
+ do {=0D
+ Status =3D gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);=0D
+ if (Status =3D=3D EFI_NOT_READY) {=0D
+ gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &Index);=0D
+ continue;=0D
+ }=0D
+=0D
+ if (Status =3D=3D EFI_DEVICE_ERROR) {=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ if (Key.ScanCode =3D=3D SCAN_ESC) {=0D
+ InputKey =3D Key.ScanCode;=0D
+ }=0D
+ if ((Key.ScanCode =3D=3D SCAN_F10) && !CautionKey) {=0D
+ InputKey =3D Key.ScanCode;=0D
+ }=0D
+ if ((Key.ScanCode =3D=3D SCAN_F12) && CautionKey) {=0D
+ InputKey =3D Key.ScanCode;=0D
+ }=0D
+ } while (InputKey =3D=3D 0);=0D
+=0D
+ if (InputKey !=3D SCAN_ESC) {=0D
+ return TRUE;=0D
+ }=0D
+=0D
+ return FALSE;=0D
+}=0D
+=0D
+/**=0D
+ The constructor function register UNI strings into imageHandle.=0D
+=0D
+ It will ASSERT() if that operation fails and it will always return EFI_S=
UCCESS.=0D
+=0D
+ @param ImageHandle The firmware allocated handle for the EFI image.=0D
+ @param SystemTable A pointer to the EFI System Table.=0D
+=0D
+ @retval EFI_SUCCESS The constructor successfully added string package.=
=0D
+ @retval Other value The constructor can't add string package.=0D
+=0D
+**/=0D
+EFI_STATUS=0D
+EFIAPI=0D
+TcgPhysicalPresenceLibConstructor (=0D
+ IN EFI_HANDLE ImageHandle,=0D
+ IN EFI_SYSTEM_TABLE *SystemTable=0D
+ )=0D
+{=0D
+ mPpStringPackHandle =3D HiiAddPackages (&gEfiPhysicalPresenceGuid, Image=
Handle, DxeTcgPhysicalPresenceLibStrings, NULL);=0D
+ ASSERT (mPpStringPackHandle !=3D NULL);=0D
+=0D
+ return EFI_SUCCESS;=0D
+}=0D
+=0D
+/**=0D
+ Display the confirm text and get user confirmation.=0D
+=0D
+ @param[in] TpmPpCommand The requested TPM physical presence command.=0D
+=0D
+ @retval TRUE The user has confirmed the changes.=0D
+ @retval FALSE The user doesn't confirm the changes.=0D
+**/=0D
+BOOLEAN=0D
+UserConfirm (=0D
+ IN UINT32 TpmPpCommand=0D
+ )=0D
+{=0D
+ CHAR16 *ConfirmText;=0D
+ CHAR16 *TmpStr1;=0D
+ CHAR16 *TmpStr2;=0D
+ UINTN BufSize;=0D
+ BOOLEAN CautionKey;=0D
+ UINT16 Index;=0D
+ CHAR16 DstStr[81];=0D
+=0D
+ TmpStr2 =3D NULL;=0D
+ CautionKey =3D FALSE;=0D
+ BufSize =3D CONFIRM_BUFFER_SIZE;=0D
+ ConfirmText =3D AllocateZeroPool (BufSize);=0D
+ ASSERT (ConfirmText !=3D NULL);=0D
+=0D
+ switch (TpmPpCommand) {=0D
+ case PHYSICAL_PRESENCE_ENABLE:=0D
+ TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ENABLE)=
);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST=
R));=0D
+ UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_=
KEY));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+ break;=0D
+=0D
+ case PHYSICAL_PRESENCE_DISABLE:=0D
+ TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_DISABLE=
));=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST=
R));=0D
+ UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING=
));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_=
KEY));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+ break;=0D
+=0D
+ case PHYSICAL_PRESENCE_ACTIVATE:=0D
+ TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACTIVAT=
E));=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST=
R));=0D
+ UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_=
KEY));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+ break;=0D
+=0D
+ case PHYSICAL_PRESENCE_DEACTIVATE:=0D
+ TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_DEACTIV=
ATE));=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST=
R));=0D
+ UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING=
));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_=
KEY));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+ break;=0D
+=0D
+ case PHYSICAL_PRESENCE_CLEAR:=0D
+ CautionKey =3D TRUE;=0D
+ TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CLEAR))=
;=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST=
R));=0D
+ UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING=
_CLEAR));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), L" \n\n", (BufSize=
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION=
_KEY));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+ break;=0D
+=0D
+ case PHYSICAL_PRESENCE_ENABLE_ACTIVATE:=0D
+ TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ENABLE_=
ACTIVATE));=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST=
R));=0D
+ UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_ON=
));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_=
KEY));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+ break;=0D
+=0D
+ case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE:=0D
+ TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_DEACTIV=
ATE_DISABLE));=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST=
R));=0D
+ UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_OF=
F));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING=
));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_=
KEY));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+ break;=0D
+=0D
+ case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE:=0D
+ TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ALLOW_T=
AKE_OWNERSHIP));=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST=
R));=0D
+ UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_=
KEY));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+ break;=0D
+=0D
+ case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_FALSE:=0D
+ TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_DISALLO=
W_TAKE_OWNERSHIP));=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST=
R));=0D
+ UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_=
KEY));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+ break;=0D
+=0D
+ case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_OWNER_TRUE:=0D
+ TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_TURN_ON=
));=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST=
R));=0D
+ UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_ON=
));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_=
KEY));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+ break;=0D
+=0D
+ case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE_OWNER_FALSE:=0D
+ TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_TURN_OF=
F));=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST=
R));=0D
+ UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_OF=
F));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING=
));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_=
KEY));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+ break;=0D
+=0D
+ case PHYSICAL_PRESENCE_DEFERRED_PP_UNOWNERED_FIELD_UPGRADE:=0D
+ CautionKey =3D TRUE;=0D
+ TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_UNOWNED=
_FIELD_UPGRADE));=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_UPGRADE=
_HEAD_STR));=0D
+ UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING=
_MAINTAIN));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION=
_KEY));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+ break;=0D
+=0D
+ case PHYSICAL_PRESENCE_SET_OPERATOR_AUTH:=0D
+ //=0D
+ // TPM_SetOperatorAuth=0D
+ // This command requires UI to prompt user for Auth data=0D
+ // Here it is NOT implemented=0D
+ //=0D
+ break;=0D
+=0D
+ case PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE:=0D
+ CautionKey =3D TRUE;=0D
+ TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CLEAR_T=
URN_ON));=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST=
R));=0D
+ UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_ON=
));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING=
_CLEAR));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING=
_CLEAR_CONT));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION=
_KEY));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+ break;=0D
+=0D
+ case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_TRUE:=0D
+ TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NO_PPI_=
PROVISION));=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_PPI_HEA=
D_STR));=0D
+ UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ACCEPT_=
KEY));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NO_PPI_=
INFO));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+ break;=0D
+=0D
+ case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_TRUE:=0D
+ CautionKey =3D TRUE;=0D
+ TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CLEAR))=
;=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_PPI_HEA=
D_STR));=0D
+ UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_CL=
EAR));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING=
_CLEAR));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), L" \n\n", (BufSize=
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION=
_KEY));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NO_PPI_=
INFO));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+ break;=0D
+=0D
+ case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_TRUE:=0D
+ CautionKey =3D TRUE;=0D
+ TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NO_PPI_=
MAINTAIN));=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_PPI_HEA=
D_STR));=0D
+ UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING=
_MAINTAIN));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION=
_KEY));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NO_PPI_=
INFO));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+ break;=0D
+=0D
+ case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR:=0D
+ CautionKey =3D TRUE;=0D
+ TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ENABLE_=
ACTIVATE_CLEAR));=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST=
R));=0D
+ UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING=
_CLEAR));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), L" \n\n", (BufSize=
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION=
_KEY));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+ break;=0D
+=0D
+ case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE:=0D
+ CautionKey =3D TRUE;=0D
+ TmpStr2 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_ENABLE_=
ACTIVATE_CLEAR_ENABLE_ACTIVATE));=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_HEAD_ST=
R));=0D
+ UnicodeSPrint (ConfirmText, BufSize, TmpStr1, TmpStr2);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_NOTE_ON=
));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING=
_CLEAR));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_WARNING=
_CLEAR_CONT));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_CAUTION=
_KEY));=0D
+ StrnCatS (ConfirmText, BufSize / sizeof (CHAR16), TmpStr1, (BufSize =
/ sizeof (CHAR16)) - StrLen (ConfirmText) - 1);=0D
+ FreePool (TmpStr1);=0D
+ break;=0D
+=0D
+ default:=0D
+ ;=0D
+ }=0D
+=0D
+ if (TmpStr2 =3D=3D NULL) {=0D
+ FreePool (ConfirmText);=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ TmpStr1 =3D PhysicalPresenceGetStringById (STRING_TOKEN (TPM_REJECT_KEY)=
);=0D
+ BufSize -=3D StrSize (ConfirmText);=0D
+ UnicodeSPrint (ConfirmText + StrLen (ConfirmText), BufSize, TmpStr1, Tmp=
Str2);=0D
+=0D
+ DstStr[80] =3D L'\0';=0D
+ for (Index =3D 0; Index < StrLen (ConfirmText); Index +=3D 80) {=0D
+ StrnCpyS(DstStr, sizeof (DstStr) / sizeof (CHAR16), ConfirmText + Inde=
x, sizeof (DstStr) / sizeof (CHAR16) - 1);=0D
+ Print (DstStr);=0D
+ }=0D
+=0D
+ FreePool (TmpStr1);=0D
+ FreePool (TmpStr2);=0D
+ FreePool (ConfirmText);=0D
+=0D
+ if (ReadUserKey (CautionKey)) {=0D
+ return TRUE;=0D
+ }=0D
+=0D
+ return FALSE;=0D
+}=0D
+=0D
+/**=0D
+ Check if there is a valid physical presence command request. Also update=
s parameter value=0D
+ to whether the requested physical presence command already confirmed by =
user=0D
+=0D
+ @param[in] TcgPpData EFI TCG Physical Presence request data.=
=0D
+ @param[in] Flags The physical presence interface flags.=
=0D
+ @param[out] RequestConfirmed If the physical presence operation comm=
and required user confirm from UI.=0D
+ True, it indicates the command doesn't =
require user confirm, or already confirmed=0D
+ in last boot cycle by user.=0D
+ False, it indicates the command need us=
er confirm from UI.=0D
+=0D
+ @retval TRUE Physical Presence operation command is valid.=0D
+ @retval FALSE Physical Presence operation command is invalid.=0D
+=0D
+**/=0D
+BOOLEAN=0D
+HaveValidTpmRequest (=0D
+ IN EFI_PHYSICAL_PRESENCE *TcgPpData,=0D
+ IN EFI_PHYSICAL_PRESENCE_FLAGS Flags,=0D
+ OUT BOOLEAN *RequestConfirmed=0D
+ )=0D
+{=0D
+ BOOLEAN IsRequestValid;=0D
+=0D
+ *RequestConfirmed =3D FALSE;=0D
+=0D
+ switch (TcgPpData->PPRequest) {=0D
+ case PHYSICAL_PRESENCE_NO_ACTION:=0D
+ *RequestConfirmed =3D TRUE;=0D
+ return TRUE;=0D
+ case PHYSICAL_PRESENCE_ENABLE:=0D
+ case PHYSICAL_PRESENCE_DISABLE:=0D
+ case PHYSICAL_PRESENCE_ACTIVATE:=0D
+ case PHYSICAL_PRESENCE_DEACTIVATE:=0D
+ case PHYSICAL_PRESENCE_ENABLE_ACTIVATE:=0D
+ case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE:=0D
+ case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_TRUE:=0D
+ case PHYSICAL_PRESENCE_SET_OWNER_INSTALL_FALSE:=0D
+ case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_OWNER_TRUE:=0D
+ case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE_OWNER_FALSE:=0D
+ case PHYSICAL_PRESENCE_SET_OPERATOR_AUTH:=0D
+ if ((Flags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION) =
!=3D 0) {=0D
+ *RequestConfirmed =3D TRUE;=0D
+ }=0D
+ break;=0D
+=0D
+ case PHYSICAL_PRESENCE_CLEAR:=0D
+ case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR:=0D
+ if ((Flags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_CLEAR) !=3D=
0) {=0D
+ *RequestConfirmed =3D TRUE;=0D
+ }=0D
+ break;=0D
+=0D
+ case PHYSICAL_PRESENCE_DEFERRED_PP_UNOWNERED_FIELD_UPGRADE:=0D
+ if ((Flags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_MAINTENANCE=
) !=3D 0) {=0D
+ *RequestConfirmed =3D TRUE;=0D
+ }=0D
+ break;=0D
+=0D
+ case PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE:=0D
+ case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE:=0D
+ if ((Flags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_CLEAR) !=3D=
0 && (Flags.PPFlags & TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION) !=3D =
0) {=0D
+ *RequestConfirmed =3D TRUE;=0D
+ }=0D
+ break;=0D
+=0D
+ case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_FALSE:=0D
+ case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_FALSE:=0D
+ case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_FALSE:=0D
+ *RequestConfirmed =3D TRUE;=0D
+ break;=0D
+=0D
+ case PHYSICAL_PRESENCE_SET_NO_PPI_PROVISION_TRUE:=0D
+ case PHYSICAL_PRESENCE_SET_NO_PPI_CLEAR_TRUE:=0D
+ case PHYSICAL_PRESENCE_SET_NO_PPI_MAINTENANCE_TRUE:=0D
+ break;=0D
+=0D
+ default:=0D
+ if (TcgPpData->PPRequest >=3D TCG_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_=
OPERATION) {=0D
+ IsRequestValid =3D TcgPpVendorLibHasValidRequest (TcgPpData->PPReq=
uest, Flags.PPFlags, RequestConfirmed);=0D
+ if (!IsRequestValid) {=0D
+ return FALSE;=0D
+ } else {=0D
+ break;=0D
+ }=0D
+ } else {=0D
+ //=0D
+ // Wrong Physical Presence command=0D
+ //=0D
+ return FALSE;=0D
+ }=0D
+ }=0D
+=0D
+ if ((Flags.PPFlags & TCG_VENDOR_LIB_FLAG_RESET_TRACK) !=3D 0) {=0D
+ //=0D
+ // It had been confirmed in last boot, it doesn't need confirm again.=
=0D
+ //=0D
+ *RequestConfirmed =3D TRUE;=0D
+ }=0D
+=0D
+ //=0D
+ // Physical Presence command is correct=0D
+ //=0D
+ return TRUE;=0D
+}=0D
+=0D
+=0D
+/**=0D
+ Check and execute the requested physical presence command.=0D
+=0D
+ Caution: This function may receive untrusted input.=0D
+ TcgPpData variable is external input, so this function will validate=0D
+ its data structure to be valid value.=0D
+=0D
+ @param[in] TcgProtocol EFI TCG Protocol instance.=0D
+ @param[in] TcgPpData Point to the physical presence NV variab=
le.=0D
+ @param[in] Flags The physical presence interface flags.=0D
+=0D
+**/=0D
+VOID=0D
+ExecutePendingTpmRequest (=0D
+ IN EFI_TCG_PROTOCOL *TcgProtocol,=0D
+ IN EFI_PHYSICAL_PRESENCE *TcgPpData,=0D
+ IN EFI_PHYSICAL_PRESENCE_FLAGS Flags=0D
+ )=0D
+{=0D
+ EFI_STATUS Status;=0D
+ UINTN DataSize;=0D
+ BOOLEAN RequestConfirmed;=0D
+ EFI_PHYSICAL_PRESENCE_FLAGS NewFlags;=0D
+ BOOLEAN ResetRequired;=0D
+ UINT32 NewPPFlags;=0D
+=0D
+ if (!HaveValidTpmRequest(TcgPpData, Flags, &RequestConfirmed)) {=0D
+ //=0D
+ // Invalid operation request.=0D
+ //=0D
+ TcgPpData->PPResponse =3D TCG_PP_OPERATION_RESPONSE_BIOS_FAILURE;=0D
+ TcgPpData->LastPPRequest =3D TcgPpData->PPRequest;=0D
+ TcgPpData->PPRequest =3D PHYSICAL_PRESENCE_NO_ACTION;=0D
+ DataSize =3D sizeof (EFI_PHYSICAL_PRESENCE);=0D
+ Status =3D gRT->SetVariable (=0D
+ PHYSICAL_PRESENCE_VARIABLE,=0D
+ &gEfiPhysicalPresenceGuid,=0D
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_A=
CCESS | EFI_VARIABLE_RUNTIME_ACCESS,=0D
+ DataSize,=0D
+ TcgPpData=0D
+ );=0D
+ return;=0D
+ }=0D
+=0D
+ ResetRequired =3D FALSE;=0D
+ if (TcgPpData->PPRequest >=3D TCG_PHYSICAL_PRESENCE_VENDOR_SPECIFIC_OPER=
ATION) {=0D
+ NewFlags =3D Flags;=0D
+ NewPPFlags =3D NewFlags.PPFlags;=0D
+ TcgPpData->PPResponse =3D TcgPpVendorLibExecutePendingRequest (TcgPpDa=
ta->PPRequest, &NewPPFlags, &ResetRequired);=0D
+ NewFlags.PPFlags =3D (UINT8)NewPPFlags;=0D
+ } else {=0D
+ if (!RequestConfirmed) {=0D
+ //=0D
+ // Print confirm text and wait for approval.=0D
+ //=0D
+ RequestConfirmed =3D UserConfirm (TcgPpData->PPRequest);=0D
+ }=0D
+=0D
+ //=0D
+ // Execute requested physical presence command=0D
+ //=0D
+ TcgPpData->PPResponse =3D TCG_PP_OPERATION_RESPONSE_USER_ABORT;=0D
+ NewFlags =3D Flags;=0D
+ if (RequestConfirmed) {=0D
+ TcgPpData->PPResponse =3D ExecutePhysicalPresence (TcgProtocol, TcgP=
pData->PPRequest, &NewFlags);=0D
+ }=0D
+ }=0D
+=0D
+ //=0D
+ // Save the flags if it is updated.=0D
+ //=0D
+ if (CompareMem (&Flags, &NewFlags, sizeof(EFI_PHYSICAL_PRESENCE_FLAGS)) =
!=3D 0) {=0D
+ Status =3D gRT->SetVariable (=0D
+ PHYSICAL_PRESENCE_FLAGS_VARIABLE,=0D
+ &gEfiPhysicalPresenceGuid,=0D
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE=
_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,=0D
+ sizeof (EFI_PHYSICAL_PRESENCE_FLAGS),=0D
+ &NewFlags=0D
+ );=0D
+ if (EFI_ERROR (Status)) {=0D
+ return;=0D
+ }=0D
+ }=0D
+=0D
+ //=0D
+ // Clear request=0D
+ //=0D
+ if ((NewFlags.PPFlags & TCG_VENDOR_LIB_FLAG_RESET_TRACK) =3D=3D 0) {=0D
+ TcgPpData->LastPPRequest =3D TcgPpData->PPRequest;=0D
+ TcgPpData->PPRequest =3D PHYSICAL_PRESENCE_NO_ACTION;=0D
+ }=0D
+=0D
+ //=0D
+ // Save changes=0D
+ //=0D
+ DataSize =3D sizeof (EFI_PHYSICAL_PRESENCE);=0D
+ Status =3D gRT->SetVariable (=0D
+ PHYSICAL_PRESENCE_VARIABLE,=0D
+ &gEfiPhysicalPresenceGuid,=0D
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACC=
ESS | EFI_VARIABLE_RUNTIME_ACCESS,=0D
+ DataSize,=0D
+ TcgPpData=0D
+ );=0D
+ if (EFI_ERROR (Status)) {=0D
+ return;=0D
+ }=0D
+=0D
+ if (TcgPpData->PPResponse =3D=3D TCG_PP_OPERATION_RESPONSE_USER_ABORT) {=
=0D
+ return;=0D
+ }=0D
+=0D
+ //=0D
+ // Reset system to make new TPM settings in effect=0D
+ //=0D
+ switch (TcgPpData->LastPPRequest) {=0D
+ case PHYSICAL_PRESENCE_ACTIVATE:=0D
+ case PHYSICAL_PRESENCE_DEACTIVATE:=0D
+ case PHYSICAL_PRESENCE_CLEAR:=0D
+ case PHYSICAL_PRESENCE_ENABLE_ACTIVATE:=0D
+ case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE:=0D
+ case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_OWNER_TRUE:=0D
+ case PHYSICAL_PRESENCE_DEACTIVATE_DISABLE_OWNER_FALSE:=0D
+ case PHYSICAL_PRESENCE_DEFERRED_PP_UNOWNERED_FIELD_UPGRADE:=0D
+ case PHYSICAL_PRESENCE_CLEAR_ENABLE_ACTIVATE:=0D
+ case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR:=0D
+ case PHYSICAL_PRESENCE_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE:=0D
+ break;=0D
+ default:=0D
+ if (TcgPpData->LastPPRequest >=3D TCG_PHYSICAL_PRESENCE_VENDOR_SPECI=
FIC_OPERATION) {=0D
+ if (ResetRequired) {=0D
+ break;=0D
+ } else {=0D
+ return ;=0D
+ }=0D
+ }=0D
+ if (TcgPpData->PPRequest !=3D PHYSICAL_PRESENCE_NO_ACTION) {=0D
+ break;=0D
+ }=0D
+ return;=0D
+ }=0D
+=0D
+ Print (L"Rebooting system to make TPM settings in effect\n");=0D
+ gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);=0D
+ ASSERT (FALSE);=0D
+}=0D
+=0D
+/**=0D
+ Check and execute the pending TPM request and Lock TPM.=0D
+=0D
+ The TPM request may come from OS or BIOS. This API will display request =
information and wait=0D
+ for user confirmation if TPM request exists. The TPM request will be sen=
t to TPM device after=0D
+ the TPM request is confirmed, and one or more reset may be required to m=
ake TPM request to=0D
+ take effect. At last, it will lock TPM to prevent TPM state change by ma=
lware.=0D
+=0D
+ This API should be invoked after console in and console out are all read=
y as they are required=0D
+ to display request information and get user input to confirm the request=
. This API should also=0D
+ be invoked as early as possible as TPM is locked in this function.=0D
+=0D
+**/=0D
+VOID=0D
+EFIAPI=0D
+TcgPhysicalPresenceLibProcessRequest (=0D
+ VOID=0D
+ )=0D
+{=0D
+ EFI_STATUS Status;=0D
+ BOOLEAN LifetimeLock;=0D
+ BOOLEAN CmdEnable;=0D
+ UINTN DataSize;=0D
+ EFI_PHYSICAL_PRESENCE TcgPpData;=0D
+ EFI_TCG_PROTOCOL *TcgProtocol;=0D
+ EDKII_VARIABLE_LOCK_PROTOCOL *VariableLockProtocol;=0D
+ EFI_PHYSICAL_PRESENCE_FLAGS PpiFlags;=0D
+=0D
+ Status =3D gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **)&Tc=
gProtocol);=0D
+ if (EFI_ERROR (Status)) {=0D
+ return ;=0D
+ }=0D
+=0D
+ //=0D
+ // Initialize physical presence flags.=0D
+ //=0D
+ DataSize =3D sizeof (EFI_PHYSICAL_PRESENCE_FLAGS);=0D
+ Status =3D gRT->GetVariable (=0D
+ PHYSICAL_PRESENCE_FLAGS_VARIABLE,=0D
+ &gEfiPhysicalPresenceGuid,=0D
+ NULL,=0D
+ &DataSize,=0D
+ &PpiFlags=0D
+ );=0D
+ if (EFI_ERROR (Status)) {=0D
+ PpiFlags.PPFlags =3D TCG_BIOS_TPM_MANAGEMENT_FLAG_NO_PPI_PROVISION;=0D
+ Status =3D gRT->SetVariable (=0D
+ PHYSICAL_PRESENCE_FLAGS_VARIABLE,=0D
+ &gEfiPhysicalPresenceGuid,=0D
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE=
_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,=0D
+ sizeof (EFI_PHYSICAL_PRESENCE_FLAGS),=0D
+ &PpiFlags=0D
+ );=0D
+ if (EFI_ERROR (Status)) {=0D
+ DEBUG ((DEBUG_ERROR, "[TPM] Set physical presence flag failed, Statu=
s =3D %r\n", Status));=0D
+ return ;=0D
+ }=0D
+ }=0D
+ DEBUG ((DEBUG_INFO, "[TPM] PpiFlags =3D %x\n", PpiFlags.PPFlags));=0D
+=0D
+ //=0D
+ // This flags variable controls whether physical presence is required fo=
r TPM command.=0D
+ // It should be protected from malicious software. We set it as read-onl=
y variable here.=0D
+ //=0D
+ Status =3D gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (=
VOID **)&VariableLockProtocol);=0D
+ if (!EFI_ERROR (Status)) {=0D
+ Status =3D VariableLockProtocol->RequestToLock (=0D
+ VariableLockProtocol,=0D
+ PHYSICAL_PRESENCE_FLAGS_VARIABLE,=0D
+ &gEfiPhysicalPresenceGuid=0D
+ );=0D
+ if (EFI_ERROR (Status)) {=0D
+ DEBUG ((DEBUG_ERROR, "[TPM] Error when lock variable %s, Status =3D =
%r\n", PHYSICAL_PRESENCE_FLAGS_VARIABLE, Status));=0D
+ ASSERT_EFI_ERROR (Status);=0D
+ }=0D
+ }=0D
+=0D
+ //=0D
+ // Initialize physical presence variable.=0D
+ //=0D
+ DataSize =3D sizeof (EFI_PHYSICAL_PRESENCE);=0D
+ Status =3D gRT->GetVariable (=0D
+ PHYSICAL_PRESENCE_VARIABLE,=0D
+ &gEfiPhysicalPresenceGuid,=0D
+ NULL,=0D
+ &DataSize,=0D
+ &TcgPpData=0D
+ );=0D
+ if (EFI_ERROR (Status)) {=0D
+ ZeroMem ((VOID*)&TcgPpData, sizeof (TcgPpData));=0D
+ DataSize =3D sizeof (EFI_PHYSICAL_PRESENCE);=0D
+ Status =3D gRT->SetVariable (=0D
+ PHYSICAL_PRESENCE_VARIABLE,=0D
+ &gEfiPhysicalPresenceGuid,=0D
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE=
_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,=0D
+ DataSize,=0D
+ &TcgPpData=0D
+ );=0D
+ if (EFI_ERROR (Status)) {=0D
+ DEBUG ((DEBUG_ERROR, "[TPM] Set physical presence variable failed, S=
tatus =3D %r\n", Status));=0D
+ return;=0D
+ }=0D
+ }=0D
+=0D
+ DEBUG ((DEBUG_INFO, "[TPM] Flags=3D%x, PPRequest=3D%x\n", PpiFlags.PPFla=
gs, TcgPpData.PPRequest));=0D
+=0D
+ if (TcgPpData.PPRequest =3D=3D PHYSICAL_PRESENCE_NO_ACTION) {=0D
+ //=0D
+ // No operation request=0D
+ //=0D
+ return;=0D
+ }=0D
+=0D
+ Status =3D GetTpmCapability (TcgProtocol, &LifetimeLock, &CmdEnable);=0D
+ if (EFI_ERROR (Status)) {=0D
+ return ;=0D
+ }=0D
+=0D
+ if (!CmdEnable) {=0D
+ if (LifetimeLock) {=0D
+ //=0D
+ // physicalPresenceCMDEnable is locked, can't execute physical prese=
nce command.=0D
+ //=0D
+ return ;=0D
+ }=0D
+ Status =3D TpmPhysicalPresence (TcgProtocol, TPM_PHYSICAL_PRESENCE_CMD=
_ENABLE);=0D
+ if (EFI_ERROR (Status)) {=0D
+ return ;=0D
+ }=0D
+ }=0D
+=0D
+ //=0D
+ // Set operator physical presence flags=0D
+ //=0D
+ Status =3D TpmPhysicalPresence (TcgProtocol, TPM_PHYSICAL_PRESENCE_PRESE=
NT);=0D
+ if (EFI_ERROR (Status)) {=0D
+ return;=0D
+ }=0D
+=0D
+ //=0D
+ // Execute pending TPM request.=0D
+ //=0D
+ ExecutePendingTpmRequest (TcgProtocol, &TcgPpData, PpiFlags);=0D
+ DEBUG ((DEBUG_INFO, "[TPM] PPResponse =3D %x\n", TcgPpData.PPResponse));=
=0D
+=0D
+ //=0D
+ // Lock physical presence.=0D
+ //=0D
+ TpmPhysicalPresence (TcgProtocol, TPM_PHYSICAL_PRESENCE_NOTPRESENT | TPM=
_PHYSICAL_PRESENCE_LOCK);=0D
+}=0D
+=0D
+/**=0D
+ Check if the pending TPM request needs user input to confirm.=0D
+=0D
+ The TPM request may come from OS. This API will check if TPM request exi=
sts and need user=0D
+ input to confirmation.=0D
+=0D
+ @retval TRUE TPM needs input to confirm user physical presence=
.=0D
+ @retval FALSE TPM doesn't need input to confirm user physical p=
resence.=0D
+=0D
+**/=0D
+BOOLEAN=0D
+EFIAPI=0D
+TcgPhysicalPresenceLibNeedUserConfirm(=0D
+ VOID=0D
+ )=0D
+{=0D
+ EFI_STATUS Status;=0D
+ EFI_PHYSICAL_PRESENCE TcgPpData;=0D
+ UINTN DataSize;=0D
+ BOOLEAN RequestConfirmed;=0D
+ BOOLEAN LifetimeLock;=0D
+ BOOLEAN CmdEnable;=0D
+ EFI_TCG_PROTOCOL *TcgProtocol;=0D
+ EFI_PHYSICAL_PRESENCE_FLAGS PpiFlags;=0D
+=0D
+ Status =3D gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **)&Tc=
gProtocol);=0D
+ if (EFI_ERROR (Status)) {=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ //=0D
+ // Check Tpm requests=0D
+ //=0D
+ DataSize =3D sizeof (EFI_PHYSICAL_PRESENCE);=0D
+ Status =3D gRT->GetVariable (=0D
+ PHYSICAL_PRESENCE_VARIABLE,=0D
+ &gEfiPhysicalPresenceGuid,=0D
+ NULL,=0D
+ &DataSize,=0D
+ &TcgPpData=0D
+ );=0D
+ if (EFI_ERROR (Status)) {=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ DataSize =3D sizeof (EFI_PHYSICAL_PRESENCE_FLAGS);=0D
+ Status =3D gRT->GetVariable (=0D
+ PHYSICAL_PRESENCE_FLAGS_VARIABLE,=0D
+ &gEfiPhysicalPresenceGuid,=0D
+ NULL,=0D
+ &DataSize,=0D
+ &PpiFlags=0D
+ );=0D
+ if (EFI_ERROR (Status)) {=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ if (TcgPpData.PPRequest =3D=3D PHYSICAL_PRESENCE_NO_ACTION) {=0D
+ //=0D
+ // No operation request=0D
+ //=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ if (!HaveValidTpmRequest(&TcgPpData, PpiFlags, &RequestConfirmed)) {=0D
+ //=0D
+ // Invalid operation request.=0D
+ //=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ //=0D
+ // Check Tpm Capability=0D
+ //=0D
+ Status =3D GetTpmCapability (TcgProtocol, &LifetimeLock, &CmdEnable);=0D
+ if (EFI_ERROR (Status)) {=0D
+ return FALSE;=0D
+ }=0D
+=0D
+ if (!CmdEnable) {=0D
+ if (LifetimeLock) {=0D
+ //=0D
+ // physicalPresenceCMDEnable is locked, can't execute physical prese=
nce command.=0D
+ //=0D
+ return FALSE;=0D
+ }=0D
+ }=0D
+=0D
+ if (!RequestConfirmed) {=0D
+ //=0D
+ // Need UI to confirm=0D
+ //=0D
+ return TRUE;=0D
+ }=0D
+=0D
+ return FALSE;=0D
+}=0D
+=0D
+/**=0D
+ The handler for TPM physical presence function:=0D
+ Submit TPM Operation Request to Pre-OS Environment and=0D
+ Submit TPM Operation Request to Pre-OS Environment 2.=0D
+=0D
+ Caution: This function may receive untrusted input.=0D
+=0D
+ @param[in] OperationRequest TPM physical presence operation request=
.=0D
+=0D
+ @return Return Code for Submit TPM Operation Request to Pre-OS Environme=
nt and=0D
+ Submit TPM Operation Request to Pre-OS Environment 2.=0D
+**/=0D
+UINT32=0D
+EFIAPI=0D
+TcgPhysicalPresenceLibSubmitRequestToPreOSFunction (=0D
+ IN UINT32 OperationRequest=0D
+ )=0D
+{=0D
+ EFI_STATUS Status;=0D
+ UINTN DataSize;=0D
+ EFI_PHYSICAL_PRESENCE PpData;=0D
+=0D
+ DEBUG ((DEBUG_INFO, "[TPM] SubmitRequestToPreOSFunction, Request =3D %x\=
n", OperationRequest));=0D
+=0D
+ //=0D
+ // Get the Physical Presence variable=0D
+ //=0D
+ DataSize =3D sizeof (EFI_PHYSICAL_PRESENCE);=0D
+ Status =3D gRT->GetVariable (=0D
+ PHYSICAL_PRESENCE_VARIABLE,=0D
+ &gEfiPhysicalPresenceGuid,=0D
+ NULL,=0D
+ &DataSize,=0D
+ &PpData=0D
+ );=0D
+ if (EFI_ERROR (Status)) {=0D
+ DEBUG ((DEBUG_ERROR, "[TPM] Get PP variable failure! Status =3D %r\n",=
Status));=0D
+ return TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE;=0D
+ }=0D
+=0D
+ PpData.PPRequest =3D (UINT8)OperationRequest;=0D
+ Status =3D gRT->SetVariable (=0D
+ PHYSICAL_PRESENCE_VARIABLE,=0D
+ &gEfiPhysicalPresenceGuid,=0D
+ EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_A=
CCESS | EFI_VARIABLE_RUNTIME_ACCESS,=0D
+ DataSize,=0D
+ &PpData=0D
+ );=0D
+ if (EFI_ERROR (Status)) {=0D
+ DEBUG ((DEBUG_ERROR, "[TPM] Set PP variable failure! Status =3D %r\n",=
Status));=0D
+ return TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE;=0D
+ }=0D
+=0D
+ return TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS;=0D
+}=0D
diff --git a/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPrese=
nceLib.inf b/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPrese=
nceLib.inf
new file mode 100644
index 0000000000..cfe14f20ca
--- /dev/null
+++ b/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.=
inf
@@ -0,0 +1,64 @@
+## @file=0D
+# Executes pending TPM 1.2 requests from OS or BIOS and Locks TPM=0D
+#=0D
+# This library will check and execute TPM 1.2 request from OS or BIOS. Th=
e request may=0D
+# ask for user confirmation before execution. This Library will also lock=
TPM physical=0D
+# presence at last.=0D
+#=0D
+# Caution: This module requires additional review when modified.=0D
+# This driver will have external input - variable.=0D
+# This external input must be validated carefully to avoid security issue=
.=0D
+#=0D
+# Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>=0D
+# SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+#=0D
+##=0D
+=0D
+[Defines]=0D
+ INF_VERSION =3D 0x00010005=0D
+ BASE_NAME =3D DxeTcgPhysicalPresenceLib=0D
+ MODULE_UNI_FILE =3D DxeTcgPhysicalPresenceLib.uni=0D
+ FILE_GUID =3D EBC43A46-34AC-4F07-A7F5-A5394619361C=
=0D
+ MODULE_TYPE =3D DXE_DRIVER=0D
+ VERSION_STRING =3D 1.0=0D
+ LIBRARY_CLASS =3D TcgPhysicalPresenceLib|DXE_DRIVER DXE=
_RUNTIME_DRIVER UEFI_APPLICATION UEFI_DRIVER=0D
+ CONSTRUCTOR =3D TcgPhysicalPresenceLibConstructor=0D
+=0D
+#=0D
+# The following information is for reference only and not required by the =
build tools.=0D
+#=0D
+# VALID_ARCHITECTURES =3D IA32 X64 EBC=0D
+#=0D
+=0D
+[Sources]=0D
+ DxeTcgPhysicalPresenceLib.c=0D
+ PhysicalPresenceStrings.uni=0D
+=0D
+[Packages]=0D
+ MdePkg/MdePkg.dec=0D
+ MdeModulePkg/MdeModulePkg.dec=0D
+ SecurityPkg/SecurityPkg.dec=0D
+=0D
+[LibraryClasses]=0D
+ MemoryAllocationLib=0D
+ UefiLib=0D
+ UefiBootServicesTableLib=0D
+ UefiDriverEntryPoint=0D
+ UefiRuntimeServicesTableLib=0D
+ BaseMemoryLib=0D
+ DebugLib=0D
+ PrintLib=0D
+ HiiLib=0D
+ TcgPpVendorLib=0D
+=0D
+[Protocols]=0D
+ gEfiTcgProtocolGuid ## SOMETIMES_CONSUMES=0D
+ gEdkiiVariableLockProtocolGuid ## SOMETIMES_CONSUMES=0D
+=0D
+[Guids]=0D
+ ## SOMETIMES_CONSUMES ## HII=0D
+ ## SOMETIMES_PRODUCES ## Variable:L"PhysicalPresence"=0D
+ ## SOMETIMES_CONSUMES ## Variable:L"PhysicalPresence"=0D
+ ## SOMETIMES_PRODUCES ## Variable:L"PhysicalPresenceFlags"=0D
+ ## SOMETIMES_CONSUMES ## Variable:L"PhysicalPresenceFlags"=0D
+ gEfiPhysicalPresenceGuid=0D
diff --git a/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPrese=
nceLib.uni b/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPrese=
nceLib.uni
new file mode 100644
index 0000000000..c7fcca5c65
--- /dev/null
+++ b/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.=
uni
@@ -0,0 +1,22 @@
+// /** @file=0D
+// Executes pending TPM 1.2 requests from OS or BIOS and Locks TPM=0D
+//=0D
+// This library will check and execute TPM 1.2 request from OS or BIOS. Th=
e request may=0D
+// ask for user confirmation before execution. This Library will also lock=
TPM physical=0D
+// presence at last.=0D
+//=0D
+// Caution: This module requires additional review when modified.=0D
+// This driver will have external input - variable.=0D
+// This external input must be validated carefully to avoid security issue=
.=0D
+//=0D
+// Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>=
=0D
+//=0D
+// SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+//=0D
+// **/=0D
+=0D
+=0D
+#string STR_MODULE_ABSTRACT #language en-US "Executes pending =
TPM 1.2 requests from OS or BIOS and Locks TPM"=0D
+=0D
+#string STR_MODULE_DESCRIPTION #language en-US "This library will=
ask for user confirmation for the pending TPM physical present requests. O=
nce confirmed, it will execute the request, and locks TPM physical presence=
at last. Caution: This module requires additional review when modified. Th=
is driver will have external input - variable. This external input must be =
validated carefully to avoid security issue."=0D
+=0D
diff --git a/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/PhysicalPresenceStr=
ings.uni b/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/PhysicalPresenceStrin=
gs.uni
new file mode 100644
index 0000000000..9d17432ef8
--- /dev/null
+++ b/OvmfPkg/Library/TcgPhysicalPresenceLibQemu/PhysicalPresenceStrings.uni
@@ -0,0 +1,46 @@
+/** @file=0D
+ String definitions for TPM 1.2 physical presence confirm text.=0D
+=0D
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>=0D
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>=0D
+SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+=0D
+**/=0D
+=0D
+#langdef en-US "English"=0D
+=0D
+#string TPM_HEAD_STR #language en-US "A configuration =
change was requested to %s this computer's TPM (Trusted Platform Module)\n\=
n"=0D
+#string TPM_PPI_HEAD_STR #language en-US "A configuration =
change was requested to allow the Operating System to %s the computer's TPM=
(Trusted Platform Module) without asking for user confirmation in the futu=
re.\n\n"=0D
+#string TPM_UPGRADE_HEAD_STR #language en-US "A configuration =
change was requested to %s to the TPM's (Trusted Platform Module) firmware.=
\n\n"=0D
+=0D
+#string TPM_ACCEPT_KEY #language en-US "Press F10 "=0D
+#string TPM_CAUTION_KEY #language en-US "Press F12 "=0D
+#string TPM_REJECT_KEY #language en-US "to %s the TPM \n=
Press ESC to reject this change request and continue\n"=0D
+=0D
+#string TPM_ENABLE #language en-US "enable"=0D
+#string TPM_DISABLE #language en-US "disable"=0D
+#string TPM_ACTIVATE #language en-US "activate"=0D
+#string TPM_DEACTIVATE #language en-US "deactivate"=0D
+#string TPM_CLEAR #language en-US "clear"=0D
+#string TPM_ENABLE_ACTIVATE #language en-US "enable and activ=
ate"=0D
+#string TPM_DEACTIVATE_DISABLE #language en-US "deactivate and d=
isable"=0D
+#string TPM_ALLOW_TAKE_OWNERSHIP #language en-US "allow a user to =
take ownership of"=0D
+#string TPM_DISALLOW_TAKE_OWNERSHIP #language en-US "disallow a user =
to take ownership of"=0D
+#string TPM_TURN_ON #language en-US "enable, activate=
, and allow a user to take ownership of"=0D
+#string TPM_TURN_OFF #language en-US "deactivate, disa=
ble, and disallow a user to take ownership of"=0D
+#string TPM_CLEAR_TURN_ON #language en-US "clear, enable, a=
nd activate"=0D
+#string TPM_ENABLE_ACTIVATE_CLEAR #language en-US "enable, activate=
and clear"=0D
+#string TPM_ENABLE_ACTIVATE_CLEAR_ENABLE_ACTIVATE #language en-US =
"enable, activate, clear, enable, and activate"=0D
+#string TPM_UNOWNED_FIELD_UPGRADE #language en-US "allow field upgr=
ade"=0D
+=0D
+#string TPM_NO_PPI_PROVISION #language en-US "provision"=0D
+#string TPM_NO_PPI_MAINTAIN #language en-US "maintain"=0D
+#string TPM_NO_PPI_INFO #language en-US "to approve futur=
e Operating System requests "=0D
+=0D
+#string TPM_WARNING_MAINTAIN #language en-US "WARNING: Allowin=
g changes to the TPM's firmware may affect the operation of the TPM and may=
erase information stored on the TPM.\nYou may lose all created keys and ac=
cess to data encrypted by these keys.\n\n"=0D
+#string TPM_WARNING #language en-US "WARNING: Doing s=
o might prevent security applications that rely on the TPM from functioning=
as expected\n\n"=0D
+#string TPM_WARNING_CLEAR #language en-US "WARNING: Clearin=
g erases information stored on the TPM. You will lose all created keys and =
access to data encrypted by these keys. "=0D
+#string TPM_WARNING_CLEAR_CONT #language en-US "Take ownership a=
s soon as possible after this step.\n\n"=0D
+#string TPM_NOTE_OFF #language en-US "NOTE: This actio=
n will turn off the TPM\n\n"=0D
+#string TPM_NOTE_ON #language en-US "NOTE: This actio=
n will turn on the TPM\n\n"=0D
+#string TPM_NOTE_CLEAR #language en-US "NOTE: This actio=
n does not clear the TPM, but by approving this configuration change, futur=
e actions to clear the TPM will not require user confirmation.\n\n"=0D
--=20
2.31.1


[PATCH v3 0/8] Add support for TPM 1.2 Physical Presence Interface and Menu

Stefan Berger
 

This series adds support for the full TPM 1.2 Physical Presence Interface
(PPI) and activates the TPM 1.2 menu at the end. PPI is a prerequisite for
the menu to work.

The modifications to the original code are mostly due to the fact that we
are using a memory region for PPI in QEMU. I tried to keep them at a minimum.
For the PPI Flags I am using a EFI variable just like the original code does.
(SecurityPkg/Library/DxeTcgPhysicalPresenceLib/DxeTcgPhysicalPresenceLib.c)

The PhysicalPresenceFlags variable is write-protected (since v3) by adding
an entry to AuthVariableLib.c. The consequence of locking the variable is
that the processing of the physical presence opcodes, and with that
write-access to that variable, had to be moved to before the end-of-DXE
because afterwards it cannot be changed anymore.

Regards,
Stefan

v3:
- Moved processing of physical presence opcodes to before end-of-DXE
- Write-protected PhysicalPresenceFlags variable by entry in AuthVariableLib.c

v2:
- Added patch that copies sources from SecurityPkg to OvmfPkg before changes
- Use CONSTRUCTOR from DxeTcgPhysicalPresenceLib.inf
- Other nits


Gerd Hoffmann (1):
OvmfPkg: add TPM 1.2 config menu

Stefan Berger (7):
OvmfPkg: Move processing of physical presence opcode before End-of-Dxe
OvmfPkg: Check for TPM 2 early to leave function early
SecurityPkg: Store physical presence code by submitting to PreOS func
SecurityPkg: Declare PhysicalPresenceFlags variable and its properties
OvmfPkg: Copy TPM 1.2 DxeTcgPhysicalPresenceLib.c from SecurityPkg
OvmfPkg: Enable physical presence interface for TPM 1.2
OvmfPkg: Enable TPM 1.2 Physical Presence Opcode processing

OvmfPkg/Bhyve/BhyveX64.dsc | 1 +
.../PlatformBootManagerLib/BdsPlatform.c | 23 +-
.../PlatformBootManagerLib.inf | 1 +
.../PlatformBootManagerLibBhyve/BdsPlatform.c | 20 +-
.../PlatformBootManagerLibGrub/BdsPlatform.c | 20 +-
.../DxeTcg2PhysicalPresenceLib.c | 36 +-
.../DxeTcgPhysicalPresenceLib.c | 22 +
.../DxeTcgPhysicalPresenceLib.inf | 27 +
.../DxeTcgPhysicalPresenceLib.c | 1448 +++++++++++++++++
.../DxeTcgPhysicalPresenceLib.inf | 64 +
.../DxeTcgPhysicalPresenceLib.uni | 22 +
.../PhysicalPresenceStrings.uni | 46 +
OvmfPkg/Microvm/MicrovmX64.dsc | 1 +
OvmfPkg/OvmfTpmComponentsDxe.dsc.inc | 1 +
OvmfPkg/OvmfTpmDxe.fdf.inc | 1 +
OvmfPkg/OvmfTpmLibs.dsc.inc | 4 +
OvmfPkg/OvmfXen.dsc | 1 +
.../Include/Library/TcgPhysicalPresenceLib.h | 39 +
.../AuthVariableLib/AuthServiceInternal.h | 1 +
.../Library/AuthVariableLib/AuthVariableLib.c | 11 +
.../AuthVariableLib/AuthVariableLib.inf | 4 +
.../DxeTcgPhysicalPresenceLib.c | 55 +
SecurityPkg/Tcg/TcgConfigDxe/TcgConfigDxe.inf | 1 +
SecurityPkg/Tcg/TcgConfigDxe/TcgConfigImpl.c | 41 +-
24 files changed, 1819 insertions(+), 71 deletions(-)
create mode 100644 OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.c
create mode 100644 OvmfPkg/Library/TcgPhysicalPresenceLibNull/DxeTcgPhysicalPresenceLib.inf
create mode 100644 OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.c
create mode 100644 OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.inf
create mode 100644 OvmfPkg/Library/TcgPhysicalPresenceLibQemu/DxeTcgPhysicalPresenceLib.uni
create mode 100644 OvmfPkg/Library/TcgPhysicalPresenceLibQemu/PhysicalPresenceStrings.uni

--
2.31.1


[PATCH v3 1/8] OvmfPkg: Move processing of physical presence opcode before End-of-Dxe

Stefan Berger
 

For variable creation and locking to work later on we need to
move the processing of the TPM physical presence opcode to before
End-of-Dxe.

Signed-off-by: Stefan Berger <stefanb@...>
---
.../PlatformBootManagerLib/BdsPlatform.c | 20 +++++++++----------
.../PlatformBootManagerLibBhyve/BdsPlatform.c | 18 ++++++++---------
.../PlatformBootManagerLibGrub/BdsPlatform.c | 18 ++++++++---------
3 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c b/OvmfPkg=
/Library/PlatformBootManagerLib/BdsPlatform.c
index 186401296a..2905356fc4 100644
--- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
+++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c
@@ -371,6 +371,16 @@ PlatformBootManagerBeforeConsole (
//=0D
EfiEventGroupSignal (&gRootBridgesConnectedEventGroupGuid);=0D
=0D
+ // We need to connect all trusted consoles for TCG PP. Here we treat all=
=0D
+ // consoles in OVMF to be trusted consoles.=0D
+ PlatformInitializeConsole (=0D
+ XenDetected() ? gXenPlatformConsole : gPlatformConsole);=0D
+=0D
+ //=0D
+ // Process TPM PPI request; this may require keyboard input=0D
+ //=0D
+ Tcg2PhysicalPresenceLibProcessRequest (NULL);=0D
+=0D
//=0D
// We can't signal End-of-Dxe earlier than this. Namely, End-of-Dxe trig=
gers=0D
// the preparation of S3 system information. That logic has a hard depen=
dency=0D
@@ -388,16 +398,6 @@ PlatformBootManagerBeforeConsole (
SaveS3BootScript ();=0D
}=0D
=0D
- // We need to connect all trusted consoles for TCG PP. Here we treat all=
=0D
- // consoles in OVMF to be trusted consoles.=0D
- PlatformInitializeConsole (=0D
- XenDetected() ? gXenPlatformConsole : gPlatformConsole);=0D
-=0D
- //=0D
- // Process TPM PPI request; this may require keyboard input=0D
- //=0D
- Tcg2PhysicalPresenceLibProcessRequest (NULL);=0D
-=0D
//=0D
// Prevent further changes to LockBoxes or SMRAM.=0D
// Any TPM 2 Physical Presence Interface opcode must be handled before.=
=0D
diff --git a/OvmfPkg/Library/PlatformBootManagerLibBhyve/BdsPlatform.c b/Ov=
mfPkg/Library/PlatformBootManagerLibBhyve/BdsPlatform.c
index e767c3b172..950ab12c94 100644
--- a/OvmfPkg/Library/PlatformBootManagerLibBhyve/BdsPlatform.c
+++ b/OvmfPkg/Library/PlatformBootManagerLibBhyve/BdsPlatform.c
@@ -366,15 +366,6 @@ PlatformBootManagerBeforeConsole (
//=0D
EfiEventGroupSignal (&gRootBridgesConnectedEventGroupGuid);=0D
=0D
- //=0D
- // We can't signal End-of-Dxe earlier than this. Namely, End-of-Dxe trig=
gers=0D
- // the preparation of S3 system information. That logic has a hard depen=
dency=0D
- // on the presence of the FACS ACPI table. Since our ACPI tables are onl=
y=0D
- // installed after PCI enumeration completes, we must not trigger the S3=
save=0D
- // earlier, hence we can't signal End-of-Dxe earlier.=0D
- //=0D
- EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);=0D
-=0D
// We need to connect all trusted consoles for TCG PP. Here we treat all=
=0D
// consoles in OVMF to be trusted consoles.=0D
PlatformInitializeConsole (gPlatformConsole);=0D
@@ -384,6 +375,15 @@ PlatformBootManagerBeforeConsole (
//=0D
Tcg2PhysicalPresenceLibProcessRequest (NULL);=0D
=0D
+ //=0D
+ // We can't signal End-of-Dxe earlier than this. Namely, End-of-Dxe trig=
gers=0D
+ // the preparation of S3 system information. That logic has a hard depen=
dency=0D
+ // on the presence of the FACS ACPI table. Since our ACPI tables are onl=
y=0D
+ // installed after PCI enumeration completes, we must not trigger the S3=
save=0D
+ // earlier, hence we can't signal End-of-Dxe earlier.=0D
+ //=0D
+ EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);=0D
+=0D
//=0D
// Prevent further changes to LockBoxes or SMRAM.=0D
// Any TPM 2 Physical Presence Interface opcode must be handled before.=
=0D
diff --git a/OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c b/Ovm=
fPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c
index fd80577355..fbc40dcb68 100644
--- a/OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c
+++ b/OvmfPkg/Library/PlatformBootManagerLibGrub/BdsPlatform.c
@@ -329,15 +329,6 @@ PlatformBootManagerBeforeConsole (
//=0D
EfiEventGroupSignal (&gRootBridgesConnectedEventGroupGuid);=0D
=0D
- //=0D
- // We can't signal End-of-Dxe earlier than this. Namely, End-of-Dxe trig=
gers=0D
- // the preparation of S3 system information. That logic has a hard depen=
dency=0D
- // on the presence of the FACS ACPI table. Since our ACPI tables are onl=
y=0D
- // installed after PCI enumeration completes, we must not trigger the S3=
save=0D
- // earlier, hence we can't signal End-of-Dxe earlier.=0D
- //=0D
- EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);=0D
-=0D
// We need to connect all trusted consoles for TCG PP. Here we treat all=
=0D
// consoles in OVMF to be trusted consoles.=0D
PlatformInitializeConsole (gPlatformConsole);=0D
@@ -347,6 +338,15 @@ PlatformBootManagerBeforeConsole (
//=0D
Tcg2PhysicalPresenceLibProcessRequest (NULL);=0D
=0D
+ //=0D
+ // We can't signal End-of-Dxe earlier than this. Namely, End-of-Dxe trig=
gers=0D
+ // the preparation of S3 system information. That logic has a hard depen=
dency=0D
+ // on the presence of the FACS ACPI table. Since our ACPI tables are onl=
y=0D
+ // installed after PCI enumeration completes, we must not trigger the S3=
save=0D
+ // earlier, hence we can't signal End-of-Dxe earlier.=0D
+ //=0D
+ EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid);=0D
+=0D
//=0D
// Prevent further changes to LockBoxes or SMRAM.=0D
// Any TPM 2 Physical Presence Interface opcode must be handled before.=
=0D
--=20
2.31.1


Re: Uncrustify Conversion Detailed Plan and Extended Hard Freeze Update #4

Bret Barkelew
 

So, so, so refreshing to see automated consistency.

 

For UnitTestFrameworkPkg…

Reviewed-by: Bret Barkelew <bret.barkelew@...>

 

- Bret

 

From: Michael D Kinney via groups.io
Sent: Tuesday, November 30, 2021 2:34 PM
To: devel@edk2.groups.io; Kinney, Michael D; Michael Kubacki; Andrew Fish (afish@...); Lindholm, Leif
Subject: [EXTERNAL] [edk2-devel] Uncrustify Conversion Detailed Plan and Extended Hard Freeze Update #4

 

Hello,

Thank you for your patience during this extended hard freeze.

Just one more step to go.  There has been a delay in the review of
the patch series with the uncrustify source changes.  PR(6).  This
patch series was not sent out as patch review email because of its
very large size.  It only contains source style changes and the
CompareBuild tool and GitHub action has shown there are no binary
differences introduced with these source style changes.

If you are a package maintainer, then please review the following
branch/PR for your package contents and review the EDK II CI results
and BuildCompare results.  I do not expect a line by line review
because we already had time to provide feedback on the source style
performed by uncrustify.  Instead, a Reviewed-by for your package
indicates that you have reviewed the EDK II CI results and CompareBuild
tool functionality and results and you accept the source style
changes to your package.

   * https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmdkinney%2Fedk2%2Ftree%2FBug_3737_3739_ApplyUncrustifyChanges_V5&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=6OFgnyfsGhclcj8GTVKchzBmkbOQJtcm4o2iz4RzPU4%3D&amp;reserved=0
   * https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftianocore%2Fedk2%2Fpull%2F2229&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=BA8pmxk0T4Uom8%2F4dzyjJ2lvEl3mALyq3wOlVCKMPD0%3D&amp;reserved=0
   * https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmdkinney%2Fedk2%2Factions%2Fruns%2F1521618836&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=1EcBi3Mjb9LM%2BhrUDfufOJFmvEEVsb6IW7chJvs3dl0%3D&amp;reserved=0

Additional details on this update below.

Thank you,

Mike


Changes from Update #3
----------------------------------------------------------------------------
* Pushed PR (5)
* Added link to PR(6). EDK II CI Status is PASS. Build Compare PASS.
* Waiting for review of PR (6)
* Review of PR (7) completed and waiting for review of PR (6)
----------------------------------------------------------------------------

Changes from Update #2
----------------------------------------------------------------------------
* Changed order of PRs swapping (4) and (5).  The PR that activates
  increases the max CI agent job time is independent of all the other
  PRs and its review is complete, so it can be committed now.
* Pushed PRs (1), (2), (3), (4).
* Waiting for review to complete for PRs (5) and (6)
* Reviews complete for PR (7)
* Identifies steps using git filter-branch to apply uncrustify changes to a
  code review patch series that was generated before the uncrustify changes
  avoiding manual merge.
* Identified steps using git filter-repo to generate an alternate history of
  the edk2 repo with uncrustify changes applied on every commit.  This may
  be useful when evaluating changes to files using tools like git blame
  without the large uncrustify patch series.
---------------------------------------------------------------------------

Changes from Update #1
----------------------------------------------------------------------------
* Changed order of PRs swapping (6) and (7).  The PR that activates
  EDK II CI check UncrustifyCheck has to be last because it unconditionally
  checks all C/H files in all packages.  Not just files that have been
  modified like some of the other checkers.
* Updated link to the branch with the UncrustifyCheck plugin that has been
  updated with a one line change and Reviewed-by and Tested-by tags.
  https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmdkinney%2Fedk2%2Ftree%2FBug_3748_add_uncrustify_ci_plugin_v6&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=j0Xjp7ss0vyQ2oNTRF4VC%2B5AwQrKQuxxGHH14q%2Fw1p8%3D&amp;reserved=0
* Reviews complete for (1), (2), (3), (5), and (7)
---------------------------------------------------------------------------

Michael Kubacki and I have prepared the patches required to apply the
uncrustify changes and enable EDK II CI to check all submitted
patches have been run through uncrustify.

We have verified through the CompareBuild GitHub Action that the
format changes performed by uncrustify have no functional changes.
All of the OBJ, LIB, DLL, EFI, FFS, FV, and FD files match 100%
across 70 VS2019/GCC5 builds of all package/platform DSC files in
the edk2 repo.

The hard freeze will be extended after the edk2-stable202111 tag until
all uncrustify related changes are committed.  We do not expect this
to take more than a few days.  Do not push any PRs until the hard
freeze is lifted.

The changes are broken up into 7 patch series/PRs.  The PRs are ordered
so they can be submitted using the normal submission process and EDK II
CI will pass for each one.  Details are listed below.

Uncrustify 73.0.3 for EDK II
=============================
* Sources: https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdev.azure.com%2Fprojectmu%2F_git%2FUncrustify&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=oxs8hpNZPKyuizJMa1Q938NvF07fpc5XN5PzQKvO5B4%3D&amp;reserved=0
* Documentation: https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdev.azure.com%2Fprojectmu%2FUncrustify%2F_wiki%2Fwikis%2FUncrustify.wiki%2F1%2FProject-Mu-&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=FPPTmTUhhXL%2FGybBIdaMcTumBnfibpjNnorESzob8jA%3D&amp;reserved=0(EDK-II)-Fork-Readme
* Download: https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdev.azure.com%2Fprojectmu%2FUncrustify%2F_packaging%3F_a%3Dpackage%26feed%3Dmu_uncrustify%26package%3Dmu-uncrustify-release%26protocolType%3DNuGet%26version%3D73.0.3&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=BUOogU1P194ZKUDhSBoO7QcxPIDjZyM%2Bqvg2kwNaSKw%3D&amp;reserved=0

Installing Uncrustify
======================
The Uncrustify tool is installed automatically when the Pytools
environment is used and the stuart* commands are run to complete the
environment setup.  Please see:

    https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftianocore%2Fedk2%2Ftree%2Fmaster%2F.pytool%23running-ci-locally&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=Gl8zfFjVrUvpnTO0UXb3bXR2lsIBz5PwLazkKyBvGIE%3D&amp;reserved=0

Uncrustify can also be installed from the download page listed above
or built from sources from the source link above.

The Documentation link provides instruction on how to run uncrustify from
the command line or install as a Visual Studio Code plugin.  The main
uncrustify documentation also describes how to integrate with a few other
editors.

We have also discussed a client side githook.  That effort has not started.
Let us know if that is a feature you would find useful.

Developer impact for new code reviews
======================================
Once the uncrustify checker is active in EDK II CI, developers must
make sure their patches are run through the uncrustify tool before
sending the patches for review.

Developers must install and run uncrustify against changes files before
sending patch review emails or submitting PR for EDK II CI.  If EDK II CI
detects and differences in source formatting, then EDK II CI will fail
and the developer must run uncrustify and resubmit the patches.

Developer impact to patch series/PRs reviewed during edk2-stable201121 soft/hard freeze
=======================================================================================
Developers must rebase their changes after the uncrustify source changes are
committed.  The branch with a preview of the uncrustify changes can be used
to start this rebase work.

    https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmdkinney%2Fedk2%2Ftree%2FBug_3737_3739_ApplyUncrustifyChanges_V5&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=6OFgnyfsGhclcj8GTVKchzBmkbOQJtcm4o2iz4RzPU4%3D&amp;reserved=0

The following steps can be used to update an existing branch with the
required uncrustify format.  This is the Windows version.  I will add
the Linux version soon.

    1) Fetch and checkout and rebase to latest edk2/master

           git fetch origin
           git checkout master
           git rebase origin/master

    2) Make a backup copy of plugin UncrustifyCheck outside WORKSPACE.
       (e.g. C:\Temp\UncrustifyCheck) so the uncrustify tool executable and
       EDK II specific uncrustify configuration file available when working
       with a branch that does not have those tools in its scope.

           xcopy .pytool\Plugin\UncrustifyCheck C:\Temp\UncrustifyCheck

    3) Check out the patch series branch (e.g. MyBranch)

           git checkout MyBranch

    4) Rebase patch series against edk2-stable202111
 
           git rebase edk2-stable202111

    5) Create new branch for the uncrustifed version (e.g. MyBranch_Uncrustified)

           git checkout -b MyBranch_Uncrustified
   
    6) Use git filter-branch to uncrustify all the commits in the series
       between the rebase target from (2) and HEAD of the branch.  A filter
       can be used to scope the uncrustify operations to only the C/H files
       in the specific package the patch series is against. (e.g. DynamicTablesPkg).
       BaseTools should always be excluded.  If the package scoped filter is
       not used, it will still work, but will take longer to run because
       uncrustify will rescan every C/H files in the whole repo.

           git filter-branch --tree-filter "git ls-files DynamicTablesPkg*.c DynamicTablesPkg*.h :!BaseTools/* | c:\\Temp\\UncrustifyCheck\\mu-uncrustify-release_extdep\\Windows-x86\\uncrustify.exe -c c:\\Temp\\UncrustifyCheck\\uncrustify.cfg -F - --replace --no-backup --if-changed" edk2-stable202111..HEAD

    7) Now that all the individual patches in the branch are uncrustified,
       rebase against latest edk2/master that is already uncrustified.

           git rebase master

    8) Verify the patches in this new branch.

Impacts to tracing history across the uncrusity changes
=======================================================
Tools the view file and line history do work with the large uncrustify
patch series.  One impact is that the operations can be very slow due
to the large uncrustify patches.

One option to provide a faster experience is to provide an alternate
version of the edk2 repository as "documentation" that has the
entire history re-written with uncrustify run on every commit.
The tool called git-filter-repo can be used to perform this
transformation and runs in a reasonable period of time (a few hours)

   https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnewren%2Fgit-filter-repo&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=ww5Wr752N7sQUbISyV8uXnv4EDRveeU6LXktsw7afIs%3D&amp;reserved=0
   https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnewren%2Fgit-filter-repo%2Fblob%2Fmain%2Fcontrib%2Ffilter-repo-demos%2Flint-history&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=VeoGuXB8K%2F1vp%2BwDdSRM6HvUhqtK4wkFfJLjdorspWs%3D&amp;reserved=0

The following steps can be used to perform this transformation.
This is the Windows version. I will add the Linux version soon.

    ** WARNING **  This operation modifies(rewrites) all the commits
                   in the local copy of the repo.  Do not perform
                   these steps on a local repo you are using for
                   active development.

    1) Clone edk2 into a new directory (see **WARNING**)

           git clone https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftianocore%2Fedk2.git&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=djea29CcnZTVc2MohA2WzGaLiKMp66sD9qdum7wcaFI%3D&amp;reserved=0 edk2-uncrustified
           cd edk2-uncrustified

    2) Setup python virtual env, install pytools, and run stuart commands
       to setup build environment which includes installing uncrustify tools.

           https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftianocore%2Fedk2%2Ftree%2Fmaster%2F.pytool%23running-ci-locally&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=Gl8zfFjVrUvpnTO0UXb3bXR2lsIBz5PwLazkKyBvGIE%3D&amp;reserved=0

    3) Make a backup copy of plugin UncrustifyCheck outside WORKSPACE.
       (e.g. C:\Temp\UncrustifyCheck) so the uncrustify tool executable and
       EDK II specific uncrustify configuration file available when working
       with a branch that does not have those tools in its scope.

           xcopy .pytool\Plugin\UncrustifyCheck C:\Temp\UncrustifyCheck

    4) Use lint-history.py from git-filter-repo examples

           https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnewren%2Fgit-filter-repo&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=ww5Wr752N7sQUbISyV8uXnv4EDRveeU6LXktsw7afIs%3D&amp;reserved=0
           https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnewren%2Fgit-filter-repo%2Fblob%2Fmain%2Fcontrib%2Ffilter-repo-demos%2Flint-history&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=VeoGuXB8K%2F1vp%2BwDdSRM6HvUhqtK4wkFfJLjdorspWs%3D&amp;reserved=0

       Line #127 - Add try except around subprocess.check_call() with except
       being pass.  This is required because there are a few commits of C
       files in the edk2 repo that have incorrect C syntax and do not
       build with a C compiler and break the uncrustify parser.  Skip reformat
       of C files that can not be parsed by uncrustify.  These rare instances
       are addressed in the commit that fixes the C syntax error.

       Run this slightly modified version of lint-history.  Include only
       C/H files and exclude directories that start with 'Tools' or 'BaseTools'.
       This step took about 2.2 hours on a laptop.

           lint-history.py
               --relevant "return (not filename.startswith(b'Tools') and not filename.startswith(b'BaseTools') and (filename.endswith(b'.c') or filename.endswith(b'.h')))"
               c:\\work\\GitHub\\tianocore\\foo\\UncrustifyCheck\\mu-uncrustify-release_extdep\\Windows-x86\\uncrustify.exe -c c:\\work\\GitHub\\tianocore\\foo\\UncrustifyCheck\\uncrustify.cfg --replace --no-backup --if-changed

Order of PRs to apply during extended hard freeze
==================================================
1) Update EmulatorPkg Win Host [BuildOptions] MSFT CC_FLAGS to not force debug information
   * https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D3747&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=vRu5LQSjbmwafbvaA6Iv0S%2FzUIbAE%2Bn2Ax9xbckTYLg%3D&amp;reserved=0
   * https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmdkinney%2Fedk2%2Ftree%2FBug_3747_EmulatorPkg_WinHost_ReproducibleBuild&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=oFCZQy6C9zf7kD4QugF9jORY%2Feh5%2B9T9odYGvMND%2FE0%3D&amp;reserved=0
   * https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftianocore%2Fedk2%2Fpull%2F2215&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=mfZMcsGnEof2DvpnVCz8NV9HTo%2FyqadoGfEquXwLjFI%3D&amp;reserved=0
   * Required for EmulatorPkg to pass CompareBuild for VS2019 IA32/X64 builds.
   * Status: Review complete.  PR pushed.

2) EccCheck should not revert staged and local changes
   * https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2986&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=SQVOuOT3Fg%2FVlH2471q0UAG9%2FGRgux3pvkRjrsM%2FkRU%3D&amp;reserved=0
   * https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmdkinney%2Fedk2%2Ftree%2FBug_2986_EccCheckRemoveGitRevert_V2&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=st1WwSlbkgoJ1nPpZqb9XnvCgLqPlpRAos5LtAM%2BcPA%3D&amp;reserved=0
   * https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftianocore%2Fedk2%2Fpull%2F2216&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=6ZQJvN7KLQl5pYsVVIosFbwIdTYtfBVU3rQgvq4cKxs%3D&amp;reserved=0
   * Required for EDK II CI to complete in a reasonable period of time when
     processing the 4000+ source file style changes made by uncrustify.
   * Also fixes critical bugs that can potentially corrupt git state when
     EccCheck is run locally.
   * Status: Review complete.  PR pushed.

3) Update pytool LicenseCheck plugin to use temp directory for diff output file
   * https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D3746&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=cukX7Hc09DRj1v%2BfC9epfr0DDeP0NKunwwbweXjK2hI%3D&amp;reserved=0
   * https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmdkinney%2Fedk2%2Ftree%2FBug_3746_LicenseCheckUseDiffOutputFile_V2&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=i7uICY1zgaq3ukuWCvWTq211b2qhHM6lYRfxTg4pJRE%3D&amp;reserved=0
   * https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftianocore%2Fedk2%2Fpull%2F2217&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=kNvYpT8TrH%2FxcykLRVAg6Z7JQ7RkBtqhFAWyR3x6%2Faw%3D&amp;reserved=0
   * Required to reduce EDK II CI build times.
   * Status: Review complete.  PR pushed.

4) Update max job time from 60 min to 120 minutes in .azurepipelines/templates
   * https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D3750&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=qlXfBBwzPrz4iLyVunIEF8N5mondsfLjMmYk7hlF5Qg%3D&amp;reserved=0
   * https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmdkinney%2Fedk2%2Ftree%2FBug_3750_IncreaseAzurePipelinesTimeout&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=3QhsR365UOEUjyOsrPXvH3oXXSx1F3g6BmpQemEjIxA%3D&amp;reserved=0
   * https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftianocore%2Fedk2%2Fpull%2F2219&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=yNZhoLZXW7hYqPNtKqq4X6rNWyblAhFPpEbkalXotVU%3D&amp;reserved=0
   * Required to allow EccCheck of uncrustify changes to complete on Azure
     Pipelines CI agents without timing out.
   * Status: Review complete.  PR pushed.

5) Update Package YAML to ignore specific ECC files/errors
   * https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D3749&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=HE2PDTC15WKVaQMPU9HZDhfJ4cx71yYzSFnnwqfVk5U%3D&amp;reserved=0
   * https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmdkinney%2Fedk2%2Ftree%2FBug_3749_EccCheckIgnoreFilesErrors&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=d6PNQhqOzohY3OQcX5WVgxB5aWp4qylzFuIzRPsAbZk%3D&amp;reserved=0
   * https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftianocore%2Fedk2%2Fpull%2F2218&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=Vvf2btUzSOzwILvps3h7cRHRfH%2B5cLV%2FcC0Zdo64QaY%3D&amp;reserved=0
   * Required to pass EccCheck
   * Status: Review complete. PR pushed

6) Uncrustify Source Changes
   * https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D3737&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=4iMSTuiCXmhNq9v1z65UYEQ4G9eS0TTkKT0gAC%2Fj%2Bjo%3D&amp;reserved=0
   * https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D3739&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=vbr%2BU6nvHHVcfaMrmfH1tMPC3kNDJyv%2BvDhOoEgUyj4%3D&amp;reserved=0
   * https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmdkinney%2Fedk2%2Ftree%2FBug_3737_3739_ApplyUncrustifyChanges_V5&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=6OFgnyfsGhclcj8GTVKchzBmkbOQJtcm4o2iz4RzPU4%3D&amp;reserved=0
   * https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftianocore%2Fedk2%2Fpull%2F2229&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=BA8pmxk0T4Uom8%2F4dzyjJ2lvEl3mALyq3wOlVCKMPD0%3D&amp;reserved=0
   * Build comparison result PASS: https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmdkinney%2Fedk2%2Factions%2Fruns%2F1521618836&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=1EcBi3Mjb9LM%2BhrUDfufOJFmvEEVsb6IW7chJvs3dl0%3D&amp;reserved=0
   * EFI_D_ -> DEBUG changes required to pass PatchCheck
   * Uncrustify format changes required to pass UncrustifyCheck
   * Status:
       Waiting for review

7) UncrustifyCheck EDK II CI Plugin
   * https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D3748&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=peNoGQGid33y42AXi3qugg4oRJycrj%2FoPZkFofszVVk%3D&amp;reserved=0
   * https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmdkinney%2Fedk2%2Ftree%2FBug_3748_add_uncrustify_ci_plugin_v6&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=j0Xjp7ss0vyQ2oNTRF4VC%2B5AwQrKQuxxGHH14q%2Fw1p8%3D&amp;reserved=0
   * Required to enforce all PRs submitted to EDK II CI match uncrustify format.
   * Unconditionally checks all packages.  Can not be committed until all C/H
     source files have been updated.
   * Status: Review complete

Combined Branch/PR for Review/Test
==================================
* Build Comparison results must pass 100% across the full set of PRs before
  the individual PRs can be pushed in the order listed above.
* Branch: https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmdkinney%2Fedk2%2Ftree%2FTestOnly_Uncrustify_PR_Series&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=%2Fgacf3RVe6uGU%2BQ2gVdQYOfKLn2zwS1DXwuqRo8k%2Fco%3D&amp;reserved=0
* PR: https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftianocore%2Fedk2%2Fpull%2F2229&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=BA8pmxk0T4Uom8%2F4dzyjJ2lvEl3mALyq3wOlVCKMPD0%3D&amp;reserved=0
    Status = PASS
* CompareBuild:
    Branch: https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmdkinney%2Fedk2%2Ftree%2FBug_3737_3739_ApplyUncrustifyChanges_V5&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=6OFgnyfsGhclcj8GTVKchzBmkbOQJtcm4o2iz4RzPU4%3D&amp;reserved=0
    --ref1:        ef9a059cdb15844fe52a49af2bf7d86b9dd3e9bf
    --ref2:        Bug_3737_3739_ApplyUncrustifyChanges_V5
    Extra Options: -n 4 --quiet
    Results: https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmdkinney%2Fedk2%2Factions%2Fruns%2F1521618836&amp;data=04%7C01%7CBret.Barkelew%40microsoft.com%7Cafe73bb0029e491612b908d9b4519560%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637739084803059341%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=1EcBi3Mjb9LM%2BhrUDfufOJFmvEEVsb6IW7chJvs3dl0%3D&amp;reserved=0
        30 VS2019 build comparisons PASS
        40 GCC5 build comparisons PASS
        100% PASS

The following git log shows the set of patches from --ref1 to --ref 2across
which there are no differences in any of the OBJ/LIB/DLL/EFI/FFS/FV/FD files.

--ref2
b7d4bf0675b7 (HEAD -> Bug_3737_3739_ApplyUncrustifyChanges_V5) UnitTestFrameworkPkg: Apply uncrusitify changes
7f03d25f60e7 UefiPayloadPkg: Apply uncrusitify changes   
0bfd8d9b5ac9 UefiCpuPkg: Apply uncrusitify changes                                                                                                                                                                       
e1cd9bfb9dea StandaloneMmPkg: Apply uncrusitify changes                                                                                                                                                                  
5da2f65be378 SourceLevelDebugPkg: Apply uncrusitify changes                                                                                                                                                              
95b86de07e5d SignedCapsulePkg: Apply uncrusitify changes                                                                                                                                                                 
fe71d97246c4 ShellPkg: Apply uncrusitify changes                                                                                                                                                                         
54c21c952992 SecurityPkg: Apply uncrusitify changes                                                                                                                                                                      
187a3785f12b RedfishPkg: Apply uncrusitify changes                                                                                                                                                                       
810100002a46 PcAtChipsetPkg: Apply uncrusitify changes                                                                                                                                                                   
276a695c0cf2 OvmfPkg: Apply uncrusitify changes                                                                                                                                                                          
303c0a91ab07 NetworkPkg: Apply uncrusitify changes                                                                                                                                                                       
bc80792cd1b1 MdePkg: Apply uncrusitify changes                                                                                                                                                                           
3ea86be17a2a MdeModulePkg: Apply uncrusitify changes                                                                                                                                                                     
c70ef11ed0cd IntelFsp2WrapperPkg: Apply uncrusitify changes                                                                                                                                                              
c0291221f252 IntelFsp2Pkg: Apply uncrusitify changes                                                                                                                                                                     
6a479952a690 FmpDevicePkg: Apply uncrusitify changes                                                                                                                                                                     
3a7c05b7070d FatPkg: Apply uncrusitify changes                                                                                                                                                                           
b789f98c8959 EmulatorPkg: Apply uncrusitify changes                                                                                                                                                                      
952d7a1c9220 EmbeddedPkg: Apply uncrusitify changes                                                                                                                                                                      
a1cc9881bab6 DynamicTablesPkg: Apply uncrusitify changes                                                                                                                                                                 
50654dfe5785 CryptoPkg: Apply uncrusitify changes                                                                                                                                                                        
ed965a02dfa1 ArmVirtPkg: Apply uncrusitify changes                                                                                                                                                                       
9744023fbc46 ArmPlatformPkg: Apply uncrusitify changes                                                                                                                                                                   
7a1cde5f5bba ArmPkg: Apply uncrusitify changes                                                                                                                                                                           
19d17e0913e8 UefiCpuPkg: Change use of EFI_D_* to DEBUG_*                                                                                                                                                                
ffa718b4f994 SourceLevelDebugPkg: Change use of EFI_D_* to DEBUG_*                                                                                                                                                       
b86cb3c5e5b4 ShellPkg: Change use of EFI_D_* to DEBUG_*                                                                                                                                                                  
c7c42204dc07 SecurityPkg: Change use of EFI_D_* to DEBUG_*                                                                                                                                                               
16b8e6f958e4 PcAtChipsetPkg: Change use of EFI_D_* to DEBUG_*                                                                                                                                                            
0ac3f8b2dac5 OvmfPkg: Change use of EFI_D_* to DEBUG_*                                                                                                                                                                   
bc5004b8d294 NetworkPkg: Change use of EFI_D_* to DEBUG_*                                                                                                                                                                
6f671a8e2377 MdePkg: Change use of EFI_D_* to DEBUG_*                                                                                                                                                                    
a10c610ff9a3 MdeModulePkg: Change use of EFI_D_* to DEBUG_*                                                                                                                                                              
09a3bddba390 FatPkg: Change use of EFI_D_* to DEBUG_*                                                                                                                                                                    
59c61318246a EmulatorPkg: Change use of EFI_D_* to DEBUG_*                                                                                                                                                               
3a80367dda3b EmbeddedPkg: Change use of EFI_D_* to DEBUG_*                                                                                                                                                               
23eb1aaf80ca ArmVirtPkg: Change use of EFI_D_* to DEBUG_*                                                                                                                                                                
875914b45c54 ArmPlatformPkg: Change use of EFI_D_* to DEBUG_*                                                                                                                                                            
eb2eca82b451 ArmPkg: Change use of EFI_D_* to DEBUG_*                                                                                                                                                                    
f0f3f5aae7c4 (origin/master, origin/HEAD, master) UnitTestFrameworkPkg: Update YAML to ignore specific ECC files/errors                                                                                                  
c05734797790 UefiPayloadPkg: Update YAML to ignore specific ECC files/errors                                                                                                                                             
c30c40d6c63d StandaloneMmPkg: Update YAML to ignore specific ECC files/errors                                                                                                                                            
9944508e85f1 ShellPkg: Update YAML to ignore specific ECC files/errors                                                                                                                                                   
60fa40be458d SecurityPkg: Update YAML to ignore specific ECC files/errors                                                                                                                                                
df790cd6b37e MdePkg: Update YAML to ignore specific ECC files/errors                                                                                                                                                     
9deb9370766e MdeModulePkg: Update YAML to ignore specific ECC files/errors                                                                                                                                               
d7d30e8f219f EmulatorPkg: Update YAML to ignore specific ECC files/errors                                                                                                                                                
d5744ecba813 CryptoPkg: Update YAML to ignore specific ECC files/errors                                                                                                                                                  
c97fee87f0f9 ArmVirtPkg: Update YAML to ignore specific ECC files/errors                                                                                                                                                 
1939fc9569f2 ArmPlatformPkg: Update YAML to ignore specific ECC files/errors                                                                                                                                             
365dced2c37a ArmPkg: Update YAML to ignore specific ECC files/errors                                                                                                                                                     
76a1ce4d5fec .azurepipelines/templates: Update max pipeline job time to 2 hours                                                                                                                                          
99f84ff47390 .pytools/Plugin/LicenseCheck: Use temp directory for git diff output                                                                                                                                        
3019f1bbabf1 .pytool/Plugin/EccCheck: Add performance optimizations                                                                                                                                                      
854462bd3479 .pytool/Plugin/EccCheck: Remove temp directory on exception                                                                                                                                                 
69877614fdee .pytool/Plugin/EccCheck: Remove RevertCode()
--ref1                                                                                                                                                               
ef9a059cdb15 EmulatorPkg/Win/Host: Update CC_FLAGS                                                                                                                                                                       
bb1bba3d7767 (tag: edk2-stable202111) NetworkPkg: Fix invalid pointer for DNS response token on error                                                                                                                    

Best regards,

Mike









 


Re: Uncrustify Conversion Detailed Plan and Extended Hard Freeze Update #4

Michael D Kinney
 

Hi Michael,

This commit provides the background on why this content was copied into edk2
instead of used as a submodule.

https://github.com/tianocore/edk2/commit/4751a48aeb2ab828b0a5cbdc585fd3642967cda1#diff-9f77cfa3b537eee28489f8713c17d8702330f5cef1795f154201dd463aabed27

I imagine the main reason for this request is to minimize the effort required
to sync these copies with new versions. The scope right now is only 7 files.
One alternative to help with the sync is for Abner to run uncrustify on the
files from the upstream source on these 7 files and then do the diff to see if
there is anything significant that needs to be merged.

Abner, are you ok with doing this 2 step process to sync the files that were copied?

Best regards,

Mike

-----Original Message-----
From: Michael Kubacki <mikuback@...>
Sent: Wednesday, December 1, 2021 9:05 AM
To: devel@edk2.groups.io; Kinney, Michael D <michael.d.kinney@...>; Chang, Abner <abner.chang@...>; Wang, Jian J
<jian.j.wang@...>; Michael Kubacki <michael.kubacki@...>; Andrew Fish (afish@...) <afish@...>;
Leif Lindholm <leif@...>
Subject: Re: [edk2-devel] Uncrustify Conversion Detailed Plan and Extended Hard Freeze Update #4

This can of course be done at a technical level but it smells of a code
cohesion problem.

The code is in the edk2 project so it would reason that it should be
uniform in style with other code and at least close to the EDK II C
Coding Standard Specification.

Currently, git submodules and ignored path are already excluded in
addition to the ability to mark packages in "audit mode" so they do not
fail the results. I would personally prefer not to allow arbitrary
subdirectories to diverge from the rest of the codebase / package but if
there's consensus this is a good idea, I can look into adding it.

Regards,
Michael

On 12/1/2021 11:43 AM, Michael D Kinney wrote:
Hi Abner,

Yes. That is possible. We are already excluding BaseTools.

In order to get the file lists that apply to uncrustify, we would have to change from:

git ls-files *.c *.h :!BaseTools/*

To:

git ls-files *.c *.h :!BaseTools/* :!RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/*

However, I do not see a feature in the UncrustifyCheck to check all c/h files in RedFishPkg and exclude one of its
directories.
If we can specify an exclusion like this in the RedFishPkg YAML file, then I think that would work well.

Michael Kubacki would have to comment on how we support this in EDK II CI checks.

Best regards,

Mike


-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Abner Chang
Sent: Tuesday, November 30, 2021 11:34 PM
To: devel@edk2.groups.io; Wang, Jian J <jian.j.wang@...>; Kinney, Michael D <michael.d.kinney@...>; Michael
Kubacki <michael.kubacki@...>; Andrew Fish (afish@...) <afish@...>; Leif Lindholm
<leif@...>
Subject: Re: [edk2-devel] Uncrustify Conversion Detailed Plan and Extended Hard Freeze Update #4

Hi Mike,
Is that possible to not applying uncrusitify on the source files that cloned from other open source?
e.g. RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/*.*

Thanks
Abner

-----Original Message-----
From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
Wang, Jian J
Sent: Wednesday, December 1, 2021 2:39 PM
To: devel@edk2.groups.io; Kinney, Michael D <michael.d.kinney@...>;
Michael Kubacki <michael.kubacki@...>; Andrew Fish
(afish@...) <afish@...>; Leif Lindholm <leif@...>
Subject: Re: [edk2-devel] Uncrustify Conversion Detailed Plan and Extended
Hard Freeze Update #4

For SignedCapulePkg,

Reviewed-by: Jian J Wang <jian.j.wang@...>

Regards,
Jian

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
Michael D
Kinney
Sent: Wednesday, December 01, 2021 6:34 AM
To: devel@edk2.groups.io; Kinney, Michael D
<michael.d.kinney@...>;
Michael Kubacki <michael.kubacki@...>; Andrew Fish
(afish@...) <afish@...>; Leif Lindholm
<leif@...>
Subject: [edk2-devel] Uncrustify Conversion Detailed Plan and Extended
Hard
Freeze Update #4

Hello,

Thank you for your patience during this extended hard freeze.

Just one more step to go. There has been a delay in the review of
the patch series with the uncrustify source changes. PR(6). This
patch series was not sent out as patch review email because of its
very large size. It only contains source style changes and the
CompareBuild tool and GitHub action has shown there are no binary
differences introduced with these source style changes.

If you are a package maintainer, then please review the following
branch/PR for your package contents and review the EDK II CI results
and BuildCompare results. I do not expect a line by line review
because we already had time to provide feedback on the source style
performed by uncrustify. Instead, a Reviewed-by for your package
indicates that you have reviewed the EDK II CI results and CompareBuild
tool functionality and results and you accept the source style
changes to your package.

*
https://github.com/mdkinney/edk2/tree/Bug_3737_3739_ApplyUncrustifyC
han
ges_V5
* https://github.com/tianocore/edk2/pull/2229
* https://github.com/mdkinney/edk2/actions/runs/1521618836

Additional details on this update below.

Thank you,

Mike


Changes from Update #3
----------------------------------------------------------------------------
* Pushed PR (5)
* Added link to PR(6). EDK II CI Status is PASS. Build Compare PASS.
* Waiting for review of PR (6)
* Review of PR (7) completed and waiting for review of PR (6)
----------------------------------------------------------------------------

Changes from Update #2
----------------------------------------------------------------------------
* Changed order of PRs swapping (4) and (5). The PR that activates
increases the max CI agent job time is independent of all the other
PRs and its review is complete, so it can be committed now.
* Pushed PRs (1), (2), (3), (4).
* Waiting for review to complete for PRs (5) and (6)
* Reviews complete for PR (7)
* Identifies steps using git filter-branch to apply uncrustify changes to a
code review patch series that was generated before the uncrustify
changes
avoiding manual merge.
* Identified steps using git filter-repo to generate an alternate history of
the edk2 repo with uncrustify changes applied on every commit. This may
be useful when evaluating changes to files using tools like git blame
without the large uncrustify patch series.
---------------------------------------------------------------------------

Changes from Update #1
----------------------------------------------------------------------------
* Changed order of PRs swapping (6) and (7). The PR that activates
EDK II CI check UncrustifyCheck has to be last because it unconditionally
checks all C/H files in all packages. Not just files that have been
modified like some of the other checkers.
* Updated link to the branch with the UncrustifyCheck plugin that has been
updated with a one line change and Reviewed-by and Tested-by tags.

https://github.com/mdkinney/edk2/tree/Bug_3748_add_uncrustify_ci_plug
in_v
6
* Reviews complete for (1), (2), (3), (5), and (7)
---------------------------------------------------------------------------

Michael Kubacki and I have prepared the patches required to apply the
uncrustify changes and enable EDK II CI to check all submitted
patches have been run through uncrustify.

We have verified through the CompareBuild GitHub Action that the
format changes performed by uncrustify have no functional changes.
All of the OBJ, LIB, DLL, EFI, FFS, FV, and FD files match 100%
across 70 VS2019/GCC5 builds of all package/platform DSC files in
the edk2 repo.

The hard freeze will be extended after the edk2-stable202111 tag until
all uncrustify related changes are committed. We do not expect this
to take more than a few days. Do not push any PRs until the hard
freeze is lifted.

The changes are broken up into 7 patch series/PRs. The PRs are ordered
so they can be submitted using the normal submission process and EDK II
CI will pass for each one. Details are listed below.

Uncrustify 73.0.3 for EDK II
=============================
* Sources:
INVALID URI REMOVED
stify__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJOYp
cSVHoHwMD2t8$
* Documentation:
INVALID URI REMOVED
/_wiki/wikis/Uncrustify.wiki/1/Proj__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKk
oslR8D0LLPZTWXL0OKtMZJOYpcSVHoP8OtlxM$
ect-Mu-(EDK-II)-Fork-Readme
* Download:
INVALID URI REMOVED
/_packaging?_a=package&feed=m__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKk
oslR8D0LLPZTWXL0OKtMZJOYpcSVHo4yTWeAM$
u_uncrustify&package=mu-uncrustify-
release&protocolType=NuGet&version=73.0.3

Installing Uncrustify
======================
The Uncrustify tool is installed automatically when the Pytools
environment is used and the stuart* commands are run to complete the
environment setup. Please see:

https://github.com/tianocore/edk2/tree/master/.pytool#running-ci-
locally

Uncrustify can also be installed from the download page listed above
or built from sources from the source link above.

The Documentation link provides instruction on how to run uncrustify from
the command line or install as a Visual Studio Code plugin. The main
uncrustify documentation also describes how to integrate with a few other
editors.

We have also discussed a client side githook. That effort has not started.
Let us know if that is a feature you would find useful.

Developer impact for new code reviews
======================================
Once the uncrustify checker is active in EDK II CI, developers must
make sure their patches are run through the uncrustify tool before
sending the patches for review.

Developers must install and run uncrustify against changes files before
sending patch review emails or submitting PR for EDK II CI. If EDK II CI
detects and differences in source formatting, then EDK II CI will fail
and the developer must run uncrustify and resubmit the patches.

Developer impact to patch series/PRs reviewed during edk2-stable201121
soft/hard freeze
==========================================================
=======
======================
Developers must rebase their changes after the uncrustify source changes
are
committed. The branch with a preview of the uncrustify changes can be
used
to start this rebase work.


https://github.com/mdkinney/edk2/tree/Bug_3737_3739_ApplyUncrustifyC
han
ges_V5

The following steps can be used to update an existing branch with the
required uncrustify format. This is the Windows version. I will add
the Linux version soon.

1) Fetch and checkout and rebase to latest edk2/master

git fetch origin
git checkout master
git rebase origin/master

2) Make a backup copy of plugin UncrustifyCheck outside WORKSPACE.
(e.g. C:\Temp\UncrustifyCheck) so the uncrustify tool executable and
EDK II specific uncrustify configuration file available when working
with a branch that does not have those tools in its scope.

xcopy .pytool\Plugin\UncrustifyCheck C:\Temp\UncrustifyCheck

3) Check out the patch series branch (e.g. MyBranch)

git checkout MyBranch

4) Rebase patch series against edk2-stable202111

git rebase edk2-stable202111

5) Create new branch for the uncrustifed version (e.g.
MyBranch_Uncrustified)

git checkout -b MyBranch_Uncrustified

6) Use git filter-branch to uncrustify all the commits in the series
between the rebase target from (2) and HEAD of the branch. A filter
can be used to scope the uncrustify operations to only the C/H files
in the specific package the patch series is against. (e.g.
DynamicTablesPkg).
BaseTools should always be excluded. If the package scoped filter is
not used, it will still work, but will take longer to run because
uncrustify will rescan every C/H files in the whole repo.

git filter-branch --tree-filter "git ls-files DynamicTablesPkg*.c
DynamicTablesPkg*.h :!BaseTools/* | c:\\Temp\\UncrustifyCheck\\mu-
uncrustify-release_extdep\\Windows-x86\\uncrustify.exe -c
c:\\Temp\\UncrustifyCheck\\uncrustify.cfg -F - --replace --no-backup --if-
changed" edk2-stable202111..HEAD

7) Now that all the individual patches in the branch are uncrustified,
rebase against latest edk2/master that is already uncrustified.

git rebase master

8) Verify the patches in this new branch.

Impacts to tracing history across the uncrusity changes
=======================================================
Tools the view file and line history do work with the large uncrustify
patch series. One impact is that the operations can be very slow due
to the large uncrustify patches.

One option to provide a faster experience is to provide an alternate
version of the edk2 repository as "documentation" that has the
entire history re-written with uncrustify run on every commit.
The tool called git-filter-repo can be used to perform this
transformation and runs in a reasonable period of time (a few hours)

https://github.com/newren/git-filter-repo
https://github.com/newren/git-filter-repo/blob/main/contrib/filter-
repo-
demos/lint-history

The following steps can be used to perform this transformation.
This is the Windows version. I will add the Linux version soon.

** WARNING ** This operation modifies(rewrites) all the commits
in the local copy of the repo. Do not perform
these steps on a local repo you are using for
active development.

1) Clone edk2 into a new directory (see **WARNING**)

git clone https://github.com/tianocore/edk2.git edk2-uncrustified
cd edk2-uncrustified

2) Setup python virtual env, install pytools, and run stuart commands
to setup build environment which includes installing uncrustify tools.

https://github.com/tianocore/edk2/tree/master/.pytool#running-ci-
locally

3) Make a backup copy of plugin UncrustifyCheck outside WORKSPACE.
(e.g. C:\Temp\UncrustifyCheck) so the uncrustify tool executable and
EDK II specific uncrustify configuration file available when working
with a branch that does not have those tools in its scope.

xcopy .pytool\Plugin\UncrustifyCheck C:\Temp\UncrustifyCheck

4) Use lint-history.py from git-filter-repo examples

https://github.com/newren/git-filter-repo
https://github.com/newren/git-filter-repo/blob/main/contrib/filter-
repo-
demos/lint-history

Line #127 - Add try except around subprocess.check_call() with except
being pass. This is required because there are a few commits of C
files in the edk2 repo that have incorrect C syntax and do not
build with a C compiler and break the uncrustify parser. Skip reformat
of C files that can not be parsed by uncrustify. These rare instances
are addressed in the commit that fixes the C syntax error.

Run this slightly modified version of lint-history. Include only
C/H files and exclude directories that start with 'Tools' or 'BaseTools'.
This step took about 2.2 hours on a laptop.

lint-history.py
--relevant "return (not filename.startswith(b'Tools') and not
filename.startswith(b'BaseTools') and (filename.endswith(b'.c') or
filename.endswith(b'.h')))"
c:\\work\\GitHub\\tianocore\\foo\\UncrustifyCheck\\mu-
uncrustify-
release_extdep\\Windows-x86\\uncrustify.exe -c
c:\\work\\GitHub\\tianocore\\foo\\UncrustifyCheck\\uncrustify.cfg --
replace --
no-backup --if-changed

Order of PRs to apply during extended hard freeze
==================================================
1) Update EmulatorPkg Win Host [BuildOptions] MSFT CC_FLAGS to not
force
debug information
*
INVALID URI REMOVED
d=3747__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJ
OYpcSVHo2BEG33c$
*
https://github.com/mdkinney/edk2/tree/Bug_3747_EmulatorPkg_WinHost_
Rep
roducibleBuild
* https://github.com/tianocore/edk2/pull/2215
* Required for EmulatorPkg to pass CompareBuild for VS2019 IA32/X64
builds.
* Status: Review complete. PR pushed.

2) EccCheck should not revert staged and local changes
*
INVALID URI REMOVED
d=2986__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJ
OYpcSVHotvR0Unk$
*
https://github.com/mdkinney/edk2/tree/Bug_2986_EccCheckRemoveGitRe
vert
_V2
* https://github.com/tianocore/edk2/pull/2216
* Required for EDK II CI to complete in a reasonable period of time when
processing the 4000+ source file style changes made by uncrustify.
* Also fixes critical bugs that can potentially corrupt git state when
EccCheck is run locally.
* Status: Review complete. PR pushed.

3) Update pytool LicenseCheck plugin to use temp directory for diff output
file
*
INVALID URI REMOVED
d=3746__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJ
OYpcSVHoWRuHaBw$
*
https://github.com/mdkinney/edk2/tree/Bug_3746_LicenseCheckUseDiffO
utput
File_V2
* https://github.com/tianocore/edk2/pull/2217
* Required to reduce EDK II CI build times.
* Status: Review complete. PR pushed.

4) Update max job time from 60 min to 120 minutes
in .azurepipelines/templates
*
INVALID URI REMOVED
d=3750__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJ
OYpcSVHozaVshgc$
*
https://github.com/mdkinney/edk2/tree/Bug_3750_IncreaseAzurePipelines
Time
out
* https://github.com/tianocore/edk2/pull/2219
* Required to allow EccCheck of uncrustify changes to complete on Azure
Pipelines CI agents without timing out.
* Status: Review complete. PR pushed.

5) Update Package YAML to ignore specific ECC files/errors
*
INVALID URI REMOVED
d=3749__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJ
OYpcSVHo-fY3dMo$
*
https://github.com/mdkinney/edk2/tree/Bug_3749_EccCheckIgnoreFilesErr
ors
* https://github.com/tianocore/edk2/pull/2218
* Required to pass EccCheck
* Status: Review complete. PR pushed

6) Uncrustify Source Changes
*
INVALID URI REMOVED
d=3737__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJ
OYpcSVHoMRa47YU$
*
INVALID URI REMOVED
d=3739__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJ
OYpcSVHoPAlckP8$
*
https://github.com/mdkinney/edk2/tree/Bug_3737_3739_ApplyUncrustifyC
han
ges_V5
* https://github.com/tianocore/edk2/pull/2229
* Build comparison result PASS:
https://github.com/mdkinney/edk2/actions/runs/1521618836
* EFI_D_ -> DEBUG changes required to pass PatchCheck
* Uncrustify format changes required to pass UncrustifyCheck
* Status:
Waiting for review

7) UncrustifyCheck EDK II CI Plugin
*
INVALID URI REMOVED
d=3748__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJ
OYpcSVHoCzEWymQ$
*
https://github.com/mdkinney/edk2/tree/Bug_3748_add_uncrustify_ci_plug
in_v
6
* Required to enforce all PRs submitted to EDK II CI match uncrustify
format.
* Unconditionally checks all packages. Can not be committed until all C/H
source files have been updated.
* Status: Review complete

Combined Branch/PR for Review/Test
==================================
* Build Comparison results must pass 100% across the full set of PRs before
the individual PRs can be pushed in the order listed above.
* Branch:
https://github.com/mdkinney/edk2/tree/TestOnly_Uncrustify_PR_Series
* PR: https://github.com/tianocore/edk2/pull/2229
Status = PASS
* CompareBuild:
Branch:
https://github.com/mdkinney/edk2/tree/Bug_3737_3739_ApplyUncrustifyC
han
ges_V5
--ref1: ef9a059cdb15844fe52a49af2bf7d86b9dd3e9bf
--ref2: Bug_3737_3739_ApplyUncrustifyChanges_V5
Extra Options: -n 4 --quiet
Results: https://github.com/mdkinney/edk2/actions/runs/1521618836
30 VS2019 build comparisons PASS
40 GCC5 build comparisons PASS
100% PASS

The following git log shows the set of patches from --ref1 to --ref 2across
which there are no differences in any of the OBJ/LIB/DLL/EFI/FFS/FV/FD
files.

--ref2
b7d4bf0675b7 (HEAD -> Bug_3737_3739_ApplyUncrustifyChanges_V5)
UnitTestFrameworkPkg: Apply uncrusitify changes
7f03d25f60e7 UefiPayloadPkg: Apply uncrusitify changes
0bfd8d9b5ac9 UefiCpuPkg: Apply uncrusitify changes
e1cd9bfb9dea StandaloneMmPkg: Apply uncrusitify changes
5da2f65be378 SourceLevelDebugPkg: Apply uncrusitify changes
95b86de07e5d SignedCapsulePkg: Apply uncrusitify changes
fe71d97246c4 ShellPkg: Apply uncrusitify changes
54c21c952992 SecurityPkg: Apply uncrusitify changes
187a3785f12b RedfishPkg: Apply uncrusitify changes
810100002a46 PcAtChipsetPkg: Apply uncrusitify changes
276a695c0cf2 OvmfPkg: Apply uncrusitify changes
303c0a91ab07 NetworkPkg: Apply uncrusitify changes
bc80792cd1b1 MdePkg: Apply uncrusitify changes
3ea86be17a2a MdeModulePkg: Apply uncrusitify changes
c70ef11ed0cd IntelFsp2WrapperPkg: Apply uncrusitify changes
c0291221f252 IntelFsp2Pkg: Apply uncrusitify changes
6a479952a690 FmpDevicePkg: Apply uncrusitify changes
3a7c05b7070d FatPkg: Apply uncrusitify changes
b789f98c8959 EmulatorPkg: Apply uncrusitify changes
952d7a1c9220 EmbeddedPkg: Apply uncrusitify changes
a1cc9881bab6 DynamicTablesPkg: Apply uncrusitify changes
50654dfe5785 CryptoPkg: Apply uncrusitify changes
ed965a02dfa1 ArmVirtPkg: Apply uncrusitify changes
9744023fbc46 ArmPlatformPkg: Apply uncrusitify changes
7a1cde5f5bba ArmPkg: Apply uncrusitify changes
19d17e0913e8 UefiCpuPkg: Change use of EFI_D_* to DEBUG_*
ffa718b4f994 SourceLevelDebugPkg: Change use of EFI_D_* to DEBUG_*
b86cb3c5e5b4 ShellPkg: Change use of EFI_D_* to DEBUG_*
c7c42204dc07 SecurityPkg: Change use of EFI_D_* to DEBUG_*
16b8e6f958e4 PcAtChipsetPkg: Change use of EFI_D_* to DEBUG_*
0ac3f8b2dac5 OvmfPkg: Change use of EFI_D_* to DEBUG_*
bc5004b8d294 NetworkPkg: Change use of EFI_D_* to DEBUG_*
6f671a8e2377 MdePkg: Change use of EFI_D_* to DEBUG_*
a10c610ff9a3 MdeModulePkg: Change use of EFI_D_* to DEBUG_*
09a3bddba390 FatPkg: Change use of EFI_D_* to DEBUG_*
59c61318246a EmulatorPkg: Change use of EFI_D_* to DEBUG_*
3a80367dda3b EmbeddedPkg: Change use of EFI_D_* to DEBUG_*
23eb1aaf80ca ArmVirtPkg: Change use of EFI_D_* to DEBUG_*
875914b45c54 ArmPlatformPkg: Change use of EFI_D_* to DEBUG_*
eb2eca82b451 ArmPkg: Change use of EFI_D_* to DEBUG_*
f0f3f5aae7c4 (origin/master, origin/HEAD, master) UnitTestFrameworkPkg:
Update YAML to ignore specific ECC files/errors
c05734797790 UefiPayloadPkg: Update YAML to ignore specific ECC
files/errors
c30c40d6c63d StandaloneMmPkg: Update YAML to ignore specific ECC
files/errors
9944508e85f1 ShellPkg: Update YAML to ignore specific ECC files/errors
60fa40be458d SecurityPkg: Update YAML to ignore specific ECC files/errors
df790cd6b37e MdePkg: Update YAML to ignore specific ECC files/errors
9deb9370766e MdeModulePkg: Update YAML to ignore specific ECC
files/errors
d7d30e8f219f EmulatorPkg: Update YAML to ignore specific ECC files/errors
d5744ecba813 CryptoPkg: Update YAML to ignore specific ECC files/errors
c97fee87f0f9 ArmVirtPkg: Update YAML to ignore specific ECC files/errors
1939fc9569f2 ArmPlatformPkg: Update YAML to ignore specific ECC
files/errors
365dced2c37a ArmPkg: Update YAML to ignore specific ECC files/errors
76a1ce4d5fec .azurepipelines/templates: Update max pipeline job time to
2
hours
99f84ff47390 .pytools/Plugin/LicenseCheck: Use temp directory for git diff
output
3019f1bbabf1 .pytool/Plugin/EccCheck: Add performance optimizations
854462bd3479 .pytool/Plugin/EccCheck: Remove temp directory on
exception
69877614fdee .pytool/Plugin/EccCheck: Remove RevertCode()
--ref1
ef9a059cdb15 EmulatorPkg/Win/Host: Update CC_FLAGS
bb1bba3d7767 (tag: edk2-stable202111) NetworkPkg: Fix invalid pointer for
DNS
response token on error

Best regards,

Mike



















Re: Uncrustify Conversion Detailed Plan and Extended Hard Freeze Update #4

Michael Kubacki
 

This can of course be done at a technical level but it smells of a code cohesion problem.

The code is in the edk2 project so it would reason that it should be uniform in style with other code and at least close to the EDK II C Coding Standard Specification.

Currently, git submodules and ignored path are already excluded in addition to the ability to mark packages in "audit mode" so they do not fail the results. I would personally prefer not to allow arbitrary subdirectories to diverge from the rest of the codebase / package but if there's consensus this is a good idea, I can look into adding it.

Regards,
Michael

On 12/1/2021 11:43 AM, Michael D Kinney wrote:
Hi Abner,
Yes. That is possible. We are already excluding BaseTools.
In order to get the file lists that apply to uncrustify, we would have to change from:
git ls-files *.c *.h :!BaseTools/*
To:
git ls-files *.c *.h :!BaseTools/* :!RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/*
However, I do not see a feature in the UncrustifyCheck to check all c/h files in RedFishPkg and exclude one of its directories.
If we can specify an exclusion like this in the RedFishPkg YAML file, then I think that would work well.
Michael Kubacki would have to comment on how we support this in EDK II CI checks.
Best regards,
Mike

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Abner Chang
Sent: Tuesday, November 30, 2021 11:34 PM
To: devel@edk2.groups.io; Wang, Jian J <jian.j.wang@...>; Kinney, Michael D <michael.d.kinney@...>; Michael
Kubacki <michael.kubacki@...>; Andrew Fish (afish@...) <afish@...>; Leif Lindholm
<leif@...>
Subject: Re: [edk2-devel] Uncrustify Conversion Detailed Plan and Extended Hard Freeze Update #4

Hi Mike,
Is that possible to not applying uncrusitify on the source files that cloned from other open source?
e.g. RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/*.*

Thanks
Abner

-----Original Message-----
From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
Wang, Jian J
Sent: Wednesday, December 1, 2021 2:39 PM
To: devel@edk2.groups.io; Kinney, Michael D <michael.d.kinney@...>;
Michael Kubacki <michael.kubacki@...>; Andrew Fish
(afish@...) <afish@...>; Leif Lindholm <leif@...>
Subject: Re: [edk2-devel] Uncrustify Conversion Detailed Plan and Extended
Hard Freeze Update #4

For SignedCapulePkg,

Reviewed-by: Jian J Wang <jian.j.wang@...>

Regards,
Jian

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
Michael D
Kinney
Sent: Wednesday, December 01, 2021 6:34 AM
To: devel@edk2.groups.io; Kinney, Michael D
<michael.d.kinney@...>;
Michael Kubacki <michael.kubacki@...>; Andrew Fish
(afish@...) <afish@...>; Leif Lindholm
<leif@...>
Subject: [edk2-devel] Uncrustify Conversion Detailed Plan and Extended
Hard
Freeze Update #4

Hello,

Thank you for your patience during this extended hard freeze.

Just one more step to go. There has been a delay in the review of
the patch series with the uncrustify source changes. PR(6). This
patch series was not sent out as patch review email because of its
very large size. It only contains source style changes and the
CompareBuild tool and GitHub action has shown there are no binary
differences introduced with these source style changes.

If you are a package maintainer, then please review the following
branch/PR for your package contents and review the EDK II CI results
and BuildCompare results. I do not expect a line by line review
because we already had time to provide feedback on the source style
performed by uncrustify. Instead, a Reviewed-by for your package
indicates that you have reviewed the EDK II CI results and CompareBuild
tool functionality and results and you accept the source style
changes to your package.

*
https://github.com/mdkinney/edk2/tree/Bug_3737_3739_ApplyUncrustifyC
han
ges_V5
* https://github.com/tianocore/edk2/pull/2229
* https://github.com/mdkinney/edk2/actions/runs/1521618836

Additional details on this update below.

Thank you,

Mike


Changes from Update #3
----------------------------------------------------------------------------
* Pushed PR (5)
* Added link to PR(6). EDK II CI Status is PASS. Build Compare PASS.
* Waiting for review of PR (6)
* Review of PR (7) completed and waiting for review of PR (6)
----------------------------------------------------------------------------

Changes from Update #2
----------------------------------------------------------------------------
* Changed order of PRs swapping (4) and (5). The PR that activates
increases the max CI agent job time is independent of all the other
PRs and its review is complete, so it can be committed now.
* Pushed PRs (1), (2), (3), (4).
* Waiting for review to complete for PRs (5) and (6)
* Reviews complete for PR (7)
* Identifies steps using git filter-branch to apply uncrustify changes to a
code review patch series that was generated before the uncrustify
changes
avoiding manual merge.
* Identified steps using git filter-repo to generate an alternate history of
the edk2 repo with uncrustify changes applied on every commit. This may
be useful when evaluating changes to files using tools like git blame
without the large uncrustify patch series.
---------------------------------------------------------------------------

Changes from Update #1
----------------------------------------------------------------------------
* Changed order of PRs swapping (6) and (7). The PR that activates
EDK II CI check UncrustifyCheck has to be last because it unconditionally
checks all C/H files in all packages. Not just files that have been
modified like some of the other checkers.
* Updated link to the branch with the UncrustifyCheck plugin that has been
updated with a one line change and Reviewed-by and Tested-by tags.

https://github.com/mdkinney/edk2/tree/Bug_3748_add_uncrustify_ci_plug
in_v
6
* Reviews complete for (1), (2), (3), (5), and (7)
---------------------------------------------------------------------------

Michael Kubacki and I have prepared the patches required to apply the
uncrustify changes and enable EDK II CI to check all submitted
patches have been run through uncrustify.

We have verified through the CompareBuild GitHub Action that the
format changes performed by uncrustify have no functional changes.
All of the OBJ, LIB, DLL, EFI, FFS, FV, and FD files match 100%
across 70 VS2019/GCC5 builds of all package/platform DSC files in
the edk2 repo.

The hard freeze will be extended after the edk2-stable202111 tag until
all uncrustify related changes are committed. We do not expect this
to take more than a few days. Do not push any PRs until the hard
freeze is lifted.

The changes are broken up into 7 patch series/PRs. The PRs are ordered
so they can be submitted using the normal submission process and EDK II
CI will pass for each one. Details are listed below.

Uncrustify 73.0.3 for EDK II
=============================
* Sources:
INVALID URI REMOVED
stify__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJOYp
cSVHoHwMD2t8$
* Documentation:
INVALID URI REMOVED
/_wiki/wikis/Uncrustify.wiki/1/Proj__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKk
oslR8D0LLPZTWXL0OKtMZJOYpcSVHoP8OtlxM$
ect-Mu-(EDK-II)-Fork-Readme
* Download:
INVALID URI REMOVED
/_packaging?_a=package&feed=m__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKk
oslR8D0LLPZTWXL0OKtMZJOYpcSVHo4yTWeAM$
u_uncrustify&package=mu-uncrustify-
release&protocolType=NuGet&version=73.0.3

Installing Uncrustify
======================
The Uncrustify tool is installed automatically when the Pytools
environment is used and the stuart* commands are run to complete the
environment setup. Please see:

https://github.com/tianocore/edk2/tree/master/.pytool#running-ci-
locally

Uncrustify can also be installed from the download page listed above
or built from sources from the source link above.

The Documentation link provides instruction on how to run uncrustify from
the command line or install as a Visual Studio Code plugin. The main
uncrustify documentation also describes how to integrate with a few other
editors.

We have also discussed a client side githook. That effort has not started.
Let us know if that is a feature you would find useful.

Developer impact for new code reviews
======================================
Once the uncrustify checker is active in EDK II CI, developers must
make sure their patches are run through the uncrustify tool before
sending the patches for review.

Developers must install and run uncrustify against changes files before
sending patch review emails or submitting PR for EDK II CI. If EDK II CI
detects and differences in source formatting, then EDK II CI will fail
and the developer must run uncrustify and resubmit the patches.

Developer impact to patch series/PRs reviewed during edk2-stable201121
soft/hard freeze
==========================================================
=======
======================
Developers must rebase their changes after the uncrustify source changes
are
committed. The branch with a preview of the uncrustify changes can be
used
to start this rebase work.


https://github.com/mdkinney/edk2/tree/Bug_3737_3739_ApplyUncrustifyC
han
ges_V5

The following steps can be used to update an existing branch with the
required uncrustify format. This is the Windows version. I will add
the Linux version soon.

1) Fetch and checkout and rebase to latest edk2/master

git fetch origin
git checkout master
git rebase origin/master

2) Make a backup copy of plugin UncrustifyCheck outside WORKSPACE.
(e.g. C:\Temp\UncrustifyCheck) so the uncrustify tool executable and
EDK II specific uncrustify configuration file available when working
with a branch that does not have those tools in its scope.

xcopy .pytool\Plugin\UncrustifyCheck C:\Temp\UncrustifyCheck

3) Check out the patch series branch (e.g. MyBranch)

git checkout MyBranch

4) Rebase patch series against edk2-stable202111

git rebase edk2-stable202111

5) Create new branch for the uncrustifed version (e.g.
MyBranch_Uncrustified)

git checkout -b MyBranch_Uncrustified

6) Use git filter-branch to uncrustify all the commits in the series
between the rebase target from (2) and HEAD of the branch. A filter
can be used to scope the uncrustify operations to only the C/H files
in the specific package the patch series is against. (e.g.
DynamicTablesPkg).
BaseTools should always be excluded. If the package scoped filter is
not used, it will still work, but will take longer to run because
uncrustify will rescan every C/H files in the whole repo.

git filter-branch --tree-filter "git ls-files DynamicTablesPkg*.c
DynamicTablesPkg*.h :!BaseTools/* | c:\\Temp\\UncrustifyCheck\\mu-
uncrustify-release_extdep\\Windows-x86\\uncrustify.exe -c
c:\\Temp\\UncrustifyCheck\\uncrustify.cfg -F - --replace --no-backup --if-
changed" edk2-stable202111..HEAD

7) Now that all the individual patches in the branch are uncrustified,
rebase against latest edk2/master that is already uncrustified.

git rebase master

8) Verify the patches in this new branch.

Impacts to tracing history across the uncrusity changes
=======================================================
Tools the view file and line history do work with the large uncrustify
patch series. One impact is that the operations can be very slow due
to the large uncrustify patches.

One option to provide a faster experience is to provide an alternate
version of the edk2 repository as "documentation" that has the
entire history re-written with uncrustify run on every commit.
The tool called git-filter-repo can be used to perform this
transformation and runs in a reasonable period of time (a few hours)

https://github.com/newren/git-filter-repo
https://github.com/newren/git-filter-repo/blob/main/contrib/filter-
repo-
demos/lint-history

The following steps can be used to perform this transformation.
This is the Windows version. I will add the Linux version soon.

** WARNING ** This operation modifies(rewrites) all the commits
in the local copy of the repo. Do not perform
these steps on a local repo you are using for
active development.

1) Clone edk2 into a new directory (see **WARNING**)

git clone https://github.com/tianocore/edk2.git edk2-uncrustified
cd edk2-uncrustified

2) Setup python virtual env, install pytools, and run stuart commands
to setup build environment which includes installing uncrustify tools.

https://github.com/tianocore/edk2/tree/master/.pytool#running-ci-
locally

3) Make a backup copy of plugin UncrustifyCheck outside WORKSPACE.
(e.g. C:\Temp\UncrustifyCheck) so the uncrustify tool executable and
EDK II specific uncrustify configuration file available when working
with a branch that does not have those tools in its scope.

xcopy .pytool\Plugin\UncrustifyCheck C:\Temp\UncrustifyCheck

4) Use lint-history.py from git-filter-repo examples

https://github.com/newren/git-filter-repo
https://github.com/newren/git-filter-repo/blob/main/contrib/filter-
repo-
demos/lint-history

Line #127 - Add try except around subprocess.check_call() with except
being pass. This is required because there are a few commits of C
files in the edk2 repo that have incorrect C syntax and do not
build with a C compiler and break the uncrustify parser. Skip reformat
of C files that can not be parsed by uncrustify. These rare instances
are addressed in the commit that fixes the C syntax error.

Run this slightly modified version of lint-history. Include only
C/H files and exclude directories that start with 'Tools' or 'BaseTools'.
This step took about 2.2 hours on a laptop.

lint-history.py
--relevant "return (not filename.startswith(b'Tools') and not
filename.startswith(b'BaseTools') and (filename.endswith(b'.c') or
filename.endswith(b'.h')))"
c:\\work\\GitHub\\tianocore\\foo\\UncrustifyCheck\\mu-
uncrustify-
release_extdep\\Windows-x86\\uncrustify.exe -c
c:\\work\\GitHub\\tianocore\\foo\\UncrustifyCheck\\uncrustify.cfg --
replace --
no-backup --if-changed

Order of PRs to apply during extended hard freeze
==================================================
1) Update EmulatorPkg Win Host [BuildOptions] MSFT CC_FLAGS to not
force
debug information
*
INVALID URI REMOVED
d=3747__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJ
OYpcSVHo2BEG33c$
*
https://github.com/mdkinney/edk2/tree/Bug_3747_EmulatorPkg_WinHost_
Rep
roducibleBuild
* https://github.com/tianocore/edk2/pull/2215
* Required for EmulatorPkg to pass CompareBuild for VS2019 IA32/X64
builds.
* Status: Review complete. PR pushed.

2) EccCheck should not revert staged and local changes
*
INVALID URI REMOVED
d=2986__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJ
OYpcSVHotvR0Unk$
*
https://github.com/mdkinney/edk2/tree/Bug_2986_EccCheckRemoveGitRe
vert
_V2
* https://github.com/tianocore/edk2/pull/2216
* Required for EDK II CI to complete in a reasonable period of time when
processing the 4000+ source file style changes made by uncrustify.
* Also fixes critical bugs that can potentially corrupt git state when
EccCheck is run locally.
* Status: Review complete. PR pushed.

3) Update pytool LicenseCheck plugin to use temp directory for diff output
file
*
INVALID URI REMOVED
d=3746__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJ
OYpcSVHoWRuHaBw$
*
https://github.com/mdkinney/edk2/tree/Bug_3746_LicenseCheckUseDiffO
utput
File_V2
* https://github.com/tianocore/edk2/pull/2217
* Required to reduce EDK II CI build times.
* Status: Review complete. PR pushed.

4) Update max job time from 60 min to 120 minutes
in .azurepipelines/templates
*
INVALID URI REMOVED
d=3750__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJ
OYpcSVHozaVshgc$
*
https://github.com/mdkinney/edk2/tree/Bug_3750_IncreaseAzurePipelines
Time
out
* https://github.com/tianocore/edk2/pull/2219
* Required to allow EccCheck of uncrustify changes to complete on Azure
Pipelines CI agents without timing out.
* Status: Review complete. PR pushed.

5) Update Package YAML to ignore specific ECC files/errors
*
INVALID URI REMOVED
d=3749__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJ
OYpcSVHo-fY3dMo$
*
https://github.com/mdkinney/edk2/tree/Bug_3749_EccCheckIgnoreFilesErr
ors
* https://github.com/tianocore/edk2/pull/2218
* Required to pass EccCheck
* Status: Review complete. PR pushed

6) Uncrustify Source Changes
*
INVALID URI REMOVED
d=3737__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJ
OYpcSVHoMRa47YU$
*
INVALID URI REMOVED
d=3739__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJ
OYpcSVHoPAlckP8$
*
https://github.com/mdkinney/edk2/tree/Bug_3737_3739_ApplyUncrustifyC
han
ges_V5
* https://github.com/tianocore/edk2/pull/2229
* Build comparison result PASS:
https://github.com/mdkinney/edk2/actions/runs/1521618836
* EFI_D_ -> DEBUG changes required to pass PatchCheck
* Uncrustify format changes required to pass UncrustifyCheck
* Status:
Waiting for review

7) UncrustifyCheck EDK II CI Plugin
*
INVALID URI REMOVED
d=3748__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJ
OYpcSVHoCzEWymQ$
*
https://github.com/mdkinney/edk2/tree/Bug_3748_add_uncrustify_ci_plug
in_v
6
* Required to enforce all PRs submitted to EDK II CI match uncrustify
format.
* Unconditionally checks all packages. Can not be committed until all C/H
source files have been updated.
* Status: Review complete

Combined Branch/PR for Review/Test
==================================
* Build Comparison results must pass 100% across the full set of PRs before
the individual PRs can be pushed in the order listed above.
* Branch:
https://github.com/mdkinney/edk2/tree/TestOnly_Uncrustify_PR_Series
* PR: https://github.com/tianocore/edk2/pull/2229
Status = PASS
* CompareBuild:
Branch:
https://github.com/mdkinney/edk2/tree/Bug_3737_3739_ApplyUncrustifyC
han
ges_V5
--ref1: ef9a059cdb15844fe52a49af2bf7d86b9dd3e9bf
--ref2: Bug_3737_3739_ApplyUncrustifyChanges_V5
Extra Options: -n 4 --quiet
Results: https://github.com/mdkinney/edk2/actions/runs/1521618836
30 VS2019 build comparisons PASS
40 GCC5 build comparisons PASS
100% PASS

The following git log shows the set of patches from --ref1 to --ref 2across
which there are no differences in any of the OBJ/LIB/DLL/EFI/FFS/FV/FD
files.

--ref2
b7d4bf0675b7 (HEAD -> Bug_3737_3739_ApplyUncrustifyChanges_V5)
UnitTestFrameworkPkg: Apply uncrusitify changes
7f03d25f60e7 UefiPayloadPkg: Apply uncrusitify changes
0bfd8d9b5ac9 UefiCpuPkg: Apply uncrusitify changes
e1cd9bfb9dea StandaloneMmPkg: Apply uncrusitify changes
5da2f65be378 SourceLevelDebugPkg: Apply uncrusitify changes
95b86de07e5d SignedCapsulePkg: Apply uncrusitify changes
fe71d97246c4 ShellPkg: Apply uncrusitify changes
54c21c952992 SecurityPkg: Apply uncrusitify changes
187a3785f12b RedfishPkg: Apply uncrusitify changes
810100002a46 PcAtChipsetPkg: Apply uncrusitify changes
276a695c0cf2 OvmfPkg: Apply uncrusitify changes
303c0a91ab07 NetworkPkg: Apply uncrusitify changes
bc80792cd1b1 MdePkg: Apply uncrusitify changes
3ea86be17a2a MdeModulePkg: Apply uncrusitify changes
c70ef11ed0cd IntelFsp2WrapperPkg: Apply uncrusitify changes
c0291221f252 IntelFsp2Pkg: Apply uncrusitify changes
6a479952a690 FmpDevicePkg: Apply uncrusitify changes
3a7c05b7070d FatPkg: Apply uncrusitify changes
b789f98c8959 EmulatorPkg: Apply uncrusitify changes
952d7a1c9220 EmbeddedPkg: Apply uncrusitify changes
a1cc9881bab6 DynamicTablesPkg: Apply uncrusitify changes
50654dfe5785 CryptoPkg: Apply uncrusitify changes
ed965a02dfa1 ArmVirtPkg: Apply uncrusitify changes
9744023fbc46 ArmPlatformPkg: Apply uncrusitify changes
7a1cde5f5bba ArmPkg: Apply uncrusitify changes
19d17e0913e8 UefiCpuPkg: Change use of EFI_D_* to DEBUG_*
ffa718b4f994 SourceLevelDebugPkg: Change use of EFI_D_* to DEBUG_*
b86cb3c5e5b4 ShellPkg: Change use of EFI_D_* to DEBUG_*
c7c42204dc07 SecurityPkg: Change use of EFI_D_* to DEBUG_*
16b8e6f958e4 PcAtChipsetPkg: Change use of EFI_D_* to DEBUG_*
0ac3f8b2dac5 OvmfPkg: Change use of EFI_D_* to DEBUG_*
bc5004b8d294 NetworkPkg: Change use of EFI_D_* to DEBUG_*
6f671a8e2377 MdePkg: Change use of EFI_D_* to DEBUG_*
a10c610ff9a3 MdeModulePkg: Change use of EFI_D_* to DEBUG_*
09a3bddba390 FatPkg: Change use of EFI_D_* to DEBUG_*
59c61318246a EmulatorPkg: Change use of EFI_D_* to DEBUG_*
3a80367dda3b EmbeddedPkg: Change use of EFI_D_* to DEBUG_*
23eb1aaf80ca ArmVirtPkg: Change use of EFI_D_* to DEBUG_*
875914b45c54 ArmPlatformPkg: Change use of EFI_D_* to DEBUG_*
eb2eca82b451 ArmPkg: Change use of EFI_D_* to DEBUG_*
f0f3f5aae7c4 (origin/master, origin/HEAD, master) UnitTestFrameworkPkg:
Update YAML to ignore specific ECC files/errors
c05734797790 UefiPayloadPkg: Update YAML to ignore specific ECC
files/errors
c30c40d6c63d StandaloneMmPkg: Update YAML to ignore specific ECC
files/errors
9944508e85f1 ShellPkg: Update YAML to ignore specific ECC files/errors
60fa40be458d SecurityPkg: Update YAML to ignore specific ECC files/errors
df790cd6b37e MdePkg: Update YAML to ignore specific ECC files/errors
9deb9370766e MdeModulePkg: Update YAML to ignore specific ECC
files/errors
d7d30e8f219f EmulatorPkg: Update YAML to ignore specific ECC files/errors
d5744ecba813 CryptoPkg: Update YAML to ignore specific ECC files/errors
c97fee87f0f9 ArmVirtPkg: Update YAML to ignore specific ECC files/errors
1939fc9569f2 ArmPlatformPkg: Update YAML to ignore specific ECC
files/errors
365dced2c37a ArmPkg: Update YAML to ignore specific ECC files/errors
76a1ce4d5fec .azurepipelines/templates: Update max pipeline job time to
2
hours
99f84ff47390 .pytools/Plugin/LicenseCheck: Use temp directory for git diff
output
3019f1bbabf1 .pytool/Plugin/EccCheck: Add performance optimizations
854462bd3479 .pytool/Plugin/EccCheck: Remove temp directory on
exception
69877614fdee .pytool/Plugin/EccCheck: Remove RevertCode()
--ref1
ef9a059cdb15 EmulatorPkg/Win/Host: Update CC_FLAGS
bb1bba3d7767 (tag: edk2-stable202111) NetworkPkg: Fix invalid pointer for
DNS
response token on error

Best regards,

Mike















Re: EDK2 doxygen documentation - adding docs for stable tags?

Michael D Kinney
 

Hi Rebecca,

It does not push to gitbook server. It is pushed to web pages hosted by GitHub.

It uses gitbook tools to process MD files into published PDF, MOBI, HTML.

For example, the EDK II Build Specification has repo in GitHub:

https://github.com/tianocore-docs/edk2-BuildSpecification

And the HTML version of the draft revision of this spec is published here:

https://tianocore-docs.github.io/edk2-BuildSpecification/draft/

These are the web pages associated with tianocore-docs org.

Thanks,

Mike

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Rebecca Cran
Sent: Wednesday, December 1, 2021 8:52 AM
To: Kinney, Michael D <michael.d.kinney@...>; devel@edk2.groups.io
Subject: Re: [edk2-devel] EDK2 doxygen documentation - adding docs for stable tags?

From what I can see, the tianocore-docs actions push to gitbooks, not
tianocore.org?

I don't think gitbooks will work for the doxygen pages.


--

Rebecca Cran


On 11/30/21 20:21, Kinney, Michael D wrote:
Hi Rebecca,

This is a good idea. We use GitHub Actions to publish the EDK II Specifications
to a web page hosted as part of the documents GitHub repo.

I think we can do something similar for generating and publishing the doxygen
generated web content for the edk2 packages. I think a manually triggered
GitHub action in a repo in tianocore-docs organization might be a good place
to do this so all document publication activities are under that same org.
The GitHub action can take a branch or tag or sha of the edk2 repo as input
to generate the doxygen documentation.

Best regards,

Mike

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Rebecca Cran
Sent: Tuesday, November 9, 2021 3:20 PM
To: devel@edk2.groups.io; discuss@edk2.groups.io
Subject: [edk2-devel] EDK2 doxygen documentation - adding docs for stable tags?

I've been hosting the Doxygen documentation for EDK2 at
https://bsdio.com/edk2/docs for a few years now. I previously had
versions for master, UDK2015, UDK2017, UDK2018 etc. but since migrating
my web server dropped everything except master.


I was wondering if people are finding it useful, and if so whether
they'd like me to generate documentation for each stable tag too?


Personally, _I_ find the web-based version (as opposed to a
locally-generated version) useful for the search feature -- being able
to quickly find the documentation for a certain function.


--

Rebecca Cran








Re: EDK2 doxygen documentation - adding docs for stable tags?

Rebecca Cran
 

From what I can see, the tianocore-docs actions push to gitbooks, not tianocore.org?

I don't think gitbooks will work for the doxygen pages.


--

Rebecca Cran

On 11/30/21 20:21, Kinney, Michael D wrote:
Hi Rebecca,

This is a good idea. We use GitHub Actions to publish the EDK II Specifications
to a web page hosted as part of the documents GitHub repo.

I think we can do something similar for generating and publishing the doxygen
generated web content for the edk2 packages. I think a manually triggered
GitHub action in a repo in tianocore-docs organization might be a good place
to do this so all document publication activities are under that same org.
The GitHub action can take a branch or tag or sha of the edk2 repo as input
to generate the doxygen documentation.

Best regards,

Mike

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Rebecca Cran
Sent: Tuesday, November 9, 2021 3:20 PM
To: devel@edk2.groups.io; discuss@edk2.groups.io
Subject: [edk2-devel] EDK2 doxygen documentation - adding docs for stable tags?

I've been hosting the Doxygen documentation for EDK2 at
https://bsdio.com/edk2/docs for a few years now. I previously had
versions for master, UDK2015, UDK2017, UDK2018 etc. but since migrating
my web server dropped everything except master.


I was wondering if people are finding it useful, and if so whether
they'd like me to generate documentation for each stable tag too?


Personally, _I_ find the web-based version (as opposed to a
locally-generated version) useful for the search feature -- being able
to quickly find the documentation for a certain function.


--

Rebecca Cran





Re: Uncrustify Conversion Detailed Plan and Extended Hard Freeze Update #4

Michael D Kinney
 

Hi Abner,

Yes. That is possible. We are already excluding BaseTools.

In order to get the file lists that apply to uncrustify, we would have to change from:

git ls-files *.c *.h :!BaseTools/*

To:

git ls-files *.c *.h :!BaseTools/* :!RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/*

However, I do not see a feature in the UncrustifyCheck to check all c/h files in RedFishPkg and exclude one of its directories.
If we can specify an exclusion like this in the RedFishPkg YAML file, then I think that would work well.

Michael Kubacki would have to comment on how we support this in EDK II CI checks.

Best regards,

Mike

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Abner Chang
Sent: Tuesday, November 30, 2021 11:34 PM
To: devel@edk2.groups.io; Wang, Jian J <jian.j.wang@...>; Kinney, Michael D <michael.d.kinney@...>; Michael
Kubacki <michael.kubacki@...>; Andrew Fish (afish@...) <afish@...>; Leif Lindholm
<leif@...>
Subject: Re: [edk2-devel] Uncrustify Conversion Detailed Plan and Extended Hard Freeze Update #4

Hi Mike,
Is that possible to not applying uncrusitify on the source files that cloned from other open source?
e.g. RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/*.*

Thanks
Abner

-----Original Message-----
From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of
Wang, Jian J
Sent: Wednesday, December 1, 2021 2:39 PM
To: devel@edk2.groups.io; Kinney, Michael D <michael.d.kinney@...>;
Michael Kubacki <michael.kubacki@...>; Andrew Fish
(afish@...) <afish@...>; Leif Lindholm <leif@...>
Subject: Re: [edk2-devel] Uncrustify Conversion Detailed Plan and Extended
Hard Freeze Update #4

For SignedCapulePkg,

Reviewed-by: Jian J Wang <jian.j.wang@...>

Regards,
Jian

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
Michael D
Kinney
Sent: Wednesday, December 01, 2021 6:34 AM
To: devel@edk2.groups.io; Kinney, Michael D
<michael.d.kinney@...>;
Michael Kubacki <michael.kubacki@...>; Andrew Fish
(afish@...) <afish@...>; Leif Lindholm
<leif@...>
Subject: [edk2-devel] Uncrustify Conversion Detailed Plan and Extended
Hard
Freeze Update #4

Hello,

Thank you for your patience during this extended hard freeze.

Just one more step to go. There has been a delay in the review of
the patch series with the uncrustify source changes. PR(6). This
patch series was not sent out as patch review email because of its
very large size. It only contains source style changes and the
CompareBuild tool and GitHub action has shown there are no binary
differences introduced with these source style changes.

If you are a package maintainer, then please review the following
branch/PR for your package contents and review the EDK II CI results
and BuildCompare results. I do not expect a line by line review
because we already had time to provide feedback on the source style
performed by uncrustify. Instead, a Reviewed-by for your package
indicates that you have reviewed the EDK II CI results and CompareBuild
tool functionality and results and you accept the source style
changes to your package.

*
https://github.com/mdkinney/edk2/tree/Bug_3737_3739_ApplyUncrustifyC
han
ges_V5
* https://github.com/tianocore/edk2/pull/2229
* https://github.com/mdkinney/edk2/actions/runs/1521618836

Additional details on this update below.

Thank you,

Mike


Changes from Update #3
----------------------------------------------------------------------------
* Pushed PR (5)
* Added link to PR(6). EDK II CI Status is PASS. Build Compare PASS.
* Waiting for review of PR (6)
* Review of PR (7) completed and waiting for review of PR (6)
----------------------------------------------------------------------------

Changes from Update #2
----------------------------------------------------------------------------
* Changed order of PRs swapping (4) and (5). The PR that activates
increases the max CI agent job time is independent of all the other
PRs and its review is complete, so it can be committed now.
* Pushed PRs (1), (2), (3), (4).
* Waiting for review to complete for PRs (5) and (6)
* Reviews complete for PR (7)
* Identifies steps using git filter-branch to apply uncrustify changes to a
code review patch series that was generated before the uncrustify
changes
avoiding manual merge.
* Identified steps using git filter-repo to generate an alternate history of
the edk2 repo with uncrustify changes applied on every commit. This may
be useful when evaluating changes to files using tools like git blame
without the large uncrustify patch series.
---------------------------------------------------------------------------

Changes from Update #1
----------------------------------------------------------------------------
* Changed order of PRs swapping (6) and (7). The PR that activates
EDK II CI check UncrustifyCheck has to be last because it unconditionally
checks all C/H files in all packages. Not just files that have been
modified like some of the other checkers.
* Updated link to the branch with the UncrustifyCheck plugin that has been
updated with a one line change and Reviewed-by and Tested-by tags.

https://github.com/mdkinney/edk2/tree/Bug_3748_add_uncrustify_ci_plug
in_v
6
* Reviews complete for (1), (2), (3), (5), and (7)
---------------------------------------------------------------------------

Michael Kubacki and I have prepared the patches required to apply the
uncrustify changes and enable EDK II CI to check all submitted
patches have been run through uncrustify.

We have verified through the CompareBuild GitHub Action that the
format changes performed by uncrustify have no functional changes.
All of the OBJ, LIB, DLL, EFI, FFS, FV, and FD files match 100%
across 70 VS2019/GCC5 builds of all package/platform DSC files in
the edk2 repo.

The hard freeze will be extended after the edk2-stable202111 tag until
all uncrustify related changes are committed. We do not expect this
to take more than a few days. Do not push any PRs until the hard
freeze is lifted.

The changes are broken up into 7 patch series/PRs. The PRs are ordered
so they can be submitted using the normal submission process and EDK II
CI will pass for each one. Details are listed below.

Uncrustify 73.0.3 for EDK II
=============================
* Sources:
INVALID URI REMOVED
stify__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJOYp
cSVHoHwMD2t8$
* Documentation:
INVALID URI REMOVED
/_wiki/wikis/Uncrustify.wiki/1/Proj__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKk
oslR8D0LLPZTWXL0OKtMZJOYpcSVHoP8OtlxM$
ect-Mu-(EDK-II)-Fork-Readme
* Download:
INVALID URI REMOVED
/_packaging?_a=package&feed=m__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKk
oslR8D0LLPZTWXL0OKtMZJOYpcSVHo4yTWeAM$
u_uncrustify&package=mu-uncrustify-
release&protocolType=NuGet&version=73.0.3

Installing Uncrustify
======================
The Uncrustify tool is installed automatically when the Pytools
environment is used and the stuart* commands are run to complete the
environment setup. Please see:

https://github.com/tianocore/edk2/tree/master/.pytool#running-ci-
locally

Uncrustify can also be installed from the download page listed above
or built from sources from the source link above.

The Documentation link provides instruction on how to run uncrustify from
the command line or install as a Visual Studio Code plugin. The main
uncrustify documentation also describes how to integrate with a few other
editors.

We have also discussed a client side githook. That effort has not started.
Let us know if that is a feature you would find useful.

Developer impact for new code reviews
======================================
Once the uncrustify checker is active in EDK II CI, developers must
make sure their patches are run through the uncrustify tool before
sending the patches for review.

Developers must install and run uncrustify against changes files before
sending patch review emails or submitting PR for EDK II CI. If EDK II CI
detects and differences in source formatting, then EDK II CI will fail
and the developer must run uncrustify and resubmit the patches.

Developer impact to patch series/PRs reviewed during edk2-stable201121
soft/hard freeze
==========================================================
=======
======================
Developers must rebase their changes after the uncrustify source changes
are
committed. The branch with a preview of the uncrustify changes can be
used
to start this rebase work.


https://github.com/mdkinney/edk2/tree/Bug_3737_3739_ApplyUncrustifyC
han
ges_V5

The following steps can be used to update an existing branch with the
required uncrustify format. This is the Windows version. I will add
the Linux version soon.

1) Fetch and checkout and rebase to latest edk2/master

git fetch origin
git checkout master
git rebase origin/master

2) Make a backup copy of plugin UncrustifyCheck outside WORKSPACE.
(e.g. C:\Temp\UncrustifyCheck) so the uncrustify tool executable and
EDK II specific uncrustify configuration file available when working
with a branch that does not have those tools in its scope.

xcopy .pytool\Plugin\UncrustifyCheck C:\Temp\UncrustifyCheck

3) Check out the patch series branch (e.g. MyBranch)

git checkout MyBranch

4) Rebase patch series against edk2-stable202111

git rebase edk2-stable202111

5) Create new branch for the uncrustifed version (e.g.
MyBranch_Uncrustified)

git checkout -b MyBranch_Uncrustified

6) Use git filter-branch to uncrustify all the commits in the series
between the rebase target from (2) and HEAD of the branch. A filter
can be used to scope the uncrustify operations to only the C/H files
in the specific package the patch series is against. (e.g.
DynamicTablesPkg).
BaseTools should always be excluded. If the package scoped filter is
not used, it will still work, but will take longer to run because
uncrustify will rescan every C/H files in the whole repo.

git filter-branch --tree-filter "git ls-files DynamicTablesPkg*.c
DynamicTablesPkg*.h :!BaseTools/* | c:\\Temp\\UncrustifyCheck\\mu-
uncrustify-release_extdep\\Windows-x86\\uncrustify.exe -c
c:\\Temp\\UncrustifyCheck\\uncrustify.cfg -F - --replace --no-backup --if-
changed" edk2-stable202111..HEAD

7) Now that all the individual patches in the branch are uncrustified,
rebase against latest edk2/master that is already uncrustified.

git rebase master

8) Verify the patches in this new branch.

Impacts to tracing history across the uncrusity changes
=======================================================
Tools the view file and line history do work with the large uncrustify
patch series. One impact is that the operations can be very slow due
to the large uncrustify patches.

One option to provide a faster experience is to provide an alternate
version of the edk2 repository as "documentation" that has the
entire history re-written with uncrustify run on every commit.
The tool called git-filter-repo can be used to perform this
transformation and runs in a reasonable period of time (a few hours)

https://github.com/newren/git-filter-repo
https://github.com/newren/git-filter-repo/blob/main/contrib/filter-
repo-
demos/lint-history

The following steps can be used to perform this transformation.
This is the Windows version. I will add the Linux version soon.

** WARNING ** This operation modifies(rewrites) all the commits
in the local copy of the repo. Do not perform
these steps on a local repo you are using for
active development.

1) Clone edk2 into a new directory (see **WARNING**)

git clone https://github.com/tianocore/edk2.git edk2-uncrustified
cd edk2-uncrustified

2) Setup python virtual env, install pytools, and run stuart commands
to setup build environment which includes installing uncrustify tools.

https://github.com/tianocore/edk2/tree/master/.pytool#running-ci-
locally

3) Make a backup copy of plugin UncrustifyCheck outside WORKSPACE.
(e.g. C:\Temp\UncrustifyCheck) so the uncrustify tool executable and
EDK II specific uncrustify configuration file available when working
with a branch that does not have those tools in its scope.

xcopy .pytool\Plugin\UncrustifyCheck C:\Temp\UncrustifyCheck

4) Use lint-history.py from git-filter-repo examples

https://github.com/newren/git-filter-repo
https://github.com/newren/git-filter-repo/blob/main/contrib/filter-
repo-
demos/lint-history

Line #127 - Add try except around subprocess.check_call() with except
being pass. This is required because there are a few commits of C
files in the edk2 repo that have incorrect C syntax and do not
build with a C compiler and break the uncrustify parser. Skip reformat
of C files that can not be parsed by uncrustify. These rare instances
are addressed in the commit that fixes the C syntax error.

Run this slightly modified version of lint-history. Include only
C/H files and exclude directories that start with 'Tools' or 'BaseTools'.
This step took about 2.2 hours on a laptop.

lint-history.py
--relevant "return (not filename.startswith(b'Tools') and not
filename.startswith(b'BaseTools') and (filename.endswith(b'.c') or
filename.endswith(b'.h')))"
c:\\work\\GitHub\\tianocore\\foo\\UncrustifyCheck\\mu-
uncrustify-
release_extdep\\Windows-x86\\uncrustify.exe -c
c:\\work\\GitHub\\tianocore\\foo\\UncrustifyCheck\\uncrustify.cfg --
replace --
no-backup --if-changed

Order of PRs to apply during extended hard freeze
==================================================
1) Update EmulatorPkg Win Host [BuildOptions] MSFT CC_FLAGS to not
force
debug information
*
INVALID URI REMOVED
d=3747__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJ
OYpcSVHo2BEG33c$
*
https://github.com/mdkinney/edk2/tree/Bug_3747_EmulatorPkg_WinHost_
Rep
roducibleBuild
* https://github.com/tianocore/edk2/pull/2215
* Required for EmulatorPkg to pass CompareBuild for VS2019 IA32/X64
builds.
* Status: Review complete. PR pushed.

2) EccCheck should not revert staged and local changes
*
INVALID URI REMOVED
d=2986__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJ
OYpcSVHotvR0Unk$
*
https://github.com/mdkinney/edk2/tree/Bug_2986_EccCheckRemoveGitRe
vert
_V2
* https://github.com/tianocore/edk2/pull/2216
* Required for EDK II CI to complete in a reasonable period of time when
processing the 4000+ source file style changes made by uncrustify.
* Also fixes critical bugs that can potentially corrupt git state when
EccCheck is run locally.
* Status: Review complete. PR pushed.

3) Update pytool LicenseCheck plugin to use temp directory for diff output
file
*
INVALID URI REMOVED
d=3746__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJ
OYpcSVHoWRuHaBw$
*
https://github.com/mdkinney/edk2/tree/Bug_3746_LicenseCheckUseDiffO
utput
File_V2
* https://github.com/tianocore/edk2/pull/2217
* Required to reduce EDK II CI build times.
* Status: Review complete. PR pushed.

4) Update max job time from 60 min to 120 minutes
in .azurepipelines/templates
*
INVALID URI REMOVED
d=3750__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJ
OYpcSVHozaVshgc$
*
https://github.com/mdkinney/edk2/tree/Bug_3750_IncreaseAzurePipelines
Time
out
* https://github.com/tianocore/edk2/pull/2219
* Required to allow EccCheck of uncrustify changes to complete on Azure
Pipelines CI agents without timing out.
* Status: Review complete. PR pushed.

5) Update Package YAML to ignore specific ECC files/errors
*
INVALID URI REMOVED
d=3749__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJ
OYpcSVHo-fY3dMo$
*
https://github.com/mdkinney/edk2/tree/Bug_3749_EccCheckIgnoreFilesErr
ors
* https://github.com/tianocore/edk2/pull/2218
* Required to pass EccCheck
* Status: Review complete. PR pushed

6) Uncrustify Source Changes
*
INVALID URI REMOVED
d=3737__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJ
OYpcSVHoMRa47YU$
*
INVALID URI REMOVED
d=3739__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJ
OYpcSVHoPAlckP8$
*
https://github.com/mdkinney/edk2/tree/Bug_3737_3739_ApplyUncrustifyC
han
ges_V5
* https://github.com/tianocore/edk2/pull/2229
* Build comparison result PASS:
https://github.com/mdkinney/edk2/actions/runs/1521618836
* EFI_D_ -> DEBUG changes required to pass PatchCheck
* Uncrustify format changes required to pass UncrustifyCheck
* Status:
Waiting for review

7) UncrustifyCheck EDK II CI Plugin
*
INVALID URI REMOVED
d=3748__;!!NpxR!3rTN8lYPg_5bczi9Qai9VWvHKkoslR8D0LLPZTWXL0OKtMZJ
OYpcSVHoCzEWymQ$
*
https://github.com/mdkinney/edk2/tree/Bug_3748_add_uncrustify_ci_plug
in_v
6
* Required to enforce all PRs submitted to EDK II CI match uncrustify
format.
* Unconditionally checks all packages. Can not be committed until all C/H
source files have been updated.
* Status: Review complete

Combined Branch/PR for Review/Test
==================================
* Build Comparison results must pass 100% across the full set of PRs before
the individual PRs can be pushed in the order listed above.
* Branch:
https://github.com/mdkinney/edk2/tree/TestOnly_Uncrustify_PR_Series
* PR: https://github.com/tianocore/edk2/pull/2229
Status = PASS
* CompareBuild:
Branch:
https://github.com/mdkinney/edk2/tree/Bug_3737_3739_ApplyUncrustifyC
han
ges_V5
--ref1: ef9a059cdb15844fe52a49af2bf7d86b9dd3e9bf
--ref2: Bug_3737_3739_ApplyUncrustifyChanges_V5
Extra Options: -n 4 --quiet
Results: https://github.com/mdkinney/edk2/actions/runs/1521618836
30 VS2019 build comparisons PASS
40 GCC5 build comparisons PASS
100% PASS

The following git log shows the set of patches from --ref1 to --ref 2across
which there are no differences in any of the OBJ/LIB/DLL/EFI/FFS/FV/FD
files.

--ref2
b7d4bf0675b7 (HEAD -> Bug_3737_3739_ApplyUncrustifyChanges_V5)
UnitTestFrameworkPkg: Apply uncrusitify changes
7f03d25f60e7 UefiPayloadPkg: Apply uncrusitify changes
0bfd8d9b5ac9 UefiCpuPkg: Apply uncrusitify changes
e1cd9bfb9dea StandaloneMmPkg: Apply uncrusitify changes
5da2f65be378 SourceLevelDebugPkg: Apply uncrusitify changes
95b86de07e5d SignedCapsulePkg: Apply uncrusitify changes
fe71d97246c4 ShellPkg: Apply uncrusitify changes
54c21c952992 SecurityPkg: Apply uncrusitify changes
187a3785f12b RedfishPkg: Apply uncrusitify changes
810100002a46 PcAtChipsetPkg: Apply uncrusitify changes
276a695c0cf2 OvmfPkg: Apply uncrusitify changes
303c0a91ab07 NetworkPkg: Apply uncrusitify changes
bc80792cd1b1 MdePkg: Apply uncrusitify changes
3ea86be17a2a MdeModulePkg: Apply uncrusitify changes
c70ef11ed0cd IntelFsp2WrapperPkg: Apply uncrusitify changes
c0291221f252 IntelFsp2Pkg: Apply uncrusitify changes
6a479952a690 FmpDevicePkg: Apply uncrusitify changes
3a7c05b7070d FatPkg: Apply uncrusitify changes
b789f98c8959 EmulatorPkg: Apply uncrusitify changes
952d7a1c9220 EmbeddedPkg: Apply uncrusitify changes
a1cc9881bab6 DynamicTablesPkg: Apply uncrusitify changes
50654dfe5785 CryptoPkg: Apply uncrusitify changes
ed965a02dfa1 ArmVirtPkg: Apply uncrusitify changes
9744023fbc46 ArmPlatformPkg: Apply uncrusitify changes
7a1cde5f5bba ArmPkg: Apply uncrusitify changes
19d17e0913e8 UefiCpuPkg: Change use of EFI_D_* to DEBUG_*
ffa718b4f994 SourceLevelDebugPkg: Change use of EFI_D_* to DEBUG_*
b86cb3c5e5b4 ShellPkg: Change use of EFI_D_* to DEBUG_*
c7c42204dc07 SecurityPkg: Change use of EFI_D_* to DEBUG_*
16b8e6f958e4 PcAtChipsetPkg: Change use of EFI_D_* to DEBUG_*
0ac3f8b2dac5 OvmfPkg: Change use of EFI_D_* to DEBUG_*
bc5004b8d294 NetworkPkg: Change use of EFI_D_* to DEBUG_*
6f671a8e2377 MdePkg: Change use of EFI_D_* to DEBUG_*
a10c610ff9a3 MdeModulePkg: Change use of EFI_D_* to DEBUG_*
09a3bddba390 FatPkg: Change use of EFI_D_* to DEBUG_*
59c61318246a EmulatorPkg: Change use of EFI_D_* to DEBUG_*
3a80367dda3b EmbeddedPkg: Change use of EFI_D_* to DEBUG_*
23eb1aaf80ca ArmVirtPkg: Change use of EFI_D_* to DEBUG_*
875914b45c54 ArmPlatformPkg: Change use of EFI_D_* to DEBUG_*
eb2eca82b451 ArmPkg: Change use of EFI_D_* to DEBUG_*
f0f3f5aae7c4 (origin/master, origin/HEAD, master) UnitTestFrameworkPkg:
Update YAML to ignore specific ECC files/errors
c05734797790 UefiPayloadPkg: Update YAML to ignore specific ECC
files/errors
c30c40d6c63d StandaloneMmPkg: Update YAML to ignore specific ECC
files/errors
9944508e85f1 ShellPkg: Update YAML to ignore specific ECC files/errors
60fa40be458d SecurityPkg: Update YAML to ignore specific ECC files/errors
df790cd6b37e MdePkg: Update YAML to ignore specific ECC files/errors
9deb9370766e MdeModulePkg: Update YAML to ignore specific ECC
files/errors
d7d30e8f219f EmulatorPkg: Update YAML to ignore specific ECC files/errors
d5744ecba813 CryptoPkg: Update YAML to ignore specific ECC files/errors
c97fee87f0f9 ArmVirtPkg: Update YAML to ignore specific ECC files/errors
1939fc9569f2 ArmPlatformPkg: Update YAML to ignore specific ECC
files/errors
365dced2c37a ArmPkg: Update YAML to ignore specific ECC files/errors
76a1ce4d5fec .azurepipelines/templates: Update max pipeline job time to
2
hours
99f84ff47390 .pytools/Plugin/LicenseCheck: Use temp directory for git diff
output
3019f1bbabf1 .pytool/Plugin/EccCheck: Add performance optimizations
854462bd3479 .pytool/Plugin/EccCheck: Remove temp directory on
exception
69877614fdee .pytool/Plugin/EccCheck: Remove RevertCode()
--ref1
ef9a059cdb15 EmulatorPkg/Win/Host: Update CC_FLAGS
bb1bba3d7767 (tag: edk2-stable202111) NetworkPkg: Fix invalid pointer for
DNS
response token on error

Best regards,

Mike















[PATCH 1/1] OvmfPkg/MemEncryptSevLib: Check the guest type before EsWorkarea access

Brijesh Singh
 

The commit 80e67af9afca added support for a generic workarea concept.
The workarea header contains the information of the guest type. The
header is populated by ResetVector code during the guest detection.

Currently, the InternalMemEncryptSevStatus() reads the EsWorkArea to
determine the C-bit position. The EsWorkArea PCD is valid only for the
SEV guest type. Add a check of the guest type before accessing the
EsWorkArea PCD.

Fixes: 80e67af9afca ("OvmfPkg: introduce a common work area")
Cc: James Bottomley <jejb@...>
Cc: Min Xu <min.m.xu@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Cc: Jordan Justen <jordan.l.justen@...>
Cc: Ard Biesheuvel <ardb+tianocore@...>
Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: Qi Zhou <atmgnd@...>
Signed-off-by: Brijesh Singh <brijesh.singh@...>
---
.../DxeMemEncryptSevLib.inf | 2 +
.../PeiMemEncryptSevLib.inf | 2 +
.../SecMemEncryptSevLib.inf | 2 +
.../PeiMemEncryptSevLibInternal.c | 50 +++++++++++++++-
.../SecMemEncryptSevLibInternal.c | 58 ++++++++++++++++++-
5 files changed, 110 insertions(+), 4 deletions(-)

diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf b/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf
index f2e162d68076..03b66b986f1f 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf
@@ -54,4 +54,6 @@ [FeaturePcd]
gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire

[Pcd]
+ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase
gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask
+ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfConfidentialComputingWorkAreaHeader
diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf
index 03a78c32df28..16dd4d9d8b77 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf
@@ -54,4 +54,6 @@ [FeaturePcd]
gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire

[FixedPcd]
+ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase
gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase
+ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfConfidentialComputingWorkAreaHeader
diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf b/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf
index 279c38bfbc2c..a933cb33a9cb 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf
@@ -48,4 +48,6 @@ [LibraryClasses]
PcdLib

[FixedPcd]
+ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase
gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase
+ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfConfidentialComputingWorkAreaHeader
diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLibInternal.c b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLibInternal.c
index e2fd109d120f..db4249ec0d7d 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLibInternal.c
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLibInternal.c
@@ -24,6 +24,52 @@ STATIC BOOLEAN mSevStatusChecked = FALSE;
STATIC UINT64 mSevEncryptionMask = 0;
STATIC BOOLEAN mSevEncryptionMaskSaved = FALSE;

+/**
+ Determine if the SEV is active.
+
+ During the early booting, GuestType is set in the work area. Verify that it
+ is an SEV guest.
+
+ @retval TRUE SEV is enabled
+ @retval FALSE SEV is not enabled
+
+ **/
+STATIC
+BOOLEAN
+IsSevGuest (
+ VOID
+ )
+{
+ OVMF_WORK_AREA *WorkArea;
+
+ //
+ // Ensure that the size of the Confidential Computing work area header
+ // is same as what is provided through a fixed PCD.
+ //
+ ASSERT ((UINTN) FixedPcdGet32 (PcdOvmfConfidentialComputingWorkAreaHeader) ==
+ sizeof(CONFIDENTIAL_COMPUTING_WORK_AREA_HEADER));
+
+ WorkArea = (OVMF_WORK_AREA *) FixedPcdGet32 (PcdOvmfWorkAreaBase);
+
+ return ((WorkArea != NULL) && (WorkArea->Header.GuestType == GUEST_TYPE_AMD_SEV));
+}
+
+STATIC
+SEC_SEV_ES_WORK_AREA *
+GetSevEsWorkArea (
+ VOID
+ )
+{
+ //
+ // Before accessing the Es workarea lets verify that its SEV guest
+ //
+ if (!IsSevGuest()) {
+ return NULL;
+ }
+
+ return (SEC_SEV_ES_WORK_AREA *) FixedPcdGet32 (PcdSevEsWorkAreaBase);
+}
+
/**
Reads and sets the status of SEV features.

@@ -43,7 +89,7 @@ InternalMemEncryptSevStatus (

ReadSevMsr = FALSE;

- SevEsWorkArea = (SEC_SEV_ES_WORK_AREA *) FixedPcdGet32 (PcdSevEsWorkAreaBase);
+ SevEsWorkArea = GetSevEsWorkArea ();
if (SevEsWorkArea != NULL && SevEsWorkArea->EncryptionMask != 0) {
//
// The MSR has been read before, so it is safe to read it again and avoid
@@ -139,7 +185,7 @@ MemEncryptSevGetEncryptionMask (
if (!mSevEncryptionMaskSaved) {
SEC_SEV_ES_WORK_AREA *SevEsWorkArea;

- SevEsWorkArea = (SEC_SEV_ES_WORK_AREA *) FixedPcdGet32 (PcdSevEsWorkAreaBase);
+ SevEsWorkArea = GetSevEsWorkArea ();
if (SevEsWorkArea != NULL) {
mSevEncryptionMask = SevEsWorkArea->EncryptionMask;
} else {
diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibInternal.c b/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibInternal.c
index 56d8f3f3183f..d7aff1fa40ba 100644
--- a/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibInternal.c
+++ b/OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLibInternal.c
@@ -17,6 +17,52 @@
#include <Register/Cpuid.h>
#include <Uefi/UefiBaseType.h>

+/**
+ Determine if the SEV is active.
+
+ During the early booting, GuestType is set in the work area. Verify that it
+ is an SEV guest.
+
+ @retval TRUE SEV is enabled
+ @retval FALSE SEV is not enabled
+
+ **/
+STATIC
+BOOLEAN
+IsSevGuest (
+ VOID
+ )
+{
+ OVMF_WORK_AREA *WorkArea;
+
+ //
+ // Ensure that the size of the Confidential Computing work area header
+ // is same as what is provided through a fixed PCD.
+ //
+ ASSERT ((UINTN) FixedPcdGet32 (PcdOvmfConfidentialComputingWorkAreaHeader) ==
+ sizeof(CONFIDENTIAL_COMPUTING_WORK_AREA_HEADER));
+
+ WorkArea = (OVMF_WORK_AREA *) FixedPcdGet32 (PcdOvmfWorkAreaBase);
+
+ return ((WorkArea != NULL) && (WorkArea->Header.GuestType == GUEST_TYPE_AMD_SEV));
+}
+
+STATIC
+SEC_SEV_ES_WORK_AREA *
+GetSevEsWorkArea (
+ VOID
+ )
+{
+ //
+ // Before accessing the Es workarea lets verify that its SEV guest
+ //
+ if (!IsSevGuest()) {
+ return NULL;
+ }
+
+ return (SEC_SEV_ES_WORK_AREA *) FixedPcdGet32 (PcdSevEsWorkAreaBase);
+}
+
/**
Reads and sets the status of SEV features.

@@ -35,7 +81,8 @@ InternalMemEncryptSevStatus (

ReadSevMsr = FALSE;

- SevEsWorkArea = (SEC_SEV_ES_WORK_AREA *) FixedPcdGet32 (PcdSevEsWorkAreaBase);
+
+ SevEsWorkArea = GetSevEsWorkArea ();
if (SevEsWorkArea != NULL && SevEsWorkArea->EncryptionMask != 0) {
//
// The MSR has been read before, so it is safe to read it again and avoid
@@ -115,7 +162,14 @@ MemEncryptSevGetEncryptionMask (
SEC_SEV_ES_WORK_AREA *SevEsWorkArea;
UINT64 EncryptionMask;

- SevEsWorkArea = (SEC_SEV_ES_WORK_AREA *) FixedPcdGet32 (PcdSevEsWorkAreaBase);
+ //
+ // Before accessing the Es workarea lets verify that its SEV guest
+ //
+ if (!IsSevGuest()) {
+ return 0;
+ }
+
+ SevEsWorkArea = GetSevEsWorkArea ();
if (SevEsWorkArea != NULL) {
EncryptionMask = SevEsWorkArea->EncryptionMask;
} else {
--
2.25.1


Re: [Patch 02/12] ArmPlatformPkg: Update YAML to ignore specific ECC files/errors

PierreGondois
 

Hi,

If the exceptions to the yaml files are added to allow the unscrustify patches to pass the CI tests, shouldn't the same exceptions be removed once the patches are merged ?

Regards,

Pierre

On 11/23/21 10:21 PM, Michael D Kinney via groups.io wrote:
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3749

Update package YAML files to ignore ECC errors that are
already present. These issues must be fixed in the future,
but should not block source code changes for these known
issues.

Cc: Leif Lindholm <leif@...>
Cc: Ard Biesheuvel <ardb+tianocore@...>
Cc: Sean Brogan <sean.brogan@...>
Cc: Bret Barkelew <Bret.Barkelew@...>
Cc: Liming Gao <gaoliming@...>
Cc: Michael Kubacki <michael.kubacki@...>
Signed-off-by: Michael D Kinney <michael.d.kinney@...>
---
ArmPlatformPkg/ArmPlatformPkg.ci.yaml | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/ArmPlatformPkg/ArmPlatformPkg.ci.yaml b/ArmPlatformPkg/ArmPlatformPkg.ci.yaml
index 3dbbcc673bf0..03632e74df73 100644
--- a/ArmPlatformPkg/ArmPlatformPkg.ci.yaml
+++ b/ArmPlatformPkg/ArmPlatformPkg.ci.yaml
@@ -19,7 +19,8 @@
],
## Both file path and directory path are accepted.
"IgnoreFiles": [
- "Scripts/Ds5/"
+ "Scripts/Ds5/",
+ "Drivers/PL061GpioDxe/PL061Gpio.c"
]
},


[PATCH 5/5] OvmfPkg: Install ACPI tables for Cloud Hypervisor

Boeuf, Sebastien
 

From: Sebastien Boeuf <sebastien.boeuf@...>

Adding support for retrieving the Cloud Hypervisor ACPI tables as a
fallback mechanism if tables are not found through fw_cfg.

Signed-off-by: Rob Bradford <robert.bradford@...>
Signed-off-by: Sebastien Boeuf <sebastien.boeuf@...>
---
OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c | 4 +
OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h | 6 +
OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf | 1 +
OvmfPkg/AcpiPlatformDxe/CloudHvAcpi.c | 117 ++++++++++++++++++++
OvmfPkg/Include/IndustryStandard/CloudHv.h | 5 +
5 files changed, 133 insertions(+)
create mode 100644 OvmfPkg/AcpiPlatformDxe/CloudHvAcpi.c

diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c
index 613a8ac97f..abd1f550d4 100644
--- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c
+++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c
@@ -29,5 +29,9 @@ InstallAcpiTables (
EFI_STATUS Status;

Status = InstallQemuFwCfgTables (AcpiTable);
+ if (EFI_ERROR (Status)) {
+ Status = InstallCloudHvTables (AcpiTable);
+ }
+
return Status;
}
diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h
index bd4c26f07f..bee48a93da 100644
--- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h
+++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h
@@ -19,6 +19,12 @@ typedef struct {

typedef struct S3_CONTEXT S3_CONTEXT;

+EFI_STATUS
+EFIAPI
+InstallCloudHvTables (
+ IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol
+ );
+
EFI_STATUS
EFIAPI
InstallQemuFwCfgTables (
diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf b/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
index eedd3b5af3..3ac9054d75 100644
--- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
+++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
@@ -24,6 +24,7 @@
AcpiPlatform.c
AcpiPlatform.h
BootScript.c
+ CloudHvAcpi.c
EntryPoint.c
PciDecoding.c
QemuFwCfgAcpi.c
diff --git a/OvmfPkg/AcpiPlatformDxe/CloudHvAcpi.c b/OvmfPkg/AcpiPlatformDxe/CloudHvAcpi.c
new file mode 100644
index 0000000000..96c532cce6
--- /dev/null
+++ b/OvmfPkg/AcpiPlatformDxe/CloudHvAcpi.c
@@ -0,0 +1,117 @@
+/** @file
+ OVMF ACPI Cloud Hypervisor support
+
+ Copyright (c) 2021, Intel Corporation. All rights reserved.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <IndustryStandard/CloudHv.h> // CLOUDHV_RSDP_ADDRESS
+#include <Library/BaseLib.h> // CpuDeadLoop()
+#include <Library/DebugLib.h> // DEBUG()
+
+#include "AcpiPlatform.h"
+
+// Get the ACPI tables from EBDA start
+EFI_STATUS
+EFIAPI
+InstallCloudHvTables (
+ IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol
+ )
+{
+ EFI_STATUS Status;
+ UINTN TableHandle;
+
+ EFI_ACPI_DESCRIPTION_HEADER *Xsdt;
+ VOID *CurrentTableEntry;
+ UINTN CurrentTablePointer;
+ EFI_ACPI_DESCRIPTION_HEADER *CurrentTable;
+ UINTN Index;
+ UINTN NumberOfTableEntries;
+ EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt2Table;
+ EFI_ACPI_DESCRIPTION_HEADER *DsdtTable;
+ Fadt2Table = NULL;
+ DsdtTable = NULL;
+ TableHandle = 0;
+ NumberOfTableEntries = 0;
+ EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *AcpiRsdpStructurePtr = (VOID *)CLOUDHV_RSDP_ADDRESS;
+
+ // If XSDT table is found, just install its tables.
+ // Otherwise, try to find and install the RSDT tables.
+ //
+ if (AcpiRsdpStructurePtr->XsdtAddress) {
+ //
+ // Retrieve the addresses of XSDT and
+ // calculate the number of its table entries.
+ //
+ Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN)
+ AcpiRsdpStructurePtr->XsdtAddress;
+ NumberOfTableEntries = (Xsdt->Length -
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER)) /
+ sizeof (UINT64);
+
+ //
+ // Install ACPI tables found in XSDT.
+ //
+ for (Index = 0; Index < NumberOfTableEntries; Index++) {
+ //
+ // Get the table entry from XSDT
+ //
+ CurrentTableEntry = (VOID *) ((UINT8 *) Xsdt +
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER) +
+ Index * sizeof (UINT64));
+ CurrentTablePointer = (UINTN) *(UINT64 *)CurrentTableEntry;
+ CurrentTable = (EFI_ACPI_DESCRIPTION_HEADER *) CurrentTablePointer;
+
+ //
+ // Install the XSDT tables
+ //
+ Status = AcpiProtocol->InstallAcpiTable (
+ AcpiProtocol,
+ CurrentTable,
+ CurrentTable->Length,
+ &TableHandle
+ );
+
+ if (EFI_ERROR (Status)) {
+ ASSERT_EFI_ERROR(Status);
+ return Status;
+ }
+
+ //
+ // Get the X-DSDT table address from the table FADT
+ //
+ if (!AsciiStrnCmp ((CHAR8 *) &CurrentTable->Signature, "FACP", 4)) {
+ Fadt2Table = (EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *)
+ (UINTN) CurrentTablePointer;
+ DsdtTable = (EFI_ACPI_DESCRIPTION_HEADER *) (UINTN) Fadt2Table->XDsdt;
+ }
+ }
+ } else {
+ return EFI_NOT_FOUND;
+ }
+
+ //
+ // Install DSDT table. If we reached this point without finding the DSDT,
+ // then we're out of sync with the hypervisor, and cannot continue.
+ //
+ if (DsdtTable == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a: no DSDT found\n", __FUNCTION__));
+ ASSERT (FALSE);
+ CpuDeadLoop ();
+ }
+
+ Status = AcpiProtocol->InstallAcpiTable (
+ AcpiProtocol,
+ DsdtTable,
+ DsdtTable->Length,
+ &TableHandle
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT_EFI_ERROR(Status);
+ return Status;
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/OvmfPkg/Include/IndustryStandard/CloudHv.h b/OvmfPkg/Include/IndustryStandard/CloudHv.h
index ad0e170795..3a01dbb7d7 100644
--- a/OvmfPkg/Include/IndustryStandard/CloudHv.h
+++ b/OvmfPkg/Include/IndustryStandard/CloudHv.h
@@ -37,4 +37,9 @@
//
#define CLOUDHV_SMBIOS_ADDRESS 0xf0000

+//
+// RSDP address
+//
+#define CLOUDHV_RSDP_ADDRESS 0xa0000
+
#endif // __CLOUDHV_H__
--
2.30.2

---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris,
92196 Meudon Cedex, France
Registration Number: 302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.


[PATCH 4/5] OvmfPkg: Generalize AcpiPlatformDxe

Boeuf, Sebastien
 

From: Sebastien Boeuf <sebastien.boeuf@...>

Don't make the package Qemu centric so that we can introduce some
alternative support for other VMMs not using the fw_cfg mechanism.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@...>
---
ArmVirtPkg/ArmVirtQemu.dsc | 2 +-
ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc | 2 +-
ArmVirtPkg/ArmVirtQemuKernel.dsc | 2 +-
.../{QemuFwCfgAcpiPlatform.c => AcpiPlatform.c} | 4 ++--
.../{QemuFwCfgAcpiPlatformDxe.inf => AcpiPlatformDxe.inf} | 4 ++--
OvmfPkg/AmdSev/AmdSevX64.dsc | 2 +-
OvmfPkg/AmdSev/AmdSevX64.fdf | 2 +-
OvmfPkg/Microvm/MicrovmX64.dsc | 2 +-
OvmfPkg/Microvm/MicrovmX64.fdf | 2 +-
OvmfPkg/OvmfPkgIa32.dsc | 2 +-
OvmfPkg/OvmfPkgIa32.fdf | 2 +-
OvmfPkg/OvmfPkgIa32X64.dsc | 2 +-
OvmfPkg/OvmfPkgIa32X64.fdf | 2 +-
OvmfPkg/OvmfPkgX64.dsc | 2 +-
OvmfPkg/OvmfPkgX64.fdf | 2 +-
15 files changed, 17 insertions(+), 17 deletions(-)
rename OvmfPkg/AcpiPlatformDxe/{QemuFwCfgAcpiPlatform.c => AcpiPlatform.c} (78%)
rename OvmfPkg/AcpiPlatformDxe/{QemuFwCfgAcpiPlatformDxe.inf => AcpiPlatformDxe.inf} (90%)

diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
index 891e065311..84c28b0c1d 100644
--- a/ArmVirtPkg/ArmVirtQemu.dsc
+++ b/ArmVirtPkg/ArmVirtQemu.dsc
@@ -543,7 +543,7 @@
ArmVirtPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf
[Components.AARCH64]
MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf
- OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf {
+ OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf {
<LibraryClasses>
NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf
}
diff --git a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc
index f6a538df72..d4df6dede0 100644
--- a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc
+++ b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc
@@ -145,7 +145,7 @@ READ_LOCK_STATUS = TRUE
!if $(ARCH) == AARCH64
INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf
- INF OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf
+ INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf

#
# EBC support
diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKernel.dsc
index a8bb83b288..8e82c5050f 100644
--- a/ArmVirtPkg/ArmVirtQemuKernel.dsc
+++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc
@@ -458,7 +458,7 @@
ArmVirtPkg/PlatformHasAcpiDtDxe/PlatformHasAcpiDtDxe.inf
[Components.AARCH64]
MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf
- OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf {
+ OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf {
<LibraryClasses>
NULL|OvmfPkg/Fdt/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf
}
diff --git a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatform.c b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c
similarity index 78%
rename from OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatform.c
rename to OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c
index 057a450af9..613a8ac97f 100644
--- a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatform.c
+++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c
@@ -1,5 +1,5 @@
/** @file
- OVMF ACPI Platform Driver using QEMU's fw-cfg interface
+ OVMF ACPI Platform Driver

Copyright (C) 2015, Red Hat, Inc.
Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR>
@@ -10,7 +10,7 @@
#include "AcpiPlatform.h"

/**
- Effective entrypoint of QEMU fw-cfg Acpi Platform driver.
+ Effective entrypoint of Acpi Platform driver.

@param ImageHandle
@param SystemTable
diff --git a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf b/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
similarity index 90%
rename from OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf
rename to OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
index dac25d1505..eedd3b5af3 100644
--- a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf
+++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
@@ -1,5 +1,5 @@
## @file
-# OVMF ACPI Platform Driver using QEMU's fw-cfg interface
+# OVMF ACPI Platform Driver
#
# Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -21,12 +21,12 @@
#

[Sources]
+ AcpiPlatform.c
AcpiPlatform.h
BootScript.c
EntryPoint.c
PciDecoding.c
QemuFwCfgAcpi.c
- QemuFwCfgAcpiPlatform.c

[Packages]
MdeModulePkg/MdeModulePkg.dec
diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc
index 5ee5445116..14ab027f63 100644
--- a/OvmfPkg/AmdSev/AmdSevX64.dsc
+++ b/OvmfPkg/AmdSev/AmdSevX64.dsc
@@ -773,7 +773,7 @@
# ACPI Support
#
MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
- OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf
+ OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf

#
diff --git a/OvmfPkg/AmdSev/AmdSevX64.fdf b/OvmfPkg/AmdSev/AmdSevX64.fdf
index 5662609886..5b61da2edd 100644
--- a/OvmfPkg/AmdSev/AmdSevX64.fdf
+++ b/OvmfPkg/AmdSev/AmdSevX64.fdf
@@ -271,7 +271,7 @@ INF MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf
INF OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf

INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
-INF OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf
+INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf

INF FatPkg/EnhancedFatDxe/Fat.inf
diff --git a/OvmfPkg/Microvm/MicrovmX64.dsc b/OvmfPkg/Microvm/MicrovmX64.dsc
index 617f925395..2c6f932d95 100644
--- a/OvmfPkg/Microvm/MicrovmX64.dsc
+++ b/OvmfPkg/Microvm/MicrovmX64.dsc
@@ -751,7 +751,7 @@
# ACPI Support
#
MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
- OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf
+ OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf
MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf
MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf
diff --git a/OvmfPkg/Microvm/MicrovmX64.fdf b/OvmfPkg/Microvm/MicrovmX64.fdf
index 6314014f3d..459c639e5a 100644
--- a/OvmfPkg/Microvm/MicrovmX64.fdf
+++ b/OvmfPkg/Microvm/MicrovmX64.fdf
@@ -268,7 +268,7 @@ INF MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf
INF OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf

INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
-INF OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf
+INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
INF MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf
INF MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf
INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf
diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index 6a5be97c05..61209e3db1 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -870,7 +870,7 @@
# ACPI Support
#
MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
- OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf
+ OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf
MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf
MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf
diff --git a/OvmfPkg/OvmfPkgIa32.fdf b/OvmfPkg/OvmfPkgIa32.fdf
index 775ea2d710..6b37238634 100644
--- a/OvmfPkg/OvmfPkgIa32.fdf
+++ b/OvmfPkg/OvmfPkgIa32.fdf
@@ -281,7 +281,7 @@ INF MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf
INF OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf

INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
-INF OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf
+INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
INF MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf
INF MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf
INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf
diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index 71227d1b70..a4447508bc 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -884,7 +884,7 @@
# ACPI Support
#
MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
- OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf
+ OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf
MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf
MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf
diff --git a/OvmfPkg/OvmfPkgIa32X64.fdf b/OvmfPkg/OvmfPkgIa32X64.fdf
index 9d8695922f..88f3e16656 100644
--- a/OvmfPkg/OvmfPkgIa32X64.fdf
+++ b/OvmfPkg/OvmfPkgIa32X64.fdf
@@ -285,7 +285,7 @@ INF MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf
INF OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf

INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
-INF OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf
+INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
INF MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf
INF MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf
INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index 52f7598cf1..6b1d8d3247 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -882,7 +882,7 @@
# ACPI Support
#
MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
- OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf
+ OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf
MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf
MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf
diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf
index b6cc3cabdd..c97c4ae16c 100644
--- a/OvmfPkg/OvmfPkgX64.fdf
+++ b/OvmfPkg/OvmfPkgX64.fdf
@@ -301,7 +301,7 @@ INF MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf
INF OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf

INF MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
-INF OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf
+INF OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
INF MdeModulePkg/Universal/Acpi/S3SaveStateDxe/S3SaveStateDxe.inf
INF MdeModulePkg/Universal/Acpi/BootScriptExecutorDxe/BootScriptExecutorDxe.inf
INF MdeModulePkg/Universal/Acpi/BootGraphicsResourceTableDxe/BootGraphicsResourceTableDxe.inf
--
2.30.2

---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris,
92196 Meudon Cedex, France
Registration Number: 302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.


[PATCH 3/5] OvmfPkg: Retrieve SMBIOS from Cloud Hypervisor

Boeuf, Sebastien
 

From: Sebastien Boeuf <sebastien.boeuf@...>

Add a fallback on the SMBIOS code to find the SMBIOS table for Cloud
Hypervisor if it couldn't be found for Qemu through fw_cfg.

Signed-off-by: Rob Bradford <robert.bradford@...>
Signed-off-by: Sebastien Boeuf <sebastien.boeuf@...>
---
OvmfPkg/Include/IndustryStandard/CloudHv.h | 5 +++
OvmfPkg/SmbiosPlatformDxe/CloudHv.c | 32 +++++++++++++++++++
OvmfPkg/SmbiosPlatformDxe/EntryPoint.c | 23 +++++++++++--
.../SmbiosPlatformDxe/SmbiosPlatformDxe.inf | 1 +
4 files changed, 59 insertions(+), 2 deletions(-)
create mode 100644 OvmfPkg/SmbiosPlatformDxe/CloudHv.c

diff --git a/OvmfPkg/Include/IndustryStandard/CloudHv.h b/OvmfPkg/Include/IndustryStandard/CloudHv.h
index 6ab18ad50d..ad0e170795 100644
--- a/OvmfPkg/Include/IndustryStandard/CloudHv.h
+++ b/OvmfPkg/Include/IndustryStandard/CloudHv.h
@@ -32,4 +32,9 @@
//
#define CLOUDHV_MMIO_HOLE_SIZE 0x38000000

+//
+// SMBIOS address
+//
+#define CLOUDHV_SMBIOS_ADDRESS 0xf0000
+
#endif // __CLOUDHV_H__
diff --git a/OvmfPkg/SmbiosPlatformDxe/CloudHv.c b/OvmfPkg/SmbiosPlatformDxe/CloudHv.c
new file mode 100644
index 0000000000..f56a810684
--- /dev/null
+++ b/OvmfPkg/SmbiosPlatformDxe/CloudHv.c
@@ -0,0 +1,32 @@
+/** @file
+ Find Cloud Hypervisor SMBIOS data.
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <IndustryStandard/CloudHv.h> // CLOUDHV_SMBIOS_ADDRESS
+#include <IndustryStandard/SmBios.h> // SMBIOS_TABLE_3_0_ENTRY_POINT
+
+/**
+ Locates and extracts the QEMU SMBIOS data if present in fw_cfg
+
+ @return Address of extracted QEMU SMBIOS data
+
+**/
+UINT8 *
+GetCloudHvSmbiosTables (
+ VOID
+ )
+{
+ SMBIOS_TABLE_3_0_ENTRY_POINT *CloudHvTables = (VOID *)CLOUDHV_SMBIOS_ADDRESS;
+
+ if (CloudHvTables->AnchorString[0] == '_' &&
+ CloudHvTables->AnchorString[1] == 'S' &&
+ CloudHvTables->AnchorString[2] == 'M' &&
+ CloudHvTables->AnchorString[3] == '3' &&
+ CloudHvTables->AnchorString[4] == '_') {
+ return (UINT8*)(UINTN)CloudHvTables->TableAddress;
+ }
+
+ return NULL;
+}
diff --git a/OvmfPkg/SmbiosPlatformDxe/EntryPoint.c b/OvmfPkg/SmbiosPlatformDxe/EntryPoint.c
index d3b1836a04..28faabb46a 100644
--- a/OvmfPkg/SmbiosPlatformDxe/EntryPoint.c
+++ b/OvmfPkg/SmbiosPlatformDxe/EntryPoint.c
@@ -8,6 +8,11 @@

#include "SmbiosPlatformDxe.h"

+UINT8 *
+GetCloudHvSmbiosTables (
+ VOID
+ );
+
UINT8 *
GetQemuSmbiosTables (
VOID
@@ -32,14 +37,28 @@ SmbiosTablePublishEntry (
{
EFI_STATUS Status;
UINT8 *SmbiosTables;
+ BOOLEAN FreeTables = FALSE;

Status = EFI_NOT_FOUND;
//
// Add QEMU SMBIOS data if found
//
SmbiosTables = GetQemuSmbiosTables ();
- if (SmbiosTables != NULL) {
- Status = InstallAllStructures (SmbiosTables);
+ if (SmbiosTables == NULL) {
+ SmbiosTables = GetCloudHvSmbiosTables ();
+ if (SmbiosTables == NULL) {
+ return EFI_NOT_FOUND;
+ }
+ } else {
+ FreeTables = TRUE;
+ }
+
+ Status = InstallAllStructures (SmbiosTables);
+
+ //
+ // Free SmbiosTables if allocated by Qemu.
+ //
+ if (FreeTables) {
FreePool (SmbiosTables);
}

diff --git a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
index e239a631f2..365d96241e 100644
--- a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
+++ b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
@@ -24,6 +24,7 @@
#

[Sources]
+ CloudHv.c
EntryPoint.c
Qemu.c
SmbiosPlatformDxe.c
--
2.30.2

---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris,
92196 Meudon Cedex, France
Registration Number: 302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

6821 - 6840 of 90967