From: Dandan Bi Date: Mon, 27 Feb 2017 05:33:06 +0000 (+0800) Subject: MdeModulePkg/BMMUiLib: Replace same logic with API in UefiBootManagerLib X-Git-Tag: edk2-stable201903~4530 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=bdc8cb0d3b8dc53fdf1b14af4245432d2bfb8115;ds=sidebyside MdeModulePkg/BMMUiLib: Replace same logic with API in UefiBootManagerLib Use the API EfiBootManagerDeleteLoadOptionVariable in UefiBootManagerLib to replace the same logic in function Var_DelBootOption/Var_DelDriverOption. This can make code clean and prevent potential bugs. https://bugzilla.tianocore.org/show_bug.cgi?id=391 Cc: Eric Dong Cc: Ruiyu Ni Cc: Star Zeng Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Dandan Bi Reviewed-by: Ruiyu Ni Reviewed-by: Eric Dong --- diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManager.h b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManager.h index 532b75b202..a8d7a0f8d0 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManager.h +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManager.h @@ -633,8 +633,6 @@ Var_UpdateBootOption ( /** Delete Boot Option that represent a Deleted state in BootOptionMenu. - After deleting this boot option, call Var_ChangeBootOrder to - make sure BootOrder is in valid state. @retval EFI_SUCCESS If all boot load option EFI Variables corresponding to BM_LOAD_CONTEXT marked for deletion is deleted @@ -646,21 +644,6 @@ Var_DelBootOption ( VOID ); -/** - After any operation on Boot####, there will be a discrepancy in BootOrder. - Since some are missing but in BootOrder, while some are present but are - not reflected by BootOrder. Then a function rebuild BootOrder from - scratch by content from BootOptionMenu is needed. - - @retval EFI_SUCCESS The boot order is updated successfully. - @return other than EFI_SUCCESS if failed to change the "BootOrder" EFI Variable. - -**/ -EFI_STATUS -Var_ChangeBootOrder ( - VOID - ); - /** This function create a currently loaded Drive Option from the BMM. It then appends this Driver Option to the end of @@ -687,9 +670,7 @@ Var_UpdateDriverOption ( ); /** - Delete Load Option that represent a Deleted state in BootOptionMenu. - After deleting this Driver option, call Var_ChangeDriverOrder to - make sure DriverOrder is in valid state. + Delete Load Option that represent a Deleted state in DriverOptionMenu. @retval EFI_SUCCESS Load Option is successfully updated. @return Other value than EFI_SUCCESS if failed to update "Driver Order" EFI @@ -701,22 +682,6 @@ Var_DelDriverOption ( VOID ); -/** - After any operation on Driver####, there will be a discrepancy in - DriverOrder. Since some are missing but in DriverOrder, while some - are present but are not reflected by DriverOrder. Then a function - rebuild DriverOrder from scratch by content from DriverOptionMenu is - needed. - - @retval EFI_SUCCESS The driver order is updated successfully. - @return other than EFI_SUCCESS if failed to set the "DriverOrder" EFI Variable. - -**/ -EFI_STATUS -Var_ChangeDriverOrder ( - VOID - ); - /** This function delete and build multi-instance device path ConIn console device. diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/Variable.c b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/Variable.c index 746b2335ed..c1c55b0fb2 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/Variable.c +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/Variable.c @@ -1,7 +1,7 @@ /** @file Variable operation that will be used by bootmaint -Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -16,8 +16,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. /** Delete Boot Option that represent a Deleted state in BootOptionMenu. - After deleting this boot option, call Var_ChangeBootOrder to - make sure BootOrder is in valid state. @retval EFI_SUCCESS If all boot load option EFI Variables corresponding to BM_LOAD_CONTEXT marked for deletion is deleted. @@ -32,12 +30,10 @@ Var_DelBootOption ( { BM_MENU_ENTRY *NewMenuEntry; BM_LOAD_CONTEXT *NewLoadContext; - UINT16 BootString[10]; EFI_STATUS Status; UINTN Index; UINTN Index2; - Status = EFI_SUCCESS; Index2 = 0; for (Index = 0; Index < BootOptionMenu.MenuNumber; Index++) { NewMenuEntry = BOpt_GetMenuEntry (&BootOptionMenu, (Index - Index2)); @@ -50,14 +46,10 @@ Var_DelBootOption ( continue; } - UnicodeSPrint ( - BootString, - sizeof (BootString), - L"Boot%04x", - NewMenuEntry->OptionNumber - ); - - EfiLibDeleteVariable (BootString, &gEfiGlobalVariableGuid); + Status = EfiBootManagerDeleteLoadOptionVariable (NewMenuEntry->OptionNumber,LoadOptionTypeBoot); + if (EFI_ERROR (Status)) { + return Status; + } Index2++; // // If current Load Option is the same as BootNext, @@ -75,102 +67,11 @@ Var_DelBootOption ( BootOptionMenu.MenuNumber -= Index2; - Status = Var_ChangeBootOrder (); - return Status; -} - -/** - After any operation on Boot####, there will be a discrepancy in BootOrder. - Since some are missing but in BootOrder, while some are present but are - not reflected by BootOrder. Then a function rebuild BootOrder from - scratch by content from BootOptionMenu is needed. - - - - - @retval EFI_SUCCESS The boot order is updated successfully. - @return EFI_STATUS other than EFI_SUCCESS if failed to - Set the "BootOrder" EFI Variable. - -**/ -EFI_STATUS -Var_ChangeBootOrder ( - VOID - ) -{ - - EFI_STATUS Status; - BM_MENU_ENTRY *NewMenuEntry; - UINT16 *BootOrderList; - UINT16 *BootOrderListPtr; - UINTN BootOrderListSize; - UINTN Index; - - BootOrderList = NULL; - BootOrderListSize = 0; - // - // First check whether BootOrder is present in current configuration - // - GetEfiGlobalVariable2 (L"BootOrder", (VOID **) &BootOrderList, &BootOrderListSize); - - // - // If exists, delete it to hold new BootOrder - // - if (BootOrderList != NULL) { - EfiLibDeleteVariable (L"BootOrder", &gEfiGlobalVariableGuid); - FreePool (BootOrderList); - BootOrderList = NULL; - } - // - // Maybe here should be some check method to ensure that - // no new added boot options will be added - // but the setup engine now will give only one callback - // that is to say, user are granted only one chance to - // decide whether the boot option will be added or not - // there should be no indictor to show whether this - // is a "new" boot option - // - BootOrderListSize = BootOptionMenu.MenuNumber; - - if (BootOrderListSize > 0) { - BootOrderList = AllocateZeroPool (BootOrderListSize * sizeof (UINT16)); - ASSERT (BootOrderList != NULL); - BootOrderListPtr = BootOrderList; - - // - // Get all current used Boot#### from BootOptionMenu. - // OptionNumber in each BM_LOAD_OPTION is really its - // #### value. - // - for (Index = 0; Index < BootOrderListSize; Index++) { - NewMenuEntry = BOpt_GetMenuEntry (&BootOptionMenu, Index); - *BootOrderList = (UINT16) NewMenuEntry->OptionNumber; - BootOrderList++; - } - - BootOrderList = BootOrderListPtr; - - // - // After building the BootOrderList, write it back - // - Status = gRT->SetVariable ( - L"BootOrder", - &gEfiGlobalVariableGuid, - VAR_FLAG, - BootOrderListSize * sizeof (UINT16), - BootOrderList - ); - if (EFI_ERROR (Status)) { - return Status; - } - } return EFI_SUCCESS; } /** - Delete Load Option that represent a Deleted state in BootOptionMenu. - After deleting this Driver option, call Var_ChangeDriverOrder to - make sure DriverOrder is in valid state. + Delete Load Option that represent a Deleted state in DriverOptionMenu. @retval EFI_SUCCESS Load Option is successfully updated. @retval EFI_NOT_FOUND Fail to find the driver option want to be deleted. @@ -185,12 +86,10 @@ Var_DelDriverOption ( { BM_MENU_ENTRY *NewMenuEntry; BM_LOAD_CONTEXT *NewLoadContext; - UINT16 DriverString[12]; EFI_STATUS Status; UINTN Index; UINTN Index2; - Status = EFI_SUCCESS; Index2 = 0; for (Index = 0; Index < DriverOptionMenu.MenuNumber; Index++) { NewMenuEntry = BOpt_GetMenuEntry (&DriverOptionMenu, (Index - Index2)); @@ -202,15 +101,11 @@ Var_DelDriverOption ( if (!NewLoadContext->Deleted) { continue; } + Status = EfiBootManagerDeleteLoadOptionVariable (NewMenuEntry->OptionNumber,LoadOptionTypeDriver); + if (EFI_ERROR (Status)) { + return Status; + } - UnicodeSPrint ( - DriverString, - sizeof (DriverString), - L"Driver%04x", - NewMenuEntry->OptionNumber - ); - - EfiLibDeleteVariable (DriverString, &gEfiGlobalVariableGuid); Index2++; RemoveEntryList (&NewMenuEntry->Link); @@ -220,83 +115,6 @@ Var_DelDriverOption ( DriverOptionMenu.MenuNumber -= Index2; - Status = Var_ChangeDriverOrder (); - return Status; -} - -/** - After any operation on Driver####, there will be a discrepancy in - DriverOrder. Since some are missing but in DriverOrder, while some - are present but are not reflected by DriverOrder. Then a function - rebuild DriverOrder from scratch by content from DriverOptionMenu is - needed. - - @retval EFI_SUCCESS The driver order is updated successfully. - @return Other status than EFI_SUCCESS if failed to set the "DriverOrder" EFI Variable. - -**/ -EFI_STATUS -Var_ChangeDriverOrder ( - VOID - ) -{ - EFI_STATUS Status; - BM_MENU_ENTRY *NewMenuEntry; - UINT16 *DriverOrderList; - UINT16 *DriverOrderListPtr; - UINTN DriverOrderListSize; - UINTN Index; - - DriverOrderList = NULL; - DriverOrderListSize = 0; - - // - // First check whether DriverOrder is present in current configuration - // - GetEfiGlobalVariable2 (L"DriverOrder", (VOID **) &DriverOrderList, &DriverOrderListSize); - // - // If exists, delete it to hold new DriverOrder - // - if (DriverOrderList != NULL) { - EfiLibDeleteVariable (L"DriverOrder", &gEfiGlobalVariableGuid); - FreePool (DriverOrderList); - DriverOrderList = NULL; - } - - DriverOrderListSize = DriverOptionMenu.MenuNumber; - - if (DriverOrderListSize > 0) { - DriverOrderList = AllocateZeroPool (DriverOrderListSize * sizeof (UINT16)); - ASSERT (DriverOrderList != NULL); - DriverOrderListPtr = DriverOrderList; - - // - // Get all current used Driver#### from DriverOptionMenu. - // OptionNumber in each BM_LOAD_OPTION is really its - // #### value. - // - for (Index = 0; Index < DriverOrderListSize; Index++) { - NewMenuEntry = BOpt_GetMenuEntry (&DriverOptionMenu, Index); - *DriverOrderList = (UINT16) NewMenuEntry->OptionNumber; - DriverOrderList++; - } - - DriverOrderList = DriverOrderListPtr; - - // - // After building the DriverOrderList, write it back - // - Status = gRT->SetVariable ( - L"DriverOrder", - &gEfiGlobalVariableGuid, - VAR_FLAG, - DriverOrderListSize * sizeof (UINT16), - DriverOrderList - ); - if (EFI_ERROR (Status)) { - return Status; - } - } return EFI_SUCCESS; }