public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* Re: [Bug 2321] Add FitGen feature to support uCode Capsule Update
       [not found] ` <bug-2321-591-866w3Xggjl@https.bugzilla.tianocore.org/>
@ 2019-11-08  8:49   ` kenji.chen
       [not found]     ` <4A89E2EF3DFEDB4C8BFDE51014F606A14E53E843@SHSMSX104.ccr.corp.intel.com>
  0 siblings, 1 reply; 7+ messages in thread
From: kenji.chen @ 2019-11-08  8:49 UTC (permalink / raw)
  To: 'devel@edk2.groups.io'

[-- Attachment #1: Type: text/plain, Size: 1012 bytes --]

Having problems in git send-email. Send it by outlook.

-----Original Message-----
From: bugzilla-daemon@bugzilla.tianocore.org <bugzilla-daemon@bugzilla.tianocore.org> 
Sent: Monday, November 4, 2019 10:14 AM
To: Chen, Kenji <kenji.chen@intel.com>
Subject: [Bug 2321] Add FitGen feature to support uCode Capsule Update

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

Liming Gao <liming.gao@intel.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |CONFIRMED
                 CC|                            |liming.gao@intel.com
           Assignee|michael.d.kinney@intel.com  |kenji.chen@intel.com
     Ever confirmed|0                           |1

--- Comment #1 from Liming Gao <liming.gao@intel.com> --- Kenji is working on the patch.

--
You are receiving this mail because:
You are the assignee for the bug.
You reported the bug.

[-- Attachment #2: 0001-Enhance-FitGen.patch --]
[-- Type: application/octet-stream, Size: 6496 bytes --]

From 366e1d9b2488171bc07be6b699bc69a48f569835 Mon Sep 17 00:00:00 2001
From: Chen A Chen <chen.a.chen@intel.com>
Date: Tue, 7 May 2019 13:14:49 +0800
Subject: [PATCH] Enhance FitGen

1) Fix alignment issue for FV header
2) Will check each size of uCode patch is less than SlotSize
3) Will continue to scan empty slot after uCode patch array
   Assumption: there are no empty slot between each uCode patch
   The empty range is behind uCode patch array
4) We reserve 100KB for each uCode patch in current solution

Change-Id: Ie324b5379a86905837aeba7d900b6ce29ca66179
Signed-off-by: Chen A Chen <chen.a.chen@intel.com>
Hsd-es-id: None
Tracker-link: None
Attestation-link: None
Reviewed-on: https://git-amr-7.devtools.intel.com/gerrit/48140
Tested-by: CR <cr2@intel.com>
Test-Verified: CR <cr2@intel.com>
Reviewed-by: Zhang, Chao B <chao.b.zhang@intel.com>
Reviewed-by: Chai, Evan <evan.chai@intel.com>
---
 BpCommonPkg/Tools/FitGen/FitGen.c | 76 +++++++++++++++++++++++++++++++++++----
 1 file changed, 69 insertions(+), 7 deletions(-)

diff --git a/BpCommonPkg/Tools/FitGen/FitGen.c b/BpCommonPkg/Tools/FitGen/FitGen.c
index 6ed48f9d30..aef0d838a0 100644
--- a/BpCommonPkg/Tools/FitGen/FitGen.c
+++ b/BpCommonPkg/Tools/FitGen/FitGen.c
@@ -776,6 +776,7 @@ Returns:
 {
   EFI_GUID  Guid;
   INTN      Index;
+  UINTN     MicrocodeIndex;
   UINT8     *FileBuffer;
   UINT32    FileSize;
   UINT32    Type;
@@ -785,8 +786,10 @@ Returns:
   UINT32    MicrocodeBase;
   UINT32    MicrocodeSize;
   UINT8     *MicrocodeBuffer;
+  UINT8     *MicrocodeBufferEnd;
   UINT32    MicrocodeRegionOffset;
   UINT32    MicrocodeRegionSize;
+  UINT32    SlotSize;
   STATUS    Status;
   EFI_FIRMWARE_VOLUME_HEADER  *FvHeader;
   UINTN                       FitEntryNumber;
@@ -794,6 +797,7 @@ Returns:
   BIOS_INFO_HEADER            *BiosInfo;
   BIOS_INFO_STRUCT            *BiosInfoStruct;
   UINTN                       BiosInfoIndex;
+  UINT32                      AlignmentByte;
 
   //
   // Init index
@@ -911,7 +915,22 @@ Returns:
   }
 
   //
-  // 0.5 BiosInfo
+  // 0.5 SlotSize
+  //
+  if ((Index + 1 >= argc) ||
+      ((strcmp (argv[Index], "-S") != 0) &&
+       (strcmp (argv[Index], "-s") != 0)) ) {
+    //
+    // Bypass
+    //
+    SlotSize = 0;
+  } else {
+    SlotSize = xtoi (argv[Index + 1]);
+    Index += 2;
+  }
+
+  //
+  // 0.6 BiosInfo
   //
   if ((Index + 1 >= argc) ||
       ((strcmp (argv[Index], "-I") != 0) &&
@@ -1009,6 +1028,7 @@ Returns:
 
             MicrocodeFileBuffer = FLASH_TO_MEMORY (MicrocodeRegionOffset, FdBuffer, FdSize);
             MicrocodeFileSize = MicrocodeRegionSize;
+            MicrocodeBufferEnd = MicrocodeFileBuffer + MicrocodeFileSize;
             MicrocodeBase = MicrocodeRegionOffset;
 
             FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)MicrocodeFileBuffer;
@@ -1018,13 +1038,26 @@ Returns:
             } else {
               MicrocodeBuffer = MicrocodeFileBuffer;
             }
+
+            AlignmentByte = 1;
+            AlignmentByte = AlignmentByte << ((FvHeader->Attributes&0x000F0000) >> 16);
+
+            ///
+            /// Make MicrocodeBuffer address to alignment.
+            ///
+            if ((UINT32)MicrocodeBuffer % AlignmentByte != 0) {
+              MicrocodeBuffer = (UINT8 *)((UINT32)MicrocodeBuffer &~(AlignmentByte - 1));
+              MicrocodeBuffer += AlignmentByte;
+            }
+
             while ((UINT32)(MicrocodeBuffer - MicrocodeFileBuffer) < MicrocodeFileSize) {
-              if (*(UINT32 *)(MicrocodeBuffer) != 0x1) { // HeaderVersion
-                break;
-              }
-              if (*(UINT32 *)(MicrocodeBuffer + 20) != 0x1) { // LoaderVersion
-                break;
+              if (*(UINT32 *)(MicrocodeBuffer) != 0x1 ||
+                  *(UINT32 *)(MicrocodeBuffer + 20) != 0x1
+                 ) { // HeaderVersion
+                MicrocodeBuffer += 1024;
+                continue;
               }
+
               if (*(UINT32 *)(MicrocodeBuffer + 28) == 0) { // DataSize
                 MicrocodeSize = 2048;
               } else {
@@ -1047,12 +1080,41 @@ Returns:
               }
               gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Type = FIT_TABLE_TYPE_MICROCODE;
               gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Address = MicrocodeBase + ((UINT32) (UINTN) MicrocodeBuffer - (UINT32) (UINTN) MicrocodeFileBuffer);
-              gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Size = MicrocodeSize;
+              //
+              // No longer use.
+              //
+              //gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Size = MicrocodeSize;
               gFitTableContext.MicrocodeNumber++;
               gFitTableContext.FitEntryNumber++;
 
               MicrocodeBuffer += MicrocodeSize;
             }
+
+            if (SlotSize != 0) {
+              ///
+              /// Check whether each uCode is alignment with SlotSize bytes.
+              ///
+              for (MicrocodeIndex = 1; MicrocodeIndex < (INTN)gFitTableContext.MicrocodeNumber; MicrocodeIndex++) {
+                if (gFitTableContext.Microcode[MicrocodeIndex].Address - gFitTableContext.Microcode[MicrocodeIndex - 1].Address != SlotSize) {
+                  printf ("uCode must be follow SlotSize(%lu) alignment.\n", SlotSize);
+                  ASSERT (FALSE);
+                }
+              }
+
+              ///
+              /// Assume the empty space follows the uCode array.
+              ///
+              MicrocodeBuffer = (UINT8 *)(gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber - 1].Address - MicrocodeBase + MicrocodeFileBuffer);
+              MicrocodeBuffer += SlotSize;
+              while (MicrocodeBuffer + SlotSize <= MicrocodeBufferEnd) {
+                gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Type = FIT_TABLE_TYPE_MICROCODE;
+                gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Address = MicrocodeBase + ((UINT32) (UINTN) MicrocodeBuffer - (UINT32) (UINTN) MicrocodeFileBuffer);
+                gFitTableContext.MicrocodeNumber++;
+                gFitTableContext.FitEntryNumber++;
+
+                MicrocodeBuffer += SlotSize;
+              }
+            }
           }
           break;
         case FIT_TABLE_TYPE_TPM_POLICY:
-- 
2.16.2.windows.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [edk2-devel] [Bug 2321] Add FitGen feature to support uCode Capsule Update
       [not found]       ` <4A89E2EF3DFEDB4C8BFDE51014F606A14E53E84D@SHSMSX104.ccr.corp.intel.com>
@ 2019-11-13  0:01         ` Chen, Kenji
  2019-11-13  0:47           ` Liming Gao
  0 siblings, 1 reply; 7+ messages in thread
