Revision: 15385
          http://sourceforge.net/p/edk2/code/15385
Author:   niruiyu
Date:     2014-03-25 02:38:54 +0000 (Tue, 25 Mar 2014)
Log Message:
-----------
Report the setting variable failure to platform through the status code when 
core cannot handle the error.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <[email protected]>
Reviewed-by: Jiewen Yao <[email protected]>

Modified Paths:
--------------
    trunk/edk2/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
    trunk/edk2/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c
    trunk/edk2/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c
    trunk/edk2/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf
    trunk/edk2/IntelFrameworkModulePkg/Library/GenericBdsLib/InternalBdsLib.h
    trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/Bds.h
    trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf
    trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c
    trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BBSsupport.c
    trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BmLib.c
    trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BootMaint.c
    trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/Variable.c
    trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c
    trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/Hotkey.c
    trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/Language.c
    trunk/edk2/MdeModulePkg/MdeModulePkg.dec

Added Paths:
-----------
    trunk/edk2/MdeModulePkg/Include/Guid/StatusCodeDataTypeVariable.h

Modified: trunk/edk2/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
===================================================================
--- trunk/edk2/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c  
2014-03-24 15:30:48 UTC (rev 15384)
+++ trunk/edk2/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c  
2014-03-25 02:38:54 UTC (rev 15385)
@@ -1,7 +1,7 @@
 /** @file
   BDS Lib functions which relate with create or process the boot option.
 
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
 which accompanies this distribution.  The full text of the license may be 
found at
@@ -82,6 +82,10 @@
                   0,
                   NULL
                   );
+  //
+  // Deleting variable with existing variable implementation shouldn't fail.
+  //
+  ASSERT_EFI_ERROR (Status);
 
   //
   // adjust boot order array
@@ -626,6 +630,10 @@
                   BootOrderSize,
                   BootOrder
                   );
+  //
+  // Shrinking variable with existing variable implementation shouldn't fail.
+  //
+  ASSERT_EFI_ERROR (Status);
   if (BootOrder != NULL) {
     FreePool (BootOrder);
   }
@@ -857,11 +865,10 @@
                 &BootOrder,
                 &BootOrderSize
                 );
-      if (EFI_ERROR (Status)) {
-        break;
+      if (!EFI_ERROR (Status)) {
+        BbsIndex     = Index;
+        OptionNumber = BootOrder[BootOrderSize / sizeof (UINT16) - 1];
       }
-      BbsIndex     = Index;
-      OptionNumber = BootOrder[BootOrderSize / sizeof (UINT16) - 1];
     }
 
     ASSERT (BbsIndex == Index);
@@ -2265,7 +2272,7 @@
     // In this case, "BootCurrent" is not created.
     // Only create the BootCurrent variable when it points to a valid Boot#### 
variable.
     //
-    gRT->SetVariable (
+    SetVariableAndReportStatusCodeOnError (
           L"BootCurrent",
           &gEfiGlobalVariableGuid,
           EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
@@ -2463,13 +2470,14 @@
 
   //
   // Clear Boot Current
+  // Deleting variable with current implementation shouldn't fail.
   //
   gRT->SetVariable (
         L"BootCurrent",
         &gEfiGlobalVariableGuid,
         EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
         0,
-        &Option->BootCurrent
+        NULL
         );
 
   return Status;
@@ -2580,6 +2588,7 @@
         FreePool (TempNewDevicePath);
         //
         // Save the matching Device Path so we don't need to do a connect all 
next time
+        // Failure to set the variable only impacts the performance when next 
time expanding the short-form device path.
         //
         Status = gRT->SetVariable (
                         HD_BOOT_DEVICE_PATH_VARIABLE_NAME,
@@ -2678,6 +2687,7 @@
 
       //
       // Save the matching Device Path so we don't need to do a connect all 
next time
+      // Failure to set the variable only impacts the performance when next 
time expanding the short-form device path.
       //
       Status = gRT->SetVariable (
                       HD_BOOT_DEVICE_PATH_VARIABLE_NAME,
@@ -2887,6 +2897,10 @@
                   BootOrderSize,
                   BootOrder
                   );
+  //
+  // Shrinking variable with existing variable implementation shouldn't fail.
+  //
+  ASSERT_EFI_ERROR (Status);
 
   FreePool (BootOrder);
 
@@ -2985,6 +2999,10 @@
                       NULL
                       );
       //
+      // Deleting variable with current variable implementation shouldn't fail.
+      //
+      ASSERT_EFI_ERROR (Status);
+      //
       // Mark this boot option in boot order as deleted
       //
       BootOrder[Index] = 0xffff;
@@ -3012,6 +3030,10 @@
                   Index2 * sizeof (UINT16),
                   BootOrder
                   );
+  //
+  // Shrinking variable with current variable implementation shouldn't fail.
+  //
+  ASSERT_EFI_ERROR (Status);
 
   FreePool (BootOrder);
 
@@ -3135,7 +3157,9 @@
         AsciiStrSize (PlatLang),
         PlatLang
         );
-      ASSERT_EFI_ERROR (Status);
+      //
+      // Failure to set the variable only impacts the performance next time 
enumerating the boot options.
+      //
 
       if (LastLang != NULL) {
         FreePool (LastLang);
@@ -3478,6 +3502,7 @@
   VOID
   )
 {
+  EFI_STATUS        Status;
   UINT16            *BootNext;
   UINTN             BootNextSize;
   CHAR16            Buffer[20];
@@ -3502,13 +3527,17 @@
   // Clear the boot next variable first
   //
   if (BootNext != NULL) {
-    gRT->SetVariable (
-          L"BootNext",
-          &gEfiGlobalVariableGuid,
-          EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | 
EFI_VARIABLE_NON_VOLATILE,
-          0,
-          BootNext
-          );
+    Status = gRT->SetVariable (
+                    L"BootNext",
+                    &gEfiGlobalVariableGuid,
+                    EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+                    0,
+                    NULL
+                    );
+    //
+    // Deleting variable with current variable implementation shouldn't fail.
+    //
+    ASSERT_EFI_ERROR (Status);
 
     //
     // Start to build the boot option and try to boot

Modified: trunk/edk2/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c
===================================================================
--- trunk/edk2/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c       
2014-03-24 15:30:48 UTC (rev 15384)
+++ trunk/edk2/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c       
2014-03-25 02:38:54 UTC (rev 15385)
@@ -1,7 +1,7 @@
 /** @file
   BDS Lib functions which contain all the code to connect console device
 
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
 which accompanies this distribution.  The full text of the license may be 
found at
@@ -285,17 +285,16 @@
   // Finally, Update the variable of the default console by NewDevicePath
   //
   DevicePathSize = GetDevicePathSize (NewDevicePath);
-  Status = gRT->SetVariable (
-                  ConVarName,
-                  &gEfiGlobalVariableGuid,
-                  Attributes,
-                  DevicePathSize,
-                  NewDevicePath
-                  );
+  Status = SetVariableAndReportStatusCodeOnError (
+             ConVarName,
+             &gEfiGlobalVariableGuid,
+             Attributes,
+             DevicePathSize,
+             NewDevicePath
+             );
   if ((DevicePathSize == 0) && (Status == EFI_NOT_FOUND)) {
     Status = EFI_SUCCESS;
   }
-  ASSERT_EFI_ERROR (Status);
 
   if (VarConsole == NewDevicePath) {
     if (VarConsole != NULL) {

Modified: trunk/edk2/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c
===================================================================
--- trunk/edk2/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c  
2014-03-24 15:30:48 UTC (rev 15384)
+++ trunk/edk2/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c  
2014-03-25 02:38:54 UTC (rev 15385)
@@ -1419,13 +1419,13 @@
   // Or create the variable in first boot.
   //
   if (MemoryTypeInformationModified || !MemoryTypeInformationVariableExists) {
-    Status = gRT->SetVariable (
-                    EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,
-                    &gEfiMemoryTypeInformationGuid,
-                    EFI_VARIABLE_NON_VOLATILE  | 
EFI_VARIABLE_BOOTSERVICE_ACCESS,
-                    VariableSize,
-                    PreviousMemoryTypeInformation
-                    );
+    Status = SetVariableAndReportStatusCodeOnError (
+               EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,
+               &gEfiMemoryTypeInformationGuid,
+               EFI_VARIABLE_NON_VOLATILE  | EFI_VARIABLE_BOOTSERVICE_ACCESS,
+               VariableSize,
+               PreviousMemoryTypeInformation
+               );
 
     if (!EFI_ERROR (Status)) {
       //
@@ -1486,3 +1486,87 @@
   return Manager->Identify (Manager, User);
 }
 
+/**
+  Set the variable and report the error through status code upon failure.
+
+  @param  VariableName           A Null-terminated string that is the name of 
the vendor's variable.
+                                 Each VariableName is unique for each 
VendorGuid. VariableName must
+                                 contain 1 or more characters. If VariableName 
is an empty string,
+                                 then EFI_INVALID_PARAMETER is returned.
+  @param  VendorGuid             A unique identifier for the vendor.
+  @param  Attributes             Attributes bitmask to set for the variable.
+  @param  DataSize               The size in bytes of the Data buffer. Unless 
the EFI_VARIABLE_APPEND_WRITE, 
+                                 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or 
+                                 
EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of 
zero 
+                                 causes the variable to be deleted. When the 
EFI_VARIABLE_APPEND_WRITE attribute is 
+                                 set, then a SetVariable() call with a 
DataSize of zero will not cause any change to 
+                                 the variable value (the timestamp associated 
with the variable may be updated however 
+                                 even if no new data value is provided,see the 
description of the 
+                                 EFI_VARIABLE_AUTHENTICATION_2 descriptor 
below. In this case the DataSize will not 
+                                 be zero since the 
EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated). 
+  @param  Data                   The contents for the variable.
+
+  @retval EFI_SUCCESS            The firmware has successfully stored the 
variable and its data as
+                                 defined by the Attributes.
+  @retval EFI_INVALID_PARAMETER  An invalid combination of attribute bits, 
name, and GUID was supplied, or the
+                                 DataSize exceeds the maximum allowed.
+  @retval EFI_INVALID_PARAMETER  VariableName is an empty string.
+  @retval EFI_OUT_OF_RESOURCES   Not enough storage is available to hold the 
variable and its data.
+  @retval EFI_DEVICE_ERROR       The variable could not be retrieved due to a 
hardware error.
+  @retval EFI_WRITE_PROTECTED    The variable in question is read-only.
+  @retval EFI_WRITE_PROTECTED    The variable in question cannot be deleted.
+  @retval EFI_SECURITY_VIOLATION The variable could not be written due to 
EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 
+                                 or 
EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo 
+                                 does NOT pass the validation check carried 
out by the firmware.
+
+  @retval EFI_NOT_FOUND          The variable trying to be updated or deleted 
was not found.
+**/
+EFI_STATUS
+SetVariableAndReportStatusCodeOnError (
+  IN CHAR16     *VariableName,
+  IN EFI_GUID   *VendorGuid,
+  IN UINT32     Attributes,
+  IN UINTN      DataSize,
+  IN VOID       *Data
+  )
+{
+  EFI_STATUS                 Status;
+  EDKII_SET_VARIABLE_STATUS  *SetVariableStatus;
+  UINTN                      NameSize;
+
+  Status = gRT->SetVariable (
+                  VariableName,
+                  VendorGuid,
+                  Attributes,
+                  DataSize,
+                  Data
+                  );
+  if (EFI_ERROR (Status)) {
+    NameSize = StrSize (VariableName);
+    SetVariableStatus = AllocatePool (sizeof (EDKII_SET_VARIABLE_STATUS) + 
NameSize + DataSize);
+    if (SetVariableStatus != NULL) {
+      CopyGuid (&SetVariableStatus->Guid, VendorGuid);
+      SetVariableStatus->NameSize   = NameSize;
+      SetVariableStatus->DataSize   = DataSize;
+      SetVariableStatus->SetStatus  = Status;
+      SetVariableStatus->Attributes = Attributes;
+      CopyMem (SetVariableStatus + 1,                          VariableName, 
NameSize);
+      CopyMem (((UINT8 *) (SetVariableStatus + 1)) + NameSize, Data,         
DataSize);
+
+      REPORT_STATUS_CODE_EX (
+        EFI_ERROR_CODE,
+        PcdGet32 (PcdErrorCodeSetVariable),
+        0,
+        NULL,
+        &gEdkiiStatusCodeDataTypeVariableGuid,
+        SetVariableStatus,
+        sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + DataSize
+        );
+
+      FreePool (SetVariableStatus);
+    }
+  }
+
+  return Status;
+}
+

