\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