public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Lin, Jason1" <jason1.lin@intel.com>
To: devel@edk2.groups.io
Cc: Jason1 Lin <jason1.lin@intel.com>,
	Bob Feng <bob.c.feng@intel.com>,
	Liming Gao <gaoliming@byosoft.com.cn>,
	Yuwei Chen <yuwei.chen@intel.com>,
	Dakota Chiang <dakota.chiang@intel.com>
Subject: [PATCH v1 2/2] [edk2-platforms] Silicon/Intel/FitGen: Support to override the MBZ byte in Startup ACM entries for other usages
Date: Thu, 23 Jun 2022 22:35:48 +0800	[thread overview]
Message-ID: <20220623143548.3129-2-jason1.lin@intel.com> (raw)
In-Reply-To: <20220623143548.3129-1-jason1.lin@intel.com>

From: Jason1 Lin <jason1.lin@intel.com>

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3959

As per FIT BIOS Specification 1.2 Rules, the size bytes (3 bytes)/
reserved byte (1 byte) / CheckSum byte (1 byte) in type 2 are must-be-zero (MBZ).
These bytes could be override for the other usages.
In the future, if these bytes field have other meanings, there would be no need to change the FitGen.

Command:
[-S <StartupAcmAddress StartupAcmSize>|<StartupAcmGuid>]
[-I <StartupAcmSizeByte0 StartupAcmSizeByte1 StartupAcmSizeByte2 StartupAcmRsvd StartupAcmChksum>]
[-V <StartupAcmVersion>]

With "-I" input the default Type 2 entry version would be 0x200.

Signed-off-by: Jason1 Lin <jason1.lin@intel.com>
Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Yuwei Chen <yuwei.chen@intel.com>
Cc: Dakota Chiang <dakota.chiang@intel.com>
---
 Silicon/Intel/Tools/FitGen/FitGen.c | 105 ++++++++++++++++----
 Silicon/Intel/Tools/FitGen/FitGen.h |   2 +-
 2 files changed, 88 insertions(+), 19 deletions(-)

