\r
Boot option manipulation\r
\r
-Copyright (c) 2004 - 2010, Intel Corporation. <BR>\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2004 - 2010, 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
http://opensource.org/licenses/bsd-license.php\r
EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
UINTN MenuCount;\r
UINT8 *Ptr;\r
- UINTN DevicePathType;\r
- CHAR16 *HiiString;\r
\r
MenuCount = 0;\r
BootOrderListSize = 0;\r
LoadOptionPtr += sizeof (UINT16);\r
\r
StringSize = StrSize((UINT16*)LoadOptionPtr);\r
- //\r
- // Get Hii description string according to device path type\r
- //\r
- HiiString = NULL;\r
- DevicePathType = BdsGetBootTypeFromDevicePath (DevicePath);\r
- switch (DevicePathType) {\r
- case BDS_EFI_ACPI_FLOPPY_BOOT:\r
- HiiString = GetStringById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY));\r
- break;\r
- case BDS_EFI_MESSAGE_SATA_BOOT:\r
- case BDS_EFI_MESSAGE_ATAPI_BOOT:\r
- case BDS_EFI_MEDIA_CDROM_BOOT:\r
- HiiString = GetStringById (STRING_TOKEN (STR_DESCRIPTION_DVD));\r
- break;\r
- case BDS_EFI_MESSAGE_USB_DEVICE_BOOT:\r
- HiiString = GetStringById (STRING_TOKEN (STR_DESCRIPTION_USB));\r
- break;\r
- case BDS_EFI_MESSAGE_SCSI_BOOT:\r
- HiiString = GetStringById (STRING_TOKEN (STR_DESCRIPTION_SCSI));\r
- break;\r
- case BDS_EFI_MESSAGE_MISC_BOOT:\r
- HiiString = GetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC));\r
- break;\r
- case BDS_EFI_MESSAGE_MAC_BOOT:\r
- HiiString = GetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK));\r
- break;\r
- case BBS_DEVICE_PATH:\r
- //\r
- // Do nothing for legacy boot option.\r
- //\r
- break; \r
- default:\r
- DEBUG((EFI_D_INFO, "Can not find HiiString for given device path type 0x%x\n", DevicePathType));\r
- }\r
- \r
- if (HiiString != NULL) {\r
- NewLoadContext->Description = AllocateZeroPool(StringSize + StrSize(HiiString));\r
- ASSERT (NewLoadContext->Description != NULL);\r
- StrCpy (NewLoadContext->Description, HiiString);\r
- if (StrnCmp ((UINT16*)LoadOptionPtr, L"0", 1) != 0) {\r
- StrCat (NewLoadContext->Description, L" ");\r
- StrCat (NewLoadContext->Description, (UINT16*)LoadOptionPtr);\r
- } \r
- \r
- FreePool (HiiString);\r
- } else {\r
- NewLoadContext->Description = AllocateZeroPool (StrSize((UINT16*)LoadOptionPtr));\r
- StrCpy(NewLoadContext->Description, (UINT16*)LoadOptionPtr);\r
- }\r
+\r
+ NewLoadContext->Description = AllocateZeroPool (StrSize((UINT16*)LoadOptionPtr));\r
+ ASSERT (NewLoadContext->Description != NULL);\r
+ StrCpy (NewLoadContext->Description, (UINT16*)LoadOptionPtr);\r
\r
ASSERT (NewLoadContext->Description != NULL);\r
NewMenuEntry->DisplayString = NewLoadContext->Description;\r
\r
Get the Option Number that has not been allocated for use.\r
\r
+ @param Type The type of Option.\r
+\r
@return The available Option Number.\r
\r
**/\r
UINT16\r
-BOpt_GetBootOptionNumber (\r
- VOID\r
+BOpt_GetOptionNumber (\r
+ CHAR16 *Type\r
)\r
{\r
- BM_MENU_ENTRY *NewMenuEntry;\r
- UINT16 *BootOrderList;\r
- UINTN BootOrderListSize;\r
- UINT16 Number;\r
+ UINT16 *OrderList;\r
+ UINTN OrderListSize;\r
UINTN Index;\r
- UINTN Index2;\r
- BOOLEAN Found;\r
- CHAR16 StrTemp[100];\r
+ CHAR16 StrTemp[20];\r
UINT16 *OptionBuffer;\r
+ UINT16 OptionNumber;\r
UINTN OptionSize;\r
\r
- BootOrderListSize = 0;\r
- BootOrderList = NULL;\r
+ OrderListSize = 0;\r
+ OrderList = NULL;\r
+ OptionNumber = 0;\r
\r
- BootOrderList = BdsLibGetVariableAndSize (\r
- L"BootOrder",\r
- &gEfiGlobalVariableGuid,\r
- &BootOrderListSize\r
- );\r
- if (BootOrderList != NULL) {\r
- //\r
- // already have Boot####\r
- //\r
- // AlreadyBootNumbers = BootOrderListSize / sizeof(UINT16);\r
- //\r
- for (Index = 0; Index < BootOrderListSize / sizeof (UINT16); Index++) {\r
- Found = TRUE;\r
- for (Index2 = 0; Index2 < BootOptionMenu.MenuNumber; Index2++) {\r
- NewMenuEntry = BOpt_GetMenuEntry (&BootOptionMenu, Index2);\r
- if (Index == NewMenuEntry->OptionNumber) {\r
- Found = FALSE;\r
- break;\r
- }\r
- }\r
+ UnicodeSPrint (StrTemp, sizeof (StrTemp), L"%sOrder", Type);\r
\r
- if (Found) {\r
- UnicodeSPrint (StrTemp, 100, L"Boot%04x", Index);\r
- DEBUG((DEBUG_ERROR,"INdex= %s\n", StrTemp));\r
- OptionBuffer = BdsLibGetVariableAndSize (\r
+ OrderList = BdsLibGetVariableAndSize (\r
StrTemp,\r
&gEfiGlobalVariableGuid,\r
- &OptionSize\r
+ &OrderListSize\r
);\r
- if (NULL == OptionBuffer) {\r
- break;\r
- }\r
+ for (OptionNumber = 0; ; OptionNumber++) {\r
+ for (Index = 0; Index < OrderListSize / sizeof (UINT16); Index++) {\r
+ if (OptionNumber == OrderList[Index]) {\r
+ break;\r
}\r
}\r
- //\r
- // end for Index\r
- //\r
- Number = (UINT16) Index;\r
- } else {\r
- //\r
- // No Boot####\r
- //\r
- Number = 0;\r
+\r
+ if (Index < OrderListSize / sizeof (UINT16)) {\r
+ //\r
+ // The OptionNumber occurs in the OrderList, continue to use next one\r
+ //\r
+ continue;\r
+ }\r
+ UnicodeSPrint (StrTemp, sizeof (StrTemp), L"%s%04x", Type, (UINTN) OptionNumber);\r
+ DEBUG((EFI_D_ERROR,"Option = %s\n", StrTemp));\r
+ OptionBuffer = BdsLibGetVariableAndSize (\r
+ StrTemp,\r
+ &gEfiGlobalVariableGuid,\r
+ &OptionSize\r
+ );\r
+ if (NULL == OptionBuffer) {\r
+ //\r
+ // The Boot[OptionNumber] / Driver[OptionNumber] NOT occurs, we found it\r
+ //\r
+ break;\r
+ }\r
}\r
\r
- return Number;\r
+ return OptionNumber;\r
}\r
\r
/**\r
\r
- Get the Option Number that is not in use.\r
+ Get the Option Number for Boot#### that does not used.\r
\r
- @return The unused Option Number.\r
+ @return The available Option Number.\r
\r
**/\r
UINT16\r
-BOpt_GetDriverOptionNumber (\r
+BOpt_GetBootOptionNumber (\r
VOID\r
)\r
{\r
- BM_MENU_ENTRY *NewMenuEntry;\r
- UINT16 *DriverOrderList;\r
- UINTN DriverOrderListSize;\r
- UINT16 Number;\r
- UINTN Index;\r
- UINTN Index2;\r
- BOOLEAN Found;\r
+ return BOpt_GetOptionNumber (L"Boot");\r
+}\r
\r
- DriverOrderListSize = 0;\r
- DriverOrderList = NULL;\r
+/**\r
\r
- DriverOrderList = BdsLibGetVariableAndSize (\r
- L"DriverOrder",\r
- &gEfiGlobalVariableGuid,\r
- &DriverOrderListSize\r
- );\r
- if (DriverOrderList != NULL) {\r
- //\r
- // already have Driver####\r
- //\r
- // AlreadyDriverNumbers = DriverOrderListSize / sizeof(UINT16);\r
- //\r
- for (Index = 0; Index < DriverOrderListSize / sizeof (UINT16); Index++) {\r
- Found = TRUE;\r
- for (Index2 = 0; Index2 < DriverOptionMenu.MenuNumber; Index2++) {\r
- NewMenuEntry = BOpt_GetMenuEntry (&DriverOptionMenu, Index2);\r
- if (Index == NewMenuEntry->OptionNumber) {\r
- Found = FALSE;\r
- break;\r
- }\r
- }\r
+ Get the Option Number for Driver#### that does not used.\r
\r
- if (Found) {\r
- break;\r
- }\r
- }\r
- //\r
- // end for Index\r
- //\r
- Number = (UINT16) Index;\r
- } else {\r
- //\r
- // No Driver####\r
- //\r
- Number = 0;\r
- }\r
+ @return The unused Option Number.\r
\r
- return Number;\r
+**/\r
+UINT16\r
+BOpt_GetDriverOptionNumber (\r
+ VOID\r
+ )\r
+{\r
+ return BOpt_GetOptionNumber (L"Driver");\r
}\r
\r
/**\r