1 | /*␊ |
2 | * SMBIOS Table Patcher, part of the Chameleon Boot Loader Project␊ |
3 | *␊ |
4 | * Copyright 2010 by Islam M. Ahmed Zaid. All rights reserved.␊ |
5 | *␊ |
6 | */␊ |
7 | ␊ |
8 | ␊ |
9 | #include "boot.h"␊ |
10 | #include "bootstruct.h"␊ |
11 | #include "smbios_getters.h"␊ |
12 | ␊ |
13 | #ifndef DEBUG_SMBIOS␊ |
14 | #define DEBUG_SMBIOS 0␊ |
15 | #endif␊ |
16 | ␊ |
17 | #if DEBUG_SMBIOS==2␊ |
18 | #define DBG(x...)␉printf(x)␊ |
19 | #elif DEBUG_SMBIOS==1␊ |
20 | #define DBG(x...) msglog(x)␊ |
21 | #else␊ |
22 | #define DBG(x...)␉␊ |
23 | #endif␊ |
24 | ␊ |
25 | #define SMBPlist␉␉␉&bootInfo->smbiosConfig␊ |
26 | /* ASSUMPTION: 16KB should be enough for the whole thing */␊ |
27 | #define SMB_ALLOC_SIZE␉16384␊ |
28 | ␊ |
29 | ␊ |
30 | //-------------------------------------------------------------------------------------------------------------------------␊ |
31 | // SMBIOS Plist Keys␊ |
32 | //-------------------------------------------------------------------------------------------------------------------------␊ |
33 | /* BIOS Information */␊ |
34 | #define kSMBBIOSInformationVendorKey␉␉␉␉"SMbiosvendor"␊ |
35 | #define kSMBBIOSInformationVersionKey␉␉␉␉"SMbiosversion"␊ |
36 | #define kSMBBIOSInformationReleaseDateKey␉␉␉"SMbiosdate"␊ |
37 | ␊ |
38 | /* System Information */␊ |
39 | #define kSMBSystemInformationManufacturerKey␉␉"SMmanufacturer"␊ |
40 | #define kSMBSystemInformationProductNameKey␉␉␉"SMproductname"␊ |
41 | #define kSMBSystemInformationVersionKey␉␉␉␉"SMsystemversion"␊ |
42 | #define kSMBSystemInformationSerialNumberKey␉␉"SMserial"␊ |
43 | #define kSMBSystemInformationFamilyKey␉␉␉␉"SMfamily"␊ |
44 | ␊ |
45 | /* Base Board */␊ |
46 | #define kSMBBaseBoardManufacturerKey␉␉␉␉"SMboardmanufacturer"␊ |
47 | #define kSMBBaseBoardProductKey␉␉␉␉␉␉"SMboardproduct"␊ |
48 | ␊ |
49 | /* Processor Information */␊ |
50 | #define kSMBProcessorInformationExternalClockKey␉"SMexternalclock"␊ |
51 | #define kSMBProcessorInformationMaximumClockKey␉␉"SMmaximalclock"␊ |
52 | ␊ |
53 | /* Memory Device */␊ |
54 | #define kSMBMemoryDeviceDeviceLocatorKey␉␉␉"SMmemdevloc"␊ |
55 | #define kSMBMemoryDeviceBankLocatorKey␉␉␉␉"SMmembankloc"␊ |
56 | #define kSMBMemoryDeviceMemoryTypeKey␉␉␉␉"SMmemtype"␊ |
57 | #define kSMBMemoryDeviceMemorySpeedKey␉␉␉␉"SMmemspeed"␊ |
58 | #define kSMBMemoryDeviceManufacturerKey␉␉␉␉"SMmemmanufacturer"␊ |
59 | #define kSMBMemoryDeviceSerialNumberKey␉␉␉␉"SMmemserial"␊ |
60 | #define kSMBMemoryDevicePartNumberKey␉␉␉␉"SMmempart"␊ |
61 | ␊ |
62 | /* Apple Specific */␊ |
63 | #define kSMBOemProcessorTypeKey␉␉␉␉␉␉"SMcputype"␊ |
64 | #define kSMBOemProcessorBusSpeedKey␉␉␉␉␉"SMbusspeed"␊ |
65 | ␊ |
66 | //-------------------------------------------------------------------------------------------------------------------------␊ |
67 | // Default SMBIOS Data␊ |
68 | //-------------------------------------------------------------------------------------------------------------------------␊ |
69 | /* Rewrite: use a struct */␊ |
70 | ␊ |
71 | #define kDefaultVendorManufacturer␉␉␉␉␉"Apple Inc."␊ |
72 | #define kDefaultBIOSReleaseDate␉␉␉␉␉␉"11/06/2009"␊ |
73 | #define kDefaultSerialNumber␉␉␉␉␉␉"SOMESRLNMBR"␊ |
74 | #define kDefaultBoardProduct␉␉␉␉␉␉"Mac-F4208DC8"␊ |
75 | #define kDefaultSystemVersion␉␉␉␉␉␉"1.0"␊ |
76 | ␊ |
77 | // defaults for a Mac mini ␊ |
78 | #define kDefaultMacminiFamily␉␉␉␉␉␉"Macmini"␊ |
79 | #define kDefaultMacmini␉␉␉␉␉␉␉␉"Macmini2,1"␊ |
80 | #define kDefaultMacminiBIOSVersion␉␉␉␉␉" MM21.88Z.009A.B00.0903051113"␊ |
81 | ␊ |
82 | // defaults for a MacBook␊ |
83 | #define kDefaultMacBookFamily␉␉␉␉␉␉"MacBook"␊ |
84 | #define kDefaultMacBook␉␉␉␉␉␉␉␉"MacBook4,1"␊ |
85 | #define kDefaultMacBookBIOSVersion␉␉␉␉␉" MB41.88Z.0073.B00.0903051113"␊ |
86 | ␊ |
87 | // defaults for a MacBook Pro␊ |
88 | #define kDefaultMacBookProFamily␉␉␉␉␉"MacBookPro"␊ |
89 | #define kDefaultMacBookPro␉␉␉␉␉␉␉"MacBookPro4,1"␊ |
90 | #define kDefaultMacBookProBIOSVersion␉␉␉␉" MBP41.88Z.0073.B00.0903051113"␊ |
91 | ␊ |
92 | // defaults for an iMac␊ |
93 | #define kDefaultiMacFamily␉␉␉␉␉␉␉"iMac"␊ |
94 | #define kDefaultiMac␉␉␉␉␉␉␉␉"iMac8,1"␊ |
95 | #define kDefaultiMacBIOSVersion␉␉␉␉␉␉" IM81.88Z.00C1.B00.0903051113"␊ |
96 | // defaults for an iMac11,1 core i3/i5/i7␊ |
97 | #define kDefaultiMacNehalem␉␉␉␉␉␉␉"iMac11,1"␊ |
98 | #define kDefaultiMacNehalemBIOSVersion␉␉␉␉" IM111.88Z.0034.B00.0903051113"␊ |
99 | // defaults for an iMac12,1␊ |
100 | #define kDefaultiMacSandy␉␉␉␉␉␉␉"iMac12,1"␊ |
101 | #define kDefaultiMacSandyBIOSVersion␉␉␉␉" IM121.88Z.0047.B00.1102091756"␊ |
102 | // defaults for a Mac Pro␊ |
103 | #define kDefaultMacProFamily␉␉␉␉␉␉"MacPro"␊ |
104 | #define kDefaultMacPro␉␉␉␉␉␉␉␉"MacPro3,1"␊ |
105 | #define kDefaultMacProBIOSVersion␉␉␉␉␉" MP31.88Z.006C.B05.0903051113"␊ |
106 | // defaults for a Mac Pro 4,1 core i7/Xeon␊ |
107 | #define kDefaultMacProNehalem␉␉␉␉␉␉"MacPro4,1"␊ |
108 | #define kDefaultMacProNehalemBIOSVersion␉␉␉" MP41.88Z.0081.B04.0903051113"␊ |
109 | // defaults for a Mac Pro 5,1 core i7/Xeon␊ |
110 | #define kDefaultMacProWestmere␉␉␉␉␉␉"MacPro5,1"␊ |
111 | #define kDefaultMacProWestmereBIOSVersion␉␉␉" MP51.88Z.007F.B00.1008031144"␊ |
112 | #define kDefaulMacProWestmereBIOSReleaseDate␉␉"08/03/10"␊ |
113 | // defaults for a Xserve␊ |
114 | #define kDefaultXserve␉␉␉␉␉␉␉␉"Xserve2,1"␊ |
115 | #define kDefaultXserveBIOSVersion␉␉␉␉␉" XS21.88Z.006C.B06.0804011317"␊ |
116 | #define kDefaulXserveBIOSReleaseDate␉␉␉␉"04/01/2008"␊ |
117 | #define kDefaultXserveFamily␉␉␉␉␉␉"Xserve"␊ |
118 | //-------------------------------------------------------------------------------------------------------------------------␊ |
119 | ␊ |
120 | ␊ |
121 | #define getFieldOffset(struct, field)␉((uint8_t)(uint32_t)&(((struct *)0)->field))␊ |
122 | ␊ |
123 | typedef struct {␊ |
124 | ␉SMBStructHeader *orig;␊ |
125 | ␉SMBStructHeader *new;␊ |
126 | } SMBStructPtrs;␊ |
127 | ␊ |
128 | struct {␊ |
129 | ␉char *vendor;␊ |
130 | ␉char *version;␊ |
131 | ␉char *releaseDate;␊ |
132 | } defaultBIOSInfo;␊ |
133 | ␊ |
134 | struct {␊ |
135 | ␉char *manufacturer;␊ |
136 | ␉char *productName;␊ |
137 | ␉char *version;␊ |
138 | ␉char *serialNumber;␊ |
139 | ␉char *family;␊ |
140 | } defaultSystemInfo;␊ |
141 | ␊ |
142 | struct {␊ |
143 | ␉char *manufacturer;␊ |
144 | ␉char *product;␊ |
145 | } defaultBaseBoard;␊ |
146 | ␊ |
147 | ␊ |
148 | typedef struct {␊ |
149 | ␉uint8_t␉␉␉type;␊ |
150 | ␉SMBValueType␉valueType;␊ |
151 | ␉uint8_t␉␉␉fieldOffset;␊ |
152 | ␉char␉␉␉*keyString;␊ |
153 | ␉bool␉␉␉(*getSMBValue)(returnType *);␊ |
154 | ␉char␉␉␉**defaultValue;␊ |
155 | } SMBValueSetter;␊ |
156 | ␊ |
157 | SMBValueSetter SMBSetters[] = ␊ |
158 | { ␊ |
159 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
160 | ␉// BIOSInformation␊ |
161 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
162 | ␉{kSMBTypeBIOSInformation,␉kSMBString,␉getFieldOffset(SMBBIOSInformation, vendor),␉␉␉kSMBBIOSInformationVendorKey,␉␉␊ |
163 | ␉␉NULL,␉&defaultBIOSInfo.vendor␉␉␉},␊ |
164 | ␊ |
165 | ␉{kSMBTypeBIOSInformation,␉kSMBString,␉getFieldOffset(SMBBIOSInformation, version),␉␉kSMBBIOSInformationVersionKey,␉␉␊ |
166 | ␉␉NULL,␉&defaultBIOSInfo.version␉␉},␊ |
167 | ␊ |
168 | ␉{kSMBTypeBIOSInformation,␉kSMBString,␉getFieldOffset(SMBBIOSInformation, releaseDate),␉kSMBBIOSInformationReleaseDateKey,␉␊ |
169 | ␉␉NULL,␉&defaultBIOSInfo.releaseDate␉},␊ |
170 | ␊ |
171 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
172 | ␉// SystemInformation␊ |
173 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
174 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, manufacturer),␉kSMBSystemInformationManufacturerKey,␉␊ |
175 | ␉␉NULL,␉&defaultSystemInfo.manufacturer␉},␊ |
176 | ␊ |
177 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, productName),␉kSMBSystemInformationProductNameKey,␉␊ |
178 | ␉␉NULL,␉&defaultSystemInfo.productName␉},␊ |
179 | ␊ |
180 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, version),␉␉kSMBSystemInformationVersionKey,␉␉␊ |
181 | ␉␉NULL,␉&defaultSystemInfo.version␉␉},␊ |
182 | ␊ |
183 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, serialNumber),␉kSMBSystemInformationSerialNumberKey,␉␊ |
184 | ␉␉NULL,␉&defaultSystemInfo.serialNumber␉},␊ |
185 | ␊ |
186 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, skuNumber),␉NULL,␉␉␉␉␉␉␉␉␉␊ |
187 | ␉␉NULL,␉NULL␉␉␉␉␉␉␉},␊ |
188 | ␊ |
189 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, family),␉␉kSMBSystemInformationFamilyKey,␉␉␉␊ |
190 | ␉␉NULL,␉&defaultSystemInfo.family␉␉},␊ |
191 | ␊ |
192 | ␊ |
193 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
194 | ␉// BaseBoard␊ |
195 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
196 | ␉{kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, manufacturer),␉␉␉kSMBBaseBoardManufacturerKey,␉␊ |
197 | ␉␉NULL,␉&defaultBaseBoard.manufacturer␉},␊ |
198 | ␊ |
199 | ␉{kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, product),␉␉␉␉kSMBBaseBoardProductKey,␉␉␊ |
200 | ␉␉NULL,␉&defaultBaseBoard.product␉␉},␊ |
201 | ␊ |
202 | {kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, version),␉␉␉␉NULL,␉NULL,␉NULL},␊ |
203 | ␊ |
204 | {kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, serialNumber),␉␉␉NULL,␉NULL,␉NULL},␊ |
205 | ␊ |
206 | {kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, assetTagNumber),␉␉NULL,␉NULL,␉NULL},␊ |
207 | ␊ |
208 | {kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, locationInChassis),␉NULL,␉NULL,␉NULL},␊ |
209 | ␊ |
210 | ␊ |
211 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
212 | ␉// ProcessorInformation␊ |
213 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
214 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, socketDesignation),␉NULL,␉NULL,␉NULL},␊ |
215 | ␊ |
216 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, manufacturer),␉␉NULL,␉NULL,␉NULL},␊ |
217 | ␊ |
218 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, processorVersion),␉NULL,␉NULL,␉NULL},␊ |
219 | ␊ |
220 | ␉{kSMBTypeProcessorInformation,␉kSMBWord,␉getFieldOffset(SMBProcessorInformation, externalClock),␉␉kSMBProcessorInformationExternalClockKey,␉␊ |
221 | ␉␉getProcessorInformationExternalClock,␉NULL},␊ |
222 | ␊ |
223 | ␉{kSMBTypeProcessorInformation,␉kSMBWord,␉getFieldOffset(SMBProcessorInformation, maximumClock),␉␉kSMBProcessorInformationMaximumClockKey,␉␊ |
224 | ␉␉getProcessorInformationMaximumClock,␉NULL},␊ |
225 | ␊ |
226 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, serialNumber),␉␉NULL,␉NULL,␉NULL},␊ |
227 | ␊ |
228 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, assetTag),␉␉␉NULL,␉NULL,␉NULL},␊ |
229 | ␊ |
230 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, partNumber),␉␉NULL,␉NULL,␉NULL},␊ |
231 | ␊ |
232 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
233 | ␉// Memory Device␊ |
234 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
235 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, deviceLocator),␉kSMBMemoryDeviceDeviceLocatorKey,␉␊ |
236 | ␉␉NULL,␉␉␉␉␉␉␉NULL},␊ |
237 | ␊ |
238 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, bankLocator),␉kSMBMemoryDeviceBankLocatorKey,␉␉␊ |
239 | ␉␉NULL,␉␉␉␉␉␉␉NULL},␊ |
240 | ␊ |
241 | ␉{kSMBTypeMemoryDevice,␉kSMBByte,␉getFieldOffset(SMBMemoryDevice, memoryType),␉kSMBMemoryDeviceMemoryTypeKey,␉␉␊ |
242 | ␉␉getSMBMemoryDeviceMemoryType,␉NULL},␊ |
243 | ␊ |
244 | ␉{kSMBTypeMemoryDevice,␉kSMBWord,␉getFieldOffset(SMBMemoryDevice, memorySpeed),␉kSMBMemoryDeviceMemorySpeedKey,␉␉␊ |
245 | ␉␉getSMBMemoryDeviceMemorySpeed,␉NULL},␊ |
246 | ␊ |
247 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, manufacturer),␉kSMBMemoryDeviceManufacturerKey,␉␊ |
248 | ␉␉getSMBMemoryDeviceManufacturer,␉NULL},␊ |
249 | ␊ |
250 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, serialNumber),␉kSMBMemoryDeviceSerialNumberKey,␉␊ |
251 | ␉␉getSMBMemoryDeviceSerialNumber,␉NULL},␊ |
252 | ␊ |
253 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, assetTag),␉␉NULL,␉NULL,␉NULL},␊ |
254 | ␊ |
255 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, partNumber),␉kSMBMemoryDevicePartNumberKey,␉␉␊ |
256 | ␉␉getSMBMemoryDevicePartNumber,␉NULL},␊ |
257 | ␊ |
258 | ␊ |
259 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
260 | ␉// Apple Specific␊ |
261 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
262 | ␉{kSMBTypeOemProcessorType,␉␉kSMBWord,␉getFieldOffset(SMBOemProcessorType, ProcessorType),␉␉␉kSMBOemProcessorTypeKey,␉␉␊ |
263 | ␉␉getSMBOemProcessorType,␉␉␉NULL},␊ |
264 | ␊ |
265 | ␉{kSMBTypeOemProcessorBusSpeed,␉kSMBWord,␉getFieldOffset(SMBOemProcessorBusSpeed, ProcessorBusSpeed),␉kSMBOemProcessorBusSpeedKey,␉␊ |
266 | ␉␉getSMBOemProcessorBusSpeed,␉␉NULL}␊ |
267 | };␊ |
268 | ␊ |
269 | int numOfSetters = sizeof(SMBSetters) / sizeof(SMBValueSetter);␊ |
270 | ␊ |
271 | SMBEntryPoint *neweps␉= 0;␊ |
272 | ␊ |
273 | static uint8_t stringIndex;␉// increament when a string is added and set the field value accordingly␊ |
274 | static uint8_t stringsSize;␉// add string size␊ |
275 | ␊ |
276 | static SMBWord tableLength␉␉= 0;␊ |
277 | static SMBWord handle␉␉␉= 0;␊ |
278 | static SMBWord maxStructSize␉= 0;␊ |
279 | static SMBWord structureCount␉= 0;␊ |
280 | ␊ |
281 | static void setDefaultSMBData(void);␊ |
282 | static bool getSMBValueForKey(SMBStructHeader *structHeader, const char *keyString, const char **string, returnType *value);␊ |
283 | static void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field);␊ |
284 | static bool setSMBValue(SMBStructPtrs *structPtr, int idx, returnType *value);␊ |
285 | static void addSMBFirmwareVolume(SMBStructPtrs *structPtr);␊ |
286 | static void addSMBMemorySPD(SMBStructPtrs *structPtr);␊ |
287 | static void addSMBOemProcessorType(SMBStructPtrs *structPtr);␊ |
288 | static void addSMBOemProcessorBusSpeed(SMBStructPtrs *structPtr);␊ |
289 | static void addSMBEndOfTable(SMBStructPtrs *structPtr);␊ |
290 | static void setSMBStruct(SMBStructPtrs *structPtr);␊ |
291 | static void setupNewSMBIOSTable(SMBEntryPoint *eps, SMBStructPtrs *structPtr);␊ |
292 | ␊ |
293 | ␊ |
294 | char *getDefaultSMBproductName(void)␊ |
295 | {␊ |
296 | ␉setDefaultSMBData();␊ |
297 | ␉return defaultSystemInfo.productName;␊ |
298 | }␊ |
299 | ␊ |
300 | char *getDefaultSMBBoardProduct(void)␊ |
301 | {␊ |
302 | ␉setDefaultSMBData();␊ |
303 | ␉return defaultBaseBoard.product;␊ |
304 | }␊ |
305 | ␊ |
306 | /* Rewrite this function */␊ |
307 | static void setDefaultSMBData(void)␊ |
308 | {␊ |
309 | ␉static bool setDefSMB = true;␊ |
310 | ␉␊ |
311 | ␉if (setDefSMB) {␉␉␊ |
312 | ␉␉␊ |
313 | ␉␉if (Platform->CPU.isServer == true) {␊ |
314 | ␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultXserveBIOSVersion;␊ |
315 | ␉␉␉defaultSystemInfo.productName␉= kDefaultXserve;␉␉␉␊ |
316 | ␉␉␉defaultBIOSInfo.releaseDate␉␉= kDefaulXserveBIOSReleaseDate;␊ |
317 | ␉␉␉defaultSystemInfo.family␉␉= kDefaultXserveFamily;␊ |
318 | ␉␉}␊ |
319 | ␉␉else if (Platform->CPU.isMobile == true)␊ |
320 | ␉␉{␊ |
321 | ␉␉␉if (Platform->CPU.NoCores > 1)␊ |
322 | ␉␉␉{␊ |
323 | ␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacBookProBIOSVersion;␊ |
324 | ␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacBookPro;␊ |
325 | ␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacBookProFamily;␊ |
326 | ␉␉␉}␊ |
327 | ␉␉␉else␊ |
328 | ␉␉␉{␊ |
329 | ␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacBookBIOSVersion;␊ |
330 | ␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacBook;␊ |
331 | ␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacBookFamily;␊ |
332 | ␉␉␉}␊ |
333 | ␉␉}␊ |
334 | ␉␉else␊ |
335 | ␉␉{␊ |
336 | ␉␉␉switch (Platform->CPU.NoCores) ␊ |
337 | ␉␉␉{␊ |
338 | ␉␉␉␉case 1: ␊ |
339 | ␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacminiBIOSVersion;␊ |
340 | ␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacmini;␊ |
341 | ␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacminiFamily;␊ |
342 | ␉␉␉␉␉break;␊ |
343 | ␉␉␉␉␉␊ |
344 | ␉␉␉␉case 2:␊ |
345 | ␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultiMacBIOSVersion;␊ |
346 | ␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultiMac;␊ |
347 | ␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultiMacFamily;␊ |
348 | ␉␉␉␉␉break;␊ |
349 | ␉␉␉␉default:␊ |
350 | ␉␉␉␉{␊ |
351 | ␉␉␉␉␉switch (Platform->CPU.Family) ␊ |
352 | ␉␉␉␉␉{␊ |
353 | ␉␉␉␉␉␉case 0x06:␊ |
354 | ␉␉␉␉␉␉{␊ |
355 | ␉␉␉␉␉␉␉switch (Platform->CPU.Model)␊ |
356 | ␉␉␉␉␉␉␉{␊ |
357 | ␉␉␉␉␉␉␉␉case CPUID_MODEL_FIELDS:␉␉// Intel Core i5, i7 LGA1156 (45nm)␊ |
358 | ␉␉␉␉␉␉␉␉case CPUID_MODEL_DALES:␉␉// Intel Core i5, i7 LGA1156 (45nm) ???␊ |
359 | ␉␉␉␉␉␉␉␉case CPUID_MODEL_DALES_32NM:␉// Intel Core i3, i5, i7 LGA1156 (32nm) (Clarkdale, Arrandale)␊ |
360 | ␉␉␉␉␉␉␉␉case 0x19:␉␉␉␉␉// Intel Core i5 650 @3.20 Ghz ␊ |
361 | ␉␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultiMacNehalemBIOSVersion;␊ |
362 | ␉␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultiMacNehalem;␊ |
363 | ␉␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultiMacFamily;␊ |
364 | ␉␉␉␉␉␉␉␉␉break;␊ |
365 | ␉␉␉␉␉␉␉␉␉␊ |
366 | ␉␉␉␉␉␉␉␉case CPUID_MODEL_SANDYBRIDGE:␊ |
367 | ␉␉␉␉␉␉␉␉case CPUID_MODEL_JAKETOWN: // Until Apple release a MacPro6,1 ??␊ |
368 | ␉␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultiMacSandyBIOSVersion;␊ |
369 | ␉␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultiMacSandy;␊ |
370 | ␉␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultiMacFamily;␊ |
371 | ␉␉␉␉␉␉␉␉␉break;␊ |
372 | ␉␉␉␉␉␉␉␉␉␊ |
373 | ␉␉␉␉␉␉␉␉case CPUID_MODEL_NEHALEM: ␊ |
374 | ␉␉␉␉␉␉␉␉case CPUID_MODEL_NEHALEM_EX:␊ |
375 | ␉␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacProNehalemBIOSVersion;␊ |
376 | ␉␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacProNehalem;␊ |
377 | ␉␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacProFamily;␊ |
378 | ␉␉␉␉␉␉␉␉␉break;␊ |
379 | ␉␉␉␉␉␉␉␉␉␊ |
380 | ␉␉␉␉␉␉␉␉case CPUID_MODEL_WESTMERE: ␊ |
381 | ␉␉␉␉␉␉␉␉case CPUID_MODEL_WESTMERE_EX:␊ |
382 | ␉␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacProWestmereBIOSVersion;␊ |
383 | ␉␉␉␉␉␉␉␉␉defaultBIOSInfo.releaseDate␉␉= kDefaulMacProWestmereBIOSReleaseDate;␊ |
384 | ␉␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacProWestmere;␊ |
385 | ␉␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacProFamily;␊ |
386 | ␉␉␉␉␉␉␉␉␉break;␊ |
387 | ␉␉␉␉␉␉␉␉␉␊ |
388 | ␉␉␉␉␉␉␉␉default:␊ |
389 | ␉␉␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacProBIOSVersion;␊ |
390 | ␉␉␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacPro;␊ |
391 | ␉␉␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacProFamily;␊ |
392 | ␉␉␉␉␉␉␉␉␉break;␊ |
393 | ␉␉␉␉␉␉␉}␊ |
394 | ␉␉␉␉␉␉␉break;␊ |
395 | ␉␉␉␉␉␉}␊ |
396 | ␉␉␉␉␉␉default:␊ |
397 | ␉␉␉␉␉␉␉defaultBIOSInfo.version␉␉␉= kDefaultMacProBIOSVersion;␊ |
398 | ␉␉␉␉␉␉␉defaultSystemInfo.productName␉= kDefaultMacPro;␊ |
399 | ␉␉␉␉␉␉␉defaultSystemInfo.family␉␉= kDefaultMacProFamily;␊ |
400 | ␉␉␉␉␉␉␉break;␊ |
401 | ␉␉␉␉␉}␊ |
402 | ␉␉␉␉␉break;␊ |
403 | ␉␉␉␉}␊ |
404 | ␉␉␉}␊ |
405 | ␉␉}␊ |
406 | ␉␉␊ |
407 | ␉␉if (!defaultBIOSInfo.vendor) ␊ |
408 | ␉␉defaultBIOSInfo.vendor␉␉␉= kDefaultVendorManufacturer;␊ |
409 | ␉␉if (!defaultBIOSInfo.releaseDate) ␊ |
410 | ␉␉defaultBIOSInfo.releaseDate␉␉= kDefaultBIOSReleaseDate;␊ |
411 | ␉␉␊ |
412 | ␉␉if (!defaultSystemInfo.manufacturer) ␊ |
413 | ␉␉defaultSystemInfo.manufacturer␉= kDefaultVendorManufacturer;␊ |
414 | ␉␉if (!defaultSystemInfo.version) ␊ |
415 | ␉␉defaultSystemInfo.version␉␉= kDefaultSystemVersion;␊ |
416 | ␉␉if (!defaultSystemInfo.serialNumber) ␊ |
417 | ␉␉defaultSystemInfo.serialNumber␉= kDefaultSerialNumber;␊ |
418 | ␉␉␊ |
419 | ␉␉if (!defaultBaseBoard.manufacturer) ␊ |
420 | ␉␉defaultBaseBoard.manufacturer␉= kDefaultVendorManufacturer;␊ |
421 | ␉␉if (!defaultBaseBoard.product) ␊ |
422 | ␉␉defaultBaseBoard.product␉␉= kDefaultBoardProduct;␊ |
423 | ␉␉␊ |
424 | ␉␉setDefSMB = false;␊ |
425 | ␉}␉␊ |
426 | }␊ |
427 | ␊ |
428 | /* Used for SM*_N smbios.plist keys */␊ |
429 | static bool getSMBValueForKey(SMBStructHeader *structHeader, const char *keyString, const char **string, returnType *value)␊ |
430 | {␊ |
431 | ␉static int idx = -1;␊ |
432 | ␉static int current = -1;␊ |
433 | ␉int len;␊ |
434 | ␉char key[24];␊ |
435 | ␊ |
436 | ␉if (current != structHeader->handle)␊ |
437 | ␉{␊ |
438 | ␉␉idx++;␊ |
439 | ␉␉current = structHeader->handle;␊ |
440 | ␉}␊ |
441 | ␊ |
442 | ␉sprintf(key, "%s%d", keyString, idx);␊ |
443 | ␊ |
444 | ␉if (value)␊ |
445 | ␉{␊ |
446 | ␉␉if (getIntForKey(key, (int *)&(value->dword), SMBPlist))␊ |
447 | ␉␉␉return true;␊ |
448 | ␉}␊ |
449 | ␉else␊ |
450 | ␉{␊ |
451 | ␉␉if (getValueForKey(key, string, &len, SMBPlist))␊ |
452 | ␉␉␉return true;␊ |
453 | ␉}␊ |
454 | ␉␊ |
455 | ␉return false;␊ |
456 | }␊ |
457 | ␊ |
458 | char *getSMBStringForField(SMBStructHeader *structHeader, uint8_t field)␊ |
459 | {␊ |
460 | ␉uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length;␊ |
461 | ␊ |
462 | ␉if (!field)␊ |
463 | {␊ |
464 | ␉␉//return (char *)0;␊ |
465 | return NULL;␊ |
466 | }␊ |
467 | ␊ |
468 | ␉for (field--; field != 0 && strlen((char *)stringPtr) > 0; ␊ |
469 | ␉␉field--, stringPtr = (uint8_t *)((uint32_t)stringPtr + strlen((char *)stringPtr) + 1));␊ |
470 | ␊ |
471 | ␉return (char *)stringPtr;␊ |
472 | }␊ |
473 | ␊ |
474 | static void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field)␊ |
475 | {␊ |
476 | ␉int strSize;␊ |
477 | ␊ |
478 | ␉if (!field)␊ |
479 | {␊ |
480 | ␊ |
481 | ␉␉return;␊ |
482 | }␊ |
483 | ␉if (!string)␊ |
484 | ␉{␊ |
485 | ␉␉*field = 0;␊ |
486 | ␉␉return;␊ |
487 | ␉}␊ |
488 | ␉␊ |
489 | ␉strSize = strlen(string);␊ |
490 | ␉␊ |
491 | ␉// remove any spaces found at the end␊ |
492 | while ((strSize != 0) && (string[strSize - 1] == ' '))␊ |
493 | ␉␉strSize--;␊ |
494 | ␉␊ |
495 | ␊ |
496 | ␉if (strSize == 0)␊ |
497 | ␉{␊ |
498 | ␉␉*field = 0;␊ |
499 | ␉␉return;␊ |
500 | ␉}␊ |
501 | ␉␊ |
502 | ␉memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize);␊ |
503 | ␊ |
504 | ␉*field = stringIndex;␊ |
505 | ␉␊ |
506 | ␉stringIndex++;␊ |
507 | ␉stringsSize += strSize + 1;␊ |
508 | }␊ |
509 | ␊ |
510 | static bool setSMBValue(SMBStructPtrs *structPtr, int idx, returnType *value)␊ |
511 | {␊ |
512 | ␉const char *string = 0;␊ |
513 | ␉int len;␊ |
514 | ␉bool parsed;␊ |
515 | ␉int val;␊ |
516 | ␊ |
517 | ␉if (numOfSetters <= idx)␊ |
518 | ␉␉return false;␊ |
519 | ␉␊ |
520 | ␉switch (SMBSetters[idx].valueType)␊ |
521 | ␉{␊ |
522 | ␉␉case kSMBString:␊ |
523 | ␉␉␉if (SMBSetters[idx].keyString)␊ |
524 | ␉␉␉{␊ |
525 | ␉␉␉␉if (getValueForKey(SMBSetters[idx].keyString, &string, &len, SMBPlist))␊ |
526 | ␉␉␉␉␉break;␊ |
527 | ␉␉␉␉else␊ |
528 | ␉␉␉␉␉if (structPtr->orig->type == kSMBTypeMemoryDevice)␉// MemoryDevice only␊ |
529 | ␉␉␉␉␉␉if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, &string, NULL))␊ |
530 | ␉␉␉␉␉␉␉break;␊ |
531 | ␉␉␉}␊ |
532 | ␉␉␉if (SMBSetters[idx].getSMBValue)␊ |
533 | ␉␉␉␉if (SMBSetters[idx].getSMBValue((returnType *)&string))␊ |
534 | ␉␉␉␉␉break;␊ |
535 | ␉␉␉if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue))␊ |
536 | ␉␉␉{␊ |
537 | ␉␉␉␉string = *(SMBSetters[idx].defaultValue);␊ |
538 | ␉␉␉␉break;␊ |
539 | ␉␉␉}␊ |
540 | ␉␉␉string = getSMBStringForField(structPtr->orig, *(uint8_t *)value);␊ |
541 | ␉␉␉break;␊ |
542 | ␉␉␉␊ |
543 | ␉␉case kSMBByte:␊ |
544 | ␉␉case kSMBWord:␊ |
545 | ␉␉case kSMBDWord:␊ |
546 | ␉␉␉//case kSMBQWord:␊ |
547 | ␉␉␉/*if (SMBSetters[idx].keyString)␊ |
548 | {␊ |
549 | if (getIntForKey(SMBSetters[idx].keyString, (int *)&(value->dword), SMBPlist))␊ |
550 | return true;␊ |
551 | else␊ |
552 | if (structPtr->orig->type == kSMBTypeMemoryDevice)␉// MemoryDevice only␊ |
553 | if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, value))␊ |
554 | return true;␊ |
555 | }*/␊ |
556 | if (SMBSetters[idx].keyString)␊ |
557 | ␉␉␉{␊ |
558 | ␉␉␉␉parsed = getIntForKey(SMBSetters[idx].keyString, &val, SMBPlist);␊ |
559 | ␉␉␉␉if (!parsed)␊ |
560 | ␉␉␉␉␉if (structPtr->orig->type == kSMBTypeMemoryDevice)␉// MemoryDevice only␊ |
561 | ␉␉␉␉␉␉parsed = getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, (returnType *)&val);␊ |
562 | ␉␉␉␉if (parsed)␊ |
563 | ␉␉␉␉{␊ |
564 | ␉␉␉␉␉switch (SMBSetters[idx].valueType)␊ |
565 | ␉␉␉␉␉{␊ |
566 | ␉␉␉␉␉␉case kSMBByte:␊ |
567 | ␉␉␉␉␉␉␉value->byte = (uint8_t)val;␊ |
568 | ␉␉␉␉␉␉␉break;␊ |
569 | ␉␉␉␉␉␉case kSMBWord:␊ |
570 | ␉␉␉␉␉␉␉value->word = (uint16_t)val;␊ |
571 | ␉␉␉␉␉␉␉break;␊ |
572 | ␉␉␉␉␉␉case kSMBDWord:␊ |
573 | ␉␉␉␉␉␉default:␊ |
574 | ␉␉␉␉␉␉␉value->dword = (uint32_t)val;␊ |
575 | ␉␉␉␉␉␉␉break;␊ |
576 | ␉␉␉␉␉}␊ |
577 | ␉␉␉␉␉return true;␊ |
578 | ␉␉␉␉}␊ |
579 | }␊ |
580 | ␉␉␉if (SMBSetters[idx].getSMBValue)␊ |
581 | ␉␉␉␉if (SMBSetters[idx].getSMBValue(value))␊ |
582 | ␉␉␉␉␉return true;␊ |
583 | #if 0␊ |
584 | ␉␉␉if (*(SMBSetters[idx].defaultValue))␊ |
585 | ␉␉␉{␊ |
586 | ␉␉␉␉value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue);␊ |
587 | ␉␉␉␉return true;␊ |
588 | ␉␉␉}␊ |
589 | #endif␊ |
590 | ␉␉␉break;␊ |
591 | ␉}␊ |
592 | ␉␊ |
593 | ␉if (SMBSetters[idx].valueType == kSMBString && string)␊ |
594 | ␉␉setSMBStringForField(structPtr->new, string, &value->byte);␊ |
595 | ␊ |
596 | ␉return true;␊ |
597 | }␊ |
598 | //-------------------------------------------------------------------------------------------------------------------------␊ |
599 | // Apple Specific␊ |
600 | //-------------------------------------------------------------------------------------------------------------------------␊ |
601 | static void addSMBFirmwareVolume(SMBStructPtrs *structPtr)␊ |
602 | {␊ |
603 | ␉return;␊ |
604 | }␊ |
605 | ␊ |
606 | static void addSMBMemorySPD(SMBStructPtrs *structPtr)␊ |
607 | {␊ |
608 | ␉/* SPD data from Platform->RAM.spd */␊ |
609 | ␉return;␊ |
610 | }␊ |
611 | ␊ |
612 | static void addSMBOemProcessorType(SMBStructPtrs *structPtr)␊ |
613 | {␊ |
614 | ␉SMBOemProcessorType *p = (SMBOemProcessorType *)structPtr->new;␊ |
615 | ␉␊ |
616 | ␉p->header.type␉␉= kSMBTypeOemProcessorType;␊ |
617 | ␉p->header.length␉= sizeof(SMBOemProcessorType);␊ |
618 | ␉p->header.handle␉= handle++;␊ |
619 | ␊ |
620 | ␉setSMBValue(structPtr, numOfSetters - 2 , (returnType *)&(p->ProcessorType));␊ |
621 | ␊ |
622 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorType) + 2);␊ |
623 | ␉tableLength += sizeof(SMBOemProcessorType) + 2;␊ |
624 | ␉structureCount++;␊ |
625 | }␊ |
626 | ␊ |
627 | static void addSMBOemProcessorBusSpeed(SMBStructPtrs *structPtr)␊ |
628 | {␊ |
629 | ␉SMBOemProcessorBusSpeed *p = (SMBOemProcessorBusSpeed *)structPtr->new;␊ |
630 | ␊ |
631 | ␉switch (Platform->CPU.Family) ␊ |
632 | ␉{␊ |
633 | ␉␉case 0x06:␊ |
634 | ␉␉{␊ |
635 | ␉␉␉switch (Platform->CPU.Model)␊ |
636 | ␉␉␉{␊ |
637 | ␉␉␉␉case 0x19:␉␉␉␉␉// Intel Core i5 650 @3.20 Ghz␊ |
638 | ␉␉␉␉case CPUID_MODEL_FIELDS:␉␉// Intel Core i5, i7 LGA1156 (45nm)␊ |
639 | ␉␉␉␉case CPUID_MODEL_DALES:␉␉// Intel Core i5, i7 LGA1156 (45nm) ???␊ |
640 | ␉␉␉␉case CPUID_MODEL_DALES_32NM:␉// Intel Core i3, i5, i7 LGA1156 (32nm)␊ |
641 | ␉␉␉␉case CPUID_MODEL_NEHALEM:␉␉// Intel Core i7 LGA1366 (45nm)␊ |
642 | ␉␉␉␉case CPUID_MODEL_NEHALEM_EX:␉// Intel Core i7 LGA1366 (45nm) 6 Core ???␊ |
643 | ␉␉␉␉case CPUID_MODEL_WESTMERE:␉// Intel Core i7 LGA1366 (32nm) 6 Core␊ |
644 | ␉␉␉␉case CPUID_MODEL_WESTMERE_EX:␉// Intel Core i7 LGA1366 (45nm) 6 Core ???␊ |
645 | ␉␉␉␉case CPUID_MODEL_SANDYBRIDGE:␊ |
646 | ␉␉␉␉case CPUID_MODEL_JAKETOWN: ␊ |
647 | ␉␉␉␉␉break;␊ |
648 | ␉␉␉␉␉␊ |
649 | ␉␉␉␉default:␊ |
650 | ␉␉␉␉␉return;␊ |
651 | ␉␉␉}␊ |
652 | ␉␉}␊ |
653 | ␉}␊ |
654 | ␉␊ |
655 | ␉p->header.type␉␉= kSMBTypeOemProcessorBusSpeed;␊ |
656 | ␉p->header.length␉= sizeof(SMBOemProcessorBusSpeed);␊ |
657 | ␉p->header.handle␉= handle++;␊ |
658 | ␊ |
659 | ␉setSMBValue(structPtr, numOfSetters -1, (returnType *)&(p->ProcessorBusSpeed));␊ |
660 | ␊ |
661 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorBusSpeed) + 2);␊ |
662 | ␉tableLength += sizeof(SMBOemProcessorBusSpeed) + 2;␊ |
663 | ␉structureCount++;␊ |
664 | }␊ |
665 | ␊ |
666 | //-------------------------------------------------------------------------------------------------------------------------␊ |
667 | // EndOfTable␊ |
668 | //-------------------------------------------------------------------------------------------------------------------------␊ |
669 | static void addSMBEndOfTable(SMBStructPtrs *structPtr)␊ |
670 | {␊ |
671 | ␉structPtr->new->type␉= kSMBTypeEndOfTable;␊ |
672 | ␉structPtr->new->length␉= sizeof(SMBStructHeader);␊ |
673 | ␉structPtr->new->handle␉= handle++;␊ |
674 | ␊ |
675 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBStructHeader) + 2);␊ |
676 | ␉tableLength += sizeof(SMBStructHeader) + 2;␊ |
677 | ␉structureCount++;␊ |
678 | }␊ |
679 | ␊ |
680 | static void setSMBStruct(SMBStructPtrs *structPtr)␊ |
681 | {␊ |
682 | ␉bool setterFound = false;␊ |
683 | ␊ |
684 | ␉uint8_t *ptr;␊ |
685 | ␉SMBWord structSize;␊ |
686 | ␉int i;␊ |
687 | ␉␉␊ |
688 | ␉stringIndex = 1;␊ |
689 | ␉stringsSize = 0;␊ |
690 | ␊ |
691 | ␉if (handle < structPtr->orig->handle)␊ |
692 | ␉␉handle = structPtr->orig->handle;␊ |
693 | ␊ |
694 | ␉memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);␊ |
695 | ␊ |
696 | ␉for (i = 0; i < numOfSetters; i++)␊ |
697 | ␉␉/*if (structPtr->orig->type == SMBSetters[i].type)␊ |
698 | ␉␉{␊ |
699 | ␉␉␉if (SMBSetters[i].fieldOffset > structPtr->orig->length)␊ |
700 | ␉␉␉␉continue;*/␊ |
701 | if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structPtr->orig->length))␊ |
702 | {␊ |
703 | ␉␉␉setterFound = true;␊ |
704 | ␉␉␉setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset));␊ |
705 | ␉␉}␊ |
706 | ␊ |
707 | ␉if (setterFound)␊ |
708 | ␉{␊ |
709 | ␉␉ptr = (uint8_t *)structPtr->new + structPtr->orig->length;␊ |
710 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
711 | ␊ |
712 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
713 | ␉␉␉ptr += 2;␊ |
714 | ␊ |
715 | ␉␉structSize = ptr - (uint8_t *)structPtr->new;␊ |
716 | ␉}␊ |
717 | ␉else␊ |
718 | ␉{␊ |
719 | ␉␉ptr = (uint8_t *)structPtr->orig + structPtr->orig->length;␊ |
720 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
721 | ␊ |
722 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
723 | ␉␉␉ptr += 2;␊ |
724 | ␉␉␊ |
725 | ␉␉structSize = ptr - (uint8_t *)structPtr->orig;␊ |
726 | ␉␉memcpy((void *)structPtr->new, structPtr->orig, structSize);␊ |
727 | ␉}␊ |
728 | ␊ |
729 | ␉structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + structSize);␊ |
730 | ␊ |
731 | ␉tableLength += structSize;␊ |
732 | ␊ |
733 | ␉if (structSize > maxStructSize)␊ |
734 | ␉␉maxStructSize = structSize;␊ |
735 | ␊ |
736 | ␉structureCount++;␊ |
737 | ␊ |
738 | }␊ |
739 | ␊ |
740 | static void setupNewSMBIOSTable(SMBEntryPoint *eps, SMBStructPtrs *structPtr)␊ |
741 | {␊ |
742 | ␉uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress;␊ |
743 | ␉structPtr->orig = (SMBStructHeader *)ptr;␊ |
744 | ␊ |
745 | ␉for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));)␊ |
746 | ␉{␊ |
747 | ␉␉switch (structPtr->orig->type)␊ |
748 | ␉␉{␊ |
749 | ␉␉␉/* Skip all Apple Specific Structures */␊ |
750 | ␉␉␉case kSMBTypeFirmwareVolume:␊ |
751 | ␉␉␉case kSMBTypeMemorySPD:␊ |
752 | ␉␉␉case kSMBTypeOemProcessorType:␊ |
753 | ␉␉␉case kSMBTypeOemProcessorBusSpeed:␊ |
754 | ␉␉␉␉/* And this one too, to be added at the end */␊ |
755 | ␉␉␉case kSMBTypeEndOfTable:␊ |
756 | ␉␉␉␉break;␊ |
757 | ␊ |
758 | ␉␉␉default:␊ |
759 | {␊ |
760 | ␉␉␉␉/* Add */␊ |
761 | ␉␉␉␉setSMBStruct(structPtr);␊ |
762 | ␉␉␉␉break;␊ |
763 | }␊ |
764 | ␉␉}␊ |
765 | ␊ |
766 | ␉␉ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length);␊ |
767 | ␊ |
768 | ␉␉for (; ((uint16_t *)ptr)[0] != 0; ptr++);␊ |
769 | ␊ |
770 | ␉␉if (((uint16_t *)ptr)[0] == 0)␊ |
771 | ␉␉␉ptr += 2;␊ |
772 | ␊ |
773 | ␉␉structPtr->orig = (SMBStructHeader *)ptr;␊ |
774 | ␉}␊ |
775 | ␊ |
776 | ␊ |
777 | ␉addSMBFirmwareVolume(structPtr);␊ |
778 | ␊ |
779 | ␉addSMBMemorySPD(structPtr);␊ |
780 | ␊ |
781 | ␉addSMBOemProcessorType(structPtr);␊ |
782 | ␊ |
783 | ␉addSMBOemProcessorBusSpeed(structPtr);␊ |
784 | ␊ |
785 | ␉addSMBEndOfTable(structPtr);␊ |
786 | ␊ |
787 | ␊ |
788 | }␊ |
789 | ␊ |
790 | SMBEntryPoint * setupSMBIOSTable(SMBEntryPoint *origeps)␊ |
791 | {␊ |
792 | ␉SMBStructPtrs *structPtr;␊ |
793 | ␉//uint8_t *buffer;␊ |
794 | ␉bool setSMB = true;␊ |
795 | ␊ |
796 | ␉if (!origeps)␊ |
797 | ␉␉return NULL;␊ |
798 | ␊ |
799 | ␉structPtr = (SMBStructPtrs *)malloc(sizeof(SMBStructPtrs));␊ |
800 | ␉if (!structPtr)␊ |
801 | ␉␉return NULL;␊ |
802 | ␉/*␊ |
803 | ␉buffer = malloc(SMB_ALLOC_SIZE);␊ |
804 | ␉if (!buffer)␊ |
805 | ␉␉return NULL;*/␊ |
806 | ␉uint8_t buffer[SMB_ALLOC_SIZE]; // put the buffer in the stack fix some problem with xcode4, but all data seems to be corrupted␊ |
807 | ␊ |
808 | ␉bzero(buffer, SMB_ALLOC_SIZE);␊ |
809 | ␉structPtr->new = (SMBStructHeader *)buffer;␊ |
810 | ␊ |
811 | ␉getBoolForKey(kSMBIOSdefaults, &setSMB, &bootInfo->bootConfig);␊ |
812 | ␉if (setSMB)␊ |
813 | ␉␉setDefaultSMBData();␊ |
814 | ␊ |
815 | ␉setupNewSMBIOSTable(origeps, structPtr);␊ |
816 | ␉␊ |
817 | ␉SMBEntryPoint *neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint));␊ |
818 | ␉if (!neweps)␊ |
819 | ␉␉return NULL;␊ |
820 | ␉bzero(neweps, sizeof(SMBEntryPoint));␊ |
821 | ␊ |
822 | ␉neweps->anchor[0]␉␉␉= '_';␊ |
823 | ␉neweps->anchor[1]␉␉␉= 'S';␊ |
824 | ␉neweps->anchor[2]␉␉␉= 'M';␊ |
825 | ␉neweps->anchor[3]␉␉␉= '_';␊ |
826 | ␉neweps->entryPointLength␉= sizeof(SMBEntryPoint);␊ |
827 | ␉neweps->majorVersion␉␉= 2;␊ |
828 | ␉neweps->minorVersion␉␉= 4;␊ |
829 | ␉neweps->maxStructureSize␉= maxStructSize;␊ |
830 | ␉neweps->entryPointRevision␉= 0;␊ |
831 | ␊ |
832 | ␉neweps->dmi.anchor[0]␉␉= '_';␊ |
833 | ␉neweps->dmi.anchor[1]␉␉= 'D';␊ |
834 | ␉neweps->dmi.anchor[2]␉␉= 'M';␊ |
835 | ␉neweps->dmi.anchor[3]␉␉= 'I';␊ |
836 | ␉neweps->dmi.anchor[4]␉␉= '_';␊ |
837 | ␉neweps->dmi.tableLength␉␉= tableLength;␊ |
838 | ␉neweps->dmi.tableAddress␉= AllocateKernelMemory(tableLength);␊ |
839 | ␉neweps->dmi.structureCount␉= structureCount;␊ |
840 | ␉neweps->dmi.bcdRevision␉␉= 0x24;␊ |
841 | ␊ |
842 | ␉if (!neweps->dmi.tableAddress)␊ |
843 | ␉␉return NULL;␊ |
844 | ␊ |
845 | ␉memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength);␊ |
846 | ␊ |
847 | ␉neweps->dmi.checksum␉␉= 0;␊ |
848 | ␉neweps->dmi.checksum␉␉= 0x100 - checksum8(&neweps->dmi, sizeof(DMIEntryPoint));␊ |
849 | ␊ |
850 | ␉neweps->checksum␉␉␉= 0;␊ |
851 | ␉neweps->checksum␉␉␉= 0x100 - checksum8(neweps, sizeof(SMBEntryPoint));␊ |
852 | ␊ |
853 | ␉//free(buffer);␊ |
854 | ␉decodeSMBIOSTable(neweps);␊ |
855 | ␊ |
856 | return neweps;␊ |
857 | }␊ |
858 | ␊ |
859 | /* Collect any information needed later */␊ |
860 | void readSMBIOSInfo(SMBEntryPoint *eps)␊ |
861 | {␊ |
862 | ␉uint8_t *structPtr = (uint8_t *)eps->dmi.tableAddress;␊ |
863 | ␉SMBStructHeader *structHeader = (SMBStructHeader *)structPtr;␊ |
864 | ␊ |
865 | ␉int dimmnbr = 0;␊ |
866 | ␉Platform->DMI.MaxMemorySlots␉= 0;␊ |
867 | ␉Platform->DMI.CntMemorySlots␉= 0;␊ |
868 | ␉Platform->DMI.MemoryModules␉= 0;␊ |
869 | ␊ |
870 | ␉for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));)␊ |
871 | ␉{␊ |
872 | ␉␉switch (structHeader->type)␊ |
873 | ␉␉{␊ |
874 | ␉␉␉case kSMBTypeSystemInformation:␊ |
875 | ␉␉␉␉Platform->UUID = ((SMBSystemInformation *)structHeader)->uuid;␊ |
876 | ␉␉␉␉break;␊ |
877 | ␊ |
878 | ␉␉␉case kSMBTypePhysicalMemoryArray:␊ |
879 | ␉␉␉␉Platform->DMI.MaxMemorySlots += ((SMBPhysicalMemoryArray *)structHeader)->numMemoryDevices;␊ |
880 | ␉␉␉␉break;␊ |
881 | ␊ |
882 | ␉␉␉case kSMBTypeMemoryDevice:␊ |
883 | ␉␉␉␉Platform->DMI.CntMemorySlots++;␊ |
884 | ␉␉if (((SMBMemoryDevice *)structHeader)->memorySize != 0)␊ |
885 | ␉␉␉␉␉Platform->DMI.MemoryModules++;␊ |
886 | ␉␉if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0)␊ |
887 | ␉␉␉␉␉Platform->RAM.DIMM[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed;␊ |
888 | ␉␉␉␉dimmnbr++;␊ |
889 | ␉␉␉␉break;␊ |
890 | ␉␉␉default:␊ |
891 | ␉␉␉␉break;␊ |
892 | ␉␉}␊ |
893 | ␊ |
894 | ␉␉structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length);␊ |
895 | ␉␉for (; ((uint16_t *)structPtr)[0] != 0; structPtr++);␊ |
896 | ␊ |
897 | ␉␉if (((uint16_t *)structPtr)[0] == 0)␊ |
898 | ␉␉␉structPtr += 2;␊ |
899 | ␊ |
900 | ␉␉structHeader = (SMBStructHeader *)structPtr;␊ |
901 | ␉}␊ |
902 | }␊ |
903 | ␊ |
904 | |