[edk2-platforms: PATCH v5 8/9] WhitleyOpenBoardPkg: Support FSP 2.3 FSP_NON_VOLATILE_STORAGE_HOB2.


Chiu, Chasel
 

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3678

Implementation should search FSP_NON_VOLATILE_STORAGE_HOB2 firstly
and only search FSP_NON_VOLATILE_STORAGE_HOB when former one is not found.

Also added PeiGetLargeVariable () to support the scenarios where the
variable data size is bigger than a single variable size limit.

Cc: Isaac Oram <isaac.w.oram@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Signed-off-by: Chasel Chiu <chasel.chiu@intel.com>
Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
---
Platform/Intel/WhitleyOpenBoardPkg/Platform/Dxe/S3NvramSave/S3NvramSave.c =
| 29 +++++++++++++++++++++++------
Platform/Intel/WhitleyOpenBoardPkg/Platform/Dxe/S3NvramSave/S3NvramSave.in=
f | 4 +++-
Platform/Intel/WhitleyOpenBoardPkg/PlatformPkg.dsc =
| 1 +
3 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/Platform/Intel/WhitleyOpenBoardPkg/Platform/Dxe/S3NvramSave/S3=
NvramSave.c b/Platform/Intel/WhitleyOpenBoardPkg/Platform/Dxe/S3NvramSave/S=
3NvramSave.c
index 709c7ad479..01e36cda27 100644
--- a/Platform/Intel/WhitleyOpenBoardPkg/Platform/Dxe/S3NvramSave/S3NvramSa=
ve.c
+++ b/Platform/Intel/WhitleyOpenBoardPkg/Platform/Dxe/S3NvramSave/S3NvramSa=
ve.c
@@ -7,6 +7,7 @@
**/=0D
=0D
#include "S3NvramSave.h"=0D
+#include <Guid/FspNonVolatileStorageHob2.h>=0D
#include <Library/MemoryAllocationLib.h>=0D
#include <Library/LargeVariableReadLib.h>=0D
#include <Library/LargeVariableWriteLib.h>=0D
@@ -80,21 +81,37 @@ SaveFspNonVolatileStorageHob (
Status =3D EFI_SUCCESS;=0D
=0D
DEBUG ((DEBUG_INFO, "Saving FSP / MRC Training Data\n"));=0D
- GuidHob =3D GetFirstGuidHob (&gFspNonVolatileStorageHobGuid);=0D
+ //=0D
+ // Firstly check version2 FspNvsHob.=0D
+ //=0D
+ GuidHob =3D GetFirstGuidHob (&gFspNonVolatileStorageHob2Guid);=0D
if (GuidHob !=3D NULL) {=0D
- HobData =3D GET_GUID_HOB_DATA (GuidHob);=0D
- DataSize =3D GET_GUID_HOB_DATA_SIZE (GuidHob);=0D
+ HobData =3D (VOID *) (UINTN) ((FSP_NON_VOLATILE_STORAGE_HOB2 *) (UINTN=
) GuidHob)->NvsDataPtr;=0D
+ DataSize =3D (UINTN) ((FSP_NON_VOLATILE_STORAGE_HOB2 *) (UINTN) GuidHo=
b)->NvsDataLength;=0D
+ } else {=0D
+ //=0D
+ // Fall back to version1 FspNvsHob=0D
+ //=0D
+ GuidHob =3D GetFirstGuidHob (&gFspNonVolatileStorageHobGuid);=0D
+ if (GuidHob !=3D NULL) {=0D
+ HobData =3D GET_GUID_HOB_DATA (GuidHob);=0D
+ DataSize =3D GET_GUID_HOB_DATA_SIZE (GuidHob);=0D
+ }=0D
+ }=0D
+ if (HobData !=3D NULL) {=0D
+ DEBUG ((DEBUG_INFO, "FspNvsHob.Size: %d\n", DataSize));=0D
+ DEBUG ((DEBUG_INFO, "FspNvsHob.NvsDataPtr: 0x%x\n", HobData));=0D
if (DataSize > 0) {=0D
=0D
//=0D
// Check if the presently saved data is identical to the data given =
by MRC/FSP=0D
//=0D
- Status =3D GetLargeVariable (L"FspNvsBuffer", &gFspNonVolatileStorag=
eHobGuid, &FspNvsBufferSize, NULL);=0D
+ Status =3D GetLargeVariable (L"FspNvsBuffer", &gFspNvsBufferVariable=
Guid, &FspNvsBufferSize, NULL);=0D
if (Status =3D=3D EFI_BUFFER_TOO_SMALL) {=0D
if (FspNvsBufferSize =3D=3D DataSize) {=0D
VariableData =3D AllocatePool (FspNvsBufferSize);=0D
if (VariableData !=3D NULL) {=0D
- Status =3D GetLargeVariable (L"FspNvsBuffer", &gFspNonVolatile=
StorageHobGuid, &FspNvsBufferSize, VariableData);=0D
+ Status =3D GetLargeVariable (L"FspNvsBuffer", &gFspNvsBufferVa=
riableGuid, &FspNvsBufferSize, VariableData);=0D
if (!EFI_ERROR (Status) && (FspNvsBufferSize =3D=3D DataSize) =
&& (0 =3D=3D CompareMem (HobData, VariableData, DataSize))) {=0D
DataIsIdentical =3D TRUE;=0D
}=0D
@@ -105,7 +122,7 @@ SaveFspNonVolatileStorageHob (
Status =3D EFI_SUCCESS;=0D
=0D
if (!DataIsIdentical) {=0D
- Status =3D SetLargeVariable (L"FspNvsBuffer", &gFspNonVolatileStor=
ageHobGuid, TRUE, DataSize, HobData);=0D
+ Status =3D SetLargeVariable (L"FspNvsBuffer", &gFspNvsBufferVariab=
leGuid, TRUE, DataSize, HobData);=0D
ASSERT_EFI_ERROR (Status);=0D
DEBUG ((DEBUG_INFO, "Saved size of FSP / MRC Training Data: 0x%x\n=
", DataSize));=0D
} else {=0D
diff --git a/Platform/Intel/WhitleyOpenBoardPkg/Platform/Dxe/S3NvramSave/S3=
NvramSave.inf b/Platform/Intel/WhitleyOpenBoardPkg/Platform/Dxe/S3NvramSave=
/S3NvramSave.inf
index e62baa24c4..a77125cf44 100644
--- a/Platform/Intel/WhitleyOpenBoardPkg/Platform/Dxe/S3NvramSave/S3NvramSa=
ve.inf
+++ b/Platform/Intel/WhitleyOpenBoardPkg/Platform/Dxe/S3NvramSave/S3NvramSa=
ve.inf
@@ -43,7 +43,9 @@
LargeVariableWriteLib=0D
=0D
[Guids]=0D
- gFspNonVolatileStorageHobGuid # CONSUMES=0D
+ gFspNonVolatileStorageHobGuid # CONSUMES=0D
+ gFspNonVolatileStorageHob2Guid # CONSUMES=0D
+ gFspNvsBufferVariableGuid # PRODUCES=0D
=0D
[Pcd]=0D
gEfiCpRcPkgTokenSpaceGuid.PcdPeiSyshostMemorySize=0D
diff --git a/Platform/Intel/WhitleyOpenBoardPkg/PlatformPkg.dsc b/Platform/=
Intel/WhitleyOpenBoardPkg/PlatformPkg.dsc
index dc3dd0e026..87165103bf 100644
--- a/Platform/Intel/WhitleyOpenBoardPkg/PlatformPkg.dsc
+++ b/Platform/Intel/WhitleyOpenBoardPkg/PlatformPkg.dsc
@@ -637,6 +637,7 @@
=0D
[LibraryClasses.Common]=0D
DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.in=
f=0D
+ PeiLib|MinPlatformPkg/Library/PeiLib/PeiLib.inf=0D
=0D
[Components.IA32]=0D
UefiCpuPkg/SecCore/SecCore.inf=0D
--=20
2.28.0.windows.1