]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/GenFv/GenFvInternalLib.c
BaseTools: Various typo
[mirror_edk2.git] / BaseTools / Source / C / GenFv / GenFvInternalLib.c
index 01c862e89a393d74b8e004b4cce661fe22f2b9fa..818c46407beb755c8ad59378b2cc388d69a46de6 100644 (file)
@@ -1,16 +1,16 @@
 /** @file\r
 This file contains the internal functions required to generate a Firmware Volume.\r
 \r
-Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>\r
 Portions Copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR>\r
 Portions Copyright (c) 2016 HP Development Company, L.P.<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
-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
+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
 **/\r
 \r
@@ -34,16 +34,17 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include <Guid/FfsSectionAlignmentPadding.h>\r
 \r
+#include "WinNtInclude.h"\r
 #include "GenFvInternalLib.h"\r
 #include "FvLib.h"\r
 #include "PeCoffLib.h"\r
-#include "WinNtInclude.h"\r
 \r
 #define ARMT_UNCONDITIONAL_JUMP_INSTRUCTION       0xEB000000\r
 #define ARM64_UNCONDITIONAL_JUMP_INSTRUCTION      0x14000000\r
 \r
 BOOLEAN mArm = FALSE;\r
 STATIC UINT32   MaxFfsAlignment = 0;\r
+BOOLEAN VtfFileFlag = FALSE;\r
 \r
 EFI_GUID  mEfiFirmwareVolumeTopFileGuid       = EFI_FFS_VOLUME_TOP_FILE_GUID;\r
 EFI_GUID  mFileGuidArray [MAX_NUMBER_OF_FILES_IN_FV];\r
