]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c
MdeModulePkg: Apply uncrustify changes
[mirror_edk2.git] / MdeModulePkg / Application / BootManagerMenuApp / BootManagerMenu.c
index a25f2ca298c758ee6e7e145b79ebe2cd25ed17b3..ef1931961432da8ee1481adfd1b38004de0dd64b 100644 (file)
@@ -1,37 +1,31 @@
 /** @file\r
   The application to show the Boot Manager Menu.\r
 \r
-Copyright (c) 2011 - 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
-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
+Copyright (c) 2011 - 2021, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 #include "BootManagerMenu.h"\r
 \r
-EFI_HII_HANDLE gStringPackHandle;\r
+EFI_HII_HANDLE  gStringPackHandle;\r
 \r
-BOOLEAN   mModeInitialized = FALSE;\r
+BOOLEAN  mModeInitialized = FALSE;\r
 \r
 //\r
 // Boot video resolution and text mode.\r
 //\r
-UINT32    mBootHorizontalResolution    = 0;\r
-UINT32    mBootVerticalResolution      = 0;\r
-UINT32    mBootTextModeColumn          = 0;\r
-UINT32    mBootTextModeRow             = 0;\r
+UINT32  mBootHorizontalResolution = 0;\r
+UINT32  mBootVerticalResolution   = 0;\r
+UINT32  mBootTextModeColumn       = 0;\r
+UINT32  mBootTextModeRow          = 0;\r
 //\r
 // BIOS setup video resolution and text mode.\r
 //\r
-UINT32    mSetupTextModeColumn         = 0;\r
-UINT32    mSetupTextModeRow            = 0;\r
-UINT32    mSetupHorizontalResolution   = 0;\r
-UINT32    mSetupVerticalResolution     = 0;\r
+UINT32  mSetupTextModeColumn       = 0;\r
+UINT32  mSetupTextModeRow          = 0;\r
+UINT32  mSetupHorizontalResolution = 0;\r
+UINT32  mSetupVerticalResolution   = 0;\r
 \r
 /**\r
   Prints a unicode string to the default console, at\r
@@ -46,14 +40,61 @@ UINT32    mSetupVerticalResolution     = 0;
 **/\r
 UINTN\r
 PrintStringAt (\r
-  IN UINTN     Column,\r
-  IN UINTN     Row,\r
-  IN CHAR16    *String\r
+  IN UINTN   Column,\r
+  IN UINTN   Row,\r
+  IN CHAR16  *String\r
   )\r
 {\r
+  UINTN       ScreenWidth;\r
+  UINTN       ScreenRows;\r
+  CHAR16      *TurncateString;\r
+  EFI_STATUS  Status;\r
+  UINTN       ShowingLength;\r
 \r
   gST->ConOut->SetCursorPosition (gST->ConOut, Column, Row);\r
-  return Print (L"%s", String);\r
+\r
+  gST->ConOut->QueryMode (\r
+                 gST->ConOut,\r
+                 gST->ConOut->Mode->Mode,\r
+                 &ScreenWidth,\r
+                 &ScreenRows\r
+                 );\r
+\r
+  if ((Column > (ScreenWidth - 1)) || (Row > (ScreenRows - 1))) {\r
+    return 0;\r
+  }\r
+\r
+  if ((StrLen (String) + Column) > (ScreenWidth - 1)) {\r
+    //\r
+    // |      - ScreenWidth -       |\r
+    // ...Column.....................\r
+    // TurncateString length should leave one character for draw box and\r
+    // require one character for string end.\r
+    //\r
+    ShowingLength  = ScreenWidth - Column - 1;\r
+    TurncateString = AllocatePool ((ShowingLength + 1) * sizeof (CHAR16));\r
+\r
+    if (TurncateString == NULL) {\r
+      return 0;\r
+    }\r
+\r
+    Status = StrnCpyS (TurncateString, ShowingLength + 1, String, ShowingLength - 3);\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      FreePool (TurncateString);\r
+      return 0;\r
+    }\r
+\r
+    *(TurncateString + ShowingLength - 3) = L'.';\r
+    *(TurncateString + ShowingLength - 2) = L'.';\r
+    *(TurncateString + ShowingLength - 1) = L'.';\r
+    *(TurncateString + ShowingLength)     = L'\0';\r
+    ShowingLength                         = Print (L"%s", TurncateString);\r
+    FreePool (TurncateString);\r
+    return ShowingLength;\r
+  } else {\r
+    return Print (L"%s", String);\r
+  }\r
 }\r
 \r
 /**\r
@@ -69,12 +110,27 @@ PrintStringAt (
 **/\r
 UINTN\r
 PrintCharAt (\r
-  IN UINTN     Column,\r
-  IN UINTN     Row,\r
-  CHAR16       Character\r
+  IN UINTN  Column,\r
+  IN UINTN  Row,\r
+  CHAR16    Character\r
   )\r
 {\r
+  UINTN  ScreenWidth;\r
+  UINTN  ScreenRows;\r
+\r
   gST->ConOut->SetCursorPosition (gST->ConOut, Column, Row);\r
+\r
+  gST->ConOut->QueryMode (\r
+                 gST->ConOut,\r
+                 gST->ConOut->Mode->Mode,\r
+                 &ScreenWidth,\r
+                 &ScreenRows\r
+                 );\r
+\r
+  if ((Column > (ScreenWidth - 1)) || (Row > (ScreenRows - 1))) {\r
+    return 0;\r
+  }\r
+\r
   return Print (L"%c", Character);\r
 }\r
 \r
