/** @file\r
Library functions which relates with booting.\r
\r
-(C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>\r
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
mBmLegacyBoot = LegacyBoot;\r
}\r
\r
+/**\r
+ Return TRUE when the boot option is auto-created instead of manually added.\r
+\r
+ @param BootOption Pointer to the boot option to check.\r
+\r
+ @retval TRUE The boot option is auto-created.\r
+ @retval FALSE The boot option is manually added.\r
+**/\r
+BOOLEAN\r
+BmIsAutoCreateBootOption (\r
+ EFI_BOOT_MANAGER_LOAD_OPTION *BootOption\r
+ )\r
+{\r
+ if ((BootOption->OptionalDataSize == sizeof (EFI_GUID)) &&\r
+ CompareGuid ((EFI_GUID *) BootOption->OptionalData, &mBmAutoCreateBootOptionGuid)\r
+ ) {\r
+ return TRUE;\r
+ } else {\r
+ return FALSE;\r
+ }\r
+}\r
+\r
/**\r
For a bootable Device path, return its boot type.\r
\r
if (OptionNumber == LoadOptionNumberUnassigned) {\r
BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);\r
\r
- Index = BmFindLoadOption (OptionToFind, BootOptions, BootOptionCount);\r
+ Index = EfiBootManagerFindLoadOption (OptionToFind, BootOptions, BootOptionCount);\r
if (Index != -1) {\r
OptionNumber = BootOptions[Index].OptionNumber;\r
}\r
return FileBuffer;\r
}\r
\r
+/**\r
+ Expand File-path device path node to be full device path in platform.\r
+\r
+ @param FilePath The device path pointing to a load option.\r
+ It could be a short-form device path.\r
+ @param FullPath Return the full device path of the load option after\r
+ short-form device path expanding.\r
+ Caller is responsible to free it.\r
+ @param FileSize Return the load option size.\r
+\r
+ @return The load option buffer. Caller is responsible to free the memory.\r
+**/\r
+VOID *\r
+BmExpandFileDevicePath (\r
+ IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r
+ OUT EFI_DEVICE_PATH_PROTOCOL **FullPath,\r
+ OUT UINTN *FileSize\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ UINTN Index;\r
+ UINTN HandleCount;\r
+ EFI_HANDLE *Handles;\r
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+ UINTN MediaType;\r
+ EFI_DEVICE_PATH_PROTOCOL *FullDevicePath;\r
+ VOID *FileBuffer;\r
+ UINT32 AuthenticationStatus;\r
+ \r
+ EfiBootManagerConnectAll ();\r
+ Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiSimpleFileSystemProtocolGuid, NULL, &HandleCount, &Handles);\r
+ if (EFI_ERROR (Status)) {\r
+ HandleCount = 0;\r
+ Handles = NULL;\r
+ }\r
+\r
+ //\r
+ // Enumerate all removable media devices followed by all fixed media devices,\r
+ // followed by media devices which don't layer on block io.\r
+ //\r
+ for (MediaType = 0; MediaType < 3; MediaType++) {\r
+ for (Index = 0; Index < HandleCount; Index++) {\r
+ Status = gBS->HandleProtocol (Handles[Index], &gEfiBlockIoProtocolGuid, (VOID *) &BlockIo);\r
+ if (EFI_ERROR (Status)) {\r
+ BlockIo = NULL;\r
+ }\r
+ if ((MediaType == 0 && BlockIo != NULL && BlockIo->Media->RemovableMedia) ||\r
+ (MediaType == 1 && BlockIo != NULL && !BlockIo->Media->RemovableMedia) ||\r
+ (MediaType == 2 && BlockIo == NULL)\r
+ ) {\r
+ FullDevicePath = AppendDevicePath (DevicePathFromHandle (Handles[Index]), FilePath);\r
+ FileBuffer = GetFileBufferByFilePath (TRUE, FullDevicePath, FileSize, &AuthenticationStatus);\r
+ if (FileBuffer != NULL) {\r
+ *FullPath = FullDevicePath;\r
+ FreePool (Handles);\r
+ return FileBuffer;\r
+ }\r
+ FreePool (FullDevicePath);\r
+ }\r
+ }\r
+ }\r
+\r
+ if (Handles != NULL) {\r
+ FreePool (Handles);\r
+ }\r
+\r
+ *FullPath = NULL;\r
+ return NULL;\r
+}\r
+\r
/**\r
Save the partition DevicePath to the CachedDevicePath as the first instance.\r
\r
// Expand the Harddrive device path\r
//\r
return BmExpandPartitionDevicePath (FilePath, FullPath, FileSize);\r
+ } else if ((DevicePathType (FilePath) == MEDIA_DEVICE_PATH) &&\r
+ (DevicePathSubType (FilePath) == MEDIA_FILEPATH_DP)) {\r
+ //\r
+ // Expand the File-path device path\r
+ //\r
+ return BmExpandFileDevicePath (FilePath, FullPath, FileSize);\r
} else {\r
for (Node = FilePath; !IsDevicePathEnd (Node); Node = NextDevicePathNode (Node)) {\r
if ((DevicePathType (Node) == MESSAGING_DEVICE_PATH) &&\r
// 6. Adjust the different type memory page number just before booting\r
// and save the updated info into the variable for next boot to use\r
//\r
- if ((BootOption->Attributes & LOAD_OPTION_CATEGORY) == LOAD_OPTION_CATEGORY_BOOT) {\r
- if (PcdGetBool (PcdResetOnMemoryTypeInformationChange)) {\r
- BmSetMemoryTypeInformationVariable ();\r
- }\r
- }\r
+ BmSetMemoryTypeInformationVariable (\r
+ (BOOLEAN) ((BootOption->Attributes & LOAD_OPTION_CATEGORY) == LOAD_OPTION_CATEGORY_BOOT)\r
+ );\r
\r
DEBUG_CODE_BEGIN();\r
if (BootOption->Description == NULL) {\r
Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &ImageInfo);\r
ASSERT_EFI_ERROR (Status);\r
\r
- ImageInfo->LoadOptionsSize = BootOption->OptionalDataSize;\r
- ImageInfo->LoadOptions = BootOption->OptionalData;\r
+ if (!BmIsAutoCreateBootOption (BootOption)) {\r
+ ImageInfo->LoadOptionsSize = BootOption->OptionalDataSize;\r
+ ImageInfo->LoadOptions = BootOption->OptionalData;\r
+ }\r
\r
//\r
// Clean to NULL because the image is loaded directly from the firmwares boot manager.\r
for (Index = 0; Index < NvBootOptionCount; Index++) {\r
if (((DevicePathType (NvBootOptions[Index].FilePath) != BBS_DEVICE_PATH) || \r
(DevicePathSubType (NvBootOptions[Index].FilePath) != BBS_BBS_DP)\r
- ) &&\r
- (NvBootOptions[Index].OptionalDataSize == sizeof (EFI_GUID)) &&\r
- CompareGuid ((EFI_GUID *) NvBootOptions[Index].OptionalData, &mBmAutoCreateBootOptionGuid)\r
+ ) && BmIsAutoCreateBootOption (&NvBootOptions[Index])\r
) {\r
//\r
// Only check those added by BDS\r
// so that the boot options added by end-user or OS installer won't be deleted\r
//\r
- if (BmFindLoadOption (&NvBootOptions[Index], BootOptions, BootOptionCount) == (UINTN) -1) {\r
+ if (EfiBootManagerFindLoadOption (&NvBootOptions[Index], BootOptions, BootOptionCount) == (UINTN) -1) {\r
Status = EfiBootManagerDeleteLoadOptionVariable (NvBootOptions[Index].OptionNumber, LoadOptionTypeBoot);\r
//\r
// Deleting variable with current variable implementation shouldn't fail.\r
// Add new EFI boot options to NV\r
//\r
for (Index = 0; Index < BootOptionCount; Index++) {\r
- if (BmFindLoadOption (&BootOptions[Index], NvBootOptions, NvBootOptionCount) == (UINTN) -1) {\r
+ if (EfiBootManagerFindLoadOption (&BootOptions[Index], NvBootOptions, NvBootOptionCount) == (UINTN) -1) {\r
EfiBootManagerAddLoadOptionVariable (&BootOptions[Index], (UINTN) -1);\r
//\r
// Try best to add the boot options so continue upon failure.\r
UINTN BootOptionCount;\r
\r
BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);\r
- ASSERT (BmFindLoadOption (BootOption, BootOptions, BootOptionCount) == -1);\r
+ ASSERT (EfiBootManagerFindLoadOption (BootOption, BootOptions, BootOptionCount) == -1);\r
EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount);\r
);\r
\r