Skip to content

Commit

Permalink
AmpereAltraPkg: Move clear-cmos support to PEI phase
Browse files Browse the repository at this point in the history
In PEI phase, firmware will check clear-cmos option in IPMI boot flags
and trigger reset user setting and NVPARAMs to defaults value.When the
clear-cmos option is selected, it helps to prevent needing two reboots.

Signed-off-by: Tinh Nguyen <tinhn@amperecomputing.com>
  • Loading branch information
tinhnampere committed Aug 19, 2022
1 parent 7be54b3 commit fc4d007
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 73 deletions.
50 changes: 39 additions & 11 deletions Silicon/Ampere/AmpereAltraPkg/Drivers/FlashPei/FlashPei.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @file
Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.<BR>
Copyright (c) 2020 - 2022, Ampere Computing LLC. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
Expand All @@ -12,6 +12,7 @@
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/FlashLib.h>
#include <Library/IpmiCommandLibExt.h>
#include <Library/NVParamLib.h>
#include <Library/PcdLib.h>
#include <Library/PeimEntryPoint.h>
Expand All @@ -35,15 +36,19 @@ FlashPeiEntryPoint (
IN CONST EFI_PEI_SERVICES **PeiServices
)
{
CHAR8 BuildUuid[UUID_SIZE];
CHAR8 StoredUuid[UUID_SIZE];
EFI_STATUS Status;
UINTN FWNvRamStartOffset;
UINT32 FWNvRamSize;
UINTN NvRamAddress;
UINT32 NvRamSize;
UINTN UefiMiscOffset;
UINT32 UefiMiscSize;
CHAR8 BuildUuid[UUID_SIZE];
CHAR8 StoredUuid[UUID_SIZE];
EFI_STATUS Status;
IPMI_BOOT_FLAGS_INFO BootFlags;
BOOLEAN NeedToClearUserConfiguration;
UINT32 FWNvRamSize;
UINT32 NvRamSize;
UINT32 UefiMiscSize;
UINTN FWNvRamStartOffset;
UINTN NvRamAddress;
UINTN UefiMiscOffset;

NeedToClearUserConfiguration = FALSE;

CopyMem ((VOID *)BuildUuid, PcdGetPtr (PcdPlatformConfigUuid), UUID_SIZE);

Expand Down Expand Up @@ -74,6 +79,25 @@ FlashPeiEntryPoint (
return EFI_INVALID_PARAMETER;
}

//
// Get Boot Flags from BMC to determine if an NVRAM clear request has been made or not.
//
Status = IpmiGetBootFlags (&BootFlags);
if (!EFI_ERROR (Status)) {
if (BootFlags.IsCmosClear) {
DEBUG ((DEBUG_INFO, "FlashPei: Clear-cmos option is selected\n"));
NeedToClearUserConfiguration = TRUE;
}

Status = IpmiClearCmosBootFlags ();
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "FlashPei: Failed to clear clear-cmos boot flags - %r\n", Status));
NeedToClearUserConfiguration = FALSE;
}
} else {
DEBUG ((DEBUG_ERROR, "FlashPei: Failed to get Boot Flags via IPMI - %r\n", Status));
}

//
// Get the Platform UUID stored in the very first bytes of the UEFI Misc.
//
Expand All @@ -86,8 +110,12 @@ FlashPeiEntryPoint (
return Status;
}

