From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web10.110972.1669614031344330175 for ; Sun, 27 Nov 2022 21:40:32 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=booAEWZq; spf=pass (domain: redhat.com, ip: 170.10.133.124, mailfrom: kraxel@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669614029; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BgY6CRpgLLjJaO9EoQ+BdDGcHyzJ1QcXCSlnwf5TIGo=; b=booAEWZqSSfpRzWGaTa5ynaxPm5wsf7S6msJf23KDj6dgF0Bei2+tvm7Cn7ioQg45U3w/+ hwuTDyD/i+pCiAkg7OUV06THzmfXXBlwAFsonURGOoq/3/eC0tKtp7s5WcO799v/Vis+yx DGpiy6t4dLx9ESojAzHsXj5kkWujLtE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-528-2vf-bvwZP3m_IyYQy43d_g-1; Mon, 28 Nov 2022 00:40:27 -0500 X-MC-Unique: 2vf-bvwZP3m_IyYQy43d_g-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 179B5802314; Mon, 28 Nov 2022 05:40:27 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.79]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5873320290A5; Mon, 28 Nov 2022 05:40:25 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 1720018000A3; Mon, 28 Nov 2022 06:40:20 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Pawel Polawski , Anthony Perard , Jordan Justen , Jiewen Yao , Liming Gao , Julien Grall , Oliver Steffen , Jian J Wang , Ard Biesheuvel , Gerd Hoffmann Subject: [PATCH v3 1/1] OvmfPkg/SmbiosPlatformDxe: use PcdFirmware* Date: Mon, 28 Nov 2022 06:40:20 +0100 Message-Id: <20221128054020.25531-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 --- .../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 // SMBIOS_TABLE_TYPE0 +#include +#include #include // ASSERT_EFI_ERROR() +#include +#include #include // gBS #include // 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.38.1