35 IN CONST EFI_DEVICE_PATH_PROTOCOL *DmgDevicePath,
36 IN UINTN DmgDevicePathSize
39 EFI_DEVICE_PATH_PROTOCOL *BootDevicePath;
44 CONST EFI_DEVICE_PATH_PROTOCOL *FsDevicePath;
45 UINTN FsDevicePathSize;
48 EFI_HANDLE *HandleBuffer;
51 ASSERT (DmgDevicePath != NULL);
52 ASSERT (DmgDevicePathSize >= END_DEVICE_PATH_LENGTH);
54 BootDevicePath = NULL;
56 Status =
gBS->LocateHandleBuffer (
63 if (EFI_ERROR (Status)) {
67 for (Index = 0; Index < NumHandles; ++Index) {
68 Status =
gBS->HandleProtocol (
71 (VOID **)&FsDevicePath
73 if (EFI_ERROR (Status)) {
77 FsDevicePathSize = GetDevicePathSize (FsDevicePath);
79 if (FsDevicePathSize < DmgDevicePathSize) {
86 (DmgDevicePathSize - END_DEVICE_PATH_LENGTH)
98 if (!EFI_ERROR (Status)) {
102 BootDevicePath = NULL;
105 FreePool (HandleBuffer);
107 return BootDevicePath;
213 IN EFI_FILE_PROTOCOL *Directory,
214 OUT UINTN *FileNameLen
218 EFI_FILE_INFO *FileInfo;
224 ASSERT (Directory != NULL);
227 Status = FileHandleFindFirstFile (Directory, &FileInfo), NoFile = FALSE;
228 (!EFI_ERROR (Status) && !NoFile);
229 Status = FileHandleFindNextFile (Directory, FileInfo, &NoFile)
232 if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) != 0) {
239 Length = StrLen (FileInfo->FileName);
245 Result = StrCmp (&FileInfo->FileName[ExtOffset], L
".dmg");
247 if (FileNameLen != NULL) {
248 *FileNameLen = ExtOffset;
261 IN EFI_FILE_PROTOCOL *Directory,
262 IN CONST CHAR16 *DmgFileName,
263 IN UINTN DmgFileNameLen
267 EFI_FILE_INFO *FileInfo;
271 UINTN ChunklistFileNameLen;
273 ChunklistFileNameLen = (DmgFileNameLen +
L_STR_LEN (
".chunklist"));
276 Status = FileHandleFindFirstFile (Directory, &FileInfo), NoFile = FALSE;
277 (!EFI_ERROR (Status) && !NoFile);
278 Status = FileHandleFindNextFile (Directory, FileInfo, &NoFile)
281 if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) != 0) {
285 NameLen = StrLen (FileInfo->FileName);
287 if (NameLen != ChunklistFileNameLen) {
291 Result = StrnCmp (FileInfo->FileName, DmgFileName, DmgFileNameLen);
296 Result = StrCmp (&FileInfo->FileName[DmgFileNameLen], L
".chunklist");
300 "OCB: Found chunklist %s for DMG %s[%d]\n",
311 "OCB: Found no chunklist for DMG %s[%d]\n",
325 EFI_DEVICE_PATH_PROTOCOL *DevPath;
330 EFI_FILE_PROTOCOL *DmgDir;
332 UINTN DmgFileNameLen;
333 EFI_FILE_INFO *DmgFileInfo;
334 EFI_FILE_PROTOCOL *DmgFile;
337 EFI_FILE_INFO *ChunklistFileInfo;
338 EFI_FILE_PROTOCOL *ChunklistFile;
339 UINT32 ChunklistFileSize;
340 VOID *ChunklistBuffer;
346 if (DmgPreloadContext->DmgContext != NULL) {
347 Context->DmgContext = DmgPreloadContext->DmgContext;
348 DmgFileSize = DmgPreloadContext->DmgFileSize;
350 if (DmgPreloadContext->DmgFile != NULL) {
351 DmgFile = DmgPreloadContext->DmgFile;
352 DmgFileSize = DmgPreloadContext->DmgFileSize;
354 DevPath = Context->DevicePath;
361 if (EFI_ERROR (Status)) {
362 DevPathText = ConvertDevicePathToText (Context->DevicePath, FALSE, FALSE);
363 DEBUG ((DEBUG_INFO,
"OCB: Failed to open DMG directory %s\n", DevPathText));
364 if (DevPathText != NULL) {
365 FreePool (DevPathText);
372 if (DmgFileInfo == NULL) {
373 DevPathText = ConvertDevicePathToText (Context->DevicePath, FALSE, FALSE);
374 DEBUG ((DEBUG_INFO,
"OCB: Unable to find any DMG at %s\n"));
375 if (DevPathText != NULL) {
376 FreePool (DevPathText);
379 DmgDir->Close (DmgDir);
386 DmgFileInfo->FileName,
390 if (EFI_ERROR (Status)) {
393 "OCB: Failed to open DMG file %s - %r\n",
394 DmgFileInfo->FileName,
398 FreePool (DmgFileInfo);
399 DmgDir->Close (DmgDir);
404 if (EFI_ERROR (Status)) {
407 "OCB: Failed to retrieve DMG file size - %r\n",
411 FreePool (DmgFileInfo);
412 DmgDir->Close (DmgDir);
413 DmgFile->Close (DmgFile);
418 Context->DmgContext = AllocatePool (
sizeof (*Context->DmgContext));
419 if (Context->DmgContext == NULL) {
420 DEBUG ((DEBUG_INFO,
"OCB: Failed to allocate DMG context\n"));
426 DmgFile->Close (DmgFile);
429 DEBUG ((DEBUG_INFO,
"OCB: Failed to initialise DMG from file\n"));
431 if (DmgPreloadContext->DmgFile == NULL) {
432 FreePool (DmgFileInfo);
433 DmgDir->Close (DmgDir);
436 FreePool (Context->DmgContext);
441 ChunklistBuffer = NULL;
442 ChunklistFileSize = 0;
443 if ( (DmgPreloadContext->DmgFile != NULL)
444 || (DmgPreloadContext->DmgContext != NULL))
446 if (DmgPreloadContext->ChunklistBuffer != NULL) {
447 ChunklistBuffer = DmgPreloadContext->ChunklistBuffer;
448 ChunklistFileSize = DmgPreloadContext->ChunklistFileSize;
453 DmgFileInfo->FileName,
456 if (ChunklistFileInfo != NULL) {
460 ChunklistFileInfo->FileName,
464 if (!EFI_ERROR (Status)) {
466 if (Status == EFI_SUCCESS) {
467 ChunklistBuffer = AllocatePool (ChunklistFileSize);
469 if (ChunklistBuffer == NULL) {
470 ChunklistFileSize = 0;
472 Status =
OcGetFileData (ChunklistFile, 0, ChunklistFileSize, ChunklistBuffer);
473 if (EFI_ERROR (Status)) {
474 FreePool (ChunklistBuffer);
475 ChunklistBuffer = NULL;
476 ChunklistFileSize = 0;
481 ChunklistFile->Close (ChunklistFile);
484 FreePool (ChunklistFileInfo);
488 if ( (DmgPreloadContext->DmgFile == NULL)
489 && (DmgPreloadContext->DmgContext == NULL))
491 FreePool (DmgFileInfo);
492 DmgDir->Close (DmgDir);
502 Context->DevicePath = DevPath;
504 if (DevPath != NULL) {
511 DEBUG ((DEBUG_INFO,
"OCB: Failed to retrieve boot file from DMG\n"));
514 FreePool (Context->DmgContext);
517 if (ChunklistBuffer != NULL) {
518 FreePool (ChunklistBuffer);