[PATCH] UefiPayloadPkg/BlSupportDxe: Use EfiSmbiosProtocol to install tables


Patrick Rudolph
 

The default EfiSmbiosProtocol operates on an empty SMBIOS table.
As the SMBIOS tables are provided by the bootloader, install the
SMBIOS tables using the EfiSmbiosProtocol.

This fixes the settings menu not showing any hardware information, instead
only "0 MB RAM" was displayed.

Tests showed that the OS can still see the SMBIOS tables.

Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
---
UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c | 111 +++++++++++++++++++-
UefiPayloadPkg/BlSupportDxe/BlSupportDxe.h | 3 +
UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf | 5 +-
3 files changed, 115 insertions(+), 4 deletions(-)

diff --git a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c b/UefiPayloadPkg/Bl=
SupportDxe/BlSupportDxe.c
index a746d0581e..db478c1abc 100644
--- a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c
+++ b/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.c
@@ -79,6 +79,107 @@ ReserveResourceInGcd (
return Status;=0D
}=0D
=0D
+EFI_STATUS=0D
+EFIAPI=0D
+BlDxeInstallSMBIOStables(=0D
+ IN UINT64 SmbiosTableBase,=0D
+ IN UINT32 SmbiosTableSize=0D
+)=0D
+{=0D
+ EFI_STATUS Status;=0D
+ SMBIOS_TABLE_ENTRY_POINT *SmbiosTable;=0D
+ SMBIOS_TABLE_3_0_ENTRY_POINT *Smbios30Table;=0D
+ SMBIOS_STRUCTURE_POINTER Smbios;=0D
+ SMBIOS_STRUCTURE_POINTER SmbiosEnd;=0D
+ CHAR8 *String;=0D
+ EFI_SMBIOS_HANDLE SmbiosHandle;=0D
+ EFI_SMBIOS_PROTOCOL *SmbiosProto;=0D
+=0D
+ //=0D
+ // Locate Smbios protocol.=0D
+ //=0D
+ Status =3D gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)=
&SmbiosProto);=0D
+ if (EFI_ERROR (Status)) {=0D
+ DEBUG ((DEBUG_ERROR, "%a: Failed to locate gEfiSmbiosProtocolGuid\n",=
=0D
+ __FUNCTION__));=0D
+ return Status;=0D
+ }=0D
+=0D
+ Smbios30Table =3D (SMBIOS_TABLE_3_0_ENTRY_POINT *)(UINTN)(SmbiosTableBas=
e);=0D
+ SmbiosTable =3D (SMBIOS_TABLE_ENTRY_POINT *)(UINTN)(SmbiosTableBase);=0D
+=0D
+ if (CompareMem (Smbios30Table->AnchorString, "_SM3_", 5) =3D=3D 0) {=0D
+ Smbios.Hdr =3D (SMBIOS_STRUCTURE *) (UINTN) Smbios30Table->TableAddres=
s;=0D
+ SmbiosEnd.Raw =3D (UINT8 *) (UINTN) (Smbios30Table->TableAddress + Smb=
ios30Table->TableMaximumSize);=0D
+ if (Smbios30Table->TableMaximumSize > SmbiosTableSize) {=0D
+ DEBUG((DEBUG_INFO, "%a: SMBIOS table size greater than reported by b=
ootloader\n",=0D
+ __FUNCTION__));=0D
+ }=0D
+ } else if (CompareMem (SmbiosTable->AnchorString, "_SM_", 4) =3D=3D 0) {=
=0D
+ Smbios.Hdr =3D (SMBIOS_STRUCTURE *) (UINTN) SmbiosTable->TableAddre=
ss;=0D
+ SmbiosEnd.Raw =3D (UINT8 *) ((UINTN) SmbiosTable->TableAddress + Smbio=
sTable->TableLength);=0D
+=0D
+ if (SmbiosTable->TableLength > SmbiosTableSize) {=0D
+ DEBUG((DEBUG_INFO, "%a: SMBIOS table size greater than reported by b=
ootloader\n",=0D
+ __FUNCTION__));=0D
+ }=0D
+ } else {=0D
+ DEBUG ((DEBUG_ERROR, "%a: No valid SMBIOS table found\n", __FUNCTION__=
));=0D
+ return EFI_NOT_FOUND;=0D
+ }=0D
+=0D
+ do {=0D
+ // Check for end marker=0D
+ if (Smbios.Hdr->Type =3D=3D 127) {=0D
+ break;=0D
+ }=0D
+=0D
+ // Install the table=0D
+ SmbiosHandle =3D SMBIOS_HANDLE_PI_RESERVED;=0D
+ Status =3D SmbiosProto->Add (=0D
+ SmbiosProto,=0D
+ gImageHandle,=0D
+ &SmbiosHandle,=0D
+ Smbios.Hdr=0D
+ );=0D
+ ASSERT_EFI_ERROR (Status);=0D
+ if (EFI_ERROR (Status)) {=0D
+ return Status;=0D
+ }=0D
+ //=0D
+ // Go to the next SMBIOS structure. Each SMBIOS structure may include =
2 parts:=0D
+ // 1. Formatted section; 2. Unformatted string section. So, 2 steps ar=
e needed=0D
+ // to skip one SMBIOS structure.=0D
+ //=0D
+=0D
+ //=0D
+ // Step 1: Skip over formatted section.=0D
+ //=0D
+ String =3D (CHAR8 *) (Smbios.Raw + Smbios.Hdr->Length);=0D
+=0D
+ //=0D
+ // Step 2: Skip over unformatted string section.=0D
+ //=0D
+ do {=0D
+ //=0D
+ // Each string is terminated with a NULL(00h) BYTE and the sets of s=
trings=0D
+ // is terminated with an additional NULL(00h) BYTE.=0D
+ //=0D
+ for ( ; *String !=3D 0; String++) {=0D
+ }=0D
+=0D
+ if (*(UINT8*)++String =3D=3D 0) {=0D
+ //=0D
+ // Pointer to the next SMBIOS structure.=0D
+ //=0D
+ Smbios.Raw =3D (UINT8 *)++String;=0D
+ break;=0D
+ }=0D
+ } while (TRUE);=0D
+ } while (Smbios.Raw < SmbiosEnd.Raw);=0D
+=0D
+ return EFI_SUCCESS;=0D
+}=0D
=0D
/**=0D
Main entry for the bootloader support DXE module.=0D
@@ -133,9 +234,13 @@ BlDxeEntryPoint (
// Install Smbios Table=0D
//=0D
if (SystemTableInfo->SmbiosTableBase !=3D 0 && SystemTableInfo->SmbiosTa=
bleSize !=3D 0) {=0D
- DEBUG ((DEBUG_ERROR, "Install Smbios Table at 0x%lx, length 0x%x\n", S=
ystemTableInfo->SmbiosTableBase, SystemTableInfo->SmbiosTableSize));=0D
- Status =3D gBS->InstallConfigurationTable (&gEfiSmbiosTableGuid, (VOID=
*)(UINTN)SystemTableInfo->SmbiosTableBase);=0D
- ASSERT_EFI_ERROR (Status);=0D
+ DEBUG ((DEBUG_ERROR, "Install Smbios Table at 0x%lx, length 0x%x\n",=0D
+ SystemTableInfo->SmbiosTableBase, SystemTableInfo->SmbiosTableSize))=
;=0D
+=0D
+ if (BlDxeInstallSMBIOStables(SystemTableInfo->SmbiosTableBase, SystemT=
ableInfo->SmbiosTableSize) !=3D EFI_SUCCESS) {=0D
+ Status =3D gBS->InstallConfigurationTable (&gEfiSmbiosTableGuid, (VO=
ID *)(UINTN)SystemTableInfo->SmbiosTableBase);=0D
+ ASSERT_EFI_ERROR (Status);=0D
+ }=0D
}=0D
=0D
//=0D
diff --git a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.h b/UefiPayloadPkg/Bl=
SupportDxe/BlSupportDxe.h
index 512105fafd..a5216cd2e9 100644
--- a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.h
+++ b/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.h
@@ -10,6 +10,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
=0D
#include <PiDxe.h>=0D
=0D
+#include <Protocol/Smbios.h>=0D
+=0D
#include <Library/UefiDriverEntryPoint.h>=0D
#include <Library/UefiBootServicesTableLib.h>=0D
#include <Library/DxeServicesTableLib.h>=0D
@@ -26,5 +28,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Guid/GraphicsInfoHob.h>=0D
=0D
#include <IndustryStandard/Acpi.h>=0D
+#include <IndustryStandard/SmBios.h>=0D
=0D
#endif=0D
diff --git a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf b/UefiPayloadPkg/=
BlSupportDxe/BlSupportDxe.inf
index cebc811355..d26a75248b 100644
--- a/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf
+++ b/UefiPayloadPkg/BlSupportDxe/BlSupportDxe.inf
@@ -56,5 +56,8 @@
gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress=0D
gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseSize=0D
=0D
+[Protocols]=0D
+ gEfiSmbiosProtocolGuid=0D
+=0D
[Depex]=0D
- TRUE=0D
+ gEfiSmbiosProtocolGuid=0D
--=20
2.26.2

Join devel@edk2.groups.io to automatically receive all group messages.