]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c
MdeModulePkg/BootManagerMenu: Add assertion to indicate no DIV by 0
[mirror_edk2.git] / MdeModulePkg / Application / BootManagerMenuApp / BootManagerMenu.c
index c5a35c070fe2822d6f6a12aecfff411a4b1ee56e..a25f2ca298c758ee6e7e145b79ebe2cd25ed17b3 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 - 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
@@ -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
@@ -147,7 +147,7 @@ GetLineWidth (
 /**\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
@@ -219,7 +219,7 @@ InitializeBootMenuScreen (
   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
@@ -242,10 +242,51 @@ 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
@@ -267,8 +308,8 @@ InitializeBootMenuData (
       \r
   if (BootOption == NULL || BootMenuData == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
-  } \r
-  \r
+  }\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
@@ -277,13 +318,10 @@ 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
+    if (IgnoreBootOption (&BootOption[Index])) {\r
       continue;\r
     }\r
+\r
     ASSERT (BootOption[Index].Description != NULL);\r
     BootMenuData->PtrTokens[StrIndex++] = HiiSetString (\r
                                             gStringPackHandle, \r
@@ -307,7 +345,7 @@ InitializeBootMenuData (
   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
@@ -336,6 +374,7 @@ BootMenuSelectItem (
   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
@@ -447,7 +486,7 @@ 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
@@ -462,7 +501,6 @@ DrawBootPopupMenu (
   EFI_STRING            String;\r
   UINTN                 Index;\r
   UINTN                 Width;  \r
-  UINTN                 Height;\r
   UINTN                 StartCol;\r
   UINTN                 StartRow;\r
   UINTN                 PrintRow;\r
@@ -476,7 +514,6 @@ DrawBootPopupMenu (
   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
@@ -608,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
@@ -627,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
@@ -705,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
@@ -761,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
@@ -775,8 +809,10 @@ BdsSetConsoleMode (
                   //\r
                   // Update text mode PCD.\r
                   //\r
-                  PcdSet32 (PcdConOutColumn, mSetupTextModeColumn);\r
-                  PcdSet32 (PcdConOutRow, mSetupTextModeRow);\r
+                  Status = PcdSet32S (PcdConOutColumn, mSetupTextModeColumn);\r
+                  ASSERT_EFI_ERROR (Status);\r
+                  Status = PcdSet32S (PcdConOutRow, mSetupTextModeRow);\r
+                  ASSERT_EFI_ERROR (Status);\r
                   FreePool (Info);\r
                   return EFI_SUCCESS;\r
                 }\r
@@ -784,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
@@ -817,11 +853,14 @@ BdsSetConsoleMode (
   // Set PCD to Inform GraphicsConsole to change video resolution.\r
   // Set PCD to Inform Consplitter to change text mode.\r
   //\r
-  PcdSet32 (PcdVideoHorizontalResolution, NewHorizontalResolution);\r
-  PcdSet32 (PcdVideoVerticalResolution, NewVerticalResolution);\r
-  PcdSet32 (PcdConOutColumn, NewColumns);\r
-  PcdSet32 (PcdConOutRow, NewRows);\r
-  \r
+  Status = PcdSet32S (PcdVideoHorizontalResolution, NewHorizontalResolution);\r
+  ASSERT_EFI_ERROR (Status);\r
+  Status = PcdSet32S (PcdVideoVerticalResolution, NewVerticalResolution);\r
+  ASSERT_EFI_ERROR (Status);\r
+  Status = PcdSet32S (PcdConOutColumn, NewColumns);\r
+  ASSERT_EFI_ERROR (Status);\r
+  Status = PcdSet32S (PcdConOutRow, NewRows);\r
+  ASSERT_EFI_ERROR (Status);\r
   \r
   //\r
   // Video mode is changed, so restart graphics console driver and higher level driver.\r