Chameleon

Chameleon Svn Source Tree

Root/branches/Bungo/i386/libsaio/smbios.c

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

Archive Download this file

Revision: 2360