Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 2728