Chameleon

Chameleon Svn Source Tree

Root/tags/2.3/i386/libsaio/smbios.c

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

Archive Download this file

Revision: HEAD