Modified: 
trunk/edk2/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf
===================================================================
--- trunk/edk2/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf  
2014-03-24 15:30:48 UTC (rev 15384)
+++ trunk/edk2/IntelFrameworkModulePkg/Library/GenericBdsLib/GenericBdsLib.inf  
2014-03-25 02:38:54 UTC (rev 15385)
@@ -5,7 +5,7 @@
 #  2) BDS boot device connect interface;
 #  3) BDS Misc interfaces for mainting boot variable, ouput string, etc.
 #  
-#  Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD 
License
 #  which accompanies this distribution.  The full text of the license may be 
found at
@@ -79,6 +79,7 @@
   gHdBootDevicePathVariablGuid                  ## SOMETIMES_PRODUCES ## 
Variable:L"HDDP" (The device path of Boot file on Hard device.)
   gBdsLibStringPackageGuid                      ## PRODUCES ## GUID (HII 
String PackageList Guid)
   gEfiLegacyDevOrderVariableGuid                ## CONSUMES ## GUID
+  gEdkiiStatusCodeDataTypeVariableGuid          ## SOMETIMES_CONSUMES
 
 [Protocols]
   gEfiSimpleFileSystemProtocolGuid              # PROTOCOL CONSUMES
@@ -111,4 +112,5 @@
   gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange
   gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderLoad
   gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderStart
