bdsmisc.c
来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 1,279 行 · 第 1/3 页
C
1,279 行
)
/*++
Routine Description:
Enable the setup browser reset reminder feature.
This routine is used in platform tip. If the platform policy need the feature, use the routine to enable it.
Arguments:
VOID
Returns:
VOID
--*/
{
mFeaturerSwitch = TRUE;
}
VOID
DisableResetReminderFeature (
VOID
)
/*++
Routine Description:
Disable the setup browser reset reminder feature.
This routine is used in platform tip. If the platform policy do not want the feature, use the routine to disable it.
Arguments:
VOID
Returns:
VOID
--*/
{
mFeaturerSwitch = FALSE;
}
VOID
EnableResetRequired (
VOID
)
/*++
Routine Description:
Record the info that a reset is required.
A module boolean variable is used to record whether a reset is required.
Arguments:
VOID
Returns:
VOID
--*/
{
mResetRequired = TRUE;
}
VOID
DisableResetRequired (
VOID
)
/*++
Routine Description:
Record the info that no reset is required.
A module boolean variable is used to record whether a reset is required.
Arguments:
VOID
Returns:
VOID
--*/
{
mResetRequired = FALSE;
}
BOOLEAN
IsResetReminderFeatureEnable (
VOID
)
/*++
Routine Description:
Check whether platform policy enable the reset reminder feature. The default is enabled.
Arguments:
VOID
Returns:
VOID
--*/
{
return mFeaturerSwitch;
}
BOOLEAN
IsResetRequired (
VOID
)
/*++
Routine Description:
Check if user changed any option setting which needs a system reset to be effective.
Arguments:
VOID
Returns:
VOID
--*/
{
return mResetRequired;
}
VOID
SetupResetReminder (
VOID
)
/*++
Routine Description:
Check whether a reset is needed, and finish the reset reminder feature.
If a reset is needed, Popup a menu to notice user, and finish the feature
according to the user selection.
Arguments:
VOID
Returns:
VOID
--*/
{
EFI_STATUS Status;
EFI_FORM_BROWSER_PROTOCOL *Browser;
EFI_INPUT_KEY Key;
CHAR16 *StringBuffer1;
CHAR16 *StringBuffer2;
//
//check any reset required change is applied? if yes, reset system
//
if (IsResetReminderFeatureEnable ()) {
if (IsResetRequired ()) {
Status = gBS->LocateProtocol (
&gEfiFormBrowserProtocolGuid,
NULL,
&Browser
);
StringBuffer1 = EfiLibAllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));
ASSERT (StringBuffer1 != NULL);
StringBuffer2 = EfiLibAllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));
ASSERT (StringBuffer2 != NULL);
EfiStrCpy (StringBuffer1, L"Configuration changed. Reset to apply it Now ? ");
EfiStrCpy (StringBuffer2, L"Enter (YES) / Esc (NO)");
//
// Popup a menu to notice user
//
do {
Browser->CreatePopUp (2, TRUE, 0, NULL, &Key, StringBuffer1, StringBuffer2);
} while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));
gBS->FreePool (StringBuffer1);
gBS->FreePool (StringBuffer2);
//
// If the user hits the YES Response key, reset
//
if ((Key.UnicodeChar == CHAR_CARRIAGE_RETURN)) {
gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);
}
gST->ConOut->ClearScreen (gST->ConOut);
}
}
}
EFI_STATUS
BdsLibGetImageHeader (
IN EFI_HANDLE Device,
IN CHAR16 *FileName,
OUT EFI_IMAGE_DOS_HEADER *DosHeader,
OUT EFI_IMAGE_FILE_HEADER *ImageHeader,
OUT EFI_IMAGE_OPTIONAL_HEADER *OptionalHeader
)
/*++
Routine Description:
Get the headers (dos, image, optional header) from an image
Arguments:
Device - SimpleFileSystem device handle
FileName - File name for the image
DosHeader - Pointer to dos header
ImageHeader - Pointer to image header
OptionalHeader - Pointer to optional header
Returns:
EFI_SUCCESS - Successfully get the machine type.
EFI_NOT_FOUND - The file is not found.
EFI_LOAD_ERROR - File is not a valid image file.
--*/
{
EFI_STATUS Status;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Volume;
EFI_FILE_HANDLE Root;
EFI_FILE_HANDLE ThisFile;
UINT32 Signature;
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)) {
goto Done;
}
Status = Root->Open (Root, &ThisFile, FileName, EFI_FILE_MODE_READ, 0);
if (EFI_ERROR (Status)) {
goto Done;
}
//
// Get file size
//
BufferSize = SIZE_OF_EFI_FILE_INFO + 200;
do {
Info = NULL;
Status = gBS->AllocatePool (EfiBootServicesData, BufferSize, &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) {
goto Done;
}
gBS->FreePool (Info);
} while (TRUE);
FileSize = Info->FileSize;
gBS->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 (Signature);
Status = ThisFile->Read (ThisFile, &BufferSize, &Signature);
if (EFI_ERROR (Status) ||
BufferSize < sizeof (Signature) ||
Signature != EFI_IMAGE_NT_SIGNATURE) {
Status = EFI_LOAD_ERROR;
goto Done;
}
//
// Read image header
//
BufferSize = EFI_IMAGE_SIZEOF_FILE_HEADER;
Status = ThisFile->Read (ThisFile, &BufferSize, ImageHeader);
if (EFI_ERROR (Status) ||
BufferSize < EFI_IMAGE_SIZEOF_FILE_HEADER) {
Status = EFI_LOAD_ERROR;
goto Done;
}
//
// Read optional header
//
BufferSize = ImageHeader->SizeOfOptionalHeader;
Status = ThisFile->Read (ThisFile, &BufferSize, OptionalHeader);
if (EFI_ERROR (Status) ||
BufferSize < ImageHeader->SizeOfOptionalHeader) {
Status = EFI_LOAD_ERROR;
goto Done;
}
//
// Check PE32 or PE32+ magic
//
if (OptionalHeader->Magic != EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC &&
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;
}
EFI_STATUS
BdsLibGetHiiHandles (
IN EFI_HII_PROTOCOL *Hii,
IN OUT UINT16 *HandleBufferLength,
OUT EFI_HII_HANDLE **HiiHandleBuffer
)
/*++
Routine Description:
Determines the handles that are currently active in the database.
It's the caller's responsibility to free handle buffer.
Arguments:
This - A pointer to the EFI_HII_PROTOCOL instance.
HandleBufferLength - On input, a pointer to the length of the handle buffer. On output,
the length of the handle buffer that is required for the handles found.
HiiHandleBuffer - Pointer to an array of EFI_HII_PROTOCOL instances returned.
Returns:
EFI_SUCCESS - Get an array of EFI_HII_PROTOCOL instances successfully.
EFI_INVALID_PARAMETER - Hii is NULL.
EFI_NOT_FOUND - Database not found.
--*/
{
UINT16 TempBufferLength;
EFI_STATUS Status;
TempBufferLength = 0;
//
// Try to find the actual buffer size for HiiHandle Buffer.
//
Status = Hii->FindHandles (Hii, &TempBufferLength, *HiiHandleBuffer);
if (Status == EFI_BUFFER_TOO_SMALL) {
*HiiHandleBuffer = EfiLibAllocateZeroPool (TempBufferLength);
Status = Hii->FindHandles (Hii, &TempBufferLength, *HiiHandleBuffer);
//
// we should not fail here.
//
ASSERT_EFI_ERROR (Status);
}
*HandleBufferLength = TempBufferLength;
return Status;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?