]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Universal/BdsDxe/BdsEntry.c
Report the setting variable failure to platform through the status code when core...
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / BdsDxe / BdsEntry.c
index 5486a5c5301d58e41682f1b8968c5d76fce345fa..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 - 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
@@ -38,6 +38,17 @@ EFI_BDS_ARCH_PROTOCOL  gBds = {
 \r
 UINT16                          *mBootNext = NULL;\r
 \r
+///\r
+/// The read-only variables defined in UEFI Spec.\r
+///\r
+CHAR16  *mReadOnlyVariables[] = {\r
+  L"PlatformLangCodes",\r
+  L"LangCodes",\r
+  L"BootOptionSupport",\r
+  L"HwErrRecSupport",\r
+  L"OsIndicationsSupported"\r
+  };\r
+\r
 /**\r
 \r
   Install Boot Device Selection Protocol\r
@@ -153,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
@@ -357,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
@@ -392,15 +410,16 @@ BdsFormalizeEfiGlobalVariable (
   //\r
   // OS indicater support variable\r
   //\r
-  OsIndicationSupport = EFI_OS_INDICATIONS_BOOT_TO_FW_UI;\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
+  OsIndicationSupport = EFI_OS_INDICATIONS_BOOT_TO_FW_UI \\r
+                      | EFI_OS_INDICATIONS_FMP_CAPSULE_SUPPORTED;\r
+\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
@@ -429,16 +448,70 @@ 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
 \r
 }\r
 \r
+/**\r
+\r
+  Allocate a block of memory that will contain performance data to OS.\r
+\r
+**/\r
+VOID\r
+BdsAllocateMemoryForPerformanceData (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS                    Status;\r
+  EFI_PHYSICAL_ADDRESS          AcpiLowMemoryBase;\r
+  EDKII_VARIABLE_LOCK_PROTOCOL  *VariableLock;\r
+\r
+  AcpiLowMemoryBase = 0x0FFFFFFFFULL;\r
+\r
+  //\r
+  // Allocate a block of memory that will contain performance data to OS.\r
+  //\r
+  Status = gBS->AllocatePages (\r
+                  AllocateMaxAddress,\r
+                  EfiReservedMemoryType,\r
+                  EFI_SIZE_TO_PAGES (PERF_DATA_MAX_LENGTH),\r
+                  &AcpiLowMemoryBase\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Save the pointer to variable for use in S3 resume.\r
+    //\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
+      Status = VariableLock->RequestToLock (VariableLock, L"PerfDataMemAddr", &gPerformanceProtocolGuid);\r
+      ASSERT_EFI_ERROR (Status);\r
+    }\r
+  }\r
+}\r
+\r
 /**\r
 \r
   Service routine for BdsInstance->Entry(). Devices are connected, the\r
@@ -457,6 +530,10 @@ BdsEntry (
   LIST_ENTRY                      BootOptionList;\r
   UINTN                           BootNextSize;\r
   CHAR16                          *FirmwareVendor;\r
+  EFI_STATUS                      Status;\r
+  UINT16                          BootTimeOut;\r
+  UINTN                           Index;\r
+  EDKII_VARIABLE_LOCK_PROTOCOL    *VariableLock;\r
 \r
   //\r
   // Insert the performance probe\r
@@ -464,6 +541,10 @@ BdsEntry (
   PERF_END (NULL, "DXE", NULL, 0);\r
   PERF_START (NULL, "BDS", NULL, 0);\r
 \r
+  PERF_CODE (\r
+    BdsAllocateMemoryForPerformanceData ();\r
+  );\r
+\r
   //\r
   // Initialize the global system boot option and driver option\r
   //\r
@@ -486,6 +567,7 @@ BdsEntry (
   //\r
   // Fixup Tasble CRC after we updated Firmware Vendor and Revision\r
   //\r
+  gST->Hdr.CRC32 = 0;\r
   gBS->CalculateCrc32 ((VOID *)gST, sizeof(EFI_SYSTEM_TABLE), &gST->Hdr.CRC32);\r
 \r
   //\r
@@ -493,6 +575,18 @@ BdsEntry (
   //\r
   BdsFormalizeEfiGlobalVariable();\r
 \r
+  //\r
+  // Mark the read-only variables if the Variable Lock protocol exists\r
+  //\r
+  Status = gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (VOID **) &VariableLock);\r
+  DEBUG ((EFI_D_INFO, "[BdsDxe] Locate Variable Lock protocol - %r\n", Status));\r
+  if (!EFI_ERROR (Status)) {\r
+    for (Index = 0; Index < sizeof (mReadOnlyVariables) / sizeof (mReadOnlyVariables[0]); Index++) {\r
+      Status = VariableLock->RequestToLock (VariableLock, mReadOnlyVariables[Index], &gEfiGlobalVariableGuid);\r
+      ASSERT_EFI_ERROR (Status);\r
+    }\r
+  }\r
+\r
   //\r
   // Report Status Code to indicate connecting drivers will happen\r
   //\r
@@ -501,13 +595,25 @@ BdsEntry (
     (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_BEGIN_CONNECTING_DRIVERS)\r
     );\r
 \r
+  InitializeHwErrRecSupport();\r
+\r
   //\r
-  // Do the platform init, can be customized by OEM/IBV\r
+  // Initialize L"Timeout" EFI global variable.\r
   //\r
-  PERF_START (NULL, "PlatformBds", "BDS", 0);\r
-  PlatformBdsInit ();\r
-\r
-  InitializeHwErrRecSupport();\r
+  BootTimeOut = PcdGet16 (PcdPlatformBootTimeOut);\r
+  if (BootTimeOut != 0xFFFF) {\r
+    //\r
+    // 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
+    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
+  }\r
 \r
   //\r
   // bugbug: platform specific code\r
@@ -517,6 +623,12 @@ BdsEntry (
   InitializeLanguage (TRUE);\r
   InitializeFrontPage (TRUE);\r
 \r
+  //\r
+  // Do the platform init, can be customized by OEM/IBV\r
+  //\r
+  PERF_START (NULL, "PlatformBds", "BDS", 0);\r
+  PlatformBdsInit ();\r
+\r
   //\r
   // Set up the device list based on EFI 1.1 variables\r
   // process Driver#### and Load the driver's in the\r
@@ -554,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