+  gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable
   gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile

Modified: 
trunk/edk2/IntelFrameworkModulePkg/Library/GenericBdsLib/InternalBdsLib.h
===================================================================
--- trunk/edk2/IntelFrameworkModulePkg/Library/GenericBdsLib/InternalBdsLib.h   
2014-03-24 15:30:48 UTC (rev 15384)
+++ trunk/edk2/IntelFrameworkModulePkg/Library/GenericBdsLib/InternalBdsLib.h   
2014-03-25 02:38:54 UTC (rev 15385)
@@ -1,7 +1,7 @@
 /** @file
   BDS library definition, include the file and data structure
 
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
 which accompanies this distribution.  The full text of the license may be 
found at
@@ -51,6 +51,7 @@
 #include <Guid/HdBootVariable.h>
 #include <Guid/LastEnumLang.h>
 #include <Guid/LegacyDevOrder.h>
+#include <Guid/StatusCodeDataTypeVariable.h>
 
 #include <Library/PrintLib.h>
 #include <Library/DebugLib.h>
@@ -147,4 +148,48 @@
   UINTN                     VariableSize
   );
 
+/**
+  Set the variable and report the error through status code upon failure.
+
+  @param  VariableName           A Null-terminated string that is the name of 
the vendor's variable.
+                                 Each VariableName is unique for each 
VendorGuid. VariableName must
+                                 contain 1 or more characters. If VariableName 
is an empty string,
+                                 then EFI_INVALID_PARAMETER is returned.
+  @param  VendorGuid             A unique identifier for the vendor.
+  @param  Attributes             Attributes bitmask to set for the variable.
+  @param  DataSize               The size in bytes of the Data buffer. Unless 
the EFI_VARIABLE_APPEND_WRITE, 
+                                 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or 
+                                 
EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of 
zero 
+                                 causes the variable to be deleted. When the 
EFI_VARIABLE_APPEND_WRITE attribute is 
+                                 set, then a SetVariable() call with a 
DataSize of zero will not cause any change to 
+                                 the variable value (the timestamp associated 
with the variable may be updated however 
+                                 even if no new data value is provided,see the 
description of the 
+                                 EFI_VARIABLE_AUTHENTICATION_2 descriptor 
below. In this case the DataSize will not 
+                                 be zero since the 
EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated). 
+  @param  Data                   The contents for the variable.
+
+  @retval EFI_SUCCESS            The firmware has successfully stored the 
variable and its data as
+                                 defined by the Attributes.
+  @retval EFI_INVALID_PARAMETER  An invalid combination of attribute bits, 
name, and GUID was supplied, or the
+                                 DataSize exceeds the maximum allowed.
+  @retval EFI_INVALID_PARAMETER  VariableName is an empty string.
+  @retval EFI_OUT_OF_RESOURCES   Not enough storage is available to hold the 
variable and its data.
+  @retval EFI_DEVICE_ERROR       The variable could not be retrieved due to a 
hardware error.
+  @retval EFI_WRITE_PROTECTED    The variable in question is read-only.
+  @retval EFI_WRITE_PROTECTED    The variable in question cannot be deleted.
+  @retval EFI_SECURITY_VIOLATION The variable could not be written due to 
EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 
+                                 or 
EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo 
+                                 does NOT pass the validation check carried 
out by the firmware.
+
+  @retval EFI_NOT_FOUND          The variable trying to be updated or deleted 
was not found.
+**/
+EFI_STATUS
+SetVariableAndReportStatusCodeOnError (
+  IN CHAR16     *VariableName,
+  IN EFI_GUID   *VendorGuid,
+  IN UINT32     Attributes,
+  IN UINTN      DataSize,
+  IN VOID       *Data
+  );
+
 #endif // _BDS_LIB_H_

Modified: trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/Bds.h
===================================================================
--- trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/Bds.h   2014-03-24 
15:30:48 UTC (rev 15384)
+++ trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/Bds.h   2014-03-25 
02:38:54 UTC (rev 15385)
@@ -1,7 +1,7 @@
 /** @file
   Head file for BDS Architectural Protocol implementation
 
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
 which accompanies this distribution.  The full text of the license may be 
found at
@@ -20,6 +20,7 @@
 #include <Guid/MdeModuleHii.h>
 #include <Guid/FileSystemVolumeLabelInfo.h>
 #include <Guid/HiiPlatformSetupFormset.h>
+#include <Guid/StatusCodeDataTypeVariable.h>
 #include <Protocol/DevicePath.h>
 #include <IndustryStandard/SmBios.h>
 #include <Protocol/LoadFile.h>
@@ -189,4 +190,48 @@
   EFI_BOOT_MODE BootMode
   );
 
+/**
+  Set the variable and report the error through status code upon failure.
+
+  @param  VariableName           A Null-terminated string that is the name of 
the vendor's variable.
+                                 Each VariableName is unique for each 
VendorGuid. VariableName must
+                                 contain 1 or more characters. If VariableName 
is an empty string,
+                                 then EFI_INVALID_PARAMETER is returned.
+  @param  VendorGuid             A unique identifier for the vendor.
+  @param  Attributes             Attributes bitmask to set for the variable.
+  @param  DataSize               The size in bytes of the Data buffer. Unless 
the EFI_VARIABLE_APPEND_WRITE, 
+                                 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or 
+                                 
EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of 
zero 
+                                 causes the variable to be deleted. When the 
EFI_VARIABLE_APPEND_WRITE attribute is 
+                                 set, then a SetVariable() call with a 
DataSize of zero will not cause any change to 
+                                 the variable value (the timestamp associated 
with the variable may be updated however 
+                                 even if no new data value is provided,see the 
description of the 
+                                 EFI_VARIABLE_AUTHENTICATION_2 descriptor 
below. In this case the DataSize will not 
+                                 be zero since the 
EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated). 
+  @param  Data                   The contents for the variable.
+
+  @retval EFI_SUCCESS            The firmware has successfully stored the 
variable and its data as
+                                 defined by the Attributes.
+  @retval EFI_INVALID_PARAMETER  An invalid combination of attribute bits, 
name, and GUID was supplied, or the
+                                 DataSize exceeds the maximum allowed.
+  @retval EFI_INVALID_PARAMETER  VariableName is an empty string.
+  @retval EFI_OUT_OF_RESOURCES   Not enough storage is available to hold the 
variable and its data.
+  @retval EFI_DEVICE_ERROR       The variable could not be retrieved due to a 
hardware error.
+  @retval EFI_WRITE_PROTECTED    The variable in question is read-only.
+  @retval EFI_WRITE_PROTECTED    The variable in question cannot be deleted.
+  @retval EFI_SECURITY_VIOLATION The variable could not be written due to 
EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 
+                                 or 
EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo 
+                                 does NOT pass the validation check carried 
out by the firmware.
+
+  @retval EFI_NOT_FOUND          The variable trying to be updated or deleted 
was not found.
+**/
+EFI_STATUS
+BdsDxeSetVariableAndReportStatusCodeOnError (
+  IN CHAR16     *VariableName,
+  IN EFI_GUID   *VendorGuid,
+  IN UINT32     Attributes,
+  IN UINTN      DataSize,
+  IN VOID       *Data
+  );
+
 #endif

