summaryrefslogtreecommitdiffstats
path: root/BaseTools/Source/C/GenSec
diff options
context:
space:
mode:
authorYonghong Zhu <yonghong.zhu@intel.com>2017-11-29 11:45:22 +0800
committerYonghong Zhu <yonghong.zhu@intel.com>2017-12-05 09:25:32 +0800
commitb37b108d92aa08cc7eed5f52feea53b0e7563068 (patch)
treed456bafa0d46d051ccca8a5b79469507e40a55a5 /BaseTools/Source/C/GenSec
parent111dab620362b2f28ce48c18b1e513819e32e37f (diff)
downloadedk2-b37b108d92aa08cc7eed5f52feea53b0e7563068.tar.gz
edk2-b37b108d92aa08cc7eed5f52feea53b0e7563068.tar.bz2
edk2-b37b108d92aa08cc7eed5f52feea53b0e7563068.zip
BaseTools: Update Gensec to set PROCESSING_REQUIRED value
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> Reviewed-by: Liming Gao <liming.gao@intel.com>
Diffstat (limited to 'BaseTools/Source/C/GenSec')
-rw-r--r--BaseTools/Source/C/GenSec/GenSec.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/BaseTools/Source/C/GenSec/GenSec.c b/BaseTools/Source/C/GenSec/GenSec.c
index d9cdc1f631..2b2def1261 100644
--- a/BaseTools/Source/C/GenSec/GenSec.c
+++ b/BaseTools/Source/C/GenSec/GenSec.c
@@ -187,6 +187,9 @@ Returns:
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");
@@ -1028,6 +1031,13 @@ Returns:
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;
@@ -1049,6 +1059,13 @@ Returns:
SectGuidHeaderLength = 0;
VersionSect = NULL;
UiSect = NULL;
+ DummyFileSize = 0;
+ DummyFileName = NULL;
+ DummyFile = NULL;
+ DummyFileBuffer = NULL;
+ InFile = NULL;
+ InFileSize = 0;
+ InFileBuffer = NULL;
SetUtilityName (UTILITY_NAME);
@@ -1119,6 +1136,16 @@ Returns:
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) {
@@ -1292,6 +1319,53 @@ Returns:
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.
//