From: Chen, Kenji @ 2019-11-13  0:01 UTC (permalink / raw)
  To: Gao, Liming, Ke, VincentX; +Cc: 'devel@edk2.groups.io'

[-- Attachment #1: Type: text/plain, Size: 2152 bytes --]

Updating the correct one.
+ Vincent to confirm the patch.

Thanks, Kenji.
-----Original Message-----
From: Gao, Liming <liming.gao@intel.com> 
Sent: Tuesday, November 12, 2019 11:43 PM
To: Chen, Kenji <kenji.chen@intel.com>
Subject: RE: [edk2-devel] [Bug 2321] Add FitGen feature to support uCode Capsule Update

Here is edk2platform git repo https://github.com/tianocore/edk2-platforms

> -----Original Message-----
> From: Gao, Liming
> Sent: Tuesday, November 12, 2019 11:42 PM
> To: Chen, Kenji <kenji.chen@intel.com>
> Subject: RE: [edk2-devel] [Bug 2321] Add FitGen feature to support uCode Capsule Update
> 
> Can you update the patch base on edk2-platforms\Silicon\Intel\Tools\FitGen source?
> 
> > -----Original Message-----
> > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Chen, Kenji
> > Sent: Friday, November 8, 2019 4:49 PM
> > To: 'devel@edk2.groups.io' <devel@edk2.groups.io>
> > Subject: Re: [edk2-devel] [Bug 2321] Add FitGen feature to support uCode Capsule Update
> >
> > Having problems in git send-email. Send it by outlook.
> >
> > -----Original Message-----
> > From: bugzilla-daemon@bugzilla.tianocore.org <bugzilla-daemon@bugzilla.tianocore.org>
> > Sent: Monday, November 4, 2019 10:14 AM
> > To: Chen, Kenji <kenji.chen@intel.com>
> > Subject: [Bug 2321] Add FitGen feature to support uCode Capsule Update
> >
> > https://bugzilla.tianocore.org/show_bug.cgi?id=2321
> >
> > Liming Gao <liming.gao@intel.com> changed:
> >
> >            What    |Removed                     |Added
> > ----------------------------------------------------------------------------
> >              Status|UNCONFIRMED                 |CONFIRMED
> >                  CC|                            |liming.gao@intel.com
> >            Assignee|michael.d.kinney@intel.com  |kenji.chen@intel.com
> >      Ever confirmed|0                           |1
> >
> > --- Comment #1 from Liming Gao <liming.gao@intel.com> --- Kenji is working on the patch.
> >
> > --
> > You are receiving this mail because:
> > You are the assignee for the bug.
> > You reported the bug.
> >
> > 



[-- Attachment #2: 0001-FitGen-Add-FitGen-feature-to-support-uCode-Capsule-U.patch --]
[-- Type: application/octet-stream, Size: 5968 bytes --]

From 37905818f622641cf89642c5d7584c871c27d090 Mon Sep 17 00:00:00 2001
From: Kenji Chen <kenji.chen@intel.com>
Date: Tue, 5 Nov 2019 11:01:32 +0800
Subject: [PATCH] FitGen: Add FitGen feature to support uCode Capsule Update

Add slot mode handling with header array.

Change-Id: Icee955a8cb4456ceb233e7a068fa7db733464626
Signed-off-by: Kenji Chen <kenji.chen@intel.com>
---
 Silicon/Intel/Tools/FitGen/FitGen.c | 76 +++++++++++++++++++++++++++++++++----
 1 file changed, 69 insertions(+), 7 deletions(-)

diff --git a/Silicon/Intel/Tools/FitGen/FitGen.c b/Silicon/Intel/Tools/FitGen/FitGen.c
index faf98800..94a1e58c 100644
--- a/Silicon/Intel/Tools/FitGen/FitGen.c
+++ b/Silicon/Intel/Tools/FitGen/FitGen.c
@@ -765,6 +765,7 @@ Returns:
 {
   EFI_GUID  Guid;
   INTN      Index;
+  UINTN     MicrocodeIndex;
   UINT8     *FileBuffer;
   UINT32    FileSize;
   UINT32    Type;
@@ -774,8 +775,10 @@ Returns:
   UINT32    MicrocodeBase;
   UINT32    MicrocodeSize;
   UINT8     *MicrocodeBuffer;
+  UINT8     *MicrocodeBufferEnd;
   UINT32    MicrocodeRegionOffset;
   UINT32    MicrocodeRegionSize;
+  UINT32    SlotSize;
   STATUS    Status;
   EFI_FIRMWARE_VOLUME_HEADER  *FvHeader;
   UINTN                       FitEntryNumber;
@@ -783,6 +786,7 @@ Returns:
   BIOS_INFO_HEADER            *BiosInfo;
   BIOS_INFO_STRUCT            *BiosInfoStruct;
   UINTN                       BiosInfoIndex;
+  UINT32                      AlignmentByte;
 
   //
   // Init index
@@ -900,7 +904,22 @@ Returns:
   }
 
   //
-  // 0.5 BiosInfo
+  // 0.5 SlotSize
+  //
+  if ((Index + 1 >= argc) ||
+      ((strcmp (argv[Index], "-S") != 0) &&
+       (strcmp (argv[Index], "-s") != 0)) ) {
+    //
+    // Bypass
+    //
+    SlotSize = 0;
+  } else {
+    SlotSize = xtoi (argv[Index + 1]);
+    Index += 2;
+  }
+
+  //
+  // 0.6 BiosInfo
   //
   if ((Index + 1 >= argc) ||
       ((strcmp (argv[Index], "-I") != 0) &&
@@ -998,6 +1017,7 @@ Returns:
 
             MicrocodeFileBuffer = FLASH_TO_MEMORY (MicrocodeRegionOffset, FdBuffer, FdSize);
             MicrocodeFileSize = MicrocodeRegionSize;
+            MicrocodeBufferEnd = MicrocodeFileBuffer + MicrocodeFileSize;
             MicrocodeBase = MicrocodeRegionOffset;
 
             FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)MicrocodeFileBuffer;
@@ -1007,13 +1027,26 @@ Returns:
             } else {
               MicrocodeBuffer = MicrocodeFileBuffer;
             }
+
+            AlignmentByte = 1;
+            AlignmentByte = AlignmentByte << ((FvHeader->Attributes&0x000F0000) >> 16);
+
+            ///
+            /// Make MicrocodeBuffer address to alignment.
+            ///
+            if ((UINT32)MicrocodeBuffer % AlignmentByte != 0) {
+              MicrocodeBuffer = (UINT8 *)((UINT32)MicrocodeBuffer &~(AlignmentByte - 1));
+              MicrocodeBuffer += AlignmentByte;
+            }
+
             while ((UINT32)(MicrocodeBuffer - MicrocodeFileBuffer) < MicrocodeFileSize) {
-              if (*(UINT32 *)(MicrocodeBuffer) != 0x1) { // HeaderVersion
-                break;
-              }
-              if (*(UINT32 *)(MicrocodeBuffer + 20) != 0x1) { // LoaderVersion
-                break;
+              if (*(UINT32 *)(MicrocodeBuffer) != 0x1 ||
+                  *(UINT32 *)(MicrocodeBuffer + 20) != 0x1
+                 ) { // HeaderVersion
+                MicrocodeBuffer += 1024;
+                continue;
               }
+
               if (*(UINT32 *)(MicrocodeBuffer + 28) == 0) { // DataSize
                 MicrocodeSize = 2048;
               } else {
@@ -1036,12 +1069,41 @@ Returns:
               }
               gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Type = FIT_TABLE_TYPE_MICROCODE;
               gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Address = MicrocodeBase + ((UINT32) (UINTN) MicrocodeBuffer - (UINT32) (UINTN) MicrocodeFileBuffer);
-              gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Size = MicrocodeSize;
+              //
+              // No longer use.
+              //
+              //gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Size = MicrocodeSize;
               gFitTableContext.MicrocodeNumber++;
               gFitTableContext.FitEntryNumber++;
 
               MicrocodeBuffer += MicrocodeSize;
             }
+
+            if (SlotSize != 0) {
+              ///
+              /// Check whether each uCode is alignment with SlotSize bytes.
+              ///
+              for (MicrocodeIndex = 1; MicrocodeIndex < (INTN)gFitTableContext.MicrocodeNumber; MicrocodeIndex++) {
+                if (gFitTableContext.Microcode[MicrocodeIndex].Address - gFitTableContext.Microcode[MicrocodeIndex - 1].Address != SlotSize) {
+                  printf ("uCode must be follow SlotSize(%lu) alignment.\n", SlotSize);
+                  ASSERT (FALSE);
+                }
+              }
+
+              ///
+              /// Assume the empty space follows the uCode array.
+              ///
+              MicrocodeBuffer = (UINT8 *)(gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber - 1].Address - MicrocodeBase + MicrocodeFileBuffer);
+              MicrocodeBuffer += SlotSize;
+              while (MicrocodeBuffer + SlotSize <= MicrocodeBufferEnd) {
+                gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Type = FIT_TABLE_TYPE_MICROCODE;
+                gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Address = MicrocodeBase + ((UINT32) (UINTN) MicrocodeBuffer - (UINT32) (UINTN) MicrocodeFileBuffer);
+                gFitTableContext.MicrocodeNumber++;
+                gFitTableContext.FitEntryNumber++;
+
+                MicrocodeBuffer += SlotSize;
+              }
+            }
           }
           break;
         case FIT_TABLE_TYPE_TPM_POLICY:
-- 
2.16.2.windows.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [edk2-devel] [Bug 2321] Add FitGen feature to support uCode Capsule Update
  2019-11-13  0:01         ` [edk2-devel] " Chen, Kenji
@ 2019-11-13  0:47           ` Liming Gao
  2019-11-13  1:43             ` Chen, Kenji
       [not found]             ` <15D6956B317AC3B8.15925@groups.io>
  0 siblings, 2 replies; 7+ messages in thread
From: Liming Gao @ 2019-11-13  0:47 UTC (permalink / raw)
  To: Chen, Kenji, Ke, VincentX; +Cc: 'devel@edk2.groups.io'

Kenji:
  This patch adds -S option for Slotsize. Please update FitGen tool help message to list this new option. 
  And, you also need to update BZ https://bugzilla.tianocore.org/show_bug.cgi?id=2321 for this change. 
  Based on current description in BZ, I don't know why need to add -S option.  

Thanks
Liming
>-----Original Message-----
>From: Chen, Kenji
>Sent: Wednesday, November 13, 2019 8:01 AM
>To: Gao, Liming <liming.gao@intel.com>; Ke, VincentX
><vincentx.ke@intel.com>
>Cc: 'devel@edk2.groups.io' <devel@edk2.groups.io>
>Subject: RE: [edk2-devel] [Bug 2321] Add FitGen feature to support uCode
>Capsule Update
>
>Updating the correct one.
>+ Vincent to confirm the patch.
>
>Thanks, Kenji.
>-----Original Message-----
>From: Gao, Liming <liming.gao@intel.com>
>Sent: Tuesday, November 12, 2019 11:43 PM
>To: Chen, Kenji <kenji.chen@intel.com>
>Subject: RE: [edk2-devel] [Bug 2321] Add FitGen feature to support uCode
>Capsule Update
>
>Here is edk2platform git repo https://github.com/tianocore/edk2-platforms
>
>> -----Original Message-----
>> From: Gao, Liming
>> Sent: Tuesday, November 12, 2019 11:42 PM
>> To: Chen, Kenji <kenji.chen@intel.com>
>> Subject: RE: [edk2-devel] [Bug 2321] Add FitGen feature to support uCode
>Capsule Update
>>
>> Can you update the patch base on edk2-
>platforms\Silicon\Intel\Tools\FitGen source?
>>
>> > -----Original Message-----
>> > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Chen,
>Kenji
>> > Sent: Friday, November 8, 2019 4:49 PM
>> > To: 'devel@edk2.groups.io' <devel@edk2.groups.io>
>> > Subject: Re: [edk2-devel] [Bug 2321] Add FitGen feature to support uCode
>Capsule Update
>> >
>> > Having problems in git send-email. Send it by outlook.
>> >
>> > -----Original Message-----
>> > From: bugzilla-daemon@bugzilla.tianocore.org <bugzilla-
>daemon@bugzilla.tianocore.org>
>> > Sent: Monday, November 4, 2019 10:14 AM
>> > To: Chen, Kenji <kenji.chen@intel.com>
>> > Subject: [Bug 2321] Add FitGen feature to support uCode Capsule Update
>> >
>> > https://bugzilla.tianocore.org/show_bug.cgi?id=2321
>> >
>> > Liming Gao <liming.gao@intel.com> changed:
>> >
>> >            What    |Removed                     |Added
>> > ----------------------------------------------------------------------------
>> >              Status|UNCONFIRMED                 |CONFIRMED
>> >                  CC|                            |liming.gao@intel.com
>> >            Assignee|michael.d.kinney@intel.com  |kenji.chen@intel.com
>> >      Ever confirmed|0                           |1
>> >
>> > --- Comment #1 from Liming Gao <liming.gao@intel.com> --- Kenji is
>working on the patch.
>> >
>> > --
>> > You are receiving this mail because:
>> > You are the assignee for the bug.
>> > You reported the bug.
>> >
>> > 
>
>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [edk2-devel] [Bug 2321] Add FitGen feature to support uCode Capsule Update
  2019-11-13  0:47           ` Liming Gao
@ 2019-11-13  1:43             ` Chen, Kenji
       [not found]             ` <15D6956B317AC3B8.15925@groups.io>
  1 sibling, 0 replies; 7+ messages in thread
From: Chen, Kenji @ 2019-11-13  1:43 UTC (permalink / raw)
  To: Gao, Liming, Ke, VincentX; +Cc: 'devel@edk2.groups.io'

[-- Attachment #1: Type: text/plain, Size: 3294 bytes --]

Sure. Added the comment and help message. Will update BZ.

-----Original Message-----
From: Gao, Liming <liming.gao@intel.com> 
Sent: Wednesday, November 13, 2019 8:48 AM
To: Chen, Kenji <kenji.chen@intel.com>; Ke, VincentX <vincentx.ke@intel.com>
Cc: 'devel@edk2.groups.io' <devel@edk2.groups.io>
Subject: RE: [edk2-devel] [Bug 2321] Add FitGen feature to support uCode Capsule Update

Kenji:
  This patch adds -S option for Slotsize. Please update FitGen tool help message to list this new option. 
  And, you also need to update BZ https://bugzilla.tianocore.org/show_bug.cgi?id=2321 for this change. 
  Based on current description in BZ, I don't know why need to add -S option.  

Thanks
Liming
>-----Original Message-----
>From: Chen, Kenji
>Sent: Wednesday, November 13, 2019 8:01 AM
>To: Gao, Liming <liming.gao@intel.com>; Ke, VincentX 
><vincentx.ke@intel.com>
>Cc: 'devel@edk2.groups.io' <devel@edk2.groups.io>
>Subject: RE: [edk2-devel] [Bug 2321] Add FitGen feature to support 
>uCode Capsule Update
>
>Updating the correct one.
>+ Vincent to confirm the patch.
>
>Thanks, Kenji.
>-----Original Message-----
>From: Gao, Liming <liming.gao@intel.com>
>Sent: Tuesday, November 12, 2019 11:43 PM
>To: Chen, Kenji <kenji.chen@intel.com>
>Subject: RE: [edk2-devel] [Bug 2321] Add FitGen feature to support 
>uCode Capsule Update
>
>Here is edk2platform git repo 
>https://github.com/tianocore/edk2-platforms
>
>> -----Original Message-----
>> From: Gao, Liming
>> Sent: Tuesday, November 12, 2019 11:42 PM
>> To: Chen, Kenji <kenji.chen@intel.com>
>> Subject: RE: [edk2-devel] [Bug 2321] Add FitGen feature to support 
>> uCode
>Capsule Update
>>
>> Can you update the patch base on edk2-
>platforms\Silicon\Intel\Tools\FitGen source?
>>
>> > -----Original Message-----
>> > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of 
>> > Chen,
>Kenji
>> > Sent: Friday, November 8, 2019 4:49 PM
>> > To: 'devel@edk2.groups.io' <devel@edk2.groups.io>
>> > Subject: Re: [edk2-devel] [Bug 2321] Add FitGen feature to support 
>> > uCode
>Capsule Update
>> >
>> > Having problems in git send-email. Send it by outlook.
>> >
>> > -----Original Message-----
>> > From: bugzilla-daemon@bugzilla.tianocore.org <bugzilla-
>daemon@bugzilla.tianocore.org>
>> > Sent: Monday, November 4, 2019 10:14 AM
>> > To: Chen, Kenji <kenji.chen@intel.com>
>> > Subject: [Bug 2321] Add FitGen feature to support uCode Capsule 
>> > Update
>> >
>> > https://bugzilla.tianocore.org/show_bug.cgi?id=2321
>> >
>> > Liming Gao <liming.gao@intel.com> changed:
>> >
>> >            What    |Removed                     |Added
>> > ----------------------------------------------------------------------------
>> >              Status|UNCONFIRMED                 |CONFIRMED
>> >                  CC|                            |liming.gao@intel.com
>> >            Assignee|michael.d.kinney@intel.com  |kenji.chen@intel.com
>> >      Ever confirmed|0                           |1
>> >
>> > --- Comment #1 from Liming Gao <liming.gao@intel.com> --- Kenji is
>working on the patch.
>> >
>> > --
>> > You are receiving this mail because:
>> > You are the assignee for the bug.
>> > You reported the bug.
>> >
>> > 
>
>



[-- Attachment #2: 0001-FitGen-Add-FitGen-feature-to-support-uCode-Capsule-U_20191113.patch --]
[-- Type: application/octet-stream, Size: 9272 bytes --]

From 7eb886ff13b52d726847e4c26b1b52b5b639aadc Mon Sep 17 00:00:00 2001
From: Kenji Chen <kenji.chen@intel.com>
Date: Tue, 5 Nov 2019 11:01:32 +0800
Subject: [PATCH] FitGen: Add FitGen feature to support uCode Capsule Update

Add slot mode handling with a header array.

Change-Id: Icee955a8cb4456ceb233e7a068fa7db733464626
Signed-off-by: Kenji Chen <kenji.chen@intel.com>
---
 Silicon/Intel/Tools/FitGen/FitGen.c | 94 +++++++++++++++++++++++++++++++------
 1 file changed, 79 insertions(+), 15 deletions(-)

diff --git a/Silicon/Intel/Tools/FitGen/FitGen.c b/Silicon/Intel/Tools/FitGen/FitGen.c
index faf98800..dc760f02 100644
--- a/Silicon/Intel/Tools/FitGen/FitGen.c
+++ b/Silicon/Intel/Tools/FitGen/FitGen.c
@@ -316,7 +316,8 @@ Returns:
           "\t[-NA]\n"
           "\t[-CLEAR]\n"
           "\t[-I <BiosInfoGuid>]\n"
-          "\t[-S <StartupAcmAddress StartupAcmSize>|<StartupAcmGuid>] [-V <StartupAcmVersion>]\n"
+          "\t[-S <MicrocodeSlotSize>]\n"
+          "\t[-A <StartupAcmAddress StartupAcmSize>|<StartupAcmGuid>] [-V <StartupAcmVersion>]\n"
           "\t[-B <BiosModuleAddress BiosModuleSize>] [-B ...] [-V <BiosModuleVersion>]\n"
           "\t[-M <MicrocodeAddress MicrocodeSize>] [-M ...]|[-U <MicrocodeFv MicrocodeBase>|<MicrocodeRegionOffset MicrocodeRegionSize>|<MicrocodeGuid>] [-V <MicrocodeVersion>]\n"
           "\t[-O RecordType <RecordDataAddress RecordDataSize>|<RESERVE RecordDataSize>|<RecordDataGuid>|<RecordBinFile> [-V <RecordVersion>]] [-O ... [-V ...]]\n"
@@ -340,6 +341,7 @@ Returns:
   printf ("\tMicrocodeRegionOffset  - Offset of Microcode region in input FD image.\n");
   printf ("\tMicrocodeRegionSize    - Size of Microcode region in input FD image.\n");
   printf ("\tMicrocodeGuid          - Guid of Microcode Module.\n");
+  printf ("\tMicrocodeSlotSize      - Occupied region size of each Microcode binary.\n");
   printf ("\t-NA                    - No 0x800 aligned Microcode requirement. No -NA means Microcode is 0x800 aligned.\n");
   printf ("\tRecordType             - FIT entry record type. User should ensure it is ordered.\n");
   printf ("\tRecordDataAddress      - FIT entry record data address.\n");
@@ -765,6 +767,7 @@ Returns:
 {
   EFI_GUID  Guid;
   INTN      Index;
+  UINTN     MicrocodeIndex;
   UINT8     *FileBuffer;
   UINT32    FileSize;
   UINT32    Type;
@@ -774,8 +777,10 @@ Returns:
   UINT32    MicrocodeBase;
   UINT32    MicrocodeSize;
   UINT8     *MicrocodeBuffer;
+  UINT8     *MicrocodeBufferEnd;
   UINT32    MicrocodeRegionOffset;
   UINT32    MicrocodeRegionSize;
+  UINT32    SlotSize;
   STATUS    Status;
   EFI_FIRMWARE_VOLUME_HEADER  *FvHeader;
   UINTN                       FitEntryNumber;
@@ -783,6 +788,7 @@ Returns:
   BIOS_INFO_HEADER            *BiosInfo;
   BIOS_INFO_STRUCT            *BiosInfoStruct;
   UINTN                       BiosInfoIndex;
+  UINT32                      AlignmentByte;
 
   //
   // Init index
@@ -900,7 +906,22 @@ Returns:
   }
 
   //
-  // 0.5 BiosInfo
+  // 0.5 SlotSize
+  //
+  if ((Index + 1 >= argc) ||
+      ((strcmp (argv[Index], "-S") != 0) &&
+       (strcmp (argv[Index], "-s") != 0)) ) {
+    //
+    // Bypass
+    //
+    SlotSize = 0;
+  } else {
+    SlotSize = xtoi (argv[Index + 1]);
+    Index += 2;
+  }
+
+  //
+  // 0.6 BiosInfo
   //
   if ((Index + 1 >= argc) ||
       ((strcmp (argv[Index], "-I") != 0) &&
@@ -998,6 +1019,7 @@ Returns:
 
             MicrocodeFileBuffer = FLASH_TO_MEMORY (MicrocodeRegionOffset, FdBuffer, FdSize);
             MicrocodeFileSize = MicrocodeRegionSize;
+            MicrocodeBufferEnd = MicrocodeFileBuffer + MicrocodeFileSize;
             MicrocodeBase = MicrocodeRegionOffset;
 
             FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)MicrocodeFileBuffer;
@@ -1007,13 +1029,26 @@ Returns:
             } else {
               MicrocodeBuffer = MicrocodeFileBuffer;
             }
+
+            AlignmentByte = 1;
+            AlignmentByte = AlignmentByte << ((FvHeader->Attributes&0x000F0000) >> 16);
+
+            ///
+            /// Make MicrocodeBuffer address to alignment.
+            ///
+            if ((UINT32)MicrocodeBuffer % AlignmentByte != 0) {
+              MicrocodeBuffer = (UINT8 *)((UINT32)MicrocodeBuffer &~(AlignmentByte - 1));
+              MicrocodeBuffer += AlignmentByte;
+            }
+
             while ((UINT32)(MicrocodeBuffer - MicrocodeFileBuffer) < MicrocodeFileSize) {
-              if (*(UINT32 *)(MicrocodeBuffer) != 0x1) { // HeaderVersion
-                break;
-              }
-              if (*(UINT32 *)(MicrocodeBuffer + 20) != 0x1) { // LoaderVersion
-                break;
+              if (*(UINT32 *)(MicrocodeBuffer) != 0x1 ||
+                  *(UINT32 *)(MicrocodeBuffer + 20) != 0x1
+                 ) { // HeaderVersion
+                MicrocodeBuffer += 1024;
+                continue;
               }
+
               if (*(UINT32 *)(MicrocodeBuffer + 28) == 0) { // DataSize
                 MicrocodeSize = 2048;
               } else {
@@ -1036,12 +1071,41 @@ Returns:
               }
               gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Type = FIT_TABLE_TYPE_MICROCODE;
               gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Address = MicrocodeBase + ((UINT32) (UINTN) MicrocodeBuffer - (UINT32) (UINTN) MicrocodeFileBuffer);
-              gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Size = MicrocodeSize;
+              //
+              // No longer use.
+              //
+              //gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Size = MicrocodeSize;
               gFitTableContext.MicrocodeNumber++;
               gFitTableContext.FitEntryNumber++;
 
               MicrocodeBuffer += MicrocodeSize;
             }
+
+            if (SlotSize != 0) {
+              ///
+              /// Check whether each uCode is alignment with SlotSize bytes.
+              ///
+              for (MicrocodeIndex = 1; MicrocodeIndex < (INTN)gFitTableContext.MicrocodeNumber; MicrocodeIndex++) {
+                if (gFitTableContext.Microcode[MicrocodeIndex].Address - gFitTableContext.Microcode[MicrocodeIndex - 1].Address != SlotSize) {
+                  printf ("uCode must be follow SlotSize(%lu) alignment.\n", SlotSize);
+                  ASSERT (FALSE);
+                }
+              }
+
+              ///
+              /// Assume the empty space follows the uCode array.
+              ///
+              MicrocodeBuffer = (UINT8 *)(gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber - 1].Address - MicrocodeBase + MicrocodeFileBuffer);
+              MicrocodeBuffer += SlotSize;
+              while (MicrocodeBuffer + SlotSize <= MicrocodeBufferEnd) {
+                gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Type = FIT_TABLE_TYPE_MICROCODE;
+                gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Address = MicrocodeBase + ((UINT32) (UINTN) MicrocodeBuffer - (UINT32) (UINTN) MicrocodeFileBuffer);
+                gFitTableContext.MicrocodeNumber++;
+                gFitTableContext.FitEntryNumber++;
+
+                MicrocodeBuffer += SlotSize;
+              }
+            }
           }
           break;
         case FIT_TABLE_TYPE_TPM_POLICY:
@@ -1091,20 +1155,20 @@ Returns:
   //
   do {
     if ((Index + 1 >= argc) ||
-        ((strcmp (argv[Index], "-S") != 0) &&
-         (strcmp (argv[Index], "-s") != 0)) ) {
+        ((strcmp (argv[Index], "-A") != 0) &&
+         (strcmp (argv[Index], "-a") != 0)) ) {
       if (BiosInfoExist && (gFitTableContext.StartupAcm.Type == FIT_TABLE_TYPE_STARTUP_ACM)) {
         break;
       }
-//      Error (NULL, 0, 0, "-S Parameter incorrect, expect -S!", NULL);
+//      Error (NULL, 0, 0, "-A Parameter incorrect, expect -A!", NULL);
 //      return 0;
-      printf ("-S not found. WARNING!\n");
+      printf ("-A not found. WARNING!\n");
       break;
     }
     if (IsGuidData (argv[Index + 1], &Guid)) {
       FileBuffer = FindFileFromFvByGuid (FdBuffer, FdSize, &Guid, &FileSize);
       if (FileBuffer == NULL) {
-        Error (NULL, 0, 0, "-S Parameter incorrect, GUID not found!", "%s", argv[Index + 1]);
+        Error (NULL, 0, 0, "-A Parameter incorrect, GUID not found!", "%s", argv[Index + 1]);
         // not found
         return 0;
       }
@@ -1112,7 +1176,7 @@ Returns:
       Index += 2;
     } else {
       if (Index + 2 >= argc) {
-        Error (NULL, 0, 0, "-S Parameter incorrect, expect Address Size!", NULL);
+        Error (NULL, 0, 0, "-A Parameter incorrect, expect Address Size!", NULL);
         return 0;
       }
       FileBuffer = (UINT8 *) (UINTN) xtoi (argv[Index + 1]);
@@ -1120,7 +1184,7 @@ Returns:
       Index += 3;
     }
     if (gFitTableContext.StartupAcm.Type != 0) {
-      Error (NULL, 0, 0, "-S Parameter incorrect, Duplicated StartupAcm!", NULL);
+      Error (NULL, 0, 0, "-A Parameter incorrect, Duplicated StartupAcm!", NULL);
       return 0;
     }
     gFitTableContext.StartupAcm.Type = FIT_TABLE_TYPE_STARTUP_ACM;
-- 
2.16.2.windows.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [edk2-devel] [Bug 2321] Add FitGen feature to support uCode Capsule Update
       [not found]             ` <15D6956B317AC3B8.15925@groups.io>
@ 2019-11-13  1:52               ` Chen, Kenji
  2019-11-13  1:53                 ` Liming Gao
       [not found]               ` <15D695F978FFA77A.3623@groups.io>
  1 sibling, 1 reply; 7+ messages in thread
From: Chen, Kenji @ 2019-11-13  1:52 UTC (permalink / raw)
  To: devel@edk2.groups.io, Chen, Kenji, Gao, Liming, Ke, VincentX

[-- Attachment #1: Type: text/plain, Size: 3835 bytes --]

Newer version. 

Add -L/-l for Microcode slot mode.

Hi Vincent, Pls follow this to change the usage in postbuild.bat when generating BIOS image.

Thanks, Kenji.
-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Chen, Kenji
Sent: Wednesday, November 13, 2019 9:43 AM
To: Gao, Liming <liming.gao@intel.com>; Ke, VincentX <vincentx.ke@intel.com>
Cc: 'devel@edk2.groups.io' <devel@edk2.groups.io>
Subject: Re: [edk2-devel] [Bug 2321] Add FitGen feature to support uCode Capsule Update

Sure. Added the comment and help message. Will update BZ.

-----Original Message-----
From: Gao, Liming <liming.gao@intel.com>
Sent: Wednesday, November 13, 2019 8:48 AM
To: Chen, Kenji <kenji.chen@intel.com>; Ke, VincentX <vincentx.ke@intel.com>
Cc: 'devel@edk2.groups.io' <devel@edk2.groups.io>
Subject: RE: [edk2-devel] [Bug 2321] Add FitGen feature to support uCode Capsule Update

Kenji:
  This patch adds -S option for Slotsize. Please update FitGen tool help message to list this new option. 
  And, you also need to update BZ https://bugzilla.tianocore.org/show_bug.cgi?id=2321 for this change. 
  Based on current description in BZ, I don't know why need to add -S option.  

Thanks
Liming
>-----Original Message-----
>From: Chen, Kenji
>Sent: Wednesday, November 13, 2019 8:01 AM
>To: Gao, Liming <liming.gao@intel.com>; Ke, VincentX 
><vincentx.ke@intel.com>
>Cc: 'devel@edk2.groups.io' <devel@edk2.groups.io>
>Subject: RE: [edk2-devel] [Bug 2321] Add FitGen feature to support 
>uCode Capsule Update
>
>Updating the correct one.
>+ Vincent to confirm the patch.
>
>Thanks, Kenji.
>-----Original Message-----
>From: Gao, Liming <liming.gao@intel.com>
>Sent: Tuesday, November 12, 2019 11:43 PM
>To: Chen, Kenji <kenji.chen@intel.com>
>Subject: RE: [edk2-devel] [Bug 2321] Add FitGen feature to support 
>uCode Capsule Update
>
>Here is edk2platform git repo
>https://github.com/tianocore/edk2-platforms
>
>> -----Original Message-----
>> From: Gao, Liming
>> Sent: Tuesday, November 12, 2019 11:42 PM
>> To: Chen, Kenji <kenji.chen@intel.com>
>> Subject: RE: [edk2-devel] [Bug 2321] Add FitGen feature to support 
>> uCode
>Capsule Update
>>
>> Can you update the patch base on edk2-
>platforms\Silicon\Intel\Tools\FitGen source?
>>
>> > -----Original Message-----
>> > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of 
>> > Chen,
>Kenji
>> > Sent: Friday, November 8, 2019 4:49 PM
>> > To: 'devel@edk2.groups.io' <devel@edk2.groups.io>
>> > Subject: Re: [edk2-devel] [Bug 2321] Add FitGen feature to support 
>> > uCode
>Capsule Update
>> >
>> > Having problems in git send-email. Send it by outlook.
>> >
>> > -----Original Message-----
>> > From: bugzilla-daemon@bugzilla.tianocore.org <bugzilla-
>daemon@bugzilla.tianocore.org>
>> > Sent: Monday, November 4, 2019 10:14 AM
>> > To: Chen, Kenji <kenji.chen@intel.com>
>> > Subject: [Bug 2321] Add FitGen feature to support uCode Capsule 
>> > Update
>> >
>> > https://bugzilla.tianocore.org/show_bug.cgi?id=2321
>> >
>> > Liming Gao <liming.gao@intel.com> changed:
>> >
>> >            What    |Removed                     |Added
>> > ----------------------------------------------------------------------------
>> >              Status|UNCONFIRMED                 |CONFIRMED
>> >                  CC|                            |liming.gao@intel.com
>> >            Assignee|michael.d.kinney@intel.com  |kenji.chen@intel.com
>> >      Ever confirmed|0                           |1
>> >
>> > --- Comment #1 from Liming Gao <liming.gao@intel.com> --- Kenji is
>working on the patch.
>> >
>> > --
>> > You are receiving this mail because:
>> > You are the assignee for the bug.
>> > You reported the bug.
>> >
>> > 
>
>






[-- Attachment #2: 0001-FitGen-Add-FitGen-feature-to-support-uCode-Capsule-U_20191113_1.patch --]
[-- Type: application/octet-stream, Size: 9272 bytes --]

From 7eb886ff13b52d726847e4c26b1b52b5b639aadc Mon Sep 17 00:00:00 2001
From: Kenji Chen <kenji.chen@intel.com>
Date: Tue, 5 Nov 2019 11:01:32 +0800
Subject: [PATCH] FitGen: Add FitGen feature to support uCode Capsule Update

Add slot mode handling with a header array.

Change-Id: Icee955a8cb4456ceb233e7a068fa7db733464626
Signed-off-by: Kenji Chen <kenji.chen@intel.com>
---
 Silicon/Intel/Tools/FitGen/FitGen.c | 94 +++++++++++++++++++++++++++++++------
 1 file changed, 79 insertions(+), 15 deletions(-)

diff --git a/Silicon/Intel/Tools/FitGen/FitGen.c b/Silicon/Intel/Tools/FitGen/FitGen.c
index faf98800..dc760f02 100644
--- a/Silicon/Intel/Tools/FitGen/FitGen.c
+++ b/Silicon/Intel/Tools/FitGen/FitGen.c
@@ -316,7 +316,8 @@ Returns:
           "\t[-NA]\n"
           "\t[-CLEAR]\n"
           "\t[-I <BiosInfoGuid>]\n"
-          "\t[-S <StartupAcmAddress StartupAcmSize>|<StartupAcmGuid>] [-V <StartupAcmVersion>]\n"
+          "\t[-S <MicrocodeSlotSize>]\n"
+          "\t[-A <StartupAcmAddress StartupAcmSize>|<StartupAcmGuid>] [-V <StartupAcmVersion>]\n"
           "\t[-B <BiosModuleAddress BiosModuleSize>] [-B ...] [-V <BiosModuleVersion>]\n"
           "\t[-M <MicrocodeAddress MicrocodeSize>] [-M ...]|[-U <MicrocodeFv MicrocodeBase>|<MicrocodeRegionOffset MicrocodeRegionSize>|<MicrocodeGuid>] [-V <MicrocodeVersion>]\n"
           "\t[-O RecordType <RecordDataAddress RecordDataSize>|<RESERVE RecordDataSize>|<RecordDataGuid>|<RecordBinFile> [-V <RecordVersion>]] [-O ... [-V ...]]\n"
@@ -340,6 +341,7 @@ Returns:
   printf ("\tMicrocodeRegionOffset  - Offset of Microcode region in input FD image.\n");
   printf ("\tMicrocodeRegionSize    - Size of Microcode region in input FD image.\n");
   printf ("\tMicrocodeGuid          - Guid of Microcode Module.\n");
+  printf ("\tMicrocodeSlotSize      - Occupied region size of each Microcode binary.\n");
   printf ("\t-NA                    - No 0x800 aligned Microcode requirement. No -NA means Microcode is 0x800 aligned.\n");
   printf ("\tRecordType             - FIT entry record type. User should ensure it is ordered.\n");
   printf ("\tRecordDataAddress      - FIT entry record data address.\n");
@@ -765,6 +767,7 @@ Returns:
 {
   EFI_GUID  Guid;
   INTN      Index;
+  UINTN     MicrocodeIndex;
   UINT8     *FileBuffer;
   UINT32    FileSize;
   UINT32    Type;
@@ -774,8 +777,10 @@ Returns:
   UINT32    MicrocodeBase;
   UINT32    MicrocodeSize;
   UINT8     *MicrocodeBuffer;
+  UINT8     *MicrocodeBufferEnd;
   UINT32    MicrocodeRegionOffset;
   UINT32    MicrocodeRegionSize;
+  UINT32    SlotSize;
   STATUS    Status;
   EFI_FIRMWARE_VOLUME_HEADER  *FvHeader;
   UINTN                       FitEntryNumber;
@@ -783,6 +788,7 @@ Returns:
   BIOS_INFO_HEADER            *BiosInfo;
   BIOS_INFO_STRUCT            *BiosInfoStruct;
   UINTN                       BiosInfoIndex;
+  UINT32                      AlignmentByte;
 
   //
   // Init index
@@ -900,7 +906,22 @@ Returns:
   }
 
   //
-  // 0.5 BiosInfo
+  // 0.5 SlotSize
+  //
+  if ((Index + 1 >= argc) ||
+      ((strcmp (argv[Index], "-S") != 0) &&
+       (strcmp (argv[Index], "-s") != 0)) ) {
+    //
+    // Bypass
+    //
+    SlotSize = 0;
+  } else {
+    SlotSize = xtoi (argv[Index + 1]);
+    Index += 2;
+  }
+
+  //
+  // 0.6 BiosInfo
   //
   if ((Index + 1 >= argc) ||
       ((strcmp (argv[Index], "-I") != 0) &&
@@ -998,6 +1019,7 @@ Returns:
 
             MicrocodeFileBuffer = FLASH_TO_MEMORY (MicrocodeRegionOffset, FdBuffer, FdSize);
             MicrocodeFileSize = MicrocodeRegionSize;
+            MicrocodeBufferEnd = MicrocodeFileBuffer + MicrocodeFileSize;
             MicrocodeBase = MicrocodeRegionOffset;
 
             FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)MicrocodeFileBuffer;
@@ -1007,13 +1029,26 @@ Returns:
             } else {
               MicrocodeBuffer = MicrocodeFileBuffer;
             }
+
+            AlignmentByte = 1;
+            AlignmentByte = AlignmentByte << ((FvHeader->Attributes&0x000F0000) >> 16);
+
+            ///
+            /// Make MicrocodeBuffer address to alignment.
+            ///
+            if ((UINT32)MicrocodeBuffer % AlignmentByte != 0) {
+              MicrocodeBuffer = (UINT8 *)((UINT32)MicrocodeBuffer &~(AlignmentByte - 1));
+              MicrocodeBuffer += AlignmentByte;
+            }
+
             while ((UINT32)(MicrocodeBuffer - MicrocodeFileBuffer) < MicrocodeFileSize) {
-              if (*(UINT32 *)(MicrocodeBuffer) != 0x1) { // HeaderVersion
-                break;
-              }
-              if (*(UINT32 *)(MicrocodeBuffer + 20) != 0x1) { // LoaderVersion
-                break;
+              if (*(UINT32 *)(MicrocodeBuffer) != 0x1 ||
+                  *(UINT32 *)(MicrocodeBuffer + 20) != 0x1
+                 ) { // HeaderVersion
+                MicrocodeBuffer += 1024;
+                continue;
               }
+
               if (*(UINT32 *)(MicrocodeBuffer + 28) == 0) { // DataSize
                 MicrocodeSize = 2048;
               } else {
@@ -1036,12 +1071,41 @@ Returns:
               }
               gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Type = FIT_TABLE_TYPE_MICROCODE;
               gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Address = MicrocodeBase + ((UINT32) (UINTN) MicrocodeBuffer - (UINT32) (UINTN) MicrocodeFileBuffer);
-              gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Size = MicrocodeSize;
+              //
+              // No longer use.
+              //
+              //gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Size = MicrocodeSize;
               gFitTableContext.MicrocodeNumber++;
               gFitTableContext.FitEntryNumber++;
 
               MicrocodeBuffer += MicrocodeSize;
             }
+
+            if (SlotSize != 0) {
+              ///
+              /// Check whether each uCode is alignment with SlotSize bytes.
+              ///
+              for (MicrocodeIndex = 1; MicrocodeIndex < (INTN)gFitTableContext.MicrocodeNumber; MicrocodeIndex++) {
+                if (gFitTableContext.Microcode[MicrocodeIndex].Address - gFitTableContext.Microcode[MicrocodeIndex - 1].Address != SlotSize) {
+                  printf ("uCode must be follow SlotSize(%lu) alignment.\n", SlotSize);
+                  ASSERT (FALSE);
+                }
+              }
+
+              ///
+              /// Assume the empty space follows the uCode array.
+              ///
+              MicrocodeBuffer = (UINT8 *)(gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber - 1].Address - MicrocodeBase + MicrocodeFileBuffer);
+              MicrocodeBuffer += SlotSize;
+              while (MicrocodeBuffer + SlotSize <= MicrocodeBufferEnd) {
+                gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Type = FIT_TABLE_TYPE_MICROCODE;
+                gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Address = MicrocodeBase + ((UINT32) (UINTN) MicrocodeBuffer - (UINT32) (UINTN) MicrocodeFileBuffer);
+                gFitTableContext.MicrocodeNumber++;
+                gFitTableContext.FitEntryNumber++;
+
+                MicrocodeBuffer += SlotSize;
+              }
+            }
           }
           break;
         case FIT_TABLE_TYPE_TPM_POLICY:
@@ -1091,20 +1155,20 @@ Returns:
   //
   do {
     if ((Index + 1 >= argc) ||
-        ((strcmp (argv[Index], "-S") != 0) &&
-         (strcmp (argv[Index], "-s") != 0)) ) {
+        ((strcmp (argv[Index], "-A") != 0) &&
+         (strcmp (argv[Index], "-a") != 0)) ) {
       if (BiosInfoExist && (gFitTableContext.StartupAcm.Type == FIT_TABLE_TYPE_STARTUP_ACM)) {
         break;
       }
-//      Error (NULL, 0, 0, "-S Parameter incorrect, expect -S!", NULL);
+//      Error (NULL, 0, 0, "-A Parameter incorrect, expect -A!", NULL);
 //      return 0;
-      printf ("-S not found. WARNING!\n");
+      printf ("-A not found. WARNING!\n");
       break;
     }
     if (IsGuidData (argv[Index + 1], &Guid)) {
       FileBuffer = FindFileFromFvByGuid (FdBuffer, FdSize, &Guid, &FileSize);
       if (FileBuffer == NULL) {
-        Error (NULL, 0, 0, "-S Parameter incorrect, GUID not found!", "%s", argv[Index + 1]);
+        Error (NULL, 0, 0, "-A Parameter incorrect, GUID not found!", "%s", argv[Index + 1]);
         // not found
         return 0;
       }
@@ -1112,7 +1176,7 @@ Returns:
       Index += 2;
     } else {
       if (Index + 2 >= argc) {
-        Error (NULL, 0, 0, "-S Parameter incorrect, expect Address Size!", NULL);
+        Error (NULL, 0, 0, "-A Parameter incorrect, expect Address Size!", NULL);
         return 0;
       }
       FileBuffer = (UINT8 *) (UINTN) xtoi (argv[Index + 1]);
@@ -1120,7 +1184,7 @@ Returns:
       Index += 3;
     }
     if (gFitTableContext.StartupAcm.Type != 0) {
-      Error (NULL, 0, 0, "-S Parameter incorrect, Duplicated StartupAcm!", NULL);
+      Error (NULL, 0, 0, "-A Parameter incorrect, Duplicated StartupAcm!", NULL);
       return 0;
     }
     gFitTableContext.StartupAcm.Type = FIT_TABLE_TYPE_STARTUP_ACM;
-- 
2.16.2.windows.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [edk2-devel] [Bug 2321] Add FitGen feature to support uCode Capsule Update
  2019-11-13  1:52               ` Chen, Kenji
@ 2019-11-13  1:53                 ` Liming Gao
  0 siblings, 0 replies; 7+ messages in thread
From: Liming Gao @ 2019-11-13  1:53 UTC (permalink / raw)
  To: Chen, Kenji, devel@edk2.groups.io, Ke, VincentX

The patch is not updated. 

>-----Original Message-----
>From: Chen, Kenji
>Sent: Wednesday, November 13, 2019 9:53 AM
>To: devel@edk2.groups.io; Chen, Kenji <kenji.chen@intel.com>; Gao, Liming
><liming.gao@intel.com>; Ke, VincentX <vincentx.ke@intel.com>
>Subject: RE: [edk2-devel] [Bug 2321] Add FitGen feature to support uCode
>Capsule Update
>
>Newer version.
>
>Add -L/-l for Microcode slot mode.
>
>Hi Vincent, Pls follow this to change the usage in postbuild.bat when
>generating BIOS image.
>
>Thanks, Kenji.
>-----Original Message-----
>From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Chen,
>Kenji
>Sent: Wednesday, November 13, 2019 9:43 AM
>To: Gao, Liming <liming.gao@intel.com>; Ke, VincentX
><vincentx.ke@intel.com>
>Cc: 'devel@edk2.groups.io' <devel@edk2.groups.io>
>Subject: Re: [edk2-devel] [Bug 2321] Add FitGen feature to support uCode
>Capsule Update
>
>Sure. Added the comment and help message. Will update BZ.
>
>-----Original Message-----
>From: Gao, Liming <liming.gao@intel.com>
>Sent: Wednesday, November 13, 2019 8:48 AM
>To: Chen, Kenji <kenji.chen@intel.com>; Ke, VincentX
><vincentx.ke@intel.com>
>Cc: 'devel@edk2.groups.io' <devel@edk2.groups.io>
>Subject: RE: [edk2-devel] [Bug 2321] Add FitGen feature to support uCode
>Capsule Update
>
>Kenji:
>  This patch adds -S option for Slotsize. Please update FitGen tool help
>message to list this new option.
>  And, you also need to update BZ
>https://bugzilla.tianocore.org/show_bug.cgi?id=2321 for this change.
>  Based on current description in BZ, I don't know why need to add -S option.
>
>Thanks
>Liming
>>-----Original Message-----
>>From: Chen, Kenji
>>Sent: Wednesday, November 13, 2019 8:01 AM
>>To: Gao, Liming <liming.gao@intel.com>; Ke, VincentX
>><vincentx.ke@intel.com>
>>Cc: 'devel@edk2.groups.io' <devel@edk2.groups.io>
>>Subject: RE: [edk2-devel] [Bug 2321] Add FitGen feature to support
>>uCode Capsule Update
>>
>>Updating the correct one.
>>+ Vincent to confirm the patch.
>>
>>Thanks, Kenji.
>>-----Original Message-----
>>From: Gao, Liming <liming.gao@intel.com>
>>Sent: Tuesday, November 12, 2019 11:43 PM
>>To: Chen, Kenji <kenji.chen@intel.com>
>>Subject: RE: [edk2-devel] [Bug 2321] Add FitGen feature to support
>>uCode Capsule Update
>>
>>Here is edk2platform git repo
>>https://github.com/tianocore/edk2-platforms
>>
>>> -----Original Message-----
>>> From: Gao, Liming
>>> Sent: Tuesday, November 12, 2019 11:42 PM
>>> To: Chen, Kenji <kenji.chen@intel.com>
>>> Subject: RE: [edk2-devel] [Bug 2321] Add FitGen feature to support
>>> uCode
>>Capsule Update
>>>
>>> Can you update the patch base on edk2-
>>platforms\Silicon\Intel\Tools\FitGen source?
>>>
>>> > -----Original Message-----
>>> > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
>>> > Chen,
>>Kenji
>>> > Sent: Friday, November 8, 2019 4:49 PM
>>> > To: 'devel@edk2.groups.io' <devel@edk2.groups.io>
>>> > Subject: Re: [edk2-devel] [Bug 2321] Add FitGen feature to support
>>> > uCode
>>Capsule Update
>>> >
>>> > Having problems in git send-email. Send it by outlook.
>>> >
>>> > -----Original Message-----
>>> > From: bugzilla-daemon@bugzilla.tianocore.org <bugzilla-
>>daemon@bugzilla.tianocore.org>
>>> > Sent: Monday, November 4, 2019 10:14 AM
>>> > To: Chen, Kenji <kenji.chen@intel.com>
>>> > Subject: [Bug 2321] Add FitGen feature to support uCode Capsule
>>> > Update
>>> >
>>> > https://bugzilla.tianocore.org/show_bug.cgi?id=2321
>>> >
>>> > Liming Gao <liming.gao@intel.com> changed:
>>> >
>>> >            What    |Removed                     |Added
>>> > ----------------------------------------------------------------------------
>>> >              Status|UNCONFIRMED                 |CONFIRMED
>>> >                  CC|                            |liming.gao@intel.com
>>> >            Assignee|michael.d.kinney@intel.com  |kenji.chen@intel.com
>>> >      Ever confirmed|0                           |1
>>> >
>>> > --- Comment #1 from Liming Gao <liming.gao@intel.com> --- Kenji is
>>working on the patch.
>>> >
>>> > --
>>> > You are receiving this mail because:
>>> > You are the assignee for the bug.
>>> > You reported the bug.
>>> >
>>> >
>>
>>
>
>
>
>
>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [edk2-devel] [Bug 2321] Add FitGen feature to support uCode Capsule Update
       [not found]               ` <15D695F978FFA77A.3623@groups.io>
@ 2019-11-13  1:59                 ` Chen, Kenji
  0 siblings, 0 replies; 7+ messages in thread
From: Chen, Kenji @ 2019-11-13  1:59 UTC (permalink / raw)
  To: devel@edk2.groups.io, Chen, Kenji, Gao, Liming, Ke, VincentX

[-- Attachment #1: Type: text/plain, Size: 4243 bytes --]

Adding the correct one.

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Chen, Kenji
Sent: Wednesday, November 13, 2019 9:53 AM
To: devel@edk2.groups.io; Chen, Kenji <kenji.chen@intel.com>; Gao, Liming <liming.gao@intel.com>; Ke, VincentX <vincentx.ke@intel.com>
Subject: Re: [edk2-devel] [Bug 2321] Add FitGen feature to support uCode Capsule Update

Newer version. 

Add -L/-l for Microcode slot mode.

Hi Vincent, Pls follow this to change the usage in postbuild.bat when generating BIOS image.

Thanks, Kenji.
-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Chen, Kenji
Sent: Wednesday, November 13, 2019 9:43 AM
To: Gao, Liming <liming.gao@intel.com>; Ke, VincentX <vincentx.ke@intel.com>
Cc: 'devel@edk2.groups.io' <devel@edk2.groups.io>
Subject: Re: [edk2-devel] [Bug 2321] Add FitGen feature to support uCode Capsule Update

Sure. Added the comment and help message. Will update BZ.

-----Original Message-----
From: Gao, Liming <liming.gao@intel.com>
Sent: Wednesday, November 13, 2019 8:48 AM
To: Chen, Kenji <kenji.chen@intel.com>; Ke, VincentX <vincentx.ke@intel.com>
Cc: 'devel@edk2.groups.io' <devel@edk2.groups.io>
Subject: RE: [edk2-devel] [Bug 2321] Add FitGen feature to support uCode Capsule Update

Kenji:
  This patch adds -S option for Slotsize. Please update FitGen tool help message to list this new option. 
  And, you also need to update BZ https://bugzilla.tianocore.org/show_bug.cgi?id=2321 for this change. 
  Based on current description in BZ, I don't know why need to add -S option.  

Thanks
Liming
>-----Original Message-----
>From: Chen, Kenji
>Sent: Wednesday, November 13, 2019 8:01 AM
>To: Gao, Liming <liming.gao@intel.com>; Ke, VincentX 
><vincentx.ke@intel.com>
>Cc: 'devel@edk2.groups.io' <devel@edk2.groups.io>
>Subject: RE: [edk2-devel] [Bug 2321] Add FitGen feature to support 
>uCode Capsule Update
>
>Updating the correct one.
>+ Vincent to confirm the patch.
>
>Thanks, Kenji.
>-----Original Message-----
>From: Gao, Liming <liming.gao@intel.com>
>Sent: Tuesday, November 12, 2019 11:43 PM
>To: Chen, Kenji <kenji.chen@intel.com>
>Subject: RE: [edk2-devel] [Bug 2321] Add FitGen feature to support 
>uCode Capsule Update
>
>Here is edk2platform git repo
>https://github.com/tianocore/edk2-platforms
>
>> -----Original Message-----
>> From: Gao, Liming
>> Sent: Tuesday, November 12, 2019 11:42 PM
>> To: Chen, Kenji <kenji.chen@intel.com>
>> Subject: RE: [edk2-devel] [Bug 2321] Add FitGen feature to support 
>> uCode
>Capsule Update
>>
>> Can you update the patch base on edk2-
>platforms\Silicon\Intel\Tools\FitGen source?
>>
>> > -----Original Message-----
>> > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of 
>> > Chen,
>Kenji
>> > Sent: Friday, November 8, 2019 4:49 PM
>> > To: 'devel@edk2.groups.io' <devel@edk2.groups.io>
>> > Subject: Re: [edk2-devel] [Bug 2321] Add FitGen feature to support 
>> > uCode
>Capsule Update
>> >
>> > Having problems in git send-email. Send it by outlook.
>> >
>> > -----Original Message-----
>> > From: bugzilla-daemon@bugzilla.tianocore.org <bugzilla-
>daemon@bugzilla.tianocore.org>
>> > Sent: Monday, November 4, 2019 10:14 AM
>> > To: Chen, Kenji <kenji.chen@intel.com>
>> > Subject: [Bug 2321] Add FitGen feature to support uCode Capsule 
>> > Update
>> >
>> > https://bugzilla.tianocore.org/show_bug.cgi?id=2321
>> >
>> > Liming Gao <liming.gao@intel.com> changed:
>> >
>> >            What    |Removed                     |Added
>> > ----------------------------------------------------------------------------
>> >              Status|UNCONFIRMED                 |CONFIRMED
>> >                  CC|                            |liming.gao@intel.com
>> >            Assignee|michael.d.kinney@intel.com  |kenji.chen@intel.com
>> >      Ever confirmed|0                           |1
>> >
>> > --- Comment #1 from Liming Gao <liming.gao@intel.com> --- Kenji is
>working on the patch.
>> >
>> > --
>> > You are receiving this mail because:
>> > You are the assignee for the bug.
>> > You reported the bug.
>> >
>> > 
>
>









[-- Attachment #2: 0001-FitGen-Add-FitGen-feature-to-support-uCode-Capsule-U_20191113_1.patch --]
[-- Type: application/octet-stream, Size: 7181 bytes --]

From 1af5c743adc4ba273a38fc21c1704d7d15c61f72 Mon Sep 17 00:00:00 2001
From: Kenji Chen <kenji.chen@intel.com>
Date: Tue, 5 Nov 2019 11:01:32 +0800
Subject: [PATCH] FitGen: Add FitGen feature to support uCode Capsule Update

Add slot mode handling with a header array.

Change-Id: Icee955a8cb4456ceb233e7a068fa7db733464626
Signed-off-by: Kenji Chen <kenji.chen@intel.com>
---
 Silicon/Intel/Tools/FitGen/FitGen.c | 78 +++++++++++++++++++++++++++++++++----
 1 file changed, 71 insertions(+), 7 deletions(-)

diff --git a/Silicon/Intel/Tools/FitGen/FitGen.c b/Silicon/Intel/Tools/FitGen/FitGen.c
index faf98800..9055776d 100644
--- a/Silicon/Intel/Tools/FitGen/FitGen.c
+++ b/Silicon/Intel/Tools/FitGen/FitGen.c
@@ -316,6 +316,7 @@ Returns:
           "\t[-NA]\n"
           "\t[-CLEAR]\n"
           "\t[-I <BiosInfoGuid>]\n"
+          "\t[-L <MicrocodeSlotSize>]\n"
           "\t[-S <StartupAcmAddress StartupAcmSize>|<StartupAcmGuid>] [-V <StartupAcmVersion>]\n"
           "\t[-B <BiosModuleAddress BiosModuleSize>] [-B ...] [-V <BiosModuleVersion>]\n"
           "\t[-M <MicrocodeAddress MicrocodeSize>] [-M ...]|[-U <MicrocodeFv MicrocodeBase>|<MicrocodeRegionOffset MicrocodeRegionSize>|<MicrocodeGuid>] [-V <MicrocodeVersion>]\n"
@@ -340,6 +341,7 @@ Returns:
   printf ("\tMicrocodeRegionOffset  - Offset of Microcode region in input FD image.\n");
   printf ("\tMicrocodeRegionSize    - Size of Microcode region in input FD image.\n");
   printf ("\tMicrocodeGuid          - Guid of Microcode Module.\n");
+  printf ("\tMicrocodeSlotSize      - Occupied region size of each Microcode binary.\n");
   printf ("\t-NA                    - No 0x800 aligned Microcode requirement. No -NA means Microcode is 0x800 aligned.\n");
   printf ("\tRecordType             - FIT entry record type. User should ensure it is ordered.\n");
   printf ("\tRecordDataAddress      - FIT entry record data address.\n");
@@ -765,6 +767,7 @@ Returns:
 {
   EFI_GUID  Guid;
   INTN      Index;
+  UINTN     MicrocodeIndex;
   UINT8     *FileBuffer;
   UINT32    FileSize;
   UINT32    Type;
@@ -774,8 +777,10 @@ Returns:
   UINT32    MicrocodeBase;
   UINT32    MicrocodeSize;
   UINT8     *MicrocodeBuffer;
+  UINT8     *MicrocodeBufferEnd;
   UINT32    MicrocodeRegionOffset;
   UINT32    MicrocodeRegionSize;
+  UINT32    SlotSize;
   STATUS    Status;
   EFI_FIRMWARE_VOLUME_HEADER  *FvHeader;
   UINTN                       FitEntryNumber;
@@ -783,6 +788,7 @@ Returns:
   BIOS_INFO_HEADER            *BiosInfo;
   BIOS_INFO_STRUCT            *BiosInfoStruct;
   UINTN                       BiosInfoIndex;
+  UINT32                      AlignmentByte;
 
   //
   // Init index
@@ -900,7 +906,22 @@ Returns:
   }
 
   //
-  // 0.5 BiosInfo
+  // 0.5 SlotSize
+  //
+  if ((Index + 1 >= argc) ||
+      ((strcmp (argv[Index], "-L") != 0) &&
+       (strcmp (argv[Index], "-l") != 0)) ) {
+    //
+    // Bypass
+    //
+    SlotSize = 0;
+  } else {
+    SlotSize = xtoi (argv[Index + 1]);
+    Index += 2;
+  }
+
+  //
+  // 0.6 BiosInfo
   //
   if ((Index + 1 >= argc) ||
       ((strcmp (argv[Index], "-I") != 0) &&
@@ -998,6 +1019,7 @@ Returns:
 
             MicrocodeFileBuffer = FLASH_TO_MEMORY (MicrocodeRegionOffset, FdBuffer, FdSize);
             MicrocodeFileSize = MicrocodeRegionSize;
+            MicrocodeBufferEnd = MicrocodeFileBuffer + MicrocodeFileSize;
             MicrocodeBase = MicrocodeRegionOffset;
 
             FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)MicrocodeFileBuffer;
@@ -1007,13 +1029,26 @@ Returns:
             } else {
               MicrocodeBuffer = MicrocodeFileBuffer;
             }
+
+            AlignmentByte = 1;
+            AlignmentByte = AlignmentByte << ((FvHeader->Attributes&0x000F0000) >> 16);
+
+            ///
+            /// Make MicrocodeBuffer address to alignment.
+            ///
+            if ((UINT32)MicrocodeBuffer % AlignmentByte != 0) {
+              MicrocodeBuffer = (UINT8 *)((UINT32)MicrocodeBuffer &~(AlignmentByte - 1));
+              MicrocodeBuffer += AlignmentByte;
+            }
+
             while ((UINT32)(MicrocodeBuffer - MicrocodeFileBuffer) < MicrocodeFileSize) {
-              if (*(UINT32 *)(MicrocodeBuffer) != 0x1) { // HeaderVersion
-                break;
-              }
-              if (*(UINT32 *)(MicrocodeBuffer + 20) != 0x1) { // LoaderVersion
-                break;
+              if (*(UINT32 *)(MicrocodeBuffer) != 0x1 ||
+                  *(UINT32 *)(MicrocodeBuffer + 20) != 0x1
+                 ) { // HeaderVersion
+                MicrocodeBuffer += 1024;
+                continue;
               }
+
               if (*(UINT32 *)(MicrocodeBuffer + 28) == 0) { // DataSize
                 MicrocodeSize = 2048;
               } else {
@@ -1036,12 +1071,41 @@ Returns:
               }
               gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Type = FIT_TABLE_TYPE_MICROCODE;
               gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Address = MicrocodeBase + ((UINT32) (UINTN) MicrocodeBuffer - (UINT32) (UINTN) MicrocodeFileBuffer);
-              gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Size = MicrocodeSize;
+              //
+              // No longer use.
+              //
+              //gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Size = MicrocodeSize;
               gFitTableContext.MicrocodeNumber++;
               gFitTableContext.FitEntryNumber++;
 
               MicrocodeBuffer += MicrocodeSize;
             }
+
+            if (SlotSize != 0) {
+              ///
+              /// Check whether each uCode is alignment with SlotSize bytes.
+              ///
+              for (MicrocodeIndex = 1; MicrocodeIndex < (INTN)gFitTableContext.MicrocodeNumber; MicrocodeIndex++) {
+                if (gFitTableContext.Microcode[MicrocodeIndex].Address - gFitTableContext.Microcode[MicrocodeIndex - 1].Address != SlotSize) {
+                  printf ("uCode must be follow SlotSize(%lu) alignment.\n", SlotSize);
+                  ASSERT (FALSE);
+                }
+              }
+
+              ///
+              /// Assume the empty space follows the uCode array.
+              ///
+              MicrocodeBuffer = (UINT8 *)(gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber - 1].Address - MicrocodeBase + MicrocodeFileBuffer);
+              MicrocodeBuffer += SlotSize;
+              while (MicrocodeBuffer + SlotSize <= MicrocodeBufferEnd) {
+                gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Type = FIT_TABLE_TYPE_MICROCODE;
+                gFitTableContext.Microcode[gFitTableContext.MicrocodeNumber].Address = MicrocodeBase + ((UINT32) (UINTN) MicrocodeBuffer - (UINT32) (UINTN) MicrocodeFileBuffer);
+                gFitTableContext.MicrocodeNumber++;
+                gFitTableContext.FitEntryNumber++;
+
+                MicrocodeBuffer += SlotSize;
+              }
+            }
           }
           break;
         case FIT_TABLE_TYPE_TPM_POLICY:
-- 
2.16.2.windows.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-11-13  2:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <bug-2321-591@https.bugzilla.tianocore.org/>
     [not found] ` <bug-2321-591-866w3Xggjl@https.bugzilla.tianocore.org/>
2019-11-08  8:49   ` [Bug 2321] Add FitGen feature to support uCode Capsule Update kenji.chen
     [not found]     ` <4A89E2EF3DFEDB4C8BFDE51014F606A14E53E843@SHSMSX104.ccr.corp.intel.com>
     [not found]       ` <4A89E2EF3DFEDB4C8BFDE51014F606A14E53E84D@SHSMSX104.ccr.corp.intel.com>
2019-11-13  0:01         ` [edk2-devel] " Chen, Kenji
2019-11-13  0:47           ` Liming Gao
2019-11-13  1:43             ` Chen, Kenji
     [not found]             ` <15D6956B317AC3B8.15925@groups.io>
2019-11-13  1:52               ` Chen, Kenji
2019-11-13  1:53                 ` Liming Gao
     [not found]               ` <15D695F978FFA77A.3623@groups.io>
2019-11-13  1:59                 ` Chen, Kenji

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox