]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/CCode/Source/Common/FvLib.c
Retiring the ANT/JAVA build and removing the older EDK II packages that required...
[mirror_edk2.git] / Tools / CCode / Source / Common / FvLib.c
diff --git a/Tools/CCode/Source/Common/FvLib.c b/Tools/CCode/Source/Common/FvLib.c
deleted file mode 100644 (file)
index f526a30..0000000
+++ /dev/null
@@ -1,782 +0,0 @@
-/*++\r
-\r
-Copyright (c) 2004 - 2006, Intel Corporation                                                         \r
-All rights reserved. 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
-http://opensource.org/licenses/bsd-license.php                                            \r
-                                                                                          \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
-\r
-Module Name:\r
-\r
-  FvLib.c\r
-\r
-Abstract:\r
-\r
-  These functions assist in parsing and manipulating a Firmware Volume.\r
-\r
---*/\r
-\r
-//\r
-// Include files\r
-//\r
-#include "FvLib.h"\r
-#include "CommonLib.h"\r
-#include "EfiUtilityMsgs.h"\r
-\r
-//\r
-// Module global variables\r
-//\r
-EFI_FIRMWARE_VOLUME_HEADER  *mFvHeader  = NULL;\r
-UINT32                      mFvLength   = 0;\r
-\r
-//\r
-// External function implementations\r
-//\r
-EFI_STATUS\r
-InitializeFvLib (\r
-  IN VOID                         *Fv,\r
-  IN UINT32                       FvLength\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  This initializes the FV lib with a pointer to the FV and length.  It does not\r
-  verify the FV in any way.\r
-\r
-Arguments:\r
-\r
-  Fv            Buffer containing the FV.\r
-  FvLength      Length of the FV\r
-    \r
-Returns:\r
\r
-  EFI_SUCCESS             Function Completed successfully.\r
-  EFI_INVALID_PARAMETER   A required parameter was NULL.\r
-\r
---*/\r
-{\r
-  //\r
-  // Verify input arguments\r
-  //\r
-  if (Fv == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  mFvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) Fv;\r
-  mFvLength = FvLength;\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-GetFvHeader (\r
-  OUT EFI_FIRMWARE_VOLUME_HEADER  **FvHeader,\r
-  OUT UINT32                      *FvLength\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  This function returns a pointer to the current FV and the size.\r
-\r
-Arguments:\r
-\r
-  FvHeader      Pointer to the FV buffer.\r
-  FvLength      Length of the FV\r
-    \r
-Returns:\r
\r
-  EFI_SUCCESS             Function Completed successfully.\r
-  EFI_INVALID_PARAMETER   A required parameter was NULL.\r
-  EFI_ABORTED             The library needs to be initialized.\r
-\r
---*/\r
-{\r
-  //\r
-  // Verify library has been initialized.\r
-  //\r
-  if (mFvHeader == NULL || mFvLength == 0) {\r
-    return EFI_ABORTED;\r
-  }\r
-  //\r
-  // Verify input arguments\r
-  //\r
-  if (FvHeader == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  *FvHeader = mFvHeader;\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-GetNextFile (\r
-  IN EFI_FFS_FILE_HEADER          *CurrentFile,\r
-  OUT EFI_FFS_FILE_HEADER         **NextFile\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  This function returns the next file.  If the current file is NULL, it returns\r
-  the first file in the FV.  If the function returns EFI_SUCCESS and the file \r
-  pointer is NULL, then there are no more files in the FV.\r
-\r
-Arguments:\r
-\r
-  CurrentFile   Pointer to the current file, must be within the current FV.\r
-  NextFile      Pointer to the next file in the FV.\r
-    \r
-Returns:\r
\r
-  EFI_SUCCESS             Function completed successfully.\r
-  EFI_INVALID_PARAMETER   A required parameter was NULL or is out of range.\r
-  EFI_ABORTED             The library needs to be initialized.\r
-\r
---*/\r
-{\r
-  EFI_STATUS  Status;\r
-\r
-  //\r
-  // Verify library has been initialized.\r
-  //\r
-  if (mFvHeader == NULL || mFvLength == 0) {\r
-    return EFI_ABORTED;\r
-  }\r
-  //\r
-  // Verify input arguments\r
-  //\r
-  if (NextFile == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-  //\r
-  // Verify FV header\r
-  //\r
-  Status = VerifyFv (mFvHeader);\r
-  if (EFI_ERROR (Status)) {\r
-    return EFI_ABORTED;\r
-  }\r
-  //\r
-  // Get first file\r
-  //\r
-  if (CurrentFile == NULL) {\r
-    CurrentFile = (EFI_FFS_FILE_HEADER *) ((UINTN) mFvHeader + mFvHeader->HeaderLength);\r
-\r
-    //\r
-    // Verify file is valid\r
-    //\r
-    Status = VerifyFfsFile (CurrentFile);\r
-    if (EFI_ERROR (Status)) {\r
-      //\r
-      // no files in this FV\r
-      //\r
-      *NextFile = NULL;\r
-      return EFI_SUCCESS;\r
-    } else {\r
-      //\r
-      // Verify file is in this FV.\r
-      //\r
-      if ((UINTN) CurrentFile + GetLength (CurrentFile->Size) > (UINTN) mFvHeader + mFvLength) {\r
-        *NextFile = NULL;\r
-        return EFI_SUCCESS;\r
-      }\r
-\r
-      *NextFile = CurrentFile;\r
-      return EFI_SUCCESS;\r
-    }\r
-  }\r
-  //\r
-  // Verify current file is in range\r
-  //\r
-  if (((UINTN) CurrentFile < (UINTN) mFvHeader + mFvHeader->HeaderLength) ||\r
-      ((UINTN) CurrentFile + GetLength (CurrentFile->Size) > (UINTN) mFvHeader + mFvLength)\r
-     ) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-  //\r
-  // Get next file, compensate for 8 byte alignment if necessary.\r
-  //\r
-  *NextFile = (EFI_FFS_FILE_HEADER *) (((UINTN) CurrentFile + GetLength (CurrentFile->Size) + 0x07) & (-1 << 3));\r
-\r
-  //\r
-  // Verify file is in this FV.\r
-  //\r
-  if (((UINTN) *NextFile + sizeof (EFI_FFS_FILE_HEADER) >= (UINTN) mFvHeader + mFvLength) ||\r
-      ((UINTN) *NextFile + GetLength ((*NextFile)->Size) > (UINTN) mFvHeader + mFvLength)\r
-     ) {\r
-    *NextFile = NULL;\r
-    return EFI_SUCCESS;\r
-  }\r
-  //\r
-  // Verify file is valid\r
-  //\r
-  Status = VerifyFfsFile (*NextFile);\r
-  if (EFI_ERROR (Status)) {\r
-    //\r
-    // no more files in this FV\r
-    //\r
-    *NextFile = NULL;\r
-    return EFI_SUCCESS;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-GetFileByName (\r
-  IN EFI_GUID                     *FileName,\r
-  OUT EFI_FFS_FILE_HEADER         **File\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Find a file by name.  The function will return NULL if the file is not found.\r
-\r
-Arguments:\r
-\r
-  FileName    The GUID file name of the file to search for.\r
-  File        Return pointer.  In the case of an error, contents are undefined.\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS             The function completed successfully.\r
-  EFI_ABORTED             An error was encountered.\r
-  EFI_INVALID_PARAMETER   One of the parameters was NULL.\r
-\r
---*/\r
-{\r
-  EFI_FFS_FILE_HEADER *CurrentFile;\r
-  EFI_STATUS          Status;\r
-\r
-  //\r
-  // Verify library has been initialized.\r
-  //\r
-  if (mFvHeader == NULL || mFvLength == 0) {\r
-    return EFI_ABORTED;\r
-  }\r
-  //\r
-  // Verify input parameters\r
-  //\r
-  if (FileName == NULL || File == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-  //\r
-  // Verify FV header\r
-  //\r
-  Status = VerifyFv (mFvHeader);\r
-  if (EFI_ERROR (Status)) {\r
-    return EFI_ABORTED;\r
-  }\r
-  //\r
-  // Get the first file\r
-  //\r
-  Status = GetNextFile (NULL, &CurrentFile);\r
-  if (EFI_ERROR (Status)) {\r
-    Error (NULL, 0, 0, "error parsing the FV", NULL);\r
-    return EFI_ABORTED;\r
-  }\r
-  //\r
-  // Loop as long as we have a valid file\r
-  //\r
-  while (CurrentFile) {\r
-    if (!CompareGuid (&CurrentFile->Name, FileName)) {\r
-      *File = CurrentFile;\r
-      return EFI_SUCCESS;\r
-    }\r
-\r
-    Status = GetNextFile (CurrentFile, &CurrentFile);\r
-    if (EFI_ERROR (Status)) {\r
-      Error (NULL, 0, 0, "error parsing the FV", NULL);\r
-      return EFI_ABORTED;\r
-    }\r
-  }\r
-  //\r
-  // File not found in this FV.\r
-  //\r
-  *File = NULL;\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-GetFileByType (\r
-  IN EFI_FV_FILETYPE              FileType,\r
-  IN UINTN                        Instance,\r
-  OUT EFI_FFS_FILE_HEADER         **File\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Find a file by type and instance.  An instance of 1 is the first instance.\r
-  The function will return NULL if a matching file cannot be found.\r
-  File type EFI_FV_FILETYPE_ALL means any file type is valid.\r
-\r
-Arguments:\r
-\r
-  FileType    Type of file to search for.\r
-  Instance    Instace of the file type to return.\r
-  File        Return pointer.  In the case of an error, contents are undefined.\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS             The function completed successfully.\r
-  EFI_ABORTED             An error was encountered.\r
-  EFI_INVALID_PARAMETER   One of the parameters was NULL.\r
-\r
---*/\r
-{\r
-  EFI_FFS_FILE_HEADER *CurrentFile;\r
-  EFI_STATUS          Status;\r
-  UINTN               FileCount;\r
-\r
-  //\r
-  // Verify library has been initialized.\r
-  //\r
-  if (mFvHeader == NULL || mFvLength == 0) {\r
-    return EFI_ABORTED;\r
-  }\r
-  //\r
-  // Verify input parameters\r
-  //\r
-  if (File == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-  //\r
-  // Verify FV header\r
-  //\r
-  Status = VerifyFv (mFvHeader);\r
-  if (EFI_ERROR (Status)) {\r
-    return EFI_ABORTED;\r
-  }\r
-  //\r
-  // Initialize the number of matching files found.\r
-  //\r
-  FileCount = 0;\r
-\r
-  //\r
-  // Get the first file\r
-  //\r
-  Status = GetNextFile (NULL, &CurrentFile);\r
-  if (EFI_ERROR (Status)) {\r
-    Error (NULL, 0, 0, "error parsing FV", NULL);\r
-    return EFI_ABORTED;\r
-  }\r
-  //\r
-  // Loop as long as we have a valid file\r
-  //\r
-  while (CurrentFile) {\r
-    if (FileType == EFI_FV_FILETYPE_ALL || CurrentFile->Type == FileType) {\r
-      FileCount++;\r
-    }\r
-\r
-    if (FileCount == Instance) {\r
-      *File = CurrentFile;\r
-      return EFI_SUCCESS;\r
-    }\r
-\r
-    Status = GetNextFile (CurrentFile, &CurrentFile);\r
-    if (EFI_ERROR (Status)) {\r
-      Error (NULL, 0, 0, "error parsing the FV", NULL);\r
-      return EFI_ABORTED;\r
-    }\r
-  }\r
-\r
-  *File = NULL;\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-GetSectionByType (\r
-  IN EFI_FFS_FILE_HEADER          *File,\r
-  IN EFI_SECTION_TYPE             SectionType,\r
-  IN UINTN                        Instance,\r
-  OUT EFI_FILE_SECTION_POINTER    *Section\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Find a section in a file by type and instance.  An instance of 1 is the first \r
-  instance.  The function will return NULL if a matching section cannot be found.\r
-  The function will not handle encapsulating sections.\r
-\r
-Arguments:\r
-\r
-  File        The file to search.\r
-  SectionType Type of file to search for.\r
-  Instance    Instace of the section to return.\r
-  Section     Return pointer.  In the case of an error, contents are undefined.\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS             The function completed successfully.\r
-  EFI_ABORTED             An error was encountered.\r
-  EFI_INVALID_PARAMETER   One of the parameters was NULL.\r
-  EFI_NOT_FOUND           No found.\r
---*/\r
-{\r
-  EFI_FILE_SECTION_POINTER  CurrentSection;\r
-  EFI_STATUS                Status;\r
-  UINTN                     SectionCount;\r
-\r
-  //\r
-  // Verify input parameters\r
-  //\r
-  if (File == NULL || Instance == 0) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-  //\r
-  // Verify FFS header\r
-  //\r
-  Status = VerifyFfsFile (File);\r
-  if (EFI_ERROR (Status)) {\r
-    Error (NULL, 0, 0, "invalid FFS file", NULL);\r
-    return EFI_ABORTED;\r
-  }\r
-  //\r
-  // Initialize the number of matching sections found.\r
-  //\r
-  SectionCount = 0;\r
-\r
-  //\r
-  // Get the first section\r
-  //\r
-  CurrentSection.CommonHeader = (EFI_COMMON_SECTION_HEADER *) ((UINTN) File + sizeof (EFI_FFS_FILE_HEADER));\r
-\r
-  //\r
-  // Loop as long as we have a valid file\r
-  //\r
-  while ((UINTN) CurrentSection.CommonHeader < (UINTN) File + GetLength (File->Size)) {\r
-    if (CurrentSection.CommonHeader->Type == SectionType) {\r
-      SectionCount++;\r
-    }\r
-\r
-    if (SectionCount == Instance) {\r
-      *Section = CurrentSection;\r
-      return EFI_SUCCESS;\r
-    }\r
-    //\r
-    // Find next section (including compensating for alignment issues.\r
-    //\r
-    CurrentSection.CommonHeader = (EFI_COMMON_SECTION_HEADER *) ((((UINTN) CurrentSection.CommonHeader) + GetLength (CurrentSection.CommonHeader->Size) + 0x03) & (-1 << 2));\r
-  }\r
-  //\r
-  // Section not found\r
-  //\r
-  (*Section).Code16Section = NULL;\r
-  return EFI_NOT_FOUND;\r
-}\r
-//\r
-// will not parse compressed sections\r
-//\r
-EFI_STATUS\r
-VerifyFv (\r
-  IN EFI_FIRMWARE_VOLUME_HEADER   *FvHeader\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Verify the current pointer points to a valid FV header.\r
-\r
-Arguments:\r
-\r
-  FvHeader     Pointer to an alleged FV file.\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS             The FV header is valid.\r
-  EFI_VOLUME_CORRUPTED    The FV header is not valid.\r
-  EFI_INVALID_PARAMETER   A required parameter was NULL.\r
-  EFI_ABORTED             Operation aborted.\r
-\r
---*/\r
-{\r
-  UINT16  Checksum;\r
-\r
-  //\r
-  // Verify input parameters\r
-  //\r
-  if (FvHeader == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  if (FvHeader->Signature != EFI_FVH_SIGNATURE) {\r
-    Error (NULL, 0, 0, "invalid FV header signature", NULL);\r
-    return EFI_VOLUME_CORRUPTED;\r
-  }\r
-  //\r
-  // Verify header checksum\r
-  //\r
-  Checksum = CalculateSum16 ((UINT16 *) FvHeader, FvHeader->HeaderLength / sizeof (UINT16));\r
-\r
-  if (Checksum != 0) {\r
-    Error (NULL, 0, 0, "invalid FV header checksum", NULL);\r
-    return EFI_ABORTED;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-EFI_STATUS\r
-VerifyFfsFile (\r
-  IN EFI_FFS_FILE_HEADER  *FfsHeader\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Verify the current pointer points to a FFS file header.\r
-\r
-Arguments:\r
-\r
-  FfsHeader     Pointer to an alleged FFS file.\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS           The Ffs header is valid.\r
-  EFI_NOT_FOUND         This "file" is the beginning of free space.\r
-  EFI_VOLUME_CORRUPTED  The Ffs header is not valid.\r
-  EFI_ABORTED           The erase polarity is not known.\r
-\r
---*/\r
-{\r
-  BOOLEAN             ErasePolarity;\r
-  EFI_STATUS          Status;\r
-  EFI_FFS_FILE_HEADER BlankHeader;\r
-  UINT8               Checksum;\r
-  UINT32              FileLength;\r
-  UINT32              OccupiedFileLength;\r
-  EFI_FFS_FILE_TAIL   *Tail;\r
-  UINT8               SavedChecksum;\r
-  UINT8               SavedState;\r
-  UINT8               FileGuidString[80];\r
-  UINT32              TailSize;\r
-  //\r
-  // Verify library has been initialized.\r
-  //\r
-  if (mFvHeader == NULL || mFvLength == 0) {\r
-    return EFI_ABORTED;\r
-  }\r
-  //\r
-  // Verify FV header\r
-  //\r
-  Status = VerifyFv (mFvHeader);\r
-  if (EFI_ERROR (Status)) {\r
-    return EFI_ABORTED;\r
-  }\r
-  //\r
-  // Get the erase polarity.\r
-  //\r
-  Status = GetErasePolarity (&ErasePolarity);\r
-  if (EFI_ERROR (Status)) {\r
-    return EFI_ABORTED;\r
-  }\r
-  //\r
-  // Check if we have free space\r
-  //\r
-  if (ErasePolarity) {\r
-    memset (&BlankHeader, -1, sizeof (EFI_FFS_FILE_HEADER));\r
-  } else {\r
-    memset (&BlankHeader, 0, sizeof (EFI_FFS_FILE_HEADER));\r
-  }\r
-\r
-  if (memcmp (&BlankHeader, FfsHeader, sizeof (EFI_FFS_FILE_HEADER)) == 0) {\r
-    return EFI_NOT_FOUND;\r
-  }\r
-  //\r
-  // Convert the GUID to a string so we can at least report which file\r
-  // if we find an error.\r
-  //\r
-  PrintGuidToBuffer (&FfsHeader->Name, FileGuidString, sizeof (FileGuidString), TRUE);\r
-  if (FfsHeader->Attributes & FFS_ATTRIB_TAIL_PRESENT) {\r
-    TailSize = sizeof (EFI_FFS_FILE_TAIL);\r
-  } else {\r
-    TailSize = 0;\r
-  }\r
-  //\r
-  // Verify file header checksum\r
-  //\r
-  SavedState = FfsHeader->State;\r
-  FfsHeader->State = 0;\r
-  SavedChecksum = FfsHeader->IntegrityCheck.Checksum.File;\r
-  FfsHeader->IntegrityCheck.Checksum.File = 0;\r
-  Checksum = CalculateSum8 ((UINT8 *) FfsHeader, sizeof (EFI_FFS_FILE_HEADER));\r
-  FfsHeader->State = SavedState;\r
-  FfsHeader->IntegrityCheck.Checksum.File = SavedChecksum;\r
-  if (Checksum != 0) {\r
-    Error (NULL, 0, 0, FileGuidString, "invalid FFS file header checksum");\r
-    return EFI_ABORTED;\r
-  }\r
-  //\r
-  // Verify file checksum\r
-  //\r
-  if (FfsHeader->Attributes & FFS_ATTRIB_CHECKSUM) {\r
-    //\r
-    // Verify file data checksum\r
-    //\r
-    FileLength          = GetLength (FfsHeader->Size);\r
-    OccupiedFileLength  = (FileLength + 0x07) & (-1 << 3);\r
-    Checksum            = CalculateSum8 ((UINT8 *) FfsHeader, FileLength - TailSize);\r
-    Checksum            = (UINT8) (Checksum - FfsHeader->State);\r
-    if (Checksum != 0) {\r
-      Error (NULL, 0, 0, FileGuidString, "invalid FFS file checksum");\r
-      return EFI_ABORTED;\r
-    }\r
-  } else {\r
-    //\r
-    // File does not have a checksum\r
-    // Verify contents are 0x5A as spec'd\r
-    //\r
-    if (FfsHeader->IntegrityCheck.Checksum.File != FFS_FIXED_CHECKSUM) {\r
-      Error (NULL, 0, 0, FileGuidString, "invalid fixed FFS file header checksum");\r
-      return EFI_ABORTED;\r
-    }\r
-  }\r
-  //\r
-  // Check if the tail is present and verify it if it is.\r
-  //\r
-  if (FfsHeader->Attributes & FFS_ATTRIB_TAIL_PRESENT) {\r
-    //\r
-    // Verify tail is complement of integrity check field in the header.\r
-    //\r
-    Tail = (EFI_FFS_FILE_TAIL *) ((UINTN) FfsHeader + GetLength (FfsHeader->Size) - sizeof (EFI_FFS_FILE_TAIL));\r
-    if (FfsHeader->IntegrityCheck.TailReference != (EFI_FFS_FILE_TAIL)~(*Tail)) {\r
-      Error (NULL, 0, 0, FileGuidString, "invalid FFS file tail");\r
-      return EFI_ABORTED;\r
-    }\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-UINT32\r
-GetLength (\r
-  UINT8     *ThreeByteLength\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  Converts a three byte length value into a UINT32.\r
-\r
-Arguments:\r
-\r
-  ThreeByteLength   Pointer to the first of the 3 byte length.\r
-\r
-Returns:\r
-\r
-  UINT32      Size of the section\r
-\r
---*/\r
-{\r
-  UINT32  Length;\r
-\r
-  if (ThreeByteLength == NULL) {\r
-    return 0;\r
-  }\r
-\r
-  Length  = *((UINT32 *) ThreeByteLength);\r
-  Length  = Length & 0x00FFFFFF;\r
-\r
-  return Length;\r
-}\r
-\r
-EFI_STATUS\r
-GetErasePolarity (\r
-  OUT BOOLEAN   *ErasePolarity\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  This function returns with the FV erase polarity.  If the erase polarity\r
-  for a bit is 1, the function return TRUE.\r
-\r
-Arguments:\r
-\r
-  ErasePolarity   A pointer to the erase polarity.\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS              The function completed successfully.\r
-  EFI_INVALID_PARAMETER    One of the input parameters was invalid.\r
-  EFI_ABORTED              Operation aborted.\r
-  \r
---*/\r
-{\r
-  EFI_STATUS  Status;\r
-\r
-  //\r
-  // Verify library has been initialized.\r
-  //\r
-  if (mFvHeader == NULL || mFvLength == 0) {\r
-    return EFI_ABORTED;\r
-  }\r
-  //\r
-  // Verify FV header\r
-  //\r
-  Status = VerifyFv (mFvHeader);\r
-  if (EFI_ERROR (Status)) {\r
-    return EFI_ABORTED;\r
-  }\r
-  //\r
-  // Verify input parameters.\r
-  //\r
-  if (ErasePolarity == NULL) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  if (mFvHeader->Attributes & EFI_FVB_ERASE_POLARITY) {\r
-    *ErasePolarity = TRUE;\r
-  } else {\r
-    *ErasePolarity = FALSE;\r
-  }\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-UINT8\r
-GetFileState (\r
-  IN BOOLEAN              ErasePolarity,\r
-  IN EFI_FFS_FILE_HEADER  *FfsHeader\r
-  )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  This function returns a the highest state bit in the FFS that is set.\r
-  It in no way validate the FFS file.\r
-\r
-Arguments:\r
-  \r
-  ErasePolarity The erase polarity for the file state bits.\r
-  FfsHeader     Pointer to a FFS file.\r
-\r
-Returns:\r
-\r
-  UINT8   The hightest set state of the file.\r
-\r
---*/\r
-{\r
-  UINT8 FileState;\r
-  UINT8 HighestBit;\r
-\r
-  FileState = FfsHeader->State;\r
-\r
-  if (ErasePolarity) {\r
-    FileState = (UINT8)~FileState;\r
-  }\r
-\r
-  HighestBit = 0x80;\r
-  while (HighestBit != 0 && (HighestBit & FileState) == 0) {\r
-    HighestBit >>= 1;\r
-  }\r
-\r
-  return HighestBit;\r
-}\r