Modified: trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf
===================================================================
--- trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf      
2014-03-24 15:30:48 UTC (rev 15384)
+++ trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/BdsDxe.inf      
2014-03-25 02:38:54 UTC (rev 15385)
@@ -14,7 +14,7 @@
 #  BDSDxe also maintain the UI for "Boot Manager, Boot Maintaince Manager, 
Device Manager" which
 #  is used for user to configure boot option or maintain hardware device.
 #  
-#  Copyright (c) 2008 - 2013, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR>
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD 
License
 #  which accompanies this distribution.  The full text of the license may be 
found at
@@ -142,6 +142,7 @@
   gDriverHealthFormSetGuid                      ## SOMETIMES_PRODUCES ## 
DriverHealth HII Package
   gConnectConInEventGuid                        ## CONSUMES ## GUID (Connect 
ConIn Event)
   gEfiFmpCapsuleGuid                            ## CONSUMES ## GUID (FMP 
Capsule)
+  gEdkiiStatusCodeDataTypeVariableGuid          ## SOMETIMES_CONSUMES
 
 [Protocols]
   gEfiSimpleFileSystemProtocolGuid              ## PROTOCOL CONSUMES
@@ -188,6 +189,7 @@
   gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdSetupVideoHorizontalResolution
   gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdSetupVideoVerticalResolution
   gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile
+  gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable
 
 [Depex]
   TRUE

Modified: trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c
===================================================================
--- trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c      
2014-03-24 15:30:48 UTC (rev 15384)
+++ trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c      
2014-03-25 02:38:54 UTC (rev 15385)
@@ -5,7 +5,7 @@
   After DxeCore finish DXE phase, gEfiBdsArchProtocolGuid->BdsEntry will be 
invoked
   to enter BDS phase.
 
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
 which accompanies this distribution.  The full text of the license may be 
found at
@@ -164,13 +164,17 @@
     //
     // Clear the this variable so it's only exist in this time boot
     //
-    gRT->SetVariable (
-          L"BootNext",
-          &gEfiGlobalVariableGuid,
-          EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | 
EFI_VARIABLE_NON_VOLATILE,
-          0,
-          mBootNext
-          );
+    Status = gRT->SetVariable (
+                    L"BootNext",
+                    &gEfiGlobalVariableGuid,
+                    EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+                    0,
+                    NULL
+                    );
+    //
+    // Deleting variable with current variable implementation shouldn't fail.
+    //
+    ASSERT_EFI_ERROR (Status);
 
     //
     // Add the boot next boot option
@@ -368,6 +372,9 @@
                     0,
                     NULL
                     );
+    //
+    // Deleting variable with current variable implementation shouldn't fail.
+    //
     ASSERT_EFI_ERROR (Status);
   }
 }
@@ -406,14 +413,13 @@
   OsIndicationSupport = EFI_OS_INDICATIONS_BOOT_TO_FW_UI \
                       | EFI_OS_INDICATIONS_FMP_CAPSULE_SUPPORTED;
 
-  Status = gRT->SetVariable (
-                  L"OsIndicationsSupported",
-                  &gEfiGlobalVariableGuid,
-                  EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS,
-                  sizeof(UINT64),
-                  &OsIndicationSupport
-                  );
-  ASSERT_EFI_ERROR (Status);
+  BdsDxeSetVariableAndReportStatusCodeOnError (
+    L"OsIndicationsSupported",
+    &gEfiGlobalVariableGuid,
+    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
+    sizeof(UINT64),
+    &OsIndicationSupport
+    );
 
   //
   // If OsIndications is invalid, remove it.
@@ -442,10 +448,13 @@
       Status = gRT->SetVariable (
                       L"OsIndications",
                       &gEfiGlobalVariableGuid,
-                      Attributes,
                       0,
-                      &OsIndication
+                      0,
+                      NULL
                       );
+      //
+      // Deleting variable with current variable implementation shouldn't fail.
+      //
       ASSERT_EFI_ERROR (Status);
     }
   }
@@ -481,16 +490,19 @@
     //
     // Save the pointer to variable for use in S3 resume.
     //
-    Status = gRT->SetVariable (
-               L"PerfDataMemAddr",
-               &gPerformanceProtocolGuid,
-               EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS,
-               sizeof (EFI_PHYSICAL_ADDRESS),
-               &AcpiLowMemoryBase
-               );
-    ASSERT_EFI_ERROR (Status);
+    BdsDxeSetVariableAndReportStatusCodeOnError (
+      L"PerfDataMemAddr",
+      &gPerformanceProtocolGuid,
+      EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS,
+      sizeof (EFI_PHYSICAL_ADDRESS),
+      &AcpiLowMemoryBase
+      );
+    if (EFI_ERROR (Status)) {
+      DEBUG ((EFI_D_ERROR, "[Bds] PerfDataMemAddr (%08x) cannot be saved to NV 
storage.\n", AcpiLowMemoryBase));
+    }
     //
     // Mark L"PerfDataMemAddr" variable to read-only if the Variable Lock 
protocol exists
+    // Still lock it even the variable cannot be saved to prevent it's set by 
3rd party code.
     //
     Status = gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (VOID 
**) &VariableLock);
     if (!EFI_ERROR (Status)) {
@@ -594,14 +606,13 @@
     // If time out value equal 0xFFFF, no need set to 0xFFFF to variable area 
because UEFI specification
     // define same behavior between no value or 0xFFFF value for L"Timeout".
     //
-    Status = gRT->SetVariable (
+    BdsDxeSetVariableAndReportStatusCodeOnError (
                     L"Timeout",
                     &gEfiGlobalVariableGuid,
                     EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
                     sizeof (UINT16),
                     &BootTimeOut
                     );
-    ASSERT_EFI_ERROR(Status);
   }
 
   //
@@ -655,3 +666,89 @@
 
   return ;
 }
+
+
+/**
+  Set the variable and report the error through status code upon failure.
+
+  @param  VariableName           A Null-terminated string that is the name of 
the vendor's variable.
+                                 Each VariableName is unique for each 
VendorGuid. VariableName must
+                                 contain 1 or more characters. If VariableName 
is an empty string,
+                                 then EFI_INVALID_PARAMETER is returned.
+  @param  VendorGuid             A unique identifier for the vendor.
+  @param  Attributes             Attributes bitmask to set for the variable.
+  @param  DataSize               The size in bytes of the Data buffer. Unless 
the EFI_VARIABLE_APPEND_WRITE, 
+                                 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or 
+                                 
EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of 
zero 
+                                 causes the variable to be deleted. When the 
EFI_VARIABLE_APPEND_WRITE attribute is 
+                                 set, then a SetVariable() call with a 
DataSize of zero will not cause any change to 
+                                 the variable value (the timestamp associated 
with the variable may be updated however 
+                                 even if no new data value is provided,see the 
description of the 
+                                 EFI_VARIABLE_AUTHENTICATION_2 descriptor 
below. In this case the DataSize will not 
+                                 be zero since the 
EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated). 
+  @param  Data                   The contents for the variable.
+
+  @retval EFI_SUCCESS            The firmware has successfully stored the 
variable and its data as
+                                 defined by the Attributes.
+  @retval EFI_INVALID_PARAMETER  An invalid combination of attribute bits, 
name, and GUID was supplied, or the
+                                 DataSize exceeds the maximum allowed.
+  @retval EFI_INVALID_PARAMETER  VariableName is an empty string.
+  @retval EFI_OUT_OF_RESOURCES   Not enough storage is available to hold the 
variable and its data.
+  @retval EFI_DEVICE_ERROR       The variable could not be retrieved due to a 
hardware error.
+  @retval EFI_WRITE_PROTECTED    The variable in question is read-only.
+  @retval EFI_WRITE_PROTECTED    The variable in question cannot be deleted.
+  @retval EFI_SECURITY_VIOLATION The variable could not be written due to 
EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 
+                                 or 
EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo 
+                                 does NOT pass the validation check carried 
out by the firmware.
+
+  @retval EFI_NOT_FOUND          The variable trying to be updated or deleted 
was not found.
+**/
+EFI_STATUS
+BdsDxeSetVariableAndReportStatusCodeOnError (
+  IN CHAR16     *VariableName,
+  IN EFI_GUID   *VendorGuid,
+  IN UINT32     Attributes,
+  IN UINTN      DataSize,
+  IN VOID       *Data
+  )
+{
+  EFI_STATUS                 Status;
+  EDKII_SET_VARIABLE_STATUS  *SetVariableStatus;
+  UINTN                      NameSize;
+
+  Status = gRT->SetVariable (
+                  VariableName,
+                  VendorGuid,
+                  Attributes,
+                  DataSize,
+                  Data
+                  );
+  if (EFI_ERROR (Status)) {
+    NameSize = StrSize (VariableName);
+    SetVariableStatus = AllocatePool (sizeof (EDKII_SET_VARIABLE_STATUS) + 
NameSize + DataSize);
+    if (SetVariableStatus != NULL) {
+      CopyGuid (&SetVariableStatus->Guid, VendorGuid);
+      SetVariableStatus->NameSize   = NameSize;
+      SetVariableStatus->DataSize   = DataSize;
+      SetVariableStatus->SetStatus  = Status;
+      SetVariableStatus->Attributes = Attributes;
+      CopyMem (SetVariableStatus + 1,                          VariableName, 
NameSize);
+      CopyMem (((UINT8 *) (SetVariableStatus + 1)) + NameSize, Data,         
DataSize);
+
+      REPORT_STATUS_CODE_EX (
+        EFI_ERROR_CODE,
+        PcdGet32 (PcdErrorCodeSetVariable),
+        0,
+        NULL,
+        &gEdkiiStatusCodeDataTypeVariableGuid,
+        SetVariableStatus,
+        sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + DataSize
+        );
+
+      FreePool (SetVariableStatus);
+    }
+  }
+
+  return Status;
+}
+

Modified: 
trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BBSsupport.c
===================================================================
--- trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BBSsupport.c  
2014-03-24 15:30:48 UTC (rev 15384)
+++ trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BBSsupport.c  
2014-03-25 02:38:54 UTC (rev 15385)
@@ -3,7 +3,7 @@
   and manage the legacy boot option, all legacy boot option is getting from
   the legacy BBS table.
 
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
 which accompanies this distribution.  The full text of the license may be 
found at
@@ -143,6 +143,9 @@
                   BootOrderSize,
                   BootOrder
                   );
+  //
+  // Changing content without increasing its size with current variable 
implementation shouldn't fail.
+  //
   ASSERT_EFI_ERROR (Status);
 
   FreePool (NewBootOption);
@@ -171,6 +174,7 @@
   VOID
   )
 {
+  EFI_STATUS                   Status;
   UINTN                        Index;
   UINTN                        DeviceIndex;
   UINTN                        DeviceTypeIndex[7];
@@ -233,13 +237,17 @@
     FreePool (BootOption);
   }
 
-  gRT->SetVariable (
-         L"BootOrder",
-         &gEfiGlobalVariableGuid,
-         EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | 
EFI_VARIABLE_NON_VOLATILE,
-         BootOrderSize,
-         BootOrder
-         );
+  Status = gRT->SetVariable (
+                  L"BootOrder",
+                  &gEfiGlobalVariableGuid,
+                  EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+                  BootOrderSize,
+                  BootOrder
+                  );
+  //
+  // Changing content without increasing its size with current variable 
implementation shouldn't fail.
+  //
+  ASSERT_EFI_ERROR (Status);
   FreePool (BootOrder);
 }
 

