public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 1/1] OvmfPkg/SmbiosPlatformDxe: use PcdFirmwareVersionString
@ 2022-10-10 14:42 Gerd Hoffmann
  2022-10-10 16:27 ` [edk2-devel] " Rebecca Cran
  0 siblings, 1 reply; 6+ messages in thread
From: Gerd Hoffmann @ 2022-10-10 14:42 UTC (permalink / raw)
  To: devel
  Cc: Gerd Hoffmann, Jordan Justen, Julien Grall, Oliver Steffen,
	Pawel Polawski, Ard Biesheuvel, Anthony Perard, Jiewen Yao

Instead of using hard-coded string "0.0.0" for BiosVersion (which is
quite useless) read PcdFirmwareVersionString and append that to the
type0 entry string table.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 .../SmbiosPlatformDxe/SmbiosPlatformDxe.inf   |  4 +++
 .../XenSmbiosPlatformDxe.inf                  |  7 +++-
 OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c | 32 ++++++++++++++++---
 3 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
index 0066bbc9229c..1a0a032342f9 100644
--- a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
+++ b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
@@ -32,9 +32,12 @@ [Sources]
 
 [Packages]
   MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
   OvmfPkg/OvmfPkg.dec
 
 [LibraryClasses]
+  BaseLib
+  BaseMemoryLib
   DebugLib
   MemoryAllocationLib
   PcdLib
@@ -45,6 +48,7 @@ [LibraryClasses]
 [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
   gUefiOvmfPkgTokenSpaceGuid.PcdQemuSmbiosValidated
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString
 
 [Protocols]
   gEfiSmbiosProtocolGuid                      # PROTOCOL ALWAYS_CONSUMED
diff --git a/OvmfPkg/SmbiosPlatformDxe/XenSmbiosPlatformDxe.inf b/OvmfPkg/SmbiosPlatformDxe/XenSmbiosPlatformDxe.inf
index 7f4588e33d1e..73c78ec7cc73 100644
--- a/OvmfPkg/SmbiosPlatformDxe/XenSmbiosPlatformDxe.inf
+++ b/OvmfPkg/SmbiosPlatformDxe/XenSmbiosPlatformDxe.inf
@@ -38,19 +38,24 @@ [Sources.ARM, Sources.AARCH64]
 
 [Packages]
   MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
 
 [Packages.IA32, Packages.X64]
   OvmfPkg/OvmfPkg.dec
 
 [LibraryClasses]
+  BaseLib
+  BaseMemoryLib
   DebugLib
   UefiBootServicesTableLib
   UefiDriverEntryPoint
 
 [LibraryClasses.IA32, LibraryClasses.X64]
-  BaseLib
   HobLib
 
+[Pcd]
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString
+
 [Protocols]
   gEfiSmbiosProtocolGuid                      # PROTOCOL ALWAYS_CONSUMED
 
diff --git a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c
index 94249d3ff1b0..f2eb568b6964 100644
--- a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c
+++ b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c
@@ -9,7 +9,11 @@
 **/
 
 #include <IndustryStandard/SmBios.h>          // SMBIOS_TABLE_TYPE0
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
 #include <Library/DebugLib.h>                 // ASSERT_EFI_ERROR()
+#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
 #include <Library/UefiBootServicesTableLib.h> // gBS
 #include <Protocol/Smbios.h>                  // EFI_SMBIOS_PROTOCOL
 
@@ -17,8 +21,7 @@
 
 #define TYPE0_STRINGS \
   "EFI Development Kit II / OVMF\0"     /* Vendor */ \
-  "0.0.0\0"                             /* BiosVersion */ \
-  "02/06/2015\0"                        /* BiosReleaseDate */
+  "02/06/2015"                          /* BiosReleaseDate */
 //
 // Type definition and contents of the default Type 0 SMBIOS table.
 //
@@ -37,9 +40,9 @@ STATIC CONST OVMF_TYPE0  mOvmfDefaultType0 = {
       sizeof (SMBIOS_TABLE_TYPE0),      // UINT8 Length
     },
     1,      // SMBIOS_TABLE_STRING       Vendor
-    2,      // SMBIOS_TABLE_STRING       BiosVersion
+    3,      // SMBIOS_TABLE_STRING       BiosVersion
     0xE800, // UINT16                    BiosSegment
-    3,      // SMBIOS_TABLE_STRING       BiosReleaseDate
+    2,      // SMBIOS_TABLE_STRING       BiosReleaseDate
     0,      // UINT8                     BiosSize
     {      // MISC_BIOS_CHARACTERISTICS BiosCharacteristics
       0,   // Reserved                                      :2
@@ -153,14 +156,33 @@ InstallAllStructures (
     //
     // Add OVMF default Type 0 (BIOS Information) table
     //
+    CHAR16  *Str16;
+    UINTN   Chars;
+    CHAR8   *Type0;
+
+    Str16 = (CHAR16 *)FixedPcdGetPtr (PcdFirmwareVersionString);
+    Chars = StrLen (Str16);
+    if (Chars == 0) {
+      Str16 = L"unknown";
+      Chars = StrLen (Str16);
+    }
+
+    DEBUG ((DEBUG_INFO, "FirmwareVersionString: \"%s\" (%d chars)\n", Str16, Chars));
+
+    Type0 = AllocateZeroPool (sizeof (mOvmfDefaultType0) + Chars + 2);
+    CopyMem (Type0, &mOvmfDefaultType0, sizeof (mOvmfDefaultType0));
+    UnicodeStrToAsciiStrS (Str16, Type0 + sizeof (mOvmfDefaultType0), Chars + 1);
+
     SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
     Status       = Smbios->Add (
                              Smbios,
                              NULL,
                              &SmbiosHandle,
-                             (EFI_SMBIOS_TABLE_HEADER *)&mOvmfDefaultType0
+                             (EFI_SMBIOS_TABLE_HEADER *)Type0
                              );
     ASSERT_EFI_ERROR (Status);
+
+    FreePool (Type0);
   }
 
   return EFI_SUCCESS;
-- 
2.37.3


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

end of thread, other threads:[~2022-10-24 14:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-10 14:42 [PATCH 1/1] OvmfPkg/SmbiosPlatformDxe: use PcdFirmwareVersionString Gerd Hoffmann
2022-10-10 16:27 ` [edk2-devel] " Rebecca Cran
2022-10-11  7:59   ` Gerd Hoffmann
2022-10-11 15:34     ` Rebecca Cran
2022-10-12  8:52       ` Gerd Hoffmann
2022-10-24 14:03         ` Ard Biesheuvel

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