[edk2-devel] [edk2-platform] FitGen: Support FV with the extension header

Liming Gao posted 1 patch 33 weeks ago
Failed in applying to current master (apply log)
Silicon/Intel/Tools/FitGen/FitGen.c | 40 +++++++++++++++++++++++++++++++------
Silicon/Intel/Tools/FitGen/FitGen.h |  2 +-
2 files changed, 35 insertions(+), 7 deletions(-)

[edk2-devel] [edk2-platform] FitGen: Support FV with the extension header

Posted by Liming Gao 33 weeks ago
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2086

To find Microcode FILE in FV image, need to skip FV header and
FV extension header, then find the first RAW FFS file.

Cc: Bob Feng <bob.c.feng@intel.com>
Signed-off-by: Liming Gao <liming.gao@intel.com>
---
 Silicon/Intel/Tools/FitGen/FitGen.c | 40 +++++++++++++++++++++++++++++++------
 Silicon/Intel/Tools/FitGen/FitGen.h |  2 +-
 2 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/Silicon/Intel/Tools/FitGen/FitGen.c b/Silicon/Intel/Tools/FitGen/FitGen.c
index 9f1db32a15..5f5638dc8b 100644
--- a/Silicon/Intel/Tools/FitGen/FitGen.c
+++ b/Silicon/Intel/Tools/FitGen/FitGen.c
@@ -747,6 +747,37 @@ CheckOverlap (
   }
 }
 
+UINT8 *
+GetMicrocodeBufferFromFv (
+  EFI_FIRMWARE_VOLUME_HEADER *FvHeader
+  )
+{
+  UINT8 *MicrocodeBuffer;
+  EFI_FFS_FILE_HEADER *FfsHeader;
+
+  MicrocodeBuffer = NULL;
+  //
+  // Skip FV header + FV extension header + FFS header
+  //
+  FfsHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *) FvHeader + FvHeader->HeaderLength);
+  while ((UINT8 *) FfsHeader < (UINT8 *) FvHeader + FvHeader->FvLength) {
+    if (FfsHeader->Type == EFI_FV_FILETYPE_RAW) {
+      //
+      // Find the first RAW ffs file as Microcode Buffer
+      //
+      MicrocodeBuffer = (UINT8 *)(FfsHeader + 1);
+      break;
+    }
+    if (GetFfsFileLength (FfsHeader) == 0xFFFFFF) {
+      // spare space is found, and exit
+      break;
+    }
+    FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsHeader + ((GetFfsFileLength (FfsHeader)+7)&~7));
+  }
+
+  return MicrocodeBuffer;
+}
+
 UINT32
 GetFitEntryNumber (
   IN INTN   argc,
@@ -1047,8 +1078,7 @@ Returns:
 
             FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)MicrocodeFileBuffer;
             if (FvHeader->Signature == EFI_FVH_SIGNATURE) {
-              // Skip FV header + FFS header
-              MicrocodeBuffer = MicrocodeFileBuffer + sizeof(EFI_FIRMWARE_VOLUME_HEADER) + sizeof(EFI_FV_BLOCK_MAP_ENTRY) + sizeof(EFI_FFS_FILE_HEADER);
+              MicrocodeBuffer = GetMicrocodeBufferFromFv (FvHeader);
             } else {
               MicrocodeBuffer = MicrocodeFileBuffer;
             }
@@ -1388,8 +1418,7 @@ Returns:
 
         FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)MicrocodeFileBuffer;
         if (FvHeader->Signature == EFI_FVH_SIGNATURE) {
-          // Skip FV header + FFS header
-          MicrocodeBuffer = MicrocodeFileBuffer + sizeof(EFI_FIRMWARE_VOLUME_HEADER) + sizeof(EFI_FV_BLOCK_MAP_ENTRY) + sizeof(EFI_FFS_FILE_HEADER);
+          MicrocodeBuffer = GetMicrocodeBufferFromFv (FvHeader);
         } else {
           MicrocodeBuffer = MicrocodeFileBuffer;
         }
@@ -1401,8 +1430,7 @@ Returns:
 
         FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)MicrocodeFileBuffer;
         if (FvHeader->Signature == EFI_FVH_SIGNATURE) {
-          // Skip FV header + FFS header
-          MicrocodeBuffer = MicrocodeFileBuffer + sizeof(EFI_FIRMWARE_VOLUME_HEADER) + sizeof(EFI_FV_BLOCK_MAP_ENTRY) + sizeof(EFI_FFS_FILE_HEADER);
+          MicrocodeBuffer = GetMicrocodeBufferFromFv (FvHeader);
         } else {
           MicrocodeBuffer = MicrocodeFileBuffer;
         }
diff --git a/Silicon/Intel/Tools/FitGen/FitGen.h b/Silicon/Intel/Tools/FitGen/FitGen.h
index ecb5822d32..4d0a2dc6f8 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 57
+#define UTILITY_MINOR_VERSION 58
 #define UTILITY_DATE          __DATE__
 
 //
-- 
2.13.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#53829): https://edk2.groups.io/g/devel/message/53829
Mute This Topic: https://groups.io/mt/70996333/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-

Re: [edk2-devel] [edk2-platform] FitGen: Support FV with the extension header

Posted by Bob Feng 33 weeks ago
Reviewed-by: Bob Feng <bob.c.feng@intel.com>

-----Original Message-----
From: Gao, Liming <liming.gao@intel.com> 
Sent: Wednesday, February 5, 2020 10:32 PM
To: devel@edk2.groups.io
Cc: Feng, Bob C <bob.c.feng@intel.com>
Subject: [edk2-platform] FitGen: Support FV with the extension header

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

To find Microcode FILE in FV image, need to skip FV header and FV extension header, then find the first RAW FFS file.

Cc: Bob Feng <bob.c.feng@intel.com>
Signed-off-by: Liming Gao <liming.gao@intel.com>
---
 Silicon/Intel/Tools/FitGen/FitGen.c | 40 +++++++++++++++++++++++++++++++------
 Silicon/Intel/Tools/FitGen/FitGen.h |  2 +-
 2 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/Silicon/Intel/Tools/FitGen/FitGen.c b/Silicon/Intel/Tools/FitGen/FitGen.c
index 9f1db32a15..5f5638dc8b 100644
--- a/Silicon/Intel/Tools/FitGen/FitGen.c
+++ b/Silicon/Intel/Tools/FitGen/FitGen.c
@@ -747,6 +747,37 @@ CheckOverlap (
   }
 }
 
+UINT8 *
+GetMicrocodeBufferFromFv (
+  EFI_FIRMWARE_VOLUME_HEADER *FvHeader
+  )
+{
+  UINT8 *MicrocodeBuffer;
+  EFI_FFS_FILE_HEADER *FfsHeader;
+
+  MicrocodeBuffer = NULL;
+  //
+  // Skip FV header + FV extension header + FFS header  //  FfsHeader = 
+ (EFI_FFS_FILE_HEADER *)((UINT8 *) FvHeader + FvHeader->HeaderLength);  
+ while ((UINT8 *) FfsHeader < (UINT8 *) FvHeader + FvHeader->FvLength) {
+    if (FfsHeader->Type == EFI_FV_FILETYPE_RAW) {
+      //
+      // Find the first RAW ffs file as Microcode Buffer
+      //
+      MicrocodeBuffer = (UINT8 *)(FfsHeader + 1);
+      break;
+    }
+    if (GetFfsFileLength (FfsHeader) == 0xFFFFFF) {
+      // spare space is found, and exit
+      break;
+    }
+    FfsHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsHeader + 
+ ((GetFfsFileLength (FfsHeader)+7)&~7));  }
+
+  return MicrocodeBuffer;
+}
+
 UINT32
 GetFitEntryNumber (
   IN INTN   argc,
@@ -1047,8 +1078,7 @@ Returns:
 
             FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)MicrocodeFileBuffer;
             if (FvHeader->Signature == EFI_FVH_SIGNATURE) {
-              // Skip FV header + FFS header
-              MicrocodeBuffer = MicrocodeFileBuffer + sizeof(EFI_FIRMWARE_VOLUME_HEADER) + sizeof(EFI_FV_BLOCK_MAP_ENTRY) + sizeof(EFI_FFS_FILE_HEADER);
+              MicrocodeBuffer = GetMicrocodeBufferFromFv (FvHeader);
             } else {
               MicrocodeBuffer = MicrocodeFileBuffer;
             }
@@ -1388,8 +1418,7 @@ Returns:
 
         FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)MicrocodeFileBuffer;
         if (FvHeader->Signature == EFI_FVH_SIGNATURE) {
-          // Skip FV header + FFS header
-          MicrocodeBuffer = MicrocodeFileBuffer + sizeof(EFI_FIRMWARE_VOLUME_HEADER) + sizeof(EFI_FV_BLOCK_MAP_ENTRY) + sizeof(EFI_FFS_FILE_HEADER);
+          MicrocodeBuffer = GetMicrocodeBufferFromFv (FvHeader);
         } else {
           MicrocodeBuffer = MicrocodeFileBuffer;
         }
@@ -1401,8 +1430,7 @@ Returns:
 
         FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)MicrocodeFileBuffer;
         if (FvHeader->Signature == EFI_FVH_SIGNATURE) {
-          // Skip FV header + FFS header
-          MicrocodeBuffer = MicrocodeFileBuffer + sizeof(EFI_FIRMWARE_VOLUME_HEADER) + sizeof(EFI_FV_BLOCK_MAP_ENTRY) + sizeof(EFI_FFS_FILE_HEADER);
+          MicrocodeBuffer = GetMicrocodeBufferFromFv (FvHeader);
         } else {
           MicrocodeBuffer = MicrocodeFileBuffer;
         }
diff --git a/Silicon/Intel/Tools/FitGen/FitGen.h b/Silicon/Intel/Tools/FitGen/FitGen.h
index ecb5822d32..4d0a2dc6f8 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 57
+#define UTILITY_MINOR_VERSION 58
 #define UTILITY_DATE          __DATE__
 
 //
--
2.13.0.windows.1


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#53988): https://edk2.groups.io/g/devel/message/53988
Mute This Topic: https://groups.io/mt/70996333/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-