Skip to content

Commit

Permalink
OcSmbiosLib: Cleanup & refactor OEM value exposure
Browse files Browse the repository at this point in the history
  • Loading branch information
vit9696 committed Feb 13, 2021
1 parent d8f9b55 commit f51fee6
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 122 deletions.
70 changes: 58 additions & 12 deletions Include/Acidanthera/Library/OcSmbiosLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
//
#define OC_SMBIOS_VENDOR_NAME "Acidanthera"

//
// Maximum characters for valid Mac-like OEM name.
//
#define OC_SMBIOS_OEM_NAME_MAX 48

typedef struct OC_SMBIOS_MEMORY_DEVICE_DATA_ {
//
// Strings.
Expand Down Expand Up @@ -86,8 +91,9 @@ typedef struct OC_SMBIOS_DATA_ {
//
// Type 16
//
UINT16 MemoryDevicesCount;
BOOLEAN HasCustomMemory;
CONST UINT8 *MemoryErrorCorrection;
UINT16 MemoryDevicesCount;
CONST UINT64 *MemoryMaxCapacity;
//
// Type 17
Expand Down Expand Up @@ -212,36 +218,76 @@ OcSmbiosTableFree (
IN OUT OC_SMBIOS_TABLE *Table
);

/**
Create new SMBIOS based on specified overrides.
@param[in,out] SmbiosTable SMBIOS Table handle.
@param[in] Data SMBIOS overrides.
@param[in] Mode SMBIOS update mode.
@param[in] CpuInfo CPU information.
@retval EFI_SUCCESS on success.
**/
EFI_STATUS
OcSmbiosCreate (
IN OUT OC_SMBIOS_TABLE *SmbiosTable,
IN OC_SMBIOS_DATA *Data,
IN OC_SMBIOS_UPDATE_MODE Mode,
IN OC_CPU_INFO *CpuInfo,
IN BOOLEAN UseCustomMemory
IN OC_CPU_INFO *CpuInfo
);

/**
Extract OEM information from SMBIOS to different places.
@param[in,out] SmbiosTable SMBIOS Table handle.
@param[out] ProductName Export SMBIOS Type 1 product name,
requiring OC_SMBIOS_OEM_NAME_MAX bytes.
@param[in] UseVariableStorage Export OEM information to NVRAM.
**/
VOID
OcSmbiosExposeOemInfo (
IN OC_SMBIOS_TABLE *SmbiosTable
OcSmbiosExtractOemInfo (
IN OC_SMBIOS_TABLE *SmbiosTable,
OUT CHAR8 *ProductName OPTIONAL,
IN BOOLEAN UseVariableStorage
);

/**
Convert SMC revision from SMC REV key format (6-byte)
to SMBIOS ASCII format (16-byte, APPLE_SMBIOS_SMC_VERSION_SIZE).
@param[in] SmcRevision SMC revision in REV key format.
@param[out] SmcVersion SMC revision in SMBIOS format.
**/
VOID
OcSmbiosGetSmcVersion (
IN CONST UINT8 *SmcRevision,
OUT UINT8 *SmcVersion
);

CHAR8*
OcSmbiosGetManufacturer (
IN OC_SMBIOS_TABLE *SmbiosTable
);
/**
Choose update mode based on default representation.
Always returns valid update mode, by falling back
to Create when unknown mode was found. Known modes are:
TryOverwrite, Create, Overwrite, Custom.
@param[in] UpdateMode in ASCII format.
CHAR8*
OcSmbiosGetProductName (
IN OC_SMBIOS_TABLE *SmbiosTable
@returns SMBIS update mode in enum format.
**/
OC_SMBIOS_UPDATE_MODE
OcSmbiosGetUpdateMode (
IN CONST CHAR8 *UpdateMode
);

/**
Dump current SMBIOS data into specified directory
under EntryV#.bin/DataV#.bin names, where # is
SMBIOS version: 1, 3, or both.
@param[in] Root Directory to dump SMBIOS data.
@retval EFI_SUCCESS on success.
**/
EFI_STATUS
OcSmbiosDump (
IN EFI_FILE_PROTOCOL *Root
Expand Down
59 changes: 24 additions & 35 deletions Library/OcMainLib/OpenCorePlatform.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

#include <Guid/AppleVariable.h>

STATIC CHAR8 mCurrentSmbiosProductName[48];
STATIC CHAR8 mCurrentSmbiosProductName[OC_SMBIOS_OEM_NAME_MAX];

STATIC
VOID
Expand Down Expand Up @@ -414,6 +414,8 @@ OcPlatformUpdateSmbios (
// Inject custom memory info.
//
if (Config->PlatformInfo.CustomMemory) {
Data.HasCustomMemory = TRUE;

if (Config->PlatformInfo.Memory.Devices.Count <= MAX_UINT16) {
Data.MemoryDevicesCount = (UINT16) Config->PlatformInfo.Memory.Devices.Count;
} else {
Expand All @@ -435,7 +437,7 @@ OcPlatformUpdateSmbios (
Data.MemoryDevicesCount = 0;
}

for (Index = 0; Index < Data.MemoryDevicesCount; Index++) {
for (Index = 0; Index < Data.MemoryDevicesCount; ++Index) {
MemoryEntry = Config->PlatformInfo.Memory.Devices.Values[Index];

Data.MemoryDevices[Index].AssetTag = OC_BLOB_GET (&MemoryEntry->AssetTag);
Expand All @@ -458,7 +460,7 @@ OcPlatformUpdateSmbios (
}
}

Status = OcSmbiosCreate (SmbiosTable, &Data, UpdateMode, CpuInfo, Config->PlatformInfo.CustomMemory);
Status = OcSmbiosCreate (SmbiosTable, &Data, UpdateMode, CpuInfo);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "OC: Failed to update SMBIOS - %r\n", Status));
}
Expand Down Expand Up @@ -689,14 +691,12 @@ OcLoadPlatformSupport (
IN OC_CPU_INFO *CpuInfo
)
{
CONST CHAR8 *SmbiosUpdateStr;
OC_SMBIOS_UPDATE_MODE SmbiosUpdateMode;
MAC_INFO_DATA InfoData;
MAC_INFO_DATA *UsedMacInfo;
EFI_STATUS Status;
OC_SMBIOS_TABLE SmbiosTable;
BOOLEAN ExposeOem;
CONST CHAR8 *SmbiosProductName;

if (Config->PlatformInfo.Automatic) {
GetMacInfo (OC_BLOB_GET (&Config->PlatformInfo.Generic.SystemProductName), &InfoData);
Expand All @@ -705,43 +705,28 @@ OcLoadPlatformSupport (
UsedMacInfo = NULL;
}

if (Config->PlatformInfo.UpdateDataHub) {
OcPlatformUpdateDataHub (Config, CpuInfo, UsedMacInfo);
}

ExposeOem = (Config->Misc.Security.ExposeSensitiveData & OCS_EXPOSE_OEM_INFO) != 0;

if (ExposeOem || Config->PlatformInfo.UpdateSmbios) {
Status = OcSmbiosTablePrepare (&SmbiosTable);
if (!EFI_ERROR (Status)) {
if (ExposeOem) {
OcSmbiosExposeOemInfo (&SmbiosTable);
}

SmbiosProductName = OcSmbiosGetProductName (&SmbiosTable);
DEBUG ((DEBUG_INFO, "OC: Current SMBIOS: %a model %a\n", OcSmbiosGetManufacturer (&SmbiosTable), SmbiosProductName));
Status = AsciiStrCpyS (mCurrentSmbiosProductName, sizeof (mCurrentSmbiosProductName), SmbiosProductName);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "OC: Failed to copy SMBIOS product name %a\n", SmbiosProductName));
}
OcSmbiosExtractOemInfo (
&SmbiosTable,
mCurrentSmbiosProductName,
ExposeOem
);

if (Config->PlatformInfo.UpdateSmbios) {
SmbiosUpdateStr = OC_BLOB_GET (&Config->PlatformInfo.UpdateSmbiosMode);

if (AsciiStrCmp (SmbiosUpdateStr, "TryOverwrite") == 0) {
SmbiosUpdateMode = OcSmbiosUpdateTryOverwrite;
} else if (AsciiStrCmp (SmbiosUpdateStr, "Create") == 0) {
SmbiosUpdateMode = OcSmbiosUpdateCreate;
} else if (AsciiStrCmp (SmbiosUpdateStr, "Overwrite") == 0) {
SmbiosUpdateMode = OcSmbiosUpdateOverwrite;
} else if (AsciiStrCmp (SmbiosUpdateStr, "Custom") == 0) {
SmbiosUpdateMode = OcSmbiosUpdateCustom;
} else {
DEBUG ((DEBUG_WARN, "OC: Invalid SMBIOS update mode %a\n", SmbiosUpdateStr));
SmbiosUpdateMode = OcSmbiosUpdateCreate;
}

OcPlatformUpdateSmbios (Config, CpuInfo, UsedMacInfo, &SmbiosTable, SmbiosUpdateMode);
SmbiosUpdateMode = OcSmbiosGetUpdateMode (
OC_BLOB_GET (&Config->PlatformInfo.UpdateSmbiosMode)
);
OcPlatformUpdateSmbios (
Config,
CpuInfo,
UsedMacInfo,
&SmbiosTable,
SmbiosUpdateMode
);
}

OcSmbiosTableFree (&SmbiosTable);
Expand All @@ -750,6 +735,10 @@ OcLoadPlatformSupport (
}
}

if (Config->PlatformInfo.UpdateDataHub) {
OcPlatformUpdateDataHub (Config, CpuInfo, UsedMacInfo);
}

if (Config->PlatformInfo.UpdateNvram) {
OcPlatformUpdateNvram (Config, UsedMacInfo);
}
Expand Down
Loading

0 comments on commit f51fee6

Please sign in to comment.