]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Library/GenericBdsLib/BdsConsole.c
IntelFrameworkModulePkg: Refine casting expression result to bigger size
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / GenericBdsLib / BdsConsole.c
index 280b1697b6421733dccbfa2ee502e4bd741ae47a..8f273ff1b1eaaf44ad95ee2dd2655a81405db33f 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 - 2017, 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
@@ -65,9 +65,9 @@ IsNvNeed (
   @param  VarName            The name of the EFI console variable.\r
   @param  ConsoleGuid        Specified Console protocol GUID.\r
   @param  ConsoleHandle      On IN,  console handle in System Table to be checked. \r
-                             On OUT, new console hanlde in system table.\r
+                             On OUT, new console handle in system table.\r
   @param  ProtocolInterface  On IN,  console protocol on console handle in System Table to be checked. \r
-                             On OUT, new console protocol on new console hanlde in system table.\r
+                             On OUT, new console protocol on new console handle in system table.\r
 \r
   @retval TRUE               System Table has been updated.\r
   @retval FALSE              System Table hasn't been updated.\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
@@ -275,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
@@ -307,9 +316,12 @@ BdsLibUpdateConsoleVariable (
 \r
 /**\r
   Connect the console device base on the variable ConVarName, if\r
-  device path of the ConVarName is multi-instance device path, 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
+  If the handle associate with one device path node can not\r
+  be created successfully, then still give chance to do the dispatch,\r
+  which load the missing drivers if possible..\r
 \r
   @param  ConVarName               Console related variable name, ConIn, ConOut,\r
                                    ErrOut.\r
@@ -386,6 +398,7 @@ BdsLibConnectConsoleVariable (
       // Connect the instance device path\r
       //\r
       Status = BdsLibConnectDevicePath (Instance);\r
+\r
       if (EFI_ERROR (Status)) {\r
         //\r
         // Delete the instance from the console varialbe\r
@@ -407,7 +420,6 @@ BdsLibConnectConsoleVariable (
   return EFI_SUCCESS;\r
 }\r
 \r
-\r
 /**\r
   This function will search every simpletext device in current system,\r
   and make every simpletext device as pertantial console device.\r
@@ -738,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
@@ -854,12 +869,11 @@ ConvertBmpToGopBlt (
           *GopBlt = NULL;\r
         }\r
         return EFI_UNSUPPORTED;\r
-        break;\r
       };\r
 \r
     }\r
 \r
-    ImageIndex = (UINTN) (Image - ImageHeader);\r
+    ImageIndex = (UINTN)Image - (UINTN)ImageHeader;\r
     if ((ImageIndex % 4) != 0) {\r
       //\r
       // Bmp Image starts each row on a 32-bit boundary!\r