@@ -89,37 +145,39 @@ PrintCharAt (
 **/\r
 UINTN\r
 GetLineWidth (\r
-  IN EFI_STRING_ID       StringId\r
+  IN EFI_STRING_ID  StringId\r
   )\r
-{  \r
-  UINTN        Index;\r
-  UINTN        IncrementValue;\r
-  EFI_STRING   String;\r
-  UINTN        LineWidth;\r
-  \r
+{\r
+  UINTN       Index;\r
+  UINTN       IncrementValue;\r
+  EFI_STRING  String;\r
+  UINTN       LineWidth;\r
+\r
   LineWidth = 0;\r
-  String = HiiGetString (gStringPackHandle, StringId, NULL); \r
-  \r
+  String    = HiiGetString (gStringPackHandle, StringId, NULL);\r
+\r
   if (String != NULL) {\r
-    Index           = 0;\r
-    IncrementValue  = 1;\r
-    \r
+    Index          = 0;\r
+    IncrementValue = 1;\r
+\r
     do {\r
       //\r
       // Advance to the null-terminator or to the first width directive\r
       //\r
-      for (;\r
-           (String[Index] != NARROW_CHAR) && (String[Index] != WIDE_CHAR) && (String[Index] != 0);\r
-           Index++, LineWidth = LineWidth + IncrementValue\r
-          )\r
-        ;\r
-    \r
+      for ( ;\r
+            (String[Index] != NARROW_CHAR) && (String[Index] != WIDE_CHAR) && (String[Index] != 0);\r
+            Index++, LineWidth = LineWidth + IncrementValue\r
+            )\r
+      {\r
+      }\r
+\r
       //\r
       // We hit the null-terminator, we now have a count\r
       //\r
       if (String[Index] == 0) {\r
         break;\r
       }\r
+\r
       //\r
       // We encountered a narrow directive - strip it from the size calculation since it doesn't get printed\r
       // and also set the flag that determines what we increment by.(if narrow, increment by 1, if wide increment by 2)\r
@@ -137,11 +195,12 @@ GetLineWidth (
         Index++;\r
         IncrementValue = 2;\r
       }\r
-    } while (String[Index] != 0);   \r
+    } while (String[Index] != 0);\r
+\r
     FreePool (String);\r
   }\r
-  \r
-  return LineWidth;  \r
+\r
+  return LineWidth;\r
 }\r
 \r
 /**\r
@@ -150,43 +209,45 @@ GetLineWidth (
   @param  BootMenuData            The boot menu data to be processed.\r
 \r
   @return EFI_SUCCESS             calculate boot menu information successful.\r
-  @retval EFI_INVALID_PARAMETER   Input parameter is invalid   \r
+  @retval EFI_INVALID_PARAMETER   Input parameter is invalid\r
 \r
 **/\r
-EFI_STATUS \r
+EFI_STATUS\r
 InitializeBootMenuScreen (\r
   IN OUT  BOOT_MENU_POPUP_DATA  *BootMenuData\r
   )\r
 {\r
-  UINTN         MaxStrWidth;\r
-  UINTN         StrWidth;\r
-  UINTN         Index;\r
-  UINTN         Column;\r
-  UINTN         Row;\r
-  UINTN         MaxPrintRows;\r
-  UINTN         UnSelectableItmes;\r
+  UINTN  MaxStrWidth;\r
+  UINTN  StrWidth;\r
+  UINTN  Index;\r
+  UINTN  Column;\r
+  UINTN  Row;\r
+  UINTN  MaxPrintRows;\r
+  UINTN  UnSelectableItmes;\r
 \r
   if (BootMenuData == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
+\r
   //\r
   // Get maximum string width\r
   //\r
-  MaxStrWidth = 0;  \r
-  for (Index = 0; Index < TITLE_TOKEN_COUNT; Index++) {    \r
-    StrWidth = GetLineWidth (BootMenuData->TitleToken[Index]);\r
+  MaxStrWidth = 0;\r
+  for (Index = 0; Index < TITLE_TOKEN_COUNT; Index++) {\r
+    StrWidth    = GetLineWidth (BootMenuData->TitleToken[Index]);\r
     MaxStrWidth = MaxStrWidth > StrWidth ? MaxStrWidth : StrWidth;\r
   }\r
-   \r
+\r
   for (Index = 0; Index < BootMenuData->ItemCount; Index++) {\r
-    StrWidth = GetLineWidth (BootMenuData->PtrTokens[Index]);\r
-    MaxStrWidth = MaxStrWidth > StrWidth ? MaxStrWidth : StrWidth; \r
-  } \r
-  \r
-  for (Index = 0; Index < HELP_TOKEN_COUNT; Index++) {    \r
-    StrWidth = GetLineWidth (BootMenuData->HelpToken[Index]);\r
+    StrWidth    = GetLineWidth (BootMenuData->PtrTokens[Index]);\r
+    MaxStrWidth = MaxStrWidth > StrWidth ? MaxStrWidth : StrWidth;\r
+  }\r
+\r
+  for (Index = 0; Index < HELP_TOKEN_COUNT; Index++) {\r
+    StrWidth    = GetLineWidth (BootMenuData->HelpToken[Index]);\r
     MaxStrWidth = MaxStrWidth > StrWidth ? MaxStrWidth : StrWidth;\r
-  }  \r
+  }\r
+\r
   //\r
   // query current row and column to calculate boot menu location\r
   //\r
@@ -195,52 +256,59 @@ InitializeBootMenuScreen (
                  gST->ConOut->Mode->Mode,\r
                  &Column,\r
                  &Row\r
-                 ); \r
-                 \r
-  MaxPrintRows = Row - 6;    \r
-  UnSelectableItmes = TITLE_TOKEN_COUNT + 2 + HELP_TOKEN_COUNT + 2;           \r
-  BootMenuData->MenuScreen.Width = MaxStrWidth + 8;\r
+                 );\r
+\r
+  MaxPrintRows      = Row - 6;\r
+  UnSelectableItmes = TITLE_TOKEN_COUNT + 2 + HELP_TOKEN_COUNT + 2;\r
+  if (MaxStrWidth + 8 > Column) {\r
+    BootMenuData->MenuScreen.Width = Column;\r
+  } else {\r
+    BootMenuData->MenuScreen.Width = MaxStrWidth + 8;\r
+  }\r
+\r
   if (BootMenuData->ItemCount + UnSelectableItmes > MaxPrintRows) {\r
-    BootMenuData->MenuScreen.Height = MaxPrintRows;\r
-    BootMenuData->ScrollBarControl.HasScrollBar = TRUE;\r
+    BootMenuData->MenuScreen.Height                   = MaxPrintRows;\r
+    BootMenuData->ScrollBarControl.HasScrollBar       = TRUE;\r
     BootMenuData->ScrollBarControl.ItemCountPerScreen = MaxPrintRows - UnSelectableItmes;\r
-    BootMenuData->ScrollBarControl.FirstItem = 0;\r
-    BootMenuData->ScrollBarControl.LastItem = MaxPrintRows - UnSelectableItmes - 1;\r
+    BootMenuData->ScrollBarControl.FirstItem          = 0;\r
+    BootMenuData->ScrollBarControl.LastItem           = MaxPrintRows - UnSelectableItmes - 1;\r
   } else {\r
-    BootMenuData->MenuScreen.Height = BootMenuData->ItemCount + UnSelectableItmes;\r
-    BootMenuData->ScrollBarControl.HasScrollBar = FALSE;\r
+    BootMenuData->MenuScreen.Height                   = BootMenuData->ItemCount + UnSelectableItmes;\r
+    BootMenuData->ScrollBarControl.HasScrollBar       = FALSE;\r
     BootMenuData->ScrollBarControl.ItemCountPerScreen = BootMenuData->ItemCount;\r
-    BootMenuData->ScrollBarControl.FirstItem = 0;\r
-    BootMenuData->ScrollBarControl.LastItem = BootMenuData->ItemCount - 1;    \r
+    BootMenuData->ScrollBarControl.FirstItem          = 0;\r
+    BootMenuData->ScrollBarControl.LastItem           = BootMenuData->ItemCount - 1;\r
   }\r
-  BootMenuData->MenuScreen.StartCol = (Column -  BootMenuData->MenuScreen.Width) / 2;              \r
-  BootMenuData->MenuScreen.StartRow = (Row -  BootMenuData->MenuScreen.Height) / 2;  \r
+\r
+  BootMenuData->MenuScreen.StartCol = (Column -  BootMenuData->MenuScreen.Width) / 2;\r
+  BootMenuData->MenuScreen.StartRow = (Row -  BootMenuData->MenuScreen.Height) / 2;\r
 \r
   return EFI_SUCCESS;\r
 }\r
+\r
 /**\r
   This function uses check boot option is wheher setup application or no\r
 \r
   @param   BootOption   Pointer to EFI_BOOT_MANAGER_LOAD_OPTION array.\r
-  \r
+\r
   @retval  TRUE         This boot option is setup application.\r
   @retval  FALSE        This boot options isn't setup application\r
 \r
 **/\r
 BOOLEAN\r
 IsBootManagerMenu (\r
-  IN  EFI_BOOT_MANAGER_LOAD_OPTION    *BootOption\r
+  IN  EFI_BOOT_MANAGER_LOAD_OPTION  *BootOption\r
   )\r
 {\r
-  EFI_STATUS                          Status;\r
-  EFI_BOOT_MANAGER_LOAD_OPTION        BootManagerMenu;\r
+  EFI_STATUS                    Status;\r
+  EFI_BOOT_MANAGER_LOAD_OPTION  BootManagerMenu;\r
 \r
   Status = EfiBootManagerGetBootManagerMenu (&BootManagerMenu);\r
   if (!EFI_ERROR (Status)) {\r
     EfiBootManagerFreeLoadOption (&BootManagerMenu);\r
   }\r
 \r
-  return (BOOLEAN) (!EFI_ERROR (Status) && (BootOption->OptionNumber == BootManagerMenu.OptionNumber));\r
+  return (BOOLEAN)(!EFI_ERROR (Status) && (BootOption->OptionNumber == BootManagerMenu.OptionNumber));\r
 }\r
 \r
 /**\r
@@ -256,13 +324,13 @@ IgnoreBootOption (
   IN   EFI_BOOT_MANAGER_LOAD_OPTION  *BootOption\r
   )\r
 {\r
-  EFI_STATUS                    Status;\r
-  EFI_DEVICE_PATH_PROTOCOL      *ImageDevicePath;\r
+  EFI_STATUS                Status;\r
+  EFI_DEVICE_PATH_PROTOCOL  *ImageDevicePath;\r
 \r
   //\r
   // Ignore myself.\r
   //\r
-  Status = gBS->HandleProtocol (gImageHandle, &gEfiLoadedImageDevicePathProtocolGuid, (VOID **) &ImageDevicePath);\r
+  Status = gBS->HandleProtocol (gImageHandle, &gEfiLoadedImageDevicePathProtocolGuid, (VOID **)&ImageDevicePath);\r
   ASSERT_EFI_ERROR (Status);\r
   if (CompareMem (BootOption->FilePath, ImageDevicePath, GetDevicePathSize (ImageDevicePath)) == 0) {\r
     return TRUE;\r
@@ -291,9 +359,9 @@ IgnoreBootOption (
   @param   BootOption             Pointer to EFI_BOOT_MANAGER_LOAD_OPTION array.\r
   @param   BootOptionCount        Number of boot option.\r
   @param   BootMenuData           The Input BootMenuData to be initialized.\r
-  \r
+\r
   @retval  EFI_SUCCESS            Initialize boot menu data successful.\r
-  @retval  EFI_INVALID_PARAMETER  Input parameter is invalid.   \r
+  @retval  EFI_INVALID_PARAMETER  Input parameter is invalid.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -303,10 +371,10 @@ InitializeBootMenuData (
   OUT  BOOT_MENU_POPUP_DATA          *BootMenuData\r
   )\r
 {\r
-  UINTN                         Index;\r
-  UINTN                         StrIndex;\r
-      \r
-  if (BootOption == NULL || BootMenuData == NULL) {\r
+  UINTN  Index;\r
+  UINTN  StrIndex;\r
+\r
+  if ((BootOption == NULL) || (BootMenuData == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -324,21 +392,21 @@ InitializeBootMenuData (
 \r
     ASSERT (BootOption[Index].Description != NULL);\r
     BootMenuData->PtrTokens[StrIndex++] = HiiSetString (\r
-                                            gStringPackHandle, \r
+                                            gStringPackHandle,\r
                                             0,\r
                                             BootOption[Index].Description,\r
                                             NULL\r
                                             );\r
   }\r
 \r
-  BootMenuData->ItemCount           = StrIndex;   \r
+  BootMenuData->ItemCount    = StrIndex;\r
   BootMenuData->HelpToken[0] = STRING_TOKEN (STR_BOOT_POPUP_MENU_HELP1_STRING);\r
   BootMenuData->HelpToken[1] = STRING_TOKEN (STR_BOOT_POPUP_MENU_HELP2_STRING);\r
   BootMenuData->HelpToken[2] = STRING_TOKEN (STR_BOOT_POPUP_MENU_HELP3_STRING);\r
   InitializeBootMenuScreen (BootMenuData);\r
   BootMenuData->SelectItem = 0;\r
   return EFI_SUCCESS;\r
-}    \r
+}\r
 \r
 /**\r
   This function uses input select item to highlight selected item\r
@@ -347,9 +415,9 @@ InitializeBootMenuData (
   @param  WantSelectItem          The user wants to select item.\r
   @param  BootMenuData            The boot menu data to be processed\r
 \r
-  @return EFI_SUCCESS             Highlight selected item and update current selected \r
-                                  item successful \r
-  @retval EFI_INVALID_PARAMETER   Input parameter is invalid   \r
+  @return EFI_SUCCESS             Highlight selected item and update current selected\r
+                                  item successful\r
+  @retval EFI_INVALID_PARAMETER   Input parameter is invalid\r
 **/\r
 EFI_STATUS\r
 BootMenuSelectItem (\r
@@ -357,129 +425,138 @@ BootMenuSelectItem (
   IN OUT BOOT_MENU_POPUP_DATA  *BootMenuData\r
   )\r
 {\r
-  INT32                 SavedAttribute;\r
-  EFI_STRING            String;\r
-  UINTN                 StartCol;  \r
-  UINTN                 StartRow;\r
-  UINTN                 PrintCol;\r
-  UINTN                 PrintRow;\r
-  UINTN                 TopShadeNum;\r
-  UINTN                 LowShadeNum;\r
-  UINTN                 FirstItem;\r
-  UINTN                 LastItem;\r
-  UINTN                 ItemCountPerScreen;\r
-  UINTN                 Index;\r
-  BOOLEAN               RePaintItems;\r
-  \r
-  if (BootMenuData == NULL || WantSelectItem >= BootMenuData->ItemCount) {\r
+  INT32       SavedAttribute;\r
+  EFI_STRING  String;\r
+  UINTN       StartCol;\r
+  UINTN       StartRow;\r
+  UINTN       PrintCol;\r
+  UINTN       PrintRow;\r
+  UINTN       TopShadeNum;\r
+  UINTN       LowShadeNum;\r
+  UINTN       FirstItem;\r
+  UINTN       LastItem;\r
+  UINTN       ItemCountPerScreen;\r
+  UINTN       Index;\r
+  BOOLEAN     RePaintItems;\r
+\r
+  if ((BootMenuData == NULL) || (WantSelectItem >= BootMenuData->ItemCount)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
+\r
   ASSERT (BootMenuData->ItemCount != 0);\r
   SavedAttribute = gST->ConOut->Mode->Attribute;\r
-  RePaintItems = FALSE;\r
-  StartCol = BootMenuData->MenuScreen.StartCol;\r
-  StartRow = BootMenuData->MenuScreen.StartRow;\r
+  RePaintItems   = FALSE;\r
+  StartCol       = BootMenuData->MenuScreen.StartCol;\r
+  StartRow       = BootMenuData->MenuScreen.StartRow;\r
   //\r
   // print selectable items again and adjust scroll bar if need\r
-  //         \r
+  //\r
   if (BootMenuData->ScrollBarControl.HasScrollBar &&\r
-      (WantSelectItem < BootMenuData->ScrollBarControl.FirstItem ||\r
-      WantSelectItem > BootMenuData->ScrollBarControl.LastItem ||\r
-      WantSelectItem == BootMenuData->SelectItem)) {          \r
-    ItemCountPerScreen   = BootMenuData->ScrollBarControl.ItemCountPerScreen;\r
+      ((WantSelectItem < BootMenuData->ScrollBarControl.FirstItem) ||\r
+       (WantSelectItem > BootMenuData->ScrollBarControl.LastItem) ||\r
+       (WantSelectItem == BootMenuData->SelectItem)))\r
+  {\r
+    ItemCountPerScreen = BootMenuData->ScrollBarControl.ItemCountPerScreen;\r
     //\r
     // Set first item and last item\r
-    //     \r
+    //\r
     if (WantSelectItem < BootMenuData->ScrollBarControl.FirstItem) {\r
       BootMenuData->ScrollBarControl.FirstItem = WantSelectItem;\r
-      BootMenuData->ScrollBarControl.LastItem = WantSelectItem + ItemCountPerScreen - 1;  \r
+      BootMenuData->ScrollBarControl.LastItem  = WantSelectItem + ItemCountPerScreen - 1;\r
     } else if (WantSelectItem > BootMenuData->ScrollBarControl.LastItem) {\r
-      BootMenuData->ScrollBarControl.FirstItem = WantSelectItem - ItemCountPerScreen + 1; \r
-      BootMenuData->ScrollBarControl.LastItem = WantSelectItem;\r
+      BootMenuData->ScrollBarControl.FirstItem = WantSelectItem - ItemCountPerScreen + 1;\r
+      BootMenuData->ScrollBarControl.LastItem  = WantSelectItem;\r
     }\r
+\r
     gST->ConOut->SetAttribute (gST->ConOut, EFI_WHITE | EFI_BACKGROUND_BLUE);\r
-    FirstItem = BootMenuData->ScrollBarControl.FirstItem;\r
-    LastItem  = BootMenuData->ScrollBarControl.LastItem;\r
+    FirstItem   = BootMenuData->ScrollBarControl.FirstItem;\r
+    LastItem    = BootMenuData->ScrollBarControl.LastItem;\r
     TopShadeNum = 0;\r
     if (FirstItem != 0) {\r
       TopShadeNum = (FirstItem * ItemCountPerScreen) / BootMenuData->ItemCount;\r
       if ((FirstItem * ItemCountPerScreen) % BootMenuData->ItemCount != 0) {\r
         TopShadeNum++;\r
       }\r
+\r
       PrintCol = StartCol  + BootMenuData->MenuScreen.Width - 2;\r
-      PrintRow = StartRow + TITLE_TOKEN_COUNT + 2;  \r
+      PrintRow = StartRow + TITLE_TOKEN_COUNT + 2;\r
       for (Index = 0; Index < TopShadeNum; Index++, PrintRow++) {\r
         PrintCharAt (PrintCol, PrintRow, BLOCKELEMENT_LIGHT_SHADE);\r
       }\r
     }\r
+\r
     LowShadeNum = 0;\r
     if (LastItem != BootMenuData->ItemCount - 1) {\r
       LowShadeNum = ((BootMenuData->ItemCount - 1 - LastItem) * ItemCountPerScreen) / BootMenuData->ItemCount;\r
       if (((BootMenuData->ItemCount - 1 - LastItem) * ItemCountPerScreen) % BootMenuData->ItemCount != 0) {\r
         LowShadeNum++;\r
       }\r
+\r
       PrintCol = StartCol  + BootMenuData->MenuScreen.Width - 2;\r
-      PrintRow = StartRow + TITLE_TOKEN_COUNT + 2 + ItemCountPerScreen - LowShadeNum;  \r
+      PrintRow = StartRow + TITLE_TOKEN_COUNT + 2 + ItemCountPerScreen - LowShadeNum;\r
       for (Index = 0; Index < LowShadeNum; Index++, PrintRow++) {\r
         PrintCharAt (PrintCol, PrintRow, BLOCKELEMENT_LIGHT_SHADE);\r
-      } \r
+      }\r
     }\r
+\r
     PrintCol = StartCol  + BootMenuData->MenuScreen.Width - 2;\r
-    PrintRow = StartRow + TITLE_TOKEN_COUNT + 2 + TopShadeNum;  \r
+    PrintRow = StartRow + TITLE_TOKEN_COUNT + 2 + TopShadeNum;\r
     for (Index = TopShadeNum; Index < ItemCountPerScreen - LowShadeNum; Index++, PrintRow++) {\r
       PrintCharAt (PrintCol, PrintRow, BLOCKELEMENT_FULL_BLOCK);\r
-    }      \r
-\r
+    }\r
 \r
     //\r
     // Clear selectable items first\r
     //\r
     PrintCol = StartCol  + 1;\r
-    PrintRow = StartRow + TITLE_TOKEN_COUNT + 2;  \r
-    String = AllocateZeroPool ((BootMenuData->MenuScreen.Width - 2) * sizeof (CHAR16));\r
+    PrintRow = StartRow + TITLE_TOKEN_COUNT + 2;\r
+    String   = AllocateZeroPool ((BootMenuData->MenuScreen.Width - 2) * sizeof (CHAR16));\r
     ASSERT (String != NULL);\r
     for (Index = 0; Index < BootMenuData->MenuScreen.Width - 3; Index++) {\r
       String[Index] = 0x20;\r
-    }      \r
-    for (Index = 0; Index < ItemCountPerScreen; Index++) {        \r
-      PrintStringAt (PrintCol, PrintRow + Index, String); \r
     }\r
+\r
+    for (Index = 0; Index < ItemCountPerScreen; Index++) {\r
+      PrintStringAt (PrintCol, PrintRow + Index, String);\r
+    }\r
+\r
     FreePool (String);\r
     //\r
-    // print selectable items  \r
+    // print selectable items\r
     //\r
     for (Index = 0; Index < ItemCountPerScreen; Index++, PrintRow++) {\r
       String = HiiGetString (gStringPackHandle, BootMenuData->PtrTokens[Index + FirstItem], NULL);\r
       PrintStringAt (PrintCol, PrintRow, String);\r
-      FreePool (String); \r
+      FreePool (String);\r
     }\r
+\r
     RePaintItems = TRUE;\r
   }\r
-  \r
-  //\r
-  // Print want to select item \r
-  //\r
-  FirstItem = BootMenuData->ScrollBarControl.FirstItem;\r
-  gST->ConOut->SetAttribute (gST->ConOut, EFI_WHITE | EFI_BACKGROUND_BLACK);\r
-  String = HiiGetString (gStringPackHandle, BootMenuData->PtrTokens[WantSelectItem], NULL);\r
-  PrintCol = StartCol  + 1;  \r
-  PrintRow = StartRow + TITLE_TOKEN_COUNT + 2 + WantSelectItem - FirstItem;  \r
-  PrintStringAt (PrintCol, PrintRow, String);\r
-  FreePool (String);\r
-  \r
+\r
   //\r
-  // if Want Select and selected item isn't the same and doesn't re-draw selectable \r
+  // if Want Select and selected item isn't the same and doesn't re-draw selectable\r
   // items, clear select item\r
   //\r
-  if (WantSelectItem != BootMenuData->SelectItem && !RePaintItems) {\r
+  FirstItem = BootMenuData->ScrollBarControl.FirstItem;\r
+  if ((WantSelectItem != BootMenuData->SelectItem) && !RePaintItems) {\r
     gST->ConOut->SetAttribute (gST->ConOut, EFI_WHITE | EFI_BACKGROUND_BLUE);\r
-    String = HiiGetString (gStringPackHandle, BootMenuData->PtrTokens[BootMenuData->SelectItem], NULL);\r
-    PrintCol = StartCol  + 1;  \r
-    PrintRow = StartRow + 3 + BootMenuData->SelectItem - FirstItem;  \r
+    String   = HiiGetString (gStringPackHandle, BootMenuData->PtrTokens[BootMenuData->SelectItem], NULL);\r
+    PrintCol = StartCol  + 1;\r
+    PrintRow = StartRow + 3 + BootMenuData->SelectItem - FirstItem;\r
     PrintStringAt (PrintCol, PrintRow, String);\r
-    FreePool (String);    \r
+    FreePool (String);\r
   }\r
 \r
+  //\r
+  // Print want to select item\r
+  //\r
+  gST->ConOut->SetAttribute (gST->ConOut, EFI_WHITE | EFI_BACKGROUND_BLACK);\r
+  String   = HiiGetString (gStringPackHandle, BootMenuData->PtrTokens[WantSelectItem], NULL);\r
+  PrintCol = StartCol  + 1;\r
+  PrintRow = StartRow + TITLE_TOKEN_COUNT + 2 + WantSelectItem - FirstItem;\r
+  PrintStringAt (PrintCol, PrintRow, String);\r
+  FreePool (String);\r
+\r
   gST->ConOut->SetAttribute (gST->ConOut, SavedAttribute);\r
   BootMenuData->SelectItem = WantSelectItem;\r
   return EFI_SUCCESS;\r
@@ -489,46 +566,47 @@ BootMenuSelectItem (
   This function uses to draw boot popup menu\r
 \r
   @param   BootMenuData           The Input BootMenuData to be processed.\r
-  \r
+\r
   @retval  EFI_SUCCESS            Draw boot popup menu successful.\r
 \r
 **/\r
-EFI_STATUS \r
+EFI_STATUS\r
 DrawBootPopupMenu (\r
   IN  BOOT_MENU_POPUP_DATA  *BootMenuData\r
   )\r
 {\r
-  EFI_STRING            String;\r
-  UINTN                 Index;\r
-  UINTN                 Width;  \r
-  UINTN                 StartCol;\r
-  UINTN                 StartRow;\r
-  UINTN                 PrintRow;\r
-  UINTN                 PrintCol;\r
-  UINTN                 LineWidth;\r
-  INT32                 SavedAttribute; \r
-  UINTN                 ItemCountPerScreen;  \r
+  EFI_STRING  String;\r
+  UINTN       Index;\r
+  UINTN       Width;\r
+  UINTN       StartCol;\r
+  UINTN       StartRow;\r
+  UINTN       PrintRow;\r
+  UINTN       PrintCol;\r
+  UINTN       LineWidth;\r
+  INT32       SavedAttribute;\r
+  UINTN       ItemCountPerScreen;\r
 \r
   gST->ConOut->ClearScreen (gST->ConOut);\r
-  \r
+\r
   SavedAttribute = gST->ConOut->Mode->Attribute;\r
   gST->ConOut->SetAttribute (gST->ConOut, EFI_WHITE | EFI_BACKGROUND_BLUE);\r
-  Width    = BootMenuData->MenuScreen.Width;\r
-  StartCol = BootMenuData->MenuScreen.StartCol;\r
-  StartRow = BootMenuData->MenuScreen.StartRow;\r
+  Width              = BootMenuData->MenuScreen.Width;\r
+  StartCol           = BootMenuData->MenuScreen.StartCol;\r
+  StartRow           = BootMenuData->MenuScreen.StartRow;\r
   ItemCountPerScreen = BootMenuData->ScrollBarControl.ItemCountPerScreen;\r
-  PrintRow = StartRow;\r
\r
+  PrintRow           = StartRow;\r
+\r
   gST->ConOut->EnableCursor (gST->ConOut, FALSE);\r
   //\r
   // Draw Boot popup menu screen\r
   //\r
   PrintCharAt (StartCol, PrintRow, BOXDRAW_DOWN_RIGHT);\r
   for (Index = 1; Index < Width - 1; Index++) {\r
-    PrintCharAt (StartCol + Index, PrintRow, BOXDRAW_HORIZONTAL); \r
+    PrintCharAt (StartCol + Index, PrintRow, BOXDRAW_HORIZONTAL);\r
   }\r
+\r
   PrintCharAt (StartCol + Width - 1, PrintRow, BOXDRAW_DOWN_LEFT);\r
-  \r
+\r
   //\r
   // Draw the screen for title\r
   //\r
@@ -540,18 +618,19 @@ DrawBootPopupMenu (
 \r
   for (Index = 0; Index < TITLE_TOKEN_COUNT; Index++) {\r
     PrintRow++;\r
-    PrintCharAt (StartCol, PrintRow, BOXDRAW_VERTICAL);  \r
+    PrintCharAt (StartCol, PrintRow, BOXDRAW_VERTICAL);\r
     PrintStringAt (StartCol + 1, PrintRow, String);\r
     PrintCharAt (StartCol + Width - 1, PrintRow, BOXDRAW_VERTICAL);\r
   }\r
-  \r
+\r
   PrintRow++;\r
   PrintCharAt (StartCol, PrintRow, BOXDRAW_VERTICAL_RIGHT);\r
   for (Index = 1; Index < Width - 1; Index++) {\r
-    PrintCharAt (StartCol + Index, PrintRow, BOXDRAW_HORIZONTAL); \r
+    PrintCharAt (StartCol + Index, PrintRow, BOXDRAW_HORIZONTAL);\r
   }\r
-  PrintCharAt (StartCol + Width - 1, PrintRow, BOXDRAW_VERTICAL_LEFT);  \r
-  \r
+\r
+  PrintCharAt (StartCol + Width - 1, PrintRow, BOXDRAW_VERTICAL_LEFT);\r
+\r
   //\r
   // Draw screen for selectable items\r
   //\r
@@ -560,15 +639,16 @@ DrawBootPopupMenu (
     PrintCharAt (StartCol, PrintRow, BOXDRAW_VERTICAL);\r
     PrintStringAt (StartCol + 1, PrintRow, String);\r
     PrintCharAt (StartCol + Width - 1, PrintRow, BOXDRAW_VERTICAL);\r
-  }  \r
+  }\r
 \r
   PrintRow++;\r
   PrintCharAt (StartCol, PrintRow, BOXDRAW_VERTICAL_RIGHT);\r
   for (Index = 1; Index < Width - 1; Index++) {\r
-    PrintCharAt (StartCol + Index, PrintRow, BOXDRAW_HORIZONTAL); \r
+    PrintCharAt (StartCol + Index, PrintRow, BOXDRAW_HORIZONTAL);\r
   }\r
+\r
   PrintCharAt (StartCol + Width - 1, PrintRow, BOXDRAW_VERTICAL_LEFT);\r
-  \r
+\r
   //\r
   // Draw screen for Help\r
   //\r
@@ -578,64 +658,65 @@ DrawBootPopupMenu (
     PrintStringAt (StartCol + 1, PrintRow, String);\r
     PrintCharAt (StartCol + Width - 1, PrintRow, BOXDRAW_VERTICAL);\r
   }\r
-  FreePool (String);  \r
-    \r
-  PrintRow++;  \r
+\r
+  FreePool (String);\r
+\r
+  PrintRow++;\r
   PrintCharAt (StartCol, PrintRow, BOXDRAW_UP_RIGHT);\r
   for (Index = 1; Index < Width - 1; Index++) {\r
-    PrintCharAt (StartCol + Index, PrintRow, BOXDRAW_HORIZONTAL); \r
+    PrintCharAt (StartCol + Index, PrintRow, BOXDRAW_HORIZONTAL);\r
   }\r
-  PrintCharAt (StartCol + Width - 1, PrintRow, BOXDRAW_UP_LEFT);        \r
-  \r
-  \r
+\r
+  PrintCharAt (StartCol + Width - 1, PrintRow, BOXDRAW_UP_LEFT);\r
+\r
   //\r
   // print title strings\r
   //\r
   PrintRow = StartRow + 1;\r
   for (Index = 0; Index < TITLE_TOKEN_COUNT; Index++, PrintRow++) {\r
-    String = HiiGetString (gStringPackHandle, BootMenuData->TitleToken[Index], NULL);\r
-    LineWidth = GetLineWidth (BootMenuData->TitleToken[Index]);      \r
-    PrintCol = StartCol + (Width - LineWidth) / 2;\r
+    String    = HiiGetString (gStringPackHandle, BootMenuData->TitleToken[Index], NULL);\r
+    LineWidth = GetLineWidth (BootMenuData->TitleToken[Index]);\r
+    PrintCol  = StartCol + (Width - LineWidth) / 2;\r
     PrintStringAt (PrintCol, PrintRow, String);\r
     FreePool (String);\r
   }\r
-  \r
+\r
   //\r
   // print selectable items\r
   //\r
   PrintCol = StartCol + 1;\r
-  PrintRow = StartRow + TITLE_TOKEN_COUNT + 2;  \r
+  PrintRow = StartRow + TITLE_TOKEN_COUNT + 2;\r
   for (Index = 0; Index < ItemCountPerScreen; Index++, PrintRow++) {\r
     String = HiiGetString (gStringPackHandle, BootMenuData->PtrTokens[Index], NULL);\r
     PrintStringAt (PrintCol, PrintRow, String);\r
-    FreePool (String); \r
+    FreePool (String);\r
   }\r
-  \r
+\r
   //\r
   // Print Help strings\r
   //\r
   PrintRow++;\r
   for (Index = 0; Index < HELP_TOKEN_COUNT; Index++, PrintRow++) {\r
-    String = HiiGetString (gStringPackHandle, BootMenuData->HelpToken[Index], NULL);\r
+    String    = HiiGetString (gStringPackHandle, BootMenuData->HelpToken[Index], NULL);\r
     LineWidth = GetLineWidth (BootMenuData->HelpToken[Index]);\r
-    PrintCol = StartCol + (Width - LineWidth) / 2;\r
+    PrintCol  = StartCol + (Width - LineWidth) / 2;\r
     PrintStringAt (PrintCol, PrintRow, String);\r
     FreePool (String);\r
   }\r
-  \r
+\r
   //\r
   // Print scroll bar if has scroll bar\r
   //\r
   if (BootMenuData->ScrollBarControl.HasScrollBar) {\r
     PrintCol = StartCol + Width - 2;\r
-    PrintRow = StartRow + 2; \r
-    PrintCharAt (PrintCol, PrintRow, GEOMETRICSHAPE_UP_TRIANGLE); \r
-    PrintCharAt (PrintCol + 1, PrintRow, BOXDRAW_VERTICAL); \r
-    PrintRow += (ItemCountPerScreen + 1);    \r
+    PrintRow = StartRow + 2;\r
+    PrintCharAt (PrintCol, PrintRow, GEOMETRICSHAPE_UP_TRIANGLE);\r
+    PrintCharAt (PrintCol + 1, PrintRow, BOXDRAW_VERTICAL);\r
+    PrintRow += (ItemCountPerScreen + 1);\r
     PrintCharAt (PrintCol, PrintRow, GEOMETRICSHAPE_DOWN_TRIANGLE);\r
-    PrintCharAt (PrintCol + 1, PrintRow, BOXDRAW_VERTICAL); \r
-  }  \r
-    \r
+    PrintCharAt (PrintCol + 1, PrintRow, BOXDRAW_VERTICAL);\r
+  }\r
+\r
   gST->ConOut->SetAttribute (gST->ConOut, SavedAttribute);\r
   //\r
   // Print Selected item\r
@@ -645,7 +726,7 @@ DrawBootPopupMenu (
 }\r
 \r
 /**\r
-  This function uses to boot from selected item \r
+  This function uses to boot from selected item\r
 \r
   @param   BootOptions            Pointer to EFI_BOOT_MANAGER_LOAD_OPTION array.\r
   @param   BootOptionCount        Number of boot option.\r
@@ -654,12 +735,12 @@ DrawBootPopupMenu (
 VOID\r
 BootFromSelectOption (\r
   IN   EFI_BOOT_MANAGER_LOAD_OPTION  *BootOptions,\r
-  IN   UINTN                         BootOptionCount, \r
+  IN   UINTN                         BootOptionCount,\r
   IN   UINTN                         SelectItem\r
   )\r
 {\r
-  UINTN                 ItemNum;\r
-  UINTN                 Index;\r
+  UINTN  ItemNum;\r
+  UINTN  Index;\r
 \r
   ASSERT (BootOptions != NULL);\r
 \r
@@ -677,9 +758,9 @@ BootFromSelectOption (
 \r
 /**\r
   This function will change video resolution and text mode\r
-  according to defined setup mode or defined boot mode  \r
+  according to defined setup mode or defined boot mode\r
 \r
-  @param  IsSetupMode   Indicate mode is changed to setup mode or boot mode. \r
+  @param  IsSetupMode   Indicate mode is changed to setup mode or boot mode.\r
 \r
   @retval  EFI_SUCCESS  Mode is changed successfully.\r
   @retval  Others             Mode failed to be changed.\r
@@ -707,18 +788,18 @@ BdsSetConsoleMode (
   EFI_STATUS                            Status;\r
   UINTN                                 Index;\r
   UINTN                                 CurrentColumn;\r
-  UINTN                                 CurrentRow;  \r
+  UINTN                                 CurrentRow;\r
 \r
   MaxGopMode  = 0;\r
   MaxTextMode = 0;\r
 \r
   //\r
-  // Get current video resolution and text mode \r
+  // Get current video resolution and text mode\r
   //\r
   Status = gBS->HandleProtocol (\r
                   gST->ConsoleOutHandle,\r
                   &gEfiGraphicsOutputProtocolGuid,\r
-                  (VOID**)&GraphicsOutput\r
+                  (VOID **)&GraphicsOutput\r
                   );\r
   if (EFI_ERROR (Status)) {\r
     GraphicsOutput = NULL;\r
@@ -727,11 +808,11 @@ BdsSetConsoleMode (
   Status = gBS->HandleProtocol (\r
                   gST->ConsoleOutHandle,\r
                   &gEfiSimpleTextOutProtocolGuid,\r
-                  (VOID**)&SimpleTextOut\r
+                  (VOID **)&SimpleTextOut\r
                   );\r
   if (EFI_ERROR (Status)) {\r
     SimpleTextOut = NULL;\r
-  }  \r
+  }\r
 \r
   if ((GraphicsOutput == NULL) || (SimpleTextOut == NULL)) {\r
     return EFI_UNSUPPORTED;\r
@@ -752,12 +833,12 @@ BdsSetConsoleMode (
     NewHorizontalResolution = mBootHorizontalResolution;\r
     NewVerticalResolution   = mBootVerticalResolution;\r
     NewColumns              = mBootTextModeColumn;\r
-    NewRows                 = mBootTextModeRow;   \r
+    NewRows                 = mBootTextModeRow;\r
   }\r
-  \r
+\r
   if (GraphicsOutput != NULL) {\r
-    MaxGopMode  = GraphicsOutput->Mode->MaxMode;\r
-  } \r
+    MaxGopMode = GraphicsOutput->Mode->MaxMode;\r
+  }\r
 \r
   if (SimpleTextOut != NULL) {\r
     MaxTextMode = SimpleTextOut->Mode->MaxMode;\r
@@ -772,22 +853,24 @@ BdsSetConsoleMode (
   //\r
   for (ModeNumber = 0; ModeNumber < MaxGopMode; ModeNumber++) {\r
     Status = GraphicsOutput->QueryMode (\r
-                       GraphicsOutput,\r
-                       ModeNumber,\r
-                       &SizeOfInfo,\r
-                       &Info\r
-                       );\r
+                               GraphicsOutput,\r
+                               ModeNumber,\r
+                               &SizeOfInfo,\r
+                               &Info\r
+                               );\r
     if (!EFI_ERROR (Status)) {\r
       if ((Info->HorizontalResolution == NewHorizontalResolution) &&\r
-          (Info->VerticalResolution == NewVerticalResolution)) {\r
+          (Info->VerticalResolution == NewVerticalResolution))\r
+      {\r
         if ((GraphicsOutput->Mode->Info->HorizontalResolution == NewHorizontalResolution) &&\r
-            (GraphicsOutput->Mode->Info->VerticalResolution == NewVerticalResolution)) {\r
+            (GraphicsOutput->Mode->Info->VerticalResolution == NewVerticalResolution))\r
+        {\r
           //\r
           // Current resolution is same with required resolution, check if text mode need be set\r
           //\r
           Status = SimpleTextOut->QueryMode (SimpleTextOut, SimpleTextOut->Mode->Mode, &CurrentColumn, &CurrentRow);\r
           ASSERT_EFI_ERROR (Status);\r
-          if (CurrentColumn == NewColumns && CurrentRow == NewRows) {\r
+          if ((CurrentColumn == NewColumns) && (CurrentRow == NewRows)) {\r
             //\r
             // If current text mode is same with required text mode. Do nothing\r
             //\r
@@ -799,7 +882,7 @@ BdsSetConsoleMode (
             //\r
             for (Index = 0; Index < MaxTextMode; Index++) {\r
               Status = SimpleTextOut->QueryMode (SimpleTextOut, Index, &CurrentColumn, &CurrentRow);\r
-              if (!EFI_ERROR(Status)) {\r
+              if (!EFI_ERROR (Status)) {\r
                 if ((CurrentColumn == NewColumns) && (CurrentRow == NewRows)) {\r
                   //\r
                   // Required text mode is supported, set it.\r
@@ -818,6 +901,7 @@ BdsSetConsoleMode (
                 }\r
               }\r
             }\r
+\r
             if (Index == MaxTextMode) {\r
               //\r
               // If required text mode is not supported, return error.\r
@@ -838,6 +922,7 @@ BdsSetConsoleMode (
           }\r
         }\r
       }\r
+\r
       FreePool (Info);\r
     }\r
   }\r
@@ -861,26 +946,28 @@ BdsSetConsoleMode (
   ASSERT_EFI_ERROR (Status);\r
   Status = PcdSet32S (PcdConOutRow, NewRows);\r
   ASSERT_EFI_ERROR (Status);\r
-  \r
+\r
   //\r
   // Video mode is changed, so restart graphics console driver and higher level driver.\r
   // Reconnect graphics console driver and higher level driver.\r
   // Locate all the handles with GOP protocol and reconnect it.\r
   //\r
   Status = gBS->LocateHandleBuffer (\r
-                   ByProtocol,\r
-                   &gEfiSimpleTextOutProtocolGuid,\r
-                   NULL,\r
-                   &HandleCount,\r
-                   &HandleBuffer\r
-                   );\r
+                  ByProtocol,\r
+                  &gEfiSimpleTextOutProtocolGuid,\r
+                  NULL,\r
+                  &HandleCount,\r
+                  &HandleBuffer\r
+                  );\r
   if (!EFI_ERROR (Status)) {\r
     for (Index = 0; Index < HandleCount; Index++) {\r
       gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);\r
     }\r
+\r
     for (Index = 0; Index < HandleCount; Index++) {\r
       gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);\r
     }\r
+\r
     if (HandleBuffer != NULL) {\r
       FreePool (HandleBuffer);\r
     }\r
@@ -894,37 +981,37 @@ BdsSetConsoleMode (
 \r
   @param   ImageHandle     The image handle.\r
   @param   SystemTable     The system table.\r
-  \r
+\r
   @retval  EFI_SUCCESS          Boot from selected boot option, and return success from boot option\r
   @retval  EFI_NOT_FOUND        User select to enter setup or can not find boot option\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 BootManagerMenuEntry (\r
-  IN EFI_HANDLE                            ImageHandle,\r
-  IN EFI_SYSTEM_TABLE                      *SystemTable\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
   )\r
 {\r
-  EFI_BOOT_MANAGER_LOAD_OPTION    *BootOption;\r
-  UINTN                           BootOptionCount;  \r
-  EFI_STATUS                      Status;\r
-  BOOT_MENU_POPUP_DATA            BootMenuData;\r
-  UINTN                           Index;\r
-  EFI_INPUT_KEY                   Key;\r
-  BOOLEAN                         ExitApplication;\r
-  UINTN                           SelectItem;\r
-  EFI_BOOT_LOGO_PROTOCOL          *BootLogo;\r
-  EFI_GRAPHICS_OUTPUT_PROTOCOL    *GraphicsOutput;\r
-  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut;\r
-  UINTN                           BootTextColumn;\r
-  UINTN                           BootTextRow;\r
+  EFI_BOOT_MANAGER_LOAD_OPTION     *BootOption;\r
+  UINTN                            BootOptionCount;\r
+  EFI_STATUS                       Status;\r
+  BOOT_MENU_POPUP_DATA             BootMenuData;\r
+  UINTN                            Index;\r
+  EFI_INPUT_KEY                    Key;\r
+  BOOLEAN                          ExitApplication;\r
+  UINTN                            SelectItem;\r
+  EFI_BOOT_LOGO_PROTOCOL           *BootLogo;\r
+  EFI_GRAPHICS_OUTPUT_PROTOCOL     *GraphicsOutput;\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *SimpleTextOut;\r
+  UINTN                            BootTextColumn;\r
+  UINTN                            BootTextRow;\r
 \r
   //\r
   // Set Logo status invalid when boot manager menu is launched\r
   //\r
   BootLogo = NULL;\r
-  Status = gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (VOID **) &BootLogo);\r
+  Status   = gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (VOID **)&BootLogo);\r
   if (!EFI_ERROR (Status) && (BootLogo != NULL)) {\r
     Status = BootLogo->SetBootLogo (BootLogo, NULL, 0, 0, 0, 0);\r
     ASSERT_EFI_ERROR (Status);\r
@@ -933,11 +1020,11 @@ BootManagerMenuEntry (
   gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);\r
 \r
   gStringPackHandle = HiiAddPackages (\r
-                         &gEfiCallerIdGuid,\r
-                         gImageHandle,\r
-                         BootManagerMenuAppStrings,\r
-                         NULL\r
-                         );\r
+                        &gEfiCallerIdGuid,\r
+                        gImageHandle,\r
+                        BootManagerMenuAppStrings,\r
+                        NULL\r
+                        );\r
   ASSERT (gStringPackHandle != NULL);\r
 \r
   //\r
@@ -950,26 +1037,26 @@ BootManagerMenuEntry (
 \r
   if (!mModeInitialized) {\r
     //\r
-    // After the console is ready, get current video resolution \r
+    // After the console is ready, get current video resolution\r
     // and text mode before launching setup at first time.\r
     //\r
     Status = gBS->HandleProtocol (\r
                     gST->ConsoleOutHandle,\r
                     &gEfiGraphicsOutputProtocolGuid,\r
-                    (VOID**)&GraphicsOutput\r
+                    (VOID **)&GraphicsOutput\r
                     );\r
     if (EFI_ERROR (Status)) {\r
       GraphicsOutput = NULL;\r
     }\r
-    \r
+\r
     Status = gBS->HandleProtocol (\r
                     gST->ConsoleOutHandle,\r
                     &gEfiSimpleTextOutProtocolGuid,\r
-                    (VOID**)&SimpleTextOut\r
+                    (VOID **)&SimpleTextOut\r
                     );\r
     if (EFI_ERROR (Status)) {\r
       SimpleTextOut = NULL;\r
-    }  \r
+    }\r
 \r
     if (GraphicsOutput != NULL) {\r
       //\r
@@ -992,14 +1079,14 @@ BootManagerMenuEntry (
 \r
     //\r
     // Get user defined text mode for setup.\r
-    //  \r
+    //\r
     mSetupHorizontalResolution = PcdGet32 (PcdSetupVideoHorizontalResolution);\r
-    mSetupVerticalResolution   = PcdGet32 (PcdSetupVideoVerticalResolution);      \r
+    mSetupVerticalResolution   = PcdGet32 (PcdSetupVideoVerticalResolution);\r
     mSetupTextModeColumn       = PcdGet32 (PcdSetupConOutColumn);\r
     mSetupTextModeRow          = PcdGet32 (PcdSetupConOutRow);\r
     mModeInitialized           = TRUE;\r
   }\r
-  \r
+\r
   //\r
   // Set back to conventional setup resolution\r
   //\r
@@ -1013,7 +1100,7 @@ BootManagerMenuEntry (
   // According to boot menu data to draw boot popup menu\r
   //\r
   DrawBootPopupMenu (&BootMenuData);\r
-  \r
+\r
   //\r
   // check user input to determine want to re-draw or boot from user selected item\r
   //\r
@@ -1023,58 +1110,57 @@ BootManagerMenuEntry (
     Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
     if (!EFI_ERROR (Status)) {\r
       switch (Key.UnicodeChar) {\r
-      \r
-      case CHAR_NULL:        \r
-        switch (Key.ScanCode) {          \r
-          \r
-        case SCAN_UP:\r
-          SelectItem = BootMenuData.SelectItem == 0 ? BootMenuData.ItemCount - 1 : BootMenuData.SelectItem - 1;\r
-          BootMenuSelectItem (SelectItem, &BootMenuData); \r
-          break;\r
-        \r
-        case SCAN_DOWN:\r
-          SelectItem = BootMenuData.SelectItem == BootMenuData.ItemCount - 1 ? 0 : BootMenuData.SelectItem + 1;\r
-          BootMenuSelectItem (SelectItem, &BootMenuData); \r
+        case CHAR_NULL:\r
+          switch (Key.ScanCode) {\r
+            case SCAN_UP:\r
+              SelectItem = BootMenuData.SelectItem == 0 ? BootMenuData.ItemCount - 1 : BootMenuData.SelectItem - 1;\r
+              BootMenuSelectItem (SelectItem, &BootMenuData);\r
+              break;\r
+\r
+            case SCAN_DOWN:\r
+              SelectItem = BootMenuData.SelectItem == BootMenuData.ItemCount - 1 ? 0 : BootMenuData.SelectItem + 1;\r
+              BootMenuSelectItem (SelectItem, &BootMenuData);\r
+              break;\r
+\r
+            case SCAN_ESC:\r
+              gST->ConOut->ClearScreen (gST->ConOut);\r
+              ExitApplication = TRUE;\r
+              //\r
+              // Set boot resolution for normal boot\r
+              //\r
+              BdsSetConsoleMode (FALSE);\r
+              break;\r
+\r
+            default:\r
+              break;\r
+          }\r
+\r
           break;\r
 \r
-        case SCAN_ESC:\r
+        case CHAR_CARRIAGE_RETURN:\r
           gST->ConOut->ClearScreen (gST->ConOut);\r
-          ExitApplication = TRUE;\r
           //\r
           // Set boot resolution for normal boot\r
           //\r
           BdsSetConsoleMode (FALSE);\r
+          BootFromSelectOption (BootOption, BootOptionCount, BootMenuData.SelectItem);\r
+          //\r
+          // Back to boot manager menu again, set back to setup resolution\r
+          //\r
+          BdsSetConsoleMode (TRUE);\r
+          DrawBootPopupMenu (&BootMenuData);\r
           break;\r
-          \r
+\r
         default:\r
           break;\r
-        }\r
-        break;\r
-        \r
-      case CHAR_CARRIAGE_RETURN:\r
-        gST->ConOut->ClearScreen (gST->ConOut);\r
-        //\r
-        // Set boot resolution for normal boot\r
-        //\r
-        BdsSetConsoleMode (FALSE);\r
-        BootFromSelectOption (BootOption, BootOptionCount, BootMenuData.SelectItem);\r
-        //\r
-        // Back to boot manager menu again, set back to setup resolution\r
-        //\r
-        BdsSetConsoleMode (TRUE);\r
-        DrawBootPopupMenu (&BootMenuData);\r
-        break;\r
-        \r
-      default:\r
-        break;\r
       }\r
     }\r
   }\r
+\r
   EfiBootManagerFreeLoadOptions (BootOption, BootOptionCount);\r
   FreePool (BootMenuData.PtrTokens);\r
 \r
   HiiRemovePackages (gStringPackHandle);\r
 \r
   return Status;\r
-  \r
 }\r