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

Archive Download this file

Revision: 2564