@@ -52,56 +53,56 @@ EFI_GUID  mDefaultCapsuleGuid                 = {0x3B6686BD, 0x0D76, 0x4030, { 0
 EFI_GUID  mEfiFfsSectionAlignmentPaddingGuid  = EFI_FFS_SECTION_ALIGNMENT_PADDING_GUID;\r
 \r
 CHAR8      *mFvbAttributeName[] = {\r
-  EFI_FVB2_READ_DISABLED_CAP_STRING, \r
-  EFI_FVB2_READ_ENABLED_CAP_STRING,  \r
-  EFI_FVB2_READ_STATUS_STRING,       \r
+  EFI_FVB2_READ_DISABLED_CAP_STRING,\r
+  EFI_FVB2_READ_ENABLED_CAP_STRING,\r
+  EFI_FVB2_READ_STATUS_STRING,\r
   EFI_FVB2_WRITE_DISABLED_CAP_STRING,\r
-  EFI_FVB2_WRITE_ENABLED_CAP_STRING, \r
-  EFI_FVB2_WRITE_STATUS_STRING,      \r
-  EFI_FVB2_LOCK_CAP_STRING,          \r
-  EFI_FVB2_LOCK_STATUS_STRING,       \r
+  EFI_FVB2_WRITE_ENABLED_CAP_STRING,\r
+  EFI_FVB2_WRITE_STATUS_STRING,\r
+  EFI_FVB2_LOCK_CAP_STRING,\r
+  EFI_FVB2_LOCK_STATUS_STRING,\r
   NULL,\r
-  EFI_FVB2_STICKY_WRITE_STRING,      \r
-  EFI_FVB2_MEMORY_MAPPED_STRING,     \r
-  EFI_FVB2_ERASE_POLARITY_STRING,    \r
-  EFI_FVB2_READ_LOCK_CAP_STRING,     \r
-  EFI_FVB2_READ_LOCK_STATUS_STRING,  \r
-  EFI_FVB2_WRITE_LOCK_CAP_STRING,    \r
-  EFI_FVB2_WRITE_LOCK_STATUS_STRING \r
+  EFI_FVB2_STICKY_WRITE_STRING,\r
+  EFI_FVB2_MEMORY_MAPPED_STRING,\r
+  EFI_FVB2_ERASE_POLARITY_STRING,\r
+  EFI_FVB2_READ_LOCK_CAP_STRING,\r
+  EFI_FVB2_READ_LOCK_STATUS_STRING,\r
+  EFI_FVB2_WRITE_LOCK_CAP_STRING,\r
+  EFI_FVB2_WRITE_LOCK_STATUS_STRING\r
 };\r
 \r
 CHAR8      *mFvbAlignmentName[] = {\r
-  EFI_FVB2_ALIGNMENT_1_STRING,   \r
-  EFI_FVB2_ALIGNMENT_2_STRING,   \r
-  EFI_FVB2_ALIGNMENT_4_STRING,   \r
-  EFI_FVB2_ALIGNMENT_8_STRING,   \r
-  EFI_FVB2_ALIGNMENT_16_STRING,  \r
-  EFI_FVB2_ALIGNMENT_32_STRING,  \r
-  EFI_FVB2_ALIGNMENT_64_STRING,  \r
-  EFI_FVB2_ALIGNMENT_128_STRING, \r
-  EFI_FVB2_ALIGNMENT_256_STRING, \r
-  EFI_FVB2_ALIGNMENT_512_STRING, \r
-  EFI_FVB2_ALIGNMENT_1K_STRING,  \r
-  EFI_FVB2_ALIGNMENT_2K_STRING,  \r
-  EFI_FVB2_ALIGNMENT_4K_STRING,  \r
-  EFI_FVB2_ALIGNMENT_8K_STRING,  \r
-  EFI_FVB2_ALIGNMENT_16K_STRING, \r
-  EFI_FVB2_ALIGNMENT_32K_STRING, \r
-  EFI_FVB2_ALIGNMENT_64K_STRING, \r
+  EFI_FVB2_ALIGNMENT_1_STRING,\r
+  EFI_FVB2_ALIGNMENT_2_STRING,\r
+  EFI_FVB2_ALIGNMENT_4_STRING,\r
+  EFI_FVB2_ALIGNMENT_8_STRING,\r
+  EFI_FVB2_ALIGNMENT_16_STRING,\r
+  EFI_FVB2_ALIGNMENT_32_STRING,\r
+  EFI_FVB2_ALIGNMENT_64_STRING,\r
+  EFI_FVB2_ALIGNMENT_128_STRING,\r
+  EFI_FVB2_ALIGNMENT_256_STRING,\r
+  EFI_FVB2_ALIGNMENT_512_STRING,\r
+  EFI_FVB2_ALIGNMENT_1K_STRING,\r
+  EFI_FVB2_ALIGNMENT_2K_STRING,\r
+  EFI_FVB2_ALIGNMENT_4K_STRING,\r
+  EFI_FVB2_ALIGNMENT_8K_STRING,\r
+  EFI_FVB2_ALIGNMENT_16K_STRING,\r
+  EFI_FVB2_ALIGNMENT_32K_STRING,\r
+  EFI_FVB2_ALIGNMENT_64K_STRING,\r
   EFI_FVB2_ALIGNMENT_128K_STRING,\r
   EFI_FVB2_ALIGNMENT_256K_STRING,\r
   EFI_FVB2_ALIGNMENT_512K_STRING,\r
-  EFI_FVB2_ALIGNMENT_1M_STRING,  \r
-  EFI_FVB2_ALIGNMENT_2M_STRING,  \r
-  EFI_FVB2_ALIGNMENT_4M_STRING,  \r
-  EFI_FVB2_ALIGNMENT_8M_STRING,  \r
-  EFI_FVB2_ALIGNMENT_16M_STRING, \r
-  EFI_FVB2_ALIGNMENT_32M_STRING, \r
-  EFI_FVB2_ALIGNMENT_64M_STRING, \r
+  EFI_FVB2_ALIGNMENT_1M_STRING,\r
+  EFI_FVB2_ALIGNMENT_2M_STRING,\r
+  EFI_FVB2_ALIGNMENT_4M_STRING,\r
+  EFI_FVB2_ALIGNMENT_8M_STRING,\r
+  EFI_FVB2_ALIGNMENT_16M_STRING,\r
+  EFI_FVB2_ALIGNMENT_32M_STRING,\r
+  EFI_FVB2_ALIGNMENT_64M_STRING,\r
   EFI_FVB2_ALIGNMENT_128M_STRING,\r
   EFI_FVB2_ALIGNMENT_256M_STRING,\r
   EFI_FVB2_ALIGNMENT_512M_STRING,\r
-  EFI_FVB2_ALIGNMENT_1G_STRING,  \r
+  EFI_FVB2_ALIGNMENT_1G_STRING,\r
   EFI_FVB2_ALIGNMENT_2G_STRING\r
 };\r
 \r
@@ -109,7 +110,7 @@ CHAR8      *mFvbAlignmentName[] = {
 // This data array will be located at the base of the Firmware Volume Header (FVH)\r
 // in the boot block.  It must not exceed 14 bytes of code.  The last 2 bytes\r
 // will be used to keep the FVH checksum consistent.\r
-// This code will be run in response to a starutp IPI for HT-enabled systems.\r
+// This code will be run in response to a startup IPI for HT-enabled systems.\r
 //\r
 #define SIZEOF_STARTUP_DATA_ARRAY 0x10\r
 \r
@@ -257,7 +258,7 @@ Returns:
     //\r
     strcpy (FvInfo->FvName, Value);\r
   }\r
-  \r
+\r
   //\r
   // Read Fv Attribute\r
   //\r
@@ -408,7 +409,7 @@ UpdateFfsFileState (
 Routine Description:\r
 \r
   This function changes the FFS file attributes based on the erase polarity\r
-  of the FV. Update the reserved bits of State to EFI_FVB2_ERASE_POLARITY. \r
+  of the FV. Update the reserved bits of State to EFI_FVB2_ERASE_POLARITY.\r
 \r
 Arguments:\r
 \r
@@ -464,7 +465,7 @@ Returns:
   case 0:\r
     //\r
     // 1 byte alignment\r
-    //if bit 1 have set, 128K byte alignmnet\r
+    //if bit 1 have set, 128K byte alignment\r
     //\r
     if (FfsFile->Attributes & FFS_ATTRIB_DATA_ALIGNMENT2) {\r
       *Alignment = 17;\r
@@ -585,7 +586,7 @@ Arguments:
                   The current offset must be valid.\r
   DataAlignment   The data alignment of the next FFS file.\r
   FvEnd           End of the empty data in FvImage.\r
-  ExtHeader       PI FvExtHeader Optional \r
+  ExtHeader       PI FvExtHeader Optional\r
 \r
 Returns:\r
 \r
@@ -600,7 +601,9 @@ Returns:
   UINTN               PadFileSize;\r
   UINT32              NextFfsHeaderSize;\r
   UINT32              CurFfsHeaderSize;\r
+  UINT32              Index;\r
 \r
+  Index = 0;\r
   CurFfsHeaderSize = sizeof (EFI_FFS_FILE_HEADER);\r
   //\r
   // Verify input parameters.\r
@@ -705,14 +708,27 @@ Returns:
     //\r
     // Copy Fv Extension Header and Set Fv Extension header offset\r
     //\r
+    if (ExtHeader->ExtHeaderSize > sizeof (EFI_FIRMWARE_VOLUME_EXT_HEADER)) {\r
+      for (Index = sizeof (EFI_FIRMWARE_VOLUME_EXT_HEADER); Index < ExtHeader->ExtHeaderSize;) {\r
+        if (((EFI_FIRMWARE_VOLUME_EXT_ENTRY *)((UINT8 *)ExtHeader + Index))-> ExtEntryType == EFI_FV_EXT_TYPE_USED_SIZE_TYPE) {\r
+          if (VtfFileFlag) {\r
+            ((EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE *)((UINT8 *)ExtHeader + Index))->UsedSize = mFvTotalSize;\r
+          } else {\r
+            ((EFI_FIRMWARE_VOLUME_EXT_ENTRY_USED_SIZE_TYPE *)((UINT8 *)ExtHeader + Index))->UsedSize = mFvTakenSize;\r
+          }\r
+          break;\r
+        }\r
+        Index += ((EFI_FIRMWARE_VOLUME_EXT_ENTRY *)((UINT8 *)ExtHeader + Index))-> ExtEntrySize;\r
+      }\r
+    }\r
     memcpy ((UINT8 *)PadFile + CurFfsHeaderSize, ExtHeader, ExtHeader->ExtHeaderSize);\r
     ((EFI_FIRMWARE_VOLUME_HEADER *) FvImage->FileImage)->ExtHeaderOffset = (UINT16) ((UINTN) ((UINT8 *)PadFile + CurFfsHeaderSize) - (UINTN) FvImage->FileImage);\r
-         //\r
-         // Make next file start at QWord Boundry\r
-         //\r
-         while (((UINTN) FvImage->CurrentFilePointer & (EFI_FFS_FILE_HEADER_ALIGNMENT - 1)) != 0) {\r
-           FvImage->CurrentFilePointer++;\r
-         }\r
+    //\r
+    // Make next file start at QWord Boundary\r
+    //\r
+    while (((UINTN) FvImage->CurrentFilePointer & (EFI_FFS_FILE_HEADER_ALIGNMENT - 1)) != 0) {\r
+      FvImage->CurrentFilePointer++;\r
+    }\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -750,7 +766,7 @@ EFI_STATUS
 WriteMapFile (\r
   IN OUT FILE                  *FvMapFile,\r
   IN     CHAR8                 *FileName,\r
-  IN     EFI_FFS_FILE_HEADER   *FfsFile, \r
+  IN     EFI_FFS_FILE_HEADER   *FfsFile,\r
   IN     EFI_PHYSICAL_ADDRESS  ImageBaseAddress,\r
   IN     PE_COFF_LOADER_IMAGE_CONTEXT *pImageContext\r
   )\r
@@ -801,15 +817,19 @@ Returns:
   //\r
   FunctionType = 0;\r
   //\r
-  // Print FileGuid to string buffer. \r
+  // Print FileGuid to string buffer.\r
   //\r
   PrintGuidToBuffer (&FfsFile->Name, (UINT8 *)FileGuidName, MAX_LINE_LEN, TRUE);\r
-  \r
+\r
   //\r
-  // Construct Map file Name \r
+  // Construct Map file Name\r
   //\r
-  strcpy (PeMapFileName, FileName);\r
-  \r
+  if (strlen (FileName) >= MAX_LONG_FILE_PATH) {\r
+    return EFI_ABORTED;\r
+  }\r
+  strncpy (PeMapFileName, FileName, MAX_LONG_FILE_PATH - 1);\r
+  PeMapFileName[MAX_LONG_FILE_PATH - 1] = 0;\r
+\r
   //\r
   // Change '\\' to '/', unified path format.\r
   //\r
@@ -820,10 +840,10 @@ Returns:
     }\r
     Cptr ++;\r
   }\r
-  \r
+\r
   //\r
   // Get Map file\r
-  // \r
+  //\r
   Cptr = PeMapFileName + strlen (PeMapFileName);\r
   while ((*Cptr != '.') && (Cptr >= PeMapFileName)) {\r
     Cptr --;\r
@@ -844,26 +864,30 @@ Returns:
   while ((*Cptr != FILE_SEP_CHAR) && (Cptr >= PeMapFileName)) {\r
     Cptr --;\r
   }\r
-       *Cptr2 = '\0';\r
-       strcpy (KeyWord, Cptr + 1);\r
-       *Cptr2 = '.';\r
+  *Cptr2 = '\0';\r
+  if (strlen (Cptr + 1) >= MAX_LINE_LEN) {\r
+    return EFI_ABORTED;\r
+  }\r
+  strncpy (KeyWord, Cptr + 1, MAX_LINE_LEN - 1);\r
+  KeyWord[MAX_LINE_LEN - 1] = 0;\r
+  *Cptr2 = '.';\r
 \r
   //\r
   // AddressOfEntryPoint and Offset in Image\r
   //\r
   if (!pImageContext->IsTeImage) {\r
-       ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *) ((UINT8 *) pImageContext->Handle + pImageContext->PeCoffHeaderOffset);\r
-       AddressOfEntryPoint = ImgHdr->Pe32.OptionalHeader.AddressOfEntryPoint;\r
-       Offset = 0;\r
+    ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *) ((UINT8 *) pImageContext->Handle + pImageContext->PeCoffHeaderOffset);\r
+    AddressOfEntryPoint = ImgHdr->Pe32.OptionalHeader.AddressOfEntryPoint;\r
+    Offset = 0;\r
     SectionHeader = (EFI_IMAGE_SECTION_HEADER *) (\r
                        (UINT8 *) ImgHdr +\r
-                       sizeof (UINT32) + \r
-                       sizeof (EFI_IMAGE_FILE_HEADER) +  \r
+                       sizeof (UINT32) +\r
+                       sizeof (EFI_IMAGE_FILE_HEADER) +\r
                        ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader\r
                        );\r
     Index = ImgHdr->Pe32.FileHeader.NumberOfSections;\r
   } else {\r
-       TEImageHeader = (EFI_TE_IMAGE_HEADER *) pImageContext->Handle;\r
+    TEImageHeader = (EFI_TE_IMAGE_HEADER *) pImageContext->Handle;\r
     AddressOfEntryPoint = TEImageHeader->AddressOfEntryPoint;\r
     Offset = TEImageHeader->StrippedSize - sizeof (EFI_TE_IMAGE_HEADER);\r
     SectionHeader = (EFI_IMAGE_SECTION_HEADER *) (TEImageHeader + 1);\r
@@ -881,33 +905,25 @@ Returns:
     fprintf (FvMapFile, "BaseAddress=0x%010llx, ", (unsigned long long) (ImageBaseAddress + Offset));\r
   }\r
 \r
-  if (FfsFile->Type != EFI_FV_FILETYPE_SECURITY_CORE && pImageContext->Machine == EFI_IMAGE_MACHINE_IA64) {\r
-    //\r
-    // Process IPF PLABEL to get the real address after the image has been rebased. \r
-    // PLABEL structure is got by AddressOfEntryPoint offset to ImageBuffer stored in pImageContext->Handle.\r
-    //\r
-    fprintf (FvMapFile, "EntryPoint=0x%010llx", (unsigned long long) (*(UINT64 *)((UINTN) pImageContext->Handle + (UINTN) AddressOfEntryPoint)));\r
-  } else {\r
-    fprintf (FvMapFile, "EntryPoint=0x%010llx", (unsigned long long) (ImageBaseAddress + AddressOfEntryPoint));\r
-  }\r
-  fprintf (FvMapFile, ")\n"); \r
-  \r
+  fprintf (FvMapFile, "EntryPoint=0x%010llx", (unsigned long long) (ImageBaseAddress + AddressOfEntryPoint));\r
+  fprintf (FvMapFile, ")\n");\r
+\r
   fprintf (FvMapFile, "(GUID=%s", FileGuidName);\r
   TextVirtualAddress = 0;\r
   DataVirtualAddress = 0;\r
   for (; Index > 0; Index --, SectionHeader ++) {\r
     if (stricmp ((CHAR8 *)SectionHeader->Name, ".text") == 0) {\r
-               TextVirtualAddress = SectionHeader->VirtualAddress;\r
-       } else if (stricmp ((CHAR8 *)SectionHeader->Name, ".data") == 0) {\r
-         DataVirtualAddress = SectionHeader->VirtualAddress;\r
-       } else if (stricmp ((CHAR8 *)SectionHeader->Name, ".sdata") == 0) {\r
-         DataVirtualAddress = SectionHeader->VirtualAddress;\r
-       }\r
+      TextVirtualAddress = SectionHeader->VirtualAddress;\r
+    } else if (stricmp ((CHAR8 *)SectionHeader->Name, ".data") == 0) {\r
+      DataVirtualAddress = SectionHeader->VirtualAddress;\r
+    } else if (stricmp ((CHAR8 *)SectionHeader->Name, ".sdata") == 0) {\r
+      DataVirtualAddress = SectionHeader->VirtualAddress;\r
+    }\r
   }\r
   fprintf (FvMapFile, " .textbaseaddress=0x%010llx", (unsigned long long) (ImageBaseAddress + TextVirtualAddress));\r
   fprintf (FvMapFile, " .databaseaddress=0x%010llx", (unsigned long long) (ImageBaseAddress + DataVirtualAddress));\r
   fprintf (FvMapFile, ")\n\n");\r
