UINT8 *SrcPtr;\r
EFI_FFS_FILE_HEADER *FfsHeader;\r
UINTN InputBufferSize;\r
+ UINTN WholeFileSize;\r
\r
if (NameGuid == NULL) {\r
return EFI_INVALID_PARAMETER;\r
\r
//\r
// Keep looking until we find the matching NameGuid.\r
- // The Key is really an FfsFileEntry\r
+ // The Key is really a FfsFileEntry\r
//\r
FvDevice->LastKey = 0;\r
do {\r
// Get a pointer to the header\r
//\r
FfsHeader = FvDevice->LastKey->FfsHeader;\r
+ if (FvDevice->IsMemoryMapped) {\r
+ //\r
+ // Memory mapped FV has not been cached, so here is to cache by file.\r
+ //\r
+ if (!FvDevice->LastKey->FileCached) {\r
+ //\r
+ // Cache FFS file to memory buffer.\r
+ //\r
+ WholeFileSize = IS_FFS_FILE2 (FfsHeader) ? FFS_FILE2_SIZE (FfsHeader): FFS_FILE_SIZE (FfsHeader);\r
+ FfsHeader = AllocateCopyPool (WholeFileSize, FfsHeader);\r
+ if (FfsHeader == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+ //\r
+ // Let FfsHeader in FfsFileEntry point to the cached file buffer.\r
+ //\r
+ FvDevice->LastKey->FfsHeader = FfsHeader;\r
+ FvDevice->LastKey->FileCached = TRUE;\r
+ }\r
+ }\r
\r
//\r
// Remember callers buffer size\r
FvDevice = FV_DEVICE_FROM_THIS (This);\r
\r
//\r
- // Read the whole file into buffer\r
+ // Read the file\r
//\r
- FileBuffer = NULL;\r
Status = FvReadFile (\r
This,\r
NameGuid,\r
- (VOID **)&FileBuffer,\r
+ NULL,\r
&FileSize,\r
&FileType,\r
&FileAttributes,\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
- ASSERT (FileBuffer != NULL);\r
-\r
+ if (IS_FFS_FILE2 (FfsEntry->FfsHeader)) {\r
+ FileBuffer = ((UINT8 *) FfsEntry->FfsHeader) + sizeof (EFI_FFS_FILE_HEADER2);\r
+ } else {\r
+ FileBuffer = ((UINT8 *) FfsEntry->FfsHeader) + sizeof (EFI_FFS_FILE_HEADER);\r
+ }\r
//\r
// Check to see that the file actually HAS sections before we go any further.\r
//\r
//\r
\r
Done:\r
- CoreFreePool (FileBuffer);\r
-\r
return Status;\r
}\r
\r