From 4499be3aa0e44a291268f88cd5ea23666a5c5158 Mon Sep 17 00:00:00 2001 From: Ard Biesheuvel Date: Wed, 1 Nov 2017 12:48:49 +0000 Subject: Silicon/SynQuacerMemoryInitPeiLib: ignore capsules when clearing NVRAM In preparation of adding support for setting a DIP switch to clear the EFI variable store, update the early capsule handling logic to take the boot mode into account. This is necessary for two reasons: - we override the boot mode when a capsule is detected, - the capsule detection itself involves reading a EFI variable, which we shouldn't be doing if the varstore may be in a bad state. So factor out the initial capsule check (to keep the code understandable) and only perform it if we are not booting in 'clear NVRAM' mode. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel Reviewed-by: Leif Lindholm --- .../SynQuacerMemoryInitPeiLib.c | 71 ++++++++++++++-------- 1 file changed, 47 insertions(+), 24 deletions(-) (limited to 'Silicon') diff --git a/Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c b/Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c index b44c58d610..0c5df14482 100644 --- a/Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c +++ b/Silicon/Socionext/SynQuacer/Library/SynQuacerMemoryInitPeiLib/SynQuacerMemoryInitPeiLib.c @@ -170,6 +170,44 @@ DeclareDram ( return EFI_SUCCESS; } +STATIC +BOOLEAN +CheckCapsule ( + IN EFI_PEI_SERVICES **PeiServices, + IN PEI_CAPSULE_PPI *Capsule, + IN EFI_PHYSICAL_ADDRESS UefiMemoryBase, + OUT VOID **CapsuleBuffer, + OUT UINTN *CapsuleBufferLength + ) +{ + EFI_STATUS Status; + + Status = Capsule->CheckCapsuleUpdate (PeiServices); + if (!EFI_ERROR (Status)) { + + // + // Coalesce the capsule into unused memory. CreateState() below will copy + // it to a properly allocated buffer. + // + *CapsuleBuffer = (VOID *)PcdGet64 (PcdSystemMemoryBase); + *CapsuleBufferLength = UefiMemoryBase - PcdGet64 (PcdSystemMemoryBase); + + PeiServicesSetBootMode (BOOT_ON_FLASH_UPDATE); + + Status = Capsule->Coalesce (PeiServices, CapsuleBuffer, + CapsuleBufferLength); + if (!EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a: Coalesced capsule @ %p (0x%lx)\n", + __FUNCTION__, *CapsuleBuffer, *CapsuleBufferLength)); + return TRUE; + } else { + DEBUG ((DEBUG_WARN, "%a: failed to coalesce() capsule (Status == %r)\n", + __FUNCTION__, Status)); + } + } + return FALSE; +} + EFI_STATUS EFIAPI MemoryPeim ( @@ -184,6 +222,7 @@ MemoryPeim ( VOID *CapsuleBuffer; UINTN CapsuleBufferLength; BOOLEAN HaveCapsule; + EFI_BOOT_MODE BootMode; Status = DeclareDram (&VirtualMemoryTable); ASSERT_EFI_ERROR (Status); @@ -199,31 +238,15 @@ MemoryPeim ( ASSERT_EFI_ERROR (Status); // - // Check for persistent capsules + // Check for persistent capsules, unless we are booting with default + // settings. // - HaveCapsule = FALSE; - Status = Capsule->CheckCapsuleUpdate (PeiServices); - if (!EFI_ERROR (Status)) { - - // - // Coalesce the capsule into unused memory. CreateState() below will copy - // it to a properly allocated buffer. - // - CapsuleBuffer = (VOID *)PcdGet64 (PcdSystemMemoryBase); - CapsuleBufferLength = UefiMemoryBase - PcdGet64 (PcdSystemMemoryBase); - - PeiServicesSetBootMode (BOOT_ON_FLASH_UPDATE); - - Status = Capsule->Coalesce (PeiServices, &CapsuleBuffer, - &CapsuleBufferLength); - if (!EFI_ERROR (Status)) { - DEBUG ((DEBUG_INFO, "%a: Coalesced capsule @ %p (0x%lx)\n", - __FUNCTION__, CapsuleBuffer, CapsuleBufferLength)); - HaveCapsule = TRUE; - } else { - DEBUG ((DEBUG_WARN, "%a: failed to coalesce() capsule (Status == %r)\n", - __FUNCTION__, Status)); - } + Status = PeiServicesGetBootMode (&BootMode); + if (!EFI_ERROR (Status) && BootMode != BOOT_WITH_DEFAULT_SETTINGS) { + HaveCapsule = CheckCapsule (PeiServices, Capsule, UefiMemoryBase, + &CapsuleBuffer, &CapsuleBufferLength); + } else { + HaveCapsule = FALSE; } Status = ArmConfigureMmu (VirtualMemoryTable, NULL, NULL); -- cgit v1.2.3