/** @file\r
Variable operation that will be used by bootmaint\r
\r
-Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 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
\r
/**\r
Delete Boot Option that represent a Deleted state in BootOptionMenu.\r
- After deleting this boot option, call Var_ChangeBootOrder to\r
- make sure BootOrder is in valid state.\r
\r
@retval EFI_SUCCESS If all boot load option EFI Variables corresponding to \r
BM_LOAD_CONTEXT marked for deletion is deleted.\r
{\r
BM_MENU_ENTRY *NewMenuEntry;\r
BM_LOAD_CONTEXT *NewLoadContext;\r
- UINT16 BootString[10];\r
EFI_STATUS Status;\r
UINTN Index;\r
UINTN Index2;\r
\r
- Status = EFI_SUCCESS;\r
Index2 = 0;\r
for (Index = 0; Index < BootOptionMenu.MenuNumber; Index++) {\r
NewMenuEntry = BOpt_GetMenuEntry (&BootOptionMenu, (Index - Index2));\r
continue;\r
}\r
\r
- UnicodeSPrint (\r
- BootString,\r
- sizeof (BootString),\r
- L"Boot%04x",\r
- NewMenuEntry->OptionNumber\r
- );\r
-\r
- EfiLibDeleteVariable (BootString, &gEfiGlobalVariableGuid);\r
+ Status = EfiBootManagerDeleteLoadOptionVariable (NewMenuEntry->OptionNumber,LoadOptionTypeBoot);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
Index2++;\r
//\r
// If current Load Option is the same as BootNext,\r
\r
BootOptionMenu.MenuNumber -= Index2;\r
\r
- Status = Var_ChangeBootOrder ();\r
- return Status;\r
-}\r
-\r
-/**\r
- After any operation on Boot####, there will be a discrepancy in BootOrder.\r
- Since some are missing but in BootOrder, while some are present but are\r
- not reflected by BootOrder. Then a function rebuild BootOrder from\r
- scratch by content from BootOptionMenu is needed.\r
-\r
-\r
- \r
-\r
- @retval EFI_SUCCESS The boot order is updated successfully.\r
- @return EFI_STATUS other than EFI_SUCCESS if failed to\r
- Set the "BootOrder" EFI Variable.\r
-\r
-**/\r
-EFI_STATUS\r
-Var_ChangeBootOrder (\r
- VOID\r
- )\r
-{\r
-\r
- EFI_STATUS Status;\r
- BM_MENU_ENTRY *NewMenuEntry;\r
- UINT16 *BootOrderList;\r
- UINT16 *BootOrderListPtr;\r
- UINTN BootOrderListSize;\r
- UINTN Index;\r
-\r
- BootOrderList = NULL;\r
- BootOrderListSize = 0;\r
- //\r
- // First check whether BootOrder is present in current configuration\r
- //\r
- GetEfiGlobalVariable2 (L"BootOrder", (VOID **) &BootOrderList, &BootOrderListSize);\r
-\r
- //\r
- // If exists, delete it to hold new BootOrder\r
- //\r
- if (BootOrderList != NULL) {\r
- EfiLibDeleteVariable (L"BootOrder", &gEfiGlobalVariableGuid);\r
- FreePool (BootOrderList);\r
- BootOrderList = NULL;\r
- }\r
- //\r
- // Maybe here should be some check method to ensure that\r
- // no new added boot options will be added\r
- // but the setup engine now will give only one callback\r
- // that is to say, user are granted only one chance to\r
- // decide whether the boot option will be added or not\r
- // there should be no indictor to show whether this\r
- // is a "new" boot option\r
- //\r
- BootOrderListSize = BootOptionMenu.MenuNumber;\r
-\r
- if (BootOrderListSize > 0) {\r
- BootOrderList = AllocateZeroPool (BootOrderListSize * sizeof (UINT16));\r
- ASSERT (BootOrderList != NULL);\r
- BootOrderListPtr = BootOrderList;\r
-\r
- //\r
- // Get all current used Boot#### from BootOptionMenu.\r
- // OptionNumber in each BM_LOAD_OPTION is really its\r
- // #### value.\r
- //\r
- for (Index = 0; Index < BootOrderListSize; Index++) {\r
- NewMenuEntry = BOpt_GetMenuEntry (&BootOptionMenu, Index);\r
- *BootOrderList = (UINT16) NewMenuEntry->OptionNumber;\r
- BootOrderList++;\r
- }\r
-\r
- BootOrderList = BootOrderListPtr;\r
-\r
- //\r
- // After building the BootOrderList, write it back\r
- //\r
- Status = gRT->SetVariable (\r
- L"BootOrder",\r
- &gEfiGlobalVariableGuid,\r
- VAR_FLAG,\r
- BootOrderListSize * sizeof (UINT16),\r
- BootOrderList\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
- }\r
return EFI_SUCCESS;\r
}\r
\r
/**\r
- Delete Load Option that represent a Deleted state in BootOptionMenu.\r
- After deleting this Driver option, call Var_ChangeDriverOrder to\r
- make sure DriverOrder is in valid state.\r
+ Delete Load Option that represent a Deleted state in DriverOptionMenu.\r
\r
@retval EFI_SUCCESS Load Option is successfully updated.\r
@retval EFI_NOT_FOUND Fail to find the driver option want to be deleted.\r
{\r
BM_MENU_ENTRY *NewMenuEntry;\r
BM_LOAD_CONTEXT *NewLoadContext;\r
- UINT16 DriverString[12];\r
EFI_STATUS Status;\r
UINTN Index;\r
UINTN Index2;\r
\r
- Status = EFI_SUCCESS;\r
Index2 = 0;\r
for (Index = 0; Index < DriverOptionMenu.MenuNumber; Index++) {\r
NewMenuEntry = BOpt_GetMenuEntry (&DriverOptionMenu, (Index - Index2));\r
if (!NewLoadContext->Deleted) {\r
continue;\r
}\r
+ Status = EfiBootManagerDeleteLoadOptionVariable (NewMenuEntry->OptionNumber,LoadOptionTypeDriver);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
\r
- UnicodeSPrint (\r
- DriverString,\r
- sizeof (DriverString),\r
- L"Driver%04x",\r
- NewMenuEntry->OptionNumber\r
- );\r
-\r
- EfiLibDeleteVariable (DriverString, &gEfiGlobalVariableGuid);\r
Index2++;\r
\r
RemoveEntryList (&NewMenuEntry->Link);\r
\r
DriverOptionMenu.MenuNumber -= Index2;\r
\r
- Status = Var_ChangeDriverOrder ();\r
- return Status;\r
-}\r
-\r
-/**\r
- After any operation on Driver####, there will be a discrepancy in\r
- DriverOrder. Since some are missing but in DriverOrder, while some\r
- are present but are not reflected by DriverOrder. Then a function\r
- rebuild DriverOrder from scratch by content from DriverOptionMenu is\r
- needed.\r
-\r
- @retval EFI_SUCCESS The driver order is updated successfully.\r
- @return Other status than EFI_SUCCESS if failed to set the "DriverOrder" EFI Variable.\r
-\r
-**/\r
-EFI_STATUS\r
-Var_ChangeDriverOrder (\r
- VOID\r
- )\r
-{\r
- EFI_STATUS Status;\r
- BM_MENU_ENTRY *NewMenuEntry;\r
- UINT16 *DriverOrderList;\r
- UINT16 *DriverOrderListPtr;\r
- UINTN DriverOrderListSize;\r
- UINTN Index;\r
-\r
- DriverOrderList = NULL;\r
- DriverOrderListSize = 0;\r
-\r
- //\r
- // First check whether DriverOrder is present in current configuration\r
- //\r
- GetEfiGlobalVariable2 (L"DriverOrder", (VOID **) &DriverOrderList, &DriverOrderListSize);\r
- //\r
- // If exists, delete it to hold new DriverOrder\r
- //\r
- if (DriverOrderList != NULL) {\r
- EfiLibDeleteVariable (L"DriverOrder", &gEfiGlobalVariableGuid);\r
- FreePool (DriverOrderList);\r
- DriverOrderList = NULL;\r
- }\r
-\r
- DriverOrderListSize = DriverOptionMenu.MenuNumber;\r
-\r
- if (DriverOrderListSize > 0) {\r
- DriverOrderList = AllocateZeroPool (DriverOrderListSize * sizeof (UINT16));\r
- ASSERT (DriverOrderList != NULL);\r
- DriverOrderListPtr = DriverOrderList;\r
-\r
- //\r
- // Get all current used Driver#### from DriverOptionMenu.\r
- // OptionNumber in each BM_LOAD_OPTION is really its\r
- // #### value.\r
- //\r
- for (Index = 0; Index < DriverOrderListSize; Index++) {\r
- NewMenuEntry = BOpt_GetMenuEntry (&DriverOptionMenu, Index);\r
- *DriverOrderList = (UINT16) NewMenuEntry->OptionNumber;\r
- DriverOrderList++;\r
- }\r
-\r
- DriverOrderList = DriverOrderListPtr;\r
-\r
- //\r
- // After building the DriverOrderList, write it back\r
- //\r
- Status = gRT->SetVariable (\r
- L"DriverOrder",\r
- &gEfiGlobalVariableGuid,\r
- VAR_FLAG,\r
- DriverOrderListSize * sizeof (UINT16),\r
- DriverOrderList\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
- }\r
return EFI_SUCCESS;\r
}\r
\r
Vendor.Header.Type = MESSAGING_DEVICE_PATH;\r
Vendor.Header.SubType = MSG_VENDOR_DP;\r
\r
- ASSERT (NewTerminalContext->TerminalType < (sizeof (TerminalTypeGuid) / sizeof (TerminalTypeGuid[0])));\r
+ ASSERT (NewTerminalContext->TerminalType < (ARRAY_SIZE (TerminalTypeGuid)));\r
CopyMem (\r
&Vendor.Guid,\r
&TerminalTypeGuid[NewTerminalContext->TerminalType],\r
@param OptionalData The optional load option.\r
@param ForceReconnect If to force reconnect.\r
\r
- @retval EFI_OUT_OF_RESOURCES If not enought memory to complete the operation.\r
+ @retval other Contain some errors when excuting this function.See function\r
+ EfiBootManagerInitializeLoadOption/EfiBootManagerAddLoadOptionVariabl\r
+ for detail return information.\r
@retval EFI_SUCCESS If function completes successfully.\r
\r
**/\r
OptionalDesData,\r
OptionalDataSize\r
);\r
- if (!EFI_ERROR (Status)){\r
- Status = EfiBootManagerAddLoadOptionVariable (&LoadOption,(UINTN) -1 );\r
+ if (EFI_ERROR (Status)){\r
+ return Status;\r
+ }\r
+\r
+ Status = EfiBootManagerAddLoadOptionVariable (&LoadOption,(UINTN) -1 );\r
+ if (EFI_ERROR (Status)) {\r
+ EfiBootManagerFreeLoadOption(&LoadOption);\r
+ return Status;\r
}\r
\r
NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext;\r
\r
@param CallbackData The BMM context data.\r
\r
- @retval EFI_OUT_OF_RESOURCES If not enought memory to complete the operation.\r
+ @retval other Contain some errors when excuting this function. See function\r
+ EfiBootManagerInitializeLoadOption/EfiBootManagerAddLoadOptionVariabl\r
+ for detail return information.\r
@retval EFI_SUCCESS If function completes successfully.\r
\r
**/\r
OptionalData,\r
OptionalDataSize\r
);\r
- if (!EFI_ERROR (Status)){\r
- Status = EfiBootManagerAddLoadOptionVariable (&LoadOption,(UINTN) -1 );\r
+ if (EFI_ERROR (Status)){\r
+ return Status;\r
+ }\r
+\r
+ Status = EfiBootManagerAddLoadOptionVariable (&LoadOption,(UINTN) -1 );\r
+ if (EFI_ERROR (Status)) {\r
+ EfiBootManagerFreeLoadOption(&LoadOption);\r
+ return Status;\r
}\r
\r
NewLoadContext = (BM_LOAD_CONTEXT *) NewMenuEntry->VariableContext;\r