Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Enoch/i386/libsaio/smbios.c

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

Archive Download this file

Revision: 2849