Modified: trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BmLib.c
===================================================================
--- trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BmLib.c       
2014-03-24 15:30:48 UTC (rev 15384)
+++ trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BmLib.c       
2014-03-25 02:38:54 UTC (rev 15385)
@@ -1,7 +1,7 @@
 /** @file
   Utility routines used by boot maintenance modules.
 
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
 which accompanies this distribution.  The full text of the license may be 
found at
@@ -178,7 +178,10 @@
                     0,
                     NULL
                     );
-    ASSERT (!EFI_ERROR (Status));
+    //
+    // Deleting variable with current variable implementation shouldn't fail.
+    //
+    ASSERT_EFI_ERROR (Status);
     FreePool (VarBuf);
   }
 

Modified: 
trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BootMaint.c
===================================================================
--- trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BootMaint.c   
2014-03-24 15:30:48 UTC (rev 15384)
+++ trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/BootMaint.c   
2014-03-25 02:38:54 UTC (rev 15385)
@@ -1,7 +1,7 @@
 /** @file
   The functions for Boot Maintainence Main menu.
 
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
 which accompanies this distribution.  The full text of the license may be 
found at
@@ -672,14 +672,13 @@
     break;
 
   case FORM_TIME_OUT_ID:
-    Status = gRT->SetVariable (
-                    L"Timeout",
-                    &gEfiGlobalVariableGuid,
-                    EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
-                    sizeof (UINT16),
-                    &(CurrentFakeNVMap->BootTimeOut)
-                    );
-    ASSERT_EFI_ERROR(Status);
+    BdsDxeSetVariableAndReportStatusCodeOnError (
+      L"Timeout",
+      &gEfiGlobalVariableGuid,
+      EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | 
EFI_VARIABLE_NON_VOLATILE,
+      sizeof (UINT16),
+      &(CurrentFakeNVMap->BootTimeOut)
+      );
 
     Private->BmmOldFakeNVData.BootTimeOut = CurrentFakeNVMap->BootTimeOut;
     break;

Modified: 
trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/Variable.c
===================================================================
--- trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/Variable.c    
2014-03-24 15:30:48 UTC (rev 15384)
+++ trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/BootMaint/Variable.c    
2014-03-25 02:38:54 UTC (rev 15385)
@@ -1,7 +1,7 @@
 /** @file
   Variable operation that will be used by bootmaint
 
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
 which accompanies this distribution.  The full text of the license may be 
found at
@@ -165,9 +165,10 @@
                     BootOrderListSize * sizeof (UINT16),
                     BootOrderList
                     );
-    if (EFI_ERROR (Status)) {
-      return Status;
-    }
+    //
+    // Changing variable without increasing its size with current variable 
implementation shouldn't fail.
+    //
+    ASSERT_EFI_ERROR (Status);
   }
   return EFI_SUCCESS;
 }
@@ -303,9 +304,10 @@
                     DriverOrderListSize * sizeof (UINT16),
                     DriverOrderList
                     );
-    if (EFI_ERROR (Status)) {
-      return Status;
-    }
+    //
+    // Changing variable without increasing its size with current variable 
implementation shouldn't fail.
+    //
+    ASSERT_EFI_ERROR (Status);
   }
   return EFI_SUCCESS;
 }
@@ -338,7 +340,10 @@
                     GetDevicePathSize (OutDevicePath),
                     OutDevicePath
                     );
-    ASSERT (!EFI_ERROR (Status));
+    //
+    // Changing variable without increasing its size with current variable 
implementation shouldn't fail.
+    //
+    ASSERT_EFI_ERROR (Status);
   }
 
   if (InpDevicePath != NULL) {
@@ -350,7 +355,10 @@
                     GetDevicePathSize (InpDevicePath),
                     InpDevicePath
                     );
-    ASSERT (!EFI_ERROR (Status));
+    //
+    // Changing variable without increasing its size with current variable 
implementation shouldn't fail.
+    //
+    ASSERT_EFI_ERROR (Status);
   }
 
   if (ErrDevicePath != NULL) {
@@ -362,7 +370,10 @@
                     GetDevicePathSize (ErrDevicePath),
                     ErrDevicePath
                     );
-    ASSERT (!EFI_ERROR (Status));
+    //
+    // Changing variable without increasing its size with current variable 
implementation shouldn't fail.
+    //
+    ASSERT_EFI_ERROR (Status);
   }
 }
 
@@ -667,38 +678,40 @@
                   BufferSize,
                   Buffer
                   );
-  ASSERT_EFI_ERROR (Status);
-  DriverOrderList = BdsLibGetVariableAndSize (
-                      L"DriverOrder",
-                      &gEfiGlobalVariableGuid,
-                      &DriverOrderListSize
-                      );
-  NewDriverOrderList = AllocateZeroPool (DriverOrderListSize + sizeof 
(UINT16));
-  ASSERT (NewDriverOrderList != NULL);
-  if (DriverOrderList != NULL) {
-    CopyMem (NewDriverOrderList, DriverOrderList, DriverOrderListSize);
-    EfiLibDeleteVariable (L"DriverOrder", &gEfiGlobalVariableGuid);
-  }
-  NewDriverOrderList[DriverOrderListSize / sizeof (UINT16)] = Index;
+  if (!EFI_ERROR (Status)) {
+    DriverOrderList = BdsLibGetVariableAndSize (
+                        L"DriverOrder",
+                        &gEfiGlobalVariableGuid,
+                        &DriverOrderListSize
+                        );
+    NewDriverOrderList = AllocateZeroPool (DriverOrderListSize + sizeof 
(UINT16));
+    ASSERT (NewDriverOrderList != NULL);
+    if (DriverOrderList != NULL) {
+      CopyMem (NewDriverOrderList, DriverOrderList, DriverOrderListSize);
+      EfiLibDeleteVariable (L"DriverOrder", &gEfiGlobalVariableGuid);
+    }
+    NewDriverOrderList[DriverOrderListSize / sizeof (UINT16)] = Index;
 
-  Status = gRT->SetVariable (
-                  L"DriverOrder",
-                  &gEfiGlobalVariableGuid,
-                  EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
-                  DriverOrderListSize + sizeof (UINT16),
-                  NewDriverOrderList
-                  );
-  ASSERT_EFI_ERROR (Status);
-  if (DriverOrderList != NULL) {
-    FreePool (DriverOrderList);
+    Status = gRT->SetVariable (
+                    L"DriverOrder",
+                    &gEfiGlobalVariableGuid,
+                    EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+                    DriverOrderListSize + sizeof (UINT16),
+                    NewDriverOrderList
+                    );
+    if (DriverOrderList != NULL) {
+      FreePool (DriverOrderList);
+    }
+    DriverOrderList = NULL;
+    FreePool (NewDriverOrderList);
+    if (!EFI_ERROR (Status)) {
+      InsertTailList (&DriverOptionMenu.Head, &NewMenuEntry->Link);
+      DriverOptionMenu.MenuNumber++;
+
+      *DescriptionData  = 0x0000;
+      *OptionalData     = 0x0000;
+    }
   }
-  DriverOrderList = NULL;
-  FreePool (NewDriverOrderList);
-  InsertTailList (&DriverOptionMenu.Head, &NewMenuEntry->Link);
-  DriverOptionMenu.MenuNumber++;
-
-  *DescriptionData  = 0x0000;
-  *OptionalData     = 0x0000;
   return EFI_SUCCESS;
 }
 
@@ -835,39 +848,41 @@
                   BufferSize,
                   Buffer
                   );
-  ASSERT_EFI_ERROR (Status);
+  if (!EFI_ERROR (Status)) {
 
-  BootOrderList = BdsLibGetVariableAndSize (
+    BootOrderList = BdsLibGetVariableAndSize (
+                      L"BootOrder",
+                      &gEfiGlobalVariableGuid,
+                      &BootOrderListSize
+                      );
+    ASSERT (BootOrderList != NULL);
+    NewBootOrderList = AllocateZeroPool (BootOrderListSize + sizeof (UINT16));
+    ASSERT (NewBootOrderList != NULL);
+    CopyMem (NewBootOrderList, BootOrderList, BootOrderListSize);
+    NewBootOrderList[BootOrderListSize / sizeof (UINT16)] = Index;
+
+    if (BootOrderList != NULL) {
+      FreePool (BootOrderList);
+    }
+
+    Status = gRT->SetVariable (
                     L"BootOrder",
                     &gEfiGlobalVariableGuid,
-                    &BootOrderListSize
+                    EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+                    BootOrderListSize + sizeof (UINT16),
+                    NewBootOrderList
                     );
-  ASSERT (BootOrderList != NULL);
-  NewBootOrderList = AllocateZeroPool (BootOrderListSize + sizeof (UINT16));
-  ASSERT (NewBootOrderList != NULL);
-  CopyMem (NewBootOrderList, BootOrderList, BootOrderListSize);
-  NewBootOrderList[BootOrderListSize / sizeof (UINT16)] = Index;
+    if (!EFI_ERROR (Status)) {
 
-  if (BootOrderList != NULL) {
-    FreePool (BootOrderList);
+      FreePool (NewBootOrderList);
+      NewBootOrderList = NULL;
+      InsertTailList (&BootOptionMenu.Head, &NewMenuEntry->Link);
+      BootOptionMenu.MenuNumber++;
+
+      NvRamMap->DescriptionData[0]  = 0x0000;
+      NvRamMap->OptionalData[0]     = 0x0000;
+    }
   }
-
-  Status = gRT->SetVariable (
-                  L"BootOrder",
-                  &gEfiGlobalVariableGuid,
-                  EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
-                  BootOrderListSize + sizeof (UINT16),
-                  NewBootOrderList
-                  );
-  ASSERT_EFI_ERROR (Status);
-
-  FreePool (NewBootOrderList);
-  NewBootOrderList = NULL;
-  InsertTailList (&BootOptionMenu.Head, &NewMenuEntry->Link);
-  BootOptionMenu.MenuNumber++;
-
-  NvRamMap->DescriptionData[0]  = 0x0000;
-  NvRamMap->OptionalData[0]     = 0x0000;
   return EFI_SUCCESS;
 }
 
@@ -987,6 +1002,10 @@
                   BootOrderListSize,
                   BootOrderList
                   );
+  //
+  // Changing the content without increasing its size with current variable 
implementation shouldn't fail.
+  //
+  ASSERT_EFI_ERROR (Status);
   FreePool (BootOrderList);
 
   GroupMultipleLegacyBootOption4SameType ();
@@ -1058,10 +1077,11 @@
                   DriverOrderListSize,
                   NewDriverOrderList
                   );
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
-
+  //
+  // Changing the content without increasing its size with current variable 
implementation shouldn't fail.
+  //
+  ASSERT_EFI_ERROR (Status);
+  
   BOpt_FreeMenu (&DriverOptionMenu);
   BOpt_GetDriverOptions (CallbackData);
   return EFI_SUCCESS;
@@ -1258,6 +1278,10 @@
                       OptionSize,
                       BootOptionVar
                       );
+      //
+      // Changing the content without increasing its size with current 
variable implementation shouldn't fail.
+      //
+      ASSERT_EFI_ERROR (Status);
 
       FreePool (BootOptionVar);
     }
@@ -1281,6 +1305,10 @@
                       OptionSize,
                       BootOptionVar
                       );
+      //
+      // Changing the content without increasing its size with current 
variable implementation shouldn't fail.
+      //
+      ASSERT_EFI_ERROR (Status);
 
       FreePool (BootOptionVar);
     }

Modified: trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c
===================================================================
--- trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c     
2014-03-24 15:30:48 UTC (rev 15384)
+++ trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/FrontPage.c     
2014-03-25 02:38:54 UTC (rev 15385)
@@ -1,7 +1,7 @@
 /** @file
   FrontPage routines to handle the callbacks and browser calls
 
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
 which accompanies this distribution.  The full text of the license may be 
found at
@@ -182,7 +182,6 @@
   CHAR8                         *LangCode;
   CHAR8                         *Lang;
   UINTN                         Index;
-  EFI_STATUS                    Status;
 
   if (Action != EFI_BROWSER_ACTION_CHANGING && Action != 
EFI_BROWSER_ACTION_CHANGED) {
     //
@@ -226,14 +225,13 @@
       }
 
       if (Index == Value->u8) {
-        Status = gRT->SetVariable (
+        BdsDxeSetVariableAndReportStatusCodeOnError (
                         L"PlatformLang",
                         &gEfiGlobalVariableGuid,
                         EFI_VARIABLE_NON_VOLATILE | 
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
                         AsciiStrSize (Lang),
                         Lang
                         );
-        ASSERT_EFI_ERROR(Status);
       } else {
         ASSERT (FALSE);
       }
@@ -1095,6 +1093,9 @@
                     sizeof(UINT64),
                     &OsIndication
                     );
+    //
+    // Changing the content without increasing its size with current variable 
implementation shouldn't fail.
+    //
     ASSERT_EFI_ERROR (Status);
 
     //

Modified: trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/Hotkey.c
===================================================================
--- trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/Hotkey.c        
2014-03-24 15:30:48 UTC (rev 15384)
+++ trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/Hotkey.c        
2014-03-25 02:38:54 UTC (rev 15385)
@@ -2,7 +2,7 @@
   Provides a way for 3rd party applications to register themselves for launch 
by the
   Boot Manager based on hot key
 
-Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
 which accompanies this distribution.  The full text of the license may be 
found at
@@ -550,6 +550,9 @@
                   sizeof (UINT32),
                   &BootOptionSupport
                   );
+  //
+  // Platform needs to make sure setting volatile variable before calling 3rd 
party code shouldn't fail.
+  //
   ASSERT_EFI_ERROR (Status);
 
   KeyOptionNumbers = HotkeyGetOptionNumbers (&KeyOptionCount);

Modified: trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/Language.c
===================================================================
--- trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/Language.c      
2014-03-24 15:30:48 UTC (rev 15384)
+++ trunk/edk2/IntelFrameworkModulePkg/Universal/BdsDxe/Language.c      
2014-03-25 02:38:54 UTC (rev 15385)
@@ -1,7 +1,7 @@
 /** @file
   Language settings
 
-Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
 which accompanies this distribution.  The full text of the license may be 
found at
@@ -425,7 +425,7 @@
     // The default language code should be one of the supported language codes.
     //
     ASSERT (IsLangInSupportedLangCodes (SupportedLang, DefaultLang, 
Iso639Language));
-    Status = gRT->SetVariable (
+    BdsDxeSetVariableAndReportStatusCodeOnError (
                     LangName,
                     &gEfiGlobalVariableGuid,
                     EFI_VARIABLE_NON_VOLATILE | 
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
@@ -471,6 +471,10 @@
                       AsciiStrSize (LangCodes),
                       LangCodes
                       );
+      //
+      // Platform needs to make sure setting volatile variable before calling 
3rd party code shouldn't fail.
+      //
+      ASSERT_EFI_ERROR (Status);
     }
 
     Status = gRT->SetVariable (
@@ -480,6 +484,10 @@
                     AsciiStrSize (PlatformLangCodes),
                     PlatformLangCodes
                     );
+    //
+    // Platform needs to make sure setting volatile variable before calling 
3rd party code shouldn't fail.
+    //
+    ASSERT_EFI_ERROR (Status);
   }
 
   if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {

Added: trunk/edk2/MdeModulePkg/Include/Guid/StatusCodeDataTypeVariable.h
===================================================================
--- trunk/edk2/MdeModulePkg/Include/Guid/StatusCodeDataTypeVariable.h           
                (rev 0)
+++ trunk/edk2/MdeModulePkg/Include/Guid/StatusCodeDataTypeVariable.h   
2014-03-25 02:38:54 UTC (rev 15385)
@@ -0,0 +1,40 @@
+/** @file
+  This file defines the GUID and data structure used to pass variable setting 
+  failure information to the Status Code Protocol.
+
+Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
+This program and the accompanying materials are licensed and made available 
under 
+the terms and conditions of the BSD License that accompanies this 
distribution.  
+The full text of the license may be found at
+http://opensource.org/licenses/bsd-license.php.
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#ifndef _STATUS_CODE_DATA_TYPE_VARIABLE_H_
+#define _STATUS_CODE_DATA_TYPE_VARIABLE_H_
+
+///
+/// The Global ID used to identify a structure of type 
EDKII_SET_VARIABLE_STATUS.
+/// The status code value is PcdGet32 (PcdErrorCodeSetVariable).
+///
+#define EDKII_STATUS_CODE_DATA_TYPE_VARIABLE_GUID \
+  { \
+    0xf6ee6dbb, 0xd67f, 0x4ea0, { 0x8b, 0x96, 0x6a, 0x71, 0xb1, 0x9d, 0x84, 
0xad } \
+  }
+
+typedef struct {
+  EFI_GUID   Guid;
+  UINTN      NameSize;
+  UINTN      DataSize;
+  EFI_STATUS SetStatus;
+  UINT32     Attributes;
+  // CHAR16  Name[];
+  // UINT8   Data[];
+} EDKII_SET_VARIABLE_STATUS;
+
+extern EFI_GUID gEdkiiStatusCodeDataTypeVariableGuid;
+
+#endif // _STATUS_CODE_DATA_TYPE_VARIABLE_H_

Modified: trunk/edk2/MdeModulePkg/MdeModulePkg.dec
===================================================================
--- trunk/edk2/MdeModulePkg/MdeModulePkg.dec    2014-03-24 15:30:48 UTC (rev 
15384)
+++ trunk/edk2/MdeModulePkg/MdeModulePkg.dec    2014-03-25 02:38:54 UTC (rev 
15385)
@@ -270,6 +270,9 @@
   ## Include/Guid/ConnectConInEvent.h
   gConnectConInEventGuid             = { 0xdb4e8151, 0x57ed, 0x4bed, { 0x88, 
0x33, 0x67, 0x51, 0xb5, 0xd1, 0xa8, 0xd7 }}
 
+  ## Include/Guid/StatusCodeDataTypeVariable.h
+  gEdkiiStatusCodeDataTypeVariableGuid = { 0xf6ee6dbb, 0xd67f, 0x4ea0, { 0x8b, 
0x96, 0x6a, 0x71, 0xb1, 0x9d, 0x84, 0xad }}
+
 [Ppis]
   ## Include/Ppi/AtaController.h
   gPeiAtaControllerPpiGuid       = { 0xa45e60d1, 0xc719, 0x44aa, { 0xb0, 0x7a, 
0xaa, 0x77, 0x7f, 0x85, 0x90, 0x6d }}
@@ -603,6 +606,10 @@
   #  PROGRESS_CODE_S3_SUSPEND_END   = (EFI_SOFTWARE_SMM_DRIVER | 
(EFI_OEM_SPECIFIC | 0x00000001))    = 0x03078001
   
gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeS3SuspendEnd|0x03078001|UINT32|0x30001033
 
+  ## Error Code for SetVariable failure.
+  #  EDKII_ERROR_CODE_SET_VARIABLE  = (EFI_SOFTWARE_DXE_BS_DRIVER | 
(EFI_OEM_SPECIFIC | 0x00000002)) = 0x03058002
+  
gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable|0x03058002|UINT32|0x30001040
+
 [PcdsFixedAtBuild,PcdsPatchableInModule]
   ## VPD type PCD allow developer point an absoluted physical address 
PcdVpdBaseAddress
   #  to store PCD value.

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to