OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
Smbios.c
Go to the documentation of this file.
1
15#include <UserFile.h>
16#include <UserGlobalVar.h>
17#include <UserBootServices.h>
18#include <UserPcd.h>
19
20#include <Library/BaseMemoryLib.h>
21#include <Library/MemoryAllocationLib.h>
22#include <Library/OcSmbiosLib.h>
23#include <Library/OcMiscLib.h>
25
26#include <sys/time.h>
27#include <stdint.h>
28#include <stdio.h>
29#include <stdbool.h>
30#include <stdlib.h>
31
32STATIC GUID SystemUUID = {
33 0x5BC82C38, 0x4DB6, 0x4883, { 0x85, 0x2E, 0xE7, 0x8D, 0x78, 0x0A, 0x6F, 0xE6 }
34};
35STATIC UINT8 BoardType = 0xA; // Motherboard (BaseBoardTypeMotherBoard)
36STATIC UINT8 MemoryFormFactor = 0xD; // SODIMM, 0x9 for DIMM (MemoryFormFactorSodimm)
37STATIC UINT8 ChassisType = 0xD; // All in one (MiscChassisTypeAllInOne)
38STATIC UINT32 PlatformFeature = 1;
40 .BIOSVendor = NULL, // Do not change BIOS Vendor
41 .BIOSVersion = "134.0.0.0.0",
42 .BIOSReleaseDate = "12/08/2017",
43 .SystemManufacturer = NULL, // Do not change System Manufacturer
44 .SystemProductName = "iMac14,2",
45 .SystemVersion = "1.0",
46 .SystemSerialNumber = "SU77OPENCORE",
47 .SystemUUID = &SystemUUID,
48 .SystemSKUNumber = "Mac-27ADBB7B4CEE8E61",
49 .SystemFamily = "iMac",
50 .BoardManufacturer = NULL, // Do not change Board Manufacturer
51 .BoardProduct = "Mac-27ADBB7B4CEE8E61",
52 .BoardVersion = "iMac14,2",
53 .BoardSerialNumber = "SU77PEPELATZWAFFE",
54 .BoardAssetTag = "",
55 .BoardLocationInChassis = "Part Component",
56 .BoardType = &BoardType,
57 .MemoryFormFactor = &MemoryFormFactor,
58 .ChassisType = &ChassisType,
59 .ChassisManufacturer = NULL, // Do not change Chassis Manufacturer
60 .ChassisVersion = "Mac-27ADBB7B4CEE8E61",
61 .ChassisSerialNumber = "SU77OPENCORE",
62 .ChassisAssetTag = "iMac-Aluminum",
63 .FirmwareFeatures = 0xE00FE137,
64 .FirmwareFeaturesMask = 0xFF1FFF3F,
65 .ProcessorType = NULL, // Will be calculated automatically
66 .PlatformFeature = &PlatformFeature
67};
68
69bool doDump = false;
70
71SMBIOS_TABLE_ENTRY_POINT gSmbios;
72SMBIOS_TABLE_3_0_ENTRY_POINT gSmbios3;
73
74int
76 int argc,
77 char *argv[]
78 )
79{
80 PcdGet32 (PcdFixedDebugPrintErrorLevel) |= DEBUG_INFO;
81 PcdGet32 (PcdDebugPrintErrorLevel) |= DEBUG_INFO;
82
83 uint32_t f;
84 uint8_t *b;
85
86 if ((b = UserReadFile ((argc > 1) ? argv[1] : "Smbios.bin", &f)) == NULL) {
87 printf ("Read fail\n");
88 return -1;
89 }
90
91 doDump = true;
92 gSmbios3.TableMaximumSize = f;
93 gSmbios3.TableAddress = (uintptr_t)b;
94 gSmbios3.EntryPointLength = sizeof (SMBIOS_TABLE_3_0_ENTRY_POINT);
95 EFI_STATUS Status;
96
97 Status = gBS->InstallConfigurationTable (&gEfiSmbios3TableGuid, &gSmbios3);
98 if (EFI_ERROR (Status)) {
99 DEBUG ((DEBUG_ERROR, "Failed to install gSmbios3 - %r\n", Status));
100 }
101
102 OC_CPU_INFO CpuInfo;
103
104 OcCpuScanProcessor (&CpuInfo);
105
106 OC_SMBIOS_TABLE SmbiosTable;
107
108 Status = OcSmbiosTablePrepare (&SmbiosTable);
109 if (!EFI_ERROR (Status)) {
110 Status = OcSmbiosCreate (&SmbiosTable, &SmbiosData, OcSmbiosUpdateCreate, &CpuInfo);
111 if (!EFI_ERROR (Status)) {
112 SMBIOS_TABLE_3_0_ENTRY_POINT *patchedTablePtr = NULL;
113 Status = EfiGetSystemConfigurationTable (&gEfiSmbios3TableGuid, (VOID **)&patchedTablePtr);
114 if (doDump && !EFI_ERROR (Status)) {
115 (void)remove ("out.bin");
116 FILE *fh = fopen ("out.bin", "wb");
117 if (fh != NULL) {
118 fwrite ((const void *)(uintptr_t)(patchedTablePtr->TableAddress), (size_t)(patchedTablePtr->TableMaximumSize), 1, fh);
119 fclose (fh);
120 } else {
121 DEBUG ((DEBUG_ERROR, "Failed to produce out.bin - %r\n", Status));
122 }
123 } else {
124 DEBUG ((DEBUG_ERROR, "EfiGetSystemConfigurationTable returns error - %r\n", Status));
125 }
126 } else {
127 DEBUG ((DEBUG_ERROR, "OcSmbiosCreate returns error - %r\n", Status));
128 }
129
130 OcSmbiosTableFree (&SmbiosTable);
131 } else {
132 DEBUG ((DEBUG_ERROR, "Failed to prepare smbios table - %r\n", Status));
133 }
134
135 return 0;
136}
137
138int
140 const uint8_t *Data,
141 size_t Size
142 )
143{
144 if (Size > 0) {
145 VOID *NewData = AllocatePool (Size);
146 if (NewData) {
147 CopyMem (NewData, Data, Size);
148
149 gSmbios3.TableMaximumSize = Size;
150 gSmbios3.TableAddress = (uintptr_t)NewData;
151 gSmbios3.EntryPointLength = sizeof (SMBIOS_TABLE_3_0_ENTRY_POINT);
152
153 OC_CPU_INFO CpuInfo;
154 OcCpuScanProcessor (&CpuInfo);
155
156 EFI_STATUS Status;
157 OC_SMBIOS_TABLE SmbiosTable;
158 Status = OcSmbiosTablePrepare (&SmbiosTable);
159 if (!EFI_ERROR (Status)) {
160 OcSmbiosCreate (&SmbiosTable, &SmbiosData, OcSmbiosUpdateCreate, &CpuInfo);
161 OcSmbiosTableFree (&SmbiosTable);
162 }
163
164 FreePool (NewData);
165 }
166 }
167
168 return 0;
169}
DMG_SIZE_DEVICE_PATH Size
EFI_BOOT_SERVICES * gBS
VOID OcCpuScanProcessor(IN OUT OC_CPU_INFO *Cpu)
Definition OcCpuLib.c:832
VOID OcSmbiosTableFree(IN OUT OC_SMBIOS_TABLE *Table)
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)
EFI_STATUS OcSmbiosTablePrepare(IN OUT OC_SMBIOS_TABLE *SmbiosTable)
@ OcSmbiosUpdateCreate
STATIC OC_SMBIOS_DATA SmbiosData
Definition Smbios.c:39
STATIC UINT8 BoardType
Definition Smbios.c:35
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
Definition Smbios.c:139
STATIC UINT8 MemoryFormFactor
Definition Smbios.c:36
bool doDump
Definition Smbios.c:69
STATIC GUID SystemUUID
Definition Smbios.c:32
STATIC UINT8 ChassisType
Definition Smbios.c:37
SMBIOS_TABLE_3_0_ENTRY_POINT gSmbios3
Definition Smbios.c:72
SMBIOS_TABLE_ENTRY_POINT gSmbios
Definition Smbios.c:71
STATIC UINT32 PlatformFeature
Definition Smbios.c:38
#define uintptr_t
Definition Ubsan.h:63
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
UINT8 * UserReadFile(IN CONST CHAR8 *FileName, OUT UINT32 *Size)
Definition UserFile.c:62
EFI_GUID gEfiSmbios3TableGuid
UINT8 uint8_t
UINT32 uint32_t
int ENTRY_POINT(void)