Fix Boot Option appear twice while add a new boot option in some specific steps.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9738 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
gikidy 2010-01-14 04:42:45 +00:00
parent 173eeac9eb
commit a5c3c546ea
2 changed files with 83 additions and 111 deletions

View File

@ -591,6 +591,20 @@ BOpt_IsEfiApp (
Get the Option Number that has not been allocated for use. Get the Option Number that has not been allocated for use.
@param Type The type of Option.
@return The available Option Number.
**/
UINT16
BOpt_GetOptionNumber (
CHAR16 *Type
);
/**
Get the Option Number for Boot#### that does not used.
@return The available Option Number. @return The available Option Number.
**/ **/
@ -601,9 +615,9 @@ BOpt_GetBootOptionNumber (
/** /**
Get the Option Number that is not in use. Get the Option Number for Driver#### that does not used.
@return The unused Option Number. @return The unused Option Number.
**/ **/
UINT16 UINT16

View File

@ -1407,6 +1407,70 @@ BOpt_FindDrivers (
Get the Option Number that has not been allocated for use. Get the Option Number that has not been allocated for use.
@param Type The type of Option.
@return The available Option Number.
**/
UINT16
BOpt_GetOptionNumber (
CHAR16 *Type
)
{
UINT16 *OrderList;
UINTN OrderListSize;
UINTN Index;
CHAR16 StrTemp[20];
UINT16 *OptionBuffer;
UINT16 OptionNumber;
UINTN OptionSize;
OrderListSize = 0;
OrderList = NULL;
OptionNumber = 0;
UnicodeSPrint (StrTemp, sizeof (StrTemp), L"%sOrder", Type);
OrderList = BdsLibGetVariableAndSize (
StrTemp,
&gEfiGlobalVariableGuid,
&OrderListSize
);
for (OptionNumber = 0; ; OptionNumber++) {
for (Index = 0; Index < OrderListSize / sizeof (UINT16); Index++) {
if (OptionNumber == OrderList[Index]) {
break;
}
}
if (Index < OrderListSize / sizeof (UINT16)) {
//
// The OptionNumber occurs in the OrderList, continue to use next one
//
continue;
}
UnicodeSPrint (StrTemp, sizeof (StrTemp), L"%s%04x", Type, (UINTN) OptionNumber);
DEBUG((EFI_D_ERROR,"Option = %s\n", StrTemp));
OptionBuffer = BdsLibGetVariableAndSize (
StrTemp,
&gEfiGlobalVariableGuid,
&OptionSize
);
if (NULL == OptionBuffer) {
//
// The Boot[OptionNumber] / Driver[OptionNumber] NOT occurs, we found it
//
break;
}
}
return OptionNumber;
}
/**
Get the Option Number for Boot#### that does not used.
@return The available Option Number. @return The available Option Number.
**/ **/
@ -1415,71 +1479,12 @@ BOpt_GetBootOptionNumber (
VOID VOID
) )
{ {
BM_MENU_ENTRY *NewMenuEntry; return BOpt_GetOptionNumber (L"Boot");
UINT16 *BootOrderList;
UINTN BootOrderListSize;
UINT16 Number;
UINTN Index;
UINTN Index2;
BOOLEAN Found;
CHAR16 StrTemp[100];
UINT16 *OptionBuffer;
UINTN OptionSize;
BootOrderListSize = 0;
BootOrderList = NULL;
BootOrderList = BdsLibGetVariableAndSize (
L"BootOrder",
&gEfiGlobalVariableGuid,
&BootOrderListSize
);
if (BootOrderList != NULL) {
//
// already have Boot####
//
// AlreadyBootNumbers = BootOrderListSize / sizeof(UINT16);
//
for (Index = 0; Index < BootOrderListSize / sizeof (UINT16); Index++) {
Found = TRUE;
for (Index2 = 0; Index2 < BootOptionMenu.MenuNumber; Index2++) {
NewMenuEntry = BOpt_GetMenuEntry (&BootOptionMenu, Index2);
if (Index == NewMenuEntry->OptionNumber) {
Found = FALSE;
break;
}
}
if (Found) {
UnicodeSPrint (StrTemp, 100, L"Boot%04x", Index);
DEBUG((DEBUG_ERROR,"INdex= %s\n", StrTemp));
OptionBuffer = BdsLibGetVariableAndSize (
StrTemp,
&gEfiGlobalVariableGuid,
&OptionSize
);
if (NULL == OptionBuffer) {
break;
}
}
}
//
// end for Index
//
Number = (UINT16) Index;
} else {
//
// No Boot####
//
Number = 0;
}
return Number;
} }
/** /**
Get the Option Number that is not in use. Get the Option Number for Driver#### that does not used.
@return The unused Option Number. @return The unused Option Number.
@ -1489,54 +1494,7 @@ BOpt_GetDriverOptionNumber (
VOID VOID
) )
{ {
BM_MENU_ENTRY *NewMenuEntry; return BOpt_GetOptionNumber (L"Driver");
UINT16 *DriverOrderList;
UINTN DriverOrderListSize;
UINT16 Number;
UINTN Index;
UINTN Index2;
BOOLEAN Found;
DriverOrderListSize = 0;
DriverOrderList = NULL;
DriverOrderList = BdsLibGetVariableAndSize (
L"DriverOrder",
&gEfiGlobalVariableGuid,
&DriverOrderListSize
);
if (DriverOrderList != NULL) {
//
// already have Driver####
//
// AlreadyDriverNumbers = DriverOrderListSize / sizeof(UINT16);
//
for (Index = 0; Index < DriverOrderListSize / sizeof (UINT16); Index++) {
Found = TRUE;
for (Index2 = 0; Index2 < DriverOptionMenu.MenuNumber; Index2++) {
NewMenuEntry = BOpt_GetMenuEntry (&DriverOptionMenu, Index2);
if (Index == NewMenuEntry->OptionNumber) {
Found = FALSE;
break;
}
}
if (Found) {
break;
}
}
//
// end for Index
//
Number = (UINT16) Index;
} else {
//
// No Driver####
//
Number = 0;
}
return Number;
} }
/** /**