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

Archive Download this file

Revision: 2284