public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Liming Gao" <liming.gao@intel.com>
To: devel@edk2.groups.io
Cc: Bob Feng <bob.c.feng@intel.com>
Subject: [edk2-platform] FitGen: Support FV with the extension header
Date: Wed,  5 Feb 2020 22:32:24 +0800	[thread overview]
Message-ID: <20200205143224.2038-1-liming.gao@intel.com> (raw)

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


             reply	other threads:[~2020-02-05 14:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-05 14:32 Liming Gao [this message]
2020-02-07  3:12 ` [edk2-platform] FitGen: Support FV with the extension header Bob Feng

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=20200205143224.2038-1-liming.gao@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