Re: [edk2] [Patch] MdeModulePkg/BootManagerMenu: Fix bug that boots to undesired option

2015-12-24 Thread Dong, Eric
Reviewed-by: Eric Dong <eric.d...@intel.com>

-Original Message-
From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Ruiyu Ni
Sent: Thursday, December 24, 2015 3:50 PM
To: edk2-devel@lists.01.org
Cc: Ni, Ruiyu; Dong, Eric
Subject: [edk2] [Patch] MdeModulePkg/BootManagerMenu: Fix bug that boots to 
undesired option

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu...@intel.com>
Cc: Eric Dong <eric.d...@intel.com>
---
 .../BootManagerMenuApp/BootManagerMenu.c   | 68 ++
 1 file changed, 45 insertions(+), 23 deletions(-)

diff --git a/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c 
b/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c
index a8d5c03..9547c7e 100644
--- a/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c
+++ b/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c
@@ -242,7 +242,48 @@ IsBootManagerMenu (
 
   return (BOOLEAN) (!EFI_ERROR (Status) && (BootOption->OptionNumber == 
BootManagerMenu.OptionNumber));  }
- 
+
+/**
+  Return whether to ignore the boot option.
+
+  @param BootOption  Pointer to EFI_BOOT_MANAGER_LOAD_OPTION to check.
+
+  @retval TRUE  Ignore the boot optin.
+  @retval FALSE Do not ignore the boot option.
+**/
+BOOLEAN
+IgnoreBootOption (
+  IN   EFI_BOOT_MANAGER_LOAD_OPTION  *BootOption
+  )
+{
+  EFI_STATUSStatus;
+  EFI_DEVICE_PATH_PROTOCOL  *ImageDevicePath;
+
+  //
+  // Ignore myself.
+  //
+  Status = gBS->HandleProtocol (gImageHandle, 
+ , (VOID **) );  
+ ASSERT_EFI_ERROR (Status);  if (CompareMem (BootOption->FilePath, 
ImageDevicePath, GetDevicePathSize (ImageDevicePath)) == 0) {
+return TRUE;
+  }
+
+  //
+  // Do not ignore Boot Manager Menu.
+  //
+  if (IsBootManagerMenu (BootOption)) {
+return FALSE;
+  }
+
+  //
+  // Ignore the hidden/inactive boot option.
+  //
+  if (((BootOption->Attributes & LOAD_OPTION_HIDDEN) != 0) || 
((BootOption->Attributes & LOAD_OPTION_ACTIVE) == 0)) {
+return TRUE;
+  }
+
+  return FALSE;
+}
 
 /**
   This funciton uses to initialize boot menu data @@ -262,18 +303,13 @@ 
InitializeBootMenuData (
   OUT  BOOT_MENU_POPUP_DATA  *BootMenuData
   )
 {
-  EFI_STATUSStatus;
   UINTN Index;
   UINTN StrIndex;
-  EFI_DEVICE_PATH_PROTOCOL  *ImageDevicePath;
   
   if (BootOption == NULL || BootMenuData == NULL) {
 return EFI_INVALID_PARAMETER;
   }
 
-  Status = gBS->HandleProtocol (gImageHandle, 
, (VOID **) );
-  ASSERT_EFI_ERROR (Status);
-
   BootMenuData->TitleToken[0] = STRING_TOKEN 
(STR_BOOT_POPUP_MENU_TITLE_STRING);
   BootMenuData->PtrTokens = AllocateZeroPool (BootOptionCount * sizeof 
(EFI_STRING_ID));
   ASSERT (BootMenuData->PtrTokens != NULL); @@ -282,18 +318,7 @@ 
InitializeBootMenuData (
   // Skip boot option which created by BootNext Variable
   //
   for (StrIndex = 0, Index = 0; Index < BootOptionCount; Index++) {
-//
-// Don't display the hidden/inactive boot option except setup application.
-//
-if BootOption[Index].Attributes & LOAD_OPTION_HIDDEN) != 0) || 
((BootOption[Index].Attributes & LOAD_OPTION_ACTIVE) == 0)) &&
-!IsBootManagerMenu ([Index])) {  
-  continue;
-}
-
-//
-// Don't display myself
-//
-if (CompareMem (BootOption[Index].FilePath, ImageDevicePath, 
GetDevicePathSize (ImageDevicePath)) == 0) {
+if (IgnoreBootOption ([Index])) {
   continue;
 }
 
@@ -640,13 +665,10 @@ BootFromSelectOption (
   ASSERT (BootOptions != NULL);
 
   for (ItemNum = 0, Index = 0; Index < BootOptionCount; Index++) {
-//
-// Don't display the hidden/inactive boot option except setup application.
-//
-if BootOptions[Index].Attributes & LOAD_OPTION_HIDDEN) != 0) || 
((BootOptions[Index].Attributes & LOAD_OPTION_ACTIVE) == 0)) &&
-!IsBootManagerMenu ([Index])) {  
+if (IgnoreBootOption ([Index])) {
   continue;
 }
+
 if (ItemNum++ == SelectItem) {
   EfiBootManagerBoot ([Index]);
   break;
--
2.6.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


[edk2] [Patch] MdeModulePkg/BootManagerMenu: Fix bug that boots to undesired option

2015-12-23 Thread Ruiyu Ni
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni 
Cc: Eric Dong 
---
 .../BootManagerMenuApp/BootManagerMenu.c   | 68 ++
 1 file changed, 45 insertions(+), 23 deletions(-)

diff --git a/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c 
b/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c
index a8d5c03..9547c7e 100644
--- a/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c
+++ b/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c
@@ -242,7 +242,48 @@ IsBootManagerMenu (
 
   return (BOOLEAN) (!EFI_ERROR (Status) && (BootOption->OptionNumber == 
BootManagerMenu.OptionNumber));
 }
- 
+
+/**
+  Return whether to ignore the boot option.
+
+  @param BootOption  Pointer to EFI_BOOT_MANAGER_LOAD_OPTION to check.
+
+  @retval TRUE  Ignore the boot optin.
+  @retval FALSE Do not ignore the boot option.
+**/
+BOOLEAN
+IgnoreBootOption (
+  IN   EFI_BOOT_MANAGER_LOAD_OPTION  *BootOption
+  )
+{
+  EFI_STATUSStatus;
+  EFI_DEVICE_PATH_PROTOCOL  *ImageDevicePath;
+
+  //
+  // Ignore myself.
+  //
+  Status = gBS->HandleProtocol (gImageHandle, 
, (VOID **) );
+  ASSERT_EFI_ERROR (Status);
+  if (CompareMem (BootOption->FilePath, ImageDevicePath, GetDevicePathSize 
(ImageDevicePath)) == 0) {
+return TRUE;
+  }
+
+  //
+  // Do not ignore Boot Manager Menu.
+  //
+  if (IsBootManagerMenu (BootOption)) {
+return FALSE;
+  }
+
+  //
+  // Ignore the hidden/inactive boot option.
+  //
+  if (((BootOption->Attributes & LOAD_OPTION_HIDDEN) != 0) || 
((BootOption->Attributes & LOAD_OPTION_ACTIVE) == 0)) {
+return TRUE;
+  }
+
+  return FALSE;
+}
 
 /**
   This funciton uses to initialize boot menu data
@@ -262,18 +303,13 @@ InitializeBootMenuData (
   OUT  BOOT_MENU_POPUP_DATA  *BootMenuData
   )
 {
-  EFI_STATUSStatus;
   UINTN Index;
   UINTN StrIndex;
-  EFI_DEVICE_PATH_PROTOCOL  *ImageDevicePath;
   
   if (BootOption == NULL || BootMenuData == NULL) {
 return EFI_INVALID_PARAMETER;
   }
 
-  Status = gBS->HandleProtocol (gImageHandle, 
, (VOID **) );
-  ASSERT_EFI_ERROR (Status);
-
   BootMenuData->TitleToken[0] = STRING_TOKEN 
(STR_BOOT_POPUP_MENU_TITLE_STRING);
   BootMenuData->PtrTokens = AllocateZeroPool (BootOptionCount * sizeof 
(EFI_STRING_ID));
   ASSERT (BootMenuData->PtrTokens != NULL);
@@ -282,18 +318,7 @@ InitializeBootMenuData (
   // Skip boot option which created by BootNext Variable
   //
   for (StrIndex = 0, Index = 0; Index < BootOptionCount; Index++) {
-//
-// Don't display the hidden/inactive boot option except setup application.
-//
-if BootOption[Index].Attributes & LOAD_OPTION_HIDDEN) != 0) || 
((BootOption[Index].Attributes & LOAD_OPTION_ACTIVE) == 0)) &&
-!IsBootManagerMenu ([Index])) {  
-  continue;
-}
-
-//
-// Don't display myself
-//
-if (CompareMem (BootOption[Index].FilePath, ImageDevicePath, 
GetDevicePathSize (ImageDevicePath)) == 0) {
+if (IgnoreBootOption ([Index])) {
   continue;
 }
 
@@ -640,13 +665,10 @@ BootFromSelectOption (
   ASSERT (BootOptions != NULL);
 
   for (ItemNum = 0, Index = 0; Index < BootOptionCount; Index++) {
-//
-// Don't display the hidden/inactive boot option except setup application.
-//
-if BootOptions[Index].Attributes & LOAD_OPTION_HIDDEN) != 0) || 
((BootOptions[Index].Attributes & LOAD_OPTION_ACTIVE) == 0)) &&
-!IsBootManagerMenu ([Index])) {  
+if (IgnoreBootOption ([Index])) {
   continue;
 }
+
 if (ItemNum++ == SelectItem) {
   EfiBootManagerBoot ([Index]);
   break;
-- 
2.6.2.windows.1

___
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel