]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/GenFv/GenFv.c
BaseTools/GenFv: Add checks for user/file inputs
[mirror_edk2.git] / BaseTools / Source / C / GenFv / GenFv.c
index 5b7f72e19e082d7d788839542f7c1c3823b44497..4de24b9f7ec1b610b2158b468d99b8886607f8af 100644 (file)
@@ -1,7 +1,11 @@
 /** @file\r
+  This contains all code necessary to build the GenFvImage.exe utility.       \r
+  This utility relies heavily on the GenFvImage Lib.  Definitions for both\r
+  can be found in the Tiano Firmware Volume Generation Utility \r
+  Specification, review draft.\r
 \r
-Copyright (c) 2007 - 2010, Intel Corporation                                                         \r
-All rights reserved. This program and the accompanying materials                          \r
+Copyright (c) 2007 - 2016, 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
 http://opensource.org/licenses/bsd-license.php                                            \r
@@ -9,17 +13,6 @@ http://opensource.org/licenses/bsd-license.php
 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
-  GenFv.c\r
-\r
-Abstract:\r
-\r
-  This contains all code necessary to build the GenFvImage.exe utility.       \r
-  This utility relies heavily on the GenFvImage Lib.  Definitions for both\r
-  can be found in the Tiano Firmware Volume Generation Utility \r
-  Specification, review draft.\r
-\r
 **/\r
 \r
 //\r
@@ -40,9 +33,9 @@ Abstract:
 //\r
 #define UTILITY_MAJOR_VERSION 0\r
 #define UTILITY_MINOR_VERSION 1\r
-#define GENFV_UPDATE_TIME           " updated on 2010/2/1"\r
 \r
 EFI_GUID  mEfiFirmwareFileSystem2Guid = EFI_FIRMWARE_FILE_SYSTEM2_GUID;\r
+EFI_GUID  mEfiFirmwareFileSystem3Guid = EFI_FIRMWARE_FILE_SYSTEM3_GUID;\r
 \r
 STATIC\r
 VOID \r
