]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Add the alignment check for FTW spare area address and length, and...
authorStar Zeng <star.zeng@intel.com>
Thu, 11 Jul 2013 08:15:47 +0000 (08:15 +0000)
committerlzeng14 <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 11 Jul 2013 08:15:47 +0000 (08:15 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14463 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/MdeModulePkg.dec
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf
MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c

index 7db47ecfb87cb47eb8d6dec5c922b1c27d74646d..ba922a935be89d5bf469cde3de51bc2e37b92762 100644 (file)
   ## 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
index 78c65f2af6cbfef5e74a566976b26f8080ff5b1c..a460694d655972a3103e553f8f09c9614e5b240e 100644 (file)
@@ -32,6 +32,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #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
index 3d4b9123a183361343b02727c346fcda942fb2b4..f4576447db20d4c1a6cd4e12f23833080c7c5d85 100644 (file)
@@ -47,6 +47,7 @@
   DebugLib\r
   UefiLib\r
   PcdLib\r
+  ReportStatusCodeLib\r
 \r
 [Guids]\r
   gEdkiiWorkingBlockSignatureGuid               ## CONSUMES ## FV Signature of Working Space Header\r
index a5c8a58f22d3df86f80329e6f0c55ecc31b80249..7740efa35966a5dff76697bd9652d0cd0d15fdfe 100644 (file)
@@ -50,6 +50,7 @@
   DebugLib\r
   UefiLib\r
   PcdLib\r
+  ReportStatusCodeLib\r
 \r
 [Guids]\r
   gEdkiiWorkingBlockSignatureGuid                  ## CONSUMES ## FV Signature of Working Space Header\r
index fdd9dfa0c17a30f5c146dac3516ee49361323250..b3352bbe070d03510200ae69bf0f96cf89fceb65 100644 (file)
@@ -1111,6 +1111,20 @@ FindFvbForFtw (
               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
@@ -1118,12 +1132,12 @@ FindFvbForFtw (
     }\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
index a697ae1c3a39414ab3600ff53aa5e005673a9cb6..c02d637699ab6aacc04ffe8ac1eaa9884ad51e93 100644 (file)
@@ -335,6 +335,7 @@ FtwNotificationEvent (
   UINT64                                  Length;\r
   EFI_PHYSICAL_ADDRESS                    VariableStoreBase;\r
   UINT64                                  VariableStoreLength;\r
+  UINTN                                   FtwMaxBlockSize;\r
 \r
   //\r
   // Ensure FTW protocol is installed.\r
@@ -343,7 +344,12 @@ FtwNotificationEvent (
   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
index 1ffa74e6cc57c5048ec7d937136c5d77532a9441..a80948bce8279d25e526749aed855bd4a172d708 100644 (file)
@@ -792,6 +792,7 @@ SmmFtwNotificationEvent (
   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
@@ -805,6 +806,11 @@ SmmFtwNotificationEvent (
     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