Chameleon

Chameleon Svn Source Tree

Root/trunk/i386/libsaio/smbios.c

1/*
2 * SMBIOS Table Patcher, part of the Chameleon Boot Loader Project
3 *
4 * Copyright 2010 by Islam M. Ahmed Zaid. All rights reserved.
5 *
6 */
7
8
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
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; // Bungo: renamed folowing convention
190//char*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 }, // SMboardassetag - 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"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// MacMini5,2 Mac-4BC72D62AD45599E
434// MacMini5,3
435//#define kDefaultMacMini"Macmini5,3"
436//#define kDefaultMacMiniBIOSVersion" MM51.88Z.0077.B10.1201241549"
437//#define kDefaultMacMiniBoardProduct"Mac-F65AE981FFA204ED"
438//#define kDefaultMacMiniBIOSReleaseDate"01/24/2012"
439
440// MacMini 6,1 - Mac-F65AE981FFA204ED
441// MacMini 6,2
442//#define kDefaultMacMini62"Macmini6,2"
443//#define kDefaultMacMini62BIOSVersion" MM61.88Z.0106.B00.1208091121"
444//#define kDefaultMacMini62BoardProduct"Mac-F65AE981FFA204ED"
445//#define kDefaultMacMini62BIOSReleaseDate"10/14/2012"
446
447//=========== MacBook ===========
448#define kDefaultMacBookFamily"MacBook"
449//#define kDefaultMacBookBoardAssetTagNumber"MacBook-Black"
450
451#define kDefaultMacBook"MacBook4,1"
452#define kDefaultMacBookBIOSVersion" MB41.88Z.00C1.B00.0802091535"
453#define kDefaultMacBookBIOSReleaseDate"02/09/08"
454#define kDefaultMacBookBoardProduct"Mac-F22788A9"
455
456//=========== MacBookAir ===========
457#define kDefaultMacBookAirFamily"MacBook Air"
458
459// MacBookAir4,1 - Mac-C08A6BB70A942AC2
460// MacBookAir4,2 - Mac-742912EFDBEE19B3
461#define kDefaultMacBookAir"MacBookAir5,2"
462#define kDefaultMacBookAirBIOSVersion" MBA51.88Z.00EF.B00.1205221442"
463#define kDefaultMacBookAirBIOSReleaseDate"05/10/12"
464#define kDefaultMacBookBoardAirProduct"Mac-2E6FAB96566FE58C"
465
466// MacBookAir6,1 - Mac-35C1E88140C3E6CF - MBA61.88Z.0099.B04.1309271229
467// MacBookAir6,2 - Mac-7DF21CB3ED6977E5 - MBA62.88Z.00EF.B00.1205221442
468
469//=========== MacBookPro ===========
470#define kDefaultMacBookProFamily"MacBook Pro"
471//#define kDefaultMacBookProBoardAssetTagNumber"MacBook-Aluminum"
472
473#define kDefaultMacBookPro"MacBookPro4,1"
474#define kDefaultMacBookProBIOSVersion" MBP41.88Z.00C1.B03.0802271651"
475#define kDefaultMacBookProBIOSReleaseDate"02/27/08"
476#define kDefaultMacBookProBoardProduct"Mac-F42C89C8"
477
478//#define kDefaultMacBookPro"MacBookPro8,1"
479//#define kDefaultMacBookProBIOSVersion" MBP81.88Z.0047.B24.1110141131"
480//#define kDefaultMacBookProBoardProduct"Mac-94245B3640C91C81"
481//#define kDefaultMacBookProBIOSReleaseDate"10/14/11"
482
483// MacBookPro8,2 - Mac_94245A3940C91C80
484// MacBookPro8,3 - Mac-942459F5819B171B
485
486// MacBookPro10,2
487//#define kDefaultMacBookProIvy"MacBookPro10,2"
488//#define kDefaultMacBookProIvyBIOSVersion" MBP102.88Z.0106.B01.1208311637"
489//#define kDefaultMacBookProIvyBoardProduct"Mac-AFD8A9D944EA4843"
490//#define kDefaultMacBookProIvyBIOSReleaseDate"10/02/2012"
491
492// MacBookPro11,2 - Mac-3CBD00234E554E41 - MBP112.88Z.0138.B03.1310291227
493// MacBookPro11,3 - Mac-2BD1B31983FE1663 - MBP112.88Z.0138.B02.1310181745
494
495//=========== iMac ===========
496#define kDefaultiMacFamily"iMac"
497//#define kDefaultiMacBoardAssetTagNumber"iMac-Aluminum"
498
499#define kDefaultiMac"iMac8,1"
500#define kDefaultiMacBIOSVersion" IM81.88Z.00C1.B00.0903051113"
501#define kDefaultiMacBIOSReleaseDate"02/09/08"
502#define kDefaultiMacBoardProduct"Mac-F227BEC8"
503
504// iMac10,1
505// iMac11,1 core i3/i5/i7
506#define kDefaultiMacNehalem"iMac11,1"
507#define kDefaultiMacNehalemBIOSVersion" IM111.88Z.0034.B02.1003171314"
508#define kDefaultiMacNehalemBIOSReleaseDate"03/30/10"
509#define kDefaultiMacNehalemBoardProduct"Mac-F2268DAE"
510// iMac11,2
511// iMac11,3
512
513// iMac12,1
514#define kDefaultiMacSandy"iMac12,1"
515#define kDefaultiMacSandyBIOSVersion" IM121.88Z.0047.B00.1102091756"
516#define kDefaultiMacSandyBIOSReleaseDate"01/02/08"
517#define kDefaultiMacSandyBoardProduct"Mac-942B5BF58194151B"
518
519// iMac12,2 Mac-942B59F58194171B
520//#define kDefaultiMacSandy"iMac12,2"
521//#define kDefaultiMacSandyBIOSVersion" IM121.88Z.0047.B1D.1110171110"
522//#define kDefaultiMacSandyBIOSReleaseDate"10/17/11"
523//#define kDefaultiMacSandyBoardProduct"Mac-942B59F58194171B"
524
525// iMac13,1
526// Bios: IM131.88Z.010A.B05.1211151146
527// Data: 11/15/2012
528// Board: Mac-00BE6ED71E35EB86
529
530// iMac13,2
531//#define kDefaultiMacIvy"iMac13,2"
532//#define kDefaultiMacIvyBIOSVersion" IM131.88Z.00CE.B00.1203281326"
533//#define kDefaultiMacIvyBIOSReleaseDate"03/28/2012"
534//#define kDefaultiMacIvyBoardProduct"Mac-FC02E91DDD3FA6A4"
535
536//=========== MacPro ===========
537#define kDefaultMacProFamily"Mac Pro"
538//#define KDefauktMacProBoardAssetTagNumber"Pro-Enclosure"
539//#define kDefaultMacProBoardType"0xB" // 11
540
541#define kDefaultMacPro"MacPro3,1"
542#define kDefaultMacProBIOSVersion" MP31.88Z.006C.B05.0903051113"
543#define kDefaultMacProBIOSReleaseDate"08/03/2010"
544//#define kDefaultMacProSystemVersion"1.3"
545#define kDefaultMacProBoardProduct"Mac-F42C88C8"
546//#define KDefaultMacProBoardSerialNumber"J593902RA4MFE"
547
548// Mac Pro 4,1 core i7/Xeon
549#define kDefaultMacProNehalem"MacPro4,1"
550#define kDefaultMacProNehalemBIOSVersion" MP41.88Z.0081.B07.0910130729"
551#define kDefaultMacProNehalemBIOSReleaseDate"10/13/09"
552//#define kDefaultMacProNehalemSystemVersion"1.4"
553#define kDefaultMacProNehalemBoardProduct"Mac-F221BEC8"
554//#define KDefaultMacProNehalemBoardSerialNumber"J593004RB1LUE"
555
556// Mac Pro 5,1 core i7/Xeon
557#define kDefaultMacProWestmere"MacPro5,1"
558#define kDefaultMacProWestmereBIOSVersion" MP51.88Z.007F.B03.1010071432"
559#define kDefaultMacProWestmereBIOSReleaseDate"10/07/10"
560//#define kDefaultMacProWestmereSystemVersion"1.2"
561#define kDefaultMacProWestmereBoardProduct"Mac-F221BEC8"
562//#define KDefaultMacProWestmereBoardSerialNumber"J522700H7BH8C"
563
564// Mac Pro 6,1
565#define kDefaultMacProHaswell"MacPro6,1"
566#define kDefaultMacProHaswellBIOSVersion" MP61.88Z.0116.B04.1312061508"
567#define kDefaultMacProHaswellBIOSReleaseDate"12/06/2013"
568//#define kDefaultMacProHaswellSystemVersion"1.?"
569#define kDefaultMacProHaswellBoardProduct"Mac-F60DEB81FF30ACF6"
570//#define KDefaultMacProHaswellBoardSerialNumber"?????????????"
571
572//#define KDefaultBoardSerialNumber"C02140302D5DMT31M" // new C07019501PLDCVHAD - C02032101R5DC771H
573// J593902RA4MFE 3,1
574// J5031046RCZJA 5,1
575// J521101A5CZJC 3,1
576// J593004RB1LUE MacPro4,1
577// J513401PZBH8C 5,1
578// J590802LC4ACB 3,1
579// J594900AH1LUE 4,1
580// J512500HZBH8C 5,1
581// J522700H7BH8C MacPro5,1
582
583/* ============================================ */
584
585bool useSMBIOSdefaults = true; // Bungo
586
587SMBByte PlatformType= 3; // Bungo: same as Platfom.Type in platform.h
588
589/* Rewrite this function */
590void setDefaultSMBData(void) // Bungo: setting data from real Macs
591{
592defaultBIOSInfo.vendor = kDefaultVendorManufacturer;
593defaultBIOSInfo.release = kDefaultBIOSRelease; // Bungo
594
595defaultSystemInfo.manufacturer = kDefaultVendorManufacturer;
596defaultSystemInfo.version = kDefaultSystemVersion;
597defaultSystemInfo.serialNumber = kDefaultSerialNumber;
598defaultSystemInfo.skuNumber = kDefaultSkuNumber; // Bungo
599
600defaultBaseBoard.manufacturer = kDefaultVendorManufacturer;
601defaultBaseBoard.serialNumber = kDefaultSerialNumber;
602defaultBaseBoard.assetTag = kDefaultAssetTag;
603
604defaultChassis.manufacturer = kDefaultVendorManufacturer;
605defaultChassis.serialNumber = kDefaultSerialNumber;
606defaultChassis.assetTag = kDefaultAssetTag;
607//defaultChassis.skuNumber = kDefaultSkuNumber;
608
609// if (platformCPUFeature(CPU_FEATURE_MOBILE)) Bungo: doesn't recognise correctly, need fixing
610if (PlatformType == 2) // this method works but it's a substitute
611{
612if (Platform.CPU.NoCores > 1) {
613defaultSystemInfo.productName = kDefaultMacBookPro;
614defaultBIOSInfo.version = kDefaultMacBookProBIOSVersion;
615defaultBIOSInfo.releaseDate = kDefaultMacBookProBIOSReleaseDate;
616defaultSystemInfo.family = kDefaultMacBookProFamily;
617defaultBaseBoard.product = kDefaultMacBookProBoardProduct;
618defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
619defaultChassis.chassisType = kSMBchassisUnknown;
620} else {
621defaultSystemInfo.productName = kDefaultMacBook;
622defaultBIOSInfo.version = kDefaultMacBookBIOSVersion;
623defaultBIOSInfo.releaseDate = kDefaultMacBookBIOSReleaseDate;
624defaultSystemInfo.family = kDefaultMacBookFamily;
625defaultBaseBoard.product = kDefaultMacBookBoardProduct;
626defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
627defaultChassis.chassisType = kSMBchassisUnknown;
628}
629} else {
630switch (Platform.CPU.NoCores)
631{
632case 1:
633defaultBIOSInfo.version = kDefaultMacMiniBIOSVersion;
634defaultBIOSInfo.releaseDate = kDefaultMacMiniBIOSReleaseDate;
635defaultSystemInfo.productName = kDefaultMacMini;
636defaultSystemInfo.family = kDefaultMacMiniFamily;
637defaultBaseBoard.product = kDefaultMacMiniBoardProduct;
638defaultBaseBoard.boardType = kSMBBaseBoardUnknown;
639defaultChassis.chassisType = kSMBchassisLPDesktop;
640break;
641
642case 2:
643defaultBIOSInfo.version = kDefaultiMacBIOSVersion;
644defaultBIOSInfo.releaseDate = kDefaultiMacBIOSReleaseDate;
645defaultSystemInfo.productName = kDefaultiMac;
646defaultSystemInfo.family = kDefaultiMacFamily;
647defaultBaseBoard.product = kDefaultiMacBoardProduct;
648defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
649defaultChassis.chassisType = kSMBchassisAllInOne;
650break;
651default:
652{
653switch (Platform.CPU.Family)
654{
655case 0x06:
656{
657switch (Platform.CPU.Model)
658{
659case CPU_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
660case CPU_MODEL_DALES:
661case CPU_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
662defaultBIOSInfo.version= kDefaultiMacNehalemBIOSVersion;
663defaultBIOSInfo.releaseDate= kDefaultiMacNehalemBIOSReleaseDate;
664defaultSystemInfo.productName= kDefaultiMacNehalem;
665defaultSystemInfo.family= kDefaultiMacFamily;
666defaultBaseBoard.product = kDefaultiMacNehalemBoardProduct;
667defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
668defaultChassis.chassisType = kSMBchassisAllInOne;
669break;
670
671case CPU_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
672case CPU_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
673case CPU_MODEL_IVYBRIDGE_XEON:
674defaultBIOSInfo.version = kDefaultiMacSandyBIOSVersion;
675defaultBIOSInfo.releaseDate = kDefaultiMacSandyBIOSReleaseDate;
676defaultSystemInfo.productName= kDefaultiMacSandy;
677defaultSystemInfo.family = kDefaultiMacFamily;
678defaultBaseBoard.product = kDefaultiMacSandyBoardProduct;
679defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
680defaultChassis.chassisType = kSMBchassisAllInOne;
681break;
682
683case CPU_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
684case CPU_MODEL_NEHALEM_EX:// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x
685defaultBIOSInfo.version= kDefaultMacProNehalemBIOSVersion;
686defaultBIOSInfo.releaseDate= kDefaultMacProNehalemBIOSReleaseDate;
687defaultSystemInfo.productName= kDefaultMacProNehalem;
688defaultSystemInfo.family= kDefaultMacProFamily;
689defaultBaseBoard.product = kDefaultMacProNehalemBoardProduct;
690defaultBaseBoard.boardType = kSMBBaseBoardProcessorMemoryModule;
691defaultChassis.chassisType = kSMBchassisTower;
692break;
693
694case CPU_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
695case CPU_MODEL_WESTMERE_EX:// Intel Xeon E7
696case CPU_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)
697defaultBIOSInfo.version= kDefaultMacProWestmereBIOSVersion;
698defaultBIOSInfo.releaseDate= kDefaultMacProWestmereBIOSReleaseDate;
699defaultSystemInfo.productName= kDefaultMacProWestmere;
700defaultSystemInfo.family= kDefaultMacProFamily;
701defaultBaseBoard.product = kDefaultMacProWestmereBoardProduct;
702defaultBaseBoard.boardType = kSMBBaseBoardProcessorMemoryModule;
703defaultChassis.chassisType = kSMBchassisTower;
704break;
705
706default:
707defaultBIOSInfo.version= kDefaultMacProBIOSVersion;
708defaultBIOSInfo.releaseDate= kDefaultMacProBIOSReleaseDate;
709defaultSystemInfo.productName= kDefaultMacPro;
710defaultSystemInfo.family= kDefaultMacProFamily;
711defaultBaseBoard.product = kDefaultMacProBoardProduct;
712defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
713defaultChassis.chassisType = kSMBchassisUnknown;
714break;
715}
716break;
717}
718default:
719defaultBIOSInfo.version= kDefaultMacProBIOSVersion;
720defaultBIOSInfo.releaseDate= kDefaultMacProBIOSReleaseDate;
721defaultSystemInfo.productName= kDefaultMacPro;
722defaultSystemInfo.family= kDefaultMacProFamily;
723defaultBaseBoard.product = kDefaultMacProBoardProduct;
724defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
725defaultChassis.chassisType = kSMBchassisUnknown;
726break;
727}
728break;
729}
730}
731}
732}
733
734/* Used for SM*n smbios.plist keys */
735bool getSMBValueForKey(SMBStructHeader *structHeader, const char *keyString, const char **string, returnType *value)
736{
737static int idx = -1;
738static int current = -1;
739int len;
740char key[24];
741
742if (current != structHeader->handle) {
743idx++;
744current = structHeader->handle;
745}
746
747sprintf(key, "%s%d", keyString, idx);
748
749if (value) {
750if (getIntForKey(key, (int *)&(value->dword), SMBPlist)) {
751return true;
752}
753} else {
754if (getValueForKey(key, string, &len, SMBPlist)) {
755return true;
756}
757}
758return false;
759}
760
761char *getSMBStringForField(SMBStructHeader *structHeader, uint8_t field)
762{
763uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length;
764
765if (!field) {
766return NULL;
767}
768
769for (field--; field != 0 && strlen((char *)stringPtr) > 0;
770field--, stringPtr = (uint8_t *)((uint32_t)stringPtr + strlen((char *)stringPtr) + 1));
771
772return (char *)stringPtr;
773}
774
775void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field)
776{
777int strSize;
778
779if (!field) {
780return;
781}
782
783if (!string) {
784*field = 0;
785return;
786}
787
788strSize = strlen(string);
789
790/* Bungo: What was this for?
791// remove any spaces found at the end
792while ((strSize != 0) && (string[strSize - 1] == ' ')) {
793strSize--;
794}
795*/
796if (strSize == 0) {
797*field = 0;
798return;
799}
800
801memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize);
802*field = stringIndex;
803
804stringIndex++;
805stringsSize += strSize + 1;
806}
807
808bool setSMBValue(SMBStructPtrs *structPtr, int idx, returnType *value)
809{
810const char *string = 0;
811int len;
812bool parsed;
813int val;
814
815if (numOfSetters <= idx) {
816return false;
817}
818
819switch (SMBSetters[idx].valueType) {
820case kSMBString:
821{
822if (SMBSetters[idx].keyString)
823{
824if (getValueForKey(SMBSetters[idx].keyString, &string, &len, SMBPlist))
825{
826break;
827} else {
828if (structPtr->orig->type == kSMBTypeMemoryDevice)// MemoryDevice only
829{
830if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, &string, NULL))
831{
832break;
833}
834}
835}
836
837}
838if (SMBSetters[idx].getSMBValue) {
839if (SMBSetters[idx].getSMBValue((returnType *)&string)) {
840break;
841}
842}
843// if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue)) Bungo
844if (useSMBIOSdefaults && SMBSetters[idx].defaultValue && *(SMBSetters[idx].defaultValue)) {
845string = *(SMBSetters[idx].defaultValue);
846break;
847}
848string = getSMBStringForField(structPtr->orig, *(uint8_t *)value);
849break;
850}
851case kSMBByte:
852case kSMBWord:
853case kSMBDWord:
854//case kSMBQWord:
855if (SMBSetters[idx].keyString) {
856parsed = getIntForKey(SMBSetters[idx].keyString, &val, SMBPlist);
857if (!parsed)
858{
859if (structPtr->orig->type == kSMBTypeMemoryDevice) { // MemoryDevice only
860parsed = getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, (returnType *)&val);
861}
862}
863if (parsed) {
864switch (SMBSetters[idx].valueType) {
865case kSMBByte:
866value->byte = (uint8_t)val;
867break;
868case kSMBWord:
869value->word = (uint16_t)val;
870break;
871//case kSMBQWord:
872//value->qword = (uint64_t)val;
873//break;
874case kSMBDWord:
875default:
876value->dword = (uint32_t)val;
877break;
878}
879return true;
880}
881}
882
883if (SMBSetters[idx].getSMBValue) {
884if (SMBSetters[idx].getSMBValue(value)) {
885return true;
886}
887}
888// #if 0 Bungo: enables code below
889// if (*(SMBSetters[idx].defaultValue)) Bungo
890if (useSMBIOSdefaults && SMBSetters[idx].defaultValue && *(SMBSetters[idx].defaultValue)) {
891// value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue); Bungo
892switch (SMBSetters[idx].valueType) {
893case kSMBByte:
894value->byte = *(uint8_t *)(SMBSetters[idx].defaultValue);
895break;
896case kSMBWord:
897value->word = *(uint16_t *)(SMBSetters[idx].defaultValue);
898break;
899//case kSMBQWord:
900//value->qword = *(uint32_t *)(SMBSetters[idx].defaultValue);
901//break;
902case kSMBDWord:
903default:
904value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue);
905break;
906}
907return true;
908}
909// #endif Bungo
910break;
911}
912
913// if (SMBSetters[idx].valueType == kSMBString && string) Bungo: use null string too -> "Not Specified"
914if ((SMBSetters[idx].valueType == kSMBString) && string) {
915setSMBStringForField(structPtr->new, string, &value->byte);
916}
917return true;
918}
919
920//-------------------------------------------------------------------------------------------------------------------------
921// Apple Specific
922//-------------------------------------------------------------------------------------------------------------------------
923
924/* ===========================================
925 Firmware Volume (Apple Specific - Type 128)
926 ============================================= */
927void addSMBFirmwareVolume(SMBStructPtrs *structPtr)
928{
929return;
930}
931
932/* ===========================================
933 Memory SPD Data (Apple Specific - Type 130)
934 ============================================= */
935void addSMBMemorySPD(SMBStructPtrs *structPtr)
936{
937/* SPD data from Platform.RAM.spd */
938return;
939}
940
941/* ============================================
942 OEM Processor Type (Apple Specific - Type 131)
943 ============================================== */
944void addSMBOemProcessorType(SMBStructPtrs *structPtr)
945{
946SMBOemProcessorType *p = (SMBOemProcessorType *)structPtr->new;
947
948p->header.type= kSMBTypeOemProcessorType;
949p->header.length= sizeof(SMBOemProcessorType);
950p->header.handle= handle++;
951
952setSMBValue(structPtr, numOfSetters - 2 , (returnType *)&(p->ProcessorType));
953
954structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorType) + 2);
955tableLength += sizeof(SMBOemProcessorType) + 2;
956structureCount++;
957}
958
959/* =================================================
960 OEM Processor Bus Speed (Apple Specific - Type 132)
961 =================================================== */
962void addSMBOemProcessorBusSpeed(SMBStructPtrs *structPtr)
963{
964SMBOemProcessorBusSpeed *p = (SMBOemProcessorBusSpeed *)structPtr->new;
965
966switch (Platform.CPU.Family)
967{
968case 0x06:
969{
970switch (Platform.CPU.Model)
971{
972case 0x19:// Intel Core i5 650 @3.20 Ghz
973case CPU_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
974case CPU_MODEL_DALES:
975case CPU_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
976case CPU_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
977case CPU_MODEL_NEHALEM_EX:// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x
978case CPU_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
979case CPU_MODEL_WESTMERE_EX:// Intel Xeon E7
980case CPU_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
981case CPU_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
982case CPU_MODEL_IVYBRIDGE_XEON:
983case CPU_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)
984case CPU_MODEL_HASWELL:
985case CPU_MODEL_HASWELL_SVR:
986case CPU_MODEL_HASWELL_ULT:
987case CPU_MODEL_CRYSTALWELL:
988
989break;
990
991default:
992return;
993}
994}
995}
996
997p->header.type= kSMBTypeOemProcessorBusSpeed;
998p->header.length= sizeof(SMBOemProcessorBusSpeed);
999p->header.handle= handle++;
1000
1001setSMBValue(structPtr, numOfSetters -1, (returnType *)&(p->ProcessorBusSpeed));
1002
1003structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorBusSpeed) + 2);
1004tableLength += sizeof(SMBOemProcessorBusSpeed) + 2;
1005structureCount++;
1006}
1007
1008/* ==============================================
1009 OEM Platform Feature (Apple Specific - Type 133)
1010 ================================================ */
1011 /*void addSMBOemPlatformFeature(SMBStructPtrs *structPtr) { }*/
1012
1013//-------------------------------------------------------------------------------------------------------------------------
1014// EndOfTable
1015//-------------------------------------------------------------------------------------------------------------------------
1016void addSMBEndOfTable(SMBStructPtrs *structPtr)
1017{
1018structPtr->new->type= kSMBTypeEndOfTable;
1019structPtr->new->length= sizeof(SMBStructHeader);
1020structPtr->new->handle= handle++;
1021
1022structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBStructHeader) + 2);
1023tableLength += sizeof(SMBStructHeader) + 2;
1024structureCount++;
1025}
1026
1027void setSMBStruct(SMBStructPtrs *structPtr)
1028{
1029bool setterFound = false;
1030
1031uint8_t *ptr;
1032SMBWord structSize;
1033int i;
1034
1035/* Bungo: not needed because of tables lengths fix in next lines
1036// http://forge.voodooprojects.org/p/chameleon/issues/361/
1037bool forceFullMemInfo = false;
1038
1039if (structPtr->orig->type == kSMBTypeMemoryDevice) {
1040getBoolForKey(kMemFullInfo, &forceFullMemInfo, &bootInfo->chameleonConfig);
1041if (forceFullMemInfo) {
1042structPtr->orig->length = 27;
1043}
1044}*/
1045
1046stringIndex = 1;
1047stringsSize = 0;
1048
1049if (handle < structPtr->orig->handle) {
1050handle = structPtr->orig->handle;
1051}
1052// Bungo: fix unsuported tables lengths from original smbios: extend smaller or truncate bigger - we use SMBIOS rev. 2.4 like Apple uses
1053switch (structPtr->orig->type) {
1054case kSMBTypeBIOSInformation:
1055structSize = sizeof(SMBBIOSInformation);
1056break;
1057case kSMBTypeSystemInformation:
1058structSize = sizeof(SMBSystemInformation);
1059break;
1060case kSMBTypeBaseBoard:
1061structSize = sizeof(SMBBaseBoard);
1062break;
1063case kSMBTypeSystemEnclosure:
1064structSize = sizeof(SMBSystemEnclosure);
1065break;
1066case kSMBTypeProcessorInformation:
1067structSize = sizeof(SMBProcessorInformation);
1068break;
1069case kSMBTypeMemoryDevice:
1070structSize = sizeof(SMBMemoryDevice);
1071break;
1072default:
1073structSize = structPtr->orig->length; // don't change if not to patch
1074break;
1075}
1076
1077// memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);
1078if (structPtr->orig->length <= structSize) {
1079memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);
1080} else {
1081memcpy((void *)structPtr->new, structPtr->orig, structSize);
1082}
1083
1084structPtr->new->length = structSize;
1085
1086for (i = 0; i < numOfSetters; i++) {
1087// Bungo:
1088//if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structPtr->orig->length)) {
1089if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structSize)) {
1090setterFound = true;
1091setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset));
1092}
1093}
1094
1095if (setterFound) {
1096// Bungo:
1097// ptr = (uint8_t *)structPtr->new + structPtr->orig->length;
1098ptr = (uint8_t *)structPtr->new + structPtr->new->length;
1099for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1100
1101if (((uint16_t *)ptr)[0] == 0) {
1102ptr += 2;
1103}
1104structSize = ptr - (uint8_t *)structPtr->new;
1105} else {
1106ptr = (uint8_t *)structPtr->orig + structPtr->orig->length;
1107for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1108
1109if (((uint16_t *)ptr)[0] == 0) {
1110ptr += 2;
1111}
1112
1113structSize = ptr - (uint8_t *)structPtr->orig;
1114memcpy((void *)structPtr->new, structPtr->orig, structSize);
1115}
1116
1117structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + structSize);
1118
1119tableLength += structSize;
1120
1121if (structSize > maxStructSize) {
1122maxStructSize = structSize;
1123}
1124
1125structureCount++;
1126}
1127
1128void setupNewSMBIOSTable(SMBEntryPoint *eps, SMBStructPtrs *structPtr)
1129{
1130uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress;
1131structPtr->orig = (SMBStructHeader *)ptr;
1132
1133for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));) {
1134switch (structPtr->orig->type) {
1135/* Skip all Apple Specific Structures */
1136case kSMBTypeFirmwareVolume:
1137case kSMBTypeMemorySPD:
1138case kSMBTypeOemProcessorType:
1139case kSMBTypeOemProcessorBusSpeed:
1140/* And this one too, to be added at the end */
1141case kSMBTypeEndOfTable:
1142break;
1143
1144default:
1145{
1146/* Add */
1147setSMBStruct(structPtr);
1148break;
1149}
1150}
1151
1152ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length);
1153for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1154
1155if (((uint16_t *)ptr)[0] == 0) {
1156ptr += 2;
1157}
1158
1159structPtr->orig = (SMBStructHeader *)ptr;
1160}
1161
1162addSMBFirmwareVolume(structPtr);
1163addSMBMemorySPD(structPtr);
1164addSMBOemProcessorType(structPtr);
1165addSMBOemProcessorBusSpeed(structPtr);
1166
1167addSMBEndOfTable(structPtr);
1168}
1169
1170// Bungo: does fix system uuid in SMBIOS (and EFI) instead of in EFI only
1171uint8_t *FixSystemUUID()
1172{
1173uint8_t *ptr = (uint8_t *)neweps->dmi.tableAddress;
1174SMBStructHeader *structHeader = (SMBStructHeader *)ptr;
1175int i, isZero, isOnes;
1176uint8_t FixedUUID[UUID_LEN] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
1177const char *sysId = getStringForKey(kSMBSystemInformationUUIDKey, SMBPlist);
1178uint8_t *ret = (uint8_t *)getUUIDFromString(sysId);
1179
1180for (;(structHeader->type != kSMBTypeSystemInformation);) // find System Information Table (Type 1) in patched SMBIOS
1181{
1182ptr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
1183for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1184
1185if (((uint16_t *)ptr)[0] == 0) {
1186ptr += 2;
1187}
1188
1189structHeader = (SMBStructHeader *)ptr;
1190}
1191
1192ptr = ((SMBSystemInformation *)structHeader)->uuid;
1193
1194if (!sysId || !ret) { // no or bad custom UUID,...
1195sysId = 0;
1196ret = Platform.UUID; // ...try bios dmi system uuid extraction
1197}
1198
1199for (i=0, isZero=1, isOnes=1; i<UUID_LEN; i++) // check if empty or setable, means: no uuid present
1200{
1201if (ret[i] != 0x00) {
1202isZero = 0;
1203}
1204
1205if (ret[i] != 0xff) {
1206isOnes = 0;
1207}
1208}
1209
1210if (isZero || isOnes) { // if empty or setable...
1211verbose("No UUID present in SMBIOS System Information Table\n");
1212ret = FixedUUID; // ...set a fixed value for system-id = 000102030405060708090A0B0C0D0E0F
1213}
1214
1215memcpy(ptr, ret, UUID_LEN); // fix uuid in the table
1216return ptr;
1217} // Bungo: end fix
1218
1219void setupSMBIOSTable(void)
1220{
1221SMBStructPtrs *structPtr;
1222uint8_t *buffer;
1223// bool setSMB = true; Bungo: now we use useSMBIOSdefaults
1224
1225if (!origeps) {
1226return;
1227}
1228
1229neweps = origeps;
1230
1231structPtr = (SMBStructPtrs *)malloc(sizeof(SMBStructPtrs));
1232if (!structPtr) {
1233return;
1234}
1235
1236buffer = (uint8_t *)malloc(SMB_ALLOC_SIZE);
1237if (!buffer) {
1238free(structPtr);
1239return;
1240}
1241
1242bzero(buffer, SMB_ALLOC_SIZE);
1243structPtr->new = (SMBStructHeader *)buffer;
1244
1245// getBoolForKey(kSMBIOSdefaults, &setSMB, &bootInfo->chameleonConfig); Bungo
1246getBoolForKey(kSMBIOSdefaults, &useSMBIOSdefaults, &bootInfo->chameleonConfig);
1247// if (setSMB) Bungo
1248setDefaultSMBData();
1249
1250setupNewSMBIOSTable(origeps, structPtr);
1251
1252neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint));
1253if (!neweps) {
1254free(buffer);
1255free(structPtr);
1256return;
1257}
1258bzero(neweps, sizeof(SMBEntryPoint));
1259
1260neweps->anchor[0]= '_';
1261neweps->anchor[1]= 'S';
1262neweps->anchor[2]= 'M';
1263neweps->anchor[3]= '_';
1264neweps->entryPointLength= sizeof(SMBEntryPoint);
1265neweps->majorVersion= 2; // Bungo:
1266neweps->minorVersion= 4; // Here we're using 2.4 SMBIOS rev. as real Macs
1267neweps->maxStructureSize= maxStructSize;
1268neweps->entryPointRevision= 0;
1269
1270neweps->dmi.anchor[0]= '_';
1271neweps->dmi.anchor[1]= 'D';
1272neweps->dmi.anchor[2]= 'M';
1273neweps->dmi.anchor[3]= 'I';
1274neweps->dmi.anchor[4]= '_';
1275neweps->dmi.tableLength= tableLength;
1276neweps->dmi.tableAddress= AllocateKernelMemory(tableLength);
1277neweps->dmi.structureCount= structureCount;
1278neweps->dmi.bcdRevision= 0x24; // ... and 2.4 DMI rev. as real Macs
1279
1280if (!neweps->dmi.tableAddress) {
1281free(buffer);
1282free(structPtr);
1283return;
1284}
1285
1286memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength);
1287
1288Platform.UUID = FixSystemUUID(); // Bungo: fix System UUID
1289
1290neweps->dmi.checksum= 0;
1291neweps->dmi.checksum= 0x100 - checksum8(&neweps->dmi, sizeof(DMIEntryPoint));
1292
1293neweps->checksum= 0;
1294neweps->checksum= 0x100 - checksum8(neweps, sizeof(SMBEntryPoint));
1295
1296free(buffer);
1297free(structPtr);
1298
1299decodeSMBIOSTable(neweps);
1300
1301DBG("SMBIOS orig was = %x\n", origeps);
1302DBG("SMBIOS new is = %x\n", neweps);
1303}
1304
1305void *getSmbios(int which)
1306{
1307switch (which) {
1308case SMBIOS_ORIGINAL:
1309if (!origeps) {
1310origeps = getAddressOfSmbiosTable();
1311}
1312return origeps;
1313case SMBIOS_PATCHED:
1314return neweps;
1315}
1316
1317return 0;
1318}
1319
1320/* Collect any information needed later */
1321void readSMBIOSInfo(SMBEntryPoint *eps)
1322{
1323uint8_t *structPtr = (uint8_t *)eps->dmi.tableAddress;
1324SMBStructHeader *structHeader = (SMBStructHeader *)structPtr;
1325
1326int dimmnbr = 0;
1327Platform.DMI.MaxMemorySlots= 0;// number of memory slots polulated by SMBIOS
1328Platform.DMI.CntMemorySlots= 0;// number of memory slots counted
1329Platform.DMI.MemoryModules= 0;
1330
1331for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));)
1332{
1333switch (structHeader->type)
1334{
1335case kSMBTypeSystemInformation:
1336Platform.UUID = ((SMBSystemInformation *)structHeader)->uuid; // get factory system uuid
1337break;
1338
1339case kSMBTypeSystemEnclosure: // Bungo: determine platform type
1340switch (((SMBSystemEnclosure *)structHeader)->chassisType) {
1341case kSMBchassisDesktop:
1342case kSMBchassisLPDesktop:
1343case kSMBchassisAllInOne:
1344case kSMBchassisLunchBox:
1345PlatformType = 1; // desktop (iMac, MacMini)
1346break;
1347case kSMBchassisPortable:
1348case kSMBchassisLaptop:
1349case kSMBchassisNotebook:
1350case kSMBchassisHandHeld:
1351case kSMBchassisSubNotebook:
1352PlatformType = 2; // notebook (Mac Books)
1353 break;
1354default:
1355PlatformType = 3; // workstation (Mac Pro, Xserve)
1356break;
1357}
1358break;
1359//
1360case kSMBTypePhysicalMemoryArray:
1361Platform.DMI.MaxMemorySlots += ((SMBPhysicalMemoryArray *)structHeader)->numMemoryDevices;
1362break;
1363
1364case kSMBTypeMemoryDevice:
1365Platform.DMI.CntMemorySlots++;
1366if (((SMBMemoryDevice *)structHeader)->memorySize != 0){
1367Platform.DMI.MemoryModules++;
1368}
1369if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0){
1370Platform.RAM.DIMM[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed;
1371}
1372dimmnbr++;
1373break;
1374default:
1375break;
1376}
1377
1378structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
1379for (; ((uint16_t *)structPtr)[0] != 0; structPtr++);
1380
1381if (((uint16_t *)structPtr)[0] == 0) {
1382structPtr += 2;
1383}
1384
1385structHeader = (SMBStructHeader *)structPtr;
1386}
1387}
1388

Archive Download this file

Revision: 2361