Chameleon

Chameleon Svn Source Tree

Root/trunk/i386/libsaio/smbios.c

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

Archive Download this file

Revision: 2349