]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c
Report the setting variable failure to platform through the status code when core...
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / GenericBdsLib / BdsConsole.c
index 782c4a5ce1ecfd36d4a8ee606434891276b94429..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 - 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
@@ -88,6 +88,7 @@ UpdateSystemTableConsole (
   EFI_DEVICE_PATH_PROTOCOL  *Instance;\r
   VOID                      *Interface;\r
   EFI_HANDLE                NewHandle;\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOut;\r
 \r
   ASSERT (VarName != NULL);\r
   ASSERT (ConsoleHandle != NULL);\r
@@ -159,6 +160,15 @@ UpdateSystemTableConsole (
         //\r
         *ConsoleHandle     = NewHandle;\r
         *ProtocolInterface = Interface;\r
+        if (CompareGuid (ConsoleGuid, &gEfiSimpleTextOutProtocolGuid)) {\r
+          //\r
+          // If it is console out device, set console mode 80x25 if current mode is invalid.\r
+          //\r
+          TextOut = (EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *) Interface;\r
+          if (TextOut->Mode->Mode == -1) {\r
+            TextOut->SetMode (TextOut, 0);\r
+          }\r
+        }\r
         return TRUE;\r
       }\r
     }\r
@@ -171,114 +181,6 @@ UpdateSystemTableConsole (
   return FALSE;\r
 }\r
 \r
-/**\r
-  Connect the console device base on the variable ConVarName, if\r
-  device path of the ConVarName is multi-instance device path and\r
-  anyone of the instances is connected success, this function will\r
-  return success. \r
-  Dispatch service is called basing on input when the handle associate\r
-  with one device path node can not be created successfully. Since in\r
-  some cases we assume driver dependency does not exist and do not \r
-  need to call this service.\r
-\r
-  @param  ConVarName               Console related variable name, ConIn, ConOut,\r
-                                   ErrOut.\r
-  @param  NeedDispatch              Whether requires dispatch service during connection \r
-\r
-  @retval EFI_NOT_FOUND            There is not any console devices connected\r
-                                   success\r
-  @retval EFI_SUCCESS              Success connect any one instance of the console\r
-                                   device path base on the variable ConVarName.\r
-\r
-**/\r
-EFI_STATUS\r
-ConnectConsoleVariableInternal (\r
-  IN  CHAR16                 *ConVarName,\r
-  IN  BOOLEAN                NeedDispatch\r
-  )\r
-{\r
-  EFI_STATUS                Status;\r
-  EFI_DEVICE_PATH_PROTOCOL  *StartDevicePath;\r
-  UINTN                     VariableSize;\r
-  EFI_DEVICE_PATH_PROTOCOL  *Instance;\r
-  EFI_DEVICE_PATH_PROTOCOL  *Next;\r
-  EFI_DEVICE_PATH_PROTOCOL  *CopyOfDevicePath;\r
-  UINTN                     Size;\r
-  BOOLEAN                   DeviceExist;\r
-\r
-  Status      = EFI_SUCCESS;\r
-  DeviceExist = FALSE;\r
-\r
-  //\r
-  // Check if the console variable exist\r
-  //\r
-  StartDevicePath = BdsLibGetVariableAndSize (\r
-                      ConVarName,\r
-                      &gEfiGlobalVariableGuid,\r
-                      &VariableSize\r
-                      );\r
-  if (StartDevicePath == NULL) {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-\r
-  CopyOfDevicePath = StartDevicePath;\r
-  do {\r
-    //\r
-    // Check every instance of the console variable\r
-    //\r
-    Instance  = GetNextDevicePathInstance (&CopyOfDevicePath, &Size);\r
-    if (Instance == NULL) {\r
-      FreePool (StartDevicePath);\r
-      return EFI_UNSUPPORTED;\r
-    }\r
-    \r
-    Next      = Instance;\r
-    while (!IsDevicePathEndType (Next)) {\r
-      Next = NextDevicePathNode (Next);\r
-    }\r
-\r
-    SetDevicePathEndNode (Next);\r
-    //\r
-    // Connect the USB console\r
-    // USB console device path is a short-form device path that \r
-    //  starts with the first element being a USB WWID\r
-    //  or a USB Class device path\r
-    //\r
-    if ((DevicePathType (Instance) == MESSAGING_DEVICE_PATH) &&\r
-       ((DevicePathSubType (Instance) == MSG_USB_CLASS_DP)\r
-       || (DevicePathSubType (Instance) == MSG_USB_WWID_DP)\r
-       )) {\r
-      Status = BdsLibConnectUsbDevByShortFormDP (0xFF, Instance);\r
-      if (!EFI_ERROR (Status)) {\r
-        DeviceExist = TRUE;\r
-      }\r
-    } else {\r
-      //\r
-      // Connect the instance device path\r
-      //\r
-      Status = ConnectDevicePathInternal (Instance, NeedDispatch);\r
-\r
-      if (EFI_ERROR (Status)) {\r
-        //\r
-        // Delete the instance from the console varialbe\r
-        //\r
-        BdsLibUpdateConsoleVariable (ConVarName, NULL, Instance);\r
-      } else {\r
-        DeviceExist = TRUE;\r
-      }\r
-    }\r
-    FreePool(Instance);\r
-  } while (CopyOfDevicePath != NULL);\r
-\r
-  FreePool (StartDevicePath);\r
-\r
-  if (!DeviceExist) {\r
-    return EFI_NOT_FOUND;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
 /**\r
   This function update console variable based on ConVarName, it can\r
   add or remove one specific console device path from the variable\r
@@ -383,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
@@ -437,35 +338,86 @@ BdsLibConnectConsoleVariable (
   IN  CHAR16                 *ConVarName\r
   )\r
 {\r
-  return ConnectConsoleVariableInternal(ConVarName, TRUE);\r
-}\r
+  EFI_STATUS                Status;\r
+  EFI_DEVICE_PATH_PROTOCOL  *StartDevicePath;\r
+  UINTN                     VariableSize;\r
+  EFI_DEVICE_PATH_PROTOCOL  *Instance;\r
+  EFI_DEVICE_PATH_PROTOCOL  *Next;\r
+  EFI_DEVICE_PATH_PROTOCOL  *CopyOfDevicePath;\r
+  UINTN                     Size;\r
+  BOOLEAN                   DeviceExist;\r
 \r
-/**\r
-  Connect the console device base on the variable ConVarName, if\r
-  device path of the ConVarName is multi-instance device path and\r
-  anyone of the instances is connected success, then this function\r
-  will return success.\r
-  Dispatch service is not called when the handle associate with one \r
-  device path node can not be created successfully. Here no driver \r
-  dependency is assumed exist, so need not to call this service.\r
+  Status      = EFI_SUCCESS;\r
+  DeviceExist = FALSE;\r
 \r
+  //\r
+  // Check if the console variable exist\r
+  //\r
+  StartDevicePath = BdsLibGetVariableAndSize (\r
+                      ConVarName,\r
+                      &gEfiGlobalVariableGuid,\r
+                      &VariableSize\r
+                      );\r
+  if (StartDevicePath == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
 \r
-  @param  ConVarName               Console related variable name, ConIn, ConOut,\r
-                                   ErrOut.\r
+  CopyOfDevicePath = StartDevicePath;\r
+  do {\r
+    //\r
+    // Check every instance of the console variable\r
+    //\r
+    Instance  = GetNextDevicePathInstance (&CopyOfDevicePath, &Size);\r
+    if (Instance == NULL) {\r
+      FreePool (StartDevicePath);\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+    \r
+    Next      = Instance;\r
+    while (!IsDevicePathEndType (Next)) {\r
+      Next = NextDevicePathNode (Next);\r
+    }\r
 \r
-  @retval EFI_NOT_FOUND            There is not any console devices connected\r
-                                   success\r
-  @retval EFI_SUCCESS              Success connect any one instance of the console\r
-                                   device path base on the variable ConVarName.\r
+    SetDevicePathEndNode (Next);\r
+    //\r
+    // Connect the USB console\r
+    // USB console device path is a short-form device path that \r
+    //  starts with the first element being a USB WWID\r
+    //  or a USB Class device path\r
+    //\r
+    if ((DevicePathType (Instance) == MESSAGING_DEVICE_PATH) &&\r
+       ((DevicePathSubType (Instance) == MSG_USB_CLASS_DP)\r
+       || (DevicePathSubType (Instance) == MSG_USB_WWID_DP)\r
+       )) {\r
+      Status = BdsLibConnectUsbDevByShortFormDP (0xFF, Instance);\r
+      if (!EFI_ERROR (Status)) {\r
+        DeviceExist = TRUE;\r
+      }\r
+    } else {\r
+      //\r
+      // Connect the instance device path\r
+      //\r
+      Status = BdsLibConnectDevicePath (Instance);\r
 \r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-BdsLibConnectConsoleVariableWithOutDispatch (\r
-  IN  CHAR16                 *ConVarName\r
-  )\r
-{\r
-  return ConnectConsoleVariableInternal(ConVarName, FALSE);\r
+      if (EFI_ERROR (Status)) {\r
+        //\r
+        // Delete the instance from the console varialbe\r
+        //\r
+        BdsLibUpdateConsoleVariable (ConVarName, NULL, Instance);\r
+      } else {\r
+        DeviceExist = TRUE;\r
+      }\r
+    }\r
+    FreePool(Instance);\r
+  } while (CopyOfDevicePath != NULL);\r
+\r
+  FreePool (StartDevicePath);\r
+\r
+  if (!DeviceExist) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
@@ -798,7 +750,10 @@ ConvertBmpToGopBlt (
         ColorMapNum = 0;\r
         break;\r
       }\r
-    if (BmpHeader->ImageOffset - sizeof (BMP_IMAGE_HEADER) != sizeof (BMP_COLOR_MAP) * ColorMapNum) {\r
+    //\r
+    // BMP file may has padding data between the bmp header section and the bmp data section.\r
+    //\r
+    if (BmpHeader->ImageOffset - sizeof (BMP_IMAGE_HEADER) < sizeof (BMP_COLOR_MAP) * ColorMapNum) {\r
       return EFI_INVALID_PARAMETER;\r
     }\r
   }\r