]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c
MdeModulePkg: Removing ipf which is no longer supported from edk2.
[mirror_edk2.git] / MdeModulePkg / Application / BootManagerMenuApp / BootManagerMenu.c
index a8d5c0367495b9223f61d2127e1d78a7084f2d5c..6a6b19ad09d8040408da71e95acfea0744399b55 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The application to show the Boot Manager Menu.\r
 \r
-Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2011 - 2018, 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
@@ -57,7 +57,7 @@ PrintStringAt (
 }\r
 \r
 /**\r
-  Prints a chracter to the default console, at\r
+  Prints a character to the default console, at\r
   the supplied cursor position, using L"%c" format.\r
 \r
   @param  Column     The cursor position to print the string at.\r
@@ -79,7 +79,7 @@ PrintCharAt (
 }\r
 \r
 /**\r
-  Count the storage space of a Unicode string which uses current lanaguag to get \r
+  Count the storage space of a Unicode string which uses current language to get\r
   from input string ID.\r
 \r
   @param StringId          The input string to be counted.\r
@@ -91,19 +91,19 @@ UINTN
 GetLineWidth (\r
   IN EFI_STRING_ID       StringId\r
   )\r
-{  \r
+{\r
   UINTN        Index;\r
   UINTN        IncrementValue;\r
   EFI_STRING   String;\r
   UINTN        LineWidth;\r
-  \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
+\r
     do {\r
       //\r
       // Advance to the null-terminator or to the first width directive\r
@@ -113,7 +113,7 @@ GetLineWidth (
            Index++, LineWidth = LineWidth + IncrementValue\r
           )\r
         ;\r
-    \r
+\r
       //\r
       // We hit the null-terminator, we now have a count\r
       //\r
@@ -137,23 +137,23 @@ GetLineWidth (
         Index++;\r
         IncrementValue = 2;\r
       }\r
-    } while (String[Index] != 0);   \r
+    } while (String[Index] != 0);\r
     FreePool (String);\r
   }\r
-  \r
-  return LineWidth;  \r
+\r
+  return LineWidth;\r
 }\r
 \r
 /**\r
   This function uses calculate the boot menu location, size and scroll bar information.\r
 \r
-  @param  BootMenuData            The boot menu data to be proccessed.\r
+  @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
@@ -172,21 +172,21 @@ InitializeBootMenuScreen (
   //\r
   // Get maximum string width\r
   //\r
-  MaxStrWidth = 0;  \r
-  for (Index = 0; Index < TITLE_TOKEN_COUNT; 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
+    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
   // query current row and column to calculate boot menu location\r
   //\r
@@ -195,10 +195,10 @@ 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
+                 );\r
+\r
+  MaxPrintRows = Row - 6;\r
+  UnSelectableItmes = TITLE_TOKEN_COUNT + 2 + HELP_TOKEN_COUNT + 2;\r
   BootMenuData->MenuScreen.Width = MaxStrWidth + 8;\r
   if (BootMenuData->ItemCount + UnSelectableItmes > MaxPrintRows) {\r
     BootMenuData->MenuScreen.Height = MaxPrintRows;\r
@@ -211,18 +211,18 @@ InitializeBootMenuScreen (
     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.LastItem = BootMenuData->ItemCount - 1;\r
   }\r
-  BootMenuData->MenuScreen.StartCol = (Column -  BootMenuData->MenuScreen.Width) / 2;              \r
-  BootMenuData->MenuScreen.StartRow = (Row -  BootMenuData->MenuScreen.Height) / 2;  \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
-  This funciton uses check boot option is wheher setup application or no\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
@@ -242,17 +242,58 @@ IsBootManagerMenu (
 \r
   return (BOOLEAN) (!EFI_ERROR (Status) && (BootOption->OptionNumber == BootManagerMenu.OptionNumber));\r
 }\r
\r
 \r
 /**\r
-  This funciton uses to initialize boot menu data\r
+  Return whether to ignore the boot option.\r
+\r
+  @param BootOption  Pointer to EFI_BOOT_MANAGER_LOAD_OPTION to check.\r
+\r
+  @retval TRUE  Ignore the boot option.\r
+  @retval FALSE Do not ignore the boot option.\r
+**/\r
+BOOLEAN\r
+IgnoreBootOption (\r
+  IN   EFI_BOOT_MANAGER_LOAD_OPTION  *BootOption\r
+  )\r
+{\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
+  ASSERT_EFI_ERROR (Status);\r
+  if (CompareMem (BootOption->FilePath, ImageDevicePath, GetDevicePathSize (ImageDevicePath)) == 0) {\r
+    return TRUE;\r
+  }\r
+\r
+  //\r
+  // Do not ignore Boot Manager Menu.\r
+  //\r
+  if (IsBootManagerMenu (BootOption)) {\r
+    return FALSE;\r
+  }\r
+\r
+  //\r
+  // Ignore the hidden/inactive boot option.\r
+  //\r
+  if (((BootOption->Attributes & LOAD_OPTION_HIDDEN) != 0) || ((BootOption->Attributes & LOAD_OPTION_ACTIVE) == 0)) {\r
+    return TRUE;\r
+  }\r
+\r
+  return FALSE;\r
+}\r
+\r
+/**\r
+  This function uses to initialize boot menu data\r
 \r
   @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
@@ -262,18 +303,13 @@ InitializeBootMenuData (
   OUT  BOOT_MENU_POPUP_DATA          *BootMenuData\r
   )\r
 {\r
-  EFI_STATUS                    Status;\r
   UINTN                         Index;\r
   UINTN                         StrIndex;\r
-  EFI_DEVICE_PATH_PROTOCOL      *ImageDevicePath;\r
-      \r
+\r
   if (BootOption == NULL || BootMenuData == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  Status = gBS->HandleProtocol (gImageHandle, &gEfiLoadedImageDevicePathProtocolGuid, (VOID **) &ImageDevicePath);\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
   BootMenuData->TitleToken[0] = STRING_TOKEN (STR_BOOT_POPUP_MENU_TITLE_STRING);\r
   BootMenuData->PtrTokens     = AllocateZeroPool (BootOptionCount * sizeof (EFI_STRING_ID));\r
   ASSERT (BootMenuData->PtrTokens != NULL);\r
@@ -282,49 +318,38 @@ InitializeBootMenuData (
   // Skip boot option which created by BootNext Variable\r
   //\r
   for (StrIndex = 0, Index = 0; Index < BootOptionCount; Index++) {\r
-    //\r
-    // Don't display the hidden/inactive boot option except setup application.\r
-    //\r
-    if ((((BootOption[Index].Attributes & LOAD_OPTION_HIDDEN) != 0) || ((BootOption[Index].Attributes & LOAD_OPTION_ACTIVE) == 0)) &&\r
-        !IsBootManagerMenu (&BootOption[Index])) {      \r
-      continue;\r
-    }\r
-\r
-    //\r
-    // Don't display myself\r
-    //\r
-    if (CompareMem (BootOption[Index].FilePath, ImageDevicePath, GetDevicePathSize (ImageDevicePath)) == 0) {\r
+    if (IgnoreBootOption (&BootOption[Index])) {\r
       continue;\r
     }\r
 \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
   and set current selected item in BootMenuData\r
 \r
   @param  WantSelectItem          The user wants to select item.\r
-  @param  BootMenuData            The boot menu data to be proccessed\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
@@ -334,7 +359,7 @@ BootMenuSelectItem (
 {\r
   INT32                 SavedAttribute;\r
   EFI_STRING            String;\r
-  UINTN                 StartCol;  \r
+  UINTN                 StartCol;\r
   UINTN                 StartRow;\r
   UINTN                 PrintCol;\r
   UINTN                 PrintRow;\r
@@ -345,30 +370,31 @@ BootMenuSelectItem (
   UINTN                 ItemCountPerScreen;\r
   UINTN                 Index;\r
   BOOLEAN               RePaintItems;\r
-  \r
+\r
   if (BootMenuData == NULL || WantSelectItem >= BootMenuData->ItemCount) {\r
     return EFI_INVALID_PARAMETER;\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
   //\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
+      WantSelectItem == BootMenuData->SelectItem)) {\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.FirstItem = WantSelectItem - ItemCountPerScreen + 1;\r
       BootMenuData->ScrollBarControl.LastItem = WantSelectItem;\r
     }\r
     gST->ConOut->SetAttribute (gST->ConOut, EFI_WHITE | EFI_BACKGROUND_BLUE);\r
@@ -381,7 +407,7 @@ BootMenuSelectItem (
         TopShadeNum++;\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
@@ -393,65 +419,65 @@ BootMenuSelectItem (
         LowShadeNum++;\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
     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
+    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
+    for (Index = 0; Index < ItemCountPerScreen; Index++) {\r
+      PrintStringAt (PrintCol, PrintRow + Index, String);\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
     RePaintItems = TRUE;\r
   }\r
-  \r
+\r
   //\r
-  // Print want to select item \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
+  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
     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
+    PrintCol = StartCol  + 1;\r
+    PrintRow = StartRow + 3 + BootMenuData->SelectItem - FirstItem;\r
     PrintStringAt (PrintCol, PrintRow, String);\r
-    FreePool (String);    \r
+    FreePool (String);\r
   }\r
 \r
   gST->ConOut->SetAttribute (gST->ConOut, SavedAttribute);\r
@@ -460,51 +486,49 @@ BootMenuSelectItem (
 }\r
 \r
 /**\r
-  This funciton uses to draw boot popup menu\r
+  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                 Height;\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
+  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
-  Height   = BootMenuData->MenuScreen.Height;\r
   StartCol = BootMenuData->MenuScreen.StartCol;\r
   StartRow = BootMenuData->MenuScreen.StartRow;\r
   ItemCountPerScreen = BootMenuData->ScrollBarControl.ItemCountPerScreen;\r
   PrintRow = StartRow;\r
\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
   PrintCharAt (StartCol + Width - 1, PrintRow, BOXDRAW_DOWN_LEFT);\r
-  \r
+\r
   //\r
   // Draw the screen for title\r
   //\r
@@ -516,18 +540,18 @@ 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
+  PrintCharAt (StartCol + Width - 1, PrintRow, BOXDRAW_VERTICAL_LEFT);\r
+\r
   //\r
   // Draw screen for selectable items\r
   //\r
@@ -536,15 +560,15 @@ 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
   PrintCharAt (StartCol + Width - 1, PrintRow, BOXDRAW_VERTICAL_LEFT);\r
-  \r
+\r
   //\r
   // Draw screen for Help\r
   //\r
@@ -554,39 +578,39 @@ DrawBootPopupMenu (
     PrintStringAt (StartCol + 1, PrintRow, String);\r
     PrintCharAt (StartCol + Width - 1, PrintRow, BOXDRAW_VERTICAL);\r
   }\r
-  FreePool (String);  \r
-    \r
-  PrintRow++;  \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
+  PrintCharAt (StartCol + Width - 1, PrintRow, BOXDRAW_UP_LEFT);\r
+\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
+    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
@@ -598,20 +622,20 @@ DrawBootPopupMenu (
     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
@@ -621,7 +645,7 @@ DrawBootPopupMenu (
 }\r
 \r
 /**\r
-  This funciton 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
@@ -630,7 +654,7 @@ 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
@@ -640,13 +664,10 @@ BootFromSelectOption (
   ASSERT (BootOptions != NULL);\r
 \r
   for (ItemNum = 0, Index = 0; Index < BootOptionCount; Index++) {\r
-    //\r
-    // Don't display the hidden/inactive boot option except setup application.\r
-    //\r
-    if ((((BootOptions[Index].Attributes & LOAD_OPTION_HIDDEN) != 0) || ((BootOptions[Index].Attributes & LOAD_OPTION_ACTIVE) == 0)) &&\r
-        !IsBootManagerMenu (&BootOptions[Index])) {      \r
+    if (IgnoreBootOption (&BootOptions[Index])) {\r
       continue;\r
     }\r
+\r
     if (ItemNum++ == SelectItem) {\r
       EfiBootManagerBoot (&BootOptions[Index]);\r
       break;\r
@@ -656,9 +677,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
@@ -686,13 +707,13 @@ 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
@@ -710,7 +731,7 @@ BdsSetConsoleMode (
                   );\r
   if (EFI_ERROR (Status)) {\r
     SimpleTextOut = NULL;\r
-  }  \r
+  }\r
 \r
   if ((GraphicsOutput == NULL) || (SimpleTextOut == NULL)) {\r
     return EFI_UNSUPPORTED;\r
@@ -718,7 +739,7 @@ BdsSetConsoleMode (
 \r
   if (IsSetupMode) {\r
     //\r
-    // The requried resolution and text mode is setup mode.\r
+    // The required resolution and text mode is setup mode.\r
     //\r
     NewHorizontalResolution = mSetupHorizontalResolution;\r
     NewVerticalResolution   = mSetupVerticalResolution;\r
@@ -731,12 +752,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
+  }\r
 \r
   if (SimpleTextOut != NULL) {\r
     MaxTextMode = SimpleTextOut->Mode->MaxMode;\r
@@ -774,7 +795,7 @@ BdsSetConsoleMode (
             return EFI_SUCCESS;\r
           } else {\r
             //\r
-            // If current text mode is different from requried text mode.  Set new video mode\r
+            // If current text mode is different from required text mode.  Set new video mode\r
             //\r
             for (Index = 0; Index < MaxTextMode; Index++) {\r
               Status = SimpleTextOut->QueryMode (SimpleTextOut, Index, &CurrentColumn, &CurrentRow);\r
@@ -799,7 +820,7 @@ BdsSetConsoleMode (
             }\r
             if (Index == MaxTextMode) {\r
               //\r
-              // If requried text mode is not supported, return error.\r
+              // If required text mode is not supported, return error.\r
               //\r
               FreePool (Info);\r
               return EFI_UNSUPPORTED;\r
@@ -840,7 +861,7 @@ 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
@@ -873,10 +894,10 @@ 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
@@ -886,7 +907,7 @@ BootManagerMenuEntry (
   )\r
 {\r
   EFI_BOOT_MANAGER_LOAD_OPTION    *BootOption;\r
-  UINTN                           BootOptionCount;  \r
+  UINTN                           BootOptionCount;\r
   EFI_STATUS                      Status;\r
   BOOT_MENU_POPUP_DATA            BootMenuData;\r
   UINTN                           Index;\r
@@ -929,7 +950,7 @@ 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
@@ -940,7 +961,7 @@ BootManagerMenuEntry (
     if (EFI_ERROR (Status)) {\r
       GraphicsOutput = NULL;\r
     }\r
-    \r
+\r
     Status = gBS->HandleProtocol (\r
                     gST->ConsoleOutHandle,\r
                     &gEfiSimpleTextOutProtocolGuid,\r
@@ -948,7 +969,7 @@ BootManagerMenuEntry (
                     );\r
     if (EFI_ERROR (Status)) {\r
       SimpleTextOut = NULL;\r
-    }  \r
+    }\r
 \r
     if (GraphicsOutput != NULL) {\r
       //\r
@@ -971,14 +992,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
@@ -992,7 +1013,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
@@ -1002,18 +1023,18 @@ 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
+\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
+          BootMenuSelectItem (SelectItem, &BootMenuData);\r
           break;\r
-        \r
+\r
         case SCAN_DOWN:\r
           SelectItem = BootMenuData.SelectItem == BootMenuData.ItemCount - 1 ? 0 : BootMenuData.SelectItem + 1;\r
-          BootMenuSelectItem (SelectItem, &BootMenuData); \r
+          BootMenuSelectItem (SelectItem, &BootMenuData);\r
           break;\r
 \r
         case SCAN_ESC:\r
@@ -1024,12 +1045,12 @@ BootManagerMenuEntry (
           //\r
           BdsSetConsoleMode (FALSE);\r
           break;\r
-          \r
+\r
         default:\r
           break;\r
         }\r
         break;\r
-        \r
+\r
       case CHAR_CARRIAGE_RETURN:\r
         gST->ConOut->ClearScreen (gST->ConOut);\r
         //\r
@@ -1043,7 +1064,7 @@ BootManagerMenuEntry (
         BdsSetConsoleMode (TRUE);\r
         DrawBootPopupMenu (&BootMenuData);\r
         break;\r
-        \r
+\r
       default:\r
         break;\r
       }\r
@@ -1055,5 +1076,5 @@ BootManagerMenuEntry (
   HiiRemovePackages (gStringPackHandle);\r
 \r
   return Status;\r
-  \r
+\r
 }\r