]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/GenFw/GenFw.c
There is a limitation on WINDOWS OS for the length of entire file path can’t be large...
[mirror_edk2.git] / BaseTools / Source / C / GenFw / GenFw.c
index e41fe6e82ba78091124d654f7ad1d6ba104f822b..56543b411b76d49be54beb982afa1eb91a4240bd 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2014, 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
@@ -62,33 +62,10 @@ Abstract:
 \r
 #define HII_RESOURCE_SECTION_INDEX  1\r
 #define HII_RESOURCE_SECTION_NAME   "HII"\r
-//\r
-// Action for this tool.\r
-//\r
-#define FW_DUMMY_IMAGE                0\r
-#define FW_EFI_IMAGE                  1\r
-#define FW_TE_IMAGE                   2\r
-#define FW_ACPI_IMAGE                 3\r
-#define FW_BIN_IMAGE                  4\r
-#define FW_ZERO_DEBUG_IMAGE           5\r
-#define FW_SET_STAMP_IMAGE            6\r
-#define FW_MCI_IMAGE                  7\r
-#define FW_MERGE_IMAGE                8\r
-#define FW_RELOC_STRIPEED_IMAGE       9\r
-#define FW_HII_PACKAGE_LIST_RCIMAGE   10\r
-#define FW_HII_PACKAGE_LIST_BINIMAGE  11\r
-#define FW_REBASE_IMAGE               12\r
-#define FW_SET_ADDRESS_IMAGE          13\r
-\r
-#define DUMP_TE_HEADER  0x11\r
 \r
 #define DEFAULT_MC_PAD_BYTE_VALUE  0xFF\r
 #define DEFAULT_MC_ALIGNMENT       16\r
 \r
-#ifndef _MAX_PATH\r
-#define _MAX_PATH 500\r
-#endif\r
-\r
 #define STATUS_IGNORE 0xA\r
 //\r
 // Structure definition for a microcode header\r
@@ -121,6 +98,7 @@ static const char *gHiiPackageRCFileHeader[] = {
 CHAR8  *mInImageName;\r
 UINT32 mImageTimeStamp = 0;\r
 UINT32 mImageSize = 0;\r
+UINT32 mOutImageType = FW_DUMMY_IMAGE;\r
 \r
 \r
 STATIC\r
@@ -165,7 +143,7 @@ Returns:
 \r
 --*/\r
 {\r
-  fprintf (stdout, "%s Version %d.%d\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION);\r
+  fprintf (stdout, "%s Version %d.%d %s \n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);\r
 }\r
 \r
 STATIC\r
@@ -197,7 +175,7 @@ Returns:
   //\r
   // Copyright declaration\r
   //\r
-  fprintf (stdout, "Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.\n\n");\r
+  fprintf (stdout, "Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.\n\n");\r
 \r
   //\r
   // Details Option\r
@@ -676,7 +654,10 @@ PeCoffConvertImageToXip (
         SectionHeader->SizeOfRawData\r
         );\r
     }\r
-    SectionHeader->SizeOfRawData = SectionHeader->Misc.VirtualSize;\r
+    //\r
+    // Make the size of raw data in section header alignment.\r
+    //\r
+    SectionHeader->SizeOfRawData = (SectionHeader->Misc.VirtualSize + PeHdr->Pe32.OptionalHeader.FileAlignment - 1) & (~(PeHdr->Pe32.OptionalHeader.FileAlignment - 1));\r
     SectionHeader->PointerToRawData = SectionHeader->VirtualAddress;\r
   }\r
 \r
@@ -1080,7 +1061,6 @@ Returns:
   char                             *OutImageName;\r
   char                             *ModuleType;\r
   CHAR8                            *TimeStamp;\r
-  UINT32                           OutImageType;\r
   FILE                             *fpIn;\r
   FILE                             *fpOut;\r
   FILE                             *fpInOut;\r
@@ -1147,7 +1127,6 @@ Returns:
   mInImageName      = NULL;\r
   OutImageName      = NULL;\r
   ModuleType        = NULL;\r
-  OutImageType      = FW_DUMMY_IMAGE;\r
   Type              = 0;\r
   Status            = STATUS_SUCCESS;\r
   FileBuffer        = NULL;\r
@@ -1221,8 +1200,8 @@ Returns:
         goto Finish;\r
       }\r
       ModuleType = argv[1];\r
-      if (OutImageType != FW_TE_IMAGE) {\r
-        OutImageType = FW_EFI_IMAGE;\r
+      if (mOutImageType != FW_TE_IMAGE) {\r
+        mOutImageType = FW_EFI_IMAGE;\r
       }\r
       argc -= 2;\r
       argv += 2;\r
@@ -1230,49 +1209,49 @@ Returns:
     }\r
 \r
     if ((stricmp (argv[0], "-l") == 0) || (stricmp (argv[0], "--stripped") == 0)) {\r
-      OutImageType = FW_RELOC_STRIPEED_IMAGE;\r
+      mOutImageType = FW_RELOC_STRIPEED_IMAGE;\r
       argc --;\r
       argv ++;\r
       continue;\r
     }\r
 \r
     if ((stricmp (argv[0], "-c") == 0) || (stricmp (argv[0], "--acpi") == 0)) {\r
-      OutImageType = FW_ACPI_IMAGE;\r
+      mOutImageType = FW_ACPI_IMAGE;\r
       argc --;\r
       argv ++;\r
       continue;\r
     }\r
 \r
     if ((stricmp (argv[0], "-t") == 0) || (stricmp (argv[0], "--terse") == 0)) {\r
-      OutImageType = FW_TE_IMAGE;\r
+      mOutImageType = FW_TE_IMAGE;\r
       argc --;\r
       argv ++;\r
       continue;\r
     }\r
 \r
     if ((stricmp (argv[0], "-u") == 0) || (stricmp (argv[0], "--dump") == 0)) {\r
-      OutImageType = DUMP_TE_HEADER;\r
+      mOutImageType = DUMP_TE_HEADER;\r
       argc --;\r
       argv ++;\r
       continue;\r
     }\r
 \r
     if ((stricmp (argv[0], "-b") == 0) || (stricmp (argv[0], "--exe2bin") == 0)) {\r
-      OutImageType = FW_BIN_IMAGE;\r
+      mOutImageType = FW_BIN_IMAGE;\r
       argc --;\r
       argv ++;\r
       continue;\r
     }\r
 \r
     if ((stricmp (argv[0], "-z") == 0) || (stricmp (argv[0], "--zero") == 0)) {\r
-      OutImageType = FW_ZERO_DEBUG_IMAGE;\r
+      mOutImageType = FW_ZERO_DEBUG_IMAGE;\r
       argc --;\r
       argv ++;\r
       continue;\r
     }\r
 \r
     if ((stricmp (argv[0], "-s") == 0) || (stricmp (argv[0], "--stamp") == 0)) {\r
-      OutImageType = FW_SET_STAMP_IMAGE;\r
+      mOutImageType = FW_SET_STAMP_IMAGE;\r
       if (argv[1] == NULL || argv[1][0] == '-') {\r
         Error (NULL, 0, 1003, "Invalid option value", "time stamp is missing for -s option");\r
         goto Finish;\r
@@ -1305,14 +1284,14 @@ Returns:
     }\r
 \r
     if ((stricmp (argv[0], "-m") == 0) || (stricmp (argv[0], "--mcifile") == 0)) {\r
-      OutImageType = FW_MCI_IMAGE;\r
+      mOutImageType = FW_MCI_IMAGE;\r
       argc --;\r
       argv ++;\r
       continue;\r
     }\r
 \r
     if ((stricmp (argv[0], "-j") == 0) || (stricmp (argv[0], "--join") == 0)) {\r
-      OutImageType = FW_MERGE_IMAGE;\r
+      mOutImageType = FW_MERGE_IMAGE;\r
       argc --;\r
       argv ++;\r
       continue;\r
@@ -1341,7 +1320,7 @@ Returns:
         Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);\r
         goto Finish;\r
       }\r
