Chameleon

Chameleon Svn Source Tree

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

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

Archive Download this file

Revision: 2904