Pei Core Firmware File System service routines.\r
\r
Copyright (c) 2015 HP Development Company, L.P.\r
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2017, 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
};\r
\r
/**\r
-Required Alignment Alignment Value in FFS Alignment Value in\r
-(bytes) Attributes Field Firmware Volume Interfaces\r
-1 0 0\r
-16 1 4\r
-128 2 7\r
-512 3 9\r
-1 KB 4 10\r
-4 KB 5 12\r
-32 KB 6 15\r
-64 KB 7 16\r
+Required Alignment Alignment Value in FFS FFS_ATTRIB_DATA_ALIGNMENT2 Alignment Value in\r
+(bytes) Attributes Field in FFS Attributes Field Firmware Volume Interfaces\r
+1 0 0 0\r
+16 1 0 4\r
+128 2 0 7\r
+512 3 0 9\r
+1 KB 4 0 10\r
+4 KB 5 0 12\r
+32 KB 6 0 15\r
+64 KB 7 0 16\r
+128 KB 0 1 17\r
+256 KB 1 1 18\r
+512 KB 2 1 19\r
+1 MB 3 1 20\r
+2 MB 4 1 21\r
+4 MB 5 1 22\r
+8 MB 6 1 23\r
+16 MB 7 1 24\r
**/\r
UINT8 mFvAttributes[] = {0, 4, 7, 9, 10, 12, 15, 16};\r
+UINT8 mFvAttributes2[] = {17, 18, 19, 20, 21, 22, 23, 24};\r
\r
/**\r
Convert the FFS File Attributes to FV File Attributes\r
DataAlignment = (UINT8) ((FfsAttributes & FFS_ATTRIB_DATA_ALIGNMENT) >> 3);\r
ASSERT (DataAlignment < 8);\r
\r
- FileAttribute = (EFI_FV_FILE_ATTRIBUTES) mFvAttributes[DataAlignment];\r
+ if ((FfsAttributes & FFS_ATTRIB_DATA_ALIGNMENT_2) != 0) {\r
+ FileAttribute = (EFI_FV_FILE_ATTRIBUTES) mFvAttributes2[DataAlignment];\r
+ } else {\r
+ FileAttribute = (EFI_FV_FILE_ATTRIBUTES) mFvAttributes[DataAlignment];\r
+ }\r
\r
if ((FfsAttributes & FFS_ATTRIB_FIXED) == FFS_ATTRIB_FIXED) {\r
FileAttribute |= EFI_FV_FILE_ATTRIB_FIXED;\r
IsFvInfo2 = FALSE;\r
}\r
\r
+ if (CompareGuid (&FvInfo2Ppi.FvFormat, &gEfiFirmwareFileSystem2Guid)) {\r
+ //\r
+ // gEfiFirmwareFileSystem2Guid is specified for FvFormat, then here to check the\r
+ // FileSystemGuid pointed by FvInfo against gEfiFirmwareFileSystem2Guid to make sure\r
+ // FvInfo has the firmware file system 2 format.\r
+ //\r
+ // If the ASSERT really appears, FvFormat needs to be specified correctly, for example,\r
+ // gEfiFirmwareFileSystem3Guid can be used for firmware file system 3 format, or\r
+ // ((EFI_FIRMWARE_VOLUME_HEADER *) FvInfo)->FileSystemGuid can be just used for both\r
+ // firmware file system 2 and 3 format.\r
+ //\r
+ ASSERT (CompareGuid (&(((EFI_FIRMWARE_VOLUME_HEADER *) FvInfo2Ppi.FvInfo)->FileSystemGuid), &gEfiFirmwareFileSystem2Guid));\r
+ }\r
+\r
//\r
// Locate the corresponding FV_PPI according to founded FV's format guid\r
//\r
}\r
\r
if (!EFI_ERROR (Status)) {\r
- //\r
- // Update cache section data.\r
- //\r
- if (PrivateData->CacheSection.AllSectionCount < CACHE_SETION_MAX_NUMBER) {\r
- PrivateData->CacheSection.AllSectionCount ++;\r
+ if ((Authentication & EFI_AUTH_STATUS_NOT_TESTED) == 0) {\r
+ //\r
+ // Update cache section data.\r
+ //\r
+ if (PrivateData->CacheSection.AllSectionCount < CACHE_SETION_MAX_NUMBER) {\r
+ PrivateData->CacheSection.AllSectionCount ++;\r
+ }\r
+ PrivateData->CacheSection.Section [PrivateData->CacheSection.SectionIndex] = Section;\r
+ PrivateData->CacheSection.SectionData [PrivateData->CacheSection.SectionIndex] = PpiOutput;\r
+ PrivateData->CacheSection.SectionSize [PrivateData->CacheSection.SectionIndex] = PpiOutputSize;\r
+ PrivateData->CacheSection.AuthenticationStatus [PrivateData->CacheSection.SectionIndex] = Authentication;\r
+ PrivateData->CacheSection.SectionIndex = (PrivateData->CacheSection.SectionIndex + 1)%CACHE_SETION_MAX_NUMBER;\r
}\r
- PrivateData->CacheSection.Section [PrivateData->CacheSection.SectionIndex] = Section;\r
- PrivateData->CacheSection.SectionData [PrivateData->CacheSection.SectionIndex] = PpiOutput;\r
- PrivateData->CacheSection.SectionSize [PrivateData->CacheSection.SectionIndex] = PpiOutputSize;\r
- PrivateData->CacheSection.AuthenticationStatus [PrivateData->CacheSection.SectionIndex] = Authentication;\r
- PrivateData->CacheSection.SectionIndex = (PrivateData->CacheSection.SectionIndex + 1)%CACHE_SETION_MAX_NUMBER;\r
\r
TempAuthenticationStatus = 0;\r
Status = ProcessSection (\r
return CoreHandle->FvPpi->GetVolumeInfo (CoreHandle->FvPpi, VolumeHandle, VolumeInfo);\r
}\r
\r
+/**\r
+ Find USED_SIZE FV_EXT_TYPE entry in FV extension header and get the FV used size.\r
+\r
+ @param[in] FvHeader Pointer to FV header.\r
+ @param[out] FvUsedSize Pointer to FV used size returned,\r
+ only valid if USED_SIZE FV_EXT_TYPE entry is found.\r
+ @param[out] EraseByte Pointer to erase byte returned,\r
+ only valid if USED_SIZE FV_EXT_TYPE entry is found.\r
+\r
+ @retval TRUE USED_SIZE FV_EXT_TYPE entry is found,\r
+ FV used size and erase byte are returned.\r
+ @retval FALSE No USED_SIZE FV_EXT_TYPE entry found.\r
+\r
+**/\r
+BOOLEAN\r
+GetFvUsedSize (\r
+ IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader,\r
+ OUT UINT32 *FvUsedSize,\r
+ OUT UINT8 *EraseByte\r
+ )\r
+{\r
+ UINT16 ExtHeaderOffset;\r
+ EFI_FIRMWARE_VOLUME_EXT_HEADER *ExtHeader;\r
+ EFI_FIRMWARE_VOLUME_EXT_ENTRY *ExtEntryList;\r
+ EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE *ExtEntryUsedSize;\r
+\r
+ ExtHeaderOffset = ReadUnaligned16 (&FvHeader->ExtHeaderOffset);\r
+ if (ExtHeaderOffset != 0) {\r
+ ExtHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER *) ((UINT8 *) FvHeader + ExtHeaderOffset);\r
+ ExtEntryList = (EFI_FIRMWARE_VOLUME_EXT_ENTRY *) (ExtHeader + 1);\r
+ while ((UINTN) ExtEntryList < ((UINTN) ExtHeader + ReadUnaligned32 (&ExtHeader->ExtHeaderSize))) {\r
+ if (ReadUnaligned16 (&ExtEntryList->ExtEntryType) == EFI_FV_EXT_TYPE_USED_SIZE_TYPE) {\r
+ //\r
+ // USED_SIZE FV_EXT_TYPE entry is found.\r
+ //\r
+ ExtEntryUsedSize = (EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE *) ExtEntryList;\r
+ *FvUsedSize = ReadUnaligned32 (&ExtEntryUsedSize->UsedSize);\r
+ if ((ReadUnaligned32 (&FvHeader->Attributes) & EFI_FVB2_ERASE_POLARITY) != 0) {\r
+ *EraseByte = 0xFF;\r
+ } else {\r
+ *EraseByte = 0;\r
+ }\r
+ DEBUG ((\r
+ DEBUG_INFO,\r
+ "FV at 0x%x has 0x%x used size, and erase byte is 0x%02x\n",\r
+ FvHeader,\r
+ *FvUsedSize,\r
+ *EraseByte\r
+ ));\r
+ return TRUE;\r
+ }\r
+ ExtEntryList = (EFI_FIRMWARE_VOLUME_EXT_ENTRY *)\r
+ ((UINT8 *) ExtEntryList + ReadUnaligned16 (&ExtEntryList->ExtEntrySize));\r
+ }\r
+ }\r
+\r
+ //\r
+ // No USED_SIZE FV_EXT_TYPE entry found.\r
+ //\r
+ return FALSE;\r
+}\r
+\r
/**\r
Get Fv image from the FV type file, then install FV INFO(2) ppi, Build FV hob.\r
\r
EFI_FV_FILE_INFO FileInfo;\r
UINT64 FvLength;\r
UINT32 AuthenticationStatus;\r
- \r
+ UINT32 FvUsedSize;\r
+ UINT8 EraseByte;\r
+\r
//\r
// Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already\r
// been extracted.\r
FvAlignment = 8;\r
}\r
\r
+ DEBUG ((\r
+ DEBUG_INFO,\r
+ "%a() FV at 0x%x, FvAlignment required is 0x%x\n",\r
+ __FUNCTION__,\r
+ FvHeader,\r
+ FvAlignment\r
+ ));\r
+\r
//\r
- // Check FvImage\r
+ // Check FvImage alignment.\r
//\r
if ((UINTN) FvHeader % FvAlignment != 0) {\r
FvLength = ReadUnaligned64 (&FvHeader->FvLength);\r
if (NewFvBuffer == NULL) {\r
return EFI_OUT_OF_RESOURCES;\r
}\r
- CopyMem (NewFvBuffer, FvHeader, (UINTN) FvLength);\r
+ if (GetFvUsedSize (FvHeader, &FvUsedSize, &EraseByte)) {\r
+ //\r
+ // Copy the used bytes and fill the rest with the erase value.\r
+ //\r
+ CopyMem (NewFvBuffer, FvHeader, (UINTN) FvUsedSize);\r
+ SetMem (\r
+ (UINT8 *) NewFvBuffer + FvUsedSize,\r
+ (UINTN) (FvLength - FvUsedSize),\r
+ EraseByte\r
+ );\r
+ } else {\r
+ CopyMem (NewFvBuffer, FvHeader, (UINTN) FvLength);\r
+ }\r
FvHeader = (EFI_FIRMWARE_VOLUME_HEADER*) NewFvBuffer;\r
}\r
}\r
&FileInfo.FileName\r
);\r
\r
+ //\r
+ // Build FV3 HOB with authentication status to be propagated to DXE.\r
+ //\r
+ BuildFv3Hob (\r
+ (EFI_PHYSICAL_ADDRESS) (UINTN) FvHeader,\r
+ FvHeader->FvLength,\r
+ AuthenticationStatus,\r
+ TRUE,\r
+ &ParentFvImageInfo.FvName,\r
+ &FileInfo.FileName\r
+ );\r
+\r
return EFI_SUCCESS;\r
}\r
\r