/** @file
Provide boot option support for Application "BootMaint"
Include file system navigation, system handle selection
Boot option manipulation
Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>
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
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "BootMaint.h"
#include "BBSsupport.h"
/**
Create a menu entry by given menu type.
@param MenuType The Menu type to be created.
@retval NULL If failed to create the menu.
@return the new menu entry.
**/
)
{
//
// Get context size according to menu type
//
switch (MenuType) {
case BM_LOAD_CONTEXT_SELECT:
ContextSize = sizeof (BM_LOAD_CONTEXT);
break;
case BM_FILE_CONTEXT_SELECT:
ContextSize = sizeof (BM_FILE_CONTEXT);
break;
ContextSize = sizeof (BM_CONSOLE_CONTEXT);
break;
ContextSize = sizeof (BM_TERMINAL_CONTEXT);
break;
case BM_HANDLE_CONTEXT_SELECT:
ContextSize = sizeof (BM_HANDLE_CONTEXT);
break;
ContextSize = sizeof (BM_LEGACY_DEVICE_CONTEXT);
break;
default:
ContextSize = 0;
break;
}
if (ContextSize == 0) {
return NULL;
}
//
// Create new menu entry
//
return NULL;
}
return NULL;
}
return MenuEntry;
}
/**
Free up all resource allocated for a BM_MENU_ENTRY.
@param MenuEntry A pointer to BM_MENU_ENTRY.
**/
)
{
//
// Select by the type in Menu entry for current context type
//
switch (MenuEntry->ContextSelection) {
case BM_LOAD_CONTEXT_SELECT:
}
break;
case BM_FILE_CONTEXT_SELECT:
if (!FileContext->IsRoot) {
} else {
}
}
}
}
break;
break;
break;
case BM_HANDLE_CONTEXT_SELECT:
break;
default:
break;
}
}
}
/**
Get the Menu Entry from the list in Menu Entry List.
If MenuNumber is great or equal to the number of Menu
Entry in the list, then ASSERT.
@param MenuOption The Menu Entry List to read the menu entry.
@param MenuNumber The index of Menu Entry.
@return The Menu Entry.
**/
)
{
}
return NewMenuEntry;
}
/**
This function build the FsOptionMenu list which records all
available file system in the system. They includes all instances
of EFI_SIMPLE_FILE_SYSTEM_PROTOCOL, all instances of EFI_LOAD_FILE_SYSTEM
and all type of legacy boot device.
@param CallbackData BMM context data
@retval EFI_SUCCESS Success find the file system
@retval EFI_OUT_OF_RESOURCES Can not create menu entry
**/
)
{
NoSimpleFsHandles = 0;
NoLoadFileHandles = 0;
OptionNumber = 0;
//
// Locate Handles that support BlockIo protocol
//
NULL,
);
);
continue;
}
//
// Issue a dummy read to trigger reinstall of BlockIo protocol for removable media
//
return EFI_OUT_OF_RESOURCES;
}
BlkIo->ReadBlocks (
0,
);
}
}
}
//
// Locate Handles that support Simple File System protocol
//
NULL,
);
//
// Find all the instances of the File System prototocol
//
);
//
// If no block IO exists assume it's NOT a removable media
//
} else {
//
// If block IO exists check to see if it's remobable media
//
}
//
// Allocate pool for this load option
//
return EFI_OUT_OF_RESOURCES;
}
continue;
}
);
//
// Get current file system's Volume Label
//
VolumeLabel = L"NO FILE SYSTEM INFO";
} else {
VolumeLabel = L"NULL VOLUME LABEL";
} else {
if (*VolumeLabel == 0x0000) {
VolumeLabel = L"NO VOLUME LABEL";
}
}
}
L"%s, [%s]",
);
OptionNumber++;
}
}
if (NoSimpleFsHandles != 0) {
}
//
// Searching for handles that support Load File protocol
//
NULL,
);
return EFI_OUT_OF_RESOURCES;
}
L"Load File [%s]",
);
OptionNumber++;
}
}
if (NoLoadFileHandles != 0) {
}
//
// Add Legacy Boot Option Support Here
//
NULL,
(VOID **) &LegacyBios
);
return EFI_OUT_OF_RESOURCES;
}
sizeof (BBS_BBS_DEVICE_PATH)
);
BbsDevicePathNode.String[0] = 0;
);
L"Boot Legacy [%s]",
);
OptionNumber++;
}
}
//
// Remember how many file system options are here
//
return EFI_SUCCESS;
}
/**
Free resources allocated in Allocate Rountine.
@param FreeMenu Menu to be freed
**/
)
{
Link,
);
}
FreeMenu->MenuNumber = 0;
}
/**
Find files under current directory
All files and sub-directories in current directory
will be stored in DirectoryMenu for future use.
@param CallbackData The BMM context data.
@param MenuEntry The Menu Entry.
@retval EFI_SUCCESS Get files from current dir successfully.
@return Other value if can't get files from current dir.
**/
)
{
OptionNumber = 0;
//
// Open current directory to get files from it
//
Dir,
&NewDir,
0
);
if (!FileContext->IsRoot) {
}
return Status;
}
return EFI_NOT_FOUND;
}
return EFI_INVALID_PARAMETER;
}
);
return EFI_OUT_OF_RESOURCES;
}
//
// Get all files in current directory
// Pass 1 to get Directories
// Pass 2 to get files that are EFI images
//
for (;;) {
break;
}
) {
//
// Pass 1 is for Directories
// Pass 2 is for file names
//
continue;
}
//
// Slip file unless it is a directory entry or a .EFI file
//
continue;
}
if (NULL == NewMenuEntry) {
return EFI_OUT_OF_RESOURCES;
}
);
);
);
NewFileContext->IsDir = (BOOLEAN) ((DirInfo->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY);
if (NewFileContext->IsDir) {
L"<%s>",
);
} else {
}
OptionNumber++;
}
}
return EFI_SUCCESS;
}
/**
Build the LegacyFDMenu LegacyHDMenu LegacyCDMenu according to LegacyBios.GetBbsInfo().
@retval EFI_SUCCESS The function complete successfully.
@retval EFI_OUT_OF_RESOURCES No enough memory to complete this function.
**/
)
{
NewMenuEntry = NULL;
BbsCount = 0;
//
// Initialize Bbs Table Context from BBS info data
//
NULL,
(VOID **) &LegacyBios
);
&HddCount,
&HddInfo,
&BbsCount,
);
return Status;
}
}
FDNum = 0;
HDNum = 0;
CDNum = 0;
NETNum = 0;
BEVNum = 0;
) {
continue;
}
if (NULL == NewMenuEntry) {
break;
}
sizeof (DescString),
);
break;
}
case BBS_FLOPPY:
FDNum++;
break;
case BBS_HARDDISK:
HDNum++;
break;
case BBS_CDROM:
CDNum++;
break;
case BBS_EMBED_NETWORK:
NETNum++;
break;
case BBS_BEV_DEVICE:
BEVNum++;
break;
}
}
return EFI_OUT_OF_RESOURCES;
}
return EFI_SUCCESS;
}
/**
Free out resouce allocated from Legacy Boot Options.
**/
)
{
}
/**
Build the BootOptionMenu according to BootOrder Variable.
This Routine will access the Boot#### to get EFI_LOAD_OPTION.
@param CallbackData The BMM context data.
@return EFI_NOT_FOUND Fail to find "BootOrder" variable.
@return EFI_SUCESS Success build boot option menu.
**/
)
{
MenuCount = 0;
BootOrderListSize = 0;
BootNextSize = 0;
//
// Get the BootOrder from the Var
//
L"BootOrder",
);
if (BootOrderList == NULL) {
return EFI_NOT_FOUND;
}
//
// Get the BootNext from the Var
//
L"BootNext",
);
if (BootNextSize != sizeof (UINT16)) {
}
}
//
// Get all loadoptions from the VAR
//
);
if (LoadOptionFromVar == NULL) {
continue;
}
if (LoadOption == NULL) {
continue;
}
} else {
}
continue;
}
//
// BUGBUG: could not return EFI_OUT_OF_RESOURCES here directly.
// the buffer allocated already should be freed before returning.
//
if (NULL == NewMenuEntry) {
return EFI_OUT_OF_RESOURCES;
}
//
// Is a Legacy Device?
//
//
// Attribute = *(UINT32 *)Ptr;
//
//
// FilePathSize = *(UINT16 *)Ptr;
//
//
// Description = (CHAR16 *)Ptr;
//
//
// Now Ptr point to Device Path
//
} else {
}
//
// LoadOption is a pointer type of UINT8
// for easy use with following LOAD_OPTION
// embedded in this struct
//
NewLoadContext->ForceReconnect = (BOOLEAN) (NewLoadContext->Attributes & LOAD_OPTION_FORCE_RECONNECT);
LoadOptionPtr += sizeof (UINT32);
LoadOptionPtr += sizeof (UINT16);
CopyMem (
);
);
);
if (LoadOptionPtr < LoadOptionEnd) {
sizeof (UINT32) -
sizeof (UINT16) -
CopyMem (
);
}
MenuCount++;
}
}
if (BootOrderList != NULL) {
}
return EFI_SUCCESS;
}
/**
Append file name to existing file name.
@param Str1 The existing file name
@param Str2 The file name to be appended
@return Allocate a new string to hold the appended result.
Caller is responsible to free the returned string.
**/
CHAR16 *
)
{
}
while (*Ptr != 0) {
//
// Convert "\Name\..\" to "\"
// DO NOT convert the .. if it is at the end of the string. This will
// break the .. behavior in changing directories.
//
//
// Use TmpStr as a backup, as StrCpy in BaseLib does not handle copy of two strings
// that overlap.
//
//
// Convert a "\.\" to a "\"
//
//
// Use TmpStr as a backup, as StrCpy in BaseLib does not handle copy of two strings
// that overlap.
//
} else if (*Ptr == '\\') {
}
Ptr++;
}
return Str;
}
/**
Check whether current FileName point to a valid
Efi Image File.
@param FileName File need to be checked.
@retval TRUE Is Efi Image
@retval FALSE Not a valid Efi Image
**/
)
{
//
// Search for ".efi" extension
//
while (*FileName != L'\0') {
if (FileName[0] == '.') {
return TRUE;
return FALSE;
}
return FALSE;
}
return FALSE;
}
}
FileName += 1;
}
return FALSE;
}
/**
Check whether current FileName point to a valid Efi Application
@param Dir Pointer to current Directory
@param FileName Pointer to current File name.
@retval TRUE Is a valid Efi Application
@retval FALSE not a valid Efi Application
**/
)
{
return FALSE;
}
BufferSize = sizeof (EFI_IMAGE_DOS_HEADER);
return FALSE;
}
BufferSize = sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION);
return FALSE;
}
//
// Determine PE type and read subsytem
//
} else {
return FALSE;
}
if (Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) {
return TRUE;
} else {
return FALSE;
}
}
/**
Find drivers that will be added as Driver#### variables from handles
in current system environment
All valid handles in the system except those consume SimpleFs, LoadFile
are stored in DriverMenu for future use.
@retval EFI_SUCCESS The function complets successfully.
@return Other value if failed to build the DriverMenu.
**/
)
{
//
// At first, get all handles that support Device Path
// protocol which is the basic requirement for
// Driver####
//
NULL,
);
return Status;
}
OptionNumber = 0;
);
if (Status == EFI_SUCCESS) {
continue;
}
);
if (Status == EFI_SUCCESS) {
continue;
}
if (NULL == NewMenuEntry) {
return EFI_OUT_OF_RESOURCES;
}
OptionNumber++;
}
if (DevicePathHandle != NULL) {
}
return EFI_SUCCESS;
}
/**
Get the Option Number that has not been allocated for use.
@param Type The type of Option.
@return The available Option Number.
**/
)
{
OrderListSize = 0;
OptionNumber = 0;
Index = 0;
);
for (OptionNumber = 0; ; OptionNumber++) {
break;
}
}
}
//
// The OptionNumber occurs in the OrderList, continue to use next one
//
continue;
}
);
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 BOpt_GetOptionNumber (L"Boot");
}
/**
Get the Option Number for Driver#### that does not used.
@return The unused Option Number.
**/
)
{
return BOpt_GetOptionNumber (L"Driver");
}
/**
Build up all DriverOptionMenu
@param CallbackData The BMM context data.
@retval EFI_SUCESS The functin completes successfully.
@retval EFI_OUT_OF_RESOURCES Not enough memory to compete the operation.
@retval EFI_NOT_FOUND Fail to get "DriverOrder" variable.
**/
)
{
DriverOrderListSize = 0;
DriverOptionSize = 0;
//
// Get the DriverOrder from the Var
//
L"DriverOrder",
);
if (DriverOrderList == NULL) {
return EFI_NOT_FOUND;
}
sizeof (DriverString),
L"Driver%04x",
);
//
// Get all loadoptions from the VAR
//
);
if (LoadOptionFromVar == NULL) {
continue;
}
if (LoadOption == NULL) {
continue;
}
if (NULL == NewMenuEntry) {
return EFI_OUT_OF_RESOURCES;
}
//
// LoadOption is a pointer type of UINT8
// for easy use with following LOAD_OPTION
// embedded in this struct
//
NewLoadContext->ForceReconnect = (BOOLEAN) (NewLoadContext->Attributes & LOAD_OPTION_FORCE_RECONNECT);
LoadOptionPtr += sizeof (UINT32);
LoadOptionPtr += sizeof (UINT16);
CopyMem (
(UINT16 *) LoadOptionPtr,
);
CopyMem (
);
);
);
if (LoadOptionPtr < LoadOptionEnd) {
sizeof (UINT32) -
sizeof (UINT16) -
CopyMem (
);
}
}
if (DriverOrderList != NULL) {
}
return EFI_SUCCESS;
}