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

Archive Download this file

Revision: 2858