if (CompareMem ((VOID *)StoredUuid, (VOID *)BuildUuid, UUID_SIZE) != 0) {
if ((CompareMem ((VOID *)StoredUuid, (VOID *)BuildUuid, UUID_SIZE)) != 0) {
DEBUG ((DEBUG_INFO, "BUILD UUID Changed, Update Storage with NVRAM FV\n"));
NeedToClearUserConfiguration = TRUE;
}

if (NeedToClearUserConfiguration) {

Status = FlashEraseCommand (FWNvRamStartOffset, NvRamSize * 2);
if (EFI_ERROR (Status)) {
Expand Down
6 changes: 5 additions & 1 deletion Silicon/Ampere/AmpereAltraPkg/Drivers/FlashPei/FlashPei.inf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## @file
#
# Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.<BR>
# Copyright (c) 2020 - 2022, Ampere Computing LLC. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
Expand Down Expand Up @@ -28,12 +28,16 @@
BaseMemoryLib
DebugLib
FlashLib
IpmiCommandLibExt
MmCommunicationLib
NVParamLib
PcdLib
PeimEntryPoint
ResetSystemLib

[Ppis]
gPeiIpmiPpiGuid ### CONSUMES

[FixedPcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
Expand Down
55 changes: 1 addition & 54 deletions Silicon/Ampere/AmpereAltraPkg/Drivers/IpmiBootDxe/IpmiBootDxe.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @file
Process IPMI bootdev command and force the UEFI to boot with selected option.
Copyright (c) 2021, Ampere Computing LLC. All rights reserved.<BR>
Copyright (c) 2021 - 2022, Ampere Computing LLC. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
Expand All @@ -16,7 +16,6 @@
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/DevicePathLib.h>
#include <Library/FlashLib.h>
#include <Library/IpmiCommandLibExt.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
Expand All @@ -27,8 +26,6 @@
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Protocol/DevicePathToText.h>

#define UUID_SIZE PcdGetSize (PcdPlatformConfigUuid)

#define BBS_TYPE_OS_HARDDRIVE 0xFD
#define BBS_TYPE_MENU 0xFE
#define EFI_LAST_BOOT_ORDER_VARIABLE_NAME L"LastBootOrder"
Expand Down Expand Up @@ -332,41 +329,6 @@ DeviceSelectorToBBSType (
}
}

/**
Clear Platform UUID to trigger refresh NVRAM/NVPARAM
@retval EFI_SUCCESS The function executed successfully.
@retval Other Some error occurs when saving the variables.
**/
EFI_STATUS
ClearPlatformUuid (
VOID
)
{
EFI_STATUS Status;
UINTN FWNvRamStartOffset;
UINT32 FWNvRamSize;
UINTN UefiMiscOffset;
UINT32 UefiMiscSize;

Status = FlashGetNvRamInfo (&FWNvRamStartOffset, &FWNvRamSize, &UefiMiscOffset, &UefiMiscSize);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Failed to get Flash NVRAM info %r\n", __FUNCTION__, Status));
return Status;
}

//
// Clear PlatformConfigUuid
//
Status = FlashEraseCommand (UefiMiscOffset, UUID_SIZE);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "%a: Clear Platform Config UUID - %r\n", __FUNCTION__, Status));
}

return Status;
}

VOID
EFIAPI
HandleIpmiBootOption (
Expand Down Expand Up @@ -426,21 +388,6 @@ HandleIpmiBootOption (
goto Exit;
}

if (BootFlags.IsCmosClear) {
Status = ClearPlatformUuid ();
if (EFI_ERROR (Status)) {
goto Exit;
}

Status = IpmiClearCmosBootFlags ();
if (EFI_ERROR (Status)) {
goto Exit;
}

DEBUG ((DEBUG_INFO, "%a: Handle clear-cmos done, resetting ...\n", __FUNCTION__));
gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);
}

BootType = DeviceSelectorToBBSType (BootFlags.DeviceSelector);
if (BootType == BBS_TYPE_UNKNOWN) {
goto Exit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

## @file
#
# Copyright (c) 2021, Ampere Computing LLC. All rights reserved.<BR>
# Copyright (c) 2021 - 2022, Ampere Computing LLC. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
Expand All @@ -26,21 +26,15 @@
[LibraryClasses]
BaseLib
DevicePathLib
FlashLib
IpmiCommandLibExt
MemoryAllocationLib
NVParamLib
PcdLib
UefiBootManagerLib
UefiBootServicesTableLib
UefiDriverEntryPoint
UefiRuntimeServicesTableLib

[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile

gAmpereTokenSpaceGuid.PcdPlatformConfigUuid

[Guids]
gAmpereAfterConsoleEventGuid
gAmpereVariableGuid
Expand Down

0 comments on commit fc4d007

Please sign in to comment.