Chameleon

Chameleon Svn Source Tree

Root/trunk/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// Default SMBIOS Data
123//-------------------------------------------------------------------------------------------------------------------------
124/* Rewrite: use a struct */
125
126#define kDefaultVendorManufacturer"Apple Inc."
127#define kDefaultBIOSReleaseDate"11/06/2009"
128#define kDefaultSerialNumber"SOMESRLNMBR"
129#define kDefaultskuNumber"Default System SKU#"
130#define kDefaultBoardProduct"Mac-F4208DC8"
131#define kDefaultBoardType"10" // 0xA
132#define kDefaultSystemVersion"1.0"
133
134//Bungo
135/* 256 = 0x0100 -> swap bytes: 0x0001 -> Release: 0.1 (see SMBIOS spec. table Type 0) */
136#define kDefaultBIOSRelease 256
137
138#define KDefaultBoardSerialNumber"C02140302D5DMT31M" // new C07019501PLDCVHAD - C02032101R5DC771H
139#define KDefaultBoardAssetTagNumber"Pro-Enclosure" // ErmaC
140#define kDefaultLocatioInChassis"Part Component" // ErmaC
141
142// defaults for a Mac mini
143#define kDefaultMacminiFamily"Macmini"
144#define kDefaultMacmini"Macmini1,1"
145#define kDefaultMacminiBIOSVersion" MM21.88Z.009A.B00.0903051113"
146
147// defaults for a MacBook
148#define kDefaultMacBookFamily"MacBook"
149#define kDefaultMacBook"MacBook4,1"
150#define kDefaultMacBookBIOSVersion" MB41.88Z.0073.B00.0903051113"
151
152// defaults for a MacBook Pro
153#define kDefaultMacBookProFamily"MacBookPro"
154#define kDefaultMacBookPro"MacBookPro4,1"
155#define kDefaultMacBookProBIOSVersion" MBP41.88Z.0073.B00.0903051113"
156
157// defaults for an iMac
158#define kDefaultiMacFamily"iMac"
159#define kDefaultiMac"iMac8,1"
160#define kDefaultiMacBIOSVersion" IM81.88Z.00C1.B00.0903051113"
161// defaults for an iMac11,1 core i3/i5/i7
162#define kDefaultiMacNehalem"iMac11,1"
163#define kDefaultiMacNehalemBIOSVersion" IM111.88Z.0034.B00.0903051113"
164// defaults for an iMac12,1
165#define kDefaultiMacSandy"iMac12,1"
166#define kDefaultiMacSandyBIOSVersion" IM121.88Z.0047.B00.1102091756"
167
168// defaults for a Mac Pro
169#define kDefaultMacProFamily"MacPro"
170#define kDefaultMacPro"MacPro3,1"
171#define kDefaultMacProBIOSVersion" MP31.88Z.006C.B05.0903051113"
172// defaults for a Mac Pro 4,1 core i7/Xeon
173#define kDefaultMacProNehalem"MacPro4,1"
174#define kDefaultMacProNehalemBIOSVersion" MP41.88Z.0081.B04.0903051113"
175// defaults for a Mac Pro 5,1 core i7/Xeon
176#define kDefaultMacProWestmere"MacPro5,1"
177#define kDefaultMacProWestmereBIOSVersion" MP51.88Z.007F.B03.1010071432"
178#define kDefaultMacProWestmereBIOSReleaseDate"10/07/2010"
179//-------------------------------------------------------------------------------------------------------------------------
180
181
182#define getFieldOffset(struct, field)((uint8_t)(uint32_t)&(((struct *)0)->field))
183
184typedef struct
185{
186SMBStructHeader *orig;
187SMBStructHeader *new;
188} SMBStructPtrs;
189
190/* =======================
191 BIOS Information (Type 0)
192 ========================= */
193typedef struct
194{
195char *vendor;
196char *version;
197char *releaseDate;
198uint16_t release; // Bungo
199} defaultBIOSInfo_t;
200
201defaultBIOSInfo_t defaultBIOSInfo;
202
203/* =========================
204 System Information (Type 1)
205 =========================== */
206typedef struct
207{
208char *manufacturer;
209char *productName;
210char *version;
211char *serialNumber;
212char *skuNumber;// ErmaC
213char *family;
214} defaultSystemInfo_t;
215
216defaultSystemInfo_t defaultSystemInfo;
217
218/* =========================================
219 Base Board (or Module) Information (Type 2)
220 =========================================== */
221typedef struct
222{
223char *manufacturer;
224char *product;
225char *productName;// ErmaC
226char *serialNumber;// ErmaC
227char *assetTagNumber;// ErmaC
228char *locationInChassis;// ErmaC
229char *boardType;// ErmaC
230} defaultBaseBoard_t;
231
232defaultBaseBoard_t defaultBaseBoard;
233
234typedef struct
235{
236uint8_ttype;
237SMBValueTypevalueType;
238uint8_tfieldOffset;
239char*keyString;
240bool(*getSMBValue)(returnType *);
241// Bungo
242// char**defaultValue;
243void*defaultValue;
244} SMBValueSetter;
245
246SMBValueSetter SMBSetters[] =
247{
248/* =======================
249 BIOS Information (Type 0)
250 ========================= */
251{ kSMBTypeBIOSInformation, kSMBString, getFieldOffset(SMBBIOSInformation, vendor),
252kSMBBIOSInformationVendorKey, NULL, &defaultBIOSInfo.vendor }, // SMbiosvendor - Apple Inc.
253
254{ kSMBTypeBIOSInformation, kSMBString, getFieldOffset(SMBBIOSInformation, version),
255kSMBBIOSInformationVersionKey, NULL, &defaultBIOSInfo.version }, // SMbiosversion - MP31.88Z.006C.B05.0802291410
256
257{ kSMBTypeBIOSInformation, kSMBString, getFieldOffset(SMBBIOSInformation, releaseDate),
258kSMBBIOSInformationReleaseDateKey, NULL, &defaultBIOSInfo.releaseDate }, // SMbiosdate - 02/29/08
259
260// Bungo
261{ kSMBTypeBIOSInformation, kSMBWord, getFieldOffset(SMBBIOSInformation, releaseMajor),
262kSMBBIOSInformationReleaseKey, NULL,&defaultBIOSInfo.release }, // SMbiosrelease - 256
263//
264
265/* =========================
266 System Information (Type 1)
267 =========================== */
268{kSMBTypeSystemInformation,kSMBString,getFieldOffset(SMBSystemInformation, manufacturer),
269kSMBSystemInformationManufacturerKey, NULL,&defaultSystemInfo.manufacturer}, // SMmanufacturer - Apple Inc.
270
271{kSMBTypeSystemInformation,kSMBString,getFieldOffset(SMBSystemInformation, productName),
272kSMBSystemInformationProductNameKey, NULL, &defaultSystemInfo.productName }, // SMproductname - MacPro3,1
273
274{kSMBTypeSystemInformation,kSMBString,getFieldOffset(SMBSystemInformation, version),
275kSMBSystemInformationVersionKey, NULL, &defaultSystemInfo.version }, // SMsystemversion - 1.0
276
277{kSMBTypeSystemInformation,kSMBString,getFieldOffset(SMBSystemInformation, serialNumber),
278kSMBSystemInformationSerialNumberKey, NULL, &defaultSystemInfo.serialNumber }, // SMserial - Serial number
279
280// Bungo
281{kSMBTypeSystemInformation,kSMBString,getFieldOffset(SMBSystemInformation, skuNumber),
282kSMBSystemInformationSKUNumberKey, NULL, &defaultSystemInfo.skuNumber}, // SMskunumber - System SKU#
283
284//
285
286{kSMBTypeSystemInformation,kSMBString,getFieldOffset(SMBSystemInformation, family),
287kSMBSystemInformationFamilyKey,NULL,&defaultSystemInfo.family}, // SMfamily - MacPro
288
289
290/* =========================================
291 Base Board (or Module) Information (Type 2)
292 =========================================== */
293{kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, manufacturer),
294kSMBBaseBoardManufacturerKey, NULL, &defaultBaseBoard.manufacturer }, // SMboardmanufacturer - Apple Inc.
295
296{kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, product),
297kSMBBaseBoardProductKey, NULL, &defaultBaseBoard.product}, // SMboardproduct - Mac-F2268DC8
298
299// Bungo
300{kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, version),
301kSMBBaseBoardVersionKey, NULL, &defaultBaseBoard.productName}, // SMboardproductname - MacPro3,1
302
303{kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, serialNumber),
304kSMBBaseBoardSerialNumberKey, NULL, &defaultBaseBoard.serialNumber }, // SMboardserial - C02140302D5DMT31M
305
306{kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, assetTagNumber),
307kSMBBaseBoardAssetTagNumberKey, NULL, &defaultBaseBoard.assetTagNumber }, // SMboardassetag - Base Board Asset Tag#
308
309{kSMBTypeBaseBoard,kSMBString,getFieldOffset(SMBBaseBoard, locationInChassis),
310kSMBBaseBoardLocationInChassisKey, NULL, &defaultBaseBoard.locationInChassis }, // SMboardlocation - Part Component
311
312{kSMBTypeBaseBoard,kSMBByte,getFieldOffset(SMBBaseBoard, boardType),
313kSMBBaseBoardTypeKey,NULL, &defaultBaseBoard.boardType }, // SMboardtype - 10 (Motherboard) all model, 11 (Processor+Memory Module) MacPro
314//
315
316 // Bungo
317/* =======================
318 System Enclosure (Type 3)
319 ========================= */
320{kSMBTypeSystemEnclosure,kSMBString,getFieldOffset(SMBSystemEnclosure, manufacturer),
321kSMBSystemEnclosureManufacturerKey, NULL,&defaultBaseBoard.manufacturer }, // SMchassismanufacturer - Apple Inc.
322
323{kSMBTypeSystemEnclosure, kSMBByte,getFieldOffset(SMBSystemEnclosure, type),
324kSMBSystemEnclosureTypeKey, NULL, &defaultBaseBoard.boardType}, // SMchassistype - 7
325
326{kSMBTypeSystemEnclosure, kSMBString, getFieldOffset(SMBSystemEnclosure, version),
327kSMBSystemEnclosureVersionKey, NULL, &defaultBaseBoard.product }, // SMchassisversion - Mac-F42C88C8
328
329{kSMBTypeSystemEnclosure, kSMBString, getFieldOffset(SMBSystemEnclosure, serialNumber),
330kSMBSystemEnclosureSerialNumberKey, NULL, &defaultSystemInfo.serialNumber }, // SMchassisserial
331
332{kSMBTypeSystemEnclosure, kSMBString, getFieldOffset(SMBSystemEnclosure, assetTagNumber),
333kSMBSystemEnclosureAssetTagNumberKey, NULL, &defaultBaseBoard.assetTagNumber }, // SMchassisassettag - Pro Enclosure
334
335
336/* ============================
337 Processor Information (Type 4)
338 ============================== */
339{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, socketDesignation),
340kSMBProcessorInformationSocketKey, NULL, NULL}, // SMcpusocket -
341
342{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, manufacturer),
343kSMBProcessorInformationManufacturerKey, NULL, NULL}, // SMcpumanufacturer - Intel(R) Corporation
344
345{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, processorVersion),
346kSMBProcessorInformationVersionKey, NULL, NULL}, // SMcpuversion
347
348{kSMBTypeProcessorInformation,kSMBWord, getFieldOffset(SMBProcessorInformation, externalClock),
349kSMBProcessorInformationExternalClockKey, getProcessorInformationExternalClock,NULL}, // SMcpuexternalclock
350
351{kSMBTypeProcessorInformation,kSMBWord, getFieldOffset(SMBProcessorInformation, maximumClock),
352kSMBProcessorInformationMaximumClockKey, getProcessorInformationMaximumClock,NULL}, // SMcpumaxspeed
353
354// Bungo
355{kSMBTypeProcessorInformation,kSMBWord,getFieldOffset(SMBProcessorInformation, currentClock),
356kSMBProcessorInformationCurrentClockKey, NULL, NULL}, // SMcpucurrentspeed
357
358{kSMBTypeProcessorInformation,kSMBByte,getFieldOffset(SMBProcessorInformation, processorUpgrade),
359kSMBProcessorInformationUpgradeKey, NULL, NULL}, // SMcpuupgrade
360//
361
362{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, serialNumber),
363NULL, NULL, NULL},
364
365 // Bungo
366{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, assetTag),
367kSMBProcessorInformationAssetTagNumberKey, NULL, NULL}, // SMcpuassettag
368
369//
370
371{kSMBTypeProcessorInformation,kSMBString,getFieldOffset(SMBProcessorInformation, partNumber),
372NULL, NULL, NULL},
373
374/* =====================
375 Memory Device (Type 17)
376 ======================= */
377{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, deviceLocator),
378kSMBMemoryDeviceDeviceLocatorKey, NULL, NULL},
379
380{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, bankLocator),
381kSMBMemoryDeviceBankLocatorKey, NULL, NULL},
382
383{kSMBTypeMemoryDevice,kSMBByte,getFieldOffset(SMBMemoryDevice, memoryType),
384kSMBMemoryDeviceMemoryTypeKey, getSMBMemoryDeviceMemoryType,NULL},
385
386{kSMBTypeMemoryDevice,kSMBWord,getFieldOffset(SMBMemoryDevice, memorySpeed),
387kSMBMemoryDeviceMemorySpeedKey, getSMBMemoryDeviceMemorySpeed,NULL},
388
389{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, manufacturer),
390kSMBMemoryDeviceManufacturerKey, getSMBMemoryDeviceManufacturer, NULL},
391
392{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, serialNumber),
393kSMBMemoryDeviceSerialNumberKey, getSMBMemoryDeviceSerialNumber, NULL},
394
395{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, assetTag),
396NULL, NULL, NULL},
397
398{kSMBTypeMemoryDevice,kSMBWord,getFieldOffset(SMBMemoryDevice, errorHandle),
399NULL, getSMBMemoryDeviceMemoryErrorHandle, NULL},
400
401{kSMBTypeMemoryDevice,kSMBString,getFieldOffset(SMBMemoryDevice, partNumber),
402kSMBMemoryDevicePartNumberKey, getSMBMemoryDevicePartNumber, NULL},
403//
404
405//-------------------------------------------------------------------------------------------------------------------------
406// Apple Specific
407//-------------------------------------------------------------------------------------------------------------------------
408// OEM Processor Type (Apple Specific - Type 131)
409{kSMBTypeOemProcessorType,kSMBWord,getFieldOffset(SMBOemProcessorType, ProcessorType),kSMBOemProcessorTypeKey,
410getSMBOemProcessorType,NULL},
411
412// OEM Processor Bus Speed (Apple Specific - Type 132)
413{kSMBTypeOemProcessorBusSpeed,kSMBWord,getFieldOffset(SMBOemProcessorBusSpeed, ProcessorBusSpeed),kSMBOemProcessorBusSpeedKey,
414getSMBOemProcessorBusSpeed,NULL}
415};
416
417int numOfSetters = sizeof(SMBSetters) / sizeof(SMBValueSetter);
418
419
420SMBEntryPoint *origeps= 0;
421SMBEntryPoint *neweps= 0;
422
423static uint8_t stringIndex;// increament when a string is added and set the field value accordingly
424static uint8_t stringsSize;// add string size
425
426static SMBWord tableLength= 0;
427static SMBWord handle= 0;
428static SMBWord maxStructSize= 0;
429static SMBWord structureCount= 0;
430
431bool useSMBIOSdefaults = true; // Bungo
432
433/* Rewrite this function */
434void setDefaultSMBData(void)
435{
436defaultBIOSInfo.vendor = kDefaultVendorManufacturer;
437defaultBIOSInfo.releaseDate = kDefaultBIOSReleaseDate;
438
439defaultBIOSInfo.release = kDefaultBIOSRelease; // Bungo
440
441defaultSystemInfo.manufacturer = kDefaultVendorManufacturer;
442defaultSystemInfo.version = kDefaultSystemVersion;
443defaultSystemInfo.serialNumber = kDefaultSerialNumber;
444defaultSystemInfo.skuNumber = kDefaultskuNumber; // Bungo
445
446defaultBaseBoard.manufacturer = kDefaultVendorManufacturer;
447defaultBaseBoard.product = kDefaultBoardProduct;
448defaultBaseBoard.boardType = kDefaultBoardType;// ErmaC
449defaultBaseBoard.serialNumber = KDefaultBoardSerialNumber;// ErmaC
450defaultBaseBoard.assetTagNumber = KDefaultBoardAssetTagNumber;// ErmaC
451defaultBaseBoard.locationInChassis = kDefaultLocatioInChassis;// ErmaC
452
453if (platformCPUFeature(CPU_FEATURE_MOBILE))
454{
455if (Platform.CPU.NoCores > 1)
456{
457defaultBIOSInfo.version= kDefaultMacBookProBIOSVersion;
458defaultSystemInfo.productName= kDefaultMacBookPro;
459defaultSystemInfo.family= kDefaultMacBookProFamily;
460}
461else
462{
463defaultBIOSInfo.version= kDefaultMacBookBIOSVersion;
464defaultSystemInfo.productName= kDefaultMacBook;
465defaultSystemInfo.family= kDefaultMacBookFamily;
466}
467}
468else
469{
470switch (Platform.CPU.NoCores)
471{
472case 1:
473defaultBIOSInfo.version= kDefaultMacminiBIOSVersion;
474defaultSystemInfo.productName= kDefaultMacmini;
475defaultSystemInfo.family= kDefaultMacminiFamily;
476break;
477
478case 2:
479defaultBIOSInfo.version= kDefaultiMacBIOSVersion;
480defaultSystemInfo.productName= kDefaultiMac;
481defaultSystemInfo.family= kDefaultiMacFamily;
482break;
483default:
484{
485switch (Platform.CPU.Family)
486{
487case 0x06:
488{
489switch (Platform.CPU.Model)
490{
491case CPU_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
492case CPU_MODEL_DALES:
493case CPU_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
494defaultBIOSInfo.version= kDefaultiMacNehalemBIOSVersion;
495defaultSystemInfo.productName= kDefaultiMacNehalem;
496defaultSystemInfo.family= kDefaultiMacFamily;
497break;
498
499case CPU_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
500case CPU_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
501defaultBIOSInfo.version= kDefaultiMacSandyBIOSVersion;
502defaultSystemInfo.productName= kDefaultiMacSandy;
503defaultSystemInfo.family= kDefaultiMacFamily;
504break;
505case CPU_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
506case CPU_MODEL_NEHALEM_EX:// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x
507defaultBIOSInfo.version= kDefaultMacProNehalemBIOSVersion;
508defaultSystemInfo.productName= kDefaultMacProNehalem;
509defaultSystemInfo.family= kDefaultMacProFamily;
510break;
511
512case CPU_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
513case CPU_MODEL_WESTMERE_EX:// Intel Xeon E7
514case CPU_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)
515defaultBIOSInfo.version= kDefaultMacProWestmereBIOSVersion;
516defaultBIOSInfo.releaseDate= kDefaultMacProWestmereBIOSReleaseDate;
517defaultSystemInfo.productName= kDefaultMacProWestmere;
518defaultSystemInfo.family= kDefaultMacProFamily;
519break;
520
521default:
522defaultBIOSInfo.version= kDefaultMacProBIOSVersion;
523defaultSystemInfo.productName= kDefaultMacPro;
524defaultSystemInfo.family= kDefaultMacProFamily;
525break;
526}
527break;
528}
529default:
530defaultBIOSInfo.version= kDefaultMacProBIOSVersion;
531defaultSystemInfo.productName= kDefaultMacPro;
532defaultSystemInfo.family= kDefaultMacProFamily;
533break;
534}
535break;
536}
537}
538}
539}
540
541/* Used for SM*n smbios.plist keys */
542bool getSMBValueForKey(SMBStructHeader *structHeader, const char *keyString, const char **string, returnType *value)
543{
544static int idx = -1;
545static int current = -1;
546int len;
547char key[24];
548
549if (current != structHeader->handle)
550{
551idx++;
552current = structHeader->handle;
553}
554
555sprintf(key, "%s%d", keyString, idx);
556
557if (value)
558{
559if (getIntForKey(key, (int *)&(value->dword), SMBPlist))
560{
561return true;
562}
563}
564else
565{
566if (getValueForKey(key, string, &len, SMBPlist))
567{
568return true;
569}
570}
571return false;
572}
573
574char *getSMBStringForField(SMBStructHeader *structHeader, uint8_t field)
575{
576uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length;
577
578if (!field)
579{
580return NULL;
581}
582
583for (field--; field != 0 && strlen((char *)stringPtr) > 0;
584field--, stringPtr = (uint8_t *)((uint32_t)stringPtr + strlen((char *)stringPtr) + 1));
585
586return (char *)stringPtr;
587}
588
589void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field)
590{
591int strSize;
592
593if (!field)
594{
595return;
596}
597
598if (!string)
599{
600*field = 0;
601return;
602}
603
604strSize = strlen(string);
605
606// remove any spaces found at the end
607while ((strSize != 0) && (string[strSize - 1] == ' '))
608{
609strSize--;
610}
611
612if (strSize == 0)
613{
614*field = 0;
615return;
616}
617
618memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize);
619*field = stringIndex;
620
621stringIndex++;
622stringsSize += strSize + 1;
623}
624
625bool setSMBValue(SMBStructPtrs *structPtr, int idx, returnType *value)
626{
627const char *string = 0;
628int len;
629bool parsed;
630int val;
631
632if (numOfSetters <= idx)
633{
634return false;
635}
636
637switch (SMBSetters[idx].valueType)
638{
639case kSMBString:
640{
641if (SMBSetters[idx].keyString)
642{
643if (getValueForKey(SMBSetters[idx].keyString, &string, &len, SMBPlist))
644{
645break;
646}
647else
648{
649if (structPtr->orig->type == kSMBTypeMemoryDevice)// MemoryDevice only
650{
651if (getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, &string, NULL))
652{
653break;
654}
655}
656}
657
658}
659if (SMBSetters[idx].getSMBValue)
660{
661if (SMBSetters[idx].getSMBValue((returnType *)&string))
662{
663break;
664 // if ((SMBSetters[idx].defaultValue) && *(SMBSetters[idx].defaultValue)) Bungo
665}
666}
667if (useSMBIOSdefaults && (SMBSetters[idx].defaultValue) && *(char *)(SMBSetters[idx].defaultValue))
668{
669 // string = *(SMBSetters[idx].defaultValue); Bungo
670string = (char *)(SMBSetters[idx].defaultValue);
671break;
672}
673string = getSMBStringForField(structPtr->orig, *(uint8_t *)value);
674break;
675}
676case kSMBByte:
677case kSMBWord:
678case kSMBDWord:
679//case kSMBQWord:
680if (SMBSetters[idx].keyString)
681{
682parsed = getIntForKey(SMBSetters[idx].keyString, &val, SMBPlist);
683if (!parsed)
684{
685if (structPtr->orig->type == kSMBTypeMemoryDevice)// MemoryDevice only
686{
687parsed = getSMBValueForKey(structPtr->orig, SMBSetters[idx].keyString, NULL, (returnType *)&val);
688}
689}
690if (parsed)
691{
692switch (SMBSetters[idx].valueType)
693{
694case kSMBByte:
695value->byte = (uint8_t)val;
696break;
697case kSMBWord:
698value->word = (uint16_t)val;
699break;
700case kSMBDWord:
701default:
702value->dword = (uint32_t)val;
703break;
704}
705return true;
706}
707}
708
709if (SMBSetters[idx].getSMBValue)
710{
711if (SMBSetters[idx].getSMBValue(value))
712{
713return true;
714}
715}
716// #if 0 Bungo: enables code below
717 // if (*(SMBSetters[idx].defaultValue)) Bungo
718if (useSMBIOSdefaults && (SMBSetters[idx].defaultValue))
719{
720 // value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue); Bungo
721 switch (SMBSetters[idx].valueType)
722 {
723 case kSMBByte:
724 value->byte = *(uint8_t *)(SMBSetters[idx].defaultValue);
725 break;
726 case kSMBWord:
727 value->word = *(uint16_t *)(SMBSetters[idx].defaultValue);
728 break;
729 case kSMBDWord:
730 default:
731 value->dword = *(uint32_t *)(SMBSetters[idx].defaultValue);
732 break;
733 }
734 return true;
735}
736// #endif Bungo
737break;
738}
739
740// if (SMBSetters[idx].valueType == kSMBString && string) Bungo: use null string too -> "Not Specified"
741if (SMBSetters[idx].valueType == kSMBString)
742{
743setSMBStringForField(structPtr->new, string, &value->byte);
744}
745return true;
746}
747
748//-------------------------------------------------------------------------------------------------------------------------
749// Apple Specific
750//-------------------------------------------------------------------------------------------------------------------------
751void addSMBFirmwareVolume(SMBStructPtrs *structPtr)
752{
753return;
754}
755
756void addSMBMemorySPD(SMBStructPtrs *structPtr)
757{
758/* SPD data from Platform.RAM.spd */
759return;
760}
761
762void addSMBOemProcessorType(SMBStructPtrs *structPtr)
763{
764SMBOemProcessorType *p = (SMBOemProcessorType *)structPtr->new;
765
766p->header.type= kSMBTypeOemProcessorType;
767p->header.length= sizeof(SMBOemProcessorType);
768p->header.handle= handle++;
769
770setSMBValue(structPtr, numOfSetters - 2 , (returnType *)&(p->ProcessorType));
771
772structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorType) + 2);
773tableLength += sizeof(SMBOemProcessorType) + 2;
774structureCount++;
775}
776
777void addSMBOemProcessorBusSpeed(SMBStructPtrs *structPtr)
778{
779SMBOemProcessorBusSpeed *p = (SMBOemProcessorBusSpeed *)structPtr->new;
780
781switch (Platform.CPU.Family)
782{
783case 0x06:
784{
785switch (Platform.CPU.Model)
786{
787case 0x19:// Intel Core i5 650 @3.20 Ghz
788case CPU_MODEL_FIELDS:// Intel Core i5, i7, Xeon X34xx LGA1156 (45nm)
789case CPU_MODEL_DALES:
790case CPU_MODEL_DALES_32NM:// Intel Core i3, i5 LGA1156 (32nm)
791case CPU_MODEL_NEHALEM:// Intel Core i7, Xeon W35xx, Xeon X55xx, Xeon E55xx LGA1366 (45nm)
792case CPU_MODEL_NEHALEM_EX:// Intel Xeon X75xx, Xeon X65xx, Xeon E75xx, Xeon E65x
793case CPU_MODEL_WESTMERE:// Intel Core i7, Xeon X56xx, Xeon E56xx, Xeon W36xx LGA1366 (32nm) 6 Core
794case CPU_MODEL_WESTMERE_EX:// Intel Xeon E7
795case CPU_MODEL_SANDYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (32nm)
796case CPU_MODEL_IVYBRIDGE:// Intel Core i3, i5, i7 LGA1155 (22nm)
797case CPU_MODEL_IVYBRIDGE_XEON:
798case CPU_MODEL_JAKETOWN:// Intel Core i7, Xeon E5 LGA2011 (32nm)
799case CPU_MODEL_HASWELL:
800case CPU_MODEL_HASWELL_MB:
801case CPU_MODEL_HASWELL_ULT:
802case CPU_MODEL_CRYSTALWELL:
803
804break;
805
806default:
807return;
808}
809}
810}
811
812p->header.type= kSMBTypeOemProcessorBusSpeed;
813p->header.length= sizeof(SMBOemProcessorBusSpeed);
814p->header.handle= handle++;
815
816setSMBValue(structPtr, numOfSetters -1, (returnType *)&(p->ProcessorBusSpeed));
817
818structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBOemProcessorBusSpeed) + 2);
819tableLength += sizeof(SMBOemProcessorBusSpeed) + 2;
820structureCount++;
821}
822
823//-------------------------------------------------------------------------------------------------------------------------
824// EndOfTable
825//-------------------------------------------------------------------------------------------------------------------------
826void addSMBEndOfTable(SMBStructPtrs *structPtr)
827{
828structPtr->new->type= kSMBTypeEndOfTable;
829structPtr->new->length= sizeof(SMBStructHeader);
830structPtr->new->handle= handle++;
831
832structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + sizeof(SMBStructHeader) + 2);
833tableLength += sizeof(SMBStructHeader) + 2;
834structureCount++;
835}
836
837void setSMBStruct(SMBStructPtrs *structPtr)
838{
839bool setterFound = false;
840
841uint8_t *ptr;
842SMBWord structSize;
843int i;
844
845/* http://forge.voodooprojects.org/p/chameleon/issues/361/ */
846bool forceFullMemInfo = false;
847
848if (structPtr->orig->type == kSMBTypeMemoryDevice)
849{
850getBoolForKey(kMemFullInfo, &forceFullMemInfo, &bootInfo->chameleonConfig);
851if (forceFullMemInfo)
852{
853structPtr->orig->length = 27;
854}
855}
856
857stringIndex = 1;
858stringsSize = 0;
859
860if (handle < structPtr->orig->handle)
861{
862handle = structPtr->orig->handle;
863}
864
865memcpy((void *)structPtr->new, structPtr->orig, structPtr->orig->length);
866
867for (i = 0; i < numOfSetters; i++)
868{
869if ((structPtr->orig->type == SMBSetters[i].type) && (SMBSetters[i].fieldOffset < structPtr->orig->length))
870{
871setterFound = true;
872setSMBValue(structPtr, i, (returnType *)((uint8_t *)structPtr->new + SMBSetters[i].fieldOffset));
873}
874}
875
876if (setterFound)
877{
878ptr = (uint8_t *)structPtr->new + structPtr->orig->length;
879for (; ((uint16_t *)ptr)[0] != 0; ptr++);
880
881if (((uint16_t *)ptr)[0] == 0)
882{
883ptr += 2;
884}
885structSize = ptr - (uint8_t *)structPtr->new;
886}
887else
888{
889ptr = (uint8_t *)structPtr->orig + structPtr->orig->length;
890for (; ((uint16_t *)ptr)[0] != 0; ptr++);
891
892if (((uint16_t *)ptr)[0] == 0)
893{
894ptr += 2;
895}
896
897structSize = ptr - (uint8_t *)structPtr->orig;
898memcpy((void *)structPtr->new, structPtr->orig, structSize);
899}
900
901structPtr->new = (SMBStructHeader *)((uint8_t *)structPtr->new + structSize);
902
903tableLength += structSize;
904
905if (structSize > maxStructSize)
906{
907maxStructSize = structSize;
908}
909
910structureCount++;
911}
912
913void setupNewSMBIOSTable(SMBEntryPoint *eps, SMBStructPtrs *structPtr)
914{
915uint8_t *ptr = (uint8_t *)eps->dmi.tableAddress;
916structPtr->orig = (SMBStructHeader *)ptr;
917
918for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structPtr->orig + sizeof(SMBStructHeader)));)
919{
920switch (structPtr->orig->type)
921{
922/* Skip all Apple Specific Structures */
923case kSMBTypeFirmwareVolume:
924case kSMBTypeMemorySPD:
925case kSMBTypeOemProcessorType:
926case kSMBTypeOemProcessorBusSpeed:
927/* And this one too, to be added at the end */
928case kSMBTypeEndOfTable:
929break;
930
931default:
932{
933/* Add */
934setSMBStruct(structPtr);
935break;
936}
937}
938
939ptr = (uint8_t *)((uint32_t)structPtr->orig + structPtr->orig->length);
940for (; ((uint16_t *)ptr)[0] != 0; ptr++);
941
942if (((uint16_t *)ptr)[0] == 0)
943{
944ptr += 2;
945}
946
947structPtr->orig = (SMBStructHeader *)ptr;
948}
949
950addSMBFirmwareVolume(structPtr);
951addSMBMemorySPD(structPtr);
952addSMBOemProcessorType(structPtr);
953addSMBOemProcessorBusSpeed(structPtr);
954
955addSMBEndOfTable(structPtr);
956}
957
958// Bungo: does fix system uuid in SMBIOS istead of in EFI only
959uint8_t *FixSystemUUID()
960{
961uint8_t *ptr = (uint8_t *)neweps->dmi.tableAddress;
962SMBStructHeader *structHeader = (SMBStructHeader *)ptr;
963int i, isZero, isOnes;
964uint8_t FixedUUID[UUID_LEN] = {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01};
965const char *sysId = getStringForKey(kSMBSystemInformationUUIDKey, SMBPlist);
966uint8_t *ret = (uint8_t *)getUUIDFromString(sysId);
967
968for (;(structHeader->type != kSMBTypeSystemInformation);) // find System Information Table (Type 1) in patched SMBIOS
969{
970ptr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
971for (; ((uint16_t *)ptr)[0] != 0; ptr++);
972
973if (((uint16_t *)ptr)[0] == 0)
974{
975ptr += 2;
976}
977
978structHeader = (SMBStructHeader *)ptr;
979}
980
981ptr = ((SMBSystemInformation *)structHeader)->uuid;
982
983if (!sysId || !ret) // no or bad custom UUID,...
984{
985sysId = 0;
986 ret = ((SMBSystemInformation *)structHeader)->uuid; // ...try bios dmi info UUID extraction
987}
988
989for (i=0, isZero=1, isOnes=1; i<UUID_LEN; i++) // check if empty or setable, means: no uuid present
990{
991if (ret[i] != 0x00)
992{
993isZero = 0;
994}
995
996if (ret[i] != 0xff)
997{
998isOnes = 0;
999}
1000}
1001
1002if (isZero || isOnes) // if empty or setable...
1003{
1004verbose("No UUID present in SMBIOS System Information Table\n");
1005ret = FixedUUID; // ...set a fixed value for system-id = 000102030405060708090A0B0C0D0E0F
1006}
1007
1008memcpy(ptr, ret, UUID_LEN); // fix uuid in the table
1009return ptr;
1010} // Bungo: end fix
1011
1012void setupSMBIOSTable(void)
1013{
1014SMBStructPtrs *structPtr;
1015uint8_t *buffer;
1016// bool setSMB = true; Bungo
1017
1018if (!origeps)
1019{
1020return;
1021}
1022
1023neweps = origeps;
1024
1025structPtr = (SMBStructPtrs *)malloc(sizeof(SMBStructPtrs));
1026if (!structPtr)
1027{
1028return;
1029}
1030
1031buffer = (uint8_t *)malloc(SMB_ALLOC_SIZE);
1032if (!buffer)
1033{
1034free(structPtr);
1035return;
1036}
1037
1038bzero(buffer, SMB_ALLOC_SIZE);
1039structPtr->new = (SMBStructHeader *)buffer;
1040
1041// getBoolForKey(kSMBIOSdefaults, &setSMB, &bootInfo->chameleonConfig); Bungo
1042getBoolForKey(kSMBIOSdefaults, &useSMBIOSdefaults, &bootInfo->chameleonConfig);
1043// if (setSMB)
1044 setDefaultSMBData();
1045// Bungo
1046
1047setupNewSMBIOSTable(origeps, structPtr);
1048
1049neweps = (SMBEntryPoint *)AllocateKernelMemory(sizeof(SMBEntryPoint));
1050if (!neweps)
1051{
1052free(buffer);
1053free(structPtr);
1054return;
1055}
1056bzero(neweps, sizeof(SMBEntryPoint));
1057
1058neweps->anchor[0]= '_';
1059neweps->anchor[1]= 'S';
1060neweps->anchor[2]= 'M';
1061neweps->anchor[3]= '_';
1062neweps->entryPointLength= sizeof(SMBEntryPoint);
1063neweps->majorVersion= 2;
1064neweps->minorVersion= 4;
1065neweps->maxStructureSize= maxStructSize;
1066neweps->entryPointRevision= 0;
1067
1068neweps->dmi.anchor[0]= '_';
1069neweps->dmi.anchor[1]= 'D';
1070neweps->dmi.anchor[2]= 'M';
1071neweps->dmi.anchor[3]= 'I';
1072neweps->dmi.anchor[4]= '_';
1073neweps->dmi.tableLength= tableLength;
1074neweps->dmi.tableAddress= AllocateKernelMemory(tableLength);
1075neweps->dmi.structureCount= structureCount;
1076neweps->dmi.bcdRevision= 0x24;
1077
1078if (!neweps->dmi.tableAddress)
1079{
1080free(buffer);
1081free(structPtr);
1082return;
1083}
1084
1085memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength);
1086
1087// Bungo
1088Platform.UUID = FixSystemUUID(); // Fix System UUID
1089
1090neweps->dmi.checksum= 0;
1091neweps->dmi.checksum= 0x100 - checksum8(&neweps->dmi, sizeof(DMIEntryPoint));
1092
1093neweps->checksum= 0;
1094neweps->checksum= 0x100 - checksum8(neweps, sizeof(SMBEntryPoint));
1095
1096free(buffer);
1097free(structPtr);
1098
1099decodeSMBIOSTable(neweps);
1100}
1101
1102void *getSmbios(int which)
1103{
1104switch (which)
1105{
1106case SMBIOS_ORIGINAL:
1107if (!origeps)
1108{
1109origeps = getAddressOfSmbiosTable();
1110}
1111return origeps;
1112case SMBIOS_PATCHED:
1113return neweps;
1114}
1115
1116return 0;
1117}
1118
1119/* Collect any information needed later */
1120void readSMBIOSInfo(SMBEntryPoint *eps)
1121{
1122uint8_t *structPtr = (uint8_t *)eps->dmi.tableAddress;
1123SMBStructHeader *structHeader = (SMBStructHeader *)structPtr;
1124
1125int dimmnbr = 0;
1126Platform.DMI.MaxMemorySlots= 0;// number of memory slots polulated by SMBIOS
1127Platform.DMI.CntMemorySlots= 0;// number of memory slots counted
1128Platform.DMI.MemoryModules= 0;
1129
1130for (;((eps->dmi.tableAddress + eps->dmi.tableLength) > ((uint32_t)(uint8_t *)structHeader + sizeof(SMBStructHeader)));)
1131{
1132switch (structHeader->type)
1133{
1134/* Bungo
1135case kSMBTypeSystemInformation:
1136Platform.UUID = ((SMBSystemInformation *)structHeader)->uuid;
1137break;
1138*/
1139
1140case kSMBTypePhysicalMemoryArray:
1141Platform.DMI.MaxMemorySlots += ((SMBPhysicalMemoryArray *)structHeader)->numMemoryDevices;
1142break;
1143
1144case kSMBTypeMemoryDevice:
1145Platform.DMI.CntMemorySlots++;
1146if (((SMBMemoryDevice *)structHeader)->memorySize != 0)
1147{
1148Platform.DMI.MemoryModules++;
1149}
1150if (((SMBMemoryDevice *)structHeader)->memorySpeed > 0)
1151{
1152Platform.RAM.DIMM[dimmnbr].Frequency = ((SMBMemoryDevice *)structHeader)->memorySpeed;
1153}
1154dimmnbr++;
1155break;
1156default:
1157break;
1158}
1159
1160structPtr = (uint8_t *)((uint32_t)structHeader + structHeader->length);
1161for (; ((uint16_t *)structPtr)[0] != 0; structPtr++);
1162
1163if (((uint16_t *)structPtr)[0] == 0)
1164{
1165structPtr += 2;
1166}
1167
1168structHeader = (SMBStructHeader *)structPtr;
1169}
1170}
1171

Archive Download this file

Revision: 2285