diff --git a/Silicon/Intel/Tools/FitGen/FitGen.c b/Silicon/Intel/Tools/FitGen/FitGen.c
index eac8fa8715..bdda8dfd5a 100644
--- a/Silicon/Intel/Tools/FitGen/FitGen.c
+++ b/Silicon/Intel/Tools/FitGen/FitGen.c
@@ -210,6 +210,7 @@ typedef struct {
 
 #define DEFAULT_FIT_TABLE_POINTER_OFFSET  0x40
 #define DEFAULT_FIT_ENTRY_VERSION         0x0100
+#define STARTUP_ACM_FIT_ENTRY_200_VERSION 0x0200
 
 #define TOP_FLASH_ADDRESS  (gFitTableContext.TopFlashAddressRemapValue)
 
@@ -247,6 +248,12 @@ typedef struct {
   UINT8   *Buffer; // Used by OptionalModule only
   UINT32  Size;
   UINT32  Version; // Used by OptionalModule and PortModule only
+  UINT32  MaxSize;
+  UINT8   SizeByte0; // Used by S-ACM only
+  UINT8   SizeByte1; // Used by S-ACM only
+  UINT8   SizeByte2; // Used by S-ACM only
+  UINT8   Rsvd;      // Used by S-ACM only
+  UINT8   ChkSum;    // Used by S-ACM only
 } FIT_TABLE_CONTEXT_ENTRY;
 
 typedef struct {
@@ -262,7 +269,7 @@ typedef struct {
   UINT32                     GlobalVersion;
   UINT32                     FitHeaderVersion;
   FIT_TABLE_CONTEXT_ENTRY    StartupAcm[MAX_STARTUP_ACM_ENTRY];
-  UINT32                     StartupAcmVersion;
+  UINT32                     StartupAcmVersion[MAX_STARTUP_ACM_ENTRY];
   FIT_TABLE_CONTEXT_ENTRY    DiagnstAcm;
   UINT32                     DiagnstAcmVersion;
   FIT_TABLE_CONTEXT_ENTRY    BiosModule[MAX_BIOS_MODULE_ENTRY];
@@ -341,7 +348,7 @@ Returns:
           "\t[-L <MicrocodeSlotSize> <MicrocodeFfsGuid>]\n"
           "\t[-LF <MicrocodeSlotSize>]\n"
           "\t[-I <BiosInfoGuid>]\n"
-          "\t[-S <StartupAcmAddress StartupAcmSize>|<StartupAcmGuid>] [-V <StartupAcmVersion>]\n"
+          "\t[-S <StartupAcmAddress StartupAcmSize>|<StartupAcmGuid>] [-I <StartupAcmSizeByte0 StartupAcmSizeByte1 StartupAcmSizeByte2 StartupAcmRsvd StartupAcmChksum>] [-V <StartupAcmVersion>]\n"
           "\t[-U <DiagnstAcmAddress>|<DiagnstAcmGuid>]\n"
           "\t[-B <BiosModuleAddress BiosModuleSize>] [-B ...] [-V <BiosModuleVersion>]\n"
           "\t[-M <MicrocodeAddress MicrocodeSize>] [-M ...]|[-U <MicrocodeFv MicrocodeBase>|<MicrocodeRegionOffset MicrocodeRegionSize>|<MicrocodeGuid>] [-V <MicrocodeVersion>]\n"
@@ -357,7 +364,13 @@ Returns:
   printf ("\tBiosInfoGuid           - Guid of BiosInfo Module. If this module exists, StartupAcm/Bios/Microcode can be optional.\n");
   printf ("\tStartupAcmAddress      - Address of StartupAcm.\n");
   printf ("\tStartupAcmSize         - Size of StartupAcm.\n");
-  printf ("\tStartupAcmGuid         - Guid of StartupAcm Module, if StartupAcm is in a BiosModule, it will be excluded form that.\n");
+  printf ("\tStartupAcmGuid         - Guid of StartupAcm Module.\n");
+  printf ("\tStartupAcmMaxSize      - The maximum size value that could place the StartupAcm in.\n");
+  printf ("\tStartupAcmSizeByte0    - The value for Size byte 0 (Override default value).\n");
+  printf ("\tStartupAcmSizeByte1    - The value for Size byte 1 (Override default value).\n");
+  printf ("\tStartupAcmSizeByte2    - The value for Size byte 2 (Override default value).\n");
+  printf ("\tStartupAcmRsvd         - The value for Reserved byte (Override default value).\n");
+  printf ("\tStartupAcmChkSum       - The value for CheckSum byte (Override default value).\n");
   printf ("\tDiagnstAcmAddress      - Address of DiagnstAcm.\n");
   printf ("\tDiagnstAcmGuid         - Guid of DiagnstAcm Module, if DiagnstAcm is in a BiosModule, it will be excluded from that.\n");
   printf ("\tBiosModuleAddress      - Address of BiosModule. User should ensure there is no overlap.\n");
@@ -913,6 +926,9 @@ Returns:
   UINT32    FileSize;
   UINT32    Type;
   UINT32    SubType;
+  UINT8     StartupAcmSizeByte0;
+  UINT8     StartupAcmSizeByte1;
+  UINT8     StartupAcmSizeByte2;
   UINT8     *MicrocodeFileBuffer;
   UINT8     *MicrocodeFileBufferRaw;
   UINT32    MicrocodeFileSize;
@@ -1155,9 +1171,12 @@ Returns:
             Error (NULL, 0, 0, "-I Parameter incorrect, too many StartupAcm!", NULL);
             return 0;
           }
+          //
+          // NOTE: BIOS INFO structure not support to override the Size/Rsvd/ChkSum byte value.
+          //
           gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].Type    = FIT_TABLE_TYPE_STARTUP_ACM;
           gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].Address = (UINT32)BiosInfoStruct[BiosInfoIndex].Address;
-          gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].Size    = (UINT32)BiosInfoStruct[BiosInfoIndex].Size;
+          gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].MaxSize = (UINT32)BiosInfoStruct[BiosInfoIndex].Size;
           gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].Version = BiosInfoStruct[BiosInfoIndex].Version;
           gFitTableContext.StartupAcmNumber ++;
           gFitTableContext.FitEntryNumber ++;
@@ -1389,10 +1408,52 @@ Returns:
     }
     gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].Type = FIT_TABLE_TYPE_STARTUP_ACM;
     gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].Address = (UINT32) (UINTN) FileBuffer;
-    gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].Size = FileSize;
+    gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].MaxSize = FileSize;
 
     //
