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)
726{
727idx++;
728current = structHeader->handle;
729}
730
731sprintf(key, "%s%d", keyString, idx);
732
733if (value)
734{
735if (getIntForKey(key, (int *)&(value->dword), SMBPlist))
736{
737return true;
738}
739}
740else
741{
742if (getValueForKey(key, string, &len, SMBPlist))
743{
744return true;
745}
746}
747return false;
748}
749
750char *getSMBStringForField(SMBStructHeader *structHeader, uint8_t field)
751{
752uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length;
753
754if (!field)
755{
756return NULL;
757}
758
759for (field--; field != 0 && strlen((char *)stringPtr) > 0;
760field--, stringPtr = (uint8_t *)((uint32_t)stringPtr + strlen((char *)stringPtr) + 1));
761
762return (char *)stringPtr;
763}
764
765void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field)
766{
767int strSize;
768
769if (!field)
770{
771return;
772}
773
774if (!string)
775{
776*field = 0;
777return;
778}
779
780strSize = strlen(string);
781
782// remove any spaces found at the end
783while ((strSize != 0) && (string[strSize - 1] == ' '))
784{
785strSize--;
786}
787
788if (strSize == 0)
789{
790*field = 0;
791return;
792}
793
794memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize);
795*field = stringIndex;
796
797stringIndex++;
798stringsSize += strSize + 1;
799}
800
801bool setSMBValue(SMBStructPtrs *structPtr, int idx, returnType *value)
802{
803const char *string = 0;
804int len;
805bool parsed;
806int val;
807
808if (numOfSetters <= idx)
809{
810return false;
811}
812
813switch (SMBSetters[idx].valueType)
814{
815case kSMBString:
816{
817if (SMBSetters[idx].keyString)
818{
819if (getValueForKey(SMBSetters[idx].keyString, &string, &len, SMBPlist))
820{
821break;
822}
823else
824{
825if (structPtr->orig->type == kSMBTypeMemoryDevice)// MemoryDevice only
826{
827if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, &string, NULL))
828{
829break;
830}
831}
832}
833
834}
835if (SMBSetters[idx].getSMBValue)
836{
837if (SMBSetters[idx].getSMBValue((returnType *)&string))
838{
839break;
840}
841}
842// if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue)) Bungo
843if (useSMBIOSdefaults && (SMBSetters[idx].defaultValue))
844{
845string = *(SMBSetters[idx].defaultValue);
846break;
847}
848string = getSMBStringForField(structPtr->orig, *(uint8_t *)value);
849break;
850}
851case kSMBByte:
852case kSMBWord:
853case kSMBDWord:
854//case kSMBQWord:
855if (SMBSetters[idx].keyString)
856{
857parsed = getIntForKey(SMBSetters[idx].keyString, &val, SMBPlist);
858if (!parsed)
859{
860if (structPtr->orig->type == kSMBTypeMemoryDevice)// MemoryDevice only
861{
862parsed = getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, (returnType *)&val);
863}
864}
865if (parsed)
866{
867switch (SMBSetters[idx].valueType)
868{
869case kSMBByte:
870value->byte = (uint8_t)val;
871break;
872case kSMBWord:
873value->word = (uint16_t)val;
874break;
875case kSMBDWord:
876default:
877value->dword = (uint32_t)val;
878break;
879}
880return true;
881}
882}
883
884if (SMBSetters[idx].getSMBValue)
885{
886if (SMBSetters[idx].getSMBValue(value))
887{
888return true;
889}
890}
891// #if 0 Bungo: enables code below
892 // if (*(SMBSetters[idx].defaultValue)) Bungo
893if (useSMBIOSdefaults && (SMBSetters[idx].defaultValue))
894{
895 // value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue); Bungo
896 switch (SMBSetters[idx].valueType)
897 {
898 case kSMBByte:
899 value->byte = *(uint8_t *)(SMBSetters[idx].defaultValue);
900 break;
901 case kSMBWord:
902 value->word = *(uint16_t *)(SMBSetters[idx].defaultValue);
903 break;
904 case kSMBDWord:
905 default:
906 value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue);
907 break;
908 }
909 return true;
910}
911// #endif Bungo
912break;
913}
914
915// if (SMBSetters[idx].valueType == kSMBString && string) Bungo: use null string too -> "Not Specified"
916if ((SMBSetters[idx].valueType == kSMBString) && string)
917{
918setSMBStringForField(structPtr->new, string, &value->byte);
919}
920return true;
921}
922
923//-------------------------------------------------------------------------------------------------------------------------
924// Apple Specific
925//-------------------------------------------------------------------------------------------------------------------------
926void addSMBFirmwareVolume(SMBStructPtrs *structPtr)
927{
928return;
929}
930
931void addSMBMemorySPD(SMBStructPtrs *structPtr)
932{
933/* SPD data from Platform.RAM.spd */
934return;
935}
936
937void addSMBOemProcessorType(SMBStructPtrs *structPtr)
938{
939SMBOemProcessorType *p = (SMBOemProcessorType *)structPtr->new;
940
941p->header.type= kSMBTypeOemProcessorType;
942p->header.length= sizeof(SMBOemProcessorType);
943p->header.handle= handle++;
944
945setSMBValue(structPtr, numOfSetters - 2 , (returnType *)&(p->ProcessorType));
946
947structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorType) + 2);
948tableLength += sizeof(SMBOemProcessorType) + 2;
949structureCount++;
950}
951
952void addSMBOemProcessorBusSpeed(SMBStructPtrs *structPtr)
953{
954SMBOemProcessorBusSpeed *p = (SMBOemProcessorBusSpeed *)structPtr->new;
955
956switch (Platform.CPU.Family)
957{
958case 0x06:
959{
960switch (Platform.CPU.Model)
961{
962case 0x19:// Intel Core i5 650 @3.20 Ghz
963case CPU_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
964case CPU_MODEL_DALES:
965case CPU_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
966case CPU_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
967case CPU_MODEL_NEHALEM_EX:// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x
968case CPU_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
969case CPU_MODEL_WESTMERE_EX:// Intel Xeon E7
970case CPU_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
971case CPU_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
972case CPU_MODEL_IVYBRIDGE_XEON:
973case CPU_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)
974case CPU_MODEL_HASWELL:
975case CPU_MODEL_HASWELL_MB:
976case CPU_MODEL_HASWELL_ULT:
977case CPU_MODEL_CRYSTALWELL:
978
979break;
980
981default:
982return;
983}
984}
985}
986
987p->header.type= kSMBTypeOemProcessorBusSpeed;
988p->header.length= sizeof(SMBOemProcessorBusSpeed);
989p->header.handle= handle++;
990
991setSMBValue(structPtr, numOfSetters -1, (returnType *)&(p->ProcessorBusSpeed));
992
993structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorBusSpeed) + 2);
994tableLength += sizeof(SMBOemProcessorBusSpeed) + 2;
995structureCount++;
996}
997
998//-------------------------------------------------------------------------------------------------------------------------
999// EndOfTable
1000//-------------------------------------------------------------------------------------------------------------------------
1001void addSMBEndOfTable(SMBStructPtrs *structPtr)
1002{
1003structPtr->new->type= kSMBTypeEndOfTable;
1004structPtr->new->length= sizeof(SMBStructHeader);
1005structPtr->new->handle= handle++;
1006
1007structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBStructHeader) + 2);
1008tableLength += sizeof(SMBStructHeader) + 2;
1009structureCount++;
1010}
1011
1012void setSMBStruct(SMBStructPtrs *structPtr)
1013{
1014bool setterFound = false;
1015
1016uint8_t *ptr;
1017SMBWord structSize;
1018int i;
1019
1020/* http://forge.voodooprojects.org/p/chameleon/issues/361/ */
1021bool forceFullMemInfo = false;
1022
1023if (structPtr->orig->type == kSMBTypeMemoryDevice)
1024{
1025getBoolForKey(kMemFullInfo, &forceFullMemInfo, &bootInfo->chameleonConfig);
1026if (forceFullMemInfo)
1027{
1028structPtr->orig->length = 27;
1029}
1030}
1031
1032stringIndex = 1;
1033stringsSize = 0;
1034
1035if (handle < structPtr->orig->handle)
1036{
1037handle = structPtr->orig->handle;
1038}
1039
1040memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);
1041
1042for (i = 0; i < numOfSetters; i++)
1043{
1044if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structPtr->orig->length))
1045{
1046setterFound = true;
1047setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset));
1048}
1049}
1050
1051if (setterFound)
1052{
1053ptr = (uint8_t *)structPtr->new + structPtr->orig->length;
1054for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1055
1056if (((uint16_t *)ptr)[0] == 0)
1057{
1058ptr += 2;
1059}
1060structSize = ptr - (uint8_t *)structPtr->new;
1061}
1062else
1063{
1064ptr = (uint8_t *)structPtr->orig + structPtr->orig->length;
1065for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1066
1067if (((uint16_t *)ptr)[0] == 0)
1068{
1069ptr += 2;
1070}
1071
1072structSize = ptr - (uint8_t *)structPtr->orig;
1073memcpy((void *)structPtr->new, structPtr->orig, structSize);
1074}
1075
1076structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + structSize);
1077
1078tableLength += structSize;
1079
1080if (structSize > maxStructSize)
1081{
1082maxStructSize = structSize;
1083}
1084
1085structureCount++;
1086}
1087
1088void setupNewSMBIOSTable(SMBEntryPoint *eps, SMBStructPtrs *structPtr)
1089{
1090uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress;
1091structPtr->orig = (SMBStructHeader *)ptr;
1092
1093for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));)
1094{
1095switch (structPtr->orig->type)
1096{
1097/* Skip all Apple Specific Structures */
1098case kSMBTypeFirmwareVolume:
1099case kSMBTypeMemorySPD:
1100case kSMBTypeOemProcessorType:
1101case kSMBTypeOemProcessorBusSpeed:
1102/* And this one too, to be added at the end */
1103case kSMBTypeEndOfTable:
1104break;
1105
1106default:
1107{
1108/* Add */
1109setSMBStruct(structPtr);
1110break;
1111}
1112}
1113
1114ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length);
1115for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1116
1117if (((uint16_t *)ptr)[0] == 0)
1118{
1119ptr += 2;
1120}
1121
1122structPtr->orig = (SMBStructHeader *)ptr;
1123}
1124
1125addSMBFirmwareVolume(structPtr);
1126addSMBMemorySPD(structPtr);
1127addSMBOemProcessorType(structPtr);
1128addSMBOemProcessorBusSpeed(structPtr);
1129
1130addSMBEndOfTable(structPtr);
1131}
1132
1133// Bungo: does fix system uuid in SMBIOS (and EFI) instead of in EFI only
1134uint8_t *FixSystemUUID()
1135{
1136uint8_t *ptr = (uint8_t *)neweps->dmi.tableAddress;
1137SMBStructHeader *structHeader = (SMBStructHeader *)ptr;
1138int i, isZero, isOnes;
1139uint8_t FixedUUID[UUID_LEN] = {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01};
1140const char *sysId = getStringForKey(kSMBSystemInformationUUIDKey, SMBPlist);
1141uint8_t *ret = (uint8_t *)getUUIDFromString(sysId);
1142
1143for (;(structHeader->type != kSMBTypeSystemInformation);) // find System Information Table (Type 1) in patched SMBIOS
1144{
1145ptr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
1146for (; ((uint16_t *)ptr)[0] != 0; ptr++);
1147
1148if (((uint16_t *)ptr)[0] == 0)
1149{
1150ptr += 2;
1151}
1152
1153structHeader = (SMBStructHeader *)ptr;
1154}
1155
1156ptr = ((SMBSystemInformation *)structHeader)->uuid;
1157
1158if (!sysId || !ret) // no or bad custom UUID,...
1159{
1160sysId = 0;
1161 ret = ((SMBSystemInformation *)structHeader)->uuid; // ...try bios dmi info UUID extraction
1162}
1163
1164for (i=0, isZero=1, isOnes=1; i<UUID_LEN; i++) // check if empty or setable, means: no uuid present
1165{
1166if (ret[i] != 0x00)
1167{
1168isZero = 0;
1169}
1170
1171if (ret[i] != 0xff)
1172{
1173isOnes = 0;
1174}
1175}
1176
1177if (isZero || isOnes) // if empty or setable...
1178{
1179verbose("No UUID present in SMBIOS System Information Table\n");
1180ret = FixedUUID; // ...set a fixed value for system-id = 000102030405060708090A0B0C0D0E0F
1181}
1182
1183memcpy(ptr, ret, UUID_LEN); // fix uuid in the table
1184return ptr;
1185} // Bungo: end fix
1186
1187void setupSMBIOSTable(void)
1188{
1189SMBStructPtrs *structPtr;
1190uint8_t *buffer;
1191// bool setSMB = true; Bungo
1192
1193if (!origeps)
1194{
1195return;
1196}
1197
1198neweps = origeps;
1199
1200structPtr = (SMBStructPtrs *)malloc(sizeof(SMBStructPtrs));
1201if (!structPtr)
1202{
1203return;
1204}
1205
1206buffer = (uint8_t *)malloc(SMB_ALLOC_SIZE);
1207if (!buffer)
1208{
1209free(structPtr);
1210return;
1211}
1212
1213bzero(buffer, SMB_ALLOC_SIZE);
1214structPtr->new = (SMBStructHeader *)buffer;
1215
1216// getBoolForKey(kSMBIOSdefaults, &setSMB, &bootInfo->chameleonConfig); Bungo
1217getBoolForKey(kSMBIOSdefaults, &useSMBIOSdefaults, &bootInfo->chameleonConfig);
1218// if (setSMB)
1219 setDefaultSMBData();
1220// Bungo
1221
1222setupNewSMBIOSTable(origeps, structPtr);
1223
1224neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint));
1225if (!neweps)
1226{
1227free(buffer);
1228free(structPtr);
1229return;
1230}
1231bzero(neweps, sizeof(SMBEntryPoint));
1232
1233neweps->anchor[0]= '_';
1234neweps->anchor[1]= 'S';
1235neweps->anchor[2]= 'M';
1236neweps->anchor[3]= '_';
1237neweps->entryPointLength= sizeof(SMBEntryPoint);
1238neweps->majorVersion= 2; // Bungo:
1239neweps->minorVersion= 4; // We're using 2.4 SMBIOS rev. as real Macs
1240neweps->maxStructureSize= maxStructSize;
1241neweps->entryPointRevision= 0;
1242
1243neweps->dmi.anchor[0]= '_';
1244neweps->dmi.anchor[1]= 'D';
1245neweps->dmi.anchor[2]= 'M';
1246neweps->dmi.anchor[3]= 'I';
1247neweps->dmi.anchor[4]= '_';
1248neweps->dmi.tableLength= tableLength;
1249neweps->dmi.tableAddress= AllocateKernelMemory(tableLength);
1250neweps->dmi.structureCount= structureCount;
1251neweps->dmi.bcdRevision= 0x24;
1252
1253if (!neweps->dmi.tableAddress)
1254{
1255free(buffer);
1256free(structPtr);
1257return;
1258}
1259
1260memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength);
1261
1262// Bungo
1263Platform.UUID = FixSystemUUID(); // Bungo: fix System UUID
1264
1265neweps->dmi.checksum= 0;
1266neweps->dmi.checksum= 0x100 - checksum8(&neweps->dmi, sizeof(DMIEntryPoint));
1267
1268neweps->checksum= 0;
1269neweps->checksum= 0x100 - checksum8(neweps, sizeof(SMBEntryPoint));
1270
1271free(buffer);
1272free(structPtr);
1273
1274decodeSMBIOSTable(neweps);
1275}
1276
1277void *getSmbios(int which)
1278{
1279switch (which)
1280{
1281case SMBIOS_ORIGINAL:
1282if (!origeps)
1283{
1284origeps = getAddressOfSmbiosTable();
1285}
1286return origeps;
1287case SMBIOS_PATCHED:
1288return neweps;
1289}
1290
1291return 0;
1292}
1293
1294/* Collect any information needed later */
1295void readSMBIOSInfo(SMBEntryPoint *eps)
1296{
1297uint8_t *structPtr = (uint8_t *)eps->dmi.tableAddress;
1298SMBStructHeader *structHeader = (SMBStructHeader *)structPtr;
1299
1300int dimmnbr = 0;
1301Platform.DMI.MaxMemorySlots= 0;// number of memory slots polulated by SMBIOS
1302Platform.DMI.CntMemorySlots= 0;// number of memory slots counted
1303Platform.DMI.MemoryModules= 0;
1304
1305for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));)
1306{
1307switch (structHeader->type)
1308{
1309/* Bungo: fixed in smbios now
1310case kSMBTypeSystemInformation:
1311Platform.UUID = ((SMBSystemInformation *)structHeader)->uuid;
1312break;
1313*/
1314case kSMBTypeSystemEnclosure: // Bungo: determine platform type
1315switch (((SMBSystemEnclosure *)structHeader)->chassisType) {
1316case kSMBchassisDesktop:
1317case kSMBchassisLPDesktop:
1318case kSMBchassisAllInOne:
1319case kSMBchassisLunchBox:
1320PlatformType = 1; // desktop (iMac, MacMini)
1321break;
1322case kSMBchassisPortable:
1323case kSMBchassisLaptop:
1324case kSMBchassisNotebook:
1325case kSMBchassisHandHeld:
1326case kSMBchassisSubNotebook:
1327PlatformType = 2; // notebook (Mac Books)
1328 break;
1329default:
1330PlatformType = 3; // workstation (Mac Pro, Xserve)
1331break;
1332}
1333break;
1334//
1335case kSMBTypePhysicalMemoryArray:
1336Platform.DMI.MaxMemorySlots += ((SMBPhysicalMemoryArray *)structHeader)->numMemoryDevices;
1337break;
1338
1339case kSMBTypeMemoryDevice:
1340Platform.DMI.CntMemorySlots++;
1341if (((SMBMemoryDevice *)structHeader)->memorySize != 0)
1342{
1343Platform.DMI.MemoryModules++;
1344}
1345if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0)
1346{
1347Platform.RAM.DIMM[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed;
1348}
1349dimmnbr++;
1350break;
1351default:
1352break;
1353}
1354
1355structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
1356for (; ((uint16_t *)structPtr)[0] != 0; structPtr++);
1357
1358if (((uint16_t *)structPtr)[0] == 0)
1359{
1360structPtr += 2;
1361}
1362
1363structHeader = (SMBStructHeader *)structPtr;
1364}
1365}
1366

Archive Download this file

Revision: 2329