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
622/* Rewrite this function */
623void setDefaultSMBData(void) // Bungo: setting data from real Macs
624{
625defaultBIOSInfo.vendor = kDefaultVendorManufacturer;
626defaultBIOSInfo.release = kDefaultBIOSRelease; // Bungo
627
628defaultSystemInfo.manufacturer = kDefaultVendorManufacturer;
629defaultSystemInfo.version = kDefaultSystemVersion;
630defaultSystemInfo.serialNumber = kDefaultSerialNumber;
631defaultSystemInfo.skuNumber = kDefaultSkuNumber; // Bungo
632
633defaultBaseBoard.manufacturer = kDefaultVendorManufacturer;
634defaultBaseBoard.serialNumber = kDefaultSerialNumber;
635defaultBaseBoard.assetTag = kDefaultAssetTag;
636
637defaultChassis.manufacturer = kDefaultVendorManufacturer;
638defaultChassis.serialNumber = kDefaultSerialNumber;
639defaultChassis.assetTag = kDefaultAssetTag;
640defaultChassis.skuNumber = kDefaultSkuNumber;
641
642if (Platform.Type == 2)
643{
644if (Platform.CPU.NoCores > 1) {
645defaultSystemInfo.productName = kDefaultMacBookPro;
646defaultBIOSInfo.version = kDefaultMacBookProBIOSVersion;
647defaultBIOSInfo.releaseDate = kDefaultMacBookProBIOSReleaseDate;
648defaultSystemInfo.family = kDefaultMacBookProFamily;
649defaultBaseBoard.product = kDefaultMacBookProBoardProduct;
650defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
651defaultChassis.chassisType = kSMBchassisUnknown;
652} else {
653defaultSystemInfo.productName = kDefaultMacBook;
654defaultBIOSInfo.version = kDefaultMacBookBIOSVersion;
655defaultBIOSInfo.releaseDate = kDefaultMacBookBIOSReleaseDate;
656defaultSystemInfo.family = kDefaultMacBookFamily;
657defaultBaseBoard.product = kDefaultMacBookBoardProduct;
658defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
659defaultChassis.chassisType = kSMBchassisUnknown;
660}
661} else {
662switch (Platform.CPU.NoCores)
663{
664case 1:
665defaultBIOSInfo.version = kDefaultMacMiniBIOSVersion;
666defaultBIOSInfo.releaseDate = kDefaultMacMiniBIOSReleaseDate;
667defaultSystemInfo.productName = kDefaultMacMini;
668defaultSystemInfo.family = kDefaultMacMiniFamily;
669defaultBaseBoard.product = kDefaultMacMiniBoardProduct;
670defaultBaseBoard.boardType = kSMBBaseBoardUnknown;
671defaultChassis.chassisType = kSMBchassisLPDesktop;
672break;
673
674case 2:
675defaultBIOSInfo.version = kDefaultiMacBIOSVersion;
676defaultBIOSInfo.releaseDate = kDefaultiMacBIOSReleaseDate;
677defaultSystemInfo.productName = kDefaultiMac;
678defaultSystemInfo.family = kDefaultMacFamily; // iMac8,1 family = Mac
679defaultBaseBoard.product = kDefaultiMacBoardProduct;
680defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
681defaultChassis.chassisType = kSMBchassisAllInOne;
682break;
683default:
684{
685switch (Platform.CPU.Family)
686{
687case 0x06:
688{
689switch (Platform.CPU.Model)
690{
691case CPUID_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
692case CPUID_MODEL_DALES:
693case CPUID_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
694defaultBIOSInfo.version= kDefaultiMacNehalemBIOSVersion;
695defaultBIOSInfo.releaseDate= kDefaultiMacNehalemBIOSReleaseDate;
696defaultSystemInfo.productName= kDefaultiMacNehalem;
697defaultSystemInfo.family= kDefaultiMacFamily;
698defaultBaseBoard.product = kDefaultiMacNehalemBoardProduct;
699defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
700defaultChassis.chassisType = kSMBchassisAllInOne;
701break;
702
703case CPUID_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
704case CPUID_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
705defaultBIOSInfo.version = kDefaultiMacSandyBIOSVersion;
706defaultBIOSInfo.releaseDate = kDefaultiMacSandyBIOSReleaseDate;
707defaultSystemInfo.productName= kDefaultiMacSandy;
708defaultSystemInfo.family = kDefaultiMacFamily;
709defaultBaseBoard.product = kDefaultiMacSandyBoardProduct;
710defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
711defaultChassis.chassisType = kSMBchassisAllInOne;
712break;
713
714case CPUID_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
715case CPUID_MODEL_NEHALEM_EX:// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x
716defaultBIOSInfo.version = kDefaultMacProNehalemBIOSVersion;
717defaultBIOSInfo.releaseDate = kDefaultMacProNehalemBIOSReleaseDate;
718defaultSystemInfo.productName= kDefaultMacProNehalem;
719defaultSystemInfo.version = kDefaultMacProNahWestSystemVersion;
720defaultSystemInfo.family = kDefaultMacProFamily;
721defaultBaseBoard.product = kDefaultMacProNehalemBoardProduct;
722defaultBaseBoard.boardType = kSMBBaseBoardProcessorMemoryModule;
723defaultChassis.chassisType = kSMBchassisTower;
724break;
725
726case CPUID_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
727case CPUID_MODEL_WESTMERE_EX:// Intel Xeon E7
728case CPUID_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)
729case CPUID_MODEL_IVYBRIDGE_EP:// Intel Core i7, Xeon E5 v2 LGA2011 (22nm)
730defaultBIOSInfo.version = kDefaultMacProWestmereBIOSVersion;
731defaultBIOSInfo.releaseDate = kDefaultMacProWestmereBIOSReleaseDate;
732defaultSystemInfo.productName= kDefaultMacProWestmere;
733defaultSystemInfo.version = kDefaultMacProNahWestSystemVersion;
734defaultSystemInfo.family = kDefaultMacProFamily;
735defaultBaseBoard.product = kDefaultMacProWestmereBoardProduct;
736defaultBaseBoard.boardType = kSMBBaseBoardProcessorMemoryModule;
737defaultChassis.chassisType = kSMBchassisTower;
738break;
739
740default:
741defaultBIOSInfo.version = kDefaultMacProBIOSVersion;
742defaultBIOSInfo.releaseDate = kDefaultMacProBIOSReleaseDate;
743defaultSystemInfo.productName= kDefaultMacPro;
744defaultSystemInfo.family = kDefaultMacProFamily;
745defaultBaseBoard.product = kDefaultMacProBoardProduct;
746defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
747defaultChassis.chassisType = kSMBchassisUnknown;
748break;
749}
750break;
751}
752default:
753defaultBIOSInfo.version = kDefaultMacProBIOSVersion;
754defaultBIOSInfo.releaseDate = kDefaultMacProBIOSReleaseDate;
755defaultSystemInfo.productName = kDefaultMacPro;
756defaultSystemInfo.family = kDefaultMacProFamily;
757defaultBaseBoard.product = kDefaultMacProBoardProduct;
758defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
759defaultChassis.chassisType = kSMBchassisUnknown;
760break;
761}
762break;
763}
764}
765}
766}
767
768/* Used for SM*n smbios.plist keys */
769bool getSMBValueForKey(SMBStructHeader *structHeader, const char *keyString, const char **string, returnType *value)
770{
771static int idx = -1;
772static int current = -1;
773int len;
774char key[24];
775
776if (current != structHeader->handle) {
777idx++;
778current = structHeader->handle;
779}
780
781sprintf(key, "%s%d", keyString, idx);
782
783if (value) {
784if (getIntForKey(key, (int *)&(value->dword), SMBPlist)) {
785return true;
786}
787} else {
788if (getValueForKey(key, string, &len, SMBPlist)) {
789return true;
790}
791}
792return false;
793}
794
795char *getSMBStringForField(SMBStructHeader *structHeader, uint8_t field)
796{
797uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length;
798
799if (!field) {
800return NULL;
801}
802
803for (field--; field != 0 && strlen((char *)stringPtr) > 0;
804field--, stringPtr = (uint8_t *)((uint32_t)stringPtr + strlen((char *)stringPtr) + 1));
805
806return (char *)stringPtr;
807}
808
809void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field)
810{
811int strSize;
812
813if (!field) {
814return;
815}
816
817if (!string) {
818*field = 0;
819return;
820}
821
822strSize = strlen(string);
823
824// remove any spaces found at the end but only in MemoryDevice
825if (structHeader->type == kSMBTypeMemoryDevice) {
826while ((strSize != 0) && (string[strSize - 1] == ' ')) {
827strSize--;
828}
829}
830
831if (strSize == 0) {
832*field = 0;
833return;
834}
835
836memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize);
837*field = stringIndex;
838
839stringIndex++;
840stringsSize += strSize + 1;
841}
842
843bool setSMBValue(SMBStructPtrs *structPtr, int idx, returnType *value)
844{
845const char *string = 0;
846int len;
847bool parsed;
848int val;
849
850if (numOfSetters <= idx) {
851return false;
852}
853
854switch (SMBSetters[idx].valueType) {
855case kSMBString:
856{
857if (SMBSetters[idx].keyString)
858{
859if (getValueForKey(SMBSetters[idx].keyString, &string, &len, SMBPlist))
860{
861break;
862} else {
863if (structPtr->orig->type == kSMBTypeMemoryDevice) {// MemoryDevice only
864if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, &string, NULL)) {
865break;
866}
867}
868}
869
870}
871if (SMBSetters[idx].getSMBValue) {
872if (SMBSetters[idx].getSMBValue((returnType *)&string)) {
873break;
874}
875}
876// if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue)) Bungo
877if (useSMBIOSdefaults && SMBSetters[idx].defaultValue && *(SMBSetters[idx].defaultValue)) {
878string = *(SMBSetters[idx].defaultValue);
879break;
880}
881string = getSMBStringForField(structPtr->orig, *(uint8_t *)value);
882break;
883}
884case kSMBByte:
885case kSMBWord:
886case kSMBDWord:
887case kSMBQWord:
888if (SMBSetters[idx].keyString) {
889parsed = getIntForKey(SMBSetters[idx].keyString, &val, SMBPlist);
890if (!parsed)
891{
892if (structPtr->orig->type == kSMBTypeMemoryDevice) { // MemoryDevice only
893parsed = getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, (returnType *)&val);
894}
895}
896if (parsed) {
897switch (SMBSetters[idx].valueType) {
898case kSMBByte:
899value->byte = (uint8_t)val;
900break;
901case kSMBWord:
902value->word = (uint16_t)val;
903break;
904case kSMBQWord:
905value->qword = (uint64_t)val;
906break;
907case kSMBDWord:
908default:
909value->dword = (uint32_t)val;
910break;
911}
912return true;
913}
914}
915
916if (SMBSetters[idx].getSMBValue) {
917if (SMBSetters[idx].getSMBValue(value)) {
918return true;
919}
920}
921// #if 0 Bungo: enables code below
922// if (*(SMBSetters[idx].defaultValue)) Bungo
923if (useSMBIOSdefaults && SMBSetters[idx].defaultValue && *(SMBSetters[idx].defaultValue)) {
924// value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue); Bungo
925switch (SMBSetters[idx].valueType) {
926case kSMBByte:
927value->byte = *(uint8_t *)(SMBSetters[idx].defaultValue);
928break;
929case kSMBWord:
930value->word = *(uint16_t *)(SMBSetters[idx].defaultValue);
931break;
932case kSMBQWord:
933value->qword = *(uint64_t *)(SMBSetters[idx].defaultValue);
934break;
935case kSMBDWord:
936default:
937value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue);
938break;
939}
940return true;
941}
942// #endif Bungo
943break;
944}
945
946// if (SMBSetters[idx].valueType == kSMBString && string) Bungo: use null string too -> "Not Specified"
947if ((SMBSetters[idx].valueType == kSMBString) && string) {
948setSMBStringForField(structPtr->new, string, &value->byte);
949}
950return true;
951}
952
953//-------------------------------------------------------------------------------------------------------------------------
954// Apple Specific
955//-------------------------------------------------------------------------------------------------------------------------
956
957/* ===========================================
958 Firmware Volume (Apple Specific - Type 128)
959 ============================================= */
960void addSMBFirmwareVolume(SMBStructPtrs *structPtr)
961{
962return;
963}
964
965/* ===========================================
966 Memory SPD Data (Apple Specific - Type 130)
967 ============================================= */
968void addSMBMemorySPD(SMBStructPtrs *structPtr)
969{
970/* SPD data from Platform.RAM.spd */
971return;
972}
973
974/* ============================================
975 OEM Processor Type (Apple Specific - Type 131)
976 ============================================== */
977void addSMBOemProcessorType(SMBStructPtrs *structPtr)
978{
979SMBOemProcessorType *p = (SMBOemProcessorType *)structPtr->new;
980
981p->header.type= kSMBTypeOemProcessorType;
982p->header.length= sizeof(SMBOemProcessorType);
983p->header.handle= handle++;
984
985setSMBValue(structPtr, numOfSetters - 2 , (returnType *)&(p->ProcessorType));
986
987structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorType) + 2);
988tableLength += sizeof(SMBOemProcessorType) + 2;
989structureCount++;
990}
991
992/* =================================================
993 OEM Processor Bus Speed (Apple Specific - Type 132)
994 =================================================== */
995bool addSMBOemProcessorBusSpeed(SMBStructPtrs *structPtr)
996{
997SMBOemProcessorBusSpeed *p = (SMBOemProcessorBusSpeed *)structPtr->new;
998
999 if (Platform.CPU.Vendor != CPUID_VENDOR_INTEL)
1000 return false;
1001
1002switch (Platform.CPU.Family) {
1003case 0x06:
1004switch (Platform.CPU.Model) {
1005case 0x19:// Intel Core i5 650 @3.20 Ghz
1006case CPUID_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156, (45nm)
1007case CPUID_MODEL_DALES: // Intel Core i5, i7, Xeon, (45nm), integrated GPU
1008case CPUID_MODEL_DALES_32NM:// Intel Core i3, i5, Xeon, (32nm), integrated GPU
1009case CPUID_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
1010case CPUID_MODEL_NEHALEM_EX:// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x
1011case CPUID_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
1012case CPUID_MODEL_WESTMERE_EX:// Intel Xeon E7
1013case CPUID_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
1014case CPUID_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
1015case CPUID_MODEL_IVYBRIDGE_EP:
1016case CPUID_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)
1017case CPUID_MODEL_HASWELL:
1018case CPUID_MODEL_HASWELL_SVR:
1019case CPUID_MODEL_HASWELL_ULT:
1020case CPUID_MODEL_CRYSTALWELL:
1021 p->header.type= kSMBTypeOemProcessorBusSpeed;
1022 p->header.length= sizeof(SMBOemProcessorBusSpeed);
1023 p->header.handle= handle++;
1024
1025 setSMBValue(structPtr, numOfSetters - 1, (returnType *)&(p->ProcessorBusSpeed));
1026
1027 structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorBusSpeed) + 2);
1028 tableLength += sizeof(SMBOemProcessorBusSpeed) + 2;
1029 structureCount++;
1030
1031return true;
1032
1033default:
1034break;
1035}
1036 break;
1037
1038 default:
1039 break;
1040}
1041
1042 return false;
1043}
1044
1045/* ==============================================
1046 OEM Platform Feature (Apple Specific - Type 133)
1047 ================================================ */
1048 /*void addSMBOemPlatformFeature(SMBStructPtrs *structPtr) {
1049SMBOemPlatformFeature *p = (SMBOemPlatformFeature *)structPtr->new;
1050
1051p->header.type= kSMBTypeOemPlatformFeature;
1052p->header.length= sizeof(SMBOemPlatformFeature);
1053p->header.handle= handle++;
1054
1055setSMBValue(structPtr, numOfSetters - 2 , (returnType *)&(p->PlatformFeature));
1056
1057structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemPPlatformFeature) + 2);
1058tableLength += sizeof(SMBOemPlatformFeature) + 2;
1059structureCount++;
1060 }*/
1061
1062//-------------------------------------------------------------------------------------------------------------------------
1063// EndOfTable
1064//-------------------------------------------------------------------------------------------------------------------------
1065void addSMBEndOfTable(SMBStructPtrs *structPtr)
1066{
1067structPtr->new->type= kSMBTypeEndOfTable;
1068structPtr->new->length= sizeof(SMBStructHeader);
1069structPtr->new->handle= 0xFFFD; // real Macs set this value here // handle++;
1070
1071structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBStructHeader) + 2);
1072tableLength += sizeof(SMBStructHeader) + 2;
1073structureCount++;
1074}
1075
1076void setSMBStruct(SMBStructPtrs *structPtr)
1077{
1078bool setterFound = false;
1079
1080uint8_t *ptr;
1081SMBWord structSize;
1082int i;
1083
1084/* Bungo: not needed because of tables' lengths fix in next lines
1085// http://forge.voodooprojects.org/p/chameleon/issues/361/
1086bool forceFullMemInfo = false;
1087
1088if (structPtr->orig->type == kSMBTypeMemoryDevice) {
1089getBoolForKey(kMemFullInfo, &forceFullMemInfo, &bootInfo->chameleonConfig);
1090if (forceFullMemInfo) {
1091structPtr->orig->length = 27;
1092}
1093}*/
1094
1095stringIndex = 1;
1096stringsSize = 0;
1097
1098if (handle < structPtr->orig->handle) {
1099handle = structPtr->orig->handle;
1100}
1101// Bungo: fix unsuported tables lengths from original smbios: extend shorter or truncate longer - we use SMBIOS rev. 2.4 like Apple uses
1102switch (structPtr->orig->type) {
1103case kSMBTypeBIOSInformation:
1104structSize = sizeof(SMBBIOSInformation);
1105break;
1106case kSMBTypeSystemInformation:
1107structSize = sizeof(SMBSystemInformation);
1108break;
1109case kSMBTypeBaseBoard:
1110structSize = sizeof(SMBBaseBoard);
1111break;
1112case kSMBTypeSystemEnclosure:
1113structSize = sizeof(SMBSystemEnclosure);
1114break;
1115case kSMBTypeProcessorInformation:
1116structSize = sizeof(SMBProcessorInformation);
1117break;
1118case kSMBTypeMemoryDevice:
1119structSize = sizeof(SMBMemoryDevice);
1120break;
1121default:
1122structSize = structPtr->orig->length; // doesn't change a length for unpatched
1123break;
1124}
1125
1126// memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);
1127if (structPtr->orig->length <= structSize) {
1128memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);
1129} else {
1130memcpy((void *)structPtr->new, structPtr->orig, structSize);
1131}
1132
1133structPtr->new->length = structSize;
1134
1135for (i = 0; i < numOfSetters; i++) {
1136// Bungo:
1137//if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structPtr->orig->length)) {
1138if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structSize)) {
1139setterFound = true;
1140setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset));
1141}
1142}
1143
1144if (setterFound) {
1145// Bungo:
1146// ptr = (uint8_t *)structPtr->new + structPtr->orig->length;
1147ptr = (uint8_t *)structPtr->new + structPtr->new->length;
1148for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1149
1150if (((uint16_t *)ptr)[0] == 0) {
1151ptr += 2;
1152}
1153structSize = ptr - (uint8_t *)structPtr->new;
1154} else {
1155ptr = (uint8_t *)structPtr->orig + structPtr->orig->length;
1156for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1157
1158if (((uint16_t *)ptr)[0] == 0) {
1159ptr += 2;
1160}
1161
1162structSize = ptr - (uint8_t *)structPtr->orig;
1163memcpy((void *)structPtr->new, structPtr->orig, structSize);
1164}
1165
1166structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + structSize);
1167
1168tableLength += structSize;
1169
1170if (structSize > maxStructSize) {
1171maxStructSize = structSize;
1172}
1173
1174structureCount++;
1175}
1176
1177void setupNewSMBIOSTable(SMBEntryPoint *eps, SMBStructPtrs *structPtr)
1178{
1179uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress;
1180structPtr->orig = (SMBStructHeader *)ptr;
1181
1182for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));) {
1183switch (structPtr->orig->type) {
1184/* Skip all Apple Specific Structures */
1185case kSMBTypeFirmwareVolume:
1186case kSMBTypeMemorySPD:
1187case kSMBTypeOemProcessorType:
1188case kSMBTypeOemProcessorBusSpeed:
1189/* And this one too, to be added at the end */
1190case kSMBTypeEndOfTable:
1191break;
1192
1193default:
1194{
1195/* Add */
1196setSMBStruct(structPtr);
1197break;
1198}
1199}
1200
1201ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length);
1202for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1203
1204if (((uint16_t *)ptr)[0] == 0) {
1205ptr += 2;
1206}
1207
1208structPtr->orig = (SMBStructHeader *)ptr;
1209}
1210
1211addSMBFirmwareVolume(structPtr);
1212addSMBMemorySPD(structPtr);
1213addSMBOemProcessorType(structPtr);
1214addSMBOemProcessorBusSpeed(structPtr);
1215
1216addSMBEndOfTable(structPtr);
1217}
1218
1219// Bungo: does fix system uuid in SMBIOS & EFI instead of in EFI (IODT/efi/platform/system-id) only
1220uint8_t *fixSystemUUID()
1221{
1222uint8_t *ptr = (uint8_t *)neweps->dmi.tableAddress;
1223SMBStructHeader *structHeader = (SMBStructHeader *)ptr;
1224int i, isZero, isOnes;
1225uint8_t fixedUUID[UUID_LEN] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
1226const char *sysId = getStringForKey(kSMBSystemInformationUUIDKey, SMBPlist); // try to get user's uuid from smbios.plist
1227uint8_t *ret = (uint8_t *)getUUIDFromString(sysId); // convert user's uuid from string
1228
1229for (;(structHeader->type != kSMBTypeSystemInformation);) // find System Information Table (Type 1) in patched SMBIOS
1230{
1231ptr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
1232for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1233
1234if (((uint16_t *)ptr)[0] == 0) {
1235ptr += 2;
1236}
1237
1238structHeader = (SMBStructHeader *)ptr;
1239}
1240
1241ptr = ((SMBSystemInformation *)structHeader)->uuid;
1242
1243if (!sysId || !ret) { // no or bad custom uuid,...
1244sysId = 0;
1245ret = Platform.UUID; // ...use original (factory) system uuid
1246}
1247
1248for (i = 0, isZero = 1, isOnes = 1; i < UUID_LEN; i++) // check if empty (zeroed) or setable (FFed), means: no uuid present
1249{
1250if (ret[i] != 0x00) {
1251isZero = 0;
1252}
1253
1254if (ret[i] != 0xff) {
1255isOnes = 0;
1256}
1257}
1258
1259if (isZero || isOnes) { // if empty or setable...
1260 verbose("System UUID: incorrect or not present. Fixing [00112233-4455-6677-8899-AABBCCDDEEFF]\n");
1261 ret = fixedUUID; // ...set a fixed value for system uuid: <00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF>
1262}
1263
1264memcpy(ptr, ret, UUID_LEN); // save uuid into the patched SMBIOS Table 1
1265
1266return ptr;
1267} // Bungo: end fix
1268
1269void setupSMBIOS(void)
1270{
1271SMBStructPtrs *structPtr;
1272uint8_t *buffer;
1273// bool setSMB = true; Bungo: now we use useSMBIOSdefaults
1274
1275if (!origeps) {
1276return;
1277}
1278
1279neweps = origeps;
1280
1281structPtr = (SMBStructPtrs *)malloc(sizeof(SMBStructPtrs));
1282if (!structPtr) {
1283return;
1284}
1285
1286buffer = (uint8_t *)malloc(SMB_ALLOC_SIZE);
1287if (!buffer) {
1288free(structPtr);
1289return;
1290}
1291
1292bzero(buffer, SMB_ALLOC_SIZE);
1293structPtr->new = (SMBStructHeader *)buffer;
1294
1295// getBoolForKey(kSMBIOSdefaults, &setSMB, &bootInfo->chameleonConfig); Bungo
1296getBoolForKey(kSMBIOSdefaults, &useSMBIOSdefaults, &bootInfo->chameleonConfig);
1297// if (setSMB) Bungo
1298setDefaultSMBData();
1299
1300setupNewSMBIOSTable(origeps, structPtr);
1301
1302neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint));
1303if (!neweps) {
1304free(buffer);
1305free(structPtr);
1306return;
1307}
1308bzero(neweps, sizeof(SMBEntryPoint));
1309
1310neweps->anchor[0]= '_';
1311neweps->anchor[1]= 'S';
1312neweps->anchor[2]= 'M';
1313neweps->anchor[3]= '_';
1314neweps->entryPointLength= sizeof(SMBEntryPoint);
1315neweps->majorVersion= 2; // Bungo:
1316neweps->minorVersion= 4; // Here we're using 2.4 SMBIOS rev. as real Macs
1317neweps->maxStructureSize= maxStructSize;
1318neweps->entryPointRevision= 0;
1319
1320neweps->dmi.anchor[0]= '_';
1321neweps->dmi.anchor[1]= 'D';
1322neweps->dmi.anchor[2]= 'M';
1323neweps->dmi.anchor[3]= 'I';
1324neweps->dmi.anchor[4]= '_';
1325neweps->dmi.tableLength= tableLength;
1326neweps->dmi.tableAddress= AllocateKernelMemory(tableLength);
1327neweps->dmi.structureCount= structureCount;
1328neweps->dmi.bcdRevision= 0x24; // ... and 2.4 DMI rev. as real Macs
1329
1330if (!neweps->dmi.tableAddress) {
1331free(buffer);
1332free(structPtr);
1333return;
1334}
1335
1336memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength);
1337
1338Platform.UUID = fixSystemUUID(); // Bungo: fix System UUID
1339
1340neweps->dmi.checksum= 0;
1341neweps->dmi.checksum= 0x100 - checksum8(&neweps->dmi, sizeof(DMIEntryPoint));
1342
1343neweps->checksum= 0;
1344neweps->checksum= 0x100 - checksum8(neweps, sizeof(SMBEntryPoint));
1345
1346free(buffer);
1347free(structPtr);
1348
1349 verbose("\n");
1350verbose("SMBIOS orig: rev.: %d.%d, DMI rev.: %d.%d, @%08X\n", origeps->majorVersion, origeps->minorVersion, origeps->dmi.bcdRevision >> 4, origeps->dmi.bcdRevision & 0x0F, origeps);
1351 verbose("SMBIOS new: rev.: %d.%d, DMI rev.: %d.%d, @%08X\n", neweps->majorVersion, neweps->minorVersion, neweps->dmi.bcdRevision >> 4, neweps->dmi.bcdRevision & 0x0F, neweps);
1352
1353decodeSMBIOSTable(neweps);
1354
1355 smbios_p = (EFI_PTR32)neweps; // save a patched smbios ptr for efi config table
1356}
1357
1358void *getSmbios(int which)
1359{
1360switch (which) {
1361case SMBIOS_ORIGINAL:
1362if (!origeps) {
1363origeps = getAddressOfSmbiosTable();
1364}
1365return origeps;
1366case SMBIOS_PATCHED:
1367return neweps;
1368}
1369
1370return 0;
1371}
1372
1373/* Collect any information needed later */
1374void readSMBIOSInfo(SMBEntryPoint *eps)
1375{
1376uint8_t *structPtr = (uint8_t *)eps->dmi.tableAddress;
1377SMBStructHeader *structHeader = (SMBStructHeader *)structPtr;
1378
1379int dimmnbr = 0;
1380Platform.DMI.MaxMemorySlots= 0;// number of memory slots polulated by SMBIOS
1381Platform.DMI.CntMemorySlots= 0;// number of memory slots counted
1382Platform.DMI.MemoryModules= 0;
1383
1384for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));)
1385{
1386switch (structHeader->type)
1387{
1388case kSMBTypeSystemInformation:
1389Platform.UUID = ((SMBSystemInformation *)structHeader)->uuid; // save factory system uuid
1390break;
1391
1392case kSMBTypeSystemEnclosure: // Bungo: determine platform type
1393switch (((SMBSystemEnclosure *)structHeader)->chassisType) {
1394case kSMBchassisPortable:
1395case kSMBchassisLaptop:
1396case kSMBchassisNotebook:
1397case kSMBchassisHandHeld:
1398case kSMBchassisSubNotebook:
1399Platform.Type = 2; // notebook (MacBooks/Pros)
1400 break;
1401 case kSMBchassisMiniTower:
1402 case kSMBchassisTower:
1403 case kSMBchassisBlade:
1404 case kSMBchassisBladeEnclosing:
1405 Platform.Type = 3; // workstation (Mac Pro, Xserve)
1406 break;
1407default:
1408Platform.Type = 1; // defulting to 1 desktop (iMac, MacMini)
1409break;
1410}
1411break;
1412
1413case kSMBTypePhysicalMemoryArray:
1414Platform.DMI.MaxMemorySlots += ((SMBPhysicalMemoryArray *)structHeader)->numMemoryDevices;
1415break;
1416
1417case kSMBTypeMemoryDevice:
1418Platform.DMI.CntMemorySlots++;
1419if (((SMBMemoryDevice *)structHeader)->memorySize != 0){
1420Platform.DMI.MemoryModules++;
1421}
1422if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0){
1423Platform.RAM.DIMM[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed;
1424}
1425dimmnbr++;
1426break;
1427default:
1428break;
1429}
1430
1431structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
1432for (; ((uint16_t *)structPtr)[0] != 0; structPtr++);
1433
1434if (((uint16_t *)structPtr)[0] == 0) {
1435structPtr += 2;
1436}
1437
1438structHeader = (SMBStructHeader *)structPtr;
1439}
1440}
1441

Archive Download this file

Revision: 2531