public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] MdeModulePkg/Frontpage: Get SMBIOS Data from table directly
@ 2022-02-01  9:34 Sean Rhodes
  2022-02-01 11:31 ` [edk2-devel] " Michael Brown
  0 siblings, 1 reply; 7+ messages in thread
From: Sean Rhodes @ 2022-02-01  9:34 UTC (permalink / raw)
  To: devel; +Cc: Sean Rhodes, Matt DeVillier

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


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

* Re: [edk2-devel] [PATCH] MdeModulePkg/Frontpage: Get SMBIOS Data from table directly
  2022-02-01  9:34 [PATCH] MdeModulePkg/Frontpage: Get SMBIOS Data from table directly Sean Rhodes
@ 2022-02-01 11:31 ` Michael Brown
  2022-02-02  9:02   ` Sean Rhodes
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Brown @ 2022-02-01 11:31 UTC (permalink / raw)
  To: devel, sean; +Cc: Matt DeVillier

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

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

* Re: [edk2-devel] [PATCH] MdeModulePkg/Frontpage: Get SMBIOS Data from table directly
  2022-02-01 11:31 ` [edk2-devel] " Michael Brown
@ 2022-02-02  9:02   ` Sean Rhodes
  2022-02-02 14:18     ` Michael Brown
  0 siblings, 1 reply; 7+ messages in thread
From: Sean Rhodes @ 2022-02-02  9:02 UTC (permalink / raw)
  To: Michael Brown, devel

[-- Attachment #1: Type: text/plain, Size: 125 bytes --]

Hi Michael

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

Thanks!

Sean

[-- Attachment #2: Type: text/html, Size: 149 bytes --]

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

* Re: [edk2-devel] [PATCH] MdeModulePkg/Frontpage: Get SMBIOS Data from table directly
  2022-02-02  9:02   ` Sean Rhodes
@ 2022-02-02 14:18     ` Michael Brown
  2022-02-07  1:57       ` 回复: " gaoliming
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Brown @ 2022-02-02 14:18 UTC (permalink / raw)
  To: Sean Rhodes, devel

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

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

* 回复: [edk2-devel] [PATCH] MdeModulePkg/Frontpage: Get SMBIOS Data from table directly
  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
  0 siblings, 2 replies; 7+ messages in thread
From: gaoliming @ 2022-02-07  1:57 UTC (permalink / raw)
  To: devel, mcb30, 'Sean Rhodes'

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
> 
> 
> 
> 




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

* Re: [edk2-devel] 回复: [edk2-devel] [PATCH] MdeModulePkg/Frontpage: Get SMBIOS Data from table directly
  2022-02-07  1:57       ` 回复: " gaoliming
@ 2022-02-10 21:36         ` Sean Rhodes
  2022-02-10 22:12         ` Sean Rhodes
  1 sibling, 0 replies; 7+ messages in thread
From: Sean Rhodes @ 2022-02-10 21:36 UTC (permalink / raw)
  To: gaoliming, devel

[-- Attachment #1: Type: text/plain, Size: 88 bytes --]

Hi Liming

It is standard coreboot code that provides it this way.

Thanks

Sean

[-- Attachment #2: Type: text/html, Size: 112 bytes --]

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

* Re: [edk2-devel] 回复: [edk2-devel] [PATCH] MdeModulePkg/Frontpage: Get SMBIOS Data from table directly
  2022-02-07  1:57       ` 回复: " gaoliming
  2022-02-10 21:36         ` [edk2-devel] " Sean Rhodes
@ 2022-02-10 22:12         ` Sean Rhodes
  1 sibling, 0 replies; 7+ messages in thread
From: Sean Rhodes @ 2022-02-10 22:12 UTC (permalink / raw)
  To: gaoliming, devel

[-- Attachment #1: Type: text/plain, Size: 76 bytes --]

I think we can resolve in coreboot, I will close the PR :)

Thanks
Sean

[-- Attachment #2: Type: text/html, Size: 104 bytes --]

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

end of thread, other threads:[~2022-02-10 22:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-01  9:34 [PATCH] MdeModulePkg/Frontpage: Get SMBIOS Data from table directly Sean Rhodes
2022-02-01 11:31 ` [edk2-devel] " 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

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