-      OutImageType = FW_REBASE_IMAGE;\r
+      mOutImageType = FW_REBASE_IMAGE;\r
       NewBaseAddress = (UINT64) Temp64;\r
       argc -= 2;\r
       argv += 2;\r
@@ -1360,7 +1339,7 @@ Returns:
         Error (NULL, 0, 1003, "Invalid option value", "%s = %s", argv[0], argv[1]);\r
         goto Finish;\r
       }\r
-      OutImageType = FW_SET_ADDRESS_IMAGE;\r
+      mOutImageType = FW_SET_ADDRESS_IMAGE;\r
       NewBaseAddress = (UINT64) Temp64;\r
       argc -= 2;\r
       argv += 2;\r
@@ -1423,14 +1402,14 @@ Returns:
     }\r
 \r
     if (stricmp (argv[0], "--hiipackage") == 0) {\r
-      OutImageType = FW_HII_PACKAGE_LIST_RCIMAGE;\r
+      mOutImageType = FW_HII_PACKAGE_LIST_RCIMAGE;\r
       argc --;\r
       argv ++;\r
       continue;\r
     }\r
 \r
     if (stricmp (argv[0], "--hiibinpackage") == 0) {\r
-      OutImageType = FW_HII_PACKAGE_LIST_BINIMAGE;\r
+      mOutImageType = FW_HII_PACKAGE_LIST_BINIMAGE;\r
       argc --;\r
       argv ++;\r
       continue;\r
@@ -1475,7 +1454,7 @@ Returns:
 \r
   VerboseMsg ("%s tool start.", UTILITY_NAME);\r
 \r
-  if (OutImageType == FW_DUMMY_IMAGE) {\r
+  if (mOutImageType == FW_DUMMY_IMAGE) {\r
     Error (NULL, 0, 1001, "Missing option", "No create file action specified; pls specify -e, -c or -t option to create efi image, or acpi table or TeImage!");\r
     if (ReplaceFlag) {\r
       Error (NULL, 0, 1001, "Missing option", "-r option is not supported as the independent option. It can be used together with other create file option specified at the above.");\r
@@ -1494,7 +1473,7 @@ Returns:
   //\r
   // Combine MciBinary files to one file\r
   //\r
-  if ((OutImageType == FW_MERGE_IMAGE) && ReplaceFlag) {\r
+  if ((mOutImageType == FW_MERGE_IMAGE) && ReplaceFlag) {\r
     Error (NULL, 0, 1002, "Conflicting option", "-r replace option cannot be used with -j merge files option.");\r
     goto Finish;\r
   }\r
@@ -1502,12 +1481,12 @@ Returns:
   //\r
   // Combine HiiBinary packages to a single package list\r
   //\r
-  if ((OutImageType == FW_HII_PACKAGE_LIST_RCIMAGE) && ReplaceFlag) {\r
+  if ((mOutImageType == FW_HII_PACKAGE_LIST_RCIMAGE) && ReplaceFlag) {\r
     Error (NULL, 0, 1002, "Conflicting option", "-r replace option cannot be used with --hiipackage merge files option.");\r
     goto Finish;\r
   }\r
 \r
-  if ((OutImageType == FW_HII_PACKAGE_LIST_BINIMAGE) && ReplaceFlag) {\r
+  if ((mOutImageType == FW_HII_PACKAGE_LIST_BINIMAGE) && ReplaceFlag) {\r
     Error (NULL, 0, 1002, "Conflicting option", "-r replace option cannot be used with --hiibinpackage merge files option.");\r
     goto Finish;\r
   }\r
@@ -1521,7 +1500,7 @@ Returns:
   //\r
   // Action will be taken for the input file.\r
   //\r
-  switch (OutImageType) {\r
+  switch (mOutImageType) {\r
   case FW_EFI_IMAGE:\r
     VerboseMsg ("Create efi image on module type %s based on the input PE image.", ModuleType);\r
     break;\r
@@ -1576,7 +1555,7 @@ Returns:
   // Open output file and Write image into the output file.\r
   //\r
   if (OutImageName != NULL) {\r
-    fpOut = fopen (OutImageName, "rb");\r
+    fpOut = fopen (LongFilePath (OutImageName), "rb");\r
     if (fpOut != NULL) {\r
       //\r
       // Get Output file time stamp\r
@@ -1599,7 +1578,7 @@ Returns:
       fpOut = NULL;\r
     }\r
     VerboseMsg ("Output file name is %s", OutImageName);\r
-  } else if (!ReplaceFlag && OutImageType != DUMP_TE_HEADER) {\r
+  } else if (!ReplaceFlag && mOutImageType != DUMP_TE_HEADER) {\r
     Error (NULL, 0, 1001, "Missing option", "output file");\r
     goto Finish;\r
   }\r
@@ -1607,7 +1586,7 @@ Returns:
   //\r
   // Open input file and read file data into file buffer.\r
   //\r
-  fpIn = fopen (mInImageName, "rb");\r
+  fpIn = fopen (LongFilePath (mInImageName), "rb");\r
   if (fpIn == NULL) {\r
     Error (NULL, 0, 0001, "Error opening file", mInImageName);\r
     goto Finish;\r
@@ -1634,11 +1613,11 @@ Returns:
   //\r
   // Combine multi binary HII package files.\r
   //\r
-  if (OutImageType == FW_HII_PACKAGE_LIST_RCIMAGE || OutImageType == FW_HII_PACKAGE_LIST_BINIMAGE) {\r
+  if (mOutImageType == FW_HII_PACKAGE_LIST_RCIMAGE || mOutImageType == FW_HII_PACKAGE_LIST_BINIMAGE) {\r
     //\r
     // Open output file handle.\r
     //\r
-    fpOut = fopen (OutImageName, "wb");\r
+    fpOut = fopen (LongFilePath (OutImageName), "wb");\r
     if (!fpOut) {\r
       Error (NULL, 0, 0001, "Error opening output file", OutImageName);\r
       goto Finish;\r
@@ -1648,7 +1627,7 @@ Returns:
     //\r
     HiiPackageListHeader.PackageLength = sizeof (EFI_HII_PACKAGE_LIST_HEADER);\r
     for (Index = 0; Index < InputFileNum; Index ++) {\r
-      fpIn = fopen (InputFileName [Index], "rb");\r
+      fpIn = fopen (LongFilePath (InputFileName [Index]), "rb");\r
       if (fpIn == NULL) {\r
         Error (NULL, 0, 0001, "Error opening file", InputFileName [Index]);\r
         goto Finish;\r
@@ -1694,7 +1673,7 @@ Returns:
     memcpy (HiiPackageListBuffer, &HiiPackageListHeader, sizeof (HiiPackageListHeader));\r
     HiiPackageDataPointer = HiiPackageListBuffer + sizeof (HiiPackageListHeader);\r
     for (Index = 0; Index < InputFileNum; Index ++) {\r
-      fpIn = fopen (InputFileName [Index], "rb");\r
+      fpIn = fopen (LongFilePath (InputFileName [Index]), "rb");\r
       if (fpIn == NULL) {\r
         Error (NULL, 0, 0001, "Error opening file", InputFileName [Index]);\r
         free (HiiPackageListBuffer);\r
@@ -1711,7 +1690,7 @@ Returns:
     //\r
     // write the hii package into the binary package list file with the resource section header\r
     //\r
-    if (OutImageType == FW_HII_PACKAGE_LIST_BINIMAGE) {\r
+    if (mOutImageType == FW_HII_PACKAGE_LIST_BINIMAGE) {\r
       //\r
       // Create the resource section header\r
       //\r
@@ -1735,7 +1714,7 @@ Returns:
     //\r
     // write the hii package into the text package list rc file.\r
     //\r
-    if (OutImageType == FW_HII_PACKAGE_LIST_RCIMAGE) {\r
+    if (mOutImageType == FW_HII_PACKAGE_LIST_RCIMAGE) {\r
       for (Index = 0; gHiiPackageRCFileHeader[Index] != NULL; Index++) {\r
         fprintf (fpOut, "%s\n", gHiiPackageRCFileHeader[Index]);\r
       }\r
@@ -1770,17 +1749,17 @@ Returns:
   //\r
   // Combine MciBinary files to one file\r
   //\r
-  if (OutImageType == FW_MERGE_IMAGE) {\r
+  if (mOutImageType == FW_MERGE_IMAGE) {\r
     //\r
     // Open output file handle.\r
     //\r
-    fpOut = fopen (OutImageName, "wb");\r
+    fpOut = fopen (LongFilePath (OutImageName), "wb");\r
     if (!fpOut) {\r
       Error (NULL, 0, 0001, "Error opening output file", OutImageName);\r
       goto Finish;\r
     }\r
     for (Index = 0; Index < InputFileNum; Index ++) {\r
-      fpIn = fopen (InputFileName [Index], "rb");\r
+      fpIn = fopen (LongFilePath (InputFileName [Index]), "rb");\r
       if (!fpIn) {\r
         Error (NULL, 0, 0001, "Error opening file", InputFileName [Index]);\r
         goto Finish;\r
@@ -1821,8 +1800,8 @@ Returns:
   //\r
   // Convert MicroCode.txt file to MicroCode.bin file\r
   //\r
-  if (OutImageType == FW_MCI_IMAGE) {\r
-    fpIn = fopen (mInImageName, "r");\r
+  if (mOutImageType == FW_MCI_IMAGE) {\r
+    fpIn = fopen (LongFilePath (mInImageName), "r");\r
     if (fpIn == NULL) {\r
       Error (NULL, 0, 0001, "Error opening file", mInImageName);\r
       goto Finish;\r
@@ -1935,7 +1914,7 @@ Returns:
   //\r
   // Dump TeImage Header into output file.\r
   //\r
-  if (OutImageType == DUMP_TE_HEADER) {\r
+  if (mOutImageType == DUMP_TE_HEADER) {\r
     memcpy (&TEImageHeader, FileBuffer, sizeof (TEImageHeader));\r
     if (TEImageHeader.Signature != EFI_TE_IMAGE_HEADER_SIGNATURE) {\r
       Error (NULL, 0, 3000, "Invalid", "TE header signature of file %s is not correct.", mInImageName);\r
@@ -1945,14 +1924,14 @@ Returns:
     // Open the output file handle.\r
     //\r
     if (ReplaceFlag) {\r
-      fpInOut = fopen (mInImageName, "wb");\r
+      fpInOut = fopen (LongFilePath (mInImageName), "wb");\r
       if (fpInOut == NULL) {\r
         Error (NULL, 0, 0001, "Error opening file", mInImageName);\r
         goto Finish;\r
       }\r
     } else {\r
       if (OutImageName != NULL) {\r
-        fpOut = fopen (OutImageName, "wb");\r
+        fpOut = fopen (LongFilePath (OutImageName), "wb");\r
       } else {\r
         fpOut = stdout;\r
       }\r
@@ -1994,12 +1973,12 @@ Returns:
   // Following code to convert dll to efi image or te image.\r
   // Get new image type\r
   //\r
-  if ((OutImageType == FW_EFI_IMAGE) || (OutImageType == FW_TE_IMAGE)) {\r
+  if ((mOutImageType == FW_EFI_IMAGE) || (mOutImageType == FW_TE_IMAGE)) {\r
     if (ModuleType == NULL) {\r
-      if (OutImageType == FW_EFI_IMAGE) {\r
+      if (mOutImageType == FW_EFI_IMAGE) {\r
         Error (NULL, 0, 1001, "Missing option", "EFI_FILETYPE");\r
         goto Finish;\r
-      } else if (OutImageType == FW_TE_IMAGE) {\r
+      } else if (mOutImageType == FW_TE_IMAGE) {\r
         //\r
         // Default TE Image Type is Boot service driver\r
         //\r
@@ -2047,7 +2026,7 @@ Returns:
   }\r
 \r
   //\r
-  // Convert EFL image to PeImage\r
+  // Convert ELF image to PeImage\r
   //\r
   if (IsElfHeader(FileBuffer)) {\r
     VerboseMsg ("Convert %s from ELF to PE/COFF.", mInImageName);\r
@@ -2066,7 +2045,7 @@ Returns:
   //\r
   // Remove reloc section from PE or TE image\r
   //\r
-  if (OutImageType == FW_RELOC_STRIPEED_IMAGE) {\r
+  if (mOutImageType == FW_RELOC_STRIPEED_IMAGE) {\r
     //\r
     // Check TeImage\r
     //\r
@@ -2184,7 +2163,7 @@ Returns:
   //\r
   // Set new base address into image\r
   //\r
-  if (OutImageType == FW_REBASE_IMAGE || OutImageType == FW_SET_ADDRESS_IMAGE) {\r
+  if (mOutImageType == FW_REBASE_IMAGE || mOutImageType == FW_SET_ADDRESS_IMAGE) {\r
     if ((PeHdr->Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) && (PeHdr->Pe32.FileHeader.Machine != IMAGE_FILE_MACHINE_IA64)) {\r
       if (NewBaseAddress >= 0x100000000ULL) {\r
         Error (NULL, 0, 3000, "Invalid", "New base address is larger than 4G for 32bit PE image");\r
@@ -2198,7 +2177,7 @@ Returns:
       //\r
       NewBaseAddress = (UINT64) (0 - NewBaseAddress);\r
     }\r
-    if (OutImageType == FW_REBASE_IMAGE) {\r
+    if (mOutImageType == FW_REBASE_IMAGE) {\r
       Status = RebaseImage (mInImageName, FileBuffer, NewBaseAddress);\r
     } else {\r
       Status = SetAddressToSectionHeader (mInImageName, FileBuffer, NewBaseAddress);\r
@@ -2221,7 +2200,7 @@ Returns:
   //\r
   // Extract bin data from Pe image.\r
   //\r
-  if (OutImageType == FW_BIN_IMAGE) {\r
+  if (mOutImageType == FW_BIN_IMAGE) {\r
     if (FileLength < PeHdr->Pe32.OptionalHeader.SizeOfHeaders) {\r
       Error (NULL, 0, 3000, "Invalid", "FileSize of %s is not a legal size.", mInImageName);\r
       goto Finish;\r
@@ -2230,7 +2209,7 @@ Returns:
     // Output bin data from exe file\r
     //\r
     FileLength = FileLength - PeHdr->Pe32.OptionalHeader.SizeOfHeaders;\r
-    memcpy (FileBuffer, FileBuffer + PeHdr->Pe32.OptionalHeader.SizeOfHeaders, FileLength);\r
+    memmove (FileBuffer, FileBuffer + PeHdr->Pe32.OptionalHeader.SizeOfHeaders, FileLength);\r
     VerboseMsg ("the size of output file is %u bytes", (unsigned) FileLength);\r
     goto WriteFile;\r
   }\r
@@ -2238,7 +2217,7 @@ Returns:
   //\r
   // Zero Debug Information of Pe Image\r
   //\r
-  if (OutImageType == FW_ZERO_DEBUG_IMAGE) {\r
+  if (mOutImageType == FW_ZERO_DEBUG_IMAGE) {\r
     Status = ZeroDebugData (FileBuffer, TRUE);\r
     if (EFI_ERROR (Status)) {\r
       Error (NULL, 0, 3000, "Invalid", "Zero DebugData Error status is 0x%x", (int) Status);\r
@@ -2255,7 +2234,7 @@ Returns:
   //\r
   // Set Time Stamp of Pe Image\r
   //\r
-  if (OutImageType == FW_SET_STAMP_IMAGE) {\r
+  if (mOutImageType == FW_SET_STAMP_IMAGE) {\r
     Status = SetStamp (FileBuffer, TimeStamp);\r
     if (EFI_ERROR (Status)) {\r
       goto Finish;\r
@@ -2271,7 +2250,7 @@ Returns:
   //\r
   // Extract acpi data from pe image.\r
   //\r
-  if (OutImageType == FW_ACPI_IMAGE) {\r
+  if (mOutImageType == FW_ACPI_IMAGE) {\r
     SectionHeader = (EFI_IMAGE_SECTION_HEADER *) ((UINT8 *) &(PeHdr->Pe32.OptionalHeader) + PeHdr->Pe32.FileHeader.SizeOfOptionalHeader);\r
     for (Index = 0; Index < PeHdr->Pe32.FileHeader.NumberOfSections; Index ++, SectionHeader ++) {\r
       if (strcmp ((char *)SectionHeader->Name, ".data") == 0 || strcmp ((char *)SectionHeader->Name, ".sdata") == 0) {\r
@@ -2292,7 +2271,7 @@ Returns:
         //\r
         // Output Apci data to file\r
         //\r
-        memcpy (FileBuffer, FileBuffer + SectionHeader->PointerToRawData, FileLength);\r
+        memmove (FileBuffer, FileBuffer + SectionHeader->PointerToRawData, FileLength);\r
         VerboseMsg ("the size of output file is %u bytes", (unsigned) FileLength);\r
         goto WriteFile;\r
       }\r
@@ -2599,7 +2578,7 @@ Returns:
   //\r
   ZeroDebugData (FileBuffer, FALSE);\r
 \r
-  if (OutImageType == FW_TE_IMAGE) {\r
+  if (mOutImageType == FW_TE_IMAGE) {\r
     if ((PeHdr->Pe32.FileHeader.NumberOfSections &~0xFF) || (Type &~0xFF)) {\r
       //\r
       // Pack the subsystem and NumberOfSections into 1 byte. Make sure they fit both.\r
@@ -2622,7 +2601,7 @@ Returns:
     // Update Image to TeImage\r
     //\r
     FileLength = FileLength - TEImageHeader.StrippedSize;\r
-    memcpy (FileBuffer + sizeof (EFI_TE_IMAGE_HEADER), FileBuffer + TEImageHeader.StrippedSize, FileLength);\r
+    memmove (FileBuffer + sizeof (EFI_TE_IMAGE_HEADER), FileBuffer + TEImageHeader.StrippedSize, FileLength);\r
     FileLength = FileLength + sizeof (EFI_TE_IMAGE_HEADER);\r
     memcpy (FileBuffer, &TEImageHeader, sizeof (EFI_TE_IMAGE_HEADER));\r
     VerboseMsg ("the size of output file is %u bytes", (unsigned) (FileLength));\r
@@ -2658,7 +2637,7 @@ WriteFile:
       //\r
       // Update File when File is changed.\r
       //\r
-      fpInOut = fopen (mInImageName, "wb");\r
+      fpInOut = fopen (LongFilePath (mInImageName), "wb");\r
       if (fpInOut == NULL) {\r
         Error (NULL, 0, 0001, "Error opening file", mInImageName);\r
         goto Finish;\r
@@ -2671,7 +2650,7 @@ WriteFile:
       //\r
       // Update File when File is changed or File is old.\r
       //\r
-      fpOut = fopen (OutImageName, "wb");\r
+      fpOut = fopen (LongFilePath (OutImageName), "wb");\r
       if (fpOut == NULL) {\r
         Error (NULL, 0, 0001, "Error opening output file", OutImageName);\r
         goto Finish;\r
@@ -2713,7 +2692,7 @@ Finish:
       if (OutputFileBuffer == NULL) {\r
         remove (OutImageName);\r
       } else {\r
-        fpOut = fopen (OutImageName, "wb");\r
+        fpOut = fopen (LongFilePath (OutImageName), "wb");\r
         fwrite (OutputFileBuffer, 1, OutputFileLength, fpOut);\r
         fclose (fpOut);\r
       }\r
@@ -2739,7 +2718,7 @@ Finish:
     if (ReportFileName != NULL) {\r
       strcpy (ReportFileName, OutImageName);\r
       strcpy (ReportFileName + (FileLen - 4), ".txt"); \r
-      ReportFile = fopen (ReportFileName, "w+");\r
+      ReportFile = fopen (LongFilePath (ReportFileName), "w+");\r
       if (ReportFile != NULL) {\r
         fprintf (ReportFile, "MODULE_SIZE = %u\n", (unsigned) mImageSize);\r
         fprintf (ReportFile, "TIME_STAMP = %u\n", (unsigned) mImageTimeStamp);\r