render / rpms / edk2

Forked from rpms/edk2 3 months ago
Clone

Blame SOURCES/0033-OvmfPkg-SmbiosPlatformDxe-use-PcdFirmware.patch

795857
From 8b2cc30989c009ab72951022bd017143764411b2 Mon Sep 17 00:00:00 2001
795857
From: Gerd Hoffmann <kraxel@redhat.com>
795857
Date: Mon, 28 Nov 2022 13:40:20 +0800
795857
Subject: OvmfPkg/SmbiosPlatformDxe: use PcdFirmware*
795857
795857
Instead of using hard-coded strings ("0.0.0" for BiosVersion etc)
795857
which is mostly useless read the PCDs (PcdFirmwareVendor,
795857
PcdFirmwareVersionString and PcdFirmwareReleaseDateString) and
795857
build the string table dynamuically at runtime.
795857
795857
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
795857
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
795857
(cherry picked from commit 4cb94f20b002c99dd2b4b75f07c5495b81a34ffd)
795857
795857
https://issues.redhat.com/browse/RHEL-75
795857
---
795857
 OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c | 115 +++++++++++-------
795857
 .../SmbiosPlatformDxe/SmbiosPlatformDxe.inf   |   6 +
795857
 .../XenSmbiosPlatformDxe.inf                  |   9 +-
795857
 3 files changed, 85 insertions(+), 45 deletions(-)
795857
795857
diff --git a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c
795857
index 94249d3ff1..dc1e6aed63 100644
795857
--- a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c
795857
+++ b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c
795857
@@ -9,57 +9,43 @@
795857
 **/
795857
 
795857
 #include <IndustryStandard/SmBios.h>          // SMBIOS_TABLE_TYPE0
795857
+#include <Library/BaseLib.h>
795857
+#include <Library/BaseMemoryLib.h>
795857
 #include <Library/DebugLib.h>                 // ASSERT_EFI_ERROR()
795857
+#include <Library/MemoryAllocationLib.h>
795857
+#include <Library/PcdLib.h>
795857
 #include <Library/UefiBootServicesTableLib.h> // gBS
795857
 #include <Protocol/Smbios.h>                  // EFI_SMBIOS_PROTOCOL
795857
 
795857
 #include "SmbiosPlatformDxe.h"
795857
 