@@ -65,7 +58,7 @@ Returns:
 \r
 --*/\r
 {\r
-  fprintf (stdout, "%s Version %d.%d %s\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, GENFV_UPDATE_TIME);\r
+  fprintf (stdout, "%s Version %d.%d %s \n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);\r
 }\r
 \r
 STATIC\r
@@ -97,7 +90,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
@@ -125,6 +118,11 @@ Returns:
                         Address is the rebase start address for drivers that\n\\r
                         run in Flash. It supports DEC or HEX digital format.\n\\r
                         If it is set to zero, no rebase action will be taken\n");\r
+  fprintf (stdout, "  -F ForceRebase, --force-rebase ForceRebase\n\\r
+                        If value is TRUE, will always take rebase action\n\\r
+                        If value is FALSE, will always not take reabse action\n\\r
+                        If not specified, will take rebase action if rebase address greater than zero, \n\\r
+                        will not take rebase action if rebase address is zero.\n");\r
   fprintf (stdout, "  -a AddressFile, --addrfile AddressFile\n\\r
                         AddressFile is one file used to record the child\n\\r
                         FV base address when current FV base address is set.\n");\r
@@ -139,6 +137,8 @@ Returns:
                         Its format is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\n");\r
   fprintf (stdout, "  --capflag CapFlag     Capsule Reset Flag can be PersistAcrossReset,\n\\r
                         or PopulateSystemTable or InitiateReset or not set\n");\r
+  fprintf (stdout, "  --capoemflag CapOEMFlag\n\\r
+                        Capsule OEM Flag is an integer between 0x0000 and 0xffff\n");\r
   fprintf (stdout, "  --capheadsize HeadSize\n\\r
                         HeadSize is one HEX or DEC format value\n\\r
                         HeadSize is required by Capsule Image.\n");                        \r
@@ -232,6 +232,7 @@ Returns:
   // Set the default FvGuid\r
   //\r
   memcpy (&mFvDataInfo.FvFileSystemGuid, &mEfiFirmwareFileSystem2Guid, sizeof (EFI_GUID));\r
+  mFvDataInfo.ForceRebase = -1;\r
    \r
   //\r
   // Parse command line\r
@@ -331,12 +332,17 @@ Returns:
       continue; \r
     }\r
 \r
-    if ((stricmp (argv[0], "-f") == 0) || (stricmp (argv[0], "--ffsfile") == 0)) {\r
+    if ((strcmp (argv[0], "-f") == 0) || (stricmp (argv[0], "--ffsfile") == 0)) {\r
       if (argv[1] == NULL) {\r
         Error (NULL, 0, 1003, "Invalid option value", "Input Ffsfile can't be null");\r
         return STATUS_ERROR;\r
       }\r
-      strcpy (mFvDataInfo.FvFiles[Index], argv[1]);\r
+      if (strlen (argv[1]) > MAX_LONG_FILE_PATH - 1) {\r
+        Error (NULL, 0, 1003, "Invalid option value", "Input Ffsfile name %s is too long!", argv[1]);\r
+        return STATUS_ERROR;\r
+      }\r
+      strncpy (mFvDataInfo.FvFiles[Index], argv[1], MAX_LONG_FILE_PATH - 1);\r
+      mFvDataInfo.FvFiles[Index][MAX_LONG_FILE_PATH - 1] = 0;\r
       DebugMsg (NULL, 0, 9, "FV component file", "the %uth name is %s", (unsigned) Index + 1, argv[1]);\r
       argc -= 2;\r
       argv += 2;\r
@@ -373,6 +379,26 @@ Returns:
       argv ++;\r
       continue; \r
     }\r
+  \r
+    if ((strcmp (argv[0], "-F") == 0) || (stricmp (argv[0], "--force-rebase") == 0)) {\r
+      if (argv[1] == NULL) {\r
+        Error (NULL, 0, 1003, "Invalid option value", "Froce rebase flag can't be null");\r
+        return STATUS_ERROR;\r
+      }\r
+\r
+      if (stricmp (argv[1], "TRUE") == 0) {\r
+        mFvDataInfo.ForceRebase = 1;\r
+      } else if (stricmp (argv[1], "FALSE") == 0) {\r
+        mFvDataInfo.ForceRebase = 0;\r
+      } else {\r
+        Error (NULL, 0, 1003, "Invalid option value", "froce rebase flag value must be \"TRUE\" or \"FALSE\"");\r
+        return STATUS_ERROR;\r
+      }\r
+\r
+      argc -= 2;\r
+      argv += 2;\r
+      continue; \r
+    } \r
 \r
     if (stricmp (argv[0], "--capheadsize") == 0) {\r
       //\r
@@ -414,6 +440,22 @@ Returns:
       continue; \r
     }\r
 \r
+    if (stricmp (argv[0], "--capoemflag") == 0) {\r
+      if (argv[1] == NULL) {\r
+        Error (NULL, 0, 1003, "Invalid option value", "Capsule OEM flag can't be null");\r
+      }\r
+      Status = AsciiStringToUint64(argv[1], FALSE, &TempNumber);\r
+      if (EFI_ERROR (Status) || TempNumber > 0xffff) {\r
+        Error (NULL, 0, 1003, "Invalid option value", "Capsule OEM flag value must be integer value between 0x0000 and 0xffff");\r
+        return STATUS_ERROR;\r
+      }\r
+      mCapDataInfo.Flags |= TempNumber;\r
+      DebugMsg( NULL, 0, 9, "Capsule OEM Flags", argv[1]);\r
+      argc -= 2;\r
+      argv += 2;\r
+      continue;\r
+    }\r
+\r
     if (stricmp (argv[0], "--capguid") == 0) {\r
       //\r
       // Get the Capsule Guid\r
@@ -559,7 +601,7 @@ Returns:
     if (OutFileName == NULL) {\r
       FpFile = stdout;\r
     } else {\r
-      FpFile = fopen (OutFileName, "w");\r
+      FpFile = fopen (LongFilePath (OutFileName), "w");\r
       if (FpFile == NULL) {\r
         Error (NULL, 0, 0001, "Error opening file", OutFileName);\r
         return STATUS_ERROR;\r
@@ -598,7 +640,12 @@ Returns:
               );\r
   } else {\r
     VerboseMsg ("Create Fv image and its map file");\r
-    if (mFvDataInfo.BaseAddress != 0) {\r
+    //\r
+    // Will take rebase action at below situation:\r
+    // 1. ForceRebase Flag specified to TRUE;\r
+    // 2. ForceRebase Flag not specified, BaseAddress greater than zero.\r
+    //\r
+    if (((mFvDataInfo.BaseAddress > 0) && (mFvDataInfo.ForceRebase == -1)) || (mFvDataInfo.ForceRebase == 1)) {\r
       VerboseMsg ("FvImage Rebase Address is 0x%llX", (unsigned long long) mFvDataInfo.BaseAddress);\r
     }\r
     //\r
@@ -623,7 +670,7 @@ Returns:
   //  update boot driver address and runtime driver address in address file\r
   //\r
   if (Status == EFI_SUCCESS && AddrFileName != NULL && mFvBaseAddressNumber > 0) {\r
-    FpFile = fopen (AddrFileName, "w");\r
+    FpFile = fopen (LongFilePath (AddrFileName), "w");\r
     if (FpFile == NULL) {\r
       Error (NULL, 0, 0001, "Error opening file", AddrFileName);\r
       return STATUS_ERROR;\r