]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Report the setting variable failure to platform through the status code when core...
authorRuiyu Ni <ruiyu.ni@intel.com>
Tue, 25 Mar 2014 02:38:54 +0000 (02:38 +0000)
committerniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 25 Mar 2014 02:38:54 +0000 (02:38 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15385 6f19259b-4bc3-4df7-8a09-765794883524

17 files changed:
IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c
IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c
IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf
IntelFrameworkModulePkg/Library/GenericBdsLib/InternalBdsLib.h
IntelFrameworkModulePkg/Universal/BdsDxe/Bds.h
IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf
IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c
IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BBSsupport.c
IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BmLib.c
IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BootMaint.c
IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/Variable.c
IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c
IntelFrameworkModulePkg/Universal/BdsDxe/Hotkey.c
IntelFrameworkModulePkg/Universal/BdsDxe/Language.c
MdeModulePkg/Include/Guid/StatusCodeDataTypeVariable.h [new file with mode: 0644]
MdeModulePkg/MdeModulePkg.dec

index 3701434efba7d86cddb6705e1b6ffc5653590f31..134833286fcc8933d252e129ca8aaa7d9660d8ed 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   BDS Lib functions which relate with create or process the boot option.\r
 \r
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -82,6 +82,10 @@ BdsDeleteBootOption (
                   0,\r
                   NULL\r
                   );\r
+  //\r
+  // Deleting variable with existing variable implementation shouldn't fail.\r
+  //\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
   // adjust boot order array\r
@@ -626,6 +630,10 @@ BdsDeleteAllInvalidLegacyBootOptions (
                   BootOrderSize,\r
                   BootOrder\r
                   );\r
+  //\r
+  // Shrinking variable with existing variable implementation shouldn't fail.\r
+  //\r
+  ASSERT_EFI_ERROR (Status);\r
   if (BootOrder != NULL) {\r
     FreePool (BootOrder);\r
   }\r
@@ -857,11 +865,10 @@ BdsAddNonExistingLegacyBootOptions (
                 &BootOrder,\r
                 &BootOrderSize\r
                 );\r
-      if (EFI_ERROR (Status)) {\r
-        break;\r
+      if (!EFI_ERROR (Status)) {\r
+        BbsIndex     = Index;\r
+        OptionNumber = BootOrder[BootOrderSize / sizeof (UINT16) - 1];\r
       }\r
-      BbsIndex     = Index;\r
-      OptionNumber = BootOrder[BootOrderSize / sizeof (UINT16) - 1];\r
     }\r
 \r
     ASSERT (BbsIndex == Index);\r
@@ -2265,7 +2272,7 @@ BdsLibBootViaBootOption (
     // In this case, "BootCurrent" is not created.\r
     // Only create the BootCurrent variable when it points to a valid Boot#### variable.\r
     //\r
-    gRT->SetVariable (\r
+    SetVariableAndReportStatusCodeOnError (\r
           L"BootCurrent",\r
           &gEfiGlobalVariableGuid,\r
           EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
@@ -2463,13 +2470,14 @@ Done:
 \r
   //\r
   // Clear Boot Current\r
+  // Deleting variable with current implementation shouldn't fail.\r
   //\r
   gRT->SetVariable (\r
         L"BootCurrent",\r
         &gEfiGlobalVariableGuid,\r
         EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
         0,\r
-        &Option->BootCurrent\r
+        NULL\r
         );\r
 \r
   return Status;\r
@@ -2580,6 +2588,7 @@ BdsExpandPartitionPartialDevicePathToFull (
         FreePool (TempNewDevicePath);\r
         //\r
         // Save the matching Device Path so we don't need to do a connect all next time\r
+        // Failure to set the variable only impacts the performance when next time expanding the short-form device path.\r
         //\r
         Status = gRT->SetVariable (\r
                         HD_BOOT_DEVICE_PATH_VARIABLE_NAME,\r
@@ -2678,6 +2687,7 @@ BdsExpandPartitionPartialDevicePathToFull (
 \r
       //\r
       // Save the matching Device Path so we don't need to do a connect all next time\r
+      // Failure to set the variable only impacts the performance when next time expanding the short-form device path.\r
       //\r
       Status = gRT->SetVariable (\r
                       HD_BOOT_DEVICE_PATH_VARIABLE_NAME,\r
@@ -2887,6 +2897,10 @@ BdsLibDeleteOptionFromHandle (
                   BootOrderSize,\r
                   BootOrder\r
                   );\r
+  //\r
+  // Shrinking variable with existing variable implementation shouldn't fail.\r
+  //\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
   FreePool (BootOrder);\r
 \r
@@ -2985,6 +2999,10 @@ BdsDeleteAllInvalidEfiBootOption (
                       NULL\r
                       );\r
       //\r
+      // Deleting variable with current variable implementation shouldn't fail.\r
+      //\r
+      ASSERT_EFI_ERROR (Status);\r
+      //\r
       // Mark this boot option in boot order as deleted\r
       //\r
       BootOrder[Index] = 0xffff;\r
@@ -3012,6 +3030,10 @@ BdsDeleteAllInvalidEfiBootOption (
                   Index2 * sizeof (UINT16),\r
                   BootOrder\r
                   );\r
+  //\r
+  // Shrinking variable with current variable implementation shouldn't fail.\r
+  //\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
   FreePool (BootOrder);\r
 \r
@@ -3135,7 +3157,9 @@ BdsLibEnumerateAllBootOption (
         AsciiStrSize (PlatLang),\r
         PlatLang\r
         );\r
-      ASSERT_EFI_ERROR (Status);\r
+      //\r
+      // Failure to set the variable only impacts the performance next time enumerating the boot options.\r
+      //\r
 \r
       if (LastLang != NULL) {\r
         FreePool (LastLang);\r
@@ -3478,6 +3502,7 @@ BdsLibBootNext (
   VOID\r
   )\r
 {\r
+  EFI_STATUS        Status;\r
   UINT16            *BootNext;\r
   UINTN             BootNextSize;\r
   CHAR16            Buffer[20];\r
@@ -3502,13 +3527,17 @@ BdsLibBootNext (
   // Clear the boot next variable first\r
   //\r
   if (BootNext != NULL) {\r
-    gRT->SetVariable (\r
-          L"BootNext",\r
-          &gEfiGlobalVariableGuid,\r
-          EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
-          0,\r
-          BootNext\r
-          );\r
+    Status = gRT->SetVariable (\r
+                    L"BootNext",\r
+                    &gEfiGlobalVariableGuid,\r
+                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
+                    0,\r
+                    NULL\r
+                    );\r
+    //\r
+    // Deleting variable with current variable implementation shouldn't fail.\r
+    //\r
+    ASSERT_EFI_ERROR (Status);\r
 \r
     //\r
     // Start to build the boot option and try to boot\r
index 84e4a0e6be2d9cc07e348414b826428d8de42db7..271093eec95c4e884bbdb99d1a2d38335e101038 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   BDS Lib functions which contain all the code to connect console device\r
 \r
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -285,17 +285,16 @@ BdsLibUpdateConsoleVariable (
   // Finally, Update the variable of the default console by NewDevicePath\r
   //\r
   DevicePathSize = GetDevicePathSize (NewDevicePath);\r
-  Status = gRT->SetVariable (\r
-                  ConVarName,\r
-                  &gEfiGlobalVariableGuid,\r
-                  Attributes,\r
-                  DevicePathSize,\r
-                  NewDevicePath\r
-                  );\r
+  Status = SetVariableAndReportStatusCodeOnError (\r
+             ConVarName,\r
+             &gEfiGlobalVariableGuid,\r
+             Attributes,\r
+             DevicePathSize,\r
+             NewDevicePath\r
+             );\r
   if ((DevicePathSize == 0) && (Status == EFI_NOT_FOUND)) {\r
     Status = EFI_SUCCESS;\r
   }\r
-  ASSERT_EFI_ERROR (Status);\r
 \r
   if (VarConsole == NewDevicePath) {\r
     if (VarConsole != NULL) {\r
index cafbe71e25993f28fc5976713f2768168e13f2db..4ea30bdf7defb1fa8e5356a80d24629d1da46b3d 100644 (file)
@@ -1419,13 +1419,13 @@ BdsSetMemoryTypeInformationVariable (
   // Or create the variable in first boot.\r
   //\r
   if (MemoryTypeInformationModified || !MemoryTypeInformationVariableExists) {\r
-    Status = gRT->SetVariable (\r
-                    EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,\r
-                    &gEfiMemoryTypeInformationGuid,\r
-                    EFI_VARIABLE_NON_VOLATILE  | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
-                    VariableSize,\r
-                    PreviousMemoryTypeInformation\r
-                    );\r
+    Status = SetVariableAndReportStatusCodeOnError (\r
+               EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,\r
+               &gEfiMemoryTypeInformationGuid,\r
+               EFI_VARIABLE_NON_VOLATILE  | EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
+               VariableSize,\r
+               PreviousMemoryTypeInformation\r
+               );\r
 \r
     if (!EFI_ERROR (Status)) {\r
       //\r
@@ -1486,3 +1486,87 @@ BdsLibUserIdentify (
   return Manager->Identify (Manager, User);\r
 }\r
 \r
+/**\r
+  Set the variable and report the error through status code upon failure.\r
+\r
+  @param  VariableName           A Null-terminated string that is the name of the vendor's variable.\r
+                                 Each VariableName is unique for each VendorGuid. VariableName must\r
+                                 contain 1 or more characters. If VariableName is an empty string,\r
+                                 then EFI_INVALID_PARAMETER is returned.\r
+  @param  VendorGuid             A unique identifier for the vendor.\r
+  @param  Attributes             Attributes bitmask to set for the variable.\r
+  @param  DataSize               The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE, \r
+                                 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or \r
+                                 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero \r
+                                 causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is \r
+                                 set, then a SetVariable() call with a DataSize of zero will not cause any change to \r
+                                 the variable value (the timestamp associated with the variable may be updated however \r
+                                 even if no new data value is provided,see the description of the \r
+                                 EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not \r
+                                 be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated). \r
+  @param  Data                   The contents for the variable.\r
+\r
+  @retval EFI_SUCCESS            The firmware has successfully stored the variable and its data as\r
+                                 defined by the Attributes.\r
+  @retval EFI_INVALID_PARAMETER  An invalid combination of attribute bits, name, and GUID was supplied, or the\r
+                                 DataSize exceeds the maximum allowed.\r
+  @retval EFI_INVALID_PARAMETER  VariableName is an empty string.\r
+  @retval EFI_OUT_OF_RESOURCES   Not enough storage is available to hold the variable and its data.\r
+  @retval EFI_DEVICE_ERROR       The variable could not be retrieved due to a hardware error.\r
+  @retval EFI_WRITE_PROTECTED    The variable in question is read-only.\r
+  @retval EFI_WRITE_PROTECTED    The variable in question cannot be deleted.\r
+  @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS \r
+                                 or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo \r
+                                 does NOT pass the validation check carried out by the firmware.\r
+\r
+  @retval EFI_NOT_FOUND          The variable trying to be updated or deleted was not found.\r
+**/\r
+EFI_STATUS\r
+SetVariableAndReportStatusCodeOnError (\r
+  IN CHAR16     *VariableName,\r
+  IN EFI_GUID   *VendorGuid,\r
+  IN UINT32     Attributes,\r
+  IN UINTN      DataSize,\r
+  IN VOID       *Data\r
+  )\r
+{\r
+  EFI_STATUS                 Status;\r
+  EDKII_SET_VARIABLE_STATUS  *SetVariableStatus;\r
+  UINTN                      NameSize;\r
+\r
+  Status = gRT->SetVariable (\r
+                  VariableName,\r
+                  VendorGuid,\r
+                  Attributes,\r
+                  DataSize,\r
+                  Data\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    NameSize = StrSize (VariableName);\r
+    SetVariableStatus = AllocatePool (sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + DataSize);\r
+    if (SetVariableStatus != NULL) {\r
+      CopyGuid (&SetVariableStatus->Guid, VendorGuid);\r
+      SetVariableStatus->NameSize   = NameSize;\r
+      SetVariableStatus->DataSize   = DataSize;\r
+      SetVariableStatus->SetStatus  = Status;\r
+      SetVariableStatus->Attributes = Attributes;\r
+      CopyMem (SetVariableStatus + 1,                          VariableName, NameSize);\r
+      CopyMem (((UINT8 *) (SetVariableStatus + 1)) + NameSize, Data,         DataSize);\r
+\r
+      REPORT_STATUS_CODE_EX (\r
+        EFI_ERROR_CODE,\r
+        PcdGet32 (PcdErrorCodeSetVariable),\r
+        0,\r
+        NULL,\r
+        &gEdkiiStatusCodeDataTypeVariableGuid,\r
+        SetVariableStatus,\r
+        sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + DataSize\r
+        );\r
+\r
+      FreePool (SetVariableStatus);\r
+    }\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
index 2fb9916aa5334c2913611033ca4a5db9cf916e28..041afc4e109a3e3b71faf6fcc6e99f1355ce8424 100644 (file)
@@ -5,7 +5,7 @@
 #  2) BDS boot device connect interface;\r
 #  3) BDS Misc interfaces for mainting boot variable, ouput string, etc.\r
 #  \r
-#  Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
 #  which accompanies this distribution.  The full text of the license may be found at\r
@@ -79,6 +79,7 @@
   gHdBootDevicePathVariablGuid                  ## SOMETIMES_PRODUCES ## Variable:L"HDDP" (The device path of Boot file on Hard device.)\r
   gBdsLibStringPackageGuid                      ## PRODUCES ## GUID (HII String PackageList Guid)\r
   gEfiLegacyDevOrderVariableGuid                ## CONSUMES ## GUID\r
+  gEdkiiStatusCodeDataTypeVariableGuid          ## SOMETIMES_CONSUMES\r
 \r
 [Protocols]\r
   gEfiSimpleFileSystemProtocolGuid              # PROTOCOL CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderLoad\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderStart\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable\r
   gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile\r
index 80b1f49a90d3778abd1052a1af6f747342a7acd8..c32579bfc577c5b266e6edbef5ceb55fb165a870 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   BDS library definition, include the file and data structure\r
 \r
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -51,6 +51,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Guid/HdBootVariable.h>\r
 #include <Guid/LastEnumLang.h>\r
 #include <Guid/LegacyDevOrder.h>\r
+#include <Guid/StatusCodeDataTypeVariable.h>\r
 \r
 #include <Library/PrintLib.h>\r
 #include <Library/DebugLib.h>\r
@@ -147,4 +148,48 @@ ValidateOption (
   UINTN                     VariableSize\r
   );\r
 \r
+/**\r
+  Set the variable and report the error through status code upon failure.\r
+\r
+  @param  VariableName           A Null-terminated string that is the name of the vendor's variable.\r
+                                 Each VariableName is unique for each VendorGuid. VariableName must\r
+                                 contain 1 or more characters. If VariableName is an empty string,\r
+                                 then EFI_INVALID_PARAMETER is returned.\r
+  @param  VendorGuid             A unique identifier for the vendor.\r
+  @param  Attributes             Attributes bitmask to set for the variable.\r
+  @param  DataSize               The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE, \r
+                                 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or \r
+                                 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero \r
+                                 causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is \r
+                                 set, then a SetVariable() call with a DataSize of zero will not cause any change to \r
+                                 the variable value (the timestamp associated with the variable may be updated however \r
+                                 even if no new data value is provided,see the description of the \r
+                                 EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not \r
+                                 be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated). \r
+  @param  Data                   The contents for the variable.\r
+\r
+  @retval EFI_SUCCESS            The firmware has successfully stored the variable and its data as\r
+                                 defined by the Attributes.\r
+  @retval EFI_INVALID_PARAMETER  An invalid combination of attribute bits, name, and GUID was supplied, or the\r
+                                 DataSize exceeds the maximum allowed.\r
+  @retval EFI_INVALID_PARAMETER  VariableName is an empty string.\r
+  @retval EFI_OUT_OF_RESOURCES   Not enough storage is available to hold the variable and its data.\r
+  @retval EFI_DEVICE_ERROR       The variable could not be retrieved due to a hardware error.\r
+  @retval EFI_WRITE_PROTECTED    The variable in question is read-only.\r
+  @retval EFI_WRITE_PROTECTED    The variable in question cannot be deleted.\r
+  @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS \r
+                                 or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo \r
+                                 does NOT pass the validation check carried out by the firmware.\r
+\r
+  @retval EFI_NOT_FOUND          The variable trying to be updated or deleted was not found.\r
+**/\r
+EFI_STATUS\r
+SetVariableAndReportStatusCodeOnError (\r
+  IN CHAR16     *VariableName,\r
+  IN EFI_GUID   *VendorGuid,\r
+  IN UINT32     Attributes,\r
+  IN UINTN      DataSize,\r
+  IN VOID       *Data\r
+  );\r
+\r
 #endif // _BDS_LIB_H_\r
index e535bc21dadeeba8de60cecba69bc3729cef85e3..93bafd2dd8ec25c598358cdd4759ccc20068c048 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Head file for BDS Architectural Protocol implementation\r
 \r
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -20,6 +20,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Guid/MdeModuleHii.h>\r
 #include <Guid/FileSystemVolumeLabelInfo.h>\r
 #include <Guid/HiiPlatformSetupFormset.h>\r
+#include <Guid/StatusCodeDataTypeVariable.h>\r
 #include <Protocol/DevicePath.h>\r
 #include <IndustryStandard/SmBios.h>\r
 #include <Protocol/LoadFile.h>\r
@@ -189,4 +190,48 @@ BdsProcessCapsules (
   EFI_BOOT_MODE BootMode\r
   );\r
 \r
+/**\r
+  Set the variable and report the error through status code upon failure.\r
+\r
+  @param  VariableName           A Null-terminated string that is the name of the vendor's variable.\r
+                                 Each VariableName is unique for each VendorGuid. VariableName must\r
+                                 contain 1 or more characters. If VariableName is an empty string,\r
+                                 then EFI_INVALID_PARAMETER is returned.\r
+  @param  VendorGuid             A unique identifier for the vendor.\r
+  @param  Attributes             Attributes bitmask to set for the variable.\r
+  @param  DataSize               The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE, \r
+                                 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or \r
+                                 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero \r
+                                 causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is \r
+                                 set, then a SetVariable() call with a DataSize of zero will not cause any change to \r
+                                 the variable value (the timestamp associated with the variable may be updated however \r
+                                 even if no new data value is provided,see the description of the \r
+                                 EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not \r
+                                 be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated). \r
+  @param  Data                   The contents for the variable.\r
+\r
+  @retval EFI_SUCCESS            The firmware has successfully stored the variable and its data as\r
+                                 defined by the Attributes.\r
+  @retval EFI_INVALID_PARAMETER  An invalid combination of attribute bits, name, and GUID was supplied, or the\r
+                                 DataSize exceeds the maximum allowed.\r
+  @retval EFI_INVALID_PARAMETER  VariableName is an empty string.\r
+  @retval EFI_OUT_OF_RESOURCES   Not enough storage is available to hold the variable and its data.\r
+  @retval EFI_DEVICE_ERROR       The variable could not be retrieved due to a hardware error.\r
+  @retval EFI_WRITE_PROTECTED    The variable in question is read-only.\r
+  @retval EFI_WRITE_PROTECTED    The variable in question cannot be deleted.\r
+  @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS \r
+                                 or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo \r
+                                 does NOT pass the validation check carried out by the firmware.\r
+\r
+  @retval EFI_NOT_FOUND          The variable trying to be updated or deleted was not found.\r
+**/\r
+EFI_STATUS\r
+BdsDxeSetVariableAndReportStatusCodeOnError (\r
+  IN CHAR16     *VariableName,\r
+  IN EFI_GUID   *VendorGuid,\r
+  IN UINT32     Attributes,\r
+  IN UINTN      DataSize,\r
+  IN VOID       *Data\r
+  );\r
+\r
 #endif\r
index b10056491ef3eede047d17a3f809d9115f9e5d26..6796adc43674574df55cfa7d7fc7eee39dad891c 100644 (file)
@@ -14,7 +14,7 @@
 #  BDSDxe also maintain the UI for "Boot Manager, Boot Maintaince Manager, Device Manager" which\r
 #  is used for user to configure boot option or maintain hardware device.\r
 #  \r
-#  Copyright (c) 2008 - 2013, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR>\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
 #  which accompanies this distribution.  The full text of the license may be found at\r
   gDriverHealthFormSetGuid                      ## SOMETIMES_PRODUCES ## DriverHealth HII Package\r
   gConnectConInEventGuid                        ## CONSUMES ## GUID (Connect ConIn Event)\r
   gEfiFmpCapsuleGuid                            ## CONSUMES ## GUID (FMP Capsule)\r
+  gEdkiiStatusCodeDataTypeVariableGuid          ## SOMETIMES_CONSUMES\r
 \r
 [Protocols]\r
   gEfiSimpleFileSystemProtocolGuid              ## PROTOCOL CONSUMES\r
   gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdSetupVideoHorizontalResolution\r
   gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdSetupVideoVerticalResolution\r
   gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable\r
 \r
 [Depex]\r
   TRUE\r
index 33b3cc2dc4e4f46db244c64bb2e1b1c6aeb535c0..ae7ad2153c51b5d663992648db0b3e9ad5e0b7ed 100644 (file)
@@ -5,7 +5,7 @@
   After DxeCore finish DXE phase, gEfiBdsArchProtocolGuid->BdsEntry will be invoked\r
   to enter BDS phase.\r
 \r
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -164,13 +164,17 @@ BdsBootDeviceSelect (
     //\r
     // Clear the this variable so it's only exist in this time boot\r
     //\r
-    gRT->SetVariable (\r
-          L"BootNext",\r
-          &gEfiGlobalVariableGuid,\r
-          EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
-          0,\r
-          mBootNext\r
-          );\r
+    Status = gRT->SetVariable (\r
+                    L"BootNext",\r
+                    &gEfiGlobalVariableGuid,\r
+                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
+                    0,\r
+                    NULL\r
+                    );\r
+    //\r
+    // Deleting variable with current variable implementation shouldn't fail.\r
+    //\r
+    ASSERT_EFI_ERROR (Status);\r
 \r
     //\r
     // Add the boot next boot option\r
@@ -368,6 +372,9 @@ BdsFormalizeConsoleVariable (
                     0,\r
                     NULL\r
                     );\r
+    //\r
+    // Deleting variable with current variable implementation shouldn't fail.\r
+    //\r
     ASSERT_EFI_ERROR (Status);\r
   }\r
 }\r
@@ -406,14 +413,13 @@ BdsFormalizeEfiGlobalVariable (
   OsIndicationSupport = EFI_OS_INDICATIONS_BOOT_TO_FW_UI \\r
                       | EFI_OS_INDICATIONS_FMP_CAPSULE_SUPPORTED;\r
 \r
-  Status = gRT->SetVariable (\r
-                  L"OsIndicationsSupported",\r
-                  &gEfiGlobalVariableGuid,\r
-                  EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
-                  sizeof(UINT64),\r
-                  &OsIndicationSupport\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
+  BdsDxeSetVariableAndReportStatusCodeOnError (\r
+    L"OsIndicationsSupported",\r
+    &gEfiGlobalVariableGuid,\r
+    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+    sizeof(UINT64),\r
+    &OsIndicationSupport\r
+    );\r
 \r
   //\r
   // If OsIndications is invalid, remove it.\r
@@ -442,10 +448,13 @@ BdsFormalizeEfiGlobalVariable (
       Status = gRT->SetVariable (\r
                       L"OsIndications",\r
                       &gEfiGlobalVariableGuid,\r
-                      Attributes,\r
                       0,\r
-                      &OsIndication\r
+                      0,\r
+                      NULL\r
                       );\r
+      //\r
+      // Deleting variable with current variable implementation shouldn't fail.\r
+      //\r
       ASSERT_EFI_ERROR (Status);\r
     }\r
   }\r
@@ -481,16 +490,19 @@ BdsAllocateMemoryForPerformanceData (
     //\r
     // Save the pointer to variable for use in S3 resume.\r
     //\r
-    Status = gRT->SetVariable (\r
-               L"PerfDataMemAddr",\r
-               &gPerformanceProtocolGuid,\r
-               EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
-               sizeof (EFI_PHYSICAL_ADDRESS),\r
-               &AcpiLowMemoryBase\r
-               );\r
-    ASSERT_EFI_ERROR (Status);\r
+    BdsDxeSetVariableAndReportStatusCodeOnError (\r
+      L"PerfDataMemAddr",\r
+      &gPerformanceProtocolGuid,\r
+      EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+      sizeof (EFI_PHYSICAL_ADDRESS),\r
+      &AcpiLowMemoryBase\r
+      );\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((EFI_D_ERROR, "[Bds] PerfDataMemAddr (%08x) cannot be saved to NV storage.\n", AcpiLowMemoryBase));\r
+    }\r
     //\r
     // Mark L"PerfDataMemAddr" variable to read-only if the Variable Lock protocol exists\r
+    // Still lock it even the variable cannot be saved to prevent it's set by 3rd party code.\r
     //\r
     Status = gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (VOID **) &VariableLock);\r
     if (!EFI_ERROR (Status)) {\r
@@ -594,14 +606,13 @@ BdsEntry (
     // If time out value equal 0xFFFF, no need set to 0xFFFF to variable area because UEFI specification\r
     // define same behavior between no value or 0xFFFF value for L"Timeout".\r
     //\r
-    Status = gRT->SetVariable (\r
+    BdsDxeSetVariableAndReportStatusCodeOnError (\r
                     L"Timeout",\r
                     &gEfiGlobalVariableGuid,\r
                     EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
                     sizeof (UINT16),\r
                     &BootTimeOut\r
                     );\r
-    ASSERT_EFI_ERROR(Status);\r
   }\r
 \r
   //\r
@@ -655,3 +666,89 @@ BdsEntry (
 \r
   return ;\r
 }\r
+\r
+\r
+/**\r
+  Set the variable and report the error through status code upon failure.\r
+\r
+  @param  VariableName           A Null-terminated string that is the name of the vendor's variable.\r
+                                 Each VariableName is unique for each VendorGuid. VariableName must\r
+                                 contain 1 or more characters. If VariableName is an empty string,\r
+                                 then EFI_INVALID_PARAMETER is returned.\r
+  @param  VendorGuid             A unique identifier for the vendor.\r
+  @param  Attributes             Attributes bitmask to set for the variable.\r
+  @param  DataSize               The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE, \r
+                                 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or \r
+                                 EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero \r
+                                 causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is \r
+                                 set, then a SetVariable() call with a DataSize of zero will not cause any change to \r
+                                 the variable value (the timestamp associated with the variable may be updated however \r
+                                 even if no new data value is provided,see the description of the \r
+                                 EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not \r
+                                 be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated). \r
+  @param  Data                   The contents for the variable.\r
+\r
+  @retval EFI_SUCCESS            The firmware has successfully stored the variable and its data as\r
+                                 defined by the Attributes.\r
+  @retval EFI_INVALID_PARAMETER  An invalid combination of attribute bits, name, and GUID was supplied, or the\r
+                                 DataSize exceeds the maximum allowed.\r
+  @retval EFI_INVALID_PARAMETER  VariableName is an empty string.\r
+  @retval EFI_OUT_OF_RESOURCES   Not enough storage is available to hold the variable and its data.\r
+  @retval EFI_DEVICE_ERROR       The variable could not be retrieved due to a hardware error.\r
+  @retval EFI_WRITE_PROTECTED    The variable in question is read-only.\r
+  @retval EFI_WRITE_PROTECTED    The variable in question cannot be deleted.\r
+  @retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS \r
+                                 or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo \r
+                                 does NOT pass the validation check carried out by the firmware.\r
+\r
+  @retval EFI_NOT_FOUND          The variable trying to be updated or deleted was not found.\r
+**/\r
+EFI_STATUS\r
+BdsDxeSetVariableAndReportStatusCodeOnError (\r
+  IN CHAR16     *VariableName,\r
+  IN EFI_GUID   *VendorGuid,\r
+  IN UINT32     Attributes,\r
+  IN UINTN      DataSize,\r
+  IN VOID       *Data\r
+  )\r
+{\r
+  EFI_STATUS                 Status;\r
+  EDKII_SET_VARIABLE_STATUS  *SetVariableStatus;\r
+  UINTN                      NameSize;\r
+\r
+  Status = gRT->SetVariable (\r
+                  VariableName,\r
+                  VendorGuid,\r
+                  Attributes,\r
+                  DataSize,\r
+                  Data\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    NameSize = StrSize (VariableName);\r
+    SetVariableStatus = AllocatePool (sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + DataSize);\r
+    if (SetVariableStatus != NULL) {\r
+      CopyGuid (&SetVariableStatus->Guid, VendorGuid);\r
+      SetVariableStatus->NameSize   = NameSize;\r
+      SetVariableStatus->DataSize   = DataSize;\r
+      SetVariableStatus->SetStatus  = Status;\r
+      SetVariableStatus->Attributes = Attributes;\r
+      CopyMem (SetVariableStatus + 1,                          VariableName, NameSize);\r
+      CopyMem (((UINT8 *) (SetVariableStatus + 1)) + NameSize, Data,         DataSize);\r
+\r
+      REPORT_STATUS_CODE_EX (\r
+        EFI_ERROR_CODE,\r
+        PcdGet32 (PcdErrorCodeSetVariable),\r
+        0,\r
+        NULL,\r
+        &gEdkiiStatusCodeDataTypeVariableGuid,\r
+        SetVariableStatus,\r
+        sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + DataSize\r
+        );\r
+\r
+      FreePool (SetVariableStatus);\r
+    }\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
index db0fed5834d512b415784f86e537d6f745ef131c..adf84f42f78e1d35d1696a2d44e91f418b5a5c92 100644 (file)
@@ -3,7 +3,7 @@
   and manage the legacy boot option, all legacy boot option is getting from\r
   the legacy BBS table.\r
 \r
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -143,6 +143,9 @@ OrderLegacyBootOption4SameType (
                   BootOrderSize,\r
                   BootOrder\r
                   );\r
+  //\r
+  // Changing content without increasing its size with current variable implementation shouldn't fail.\r
+  //\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   FreePool (NewBootOption);\r
@@ -171,6 +174,7 @@ GroupMultipleLegacyBootOption4SameType (
   VOID\r
   )\r
 {\r
+  EFI_STATUS                   Status;\r
   UINTN                        Index;\r
   UINTN                        DeviceIndex;\r
   UINTN                        DeviceTypeIndex[7];\r
@@ -233,13 +237,17 @@ GroupMultipleLegacyBootOption4SameType (
     FreePool (BootOption);\r
   }\r
 \r
-  gRT->SetVariable (\r
-         L"BootOrder",\r
-         &gEfiGlobalVariableGuid,\r
-         EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
-         BootOrderSize,\r
-         BootOrder\r
-         );\r
+  Status = gRT->SetVariable (\r
+                  L"BootOrder",\r
+                  &gEfiGlobalVariableGuid,\r
+                  EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
+                  BootOrderSize,\r
+                  BootOrder\r
+                  );\r
+  //\r
+  // Changing content without increasing its size with current variable implementation shouldn't fail.\r
+  //\r
+  ASSERT_EFI_ERROR (Status);\r
   FreePool (BootOrder);\r
 }\r
 \r
index c83b7ddede92491b9c778d145e6ca4a85af3b759..5fe5388f9e5add1f31b45f2517a129da23034718 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Utility routines used by boot maintenance modules.\r
 \r
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -178,7 +178,10 @@ EfiLibDeleteVariable (
                     0,\r
                     NULL\r
                     );\r
-    ASSERT (!EFI_ERROR (Status));\r
+    //\r
+    // Deleting variable with current variable implementation shouldn't fail.\r
+    //\r
+    ASSERT_EFI_ERROR (Status);\r
     FreePool (VarBuf);\r
   }\r
 \r
index 5f200e2e16e2ad7391fa9ae71b45521f24b6f75c..b974a67ea53402b4c8a850278858b6ff1c680ed1 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The functions for Boot Maintainence Main menu.\r
 \r
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -672,14 +672,13 @@ ApplyChangeHandler (
     break;\r
 \r
   case FORM_TIME_OUT_ID:\r
-    Status = gRT->SetVariable (\r
-                    L"Timeout",\r
-                    &gEfiGlobalVariableGuid,\r
-                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
-                    sizeof (UINT16),\r
-                    &(CurrentFakeNVMap->BootTimeOut)\r
-                    );\r
-    ASSERT_EFI_ERROR(Status);\r
+    BdsDxeSetVariableAndReportStatusCodeOnError (\r
+      L"Timeout",\r
+      &gEfiGlobalVariableGuid,\r
+      EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
+      sizeof (UINT16),\r
+      &(CurrentFakeNVMap->BootTimeOut)\r
+      );\r
 \r
     Private->BmmOldFakeNVData.BootTimeOut = CurrentFakeNVMap->BootTimeOut;\r
     break;\r
index ef36ae2dc81b39122e62a6c8d55de76c46470df7..f374e5b2561ae4ab53fe16c0b123a0479f9996f1 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Variable operation that will be used by bootmaint\r
 \r
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -165,9 +165,10 @@ Var_ChangeBootOrder (
                     BootOrderListSize * sizeof (UINT16),\r
                     BootOrderList\r
                     );\r
-    if (EFI_ERROR (Status)) {\r
-      return Status;\r
-    }\r
+    //\r
+    // Changing variable without increasing its size with current variable implementation shouldn't fail.\r
+    //\r
+    ASSERT_EFI_ERROR (Status);\r
   }\r
   return EFI_SUCCESS;\r
 }\r
@@ -303,9 +304,10 @@ Var_ChangeDriverOrder (
                     DriverOrderListSize * sizeof (UINT16),\r
                     DriverOrderList\r
                     );\r
-    if (EFI_ERROR (Status)) {\r
-      return Status;\r
-    }\r
+    //\r
+    // Changing variable without increasing its size with current variable implementation shouldn't fail.\r
+    //\r
+    ASSERT_EFI_ERROR (Status);\r
   }\r
   return EFI_SUCCESS;\r
 }\r
@@ -338,7 +340,10 @@ Var_UpdateAllConsoleOption (
                     GetDevicePathSize (OutDevicePath),\r
                     OutDevicePath\r
                     );\r
-    ASSERT (!EFI_ERROR (Status));\r
+    //\r
+    // Changing variable without increasing its size with current variable implementation shouldn't fail.\r
+    //\r
+    ASSERT_EFI_ERROR (Status);\r
   }\r
 \r
   if (InpDevicePath != NULL) {\r
@@ -350,7 +355,10 @@ Var_UpdateAllConsoleOption (
                     GetDevicePathSize (InpDevicePath),\r
                     InpDevicePath\r
                     );\r
-    ASSERT (!EFI_ERROR (Status));\r
+    //\r
+    // Changing variable without increasing its size with current variable implementation shouldn't fail.\r
+    //\r
+    ASSERT_EFI_ERROR (Status);\r
   }\r
 \r
   if (ErrDevicePath != NULL) {\r
@@ -362,7 +370,10 @@ Var_UpdateAllConsoleOption (
                     GetDevicePathSize (ErrDevicePath),\r
                     ErrDevicePath\r
                     );\r
-    ASSERT (!EFI_ERROR (Status));\r
+    //\r
+    // Changing variable without increasing its size with current variable implementation shouldn't fail.\r
+    //\r
+    ASSERT_EFI_ERROR (Status);\r
   }\r
 }\r
 \r
@@ -667,38 +678,40 @@ Var_UpdateDriverOption (
                   BufferSize,\r
                   Buffer\r
                   );\r
-  ASSERT_EFI_ERROR (Status);\r
-  DriverOrderList = BdsLibGetVariableAndSize (\r
-                      L"DriverOrder",\r
-                      &gEfiGlobalVariableGuid,\r
-                      &DriverOrderListSize\r
-                      );\r
-  NewDriverOrderList = AllocateZeroPool (DriverOrderListSize + sizeof (UINT16));\r
-  ASSERT (NewDriverOrderList != NULL);\r
-  if (DriverOrderList != NULL) {\r
-    CopyMem (NewDriverOrderList, DriverOrderList, DriverOrderListSize);\r
-    EfiLibDeleteVariable (L"DriverOrder", &gEfiGlobalVariableGuid);\r
-  }\r
-  NewDriverOrderList[DriverOrderListSize / sizeof (UINT16)] = Index;\r
+  if (!EFI_ERROR (Status)) {\r
+    DriverOrderList = BdsLibGetVariableAndSize (\r
+                        L"DriverOrder",\r
+                        &gEfiGlobalVariableGuid,\r
+                        &DriverOrderListSize\r
+                        );\r
+    NewDriverOrderList = AllocateZeroPool (DriverOrderListSize + sizeof (UINT16));\r
+    ASSERT (NewDriverOrderList != NULL);\r
+    if (DriverOrderList != NULL) {\r
+      CopyMem (NewDriverOrderList, DriverOrderList, DriverOrderListSize);\r
+      EfiLibDeleteVariable (L"DriverOrder", &gEfiGlobalVariableGuid);\r
+    }\r
+    NewDriverOrderList[DriverOrderListSize / sizeof (UINT16)] = Index;\r
 \r
-  Status = gRT->SetVariable (\r
-                  L"DriverOrder",\r
-                  &gEfiGlobalVariableGuid,\r
-                  EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
-                  DriverOrderListSize + sizeof (UINT16),\r
-                  NewDriverOrderList\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
-  if (DriverOrderList != NULL) {\r
-    FreePool (DriverOrderList);\r
-  }\r
-  DriverOrderList = NULL;\r
-  FreePool (NewDriverOrderList);\r
-  InsertTailList (&DriverOptionMenu.Head, &NewMenuEntry->Link);\r
-  DriverOptionMenu.MenuNumber++;\r
+    Status = gRT->SetVariable (\r
+                    L"DriverOrder",\r
+                    &gEfiGlobalVariableGuid,\r
+                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
+                    DriverOrderListSize + sizeof (UINT16),\r
+                    NewDriverOrderList\r
+                    );\r
+    if (DriverOrderList != NULL) {\r
+      FreePool (DriverOrderList);\r
+    }\r
+    DriverOrderList = NULL;\r
+    FreePool (NewDriverOrderList);\r
+    if (!EFI_ERROR (Status)) {\r
+      InsertTailList (&DriverOptionMenu.Head, &NewMenuEntry->Link);\r
+      DriverOptionMenu.MenuNumber++;\r
 \r
-  *DescriptionData  = 0x0000;\r
-  *OptionalData     = 0x0000;\r
+      *DescriptionData  = 0x0000;\r
+      *OptionalData     = 0x0000;\r
+    }\r
+  }\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -835,39 +848,41 @@ Var_UpdateBootOption (
                   BufferSize,\r
                   Buffer\r
                   );\r
-  ASSERT_EFI_ERROR (Status);\r
+  if (!EFI_ERROR (Status)) {\r
 \r
-  BootOrderList = BdsLibGetVariableAndSize (\r
+    BootOrderList = BdsLibGetVariableAndSize (\r
+                      L"BootOrder",\r
+                      &gEfiGlobalVariableGuid,\r
+                      &BootOrderListSize\r
+                      );\r
+    ASSERT (BootOrderList != NULL);\r
+    NewBootOrderList = AllocateZeroPool (BootOrderListSize + sizeof (UINT16));\r
+    ASSERT (NewBootOrderList != NULL);\r
+    CopyMem (NewBootOrderList, BootOrderList, BootOrderListSize);\r
+    NewBootOrderList[BootOrderListSize / sizeof (UINT16)] = Index;\r
+\r
+    if (BootOrderList != NULL) {\r
+      FreePool (BootOrderList);\r
+    }\r
+\r
+    Status = gRT->SetVariable (\r
                     L"BootOrder",\r
                     &gEfiGlobalVariableGuid,\r
-                    &BootOrderListSize\r
+                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
+                    BootOrderListSize + sizeof (UINT16),\r
+                    NewBootOrderList\r
                     );\r
-  ASSERT (BootOrderList != NULL);\r
-  NewBootOrderList = AllocateZeroPool (BootOrderListSize + sizeof (UINT16));\r
-  ASSERT (NewBootOrderList != NULL);\r
-  CopyMem (NewBootOrderList, BootOrderList, BootOrderListSize);\r
-  NewBootOrderList[BootOrderListSize / sizeof (UINT16)] = Index;\r
+    if (!EFI_ERROR (Status)) {\r
 \r
-  if (BootOrderList != NULL) {\r
-    FreePool (BootOrderList);\r
-  }\r
+      FreePool (NewBootOrderList);\r
+      NewBootOrderList = NULL;\r
+      InsertTailList (&BootOptionMenu.Head, &NewMenuEntry->Link);\r
+      BootOptionMenu.MenuNumber++;\r
 \r
-  Status = gRT->SetVariable (\r
-                  L"BootOrder",\r
-                  &gEfiGlobalVariableGuid,\r
-                  EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
-                  BootOrderListSize + sizeof (UINT16),\r
-                  NewBootOrderList\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  FreePool (NewBootOrderList);\r
-  NewBootOrderList = NULL;\r
-  InsertTailList (&BootOptionMenu.Head, &NewMenuEntry->Link);\r
-  BootOptionMenu.MenuNumber++;\r
-\r
-  NvRamMap->DescriptionData[0]  = 0x0000;\r
-  NvRamMap->OptionalData[0]     = 0x0000;\r
+      NvRamMap->DescriptionData[0]  = 0x0000;\r
+      NvRamMap->OptionalData[0]     = 0x0000;\r
+    }\r
+  }\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -987,6 +1002,10 @@ Var_UpdateBootOrder (
                   BootOrderListSize,\r
                   BootOrderList\r
                   );\r
+  //\r
+  // Changing the content without increasing its size with current variable implementation shouldn't fail.\r
+  //\r
+  ASSERT_EFI_ERROR (Status);\r
   FreePool (BootOrderList);\r
 \r
   GroupMultipleLegacyBootOption4SameType ();\r
@@ -1058,10 +1077,11 @@ Var_UpdateDriverOrder (
                   DriverOrderListSize,\r
                   NewDriverOrderList\r
                   );\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
+  //\r
+  // Changing the content without increasing its size with current variable implementation shouldn't fail.\r
+  //\r
+  ASSERT_EFI_ERROR (Status);\r
+  \r
   BOpt_FreeMenu (&DriverOptionMenu);\r
   BOpt_GetDriverOptions (CallbackData);\r
   return EFI_SUCCESS;\r
@@ -1258,6 +1278,10 @@ Var_UpdateBBSOption (
                       OptionSize,\r
                       BootOptionVar\r
                       );\r
+      //\r
+      // Changing the content without increasing its size with current variable implementation shouldn't fail.\r
+      //\r
+      ASSERT_EFI_ERROR (Status);\r
 \r
       FreePool (BootOptionVar);\r
     }\r
@@ -1281,6 +1305,10 @@ Var_UpdateBBSOption (
                       OptionSize,\r
                       BootOptionVar\r
                       );\r
+      //\r
+      // Changing the content without increasing its size with current variable implementation shouldn't fail.\r
+      //\r
+      ASSERT_EFI_ERROR (Status);\r
 \r
       FreePool (BootOptionVar);\r
     }\r
index 432b22469ec535a52ddef442af6a4f660fd58aa5..3bbe71a8fe7c0082d80648022f30f4615f3a6c18 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   FrontPage routines to handle the callbacks and browser calls\r
 \r
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -182,7 +182,6 @@ FrontPageCallback (
   CHAR8                         *LangCode;\r
   CHAR8                         *Lang;\r
   UINTN                         Index;\r
-  EFI_STATUS                    Status;\r
 \r
   if (Action != EFI_BROWSER_ACTION_CHANGING && Action != EFI_BROWSER_ACTION_CHANGED) {\r
     //\r
@@ -226,14 +225,13 @@ FrontPageCallback (
       }\r
 \r
       if (Index == Value->u8) {\r
-        Status = gRT->SetVariable (\r
+        BdsDxeSetVariableAndReportStatusCodeOnError (\r
                         L"PlatformLang",\r
                         &gEfiGlobalVariableGuid,\r
                         EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
                         AsciiStrSize (Lang),\r
                         Lang\r
                         );\r
-        ASSERT_EFI_ERROR(Status);\r
       } else {\r
         ASSERT (FALSE);\r
       }\r
@@ -1095,6 +1093,9 @@ PlatformBdsEnterFrontPage (
                     sizeof(UINT64),\r
                     &OsIndication\r
                     );\r
+    //\r
+    // Changing the content without increasing its size with current variable implementation shouldn't fail.\r
+    //\r
     ASSERT_EFI_ERROR (Status);\r
 \r
     //\r
index 477411377d9a9ea048ffd12630270e79279a592a..63de0d5f57baed5f222fef08e25053f608b70fd8 100644 (file)
@@ -2,7 +2,7 @@
   Provides a way for 3rd party applications to register themselves for launch by the\r
   Boot Manager based on hot key\r
 \r
-Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -550,6 +550,9 @@ InitializeHotkeyService (
                   sizeof (UINT32),\r
                   &BootOptionSupport\r
                   );\r
+  //\r
+  // Platform needs to make sure setting volatile variable before calling 3rd party code shouldn't fail.\r
+  //\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   KeyOptionNumbers = HotkeyGetOptionNumbers (&KeyOptionCount);\r
index 6d25bfe2375fa2b523242f30c4592a6671750793..2eab617ae59ce109188f72d237608de800dbbe5a 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Language settings\r
 \r
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -425,7 +425,7 @@ InitializeLangVariable (
     // The default language code should be one of the supported language codes.\r
     //\r
     ASSERT (IsLangInSupportedLangCodes (SupportedLang, DefaultLang, Iso639Language));\r
-    Status = gRT->SetVariable (\r
+    BdsDxeSetVariableAndReportStatusCodeOnError (\r
                     LangName,\r
                     &gEfiGlobalVariableGuid,\r
                     EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
@@ -471,6 +471,10 @@ InitializeLanguage (
                       AsciiStrSize (LangCodes),\r
                       LangCodes\r
                       );\r
+      //\r
+      // Platform needs to make sure setting volatile variable before calling 3rd party code shouldn't fail.\r
+      //\r
+      ASSERT_EFI_ERROR (Status);\r
     }\r
 \r
     Status = gRT->SetVariable (\r
@@ -480,6 +484,10 @@ InitializeLanguage (
                     AsciiStrSize (PlatformLangCodes),\r
                     PlatformLangCodes\r
                     );\r
+    //\r
+    // Platform needs to make sure setting volatile variable before calling 3rd party code shouldn't fail.\r
+    //\r
+    ASSERT_EFI_ERROR (Status);\r
   }\r
 \r
   if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {\r
diff --git a/MdeModulePkg/Include/Guid/StatusCodeDataTypeVariable.h b/MdeModulePkg/Include/Guid/StatusCodeDataTypeVariable.h
new file mode 100644 (file)
index 0000000..9ea85f8
--- /dev/null
@@ -0,0 +1,40 @@
+/** @file\r
+  This file defines the GUID and data structure used to pass variable setting \r
+  failure information to the Status Code Protocol.\r
+\r
+Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials are licensed and made available under \r
+the terms and conditions of the BSD License that accompanies this distribution.  \r
+The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php.\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef _STATUS_CODE_DATA_TYPE_VARIABLE_H_\r
+#define _STATUS_CODE_DATA_TYPE_VARIABLE_H_\r
+\r
+///\r
+/// The Global ID used to identify a structure of type EDKII_SET_VARIABLE_STATUS.\r
+/// The status code value is PcdGet32 (PcdErrorCodeSetVariable).\r
+///\r
+#define EDKII_STATUS_CODE_DATA_TYPE_VARIABLE_GUID \\r
+  { \\r
+    0xf6ee6dbb, 0xd67f, 0x4ea0, { 0x8b, 0x96, 0x6a, 0x71, 0xb1, 0x9d, 0x84, 0xad } \\r
+  }\r
+\r
+typedef struct {\r
+  EFI_GUID   Guid;\r
+  UINTN      NameSize;\r
+  UINTN      DataSize;\r
+  EFI_STATUS SetStatus;\r
+  UINT32     Attributes;\r
+  // CHAR16  Name[];\r
+  // UINT8   Data[];\r
+} EDKII_SET_VARIABLE_STATUS;\r
+\r
+extern EFI_GUID gEdkiiStatusCodeDataTypeVariableGuid;\r
+\r
+#endif // _STATUS_CODE_DATA_TYPE_VARIABLE_H_\r
index 9084af7b84e4f83a97718fd7e51215b6b3494790..e04246a2f419eb87b27803f73e696a8c7509b568 100644 (file)
   ## Include/Guid/ConnectConInEvent.h\r
   gConnectConInEventGuid             = { 0xdb4e8151, 0x57ed, 0x4bed, { 0x88, 0x33, 0x67, 0x51, 0xb5, 0xd1, 0xa8, 0xd7 }}\r
 \r
+  ## Include/Guid/StatusCodeDataTypeVariable.h\r
+  gEdkiiStatusCodeDataTypeVariableGuid = { 0xf6ee6dbb, 0xd67f, 0x4ea0, { 0x8b, 0x96, 0x6a, 0x71, 0xb1, 0x9d, 0x84, 0xad }}\r
+\r
 [Ppis]\r
   ## Include/Ppi/AtaController.h\r
   gPeiAtaControllerPpiGuid       = { 0xa45e60d1, 0xc719, 0x44aa, { 0xb0, 0x7a, 0xaa, 0x77, 0x7f, 0x85, 0x90, 0x6d }}\r
   #  PROGRESS_CODE_S3_SUSPEND_END   = (EFI_SOFTWARE_SMM_DRIVER | (EFI_OEM_SPECIFIC | 0x00000001))    = 0x03078001\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeS3SuspendEnd|0x03078001|UINT32|0x30001033\r
 \r
+  ## Error Code for SetVariable failure.\r
+  #  EDKII_ERROR_CODE_SET_VARIABLE  = (EFI_SOFTWARE_DXE_BS_DRIVER | (EFI_OEM_SPECIFIC | 0x00000002)) = 0x03058002\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable|0x03058002|UINT32|0x30001040\r
+\r
 [PcdsFixedAtBuild,PcdsPatchableInModule]\r
   ## VPD type PCD allow developer point an absoluted physical address PcdVpdBaseAddress\r
   #  to store PCD value.\r