In commit
b24fca05751f ("OvmfPkg: introduce 4MB flash image (mainly) for
Windows HCK", 2017-04-29), I changed PcdFlashNvStorageFtwSpareSize to
264KB, in the then-new default 4MB build.
While PcdFlashNvStorageFtwSpareSize remains exactly half of the entire
non-volatile store (which is 528KB), 264KB isn't itself a power of two.
This triggers an assertion failure in AllocateAlignedRuntimePages() when
PlatformPei calls it from the ReserveEmuVariableNvStore() function,
passing PcdFlashNvStorageFtwSpareSize as the Alignment parameter:
> ASSERT MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c(196):
> (Alignment & (Alignment - 1)) == 0
Round up the alignment to the next power of two if necessary.
Fixes: b24fca05751f8222acf264853709012e0ab7bf49
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
{\r
EFI_PHYSICAL_ADDRESS VariableStore;\r
RETURN_STATUS PcdStatus;\r
{\r
EFI_PHYSICAL_ADDRESS VariableStore;\r
RETURN_STATUS PcdStatus;\r
\r
//\r
// Allocate storage for NV variables early on so it will be\r
\r
//\r
// Allocate storage for NV variables early on so it will be\r
// across reboots, this allows the NV variable storage to survive\r
// a VM reboot.\r
//\r
// across reboots, this allows the NV variable storage to survive\r
// a VM reboot.\r
//\r
+ Alignment = PcdGet32 (PcdFlashNvStorageFtwSpareSize);\r
+ if ((Alignment & (Alignment - 1)) != 0) {\r
+ //\r
+ // Round up Alignment to the next power of two.\r
+ //\r
+ Alignment = GetPowerOfTwo32 (Alignment) << 1;\r
+ }\r
+\r
VariableStore =\r
(EFI_PHYSICAL_ADDRESS)(UINTN)\r
AllocateAlignedRuntimePages (\r
EFI_SIZE_TO_PAGES (2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)),\r
VariableStore =\r
(EFI_PHYSICAL_ADDRESS)(UINTN)\r
AllocateAlignedRuntimePages (\r
EFI_SIZE_TO_PAGES (2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)),\r
- PcdGet32 (PcdFlashNvStorageFtwSpareSize)\r
);\r
DEBUG ((EFI_D_INFO,\r
);\r
DEBUG ((EFI_D_INFO,\r
- "Reserved variable store memory: 0x%lX; size: %dkb\n",\r
+ "Reserved variable store memory: 0x%lX; size: %dkb, "\r
+ "alignment: 0x%x\n",\r
- (2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)) / 1024\r
+ (2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)) / 1024,\r
+ Alignment\r
));\r
PcdStatus = PcdSet64S (PcdEmuVariableNvStoreReserved, VariableStore);\r
ASSERT_RETURN_ERROR (PcdStatus);\r
));\r
PcdStatus = PcdSet64S (PcdEmuVariableNvStoreReserved, VariableStore);\r
ASSERT_RETURN_ERROR (PcdStatus);\r