Chameleon

Chameleon Svn Source Tree

Root/branches/Bungo/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
391uint64_t smbios_p = 0;
392
393SMBEntryPoint *origeps= 0;
394SMBEntryPoint *neweps= 0;
395
396static uint8_t stringIndex;// increament when a string is added and set the field value accordingly
397static uint8_t stringsSize;// add string size
398
399static SMBWord tableLength= 0;
400static SMBWord handle= 0;
401static SMBWord maxStructSize= 0;
402static SMBWord structureCount= 0;
403
404//-------------------------------------------------------------------------------------------------------------------------
405// Default SMBIOS Data
406//-------------------------------------------------------------------------------------------------------------------------
407/* Rewrite: use a struct */
408
409// Bungo: suggest to not mixing data from different Mac models, use real Mac SMBIOS dumps
410
411#define kDefaultVendorManufacturer"Apple Inc."
412//#define kDefaultBIOSReleaseDate"11/06/2009"
413#define kDefaultSerialNumber"SOMESRLNMBR"
414//Bungo
415#define kDefaultSkuNumber"Default SKU#"
416#define kDefaultAssetTag"Default Asset Tag#"
417//#define kDefaultBoardType"10" // 0xA
418//#define kDefaultBoardProcessorType"11" // 0xB
419#define kDefaultSystemVersion"1.0"
420#define kDefaultBIOSRelease256 // 256 = 0x0100 -> swap bytes: 0x0001 -> Release: 0.1 (see SMBIOS spec. table Type 0)
421//#define kDefaultLocatioInChassis"Part Component"
422//#define KDefaultBoardSerialNumber"C02140302D5DMT31M" // new C07019501PLDCVHAD - C02032101R5DC771H
423
424//=========== Mac mini ===========
425#define kDefaultMacMiniFamily"Napa Mac" // Macmini2,1 family = "Napa Mac" not "Mac mini"
426//#define kDefaultMacMiniBoardAssetTagNumber"Mini-Aluminum"
427
428#define kDefaultMacMini"Macmini2,1"
429#define kDefaultMacMiniBIOSVersion" MM21.88Z.009A.B00.0706281359"
430#define kDefaultMacMiniBIOSReleaseDate"06/28/07"
431#define kDefaultMacMiniBoardProduct"Mac-F4208EAA"
432
433// MacMini5,1 Mac-8ED6AF5B48C039E1 - MM51.88Z.0077.B0F.1110201309
434
435// MacMini5,2 Mac-4BC72D62AD45599E
436
437// MacMini5,3
438// Bios: MM51.88Z.0077.B10.1201241549
439// Board: Mac-F65AE981FFA204ED
440// Data: 01/24/2012
441
442// MacMini 6,1
443// Bios: MM61.88Z.0106.B03.1211161202
444// Board: Mac-F65AE981FFA204ED
445// Data: 10/14/2012
446
447// MacMini 6,2
448// Bios: MM61.88Z.0106.B03.1211161202
449// Board: Mac-FC02E91DDD3FA6A4
450// Data: 10/14/2012
451
452//=========== MacBook ===========
453#define kDefaultMacBookFamily"MacBook"
454//#define kDefaultMacBookBoardAssetTagNumber"MacBook-Black"
455
456#define kDefaultMacBook"MacBook4,1"
457#define kDefaultMacBookBIOSVersion" MB41.88Z.00C1.B00.0802091535"
458#define kDefaultMacBookBIOSReleaseDate"02/09/08"
459#define kDefaultMacBookBoardProduct"Mac-F22788A9"
460
461//=========== MacBookAir ===========
462#define kDefaultMacBookAirFamily"MacBook Air"
463
464// MacBookAir4,1 - Mac-C08A6BB70A942AC2
465// MacBookAir4,2 - Mac-742912EFDBEE19B3
466
467// MacBookAir5,2
468#define kDefaultMacBookAir"MacBookAir5,2"
469#define kDefaultMacBookAirBIOSVersion" MBA51.88Z.00EF.B00.1205221442"
470#define kDefaultMacBookAirBIOSReleaseDate"05/10/12"
471#define kDefaultMacBookBoardAirProduct"Mac-2E6FAB96566FE58C"
472
473// MacBookAir6,1
474// Bios: MBA61.88Z.0099.B04.1309271229
475// Board: Mac-35C1E88140C3E6CF
476// Data: 24/06/13
477
478// MacBookAir6,2
479// Bios: MBA62.88Z.00EF.B00.1205221442
480// Board: Mac-7DF21CB3ED6977E5
481// Data: 24/06/13
482
483//=========== MacBookPro ===========
484#define kDefaultMacBookProFamily"MacBook Pro"
485//#define kDefaultMacBookProBoardAssetTagNumber"MacBook-Aluminum"
486
487#define kDefaultMacBookPro"MacBookPro4,1"
488#define kDefaultMacBookProBIOSVersion" MBP41.88Z.00C1.B03.0802271651"
489#define kDefaultMacBookProBIOSReleaseDate"02/27/08"
490#define kDefaultMacBookProBoardProduct"Mac-F42C89C8"
491
492// MacBookPro8,1
493// Bios: MBP81.88Z.0047.B24.1110141131
494// Board: Mac-94245B3640C91C81
495// Data: 10/14/11
496
497// MacBookPro8,2
498// Bios:
499// Board: Mac_94245A3940C91C80
500// Data: 10/14/11
501
502// MacBookPro8,3
503// Bios:
504// Board: Mac-942459F5819B171B
505// Data: 10/31/11
506
507// MacBookPro10,2
508// Bios: MBP102.88Z.0106.B01.1208311637
509// Board: Mac-AFD8A9D944EA4843
510// Data: 10/02/2012
511
512// MacBookPro11,2 - Mac-3CBD00234E554E41 - MBP112.88Z.0138.B03.1310291227
513// MacBookPro11,3 - Mac-2BD1B31983FE1663 - MBP112.88Z.0138.B02.1310181745
514
515//=========== iMac ===========
516#define kDefaultiMacFamily"iMac"
517//#define kDefaultiMacBoardAssetTagNumber"iMac-Aluminum"
518
519#define kDefaultiMac"iMac8,1"
520#define kDefaultiMacBIOSVersion" IM81.88Z.00C1.B00.0903051113"
521#define kDefaultiMacBIOSReleaseDate"02/09/08"
522#define kDefaultiMacBoardProduct"Mac-F227BEC8"
523#define kDefaultMacFamily"Mac" // iMac8,1 family = "Mac" not "iMac"
524
525// iMac10,1
526// iMac11,1 core i3/i5/i7
527#define kDefaultiMacNehalem"iMac11,1"
528#define kDefaultiMacNehalemBIOSVersion" IM111.88Z.0034.B02.1003171314"
529#define kDefaultiMacNehalemBIOSReleaseDate"03/17/10"
530#define kDefaultiMacNehalemBoardProduct"Mac-F2268DAE"
531// iMac11,2
532// iMac11,3
533
534// iMac12,1
535#define kDefaultiMacSandy"iMac12,1"
536#define kDefaultiMacSandyBIOSVersion" IM121.88Z.0047.B00.1102091756"
537#define kDefaultiMacSandyBIOSReleaseDate"04/22/11"
538#define kDefaultiMacSandyBoardProduct"Mac-942B5BF58194151B"
539
540// iMac12,2
541// Bios: IM121.88Z.0047.B1D.1110171110"
542// Data: 10/17/11
543// Board: Mac-942B59F58194171B"
544
545// iMac13,1
546// Bios: IM131.88Z.010A.B05.1211151146
547// Data: 11/15/2012
548// Board: Mac-00BE6ED71E35EB86
549
550// iMac13,2
551// Bios: IM131.88Z.00CE.B00.1203281326
552// Data: 03/28/2012
553// Board: Mac-FC02E91DDD3FA6A4
554
555// iMac14,1
556// iMac14,2
557// iMac14,3
558// iMac14,4
559// Bios: IM144.88Z.0179.B03.1405241029
560// Data: 05/20/2014
561// Board: Mac-81E3E92DD6088272
562
563//=========== MacPro ===========
564#define kDefaultMacProFamily"MacPro" // MacPro's family = "MacPro" not "Mac Pro"
565//#define KDefauktMacProBoardAssetTagNumber"Pro-Enclosure"
566//#define kDefaultMacProBoardType"0xB" // 11
567
568#define kDefaultMacPro"MacPro3,1"
569#define kDefaultMacProBIOSVersion" MP31.88Z.006C.B05.0903051113"
570#define kDefaultMacProBIOSReleaseDate"08/03/2010"
571//#define kDefaultMacProSystemVersion"1.3"
572#define kDefaultMacProBoardProduct"Mac-F42C88C8"
573//#define KDefaultMacProBoardSerialNumber"J593902RA4MFE"
574
575// Mac Pro 4,1 core i7/Xeon
576#define kDefaultMacProNahWestSystemVersion"0.0"
577
578#define kDefaultMacProNehalem"MacPro4,1"
579#define kDefaultMacProNehalemBIOSVersion" MP41.88Z.0081.B07.0910130729"
580#define kDefaultMacProNehalemBIOSReleaseDate"10/13/09"
581//#define kDefaultMacProNehalemSystemVersion"1.4"
582#define kDefaultMacProNehalemBoardProduct"Mac-F221BEC8"
583//#define KDefaultMacProNehalemBoardSerialNumber"J593004RB1LUE"
584//"J591302R61LUC " // 2-cpu board
585//"J591002JV4MFB " // 1-cpu board
586
587// Mac Pro 5,1 core i7/Xeon
588#define kDefaultMacProWestmere"MacPro5,1"
589#define kDefaultMacProWestmereBIOSVersion" MP51.88Z.007F.B03.1010071432"
590#define kDefaultMacProWestmereBIOSReleaseDate"10/07/10"
591//#define kDefaultMacProWestmereSystemVersion"1.2"
592#define kDefaultMacProWestmereBoardProduct"Mac-F221BEC8"
593//#define KDefaultMacProWestmereBoardSerialNumber"J522700H7BH8C"
594//"J503104H1BH8A " // 2-cpu board
595
596// Mac Pro 6,1
597#define kDefaultMacProHaswell"MacPro6,1"
598#define kDefaultMacProHaswellBIOSVersion"MP61.88Z.0116.B04.1312061508"
599#define kDefaultMacProHaswellBIOSReleaseDate"12/06/2013"
600//#define kDefaultMacProHaswellSystemVersion"1.?"
601#define kDefaultMacProHaswellBoardProduct"Mac-F60DEB81FF30ACF6"
602//#define KDefaultMacProHaswellBoardSerialNumber"F5K3474008JFNN215"
603
604//#define KDefaultBoardSerialNumber"C02140302D5DMT31M"
605// "C07019501PLDCVHAD"
606// "C02032101R5DC771H"
607
608// J593902RA4MFE 3,1
609// J5031046RCZJA 5,1
610// J521101A5CZJC 3,1
611// J593004RB1LUE MacPro4,1
612// J513401PZBH8C 5,1
613// J590802LC4ACB 3,1
614// J594900AH1LUE 4,1
615// J512500HZBH8C 5,1
616// J522700H7BH8C MacPro5,1
617
618/* ============================================ */
619
620bool useSMBIOSdefaults = true;// Bungo
621/** FIXED
622SMBByte 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.
623**/
624/* Rewrite this function */
625void setDefaultSMBData(void) // Bungo: setting data from real Macs
626{
627defaultBIOSInfo.vendor = kDefaultVendorManufacturer;
628defaultBIOSInfo.release = kDefaultBIOSRelease; // Bungo
629
630defaultSystemInfo.manufacturer = kDefaultVendorManufacturer;
631defaultSystemInfo.version = kDefaultSystemVersion;
632defaultSystemInfo.serialNumber = kDefaultSerialNumber;
633defaultSystemInfo.skuNumber = kDefaultSkuNumber; // Bungo
634
635defaultBaseBoard.manufacturer = kDefaultVendorManufacturer;
636defaultBaseBoard.serialNumber = kDefaultSerialNumber;
637defaultBaseBoard.assetTag = kDefaultAssetTag;
638
639defaultChassis.manufacturer = kDefaultVendorManufacturer;
640defaultChassis.serialNumber = kDefaultSerialNumber;
641defaultChassis.assetTag = kDefaultAssetTag;
642defaultChassis.skuNumber = kDefaultSkuNumber;
643
644if (Platform.Type == 2)
645{
646if (Platform.CPU.NoCores > 1)
647{
648defaultSystemInfo.productName = kDefaultMacBookPro;
649defaultBIOSInfo.version = kDefaultMacBookProBIOSVersion;
650defaultBIOSInfo.releaseDate = kDefaultMacBookProBIOSReleaseDate;
651defaultSystemInfo.family = kDefaultMacBookProFamily;
652defaultBaseBoard.product = kDefaultMacBookProBoardProduct;
653defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
654defaultChassis.chassisType = kSMBchassisUnknown;
655}
656else
657{
658defaultSystemInfo.productName = kDefaultMacBook;
659defaultBIOSInfo.version = kDefaultMacBookBIOSVersion;
660defaultBIOSInfo.releaseDate = kDefaultMacBookBIOSReleaseDate;
661defaultSystemInfo.family = kDefaultMacBookFamily;
662defaultBaseBoard.product = kDefaultMacBookBoardProduct;
663defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
664defaultChassis.chassisType = kSMBchassisUnknown;
665}
666}
667else
668{
669switch (Platform.CPU.NoCores)
670{
671case 1:
672defaultBIOSInfo.version = kDefaultMacMiniBIOSVersion;
673defaultBIOSInfo.releaseDate = kDefaultMacMiniBIOSReleaseDate;
674defaultSystemInfo.productName = kDefaultMacMini;
675defaultSystemInfo.family = kDefaultMacMiniFamily;
676defaultBaseBoard.product = kDefaultMacMiniBoardProduct;
677defaultBaseBoard.boardType = kSMBBaseBoardUnknown;
678defaultChassis.chassisType = kSMBchassisLPDesktop;
679break;
680
681case 2:
682defaultBIOSInfo.version = kDefaultiMacBIOSVersion;
683defaultBIOSInfo.releaseDate = kDefaultiMacBIOSReleaseDate;
684defaultSystemInfo.productName = kDefaultiMac;
685defaultSystemInfo.family = kDefaultMacFamily; // iMac8,1 family = Mac
686defaultBaseBoard.product = kDefaultiMacBoardProduct;
687defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
688defaultChassis.chassisType = kSMBchassisAllInOne;
689break;
690default:
691{
692switch (Platform.CPU.Family)
693{
694case 0x06:
695{
696switch (Platform.CPU.Model)
697{
698case CPUID_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
699case CPUID_MODEL_DALES:
700case CPUID_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
701defaultBIOSInfo.version= kDefaultiMacNehalemBIOSVersion;
702defaultBIOSInfo.releaseDate= kDefaultiMacNehalemBIOSReleaseDate;
703defaultSystemInfo.productName= kDefaultiMacNehalem;
704defaultSystemInfo.family= kDefaultiMacFamily;
705defaultBaseBoard.product = kDefaultiMacNehalemBoardProduct;
706defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
707defaultChassis.chassisType = kSMBchassisAllInOne;
708break;
709
710case CPUID_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
711case CPUID_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
712defaultBIOSInfo.version = kDefaultiMacSandyBIOSVersion;
713defaultBIOSInfo.releaseDate = kDefaultiMacSandyBIOSReleaseDate;
714defaultSystemInfo.productName= kDefaultiMacSandy;
715defaultSystemInfo.family = kDefaultiMacFamily;
716defaultBaseBoard.product = kDefaultiMacSandyBoardProduct;
717defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
718defaultChassis.chassisType = kSMBchassisAllInOne;
719break;
720
721case CPUID_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
722case CPUID_MODEL_NEHALEM_EX:// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x
723defaultBIOSInfo.version= kDefaultMacProNehalemBIOSVersion;
724defaultBIOSInfo.releaseDate= kDefaultMacProNehalemBIOSReleaseDate;
725defaultSystemInfo.productName= kDefaultMacProNehalem;
726defaultSystemInfo.version = kDefaultMacProNahWestSystemVersion;
727defaultSystemInfo.family= kDefaultMacProFamily;
728defaultBaseBoard.product = kDefaultMacProNehalemBoardProduct;
729defaultBaseBoard.boardType = kSMBBaseBoardProcessorMemoryModule;
730defaultChassis.chassisType = kSMBchassisTower;
731break;
732
733case CPUID_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
734case CPUID_MODEL_WESTMERE_EX:// Intel Xeon E7
735case CPUID_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)
736case CPUID_MODEL_IVYBRIDGE_EP:// Intel Core i7, Xeon E5 v2 LGA2011 (22nm)
737defaultBIOSInfo.version= kDefaultMacProWestmereBIOSVersion;
738defaultBIOSInfo.releaseDate= kDefaultMacProWestmereBIOSReleaseDate;
739defaultSystemInfo.productName= kDefaultMacProWestmere;
740defaultSystemInfo.version = kDefaultMacProNahWestSystemVersion;
741defaultSystemInfo.family= kDefaultMacProFamily;
742defaultBaseBoard.product = kDefaultMacProWestmereBoardProduct;
743defaultBaseBoard.boardType = kSMBBaseBoardProcessorMemoryModule;
744defaultChassis.chassisType = kSMBchassisTower;
745break;
746
747default:
748defaultBIOSInfo.version= kDefaultMacProBIOSVersion;
749defaultBIOSInfo.releaseDate= kDefaultMacProBIOSReleaseDate;
750defaultSystemInfo.productName= kDefaultMacPro;
751defaultSystemInfo.family= kDefaultMacProFamily;
752defaultBaseBoard.product = kDefaultMacProBoardProduct;
753defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
754defaultChassis.chassisType = kSMBchassisUnknown;
755break;
756}
757break;
758}
759default:
760defaultBIOSInfo.version= kDefaultMacProBIOSVersion;
761defaultBIOSInfo.releaseDate= kDefaultMacProBIOSReleaseDate;
762defaultSystemInfo.productName= kDefaultMacPro;
763defaultSystemInfo.family= kDefaultMacProFamily;
764defaultBaseBoard.product = kDefaultMacProBoardProduct;
765defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
766defaultChassis.chassisType = kSMBchassisUnknown;
767break;
768}
769break;
770}
771}
772}
773}
774
775/* Used for SM*n smbios.plist keys */
776bool getSMBValueForKey(SMBStructHeader *structHeader, const char *keyString, const char **string, returnType *value)
777{
778static int idx = -1;
779static int current = -1;
780int len;
781char key[24];
782
783if (current != structHeader->handle)
784{
785idx++;
786current = structHeader->handle;
787}
788
789sprintf(key, "%s%d", keyString, idx);
790
791if (value)
792{
793if (getIntForKey(key, (int *)&(value->dword), SMBPlist))
794{
795return true;
796}
797}
798else
799{
800if (getValueForKey(key, string, &len, SMBPlist))
801{
802return true;
803}
804}
805return false;
806}
807
808char *getSMBStringForField(SMBStructHeader *structHeader, uint8_t field)
809{
810if (!field || !structHeader)
811{
812return NULL;
813}
814
815uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length;
816
817for (field--; (field > 0) && (*stringPtr > 0) &&(*(uint16_t *)stringPtr != 0);
818field--, stringPtr = (uint8_t *)((uint32_t)stringPtr + strlen((char *)stringPtr) + 1));
819
820return (char *)stringPtr;
821}
822
823void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field)
824{
825int strSize;
826
827if (!field)
828{
829return;
830}
831
832if (!string)
833{
834*field = 0;
835return;
836}
837
838strSize = strlen(string);
839
840// remove any spaces found at the end but only in MemoryDevice avoiding errors
841if (structHeader->type == kSMBTypeMemoryDevice)
842{
843while ((strSize != 0) && (string[strSize - 1] == ' '))
844{
845strSize--;
846}
847}
848
849if (strSize == 0)
850{
851*field = 0;
852return;
853}
854
855memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize);
856*field = stringIndex;
857
858stringIndex++;
859stringsSize += strSize + 1;
860}
861
862bool setSMBValue(SMBStructPtrs *structPtr, int idx, returnType *value)
863{
864const char *string = 0;
865int len;
866bool parsed;
867int val;
868
869if (numOfSetters <= idx)
870{
871return false;
872}
873
874switch (SMBSetters[idx].valueType)
875{
876case kSMBString:
877{
878if (SMBSetters[idx].keyString)
879{
880if (getValueForKey(SMBSetters[idx].keyString, &string, &len, SMBPlist))
881{
882break;
883}
884else
885{
886if (structPtr->orig->type == kSMBTypeMemoryDevice)// MemoryDevice only
887{
888if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, &string, NULL))
889{
890break;
891}
892}
893}
894
895}
896if (SMBSetters[idx].getSMBValue)
897{
898if (SMBSetters[idx].getSMBValue((returnType *)&string))
899{
900break;
901}
902}
903// if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue)) Bungo
904if (useSMBIOSdefaults && SMBSetters[idx].defaultValue && *(SMBSetters[idx].defaultValue))
905{
906string = *(SMBSetters[idx].defaultValue);
907break;
908}
909string = getSMBStringForField(structPtr->orig, *(uint8_t *)value);
910break;
911}
912
913case kSMBByte:
914case kSMBWord:
915case kSMBDWord:
916case kSMBQWord:
917if (SMBSetters[idx].keyString)
918{
919parsed = getIntForKey(SMBSetters[idx].keyString, &val, SMBPlist);
920if (!parsed)
921{
922if (structPtr->orig->type == kSMBTypeMemoryDevice) // MemoryDevice only
923{
924parsed = getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, (returnType *)&val);
925}
926}
927
928if (parsed)
929{
930switch (SMBSetters[idx].valueType)
931{
932case kSMBByte:
933value->byte = (uint8_t)val;
934break;
935case kSMBWord:
936value->word = (uint16_t)val;
937break;
938case kSMBQWord:
939value->qword = (uint64_t)val;
940break;
941case kSMBDWord:
942default:
943value->dword = (uint32_t)val;
944break;
945}
946return true;
947}
948}
949
950if (SMBSetters[idx].getSMBValue)
951{
952if (SMBSetters[idx].getSMBValue(value))
953{
954return true;
955}
956}
957// #if 0 Bungo: enables code below
958// if (*(SMBSetters[idx].defaultValue)) Bungo
959if (useSMBIOSdefaults && SMBSetters[idx].defaultValue && *(SMBSetters[idx].defaultValue))
960{
961// value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue); Bungo
962switch (SMBSetters[idx].valueType) {
963case kSMBByte:
964value->byte = *(uint8_t *)(SMBSetters[idx].defaultValue);
965break;
966case kSMBWord:
967value->word = *(uint16_t *)(SMBSetters[idx].defaultValue);
968break;
969case kSMBQWord:
970value->qword = *(uint64_t *)(SMBSetters[idx].defaultValue);
971break;
972case kSMBDWord:
973default:
974value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue);
975break;
976}
977return true;
978}
979// #endif Bungo
980break;
981}
982
983// if (SMBSetters[idx].valueType == kSMBString && string) Bungo: use null string too -> "Not Specified"
984if ((SMBSetters[idx].valueType == kSMBString) && string)
985{
986setSMBStringForField(structPtr->new, string, &value->byte);
987}
988return true;
989}
990
991//-------------------------------------------------------------------------------------------------------------------------
992// Apple Specific
993//-------------------------------------------------------------------------------------------------------------------------
994
995/* ===========================================
996 Firmware Volume (Apple Specific - Type 128)
997 ============================================= */
998void addSMBFirmwareVolume(SMBStructPtrs *structPtr)
999{
1000return;
1001}
1002
1003/* ===========================================
1004 Memory SPD Data (Apple Specific - Type 130)
1005 ============================================= */
1006void addSMBMemorySPD(SMBStructPtrs *structPtr)
1007{
1008/* SPD data from Platform.RAM.spd */
1009return;
1010}
1011
1012/* ============================================
1013 OEM Processor Type (Apple Specific - Type 131)
1014 ============================================== */
1015void addSMBOemProcessorType(SMBStructPtrs *structPtr)
1016{
1017SMBOemProcessorType *p = (SMBOemProcessorType *)structPtr->new;
1018
1019p->header.type= kSMBTypeOemProcessorType;
1020p->header.length= sizeof(SMBOemProcessorType);
1021p->header.handle= handle++;
1022
1023setSMBValue(structPtr, numOfSetters - 2 , (returnType *)&(p->ProcessorType));
1024
1025structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorType) + 2);
1026tableLength += sizeof(SMBOemProcessorType) + 2;
1027structureCount++;
1028}
1029
1030/* =================================================
1031 OEM Processor Bus Speed (Apple Specific - Type 132)
1032 =================================================== */
1033bool addSMBOemProcessorBusSpeed(SMBStructPtrs *structPtr)
1034{
1035SMBOemProcessorBusSpeed *p = (SMBOemProcessorBusSpeed *)structPtr->new;
1036
1037if (Platform.CPU.Vendor != CPUID_VENDOR_INTEL)
1038{
1039return false;
1040}
1041
1042switch (Platform.CPU.Family)
1043{
1044case 0x06:
1045switch (Platform.CPU.Model)
1046{
1047case 0x19:// Intel Core i5 650 @3.20 Ghz
1048case CPUID_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156, (45nm)
1049case CPUID_MODEL_DALES: // Intel Core i5, i7, Xeon, (45nm), integrated GPU
1050case CPUID_MODEL_DALES_32NM:// Intel Core i3, i5, Xeon, (32nm), integrated GPU
1051case CPUID_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
1052case CPUID_MODEL_NEHALEM_EX:// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x
1053case CPUID_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
1054case CPUID_MODEL_WESTMERE_EX:// Intel Xeon E7
1055case CPUID_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
1056case CPUID_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
1057case CPUID_MODEL_IVYBRIDGE_EP:
1058case CPUID_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)
1059case CPUID_MODEL_HASWELL:
1060case CPUID_MODEL_HASWELL_SVR:
1061case CPUID_MODEL_HASWELL_ULT:
1062case CPUID_MODEL_CRYSTALWELL:
1063p->header.type= kSMBTypeOemProcessorBusSpeed;
1064p->header.length= sizeof(SMBOemProcessorBusSpeed);
1065p->header.handle= handle++;
1066
1067setSMBValue(structPtr, numOfSetters - 1, (returnType *)&(p->ProcessorBusSpeed));
1068
1069structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorBusSpeed) + 2);
1070tableLength += sizeof(SMBOemProcessorBusSpeed) + 2;
1071structureCount++;
1072
1073return true;
1074
1075default:
1076break;
1077}
1078break;
1079
1080default:
1081break;
1082}
1083
1084return false;
1085}
1086
1087/* ==============================================
1088 OEM Platform Feature (Apple Specific - Type 133)
1089 ================================================ */
1090/*
1091void addSMBOemPlatformFeature(SMBStructPtrs *structPtr)
1092{
1093SMBOemPlatformFeature *p = (SMBOemPlatformFeature *)structPtr->new;
1094
1095p->header.type= kSMBTypeOemPlatformFeature;
1096p->header.length= sizeof(SMBOemPlatformFeature);
1097p->header.handle= handle++;
1098
1099setSMBValue(structPtr, numOfSetters - 2 , (returnType *)&(p->PlatformFeature));
1100
1101structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemPPlatformFeature) + 2);
1102tableLength += sizeof(SMBOemPlatformFeature) + 2;
1103structureCount++;
1104 }
1105*/
1106
1107//-------------------------------------------------------------------------------------------------------------------------
1108// EndOfTable
1109//-------------------------------------------------------------------------------------------------------------------------
1110void addSMBEndOfTable(SMBStructPtrs *structPtr)
1111{
1112structPtr->new->type= kSMBTypeEndOfTable;
1113structPtr->new->length= sizeof(SMBStructHeader);
1114structPtr->new->handle= 0xFFFD; // real Macs set this value here // handle++;
1115
1116structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBStructHeader) + 2);
1117tableLength += sizeof(SMBStructHeader) + 2;
1118structureCount++;
1119}
1120
1121void setSMBStruct(SMBStructPtrs *structPtr)
1122{
1123bool setterFound = false;
1124
1125uint8_t *ptr;
1126SMBWord structSize;
1127int i;
1128
1129/* Bungo: not needed because of tables' lengths fix in next lines
1130// http://forge.voodooprojects.org/p/chameleon/issues/361/
1131bool forceFullMemInfo = false;
1132
1133if (structPtr->orig->type == kSMBTypeMemoryDevice)
1134{
1135getBoolForKey(kMemFullInfo, &forceFullMemInfo, &bootInfo->chameleonConfig);
1136if (forceFullMemInfo)
1137{
1138structPtr->orig->length = 27;
1139}
1140}*/
1141
1142stringIndex = 1;
1143stringsSize = 0;
1144
1145if (handle < structPtr->orig->handle)
1146{
1147handle = structPtr->orig->handle;
1148}
1149// Bungo: fix unsuported tables lengths from original smbios: extend shorter or truncate longer - we use SMBIOS rev. 2.4 like Apple uses
1150switch (structPtr->orig->type)
1151{
1152case kSMBTypeBIOSInformation:
1153structSize = sizeof(SMBBIOSInformation);
1154break;
1155case kSMBTypeSystemInformation:
1156structSize = sizeof(SMBSystemInformation);
1157break;
1158case kSMBTypeBaseBoard:
1159structSize = sizeof(SMBBaseBoard);
1160break;
1161case kSMBTypeSystemEnclosure:
1162structSize = sizeof(SMBSystemEnclosure);
1163break;
1164case kSMBTypeProcessorInformation:
1165structSize = sizeof(SMBProcessorInformation);
1166break;
1167case kSMBTypeMemoryDevice:
1168structSize = sizeof(SMBMemoryDevice);
1169break;
1170default:
1171structSize = structPtr->orig->length; // doesn't change a length for unpatched
1172break;
1173}
1174
1175// memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);
1176if (structPtr->orig->length <= structSize)
1177{
1178memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);
1179}
1180else
1181{
1182memcpy((void *)structPtr->new, structPtr->orig, structSize);
1183}
1184
1185structPtr->new->length = structSize;
1186
1187for (i = 0; i < numOfSetters; i++)
1188{
1189// Bungo:
1190//if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structPtr->orig->length)) {
1191if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structSize))
1192{
1193setterFound = true;
1194setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset));
1195}
1196}
1197
1198if (setterFound)
1199{
1200// Bungo:
1201// ptr = (uint8_t *)structPtr->new + structPtr->orig->length;
1202ptr = (uint8_t *)structPtr->new + structPtr->new->length;
1203for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1204
1205if (((uint16_t *)ptr)[0] == 0)
1206{
1207ptr += 2;
1208}
1209structSize = ptr - (uint8_t *)structPtr->new;
1210}
1211else
1212{
1213ptr = (uint8_t *)structPtr->orig + structPtr->orig->length;
1214for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1215
1216if (((uint16_t *)ptr)[0] == 0)
1217{
1218ptr += 2;
1219}
1220
1221structSize = ptr - (uint8_t *)structPtr->orig;
1222memcpy((void *)structPtr->new, structPtr->orig, structSize);
1223}
1224
1225structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + structSize);
1226
1227tableLength += structSize;
1228
1229if (structSize > maxStructSize)
1230{
1231maxStructSize = structSize;
1232}
1233
1234structureCount++;
1235}
1236
1237void setupNewSMBIOSTable(SMBEntryPoint *eps, SMBStructPtrs *structPtr)
1238{
1239uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress;
1240structPtr->orig = (SMBStructHeader *)ptr;
1241
1242for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));) {
1243switch (structPtr->orig->type) {
1244/* Skip all Apple Specific Structures */
1245case kSMBTypeFirmwareVolume:
1246case kSMBTypeMemorySPD:
1247case kSMBTypeOemProcessorType:
1248case kSMBTypeOemProcessorBusSpeed:
1249/* And this one too, to be added at the end */
1250case kSMBTypeEndOfTable:
1251break;
1252
1253default:
1254{
1255/* Add */
1256setSMBStruct(structPtr);
1257break;
1258}
1259}
1260
1261ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length);
1262for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1263
1264if (((uint16_t *)ptr)[0] == 0)
1265{
1266ptr += 2;
1267}
1268
1269structPtr->orig = (SMBStructHeader *)ptr;
1270}
1271
1272addSMBFirmwareVolume(structPtr);
1273addSMBMemorySPD(structPtr);
1274addSMBOemProcessorType(structPtr);
1275addSMBOemProcessorBusSpeed(structPtr);
1276
1277addSMBEndOfTable(structPtr);
1278}
1279
1280// Bungo: does fix system uuid in SMBIOS & EFI instead of in EFI (IODT/efi/platform/system-id) only
1281uint8_t *fixSystemUUID()
1282{
1283uint8_t *ptr = (uint8_t *)neweps->dmi.tableAddress;
1284SMBStructHeader *structHeader = (SMBStructHeader *)ptr;
1285int i, isZero, isOnes;
1286uint8_t fixedUUID[UUID_LEN] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
1287const char *sysId = getStringForKey(kSMBSystemInformationUUIDKey, SMBPlist); // try to get user's uuid from smbios.plist
1288uint8_t *ret = (uint8_t *)getUUIDFromString(sysId); // convert user's uuid from string
1289
1290for (;(structHeader->type != kSMBTypeSystemInformation);) // find System Information Table (Type 1) in patched SMBIOS
1291{
1292ptr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
1293for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1294
1295if (((uint16_t *)ptr)[0] == 0)
1296{
1297ptr += 2;
1298}
1299
1300structHeader = (SMBStructHeader *)ptr;
1301}
1302
1303ptr = ((SMBSystemInformation *)structHeader)->uuid;
1304
1305if (!sysId || !ret) // no or bad custom uuid,...
1306{
1307sysId = 0;
1308ret = Platform.UUID; // ...use original (factory) system uuid
1309}
1310
1311for (i = 0, isZero = 1, isOnes = 1; i < UUID_LEN; i++) // check if empty (zeroed) or setable (FFed), means: no uuid present
1312{
1313if (ret[i] != 0x00)
1314{
1315isZero = 0;
1316}
1317
1318if (ret[i] != 0xff)
1319{
1320isOnes = 0;
1321}
1322}
1323
1324if (isZero || isOnes) { // if empty or setable...
1325verbose("System UUID: incorrect or not present. Fixing [00112233-4455-6677-8899-AABBCCDDEEFF]\n");
1326ret = fixedUUID; // ...set a fixed value for system uuid: <00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF>
1327}
1328
1329memcpy(ptr, ret, UUID_LEN); // save uuid into the patched SMBIOS Table 1
1330
1331return ptr;
1332} // Bungo: end fix
1333
1334void setupSMBIOS(void)
1335{
1336SMBStructPtrs *structPtr;
1337uint8_t *buffer;
1338// bool setSMB = true; Bungo: now we use useSMBIOSdefaults
1339
1340if (!origeps)
1341{
1342return;
1343}
1344
1345neweps = origeps;
1346
1347structPtr = (SMBStructPtrs *)malloc(sizeof(SMBStructPtrs));
1348if (!structPtr)
1349{
1350return;
1351}
1352
1353buffer = (uint8_t *)malloc(SMB_ALLOC_SIZE);
1354if (!buffer)
1355{
1356free(structPtr);
1357return;
1358}
1359
1360bzero(buffer, SMB_ALLOC_SIZE);
1361structPtr->new = (SMBStructHeader *)buffer;
1362
1363//Bungo:
1364//getBoolForKey(kSMBIOSdefaults, &setSMB, &bootInfo->chameleonConfig);
1365getBoolForKey(kSMBIOSdefaults, &useSMBIOSdefaults, &bootInfo->chameleonConfig);
1366// if (setSMB)
1367setDefaultSMBData();
1368
1369setupNewSMBIOSTable(origeps, structPtr);
1370
1371neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint));
1372if (!neweps)
1373{
1374free(buffer);
1375free(structPtr);
1376return;
1377}
1378bzero(neweps, sizeof(SMBEntryPoint));
1379
1380neweps->anchor[0]= '_';
1381neweps->anchor[1]= 'S';
1382neweps->anchor[2]= 'M';
1383neweps->anchor[3]= '_';
1384neweps->entryPointLength= sizeof(SMBEntryPoint);
1385neweps->majorVersion= 2; // Bungo:
1386neweps->minorVersion= 4; // Here we're using 2.4 SMBIOS rev. as real Macs
1387neweps->maxStructureSize= maxStructSize;
1388neweps->entryPointRevision= 0;
1389
1390neweps->dmi.anchor[0]= '_';
1391neweps->dmi.anchor[1]= 'D';
1392neweps->dmi.anchor[2]= 'M';
1393neweps->dmi.anchor[3]= 'I';
1394neweps->dmi.anchor[4]= '_';
1395neweps->dmi.tableLength= tableLength;
1396neweps->dmi.tableAddress= AllocateKernelMemory(tableLength);
1397neweps->dmi.structureCount= structureCount;
1398neweps->dmi.bcdRevision= 0x24; // ... and 2.4 DMI rev. as real Macs
1399
1400if (!neweps->dmi.tableAddress)
1401{
1402free(buffer);
1403free(structPtr);
1404return;
1405}
1406
1407memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength);
1408
1409Platform.UUID = fixSystemUUID(); // Bungo: fix System UUID
1410
1411neweps->dmi.checksum= 0;
1412neweps->dmi.checksum= 0x100 - checksum8(&neweps->dmi, sizeof(DMIEntryPoint));
1413
1414neweps->checksum= 0;
1415neweps->checksum= 0x100 - checksum8(neweps, sizeof(SMBEntryPoint));
1416
1417free(buffer);
1418free(structPtr);
1419
1420verbose("\n");
1421verbose("SMBIOS orig: rev.: %d.%d, DMI rev.: %d.%d, @%08X\n", origeps->majorVersion, origeps->minorVersion, origeps->dmi.bcdRevision >> 4, origeps->dmi.bcdRevision & 0x0F, origeps);
1422verbose("SMBIOS new: rev.: %d.%d, DMI rev.: %d.%d, @%08X\n", neweps->majorVersion, neweps->minorVersion, neweps->dmi.bcdRevision >> 4, neweps->dmi.bcdRevision & 0x0F, neweps);
1423
1424decodeSMBIOSTable(neweps);
1425
1426smbios_p = (EFI_PTR32)neweps; // save a patched smbios ptr for efi config table
1427}
1428
1429void *getSmbios(int which)
1430{
1431switch (which)
1432{
1433case SMBIOS_ORIGINAL:
1434if (!origeps)
1435{
1436origeps = getAddressOfSmbiosTable();
1437}
1438return origeps;
1439case SMBIOS_PATCHED:
1440return neweps;
1441}
1442
1443return 0;
1444}
1445
1446/* Collect any information needed later */
1447void readSMBIOSInfo(SMBEntryPoint *eps)
1448{
1449uint8_t *structPtr = (uint8_t *)eps->dmi.tableAddress;
1450SMBStructHeader *structHeader = (SMBStructHeader *)structPtr;
1451
1452int dimmnbr = 0;
1453Platform.DMI.MaxMemorySlots= 0;// number of memory slots polulated by SMBIOS
1454Platform.DMI.CntMemorySlots= 0;// number of memory slots counted
1455Platform.DMI.MemoryModules= 0;
1456
1457for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));)
1458{
1459switch (structHeader->type)
1460{
1461case kSMBTypeSystemInformation:
1462Platform.UUID = ((SMBSystemInformation *)structHeader)->uuid; // save factory system uuid
1463break;
1464
1465case kSMBTypeSystemEnclosure: // Bungo: determine platform type
1466switch (((SMBSystemEnclosure *)structHeader)->chassisType)
1467{
1468case kSMBchassisPortable:
1469case kSMBchassisLaptop:
1470case kSMBchassisNotebook:
1471case kSMBchassisHandHeld:
1472case kSMBchassisSubNotebook:
1473Platform.Type = 2; // notebook (MacBooks/Pros)
1474break;
1475case kSMBchassisMiniTower:
1476case kSMBchassisTower:
1477case kSMBchassisBlade:
1478case kSMBchassisBladeEnclosing:
1479Platform.Type = 3; // workstation (Mac Pro, Xserve)
1480break;
1481default:
1482Platform.Type = 1; // defulting to 1 desktop (iMac, MacMini)
1483break;
1484}
1485break;
1486
1487case kSMBTypePhysicalMemoryArray:
1488Platform.DMI.MaxMemorySlots += ((SMBPhysicalMemoryArray *)structHeader)->numMemoryDevices;
1489break;
1490
1491case kSMBTypeMemoryDevice:
1492Platform.DMI.CntMemorySlots++;
1493if (((SMBMemoryDevice *)structHeader)->memorySize != 0)
1494{
1495Platform.DMI.MemoryModules++;
1496}
1497if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0)
1498{
1499Platform.RAM.DIMM[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed;
1500}
1501dimmnbr++;
1502break;
1503default:
1504break;
1505}
1506
1507structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
1508for (; ((uint16_t *)structPtr)[0] != 0; structPtr++);
1509
1510if (((uint16_t *)structPtr)[0] == 0)
1511{
1512structPtr += 2;
1513}
1514
1515structHeader = (SMBStructHeader *)structPtr;
1516}
1517}
1518

Archive Download this file

Revision: HEAD