public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Yonghong Zhu <yonghong.zhu@intel.com>
To: edk2-devel@lists.01.org
Cc: Liming Gao <liming.gao@intel.com>, Yunhua Feng <yunhuax.feng@intel.com>
Subject: [Patch 3/4 V3] BaseTools: Update Gensec to set PROCESSING_REQUIRED value
Date: Wed, 29 Nov 2017 22:02:05 +0800	[thread overview]
Message-ID: <1511964126-6716-4-git-send-email-yonghong.zhu@intel.com> (raw)
In-Reply-To: <1511964126-6716-1-git-send-email-yonghong.zhu@intel.com>

This patch add new option --dummy file, and we compare the dummpy file
with input file to decide whether we need to set PROCESSING_REQUIRED
value.

Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
---
 BaseTools/Source/C/GenSec/GenSec.c | 74 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)

diff --git a/BaseTools/Source/C/GenSec/GenSec.c b/BaseTools/Source/C/GenSec/GenSec.c
index d9cdc1f..904926c 100644
--- a/BaseTools/Source/C/GenSec/GenSec.c
+++ b/BaseTools/Source/C/GenSec/GenSec.c
@@ -185,10 +185,13 @@ Returns:
                         used in Ver section.\n");
   fprintf (stdout, "  --sectionalign SectionAlign\n\
                         SectionAlign points to section alignment, which support\n\
                         the alignment scope 1~16M. It is specified in same\n\
                         order that the section file is input.\n");
+  fprintf (stdout, "  --dummy dummyfile\n\
+                        compare dummpyfile with input_file to decide whether\n\
+                        need to set PROCESSING_REQUIRED attribute.\n");
   fprintf (stdout, "  -v, --verbose         Turn on verbose output with informational messages.\n");
   fprintf (stdout, "  -q, --quiet           Disable all messages except key message and fatal error\n");
   fprintf (stdout, "  -d, --debug level     Enable debug messages, at input debug level.\n");
   fprintf (stdout, "  --version             Show program's version number and exit.\n");
   fprintf (stdout, "  -h, --help            Show this help message and exit.\n");
@@ -1026,10 +1029,17 @@ Returns:
   EFI_STATUS                Status;
   UINT64                    LogLevel;
   UINT32                    *InputFileAlign;
   UINT32                    InputFileAlignNum;
   EFI_COMMON_SECTION_HEADER *SectionHeader;
+  CHAR8                     *DummyFileName;
+  FILE                      *DummyFile;
+  UINTN                     DummyFileSize;
+  UINT8                     *DummyFileBuffer;
+  FILE                      *InFile;
+  UINT8                     *InFileBuffer;
+  UINTN                     InFileSize;
 
   InputFileAlign        = NULL;
   InputFileAlignNum     = 0;
   InputFileName         = NULL;
   OutputFileName        = NULL;
@@ -1047,10 +1057,17 @@ Returns:
   Status                = STATUS_SUCCESS;
   LogLevel              = 0;
   SectGuidHeaderLength  = 0;
   VersionSect           = NULL;
   UiSect                = NULL;
+  DummyFileSize         = 0;
+  DummyFileName         = NULL;
+  DummyFile             = NULL;
+  DummyFileBuffer       = NULL;
+  InFile                = NULL;
+  InFileSize            = 0;
+  InFileBuffer          = NULL;
   
   SetUtilityName (UTILITY_NAME);
   
   if (argc == 1) {
     Error (NULL, 0, 1001, "Missing options", "No options input");
@@ -1117,10 +1134,20 @@ Returns:
       }
       argc -= 2;
       argv += 2;
       continue;
     }
+    if (stricmp (argv[0], "--dummy") == 0) {
+      DummyFileName = argv[1];
+      if (DummyFileName == NULL) {
+        Error (NULL, 0, 1003, "Invalid option value", "Dummy file can't be NULL");
+        goto Finish;
+      }
+      argc -= 2;
+      argv += 2;
+      continue;
+    }
 
     if ((stricmp (argv[0], "-r") == 0) || (stricmp (argv[0], "--attributes") == 0)) {
       if (argv[1] == NULL) {
         Error (NULL, 0, 1003, "Invalid option value", "Guid section attributes can't be NULL");
         goto Finish;
@@ -1290,10 +1317,57 @@ Returns:
     goto Finish;
   }
 
   VerboseMsg ("%s tool start.", UTILITY_NAME);
 
+  if (DummyFileName != NULL) {
+      //
+      // Open file and read contents
+      //
+      DummyFile = fopen (LongFilePath (DummyFileName), "rb");
+      if (DummyFile == NULL) {
+        Error (NULL, 0, 0001, "Error opening file", DummyFileName);
+        return EFI_ABORTED;
+      }
+
+      fseek (DummyFile, 0, SEEK_END);
+      DummyFileSize = ftell (DummyFile);
+      fseek (DummyFile, 0, SEEK_SET);
+      DummyFileBuffer = (UINT8 *) malloc (DummyFileSize);
+      fread(DummyFileBuffer, 1, DummyFileSize, DummyFile);
+      fclose(DummyFile);
+      DebugMsg (NULL, 0, 9, "Dummy files", "the dummy file name is %s and the size is %u bytes", DummyFileName, (unsigned) DummyFileSize);
+
+      InFile = fopen(LongFilePath(InputFileName[0]), "rb");
+      if (InFile == NULL) {
+        Error (NULL, 0, 0001, "Error opening file", InputFileName[0]);
+        return EFI_ABORTED;
+      }
+
+      fseek (InFile, 0, SEEK_END);
+      InFileSize = ftell (InFile);
+      fseek (InFile, 0, SEEK_SET);
+      InFileBuffer = (UINT8 *) malloc (InFileSize);
+      fread(InFileBuffer, 1, InFileSize, InFile);
+      fclose(InFile);
+      DebugMsg (NULL, 0, 9, "Input files", "the input file name is %s and the size is %u bytes", InputFileName[0], (unsigned) InFileSize);
+      if (InFileSize > DummyFileSize){
+        if (stricmp(DummyFileBuffer, InFileBuffer + (InFileSize - DummyFileSize)) == 0){
+          SectGuidHeaderLength = InFileSize - DummyFileSize;
+        }
+      }
+      if (SectGuidHeaderLength == 0) {
+        SectGuidAttribute |= EFI_GUIDED_SECTION_PROCESSING_REQUIRED;
+      }
+      if (DummyFileBuffer != NULL) {
+        free (DummyFileBuffer);
+      }
+      if (InFileBuffer != NULL) {
+        free (InFileBuffer);
+      }
+    }
+
   //
   // Parse all command line parameters to get the corresponding section type.
   //
   VerboseMsg ("Section type is %s", SectionName);
   if (SectionName == NULL) {
-- 
2.6.1.windows.1



  parent reply	other threads:[~2017-11-29 13:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-29 14:02 [Patch 0/4 V3] BaseTools: Enable multiple thread to generate FFS file Yonghong Zhu
2017-11-29 14:02 ` [Patch 1/4 V3] BaseTools: GenFfs support to get alignment value from SectionFile Yonghong Zhu
2017-11-29 14:02 ` [Patch 2/4 V3] BaseTools: Update Trim to generate VfrBinOffset Binary Yonghong Zhu
2017-11-29 14:02 ` Yonghong Zhu [this message]
2017-12-05 11:53   ` [Patch 3/4 V3] BaseTools: Update Gensec to set PROCESSING_REQUIRED value Leif Lindholm
2017-12-05 13:56     ` Zhu, Yonghong
2017-11-29 14:02 ` [Patch 4/4 V3] BaseTools: Update Makefile to support FFS file generation Yonghong Zhu
2017-12-06 18:23   ` Leif Lindholm
2017-12-07  0:59     ` Zhu, Yonghong
2017-12-07  9:59       ` Zhu, Yonghong
2017-12-01  6:13 ` [Patch 0/4 V3] BaseTools: Enable multiple thread to generate FFS file Gao, Liming

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1511964126-6716-4-git-send-email-yonghong.zhu@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox