From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smarthost01b.ixn.mail.zen.net.uk (smarthost01b.ixn.mail.zen.net.uk [212.23.1.21]) by mx.groups.io with SMTP id smtpd.web09.46362.1643708072828325191 for ; Tue, 01 Feb 2022 01:34:33 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=permerror, err=parse error for token &{10 18 sdn.klaviyomail.com}: permanent DNS error (domain: starlabs.systems, ip: 212.23.1.21, mailfrom: sean@starlabs.systems) Received: from [51.148.147.4] (helo=sean-StarBook.lan) by smarthost01b.ixn.mail.zen.net.uk with esmtp (Exim 4.90_1) (envelope-from ) id 1nEpYU-0004gL-RC; Tue, 01 Feb 2022 09:34:30 +0000 From: "Sean Rhodes" To: devel@edk2.groups.io Cc: Sean Rhodes , Matt DeVillier Subject: [PATCH] MdeModulePkg/Frontpage: Get SMBIOS Data from table directly Date: Tue, 1 Feb 2022 09:34:29 +0000 Message-Id: X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Originating-smarthost01b-IP: [51.148.147.4] Feedback-ID: 51.148.147.4 Content-Transfer-Encoding: quoted-printable Gather information from SMBIOS table rather than getting it from the EFI SMBIOS protocol for coreboot builds. Signed-off-by: Matt DeVillier Signed-off-by: Sean Rhodes --- 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/Appl= ication/UiApp/FrontPage.c index cc9569e225..1a7182c4dc 100644 --- a/MdeModulePkg/Application/UiApp/FrontPage.c +++ b/MdeModulePkg/Application/UiApp/FrontPage.c @@ -293,7 +293,11 @@ InitializeFrontPage ( //=0D // Updata Front Page banner strings=0D //=0D - UpdateFrontPageBannerStrings ();=0D + if (FixedPcdGetBool (PcdCoreboot)) {=0D + DirectUpdateFrontPageBannerStrings ();=0D + } else {=0D + UpdateFrontPageBannerStrings ();=0D + }=0D =0D //=0D // Update front page menus.=0D @@ -496,6 +500,55 @@ GetOptionalStringByIndex ( return EFI_SUCCESS;=0D }=0D =0D +UINT16=0D +SmbiosTableLength (=0D + SMBIOS_STRUCTURE_POINTER SmbiosTableN=0D + )=0D +{=0D + CHAR8 *AChar;=0D + UINT16 Length;=0D +=0D + AChar =3D (CHAR8 *)(SmbiosTableN.Raw + SmbiosTableN.Hdr->Length);=0D + while ((*AChar !=3D 0) || (*(AChar + 1) !=3D 0)) {=0D + AChar++; // stop at 00 - first 0=0D + }=0D +=0D + Length =3D (UINT16)((UINTN)AChar - (UINTN)SmbiosTableN.Raw + 2); // leng= th includes 00=0D + return Length;=0D +}=0D +=0D +SMBIOS_STRUCTURE_POINTER=0D +GetSmbiosTableFromType (=0D + SMBIOS_TABLE_ENTRY_POINT *SmbiosPoint,=0D + UINT8 SmbiosType,=0D + UINTN IndexTable=0D + )=0D +{=0D + SMBIOS_STRUCTURE_POINTER SmbiosTableN;=0D + UINTN SmbiosTypeIndex;=0D +=0D + SmbiosTypeIndex =3D 0;=0D + SmbiosTableN.Raw =3D (UINT8 *)((UINTN)SmbiosPoint->TableAddress);=0D + if (SmbiosTableN.Raw =3D=3D NULL) {=0D + return SmbiosTableN;=0D + }=0D +=0D + while ((SmbiosTypeIndex !=3D IndexTable) || (SmbiosTableN.Hdr->Type !=3D= SmbiosType)) {=0D + if (SmbiosTableN.Hdr->Type =3D=3D SMBIOS_TYPE_END_OF_TABLE) {=0D + SmbiosTableN.Raw =3D NULL;=0D + return SmbiosTableN;=0D + }=0D +=0D + if (SmbiosTableN.Hdr->Type =3D=3D SmbiosType) {=0D + SmbiosTypeIndex++;=0D + }=0D +=0D + SmbiosTableN.Raw =3D (UINT8 *)(SmbiosTableN.Raw + SmbiosTableLength (S= mbiosTableN));=0D + }=0D +=0D + return SmbiosTableN;=0D +}=0D +=0D /**=0D =0D Update the banner information for the Front Page based on Smbios informa= tion.=0D @@ -662,6 +715,147 @@ UpdateFrontPageBannerStrings ( FreePool (NewString);=0D }=0D =0D +/**=0D +=0D + Update the banner information for the Front Page based on table.=0D +=0D +**/=0D +VOID=0D +DirectUpdateFrontPageBannerStrings (=0D + VOID=0D + )=0D +{=0D + CHAR16 *MemoryStr;=0D + EFI_STATUS Status;=0D + EFI_STRING_ID TokenToUpdate;=0D + EFI_PHYSICAL_ADDRESS *Table;=0D + SMBIOS_TABLE_ENTRY_POINT *EntryPoint;=0D + SMBIOS_STRUCTURE_POINTER SmbiosTable;=0D + UINT64 InstalledMemory;=0D +=0D + InstalledMemory =3D 0;=0D +=0D + //=0D + // Update Front Page strings=0D + //=0D + Status =3D EfiGetSystemConfigurationTable (&gEfiSmbiosTableGuid, (VOID *= *)&Table);=0D + if (EFI_ERROR (Status) || (Table =3D=3D NULL)) {=0D + } else {=0D + EntryPoint =3D (SMBIOS_TABLE_ENTRY_POINT *)Table;=0D +=0D + SmbiosTable =3D GetSmbiosTableFromType (EntryPoint, EFI_SMBIOS_TYPE_BI= OS_INFORMATION, 0);=0D +=0D + if (SmbiosTable.Raw !=3D NULL) {=0D + CHAR16 *FwVersion;=0D + CHAR16 *FwDate;=0D + CHAR16 *TmpBuffer;=0D + UINT8 VersionIdx;=0D + UINT8 DateIdx;=0D +=0D + TmpBuffer =3D AllocateZeroPool (0x60);=0D +=0D + VersionIdx =3D SmbiosTable.Type0->BiosVersion;=0D + DateIdx =3D SmbiosTable.Type0->BiosReleaseDate;=0D +=0D + GetOptionalStringByIndex ((CHAR8 *)((UINT8 *)SmbiosTable.Raw + Smbio= sTable.Hdr->Length), VersionIdx, &FwVersion);=0D + GetOptionalStringByIndex ((CHAR8 *)((UINT8 *)SmbiosTable.Raw + Smbio= sTable.Hdr->Length), DateIdx, &FwDate);=0D +=0D + StrCatS (TmpBuffer, 0x60 / sizeof (CHAR16), L"FW: ");=0D + StrCatS (TmpBuffer, 0x60 / sizeof (CHAR16), FwVersion);=0D + StrCatS (TmpBuffer, 0x60 / sizeof (CHAR16), L" ");=0D + StrCatS (TmpBuffer, 0x60 / sizeof (CHAR16), FwDate);=0D +=0D + TokenToUpdate =3D STRING_TOKEN (STR_FRONT_PAGE_BIOS_VERSION);=0D + HiiSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, TmpBuffer,= NULL);=0D +=0D + FreePool (FwVersion);=0D + FreePool (FwDate);=0D + FreePool (TmpBuffer);=0D + }=0D +=0D + SmbiosTable =3D GetSmbiosTableFromType (EntryPoint, SMBIOS_TYPE_SYSTEM= _INFORMATION, 0);=0D +=0D + if (SmbiosTable.Raw !=3D NULL) {=0D + CHAR16 *ProductName;=0D + CHAR16 *Manufacturer;=0D + CHAR16 *DeviceName;=0D + CHAR16 *TmpBuffer;=0D + UINT8 ProductIdx;=0D + UINT8 ManIdx;=0D +=0D + TmpBuffer =3D AllocateZeroPool (0x60);=0D + DeviceName =3D AllocateZeroPool (0x60);=0D +=0D + ProductIdx =3D SmbiosTable.Type1->ProductName;=0D + ManIdx =3D SmbiosTable.Type1->Manufacturer;=0D +=0D + GetOptionalStringByIndex ((CHAR8 *)((UINT8 *)SmbiosTable.Raw + Smbio= sTable.Hdr->Length), ProductIdx, &ProductName);=0D + GetOptionalStringByIndex ((CHAR8 *)((UINT8 *)SmbiosTable.Raw + Smbio= sTable.Hdr->Length), ManIdx, &Manufacturer);=0D +=0D + StrCatS (TmpBuffer, 0x60 / sizeof (CHAR16), Manufacturer);=0D + StrCatS (TmpBuffer, 0x60 / sizeof (CHAR16), L" ");=0D + StrCatS (TmpBuffer, 0x60 / sizeof (CHAR16), ProductName);=0D +=0D + TokenToUpdate =3D STRING_TOKEN (STR_FRONT_PAGE_COMPUTER_MODEL);=0D + HiiSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, TmpBuffer,= NULL);=0D +=0D + FreePool (ProductName);=0D + FreePool (Manufacturer);=0D + FreePool (DeviceName);=0D + FreePool (TmpBuffer);=0D + }=0D +=0D + SmbiosTable =3D GetSmbiosTableFromType (EntryPoint, SMBIOS_TYPE_PROCES= SOR_INFORMATION, 0);=0D + if (SmbiosTable.Raw !=3D NULL) {=0D + CHAR16 *ProcessorVersion;=0D + CHAR16 *TmpBuffer;=0D + UINT8 CpuIdx;=0D +=0D + TmpBuffer =3D AllocateZeroPool (0x60);=0D +=0D + CpuIdx =3D SmbiosTable.Type4->ProcessorVersion;=0D +=0D + GetOptionalStringByIndex ((CHAR8 *)((UINT8 *)SmbiosTable.Raw + Smbio= sTable.Hdr->Length), CpuIdx, &ProcessorVersion);=0D + StrCatS (TmpBuffer, 0x60 / sizeof (CHAR16), ProcessorVersion);=0D +=0D + // Trim leading spaces=0D + while (TmpBuffer[0] =3D=3D 0x20) {=0D + TmpBuffer =3D &TmpBuffer[1];=0D + }=0D +=0D + TokenToUpdate =3D STRING_TOKEN (STR_FRONT_PAGE_CPU_MODEL);=0D + HiiSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, TmpBuffer,= NULL);=0D +=0D + FreePool (ProcessorVersion);=0D + FreePool (TmpBuffer);=0D + }=0D +=0D + SmbiosTable =3D GetSmbiosTableFromType (EntryPoint, SMBIOS_TYPE_MEMORY= _ARRAY_MAPPED_ADDRESS, 0);=0D + if (SmbiosTable.Raw !=3D NULL) {=0D + if (SmbiosTable.Type19->StartingAddress !=3D 0xFFFFFFFF ) {=0D + InstalledMemory +=3D RShiftU64 (=0D + SmbiosTable.Type19->EndingAddress -=0D + SmbiosTable.Type19->StartingAddress + 1,=0D + 10=0D + );=0D + } else {=0D + InstalledMemory +=3D RShiftU64 (=0D + SmbiosTable.Type19->ExtendedEndingAddress -=0D + SmbiosTable.Type19->ExtendedStartingAddress += 1,=0D + 20=0D + );=0D + }=0D +=0D + // now update the total installed RAM size=0D + ConvertMemorySizeToString ((UINT32)InstalledMemory, &MemoryStr);=0D + TokenToUpdate =3D STRING_TOKEN (STR_FRONT_PAGE_MEMORY_SIZE);=0D + HiiSetString (gFrontPagePrivate.HiiHandle, TokenToUpdate, MemoryStr,= NULL);=0D +=0D + FreePool (MemoryStr);=0D + }=0D + }=0D +}=0D +=0D /**=0D This function will change video resolution and text mode=0D according to defined setup mode or defined boot mode=0D diff --git a/MdeModulePkg/Application/UiApp/UiApp.inf b/MdeModulePkg/Applic= ation/UiApp/UiApp.inf index 3b9e048851..21979c5a55 100644 --- a/MdeModulePkg/Application/UiApp/UiApp.inf +++ b/MdeModulePkg/Application/UiApp/UiApp.inf @@ -58,6 +58,7 @@ [Guids]=0D gEfiIfrTianoGuid ## CONSUMES ## GUID (Exten= ded IFR Guid Opcode)=0D gEfiIfrFrontPageGuid ## CONSUMES ## GUID=0D + gEfiSmbiosTableGuid ## CONSUMES ## GUID=0D =0D [Protocols]=0D gEfiSmbiosProtocolGuid ## CONSUMES=0D @@ -77,6 +78,7 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoVerticalResolution ## CON= SUMES=0D gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString ## CON= SUMES=0D gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed ## CON= SUMES=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdCoreboot ## CON= SUMES=0D =0D [UserExtensions.TianoCore."ExtraFiles"]=0D UiAppExtra.uni=0D 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.
=0D # @Prompt Enable UEFI Stack Guard.=0D gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard|FALSE|BOOLEAN|0x30001055= =0D + # Build Type=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdCoreboot|FALSE|BOOLEAN|0x00000027=0D =0D [PcdsFixedAtBuild, PcdsPatchableInModule]=0D ## Dynamic type PCD can be registered callback function for Pcd setting = action.=0D diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayload= Pkg.dsc index 1ce96a51c1..636ab31b64 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dsc +++ b/UefiPayloadPkg/UefiPayloadPkg.dsc @@ -399,6 +399,12 @@ gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask | 0x1=0D !endif=0D =0D +!if $(BOOTLOADER) =3D=3D "COREBOOT"=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdCoreboot|TRUE=0D +!else=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdCoreboot|FALSE=0D +!endif=0D +=0D [PcdsPatchableInModule.X64]=0D gPcAtChipsetPkgTokenSpaceGuid.PcdRtcIndexRegister|$(RTC_INDEX_REGISTER)= =0D gPcAtChipsetPkgTokenSpaceGuid.PcdRtcTargetRegister|$(RTC_TARGET_REGISTER= )=0D --=20 2.32.0