Revision: 18767
          http://sourceforge.net/p/edk2/code/18767
Author:   yzhu52
Date:     2015-11-11 06:30:42 +0000 (Wed, 11 Nov 2015)
Log Message:
-----------
BaseTools/GenFw: add new option to not zero PE/COFF optional header fields

Add new option --keepoptionalheader and that flag does not zero PE/COFF
optional header fields including the version fields. It can support the
case that the PE/COFF optional header would be kept.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yonghong Zhu <[email protected]>
Reviewed-by: Liming Gao <[email protected]>

Modified Paths:
--------------
    trunk/edk2/BaseTools/Source/C/GenFw/GenFw.c

Modified: trunk/edk2/BaseTools/Source/C/GenFw/GenFw.c
===================================================================
--- trunk/edk2/BaseTools/Source/C/GenFw/GenFw.c 2015-11-11 02:28:51 UTC (rev 
18766)
+++ trunk/edk2/BaseTools/Source/C/GenFw/GenFw.c 2015-11-11 06:30:42 UTC (rev 
18767)
@@ -1,7 +1,7 @@
 /** @file
 Converts a pe32+ image to an FW, Te image type, or other specific image.
 
-Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD 
License
 which accompanies this distribution.  The full text of the license may be 
found at
@@ -168,7 +168,7 @@
   //
   // Copyright declaration
   //
-  fprintf (stdout, "Copyright (c) 2007 - 2014, Intel Corporation. All rights 
reserved.\n\n");
+  fprintf (stdout, "Copyright (c) 2007 - 2015, Intel Corporation. All rights 
reserved.\n\n");
 
   //
   // Details Option
@@ -184,9 +184,9 @@
                         PIC_PEIM, RELOCATABLE_PEIM, BS_DRIVER, RT_DRIVER,\n\
                         APPLICATION, SAL_RT_DRIVER to support all module 
types\n\
                         It can only be used together with 
--keepexceptiontable,\n\
-                        --keepzeropending, -r, -o option.It is a action 
option.\n\
-                        If it is combined with other action options, the 
later\n\
-                        input action option will override the previous 
one.\n");
+                        --keepzeropending, --keepoptionalheader, -r, -o 
option.\n\
+                        It is a action option. If it is combined with other 
action options,\n\
+                        the later input action option will override the 
previous one.\n");
   fprintf (stdout, "  -c, --acpi            Create Acpi table.\n\
                         It can't be combined with other action options\n\
                         except for -o, -r option. It is a action option.\n\
@@ -194,9 +194,9 @@
                         input action option will override the previous 
one.\n");
   fprintf (stdout, "  -t, --terse           Create Te Image.\n\
                         It can only be used together with 
--keepexceptiontable,\n\
-                        --keepzeropending, -r, -o option.It is a action 
option.\n\
-                        If it is combined with other action options, the 
later\n\
-                        input action option will override the previous 
one.\n");
+                        --keepzeropending, --keepoptionalheader, -r, -o 
option.\n\
+                        It is a action option. If it is combined with other 
action options,\n\
+                        the later input action option will override the 
previous one.\n");
   fprintf (stdout, "  -u, --dump            Dump TeImage Header.\n\
                         It can't be combined with other action options\n\
                         except for -o, -r option. It is a action option.\n\
@@ -246,6 +246,9 @@
   fprintf (stdout, "  --keepexceptiontable  Don't clear exception table.\n\
                         This option can be used together with -e or -t.\n\
                         It doesn't work for other options.\n");
+  fprintf (stdout, "  --keepoptionalheader  Don't zero PE/COFF optional header 
fields.\n\
+                        This option can be used together with -e or -t.\n\
+                        It doesn't work for other options.\n");
   fprintf (stdout, "  --keepzeropending     Don't strip zero pending of 
.reloc.\n\
                         This option can be used together with -e or -t.\n\
                         It doesn't work for other options.\n");
@@ -1079,6 +1082,7 @@
   STATUS                           Status;
   BOOLEAN                          ReplaceFlag;
   BOOLEAN                          KeepExceptionTableFlag;
+  BOOLEAN                          KeepOptionalHeaderFlag;
   BOOLEAN                          KeepZeroPendingFlag;
   UINT64                           LogLevel;
   EFI_TE_IMAGE_HEADER              TEImageHeader;
@@ -1141,6 +1145,7 @@
   Optional32        = NULL;
   Optional64        = NULL;
   KeepExceptionTableFlag = FALSE;
+  KeepOptionalHeaderFlag = FALSE;
   KeepZeroPendingFlag    = FALSE;
   NumberOfFormPacakge    = 0;
   HiiPackageListBuffer   = NULL;
@@ -1269,6 +1274,13 @@
       continue;
     }
 
+    if (stricmp(argv[0], "--keepoptionalheader") == 0) {
+      KeepOptionalHeaderFlag = TRUE;
+      argc--;
+      argv++;
+      continue;
+    }
+
     if (stricmp (argv[0], "--keepzeropending") == 0) {
       KeepZeroPendingFlag = TRUE;
       argc --;
@@ -2303,19 +2315,20 @@
 
   if (PeHdr->Pe32.OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
     Optional32 = (EFI_IMAGE_OPTIONAL_HEADER32 *)&PeHdr->Pe32.OptionalHeader;
-    Optional32->MajorOperatingSystemVersion = 0;
-    Optional32->MinorOperatingSystemVersion = 0;
-    Optional32->MajorImageVersion           = 0;
-    Optional32->MinorImageVersion           = 0;
-    Optional32->MajorSubsystemVersion       = 0;
-    Optional32->MinorSubsystemVersion       = 0;
-    Optional32->Win32VersionValue           = 0;
-    Optional32->CheckSum                    = 0;
-    Optional32->SizeOfStackReserve = 0;
-    Optional32->SizeOfStackCommit  = 0;
-    Optional32->SizeOfHeapReserve  = 0;
-    Optional32->SizeOfHeapCommit   = 0;
-
+    if (!KeepOptionalHeaderFlag) {
+      Optional32->MajorOperatingSystemVersion = 0;
+      Optional32->MinorOperatingSystemVersion = 0;
+      Optional32->MajorImageVersion = 0;
+      Optional32->MinorImageVersion = 0;
+      Optional32->MajorSubsystemVersion = 0;
+      Optional32->MinorSubsystemVersion = 0;
+      Optional32->Win32VersionValue = 0;
+      Optional32->CheckSum = 0;
+      Optional32->SizeOfStackReserve = 0;
+      Optional32->SizeOfStackCommit = 0;
+      Optional32->SizeOfHeapReserve = 0;
+      Optional32->SizeOfHeapCommit = 0;
+    }
     TEImageHeader.AddressOfEntryPoint = Optional32->AddressOfEntryPoint;
     TEImageHeader.BaseOfCode          = Optional32->BaseOfCode;
     TEImageHeader.ImageBase           = (UINT64) (Optional32->ImageBase);
@@ -2395,19 +2408,20 @@
     }
   } else if (PeHdr->Pe32.OptionalHeader.Magic == 
EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
     Optional64 = (EFI_IMAGE_OPTIONAL_HEADER64 *)&PeHdr->Pe32.OptionalHeader;
-    Optional64->MajorOperatingSystemVersion = 0;
-    Optional64->MinorOperatingSystemVersion = 0;
-    Optional64->MajorImageVersion           = 0;
-    Optional64->MinorImageVersion           = 0;
-    Optional64->MajorSubsystemVersion       = 0;
-    Optional64->MinorSubsystemVersion       = 0;
-    Optional64->Win32VersionValue           = 0;
-    Optional64->CheckSum                    = 0;
-    Optional64->SizeOfStackReserve = 0;
-    Optional64->SizeOfStackCommit  = 0;
-    Optional64->SizeOfHeapReserve  = 0;
-    Optional64->SizeOfHeapCommit   = 0;
-
+    if (!KeepOptionalHeaderFlag) {
+      Optional64->MajorOperatingSystemVersion = 0;
+      Optional64->MinorOperatingSystemVersion = 0;
+      Optional64->MajorImageVersion = 0;
+      Optional64->MinorImageVersion = 0;
+      Optional64->MajorSubsystemVersion = 0;
+      Optional64->MinorSubsystemVersion = 0;
+      Optional64->Win32VersionValue = 0;
+      Optional64->CheckSum = 0;
+      Optional64->SizeOfStackReserve = 0;
+      Optional64->SizeOfStackCommit = 0;
+      Optional64->SizeOfHeapReserve = 0;
+      Optional64->SizeOfHeapCommit = 0;
+    }
     TEImageHeader.AddressOfEntryPoint = Optional64->AddressOfEntryPoint;
     TEImageHeader.BaseOfCode          = Optional64->BaseOfCode;
     TEImageHeader.ImageBase           = (UINT64) (Optional64->ImageBase);


------------------------------------------------------------------------------
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to