public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Sean Rhodes" <sean@starlabs.systems>
To: devel@edk2.groups.io
Cc: Sean Rhodes <sean@starlabs.systems>,
	Matt DeVillier <matt.devillier@gmail.com>
Subject: [PATCH] MdeModulePkg/Frontpage: Get SMBIOS Data from table directly
Date: Tue,  1 Feb 2022 09:34:29 +0000	[thread overview]
Message-ID: <dfcff45f586747827e9a87020acb48cfad52b0e3.1643708039.git.sean@starlabs.systems> (raw)

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


             reply	other threads:[~2022-02-01  9:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-01  9:34 Sean Rhodes [this message]
2022-02-01 11:31 ` [edk2-devel] [PATCH] MdeModulePkg/Frontpage: Get SMBIOS Data from table directly Michael Brown
2022-02-02  9:02   ` Sean Rhodes
2022-02-02 14:18     ` Michael Brown
2022-02-07  1:57       ` 回复: " gaoliming
2022-02-10 21:36         ` [edk2-devel] " Sean Rhodes
2022-02-10 22:12         ` Sean Rhodes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=dfcff45f586747827e9a87020acb48cfad52b0e3.1643708039.git.sean@starlabs.systems \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox