diff options
author | Nhi Pham <nhi@os.amperecomputing.com> | 2024-09-27 06:44:27 +0300 |
---|---|---|
committer | Nhi Pham <npham@amperecomputing.com> | 2024-10-11 11:26:23 +0300 |
commit | 01e3d354f39ecb29a1e39bfa193bcdf776e2b2ab (patch) | |
tree | ae745a3a99efef962409352d818a715d8fef9fe6 | |
parent | f1dd1def2eea0158b62b846e502f668b2eb708b9 (diff) | |
download | edk2-platforms-01e3d354f39ecb29a1e39bfa193bcdf776e2b2ab.tar.xz |
AmpereAltraPkg/FlashPei: Add IPMI clear cmos support
This adds support for handling IPMI clear cmos. When the clear cmos flag
is set, the NVRAM will be erased, which is the same as changing the
platform UUID at build time.
Signed-off-by: Nhi Pham <nhi@os.amperecomputing.com>
-rw-r--r-- | Silicon/Ampere/AmpereAltraPkg/Drivers/FlashPei/FlashPei.c | 79 | ||||
-rw-r--r-- | Silicon/Ampere/AmpereAltraPkg/Drivers/FlashPei/FlashPei.inf | 6 |
2 files changed, 83 insertions, 2 deletions
diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/FlashPei/FlashPei.c b/Silicon/Ampere/AmpereAltraPkg/Drivers/FlashPei/FlashPei.c index 711f364be2..61745bb903 100644 --- a/Silicon/Ampere/AmpereAltraPkg/Drivers/FlashPei/FlashPei.c +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/FlashPei/FlashPei.c @@ -1,6 +1,6 @@ /** @file
- Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.<BR>
+ Copyright (c) 2020 - 2024, Ampere Computing LLC. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -13,8 +13,79 @@ #include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/FlashLib.h>
+#include <Library/IpmiCommandLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/NVParamLib.h>
#include <Library/PcdLib.h>
#include <Library/PeimEntryPoint.h>
+#include <IndustryStandard/Ipmi.h>
+
+/**
+ Check if the IPMI clear cmos flag is set or not.
+
+ @retval TRUE The clear cmos is set.
+ @retval FALSE The clear cmos is not set.
+
+**/
+STATIC
+BOOLEAN
+IsIpmiClearCmosSet (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ IPMI_GET_BOOT_OPTIONS_REQUEST BootOptionsRequest;
+ IPMI_GET_BOOT_OPTIONS_RESPONSE *BootOptionsResponse;
+ IPMI_BOOT_OPTIONS_RESPONSE_PARAMETER_5 *BootOptionsParameterData;
+ IPMI_SET_BOOT_OPTIONS_REQUEST *SetBootOptionsRequest;
+ IPMI_SET_BOOT_OPTIONS_RESPONSE SetBootOptionsResponse;
+ BOOLEAN IsClearCmosSet;
+
+ ZeroMem (&BootOptionsRequest, sizeof (IPMI_GET_BOOT_OPTIONS_REQUEST));
+ ZeroMem (&SetBootOptionsResponse, sizeof (IPMI_SET_BOOT_OPTIONS_RESPONSE));
+
+ IsClearCmosSet = FALSE;
+
+ BootOptionsResponse = AllocateZeroPool (sizeof (BootOptionsRequest) + sizeof (BootOptionsParameterData));
+ if (BootOptionsResponse == NULL) {
+ return FALSE;
+ }
+
+ BootOptionsRequest.ParameterSelector.Bits.ParameterSelector = IPMI_BOOT_OPTIONS_PARAMETER_BOOT_FLAGS;
+
+ Status = IpmiGetSystemBootOptions (&BootOptionsRequest, BootOptionsResponse);
+ if (EFI_ERROR (Status)) {
+ FreePool (BootOptionsResponse);
+ return FALSE;
+ }
+
+ BootOptionsParameterData = (IPMI_BOOT_OPTIONS_RESPONSE_PARAMETER_5 *)BootOptionsResponse->ParameterData;
+ if (BootOptionsParameterData->Data2.Bits.CmosClear != 0) {
+ IsClearCmosSet = TRUE;
+ }
+
+ SetBootOptionsRequest = AllocateZeroPool (sizeof (SetBootOptionsRequest) + sizeof (BootOptionsParameterData));
+ if (EFI_ERROR (Status)) {
+ FreePool (BootOptionsResponse);
+ return FALSE;
+ }
+
+ SetBootOptionsRequest->ParameterValid.Bits.ParameterSelector = IPMI_BOOT_OPTIONS_PARAMETER_BOOT_FLAGS;
+ SetBootOptionsRequest->ParameterValid.Bits.MarkParameterInvalid = 0x0;
+
+ BootOptionsParameterData->Data2.Bits.CmosClear = 0;
+ CopyMem (&SetBootOptionsRequest->ParameterData, BootOptionsParameterData, sizeof (IPMI_BOOT_OPTIONS_RESPONSE_PARAMETER_5));
+
+ Status = IpmiSetSystemBootOptions (SetBootOptionsRequest, &SetBootOptionsResponse);
+ if (EFI_ERROR (Status)) {
+ IsClearCmosSet = FALSE;
+ }
+
+ FreePool (BootOptionsResponse);
+ FreePool (SetBootOptionsRequest);
+
+ return IsClearCmosSet;
+}
/**
Entry point function for the PEIM
@@ -39,6 +110,7 @@ FlashPeiEntryPoint ( UINT32 FWNvRamSize;
UINTN NvRamAddress;
UINT32 NvRamSize;
+ BOOLEAN ClearUserConfig;
CopyMem ((VOID *)BuildUuid, PcdGetPtr (PcdPlatformConfigUuid), sizeof (BuildUuid));
@@ -80,9 +152,14 @@ FlashPeiEntryPoint ( return Status;
}
+ ClearUserConfig = IsIpmiClearCmosSet ();
+
if (CompareMem ((VOID *)StoredUuid, (VOID *)BuildUuid, sizeof (BuildUuid)) != 0) {
DEBUG ((DEBUG_INFO, "BUILD UUID Changed, Update Storage with NVRAM FV\n"));
+ ClearUserConfig = TRUE;
+ }
+ if (ClearUserConfig) {
Status = FlashEraseCommand (FWNvRamStartOffset, NvRamSize * 2 + sizeof (BuildUuid));
if (EFI_ERROR (Status)) {
return Status;
diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/FlashPei/FlashPei.inf b/Silicon/Ampere/AmpereAltraPkg/Drivers/FlashPei/FlashPei.inf index 2b329c5d09..1179266726 100644 --- a/Silicon/Ampere/AmpereAltraPkg/Drivers/FlashPei/FlashPei.inf +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/FlashPei/FlashPei.inf @@ -1,6 +1,6 @@ ## @file
#
-# Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.<BR>
+# Copyright (c) 2020 - 2024, Ampere Computing LLC. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
@@ -29,9 +29,13 @@ BaseMemoryLib
DebugLib
FlashLib
+ IpmiCommandLib
+ MemoryAllocationLib
MmCommunicationLib
+ NVParamLib
PcdLib
PeimEntryPoint
+ ResetSystemLib
[FixedPcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
|