503 lines
18 KiB
C
503 lines
18 KiB
C
//
|
|
// This file contains 'Framework Code' and is licensed as such
|
|
// under the terms of your license agreement with Intel or your
|
|
// vendor. This file may not be modified, except as allowed by
|
|
// additional terms of your license agreement.
|
|
//
|
|
/** @file
|
|
BDS library definition, include the file and data structure
|
|
|
|
Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
|
|
This software and associated documentation (if any) is furnished
|
|
under a license and may only be used or copied in accordance
|
|
with the terms of the license. Except as permitted by such
|
|
license, no part of this software or documentation may be
|
|
reproduced, stored in a retrieval system, or transmitted in any
|
|
form or by any means without the express written consent of
|
|
Intel Corporation.
|
|
**/
|
|
|
|
#ifndef _INTERNAL_BDS_LIB_H_
|
|
#define _INTERNAL_BDS_LIB_H_
|
|
|
|
#include <PiDxe.h>
|
|
|
|
#include <IndustryStandard/Pci.h>
|
|
#include <IndustryStandard/PeImage.h>
|
|
#include <IndustryStandard/Atapi.h>
|
|
#include <IndustryStandard/Scsi.h>
|
|
|
|
#include <Protocol/PciRootBridgeIo.h>
|
|
#include <Protocol/BlockIo.h>
|
|
#include <Protocol/LoadedImage.h>
|
|
#include <Protocol/SimpleFileSystem.h>
|
|
#include <Protocol/LoadFile.h>
|
|
#include <Protocol/DevicePath.h>
|
|
#include <Protocol/SimpleTextIn.h>
|
|
#include <Protocol/SimpleTextInEx.h>
|
|
#include <Protocol/SimpleTextOut.h>
|
|
#include <Protocol/SimpleNetwork.h>
|
|
#include <Protocol/FirmwareVolume2.h>
|
|
#include <Protocol/PciIo.h>
|
|
#include <Protocol/GraphicsOutput.h>
|
|
#include <Protocol/UsbIo.h>
|
|
#include <Protocol/DiskInfo.h>
|
|
#include <Protocol/IdeControllerInit.h>
|
|
#include <Protocol/BootLogo.h>
|
|
#include <Protocol/DriverHealth.h>
|
|
#include <Protocol/FormBrowser2.h>
|
|
|
|
#include <Guid/MemoryTypeInformation.h>
|
|
#include <Guid/FileInfo.h>
|
|
#include <Guid/GlobalVariable.h>
|
|
#include <Guid/Performance.h>
|
|
#include <Guid/StatusCodeDataTypeVariable.h>
|
|
|
|
#include <Library/PrintLib.h>
|
|
#include <Library/DebugLib.h>
|
|
#include <Library/BaseMemoryLib.h>
|
|
#include <Library/UefiBootServicesTableLib.h>
|
|
#include <Library/UefiRuntimeServicesTableLib.h>
|
|
#include <Library/UefiLib.h>
|
|
#include <Library/MemoryAllocationLib.h>
|
|
#include <Library/DxeServicesTableLib.h>
|
|
#include <Library/HobLib.h>
|
|
#include <Library/BaseLib.h>
|
|
#include <Library/DevicePathLib.h>
|
|
#include <Library/PerformanceLib.h>
|
|
#include <Library/PcdLib.h>
|
|
#include <Library/PeCoffGetEntryPointLib.h>
|
|
#include <UefiBootManagerLib.h>
|
|
#include <Library/TimerLib.h>
|
|
#include <Library/DxeServicesLib.h>
|
|
#include <Library/ReportStatusCodeLib.h>
|
|
#include <Library/CapsuleLib.h>
|
|
#include <Library/PerformanceLib.h>
|
|
#include <Library/HiiLib.h>
|
|
#include <Library/GenericBdsLib.h>
|
|
|
|
#if !defined (EFI_REMOVABLE_MEDIA_FILE_NAME)
|
|
#if defined (MDE_CPU_EBC)
|
|
//
|
|
// Uefi specification only defines the default boot file name for IA32, X64
|
|
// and IPF processor, so need define boot file name for EBC architecture here.
|
|
//
|
|
#define EFI_REMOVABLE_MEDIA_FILE_NAME L"\\EFI\\BOOT\\BOOTEBC.EFI"
|
|
#else
|
|
#error "Can not determine the default boot file name for unknown processor type!"
|
|
#endif
|
|
#endif
|
|
|
|
typedef enum {
|
|
AcpiFloppyBoot,
|
|
HardwareDeviceBoot,
|
|
MessageAtapiBoot,
|
|
MessageSataBoot,
|
|
MessageUsbBoot,
|
|
MessageScsiBoot,
|
|
MessageNetworkBoot,
|
|
MiscBoot,
|
|
MessageNvmeBoot // ROYAL_PARK_OVERRIDE: RoyalParkOverrideContent - RPCO-0005
|
|
} BOOT_TYPE;
|
|
|
|
typedef
|
|
CHAR16 *
|
|
(* GET_BOOT_DESCRIPTION) (
|
|
IN EFI_HANDLE Handle
|
|
);
|
|
|
|
/**
|
|
Get the revision of the EFI_KEY_OPTION structure.
|
|
|
|
@param KeyOption Pointer to the EFI_KEY_OPTION structure.
|
|
|
|
@return Revision.
|
|
**/
|
|
#define KEY_OPTION_REVISION(KeyOption) ((KeyOption)->KeyData & EFI_KEY_OPTION_REVISION_MASK)
|
|
|
|
/**
|
|
Get the actual number of entries in EFI_KEY_OPTION.Keys, from 0-3.
|
|
|
|
@param KeyOption Pointer to the EFI_KEY_OPTION structure.
|
|
|
|
@return Actual number of entries in EFI_KEY_OPTION.Keys.
|
|
**/
|
|
#define KEY_OPTION_INPUT_KEY_COUNT(KeyOption) (((KeyOption)->KeyData & EFI_KEY_OPTION_INPUT_KEY_COUNT_MASK) >> LowBitSet32 (EFI_KEY_OPTION_INPUT_KEY_COUNT_MASK))
|
|
|
|
/**
|
|
Return whether the Shift key needs pressed.
|
|
|
|
@param KeyOption Pointer to the EFI_KEY_OPTION structure.
|
|
|
|
@retval TRUE Shift key needs pressed.
|
|
@retval FALSE Shift key needn't pressed.
|
|
**/
|
|
#define KEY_OPTION_SHIFT_PRESSED(KeyOption) (BOOLEAN) (((KeyOption)->KeyData & EFI_KEY_OPTION_SHIFT_PRESSED_MASK) != 0)
|
|
|
|
/**
|
|
Return whether the Control key needs pressed.
|
|
|
|
@param KeyOption Pointer to the EFI_KEY_OPTION structure.
|
|
|
|
@retval TRUE Control key needs pressed.
|
|
@retval FALSE Control key needn't pressed.
|
|
**/
|
|
#define KEY_OPTION_CONTROL_PRESSED(KeyOption) (BOOLEAN) (((KeyOption)->KeyData & EFI_KEY_OPTION_CONTROL_PRESSED_MASK) != 0)
|
|
|
|
/**
|
|
Return whether the Alt key needs pressed.
|
|
|
|
@param KeyOption Pointer to the EFI_KEY_OPTION structure.
|
|
|
|
@retval TRUE Alt key needs pressed.
|
|
@retval FALSE Alt key needn't pressed.
|
|
**/
|
|
#define KEY_OPTION_ALT_PRESSED(KeyOption) (BOOLEAN) (((KeyOption)->KeyData & EFI_KEY_OPTION_ALT_PRESSED_MASK) != 0)
|
|
|
|
/**
|
|
Return whether the Logo key needs pressed.
|
|
|
|
@param KeyOption Pointer to the EFI_KEY_OPTION structure.
|
|
|
|
@retval TRUE Logo key needs pressed.
|
|
@retval FALSE Logo key needn't pressed.
|
|
**/
|
|
#define KEY_OPTION_LOGO_PRESSED(KeyOption) (BOOLEAN) (((KeyOption)->KeyData & EFI_KEY_OPTION_LOGO_PRESSED_MASK) != 0)
|
|
|
|
/**
|
|
Return whether the Menu key needs pressed.
|
|
|
|
@param KeyOption Pointer to the EFI_KEY_OPTION structure.
|
|
|
|
@retval TRUE Menu key needs pressed.
|
|
@retval FALSE Menu key needn't pressed.
|
|
**/
|
|
#define KEY_OPTION_MENU_PRESSED(KeyOption) (BOOLEAN) (((KeyOption)->KeyData & EFI_KEY_OPTION_MENU_PRESSED_MASK) != 0)
|
|
|
|
/**
|
|
Return whether the SysReq key needs pressed.
|
|
|
|
@param KeyOption Pointer to the EFI_KEY_OPTION structure.
|
|
|
|
@retval TRUE SysReq key needs pressed.
|
|
@retval FALSE SysReq key needn't pressed.
|
|
**/
|
|
#define KEY_OPTION_SYS_REQ_PRESSED(KeyOption) (BOOLEAN) (((KeyOption)->KeyData & EFI_KEY_OPTION_SYS_REQ_PRESSED_MASK) != 0)
|
|
|
|
#define HOTKEY_SIGNATURE SIGNATURE_32 ('b', 'm', 'h', 'k')
|
|
typedef struct {
|
|
UINT32 Signature;
|
|
LIST_ENTRY Link;
|
|
|
|
BOOLEAN IsContinue;
|
|
UINT16 BootOption;
|
|
UINT8 CodeCount;
|
|
UINT8 WaitingKey;
|
|
EFI_KEY_DATA KeyData[3];
|
|
} HOTKEY;
|
|
|
|
#define HOTKEY_FROM_LINK(a) CR (a, HOTKEY, Link, HOTKEY_SIGNATURE)
|
|
|
|
/**
|
|
Get the Option Number that wasn't used.
|
|
|
|
@param OrderVariableName Could be L"BootOrder" or L"DriverOrder".
|
|
@param FreeOptionNumber To receive the minimal free option number.
|
|
|
|
@retval EFI_SUCCESS The option number is found
|
|
@retval EFI_OUT_OF_RESOURCES There is no free option number that can be used.
|
|
@retval EFI_INVALID_PARAMETER FreeOptionNumber is NULL
|
|
|
|
**/
|
|
EFI_STATUS
|
|
GetFreeOptionNumber (
|
|
IN CHAR16 *OrderVariableName,
|
|
OUT UINT16 *FreeOptionNumber
|
|
);
|
|
|
|
/**
|
|
Update order variable .
|
|
|
|
@param OrderVariableName Order variable name which need to be updated.
|
|
@param OptionNumber Option number for the new option.
|
|
@param Position Position of the new load option to put in the ****Order variable.
|
|
|
|
@retval EFI_SUCCESS The boot#### or driver#### have been successfully registered.
|
|
@retval EFI_ALREADY_STARTED The option number of Option is being used already.
|
|
@retval EFI_STATUS Return the status of gRT->SetVariable ().
|
|
|
|
**/
|
|
EFI_STATUS
|
|
AddOptionNumberToOrderVariable (
|
|
IN CHAR16 *OrderVariableName,
|
|
IN UINT16 OptionNumber,
|
|
IN UINTN Position
|
|
);
|
|
|
|
/**
|
|
Update the BootOrder or DriverOrder to delete OptionNumber .
|
|
|
|
@param OptionOrderVariable Order variable name which need to be updated.
|
|
@param OptionNumber Indicate the option number of load option
|
|
|
|
@retval EFI_NOT_FOUND The load option cannot be found
|
|
@retval EFI_SUCCESS The load option was deleted
|
|
**/
|
|
EFI_STATUS
|
|
DeleteOptionVariable (
|
|
IN CHAR16 *OptionOrderVariable,
|
|
IN UINT16 OptionNumber
|
|
);
|
|
|
|
/**
|
|
|
|
Writes performance data of booting into the allocated memory.
|
|
OS can process these records.
|
|
|
|
@param Event The triggered event.
|
|
@param Context Context for this event.
|
|
|
|
**/
|
|
//VOID
|
|
//EFIAPI
|
|
//WriteBootToOsPerformanceData (
|
|
// IN EFI_EVENT Event,
|
|
// IN VOID *Context
|
|
// );
|
|
|
|
|
|
/**
|
|
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
|
|
GetImageHeader (
|
|
IN EFI_HANDLE Device,
|
|
IN CHAR16 *FileName,
|
|
OUT EFI_IMAGE_DOS_HEADER *DosHeader,
|
|
OUT EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr
|
|
);
|
|
|
|
/**
|
|
For a bootable Device path, return its boot type.
|
|
|
|
@param DevicePath The bootable device Path to check
|
|
|
|
@retval AcpiFloppyBoot If given device path contains ACPI_DEVICE_PATH type device path node
|
|
which HID is floppy device.
|
|
@retval MessageAtapiBoot If given device path contains MESSAGING_DEVICE_PATH type device path node
|
|
and its last device path node's subtype is MSG_ATAPI_DP.
|
|
@retval MessageSataBoot If given device path contains MESSAGING_DEVICE_PATH type device path node
|
|
and its last device path node's subtype is MSG_SATA_DP.
|
|
@retval MessageScsiBoot If given device path contains MESSAGING_DEVICE_PATH type device path node
|
|
and its last device path node's subtype is MSG_SCSI_DP.
|
|
@retval MessageUsbBoot If given device path contains MESSAGING_DEVICE_PATH type device path node
|
|
and its last device path node's subtype is MSG_USB_DP.
|
|
@retval MessageNetworkBoot If given device path contains MESSAGING_DEVICE_PATH type device path node
|
|
and its last device path node's subtype is MSG_MAC_ADDR_DP, MSG_VLAN_DP,
|
|
MSG_IPv4_DP or MSG_IPv6_DP.
|
|
@retval MiscBoot Other boot type,
|
|
|
|
**/
|
|
BOOT_TYPE
|
|
BootTypeFromDevicePath (
|
|
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
|
);
|
|
|
|
/**
|
|
This routine adjust the memory information for different memory type and
|
|
save them into the variables for next boot.
|
|
**/
|
|
VOID
|
|
SetMemoryTypeInformationVariable (
|
|
VOID
|
|
);
|
|
|
|
/**
|
|
Check whether there is a instance in BlockIoDevicePath, which contain multi device path
|
|
instances, has the same partition node with HardDriveDevicePath device path
|
|
|
|
@param BlockIoDevicePath Multi device path instances which need to check
|
|
@param HardDriveDevicePath A device path which starts with a hard drive media
|
|
device path.
|
|
|
|
@retval TRUE There is a matched device path instance.
|
|
@retval FALSE There is no matched device path instance.
|
|
|
|
**/
|
|
BOOLEAN
|
|
MatchPartitionDevicePathNode (
|
|
IN EFI_DEVICE_PATH_PROTOCOL *BlockIoDevicePath,
|
|
IN HARDDRIVE_DEVICE_PATH *HardDriveDevicePath
|
|
);
|
|
|
|
/**
|
|
This function will register the new boot#### or driver#### options.
|
|
After the boot#### or driver#### updated, the BootOrder or DriverOrder will also be updated.
|
|
|
|
@param Options Pointer to array of load options to add.
|
|
@param OptionCount Number of load options.
|
|
@param Position Position of the new load option to put in the ****Order variable.
|
|
|
|
@retval EFI_SUCCESS The boot#### or driver#### have been success
|
|
registered
|
|
@retval EFI_STATUS Return the status of gRT->SetVariable ().
|
|
|
|
**/
|
|
EFI_STATUS
|
|
AddLoadOptions (
|
|
IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Options,
|
|
IN UINTN OptionCount,
|
|
IN UINTN Position
|
|
);
|
|
|
|
/**
|
|
This function will connect all current system handles recursively.
|
|
gBS->ConnectController() service is invoked for each handle exist in system handler buffer.
|
|
If the handle is bus type handler, all childrens will be connected recursively by gBS->ConnectController().
|
|
**/
|
|
VOID
|
|
ConnectAllEfi (
|
|
VOID
|
|
);
|
|
|
|
|
|
/**
|
|
Connect all the drivers to all the controllers.
|
|
|
|
This function makes sure all the current system drivers manage the correspoinding
|
|
controllers if have. And at the same time, makes sure all the system controllers
|
|
have driver to manage it if have.
|
|
**/
|
|
//VOID
|
|
//ConnectAllDriversToAllControllers (
|
|
// VOID
|
|
// );
|
|
|
|
/**
|
|
Return the array of key options.
|
|
|
|
@param Count Return the number of key options.
|
|
|
|
@retval NULL No key option.
|
|
@retval Other Pointer to the key options.
|
|
**/
|
|
EFI_BOOT_MANAGER_KEY_OPTION *
|
|
EFIAPI
|
|
EfiBootManagerGetKeyOptions (
|
|
OUT UINTN *Count
|
|
);
|
|
|
|
/**
|
|
Free the key options returned from EfiBootManagerGetKeyOptions.
|
|
|
|
@param KeyOptions Pointer to the key options.
|
|
@param KeyOptionCount Number of the key options.
|
|
|
|
@retval EFI_SUCCESS The key options are freed.
|
|
@retval EFI_NOT_FOUND KeyOptions is NULL.
|
|
**/
|
|
EFI_STATUS
|
|
EFIAPI
|
|
EfiBootManagerFreeKeyOptions (
|
|
IN EFI_BOOT_MANAGER_KEY_OPTION *KeyOptions,
|
|
IN UINTN KeyOptionCount
|
|
);
|
|
|
|
/**
|
|
Connect the specific Usb device which match the short form device path.
|
|
|
|
@param DevicePath A short-form device path that starts with the first
|
|
element being a USB WWID or a USB Class device
|
|
path
|
|
|
|
@return EFI_INVALID_PARAMETER DevicePath is NULL pointer.
|
|
DevicePath is not a USB device path.
|
|
|
|
@return EFI_SUCCESS Success to connect USB device
|
|
@return EFI_NOT_FOUND Fail to find handle for USB controller to connect.
|
|
|
|
**/
|
|
EFI_STATUS
|
|
EFIAPI
|
|
EfiBootManagerConnectUsbShortFormDevicePath (
|
|
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
|
);
|
|
|
|
/**
|
|
Stop the hotkey processing.
|
|
|
|
@param Event Event pointer related to hotkey service.
|
|
@param Context Context pass to this function.
|
|
**/
|
|
VOID
|
|
EFIAPI
|
|
StopHotkeyService (
|
|
IN EFI_EVENT Event,
|
|
IN VOID *Context
|
|
);
|
|
|
|
/**
|
|
Set the variable and report the error through status code upon failure.
|
|
|
|
@param VariableName A Null-terminated string that is the name of the vendor's variable.
|
|
Each VariableName is unique for each VendorGuid. VariableName must
|
|
contain 1 or more characters. If VariableName is an empty string,
|
|
then EFI_INVALID_PARAMETER is returned.
|
|
@param VendorGuid A unique identifier for the vendor.
|
|
@param Attributes Attributes bitmask to set for the variable.
|
|
@param DataSize The size in bytes of the Data buffer. Unless the EFI_VARIABLE_APPEND_WRITE,
|
|
EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS, or
|
|
EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS attribute is set, a size of zero
|
|
causes the variable to be deleted. When the EFI_VARIABLE_APPEND_WRITE attribute is
|
|
set, then a SetVariable() call with a DataSize of zero will not cause any change to
|
|
the variable value (the timestamp associated with the variable may be updated however
|
|
even if no new data value is provided,see the description of the
|
|
EFI_VARIABLE_AUTHENTICATION_2 descriptor below. In this case the DataSize will not
|
|
be zero since the EFI_VARIABLE_AUTHENTICATION_2 descriptor will be populated).
|
|
@param Data The contents for the variable.
|
|
|
|
@retval EFI_SUCCESS The firmware has successfully stored the variable and its data as
|
|
defined by the Attributes.
|
|
@retval EFI_INVALID_PARAMETER An invalid combination of attribute bits, name, and GUID was supplied, or the
|
|
DataSize exceeds the maximum allowed.
|
|
@retval EFI_INVALID_PARAMETER VariableName is an empty string.
|
|
@retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
|
|
@retval EFI_DEVICE_ERROR The variable could not be retrieved due to a hardware error.
|
|
@retval EFI_WRITE_PROTECTED The variable in question is read-only.
|
|
@retval EFI_WRITE_PROTECTED The variable in question cannot be deleted.
|
|
@retval EFI_SECURITY_VIOLATION The variable could not be written due to EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
|
|
or EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACESS being set, but the AuthInfo
|
|
does NOT pass the validation check carried out by the firmware.
|
|
|
|
@retval EFI_NOT_FOUND The variable trying to be updated or deleted was not found.
|
|
**/
|
|
EFI_STATUS
|
|
SetVariableAndReportStatusCodeOnError (
|
|
IN CHAR16 *VariableName,
|
|
IN EFI_GUID *VendorGuid,
|
|
IN UINT32 Attributes,
|
|
IN UINTN DataSize,
|
|
IN VOID *Data
|
|
);
|
|
|
|
//extern EFI_BOOT_MANAGER_REFRESH_LEGACY_BOOT_OPTION mEfiBootManagerRefreshLegacyBootOption;
|
|
//extern EFI_BOOT_MANAGER_LEGACY_BOOT mEfiBootManagerLegacyBoot;
|
|
|
|
|
|
EFI_STATUS
|
|
BdsLibDoLegacyBoot (
|
|
IN BDS_COMMON_OPTION *Option
|
|
);
|
|
|
|
#endif // _BDS_LIB_H_
|