]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/GenFfs/GenFfs.c
BaseTools/GenFfs: add FFS file types for MM modules.
[mirror_edk2.git] / BaseTools / Source / C / GenFfs / GenFfs.c
index 433b608cb956d460f1c4115deb5641789b17c2c4..91632a90620b3e268a8e7b8250bf7f86ec9df148 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 This file contains functions required to generate a Firmware File System file.\r
 \r
-Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 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
@@ -43,8 +43,10 @@ STATIC CHAR8 *mFfsFileType[] = {
   "EFI_FV_FILETYPE_SMM",                  // 0x0A\r
   "EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE",// 0x0B\r
   "EFI_FV_FILETYPE_COMBINED_SMM_DXE",     // 0x0C\r
-  "EFI_FV_FILETYPE_SMM_CORE"              // 0x0D\r
- };\r
+  "EFI_FV_FILETYPE_SMM_CORE",             // 0x0D\r
+  "EFI_FV_FILETYPE_MM_STANDALONE",        // 0x0E\r
+  "EFI_FV_FILETYPE_MM_CORE_STANDALONE"    // 0x0F\r
+};\r
 \r
 STATIC CHAR8 *mAlignName[] = {\r
   "1", "2", "4", "8", "16", "32", "64", "128", "256", "512",\r
@@ -130,6 +132,8 @@ Returns:
                         EFI_FV_FILETYPE_DRIVER, EFI_FV_FILETYPE_APPLICATION,\n\\r
                         EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER,\n\\r
                         EFI_FV_FILETYPE_SMM, EFI_FV_FILETYPE_SMM_CORE,\n\\r
+                        EFI_FV_FILETYPE_MM_STANDALONE,\n\\r
+                        EFI_FV_FILETYPE_MM_CORE_STANDALONE,\n\\r
                         EFI_FV_FILETYPE_COMBINED_SMM_DXE, \n\\r
                         EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE.\n");\r
   fprintf (stdout, "  -g FileGuid, --fileguid FileGuid\n\\r
@@ -739,7 +743,7 @@ Returns:
   VerboseMsg ("%s tool start.", UTILITY_NAME);\r
 \r
   //\r
-  // Check the complete input paramters.\r
+  // Check the complete input parameters.\r
   //\r
   if (FfsFiletype == EFI_FV_FILETYPE_ALL) {\r
     Error (NULL, 0, 1001, "Missing option", "filetype");\r
@@ -845,6 +849,11 @@ Returns:
   if (EFI_ERROR (Status)) {\r
     goto Finish;\r
   }\r
+\r
+  if (FileBuffer == NULL && FileSize != 0) {\r
+    Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
+    goto Finish;\r
+  }\r
   \r
   //\r
   // Create Ffs file header.\r
@@ -915,22 +924,26 @@ Returns:
   //\r
   // Open output file to write ffs data.\r
   //\r
-  remove(OutputFileName);\r
-  FfsFile = fopen (LongFilePath (OutputFileName), "wb");\r
-  if (FfsFile == NULL) {\r
-    Error (NULL, 0, 0001, "Error opening file", OutputFileName);\r
-    goto Finish;\r
-  }\r
-  //\r
-  // write header\r
-  //\r
-  fwrite (&FfsFileHeader, 1, HeaderSize, FfsFile);\r
-  //\r
-  // write data\r
-  //\r
-  fwrite (FileBuffer, 1, FileSize - HeaderSize, FfsFile);\r
+  if (OutputFileName != NULL) {\r
+    remove(OutputFileName);\r
+    FfsFile = fopen (LongFilePath (OutputFileName), "wb");\r
+    if (FfsFile == NULL) {\r
+      Error (NULL, 0, 0001, "Error opening file", OutputFileName);\r
+      goto Finish;\r
+    }\r
+    //\r
+    // write header\r
+    //\r
+    fwrite (&FfsFileHeader, 1, HeaderSize, FfsFile);\r
+    //\r
+    // write data\r
+    //\r
+    if (FileBuffer != NULL) {\r
+      fwrite (FileBuffer, 1, FileSize - HeaderSize, FfsFile);\r
+    }\r
 \r
-  fclose (FfsFile);\r
+    fclose (FfsFile);\r
+  }\r
 \r
 Finish:\r
   if (InputFileName != NULL) {\r