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 | ␊ |
13 | #include "smbios.h"␊ |
14 | #include <stdlib.h>␊ |
15 | #include <string.h>␊ |
16 | ␊ |
17 | #if 0␊ |
18 | typedef unsigned char bool;␊ |
19 | #define false 0␊ |
20 | #define true 1␊ |
21 | #endif␊ |
22 | ␊ |
23 | #ifndef DEBUG_SMBIOS␊ |
24 | #define DEBUG_SMBIOS 0␊ |
25 | #endif␊ |
26 | ␊ |
27 | #if DEBUG_SMBIOS␊ |
28 | #define DBG(x...)␉printf(x)␊ |
29 | #else␊ |
30 | #define DBG(x...)␉msglog(x)␊ |
31 | #endif␊ |
32 | ␊ |
33 | #define SMBPlist␉␉␉&bootInfo->smbiosConfig␊ |
34 | /* ASSUMPTION: 16KB should be enough for the whole thing */␊ |
35 | #define SMB_ALLOC_SIZE␉16384␊ |
36 | ␊ |
37 | ␊ |
38 | //-------------------------------------------------------------------------------------------------------------------------␊ |
39 | // SMBIOS Plist Keys␊ |
40 | //-------------------------------------------------------------------------------------------------------------------------␊ |
41 | /* BIOS Information */␊ |
42 | #define kSMBBIOSInformationVendorKey␉␉␉␉"SMbiosvendor"␊ |
43 | #define kSMBBIOSInformationVersionKey␉␉␉␉"SMbiosversion"␊ |
44 | #define kSMBBIOSInformationReleaseDateKey␉␉␉"SMbiosdate"␊ |
45 | ␊ |
46 | /* System Information */␊ |
47 | #define kSMBSystemInformationManufacturerKey␉␉"SMmanufacturer"␊ |
48 | #define kSMBSystemInformationProductNameKey␉␉␉"SMproductname"␊ |
49 | #define kSMBSystemInformationVersionKey␉␉␉␉"SMsystemversion"␊ |
50 | #define kSMBSystemInformationSerialNumberKey␉␉"SMserial"␊ |
51 | #define kSMBSystemInformationFamilyKey␉␉␉␉"SMfamily"␊ |
52 | ␊ |
53 | /* Base Board */␊ |
54 | #define kSMBBaseBoardManufacturerKey␉␉␉␉"SMboardmanufacturer"␊ |
55 | #define kSMBBaseBoardProductKey␉␉␉␉␉␉"SMboardproduct"␊ |
56 | ␊ |
57 | /* Processor Information */␊ |
58 | #define kSMBProcessorInformationExternalClockKey␉"SMexternalclock"␊ |
59 | #define kSMBProcessorInformationMaximumClockKey␉␉"SMmaximalclock"␊ |
60 | ␊ |
61 | /* Memory Device */␊ |
62 | #define kSMBMemoryDeviceDeviceLocatorKey␉␉␉"SMmemdevloc"␊ |
63 | #define kSMBMemoryDeviceBankLocatorKey␉␉␉␉"SMmembankloc"␊ |
64 | #define kSMBMemoryDeviceMemoryTypeKey␉␉␉␉"SMmemtype"␊ |
65 | #define kSMBMemoryDeviceMemorySpeedKey␉␉␉␉"SMmemspeed"␊ |
66 | #define kSMBMemoryDeviceManufacturerKey␉␉␉␉"SMmemmanufacturer"␊ |
67 | #define kSMBMemoryDeviceSerialNumberKey␉␉␉␉"SMmemserial"␊ |
68 | #define kSMBMemoryDevicePartNumberKey␉␉␉␉"SMmempart"␊ |
69 | ␊ |
70 | /* Apple Specific */␊ |
71 | #define kSMBOemProcessorTypeKey␉␉␉␉␉␉"SMcputype"␊ |
72 | #define kSMBOemProcessorBusSpeedKey␉␉␉␉␉"SMbusspeed"␊ |
73 | ␊ |
74 | //-------------------------------------------------------------------------------------------------------------------------␊ |
75 | // Default SMBIOS Data␊ |
76 | //-------------------------------------------------------------------------------------------------------------------------␊ |
77 | /* Rewrite: use a struct */␊ |
78 | ␊ |
79 | #define kDefaultVendorManufacturer␉␉␉␉␉"Apple Inc."␊ |
80 | #define kDefaultBIOSReleaseDate␉␉␉␉␉␉"11/06/2009"␊ |
81 | #define kDefaultSerialNumber␉␉␉␉␉␉"SOMESRLNMBR"␊ |
82 | #define kDefaultBoardProduct␉␉␉␉␉␉"Mac-F4208DC8"␊ |
83 | #define kDefaultSystemVersion␉␉␉␉␉␉"1.0"␊ |
84 | ␊ |
85 | // defaults for a Mac mini ␊ |
86 | #define kDefaultMacminiFamily␉␉␉␉␉␉"Macmini"␊ |
87 | #define kDefaultMacmini␉␉␉␉␉␉␉␉"Macmini1,1"␊ |
88 | #define kDefaultMacminiBIOSVersion␉␉␉␉␉" MM21.88Z.009A.B00.0903051113"␊ |
89 | ␊ |
90 | // defaults for a MacBook␊ |
91 | #define kDefaultMacBookFamily␉␉␉␉␉␉"MacBook"␊ |
92 | #define kDefaultMacBook␉␉␉␉␉␉␉␉"MacBook4,1"␊ |
93 | #define kDefaultMacBookBIOSVersion␉␉␉␉␉" MB41.88Z.0073.B00.0903051113"␊ |
94 | ␊ |
95 | // defaults for a MacBook Pro␊ |
96 | #define kDefaultMacBookProFamily␉␉␉␉␉"MacBookPro"␊ |
97 | #define kDefaultMacBookPro␉␉␉␉␉␉␉"MacBookPro4,1"␊ |
98 | #define kDefaultMacBookProBIOSVersion␉␉␉␉" MBP41.88Z.0073.B00.0903051113"␊ |
99 | ␊ |
100 | // defaults for an iMac␊ |
101 | #define kDefaultiMacFamily␉␉␉␉␉␉␉"iMac"␊ |
102 | #define kDefaultiMac␉␉␉␉␉␉␉␉"iMac8,1"␊ |
103 | #define kDefaultiMacBIOSVersion␉␉␉␉␉␉" IM81.88Z.00C1.B00.0903051113"␊ |
104 | // defaults for an iMac11,1 core i3/i5/i7␊ |
105 | #define kDefaultiMacNehalem␉␉␉␉␉␉␉"iMac11,1"␊ |
106 | #define kDefaultiMacNehalemBIOSVersion␉␉␉␉" IM111.88Z.0034.B00.0903051113"␊ |
107 | // defaults for an iMac12,1␊ |
108 | #define kDefaultiMacSandy␉␉␉␉␉␉␉"iMac12,1"␊ |
109 | #define kDefaultiMacSandyBIOSVersion␉␉␉␉" IM121.88Z.0047.B00.1102091756"␊ |
110 | ␊ |
111 | // defaults for a Mac Pro␊ |
112 | #define kDefaultMacProFamily␉␉␉␉␉␉"MacPro"␊ |
113 | #define kDefaultMacPro␉␉␉␉␉␉␉␉"MacPro3,1"␊ |
114 | #define kDefaultMacProBIOSVersion␉␉␉␉␉" MP31.88Z.006C.B05.0903051113"␊ |
115 | // defaults for a Mac Pro 4,1 core i7/Xeon␊ |
116 | #define kDefaultMacProNehalem␉␉␉␉␉␉"MacPro4,1"␊ |
117 | #define kDefaultMacProNehalemBIOSVersion␉␉␉" MP41.88Z.0081.B04.0903051113"␊ |
118 | // defaults for a Mac Pro 5,1 core i7/Xeon␊ |
119 | #define kDefaultMacProWestmere␉␉␉␉␉␉"MacPro5,1"␊ |
120 | #define kDefaultMacProWestmereBIOSVersion␉␉␉" MP51.88Z.007F.B00.1008031144"␊ |
121 | #define kDefaulMacProWestmereBIOSReleaseDate␉␉"08/03/10"␊ |
122 | //-------------------------------------------------------------------------------------------------------------------------␊ |
123 | ␊ |
124 | ␊ |
125 | #define getFieldOffset(struct, field)␉((uint8_t)(unsigned long)&(((struct *)0)->field))␊ |
126 | ␊ |
127 | typedef struct {␊ |
128 | ␉SMBStructHeader *orig;␊ |
129 | ␉SMBStructHeader *new_header;␊ |
130 | } SMBStructPtrs ;␊ |
131 | ␊ |
132 | static struct {␊ |
133 | ␉char *vendor;␊ |
134 | ␉char *version;␊ |
135 | ␉char *releaseDate;␊ |
136 | } defaultBIOSInfo;␊ |
137 | ␊ |
138 | static struct {␊ |
139 | ␉char *manufacturer;␊ |
140 | ␉char *productName;␊ |
141 | ␉char *version;␊ |
142 | ␉char *serialNumber;␊ |
143 | ␉char *family;␊ |
144 | } defaultSystemInfo;␊ |
145 | ␊ |
146 | static struct {␊ |
147 | ␉char *manufacturer;␊ |
148 | ␉char *product;␊ |
149 | } defaultBaseBoard;␊ |
150 | ␊ |
151 | ␊ |
152 | typedef struct {␊ |
153 | ␉uint8_t␉␉␉type;␊ |
154 | ␉SMBValueType␉valueType;␊ |
155 | ␉uint8_t␉␉␉fieldOffset;␊ |
156 | ␉char␉␉␉*keyString;␊ |
157 | ␉bool␉␉␉(*getSMBValue)(returnType *);␊ |
158 | ␉char␉␉␉**defaultValue;␊ |
159 | } SMBValueSetter;␊ |
160 | ␊ |
161 | SMBValueSetter SMBSetters[] = ␊ |
162 | {␊ |
163 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
164 | ␉// BIOSInformation␊ |
165 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
166 | ␉{kSMBTypeBIOSInformation,␉kSMBString,␉getFieldOffset(SMBBIOSInformation, vendor),␉␉␉kSMBBIOSInformationVendorKey,␉␉␊ |
167 | ␉␉NULL,␉&defaultBIOSInfo.vendor␉␉␉},␊ |
168 | ␊ |
169 | ␉{kSMBTypeBIOSInformation,␉kSMBString,␉getFieldOffset(SMBBIOSInformation, version),␉␉kSMBBIOSInformationVersionKey,␉␉␊ |
170 | ␉␉NULL,␉&defaultBIOSInfo.version␉␉},␊ |
171 | ␊ |
172 | ␉{kSMBTypeBIOSInformation,␉kSMBString,␉getFieldOffset(SMBBIOSInformation, releaseDate),␉kSMBBIOSInformationReleaseDateKey,␉␊ |
173 | ␉␉NULL,␉&defaultBIOSInfo.releaseDate␉},␊ |
174 | ␊ |
175 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
176 | ␉// SystemInformation␊ |
177 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
178 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, manufacturer),␉kSMBSystemInformationManufacturerKey,␉␊ |
179 | ␉␉NULL,␉&defaultSystemInfo.manufacturer␉},␊ |
180 | ␊ |
181 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, productName),␉kSMBSystemInformationProductNameKey,␉␊ |
182 | ␉␉NULL,␉&defaultSystemInfo.productName␉},␊ |
183 | ␊ |
184 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, version),␉␉kSMBSystemInformationVersionKey,␉␉␊ |
185 | ␉␉NULL,␉&defaultSystemInfo.version␉␉},␊ |
186 | ␊ |
187 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, serialNumber),␉kSMBSystemInformationSerialNumberKey,␉␊ |
188 | ␉␉NULL,␉&defaultSystemInfo.serialNumber␉},␊ |
189 | ␊ |
190 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, skuNumber),␉NULL,␉␉␉␉␉␉␉␉␉␊ |
191 | ␉␉NULL,␉NULL␉␉␉␉␉␉␉},␊ |
192 | ␊ |
193 | ␉{kSMBTypeSystemInformation,␉kSMBString,␉getFieldOffset(SMBSystemInformation, family),␉␉kSMBSystemInformationFamilyKey,␉␉␉␊ |
194 | ␉␉NULL,␉&defaultSystemInfo.family␉␉},␊ |
195 | ␊ |
196 | ␊ |
197 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
198 | ␉// BaseBoard␊ |
199 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
200 | ␉{kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, manufacturer),␉␉␉kSMBBaseBoardManufacturerKey,␉␊ |
201 | ␉␉NULL,␉&defaultBaseBoard.manufacturer␉},␊ |
202 | ␊ |
203 | ␉{kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, product),␉␉␉␉kSMBBaseBoardProductKey,␉␉␊ |
204 | ␉␉NULL,␉&defaultBaseBoard.product␉␉},␊ |
205 | ␊ |
206 | ␉{kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, version),␉␉␉␉NULL,␉NULL,␉NULL},␊ |
207 | ␊ |
208 | ␉{kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, serialNumber),␉␉␉NULL,␉NULL,␉NULL},␊ |
209 | ␊ |
210 | ␉{kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, assetTagNumber),␉␉NULL,␉NULL,␉NULL},␊ |
211 | ␊ |
212 | ␉{kSMBTypeBaseBoard,␉kSMBString,␉getFieldOffset(SMBBaseBoard, locationInChassis),␉NULL,␉NULL,␉NULL},␊ |
213 | ␊ |
214 | ␊ |
215 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
216 | ␉// ProcessorInformation␊ |
217 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
218 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, socketDesignation),␉NULL,␉NULL,␉NULL},␊ |
219 | ␊ |
220 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, manufacturer),␉␉NULL,␉NULL,␉NULL},␊ |
221 | ␊ |
222 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, processorVersion),␉NULL,␉NULL,␉NULL},␊ |
223 | ␊ |
224 | ␉{kSMBTypeProcessorInformation,␉kSMBWord,␉getFieldOffset(SMBProcessorInformation, externalClock),␉␉kSMBProcessorInformationExternalClockKey,␉␊ |
225 | ␉␉NULL,␉NULL},␊ |
226 | ␊ |
227 | ␉{kSMBTypeProcessorInformation,␉kSMBWord,␉getFieldOffset(SMBProcessorInformation, maximumClock),␉␉kSMBProcessorInformationMaximumClockKey,␉␊ |
228 | ␉␉NULL,␉NULL},␊ |
229 | ␊ |
230 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, serialNumber),␉␉NULL,␉NULL,␉NULL},␊ |
231 | ␊ |
232 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, assetTag),␉␉␉NULL,␉NULL,␉NULL},␊ |
233 | ␊ |
234 | ␉{kSMBTypeProcessorInformation,␉kSMBString,␉getFieldOffset(SMBProcessorInformation, partNumber),␉␉NULL,␉NULL,␉NULL},␊ |
235 | ␊ |
236 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
237 | ␉// Memory Device␊ |
238 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
239 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, deviceLocator),␉kSMBMemoryDeviceDeviceLocatorKey,␉␊ |
240 | ␉␉NULL,␉␉␉␉␉␉␉NULL},␊ |
241 | ␊ |
242 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, bankLocator),␉kSMBMemoryDeviceBankLocatorKey,␉␉␊ |
243 | ␉␉NULL,␉␉␉␉␉␉␉NULL},␊ |
244 | ␊ |
245 | ␉{kSMBTypeMemoryDevice,␉kSMBByte,␉getFieldOffset(SMBMemoryDevice, memoryType),␉kSMBMemoryDeviceMemoryTypeKey,␉␉␊ |
246 | ␉␉NULL,␉NULL},␊ |
247 | ␊ |
248 | ␉{kSMBTypeMemoryDevice,␉kSMBWord,␉getFieldOffset(SMBMemoryDevice, memorySpeed),␉kSMBMemoryDeviceMemorySpeedKey,␉␉␊ |
249 | ␉␉NULL,␉NULL},␊ |
250 | ␊ |
251 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, manufacturer),␉kSMBMemoryDeviceManufacturerKey,␉␊ |
252 | ␉␉NULL,␉NULL},␊ |
253 | ␊ |
254 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, serialNumber),␉kSMBMemoryDeviceSerialNumberKey,␉␊ |
255 | ␉␉NULL,␉NULL},␊ |
256 | ␊ |
257 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, assetTag),␉␉NULL,␉NULL,␉NULL},␊ |
258 | ␊ |
259 | ␉{kSMBTypeMemoryDevice,␉kSMBString,␉getFieldOffset(SMBMemoryDevice, partNumber),␉kSMBMemoryDevicePartNumberKey,␉␉␊ |
260 | ␉␉NULL,␉NULL},␊ |
261 | ␊ |
262 | ␊ |
263 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
264 | ␉// Apple Specific␊ |
265 | ␉//-------------------------------------------------------------------------------------------------------------------------␊ |
266 | ␉{kSMBTypeOemProcessorType,␉␉kSMBWord,␉getFieldOffset(SMBOemProcessorType, ProcessorType),␉␉␉kSMBOemProcessorTypeKey,␉␉␊ |
267 | ␉␉NULL,␉␉␉NULL},␊ |
268 | ␊ |
269 | ␉{kSMBTypeOemProcessorBusSpeed,␉kSMBWord,␉getFieldOffset(SMBOemProcessorBusSpeed, ProcessorBusSpeed),␉kSMBOemProcessorBusSpeedKey,␉␊ |
270 | ␉␉NULL,␉␉NULL}␊ |
271 | };␊ |
272 | ␊ |
273 | int numOfSetters = sizeof(SMBSetters) / sizeof(SMBValueSetter);␊ |
274 | ␊ |
275 | ␊ |
276 | SMBEntryPoint *origeps␉= 0;␊ |
277 | SMBEntryPoint *neweps␉= 0;␊ |
278 | ␊ |
279 | static uint8_t stringIndex;␉// increament when a string is added and set the field value accordingly␊ |
280 | static uint8_t stringsSize;␉// add string size␊ |
281 | ␊ |
282 | /*␊ |
283 | static SMBWord tableLength␉␉= 0;␊ |
284 | static SMBWord handle␉␉␉= 0;␊ |
285 | static SMBWord maxStructSize␉= 0;␊ |
286 | static SMBWord structureCount␉= 0;␊ |
287 | */␊ |
288 | ␊ |
289 | /* Rewrite this function */␊ |
290 | void setDefaultSMBData(void)␊ |
291 | {␊ |
292 | ␉defaultBIOSInfo.vendor␉␉␉= kDefaultVendorManufacturer;␊ |
293 | ␉defaultBIOSInfo.releaseDate␉␉= kDefaultBIOSReleaseDate;␊ |
294 | ␊ |
295 | ␉defaultSystemInfo.manufacturer␉= kDefaultVendorManufacturer;␊ |
296 | ␉defaultSystemInfo.version␉␉= kDefaultSystemVersion;␊ |
297 | ␉defaultSystemInfo.serialNumber␉= kDefaultSerialNumber;␊ |
298 | ␊ |
299 | ␉defaultBaseBoard.manufacturer␉= kDefaultVendorManufacturer;␊ |
300 | ␉defaultBaseBoard.product␉␉= kDefaultBoardProduct;␊ |
301 | ␉defaultBIOSInfo.version␉␉␉= kDefaultMacProNehalemBIOSVersion;␊ |
302 | ␉defaultSystemInfo.productName␉= kDefaultMacProNehalem;␊ |
303 | ␉defaultSystemInfo.family␉␉= kDefaultMacProFamily;␊ |
304 | ␊ |
305 | }␊ |
306 | ␊ |
307 | char *getSMBStringForField(SMBStructHeader *structHeader, uint8_t field)␊ |
308 | {␊ |
309 | ␉uint8_t *stringPtr = ((uint8_t *)structHeader) + structHeader->length;␊ |
310 | ␊ |
311 | ␉if (!field)␊ |
312 | ␉␉return NULL;␊ |
313 | ␊ |
314 | for (field--; field != 0 && strlen((char *)stringPtr) > 0; ␊ |
315 | ␉␉field--, stringPtr = (uint8_t *)((unsigned long )stringPtr + strlen((char *)stringPtr) + 1));␊ |
316 | ␊ |
317 | ␉return (char *)stringPtr;␊ |
318 | }␊ |
319 | ␊ |
320 | void setSMBStringForField(SMBStructHeader *structHeader, const char *string, uint8_t *field)␊ |
321 | {␊ |
322 | ␉int strSize;␊ |
323 | ␊ |
324 | ␉if (!field)␊ |
325 | ␉␉return;␊ |
326 | ␉if (!string)␊ |
327 | ␉{␊ |
328 | ␉␉*field = 0;␊ |
329 | ␉␉return;␊ |
330 | ␉}␊ |
331 | ␊ |
332 | ␉strSize = strlen(string);␊ |
333 | ␊ |
334 | ␉// remove any spaces found at the end␊ |
335 | ␉while ((strSize != 0) && (string[strSize - 1] == ' '))␊ |
336 | ␉␉strSize--;␊ |
337 | ␊ |
338 | ␉if (strSize == 0)␊ |
339 | ␉{␊ |
340 | ␉␉*field = 0;␊ |
341 | ␉␉return;␊ |
342 | ␉}␊ |
343 | ␊ |
344 | ␉memcpy((uint8_t *)structHeader + structHeader->length + stringsSize, string, strSize);␊ |
345 | ␉*field = stringIndex;␊ |
346 | ␊ |
347 | ␉stringIndex++;␊ |
348 | ␉stringsSize += strSize + 1;␊ |
349 | }␊ |
350 | ␊ |
351 | |