From ffee5bbcf23c264483b9d4091d96c3c8421fd2a7 Mon Sep 17 00:00:00 2001 From: Hendrik Borghorst Date: Fri, 16 Oct 2020 10:05:08 +0200 Subject: [PATCH] uefi: Wipe emulated NvVariable memory on allocation EDK2 implements an emulation of non-volatile memory by keeping the data persistent over reboots. For now we don't want to persist data and provide a solution that is inline with the in-memory store of the .metal instances. This way we don't have to return EFI_UNSUPPORTED on SetVariable runtime service. This turned out to cause problems with Linux distribution's update routings (efibootmgr failing). Signed-off-by: Hendrik Borghorst Reviewed-by: Evgeny Iakovlev Reviewed-by: Alexander Graf (AWS) diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c index b1f8140d60..5f10976144 100644 --- a/OvmfPkg/PlatformPei/Platform.c +++ b/OvmfPkg/PlatformPei/Platform.c @@ -219,6 +219,7 @@ ReserveEmuVariableNvStore ( { EFI_PHYSICAL_ADDRESS VariableStore; RETURN_STATUS PcdStatus; + UINT32 VarStoreSize; VariableStore = (EFI_PHYSICAL_ADDRESS)(UINTN)PlatformReserveEmuVariableNvStore (); PcdStatus = PcdSet64S (PcdEmuVariableNvStoreReserved, VariableStore); @@ -227,6 +228,12 @@ ReserveEmuVariableNvStore ( PlatformInitEmuVariableNvStore ((VOID *)(UINTN)VariableStore); #endif + VarStoreSize = 2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize); + + // Clean variable space for now, as we don't want to persist variables over reboot + if ((VOID *)(UINTN)VariableStore != NULL) + SetMem((VOID *)(UINTN)VariableStore, VarStoreSize, 0x0); + ASSERT_RETURN_ERROR (PcdStatus); }