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

Archive Download this file

Revision: HEAD