UINTN Index;\r
UINTN HandleCount;\r
EFI_HANDLE *Handles;\r
- EFI_LOAD_FILE_PROTOCOL *LoadFile;\r
VOID *FileBuffer;\r
\r
EfiBootManagerConnectAll ();\r
Handles = NULL;\r
}\r
\r
- FileBuffer = NULL;\r
-\r
for (Index = 0; Index < HandleCount; Index++) {\r
- Status = gBS->HandleProtocol (Handles[Index], &gEfiLoadFileProtocolGuid, (VOID *) &LoadFile);\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- FileBuffer = NULL;\r
- Status = LoadFile->LoadFile (LoadFile, FilePath, TRUE, FileSize, FileBuffer);\r
- if (Status == EFI_BUFFER_TOO_SMALL) {\r
- FileBuffer = AllocatePool (*FileSize);\r
- if (FileBuffer == NULL) {\r
- break;\r
- }\r
- Status = LoadFile->LoadFile (LoadFile, FilePath, TRUE, FileSize, FileBuffer);\r
- }\r
-\r
- if (!EFI_ERROR (Status)) {\r
- //\r
- // LoadFile() returns a file buffer mapping to a file system.\r
- //\r
- if (Status == EFI_WARN_FILE_SYSTEM) {\r
- return BmGetFileBufferFromLoadFileFileSystem (Handles[Index], FullPath, FileSize);\r
- }\r
-\r
- ASSERT (Status == EFI_SUCCESS);\r
- *FullPath = DuplicateDevicePath (DevicePathFromHandle (Handles[Index]));\r
- break;\r
- }\r
-\r
+ FileBuffer = BmGetFileBufferFromLoadFile (Handles[Index], FilePath, FullPath, FileSize);\r
if (FileBuffer != NULL) {\r
- FreePool (FileBuffer);\r
+ break;\r
}\r
}\r
\r
@return The load option buffer.\r
**/\r
VOID *\r
-BmGetFileBufferFromLoadFileFileSystem (\r
+BmGetFileBufferFromLoadFileSystem (\r
IN EFI_HANDLE LoadFileHandle,\r
OUT EFI_DEVICE_PATH_PROTOCOL **FullPath,\r
OUT UINTN *FileSize\r
}\r
}\r
\r
+\r
/**\r
- Get the file buffer from Load File instance.\r
+ Get the file buffer from the specified Load File instance.\r
+\r
+ @param LoadFileHandle The specified Load File instance.\r
+ @param FilePath The file path which will pass to LoadFile().\r
+ @param FullPath Return the full device path pointing to the load option.\r
+ @param FileSize Return the size of the load option.\r
+\r
+ @return The load option buffer or NULL if fails.\r
+**/\r
+VOID *\r
+BmGetFileBufferFromLoadFile (\r
+ EFI_HANDLE LoadFileHandle,\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
+ EFI_LOAD_FILE_PROTOCOL *LoadFile;\r
+ VOID *FileBuffer;\r
+ BOOLEAN LoadFileSystem;\r
+ UINTN BufferSize;\r
+\r
+ *FileSize = 0;\r
+\r
+ Status = gBS->OpenProtocol (\r
+ LoadFileHandle,\r
+ &gEfiLoadFileProtocolGuid,\r
+ (VOID **) &LoadFile,\r
+ gImageHandle,\r
+ NULL,\r
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ FileBuffer = NULL;\r
+ BufferSize = 0;\r
+ Status = LoadFile->LoadFile (LoadFile, FilePath, TRUE, &BufferSize, FileBuffer);\r
+ if ((Status != EFI_WARN_FILE_SYSTEM) && (Status != EFI_BUFFER_TOO_SMALL)) {\r
+ return NULL;\r
+ }\r
+\r
+ LoadFileSystem = (BOOLEAN) (Status == EFI_WARN_FILE_SYSTEM);\r
+ FileBuffer = LoadFileSystem ? AllocateReservedPages (EFI_SIZE_TO_PAGES (BufferSize)) : AllocatePool (BufferSize);\r
+ if (FileBuffer == NULL) {\r
+ return NULL;\r
+ }\r
+\r
+ Status = LoadFile->LoadFile (LoadFile, FilePath, TRUE, &BufferSize, FileBuffer);\r
+ if (EFI_ERROR (Status)) {\r
+ if (LoadFileSystem) {\r
+ FreePages (FileBuffer, EFI_SIZE_TO_PAGES (BufferSize));\r
+ } else {\r
+ FreePool (FileBuffer);\r
+ }\r
+ return NULL;\r
+ }\r
+\r
+ if (LoadFileSystem) {\r
+ FileBuffer = BmGetFileBufferFromLoadFileSystem (LoadFileHandle, FullPath, FileSize);\r
+ } else {\r
+ *FileSize = BufferSize;\r
+ *FullPath = DuplicateDevicePath (DevicePathFromHandle (LoadFileHandle));\r
+ }\r
+\r
+ return FileBuffer;\r
+}\r
+\r
+/**\r
+ Get the file buffer from all the Load File instances.\r
\r
@param FilePath The media device path pointing to a LoadFile instance.\r
@param FullPath Return the full device path pointing to the load option.\r
@return The load option buffer.\r
**/\r
VOID *\r
-BmGetFileBufferFromLoadFile (\r
+BmGetFileBufferFromLoadFiles (\r
IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r
OUT EFI_DEVICE_PATH_PROTOCOL **FullPath,\r
OUT UINTN *FileSize\r
{\r
EFI_STATUS Status;\r
EFI_HANDLE Handle;\r
- VOID *FileBuffer;\r
EFI_HANDLE *Handles;\r
UINTN HandleCount;\r
UINTN Index;\r
EFI_DEVICE_PATH_PROTOCOL *Node;\r
- EFI_LOAD_FILE_PROTOCOL *LoadFile;\r
- UINTN BufferSize;\r
\r
//\r
// Get file buffer from load file instance.\r
return NULL;\r
}\r
\r
- Status = gBS->HandleProtocol (Handle, &gEfiLoadFileProtocolGuid, (VOID **) &LoadFile);\r
- ASSERT_EFI_ERROR (Status);\r
-\r
- BufferSize = 0;\r
- FileBuffer = NULL;\r
- Status = LoadFile->LoadFile (LoadFile, FilePath, TRUE, &BufferSize, FileBuffer);\r
- if (Status == EFI_BUFFER_TOO_SMALL) {\r
- FileBuffer = AllocatePool (BufferSize);\r
- if (FileBuffer != NULL) {\r
- Status = EFI_SUCCESS;\r
- }\r
- }\r
-\r
- if (!EFI_ERROR (Status)) {\r
- Status = LoadFile->LoadFile (LoadFile, FilePath, TRUE, &BufferSize, FileBuffer);\r
- }\r
-\r
- if (!EFI_ERROR (Status)) {\r
- //\r
- // LoadFile() returns a file buffer mapping to a file system.\r
- //\r
- if (Status == EFI_WARN_FILE_SYSTEM) {\r
- return BmGetFileBufferFromLoadFileFileSystem (Handle, FullPath, FileSize);\r
- }\r
-\r
- ASSERT (Status == EFI_SUCCESS);\r
- //\r
- // LoadFile () may cause the device path of the Handle be updated.\r
- //\r
- *FullPath = DuplicateDevicePath (DevicePathFromHandle (Handle));\r
- *FileSize = BufferSize;\r
- return FileBuffer;\r
- } else {\r
- return NULL;\r
- }\r
+ return BmGetFileBufferFromLoadFile (Handle, FilePath, FullPath, FileSize);\r
}\r
\r
/**\r
return FileBuffer;\r
}\r
\r
- return BmGetFileBufferFromLoadFile (FilePath, FullPath, FileSize);\r
+ return BmGetFileBufferFromLoadFiles (FilePath, FullPath, FileSize);\r
}\r
\r
/**\r
IN CHAR16 Char\r
);\r
\r
-\r
-/**\r
- Get the file buffer from the file system produced by Load File instance.\r
-\r
- @param LoadFileHandle The handle of LoadFile instance.\r
- @param FullPath Return the full device path pointing to the load option.\r
- @param FileSize Return the size of the load option.\r
-\r
- @return The load option buffer.\r
-**/\r
-VOID *\r
-BmGetFileBufferFromLoadFileFileSystem (\r
- IN EFI_HANDLE LoadFileHandle,\r
- OUT EFI_DEVICE_PATH_PROTOCOL **FullPath,\r
- OUT UINTN *FileSize\r
- );\r
-\r
/**\r
Return the boot description for the controller.\r
\r
EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions,\r
UINTN BootOptionCount\r
);\r
+\r
+/**\r
+ Get the file buffer from the specified Load File instance.\r
+\r
+ @param LoadFileHandle The specified Load File instance.\r
+ @param FilePath The file path which will pass to LoadFile().\r
+ @param FullPath Return the full device path pointing to the load option.\r
+ @param FileSize Return the size of the load option.\r
+\r
+ @return The load option buffer or NULL if fails.\r
+**/\r
+VOID *\r
+BmGetFileBufferFromLoadFile (\r
+ EFI_HANDLE LoadFileHandle,\r
+ IN EFI_DEVICE_PATH_PROTOCOL *FilePath,\r
+ OUT EFI_DEVICE_PATH_PROTOCOL **FullPath,\r
+ OUT UINTN *FileSize\r
+ );\r
#endif // _INTERNAL_BM_H_\r