[edk2-devel] [PATCH v6 15/22] ArmPkg: Add Universal/Smbios/SmbiosMiscDxe/Type00

Rebecca Cran posted 22 patches 3 years, 10 months ago
There is a newer version of this series
[edk2-devel] [PATCH v6 15/22] ArmPkg: Add Universal/Smbios/SmbiosMiscDxe/Type00
Posted by Rebecca Cran 3 years, 10 months ago
This code provides information for the SMBIOS Type 0 table.

Signed-off-by: Rebecca Cran <rebecca@nuviainc.com>
---
 ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendorData.c     |  93 ++++++
 ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendorFunction.c | 297 ++++++++++++++++++++
 ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendor.uni       |  18 ++
 3 files changed, 408 insertions(+)

diff --git a/ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendorData.c b/ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendorData.c
new file mode 100644
index 000000000000..edf0186aeae8
--- /dev/null
+++ b/ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendorData.c
@@ -0,0 +1,93 @@
+/** @file
+  This file provides Smbios Type0 Data
+
+  Based on the files under Nt32Pkg/MiscSubClassPlatformDxe/
+
+  Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
+  Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2015, Hisilicon Limited. All rights reserved.<BR>
+  Copyright (c) 2015, Linaro Limited. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+
+#include "SmbiosMisc.h"
+
+
+//
+// Static (possibly build generated) Bios Vendor data.
+//
+SMBIOS_MISC_TABLE_DATA(SMBIOS_TABLE_TYPE0, MiscBiosVendor) = {
+  {                                          // Hdr
+    EFI_SMBIOS_TYPE_BIOS_INFORMATION,          // Type,
+    0,                                         // Length,
+    0                                          // Handle
+  },
+  1,                                         // Vendor
+  2,                                         // BiosVersion
+  0xE000,                                    // BiosSegment
+  3,                                         // BiosReleaseDate
+  0,                                         // BiosSize
+  {                                          // BiosCharacteristics
+    0,                                         // Reserved                          :2
+    0,                                         // Unknown                           :1
+    0,                                         // BiosCharacteristicsNotSupported   :1
+    0,                                         // IsaIsSupported                    :1
+    0,                                         // McaIsSupported                    :1
+    0,                                         // EisaIsSupported                   :1
+    1,                                         // PciIsSupported                    :1
+    0,                                         // PcmciaIsSupported                 :1
+    1,                                         // PlugAndPlayIsSupported            :1
+    0,                                         // ApmIsSupported                    :1
+    1,                                         // BiosIsUpgradable                  :1
+    1,                                         // BiosShadowingAllowed              :1
+    0,                                         // VlVesaIsSupported                 :1
+    0,                                         // EscdSupportIsAvailable            :1
+    1,                                         // BootFromCdIsSupported             :1
+    1,                                         // SelectableBootIsSupported         :1
+    0,                                         // RomBiosIsSocketed                 :1
+    0,                                         // BootFromPcmciaIsSupported         :1
+    0,                                         // EDDSpecificationIsSupported       :1
+    0,                                         // JapaneseNecFloppyIsSupported      :1
+    0,                                         // JapaneseToshibaFloppyIsSupported  :1
+    0,                                         // Floppy525_360IsSupported          :1
+    0,                                         // Floppy525_12IsSupported           :1
+    0,                                         // Floppy35_720IsSupported           :1
+    0,                                         // Floppy35_288IsSupported           :1
+    0,                                         // PrintScreenIsSupported            :1
+    0,                                         // Keyboard8042IsSupported           :1
+    0,                                         // SerialIsSupported                 :1
+    0,                                         // PrinterIsSupported                :1
+    0,                                         // CgaMonoIsSupported                :1
+    0,                                         // NecPc98                           :1
+    0                                          // ReservedForVendor                 :32
+  },
+
+  {
+    0x01,                                        // BIOSCharacteristicsExtensionBytes[0]
+    //  {                                          // BiosReserved
+    //    1,                                         // AcpiIsSupported                   :1
+    //    0,                                         // UsbLegacyIsSupported              :1
+    //    0,                                         // AgpIsSupported                    :1
+    //    0,                                         // I20BootIsSupported                :1
+    //    0,                                         // Ls120BootIsSupported              :1
+    //    0,                                         // AtapiZipDriveBootIsSupported      :1
+    //    0,                                         // Boot1394IsSupported               :1
+    //    0                                          // SmartBatteryIsSupported           :1
+    //  },
+    0x0C                                         //BIOSCharacteristicsExtensionBytes[1]
+    //  {                                          //SystemReserved
+    //    0,                                         //BiosBootSpecIsSupported            :1
+    //    0,                                         //FunctionKeyNetworkBootIsSupported  :1
+    //    1,                                         //TargetContentDistributionEnabled   :1
+    //    1,                                         //UefiSpecificationSupported         :1
+    //    0,                                         //VirtualMachineSupported            :1
+    //    0                                          //ExtensionByte2Reserved             :3
+    //  },
+  },
+  0xFF,                                        // SystemBiosMajorRelease;
+  0xFF,                                        // SystemBiosMinorRelease;
+  0xFF,                                     // EmbeddedControllerFirmwareMajorRelease;
+  0xFF                                      // EmbeddedControllerFirmwareMinorRelease;
+};
diff --git a/ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendorFunction.c b/ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendorFunction.c
new file mode 100644
index 000000000000..dd8d062d4903
--- /dev/null
+++ b/ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendorFunction.c
@@ -0,0 +1,297 @@
+/** @file
+
+  Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
+  Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2015, Hisilicon Limited. All rights reserved.<BR>
+  Copyright (c) 2015, Linaro Limited. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/HiiLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/PrintLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+#include "SmbiosMisc.h"
+
+
+typedef struct {
+  CONST CHAR8* MonthStr;
+  UINT32       MonthInt;
+} MONTH_DESCRIPTION;
+
+STATIC CONST
+MONTH_DESCRIPTION mMonthDescription[] = {
+  { "Jan", 1 },
+  { "Feb", 2 },
+  { "Mar", 3 },
+  { "Apr", 4 },
+  { "May", 5 },
+  { "Jun", 6 },
+  { "Jul", 7 },
+  { "Aug", 8 },
+  { "Sep", 9 },
+  { "Oct", 10 },
+  { "Nov", 11 },
+  { "Dec", 12 },
+  { "???", 1 },  // Use 1 as default month
+};
+
+/**
+  Field Filling Function. Transform an EFI_EXP_BASE2_DATA to a byte, with '64k'
+  as the unit.
+
+  @param  Value              Pointer to Base2_Data
+
+  @retval
+
+**/
+UINT8
+Base2ToByteWith64KUnit (
+  IN  UINTN  Value
+  )
+{
+  UINT8 Size;
+
+  Size = ((Value + (SIZE_64KB - 1)) >> 16);
+
+  return Size;
+}
+
+/**
+  Returns the date and time this file (and firmware) was built.
+
+  @param[out] *Time Pointer to the EFI_TIME structure to fill in.
+**/
+VOID
+GetReleaseTime (
+  OUT EFI_TIME *Time
+  )
+{
+  CONST CHAR8      *ReleaseDate = __DATE__;
+  CONST CHAR8      *ReleaseTime = __TIME__;
+  UINTN            i;
+
+  for (i = 0; i < 12; i++) {
+    if (AsciiStrnCmp (ReleaseDate, mMonthDescription[i].MonthStr, 3) == 0) {
+      break;
+    }
+  }
+
+  Time->Month = mMonthDescription[i].MonthInt;
+  Time->Day = AsciiStrDecimalToUintn (ReleaseDate + 4);
+  Time->Year = AsciiStrDecimalToUintn (ReleaseDate + 7);
+  Time->Hour = AsciiStrDecimalToUintn (ReleaseTime);
+  Time->Minute = AsciiStrDecimalToUintn (ReleaseTime + 3);
+  Time->Second = AsciiStrDecimalToUintn (ReleaseTime + 6);
+}
+
+/**
+  Fetches the firmware ('BIOS') release date from the
+  FirmwareVersionInfo HOB.
+
+  @return The release date as a UTF-16 string
+**/
+CHAR16 *
+GetBiosReleaseDate (
+  VOID
+  )
+{
+  CHAR16      *ReleaseDate;
+  EFI_TIME    BuildTime;
+
+  ReleaseDate = AllocateZeroPool ((sizeof (CHAR16)) * SMBIOS_STRING_MAX_LENGTH);
+  if (ReleaseDate == NULL) {
+      return NULL;
+  }
+
+  GetReleaseTime (&BuildTime);
+
+  (VOID)UnicodeSPrintAsciiFormat (ReleaseDate,
+                        (sizeof (CHAR16)) * SMBIOS_STRING_MAX_LENGTH,
+                        "%02d/%02d/%4d",
+                        BuildTime.Month,
+                        BuildTime.Day,
+                        BuildTime.Year
+                        );
+
+  return ReleaseDate;
+}
+
+/**
+  Fetches the firmware ('BIOS') version from the
+  FirmwareVersionInfo HOB.
+
+  @return The version as a UTF-16 string
+**/
+CHAR16 *
+GetBiosVersion (
+  VOID
+  )
+{
+  CHAR16 *ReleaseString;
+
+  ReleaseString =
+    (CHAR16 *)FixedPcdGetPtr (PcdFirmwareVersionString);
+
+  return ReleaseString;
+}
+
+
+/**
+  This function makes boot time changes to the contents of the
+  MiscBiosVendor (Type 0) record.
+
+  @param  RecordData                 Pointer to SMBIOS table with default values.
+  @param  Smbios                     SMBIOS protocol.
+
+  @retval EFI_SUCCESS                The SMBIOS table was successfully added.
+  @retval EFI_INVALID_PARAMETER      Invalid parameter was found.
+  @retval EFI_OUT_OF_RESOURCES       Failed to allocate required memory.
+
+**/
+SMBIOS_MISC_TABLE_FUNCTION (MiscBiosVendor)
+{
+  CHAR8                 *OptionalStrStart;
+  CHAR8                 *StrStart;
+  UINTN                 VendorStrLen;
+  UINTN                 VerStrLen;
+  UINTN                 DateStrLen;
+  UINTN                 BiosPhysicalSize;
+  CHAR16                *Vendor;
+  CHAR16                *Version;
+  CHAR16                *ReleaseDate;
+  CHAR16                *Char16String;
+  EFI_STATUS            Status;
+  EFI_STRING_ID         TokenToUpdate;
+  EFI_STRING_ID         TokenToGet;
+  SMBIOS_TABLE_TYPE0    *SmbiosRecord;
+  SMBIOS_TABLE_TYPE0    *InputData;
+
+  //
+  // First check for invalid parameters.
+  //
+  if (RecordData == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  InputData = (SMBIOS_TABLE_TYPE0 *)RecordData;
+
+  Vendor = (CHAR16 *) PcdGetPtr (PcdFirmwareVendor);
+
+  if (StrLen (Vendor) > 0) {
+    TokenToUpdate = STRING_TOKEN (STR_MISC_BIOS_VENDOR);
+    HiiSetString (mSmbiosMiscHiiHandle, TokenToUpdate, Vendor, NULL);
+  }
+
+  Version = GetBiosVersion();
+
+  if (StrLen (Version) > 0) {
+    TokenToUpdate = STRING_TOKEN (STR_MISC_BIOS_VERSION);
+    HiiSetString (mSmbiosMiscHiiHandle, TokenToUpdate, Version, NULL);
+  } else {
+    Version = (CHAR16 *) PcdGetPtr (PcdFirmwareVersionString);
+    if (StrLen (Version) > 0) {
+      TokenToUpdate = STRING_TOKEN (STR_MISC_BIOS_VERSION);
+      HiiSetString (mSmbiosMiscHiiHandle, TokenToUpdate, Version, NULL);
+    }
+  }
+
+  Char16String = GetBiosReleaseDate ();
+  if (StrLen(Char16String) > 0) {
+    TokenToUpdate = STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE);
+    HiiSetString (mSmbiosMiscHiiHandle, TokenToUpdate, Char16String, NULL);
+  }
+
+  TokenToGet = STRING_TOKEN (STR_MISC_BIOS_VENDOR);
+  Vendor = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
+  VendorStrLen = StrLen (Vendor);
+
+  TokenToGet = STRING_TOKEN (STR_MISC_BIOS_VERSION);
+  Version = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
+  VerStrLen = StrLen (Version);
+
+  TokenToGet = STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE);
+  ReleaseDate = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
+  DateStrLen = StrLen (ReleaseDate);
+
+  //
+  // Now update the BiosPhysicalSize
+  //
+  BiosPhysicalSize = FixedPcdGet32 (PcdFdSize);
+
+  //
+  // Two zeros following the last string.
+  //
+  SmbiosRecord = AllocateZeroPool (sizeof (SMBIOS_TABLE_TYPE0) + VendorStrLen + 1 +
+                                   VerStrLen + 1 +
+                                   DateStrLen + 1 + 1);
+  if (SmbiosRecord == NULL) {
+    Status = EFI_OUT_OF_RESOURCES;
+    goto Exit;
+  }
+
+  (VOID)CopyMem (SmbiosRecord, InputData, sizeof (SMBIOS_TABLE_TYPE0));
+
+  SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE0);
+  SmbiosRecord->BiosSegment = (UINT16)(FixedPcdGet32 (PcdFdBaseAddress) / SIZE_64KB);
+  if (BiosPhysicalSize < SIZE_16MB) {
+    SmbiosRecord->BiosSize = Base2ToByteWith64KUnit (BiosPhysicalSize) - 1;
+    SmbiosRecord->ExtendedBiosSize.Size = BiosPhysicalSize / SIZE_1MB;
+    SmbiosRecord->ExtendedBiosSize.Unit = 0; // Size is in MB
+  } else {
+    SmbiosRecord->BiosSize = 0xFF;
+    if (BiosPhysicalSize > 0x3FFF) {
+      SmbiosRecord->ExtendedBiosSize.Size = BiosPhysicalSize / SIZE_1GB;
+      SmbiosRecord->ExtendedBiosSize.Unit = 1; // Size is in GB
+    }
+  }
+
+  SmbiosRecord->SystemBiosMajorRelease = (UINT8) (PcdGet16 (PcdSystemBiosRelease) >> 8);
+  SmbiosRecord->SystemBiosMinorRelease = (UINT8) (PcdGet16 (PcdSystemBiosRelease) & 0xFF);
+
+  SmbiosRecord->EmbeddedControllerFirmwareMajorRelease = (UINT16)
+    (PcdGet16 (PcdEmbeddedControllerFirmwareRelease) >> 8);
+  SmbiosRecord->EmbeddedControllerFirmwareMinorRelease = (UINT16)
+    (PcdGet16 (PcdEmbeddedControllerFirmwareRelease) & 0xFF);
+
+  OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
+  UnicodeStrToAsciiStrS (Vendor, OptionalStrStart, VendorStrLen + 1);
+  StrStart = OptionalStrStart + VendorStrLen + 1;
+  UnicodeStrToAsciiStrS (Version, StrStart, VerStrLen + 1);
+  StrStart += VerStrLen + 1;
+  UnicodeStrToAsciiStrS (ReleaseDate, StrStart, DateStrLen + 1);
+  //
+  // Now we have got the full smbios record, call smbios protocol to add this record.
+  //
+  Status = SmbiosMiscAddRecord ((UINT8*)SmbiosRecord, NULL);
+  if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_ERROR, "[%a]:[%dL] Smbios Type00 Table Log Failed! %r \n",
+              __FUNCTION__, __LINE__, Status));
+  }
+
+  FreePool (SmbiosRecord);
+
+Exit:
+  if (Vendor != NULL) {
+    FreePool (Vendor);
+  }
+
+  if (Version != NULL) {
+    FreePool (Version);
+  }
+
+  if (ReleaseDate != NULL) {
+    FreePool (ReleaseDate);
+  }
+
+  if (Char16String != NULL) {
+    FreePool (Char16String);
+  }
+
+  return Status;
+}
diff --git a/ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendor.uni b/ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendor.uni
new file mode 100644
index 000000000000..a3f068cdcca2
--- /dev/null
+++ b/ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendor.uni
@@ -0,0 +1,18 @@
+/** @file
+  Based on files under Nt32Pkg/MiscSubClassPlatformDxe/
+
+  Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
+  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2015, Hisilicon Limited. All rights reserved.<BR>
+  Copyright (c) 2015, Linaro Limited. All rights reserved.<BR>
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+/=#
+
+#string STR_MISC_BIOS_VENDOR           #language en-US  "Not Specified"
+#string STR_MISC_BIOS_VERSION          #language en-US  "Not Specified"
+#string STR_MISC_BIOS_RELEASE_DATE     #language en-US  "Not Specified"
+#string STR_MISC_BIOS_VENDOR           #language en-US  "Not Specified"
+#string STR_MISC_BIOS_RELEASE_DATE     #language en-US  "12/02/2020"
-- 
2.26.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#70310): https://edk2.groups.io/g/devel/message/70310
Mute This Topic: https://groups.io/mt/79679257/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [PATCH v6 15/22] ArmPkg: Add Universal/Smbios/SmbiosMiscDxe/Type00
Posted by Samer El-Haj-Mahmoud 3 years, 10 months ago
With a minor feedback below:
Reviewed-by: Samer El-Haj-Mahmoud <Samer.El-Haj-Mahmoud@arm.com>

+  }
> +
> +  (VOID)CopyMem (SmbiosRecord, InputData, sizeof (SMBIOS_TABLE_TYPE0));
> +
> +  SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE0);
> + SmbiosRecord->BiosSegment = (UINT16)(FixedPcdGet32 (PcdFdBaseAddress)
> + / SIZE_64KB);  if (BiosPhysicalSize < SIZE_16MB) {
> +    SmbiosRecord->BiosSize = Base2ToByteWith64KUnit (BiosPhysicalSize) - 1;
> +    SmbiosRecord->ExtendedBiosSize.Size = BiosPhysicalSize / SIZE_1MB;
> +    SmbiosRecord->ExtendedBiosSize.Unit = 0; // Size is in MB  } else {
> +    SmbiosRecord->BiosSize = 0xFF;
> +    if (BiosPhysicalSize > 0x3FFF) {
> +      SmbiosRecord->ExtendedBiosSize.Size = BiosPhysicalSize / SIZE_1GB;
> +      SmbiosRecord->ExtendedBiosSize.Unit = 1; // Size is in GB
> +    }
> +  }
> +
> +  SmbiosRecord->SystemBiosMajorRelease = (UINT8) (PcdGet16
> + (PcdSystemBiosRelease) >> 8);  SmbiosRecord->SystemBiosMinorRelease =
> + (UINT8) (PcdGet16 (PcdSystemBiosRelease) & 0xFF);
> +
> +  SmbiosRecord->EmbeddedControllerFirmwareMajorRelease = (UINT16)
> +    (PcdGet16 (PcdEmbeddedControllerFirmwareRelease) >> 8);
> + SmbiosRecord->EmbeddedControllerFirmwareMinorRelease = (UINT16)
> +    (PcdGet16 (PcdEmbeddedControllerFirmwareRelease) & 0xFF);
> +

Not really an issue, but a function in OemMiscLib is possibly a better option than using PCDs for these. Platforms may have an easy way to build the Major.Minor FW values (such as by parsing PcdFirmwareVersionString and splitting into major and minor values). See for example for RPi4 at: https://github.com/tianocore/edk2-platforms/blob/master/Platform/RaspberryPi/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c#L754
Using PCDs will still work, but the platform will need to put this code in some other module/library just to initialize the dynamic PCD.




-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#70457): https://edk2.groups.io/g/devel/message/70457
Mute This Topic: https://groups.io/mt/79679257/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [edk2-devel] [PATCH v6 15/22] ArmPkg: Add Universal/Smbios/SmbiosMiscDxe/Type00
Posted by Leif Lindholm 3 years, 10 months ago
On Thu, Jan 14, 2021 at 09:36:21 -0700, Rebecca Cran wrote:
> This code provides information for the SMBIOS Type 0 table.
> 
> Signed-off-by: Rebecca Cran <rebecca@nuviainc.com>

Minor whitespace comments below only, if addressed, please add
Reviewed-by: Leif Lindholm <leif@nuviainc.com>

> ---
>  ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendorData.c     |  93 ++++++
>  ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendorFunction.c | 297 ++++++++++++++++++++
>  ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendor.uni       |  18 ++
>  3 files changed, 408 insertions(+)
> 
> diff --git a/ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendorData.c b/ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendorData.c
> new file mode 100644
> index 000000000000..edf0186aeae8
> --- /dev/null
> +++ b/ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendorData.c
> @@ -0,0 +1,93 @@
> +/** @file
> +  This file provides Smbios Type0 Data
> +
> +  Based on the files under Nt32Pkg/MiscSubClassPlatformDxe/
> +
> +  Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
> +  Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2015, Hisilicon Limited. All rights reserved.<BR>
> +  Copyright (c) 2015, Linaro Limited. All rights reserved.<BR>
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +
> +#include "SmbiosMisc.h"
> +
> +
> +//
> +// Static (possibly build generated) Bios Vendor data.
> +//
> +SMBIOS_MISC_TABLE_DATA(SMBIOS_TABLE_TYPE0, MiscBiosVendor) = {
> +  {                                          // Hdr
> +    EFI_SMBIOS_TYPE_BIOS_INFORMATION,          // Type,
> +    0,                                         // Length,
> +    0                                          // Handle
> +  },
> +  1,                                         // Vendor
> +  2,                                         // BiosVersion
> +  0xE000,                                    // BiosSegment
> +  3,                                         // BiosReleaseDate
> +  0,                                         // BiosSize
> +  {                                          // BiosCharacteristics
> +    0,                                         // Reserved                          :2
> +    0,                                         // Unknown                           :1
> +    0,                                         // BiosCharacteristicsNotSupported   :1
> +    0,                                         // IsaIsSupported                    :1
> +    0,                                         // McaIsSupported                    :1
> +    0,                                         // EisaIsSupported                   :1
> +    1,                                         // PciIsSupported                    :1
> +    0,                                         // PcmciaIsSupported                 :1
> +    1,                                         // PlugAndPlayIsSupported            :1
> +    0,                                         // ApmIsSupported                    :1
> +    1,                                         // BiosIsUpgradable                  :1
> +    1,                                         // BiosShadowingAllowed              :1
> +    0,                                         // VlVesaIsSupported                 :1
> +    0,                                         // EscdSupportIsAvailable            :1
> +    1,                                         // BootFromCdIsSupported             :1
> +    1,                                         // SelectableBootIsSupported         :1
> +    0,                                         // RomBiosIsSocketed                 :1
> +    0,                                         // BootFromPcmciaIsSupported         :1
> +    0,                                         // EDDSpecificationIsSupported       :1
> +    0,                                         // JapaneseNecFloppyIsSupported      :1
> +    0,                                         // JapaneseToshibaFloppyIsSupported  :1
> +    0,                                         // Floppy525_360IsSupported          :1
> +    0,                                         // Floppy525_12IsSupported           :1
> +    0,                                         // Floppy35_720IsSupported           :1
> +    0,                                         // Floppy35_288IsSupported           :1
> +    0,                                         // PrintScreenIsSupported            :1
> +    0,                                         // Keyboard8042IsSupported           :1
> +    0,                                         // SerialIsSupported                 :1
> +    0,                                         // PrinterIsSupported                :1
> +    0,                                         // CgaMonoIsSupported                :1
> +    0,                                         // NecPc98                           :1
> +    0                                          // ReservedForVendor                 :32
> +  },
> +
> +  {
> +    0x01,                                        // BIOSCharacteristicsExtensionBytes[0]
> +    //  {                                          // BiosReserved
> +    //    1,                                         // AcpiIsSupported                   :1
> +    //    0,                                         // UsbLegacyIsSupported              :1
> +    //    0,                                         // AgpIsSupported                    :1
> +    //    0,                                         // I20BootIsSupported                :1
> +    //    0,                                         // Ls120BootIsSupported              :1
> +    //    0,                                         // AtapiZipDriveBootIsSupported      :1
> +    //    0,                                         // Boot1394IsSupported               :1
> +    //    0                                          // SmartBatteryIsSupported           :1
> +    //  },
> +    0x0C                                         //BIOSCharacteristicsExtensionBytes[1]
> +    //  {                                          //SystemReserved
> +    //    0,                                         //BiosBootSpecIsSupported            :1
> +    //    0,                                         //FunctionKeyNetworkBootIsSupported  :1
> +    //    1,                                         //TargetContentDistributionEnabled   :1
> +    //    1,                                         //UefiSpecificationSupported         :1
> +    //    0,                                         //VirtualMachineSupported            :1
> +    //    0                                          //ExtensionByte2Reserved             :3
> +    //  },
> +  },
> +  0xFF,                                        // SystemBiosMajorRelease;
> +  0xFF,                                        // SystemBiosMinorRelease;
> +  0xFF,                                     // EmbeddedControllerFirmwareMajorRelease;
> +  0xFF                                      // EmbeddedControllerFirmwareMinorRelease;
> +};
> diff --git a/ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendorFunction.c b/ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendorFunction.c
> new file mode 100644
> index 000000000000..dd8d062d4903
> --- /dev/null
> +++ b/ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendorFunction.c
> @@ -0,0 +1,297 @@
> +/** @file
> +
> +  Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
> +  Copyright (c) 2009, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2015, Hisilicon Limited. All rights reserved.<BR>
> +  Copyright (c) 2015, Linaro Limited. All rights reserved.<BR>
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <Library/BaseLib.h>
> +#include <Library/BaseMemoryLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/HiiLib.h>
> +#include <Library/MemoryAllocationLib.h>
> +#include <Library/PrintLib.h>
> +#include <Library/UefiBootServicesTableLib.h>
> +
> +#include "SmbiosMisc.h"
> +
> +
> +typedef struct {
> +  CONST CHAR8* MonthStr;
> +  UINT32       MonthInt;
> +} MONTH_DESCRIPTION;
> +
> +STATIC CONST
> +MONTH_DESCRIPTION mMonthDescription[] = {
> +  { "Jan", 1 },
> +  { "Feb", 2 },
> +  { "Mar", 3 },
> +  { "Apr", 4 },
> +  { "May", 5 },
> +  { "Jun", 6 },
> +  { "Jul", 7 },
> +  { "Aug", 8 },
> +  { "Sep", 9 },
> +  { "Oct", 10 },
> +  { "Nov", 11 },
> +  { "Dec", 12 },
> +  { "???", 1 },  // Use 1 as default month
> +};
> +
> +/**
> +  Field Filling Function. Transform an EFI_EXP_BASE2_DATA to a byte, with '64k'
> +  as the unit.
> +
> +  @param  Value              Pointer to Base2_Data
> +
> +  @retval
> +
> +**/
> +UINT8
> +Base2ToByteWith64KUnit (
> +  IN  UINTN  Value
> +  )
> +{
> +  UINT8 Size;
> +
> +  Size = ((Value + (SIZE_64KB - 1)) >> 16);
> +
> +  return Size;
> +}
> +
> +/**
> +  Returns the date and time this file (and firmware) was built.
> +
> +  @param[out] *Time Pointer to the EFI_TIME structure to fill in.
> +**/
> +VOID
> +GetReleaseTime (
> +  OUT EFI_TIME *Time
> +  )
> +{
> +  CONST CHAR8      *ReleaseDate = __DATE__;
> +  CONST CHAR8      *ReleaseTime = __TIME__;
> +  UINTN            i;
> +
> +  for (i = 0; i < 12; i++) {
> +    if (AsciiStrnCmp (ReleaseDate, mMonthDescription[i].MonthStr, 3) == 0) {
> +      break;
> +    }
> +  }
> +
> +  Time->Month = mMonthDescription[i].MonthInt;
> +  Time->Day = AsciiStrDecimalToUintn (ReleaseDate + 4);
> +  Time->Year = AsciiStrDecimalToUintn (ReleaseDate + 7);
> +  Time->Hour = AsciiStrDecimalToUintn (ReleaseTime);
> +  Time->Minute = AsciiStrDecimalToUintn (ReleaseTime + 3);
> +  Time->Second = AsciiStrDecimalToUintn (ReleaseTime + 6);
> +}
> +
> +/**
> +  Fetches the firmware ('BIOS') release date from the
> +  FirmwareVersionInfo HOB.
> +
> +  @return The release date as a UTF-16 string
> +**/
> +CHAR16 *
> +GetBiosReleaseDate (
> +  VOID
> +  )
> +{
> +  CHAR16      *ReleaseDate;
> +  EFI_TIME    BuildTime;
> +
> +  ReleaseDate = AllocateZeroPool ((sizeof (CHAR16)) * SMBIOS_STRING_MAX_LENGTH);
> +  if (ReleaseDate == NULL) {
> +      return NULL;
> +  }
> +
> +  GetReleaseTime (&BuildTime);
> +
> +  (VOID)UnicodeSPrintAsciiFormat (ReleaseDate,
> +                        (sizeof (CHAR16)) * SMBIOS_STRING_MAX_LENGTH,
> +                        "%02d/%02d/%4d",
> +                        BuildTime.Month,
> +                        BuildTime.Day,
> +                        BuildTime.Year
> +                        );

Something strange about indentation.

> +
> +  return ReleaseDate;
> +}
> +
> +/**
> +  Fetches the firmware ('BIOS') version from the
> +  FirmwareVersionInfo HOB.
> +
> +  @return The version as a UTF-16 string
> +**/
> +CHAR16 *
> +GetBiosVersion (
> +  VOID
> +  )
> +{
> +  CHAR16 *ReleaseString;
> +
> +  ReleaseString =
> +    (CHAR16 *)FixedPcdGetPtr (PcdFirmwareVersionString);

Does this line even need breaking?

> +
> +  return ReleaseString;
> +}
> +
> +
> +/**
> +  This function makes boot time changes to the contents of the
> +  MiscBiosVendor (Type 0) record.
> +
> +  @param  RecordData                 Pointer to SMBIOS table with default values.
> +  @param  Smbios                     SMBIOS protocol.
> +
> +  @retval EFI_SUCCESS                The SMBIOS table was successfully added.
> +  @retval EFI_INVALID_PARAMETER      Invalid parameter was found.
> +  @retval EFI_OUT_OF_RESOURCES       Failed to allocate required memory.
> +
> +**/
> +SMBIOS_MISC_TABLE_FUNCTION (MiscBiosVendor)
> +{
> +  CHAR8                 *OptionalStrStart;
> +  CHAR8                 *StrStart;
> +  UINTN                 VendorStrLen;
> +  UINTN                 VerStrLen;
> +  UINTN                 DateStrLen;
> +  UINTN                 BiosPhysicalSize;
> +  CHAR16                *Vendor;
> +  CHAR16                *Version;
> +  CHAR16                *ReleaseDate;
> +  CHAR16                *Char16String;
> +  EFI_STATUS            Status;
> +  EFI_STRING_ID         TokenToUpdate;
> +  EFI_STRING_ID         TokenToGet;
> +  SMBIOS_TABLE_TYPE0    *SmbiosRecord;
> +  SMBIOS_TABLE_TYPE0    *InputData;
> +
> +  //
> +  // First check for invalid parameters.
> +  //
> +  if (RecordData == NULL) {
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  InputData = (SMBIOS_TABLE_TYPE0 *)RecordData;
> +
> +  Vendor = (CHAR16 *) PcdGetPtr (PcdFirmwareVendor);
> +
> +  if (StrLen (Vendor) > 0) {
> +    TokenToUpdate = STRING_TOKEN (STR_MISC_BIOS_VENDOR);
> +    HiiSetString (mSmbiosMiscHiiHandle, TokenToUpdate, Vendor, NULL);
> +  }
> +
> +  Version = GetBiosVersion();
> +
> +  if (StrLen (Version) > 0) {
> +    TokenToUpdate = STRING_TOKEN (STR_MISC_BIOS_VERSION);
> +    HiiSetString (mSmbiosMiscHiiHandle, TokenToUpdate, Version, NULL);
> +  } else {
> +    Version = (CHAR16 *) PcdGetPtr (PcdFirmwareVersionString);
> +    if (StrLen (Version) > 0) {
> +      TokenToUpdate = STRING_TOKEN (STR_MISC_BIOS_VERSION);
> +      HiiSetString (mSmbiosMiscHiiHandle, TokenToUpdate, Version, NULL);
> +    }
> +  }
> +
> +  Char16String = GetBiosReleaseDate ();
> +  if (StrLen(Char16String) > 0) {
> +    TokenToUpdate = STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE);
> +    HiiSetString (mSmbiosMiscHiiHandle, TokenToUpdate, Char16String, NULL);
> +  }
> +
> +  TokenToGet = STRING_TOKEN (STR_MISC_BIOS_VENDOR);
> +  Vendor = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
> +  VendorStrLen = StrLen (Vendor);
> +
> +  TokenToGet = STRING_TOKEN (STR_MISC_BIOS_VERSION);
> +  Version = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
> +  VerStrLen = StrLen (Version);
> +
> +  TokenToGet = STRING_TOKEN (STR_MISC_BIOS_RELEASE_DATE);
> +  ReleaseDate = HiiGetPackageString (&gEfiCallerIdGuid, TokenToGet, NULL);
> +  DateStrLen = StrLen (ReleaseDate);
> +
> +  //
> +  // Now update the BiosPhysicalSize
> +  //
> +  BiosPhysicalSize = FixedPcdGet32 (PcdFdSize);
> +
> +  //
> +  // Two zeros following the last string.
> +  //
> +  SmbiosRecord = AllocateZeroPool (sizeof (SMBIOS_TABLE_TYPE0) + VendorStrLen + 1 +
> +                                   VerStrLen + 1 +
> +                                   DateStrLen + 1 + 1);
> +  if (SmbiosRecord == NULL) {
> +    Status = EFI_OUT_OF_RESOURCES;
> +    goto Exit;
> +  }
> +
> +  (VOID)CopyMem (SmbiosRecord, InputData, sizeof (SMBIOS_TABLE_TYPE0));
> +
> +  SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE0);
> +  SmbiosRecord->BiosSegment = (UINT16)(FixedPcdGet32 (PcdFdBaseAddress) / SIZE_64KB);
> +  if (BiosPhysicalSize < SIZE_16MB) {
> +    SmbiosRecord->BiosSize = Base2ToByteWith64KUnit (BiosPhysicalSize) - 1;
> +    SmbiosRecord->ExtendedBiosSize.Size = BiosPhysicalSize / SIZE_1MB;
> +    SmbiosRecord->ExtendedBiosSize.Unit = 0; // Size is in MB
> +  } else {
> +    SmbiosRecord->BiosSize = 0xFF;
> +    if (BiosPhysicalSize > 0x3FFF) {
> +      SmbiosRecord->ExtendedBiosSize.Size = BiosPhysicalSize / SIZE_1GB;
> +      SmbiosRecord->ExtendedBiosSize.Unit = 1; // Size is in GB
> +    }
> +  }
> +
> +  SmbiosRecord->SystemBiosMajorRelease = (UINT8) (PcdGet16 (PcdSystemBiosRelease) >> 8);
> +  SmbiosRecord->SystemBiosMinorRelease = (UINT8) (PcdGet16 (PcdSystemBiosRelease) & 0xFF);
> +
> +  SmbiosRecord->EmbeddedControllerFirmwareMajorRelease = (UINT16)
> +    (PcdGet16 (PcdEmbeddedControllerFirmwareRelease) >> 8);
> +  SmbiosRecord->EmbeddedControllerFirmwareMinorRelease = (UINT16)
> +    (PcdGet16 (PcdEmbeddedControllerFirmwareRelease) & 0xFF);
> +
> +  OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);
> +  UnicodeStrToAsciiStrS (Vendor, OptionalStrStart, VendorStrLen + 1);
> +  StrStart = OptionalStrStart + VendorStrLen + 1;
> +  UnicodeStrToAsciiStrS (Version, StrStart, VerStrLen + 1);
> +  StrStart += VerStrLen + 1;
> +  UnicodeStrToAsciiStrS (ReleaseDate, StrStart, DateStrLen + 1);
> +  //
> +  // Now we have got the full smbios record, call smbios protocol to add this record.
> +  //
> +  Status = SmbiosMiscAddRecord ((UINT8*)SmbiosRecord, NULL);
> +  if (EFI_ERROR (Status)) {
> +      DEBUG ((DEBUG_ERROR, "[%a]:[%dL] Smbios Type00 Table Log Failed! %r \n",

Funky indentation.

/
    Leif

> +              __FUNCTION__, __LINE__, Status));
> +  }
> +
> +  FreePool (SmbiosRecord);
> +
> +Exit:
> +  if (Vendor != NULL) {
> +    FreePool (Vendor);
> +  }
> +
> +  if (Version != NULL) {
> +    FreePool (Version);
> +  }
> +
> +  if (ReleaseDate != NULL) {
> +    FreePool (ReleaseDate);
> +  }
> +
> +  if (Char16String != NULL) {
> +    FreePool (Char16String);
> +  }
> +
> +  return Status;
> +}
> diff --git a/ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendor.uni b/ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendor.uni
> new file mode 100644
> index 000000000000..a3f068cdcca2
> --- /dev/null
> +++ b/ArmPkg/Universal/Smbios/SmbiosMiscDxe/Type00/MiscBiosVendor.uni
> @@ -0,0 +1,18 @@
> +/** @file
> +  Based on files under Nt32Pkg/MiscSubClassPlatformDxe/
> +
> +  Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
> +  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
> +  Copyright (c) 2015, Hisilicon Limited. All rights reserved.<BR>
> +  Copyright (c) 2015, Linaro Limited. All rights reserved.<BR>
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +/=#
> +
> +#string STR_MISC_BIOS_VENDOR           #language en-US  "Not Specified"
> +#string STR_MISC_BIOS_VERSION          #language en-US  "Not Specified"
> +#string STR_MISC_BIOS_RELEASE_DATE     #language en-US  "Not Specified"
> +#string STR_MISC_BIOS_VENDOR           #language en-US  "Not Specified"
> +#string STR_MISC_BIOS_RELEASE_DATE     #language en-US  "12/02/2020"
> -- 
> 2.26.2
> 


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#70730): https://edk2.groups.io/g/devel/message/70730
Mute This Topic: https://groups.io/mt/79679257/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-