Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 2363