/* Searches the FFS file for a section by its type */
EFI_STATUS FvBufFindSectionByType(IN VOID *FfsFile, IN UINT8 Type, OUT VOID **Section)
/* Searches the FFS file for a section by its type */
EFI_STATUS FvBufFindSectionByType(IN VOID *FfsFile, IN UINT8 Type, OUT VOID **Section)
{
  EFI_STATUS Status;
  UINTN Key;
  VOID*                      SectionStart;
  UINTN                      TotalSectionsSize;
  EFI_COMMON_SECTION_HEADER* NextSection;
  SectionStart = (VOID*)((UINTN)FfsFile + FvBufGetFfsHeaderSize(FfsFile));
  TotalSectionsSize =
    FvBufGetFfsFileSize ((EFI_FFS_FILE_HEADER*)FfsFile) -
    FvBufGetFfsHeaderSize(FfsFile);
  Key = 0;
  while (TRUE) {
    Status = FvBufFindNextSection (
               SectionStart,
               TotalSectionsSize,
               &Key,
               (VOID **)&NextSection
               );
    if (EFI_ERROR (Status)) {
      return Status;
    }
    if (Type == NextSection->Type) {
      if (Section != NULL) {
        *Section = NextSection;
      }
      return EFI_SUCCESS;
    }
  }
  return EFI_NOT_FOUND;
}