Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 2337