X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FLibrary%2FBootMaintenanceManagerUiLib%2FVariable.c;h=f934546829c08e9318febaecd9e3bad91f3c6ab4;hb=8f7a05e1396657c8bd2948825f41d0fdf239e334;hp=b65d6a5c9ed035258bd1278d90e6fac96e989c75;hpb=c7d310dd169ef84eee1ffab3af763372a363ab4b;p=mirror_edk2.git diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/Variable.c b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/Variable.c index b65d6a5c9e..f934546829 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 - 2018, 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,13 +16,11 @@ 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 + @retval EFI_SUCCESS If all boot load option EFI Variables corresponding to BM_LOAD_CONTEXT marked for deletion is deleted. @retval EFI_NOT_FOUND If can not find the boot option want to be deleted. - @return Others If failed to update the "BootOrder" variable after deletion. + @return Others If failed to update the "BootOrder" variable after deletion. **/ EFI_STATUS @@ -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; } @@ -306,7 +124,7 @@ Var_ChangeDriverOrder ( This function clear the EFI variable defined by ConsoleName and gEfiGlobalVariableGuid. It then build the multi-instance device - path by appending the device path of the Console (In/Out/Err) instance + path by appending the device path of the Console (In/Out/Err) instance in ConsoleMenu. Then it scan all corresponding console device by scanning Terminal (built from device supporting Serial I/O instances) devices in TerminalMenu. At last, it save a EFI variable specifed @@ -370,8 +188,8 @@ Var_UpdateConsoleOption ( ) { Vendor.Header.Type = MESSAGING_DEVICE_PATH; Vendor.Header.SubType = MSG_VENDOR_DP; - - ASSERT (NewTerminalContext->TerminalType < (sizeof (TerminalTypeGuid) / sizeof (TerminalTypeGuid[0]))); + + ASSERT (NewTerminalContext->TerminalType < (ARRAY_SIZE (TerminalTypeGuid))); CopyMem ( &Vendor.Guid, &TerminalTypeGuid[NewTerminalContext->TerminalType], @@ -443,7 +261,7 @@ Var_UpdateConsoleOutOption ( console device. @retval EFI_SUCCESS The function complete successfully. - @return The EFI variable can not be saved. See gRT->SetVariable for detail return information. + @return The EFI variable can not be saved. See gRT->SetVariable for detail return information. **/ EFI_STATUS Var_UpdateErrorOutOption ( @@ -454,8 +272,8 @@ Var_UpdateErrorOutOption ( } /** - This function create a currently loaded Drive Option from - the BMM. It then appends this Driver Option to the end of + This function create a currently loaded Drive Option from + the BMM. It then appends this Driver Option to the end of the "DriverOrder" list. It append this Driver Opotion to the end of DriverOptionMenu. @@ -465,7 +283,9 @@ Var_UpdateErrorOutOption ( @param OptionalData The optional load option. @param ForceReconnect If to force reconnect. - @retval EFI_OUT_OF_RESOURCES If not enought memory to complete the operation. + @retval other Contain some errors when excuting this function.See function + EfiBootManagerInitializeLoadOption/EfiBootManagerAddLoadOptionVariabl + for detail return information. @retval EFI_SUCCESS If function completes successfully. **/ @@ -525,8 +345,14 @@ Var_UpdateDriverOption ( OptionalDesData, OptionalDataSize ); - if (!EFI_ERROR (Status)){ - Status = EfiBootManagerAddLoadOptionVariable (&LoadOption,(UINTN) -1 ); + if (EFI_ERROR (Status)){ + return Status; + } + + Status = EfiBootManagerAddLoadOptionVariable (&LoadOption,(UINTN) -1 ); + if (EFI_ERROR (Status)) { + EfiBootManagerFreeLoadOption(&LoadOption); + return Status; } NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext; @@ -575,14 +401,16 @@ Var_UpdateDriverOption ( } /** - This function create a currently loaded Boot Option from - the BMM. It then appends this Boot Option to the end of + This function create a currently loaded Boot Option from + the BMM. It then appends this Boot Option to the end of the "BootOrder" list. It also append this Boot Opotion to the end of BootOptionMenu. @param CallbackData The BMM context data. - @retval EFI_OUT_OF_RESOURCES If not enought memory to complete the operation. + @retval other Contain some errors when excuting this function. See function + EfiBootManagerInitializeLoadOption/EfiBootManagerAddLoadOptionVariabl + for detail return information. @retval EFI_SUCCESS If function completes successfully. **/ @@ -635,8 +463,14 @@ Var_UpdateBootOption ( OptionalData, OptionalDataSize ); - if (!EFI_ERROR (Status)){ - Status = EfiBootManagerAddLoadOptionVariable (&LoadOption,(UINTN) -1 ); + if (EFI_ERROR (Status)){ + return Status; + } + + Status = EfiBootManagerAddLoadOptionVariable (&LoadOption,(UINTN) -1 ); + if (EFI_ERROR (Status)) { + EfiBootManagerFreeLoadOption(&LoadOption); + return Status; } NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext; @@ -687,7 +521,7 @@ Var_UpdateBootOption ( } /** - This function update the "BootNext" EFI Variable. If there is + This function update the "BootNext" EFI Variable. If there is no "BootNext" specified in BMM, this EFI Variable is deleted. It also update the BMM context data specified the "BootNext" vaule. @@ -695,7 +529,7 @@ Var_UpdateBootOption ( @param CallbackData The BMM context data. @retval EFI_SUCCESS The function complete successfully. - @return The EFI variable can be saved. See gRT->SetVariable + @return The EFI variable can be saved. See gRT->SetVariable for detail return information. **/ @@ -799,7 +633,7 @@ Var_UpdateBootOrder ( BootOrder ); FreePool (BootOrder); - + BOpt_FreeMenu (&BootOptionMenu); BOpt_GetBootOptions (CallbackData);