-    // 1.1 StartupAcm version
+    // 1.1 Support 0x200 StartupAcm Information
+    //
+    if ((Index + 1 >= argc) ||
+        ((strcmp (argv[Index], "-I") != 0) &&
+         (strcmp (argv[Index], "-i") != 0)) ) {
+      //
+      // Bypass
+      //
+      gFitTableContext.StartupAcmVersion[gFitTableContext.StartupAcmNumber] = gFitTableContext.GlobalVersion;
+      gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].Size = 0;
+    } else {
+      //
+      // Should use the multiple StartupACM
+      //
+      if (Index + 5 >= argc) {
+        //
+        // Should get five input value, but not sufficient
+        //
+        Error (NULL, 0, 0, "-I Parameter incorrect, Require five inputs value!", NULL);
+        return 0;
+      } else {
+        //
+        // Should assign this as 0x200
+        //
+        gFitTableContext.StartupAcmVersion[gFitTableContext.StartupAcmNumber] = STARTUP_ACM_FIT_ENTRY_200_VERSION;
+        gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].SizeByte0 = (UINT8)xtoi (argv[Index + 1]);
+        gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].SizeByte1 = (UINT8)xtoi (argv[Index + 2]);
+        gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].SizeByte2 = (UINT8)xtoi (argv[Index + 3]);
+        gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].Rsvd   = (UINT8)xtoi (argv[Index + 4]);
+        gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].ChkSum = (UINT8)xtoi (argv[Index + 5]);
+
+        StartupAcmSizeByte0  = (UINT32)gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].SizeByte0;
+        StartupAcmSizeByte1  = (UINT32)gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].SizeByte1;
+        StartupAcmSizeByte2  = (UINT32)gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].SizeByte2;
+
+        gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].Size   = (StartupAcmSizeByte2 << 16) + (StartupAcmSizeByte1 << 8) + (StartupAcmSizeByte0);
+
+        Index += 6;
+      }
+    }
+
+    //
+    // 1.2 StartupAcm version
     //
     if ((Index + 1 >= argc) ||
         ((strcmp (argv[Index], "-V") != 0) &&
@@ -1400,18 +1461,17 @@ Returns:
       //
       // Bypass
       //
-      gFitTableContext.StartupAcmVersion = gFitTableContext.GlobalVersion;
     } else {
       //
       // Get offset from parameter
       //
-      gFitTableContext.StartupAcmVersion = xtoi (argv[Index + 1]);
+      gFitTableContext.StartupAcmVersion[gFitTableContext.StartupAcmNumber] = xtoi (argv[Index + 1]);
       Index += 2;
     }
 
     gFitTableContext.StartupAcmNumber ++;
     gFitTableContext.FitEntryNumber ++;
-  }
+  };
 
   //
   // 1.5. DiagnosticsAcm
@@ -1895,7 +1955,7 @@ Returns:
   // Final: Check StartupAcm in BiosModule.
   //
   for (Index = 0; Index < (INTN)gFitTableContext.StartupAcmNumber; Index++) {
-    CheckOverlap (gFitTableContext.StartupAcm[Index].Address, gFitTableContext.StartupAcm[Index].Size);
+    CheckOverlap (gFitTableContext.StartupAcm[Index].Address, gFitTableContext.StartupAcm[Index].MaxSize);
   }
   FitEntryNumber = gFitTableContext.FitEntryNumber;
   for (Index = 0; Index < (INTN)gFitTableContext.OptionalModuleNumber; Index++) {
@@ -2185,7 +2245,7 @@ Returns:
   printf ("Total FIT Entry number: 0x%x\n", gFitTableContext.FitEntryNumber);
   printf ("FitHeader version: 0x%04x\n", gFitTableContext.FitHeaderVersion);
   for (Index = 0; Index < gFitTableContext.StartupAcmNumber; Index++) {
-    printf ("StartupAcm[%d] - (0x%08x, 0x%08x, 0x%04x)\n", Index, gFitTableContext.StartupAcm[Index].Address, gFitTableContext.StartupAcm[Index].Size, gFitTableContext.StartupAcmVersion);
+    printf ("StartupAcm[%d] - (0x%08x, 0x%08x, 0x%08x, 0x%04x)\n", Index, gFitTableContext.StartupAcm[Index].Address, gFitTableContext.StartupAcm[Index].Size, gFitTableContext.StartupAcm[Index].MaxSize, gFitTableContext.StartupAcmVersion[Index]);
   }
   if (gFitTableContext.DiagnstAcm.Address != 0) {
     printf ("DiagnosticAcm - (0x%08x, 0x%08x, 0x%04x)\n", gFitTableContext.DiagnstAcm.Address, gFitTableContext.DiagnstAcm.Size, gFitTableContext.DiagnstAcmVersion);
@@ -2817,11 +2877,12 @@ Returns:
   //
   for (Index = 0; Index < gFitTableContext.StartupAcmNumber; Index++) {
     FitEntry[FitIndex].Address             = gFitTableContext.StartupAcm[Index].Address;
-    *(UINT32 *)&FitEntry[FitIndex].Size[0] = 0; //gFitTableContext.StartupAcm.Size / 16;
-    FitEntry[FitIndex].Version             = (UINT16)gFitTableContext.StartupAcmVersion;
+    *(UINT32 *)&FitEntry[FitIndex].Size[0] = gFitTableContext.StartupAcm[Index].Size;
+    FitEntry[FitIndex].Version             = (UINT16)gFitTableContext.StartupAcmVersion[Index];
     FitEntry[FitIndex].Type                = FIT_TABLE_TYPE_STARTUP_ACM;
     FitEntry[FitIndex].C_V                 = 0;
-    FitEntry[FitIndex].Checksum            = 0;
+    FitEntry[FitIndex].Rsvd                = gFitTableContext.StartupAcm[Index].Rsvd;
+    FitEntry[FitIndex].Checksum            = gFitTableContext.StartupAcm[Index].ChkSum;
     FitIndex++;
   }
 
@@ -3170,8 +3231,16 @@ Returns:
       gFitTableContext.MicrocodeNumber ++;
       break;
     case FIT_TABLE_TYPE_STARTUP_ACM:
-      gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].Address = (UINT32)FitEntry[FitIndex].Address;
-      gFitTableContext.StartupAcmVersion                                     = FitEntry[FitIndex].Version;
+      gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].Address   = (UINT32)FitEntry[FitIndex].Address;
+      gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].Type      = FitEntry[FitIndex].Type;
+      gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].Size      = *(UINT32 *)&FitEntry[FitIndex].Size[0];
+      gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].SizeByte0 = *(UINT8 *)&FitEntry[FitIndex].Size[0];
+      gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].SizeByte1 = *(UINT8 *)&FitEntry[FitIndex].Size[1];
+      gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].SizeByte2 = *(UINT8 *)&FitEntry[FitIndex].Size[2];
+      gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].Rsvd      = FitEntry[FitIndex].Rsvd;
+      gFitTableContext.StartupAcm[gFitTableContext.StartupAcmNumber].ChkSum    = FitEntry[FitIndex].Checksum;
+      gFitTableContext.StartupAcmVersion[gFitTableContext.StartupAcmNumber]    = FitEntry[FitIndex].Version;
+      gFitTableContext.StartupAcmNumber ++;
       break;
     case FIT_TABLE_TYPE_BIOS_MODULE:
       gFitTableContext.BiosModule[gFitTableContext.BiosModuleNumber].Address = (UINT32)FitEntry[FitIndex].Address;