-   \r
+\r
   //\r
   // Open PeMapFile\r
   //\r
@@ -917,7 +933,7 @@ Returns:
     return EFI_ABORTED;\r
   }\r
   VerboseMsg ("The map file is %s", PeMapFileName);\r
-  \r
+\r
   //\r
   // Output Functions information into Fv Map file\r
   //\r
@@ -932,7 +948,7 @@ Returns:
     }\r
     //\r
     // By Address and Static keyword\r
-    //  \r
+    //\r
     if (FunctionType == 0) {\r
       sscanf (Line, "%s", KeyWord);\r
       if (stricmp (KeyWord, "Address") == 0) {\r
@@ -977,7 +993,7 @@ Returns:
   //\r
   fprintf (FvMapFile, "\n\n");\r
   fclose (PeMapFile);\r
-  \r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -1172,7 +1188,7 @@ Returns:
   EFI_STATUS            Status;\r
   UINTN                 Index1;\r
   UINT8                 FileGuidString[PRINTED_GUID_BUFFER_SIZE];\r
-  \r
+\r
   Index1 = 0;\r
   //\r
   // Verify input parameters.\r
@@ -1202,7 +1218,7 @@ Returns:
   FileBuffer = malloc (FileSize);\r
   if (FileBuffer == NULL) {\r
     fclose (NewFile);\r
-    Error (NULL, 0, 4001, "Resouce", "memory cannot be allocated!");\r
+    Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
@@ -1212,7 +1228,7 @@ Returns:
   // Done with the file, from this point on we will just use the buffer read.\r
   //\r
   fclose (NewFile);\r
-  \r
+\r
   //\r
   // Verify read successful\r
   //\r
@@ -1221,20 +1237,20 @@ Returns:
     Error (NULL, 0, 0004, "Error reading file", FvInfo->FvFiles[Index]);\r
     return EFI_ABORTED;\r
   }\r
-  \r
+\r
   //\r
   // For None PI Ffs file, directly add them into FvImage.\r
   //\r
   if (!FvInfo->IsPiFvImage) {\r
     memcpy (FvImage->CurrentFilePointer, FileBuffer, FileSize);\r
     if (FvInfo->SizeofFvFiles[Index] > FileSize) {\r
-       FvImage->CurrentFilePointer += FvInfo->SizeofFvFiles[Index];\r
+      FvImage->CurrentFilePointer += FvInfo->SizeofFvFiles[Index];\r
     } else {\r
-       FvImage->CurrentFilePointer += FileSize;\r
+      FvImage->CurrentFilePointer += FileSize;\r
     }\r
     goto Done;\r
   }\r
-  \r
+\r
   //\r
   // Verify Ffs file\r
   //\r
@@ -1279,7 +1295,7 @@ Returns:
   // Check if alignment is required\r
   //\r
   ReadFfsAlignment ((EFI_FFS_FILE_HEADER *) FileBuffer, &CurrentFileAlignment);\r
-  \r
+\r
   //\r
   // Find the largest alignment of all the FFS files in the FV\r
   //\r
@@ -1304,20 +1320,20 @@ Returns:
         return EFI_ABORTED;\r
       }\r
       //\r
-      // Rebase the PE or TE image in FileBuffer of FFS file for XIP \r
+      // Rebase the PE or TE image in FileBuffer of FFS file for XIP\r
       // Rebase for the debug genfvmap tool\r
       //\r
       Status = FfsRebase (FvInfo, FvInfo->FvFiles[Index], (EFI_FFS_FILE_HEADER *) FileBuffer, (UINTN) *VtfFileImage - (UINTN) FvImage->FileImage, FvMapFile);\r
       if (EFI_ERROR (Status)) {\r
         Error (NULL, 0, 3000, "Invalid", "Could not rebase %s.", FvInfo->FvFiles[Index]);\r
         return Status;\r
-      }          \r
+      }\r
       //\r
       // copy VTF File\r
       //\r
       memcpy (*VtfFileImage, FileBuffer, FileSize);\r
-      \r
-      PrintGuidToBuffer ((EFI_GUID *) FileBuffer, FileGuidString, sizeof (FileGuidString), TRUE); \r
+\r
+      PrintGuidToBuffer ((EFI_GUID *) FileBuffer, FileGuidString, sizeof (FileGuidString), TRUE);\r
       fprintf (FvReportFile, "0x%08X %s\n", (unsigned)(UINTN) (((UINT8 *)*VtfFileImage) - (UINTN)FvImage->FileImage), FileGuidString);\r
 \r
       free (FileBuffer);\r
@@ -1350,19 +1366,19 @@ Returns:
   //\r
   if ((UINTN) (FvImage->CurrentFilePointer + FileSize) <= (UINTN) (*VtfFileImage)) {\r
     //\r
-    // Rebase the PE or TE image in FileBuffer of FFS file for XIP. \r
+    // Rebase the PE or TE image in FileBuffer of FFS file for XIP.\r
     // Rebase Bs and Rt drivers for the debug genfvmap tool.\r
     //\r
     Status = FfsRebase (FvInfo, FvInfo->FvFiles[Index], (EFI_FFS_FILE_HEADER *) FileBuffer, (UINTN) FvImage->CurrentFilePointer - (UINTN) FvImage->FileImage, FvMapFile);\r
-       if (EFI_ERROR (Status)) {\r
-         Error (NULL, 0, 3000, "Invalid", "Could not rebase %s.", FvInfo->FvFiles[Index]);\r
-         return Status;\r
-       }               \r
+  if (EFI_ERROR (Status)) {\r
+    Error (NULL, 0, 3000, "Invalid", "Could not rebase %s.", FvInfo->FvFiles[Index]);\r
+    return Status;\r
+  }\r
     //\r
     // Copy the file\r
     //\r
     memcpy (FvImage->CurrentFilePointer, FileBuffer, FileSize);\r
-    PrintGuidToBuffer ((EFI_GUID *) FileBuffer, FileGuidString, sizeof (FileGuidString), TRUE); \r
+    PrintGuidToBuffer ((EFI_GUID *) FileBuffer, FileGuidString, sizeof (FileGuidString), TRUE);\r
     fprintf (FvReportFile, "0x%08X %s\n", (unsigned) (FvImage->CurrentFilePointer - FvImage->FileImage), FileGuidString);\r
     FvImage->CurrentFilePointer += FileSize;\r
   } else {\r
@@ -1371,13 +1387,13 @@ Returns:
     return EFI_ABORTED;\r
   }\r
   //\r
-  // Make next file start at QWord Boundry\r
+  // Make next file start at QWord Boundary\r
   //\r
   while (((UINTN) FvImage->CurrentFilePointer & (EFI_FFS_FILE_HEADER_ALIGNMENT - 1)) != 0) {\r
     FvImage->CurrentFilePointer++;\r
   }\r
 \r
-Done: \r
+Done:\r
   //\r
   // Free allocated memory.\r
   //\r
@@ -1434,7 +1450,7 @@ Returns:
   PadFile = (EFI_FFS_FILE_HEADER *) FvImage->CurrentFilePointer;\r
 \r
   //\r
-  // write PadFile FFS header with PadType, don't need to set PAD file guid in its header. \r
+  // write PadFile FFS header with PadType, don't need to set PAD file guid in its header.\r
   //\r
   PadFile->Type       = EFI_FV_FILETYPE_FFS_PAD;\r
   PadFile->Attributes = 0;\r
@@ -1517,7 +1533,6 @@ Returns:
   UINT16                    MachineType;\r
   EFI_PHYSICAL_ADDRESS      PeiCorePhysicalAddress;\r
   EFI_PHYSICAL_ADDRESS      SecCorePhysicalAddress;\r
-  EFI_PHYSICAL_ADDRESS      *SecCoreEntryAddressPtr;\r
   INT32                     Ia32SecEntryOffset;\r
   UINT32                    *Ia32ResetAddressPtr;\r
   UINT8                     *BytePointer;\r
