[edk2-devel] [PATCH] MdeModulePkg/Frontpage: Get SMBIOS Data from table directly

Sean Rhodes posted 1 patch 2 years, 3 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/edk2 tags/patchew/dfcff45f586747827e9a87020acb48cfad52b0e3.1643708039.git.sean@starlabs.systems
MdeModulePkg/Application/UiApp/FrontPage.c | 196 ++++++++++++++++++++-
MdeModulePkg/Application/UiApp/UiApp.inf   |   2 +
MdeModulePkg/MdeModulePkg.dec              |   2 +
UefiPayloadPkg/UefiPayloadPkg.dsc          |   6 +
4 files changed, 205 insertions(+), 1 deletion(-)
[edk2-devel] [PATCH] MdeModulePkg/Frontpage: Get SMBIOS Data from table directly
Posted by Sean Rhodes 2 years, 3 months ago
Gather information from SMBIOS table rather than getting it
from the EFI SMBIOS protocol for coreboot builds.

Signed-off-by: Matt DeVillier <matt.devillier@gmail.com>
Signed-off-by: Sean Rhodes <sean@starlabs.systems>
---
 MdeModulePkg/Application/UiApp/FrontPage.c | 196 ++++++++++++++++++++-
 MdeModulePkg/Application/UiApp/UiApp.inf   |   2 +
 MdeModulePkg/MdeModulePkg.dec              |   2 +
 UefiPayloadPkg/UefiPayloadPkg.dsc          |   6 +
 4 files changed, 205 insertions(+), 1 deletion(-)