@@ -3333,13 +3402,13 @@ Returns:
     for (Index = 0; Index < (INTN)gFitTableContext.StartupAcmNumber; Index ++) {
       if (gFitTableContext.StartupAcm[Index].Address != 0) {
         AcmBuffer = FLASH_TO_MEMORY(gFitTableContext.StartupAcm[Index].Address, FdFileBuffer, FdFileSize);
-        if ((AcmBuffer < FdFileBuffer) || (AcmBuffer + gFitTableContext.StartupAcm[Index].Size > FdFileBuffer + FdFileSize)) {
+        if ((AcmBuffer < FdFileBuffer) || (AcmBuffer + gFitTableContext.StartupAcm[Index].MaxSize > FdFileBuffer + FdFileSize)) {
           printf ("ACM out of range - can not validate it\n");
           AcmBuffer = NULL;
         }
 
         if (AcmBuffer != NULL) {
-          if (CheckAcm ((ACM_FORMAT *)AcmBuffer, gFitTableContext.StartupAcm[Index].Size)) {
+          if (CheckAcm ((ACM_FORMAT *)AcmBuffer, gFitTableContext.StartupAcm[Index].MaxSize)) {
             DumpAcm ((ACM_FORMAT *)AcmBuffer);
           } else {
             Status = STATUS_ERROR;
diff --git a/Silicon/Intel/Tools/FitGen/FitGen.h b/Silicon/Intel/Tools/FitGen/FitGen.h
index b7de0a6b2d..80a1423ceb 100644
--- a/Silicon/Intel/Tools/FitGen/FitGen.h
+++ b/Silicon/Intel/Tools/FitGen/FitGen.h
@@ -31,7 +31,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 // Utility version information
 //
 #define UTILITY_MAJOR_VERSION 0
-#define UTILITY_MINOR_VERSION 65
+#define UTILITY_MINOR_VERSION 66
 #define UTILITY_DATE          __DATE__
 
 //
-- 
2.26.2.windows.1


      reply	other threads:[~2022-06-23 14:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-23 14:35 [PATCH v1 1/2] [edk2-platforms] Silicon/Intel/FitGen: Support multiple Startup ACM Type 2 entries in FitGen tool Lin, Jason1
2022-06-23 14:35 ` Lin, Jason1 [this message]

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=20220623143548.3129-2-jason1.lin@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