Chameleon

Chameleon Svn Source Tree

Root/branches/Chimera/i386/libsaio/smbios.c

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// Bungo
13#include "convert.h"
14
15#ifndef DEBUG_SMBIOS
16#define DEBUG_SMBIOS 0
17#endif
18
19#if DEBUG_SMBIOS
20#define DBG(x...)printf(x)
21#else
22#define DBG(x...)msglog(x)
23#endif
24
25#define SMBPlist&bootInfo->smbiosConfig
26/* ASSUMPTION: 16KB should be enough for the whole thing */
27#define SMB_ALLOC_SIZE16384
28
29
30//-------------------------------------------------------------------------------------------------------------------------
31// SMBIOS Plist Keys
32//-------------------------------------------------------------------------------------------------------------------------
33
34/* =======================
35 BIOS Information (Type 0)
36 ========================= */
37#define kSMBBIOSInformationVendorKey "SMbiosvendor" // Apple Inc.
38#define kSMBBIOSInformationVersionKey "SMbiosversion" // MP31.88Z.006C.B05.0802291410
39#define kSMBBIOSInformationReleaseDateKey "SMbiosdate" // 02/29/08
40// Bungo
41#define kSMBBIOSInformationReleaseKey "SMbiosrelease" // BIOS Revision
42// example: BIOS Revision: 1.23 --> 2 bytes: Major=0x01, Minor=0x17 --> after swap: 0x1701hex = 5889dec (SMBIOS_spec_DSP0134_2.7.1)
43
44/* =========================
45 System Information (Type 1)
46 =========================== */
47#define kSMBSystemInformationManufacturerKey "SMmanufacturer" // Apple Inc.
48#define kSMBSystemInformationProductNameKey "SMproductname" // MacPro3,1
49#define kSMBSystemInformationVersionKey "SMsystemversion" // 1.0
50#define kSMBSystemInformationSerialNumberKey "SMserial" // Serial number
51//Bungo
52#define kSMBSystemInformationUUIDKey "SMsystemuuid" // ioreg -rd1 -c IOPlatformExpertDevice | awk '/IOPlatformUUID/ { split($0, line, "\""); printf("%s\n", line[4]); }'
53#define kSMBSystemInformationSKUNumberKey "SMskunumber" // System SKU#
54
55#define kSMBSystemInformationFamilyKey "SMfamily" // MacPro
56
57/* =========================================
58 Base Board (or Module) Information (Type 2)
59 =========================================== */
60#define kSMBBaseBoardManufacturerKey "SMboardmanufacturer" // Apple Inc.
61#define kSMBBaseBoardProductKey "SMboardproduct" // Mac-F2268DC8
62// Bungo
63#define kSMBBaseBoardVersionKey "SMboardversion" // MacPro3,1
64#define kSMBBaseBoardSerialNumberKey "SMboardserial" // C02140302D5DMT31M
65#define kSMBBaseBoardAssetTagKey "SMboardassettag" // Base Board Asset Tag# Bungo: renamed folowing convention
66#define kSMBBaseBoardLocationInChassisKey "SMboardlocation" // Part Component
67
68// ErmaC BoardType 0x0a(10) or 0x0b(11) MacPro Family
69#define kSMBBaseBoardTypeKey "SMboardtype" // 10 (Motherboard) all model, 11 (Processor+Memory Module) MacPro
70
71// Bungo
72/* =======================
73 System Enclosure (Type 3)
74 ========================= */
75#define kSMBSystemEnclosureManufacturerKey "SMchassismanufacturer" // Apple Inc.
76#define kSMBSystemEnclosureTypeKey "SMchassistype" // 7 Desktop
77#define kSMBSystemEnclosureVersionKey "SMchassisversion" // Mac-F42C88C8
78#define kSMBSystemEnclosureSerialNumberKey "SMchassisserial" // Serial number
79#define kSMBSystemEnclosureAssetTagKey "SMchassisassettag" // Pro-Enclosure Bungo: renamed folowing convention
80
81/* ============================
82 Processor Information (Type 4)
83 ============================== */
84// Bungo
85#define kSMBProcessorInformationSocketKey "SMcpusocket"
86#define kSMBProcessorInformationManufacturerKey "SMcpumanufacturer"
87#define kSMBProcessorInformationVersionKey "SMcpuversion"
88//
89#define kSMBProcessorInformationExternalClockKey"SMexternalclock"
90#define kSMBProcessorInformationMaximumClockKey"SMmaximalclock"
91// Bungo
92#define kSMBProcessorInformationCurrentClockKey "SMcurrentclock"
93#define kSMBProcessorInformationUpgradeKey "SMcpuupgrade"
94#define kSMBProcessorInformationSerialNumberKey "SMcpuserial"
95#define kSMBProcessorInformationAssetTagKey "SMcpuassettag" // Bungo: renamed folowing convention
96#define kSMBProcessorInformationPartNumberKey "SMcpupartnumber"
97
98/* =====================
99 Memory Device (Type 17)
100 ======================= */
101#define kSMBMemoryDeviceDeviceLocatorKey "SMmemdevloc" //
102#define kSMBMemoryDeviceBankLocatorKey "SMmembankloc" //
103#define kSMBMemoryDeviceMemoryTypeKey "SMmemtype" //
104#define kSMBMemoryDeviceMemorySpeedKey "SMmemspeed" //
105#define kSMBMemoryDeviceManufacturerKey "SMmemmanufacturer" //
106#define kSMBMemoryDeviceSerialNumberKey "SMmemserial" //
107#define kSMBMemoryDevicePartNumberKey "SMmempart" //
108// Bungo:
109#define kSMBMemoryDeviceAssetTagKey "SMmemassettag" //
110
111/* ===========================================
112 Memory SPD Data (Apple Specific - Type 130)
113 ============================================= */
114
115/* ============================================
116 OEM Processor Type (Apple Specific - Type 131)
117 ============================================== */
118#define kSMBOemProcessorTypeKey "SMoemcputype" // Bungo: renamed from SMcputype
119
120/* =================================================
121 OEM Processor Bus Speed (Apple Specific - Type 132)
122 =================================================== */
123#define kSMBOemProcessorBusSpeedKey "SMoemcpubusspeed" // Bungo: renamed from SMbusspeed
124
125/* ==============================================
126 OEM Platform Feature (Apple Specific - Type 133)
127 ================================================ */
128//#define kSMBOemPlatformFeatureKey "SMoemplatformfeature"
129
130/* ==================================================*/
131#define getFieldOffset(struct, field)((uint8_t)(uint32_t)&(((struct *)0)->field))
132
133typedef struct
134{
135SMBStructHeader *orig;
136SMBStructHeader *new;
137} SMBStructPtrs;
138
139/* =======================
140 BIOS Information (Type 0)
141 ========================= */
142typedef struct
143{
144char *vendor;
145char *version;
146char *releaseDate;
147uint16_t release; // Bungo
148} defaultBIOSInfo_t;
149
150defaultBIOSInfo_t defaultBIOSInfo;
151
152/* =========================
153 System Information (Type 1)
154 =========================== */
155typedef struct
156{
157char *manufacturer;
158char *productName;
159char *version;
160char *serialNumber;
161char *skuNumber;// ErmaC
162char *family;
163} defaultSystemInfo_t;
164
165defaultSystemInfo_t defaultSystemInfo;
166
167/* =========================================
168 Base Board (or Module) Information (Type 2)
169 =========================================== */
170typedef struct
171{
172char *manufacturer;
173char *product;
174char *version;// Bungo
175char *serialNumber;// ErmaC
176char *assetTag;// ErmaC Bungo: renamed folowing convention
177char *locationInChassis;// ErmaC
178uint8_t boardType;// ErmaC
179} defaultBaseBoard_t;
180
181defaultBaseBoard_t defaultBaseBoard;
182
183// Bungo
184typedef struct {
185char*manufacturer;
186uint8_tchassisType;
187char*version;
188char*serialNumber;
189char*assetTag;
190char*skuNumber;
191} defaultChassis_t;
192
193defaultChassis_t defaultChassis;
194
195typedef struct
196{
197uint8_ttype;
198SMBValueTypevalueType;
199uint8_tfieldOffset;
200char*keyString;
201bool(*getSMBValue)(returnType *);
202char**defaultValue;
203} SMBValueSetter;
204
205SMBValueSetter SMBSetters[] =
206{
207/* =======================
208 BIOS Information (Type 0)
209 ========================= */
210{ kSMBTypeBIOSInformation, kSMBString, getFieldOffset(SMBBIOSInformation, vendor),
211kSMBBIOSInformationVendorKey, NULL, &defaultBIOSInfo.vendor }, // SMbiosvendor - Apple Inc.
212
213{ kSMBTypeBIOSInformation, kSMBString, getFieldOffset(SMBBIOSInformation, version),
214kSMBBIOSInformationVersionKey, NULL, &defaultBIOSInfo.version }, // SMbiosversion - MP31.88Z.006C.B05.0802291410
215
216{ kSMBTypeBIOSInformation, kSMBString, getFieldOffset(SMBBIOSInformation, releaseDate),
217kSMBBIOSInformationReleaseDateKey, NULL, &defaultBIOSInfo.releaseDate }, // SMbiosdate - 02/29/08
218
219// Bungo
220{ kSMBTypeBIOSInformation, kSMBWord, getFieldOffset(SMBBIOSInformation, releaseMajor),
221kSMBBIOSInformationReleaseKey, NULL,(char **)&defaultBIOSInfo.release }, // SMbiosrelease - 0.1 (256)
222
223/* =========================
224 System Information (Type 1)
225 =========================== */
226{kSMBTypeSystemInformation,kSMBString,getFieldOffset(SMBSystemInformation, manufacturer),
227kSMBSystemInformationManufacturerKey, NULL,&defaultSystemInfo.manufacturer}, // SMmanufacturer - Apple Inc.
228
229{kSMBTypeSystemInformation,kSMBString,getFieldOffset(SMBSystemInformation, productName),
230kSMBSystemInformationProductNameKey, NULL, &defaultSystemInfo.productName }, // SMproductname - MacPro3,1
231
232{kSMBTypeSystemInformation,kSMBString,getFieldOffset(SMBSystemInformation, version),
233kSMBSystemInformationVersionKey, NULL, &defaultSystemInfo.version }, // SMsystemversion - 1.0
234
235{kSMBTypeSystemInformation,kSMBString,getFieldOffset(SMBSystemInformation, serialNumber),
236kSMBSystemInformationSerialNumberKey, NULL, &defaultSystemInfo.serialNumber }, // SMserial - Serial number
237/* Bungo:
238{kSMBTypeSystemInformation,kSMBByte,getFieldOffset(SMBSystemInformation, uuid),
239kSMBSystemInformationUUIDKey, NULL, NULL}, // SMsystemuuid
240
241{kSMBTypeSystemInformation,kSMBByte,getFieldOffset(SMBSystemInformation, wakeupReason),
242NULL, NULL, NULL}, // reason for system wakeup
243*/
244
245// Bungo
246{kSMBTypeSystemInformation,kSMBString,getFieldOffset(SMBSystemInformation, skuNumber),
247kSMBSystemInformationSKUNumberKey, NULL, &defaultSystemInfo.skuNumber}, // SMskunumber - System SKU#
248
249{kSMBTypeSystemInformation,kSMBString,getFieldOffset(SMBSystemInformation, family),
250kSMBSystemInformationFamilyKey,NULL,&defaultSystemInfo.family}, // SMfamily - MacPro
251
252
253/* =========================================
254 Base Board (or Module) Information (Type 2)
255 =========================================== */
256{kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, manufacturer),
257kSMBBaseBoardManufacturerKey, NULL, &defaultBaseBoard.manufacturer }, // SMboardmanufacturer - Apple Inc.
258
259{kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, product),
260kSMBBaseBoardProductKey, NULL, &defaultBaseBoard.product }, // SMboardproduct - Mac-F2268DC8
261
262// Bungo
263{kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, version),
264kSMBBaseBoardVersionKey, NULL, &defaultBaseBoard.version }, // SMboardversion - MacPro3,1
265
266{kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, serialNumber),
267kSMBBaseBoardSerialNumberKey, NULL, &defaultBaseBoard.serialNumber }, // SMboardserial - C02140302D5DMT31M
268
269{kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, assetTag),
270kSMBBaseBoardAssetTagKey, NULL, &defaultBaseBoard.assetTag }, // SMboardassettag - Base Board Asset Tag#
271
272{kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, locationInChassis),
273kSMBBaseBoardLocationInChassisKey, NULL, &defaultBaseBoard.locationInChassis }, // SMboardlocation - Part Component
274
275{kSMBTypeBaseBoard,kSMBByte,getFieldOffset(SMBBaseBoard, boardType),
276kSMBBaseBoardTypeKey,NULL, (char **)&defaultBaseBoard.boardType }, // SMboardtype - 10 (Motherboard) all model, 11 (Processor+Memory Module) MacPro
277
278/*{kSMBTypeBaseBoard,kSMBByte, getFieldOffset(SMBBaseBoard, numberOfContainedHandles),
279NULL , NULL, NULL }, // numberOfContainedHandles = 0
280*/
281//
282
283// Bungo
284/* =======================
285 System Enclosure (Type 3)
286 ========================= */
287{kSMBTypeSystemEnclosure,kSMBString,getFieldOffset(SMBSystemEnclosure, manufacturer),
288kSMBSystemEnclosureManufacturerKey, NULL,&defaultChassis.manufacturer }, // SMchassismanufacturer - Apple Inc.
289
290{kSMBTypeSystemEnclosure, kSMBByte,getFieldOffset(SMBSystemEnclosure, chassisType),
291kSMBSystemEnclosureTypeKey, NULL, (char **)&defaultChassis.chassisType}, // SMchassistype - 7
292
293{kSMBTypeSystemEnclosure, kSMBString, getFieldOffset(SMBSystemEnclosure, version),
294kSMBSystemEnclosureVersionKey, NULL, &defaultChassis.version }, // SMchassisversion - Mac-F42C88C8
295
296{kSMBTypeSystemEnclosure, kSMBString, getFieldOffset(SMBSystemEnclosure, serialNumber),
297kSMBSystemEnclosureSerialNumberKey, NULL, &defaultChassis.serialNumber }, // SMchassisserial
298
299{kSMBTypeSystemEnclosure, kSMBString, getFieldOffset(SMBSystemEnclosure, assetTag),
300kSMBSystemEnclosureAssetTagKey, NULL, &defaultChassis.assetTag }, // SMchassisassettag - Pro Enclosure
301
302/*
303{kSMBTypeSystemEnclosure, kSMBString, getFieldOffset(SMBSystemEnclosure, skuNumber),
304NULL, NULL, &defaultChassis.skuNumber },
305*/
306
307/* ============================
308 Processor Information (Type 4)
309 ============================== */
310{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, socketDesignation),
311kSMBProcessorInformationSocketKey, NULL, NULL}, // SMcpusocket -
312
313{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, manufacturer),
314kSMBProcessorInformationManufacturerKey, NULL, NULL}, // SMcpumanufacturer - Intel(R) Corporation
315
316{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, processorVersion),
317kSMBProcessorInformationVersionKey, NULL, NULL}, // SMcpuversion
318
319{kSMBTypeProcessorInformation,kSMBWord, getFieldOffset(SMBProcessorInformation, externalClock),
320kSMBProcessorInformationExternalClockKey, getProcessorInformationExternalClock,NULL}, // SMcpuexternalclock
321
322{kSMBTypeProcessorInformation,kSMBWord, getFieldOffset(SMBProcessorInformation, maximumClock),
323kSMBProcessorInformationMaximumClockKey, getProcessorInformationMaximumClock,NULL}, // SMcpumaximumclock
324// Bungo
325{kSMBTypeProcessorInformation,kSMBWord,getFieldOffset(SMBProcessorInformation, currentClock),
326kSMBProcessorInformationCurrentClockKey, NULL, NULL}, // SMcpucurrentclock
327
328{kSMBTypeProcessorInformation,kSMBByte,getFieldOffset(SMBProcessorInformation, processorUpgrade),
329kSMBProcessorInformationUpgradeKey, NULL, NULL}, // SMcpuupgrade
330//
331{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, serialNumber),
332kSMBProcessorInformationSerialNumberKey, NULL, NULL},
333
334// Bungo
335{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, assetTag),
336kSMBProcessorInformationAssetTagKey, NULL, NULL}, // SMcpuassettag
337//
338{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, partNumber),
339kSMBProcessorInformationPartNumberKey, NULL, NULL},
340
341/* =====================
342 Memory Device (Type 17)
343 ======================= */
344{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, deviceLocator),
345kSMBMemoryDeviceDeviceLocatorKey, NULL, NULL},
346
347{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, bankLocator),
348kSMBMemoryDeviceBankLocatorKey, NULL, NULL},
349
350{kSMBTypeMemoryDevice,kSMBByte,getFieldOffset(SMBMemoryDevice, memoryType),
351kSMBMemoryDeviceMemoryTypeKey, getSMBMemoryDeviceMemoryType,NULL},
352
353{kSMBTypeMemoryDevice,kSMBWord,getFieldOffset(SMBMemoryDevice, memorySpeed),
354kSMBMemoryDeviceMemorySpeedKey, getSMBMemoryDeviceMemorySpeed,NULL},
355
356{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, manufacturer),
357kSMBMemoryDeviceManufacturerKey, getSMBMemoryDeviceManufacturer, NULL},
358
359{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, serialNumber),
360kSMBMemoryDeviceSerialNumberKey, getSMBMemoryDeviceSerialNumber, NULL},
361
362{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, assetTag),
363kSMBMemoryDeviceAssetTagKey, NULL, NULL},
364
365{kSMBTypeMemoryDevice,kSMBWord,getFieldOffset(SMBMemoryDevice, errorHandle),
366NULL, getSMBMemoryDeviceMemoryErrorHandle, NULL},
367
368{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, partNumber),
369kSMBMemoryDevicePartNumberKey, getSMBMemoryDevicePartNumber, NULL},
370
371//-------------------------------------------------------------------------------------------------------------------------
372// Apple Specific
373//-------------------------------------------------------------------------------------------------------------------------
374// OEM Processor Type (Apple Specific - Type 131)
375{kSMBTypeOemProcessorType,kSMBWord,getFieldOffset(SMBOemProcessorType, ProcessorType),kSMBOemProcessorTypeKey,
376getSMBOemProcessorType,NULL},
377
378// OEM Processor Bus Speed (Apple Specific - Type 132)
379{kSMBTypeOemProcessorBusSpeed,kSMBWord,getFieldOffset(SMBOemProcessorBusSpeed, ProcessorBusSpeed),kSMBOemProcessorBusSpeedKey,
380getSMBOemProcessorBusSpeed,NULL}
381
382// OEM Platform Feature (Apple Specific - Type 133)
383/*
384{kSMBTypeOemPlatformFeature,kSMBWord,getFieldOffset(SMBOemPlatformFeature, PlatformFeature),kSMBOemPlatformFeatureKey,
385getSMBOemPlatformFeature,NULL}
386*/
387};
388
389int numOfSetters = sizeof(SMBSetters) / sizeof(SMBValueSetter);
390
391
392SMBEntryPoint *origeps= 0;
393SMBEntryPoint *neweps= 0;
394
395static uint8_t stringIndex;// increament when a string is added and set the field value accordingly
396static uint8_t stringsSize;// add string size
397
398static SMBWord tableLength= 0;
399static SMBWord handle= 0;
400static SMBWord maxStructSize= 0;
401static SMBWord structureCount= 0;
402
403//-------------------------------------------------------------------------------------------------------------------------
404// Default SMBIOS Data
405//-------------------------------------------------------------------------------------------------------------------------
406/* Rewrite: use a struct */
407
408// Bungo: suggest to not mixing data from different Mac models, use real Mac SMBIOS dumps
409
410#define kDefaultVendorManufacturer"Apple Inc."
411//#define kDefaultBIOSReleaseDate"11/06/2009"
412#define kDefaultSerialNumber"SOMESRLNMBR"
413//Bungo
414#define kDefaultSkuNumber"Default SKU#"
415#define kDefaultAssetTag"Default Asset Tag#"
416//#define kDefaultBoardType"10" // 0xA
417//#define kDefaultBoardProcessorType"11" // 0xB
418#define kDefaultSystemVersion"1.0"
419#define kDefaultBIOSRelease256 // 256 = 0x0100 -> swap bytes: 0x0001 -> Release: 0.1 (see SMBIOS spec. table Type 0)
420//#define kDefaultLocatioInChassis"Part Component"
421//#define KDefaultBoardSerialNumber"C02140302D5DMT31M" // new C07019501PLDCVHAD - C02032101R5DC771H
422
423//=========== Mac mini ===========
424#define kDefaultMacMiniFamily"Mac mini"
425//#define kDefaultMacMiniBoardAssetTagNumber"Mini-Aluminum"
426
427#define kDefaultMacMini"Macmini2,1"
428#define kDefaultMacMiniBIOSVersion" MM21.88Z.009A.B00.0706281359"
429#define kDefaultMacMiniBIOSReleaseDate"06/28/07"
430#define kDefaultMacMiniBoardProduct"Mac-F4208EAA"
431
432// MacMini5,1 Mac-8ED6AF5B48C039E1 - MM51.88Z.0077.B0F.1110201309
433
434// MacMini5,2 Mac-4BC72D62AD45599E
435
436// MacMini5,3
437//#define kDefaultMacMini"Macmini5,3"
438//#define kDefaultMacMiniBIOSVersion" MM51.88Z.0077.B10.1201241549"
439//#define kDefaultMacMiniBoardProduct"Mac-F65AE981FFA204ED"
440//#define kDefaultMacMiniBIOSReleaseDate"01/24/2012"
441
442// MacMini 6,1 - Mac-F65AE981FFA204ED
443// MacMini 6,2
444//#define kDefaultMacMini62"Macmini6,2"
445//#define kDefaultMacMini62BIOSVersion" MM61.88Z.0106.B00.1208091121"
446//#define kDefaultMacMini62BoardProduct"Mac-F65AE981FFA204ED"
447//#define kDefaultMacMini62BIOSReleaseDate"10/14/2012"
448
449//=========== MacBook ===========
450#define kDefaultMacBookFamily"MacBook"
451//#define kDefaultMacBookBoardAssetTagNumber"MacBook-Black"
452
453#define kDefaultMacBook"MacBook4,1"
454#define kDefaultMacBookBIOSVersion" MB41.88Z.00C1.B00.0802091535"
455#define kDefaultMacBookBIOSReleaseDate"02/09/08"
456#define kDefaultMacBookBoardProduct"Mac-F22788A9"
457
458//=========== MacBookAir ===========
459#define kDefaultMacBookAirFamily"MacBook Air"
460
461// MacBookAir4,1 - Mac-C08A6BB70A942AC2
462// MacBookAir4,2 - Mac-742912EFDBEE19B3
463
464// MacBookAir5,2
465#define kDefaultMacBookAir"MacBookAir5,2"
466#define kDefaultMacBookAirBIOSVersion" MBA51.88Z.00EF.B00.1205221442"
467#define kDefaultMacBookAirBIOSReleaseDate"05/10/12"
468#define kDefaultMacBookBoardAirProduct"Mac-2E6FAB96566FE58C"
469
470// MacBookAir6,1
471// Bios: MBA61.88Z.0099.B04.1309271229
472// Board: Mac-35C1E88140C3E6CF
473// Data: 24/06/13
474
475// MacBookAir6,2
476// Bios: MBA62.88Z.00EF.B00.1205221442
477// Board: Mac-7DF21CB3ED6977E5
478// Data: 24/06/13
479
480//=========== MacBookPro ===========
481#define kDefaultMacBookProFamily"MacBook Pro"
482//#define kDefaultMacBookProBoardAssetTagNumber"MacBook-Aluminum"
483
484#define kDefaultMacBookPro"MacBookPro4,1"
485#define kDefaultMacBookProBIOSVersion" MBP41.88Z.00C1.B03.0802271651"
486#define kDefaultMacBookProBIOSReleaseDate"02/27/08"
487#define kDefaultMacBookProBoardProduct"Mac-F42C89C8"
488
489//#define kDefaultMacBookPro"MacBookPro8,1"
490//#define kDefaultMacBookProBIOSVersion" MBP81.88Z.0047.B24.1110141131"
491//#define kDefaultMacBookProBoardProduct"Mac-94245B3640C91C81"
492//#define kDefaultMacBookProBIOSReleaseDate"10/14/11"
493
494// MacBookPro8,2 - Mac_94245A3940C91C80
495// MacBookPro8,3 - Mac-942459F5819B171B
496
497// MacBookPro10,2
498//#define kDefaultMacBookProIvy"MacBookPro10,2"
499//#define kDefaultMacBookProIvyBIOSVersion" MBP102.88Z.0106.B01.1208311637"
500//#define kDefaultMacBookProIvyBoardProduct"Mac-AFD8A9D944EA4843"
501//#define kDefaultMacBookProIvyBIOSReleaseDate"10/02/2012"
502
503// MacBookPro11,2 - Mac-3CBD00234E554E41 - MBP112.88Z.0138.B03.1310291227
504// MacBookPro11,3 - Mac-2BD1B31983FE1663 - MBP112.88Z.0138.B02.1310181745
505
506//=========== iMac ===========
507#define kDefaultiMacFamily"iMac"
508//#define kDefaultiMacBoardAssetTagNumber"iMac-Aluminum"
509
510#define kDefaultiMac"iMac8,1"
511#define kDefaultiMacBIOSVersion" IM81.88Z.00C1.B00.0903051113"
512#define kDefaultiMacBIOSReleaseDate"02/09/08"
513#define kDefaultiMacBoardProduct"Mac-F227BEC8"
514#define kDefaultMacFamily"Mac" // iMac8,1 family = "Mac" not "iMac"
515
516// iMac10,1
517// iMac11,1 core i3/i5/i7
518#define kDefaultiMacNehalem"iMac11,1"
519#define kDefaultiMacNehalemBIOSVersion" IM111.88Z.0034.B02.1003171314"
520#define kDefaultiMacNehalemBIOSReleaseDate"03/30/10"
521#define kDefaultiMacNehalemBoardProduct"Mac-F2268DAE"
522// iMac11,2
523// iMac11,3
524
525// iMac12,1
526#define kDefaultiMacSandy"iMac12,1"
527#define kDefaultiMacSandyBIOSVersion" IM121.88Z.0047.B00.1102091756"
528#define kDefaultiMacSandyBIOSReleaseDate"04/22/11"
529#define kDefaultiMacSandyBoardProduct"Mac-942B5BF58194151B"
530
531// iMac12,2 Mac-942B59F58194171B
532//#define kDefaultiMacSandy"iMac12,2"
533//#define kDefaultiMacSandyBIOSVersion" IM121.88Z.0047.B1D.1110171110"
534//#define kDefaultiMacSandyBIOSReleaseDate"10/17/11"
535//#define kDefaultiMacSandyBoardProduct"Mac-942B59F58194171B"
536
537// iMac13,1
538// Bios: IM131.88Z.010A.B05.1211151146
539// Data: 11/15/2012
540// Board: Mac-00BE6ED71E35EB86
541
542// iMac13,2
543//#define kDefaultiMacIvy"iMac13,2"
544//#define kDefaultiMacIvyBIOSVersion" IM131.88Z.00CE.B00.1203281326"
545//#define kDefaultiMacIvyBIOSReleaseDate"03/28/2012"
546//#define kDefaultiMacIvyBoardProduct"Mac-FC02E91DDD3FA6A4"
547
548//=========== MacPro ===========
549#define kDefaultMacProFamily"Mac Pro"
550//#define KDefauktMacProBoardAssetTagNumber"Pro-Enclosure"
551//#define kDefaultMacProBoardType"0xB" // 11
552
553#define kDefaultMacPro"MacPro3,1"
554#define kDefaultMacProBIOSVersion" MP31.88Z.006C.B05.0903051113"
555#define kDefaultMacProBIOSReleaseDate"08/03/2010"
556//#define kDefaultMacProSystemVersion"1.3"
557#define kDefaultMacProBoardProduct"Mac-F42C88C8"
558//#define KDefaultMacProBoardSerialNumber"J593902RA4MFE"
559
560// Mac Pro 4,1 core i7/Xeon
561#define kDefaultMacProNahWestSystemVersion"0.0"
562
563#define kDefaultMacProNehalem"MacPro4,1"
564#define kDefaultMacProNehalemBIOSVersion" MP41.88Z.0081.B07.0910130729"
565#define kDefaultMacProNehalemBIOSReleaseDate"10/13/09"
566//#define kDefaultMacProNehalemSystemVersion"1.4"
567#define kDefaultMacProNehalemBoardProduct"Mac-F221BEC8"
568//#define KDefaultMacProNehalemBoardSerialNumber"J593004RB1LUE"
569
570// Mac Pro 5,1 core i7/Xeon
571#define kDefaultMacProWestmere"MacPro5,1"
572#define kDefaultMacProWestmereBIOSVersion" MP51.88Z.007F.B03.1010071432"
573#define kDefaultMacProWestmereBIOSReleaseDate"10/07/10"
574//#define kDefaultMacProWestmereSystemVersion"1.2"
575#define kDefaultMacProWestmereBoardProduct"Mac-F221BEC8"
576//#define KDefaultMacProWestmereBoardSerialNumber"J522700H7BH8C"
577
578// Mac Pro 6,1
579#define kDefaultMacProHaswell"MacPro6,1"
580#define kDefaultMacProHaswellBIOSVersion" MP61.88Z.0116.B04.1312061508"
581#define kDefaultMacProHaswellBIOSReleaseDate"12/06/2013"
582//#define kDefaultMacProHaswellSystemVersion"1.?"
583#define kDefaultMacProHaswellBoardProduct"Mac-F60DEB81FF30ACF6"
584//#define KDefaultMacProHaswellBoardSerialNumber"?????????????"
585
586//#define KDefaultBoardSerialNumber"C02140302D5DMT31M" // new C07019501PLDCVHAD - C02032101R5DC771H
587// J593902RA4MFE 3,1
588// J5031046RCZJA 5,1
589// J521101A5CZJC 3,1
590// J593004RB1LUE MacPro4,1
591// J513401PZBH8C 5,1
592// J590802LC4ACB 3,1
593// J594900AH1LUE 4,1
594// J512500HZBH8C 5,1
595// J522700H7BH8C MacPro5,1
596
597/* ============================================ */
598
599bool useSMBIOSdefaults = true; // Bungo
600
601SMBByte PlatformType= 1; // Bungo: same as Platfom.Type in platform.h. Because can't get from ACPI FADT PM profile and platformCPUFeature(CPU_FEATURE_MOBILE)) doesn't work as expect, FIXING NEEDED.
602
603/* Rewrite this function */
604void setDefaultSMBData(void) // Bungo: setting data from real Macs
605{
606defaultBIOSInfo.vendor = kDefaultVendorManufacturer;
607defaultBIOSInfo.release = kDefaultBIOSRelease; // Bungo
608
609defaultSystemInfo.manufacturer = kDefaultVendorManufacturer;
610defaultSystemInfo.version = kDefaultSystemVersion;
611defaultSystemInfo.serialNumber = kDefaultSerialNumber;
612defaultSystemInfo.skuNumber = kDefaultSkuNumber; // Bungo
613
614defaultBaseBoard.manufacturer = kDefaultVendorManufacturer;
615defaultBaseBoard.serialNumber = kDefaultSerialNumber;
616defaultBaseBoard.assetTag = kDefaultAssetTag;
617
618defaultChassis.manufacturer = kDefaultVendorManufacturer;
619defaultChassis.serialNumber = kDefaultSerialNumber;
620defaultChassis.assetTag = kDefaultAssetTag;
621defaultChassis.skuNumber = kDefaultSkuNumber;
622
623// if (platformCPUFeature(CPU_FEATURE_MOBILE)) Bungo: doesn't recognise correctly, need fixing
624if (PlatformType == 2) // this method works but it's a substitute
625{
626if (Platform.CPU.NoCores > 1)
627 {
628defaultSystemInfo.productName = kDefaultMacBookPro;
629defaultBIOSInfo.version = kDefaultMacBookProBIOSVersion;
630defaultBIOSInfo.releaseDate = kDefaultMacBookProBIOSReleaseDate;
631defaultSystemInfo.family = kDefaultMacBookProFamily;
632defaultBaseBoard.product = kDefaultMacBookProBoardProduct;
633defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
634defaultChassis.chassisType = kSMBchassisUnknown;
635} else {
636defaultSystemInfo.productName = kDefaultMacBook;
637defaultBIOSInfo.version = kDefaultMacBookBIOSVersion;
638defaultBIOSInfo.releaseDate = kDefaultMacBookBIOSReleaseDate;
639defaultSystemInfo.family = kDefaultMacBookFamily;
640defaultBaseBoard.product = kDefaultMacBookBoardProduct;
641defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
642defaultChassis.chassisType = kSMBchassisUnknown;
643}
644} else {
645switch (Platform.CPU.NoCores)
646{
647case 1:
648defaultBIOSInfo.version = kDefaultMacMiniBIOSVersion;
649defaultBIOSInfo.releaseDate = kDefaultMacMiniBIOSReleaseDate;
650defaultSystemInfo.productName = kDefaultMacMini;
651defaultSystemInfo.family = kDefaultMacMiniFamily;
652defaultBaseBoard.product = kDefaultMacMiniBoardProduct;
653defaultBaseBoard.boardType = kSMBBaseBoardUnknown;
654defaultChassis.chassisType = kSMBchassisLPDesktop;
655break;
656
657case 2:
658defaultBIOSInfo.version = kDefaultiMacBIOSVersion;
659defaultBIOSInfo.releaseDate = kDefaultiMacBIOSReleaseDate;
660defaultSystemInfo.productName = kDefaultiMac;
661defaultSystemInfo.family = kDefaultiMacFamily; // iMac8,1 family = Mac
662defaultBaseBoard.product = kDefaultiMacBoardProduct;
663defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
664defaultChassis.chassisType = kSMBchassisAllInOne;
665break;
666default:
667{
668switch (Platform.CPU.Family)
669{
670case 0x06:
671{
672switch (Platform.CPU.Model)
673{
674case CPU_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
675case CPU_MODEL_DALES:
676case CPU_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
677defaultBIOSInfo.version= kDefaultiMacNehalemBIOSVersion;
678defaultBIOSInfo.releaseDate= kDefaultiMacNehalemBIOSReleaseDate;
679defaultSystemInfo.productName= kDefaultiMacNehalem;
680defaultSystemInfo.family= kDefaultiMacFamily; // iMac8,1 family = Mac
681defaultBaseBoard.product = kDefaultiMacNehalemBoardProduct;
682defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
683defaultChassis.chassisType = kSMBchassisAllInOne;
684break;
685
686case CPU_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
687case CPU_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
688defaultBIOSInfo.version = kDefaultiMacSandyBIOSVersion;
689defaultBIOSInfo.releaseDate = kDefaultiMacSandyBIOSReleaseDate;
690defaultSystemInfo.productName= kDefaultiMacSandy;
691defaultSystemInfo.family = kDefaultiMacFamily;
692defaultBaseBoard.product = kDefaultiMacSandyBoardProduct;
693defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
694defaultChassis.chassisType = kSMBchassisAllInOne;
695break;
696
697case CPU_MODEL_NEHALEM: // Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
698case CPU_MODEL_NEHALEM_EX: // Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x
699defaultBIOSInfo.version = kDefaultMacProNehalemBIOSVersion;
700defaultBIOSInfo.releaseDate = kDefaultMacProNehalemBIOSReleaseDate;
701defaultSystemInfo.productName= kDefaultMacProNehalem;
702 defaultSystemInfo.version = kDefaultMacProNahWestSystemVersion;
703defaultSystemInfo.family = kDefaultMacProFamily;
704defaultBaseBoard.product = kDefaultMacProNehalemBoardProduct;
705defaultBaseBoard.boardType = kSMBBaseBoardProcessorMemoryModule;
706defaultChassis.chassisType = kSMBchassisTower;
707break;
708
709case CPU_MODEL_WESTMERE: // Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
710case CPU_MODEL_WESTMERE_EX:// Intel Xeon E7
711case CPU_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)
712 case CPU_MODEL_IVYBRIDGE_XEON: // Intel Core i7, Xeon E5 v2 LGA2011 (22nm) MacMan moved to proper location
713 case CPU_MODEL_HASWELL_SVR: // Intel Core i7, Xeon E5 v3 LGA2011v3 (22nm)
714 case CPU_MODEL_BROADWELL: // Intel Core i3, i5, i7 LGA1150 LGA2011v3 (14nm)
715 case CPU_MODEL_HASWELL_ULT:
716 case CPU_MODEL_CRYSTALWELL:
717 case CPU_MODEL_BRODWELL_SVR:
718 case CPU_MODEL_BRODWELL_MSVR:
719defaultBIOSInfo.version = kDefaultMacProWestmereBIOSVersion;
720defaultBIOSInfo.releaseDate = kDefaultMacProWestmereBIOSReleaseDate;
721defaultSystemInfo.productName= kDefaultMacProWestmere;
722 defaultSystemInfo.version = kDefaultMacProNahWestSystemVersion;
723defaultSystemInfo.family = kDefaultMacProFamily;
724defaultBaseBoard.product = kDefaultMacProWestmereBoardProduct;
725defaultBaseBoard.boardType = kSMBBaseBoardProcessorMemoryModule;
726defaultChassis.chassisType = kSMBchassisTower;
727break;
728
729default:
730defaultBIOSInfo.version = kDefaultMacProBIOSVersion;
731defaultBIOSInfo.releaseDate = kDefaultMacProBIOSReleaseDate;
732defaultSystemInfo.productName= kDefaultMacPro;
733defaultSystemInfo.family = kDefaultMacProFamily;
734defaultBaseBoard.product = kDefaultMacProBoardProduct;
735defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
736defaultChassis.chassisType = kSMBchassisUnknown;
737break;
738}
739break;
740}
741default:
742defaultBIOSInfo.version = kDefaultMacProBIOSVersion;
743defaultBIOSInfo.releaseDate = kDefaultMacProBIOSReleaseDate;
744defaultSystemInfo.productName= kDefaultMacPro;
745defaultSystemInfo.family = kDefaultMacProFamily;
746defaultBaseBoard.product = kDefaultMacProBoardProduct;
747defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
748defaultChassis.chassisType = kSMBchassisUnknown;
749break;
750}
751break;
752}
753}
754}
755}
756
757/* Used for SM*n smbios.plist keys */
758bool getSMBValueForKey(SMBStructHeader *structHeader, const char *keyString, const char **string, returnType *value)
759{
760static int idx = -1;
761static int current = -1;
762int len;
763char key[24];
764
765if (current != structHeader->handle) {
766idx++;
767current = structHeader->handle;
768}
769
770sprintf(key, "%s%d", keyString, idx);
771
772if (value) {
773if (getIntForKey(key, (int *)&(value->dword), SMBPlist)) {
774return true;
775}
776} else {
777if (getValueForKey(key, string, &len, SMBPlist)) {
778return true;
779}
780}
781return false;
782}
783
784char *getSMBStringForField(SMBStructHeader *structHeader, uint8_t field)
785{
786uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length;
787
788if (!field) {
789return NULL;
790}
791
792for (field--; field != 0 && strlen((char *)stringPtr) > 0;
793field--, stringPtr = (uint8_t *)((uint32_t)stringPtr + strlen((char *)stringPtr) + 1));
794
795return (char *)stringPtr;
796}
797
798void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field)
799{
800int strSize;
801
802if (!field) {
803return;
804}
805
806if (!string) {
807*field = 0;
808return;
809}
810
811strSize = strlen(string);
812
813// remove any spaces found at the end but only in MemoryDevice
814if (structHeader->type == kSMBTypeMemoryDevice) {
815while ((strSize != 0) && (string[strSize - 1] == ' ')) {
816strSize--;
817}
818}
819
820if (strSize == 0) {
821*field = 0;
822return;
823}
824
825memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize);
826*field = stringIndex;
827
828stringIndex++;
829stringsSize += strSize + 1;
830}
831
832bool setSMBValue(SMBStructPtrs *structPtr, int idx, returnType *value)
833{
834const char *string = 0;
835int len;
836bool parsed;
837int val;
838
839if (numOfSetters <= idx) {
840return false;
841}
842
843switch (SMBSetters[idx].valueType) {
844case kSMBString:
845{
846if (SMBSetters[idx].keyString)
847{
848if (getValueForKey(SMBSetters[idx].keyString, &string, &len, SMBPlist))
849{
850break;
851} else {
852if (structPtr->orig->type == kSMBTypeMemoryDevice)// MemoryDevice only
853{
854if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, &string, NULL))
855{
856break;
857}
858}
859}
860
861}
862if (SMBSetters[idx].getSMBValue) {
863if (SMBSetters[idx].getSMBValue((returnType *)&string)) {
864break;
865}
866}
867// if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue)) Bungo
868if (useSMBIOSdefaults && SMBSetters[idx].defaultValue && *(SMBSetters[idx].defaultValue)) {
869string = *(SMBSetters[idx].defaultValue);
870break;
871}
872string = getSMBStringForField(structPtr->orig, *(uint8_t *)value);
873break;
874}
875case kSMBByte:
876case kSMBWord:
877case kSMBDWord:
878case kSMBQWord:
879if (SMBSetters[idx].keyString) {
880parsed = getIntForKey(SMBSetters[idx].keyString, &val, SMBPlist);
881if (!parsed)
882{
883if (structPtr->orig->type == kSMBTypeMemoryDevice) { // MemoryDevice only
884parsed = getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, (returnType *)&val);
885}
886}
887if (parsed) {
888switch (SMBSetters[idx].valueType) {
889case kSMBByte:
890value->byte = (uint8_t)val;
891break;
892case kSMBWord:
893value->word = (uint16_t)val;
894break;
895case kSMBQWord:
896value->qword = (uint64_t)val;
897break;
898case kSMBDWord:
899default:
900value->dword = (uint32_t)val;
901break;
902}
903return true;
904}
905}
906
907if (SMBSetters[idx].getSMBValue) {
908if (SMBSetters[idx].getSMBValue(value)) {
909return true;
910}
911}
912// #if 0 Bungo: enables code below
913// if (*(SMBSetters[idx].defaultValue)) Bungo
914if (useSMBIOSdefaults && SMBSetters[idx].defaultValue && *(SMBSetters[idx].defaultValue)) {
915// value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue); Bungo
916switch (SMBSetters[idx].valueType) {
917case kSMBByte:
918value->byte = *(uint8_t *)(SMBSetters[idx].defaultValue);
919break;
920case kSMBWord:
921value->word = *(uint16_t *)(SMBSetters[idx].defaultValue);
922break;
923case kSMBQWord:
924value->qword = *(uint64_t *)(SMBSetters[idx].defaultValue);
925break;
926case kSMBDWord:
927default:
928value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue);
929break;
930}
931return true;
932}
933// #endif Bungo
934break;
935}
936
937// if (SMBSetters[idx].valueType == kSMBString && string) Bungo: use null string too -> "Not Specified"
938if ((SMBSetters[idx].valueType == kSMBString) && string) {
939setSMBStringForField(structPtr->new, string, &value->byte);
940}
941return true;
942}
943
944//-------------------------------------------------------------------------------------------------------------------------
945// Apple Specific
946//-------------------------------------------------------------------------------------------------------------------------
947
948/* ===========================================
949 Firmware Volume (Apple Specific - Type 128)
950 ============================================= */
951void addSMBFirmwareVolume(SMBStructPtrs *structPtr)
952{
953return;
954}
955
956/* ===========================================
957 Memory SPD Data (Apple Specific - Type 130)
958 ============================================= */
959void addSMBMemorySPD(SMBStructPtrs *structPtr)
960{
961/* SPD data from Platform.RAM.spd */
962return;
963}
964
965/* ============================================
966 OEM Processor Type (Apple Specific - Type 131)
967 ============================================== */
968void addSMBOemProcessorType(SMBStructPtrs *structPtr)
969{
970SMBOemProcessorType *p = (SMBOemProcessorType *)structPtr->new;
971
972p->header.type= kSMBTypeOemProcessorType;
973p->header.length= sizeof(SMBOemProcessorType);
974p->header.handle= handle++;
975
976setSMBValue(structPtr, numOfSetters - 2 , (returnType *)&(p->ProcessorType));
977
978structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorType) + 2);
979tableLength += sizeof(SMBOemProcessorType) + 2;
980structureCount++;
981}
982
983/* =================================================
984 OEM Processor Bus Speed (Apple Specific - Type 132)
985 =================================================== */
986void addSMBOemProcessorBusSpeed(SMBStructPtrs *structPtr)
987{
988SMBOemProcessorBusSpeed *p = (SMBOemProcessorBusSpeed *)structPtr->new;
989
990switch (Platform.CPU.Family)
991{
992case 0x06:
993{
994switch (Platform.CPU.Model)
995{
996case 0x19:// Intel Core i5 650 @3.20 Ghz
997case CPU_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
998case CPU_MODEL_DALES:
999case CPU_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
1000case CPU_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
1001case CPU_MODEL_NEHALEM_EX:// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x
1002case CPU_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
1003case CPU_MODEL_WESTMERE_EX:// Intel Xeon E7
1004case CPU_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
1005case CPU_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
1006case CPU_MODEL_IVYBRIDGE_XEON:
1007case CPU_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)
1008case CPU_MODEL_HASWELL: // Intel Core i3, i5, i7 LGA1150 LGA2011v3 (22nm)
1009case CPU_MODEL_HASWELL_SVR:
1010case CPU_MODEL_HASWELL_ULT:
1011case CPU_MODEL_CRYSTALWELL:
1012 case CPU_MODEL_BROADWELL: // Intel Core i3, i5, i7 LGA1150 LGA2011v3 (14nm)
1013 case CPU_MODEL_BRODWELL_SVR:
1014 case CPU_MODEL_BRODWELL_MSVR:
1015
1016break;
1017
1018default:
1019return;
1020}
1021}
1022}
1023
1024p->header.type= kSMBTypeOemProcessorBusSpeed;
1025p->header.length= sizeof(SMBOemProcessorBusSpeed);
1026p->header.handle= handle++;
1027
1028setSMBValue(structPtr, numOfSetters -1, (returnType *)&(p->ProcessorBusSpeed));
1029
1030structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorBusSpeed) + 2);
1031tableLength += sizeof(SMBOemProcessorBusSpeed) + 2;
1032structureCount++;
1033}
1034
1035/* ==============================================
1036 OEM Platform Feature (Apple Specific - Type 133)
1037 ================================================ */
1038 /*void addSMBOemPlatformFeature(SMBStructPtrs *structPtr) { }*/
1039
1040//-------------------------------------------------------------------------------------------------------------------------
1041// EndOfTable
1042//-------------------------------------------------------------------------------------------------------------------------
1043void addSMBEndOfTable(SMBStructPtrs *structPtr)
1044{
1045structPtr->new->type= kSMBTypeEndOfTable;
1046structPtr->new->length= sizeof(SMBStructHeader);
1047structPtr->new->handle= handle++;
1048
1049structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBStructHeader) + 2);
1050tableLength += sizeof(SMBStructHeader) + 2;
1051structureCount++;
1052}
1053
1054void setSMBStruct(SMBStructPtrs *structPtr)
1055{
1056bool setterFound = false;
1057
1058uint8_t *ptr;
1059SMBWord structSize;
1060int i;
1061
1062/* Bungo: not needed because of tables lengths fix in next lines
1063// http://forge.voodooprojects.org/p/chameleon/issues/361/
1064bool forceFullMemInfo = false;
1065
1066if (structPtr->orig->type == kSMBTypeMemoryDevice) {
1067getBoolForKey(kMemFullInfo, &forceFullMemInfo, &bootInfo->chameleonConfig);
1068if (forceFullMemInfo) {
1069structPtr->orig->length = 27;
1070}
1071}*/
1072
1073stringIndex = 1;
1074stringsSize = 0;
1075
1076if (handle < structPtr->orig->handle) {
1077handle = structPtr->orig->handle;
1078}
1079// Bungo: fix unsuported tables lengths from original smbios: extend smaller or truncate bigger - we use SMBIOS rev. 2.4 like Apple uses
1080switch (structPtr->orig->type) {
1081case kSMBTypeBIOSInformation:
1082structSize = sizeof(SMBBIOSInformation);
1083break;
1084case kSMBTypeSystemInformation:
1085structSize = sizeof(SMBSystemInformation);
1086break;
1087case kSMBTypeBaseBoard:
1088structSize = sizeof(SMBBaseBoard);
1089break;
1090case kSMBTypeSystemEnclosure:
1091structSize = sizeof(SMBSystemEnclosure);
1092break;
1093case kSMBTypeProcessorInformation:
1094structSize = sizeof(SMBProcessorInformation);
1095break;
1096case kSMBTypeMemoryDevice:
1097structSize = sizeof(SMBMemoryDevice);
1098break;
1099default:
1100structSize = structPtr->orig->length; // doesn't change a length for unpatched
1101break;
1102}
1103
1104// memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);
1105if (structPtr->orig->length <= structSize) {
1106memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);
1107} else {
1108memcpy((void *)structPtr->new, structPtr->orig, structSize);
1109}
1110
1111structPtr->new->length = structSize;
1112
1113for (i = 0; i < numOfSetters; i++) {
1114// Bungo:
1115//if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structPtr->orig->length)) {
1116if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structSize)) {
1117setterFound = true;
1118setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset));
1119}
1120}
1121
1122if (setterFound) {
1123// Bungo:
1124// ptr = (uint8_t *)structPtr->new + structPtr->orig->length;
1125ptr = (uint8_t *)structPtr->new + structPtr->new->length;
1126for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1127
1128if (((uint16_t *)ptr)[0] == 0) {
1129ptr += 2;
1130}
1131structSize = ptr - (uint8_t *)structPtr->new;
1132} else {
1133ptr = (uint8_t *)structPtr->orig + structPtr->orig->length;
1134for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1135
1136if (((uint16_t *)ptr)[0] == 0) {
1137ptr += 2;
1138}
1139
1140structSize = ptr - (uint8_t *)structPtr->orig;
1141memcpy((void *)structPtr->new, structPtr->orig, structSize);
1142}
1143
1144structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + structSize);
1145
1146tableLength += structSize;
1147
1148if (structSize > maxStructSize) {
1149maxStructSize = structSize;
1150}
1151
1152structureCount++;
1153}
1154
1155void setupNewSMBIOSTable(SMBEntryPoint *eps, SMBStructPtrs *structPtr)
1156{
1157uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress;
1158structPtr->orig = (SMBStructHeader *)ptr;
1159
1160for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));) {
1161switch (structPtr->orig->type) {
1162/* Skip all Apple Specific Structures */
1163case kSMBTypeFirmwareVolume:
1164case kSMBTypeMemorySPD:
1165case kSMBTypeOemProcessorType:
1166case kSMBTypeOemProcessorBusSpeed:
1167/* And this one too, to be added at the end */
1168case kSMBTypeEndOfTable:
1169break;
1170
1171default:
1172{
1173/* Add */
1174setSMBStruct(structPtr);
1175break;
1176}
1177}
1178
1179ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length);
1180for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1181
1182if (((uint16_t *)ptr)[0] == 0) {
1183ptr += 2;
1184}
1185
1186structPtr->orig = (SMBStructHeader *)ptr;
1187}
1188
1189addSMBFirmwareVolume(structPtr);
1190addSMBMemorySPD(structPtr);
1191addSMBOemProcessorType(structPtr);
1192addSMBOemProcessorBusSpeed(structPtr);
1193
1194addSMBEndOfTable(structPtr);
1195}
1196
1197// Bungo: does fix system uuid in SMBIOS (and EFI) instead of in EFI only
1198uint8_t *FixSystemUUID()
1199{
1200uint8_t *ptr = (uint8_t *)neweps->dmi.tableAddress;
1201SMBStructHeader *structHeader = (SMBStructHeader *)ptr;
1202int i, isZero, isOnes;
1203uint8_t FixedUUID[UUID_LEN] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
1204const char *sysId = getStringForKey(kSMBSystemInformationUUIDKey, SMBPlist);
1205uint8_t *ret = (uint8_t *)getUUIDFromString(sysId);
1206
1207for (;(structHeader->type != kSMBTypeSystemInformation);) // find System Information Table (Type 1) in patched SMBIOS
1208{
1209ptr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
1210for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1211
1212if (((uint16_t *)ptr)[0] == 0) {
1213ptr += 2;
1214}
1215
1216structHeader = (SMBStructHeader *)ptr;
1217}
1218
1219ptr = ((SMBSystemInformation *)structHeader)->uuid;
1220
1221if (!sysId || !ret) { // no or bad custom UUID,...
1222sysId = 0;
1223ret = Platform.UUID; // ...try bios dmi system uuid extraction
1224}
1225
1226for (i=0, isZero=1, isOnes=1; i<UUID_LEN; i++) // check if empty or setable, means: no uuid present
1227{
1228if (ret[i] != 0x00) {
1229isZero = 0;
1230}
1231
1232if (ret[i] != 0xff) {
1233isOnes = 0;
1234}
1235}
1236
1237if (isZero || isOnes) { // if empty or setable...
1238verbose("No UUID present in SMBIOS System Information Table\n");
1239ret = FixedUUID; // ...set a fixed value for system-id = 000102030405060708090A0B0C0D0E0F
1240}
1241
1242memcpy(ptr, ret, UUID_LEN); // fix uuid in the table
1243return ptr;
1244} // Bungo: end fix
1245
1246void setupSMBIOSTable(void)
1247{
1248SMBStructPtrs *structPtr;
1249uint8_t *buffer;
1250// bool setSMB = true; Bungo: now we use useSMBIOSdefaults
1251
1252if (!origeps) {
1253return;
1254}
1255
1256neweps = origeps;
1257
1258structPtr = (SMBStructPtrs *)malloc(sizeof(SMBStructPtrs));
1259if (!structPtr) {
1260return;
1261}
1262
1263buffer = (uint8_t *)malloc(SMB_ALLOC_SIZE);
1264if (!buffer) {
1265free(structPtr);
1266return;
1267}
1268
1269bzero(buffer, SMB_ALLOC_SIZE);
1270structPtr->new = (SMBStructHeader *)buffer;
1271
1272// getBoolForKey(kSMBIOSdefaults, &setSMB, &bootInfo->chameleonConfig); Bungo
1273getBoolForKey(kSMBIOSdefaults, &useSMBIOSdefaults, &bootInfo->chameleonConfig);
1274// if (setSMB) Bungo
1275setDefaultSMBData();
1276
1277setupNewSMBIOSTable(origeps, structPtr);
1278
1279neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint));
1280if (!neweps) {
1281free(buffer);
1282free(structPtr);
1283return;
1284}
1285bzero(neweps, sizeof(SMBEntryPoint));
1286
1287neweps->anchor[0]= '_';
1288neweps->anchor[1]= 'S';
1289neweps->anchor[2]= 'M';
1290neweps->anchor[3]= '_';
1291neweps->entryPointLength= sizeof(SMBEntryPoint);
1292neweps->majorVersion= 2; // Bungo:
1293neweps->minorVersion= 4; // Here we're using 2.4 SMBIOS rev. as real Macs
1294neweps->maxStructureSize= maxStructSize;
1295neweps->entryPointRevision= 0;
1296
1297neweps->dmi.anchor[0]= '_';
1298neweps->dmi.anchor[1]= 'D';
1299neweps->dmi.anchor[2]= 'M';
1300neweps->dmi.anchor[3]= 'I';
1301neweps->dmi.anchor[4]= '_';
1302neweps->dmi.tableLength= tableLength;
1303neweps->dmi.tableAddress= AllocateKernelMemory(tableLength);
1304neweps->dmi.structureCount= structureCount;
1305neweps->dmi.bcdRevision= 0x24; // ... and 2.4 DMI rev. as real Macs
1306
1307if (!neweps->dmi.tableAddress) {
1308free(buffer);
1309free(structPtr);
1310return;
1311}
1312
1313memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength);
1314
1315Platform.UUID = FixSystemUUID(); // Bungo: fix System UUID
1316
1317neweps->dmi.checksum= 0;
1318neweps->dmi.checksum= 0x100 - checksum8(&neweps->dmi, sizeof(DMIEntryPoint));
1319
1320neweps->checksum= 0;
1321neweps->checksum= 0x100 - checksum8(neweps, sizeof(SMBEntryPoint));
1322
1323free(buffer);
1324free(structPtr);
1325
1326decodeSMBIOSTable(neweps);
1327
1328DBG("SMBIOS orig was = %x\n", origeps);
1329DBG("SMBIOS new is = %x\n", neweps);
1330}
1331
1332void *getSmbios(int which)
1333{
1334switch (which) {
1335case SMBIOS_ORIGINAL:
1336if (!origeps) {
1337origeps = getAddressOfSmbiosTable();
1338}
1339return origeps;
1340case SMBIOS_PATCHED:
1341return neweps;
1342}
1343
1344return 0;
1345}
1346
1347/* Collect any information needed later */
1348void readSMBIOSInfo(SMBEntryPoint *eps)
1349{
1350uint8_t *structPtr = (uint8_t *)eps->dmi.tableAddress;
1351SMBStructHeader *structHeader = (SMBStructHeader *)structPtr;
1352
1353int dimmnbr = 0;
1354Platform.DMI.MaxMemorySlots= 0;// number of memory slots polulated by SMBIOS
1355Platform.DMI.CntMemorySlots= 0;// number of memory slots counted
1356Platform.DMI.MemoryModules= 0;
1357
1358for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));)
1359{
1360switch (structHeader->type)
1361{
1362case kSMBTypeSystemInformation:
1363Platform.UUID = ((SMBSystemInformation *)structHeader)->uuid; // get factory system uuid
1364break;
1365
1366case kSMBTypeSystemEnclosure: // Bungo: determine platform type
1367switch (((SMBSystemEnclosure *)structHeader)->chassisType) {
1368case kSMBchassisDesktop:
1369case kSMBchassisLPDesktop:
1370case kSMBchassisAllInOne:
1371case kSMBchassisLunchBox:
1372PlatformType = 1; // desktop (iMac, MacMini)
1373break;
1374case kSMBchassisPortable:
1375case kSMBchassisLaptop:
1376case kSMBchassisNotebook:
1377case kSMBchassisHandHeld:
1378case kSMBchassisSubNotebook:
1379PlatformType = 2; // notebook (Mac Books)
1380 break;
1381default:
1382PlatformType = 3; // workstation (Mac Pro, Xserve)
1383break;
1384}
1385break;
1386//
1387case kSMBTypePhysicalMemoryArray:
1388Platform.DMI.MaxMemorySlots += ((SMBPhysicalMemoryArray *)structHeader)->numMemoryDevices;
1389break;
1390
1391case kSMBTypeMemoryDevice:
1392Platform.DMI.CntMemorySlots++;
1393if (((SMBMemoryDevice *)structHeader)->memorySize != 0){
1394Platform.DMI.MemoryModules++;
1395}
1396if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0){
1397Platform.RAM.DIMM[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed;
1398}
1399dimmnbr++;
1400break;
1401default:
1402break;
1403}
1404
1405structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
1406for (; ((uint16_t *)structPtr)[0] != 0; structPtr++);
1407
1408if (((uint16_t *)structPtr)[0] == 0) {
1409structPtr += 2;
1410}
1411
1412structHeader = (SMBStructHeader *)structPtr;
1413}
1414}
1415

Archive Download this file

Revision: 2658