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
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.B02.1310181745
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.B05.0903051113"
524#define kDefaultMacProBIOSReleaseDate"08/03/2010"
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)
593{
594defaultSystemInfo.productName = kDefaultMacBookPro;
595defaultBIOSInfo.version = kDefaultMacBookProBIOSVersion;
596defaultBIOSInfo.releaseDate = kDefaultMacBookProBIOSReleaseDate;
597defaultSystemInfo.family = kDefaultMacBookProFamily;
598defaultBaseBoard.product = kDefaultMacBookProBoardProduct;
599defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
600defaultChassis.chassisType = kSMBchassisUnknown;
601}
602else
603{
604defaultSystemInfo.productName = kDefaultMacBook;
605defaultBIOSInfo.version = kDefaultMacBookBIOSVersion;
606defaultBIOSInfo.releaseDate = kDefaultMacBookBIOSReleaseDate;
607defaultSystemInfo.family = kDefaultMacBookFamily;
608defaultBaseBoard.product = kDefaultMacBookBoardProduct;
609defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
610defaultChassis.chassisType = kSMBchassisUnknown;
611}
612}
613else
614{
615switch (Platform.CPU.NoCores)
616{
617case 1:
618defaultBIOSInfo.version = kDefaultMacMiniBIOSVersion;
619defaultBIOSInfo.releaseDate = kDefaultMacMiniBIOSReleaseDate;
620defaultSystemInfo.productName = kDefaultMacMini;
621defaultSystemInfo.family = kDefaultMacMiniFamily;
622defaultBaseBoard.product = kDefaultMacMiniBoardProduct;
623defaultBaseBoard.boardType = kSMBBaseBoardUnknown;
624defaultChassis.chassisType = kSMBchassisLPDesktop;
625break;
626
627case 2:
628defaultBIOSInfo.version = kDefaultiMacBIOSVersion;
629defaultBIOSInfo.releaseDate = kDefaultiMacBIOSReleaseDate;
630defaultSystemInfo.productName = kDefaultiMac;
631defaultSystemInfo.family = kDefaultiMacFamily;
632defaultBaseBoard.product = kDefaultiMacBoardProduct;
633defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
634defaultChassis.chassisType = kSMBchassisAllInOne;
635break;
636default:
637{
638switch (Platform.CPU.Family)
639{
640case 0x06:
641{
642switch (Platform.CPU.Model)
643{
644case CPU_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
645case CPU_MODEL_DALES:
646case CPU_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
647defaultBIOSInfo.version= kDefaultiMacNehalemBIOSVersion;
648defaultBIOSInfo.releaseDate= kDefaultiMacNehalemBIOSReleaseDate;
649defaultSystemInfo.productName= kDefaultiMacNehalem;
650defaultSystemInfo.family= kDefaultiMacFamily;
651defaultBaseBoard.product = kDefaultiMacNehalemBoardProduct;
652defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
653defaultChassis.chassisType = kSMBchassisAllInOne;
654break;
655
656case CPU_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
657case CPU_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
658case CPU_MODEL_IVYBRIDGE_XEON:
659defaultBIOSInfo.version = kDefaultiMacSandyBIOSVersion;
660defaultBIOSInfo.releaseDate = kDefaultiMacSandyBIOSReleaseDate;
661defaultSystemInfo.productName= kDefaultiMacSandy;
662defaultSystemInfo.family = kDefaultiMacFamily;
663defaultBaseBoard.product = kDefaultiMacSandyBoardProduct;
664defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
665defaultChassis.chassisType = kSMBchassisAllInOne;
666break;
667
668case CPU_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
669case CPU_MODEL_NEHALEM_EX:// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x
670defaultBIOSInfo.version= kDefaultMacProNehalemBIOSVersion;
671defaultBIOSInfo.releaseDate= kDefaultMacProNehalemBIOSReleaseDate;
672defaultSystemInfo.productName= kDefaultMacProNehalem;
673defaultSystemInfo.family= kDefaultMacProFamily;
674defaultBaseBoard.product = kDefaultMacProNehalemBoardProduct;
675defaultBaseBoard.boardType = kSMBBaseBoardProcessorMemoryModule;
676defaultChassis.chassisType = kSMBchassisTower;
677break;
678
679case CPU_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
680case CPU_MODEL_WESTMERE_EX:// Intel Xeon E7
681case CPU_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)
682defaultBIOSInfo.version= kDefaultMacProWestmereBIOSVersion;
683defaultBIOSInfo.releaseDate= kDefaultMacProWestmereBIOSReleaseDate;
684defaultSystemInfo.productName= kDefaultMacProWestmere;
685defaultSystemInfo.family= kDefaultMacProFamily;
686defaultBaseBoard.product = kDefaultMacProWestmereBoardProduct;
687defaultBaseBoard.boardType = kSMBBaseBoardProcessorMemoryModule;
688defaultChassis.chassisType = kSMBchassisTower;
689break;
690
691default:
692defaultBIOSInfo.version= kDefaultMacProBIOSVersion;
693defaultBIOSInfo.releaseDate= kDefaultMacProBIOSReleaseDate;
694defaultSystemInfo.productName= kDefaultMacPro;
695defaultSystemInfo.family= kDefaultMacProFamily;
696defaultBaseBoard.product = kDefaultMacProBoardProduct;
697defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
698defaultChassis.chassisType = kSMBchassisUnknown;
699break;
700}
701break;
702}
703default:
704defaultBIOSInfo.version= kDefaultMacProBIOSVersion;
705defaultBIOSInfo.releaseDate= kDefaultMacProBIOSReleaseDate;
706defaultSystemInfo.productName= kDefaultMacPro;
707defaultSystemInfo.family= kDefaultMacProFamily;
708defaultBaseBoard.product = kDefaultMacProBoardProduct;
709defaultBaseBoard.boardType = kSMBBaseBoardMotherboard;
710defaultChassis.chassisType = kSMBchassisUnknown;
711break;
712}
713break;
714}
715}
716}
717}
718
719/* Used for SM*n smbios.plist keys */
720bool getSMBValueForKey(SMBStructHeader *structHeader, const char *keyString, const char **string, returnType *value)
721{
722static int idx = -1;
723static int current = -1;
724int len;
725char key[24];
726
727if (current != structHeader->handle) {
728idx++;
729current = structHeader->handle;
730}
731
732sprintf(key, "%s%d", keyString, idx);
733
734if (value) {
735if (getIntForKey(key, (int *)&(value->dword), SMBPlist)) {
736return true;
737}
738} else {
739if (getValueForKey(key, string, &len, SMBPlist)) {
740return true;
741}
742}
743return false;
744}
745
746char *getSMBStringForField(SMBStructHeader *structHeader, uint8_t field)
747{
748uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length;
749
750if (!field) {
751return NULL;
752}
753
754for (field--; field != 0 && strlen((char *)stringPtr) > 0;
755field--, stringPtr = (uint8_t *)((uint32_t)stringPtr + strlen((char *)stringPtr) + 1));
756
757return (char *)stringPtr;
758}
759
760void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field)
761{
762int strSize;
763
764if (!field) {
765return;
766}
767
768if (!string) {
769*field = 0;
770return;
771}
772
773strSize = strlen(string);
774
775// remove any spaces found at the end
776while ((strSize != 0) && (string[strSize - 1] == ' ')) {
777strSize--;
778}
779
780if (strSize == 0) {
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) {
800return false;
801}
802
803switch (SMBSetters[idx].valueType) {
804case kSMBString:
805{
806if (SMBSetters[idx].keyString)
807{
808if (getValueForKey(SMBSetters[idx].keyString, &string, &len, SMBPlist))
809{
810break;
811}
812else
813{
814if (structPtr->orig->type == kSMBTypeMemoryDevice)// MemoryDevice only
815{
816if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, &string, NULL))
817{
818break;
819}
820}
821}
822
823}
824if (SMBSetters[idx].getSMBValue) {
825if (SMBSetters[idx].getSMBValue((returnType *)&string)) {
826break;
827}
828}
829// if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue)) Bungo
830if (useSMBIOSdefaults && SMBSetters[idx].defaultValue && *(SMBSetters[idx].defaultValue)) {
831string = *(SMBSetters[idx].defaultValue);
832break;
833}
834string = getSMBStringForField(structPtr->orig, *(uint8_t *)value);
835break;
836}
837case kSMBByte:
838case kSMBWord:
839case kSMBDWord:
840//case kSMBQWord:
841if (SMBSetters[idx].keyString) {
842parsed = getIntForKey(SMBSetters[idx].keyString, &val, SMBPlist);
843if (!parsed)
844{
845if (structPtr->orig->type == kSMBTypeMemoryDevice) { // MemoryDevice only
846parsed = getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, (returnType *)&val);
847}
848}
849if (parsed) {
850switch (SMBSetters[idx].valueType) {
851case kSMBByte:
852value->byte = (uint8_t)val;
853break;
854case kSMBWord:
855value->word = (uint16_t)val;
856break;
857case kSMBDWord:
858default:
859value->dword = (uint32_t)val;
860break;
861}
862return true;
863}
864}
865
866if (SMBSetters[idx].getSMBValue) {
867if (SMBSetters[idx].getSMBValue(value)) {
868return true;
869}
870}
871// #if 0 Bungo: enables code below
872 // if (*(SMBSetters[idx].defaultValue)) Bungo
873if (useSMBIOSdefaults && SMBSetters[idx].defaultValue && *(SMBSetters[idx].defaultValue))
874{
875 // value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue); Bungo
876 switch (SMBSetters[idx].valueType) {
877 case kSMBByte:
878 value->byte = *(uint8_t *)(SMBSetters[idx].defaultValue);
879 break;
880 case kSMBWord:
881 value->word = *(uint16_t *)(SMBSetters[idx].defaultValue);
882 break;
883 case kSMBDWord:
884 default:
885 value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue);
886 break;
887 }
888 return true;
889}
890// #endif Bungo
891break;
892}
893
894// if (SMBSetters[idx].valueType == kSMBString && string) Bungo: use null string too -> "Not Specified"
895if ((SMBSetters[idx].valueType == kSMBString) && string) {
896setSMBStringForField(structPtr->new, string, &value->byte);
897}
898return true;
899}
900
901//-------------------------------------------------------------------------------------------------------------------------
902// Apple Specific
903//-------------------------------------------------------------------------------------------------------------------------
904void addSMBFirmwareVolume(SMBStructPtrs *structPtr)
905{
906return;
907}
908
909void addSMBMemorySPD(SMBStructPtrs *structPtr)
910{
911/* SPD data from Platform.RAM.spd */
912return;
913}
914
915void addSMBOemProcessorType(SMBStructPtrs *structPtr)
916{
917SMBOemProcessorType *p = (SMBOemProcessorType *)structPtr->new;
918
919p->header.type= kSMBTypeOemProcessorType;
920p->header.length= sizeof(SMBOemProcessorType);
921p->header.handle= handle++;
922
923setSMBValue(structPtr, numOfSetters - 2 , (returnType *)&(p->ProcessorType));
924
925structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorType) + 2);
926tableLength += sizeof(SMBOemProcessorType) + 2;
927structureCount++;
928}
929
930void addSMBOemProcessorBusSpeed(SMBStructPtrs *structPtr)
931{
932SMBOemProcessorBusSpeed *p = (SMBOemProcessorBusSpeed *)structPtr->new;
933
934switch (Platform.CPU.Family)
935{
936case 0x06:
937{
938switch (Platform.CPU.Model)
939{
940case 0x19:// Intel Core i5 650 @3.20 Ghz
941case CPU_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
942case CPU_MODEL_DALES:
943case CPU_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
944case CPU_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
945case CPU_MODEL_NEHALEM_EX:// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x
946case CPU_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
947case CPU_MODEL_WESTMERE_EX:// Intel Xeon E7
948case CPU_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
949case CPU_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
950case CPU_MODEL_IVYBRIDGE_XEON:
951case CPU_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)
952case CPU_MODEL_HASWELL:
953case CPU_MODEL_HASWELL_MB:
954case CPU_MODEL_HASWELL_ULT:
955case CPU_MODEL_CRYSTALWELL:
956
957break;
958
959default:
960return;
961}
962}
963}
964
965p->header.type= kSMBTypeOemProcessorBusSpeed;
966p->header.length= sizeof(SMBOemProcessorBusSpeed);
967p->header.handle= handle++;
968
969setSMBValue(structPtr, numOfSetters -1, (returnType *)&(p->ProcessorBusSpeed));
970
971structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorBusSpeed) + 2);
972tableLength += sizeof(SMBOemProcessorBusSpeed) + 2;
973structureCount++;
974}
975
976//-------------------------------------------------------------------------------------------------------------------------
977// EndOfTable
978//-------------------------------------------------------------------------------------------------------------------------
979void addSMBEndOfTable(SMBStructPtrs *structPtr)
980{
981structPtr->new->type= kSMBTypeEndOfTable;
982structPtr->new->length= sizeof(SMBStructHeader);
983structPtr->new->handle= handle++;
984
985structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBStructHeader) + 2);
986tableLength += sizeof(SMBStructHeader) + 2;
987structureCount++;
988}
989
990void setSMBStruct(SMBStructPtrs *structPtr)
991{
992bool setterFound = false;
993
994uint8_t *ptr;
995SMBWord structSize;
996int i;
997
998/* http://forge.voodooprojects.org/p/chameleon/issues/361/ */
999bool forceFullMemInfo = false;
1000
1001if (structPtr->orig->type == kSMBTypeMemoryDevice) {
1002getBoolForKey(kMemFullInfo, &forceFullMemInfo, &bootInfo->chameleonConfig);
1003if (forceFullMemInfo) {
1004structPtr->orig->length = 27;
1005}
1006}
1007
1008stringIndex = 1;
1009stringsSize = 0;
1010
1011if (handle < structPtr->orig->handle) {
1012handle = structPtr->orig->handle;
1013}
1014
1015memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);
1016
1017for (i = 0; i < numOfSetters; i++) {
1018if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structPtr->orig->length)) {
1019setterFound = true;
1020setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset));
1021}
1022}
1023
1024if (setterFound) {
1025ptr = (uint8_t *)structPtr->new + structPtr->orig->length;
1026for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1027
1028if (((uint16_t *)ptr)[0] == 0) {
1029ptr += 2;
1030}
1031structSize = ptr - (uint8_t *)structPtr->new;
1032} else {
1033ptr = (uint8_t *)structPtr->orig + structPtr->orig->length;
1034for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1035
1036if (((uint16_t *)ptr)[0] == 0) {
1037ptr += 2;
1038}
1039
1040structSize = ptr - (uint8_t *)structPtr->orig;
1041memcpy((void *)structPtr->new, structPtr->orig, structSize);
1042}
1043
1044structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + structSize);
1045
1046tableLength += structSize;
1047
1048if (structSize > maxStructSize) {
1049maxStructSize = structSize;
1050}
1051
1052structureCount++;
1053}
1054
1055void setupNewSMBIOSTable(SMBEntryPoint *eps, SMBStructPtrs *structPtr)
1056{
1057uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress;
1058structPtr->orig = (SMBStructHeader *)ptr;
1059
1060for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));) {
1061switch (structPtr->orig->type) {
1062/* Skip all Apple Specific Structures */
1063case kSMBTypeFirmwareVolume:
1064case kSMBTypeMemorySPD:
1065case kSMBTypeOemProcessorType:
1066case kSMBTypeOemProcessorBusSpeed:
1067/* And this one too, to be added at the end */
1068case kSMBTypeEndOfTable:
1069break;
1070
1071default:
1072{
1073/* Add */
1074setSMBStruct(structPtr);
1075break;
1076}
1077}
1078
1079ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length);
1080for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1081
1082if (((uint16_t *)ptr)[0] == 0) {
1083ptr += 2;
1084}
1085
1086structPtr->orig = (SMBStructHeader *)ptr;
1087}
1088
1089addSMBFirmwareVolume(structPtr);
1090addSMBMemorySPD(structPtr);
1091addSMBOemProcessorType(structPtr);
1092addSMBOemProcessorBusSpeed(structPtr);
1093
1094addSMBEndOfTable(structPtr);
1095}
1096
1097// Bungo: does fix system uuid in SMBIOS (and EFI) instead of in EFI only
1098uint8_t *FixSystemUUID()
1099{
1100uint8_t *ptr = (uint8_t *)neweps->dmi.tableAddress;
1101SMBStructHeader *structHeader = (SMBStructHeader *)ptr;
1102int i, isZero, isOnes;
1103uint8_t FixedUUID[UUID_LEN] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
1104const char *sysId = getStringForKey(kSMBSystemInformationUUIDKey, SMBPlist);
1105uint8_t *ret = (uint8_t *)getUUIDFromString(sysId);
1106
1107for (;(structHeader->type != kSMBTypeSystemInformation);) // find System Information Table (Type 1) in patched SMBIOS
1108{
1109ptr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
1110for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1111
1112if (((uint16_t *)ptr)[0] == 0) {
1113ptr += 2;
1114}
1115
1116structHeader = (SMBStructHeader *)ptr;
1117}
1118
1119ptr = ((SMBSystemInformation *)structHeader)->uuid;
1120
1121if (!sysId || !ret) { // no or bad custom UUID,...
1122sysId = 0;
1123ret = Platform.UUID; // ...try bios dmi system uuid extraction
1124}
1125
1126for (i=0, isZero=1, isOnes=1; i<UUID_LEN; i++) // check if empty or setable, means: no uuid present
1127{
1128if (ret[i] != 0x00) {
1129isZero = 0;
1130}
1131
1132if (ret[i] != 0xff) {
1133isOnes = 0;
1134}
1135}
1136
1137if (isZero || isOnes) { // if empty or setable...
1138verbose("No UUID present in SMBIOS System Information Table\n");
1139ret = FixedUUID; // ...set a fixed value for system-id = 000102030405060708090A0B0C0D0E0F
1140}
1141
1142memcpy(ptr, ret, UUID_LEN); // fix uuid in the table
1143return ptr;
1144} // Bungo: end fix
1145
1146void setupSMBIOSTable(void)
1147{
1148SMBStructPtrs *structPtr;
1149uint8_t *buffer;
1150// bool setSMB = true; Bungo
1151
1152if (!origeps) {
1153return;
1154}
1155
1156neweps = origeps;
1157
1158structPtr = (SMBStructPtrs *)malloc(sizeof(SMBStructPtrs));
1159if (!structPtr) {
1160return;
1161}
1162
1163buffer = (uint8_t *)malloc(SMB_ALLOC_SIZE);
1164if (!buffer) {
1165free(structPtr);
1166return;
1167}
1168
1169bzero(buffer, SMB_ALLOC_SIZE);
1170structPtr->new = (SMBStructHeader *)buffer;
1171
1172// getBoolForKey(kSMBIOSdefaults, &setSMB, &bootInfo->chameleonConfig); Bungo
1173getBoolForKey(kSMBIOSdefaults, &useSMBIOSdefaults, &bootInfo->chameleonConfig);
1174// if (setSMB) Bungo
1175setDefaultSMBData();
1176
1177setupNewSMBIOSTable(origeps, structPtr);
1178
1179neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint));
1180if (!neweps) {
1181free(buffer);
1182free(structPtr);
1183return;
1184}
1185bzero(neweps, sizeof(SMBEntryPoint));
1186
1187neweps->anchor[0]= '_';
1188neweps->anchor[1]= 'S';
1189neweps->anchor[2]= 'M';
1190neweps->anchor[3]= '_';
1191neweps->entryPointLength= sizeof(SMBEntryPoint);
1192neweps->majorVersion= 2; // Bungo:
1193neweps->minorVersion= 4; // Here we're using 2.4 SMBIOS rev. as real Macs
1194neweps->maxStructureSize= maxStructSize;
1195neweps->entryPointRevision= 0;
1196
1197neweps->dmi.anchor[0]= '_';
1198neweps->dmi.anchor[1]= 'D';
1199neweps->dmi.anchor[2]= 'M';
1200neweps->dmi.anchor[3]= 'I';
1201neweps->dmi.anchor[4]= '_';
1202neweps->dmi.tableLength= tableLength;
1203neweps->dmi.tableAddress= AllocateKernelMemory(tableLength);
1204neweps->dmi.structureCount= structureCount;
1205neweps->dmi.bcdRevision= 0x24; // ... and 2.4 DMI rev. as real Macs
1206
1207if (!neweps->dmi.tableAddress) {
1208free(buffer);
1209free(structPtr);
1210return;
1211}
1212
1213memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength);
1214
1215Platform.UUID = FixSystemUUID(); // Bungo: fix System UUID
1216
1217neweps->dmi.checksum= 0;
1218neweps->dmi.checksum= 0x100 - checksum8(&neweps->dmi, sizeof(DMIEntryPoint));
1219
1220neweps->checksum= 0;
1221neweps->checksum= 0x100 - checksum8(neweps, sizeof(SMBEntryPoint));
1222
1223free(buffer);
1224free(structPtr);
1225
1226decodeSMBIOSTable(neweps);
1227}
1228
1229void *getSmbios(int which)
1230{
1231switch (which) {
1232case SMBIOS_ORIGINAL:
1233if (!origeps) {
1234origeps = getAddressOfSmbiosTable();
1235}
1236return origeps;
1237case SMBIOS_PATCHED:
1238return neweps;
1239}
1240
1241return 0;
1242}
1243
1244/* Collect any information needed later */
1245void readSMBIOSInfo(SMBEntryPoint *eps)
1246{
1247uint8_t *structPtr = (uint8_t *)eps->dmi.tableAddress;
1248SMBStructHeader *structHeader = (SMBStructHeader *)structPtr;
1249
1250int dimmnbr = 0;
1251Platform.DMI.MaxMemorySlots= 0;// number of memory slots polulated by SMBIOS
1252Platform.DMI.CntMemorySlots= 0;// number of memory slots counted
1253Platform.DMI.MemoryModules= 0;
1254
1255for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));)
1256{
1257switch (structHeader->type)
1258{
1259case kSMBTypeSystemInformation:
1260Platform.UUID = ((SMBSystemInformation *)structHeader)->uuid; // get factory system uuid
1261break;
1262
1263case kSMBTypeSystemEnclosure: // Bungo: determine platform type
1264switch (((SMBSystemEnclosure *)structHeader)->chassisType) {
1265case kSMBchassisDesktop:
1266case kSMBchassisLPDesktop:
1267case kSMBchassisAllInOne:
1268case kSMBchassisLunchBox:
1269PlatformType = 1; // desktop (iMac, MacMini)
1270break;
1271case kSMBchassisPortable:
1272case kSMBchassisLaptop:
1273case kSMBchassisNotebook:
1274case kSMBchassisHandHeld:
1275case kSMBchassisSubNotebook:
1276PlatformType = 2; // notebook (Mac Books)
1277 break;
1278default:
1279PlatformType = 3; // workstation (Mac Pro, Xserve)
1280break;
1281}
1282break;
1283//
1284case kSMBTypePhysicalMemoryArray:
1285Platform.DMI.MaxMemorySlots += ((SMBPhysicalMemoryArray *)structHeader)->numMemoryDevices;
1286break;
1287
1288case kSMBTypeMemoryDevice:
1289Platform.DMI.CntMemorySlots++;
1290if (((SMBMemoryDevice *)structHeader)->memorySize != 0){
1291Platform.DMI.MemoryModules++;
1292}
1293if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0){
1294Platform.RAM.DIMM[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed;
1295}
1296dimmnbr++;
1297break;
1298default:
1299break;
1300}
1301
1302structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
1303for (; ((uint16_t *)structPtr)[0] != 0; structPtr++);
1304
1305if (((uint16_t *)structPtr)[0] == 0) {
1306structPtr += 2;
1307}
1308
1309structHeader = (SMBStructHeader *)structPtr;
1310}
1311}
1312

Archive Download this file

Revision: 2341