@@ -1527,8 +1542,6 @@ Returns:
   UINT32                    IpiVector;\r
   UINTN                     Index;\r
   EFI_FFS_FILE_STATE        SavedState;\r
-  UINT64                    FitAddress;\r
-  FIT_TABLE                 *FitTablePtr;\r
   BOOLEAN                   Vtf0Detected;\r
   UINT32                    FfsHeaderSize;\r
   UINT32                    SecHeaderSize;\r
@@ -1605,7 +1618,7 @@ Returns:
   if (EFI_ERROR (Status)) {\r
     Error (NULL, 0, 3000, "Invalid", "could not get the PE32 entry point for the SEC core.");\r
     return EFI_ABORTED;\r
-  }  \r
+  }\r
 \r
   if (\r
        Vtf0Detected &&\r
@@ -1626,126 +1639,71 @@ Returns:
   SecCorePhysicalAddress = FvInfo->BaseAddress;\r
   SecCorePhysicalAddress += (UINTN) Pe32Section.Pe32Section + SecHeaderSize - (UINTN) FvImage->FileImage;\r
   SecCorePhysicalAddress += EntryPoint;\r
-  DebugMsg (NULL, 0, 9, "SecCore physical entry point address", "Address = 0x%llX", (unsigned long long) SecCorePhysicalAddress); \r
+  DebugMsg (NULL, 0, 9, "SecCore physical entry point address", "Address = 0x%llX", (unsigned long long) SecCorePhysicalAddress);\r
 \r
   //\r
   // Find the PEI Core\r
   //\r
+  PeiCorePhysicalAddress = 0;\r
   Status = GetFileByType (EFI_FV_FILETYPE_PEI_CORE, 1, &PeiCoreFile);\r
-  if (EFI_ERROR (Status) || PeiCoreFile == NULL) {\r
-    Error (NULL, 0, 3000, "Invalid", "could not find the PEI core in the FV.");\r
-    return EFI_ABORTED;\r
-  }\r
-  //\r
-  // PEI Core found, now find PE32 or TE section\r
-  //\r
-  Status = GetSectionByType (PeiCoreFile, EFI_SECTION_PE32, 1, &Pe32Section);\r
-  if (Status == EFI_NOT_FOUND) {\r
-    Status = GetSectionByType (PeiCoreFile, EFI_SECTION_TE, 1, &Pe32Section);\r
-  }\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    Error (NULL, 0, 3000, "Invalid", "could not find either a PE32 or a TE section in PEI core file.");\r
-    return EFI_ABORTED;\r
-  }\r
-\r
-  SecHeaderSize = GetSectionHeaderLength(Pe32Section.CommonHeader);\r
-  Status = GetPe32Info (\r
-            (VOID *) ((UINTN) Pe32Section.Pe32Section + SecHeaderSize),\r
-            &EntryPoint,\r
-            &BaseOfCode,\r
-            &MachineType\r
-            );\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    Error (NULL, 0, 3000, "Invalid", "could not get the PE32 entry point for the PEI core.");\r
-    return EFI_ABORTED;\r
-  }\r
-  //\r
-  // Physical address is FV base + offset of PE32 + offset of the entry point\r
-  //\r
-  PeiCorePhysicalAddress = FvInfo->BaseAddress;\r
-  PeiCorePhysicalAddress += (UINTN) Pe32Section.Pe32Section + SecHeaderSize - (UINTN) FvImage->FileImage;\r
-  PeiCorePhysicalAddress += EntryPoint;\r
-  DebugMsg (NULL, 0, 9, "PeiCore physical entry point address", "Address = 0x%llX", (unsigned long long) PeiCorePhysicalAddress);\r
-\r
-  if (MachineType == EFI_IMAGE_MACHINE_IA64) {\r
-    //\r
-    // Update PEI_CORE address\r
-    //\r
+  if (!EFI_ERROR (Status) && (PeiCoreFile != NULL)) {\r
     //\r
-    // Set the uncached attribute bit in the physical address\r
+    // PEI Core found, now find PE32 or TE section\r
     //\r
-    PeiCorePhysicalAddress |= 0x8000000000000000ULL;\r
+    Status = GetSectionByType (PeiCoreFile, EFI_SECTION_PE32, 1, &Pe32Section);\r
+    if (Status == EFI_NOT_FOUND) {\r
+      Status = GetSectionByType (PeiCoreFile, EFI_SECTION_TE, 1, &Pe32Section);\r
+    }\r
 \r
-    //\r
-    // Check if address is aligned on a 16 byte boundary\r
-    //\r
-    if (PeiCorePhysicalAddress & 0xF) {\r
-      Error (NULL, 0, 3000, "Invalid",\r
-        "PEI_CORE entry point is not aligned on a 16 byte boundary, address specified is %llXh.",\r
-        (unsigned long long) PeiCorePhysicalAddress\r
-        );\r
+    if (EFI_ERROR (Status)) {\r
+      Error (NULL, 0, 3000, "Invalid", "could not find either a PE32 or a TE section in PEI core file.");\r
       return EFI_ABORTED;\r
     }\r
-    //\r
-    // First Get the FIT table address\r
-    //\r
-    FitAddress  = (*(UINT64 *) (FvImage->Eof - IPF_FIT_ADDRESS_OFFSET)) & 0xFFFFFFFF;\r
-\r
-    FitTablePtr = (FIT_TABLE *) (FvImage->FileImage + (FitAddress - FvInfo->BaseAddress));\r
 \r
-    Status      = UpdatePeiCoreEntryInFit (FitTablePtr, PeiCorePhysicalAddress);\r
-\r
-    if (!EFI_ERROR (Status)) {\r
-      UpdateFitCheckSum (FitTablePtr);\r
-    }\r
+    SecHeaderSize = GetSectionHeaderLength(Pe32Section.CommonHeader);\r
+    Status = GetPe32Info (\r
+              (VOID *) ((UINTN) Pe32Section.Pe32Section + SecHeaderSize),\r
+              &EntryPoint,\r
+              &BaseOfCode,\r
+              &MachineType\r
+              );\r
 \r
-    //\r
-    // Update SEC_CORE address\r
-    //\r
-    //\r
-    // Set the uncached attribute bit in the physical address\r
-    //\r
-    SecCorePhysicalAddress |= 0x8000000000000000ULL;\r
-    //\r
-    // Check if address is aligned on a 16 byte boundary\r
-    //\r
-    if (SecCorePhysicalAddress & 0xF) {\r
-      Error (NULL, 0, 3000, "Invalid",\r
-        "SALE_ENTRY entry point is not aligned on a 16 byte boundary, address specified is %llXh.",\r
-        (unsigned long long) SecCorePhysicalAddress\r
-        );\r
+    if (EFI_ERROR (Status)) {\r
+      Error (NULL, 0, 3000, "Invalid", "could not get the PE32 entry point for the PEI core.");\r
       return EFI_ABORTED;\r
     }\r
     //\r
-    // Update the address\r
+    // Physical address is FV base + offset of PE32 + offset of the entry point\r
     //\r
-    SecCoreEntryAddressPtr  = (EFI_PHYSICAL_ADDRESS *) ((UINTN) FvImage->Eof - IPF_SALE_ENTRY_ADDRESS_OFFSET);\r
-    *SecCoreEntryAddressPtr = SecCorePhysicalAddress;\r
+    PeiCorePhysicalAddress = FvInfo->BaseAddress;\r
+    PeiCorePhysicalAddress += (UINTN) Pe32Section.Pe32Section + SecHeaderSize - (UINTN) FvImage->FileImage;\r
+    PeiCorePhysicalAddress += EntryPoint;\r
+    DebugMsg (NULL, 0, 9, "PeiCore physical entry point address", "Address = 0x%llX", (unsigned long long) PeiCorePhysicalAddress);\r
+  }\r
 \r
-  } else if (MachineType == EFI_IMAGE_MACHINE_IA32 || MachineType == EFI_IMAGE_MACHINE_X64) {\r
-    //\r
-    // Get the location to update\r
-    //\r
-    Ia32ResetAddressPtr  = (UINT32 *) ((UINTN) FvImage->Eof - IA32_PEI_CORE_ENTRY_OFFSET);\r
+if (MachineType == EFI_IMAGE_MACHINE_IA32 || MachineType == EFI_IMAGE_MACHINE_X64) {\r
+    if (PeiCorePhysicalAddress != 0) {\r
+      //\r
+      // Get the location to update\r
+      //\r
+      Ia32ResetAddressPtr  = (UINT32 *) ((UINTN) FvImage->Eof - IA32_PEI_CORE_ENTRY_OFFSET);\r
 \r
-    //\r
-    // Write lower 32 bits of physical address for Pei Core entry\r
-    //\r
-    *Ia32ResetAddressPtr = (UINT32) PeiCorePhysicalAddress;\r
-    \r
+      //\r
+      // Write lower 32 bits of physical address for Pei Core entry\r
+      //\r
+      *Ia32ResetAddressPtr = (UINT32) PeiCorePhysicalAddress;\r
+    }\r
     //\r
     // Write SecCore Entry point relative address into the jmp instruction in reset vector.\r
-    // \r
+    //\r
     Ia32ResetAddressPtr  = (UINT32 *) ((UINTN) FvImage->Eof - IA32_SEC_CORE_ENTRY_OFFSET);\r
-    \r
+\r
     Ia32SecEntryOffset   = (INT32) (SecCorePhysicalAddress - (FV_IMAGES_TOP_ADDRESS - IA32_SEC_CORE_ENTRY_OFFSET + 2));\r
     if (Ia32SecEntryOffset <= -65536) {\r
       Error (NULL, 0, 3000, "Invalid", "The SEC EXE file size is too large, it must be less than 64K.");\r
       return STATUS_ERROR;\r
     }\r
-    \r
+\r
     *(UINT16 *) Ia32ResetAddressPtr = (UINT16) Ia32SecEntryOffset;\r
 \r
     //\r
@@ -1795,9 +1753,9 @@ Returns:
     //\r
     WordPointer   = (UINT16 *) (BytePointer + SIZEOF_STARTUP_DATA_ARRAY - 2);\r
     *WordPointer  = (UINT16) (0x10000 - (UINT32) CheckSum);\r
-    \r
+\r
     //\r
-    // IpiVector at the 4k aligned address in the top 2 blocks in the PEI FV. \r
+    // IpiVector at the 4k aligned address in the top 2 blocks in the PEI FV.\r
     //\r
     IpiVector  = (UINT32) (FV_IMAGES_TOP_ADDRESS - ((UINTN) FvImage->Eof - (UINTN) BytePointer));\r
     DebugMsg (NULL, 0, 9, "Startup AP Vector address", "IpiVector at 0x%X", (unsigned) IpiVector);\r
@@ -2096,15 +2054,15 @@ UpdateArmResetVectorIfNeeded (
 /*++\r
 \r
 Routine Description:\r
-  This parses the FV looking for SEC and patches that address into the \r
+  This parses the FV looking for SEC and patches that address into the\r
   beginning of the FV header.\r
 \r
   For ARM32 the reset vector is at 0x00000000 or 0xFFFF0000.\r
   For AArch64 the reset vector is at 0x00000000.\r
 \r
-  This would commonly map to the first entry in the ROM. \r
+  This would commonly map to the first entry in the ROM.\r
   ARM32 Exceptions:\r
-  Reset            +0    \r
+  Reset            +0\r
   Undefined        +4\r
   SWI              +8\r
   Prefetch Abort   +12\r
@@ -2114,15 +2072,15 @@ Routine Description:
 \r
   We support two schemes on ARM.\r
   1) Beginning of the FV is the reset vector\r
-  2) Reset vector is data bytes FDF file and that code branches to reset vector \r
+  2) Reset vector is data bytes FDF file and that code branches to reset vector\r
     in the beginning of the FV (fixed size offset).\r
 \r
   Need to have the jump for the reset vector at location zero.\r
   We also need to store the address or PEI (if it exists).\r
-  We stub out a return from interrupt in case the debugger \r
+  We stub out a return from interrupt in case the debugger\r
    is using SWI (not done for AArch64, not enough space in struct).\r
-  The optional entry to the common exception handler is \r
-   to support full featured exception handling from ROM and is currently \r
+  The optional entry to the common exception handler is\r
+   to support full featured exception handling from ROM and is currently\r
     not support by this tool.\r
 \r
 Arguments:\r
@@ -2219,7 +2177,7 @@ Returns:
     // 1 - PEI Entry Point\r
     // 2 - movs pc,lr for a SWI handler\r
     // 3 - Place holder for Common Exception Handler\r
-    UINT32                      ResetVector[4]; \r
+    UINT32                      ResetVector[4];\r
 \r
     memset(ResetVector, 0, sizeof (ResetVector));\r
 \r
@@ -2238,14 +2196,14 @@ Returns:
         return EFI_ABORTED;\r
       }\r
 \r
-      // Add opcode for an uncondional branch with no link. i.e.: " B SecEntryPoint"\r
+      // Add opcode for an unconditional branch with no link. i.e.: " B SecEntryPoint"\r
       ResetVector[0] |= ARMT_UNCONDITIONAL_JUMP_INSTRUCTION;\r
 \r
       // SWI handler movs   pc,lr. Just in case a debugger uses SWI\r
       ResetVector[2] = 0xE1B0F07E;\r
 \r
       // Place holder to support a common interrupt handler from ROM.\r
-      // Currently not suppprted. For this to be used the reset vector would not be in this FV\r
+      // Currently not supported. For this to be used the reset vector would not be in this FV\r
       // and the exception vectors would be hard coded in the ROM and just through this address\r
       // to find a common handler in the a module in the FV.\r
       ResetVector[3] = 0;\r
@@ -2277,7 +2235,7 @@ Returns:
     ARMT above has an entry in ResetVector[2] for SWI. The way we are using the ResetVector\r
     array at the moment, for AArch64, does not allow us space for this as the header only\r
     allows for a fixed amount of bytes at the start. If we are sure that UEFI will live\r
-    within the first 4GB of addressable RAM we could potensioally adopt the same ResetVector\r
+    within the first 4GB of addressable RAM we could potentially adopt the same ResetVector\r
     layout as above. But for the moment we replace the four 32bit vectors with two 64bit\r
     vectors in the same area of the Image heasder. This allows UEFI to start from a 64bit\r
     base.\r
@@ -2295,7 +2253,7 @@ Returns:
         Error(NULL, 0, 3000, "Invalid", "SEC Entry point must be within 128MB of the start of the FV");\r
         return EFI_ABORTED;\r
       }\r
-      // Add opcode for an uncondional branch with no link. i.e.: " B SecEntryPoint"\r
+      // Add opcode for an unconditional branch with no link. i.e.: " B SecEntryPoint"\r
       ResetVector[0] |= ARM64_UNCONDITIONAL_JUMP_INSTRUCTION;\r
     }\r
 \r
@@ -2332,8 +2290,8 @@ GetPe32Info (
 \r
 Routine Description:\r
 \r
-  Retrieves the PE32 entry point offset and machine type from PE image or TeImage.  \r
-  See EfiImage.h for machine types.  The entry point offset is from the beginning \r
+  Retrieves the PE32 entry point offset and machine type from PE image or TeImage.\r
+  See EfiImage.h for machine types.  The entry point offset is from the beginning\r
   of the PE32 buffer passed in.\r
 \r
 Arguments:\r
@@ -2375,13 +2333,13 @@ Returns:
     *BaseOfCode   = TeHeader->BaseOfCode + sizeof (EFI_TE_IMAGE_HEADER) - TeHeader->StrippedSize;\r
     *MachineType  = TeHeader->Machine;\r
   } else {\r
-  \r
+\r
     //\r
-    // Then check whether \r
+    // Then check whether\r
     // First is the DOS header\r
     //\r
     DosHeader = (EFI_IMAGE_DOS_HEADER *) Pe32;\r
-  \r
+\r
     //\r
     // Verify DOS header is expected\r
     //\r
@@ -2393,7 +2351,7 @@ Returns:
     // Immediately following is the NT header.\r
     //\r
     ImgHdr = (EFI_IMAGE_OPTIONAL_HEADER_UNION *) ((UINTN) Pe32 + DosHeader->e_lfanew);\r
-  \r
+\r
     //\r
     // Verify NT header is expected\r
     //\r
@@ -2412,7 +2370,7 @@ Returns:
   //\r
   // Verify machine type is supported\r
   //\r
-  if ((*MachineType != EFI_IMAGE_MACHINE_IA32) && (*MachineType != EFI_IMAGE_MACHINE_IA64) && (*MachineType != EFI_IMAGE_MACHINE_X64) && (*MachineType != EFI_IMAGE_MACHINE_EBC) && \r
+  if ((*MachineType != EFI_IMAGE_MACHINE_IA32) &&  (*MachineType != EFI_IMAGE_MACHINE_X64) && (*MachineType != EFI_IMAGE_MACHINE_EBC) &&\r
       (*MachineType != EFI_IMAGE_MACHINE_ARMT) && (*MachineType != EFI_IMAGE_MACHINE_AARCH64)) {\r
     Error (NULL, 0, 3000, "Invalid", "Unrecognized machine type in the PE32 file.");\r
     return EFI_UNSUPPORTED;\r
@@ -2482,7 +2440,7 @@ Returns:
     InfMemoryFile.FileImage           = InfFileImage;\r
     InfMemoryFile.CurrentFilePointer  = InfFileImage;\r
     InfMemoryFile.Eof                 = InfFileImage + InfFileSize;\r
-  \r
+\r
     //\r
     // Parse the FV inf file for header information\r
     //\r
@@ -2504,17 +2462,17 @@ Returns:
     Error (NULL, 0, 1001, "Missing option", "Output file name");\r
     return EFI_ABORTED;\r
   }\r
-  \r
+\r
   if (mFvDataInfo.FvBlocks[0].Length == 0) {\r
     Error (NULL, 0, 1001, "Missing required argument", "Block Size");\r
     return EFI_ABORTED;\r
   }\r
-  \r
+\r
   //\r
   // Debug message Fv File System Guid\r
   //\r
   if (mFvDataInfo.FvFileSystemGuidSet) {\r
-    DebugMsg (NULL, 0, 9, "FV File System Guid", "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", \r
+    DebugMsg (NULL, 0, 9, "FV File System Guid", "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",\r
                   (unsigned) mFvDataInfo.FvFileSystemGuid.Data1,\r
                   mFvDataInfo.FvFileSystemGuid.Data2,\r
                   mFvDataInfo.FvFileSystemGuid.Data3,\r
@@ -2587,7 +2545,7 @@ Returns:
   // Debug message Fv Name Guid\r
   //\r
   if (mFvDataInfo.FvNameGuidSet) {\r
-      DebugMsg (NULL, 0, 9, "FV Name Guid", "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", \r
+      DebugMsg (NULL, 0, 9, "FV Name Guid", "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",\r
                   (unsigned) mFvDataInfo.FvNameGuid.Data1,\r
                   mFvDataInfo.FvNameGuid.Data2,\r
                   mFvDataInfo.FvNameGuid.Data3,\r
@@ -2671,7 +2629,7 @@ Returns:
     goto Finish;\r
   }\r
   VerboseMsg ("the generated FV image size is %u bytes", (unsigned) mFvDataInfo.Size);\r
-  \r
+\r
   //\r
   // support fv image and empty fv image\r
   //\r
@@ -2692,7 +2650,7 @@ Returns:
   //\r
   if (mFvDataInfo.FvAttributes == 0) {\r
     //\r
-    // Set Default Fv Attribute \r
+    // Set Default Fv Attribute\r
     //\r
     mFvDataInfo.FvAttributes = FV_DEFAULT_ATTRIBUTE;\r
   }\r
@@ -2723,7 +2681,7 @@ Returns:
   FvHeader->Revision        = EFI_FVH_REVISION;\r
   FvHeader->ExtHeaderOffset = 0;\r
   FvHeader->Reserved[0]     = 0;\r
-  \r
+\r
   //\r
   // Copy firmware block map\r
   //\r
@@ -2778,7 +2736,7 @@ Returns:
     Status = EFI_ABORTED;\r
     goto Finish;\r
   }\r
-  \r
+\r
   //\r
   // Open FvReport file\r
   //\r
@@ -2859,7 +2817,7 @@ Returns:
     if (!mArm) {\r
       //\r
       // Update reset vector (SALE_ENTRY for IPF)\r
-      // Now for IA32 and IA64 platform, the fv which has bsf file must have the \r
+      // Now for IA32 and IA64 platform, the fv which has bsf file must have the\r
       // EndAddress of 0xFFFFFFFF (unless the section was rebased).\r
       // Thus, only this type fv needs to update the  reset vector.\r
       // If the PEI Core is found, the VTF file will probably get\r
@@ -2868,29 +2826,29 @@ Returns:
       if (mFvDataInfo.ForceRebase == 1 ||\r
           (mFvDataInfo.BaseAddress + mFvDataInfo.Size) == FV_IMAGES_TOP_ADDRESS) {\r
         Status = UpdateResetVector (&FvImageMemoryFile, &mFvDataInfo, VtfFileImage);\r
-        if (EFI_ERROR(Status)) {                                               \r
+        if (EFI_ERROR(Status)) {\r
           Error (NULL, 0, 3000, "Invalid", "Could not update the reset vector.");\r
-          goto Finish;                                              \r
+          goto Finish;\r
         }\r
         DebugMsg (NULL, 0, 9, "Update Reset vector in VTF file", NULL);\r
       }\r
     }\r
-  } \r
+  }\r
 \r
   if (mArm) {\r
     Status = UpdateArmResetVectorIfNeeded (&FvImageMemoryFile, &mFvDataInfo);\r
-    if (EFI_ERROR (Status)) {                                               \r
+    if (EFI_ERROR (Status)) {\r
       Error (NULL, 0, 3000, "Invalid", "Could not update the reset vector.");\r
-      goto Finish;                                              \r
-    }  \r
-    \r
+      goto Finish;\r
+    }\r
+\r
     //\r
     // Update Checksum for FvHeader\r
     //\r
     FvHeader->Checksum = 0;\r
     FvHeader->Checksum = CalculateChecksum16 ((UINT16 *) FvHeader, FvHeader->HeaderLength / sizeof (UINT16));\r
   }\r
-  \r
+\r
   //\r
   // Update FV Alignment attribute to the largest alignment of all the FFS files in the FV\r
   //\r
@@ -2913,7 +2871,7 @@ Returns:
     FvHeader->Checksum      = CalculateChecksum16 ((UINT16 *) FvHeader, FvHeader->HeaderLength / sizeof (UINT16));\r
   }\r
 \r
-WriteFile: \r
+WriteFile:\r
   //\r
   // Write fv file\r
   //\r
@@ -2946,12 +2904,12 @@ Finish:
   if (FvReportName != NULL) {\r
     free (FvReportName);\r
   }\r
-  \r
+\r
   if (FvFile != NULL) {\r
     fflush (FvFile);\r
     fclose (FvFile);\r
   }\r
-  \r
+\r
   if (FvMapFile != NULL) {\r
     fflush (FvMapFile);\r
     fclose (FvMapFile);\r
@@ -3059,12 +3017,10 @@ Returns:
   UINT32              FfsAlignment;\r
   UINT32              FfsHeaderSize;\r
   EFI_FFS_FILE_HEADER FfsHeader;\r
-  BOOLEAN             VtfFileFlag;\r
   UINTN               VtfFileSize;\r
-  \r
+\r
   FvExtendHeaderSize = 0;\r
   VtfFileSize = 0;\r
-  VtfFileFlag = FALSE;\r
   fpin  = NULL;\r
   Index = 0;\r
 \r
@@ -3075,19 +3031,19 @@ Returns:
   for (Index = 0; FvInfoPtr->FvBlocks[Index].NumBlocks > 0 && FvInfoPtr->FvBlocks[Index].Length > 0; Index++) {\r
     FvInfoPtr->Size += FvInfoPtr->FvBlocks[Index].NumBlocks * FvInfoPtr->FvBlocks[Index].Length;\r
   }\r
-  \r
+\r
   //\r
   // Calculate the required sizes for all FFS files.\r
   //\r
   CurrentOffset = sizeof (EFI_FIRMWARE_VOLUME_HEADER);\r
-  \r
+\r
   for (Index = 1;; Index ++) {\r
     CurrentOffset += sizeof (EFI_FV_BLOCK_MAP_ENTRY);\r
     if (FvInfoPtr->FvBlocks[Index].NumBlocks == 0 || FvInfoPtr->FvBlocks[Index].Length == 0) {\r
       break;\r
     }\r
   }\r
-  \r
+\r
   //\r
   // Calculate PI extension header\r
   //\r
@@ -3112,7 +3068,7 @@ Returns:
   }\r
 \r
   //\r
-  // Accumlate every FFS file size.\r
+  // Accumulate every FFS file size.\r
   //\r
   for (Index = 0; FvInfoPtr->FvFiles[Index][0] != 0; Index++) {\r
     //\r
@@ -3142,7 +3098,7 @@ Returns:
     // close file\r
     //\r
     fclose (fpin);\r
-    \r
+\r
     if (FvInfoPtr->IsPiFvImage) {\r
         //\r
         // Check whether this ffs file is vtf file\r
@@ -3161,7 +3117,7 @@ Returns:
       }\r
 \r
       //\r
-      // Get the alignment of FFS file \r
+      // Get the alignment of FFS file\r
       //\r
       ReadFfsAlignment (&FfsHeader, &FfsAlignment);\r
       FfsAlignment = 1 << FfsAlignment;\r
@@ -3175,28 +3131,28 @@ Returns:
         CurrentOffset = (CurrentOffset + FfsHeaderSize + sizeof(EFI_FFS_FILE_HEADER) + FfsAlignment - 1) & ~(FfsAlignment - 1);\r
         CurrentOffset -= FfsHeaderSize;\r
       }\r
-         }\r
+    }\r
 \r
     //\r
     // Add ffs file size\r
     //\r
     if (FvInfoPtr->SizeofFvFiles[Index] > FfsFileSize) {\r
-       CurrentOffset += FvInfoPtr->SizeofFvFiles[Index];\r
+      CurrentOffset += FvInfoPtr->SizeofFvFiles[Index];\r
     } else {\r
-       CurrentOffset += FfsFileSize;\r
+      CurrentOffset += FfsFileSize;\r
     }\r
-       \r
+\r
     //\r
-    // Make next ffs file start at QWord Boundry\r
+    // Make next ffs file start at QWord Boundary\r
     //\r
     if (FvInfoPtr->IsPiFvImage) {\r
-       CurrentOffset = (CurrentOffset + EFI_FFS_FILE_HEADER_ALIGNMENT - 1) & ~(EFI_FFS_FILE_HEADER_ALIGNMENT - 1);\r
+      CurrentOffset = (CurrentOffset + EFI_FFS_FILE_HEADER_ALIGNMENT - 1) & ~(EFI_FFS_FILE_HEADER_ALIGNMENT - 1);\r
     }\r
   }\r
   CurrentOffset += VtfFileSize;\r
   DebugMsg (NULL, 0, 9, "FvImage size", "The calculated fv image size is 0x%x and the current set fv image size is 0x%x", (unsigned) CurrentOffset, (unsigned) FvInfoPtr->Size);\r
-  \r
-  if (FvInfoPtr->Size == 0) { \r
+\r
+  if (FvInfoPtr->Size == 0) {\r
     //\r
     // Update FvInfo data\r
     //\r
@@ -3211,7 +3167,7 @@ Returns:
     Error (NULL, 0, 3000, "Invalid", "the required fv image size 0x%x exceeds the set fv image size 0x%x", (unsigned) CurrentOffset, (unsigned) FvInfoPtr->Size);\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
   //\r
   // Set Fv Size Information\r
   //\r
@@ -3266,7 +3222,7 @@ Returns:
 \r
 EFI_STATUS\r
 GetChildFvFromFfs (\r
-  IN      FV_INFO               *FvInfo, \r
+  IN      FV_INFO               *FvInfo,\r
   IN      EFI_FFS_FILE_HEADER   *FfsFile,\r
   IN      UINTN                 XipOffset\r
   )\r
@@ -3278,7 +3234,7 @@ Routine Description:
   their base address to the parent image.\r
 \r
 Arguments:\r
-  FvInfo            A pointer to FV_INFO struture.\r
+  FvInfo            A pointer to FV_INFO structure.\r
   FfsFile           A pointer to Ffs file image that may contain FvImage.\r
   XipOffset         The offset address to the parent FvImage base.\r
 \r
@@ -3297,7 +3253,7 @@ Returns:
 \r
   for (Index = 1;; Index++) {\r
     //\r
-    // Find FV section \r
+    // Find FV section\r
     //\r
     Status = GetSectionByType (FfsFile, EFI_SECTION_FIRMWARE_VOLUME_IMAGE, Index, &SubFvSection);\r
     if (EFI_ERROR (Status)) {\r
@@ -3321,7 +3277,7 @@ Returns:
         return EFI_ABORTED;\r
       }\r
 \r
-      // machine type is ARM, set a flag so ARM reset vector procesing occurs\r
+      // machine type is ARM, set a flag so ARM reset vector processing occurs\r
       if ((MachineType == EFI_IMAGE_MACHINE_ARMT) || (MachineType == EFI_IMAGE_MACHINE_AARCH64)) {\r
         VerboseMsg("Located ARM/AArch64 SEC/PEI core in child FV");\r
         mArm = TRUE;\r
@@ -3339,9 +3295,9 @@ Returns:
 }\r
 \r
 EFI_STATUS\r
-FfsRebase ( \r
-  IN OUT  FV_INFO               *FvInfo, \r
-  IN      CHAR8                 *FileName,           \r
+FfsRebase (\r
+  IN OUT  FV_INFO               *FvInfo,\r
+  IN      CHAR8                 *FileName,\r
   IN OUT  EFI_FFS_FILE_HEADER   *FfsFile,\r
   IN      UINTN                 XipOffset,\r
   IN      FILE                  *FvMapFile\r
@@ -3354,8 +3310,8 @@ Routine Description:
   rebase any PE32 sections found in the file using the base address.\r
 \r
 Arguments:\r
-  \r
-  FvInfo            A pointer to FV_INFO struture.\r
+\r
+  FvInfo            A pointer to FV_INFO structure.\r
   FileName          Ffs File PathName\r
   FfsFile           A pointer to Ffs file image.\r
   XipOffset         The offset address to use for rebasing the XIP file image.\r
@@ -3373,7 +3329,7 @@ Returns:
 {\r
   EFI_STATUS                            Status;\r
   PE_COFF_LOADER_IMAGE_CONTEXT          ImageContext;\r
-  PE_COFF_LOADER_IMAGE_CONTEXT          OrigImageContext;  \r
+  PE_COFF_LOADER_IMAGE_CONTEXT          OrigImageContext;\r
   EFI_PHYSICAL_ADDRESS                  XipBase;\r
   EFI_PHYSICAL_ADDRESS                  NewPe32BaseAddress;\r
   UINTN                                 Index;\r
@@ -3392,7 +3348,7 @@ Returns:
   UINT32                                FfsHeaderSize;\r
   UINT32                                CurSecHdrSize;\r
 \r
-  Index              = 0;  \r
+  Index              = 0;\r
   MemoryImagePointer = NULL;\r
   TEImageHeader      = NULL;\r
   ImgHdr             = NULL;\r
@@ -3407,7 +3363,7 @@ Returns:
   if ((FvInfo->BaseAddress == 0) && (FvInfo->ForceRebase == -1)) {\r
     return EFI_SUCCESS;\r
   }\r
-  \r
+\r
   //\r
   // If ForceRebase Flag specified to FALSE, will always not take rebase action.\r
   //\r
@@ -3453,7 +3409,7 @@ Returns:
     // Init Value\r
     //\r
     NewPe32BaseAddress = 0;\r
-    \r
+\r
     //\r
     // Find Pe Image\r
     //\r
@@ -3484,7 +3440,7 @@ Returns:
     // Keep Image Context for PE image in FV\r
     //\r
     memcpy (&OrigImageContext, &ImageContext, sizeof (ImageContext));\r
-    \r
+\r
     //\r
     // Get File PdbPointer\r
     //\r
@@ -3510,17 +3466,22 @@ Returns:
           //\r
           // Xip module has the same section alignment and file alignment.\r
           //\r
-          Error (NULL, 0, 3000, "Invalid", "Section-Alignment and File-Alignment do not match : %s.", FileName);\r
+          Error (NULL, 0, 3000, "Invalid", "PE image Section-Alignment and File-Alignment do not match : %s.", FileName);\r
           return EFI_ABORTED;\r
         }\r
         //\r
-        // PeImage has no reloc section. It will try to get reloc data from the original EFI image. \r
+        // PeImage has no reloc section. It will try to get reloc data from the original EFI image.\r
         //\r
         if (ImageContext.RelocationsStripped) {\r
           //\r
-          // Construct the original efi file Name \r
+          // Construct the original efi file Name\r
           //\r
-          strcpy (PeFileName, FileName);\r
+          if (strlen (FileName) >= MAX_LONG_FILE_PATH) {\r
+            Error (NULL, 0, 2000, "Invalid", "The file name %s is too long.", FileName);\r
+            return EFI_ABORTED;\r
+          }\r
+          strncpy (PeFileName, FileName, MAX_LONG_FILE_PATH - 1);\r
+          PeFileName[MAX_LONG_FILE_PATH - 1] = 0;\r
           Cptr = PeFileName + strlen (PeFileName);\r
           while (*Cptr != '.') {\r
             Cptr --;\r
@@ -3583,7 +3544,7 @@ Returns:
           //\r
           // Xip module has the same section alignment and file alignment.\r
           //\r
-          Error (NULL, 0, 3000, "Invalid", "Section-Alignment and File-Alignment do not match : %s.", FileName);\r
+          Error (NULL, 0, 3000, "Invalid", "PE image Section-Alignment and File-Alignment do not match : %s.", FileName);\r
           return EFI_ABORTED;\r
         }\r
         NewPe32BaseAddress = XipBase + (UINTN) CurrentPe32Section.Pe32Section + CurSecHdrSize - (UINTN)FfsFile;\r
@@ -3595,7 +3556,7 @@ Returns:
         //\r
         return EFI_SUCCESS;\r
     }\r
-    \r
+\r
     //\r
     // Relocation doesn't exist\r
     //\r
@@ -3617,14 +3578,14 @@ Returns:
     }\r
     memset ((VOID *) MemoryImagePointer, 0, (UINTN) ImageContext.ImageSize + ImageContext.SectionAlignment);\r
     ImageContext.ImageAddress = ((UINTN) MemoryImagePointer + ImageContext.SectionAlignment - 1) & (~((UINTN) ImageContext.SectionAlignment - 1));\r
-    \r
+\r
     Status =  PeCoffLoaderLoadImage (&ImageContext);\r
     if (EFI_ERROR (Status)) {\r
       Error (NULL, 0, 3000, "Invalid", "LocateImage() call failed on rebase of %s", FileName);\r
       free ((VOID *) MemoryImagePointer);\r
       return Status;\r
     }\r
-         \r
+\r
     ImageContext.DestinationAddress = NewPe32BaseAddress;\r
     Status                          = PeCoffLoaderRelocateImage (&ImageContext);\r
     if (EFI_ERROR (Status)) {\r
@@ -3638,15 +3599,15 @@ Returns:
     //\r
     SectionHeader = (EFI_IMAGE_SECTION_HEADER *) (\r
                        (UINTN) ImgHdr +\r
-                       sizeof (UINT32) + \r
-                       sizeof (EFI_IMAGE_FILE_HEADER) +  \r
+                       sizeof (UINT32) +\r
+                       sizeof (EFI_IMAGE_FILE_HEADER) +\r
                        ImgHdr->Pe32.FileHeader.SizeOfOptionalHeader\r
                        );\r
-    \r
+\r
     for (Index = 0; Index < ImgHdr->Pe32.FileHeader.NumberOfSections; Index ++, SectionHeader ++) {\r
       CopyMem (\r
-        (UINT8 *) CurrentPe32Section.Pe32Section + CurSecHdrSize + SectionHeader->PointerToRawData, \r
-        (VOID*) (UINTN) (ImageContext.ImageAddress + SectionHeader->VirtualAddress), \r
+        (UINT8 *) CurrentPe32Section.Pe32Section + CurSecHdrSize + SectionHeader->PointerToRawData,\r
+        (VOID*) (UINTN) (ImageContext.ImageAddress + SectionHeader->VirtualAddress),\r
         SectionHeader->SizeOfRawData\r
         );\r
     }\r
@@ -3657,7 +3618,7 @@ Returns:
       free (PeFileBuffer);\r
       PeFileBuffer = NULL;\r
     }\r
-    \r
+\r
     //\r
     // Update Image Base Address\r
     //\r
@@ -3712,13 +3673,13 @@ Returns:
     //\r
     return EFI_SUCCESS;\r
   }\r
-  \r
+\r
   //\r
   // Now process TE sections\r
   //\r
   for (Index = 1;; Index++) {\r
     NewPe32BaseAddress = 0;\r
-    \r
+\r
     //\r
     // Find Te Image\r
     //\r
@@ -3728,7 +3689,7 @@ Returns:
     }\r
 \r
     CurSecHdrSize = GetSectionHeaderLength(CurrentPe32Section.CommonHeader);\r
-    \r
+\r
     //\r
     // Calculate the TE base address, the FFS file base plus the offset of the TE section less the size stripped off\r
     // by GenTEImage\r
@@ -3773,9 +3734,14 @@ Returns:
     //\r
     if (ImageContext.RelocationsStripped) {\r
       //\r
-      // Construct the original efi file name \r
+      // Construct the original efi file name\r
       //\r
-      strcpy (PeFileName, FileName);\r
+      if (strlen (FileName) >= MAX_LONG_FILE_PATH) {\r
+        Error (NULL, 0, 2000, "Invalid", "The file name %s is too long.", FileName);\r
+        return EFI_ABORTED;\r
+      }\r
+      strncpy (PeFileName, FileName, MAX_LONG_FILE_PATH - 1);\r
+      PeFileName[MAX_LONG_FILE_PATH - 1] = 0;\r
       Cptr = PeFileName + strlen (PeFileName);\r
       while (*Cptr != '.') {\r
         Cptr --;\r
@@ -3857,7 +3823,7 @@ Returns:
     }\r
     //\r
     // Reloacate TeImage\r
-    // \r
+    //\r
     ImageContext.DestinationAddress = NewPe32BaseAddress;\r
     Status                          = PeCoffLoaderRelocateImage (&ImageContext);\r
     if (EFI_ERROR (Status)) {\r
@@ -3865,7 +3831,7 @@ Returns:
       free ((VOID *) MemoryImagePointer);\r
       return Status;\r
     }\r
-    \r
+\r
     //\r
     // Copy the relocated image into raw image file.\r
     //\r
@@ -3873,19 +3839,19 @@ Returns:
     for (Index = 0; Index < TEImageHeader->NumberOfSections; Index ++, SectionHeader ++) {\r
       if (!ImageContext.IsTeImage) {\r
         CopyMem (\r
-          (UINT8 *) TEImageHeader + sizeof (EFI_TE_IMAGE_HEADER) - TEImageHeader->StrippedSize + SectionHeader->PointerToRawData, \r
-          (VOID*) (UINTN) (ImageContext.ImageAddress + SectionHeader->VirtualAddress), \r
+          (UINT8 *) TEImageHeader + sizeof (EFI_TE_IMAGE_HEADER) - TEImageHeader->StrippedSize + SectionHeader->PointerToRawData,\r
+          (VOID*) (UINTN) (ImageContext.ImageAddress + SectionHeader->VirtualAddress),\r
           SectionHeader->SizeOfRawData\r
           );\r
       } else {\r
         CopyMem (\r
-          (UINT8 *) TEImageHeader + sizeof (EFI_TE_IMAGE_HEADER) - TEImageHeader->StrippedSize + SectionHeader->PointerToRawData, \r
-          (VOID*) (UINTN) (ImageContext.ImageAddress + sizeof (EFI_TE_IMAGE_HEADER) - TEImageHeader->StrippedSize + SectionHeader->VirtualAddress), \r
+          (UINT8 *) TEImageHeader + sizeof (EFI_TE_IMAGE_HEADER) - TEImageHeader->StrippedSize + SectionHeader->PointerToRawData,\r
+          (VOID*) (UINTN) (ImageContext.ImageAddress + sizeof (EFI_TE_IMAGE_HEADER) - TEImageHeader->StrippedSize + SectionHeader->VirtualAddress),\r
           SectionHeader->SizeOfRawData\r
           );\r
       }\r
     }\r
-    \r
+\r
     //\r
     // Free the allocated memory resource\r
     //\r
@@ -3895,7 +3861,7 @@ Returns:
       free (PeFileBuffer);\r
       PeFileBuffer = NULL;\r
     }\r
-    \r
+\r
     //\r
     // Update Image Base Address\r
     //\r
@@ -3926,14 +3892,14 @@ Returns:
     }\r
 \r
     WriteMapFile (\r
-      FvMapFile, \r
-      PdbPointer, \r
+      FvMapFile,\r
+      PdbPointer,\r
       FfsFile,\r
-      NewPe32BaseAddress, \r
+      NewPe32BaseAddress,\r
       &OrigImageContext\r
       );\r
   }\r
\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -3981,7 +3947,7 @@ Returns:
     // Get Pad file size.\r
     //\r
     FileLength = GetFfsFileLength(PadFile);\r
-    FileLength = (FileLength + EFI_FFS_FILE_HEADER_ALIGNMENT - 1) & ~(EFI_FFS_FILE_HEADER_ALIGNMENT - 1); \r
+    FileLength = (FileLength + EFI_FFS_FILE_HEADER_ALIGNMENT - 1) & ~(EFI_FFS_FILE_HEADER_ALIGNMENT - 1);\r
     //\r
     // FixPoint must be align on 0x1000 relative to FvImage Header\r
     //\r
@@ -3994,7 +3960,7 @@ Returns:
       FixPoint += 0x1000;\r
     }\r
     FixPoint -= 0x1000;\r
-    \r
+\r
     if ((UINTN) FixPoint < ((UINTN) PadFile + GetFfsHeaderLength(PadFile))) {\r
       //\r
       // No alignment FixPoint in this Pad File.\r
@@ -4002,7 +3968,7 @@ Returns:
       continue;\r
     }\r
 \r
-    if ((UINTN) FvImage->Eof - (UINTN)FixPoint <= 0x20000) {    \r
+    if ((UINTN) FvImage->Eof - (UINTN)FixPoint <= 0x20000) {\r
       //\r
       // Find the position to place ApResetVector\r
       //\r
@@ -4010,7 +3976,7 @@ Returns:
       return EFI_SUCCESS;\r
     }\r
   }\r
-  \r
+\r
   return EFI_NOT_FOUND;\r
 }\r
 \r
@@ -4089,7 +4055,7 @@ Returns:
         CapInfo->Flags |= CAPSULE_FLAGS_INITIATE_RESET;\r
       }\r
     } else if (strstr (Value, "PersistAcrossReset") != NULL) {\r
-      CapInfo->Flags |= CAPSULE_FLAGS_PERSIST_ACROSS_RESET; \r
+      CapInfo->Flags |= CAPSULE_FLAGS_PERSIST_ACROSS_RESET;\r
       if (strstr (Value, "InitiateReset") != NULL) {\r
         CapInfo->Flags |= CAPSULE_FLAGS_INITIATE_RESET;\r
       }\r
@@ -4142,12 +4108,12 @@ Returns:
       // Add the file\r
       //\r
       strcpy (CapInfo->CapFiles[Index], Value);\r
-      DebugMsg (NULL, 0, 9, "Capsule component file", "the %uth file name is %s", (unsigned) Index, CapInfo->CapFiles[Index]); \r
+      DebugMsg (NULL, 0, 9, "Capsule component file", "the %uth file name is %s", (unsigned) Index, CapInfo->CapFiles[Index]);\r
     } else {\r
       break;\r
     }\r
   }\r
-  \r
+\r
   if (Index == 0) {\r
     Warning (NULL, 0, 0, "Capsule components are not specified.", NULL);\r
   }\r
@@ -4190,7 +4156,7 @@ Returns:
   UINT32                Index;\r
   FILE                  *fpin, *fpout;\r
   EFI_STATUS            Status;\r
-  \r
+\r
   if (InfFileImage != NULL) {\r
     //\r
     // Initialize file structures\r
@@ -4198,7 +4164,7 @@ Returns:
     InfMemoryFile.FileImage           = InfFileImage;\r
     InfMemoryFile.CurrentFilePointer  = InfFileImage;\r
     InfMemoryFile.Eof                 = InfFileImage + InfFileSize;\r
-  \r
+\r
     //\r
     // Parse the Cap inf file for header information\r
     //\r
@@ -4207,7 +4173,7 @@ Returns:
       return Status;\r
     }\r
   }\r
-  \r
+\r
   if (mCapDataInfo.HeaderSize == 0) {\r
     //\r
     // make header size align 16 bytes.\r
@@ -4220,16 +4186,16 @@ Returns:
     Error (NULL, 0, 2000, "Invalid parameter", "The specified HeaderSize cannot be less than the size of EFI_CAPSULE_HEADER.");\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
   if (CapFileName == NULL && mCapDataInfo.CapName[0] != '\0') {\r
     CapFileName = mCapDataInfo.CapName;\r
   }\r
-  \r
+\r
   if (CapFileName == NULL) {\r
     Error (NULL, 0, 2001, "Missing required argument", "Output Capsule file name");\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
   //\r
   // Set Default Capsule Guid value\r
   //\r
@@ -4267,7 +4233,7 @@ Returns:
   // Initialize the capsule header to zero\r
   //\r
   memset (CapBuffer, 0, mCapDataInfo.HeaderSize);\r
-  \r
+\r
   //\r
   // create capsule header and get capsule body\r
   //\r
@@ -4293,7 +4259,7 @@ Returns:
     Index ++;\r
     CapSize += FileSize;\r
   }\r
-  \r
+\r
   //\r
   // write capsule data into the output file\r
   //\r
@@ -4307,7 +4273,7 @@ Returns:
   fwrite (CapBuffer, 1, CapSize, fpout);\r
   fclose (fpout);\r
   free (CapBuffer);\r
-  \r
+\r
   VerboseMsg ("The size of the generated capsule image is %u bytes", (unsigned) CapSize);\r
 \r
   return EFI_SUCCESS;\r