/** @file
Misc BDS library function
Copyright (c) 2004 - 2012, 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 "InternalBdsLib.h"
extern UINT16 gPlatformBootTimeOutDefault;
/**
The function will go through the driver option link list, load and start
every driver the driver option device path point to.
@param BdsDriverLists The header of the current driver option link list
**/
)
{
//
// Process the driver option
//
//
// If a load option is not marked as LOAD_OPTION_ACTIVE,
// the boot manager will not automatically load the option.
//
continue;
}
//
// If a driver load option is marked as LOAD_OPTION_FORCE_RECONNECT,
// then all of the EFI drivers in the system will be disconnected and
// reconnected after the last driver load option is processed.
//
ReconnectAll = TRUE;
}
//
// Make sure the driver path is connected.
//
//
// Load and start the image that Driver#### describes
//
NULL,
0,
);
//
// Verify whether this image is a driver, if not,
// exit it and continue to parse next load option
//
if (ImageInfo->ImageCodeType != EfiBootServicesCode && ImageInfo->ImageCodeType != EfiRuntimeServicesCode) {
continue;
}
if (Option->LoadOptionsSize != 0) {
}
//
// Before calling the image, enable the Watchdog Timer for
// the 5 Minute period
//
//
// Clear the Watchdog Timer after the image returns
//
}
}
//
// Process the LOAD_OPTION_FORCE_RECONNECT driver option
//
if (ReconnectAll) {
BdsLibConnectAll ();
}
}
/**
Get the Option Number that does not used.
Try to locate the specific option variable one by one utile find a free number.
@param VariableName Indicate if the boot#### or driver#### option
@return The Minimal Free Option Number
**/
)
{
//
// Try to find the minimum free number from 0, 1, 2, 3....
//
Index = 0;
do {
if (*VariableName == 'B') {
} else {
}
//
// try if the option number is used
//
);
if (OptionBuffer == NULL) {
break;
}
Index++;
} while (TRUE);
}
/**
This function will register the new boot#### or driver#### option base on
the VariableName. The new registered boot#### or driver#### will be linked
to BdsOptionList and also update to the VariableName. After the boot#### or
driver#### updated, the BootOrder or DriverOrder will also be updated.
@param BdsOptionList The header of the boot#### or driver#### link list
@param DevicePath The device path which the boot#### or driver####
option present
@param String The description of the boot#### or driver####
@param VariableName Indicate if the boot#### or driver#### option
@retval EFI_SUCCESS The boot#### or driver#### have been success
registered
@retval EFI_STATUS Return the status of gRT->SetVariable ().
**/
)
{
OptionSize = 0;
Description = NULL;
TempOptionSize = 0;
);
//
// Compare with current option variable if the previous option is set in global variable.
//
//
// TempOptionPtr must not be NULL if we have non-zero TempOptionSize.
//
if (*VariableName == 'B') {
} else {
}
);
continue;
}
//
// Validate the variable.
//
continue;
}
//
// Notes: the description may will change base on the GetStringToken
//
//
// Got the option, so just return
//
return EFI_SUCCESS;
} else {
//
// Option description changed, need update.
//
break;
}
}
}
if (UpdateDescription) {
//
// The number in option#### to be updated.
// In this case, we must have non-NULL TempOptionPtr.
//
} else {
//
// The new option#### number
//
}
if (*VariableName == 'B') {
} else {
}
);
//
// Return if only need to update a changed description or fail to set option.
//
if (TempOptionPtr != NULL) {
}
return Status;
}
//
// Update the option order variable
//
//
// If no option order
//
if (TempOptionSize == 0) {
BootOrderEntry = 0;
sizeof (UINT16),
);
if (TempOptionPtr != NULL) {
}
return Status;
}
//
// TempOptionPtr must not be NULL if TempOptionSize is not zero.
//
//
// Append the new option number to the original option order
//
OrderItemNum * sizeof (UINT16),
);
return Status;
}
/**
Returns the size of a device path in bytes.
This function returns the size, in bytes, of the device path data structure
specified by DevicePath including the end of device path node. If DevicePath
is NULL, then 0 is returned. If the length of the device path is bigger than
MaxSize, also return 0 to indicate this is an invalidate device path.
@param DevicePath A pointer to a device path data structure.
@param MaxSize Max valid device path size. If big than this size,
return error.
@retval 0 An invalid device path.
@retval Others The size of a device path in bytes.
**/
)
{
if (DevicePath == NULL) {
return 0;
}
//
// Search for the end of the device path structure
//
Size = 0;
while (!IsDevicePathEnd (DevicePath)) {
if (NodeSize < END_DEVICE_PATH_LENGTH) {
return 0;
}
return 0;
}
}
return 0;
}
return Size;
}
/**
Returns the length of a Null-terminated Unicode string. If the length is
bigger than MaxStringLen, return length 0 to indicate that this is an
invalidate string.
This function returns the number of Unicode characters in the Null-terminated
Unicode string specified by String.
If String is NULL, then ASSERT().
If String is not aligned on a 16-bit boundary, then ASSERT().
@param String A pointer to a Null-terminated Unicode string.
@param MaxStringLen Max string len in this string.
@retval 0 An invalid string.
@retval Others The length of String.
**/
)
{
return 0;
}
}
/**
Validate the EFI Boot#### variable (VendorGuid/Name)
@param Variable Boot#### variable data.
@param VariableSize Returns the size of the EFI variable that was read
@retval TRUE The variable data is correct.
@retval FALSE The variable data is corrupted.
**/
)
{
//
// Skip the option attribute
//
//
// Get the option's device path size
//
//
// Get the option's description string size
//
//
// Get the option's device path
//
TempPtr += FilePathSize;
//
// Validation boot option variable.
//
if ((FilePathSize == 0) || (TempSize == 0)) {
return FALSE;
}
return FALSE;
}
while (FilePathSize > 0) {
if (TempSize == 0) {
return FALSE;
}
}
return TRUE;
}
/**
Convert a single character to number.
It assumes the input Char is in the scope of L'0' ~ L'9' and L'A' ~ L'F'
@param Char The input char which need to change to a hex number.
**/
)
{
}
}
return 0;
}
/**
Build the boot#### or driver#### option from the VariableName, the
build boot#### or driver#### will also be linked to BdsCommonOptionList.
@param BdsCommonOptionList The header of the boot#### or driver#### option
link list
@param VariableName EFI Variable name indicate if it is boot#### or
driver####
@retval BDS_COMMON_OPTION Get the option just been created
@retval NULL Failed to get the new option
**/
)
{
//
// Read the variable. We will never free this data.
//
);
return NULL;
}
//
// Validate Boot#### variable data.
//
return NULL;
}
//
// Notes: careful defined the variable of Boot#### or
// Driver####, consider use some macro to abstract the code
//
//
// Get the option attribute
//
//
// Get the option's device path size
//
//
// Get the option's description string
//
//
// Get the option's description string size
//
if (TempSize == 0) {
return NULL;
}
//
// Get the option's device path
//
TempPtr += FilePathSize;
//
// Validation device path.
//
while (FilePathSize > 0) {
if (TempSize == 0) {
return NULL;
}
}
//
// Get load opion data.
//
return NULL;
}
//
// The Console variables may have multiple device paths, so make
// an Entry for each one.
//
return NULL;
}
#ifdef VBOX /* We need the OptionName later for Mac OS x related "Boot0080" hacks. */
#endif
//
// Get the value from VariableName Unicode string
// since the ISO standard assumes ASCII equivalent abbreviations, we can be safe in converting this
// Unicode stream to ASCII without any loss in meaning.
//
if (*VariableName == 'B') {
}
//
// Insert active entry to BdsDeviceList
//
return Option;
}
#ifdef VBOX
#endif
return NULL;
}
/**
Process BootOrder, or DriverOrder variables, by calling
BdsLibVariableToOption () for each UINT16 in the variables.
@param BdsCommonOptionList The header of the option list base on variable
VariableName
@param VariableName EFI Variable name indicate the BootOrder or
DriverOrder
@retval EFI_SUCCESS Success create the boot option or driver option
list
@retval EFI_OUT_OF_RESOURCES Failed to get the boot option or driver option list
**/
)
{
//
// Zero Buffer in order to get all BOOT#### variables
//
//
// Read the BootOrder, or DriverOrder variable.
//
);
if (OptionOrder == NULL) {
return EFI_OUT_OF_RESOURCES;
}
if (*VariableName == 'B') {
} else {
}
}
}
return EFI_SUCCESS;
}
/**
Get boot mode by looking up configuration table and parsing HOB list
@param BootMode Boot mode from PEI handoff HOB.
@retval EFI_SUCCESS Successfully get boot mode
**/
)
{
*BootMode = GetBootModeHob ();
return EFI_SUCCESS;
}
/**
Read the EFI variable (VendorGuid/Name) and return a dynamically allocated
buffer, and the size of the buffer. If failure return NULL.
@param Name String part of EFI variable name
@param VendorGuid GUID part of EFI variable name
@param VariableSize Returns the size of the EFI variable that was read
@return Dynamically allocated memory that contains a copy of the EFI variable
Caller is responsible freeing the buffer.
@retval NULL Variable was not read
**/
VOID *
)
{
//
// Pass in a zero size buffer to find the required buffer size.
//
BufferSize = 0;
if (Status == EFI_BUFFER_TOO_SMALL) {
//
// Allocate the buffer to return
//
return NULL;
}
//
// Read variable into the allocated buffer.
//
BufferSize = 0;
}
}
return Buffer;
}
/**
Delete the instance in Multi which matches partly with Single instance
@param Multi A pointer to a multi-instance device path data
structure.
@param Single A pointer to a single-instance device path data
structure.
@return This function will remove the device path instances in Multi which partly
match with the Single, and return the result device path. If there is no
remaining device path as a result, this function will return NULL.
**/
)
{
return Multi;
}
//
// Append the device path instance which does not match with Single
//
if (TempNewDevicePath != NULL) {
}
}
}
return NewDevicePath;
}
/**
Function compares a device path data structure to that of all the nodes of a
second device path instance.
@param Multi A pointer to a multi-instance device path data
structure.
@param Single A pointer to a single-instance device path data
structure.
@retval TRUE If the Single device path is contained within Multi device path.
@retval FALSE The Single device path is not match within Multi device path.
**/
)
{
return FALSE;
}
DevicePath = Multi;
//
// Search for the match of 'Single' in 'Multi'
//
while (DevicePathInst != NULL) {
//
// If the single device path is found in multiple device paths,
// return success
//
return TRUE;
}
}
return FALSE;
}
/**
This function prints a series of strings.
@param ConOut Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
@param ... A variable argument list containing series of
strings, the last string must be NULL.
@retval EFI_SUCCESS Success print out the string using ConOut.
@retval EFI_STATUS Return the status of the ConOut->OutputString ().
**/
...
)
{
//
// If String is NULL, then it's the end of the list
//
break;
}
break;
}
}
return Status;
}
//
// Following are BDS Lib functions which contain all the code about setup browser reset reminder feature.
// Setup Browser reset reminder feature is that an reset reminder will be given before user leaves the setup browser if
// user change any option setting which needs a reset to be effective, and the reset will be applied according to the user selection.
//
/**
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.
**/
)
{
}
/**
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.
**/
)
{
}
/**
Record the info that a reset is required.
A module boolean variable is used to record whether a reset is required.
**/
)
{
}
/**
Record the info that no reset is required.
A module boolean variable is used to record whether a reset is required.
**/
)
{
}
/**
Check whether platform policy enable the reset reminder feature. The default is enabled.
**/
)
{
return mFeaturerSwitch;
}
/**
Check if user changed any option setting which needs a system reset to be effective.
**/
)
{
return mResetRequired;
}
/**
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.
**/
)
{
//
//check any reset required change is applied? if yes, reset system
//
if (IsResetReminderFeatureEnable ()) {
if (IsResetRequired ()) {
//
// Popup a menu to notice user
//
do {
//
// If the user hits the YES Response key, reset
//
}
}
}
}
/**
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.
**/
)
{
#ifdef VBOX
#endif
//
// Handle the file system interface to the device
//
);
goto Done;
}
&Root
);
goto Done;
}
goto Done;
}
//
// Get file size
//
do {
goto Done;
}
);
break;
}
if (Status != EFI_BUFFER_TOO_SMALL) {
goto Done;
}
} while (TRUE);
//
// Read dos header
//
BufferSize = sizeof (EFI_IMAGE_DOS_HEADER);
if (
#ifdef VBOX
#endif
|| BufferSize < sizeof (EFI_IMAGE_DOS_HEADER)
goto Done;
}
#ifdef VBOX
if (fAnalyzeDosHeader)
{
#endif
//
// Move to PE signature
//
goto Done;
}
//
// Read and check PE signature
//
BufferSize = sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION);
BufferSize < sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION) ||
goto Done;
}
//
// Check PE32 or PE32+ magic
//
goto Done;
}
#ifdef VBOX
}
#endif
Done:
}
}
return Status;
}
/**
This routine adjusts the memory information for different memory type and
saves them into the variables for next boot. It conditionally resets the
system when the memory information changes. Platform can reserve memory
large enough (125% of actual requirement) to avoid the reset in the first boot.
**/
)
{
BootMode = GetBootModeHob ();
//
// In BOOT_IN_RECOVERY_MODE, Variable region is not reliable.
//
if (BootMode == BOOT_IN_RECOVERY_MODE) {
return;
}
//
// Only check the the Memory Type Information variable in the boot mode
// other than BOOT_WITH_DEFAULT_SETTINGS because the Memory Type
// Information is not valid in this boot mode.
//
if (BootMode != BOOT_WITH_DEFAULT_SETTINGS) {
VariableSize = 0;
NULL,
);
if (Status == EFI_BUFFER_TOO_SMALL) {
}
}
//
// Retrieve the current memory usage statistics. If they are not found, then
// no adjustments can be made to the Memory Type Information variable.
//
);
return;
}
//
// Get the Memory Type Information settings from Hob if they exist,
// PEI is responsible for getting them from variable and build a Hob to save them.
// If the previous Memory Type Information is not available, then set defaults
//
//
// If Platform has not built Memory Type Info into the Hob, just return.
//
return;
}
//
// Use a heuristic to adjust the Memory Type Information for the next boot
//
break;
}
}
continue;
}
//
// Previous is the number of pages pre-allocated
// Current is the number of pages actually needed
//
//
// Write next varible to 125% * current and Inconsistent Memory Reserved across bootings may lead to S4 fail
//
if (BootMode == BOOT_WITH_DEFAULT_SETTINGS) {
} else if (!MemoryTypeInformationVariableExists) {
}
}
Next = 4;
}
}
DEBUG ((EFI_D_INFO, " %02x %08x %08x %08x\n", PreviousMemoryTypeInformation[Index].Type, Previous, Current, Next));
}
//
// If any changes were made to the Memory Type Information settings, then set the new variable value;
// Or create the variable in first boot.
//
);
//
// If the Memory Type Information settings have been modified, then reset the platform
// so the new Memory Type Information setting will be used to guarantee that an S4
//
}
}
}
/**
This routine is kept for backward compatibility.
**/
)
{
}
/**
Identify a user and, if authenticated, returns the current user profile handle.
@param[out] User Point to user profile handle.
@retval EFI_SUCCESS User is successfully identified, or user identification
is not supported.
@retval EFI_ACCESS_DENIED User is not successfully identified
**/
)
{
NULL,
);
return EFI_SUCCESS;
}
}