Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 2353