/** @file\r
Pei Core Firmware File System service routines.\r
\r
-Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 HP Development Company, L.P.\r
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<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
UINTN Index;\r
PEI_CORE_INSTANCE *PrivateData;\r
EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;\r
+ UINTN BestIndex;\r
\r
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (GetPeiServicesTablePointer ());\r
+ BestIndex = PrivateData->FvCount;\r
\r
+ //\r
+ // Find the best matched FV image that includes this FileHandle.\r
+ // FV may include the child FV, and they are in the same continuous space. \r
+ // If FileHandle is from the child FV, the updated logic can find its matched FV.\r
+ //\r
for (Index = 0; Index < PrivateData->FvCount; Index++) {\r
FwVolHeader = PrivateData->Fv[Index].FvHeader;\r
if (((UINT64) (UINTN) FileHandle > (UINT64) (UINTN) FwVolHeader ) && \\r
((UINT64) (UINTN) FileHandle <= ((UINT64) (UINTN) FwVolHeader + FwVolHeader->FvLength - 1))) {\r
- return &PrivateData->Fv[Index];\r
+ if (BestIndex == PrivateData->FvCount) {\r
+ BestIndex = Index;\r
+ } else {\r
+ if ((UINT64) (UINTN) PrivateData->Fv[BestIndex].FvHeader < (UINT64) (UINTN) FwVolHeader) {\r
+ BestIndex = Index;\r
+ }\r
+ }\r
}\r
}\r
+\r
+ if (BestIndex < PrivateData->FvCount) {\r
+ return &PrivateData->Fv[BestIndex];\r
+ }\r
+\r
return NULL;\r
}\r
\r
EFI_PEI_FILE_HANDLE FileHandle;\r
VOID *DepexData;\r
BOOLEAN IsFvInfo2;\r
- \r
+ UINTN CurFvCount;\r
+\r
Status = EFI_SUCCESS;\r
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
\r
- if (PrivateData->FvCount >= PcdGet32 (PcdPeiCoreMaxFvSupported)) {\r
- DEBUG ((EFI_D_ERROR, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData->FvCount + 1, PcdGet32 (PcdPeiCoreMaxFvSupported)));\r
- DEBUG ((EFI_D_ERROR, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));\r
- ASSERT (FALSE);\r
- }\r
-\r
if (CompareGuid (NotifyDescriptor->Guid, &gEfiPeiFirmwareVolumeInfo2PpiGuid)) {\r
//\r
// It is FvInfo2PPI.\r
}\r
}\r
\r
+ if (PrivateData->FvCount >= PcdGet32 (PcdPeiCoreMaxFvSupported)) {\r
+ DEBUG ((EFI_D_ERROR, "The number of Fv Images (%d) exceed the max supported FVs (%d) in Pei", PrivateData->FvCount + 1, PcdGet32 (PcdPeiCoreMaxFvSupported)));\r
+ DEBUG ((EFI_D_ERROR, "PcdPeiCoreMaxFvSupported value need be reconfigurated in DSC"));\r
+ ASSERT (FALSE);\r
+ }\r
+\r
//\r
// Update internal PEI_CORE_FV array.\r
//\r
PrivateData->Fv[PrivateData->FvCount].FvPpi = FvPpi;\r
PrivateData->Fv[PrivateData->FvCount].FvHandle = FvHandle;\r
PrivateData->Fv[PrivateData->FvCount].AuthenticationStatus = FvInfo2Ppi.AuthenticationStatus;\r
+ CurFvCount = PrivateData->FvCount;\r
DEBUG ((\r
EFI_D_INFO, \r
"The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n", \r
- (UINT32) PrivateData->FvCount, \r
+ (UINT32) CurFvCount,\r
(VOID *) FvInfo2Ppi.FvInfo, \r
FvInfo2Ppi.FvInfoSize,\r
FvHandle\r
}\r
}\r
\r
- DEBUG ((EFI_D_INFO, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle, PrivateData->FvCount - 1, FvHandle));\r
- ProcessFvFile (PrivateData, &PrivateData->Fv[PrivateData->FvCount - 1], FileHandle);\r
+ DEBUG ((EFI_D_INFO, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle, CurFvCount, FvHandle));\r
+ ProcessFvFile (PrivateData, &PrivateData->Fv[CurFvCount], FileHandle);\r
}\r
} while (FileHandle != NULL);\r
} else {\r
\r
//\r
// Install FvInfo(2) Ppi\r
+ // NOTE: FvInfo2 must be installed before FvInfo so that recursive processing of encapsulated\r
+ // FVs inherit the proper AuthenticationStatus.\r
//\r
- PeiServicesInstallFvInfoPpi (\r
+ PeiServicesInstallFvInfo2Ppi(\r
&FvHeader->FileSystemGuid,\r
- (VOID**) FvHeader,\r
- (UINT32) FvHeader->FvLength,\r
+ (VOID**)FvHeader,\r
+ (UINT32)FvHeader->FvLength,\r
&ParentFvImageInfo.FvName,\r
- &FileInfo.FileName\r
+ &FileInfo.FileName,\r
+ AuthenticationStatus\r
);\r
\r
- PeiServicesInstallFvInfo2Ppi (\r
+ PeiServicesInstallFvInfoPpi (\r
&FvHeader->FileSystemGuid,\r
(VOID**) FvHeader,\r
(UINT32) FvHeader->FvLength,\r
&ParentFvImageInfo.FvName,\r
- &FileInfo.FileName,\r
- AuthenticationStatus\r
+ &FileInfo.FileName\r
);\r
\r
//\r
/**\r
After PeiCore image is shadowed into permanent memory, all build-in FvPpi should\r
be re-installed with the instance in permanent memory and all cached FvPpi pointers in \r
- PrivateData->Fv[] array should be fixed up to be pointed to the one in permenant\r
+ PrivateData->Fv[] array should be fixed up to be pointed to the one in permanent\r
memory.\r
\r
@param PrivateData Pointer to PEI_CORE_INSTANCE.\r
UINTN FvIndex;\r
EFI_PEI_FILE_HANDLE FileHandle;\r
VOID *DepexData; \r
- \r
+ UINTN CurFvCount;\r
+\r
PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);\r
FvPpi = (EFI_PEI_FIRMWARE_VOLUME_PPI*) Ppi;\r
\r
PrivateData->Fv[PrivateData->FvCount].FvPpi = FvPpi;\r
PrivateData->Fv[PrivateData->FvCount].FvHandle = FvHandle;\r
PrivateData->Fv[PrivateData->FvCount].AuthenticationStatus = AuthenticationStatus;\r
+ CurFvCount = PrivateData->FvCount;\r
DEBUG ((\r
EFI_D_INFO, \r
"The %dth FV start address is 0x%11p, size is 0x%08x, handle is 0x%p\n", \r
- (UINT32) PrivateData->FvCount, \r
+ (UINT32) CurFvCount,\r
(VOID *) FvInfo, \r
FvInfoSize,\r
FvHandle\r
}\r
}\r
\r
- DEBUG ((EFI_D_INFO, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle, PrivateData->FvCount - 1, FvHandle));\r
- ProcessFvFile (PrivateData, &PrivateData->Fv[PrivateData->FvCount - 1], FileHandle);\r
+ DEBUG ((EFI_D_INFO, "Found firmware volume Image File %p in FV[%d] %p\n", FileHandle, CurFvCount, FvHandle));\r
+ ProcessFvFile (PrivateData, &PrivateData->Fv[CurFvCount], FileHandle);\r
}\r
} while (FileHandle != NULL);\r
} while (TRUE);\r