OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
ValidatePlatformInfo.c
Go to the documentation of this file.
1
16#include "ocvalidate.h"
17#include "OcValidateLib.h"
18
21
22STATIC
23BOOLEAN
25 IN UINT16 ProcessorType
26 )
27{
28 UINTN Index;
29 STATIC CONST UINT8 AllowedProcessorType[] = {
44 };
45
46 //
47 // 0 is allowed.
48 //
49 if (ProcessorType == 0U) {
50 return TRUE;
51 }
52
53 for (Index = 0; Index < ARRAY_SIZE (AllowedProcessorType); ++Index) {
54 if ((ProcessorType >> 8U) == AllowedProcessorType[Index]) {
55 return TRUE;
56 }
57 }
58
59 return FALSE;
60}
61
62//
63// NOTE: Only PlatformInfo->Generic is checked here. The rest is ignored.
64//
65
66STATIC
67UINT32
69 IN OC_GLOBAL_CONFIG *Config
70 )
71{
72 UINT32 ErrorCount;
73 CONST CHAR8 *SystemProductName;
74 CONST CHAR8 *SystemMemoryStatus;
75 CONST CHAR8 *AsciiSystemUUID;
76 UINT16 ProcessorType;
77
78 ErrorCount = 0;
79
80 SystemProductName = OC_BLOB_GET (&Config->PlatformInfo.Generic.SystemProductName);
81 if (!HasMacInfo (SystemProductName)) {
82 DEBUG ((DEBUG_WARN, "PlatformInfo->Generic->SystemProductName has unknown model set!\n"));
83 ++ErrorCount;
84 }
85
86 SystemMemoryStatus = OC_BLOB_GET (&Config->PlatformInfo.Generic.SystemMemoryStatus);
87 if ( (AsciiStrCmp (SystemMemoryStatus, "Auto") != 0)
88 && (AsciiStrCmp (SystemMemoryStatus, "Upgradable") != 0)
89 && (AsciiStrCmp (SystemMemoryStatus, "Soldered") != 0))
90 {
91 DEBUG ((DEBUG_WARN, "PlatformInfo->Generic->SystemMemoryStatus is borked (Can only be Auto, Upgradable, or Soldered)!\n"));
92 ++ErrorCount;
93 }
94
95 AsciiSystemUUID = OC_BLOB_GET (&Config->PlatformInfo.Generic.SystemUuid);
96 if ( (AsciiSystemUUID[0] != '\0')
97 && (AsciiStrCmp (AsciiSystemUUID, "OEM") != 0)
98 && !AsciiGuidIsLegal (AsciiSystemUUID))
99 {
100 DEBUG ((DEBUG_WARN, "PlatformInfo->Generic->SystemUUID is borked (Can only be empty, special string OEM or valid UUID)!\n"));
101 ++ErrorCount;
102 }
103
104 ProcessorType = Config->PlatformInfo.Generic.ProcessorType;
106 DEBUG ((DEBUG_WARN, "PlatformInfo->Generic->ProcessorType is borked!\n"));
107 ++ErrorCount;
108 }
109
110 //
111 // TODO: Sanitise MLB, ProcessorType, and SystemSerialNumber if possible...
112 //
113
114 return ErrorCount;
115}
116
117UINT32
119 IN OC_GLOBAL_CONFIG *Config
120 )
121{
122 UINT32 ErrorCount;
123 BOOLEAN IsAutomaticEnabled;
124 CONST CHAR8 *UpdateSMBIOSMode;
125 UINTN Index;
126 STATIC CONFIG_CHECK PlatformInfoCheckers[] = {
128 };
129
130 DEBUG ((DEBUG_VERBOSE, "config loaded into %a!\n", __func__));
131
132 ErrorCount = 0;
133
134 UpdateSMBIOSMode = OC_BLOB_GET (&Config->PlatformInfo.UpdateSmbiosMode);
135 if ( (AsciiStrCmp (UpdateSMBIOSMode, "TryOverwrite") != 0)
136 && (AsciiStrCmp (UpdateSMBIOSMode, "Create") != 0)
137 && (AsciiStrCmp (UpdateSMBIOSMode, "Overwrite") != 0)
138 && (AsciiStrCmp (UpdateSMBIOSMode, "Custom") != 0))
139 {
140 DEBUG ((DEBUG_WARN, "PlatformInfo->UpdateSMBIOSMode is borked (Can only be TryOverwrite, Create, Overwrite, or Custom)!\n"));
141 ++ErrorCount;
142 }
143
144 IsAutomaticEnabled = Config->PlatformInfo.Automatic;
145 if (!IsAutomaticEnabled) {
146 //
147 // This is not an error, but we need to stop checking further.
148 //
149 return ReportError (__func__, ErrorCount);
150 }
151
152 for (Index = 0; Index < ARRAY_SIZE (PlatformInfoCheckers); ++Index) {
153 ErrorCount += PlatformInfoCheckers[Index](Config);
154 }
155
156 return ReportError (__func__, ErrorCount);
157}
UINT8 ProcessorType[16]
Definition Apm.h:79
#define ARRAY_SIZE(Array)
Definition AppleMacEfi.h:34
@ AppleProcessorMajorI5
@ AppleProcessorMajorXeonPenryn
@ AppleProcessorMajorXeonNehalem
@ AppleProcessorMajorCore
@ AppleProcessorMajorXeonE5
@ AppleProcessorMajorI7
@ AppleProcessorMajorCore2
@ AppleProcessorMajorM
@ AppleProcessorMajorM5
@ AppleProcessorMajorM3
@ AppleProcessorMajorM7
@ AppleProcessorMajorI3
@ AppleProcessorMajorI9
@ AppleProcessorMajorXeonW
BOOLEAN HasMacInfo(IN CONST CHAR8 *ProductName)
#define OC_BLOB_GET(Blob)
UINT32 ReportError(IN CONST CHAR8 *FuncName, IN UINT32 ErrorCount)
BOOLEAN AsciiGuidIsLegal(IN CONST CHAR8 *AsciiGuid)
STATIC UINT32 CheckPlatformInfoGeneric(IN OC_GLOBAL_CONFIG *Config)
UINT32 CheckPlatformInfo(IN OC_GLOBAL_CONFIG *Config)
STATIC BOOLEAN ValidateProcessorType(IN UINT16 ProcessorType)
UINT32(* CONFIG_CHECK)(IN OC_GLOBAL_CONFIG *Config)
Definition ocvalidate.h:27