/** @file\r
- Generic BDS library definition, include the data structure and function.\r
+ Generic BDS library defines general interfaces for BDS driver including:\r
+ 1) BDS boot policy interface;\r
+ 2) BDS boot device connect interface;\r
+ 3) BDS Misc interfaces for mainting boot variable, ouput string.\r
\r
-Copyright (c) 2004 - 2008, Intel Corporation. <BR>\r
+Copyright (c) 2004 - 2009, Intel Corporation. <BR>\r
All rights reserved. This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
#ifndef _GENERIC_BDS_LIB_H_\r
#define _GENERIC_BDS_LIB_H_\r
\r
-#include <Protocol/HiiDatabase.h>\r
-#include <IndustryStandard/PeImage.h>\r
-\r
-\r
extern EFI_HANDLE mBdsImageHandle;\r
\r
-//\r
-// Constants which are variable names used to access variables\r
-//\r
+///\r
+/// Constants which are variable names used to access variables\r
+///\r
#define VAR_LEGACY_DEV_ORDER L"LegacyDevOrder"\r
\r
-//\r
-// Data structures and defines\r
-//\r
+///\r
+/// Data structures and defines\r
+///\r
#define FRONT_PAGE_QUESTION_ID 0x0000\r
#define FRONT_PAGE_DATA_WIDTH 0x01\r
\r
-//\r
-// ConnectType\r
-//\r
+///\r
+/// ConnectType\r
+///\r
#define CONSOLE_OUT 0x00000001\r
#define STD_ERROR 0x00000002\r
#define CONSOLE_IN 0x00000004\r
#define CONSOLE_ALL (CONSOLE_OUT | CONSOLE_IN | STD_ERROR)\r
\r
-//\r
-// Load Option Attributes defined in EFI Specification\r
-//\r
+///\r
+/// Load Option Attributes\r
+///\r
#define LOAD_OPTION_ACTIVE 0x00000001\r
#define LOAD_OPTION_FORCE_RECONNECT 0x00000002\r
\r
\r
#define IS_LOAD_OPTION_TYPE(_c, _Mask) (BOOLEAN) (((_c) & (_Mask)) != 0)\r
\r
-//\r
-// Define Maxmim characters that will be accepted\r
-//\r
+///\r
+/// Define Maxmim characters that will be accepted\r
+///\r
#define MAX_CHAR 480\r
#define MAX_CHAR_SIZE (MAX_CHAR * 2)\r
\r
-#define MIN_ALIGNMENT_SIZE 4\r
-#define ALIGN_SIZE(a) ((a % MIN_ALIGNMENT_SIZE) ? MIN_ALIGNMENT_SIZE - (a % MIN_ALIGNMENT_SIZE) : 0)\r
-\r
-//\r
-// Define maximum characters for boot option variable "BootXXXX"\r
-//\r
+///\r
+/// Define maximum characters for boot option variable "BootXXXX"\r
+///\r
#define BOOT_OPTION_MAX_CHAR 10\r
\r
//\r
-// This data structure is the part of BDS_CONNECT_ENTRY that we can hard code.\r
+// This data structure is the part of BDS_CONNECT_ENTRY\r
//\r
#define BDS_LOAD_OPTION_SIGNATURE SIGNATURE_32 ('B', 'd', 'C', 'O')\r
\r
UINTN ConnectType;\r
} BDS_CONSOLE_CONNECT_ENTRY;\r
\r
-//\r
-// Lib Functions\r
-//\r
-\r
//\r
// Bds boot related lib functions\r
//\r
\r
\r
/**\r
- This function will enumerate all possible boot device in the system,\r
- it will only excute once of every boot.\r
-\r
+ For EFI boot option, BDS separate them as six types:\r
+ 1. Network - The boot option points to the SimpleNetworkProtocol device. \r
+ Bds will try to automatically create this type boot option when enumerate.\r
+ 2. Shell - The boot option points to internal flash shell. \r
+ Bds will try to automatically create this type boot option when enumerate.\r
+ 3. Removable BlockIo - The boot option only points to the removable media\r
+ device, like USB flash disk, DVD, Floppy etc.\r
+ These device should contain a *removable* blockIo\r
+ protocol in their device handle.\r
+ Bds will try to automatically create this type boot option \r
+ when enumerate.\r
+ 4. Fixed BlockIo - The boot option only points to a Fixed blockIo device, \r
+ like HardDisk.\r
+ These device should contain a *fixed* blockIo\r
+ protocol in their device handle.\r
+ BDS will skip fixed blockIo devices, and NOT\r
+ automatically create boot option for them. But BDS \r
+ will help to delete those fixed blockIo boot option, \r
+ whose description rule conflict with other auto-created\r
+ boot options.\r
+ 5. Non-BlockIo Simplefile - The boot option points to a device whose handle \r
+ has SimpleFileSystem Protocol, but has no blockio\r
+ protocol. These devices do not offer blockIo\r
+ protocol, but BDS still can get the \r
+ \EFI\BOOT\boot{machinename}.EFI by SimpleFileSystem\r
+ Protocol.\r
+ 6. File - The boot option points to a file. These boot options are usually \r
+ created by user manually or OS loader. BDS will not delete or modify\r
+ these boot options. \r
+ \r
+ This function will enumerate all possible boot device in the system, and\r
+ automatically create boot options for Network, Shell, Removable BlockIo, \r
+ and Non-BlockIo Simplefile devices.\r
+ It will only excute once of every boot.\r
+ \r
@param BdsBootOptionList The header of the link list which indexed all\r
current boot options\r
\r
@retval EFI_SUCCESS Finished all the boot device enumerate and create\r
the boot option base on that boot device\r
\r
+ @retval EFI_OUT_OF_RESOURCES Failed to enumerate the boot device and create the boot option list\r
**/\r
EFI_STATUS\r
EFIAPI\r
Process BootOrder, or DriverOrder variables, by calling\r
BdsLibVariableToOption () for each UINT16 in the variables.\r
\r
- @param BdsCommonOptionList The header of the option list base on variable\r
- VariableName\r
- @param VariableName EFI Variable name indicate the BootOrder or\r
- DriverOrder\r
-\r
- @retval EFI_SUCCESS Success create the boot option or driver option\r
- list\r
- @retval EFI_OUT_OF_RESOURCES Failed to get the boot option or driver option list\r
+ @param BdsCommonOptionList The header of the option list base on variable VariableName.\r
+ @param VariableName EFI Variable name indicate the BootOrder or DriverOrder.\r
\r
+ @retval EFI_SUCCESS Success create the boot option or driver option list.\r
+ @retval EFI_OUT_OF_RESOURCES Failed to get the boot option or driver option list.\r
**/\r
EFI_STATUS\r
EFIAPI\r
);\r
\r
/**\r
- This function will connect all current system handles recursively. The\r
- connection will finish until every handle's child handle created if it have.\r
+ This function will connect all current system handles recursively. \r
+ \r
+ gBS->ConnectController() service is invoked for each handle exist in system handler buffer.\r
+ If the handle is bus type handler, all childrens also will be connected recursively\r
+ by gBS->ConnectController().\r
\r
- @retval EFI_SUCCESS All handles and it's child handle have been\r
- connected\r
- @retval EFI_STATUS Return the status of gBS->LocateHandleBuffer().\r
+ @retval EFI_SUCCESS All handles and it's child handle have been connected\r
+ @retval EFI_STATUS Error status returned by of gBS->LocateHandleBuffer().\r
\r
**/\r
EFI_STATUS\r
VOID\r
);\r
\r
-\r
/**\r
- This function will disconnect all current system handles. The disconnection\r
- will finish until every handle have been disconnected.\r
+ This function will disconnect all current system handles. \r
+ \r
+ gBS->DisconnectController() is invoked for each handle exists in system handle buffer.\r
+ If handle is a bus type handle, all childrens also are disconnected recursively by\r
+ gBS->DisconnectController().\r
\r
@retval EFI_SUCCESS All handles have been disconnected\r
- @retval EFI_STATUS Return the status of gBS->LocateHandleBuffer().\r
+ @retval EFI_STATUS Error status returned by of gBS->LocateHandleBuffer().\r
\r
**/\r
EFI_STATUS\r
// Internal definitions\r
//\r
typedef struct {\r
- CHAR16 *str;\r
- UINTN len;\r
- UINTN maxlen;\r
+ CHAR16 *Str;\r
+ UINTN Len;\r
+ UINTN Maxlen;\r
} POOL_PRINT;\r
\r
typedef struct {\r
UINT16 LoginOption;\r
UINT64 Lun;\r
UINT16 TargetPortalGroupTag;\r
- CHAR16 iSCSITargetName[1];\r
+ CHAR16 TargetName[1];\r
} ISCSI_DEVICE_PATH_WITH_NAME;\r
\r
\r
);\r
\r
/**\r
-\r
Add the legacy boot options from BBS table if they do not exist.\r
\r
- @retval EFI_SUCCESS The boot options are added successfully \r
- or they are already in boot options.\r
-\r
+ @retval EFI_SUCCESS The boot options are added successfully \r
+ or they are already in boot options.\r
+ @retval EFI_NOT_FOUND No legacy boot options is found.\r
+ @retval EFI_OUT_OF_RESOURCE No enough memory.\r
+ @return Other value LegacyBoot options are not added.\r
**/\r
EFI_STATUS\r
EFIAPI\r
);\r
\r
/**\r
-\r
Add the legacy boot devices from BBS table into \r
the legacy device boot order.\r
\r
- @retval EFI_SUCCESS The boot devices are added successfully.\r
-\r
+ @retval EFI_SUCCESS The boot devices are added successfully.\r
+ @retval EFI_NOT_FOUND The legacy boot devices are not found.\r
+ @retval EFI_OUT_OF_RESOURCES Memmory or storage is not enough.\r
+ @retval EFI_DEVICE_ERROR Fail to add the legacy device boot order into EFI variable\r
+ because of hardware error.\r
**/\r
EFI_STATUS\r
EFIAPI\r
);\r
\r
/**\r
-\r
Set the boot priority for BBS entries based on boot option entry and boot order.\r
\r
@param Entry The boot option is to be checked for refresh BBS table.\r
\r
- @retval EFI_SUCCESS The boot priority for BBS entries is refreshed successfully.\r
-\r
+ @retval EFI_SUCCESS The boot priority for BBS entries is refreshed successfully.\r
+ @retval EFI_NOT_FOUND BBS entries can't be found.\r
+ @retval EFI_OUT_OF_RESOURCES Failed to get the legacy device boot order.\r
**/\r
EFI_STATUS\r
EFIAPI\r
);\r
\r
/**\r
+ Deletete the Boot Option from EFI Variable. The Boot Order Arrray\r
+ is also updated.\r
\r
- Delete boot option specified by OptionNumber and adjust the boot order.\r
-\r
- @param OptionNumber The boot option to be deleted.\r
- @param BootOrder Boot order list to be adjusted by remove this boot option.\r
- @param BootOrderSize The size of Boot order list will be modified.\r
- \r
- @retval EFI_SUCCESS The boot option is deleted successfully.\r
+ @param OptionNumber The number of Boot option want to be deleted.\r
+ @param BootOrder The Boot Order array.\r
+ @param BootOrderSize The size of the Boot Order Array.\r
\r
+ @retval EFI_SUCCESS The Boot Option Variable was found and removed\r
+ @retval EFI_UNSUPPORTED The Boot Option Variable store was inaccessible\r
+ @retval EFI_NOT_FOUND The Boot Option Variable was not found\r
**/\r
EFI_STATUS\r
EFIAPI\r
);\r
\r
\r
-/**\r
- Get the headers (dos, image, optional header) from an image\r
-\r
- @param Device SimpleFileSystem device handle\r
- @param FileName File name for the image\r
- @param DosHeader Pointer to dos header\r
- @param Hdr The buffer in which to return the PE32, PE32+, or TE header.\r
-\r
- @retval EFI_SUCCESS Successfully get the machine type.\r
- @retval EFI_NOT_FOUND The file is not found.\r
- @retval EFI_LOAD_ERROR File is not a valid image file.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-BdsLibGetImageHeader (\r
- IN EFI_HANDLE Device,\r
- IN CHAR16 *FileName,\r
- OUT EFI_IMAGE_DOS_HEADER *DosHeader,\r
- OUT EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr\r
- );\r
-\r
-//\r
-// Define the boot type which to classify the boot option type\r
-// Different boot option type could have different boot behavior\r
-// Use their device path node (Type + SubType) as type value\r
-// The boot type here can be added according to requirement\r
-//\r
-//\r
-// ACPI boot type. For ACPI device, cannot use sub-type to distinguish device, so hardcode their value\r
-//\r
+///\r
+/// Define the boot option default description \r
+///\r
+#define DESCRIPTION_FLOPPY L"EFI Floppy"\r
+#define DESCRIPTION_FLOPPY_NUM L"EFI Floppy %d"\r
+#define DESCRIPTION_DVD L"EFI DVD/CDROM"\r
+#define DESCRIPTION_DVD_NUM L"EFI DVD/CDROM %d"\r
+#define DESCRIPTION_USB L"EFI USB Device"\r
+#define DESCRIPTION_USB_NUM L"EFI USB Device %d"\r
+#define DESCRIPTION_SCSI L"EFI SCSI Device"\r
+#define DESCRIPTION_SCSI_NUM L"EFI SCSI Device %d"\r
+#define DESCRIPTION_MISC L"EFI Misc Device"\r
+#define DESCRIPTION_MISC_NUM L"EFI Misc Device %d"\r
+#define DESCRIPTION_NETWORK L"EFI Network"\r
+#define DESCRIPTION_NETWORK_NUM L"EFI Network %d" \r
+#define DESCRIPTION_NON_BLOCK L"EFI Non-Block Boot Device"\r
+#define DESCRIPTION_NON_BLOCK_NUM L"EFI Non-Block Boot Device %d"\r
+\r
+///\r
+/// Define the boot type which to classify the boot option type\r
+/// Different boot option type could have different boot behavior\r
+/// Use their device path node (Type + SubType) as type value\r
+/// The boot type here can be added according to requirement\r
+///\r
+\r
+///\r
+/// ACPI boot type. For ACPI device, cannot use sub-type to distinguish device, so hardcode their value\r
+///\r
#define BDS_EFI_ACPI_FLOPPY_BOOT 0x0201\r
-//\r
-// Message boot type\r
-// If a device path of boot option only point to a message node, the boot option is message boot type\r
-//\r
+///\r
+/// Message boot type\r
+/// If a device path of boot option only point to a message node, the boot option is message boot type\r
+///\r
#define BDS_EFI_MESSAGE_ATAPI_BOOT 0x0301 // Type 03; Sub-Type 01\r
#define BDS_EFI_MESSAGE_SCSI_BOOT 0x0302 // Type 03; Sub-Type 02\r
#define BDS_EFI_MESSAGE_USB_DEVICE_BOOT 0x0305 // Type 03; Sub-Type 05\r
+#define BDS_EFI_MESSAGE_SATA_BOOT 0x0318 // Type 03; Sub-Type 18\r
#define BDS_EFI_MESSAGE_MISC_BOOT 0x03FF\r
-//\r
-// Media boot type\r
-// If a device path of boot option contain a media node, the boot option is media boot type\r
-//\r
+///\r
+/// Media boot type\r
+/// If a device path of boot option contain a media node, the boot option is media boot type\r
+///\r
#define BDS_EFI_MEDIA_HD_BOOT 0x0401 // Type 04; Sub-Type 01\r
#define BDS_EFI_MEDIA_CDROM_BOOT 0x0402 // Type 04; Sub-Type 02\r
-//\r
-// BBS boot type\r
-// If a device path of boot option contain a BBS node, the boot option is BBS boot type\r
-//\r
+///\r
+/// BBS boot type\r
+/// If a device path of boot option contain a BBS node, the boot option is BBS boot type\r
+///\r
#define BDS_LEGACY_BBS_BOOT 0x0501 // Type 05; Sub-Type 01\r
\r
#define BDS_EFI_UNSUPPORT 0xFFFF\r
\r
-//\r
-// USB host controller Programming Interface.\r
-//\r
+///\r
+/// USB host controller Programming Interface.\r
+///\r
#define PCI_CLASSC_PI_UHCI 0x00\r
#define PCI_CLASSC_PI_EHCI 0x20\r
\r
\r
@param DevicePath Device Path to a bootable device\r
\r
- @retval NULL The media on the DevicePath is not bootable\r
+ @return The bootable media handle. If the media on the DevicePath is not bootable, NULL will return.\r
\r
**/\r
EFI_HANDLE\r
IN EFI_DEVICE_PATH_PROTOCOL *DevPath,\r
IN BOOLEAN CheckMedia\r
);\r
- \r
+\r
+/**\r
+ Check whether the Device path in a boot option point to a valid bootable device,\r
+ And if CheckMedia is true, check the device is ready to boot now.\r
+ If Description is not NULL and the device path point to a fixed BlockIo\r
+ device, check the description whether conflict with other auto-created\r
+ boot options.\r
+\r
+ @param DevPath the Device path in a boot option\r
+ @param CheckMedia if true, check the device is ready to boot now.\r
+ @param Description the description in a boot option\r
+\r
+ @retval TRUE the Device path is valid\r
+ @retval FALSE the Device path is invalid .\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+BdsLibIsValidEFIBootOptDevicePathExt (\r
+ IN EFI_DEVICE_PATH_PROTOCOL *DevPath,\r
+ IN BOOLEAN CheckMedia,\r
+ IN CHAR16 *Description\r
+ );\r
+\r
/**\r
For a bootable Device path, return its boot type.\r
\r
@param DevicePath The bootable device Path to check\r
\r
- @retval BDS_EFI_MEDIA_HD_BOOT If the device path contains any media deviec path node, it is media boot type\r
- For the floppy node, handle it as media node\r
- @retval BDS_EFI_MEDIA_CDROM_BOOT If the device path contains any media deviec path node, it is media boot type\r
- For the floppy node, handle it as media node\r
- @retval BDS_EFI_ACPI_FLOPPY_BOOT If the device path contains any media deviec path node, it is media boot type\r
- For the floppy node, handle it as media node\r
- @retval BDS_EFI_MESSAGE_ATAPI_BOOT If the device path not contains any media deviec path node, and\r
- its last device path node point to a message device path node, it is\r
- \r
- @retval BDS_EFI_MESSAGE_SCSI_BOOT If the device path not contains any media deviec path node, and\r
- its last device path node point to a message device path node, it is\r
- @retval BDS_EFI_MESSAGE_USB_DEVICE_BOOT If the device path not contains any media deviec path node, and\r
- its last device path node point to a message device path node, it is\r
- @retval BDS_EFI_MESSAGE_MISC_BOOT If the device path not contains any media deviec path node, and\r
- its last device path node point to a message device path node, it is\r
- @retval BDS_LEGACY_BBS_BOOT Legacy boot type\r
- @retval BDS_EFI_UNSUPPORT An EFI Removable BlockIO device path not point to a media and message devie, \r
+ @retval BDS_EFI_MEDIA_HD_BOOT If given device path contains MEDIA_DEVICE_PATH type device path node \r
+ which subtype is MEDIA_HARDDRIVE_DP\r
+ @retval BDS_EFI_MEDIA_CDROM_BOOT If given device path contains MEDIA_DEVICE_PATH type device path node\r
+ which subtype is MEDIA_CDROM_DP\r
+ @retval BDS_EFI_ACPI_FLOPPY_BOOT If given device path contains ACPI_DEVICE_PATH type device path node\r
+ which HID is floppy device.\r
+ @retval BDS_EFI_MESSAGE_ATAPI_BOOT If given device path contains MESSAGING_DEVICE_PATH type device path node\r
+ and its last device path node's subtype is MSG_ATAPI_DP.\r
+ @retval BDS_EFI_MESSAGE_SCSI_BOOT If given device path contains MESSAGING_DEVICE_PATH type device path node\r
+ and its last device path node's subtype is MSG_SCSI_DP.\r
+ @retval BDS_EFI_MESSAGE_USB_DEVICE_BOOT If given device path contains MESSAGING_DEVICE_PATH type device path node\r
+ and its last device path node's subtype is MSG_USB_DP.\r
+ @retval BDS_EFI_MESSAGE_MISC_BOOT If the device path not contains any media device path node, and\r
+ its last device path node point to a message device path node.\r
+ @retval BDS_LEGACY_BBS_BOOT If given device path contains BBS_DEVICE_PATH type device path node.\r
+ @retval BDS_EFI_UNSUPPORT An EFI Removable BlockIO device path not point to a media and message device, \r
\r
**/\r
UINT32\r
The caller must free the resulting buffer.\r
\r
@param Str Tracks the allocated pool, size in use, and amount of pool allocated.\r
- @param fmt The format string\r
+ @param Fmt The format string\r
@param ... The data will be printed.\r
\r
@return Allocated buffer with the formatted string printed in it.\r
EFIAPI\r
CatPrint (\r
IN OUT POOL_PRINT *Str,\r
- IN CHAR16 *fmt,\r
+ IN CHAR16 *Fmt,\r
...\r
);\r
\r