render / rpms / edk2

Forked from rpms/edk2 3 months ago
Clone

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

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