MdeModulePkg: Process Sys Prep load options in BdsDxe driver.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17403 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Ruiyu Ni
2015-05-11 06:33:45 +00:00
committed by niruiyu
parent 573b8a86d0
commit 1634214dbb
8 changed files with 1160 additions and 1027 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -102,12 +102,13 @@ EfiBootManagerConnectAll (
a multi-instance device path
@param MatchingHandle Return the controller handle closest to the DevicePathToConnect
@retval EFI_SUCCESS All handles associate with every device path node
have been created
@retval EFI_OUT_OF_RESOURCES There is no resource to create new handles
@retval EFI_NOT_FOUND Create the handle associate with one device path
node failed
@retval EFI_SUCCESS All handles associate with every device path node
have been created.
@retval EFI_OUT_OF_RESOURCES There is no resource to create new handles.
@retval EFI_NOT_FOUND Create the handle associate with one device path
node failed.
@retval EFI_SECURITY_VIOLATION The user has no permission to start UEFI device
drivers on the DevicePath.
**/
EFI_STATUS
EFIAPI
@@ -166,9 +167,8 @@ EfiBootManagerConnectDevicePath (
// Connect all drivers that apply to Handle and RemainingDevicePath,
// the Recursive flag is FALSE so only one level will be expanded.
//
// Do not check the connect status here, if the connect controller fail,
// then still give the chance to do dispatch, because partial
// RemainingDevicepath may be in the new FV
// If ConnectController fails to find a driver, then still give the chance to
// do dispatch, because partial RemainingDevicePath may be in the new FV
//
// 1. If the connect fail, RemainingDevicepath and handle will not
// change, so next time will do the dispatch, then dispatch's status
@@ -177,7 +177,10 @@ EfiBootManagerConnectDevicePath (
// change, then avoid the dispatch, we have chance to continue the
// next connection
//
gBS->ConnectController (Handle, NULL, RemainingDevicePath, FALSE);
Status = gBS->ConnectController (Handle, NULL, RemainingDevicePath, FALSE);
if (Status == EFI_NOT_FOUND) {
Status = EFI_SUCCESS;
}
if (MatchingHandle != NULL) {
*MatchingHandle = Handle;
}

View File

@@ -695,28 +695,42 @@ EfiBootManagerConnectAllConsoles (
/**
This function will connect all the console devices base on the console
device variable ConIn, ConOut and ErrOut.
@retval EFI_DEVICE_ERROR All the consoles were not connected due to an error.
@retval EFI_SUCCESS Success connect any one instance of the console
device path base on the variable ConVarName.
**/
VOID
EFI_STATUS
EFIAPI
EfiBootManagerConnectAllDefaultConsoles (
VOID
)
{
EFI_STATUS Status;
BOOLEAN OneConnected;
BOOLEAN SystemTableUpdated;
EfiBootManagerConnectConsoleVariable (ConOut);
OneConnected = FALSE;
Status = EfiBootManagerConnectConsoleVariable (ConOut);
if (!EFI_ERROR (Status)) {
OneConnected = TRUE;
}
PERF_START (NULL, "ConOutReady", "BDS", 1);
PERF_END (NULL, "ConOutReady", "BDS", 0);
EfiBootManagerConnectConsoleVariable (ConIn);
Status = EfiBootManagerConnectConsoleVariable (ConIn);
if (!EFI_ERROR (Status)) {
OneConnected = TRUE;
}
PERF_START (NULL, "ConInReady", "BDS", 1);
PERF_END (NULL, "ConInReady", "BDS", 0);
//
// The _ModuleEntryPoint err out var is legal.
//
EfiBootManagerConnectConsoleVariable (ErrOut);
Status = EfiBootManagerConnectConsoleVariable (ErrOut);
if (!EFI_ERROR (Status)) {
OneConnected = TRUE;
}
PERF_START (NULL, "ErrOutReady", "BDS", 1);
PERF_END (NULL, "ErrOutReady", "BDS", 0);
@@ -745,4 +759,6 @@ EfiBootManagerConnectAllDefaultConsoles (
&gST->Hdr.CRC32
);
}
return OneConnected ? EFI_SUCCESS : EFI_DEVICE_ERROR;
}

File diff suppressed because it is too large Load Diff

View File

@@ -120,146 +120,6 @@ BmMatchDevicePaths (
return FALSE;
}
/**
Get the headers (dos, image, optional header) from an image
@param Device SimpleFileSystem device handle
@param FileName File name for the image
@param DosHeader Pointer to dos header
@param Hdr The buffer in which to return the PE32, PE32+, or TE header.
@retval EFI_SUCCESS Successfully get the machine type.
@retval EFI_NOT_FOUND The file is not found.
@retval EFI_LOAD_ERROR File is not a valid image file.
**/
EFI_STATUS
BmGetImageHeader (
IN EFI_HANDLE Device,
IN CHAR16 *FileName,
OUT EFI_IMAGE_DOS_HEADER *DosHeader,
OUT EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
)
{
EFI_STATUS Status;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Volume;
EFI_FILE_HANDLE Root;
EFI_FILE_HANDLE ThisFile;
UINTN BufferSize;
UINT64 FileSize;
EFI_FILE_INFO *Info;
Root = NULL;
ThisFile = NULL;
//
// Handle the file system interface to the device
//
Status = gBS->HandleProtocol (
Device,
&gEfiSimpleFileSystemProtocolGuid,
(VOID *) &Volume
);
if (EFI_ERROR (Status)) {
goto Done;
}
Status = Volume->OpenVolume (
Volume,
&Root
);
if (EFI_ERROR (Status)) {
Root = NULL;
goto Done;
}
ASSERT (Root != NULL);
Status = Root->Open (Root, &ThisFile, FileName, EFI_FILE_MODE_READ, 0);
if (EFI_ERROR (Status)) {
goto Done;
}
ASSERT (ThisFile != NULL);
//
// Get file size
//
BufferSize = SIZE_OF_EFI_FILE_INFO + 200;
do {
Info = NULL;
Status = gBS->AllocatePool (EfiBootServicesData, BufferSize, (VOID **) &Info);
if (EFI_ERROR (Status)) {
goto Done;
}
Status = ThisFile->GetInfo (
ThisFile,
&gEfiFileInfoGuid,
&BufferSize,
Info
);
if (!EFI_ERROR (Status)) {
break;
}
if (Status != EFI_BUFFER_TOO_SMALL) {
FreePool (Info);
goto Done;
}
FreePool (Info);
} while (TRUE);
FileSize = Info->FileSize;
FreePool (Info);
//
// Read dos header
//
BufferSize = sizeof (EFI_IMAGE_DOS_HEADER);
Status = ThisFile->Read (ThisFile, &BufferSize, DosHeader);
if (EFI_ERROR (Status) ||
BufferSize < sizeof (EFI_IMAGE_DOS_HEADER) ||
FileSize <= DosHeader->e_lfanew ||
DosHeader->e_magic != EFI_IMAGE_DOS_SIGNATURE) {
Status = EFI_LOAD_ERROR;
goto Done;
}
//
// Move to PE signature
//
Status = ThisFile->SetPosition (ThisFile, DosHeader->e_lfanew);
if (EFI_ERROR (Status)) {
Status = EFI_LOAD_ERROR;
goto Done;
}
//
// Read and check PE signature
//
BufferSize = sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION);
Status = ThisFile->Read (ThisFile, &BufferSize, Hdr.Pe32);
if (EFI_ERROR (Status) ||
BufferSize < sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION) ||
Hdr.Pe32->Signature != EFI_IMAGE_NT_SIGNATURE) {
Status = EFI_LOAD_ERROR;
goto Done;
}
//
// Check PE32 or PE32+ magic
//
if (Hdr.Pe32->OptionalHeader.Magic != EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC &&
Hdr.Pe32->OptionalHeader.Magic != EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
Status = EFI_LOAD_ERROR;
goto Done;
}
Done:
if (ThisFile != NULL) {
ThisFile->Close (ThisFile);
}
if (Root != NULL) {
Root->Close (Root);
}
return Status;
}
/**
This routine adjust the memory information for different memory type and
save them into the variables for next boot.
@@ -505,3 +365,22 @@ BmSetVariableAndReportStatusCodeOnError (
return Status;
}
/**
Print the device path info.
@param DevicePath The device path need to print.
**/
VOID
BmPrintDp (
EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
CHAR16 *Str;
Str = ConvertDevicePathToText (DevicePath, FALSE, FALSE);
DEBUG ((EFI_D_INFO, "%s", Str));
if (Str != NULL) {
FreePool (Str);
}
}

View File

@@ -100,6 +100,37 @@ CHAR16 *
IN EFI_HANDLE Handle
);
#define BM_OPTION_NAME_LEN sizeof ("SysPrep####")
extern CHAR16 *mBmLoadOptionName[];
typedef
VOID
(*VARIABLE_VISITOR) (
CHAR16 *Name,
EFI_GUID *Guid,
VOID *Context
);
/**
Call Visitor function for each variable in variable storage.
@param Visitor Visitor function.
@param Context The context passed to Visitor function.
**/
VOID
ForEachVariable (
VARIABLE_VISITOR Visitor,
VOID *Context
);
/**
Repair all the controllers according to the Driver Health status queried.
**/
VOID
BmRepairAllControllers (
VOID
);
#define BM_HOTKEY_SIGNATURE SIGNATURE_32 ('b', 'm', 'h', 'k')
typedef struct {
UINT32 Signature;
@@ -139,7 +170,7 @@ BmLoadEfiBootOption (
/**
Get the Option Number that wasn't used.
@param OrderVariableName Could be L"BootOrder" or L"DriverOrder".
@param LoadOptionType Load option type.
@param FreeOptionNumber To receive the minimal free option number.
@retval EFI_SUCCESS The option number is found
@@ -149,8 +180,8 @@ BmLoadEfiBootOption (
**/
EFI_STATUS
BmGetFreeOptionNumber (
IN CHAR16 *OrderVariableName,
OUT UINT16 *FreeOptionNumber
IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType,
OUT UINT16 *FreeOptionNumber
);
/**
@@ -294,6 +325,42 @@ BmSetVariableAndReportStatusCodeOnError (
IN VOID *Data
);
/**
Get the load option by its device path.
@param FilePath The device path pointing to a load option.
It could be a short-form device path.
@param FullPath Return the full device path of the load option after
short-form device path expanding.
Caller is responsible to free it.
@param FileSize Return the load option size.
@return The load option buffer. Caller is responsible to free the memory.
**/
VOID *
BmGetLoadOptionBuffer (
IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
OUT EFI_DEVICE_PATH_PROTOCOL **FullPath,
OUT UINTN *FileSize
);
/**
Return whether the PE header of the load option is valid or not.
@param[in] Type The load option type.
@param[in] FileBuffer The PE file buffer of the load option.
@param[in] FileSize The size of the load option file.
@retval TRUE The PE header of the load option is valid.
@retval FALSE The PE header of the load option is not valid.
**/
BOOLEAN
BmIsLoadOptionPeHeaderValid (
IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE Type,
IN VOID *FileBuffer,
IN UINTN FileSize
);
/**
Function compares a device path data structure to that of all the nodes of a
second device path instance.
@@ -361,4 +428,14 @@ BmRepairAllControllers (
VOID
);
/**
Print the device path info.
@param DevicePath The device path need to print.
**/
VOID
BmPrintDp (
EFI_DEVICE_PATH_PROTOCOL *DevicePath
);
#endif // _INTERNAL_BM_H_