diff --git a/MdeModulePkg/Application/UiApp/FrontPage.c b/MdeModulePkg/Application/UiApp/FrontPage.c
index cc9569e225..1a7182c4dc 100644
--- a/MdeModulePkg/Application/UiApp/FrontPage.c
+++ b/MdeModulePkg/Application/UiApp/FrontPage.c
@@ -293,7 +293,11 @@ InitializeFrontPage (
   //
   // Updata Front Page banner strings
   //
-  UpdateFrontPageBannerStrings ();
+  if (FixedPcdGetBool (PcdCoreboot)) {
+    DirectUpdateFrontPageBannerStrings ();
+  } else {
+    UpdateFrontPageBannerStrings ();
+  }
 
   //
   // Update front page menus.
@@ -496,6 +500,55 @@ GetOptionalStringByIndex (
   return EFI_SUCCESS;
 }
 
+UINT16
+SmbiosTableLength (
+  SMBIOS_STRUCTURE_POINTER  SmbiosTableN
+  )
+{
+  CHAR8   *AChar;
+  UINT16  Length;
+
+  AChar = (CHAR8 *)(SmbiosTableN.Raw + SmbiosTableN.Hdr->Length);
+  while ((*AChar != 0) || (*(AChar + 1) != 0)) {
+    AChar++;  // stop at 00 - first 0
+  }
+
+  Length = (UINT16)((UINTN)AChar - (UINTN)SmbiosTableN.Raw + 2); // length includes 00
+  return Length;
+}
+
+SMBIOS_STRUCTURE_POINTER
+GetSmbiosTableFromType (
+  SMBIOS_TABLE_ENTRY_POINT  *SmbiosPoint,
+  UINT8                     SmbiosType,
+  UINTN                     IndexTable
+  )
+{
+  SMBIOS_STRUCTURE_POINTER  SmbiosTableN;
+  UINTN                     SmbiosTypeIndex;
+
+  SmbiosTypeIndex  = 0;
+  SmbiosTableN.Raw = (UINT8 *)((UINTN)SmbiosPoint->TableAddress);
+  if (SmbiosTableN.Raw == NULL) {
+    return SmbiosTableN;
+  }
+
+  while ((SmbiosTypeIndex != IndexTable) || (SmbiosTableN.Hdr->Type != SmbiosType)) {
+    if (SmbiosTableN.Hdr->Type == SMBIOS_TYPE_END_OF_TABLE) {
+      SmbiosTableN.Raw = NULL;
+      return SmbiosTableN;
+    }
+
+    if (SmbiosTableN.Hdr->Type == SmbiosType) {
+      SmbiosTypeIndex++;
+    }
+
+    SmbiosTableN.Raw = (UINT8 *)(SmbiosTableN.Raw + SmbiosTableLength (SmbiosTableN));
+  }
+
+  return SmbiosTableN;
+}
+
 /**
 
   Update the banner information for the Front Page based on Smbios information.
@@ -662,6 +715,147 @@ UpdateFrontPageBannerStrings (
   FreePool (NewString);
 }
 
+/**
+
+  Update the banner information for the Front Page based on table.
+
+**/
+VOID
+DirectUpdateFrontPageBannerStrings (
+  VOID
+  )
+{
+  CHAR16                    *MemoryStr;
+  EFI_STATUS                Status;
+  EFI_STRING_ID             TokenToUpdate;
+  EFI_PHYSICAL_ADDRESS      *Table;
+  SMBIOS_TABLE_ENTRY_POINT  *EntryPoint;
+  SMBIOS_STRUCTURE_POINTER  SmbiosTable;
+  UINT64                    InstalledMemory;
+
+  InstalledMemory = 0;
+
+  //
+  // Update Front Page strings
+  //
+  Status = EfiGetSystemConfigurationTable (&gEfiSmbiosTableGuid, (VOID **)&Table);
+  if (EFI_ERROR (Status) || (Table == NULL)) {
+  } else {
+    EntryPoint = (SMBIOS_TABLE_ENTRY_POINT *)Table;
+
+    SmbiosTable = GetSmbiosTableFromType (EntryPoint, EFI_SMBIOS_TYPE_BIOS_INFORMATION, 0);
+
+    if (SmbiosTable.Raw != NULL) {
+      CHAR16  *FwVersion;
+      CHAR16  *FwDate;
+      CHAR16  *TmpBuffer;
+      UINT8   VersionIdx;
+      UINT8   DateIdx;
+
+      TmpBuffer = AllocateZeroPool (0x60);
+
+      VersionIdx = SmbiosTable.Type0->BiosVersion;
+      DateIdx    = SmbiosTable.Type0->BiosReleaseDate;
+
+      GetOptionalStringByIndex ((CHAR8 *)((UINT8 *)SmbiosTable.Raw + SmbiosTable.Hdr->Length), VersionIdx, &FwVersion);
+      GetOptionalStringByIndex ((CHAR8 *)((UINT8 *)SmbiosTable.Raw + SmbiosTable.Hdr->Length), DateIdx, &FwDate);
+
+      StrCatS (TmpBuffer, 0x60 / sizeof (CHAR16), L"FW: ");
+      StrCatS (TmpBuffer, 0x60 / sizeof (CHAR16), FwVersion);
+      StrCatS (TmpBuffer, 0x60 / sizeof (CHAR16), L" ");
+      StrCatS (TmpBuffer, 0x60 / sizeof (CHAR16), FwDate);
+
+      TokenToUpdate = STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION);
+      HiiSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, TmpBuffer, NULL);
+
+      FreePool (FwVersion);
+      FreePool (FwDate);
+      FreePool (TmpBuffer);
+    }
+
+    SmbiosTable = GetSmbiosTableFromType (EntryPoint, SMBIOS_TYPE_SYSTEM_INFORMATION, 0);
+
+    if (SmbiosTable.Raw != NULL) {
+      CHAR16  *ProductName;
+      CHAR16  *Manufacturer;
+      CHAR16  *DeviceName;
+      CHAR16  *TmpBuffer;
+      UINT8   ProductIdx;
+      UINT8   ManIdx;
+
+      TmpBuffer  = AllocateZeroPool (0x60);
+      DeviceName = AllocateZeroPool (0x60);
+
+      ProductIdx = SmbiosTable.Type1->ProductName;
+      ManIdx     = SmbiosTable.Type1->Manufacturer;
+
+      GetOptionalStringByIndex ((CHAR8 *)((UINT8 *)SmbiosTable.Raw + SmbiosTable.Hdr->Length), ProductIdx, &ProductName);
+      GetOptionalStringByIndex ((CHAR8 *)((UINT8 *)SmbiosTable.Raw + SmbiosTable.Hdr->Length), ManIdx, &Manufacturer);
+
+      StrCatS (TmpBuffer, 0x60 / sizeof (CHAR16), Manufacturer);
+      StrCatS (TmpBuffer, 0x60 / sizeof (CHAR16), L" ");
+      StrCatS (TmpBuffer, 0x60 / sizeof (CHAR16), ProductName);
+
+      TokenToUpdate = STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL);
+      HiiSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, TmpBuffer, NULL);
+
+      FreePool (ProductName);
+      FreePool (Manufacturer);
+      FreePool (DeviceName);
+      FreePool (TmpBuffer);
+    }
+
+    SmbiosTable = GetSmbiosTableFromType (EntryPoint, SMBIOS_TYPE_PROCESSOR_INFORMATION, 0);
+    if (SmbiosTable.Raw != NULL) {
+      CHAR16  *ProcessorVersion;
+      CHAR16  *TmpBuffer;
+      UINT8   CpuIdx;
+
+      TmpBuffer = AllocateZeroPool (0x60);
+
+      CpuIdx = SmbiosTable.Type4->ProcessorVersion;
+
+      GetOptionalStringByIndex ((CHAR8 *)((UINT8 *)SmbiosTable.Raw + SmbiosTable.Hdr->Length), CpuIdx, &ProcessorVersion);
+      StrCatS (TmpBuffer, 0x60 / sizeof (CHAR16), ProcessorVersion);
+
+      // Trim leading spaces
+      while (TmpBuffer[0] == 0x20) {
+        TmpBuffer = &TmpBuffer[1];
+      }
+
+      TokenToUpdate = STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL);
+      HiiSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, TmpBuffer, NULL);
+
+      FreePool (ProcessorVersion);
+      FreePool (TmpBuffer);
+    }
+
+    SmbiosTable = GetSmbiosTableFromType (EntryPoint, SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS, 0);
+    if (SmbiosTable.Raw != NULL) {
+      if (SmbiosTable.Type19->StartingAddress != 0xFFFFFFFF ) {
+        InstalledMemory += RShiftU64 (
+                             SmbiosTable.Type19->EndingAddress -
+                             SmbiosTable.Type19->StartingAddress + 1,
+                             10
+                             );
+      } else {
+        InstalledMemory += RShiftU64 (
+                             SmbiosTable.Type19->ExtendedEndingAddress -
+                             SmbiosTable.Type19->ExtendedStartingAddress + 1,
+                             20
+                             );
+      }
+
+      // now update the total installed RAM size
+      ConvertMemorySizeToString ((UINT32)InstalledMemory, &MemoryStr);
+      TokenToUpdate = STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE);
+      HiiSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, MemoryStr, NULL);
+
+      FreePool (MemoryStr);
+    }
+  }
+}
+
 /**
   This function will change video resolution and text mode
   according to defined setup mode or defined boot mode
diff --git a/MdeModulePkg/Application/UiApp/UiApp.inf b/MdeModulePkg/Application/UiApp/UiApp.inf
index 3b9e048851..21979c5a55 100644
--- a/MdeModulePkg/Application/UiApp/UiApp.inf
+++ b/MdeModulePkg/Application/UiApp/UiApp.inf
@@ -58,6 +58,7 @@
 [Guids]
   gEfiIfrTianoGuid                              ## CONSUMES ## GUID (Extended IFR Guid Opcode)
   gEfiIfrFrontPageGuid                          ## CONSUMES ## GUID
+  gEfiSmbiosTableGuid                           ## CONSUMES ## GUID
 
 [Protocols]
   gEfiSmbiosProtocolGuid                        ## CONSUMES
@@ -77,6 +78,7 @@
   gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoVerticalResolution    ## CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString           ## CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed                     ## CONSUMES
+  gEfiMdeModulePkgTokenSpaceGuid.PcdCoreboot                        ## CONSUMES
 
 [UserExtensions.TianoCore."ExtraFiles"]
   UiAppExtra.uni
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index 463e889e9a..e8565cf542 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -1076,6 +1076,8 @@
   #   FALSE - UEFI Stack Guard will be disabled.<BR>
   # @Prompt Enable UEFI Stack Guard.
   gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard|FALSE|BOOLEAN|0x30001055
+  # Build Type
+  gEfiMdeModulePkgTokenSpaceGuid.PcdCoreboot|FALSE|BOOLEAN|0x00000027
 
 [PcdsFixedAtBuild, PcdsPatchableInModule]
   ## Dynamic type PCD can be registered callback function for Pcd setting action.
diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayloadPkg.dsc
index 1ce96a51c1..636ab31b64 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.dsc
+++ b/UefiPayloadPkg/UefiPayloadPkg.dsc
@@ -399,6 +399,12 @@
   gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask       | 0x1
 !endif
 
+!if $(BOOTLOADER) == "COREBOOT"
+  gEfiMdeModulePkgTokenSpaceGuid.PcdCoreboot|TRUE
+!else
+  gEfiMdeModulePkgTokenSpaceGuid.PcdCoreboot|FALSE
+!endif
+
 [PcdsPatchableInModule.X64]
   gPcAtChipsetPkgTokenSpaceGuid.PcdRtcIndexRegister|$(RTC_INDEX_REGISTER)
   gPcAtChipsetPkgTokenSpaceGuid.PcdRtcTargetRegister|$(RTC_TARGET_REGISTER)
-- 
2.32.0



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


Re: [edk2-devel] [PATCH] MdeModulePkg/Frontpage: Get SMBIOS Data from table directly
Posted by Michael Brown 2 years, 3 months ago
On 01/02/2022 09:34, Sean Rhodes wrote:
> Gather information from SMBIOS table rather than getting it
> from the EFI SMBIOS protocol for coreboot builds.

Could you not avoid code duplication by exposing the SMBIOS table via 
EFI_SMBIOS_PROTOCOL?  This would provide a much more general solution 
that would not be specific to UiApp/Frontpage.c.

Michael


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


Re: [edk2-devel] [PATCH] MdeModulePkg/Frontpage: Get SMBIOS Data from table directly
Posted by Sean Rhodes 2 years, 3 months ago
Hi Michael

Not quite sure how to implement that, are there any existing use cases that I can look at?

Thanks!

Sean


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


Re: [edk2-devel] [PATCH] MdeModulePkg/Frontpage: Get SMBIOS Data from table directly
Posted by Michael Brown 2 years, 2 months ago
On 02/02/2022 09:02, Sean Rhodes wrote:
> Not quite sure how to implement that, are there any existing use cases 
> that I can look at?

 From the way that your patch uses SMBIOS data, I'm assuming that your 
use case involves a pre-existing SMBIOS table structure that is 
constructed by something (e.g. coreboot) before UEFI starts up, and that 
you want to extract information from this table.

If this assumption is correct, then the use case looks similar to the 
way that OvmfPkg handles a pre-existing SMBIOS table constructed by the 
hypervisor: the binary table is minimally parsed and all structures are 
handed over to UEFI via EFI_SMBIOS_PROTOCOL.Add().  This means that all 
structures from the pre-existing SMBIOS table are available to any UEFI 
SMBIOS consumers.

See, for example OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c.

HTH,

Michael


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


回复: [edk2-devel] [PATCH] MdeModulePkg/Frontpage: Get SMBIOS Data from table directly
Posted by gaoliming 2 years, 2 months ago
Sean:
 Seemly, your case doesn't install SMBIOS protocol. Can you give the detail information about this usage that provides SMBIOS table without SMBIOS protocol?

Thanks
Liming
> -----邮件原件-----
> 发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Michael
> Brown
> 发送时间: 2022年2月2日 22:18
> 收件人: Sean Rhodes <sean@starlabs.systems>; devel@edk2.groups.io
> 主题: Re: [edk2-devel] [PATCH] MdeModulePkg/Frontpage: Get SMBIOS Data
> from table directly
> 
> On 02/02/2022 09:02, Sean Rhodes wrote:
> > Not quite sure how to implement that, are there any existing use cases
> > that I can look at?
> 
>  From the way that your patch uses SMBIOS data, I'm assuming that your
> use case involves a pre-existing SMBIOS table structure that is
> constructed by something (e.g. coreboot) before UEFI starts up, and that
> you want to extract information from this table.
> 
> If this assumption is correct, then the use case looks similar to the
> way that OvmfPkg handles a pre-existing SMBIOS table constructed by the
> hypervisor: the binary table is minimally parsed and all structures are
> handed over to UEFI via EFI_SMBIOS_PROTOCOL.Add().  This means that all
> structures from the pre-existing SMBIOS table are available to any UEFI
> SMBIOS consumers.
> 
> See, for example OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c.
> 
> HTH,
> 
> Michael
> 
> 
> 
> 





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


Re: [edk2-devel] 回复: [edk2-devel] [PATCH] MdeModulePkg/Frontpage: Get SMBIOS Data from table directly
Posted by Sean Rhodes 2 years, 2 months ago
Hi Liming

It is standard coreboot code that provides it this way.

Thanks

Sean


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


Re: [edk2-devel] 回复: [edk2-devel] [PATCH] MdeModulePkg/Frontpage: Get SMBIOS Data from table directly
Posted by Sean Rhodes 2 years, 2 months ago
I think we can resolve in coreboot, I will close the PR :)

Thanks
Sean


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