public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v2 0/2] read version information from PCDs instead of using hard-coded values
@ 2022-10-11 10:03 Gerd Hoffmann
  2022-10-11 10:03 ` [PATCH v2 1/2] OvmfPkg/SmbiosPlatformDxe: use PcdFirmware* Gerd Hoffmann
  2022-10-11 10:03 ` [PATCH v2 2/2] RfC: MdeModulePkg: set defaults for FirmwareVersion and FirmwareReleaseDate Gerd Hoffmann
  0 siblings, 2 replies; 4+ messages in thread
From: Gerd Hoffmann @ 2022-10-11 10:03 UTC (permalink / raw)
  To: devel
  Cc: Ard Biesheuvel, Jiewen Yao, Liming Gao, Pawel Polawski,
	Jordan Justen, Oliver Steffen, Julien Grall, Gerd Hoffmann,
	Anthony Perard, Jian J Wang



Gerd Hoffmann (2):
  OvmfPkg/SmbiosPlatformDxe: use PcdFirmware*
  RfC: MdeModulePkg: set defaults for FirmwareVersion and
    FirmwareReleaseDate

 MdeModulePkg/MdeModulePkg.dec                 |   4 +-
 .../SmbiosPlatformDxe/SmbiosPlatformDxe.inf   |   6 +
 .../XenSmbiosPlatformDxe.inf                  |   9 +-
 OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c | 115 +++++++++++-------
 4 files changed, 87 insertions(+), 47 deletions(-)

-- 
2.37.3


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

* [PATCH v2 1/2] OvmfPkg/SmbiosPlatformDxe: use PcdFirmware*
  2022-10-11 10:03 [PATCH v2 0/2] read version information from PCDs instead of using hard-coded values Gerd Hoffmann
@ 2022-10-11 10:03 ` Gerd Hoffmann
  2022-10-11 10:03 ` [PATCH v2 2/2] RfC: MdeModulePkg: set defaults for FirmwareVersion and FirmwareReleaseDate Gerd Hoffmann
  1 sibling, 0 replies; 4+ messages in thread
From: Gerd Hoffmann @ 2022-10-11 10:03 UTC (permalink / raw)
  To: devel
  Cc: Ard Biesheuvel, Jiewen Yao, Liming Gao, Pawel Polawski,
	Jordan Justen, Oliver Steffen, Julien Grall, Gerd Hoffmann,
	Anthony Perard, Jian J Wang

Instead of using hard-coded strings ("0.0.0" for BiosVersion etc)
which is mostly useless read the PCDs (PcdFirmwareVendor,
PcdFirmwareVersionString and PcdFirmwareReleaseDateString) and
build the string table dynamuically at runtime.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 .../SmbiosPlatformDxe/SmbiosPlatformDxe.inf   |   6 +
 .../XenSmbiosPlatformDxe.inf                  |   9 +-
 OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c | 115 +++++++++++-------
 3 files changed, 85 insertions(+), 45 deletions(-)

