## The size of volatile buffer. This buffer is used to store VOLATILE attribute variable.\r
gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0x10000|UINT32|0x30000005\r
\r
- ## Size of the FTW spare block range. Note that this value should larger than PcdFlashNvStorageVariableSize\r
+ ## Size of the FTW spare block range. Note that this value should larger than PcdFlashNvStorageVariableSize and block size aligned.\r
# The root cause is that variable driver will use FTW protocol to reclaim variable region.\r
# If the length of variable region is larger than FTW spare size, it means the whole variable region can not\r
# be reflushed through the manner of fault tolerant write.\r
## Base address of the NV variable range in flash device\r
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0x0|UINT32|0x30000001\r
\r
- ## Base address of the FTW spare block range in flash device.\r
+ ## Base address of the FTW spare block range in flash device. Note that this value should be block size aligned.\r
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0x0|UINT32|0x30000013\r
\r
## Base address of the FTW working block range in flash device.\r
## 64-bit Base address of the NV variable range in flash device\r
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64|0x0|UINT64|0x80000001\r
\r
- ## 64-bit Base address of the FTW spare block range in flash device.\r
+ ## 64-bit Base address of the FTW spare block range in flash device. Note that this value should be block size aligned.\r
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64|0x0|UINT64|0x80000013\r
\r
## 64-bit Base address of the FTW working block range in flash device.\r
#include <Library/BaseMemoryLib.h>\r
#include <Library/MemoryAllocationLib.h>\r
#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/ReportStatusCodeLib.h>\r
\r
//\r
// Flash erase polarity is 1\r
DebugLib\r
UefiLib\r
PcdLib\r
+ ReportStatusCodeLib\r
\r
[Guids]\r
gEdkiiWorkingBlockSignatureGuid ## CONSUMES ## FV Signature of Working Space Header\r
DebugLib\r
UefiLib\r
PcdLib\r
+ ReportStatusCodeLib\r
\r
[Guids]\r
gEdkiiWorkingBlockSignatureGuid ## CONSUMES ## FV Signature of Working Space Header\r
ASSERT (FALSE);\r
return EFI_ABORTED;\r
}\r
+ //\r
+ // Check the alignment of spare area address and length, they should be block size aligned\r
+ //\r
+ if (((FtwDevice->SpareAreaAddress & (FtwDevice->BlockSize - 1)) != 0) ||\r
+ ((FtwDevice->SpareAreaLength & (FtwDevice->BlockSize - 1)) != 0)) {\r
+ DEBUG ((EFI_D_ERROR, "Ftw: Spare area address or length is not block size aligned\n"));\r
+ FreePool (HandleBuffer);\r
+ //\r
+ // Report Status Code EFI_SW_EC_ABORTED.\r
+ //\r
+ REPORT_STATUS_CODE ( (EFI_ERROR_CODE | EFI_ERROR_UNRECOVERED), (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_EC_ABORTED));\r
+ ASSERT (FALSE);\r
+ CpuDeadLoop ();\r
+ }\r
break;\r
}\r
}\r
}\r
}\r
FreePool (HandleBuffer);\r
- \r
+\r
if ((FtwDevice->FtwBackupFvb == NULL) || (FtwDevice->FtwFvBlock == NULL) ||\r
(FtwDevice->FtwWorkSpaceLba == (EFI_LBA) (-1)) || (FtwDevice->FtwSpareLba == (EFI_LBA) (-1))) {\r
return EFI_ABORTED;\r
}\r
- \r
+\r
return EFI_SUCCESS;\r
}\r
\r
UINT64 Length;\r
EFI_PHYSICAL_ADDRESS VariableStoreBase;\r
UINT64 VariableStoreLength;\r
+ UINTN FtwMaxBlockSize;\r
\r
//\r
// Ensure FTW protocol is installed.\r
if (EFI_ERROR (Status)) {\r
return ;\r
}\r
- \r
+\r
+ Status = FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize);\r
+ if (!EFI_ERROR (Status)) {\r
+ ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <= FtwMaxBlockSize);\r
+ }\r
+\r
//\r
// Find the proper FVB protocol for variable.\r
//\r
EFI_SMM_FIRMWARE_VOLUME_BLOCK_PROTOCOL *FvbProtocol;\r
EFI_SMM_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;\r
EFI_PHYSICAL_ADDRESS NvStorageVariableBase;\r
+ UINTN FtwMaxBlockSize;\r
\r
if (mVariableModuleGlobal->FvbInstance != NULL) {\r
return EFI_SUCCESS;\r
return Status;\r
}\r
\r
+ Status = FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize);\r
+ if (!EFI_ERROR (Status)) {\r
+ ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <= FtwMaxBlockSize);\r
+ }\r
+\r
//\r
// Find the proper FVB protocol for variable.\r
//\r