795857
-#define TYPE0_STRINGS \
795857
-  "EFI Development Kit II / OVMF\0"     /* Vendor */ \
795857
-  "0.0.0\0"                             /* BiosVersion */ \
795857
-  "02/06/2015\0"                        /* BiosReleaseDate */
795857
-//
795857
-// Type definition and contents of the default Type 0 SMBIOS table.
795857
-//
795857
-#pragma pack(1)
795857
-typedef struct {
795857
-  SMBIOS_TABLE_TYPE0    Base;
795857
-  UINT8                 Strings[sizeof (TYPE0_STRINGS)];
795857
-} OVMF_TYPE0;
795857
-#pragma pack()
795857
-
795857
-STATIC CONST OVMF_TYPE0  mOvmfDefaultType0 = {
795857
+STATIC CONST SMBIOS_TABLE_TYPE0  mOvmfDefaultType0 = {
795857
+  // SMBIOS_STRUCTURE Hdr
795857
   {
795857
-    // SMBIOS_STRUCTURE Hdr
795857
-    {
795857
-      EFI_SMBIOS_TYPE_BIOS_INFORMATION, // UINT8 Type
795857
-      sizeof (SMBIOS_TABLE_TYPE0),      // UINT8 Length
795857
-    },
795857
-    1,      // SMBIOS_TABLE_STRING       Vendor
795857
-    2,      // SMBIOS_TABLE_STRING       BiosVersion
795857
-    0xE800, // UINT16                    BiosSegment
795857
-    3,      // SMBIOS_TABLE_STRING       BiosReleaseDate
795857
-    0,      // UINT8                     BiosSize
795857
-    {      // MISC_BIOS_CHARACTERISTICS BiosCharacteristics
795857
-      0,   // Reserved                                      :2
795857
-      0,   // Unknown                                       :1
795857
-      1,   // BiosCharacteristicsNotSupported               :1
795857
-           // Remaining BiosCharacteristics bits left unset :60
795857
-    },
795857
-    {      // BIOSCharacteristicsExtensionBytes[2]
795857
-      0,   // BiosReserved
795857
-      0x1C // SystemReserved = VirtualMachineSupported |
795857
-           //                  UefiSpecificationSupported |
795857
-           //                  TargetContentDistributionEnabled
795857
-    },
795857
-    0,     // UINT8                     SystemBiosMajorRelease
795857
-    0,     // UINT8                     SystemBiosMinorRelease
795857
-    0xFF,  // UINT8                     EmbeddedControllerFirmwareMajorRelease
795857
-    0xFF   // UINT8                     EmbeddedControllerFirmwareMinorRelease
795857
+    EFI_SMBIOS_TYPE_BIOS_INFORMATION, // UINT8 Type
795857
+    sizeof (SMBIOS_TABLE_TYPE0),      // UINT8 Length
795857
   },
795857
-  // Text strings (unformatted area)
795857
-  TYPE0_STRINGS
795857
+  1,      // SMBIOS_TABLE_STRING       Vendor
795857
+  2,      // SMBIOS_TABLE_STRING       BiosVersion
795857
+  0xE800, // UINT16                    BiosSegment
795857
+  3,      // SMBIOS_TABLE_STRING       BiosReleaseDate
795857
+  0,      // UINT8                     BiosSize
795857
+  {      // MISC_BIOS_CHARACTERISTICS BiosCharacteristics
795857
+    0,   // Reserved                                      :2
795857
+    0,   // Unknown                                       :1
795857
+    1,   // BiosCharacteristicsNotSupported               :1
795857
+    // Remaining BiosCharacteristics bits left unset :60
795857
+  },
795857
+  {      // BIOSCharacteristicsExtensionBytes[2]
795857
+    0,   // BiosReserved
795857
+    0x1C // SystemReserved = VirtualMachineSupported |
795857
+    //                  UefiSpecificationSupported |
795857
+    //                  TargetContentDistributionEnabled
795857
+  },
795857
+  0,     // UINT8                     SystemBiosMajorRelease
795857
+  0,     // UINT8                     SystemBiosMinorRelease
795857
+  0xFF,  // UINT8                     EmbeddedControllerFirmwareMajorRelease
795857
+  0xFF   // UINT8                     EmbeddedControllerFirmwareMinorRelease
795857
 };
795857
 
795857
 /**
795857
@@ -153,14 +139,55 @@ InstallAllStructures (
795857
     //
795857
     // Add OVMF default Type 0 (BIOS Information) table
795857
     //
795857
+    CHAR16  *VendStr, *VersStr, *DateStr;
795857
+    UINTN   VendLen, VersLen, DateLen;
795857
+    CHAR8   *Type0;
795857
+
795857
+    VendStr = (CHAR16 *)FixedPcdGetPtr (PcdFirmwareVendor);
795857
+    VendLen = StrLen (VendStr);
795857
+    if (VendLen < 3) {
795857
+      VendStr = L"unknown";
795857
+      VendLen = StrLen (VendStr);
795857
+    }
795857
+
795857
+    VersStr = (CHAR16 *)FixedPcdGetPtr (PcdFirmwareVersionString);
795857
+    VersLen = StrLen (VersStr);
795857
+    if (VersLen < 3) {
795857
+      VersStr = L"unknown";
795857
+      VersLen = StrLen (VersStr);
795857
+    }
795857
+
795857
+    DateStr = (CHAR16 *)FixedPcdGetPtr (PcdFirmwareReleaseDateString);
795857
+    DateLen = StrLen (DateStr);
795857
+    if (DateLen < 3) {
795857
+      DateStr = L"unknown";
795857
+      DateLen = StrLen (DateStr);
795857
+    }
795857
+
795857
+    DEBUG ((DEBUG_INFO, "FirmwareVendor:            \"%s\" (%d chars)\n", VendStr, VendLen));
795857
+    DEBUG ((DEBUG_INFO, "FirmwareVersionString:     \"%s\" (%d chars)\n", VersStr, VersLen));
795857
+    DEBUG ((DEBUG_INFO, "FirmwareReleaseDateString: \"%s\" (%d chars)\n", DateStr, DateLen));
795857
+
795857
+    Type0 = AllocateZeroPool (sizeof (mOvmfDefaultType0) + VendLen + VersLen + DateLen + 4);
795857
+    if (Type0 == NULL) {
795857
+      return EFI_OUT_OF_RESOURCES;
795857
+    }
795857
+
795857
+    CopyMem (Type0, &mOvmfDefaultType0, sizeof (mOvmfDefaultType0));
795857
+    UnicodeStrToAsciiStrS (VendStr, Type0 + sizeof (mOvmfDefaultType0), VendLen + 1);
795857
+    UnicodeStrToAsciiStrS (VersStr, Type0 + sizeof (mOvmfDefaultType0) + VendLen + 1, VersLen + 1);
795857
+    UnicodeStrToAsciiStrS (DateStr, Type0 + sizeof (mOvmfDefaultType0) + VendLen + VersLen + 2, DateLen + 1);
795857
+
795857
     SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
795857
     Status       = Smbios->Add (
795857
                              Smbios,
795857
                              NULL,
795857
                              &SmbiosHandle,
795857
-                             (EFI_SMBIOS_TABLE_HEADER *)&mOvmfDefaultType0
795857
+                             (EFI_SMBIOS_TABLE_HEADER *)Type0
795857
                              );
795857
     ASSERT_EFI_ERROR (Status);
795857
+
795857
+    FreePool (Type0);
795857
   }
795857
 
795857
   return EFI_SUCCESS;
795857
diff --git a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
795857
index 0066bbc922..52689c96e5 100644
795857
--- a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
795857
+++ b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
795857
@@ -32,9 +32,12 @@
795857
 
795857
 [Packages]
795857
   MdePkg/MdePkg.dec
795857
+  MdeModulePkg/MdeModulePkg.dec
795857
   OvmfPkg/OvmfPkg.dec
795857
 
795857
 [LibraryClasses]
795857
+  BaseLib
795857
+  BaseMemoryLib
795857
   DebugLib
795857
   MemoryAllocationLib
795857
   PcdLib
795857
@@ -45,6 +48,9 @@
795857
 [Pcd]
795857
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
795857
   gUefiOvmfPkgTokenSpaceGuid.PcdQemuSmbiosValidated
795857
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVendor
795857
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString
795857
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareReleaseDateString
795857
 
795857
 [Protocols]
795857
   gEfiSmbiosProtocolGuid                      # PROTOCOL ALWAYS_CONSUMED
795857
diff --git a/OvmfPkg/SmbiosPlatformDxe/XenSmbiosPlatformDxe.inf b/OvmfPkg/SmbiosPlatformDxe/XenSmbiosPlatformDxe.inf
795857
index 7f4588e33d..e646c88741 100644
795857
--- a/OvmfPkg/SmbiosPlatformDxe/XenSmbiosPlatformDxe.inf
795857
+++ b/OvmfPkg/SmbiosPlatformDxe/XenSmbiosPlatformDxe.inf
795857
@@ -38,19 +38,26 @@
795857
 
795857
 [Packages]
795857
   MdePkg/MdePkg.dec
795857
+  MdeModulePkg/MdeModulePkg.dec
795857
 
795857
 [Packages.IA32, Packages.X64]
795857
   OvmfPkg/OvmfPkg.dec
795857
 
795857
 [LibraryClasses]
795857
+  BaseLib
795857
+  BaseMemoryLib
795857
   DebugLib
795857
   UefiBootServicesTableLib
795857
   UefiDriverEntryPoint
795857
 
795857
 [LibraryClasses.IA32, LibraryClasses.X64]
795857
-  BaseLib
795857
   HobLib
795857
 
795857
+[Pcd]
795857
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVendor
795857
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString
795857
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareReleaseDateString
795857
+
795857
 [Protocols]
795857
   gEfiSmbiosProtocolGuid                      # PROTOCOL ALWAYS_CONSUMED
795857
 
795857
-- 
795857
2.38.1
795857