diff --git a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
index 0066bbc9229c..52689c96e5af 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,9 @@ [LibraryClasses]
 [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
   gUefiOvmfPkgTokenSpaceGuid.PcdQemuSmbiosValidated
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVendor
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareReleaseDateString
 
 [Protocols]
   gEfiSmbiosProtocolGuid                      # PROTOCOL ALWAYS_CONSUMED
diff --git a/OvmfPkg/SmbiosPlatformDxe/XenSmbiosPlatformDxe.inf b/OvmfPkg/SmbiosPlatformDxe/XenSmbiosPlatformDxe.inf
index 7f4588e33d1e..e646c88741b6 100644
--- a/OvmfPkg/SmbiosPlatformDxe/XenSmbiosPlatformDxe.inf
+++ b/OvmfPkg/SmbiosPlatformDxe/XenSmbiosPlatformDxe.inf
@@ -38,19 +38,26 @@ [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.PcdFirmwareVendor
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareReleaseDateString
+
 [Protocols]
   gEfiSmbiosProtocolGuid                      # PROTOCOL ALWAYS_CONSUMED
 
diff --git a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c
index 94249d3ff1b0..dc1e6aed634f 100644
--- a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c
+++ b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c
@@ -9,57 +9,43 @@
 **/
 
 #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
 
 #include "SmbiosPlatformDxe.h"
 
-#define TYPE0_STRINGS \
-  "EFI Development Kit II / OVMF\0"     /* Vendor */ \
-  "0.0.0\0"                             /* BiosVersion */ \
-  "02/06/2015\0"                        /* BiosReleaseDate */
-//
-// Type definition and contents of the default Type 0 SMBIOS table.
-//
-#pragma pack(1)
-typedef struct {
-  SMBIOS_TABLE_TYPE0    Base;
-  UINT8                 Strings[sizeof (TYPE0_STRINGS)];
-} OVMF_TYPE0;
-#pragma pack()
-
-STATIC CONST OVMF_TYPE0  mOvmfDefaultType0 = {
+STATIC CONST SMBIOS_TABLE_TYPE0  mOvmfDefaultType0 = {
+  // SMBIOS_STRUCTURE Hdr
   {
-    // SMBIOS_STRUCTURE Hdr
-    {
-      EFI_SMBIOS_TYPE_BIOS_INFORMATION, // UINT8 Type
-      sizeof (SMBIOS_TABLE_TYPE0),      // UINT8 Length
-    },
-    1,      // SMBIOS_TABLE_STRING       Vendor
-    2,      // SMBIOS_TABLE_STRING       BiosVersion
-    0xE800, // UINT16                    BiosSegment
-    3,      // SMBIOS_TABLE_STRING       BiosReleaseDate
-    0,      // UINT8                     BiosSize
-    {      // MISC_BIOS_CHARACTERISTICS BiosCharacteristics
-      0,   // Reserved                                      :2
-      0,   // Unknown                                       :1
-      1,   // BiosCharacteristicsNotSupported               :1
-           // Remaining BiosCharacteristics bits left unset :60
-    },
-    {      // BIOSCharacteristicsExtensionBytes[2]
-      0,   // BiosReserved
-      0x1C // SystemReserved = VirtualMachineSupported |
-           //                  UefiSpecificationSupported |
-           //                  TargetContentDistributionEnabled
-    },
-    0,     // UINT8                     SystemBiosMajorRelease
-    0,     // UINT8                     SystemBiosMinorRelease
-    0xFF,  // UINT8                     EmbeddedControllerFirmwareMajorRelease
-    0xFF   // UINT8                     EmbeddedControllerFirmwareMinorRelease
+    EFI_SMBIOS_TYPE_BIOS_INFORMATION, // UINT8 Type
+    sizeof (SMBIOS_TABLE_TYPE0),      // UINT8 Length
   },
-  // Text strings (unformatted area)
-  TYPE0_STRINGS
+  1,      // SMBIOS_TABLE_STRING       Vendor
+  2,      // SMBIOS_TABLE_STRING       BiosVersion
+  0xE800, // UINT16                    BiosSegment
+  3,      // SMBIOS_TABLE_STRING       BiosReleaseDate
+  0,      // UINT8                     BiosSize
+  {      // MISC_BIOS_CHARACTERISTICS BiosCharacteristics
+    0,   // Reserved                                      :2
+    0,   // Unknown                                       :1
+    1,   // BiosCharacteristicsNotSupported               :1
+    // Remaining BiosCharacteristics bits left unset :60
+  },
+  {      // BIOSCharacteristicsExtensionBytes[2]
+    0,   // BiosReserved
+    0x1C // SystemReserved = VirtualMachineSupported |
+    //                  UefiSpecificationSupported |
+    //                  TargetContentDistributionEnabled
+  },
+  0,     // UINT8                     SystemBiosMajorRelease
+  0,     // UINT8                     SystemBiosMinorRelease
+  0xFF,  // UINT8                     EmbeddedControllerFirmwareMajorRelease
+  0xFF   // UINT8                     EmbeddedControllerFirmwareMinorRelease
 };
 
 /**
@@ -153,14 +139,55 @@ InstallAllStructures (
     //
     // Add OVMF default Type 0 (BIOS Information) table
     //
+    CHAR16  *VendStr, *VersStr, *DateStr;
+    UINTN   VendLen, VersLen, DateLen;
+    CHAR8   *Type0;
+
+    VendStr = (CHAR16 *)FixedPcdGetPtr (PcdFirmwareVendor);
+    VendLen = StrLen (VendStr);
+    if (VendLen < 3) {
+      VendStr = L"unknown";
+      VendLen = StrLen (VendStr);
+    }
+
+    VersStr = (CHAR16 *)FixedPcdGetPtr (PcdFirmwareVersionString);
+    VersLen = StrLen (VersStr);
+    if (VersLen < 3) {
+      VersStr = L"unknown";
+      VersLen = StrLen (VersStr);
+    }
+
+    DateStr = (CHAR16 *)FixedPcdGetPtr (PcdFirmwareReleaseDateString);
+    DateLen = StrLen (DateStr);
+    if (DateLen < 3) {
+      DateStr = L"unknown";
+      DateLen = StrLen (DateStr);
+    }
+
+    DEBUG ((DEBUG_INFO, "FirmwareVendor:            \"%s\" (%d chars)\n", VendStr, VendLen));
+    DEBUG ((DEBUG_INFO, "FirmwareVersionString:     \"%s\" (%d chars)\n", VersStr, VersLen));
+    DEBUG ((DEBUG_INFO, "FirmwareReleaseDateString: \"%s\" (%d chars)\n", DateStr, DateLen));
+
+    Type0 = AllocateZeroPool (sizeof (mOvmfDefaultType0) + VendLen + VersLen + DateLen + 4);
+    if (Type0 == NULL) {
+      return EFI_OUT_OF_RESOURCES;
+    }
+
+    CopyMem (Type0, &mOvmfDefaultType0, sizeof (mOvmfDefaultType0));
+    UnicodeStrToAsciiStrS (VendStr, Type0 + sizeof (mOvmfDefaultType0), VendLen + 1);
+    UnicodeStrToAsciiStrS (VersStr, Type0 + sizeof (mOvmfDefaultType0) + VendLen + 1, VersLen + 1);
+    UnicodeStrToAsciiStrS (DateStr, Type0 + sizeof (mOvmfDefaultType0) + VendLen + VersLen + 2, DateLen + 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] 4+ messages in thread

* [PATCH v2 2/2] RfC: MdeModulePkg: set defaults for FirmwareVersion and FirmwareReleaseDate
  2022-10-11 10:03 [PATCH v2 0/2] read version information from PCDs instead of using hard-coded values Gerd Hoffmann
  2022-10-11 10:03 ` [PATCH v2 1/2] OvmfPkg/SmbiosPlatformDxe: use PcdFirmware* Gerd Hoffmann
@ 2022-10-11 10:03 ` Gerd Hoffmann
  2022-10-11 10:27   ` Ard Biesheuvel
  1 sibling, 1 reply; 4+ messages in thread
From: Gerd Hoffmann @ 2022-10-11 10:03 UTC (permalink / raw)
  To: devel
  Cc: Ard Biesheuvel, Jiewen Yao, Liming Gao, Pawel Polawski,
	Jordan Justen, Oliver Steffen, Julien Grall, Gerd Hoffmann,
	Anthony Perard, Jian J Wang

PcdFirmwareVersionString is set to the most recent stable tag name.
PcdFirmwareReleaseDateString is set to the date of the most recent
stable tag.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 MdeModulePkg/MdeModulePkg.dec | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index 58e6ab004882..933e993359cc 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -1730,11 +1730,11 @@ [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx]
 
   ## Null-terminated Unicode string that describes the firmware version.
   # @Prompt Firmware version string.
-  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString|L""|VOID*|0x00010052
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString|L"edk2-stable202208"|VOID*|0x00010052
 
   ## Null-terminated Unicode string that contains the date the firmware was released
   # @Prompt Firmware release data string.
-  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareReleaseDateString|L""|VOID*|0x00010053
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareReleaseDateString|L"26/08/2022"|VOID*|0x00010053
 
   ## PcdStatusCodeMemorySize is used when PcdStatusCodeUseMemory is set to true.
   #  (PcdStatusCodeMemorySize * KBytes) is the total taken memory size.<BR><BR>
-- 
2.37.3


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

* Re: [PATCH v2 2/2] RfC: MdeModulePkg: set defaults for FirmwareVersion and FirmwareReleaseDate
  2022-10-11 10:03 ` [PATCH v2 2/2] RfC: MdeModulePkg: set defaults for FirmwareVersion and FirmwareReleaseDate Gerd Hoffmann
@ 2022-10-11 10:27   ` Ard Biesheuvel
  0 siblings, 0 replies; 4+ messages in thread
From: Ard Biesheuvel @ 2022-10-11 10:27 UTC (permalink / raw)
  To: Gerd Hoffmann
  Cc: devel, Jiewen Yao, Liming Gao, Pawel Polawski, Jordan Justen,
	Oliver Steffen, Julien Grall, Anthony Perard, Jian J Wang

On Tue, 11 Oct 2022 at 12:03, Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> PcdFirmwareVersionString is set to the most recent stable tag name.
> PcdFirmwareReleaseDateString is set to the date of the most recent
> stable tag.
>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>

I like this idea in principle, so

Acked-by: Ard Biesheuvel <ardb@kernel.org>

However, I will note that apparently, we couldn't even be bothered to
update the default UEFI revision (still at v2.7 as of today, while the
v2.10 spec has just been released) so I am skeptical whether we will
manage to keep this in sync with reality.


> ---
>  MdeModulePkg/MdeModulePkg.dec | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
> index 58e6ab004882..933e993359cc 100644
> --- a/MdeModulePkg/MdeModulePkg.dec
> +++ b/MdeModulePkg/MdeModulePkg.dec
> @@ -1730,11 +1730,11 @@ [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx]
>
>    ## Null-terminated Unicode string that describes the firmware version.
>    # @Prompt Firmware version string.
> -  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString|L""|VOID*|0x00010052
> +  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString|L"edk2-stable202208"|VOID*|0x00010052
>
>    ## Null-terminated Unicode string that contains the date the firmware was released
>    # @Prompt Firmware release data string.
> -  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareReleaseDateString|L""|VOID*|0x00010053
> +  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareReleaseDateString|L"26/08/2022"|VOID*|0x00010053
>
>    ## PcdStatusCodeMemorySize is used when PcdStatusCodeUseMemory is set to true.
>    #  (PcdStatusCodeMemorySize * KBytes) is the total taken memory size.<BR><BR>
> --
> 2.37.3
>

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

end of thread, other threads:[~2022-10-11 10:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-11 10:03 [PATCH v2 0/2] read version information from PCDs instead of using hard-coded values Gerd Hoffmann
2022-10-11 10:03 ` [PATCH v2 1/2] OvmfPkg/SmbiosPlatformDxe: use PcdFirmware* Gerd Hoffmann
2022-10-11 10:03 ` [PATCH v2 2/2] RfC: MdeModulePkg: set defaults for FirmwareVersion and FirmwareReleaseDate Gerd Hoffmann
2022-10-11 10:27   ` Ard Biesheuvel

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