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

Archive Download this file

Revision: 2469