\r
BOOLEAN mEnumBootDevice = FALSE;\r
\r
-//\r
-// This GUID is used for an EFI Variable that stores the front device pathes\r
-// for a partial device path that starts with the HD node.\r
-//\r
+///\r
+/// This GUID is used for an EFI Variable that stores the front device pathes\r
+/// for a partial device path that starts with the HD node.\r
+///\r
EFI_GUID mHdBootVariablePrivateGuid = { 0xfab7e9e1, 0x39dd, 0x4f2b, { 0x84, 0x8, 0xe2, 0xe, 0x90, 0x6c, 0xb6, 0xde } };\r
\r
\r
//\r
InitializeListHead (&TempBootLists);\r
BdsLibRegisterNewOption (&TempBootLists, DevicePath, L"EFI Internal Shell", L"BootOrder");\r
+ \r
//\r
// free the temporary device path created by BdsLibUpdateFvFileDevicePath()\r
//\r
- gBS->FreePool (DevicePath); \r
+ SafeFreePool (DevicePath); \r
DevicePath = Option->DevicePath;\r
}\r
\r
// Load the default boot file \EFI\BOOT\boot{machinename}.EFI from removable Media\r
// machinename is ia32, ia64, x64, ...\r
//\r
- FilePath = FileDevicePath (Handle, DEFAULT_REMOVABLE_FILE_NAME);\r
+ FilePath = FileDevicePath (Handle, (CONST CHAR16*)PcdGetPtr(PcdDefaultBootFileName));\r
if (FilePath != NULL) {\r
Status = gBS->LoadImage (\r
TRUE,\r
&mHdBootVariablePrivateGuid,\r
&CachedDevicePathSize\r
);\r
+ \r
if (CachedDevicePath != NULL) {\r
TempNewDevicePath = CachedDevicePath;\r
DeviceExist = FALSE;\r
// Find the matched device path.\r
// Append the file path infomration from the boot option and return the fully expanded device path.\r
//\r
- DevicePath = NextDevicePathNode ((EFI_DEVICE_PATH_PROTOCOL *) HardDriveDevicePath);\r
+ DevicePath = NextDevicePathNode ((EFI_DEVICE_PATH_PROTOCOL *) HardDriveDevicePath);\r
FullDevicePath = AppendDevicePath (Instance, DevicePath);\r
\r
//\r
// First delete the matched instance.\r
//\r
TempNewDevicePath = CachedDevicePath;\r
- CachedDevicePath = BdsLibDelPartMatchInstance ( CachedDevicePath, Instance );\r
+ CachedDevicePath = BdsLibDelPartMatchInstance (CachedDevicePath, Instance );\r
SafeFreePool (TempNewDevicePath);\r
+ \r
//\r
// Second, append the remaining parth after the matched instance\r
//\r
TempNewDevicePath = CachedDevicePath;\r
- CachedDevicePath = AppendDevicePathInstance ( Instance, CachedDevicePath );\r
+ CachedDevicePath = AppendDevicePathInstance (Instance, CachedDevicePath );\r
SafeFreePool (TempNewDevicePath);\r
//\r
// Save the matching Device Path so we don't need to do a connect all next time\r
CachedDevicePath\r
);\r
}\r
- SafeFreePool(Instance);\r
- gBS->FreePool (CachedDevicePath);\r
+ \r
+ SafeFreePool (Instance);\r
+ SafeFreePool (CachedDevicePath);\r
return FullDevicePath;\r
}\r
}\r
break;\r
}\r
}\r
- gBS->FreePool (CachedDevicePath);\r
- gBS->FreePool (BlockIoBuffer);\r
+ \r
+ SafeFreePool (CachedDevicePath);\r
+ SafeFreePool (BlockIoBuffer);\r
return FullDevicePath;\r
}\r
\r
-\r
/**\r
Check whether there is a instance in BlockIoDevicePath, which contain multi device path\r
instances, has the same partition node with HardDriveDevicePath device path\r
device path.\r
\r
@retval TRUE There is a matched device path instance FALSE\r
- -There is no matched device path instance\r
+ @retval FALSE There is no matched device path instance\r
\r
**/\r
BOOLEAN\r
if ((BlockIoDevicePath == NULL) || (HardDriveDevicePath == NULL)) {\r
return FALSE;\r
}\r
+ \r
//\r
// Make PreviousDevicePath == the device path node before the end node\r
//\r
- DevicePath = BlockIoDevicePath;\r
+ DevicePath = BlockIoDevicePath;\r
BlockIoHdDevicePathNode = NULL;\r
\r
//\r
TmpHdPath = (HARDDRIVE_DEVICE_PATH *) BlockIoHdDevicePathNode;\r
TempPath = (HARDDRIVE_DEVICE_PATH *) BdsLibUnpackDevicePath ((EFI_DEVICE_PATH_PROTOCOL *) HardDriveDevicePath);\r
Match = FALSE;\r
+ \r
//\r
// Check for the match\r
//\r
return Match;\r
}\r
\r
-\r
/**\r
Delete the boot option associated with the handle passed in.\r
\r
BootOrder = NULL;\r
BootOrderSize = 0;\r
\r
+ //\r
+ // Check "BootOrder" variable, if no, means there is no any boot order.\r
+ //\r
BootOrder = BdsLibGetVariableAndSize (\r
L"BootOrder",\r
&gEfiGlobalVariableGuid,\r
&BootOrderSize\r
);\r
- if (NULL == BootOrder) {\r
+ if (BootOrder == NULL) {\r
return EFI_NOT_FOUND;\r
}\r
\r
+ //\r
+ // Convert device handle to device path protocol instance\r
+ //\r
DevicePath = DevicePathFromHandle (Handle);\r
if (DevicePath == NULL) {\r
return EFI_NOT_FOUND;\r
}\r
DevicePathSize = GetDevicePathSize (DevicePath);\r
\r
+ //\r
+ // Loop all boot order variable and find the matching device path\r
+ //\r
Index = 0;\r
while (Index < BootOrderSize / sizeof (UINT16)) {\r
UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder[Index]);\r
&gEfiGlobalVariableGuid,\r
&BootOptionSize\r
);\r
- if (NULL == BootOptionVar) {\r
- gBS->FreePool (BootOrder);\r
+ \r
+ if (BootOptionVar == NULL) {\r
+ SafeFreePool (BootOrder);\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
if ((OptionDevicePathSize == DevicePathSize) &&\r
(CompareMem (DevicePath, OptionDevicePath, DevicePathSize) == 0)) {\r
BdsDeleteBootOption (BootOrder[Index], BootOrder, &BootOrderSize);\r
- gBS->FreePool (BootOptionVar);\r
+ SafeFreePool (BootOptionVar);\r
break;\r
}\r
\r
- gBS->FreePool (BootOptionVar);\r
+ SafeFreePool (BootOptionVar);\r
Index++;\r
}\r
\r
+ //\r
+ // Adjust number of boot option for "BootOrder" variable.\r
+ //\r
Status = gRT->SetVariable (\r
L"BootOrder",\r
&gEfiGlobalVariableGuid,\r
BootOrder\r
);\r
\r
- gBS->FreePool (BootOrder);\r
+ SafeFreePool (BootOrder);\r
\r
return Status;\r
}\r
Delete all invalid EFI boot options. The probable invalid boot option could\r
be Removable media or Network boot device.\r
\r
- VOID\r
-\r
@retval EFI_SUCCESS Delete all invalid boot option success\r
@retval EFI_NOT_FOUND Variable "BootOrder" is not found\r
@retval EFI_OUT_OF_RESOURCES Lack of memory resource\r
BootOrder = NULL;\r
BootOrderSize = 0;\r
\r
+ //\r
+ // Check "BootOrder" variable firstly, this variable hold the number of boot options\r
+ //\r
BootOrder = BdsLibGetVariableAndSize (\r
L"BootOrder",\r
&gEfiGlobalVariableGuid,\r
&BootOptionSize\r
);\r
if (NULL == BootOptionVar) {\r
- gBS->FreePool (BootOrder);\r
+ SafeFreePool (BootOrder);\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
//\r
if ((DevicePathType (OptionDevicePath) == BBS_DEVICE_PATH) &&\r
(DevicePathSubType (OptionDevicePath) == BBS_BBS_DP)) {\r
- gBS->FreePool (BootOptionVar);\r
+ SafeFreePool (BootOptionVar);\r
Index++;\r
continue;\r
}\r
BootOrder[Index] = 0xffff;\r
}\r
\r
- gBS->FreePool (BootOptionVar);\r
+ SafeFreePool (BootOptionVar);\r
Index++;\r
}\r
\r
BootOrder\r
);\r
\r
- gBS->FreePool (BootOrder);\r
+ SafeFreePool (BootOrder);\r
\r
return Status;\r
}\r
EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData;\r
EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;\r
\r
- FloppyNumber = 0;\r
- CdromNumber = 0;\r
- UsbNumber = 0;\r
- MiscNumber = 0;\r
+ FloppyNumber = 0;\r
+ CdromNumber = 0;\r
+ UsbNumber = 0;\r
+ MiscNumber = 0;\r
ZeroMem (Buffer, sizeof (Buffer));\r
+ \r
//\r
// If the boot device enumerate happened, just get the boot\r
// device from the boot order variable\r
BdsLibBuildOptionFromVar (BdsBootOptionList, L"BootOrder");\r
return EFI_SUCCESS;\r
}\r
+ \r
//\r
// Notes: this dirty code is to get the legacy boot option from the\r
// BBS table and create to variable as the EFI boot option, it should\r
// Delete invalid boot option\r
//\r
BdsDeleteAllInvalidEfiBootOption ();\r
+ \r
//\r
// Parse removable media\r
//\r
&NumberBlockIoHandles,\r
&BlockIoHandles\r
);\r
+ \r
for (Index = 0; Index < NumberBlockIoHandles; Index++) {\r
Status = gBS->HandleProtocol (\r
BlockIoHandles[Index],\r
}\r
\r
if (NumberBlockIoHandles != 0) {\r
- gBS->FreePool (BlockIoHandles);\r
+ SafeFreePool (BlockIoHandles);\r
}\r
\r
//\r
NeedDelete = TRUE;\r
Status = BdsLibGetImageHeader (\r
FileSystemHandles[Index],\r
- DEFAULT_REMOVABLE_FILE_NAME,\r
+ (CHAR16*)PcdGetPtr (PcdDefaultBootFileName),\r
&DosHeader,\r
Hdr\r
);\r
}\r
\r
if (NumberFileSystemHandles != 0) {\r
- gBS->FreePool (FileSystemHandles);\r
+ SafeFreePool (FileSystemHandles);\r
}\r
\r
//\r
}\r
\r
if (NumberSimpleNetworkHandles != 0) {\r
- gBS->FreePool (SimpleNetworkHandles);\r
+ SafeFreePool (SimpleNetworkHandles);\r
}\r
\r
//\r
}\r
\r
if (FvHandleCount != 0) {\r
- gBS->FreePool (FvHandleBuffer);\r
+ SafeFreePool (FvHandleBuffer);\r
}\r
//\r
// Make sure every boot only have one time\r
return EFI_SUCCESS;\r
}\r
\r
-\r
/**\r
Build the boot option with the handle parsed in.\r
\r
// Build the shell device path\r
//\r
EfiInitializeFwVolDevicepathNode (&ShellNode, &gEfiShellFileGuid);\r
- //\r
- //ShellNode.Header.Type = MEDIA_DEVICE_PATH;\r
- //ShellNode.Header.SubType = MEDIA_FV_FILEPATH_DP;\r
- //SetDevicePathNodeLength (&ShellNode.Header, sizeof (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH));\r
- //CopyMem (&ShellNode.NameGuid, &gEfiShellFileGuid, sizeof (EFI_GUID));\r
- //\r
+\r
DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &ShellNode);\r
\r
//\r
\r
}\r
\r
-\r
/**\r
Boot from the EFI1.1 spec defined "BootNext" variable\r
\r
\r
}\r
\r
-\r
-\r
/**\r
Return the bootable media handle.\r
First, check the device is connected\r
EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;\r
\r
UpdatedDevicePath = DevicePath;\r
+ \r
//\r
// Check whether the device is connected\r
//\r
// Fail to find the proper BlockIo and simple file protocol, maybe because device not present, we need to connect it firstly\r
//\r
UpdatedDevicePath = DevicePath;\r
- Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &UpdatedDevicePath, &Handle);\r
+ Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &UpdatedDevicePath, &Handle);\r
gBS->ConnectController (Handle, NULL, NULL, TRUE);\r
}\r
} else {\r
BlockIo->Media->BlockSize,\r
Buffer\r
);\r
- gBS->FreePool (Buffer);\r
+ SafeFreePool(Buffer);\r
}\r
}\r
\r
Hdr.Union = &HdrData;\r
Status = BdsLibGetImageHeader (\r
SimpleFileSystemHandles[Index],\r
- DEFAULT_REMOVABLE_FILE_NAME,\r
+ (CHAR16*)PcdGetPtr(PcdDefaultBootFileName),\r
&DosHeader,\r
Hdr\r
);\r
}\r
}\r
\r
- if (DupDevicePath != NULL) {\r
- SafeFreePool(DupDevicePath);\r
- }\r
- if (SimpleFileSystemHandles !=NULL ) {\r
- gBS->FreePool (SimpleFileSystemHandles);\r
- }\r
+ SafeFreePool(DupDevicePath);\r
+\r
+ SafeFreePool(SimpleFileSystemHandles);\r
\r
return ReturnHandle;\r
}\r
\r
-\r
-\r
-\r
/**\r
Check to see if the network cable is plugged in. If the DevicePath is not\r
connected it will be connected.\r
return MediaPresent;\r
}\r
\r
-\r
-\r
/**\r
For a bootable Device path, return its boot type.\r
\r
return BDS_EFI_UNSUPPORT;\r
}\r
\r
-\r
/**\r
Check whether the Device path in a boot option point to a valide bootable device,\r
And if CheckMedia is true, check the device is ready to boot now.\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 DevPath the Device path in a boot option\r
+ @param CheckMedia if true, check the device is ready to boot now.\r
\r
- @return TRUE -- the Device path is valide\r
- @return FALSE -- the Device path is invalide .\r
+ @retval TRUE the Device path is valide\r
+ @retval FALSE the Device path is invalide .\r
\r
**/\r
BOOLEAN\r
\r
TempDevicePath = DevPath;\r
LastDeviceNode = DevPath;\r
+ \r
//\r
// Check if it's a valid boot option for network boot device\r
// Only check if there is SimpleNetworkProtocol installed. If yes, that means\r
&Handle\r
);\r
}\r
+ \r
if (!EFI_ERROR (Status)) {\r
if (CheckMedia) {\r
//\r
return TRUE;\r
} else {\r
if (Status == EFI_SUCCESS) {\r
- gBS->FreePool (TempDevicePath); \r
+ SafeFreePool (TempDevicePath); \r
}\r
return FALSE;\r
}\r
Status = gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &TempDevicePath, &Handle);\r
}\r
}\r
+ \r
if (!EFI_ERROR (Status)) {\r
Status = gBS->HandleProtocol (Handle, &gEfiBlockIoProtocolGuid, (VOID **)&BlockIo);\r
if (!EFI_ERROR (Status)) {\r
EFIAPI\r
BdsLibUpdateFvFileDevicePath (\r
IN OUT EFI_DEVICE_PATH_PROTOCOL ** DevicePath,\r
- IN EFI_GUID *FileGuid\r
+ IN EFI_GUID *FileGuid\r
)\r
{\r
EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r
if (FileGuid == NULL) {\r
return EFI_INVALID_PARAMETER;\r
}\r
+ \r
//\r
// Check whether the device path point to the default the input Fv file\r
//\r
FoundFvHandle = FvHandleBuffer[Index];\r
break;\r
}\r
- if (FvHandleBuffer !=NULL ) {\r
- FreePool (FvHandleBuffer); \r
- }\r
+ \r
+ SafeFreePool (FvHandleBuffer); \r
}\r
\r
if (FindFvFile) {\r