16#define GET_OCCUPIED_SIZE(ActualSize, Alignment) \
17 (ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1))
30 IN UINT8 ErasePolarity,
34 EFI_FFS_FILE_STATE FileState;
35 EFI_FFS_FILE_STATE HighestBit;
37 FileState = FfsHeader->State;
39 if (ErasePolarity != 0) {
40 FileState = (EFI_FFS_FILE_STATE) ~FileState;
44 while (HighestBit != 0 && (HighestBit & FileState) == 0) {
69 ptr = (UINT8 *)FileHeader;
72 for (Index = 0; Index < Size - 3; Index += 4) {
73 Sum = (UINT8)(Sum + ptr[Index]);
74 Sum = (UINT8)(Sum + ptr[Index + 1]);
75 Sum = (UINT8)(Sum + ptr[Index + 2]);
76 Sum = (UINT8)(Sum + ptr[Index + 3]);
79 for ( ; Index < Size; Index++) {
80 Sum = (UINT8)(Sum + ptr[Index]);
86 Sum = (UINT8)(Sum - FileHeader->State);
90 Sum = (UINT8)(Sum - FileHeader->IntegrityCheck.Checksum.File);
113 IN EFI_FV_FILETYPE SearchType,
122 UINT32 FileOccupiedSize;
128 FvLength = FwVolHeader->FvLength;
129 if (FwVolHeader->Attributes & EFI_FVB2_ERASE_POLARITY) {
139 if (*FileHeader ==
NULL) {
140 if (FwVolHeader->ExtHeaderOffset != 0) {
142 FwVolHeader->ExtHeaderOffset);
148 FwVolHeader->HeaderLength);
153 (
UINTN)FfsFileHeader -
162 FileLength = IS_FFS_FILE2 (*FileHeader) ?
164 FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);
168 FileOffset = (UINT32)((UINT8 *)FfsFileHeader - (UINT8 *)FwVolHeader);
174 FileState =
GetFileState (ErasePolarity, FfsFileHeader);
177 case EFI_FILE_HEADER_INVALID:
178 if (IS_FFS_FILE2 (FfsFileHeader)) {
188 case EFI_FILE_DATA_VALID:
189 case EFI_FILE_MARKED_FOR_UPDATE:
191 FileLength = IS_FFS_FILE2 (FfsFileHeader) ?
192 FFS_FILE2_SIZE (FfsFileHeader) :
FFS_FILE_SIZE (FfsFileHeader);
193 FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);
196 *FileHeader = FfsFileHeader;
201 FileOffset += FileOccupiedSize;
204 return EFI_NOT_FOUND;
209 case EFI_FILE_DELETED:
210 FileLength = IS_FFS_FILE2 (FfsFileHeader) ?
211 FFS_FILE2_SIZE (FfsFileHeader) :
FFS_FILE_SIZE (FfsFileHeader);
212 FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);
213 FileOffset += FileOccupiedSize;
218 return EFI_NOT_FOUND;
222 return EFI_NOT_FOUND;
243 IN EFI_SECTION_TYPE SectionType,
257 EndOfSections = EndOfSection + SizeOfSections;
259 if (EndOfSection == EndOfSections) {
263 CurrentAddress = EndOfSection;
267 Size = IS_SECTION2 (Section) ? SECTION2_SIZE (Section) :
SECTION_SIZE (Section);
268 if (Size <
sizeof (*Section)) {
269 return EFI_VOLUME_CORRUPTED;
272 EndOfSection = CurrentAddress + Size;
273 if (EndOfSection > EndOfSections) {
274 return EFI_VOLUME_CORRUPTED;
277 Size = GET_OCCUPIED_SIZE (Size, 4);
282 if (Section->Type == SectionType) {
283 *FoundSection = Section;
288 return EFI_NOT_FOUND;
306 IN EFI_SECTION_TYPE SectionType,
320 if (IS_FFS_FILE2 (FfsFileHeader)) {
353 IN EFI_SECTION_TYPE SectionType,
355 IN OUT VOID **SectionData,
361 UINT32 SectionLength;
369 if (IS_FFS_FILE2 (FfsFileHeader)) {
379 while (ParsedLength < FileSize) {
380 if (Section->Type == SectionType) {
381 if (IS_SECTION2 (Section)) {
385 *SectionData = (VOID *)(Section + 1);
397 SectionLength = IS_SECTION2 (Section) ? SECTION2_SIZE (Section) :
SECTION_SIZE (Section);
398 SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4);
400 ParsedLength += SectionLength;
404 return EFI_NOT_FOUND;
EFI_STATUS EFIAPI FfsFindSection(IN EFI_SECTION_TYPE SectionType, IN EFI_FFS_FILE_HEADER *FfsFileHeader, IN OUT EFI_COMMON_SECTION_HEADER **SectionHeader)
EFI_FFS_FILE_STATE GetFileState(IN UINT8 ErasePolarity, IN EFI_FFS_FILE_HEADER *FfsHeader)
EFI_STATUS EFIAPI FfsFindNextFile(IN EFI_FV_FILETYPE SearchType, IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader, IN OUT EFI_FFS_FILE_HEADER **FileHeader)
EFI_STATUS EFIAPI FfsFindSectionData(IN EFI_SECTION_TYPE SectionType, IN EFI_FFS_FILE_HEADER *FfsFileHeader, IN OUT VOID **SectionData, IN OUT UINTN *SectionDataSize)
EFI_STATUS EFIAPI FindFfsSectionInSections(IN VOID *Sections, IN UINTN SizeOfSections, IN EFI_SECTION_TYPE SectionType, OUT EFI_COMMON_SECTION_HEADER **FoundSection)
UINT8 CalculateHeaderChecksum(IN EFI_FFS_FILE_HEADER *FileHeader)
#define ALIGN_VALUE(Value, Alignment)
#define EFI_FV_FILETYPE_ALL
#define FFS_FILE_SIZE(FfsFileHeaderPtr)
#define SECTION_SIZE(SectionHeaderPtr)
UINT64 EFI_PHYSICAL_ADDRESS