1 | ␊ |
2 | /*␊ |
3 | * Copyright 2007 David F. Elliott.␉ All rights reserved.␊ |
4 | */␊ |
5 | ␊ |
6 | /*␊ |
7 | * Copyright 2010,2011,2012 Cadet-petit Armel <armelcadetpetit@gmail.com>. All rights reserved.␊ |
8 | */␊ |
9 | ␊ |
10 | #include "libsaio.h"␊ |
11 | #include "bootstruct.h"␊ |
12 | #include "efi.h"␊ |
13 | #include "acpi.h"␊ |
14 | #include "fake_efi.h"␊ |
15 | #include "efi_tables.h"␊ |
16 | #include "platform.h"␊ |
17 | #include "convert.h"␊ |
18 | #include "pci.h"␊ |
19 | #include "sl.h"␊ |
20 | #include "modules.h"␊ |
21 | #include "vers.h"␊ |
22 | ␊ |
23 | #ifndef NO_SMP_SUPPORT␊ |
24 | #include "smp-imps.h"␊ |
25 | #endif␊ |
26 | ␊ |
27 | #ifndef DEBUG_EFI␊ |
28 | #define DEBUG_EFI 0␊ |
29 | #endif␊ |
30 | ␊ |
31 | #if DEBUG_EFI␊ |
32 | #define DBG(x...)␉printf(x)␊ |
33 | #else␊ |
34 | #define DBG(x...)␊ |
35 | #endif␊ |
36 | /*␊ |
37 | * Modern Darwin kernels require some amount of EFI because Apple machines all␊ |
38 | * have EFI. Modifying the kernel source to not require EFI is of course␊ |
39 | * possible but would have to be maintained as a separate patch because it is␊ |
40 | * unlikely that Apple wishes to add legacy support to their kernel.␊ |
41 | *␊ |
42 | * As you can see from the Apple-supplied code in bootstruct.c, it seems that␊ |
43 | * the intention was clearly to modify this booter to provide EFI-like structures␊ |
44 | * to the kernel rather than modifying the kernel to handle non-EFI stuff.␉ This␊ |
45 | * makes a lot of sense from an engineering point of view as it means the kernel␊ |
46 | * for the as yet unreleased EFI-only Macs could still be booted by the non-EFI␊ |
47 | * DTK systems so long as the kernel checked to ensure the boot tables were␊ |
48 | * filled in appropriately.␉ Modern xnu requires a system table and a runtime␊ |
49 | * services table and performs no checks whatsoever to ensure the pointers to␊ |
50 | * these tables are non-NULL.␉Therefore, any modern xnu kernel will page fault␊ |
51 | * early on in the boot process if the system table pointer is zero.␊ |
52 | *␊ |
53 | * Even before that happens, the tsc_init function in modern xnu requires the FSB␊ |
54 | * Frequency to be a property in the /efi/platform node of the device tree or else␊ |
55 | * it panics the bootstrap process very early on.␊ |
56 | *␊ |
57 | * As of this writing, the current implementation found here is good enough␊ |
58 | * to make the currently available xnu kernel boot without modification on a␊ |
59 | * system with an appropriate processor. With a minor source modification to␊ |
60 | * the tsc_init function to remove the explicit check for Core or Core 2␊ |
61 | * processors the kernel can be made to boot on other processors so long as␊ |
62 | * the code can be executed by the processor and the machine contains the␊ |
63 | * necessary hardware.␊ |
64 | */␊ |
65 | static inline char * mallocStringForGuid(EFI_GUID const *pGuid);␊ |
66 | static VOID EFI_ST_FIX_CRC32(VOID);␊ |
67 | static EFI_STATUS setupAcpiNoMod(VOID);␊ |
68 | static EFI_CHAR16* getSmbiosChar16(const char * key, size_t* len);␊ |
69 | static EFI_CHAR8* getSmbiosUUID(VOID);␊ |
70 | static int8_t *getSystemID(VOID);␊ |
71 | static VOID setupSystemType(VOID);␊ |
72 | static VOID setupEfiDeviceTree(VOID);␊ |
73 | static VOID setup_Smbios(VOID);␊ |
74 | static VOID setup_machine_signature(VOID);␊ |
75 | static VOID setupEfiConfigurationTable(VOID);␊ |
76 | static EFI_STATUS EFI_FindAcpiTables(VOID);␊ |
77 | static VOID efi_setupDeviceProperties(Node *node);␊ |
78 | ␊ |
79 | /*==========================================================================␊ |
80 | * Utility function to make a device tree string from an EFI_GUID␊ |
81 | */␊ |
82 | ␊ |
83 | static inline char * mallocStringForGuid(EFI_GUID const *pGuid)␊ |
84 | {␊ |
85 | ␉char *string = malloc(37);␊ |
86 | if (!string) {␊ |
87 | #if DEBUG_EFI␊ |
88 | char string_d[37];␊ |
89 | efi_guid_unparse_upper(pGuid, string_d, sizeof(string_d));␊ |
90 | printf("Couldn't allocate Guid String for %s\n", string_d); ␊ |
91 | #endif␊ |
92 | return NULL;␊ |
93 | }␊ |
94 | ␊ |
95 | ␉efi_guid_unparse_upper(pGuid, string, 37);␊ |
96 | ␉return string;␊ |
97 | }␊ |
98 | ␊ |
99 | /*==========================================================================␊ |
100 | * Function to map 32 bit physical address to 64 bit virtual address␊ |
101 | */␊ |
102 | ␊ |
103 | #define ptov64(addr) (uint64_t)((uint64_t)addr | 0xFFFFFF8000000000ULL)␊ |
104 | ␊ |
105 | /*==========================================================================␊ |
106 | * Fake EFI implementation␊ |
107 | */␊ |
108 | ␊ |
109 | static EFI_CHAR16 const FIRMWARE_VENDOR[] = {'A','p','p','l','e', 0}; ␊ |
110 | ␊ |
111 | /* Info About the current Firmware */␊ |
112 | #define FIRMWARE_MAINTENER "cparm, armelcadetpetit@gmail.com" ␊ |
113 | static EFI_CHAR16 const FIRMWARE_NAME[] = {'M','a','s','h','e','r','b','r','u','m','-','2','.','1', 0}; ␊ |
114 | static EFI_UINT32 const FIRMWARE_REVISION = 0x00020100; //2.1␊ |
115 | static EFI_UINT32 const DEVICE_SUPPORTED = 0x00000001;␊ |
116 | ␊ |
117 | /* Just a ret instruction */␊ |
118 | static uint8_t const VOIDRET_INSTRUCTIONS[] = {0xc3};␊ |
119 | ␊ |
120 | /* movl $0x80000003,%eax; ret */␊ |
121 | static uint8_t const UNSUPPORTEDRET_INSTRUCTIONS[] = {0xb8, 0x03, 0x00, 0x00, 0x80, 0xc3};␊ |
122 | ␊ |
123 | EFI_SYSTEM_TABLE_32 *gST32 = NULL;␊ |
124 | EFI_SYSTEM_TABLE_64 *gST64 = NULL;␊ |
125 | Node *gEfiConfigurationTableNode = NULL;␊ |
126 | ␊ |
127 | /* From Foundation/Efi/Guid/Smbios/SmBios.h */␊ |
128 | /* Modified to wrap Data4 array init with {} */␊ |
129 | #define EFI_SMBIOS_TABLE_GUID {0xeb9d2d31, 0x2d88, 0x11d3, {0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d}}␊ |
130 | ␊ |
131 | #define EFI_ACPI_TABLE_GUID \␊ |
132 | { \␊ |
133 | 0xeb9d2d30, 0x2d88, 0x11d3, { 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \␊ |
134 | }␊ |
135 | ␊ |
136 | #define EFI_ACPI_20_TABLE_GUID \␊ |
137 | { \␊ |
138 | 0x8868e871, 0xe4f1, 0x11d3, { 0xbc, 0x22, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 } \␊ |
139 | }␊ |
140 | ␊ |
141 | #ifndef NO_SMP_SUPPORT␊ |
142 | #define EFI_MPS_TABLE_GUID \␊ |
143 | { \␊ |
144 | 0xeb9d2d2f,0x2d88,0x11d3,{0x9a,0x16,0x0,0x90,0x27,0x3f,0xc1,0x4d} \␊ |
145 | }␊ |
146 | #endif␊ |
147 | ␊ |
148 | /* From Foundation/Efi/Guid/Smbios/SmBios.c */␊ |
149 | EFI_GUID const␉gEfiSmbiosTableGuid = EFI_SMBIOS_TABLE_GUID;␊ |
150 | ␊ |
151 | EFI_GUID gEfiAcpiTableGuid = EFI_ACPI_TABLE_GUID;␊ |
152 | EFI_GUID gEfiAcpi20TableGuid = EFI_ACPI_20_TABLE_GUID;␊ |
153 | ␊ |
154 | #ifndef NO_SMP_SUPPORT␊ |
155 | EFI_GUID gEfiMpsTableGuid = EFI_MPS_TABLE_GUID;␊ |
156 | #endif␊ |
157 | ␊ |
158 | EFI_UINT32 gNumTables32 = 0;␊ |
159 | EFI_UINT64 gNumTables64 = 0;␊ |
160 | EFI_CONFIGURATION_TABLE_32 gEfiConfigurationTable32[MAX_CONFIGURATION_TABLE_ENTRIES];␊ |
161 | EFI_CONFIGURATION_TABLE_64 gEfiConfigurationTable64[MAX_CONFIGURATION_TABLE_ENTRIES];␊ |
162 | EFI_STATUS addConfigurationTable(EFI_GUID const *pGuid, void *table, char const *alias)␊ |
163 | {␊ |
164 | ␉EFI_UINTN i = 0;␊ |
165 | ␉␊ |
166 | if (pGuid == NULL || table == NULL)␊ |
167 | ␉␉return EFI_INVALID_PARAMETER;␊ |
168 | ␊ |
169 | char * GuidStr = mallocStringForGuid(pGuid);␊ |
170 | if (!GuidStr) {␊ |
171 | return EFI_OUT_OF_RESOURCES;␊ |
172 | }␊ |
173 | ␊ |
174 | ␉//Azi: as is, cpu's with em64t will use EFI64 on pre 10.6 systems,␊ |
175 | ␉// wich seems to cause no problem. In case it does, force i386 arch.␊ |
176 | ␉if (get_env(envarchCpuType) == CPU_TYPE_I386)␊ |
177 | ␉{␊ |
178 | ␉␉i = gNumTables32;␊ |
179 | ␉}␊ |
180 | ␉else␊ |
181 | ␉{␊ |
182 | ␉␉i = (EFI_UINTN)gNumTables64;␊ |
183 | ␉}␊ |
184 | ␉␊ |
185 | ␉// We only do adds, not modifications and deletes like InstallConfigurationTable␊ |
186 | ␉if (i >= MAX_CONFIGURATION_TABLE_ENTRIES)␊ |
187 | ␉{␊ |
188 | ␊ |
189 | ␉␉␊ |
190 | printf("Ran out of space for configuration tables (max = %d). Please, increase the reserved size in the code.\n", (int)MAX_CONFIGURATION_TABLE_ENTRIES);␊ |
191 | return EFI_ABORTED;␊ |
192 | } ␊ |
193 | ␊ |
194 | if (get_env(envarchCpuType) == CPU_TYPE_I386)␊ |
195 | ␉{ ␊ |
196 | ␊ |
197 | gEfiConfigurationTable32[i].VendorGuid = *pGuid;␊ |
198 | gEfiConfigurationTable32[i].VendorTable = (EFI_PTR32)table;␊ |
199 | ␊ |
200 | ␉␉gNumTables32++;␊ |
201 | ␉}␊ |
202 | ␉else␊ |
203 | ␉{ ␊ |
204 | gEfiConfigurationTable64[i].VendorGuid = *pGuid;␊ |
205 | gEfiConfigurationTable64[i].VendorTable = (EFI_PTR32)table;␊ |
206 | ␉␉gNumTables64++ ;␊ |
207 | ␉} ␊ |
208 | ␉␊ |
209 | ␊ |
210 | Node *tableNode = DT__AddChild(gEfiConfigurationTableNode, GuidStr);␊ |
211 | ␊ |
212 | // Use the pointer to the GUID we just stuffed into the system table␊ |
213 | DT__AddProperty(tableNode, "guid", sizeof(EFI_GUID), (void*)pGuid);␊ |
214 | ␊ |
215 | // The "table" property is the 32-bit (in our implementation) physical address of the table␊ |
216 | DT__AddProperty(tableNode, "table", sizeof(void*) * 2, table);␊ |
217 | ␊ |
218 | // Assume the alias pointer is a global or static piece of data␊ |
219 | if (alias != NULL)␊ |
220 | DT__AddProperty(tableNode, "alias", strlen(alias)+1, (char*)alias);␊ |
221 | ␊ |
222 | return EFI_SUCCESS;␊ |
223 | ␉␊ |
224 | }␊ |
225 | ␊ |
226 | static VOID EFI_ST_FIX_CRC32(void)␊ |
227 | {␊ |
228 | ␉if (get_env(envarchCpuType) == CPU_TYPE_I386)␊ |
229 | ␉{␊ |
230 | ␉␉gST32->Hdr.CRC32 = 0;␊ |
231 | ␉␉gST32->Hdr.CRC32 = crc32(0L, gST32, gST32->Hdr.HeaderSize);␊ |
232 | ␉}␊ |
233 | ␉else␊ |
234 | ␉{␊ |
235 | ␉␉gST64->Hdr.CRC32 = 0;␊ |
236 | ␉␉gST64->Hdr.CRC32 = crc32(0L, gST64, gST64->Hdr.HeaderSize);␊ |
237 | ␉}␊ |
238 | }␊ |
239 | ␊ |
240 | static VOID efi_setupDeviceProperties(Node *node)␊ |
241 | {␊ |
242 | ␉const char *val;␊ |
243 | ␉uint8_t *binStr;␊ |
244 | uint8_t *kbinStr;␊ |
245 | ␊ |
246 | ␉int cnt = 0, cnt2 = 0;␊ |
247 | ␉␊ |
248 | ␉static char DEVICE_PROPERTIES_PROP[] = "device-properties";␊ |
249 | ␉␊ |
250 | ␉EFI_STATUS ret = EFI_NO_MEDIA;␊ |
251 | ␉␊ |
252 | ␉execute_hook("setupDeviceProperties", node, &ret, NULL, NULL, NULL, NULL);␊ |
253 | ␉␊ |
254 | ␉if (ret != EFI_SUCCESS)␊ |
255 | ␉{␊ |
256 | ␉␉/* ␊ |
257 | ␉␉ * Use the static "device-properties" boot config key contents if available␊ |
258 | ␉␉ */␊ |
259 | ␉␉if (!getValueForKey(kDeviceProperties, &val, &cnt, DEFAULT_BOOT_CONFIG))␊ |
260 | ␉␉{ ␊ |
261 | return;␉␊ |
262 | ␉␉}␊ |
263 | ␉␉␊ |
264 | ␉␉if (cnt > 1)␊ |
265 | ␉␉{␊ |
266 | ␉␉␉binStr = convertHexStr2Binary(val, &cnt2);␊ |
267 | ␉␉␉if (binStr) ␊ |
268 | ␉␉␉{␊ |
269 | ␉␉␉␉if (cnt2 > 0)␊ |
270 | ␉␉␉␉{␊ |
271 | ␉␉␉␉␉kbinStr = (uint8_t*)AllocateKernelMemory(cnt2);␊ |
272 | ␉␉␉␉␉␊ |
273 | ␉␉␉␉␉if (kbinStr)␊ |
274 | ␉␉␉␉␉{␊ |
275 | ␉␉␉␉␉␉bcopy(binStr,kbinStr,cnt2);␊ |
276 | ␉␉␉␉␉␉DT__AddProperty(node, DEVICE_PROPERTIES_PROP, cnt2, kbinStr);␊ |
277 | ␉␉␉␉␉} ␊ |
278 | ␉␉␉␉}␊ |
279 | ␉␉␉␉free(binStr);␊ |
280 | ␉␉␉}␊ |
281 | ␉␉␉␊ |
282 | ␉␉}␊ |
283 | ␉}␉␊ |
284 | }␊ |
285 | ␊ |
286 | ␊ |
287 | void finalizeEFIConfigTable(void)␊ |
288 | { ␊ |
289 | if (get_env(envarchCpuType) == CPU_TYPE_I386)␊ |
290 | ␉{␊ |
291 | ␉␉EFI_SYSTEM_TABLE_32 *efiSystemTable = gST32; ␊ |
292 | ␊ |
293 | efiSystemTable->NumberOfTableEntries = gNumTables32; ␊ |
294 | efiSystemTable->ConfigurationTable = (EFI_PTR32)gEfiConfigurationTable32;␊ |
295 | ␊ |
296 | ␉}␊ |
297 | ␉else␊ |
298 | ␉{␊ |
299 | ␉␉EFI_SYSTEM_TABLE_64 *efiSystemTable = gST64; ␊ |
300 | ␊ |
301 | efiSystemTable->NumberOfTableEntries = gNumTables64; ␊ |
302 | efiSystemTable->ConfigurationTable = ptov64((EFI_PTR32)gEfiConfigurationTable64); ␊ |
303 | ␊ |
304 | ␉}␊ |
305 | EFI_ST_FIX_CRC32();␊ |
306 | ␊ |
307 | #if DEBUG_EFI␊ |
308 | EFI_UINTN i;␊ |
309 | EFI_UINTN num = 0;␊ |
310 | uint32_t table ;␊ |
311 | EFI_GUID Guid;␊ |
312 | ␊ |
313 | if (get_env(envarchCpuType) == CPU_TYPE_I386)␊ |
314 | ␉{␊ |
315 | ␉␉num = gST32->NumberOfTableEntries; ␊ |
316 | ␊ |
317 | ␉}␊ |
318 | ␉else␊ |
319 | ␉{␊ |
320 | ␉␉num = (EFI_UINTN)gST64->NumberOfTableEntries; ␊ |
321 | ␊ |
322 | ␉}␊ |
323 | ␉msglog("EFI Configuration table :\n");␊ |
324 | for (i=0; i<num; i++)␊ |
325 | ␉{␊ |
326 | if (get_env(envarchCpuType) == CPU_TYPE_I386)␊ |
327 | {␊ |
328 | table = gEfiConfigurationTable32[i].VendorTable;␊ |
329 | Guid = gEfiConfigurationTable32[i].VendorGuid;␊ |
330 | ␊ |
331 | }␊ |
332 | else␊ |
333 | {␊ |
334 | table = gEfiConfigurationTable64[i].VendorTable;␊ |
335 | Guid = gEfiConfigurationTable64[i].VendorGuid;␊ |
336 | ␊ |
337 | }␊ |
338 | char id[4+1];␊ |
339 | bzero(id,sizeof(id)); ␊ |
340 | if (memcmp(&Guid, &gEfiSmbiosTableGuid, sizeof(EFI_GUID)) == 0)␊ |
341 | ␉␉{␊ |
342 | snprintf(id, sizeof(id),"%s", "_SM_");␊ |
343 | }␊ |
344 | ␉␉else if (memcmp(&Guid, &gEfiAcpiTableGuid, sizeof(EFI_GUID)) == 0)␊ |
345 | ␉␉{␊ |
346 | snprintf(id,sizeof(id), "%s", "RSD1");␊ |
347 | }␊ |
348 | ␉␉else if (memcmp(&Guid, &gEfiAcpi20TableGuid, sizeof(EFI_GUID)) == 0)␊ |
349 | ␉␉{␊ |
350 | snprintf(id, sizeof(id),"%s", "RSD2");␊ |
351 | }␊ |
352 | #ifndef NO_SMP_SUPPORT␊ |
353 | ␉␉else if (memcmp(&Guid, &gEfiMpsTableGuid, sizeof(EFI_GUID)) == 0)␊ |
354 | ␉␉{␊ |
355 | snprintf(id, sizeof(id),"%s", "_MP_");␊ |
356 | } ␊ |
357 | #endif␊ |
358 | ␉␉␊ |
359 | msglog("table [%d]:%s , 32Bit addr : 0x%x\n",i,id,table);␊ |
360 | ␊ |
361 | }␊ |
362 | msglog("\n");␊ |
363 | #endif␊ |
364 | ␊ |
365 | }␊ |
366 | ␊ |
367 | /*␊ |
368 | * What we do here is simply allocate a fake EFI system table and a fake EFI␊ |
369 | * runtime services table.␊ |
370 | *␊ |
371 | * Because we build against modern headers with kBootArgsRevision 4 we␊ |
372 | * also take care to set efiMode = 32.␊ |
373 | */␊ |
374 | ␊ |
375 | ␊ |
376 | #define pto(mode, addr) (mode == 64) ? ptov64((EFI_PTR32)addr) : (EFI_PTR32)addr␊ |
377 | ␊ |
378 | #define setupEfiTables(mode) \␊ |
379 | { \␊ |
380 | struct fake_efi_pages \␊ |
381 | {\␊ |
382 | /* We use the fake_efi_pages struct so that we only need to do one kernel␊ |
383 | * memory allocation for all needed EFI data. Otherwise, small allocations␊ |
384 | * like the FIRMWARE_VENDOR string would take up an entire page.␊ |
385 | * NOTE WELL: Do NOT assume this struct has any particular layout within itself.␊ |
386 | * It is absolutely not intended to be publicly exposed anywhere␊ |
387 | * We say pages (plural) although right now we are well within the 1 page size␊ |
388 | * and probably will stay that way.␊ |
389 | */\␊ |
390 | EFI_SYSTEM_TABLE_##mode efiSystemTable;\␊ |
391 | EFI_RUNTIME_SERVICES_##mode efiRuntimeServices;\␊ |
392 | EFI_CONFIGURATION_TABLE_##mode efiConfigurationTable[MAX_CONFIGURATION_TABLE_ENTRIES];\␊ |
393 | EFI_CHAR16 firmwareVendor[sizeof(FIRMWARE_VENDOR)/sizeof(EFI_CHAR16)];\␊ |
394 | uint8_t voidret_instructions[sizeof(VOIDRET_INSTRUCTIONS)/sizeof(uint8_t)];\␊ |
395 | uint8_t unsupportedret_instructions[sizeof(UNSUPPORTEDRET_INSTRUCTIONS)/sizeof(uint8_t)];\␊ |
396 | };\␊ |
397 | struct fake_efi_pages *fakeEfiPages = (struct fake_efi_pages*)AllocateKernelMemory(sizeof(struct fake_efi_pages));\␊ |
398 | /* Zero out all the tables in case fields are added later*/\␊ |
399 | bzero(fakeEfiPages, sizeof(struct fake_efi_pages));\␊ |
400 | /*--------------------------------------------------------------------␊ |
401 | * Initialize some machine code that will return EFI_UNSUPPORTED for␊ |
402 | * functions returning int and simply return for void functions.*/\␊ |
403 | memcpy(fakeEfiPages->voidret_instructions, VOIDRET_INSTRUCTIONS, sizeof(VOIDRET_INSTRUCTIONS));\␊ |
404 | memcpy(fakeEfiPages->unsupportedret_instructions, UNSUPPORTEDRET_INSTRUCTIONS, sizeof(UNSUPPORTEDRET_INSTRUCTIONS));\␊ |
405 | /*--------------------------------------------------------------------␊ |
406 | * System table*/\␊ |
407 | EFI_SYSTEM_TABLE_##mode *efiSystemTable = gST##mode = &fakeEfiPages->efiSystemTable;\␊ |
408 | efiSystemTable->Hdr.Signature = EFI_SYSTEM_TABLE_SIGNATURE;\␊ |
409 | efiSystemTable->Hdr.Revision = EFI_SYSTEM_TABLE_REVISION;\␊ |
410 | efiSystemTable->Hdr.HeaderSize = sizeof(EFI_SYSTEM_TABLE_##mode);\␊ |
411 | efiSystemTable->Hdr.CRC32 = 0;/*Initialize to zero and then do CRC32*/ \␊ |
412 | efiSystemTable->Hdr.Reserved = 0;\␊ |
413 | efiSystemTable->FirmwareVendor = pto(mode, &fakeEfiPages->firmwareVendor);\␊ |
414 | memcpy(fakeEfiPages->firmwareVendor, FIRMWARE_VENDOR, sizeof(FIRMWARE_VENDOR));\␊ |
415 | efiSystemTable->FirmwareRevision = FIRMWARE_REVISION;\␊ |
416 | /* XXX: We may need to have basic implementations of ConIn/ConOut/StdErr␊ |
417 | * The EFI spec states that all handles are invalid after boot services have been␊ |
418 | * exited so we can probably get by with leaving the handles as zero.␊ |
419 | */\␊ |
420 | efiSystemTable->ConsoleInHandle = 0;\␊ |
421 | efiSystemTable->ConIn = 0;\␊ |
422 | efiSystemTable->ConsoleOutHandle = 0;\␊ |
423 | efiSystemTable->ConOut = 0;\␊ |
424 | efiSystemTable->StandardErrorHandle = 0;\␊ |
425 | efiSystemTable->StdErr = 0;\␊ |
426 | efiSystemTable->RuntimeServices = pto(mode,&fakeEfiPages->efiRuntimeServices) ;\␊ |
427 | /* According to the EFI spec, BootServices aren't valid after the␊ |
428 | * boot process is exited so we can probably do without it.␊ |
429 | * Apple didn't provide a definition for it in pexpert/i386/efi.h␊ |
430 | * so I'm guessing they don't use it.␊ |
431 | */\␊ |
432 | efiSystemTable->BootServices = 0;\␊ |
433 | efiSystemTable->NumberOfTableEntries = 0;\␊ |
434 | efiSystemTable->ConfigurationTable = pto(mode,fakeEfiPages->efiConfigurationTable);\␊ |
435 | /* We're done. Now CRC32 the thing so the kernel will accept it.␊ |
436 | * Must be initialized to zero before CRC32, done above.␊ |
437 | */\␊ |
438 | gST##mode->Hdr.CRC32 = crc32(0L, gST##mode, gST##mode->Hdr.HeaderSize);\␊ |
439 | /*--------------------------------------------------------------------␊ |
440 | * Runtime services*/\␊ |
441 | EFI_RUNTIME_SERVICES_##mode *efiRuntimeServices = &fakeEfiPages->efiRuntimeServices;\␊ |
442 | efiRuntimeServices->Hdr.Signature = EFI_RUNTIME_SERVICES_SIGNATURE;\␊ |
443 | efiRuntimeServices->Hdr.Revision = EFI_RUNTIME_SERVICES_REVISION;\␊ |
444 | efiRuntimeServices->Hdr.HeaderSize = sizeof(EFI_RUNTIME_SERVICES_##mode);\␊ |
445 | efiRuntimeServices->Hdr.CRC32 = 0;\␊ |
446 | efiRuntimeServices->Hdr.Reserved = 0;\␊ |
447 | /* There are a number of function pointers in the efiRuntimeServices table.␊ |
448 | * These are the Foundation (e.g. core) services and are expected to be present on␊ |
449 | * all EFI-compliant machines.␉Some kernel extensions (notably AppleEFIRuntime)␊ |
450 | * will call these without checking to see if they are null.␊ |
451 | *␊ |
452 | * We don't really feel like doing an EFI implementation in the bootloader␊ |
453 | * but it is nice if we can at least prevent a complete crash by␊ |
454 | * at least providing some sort of implementation until one can be provided␊ |
455 | * nicely in a kext.␊ |
456 | */\␊ |
457 | void (*voidret_fp)() = (void*)fakeEfiPages->voidret_instructions;\␊ |
458 | void (*unsupportedret_fp)() = (void*)fakeEfiPages->unsupportedret_instructions;\␊ |
459 | efiRuntimeServices->GetTime = pto(mode,unsupportedret_fp);\␊ |
460 | efiRuntimeServices->SetTime = pto(mode,unsupportedret_fp);\␊ |
461 | efiRuntimeServices->GetWakeupTime = pto(mode,unsupportedret_fp);\␊ |
462 | efiRuntimeServices->SetWakeupTime = pto(mode,unsupportedret_fp);\␊ |
463 | efiRuntimeServices->SetVirtualAddressMap = pto(mode,unsupportedret_fp);\␊ |
464 | efiRuntimeServices->ConvertPointer = pto(mode,unsupportedret_fp);\␊ |
465 | efiRuntimeServices->GetVariable = pto(mode,unsupportedret_fp);\␊ |
466 | efiRuntimeServices->GetNextVariableName = pto(mode,unsupportedret_fp);\␊ |
467 | efiRuntimeServices->SetVariable = pto(mode,unsupportedret_fp);\␊ |
468 | efiRuntimeServices->GetNextHighMonotonicCount = pto(mode,unsupportedret_fp);\␊ |
469 | efiRuntimeServices->ResetSystem = pto(mode,voidret_fp);\␊ |
470 | /*We're done.␉Now CRC32 the thing so the kernel will accept it*/\␊ |
471 | efiRuntimeServices->Hdr.CRC32 = crc32(0L, efiRuntimeServices, efiRuntimeServices->Hdr.HeaderSize);\␊ |
472 | /*--------------------------------------------------------------------␊ |
473 | * Finish filling in the rest of the boot args that we need.*/\␊ |
474 | bootArgs->efiSystemTable = (uint32_t)efiSystemTable;\␊ |
475 | bootArgs->efiMode = kBootArgsEfiMode##mode;\␊ |
476 | /* The bootArgs structure as a whole is bzero'd so we don't need to fill in␊ |
477 | * things like efiRuntimeServices* and what not.␊ |
478 | *␊ |
479 | * In fact, the only code that seems to use that is the hibernate code so it␊ |
480 | * knows not to save the pages.␉ It even checks to make sure its nonzero.␊ |
481 | */\␊ |
482 | }␊ |
483 | ␊ |
484 | /*␊ |
485 | * In addition to the EFI tables there is also the EFI device tree node.␊ |
486 | * In particular, we need /efi/platform to have an FSBFrequency key. Without it,␊ |
487 | * the tsc_init function will panic very early on in kernel startup, before␊ |
488 | * the console is available.␊ |
489 | */␊ |
490 | ␊ |
491 | /*==========================================================================␊ |
492 | * FSB Frequency detection␊ |
493 | */␊ |
494 | ␊ |
495 | /* These should be const but DT__AddProperty takes char* */␊ |
496 | #if UNUSED␊ |
497 | static const char const TSC_Frequency_prop[] = "TSCFrequency";␊ |
498 | static const char const CPU_Frequency_prop[] = "CPUFrequency";␊ |
499 | #endif␊ |
500 | static const char const FSB_Frequency_prop[] = "FSBFrequency";␊ |
501 | ␊ |
502 | /*==========================================================================␊ |
503 | * SMBIOS␊ |
504 | */␊ |
505 | ␊ |
506 | static uint64_t smbios_p;␊ |
507 | ␊ |
508 | void Register_Smbios_Efi(void* smbios)␊ |
509 | {␊ |
510 | smbios_p = ((uint64_t)((uint32_t)smbios));␉␊ |
511 | }␊ |
512 | ␊ |
513 | /*==========================================================================␊ |
514 | * ACPI ␊ |
515 | */␊ |
516 | ␊ |
517 | static uint64_t local_rsd_p␉␉␉= 0;␊ |
518 | static uint64_t kFSBFrequency␉␉= 0;␊ |
519 | static uint32_t␉␉kHardware_signature = 0;␊ |
520 | static uint8_t␉␉kType␉␉␉␉= 0;␊ |
521 | static uint32_t␉␉kAdler32␉␉␉= 0;␊ |
522 | static ACPI_TABLES acpi_tables;␊ |
523 | ␊ |
524 | ␊ |
525 | EFI_STATUS Register_Acpi_Efi(void* rsd_p, unsigned char rev )␊ |
526 | {␊ |
527 | ␉EFI_STATUS Status = EFI_UNSUPPORTED;␊ |
528 | ␉local_rsd_p = ((U64)((U32)rsd_p));␊ |
529 | ␊ |
530 | ␉if (local_rsd_p) {␊ |
531 | ␉␉if (rev == 2)␊ |
532 | ␉␉{␊ |
533 | ␉␉␉Status = addConfigurationTable(&gEfiAcpi20TableGuid, &local_rsd_p, "ACPI_20");␊ |
534 | ␉␉}␊ |
535 | ␉␉else␊ |
536 | ␉␉{␊ |
537 | ␉␉␉Status = addConfigurationTable(&gEfiAcpiTableGuid, &local_rsd_p, "ACPI");␉␉␉␊ |
538 | ␉␉}␊ |
539 | ␉}␊ |
540 | ␉else ␊ |
541 | ␉{␊ |
542 | ␉␉Status = setupAcpiNoMod();␊ |
543 | ␉}␊ |
544 | ␉␉␊ |
545 | ␉␊ |
546 | ␉return Status;␉␊ |
547 | }␊ |
548 | ␊ |
549 | static EFI_STATUS EFI_FindAcpiTables(VOID)␊ |
550 | {␊ |
551 | ␉EFI_STATUS ret = EFI_UNSUPPORTED;␊ |
552 | ␉␊ |
553 | ␉if (local_rsd_p)␊ |
554 | ␉{␊ |
555 | ␉␉return EFI_SUCCESS;␊ |
556 | ␉}␊ |
557 | ␊ |
558 | ␉if (!FindAcpiTables(&acpi_tables))␊ |
559 | ␉{␊ |
560 | ␉␉printf("Failed to detect ACPI tables.\n");␊ |
561 | ␉␉ret = EFI_NOT_FOUND;␊ |
562 | ␉}␊ |
563 | ␉␊ |
564 | ␉local_rsd_p = ((uint64_t)((uint32_t)acpi_tables.RsdPointer));␊ |
565 | ␉␊ |
566 | ␉if (local_rsd_p)␊ |
567 | ␉{␊ |
568 | ␉␉ret = EFI_SUCCESS;␊ |
569 | ␉}␊ |
570 | ␉return ret;␊ |
571 | ␊ |
572 | }␊ |
573 | ␊ |
574 | /* Setup ACPI without any patch. */␊ |
575 | static EFI_STATUS setupAcpiNoMod(VOID)␊ |
576 | { ␉␊ |
577 | ␉EFI_STATUS ret = EFI_UNSUPPORTED;␊ |
578 | ␉␊ |
579 | ␉if (EFI_FindAcpiTables() == EFI_SUCCESS) ␊ |
580 | ␉{␊ |
581 | ␉␉ACPI_TABLE_RSDP* rsdp = (ACPI_TABLE_RSDP*)((uint32_t)local_rsd_p);␊ |
582 | ␉␉if(rsdp->Revision > 0 && (GetChecksum(rsdp, sizeof(ACPI_TABLE_RSDP)) == 0))␊ |
583 | ␉␉{␊ |
584 | ␉␉␉ret = addConfigurationTable(&gEfiAcpi20TableGuid, &local_rsd_p, "ACPI_20");␉␉ ␊ |
585 | ␉␉}␊ |
586 | ␉␉else␊ |
587 | ␉␉{␊ |
588 | ␉␉␉ret = addConfigurationTable(&gEfiAcpiTableGuid, &local_rsd_p, "ACPI");␉␉␊ |
589 | ␉␉}␊ |
590 | ␉} ␊ |
591 | ␉␊ |
592 | ␉return ret;␊ |
593 | }␊ |
594 | ␊ |
595 | EFI_STATUS setup_acpi (VOID)␊ |
596 | {␉␊ |
597 | ␉EFI_STATUS ret = EFI_UNSUPPORTED;␉␊ |
598 | ␉␊ |
599 | ␉do {␊ |
600 | ␉␉␊ |
601 | if ((ret = EFI_FindAcpiTables()) != EFI_SUCCESS)␊ |
602 | { ␊ |
603 | break;␊ |
604 | } ␊ |
605 | ␊ |
606 | {␊ |
607 | ACPI_TABLE_FADT *FacpPointer = (acpi_tables.FacpPointer64 != (void*)0ul) ? (ACPI_TABLE_FADT *)acpi_tables.FacpPointer64 : (ACPI_TABLE_FADT *)acpi_tables.FacpPointer;␊ |
608 | ␊ |
609 | uint8_t type = FacpPointer->PreferredProfile;␊ |
610 | if (type <= MaxSupportedPMProfile) ␊ |
611 | safe_set_env(envType,type);␊ |
612 | } ␊ |
613 | ␊ |
614 | ret = setupAcpiNoMod();␊ |
615 | ␉␉␊ |
616 | ␉} while (0);␉␊ |
617 | ␉␊ |
618 | ␉return ret;␉␊ |
619 | ␉␊ |
620 | }␊ |
621 | ␊ |
622 | /*==========================================================================␊ |
623 | * Fake EFI implementation␊ |
624 | */␊ |
625 | ␊ |
626 | /* These should be const but DT__AddProperty takes char* */␊ |
627 | static const char const FIRMWARE_REVISION_PROP[] = "firmware-revision";␊ |
628 | static const char const FIRMWARE_ABI_PROP[] = "firmware-abi";␊ |
629 | static const char const FIRMWARE_VENDOR_PROP[] = "firmware-vendor";␊ |
630 | static const char const FIRMWARE_NAME_PROP[] = "firmware-name";␊ |
631 | static const char const FIRMWARE_DATE_PROP[] = "firmware-date";␊ |
632 | static const char const FIRMWARE_DEV_PROP[] = "firmware-maintener";␊ |
633 | static const char const FIRMWARE_PUBLISH_PROP[] = "firmware-publisher";␊ |
634 | ␊ |
635 | ␊ |
636 | static const char const FIRMWARE_ABI_32_PROP_VALUE[] = "EFI32";␊ |
637 | static const char const FIRMWARE_ABI_64_PROP_VALUE[] = "EFI64";␊ |
638 | static const char const SYSTEM_ID_PROP[] = "system-id";␊ |
639 | static const char const SYSTEM_SERIAL_PROP[] = "SystemSerialNumber";␊ |
640 | static const char const SYSTEM_TYPE_PROP[] = "system-type";␊ |
641 | static const char const MODEL_PROP[] = "Model";␊ |
642 | static const char const MOTHERBOARD_NAME_PROP[] = "motherboard-name";␊ |
643 | ␊ |
644 | ␊ |
645 | /*␊ |
646 | * Get an smbios option string option to convert to EFI_CHAR16 string␊ |
647 | */␊ |
648 | ␊ |
649 | static EFI_CHAR16* getSmbiosChar16(const char * key, size_t* len)␊ |
650 | {␊ |
651 | ␉if (!GetgPlatformName() && strncmp(key, "SMproductname", sizeof("SMproductname")) == 0)␊ |
652 | ␉␉readSMBIOS(thePlatformName);␊ |
653 | ␉␊ |
654 | ␉const char␉*PlatformName = GetgPlatformName() ;␊ |
655 | ␉␊ |
656 | ␉const char␉*src = (strncmp(key, "SMproductname", sizeof("SMproductname")) == 0) ? PlatformName : getStringForKey(key, DEFAULT_SMBIOS_CONFIG);␊ |
657 | ␉␊ |
658 | ␉EFI_CHAR16*␉ dst = 0;␉␊ |
659 | ␉␊ |
660 | ␉if (!key || !(*key) || !src) goto error;␊ |
661 | ␉␊ |
662 | int tmp_len = strlen(src);␊ |
663 | ␊ |
664 | *len = ((tmp_len)+1) * 2; // return the CHAR16 bufsize in cluding zero terminated CHAR16␊ |
665 | ␊ |
666 | if (!(*len > 0)) goto error;␊ |
667 | ␊ |
668 | ␉dst = (EFI_CHAR16*) malloc( *len );␊ |
669 | if (!dst) ␊ |
670 | {␊ |
671 | goto error;␊ |
672 | }␊ |
673 | ␊ |
674 | ␉{␊ |
675 | ␉␉size_t␉␉ i = 0;␊ |
676 | ␉␉for (; i < (tmp_len); i++)␉ dst[i] = src[i];␊ |
677 | ␉}␊ |
678 | ␉dst[(tmp_len)] = '\0';␊ |
679 | ␉return dst;␊ |
680 | ␊ |
681 | error:␊ |
682 | *len = 0;␊ |
683 | return NULL;␊ |
684 | }␊ |
685 | ␊ |
686 | /*␊ |
687 | * Get the SystemID from the bios dmi info␊ |
688 | */␊ |
689 | ␊ |
690 | static EFI_CHAR8* getSmbiosUUID(VOID)␊ |
691 | {␊ |
692 | ␉static EFI_CHAR8␉␉ uuid[UUID_LEN];␊ |
693 | ␉int␉␉␉␉␉␉ i, isZero, isOnes;␊ |
694 | ␉SMBByte␉␉␉␉␉*p;␉␉␊ |
695 | ␉␊ |
696 | p = (SMBByte*)(uint32_t)get_env(envUUID);␊ |
697 | ␊ |
698 | if ( p == NULL )␊ |
699 | ␉{␊ |
700 | DBG("No patched UUID found, fallback to original UUID (if exist) \n");␊ |
701 | ␉␉␊ |
702 | readSMBIOS(theUUID);␉␉␊ |
703 | p = (SMBByte*)(uint32_t)get_env(envUUID);␊ |
704 | ␊ |
705 | }␊ |
706 | ␊ |
707 | ␉for (i=0, isZero=1, isOnes=1; i<UUID_LEN; i++)␊ |
708 | ␉{␊ |
709 | ␉␉if (p[i] != 0x00) isZero = 0;␊ |
710 | ␉␉if (p[i] != 0xff) isOnes = 0;␊ |
711 | ␉}␊ |
712 | ␉␊ |
713 | ␉if (isZero || isOnes) // empty or setable means: no uuid present␊ |
714 | ␉{␊ |
715 | ␉␉verbose("No UUID present in SMBIOS System Information Table\n");␊ |
716 | ␉␉return 0;␊ |
717 | ␉} ␊ |
718 | #if DEBUG_EFI␊ |
719 | ␉else␊ |
720 | ␉␉verbose("Found UUID in SMBIOS System Information Table\n");␊ |
721 | #endif␊ |
722 | ␉␊ |
723 | ␉memcpy(uuid, p, UUID_LEN);␊ |
724 | ␉return uuid;␊ |
725 | }␊ |
726 | ␊ |
727 | /*␊ |
728 | * return a binary UUID value from the overriden SystemID and SMUUID if found, ␊ |
729 | * or from the bios if not, or from a fixed value if no bios value is found ␊ |
730 | */␊ |
731 | ␊ |
732 | static int8_t *getSystemID(VOID)␊ |
733 | {␊ |
734 | static int8_t␉␉␉␉sysid[16];␊ |
735 | ␉// unable to determine UUID for host. Error: 35 fix␊ |
736 | ␉// Rek: new SMsystemid option conforming to smbios notation standards, this option should␊ |
737 | ␉// belong to smbios config only ...␊ |
738 | ␉EFI_CHAR8*␉ret = NULL;␉␊ |
739 | ␉uuid_t uuid;␊ |
740 | ␉␊ |
741 | ␉{␊ |
742 | ␉␉bool value = false;␊ |
743 | ␉␉if (getBoolForKey( kRandomSystemID, &value, DEFAULT_BOOT_CONFIG ) && value) ␊ |
744 | ␉␉{ ␊ |
745 | ␉␉␉uuid_generate_random(uuid);␊ |
746 | ␉␉␉ret = (EFI_CHAR8*)uuid;␊ |
747 | ␉␉␉if (ret) goto out;␊ |
748 | ␉␉}␊ |
749 | ␉}␊ |
750 | ␉␊ |
751 | ␉␊ |
752 | ␉{␊ |
753 | ␉␉const char *user_uuid = getStringForKey(kSystemID, DEFAULT_BOOT_CONFIG);␊ |
754 | ␉␉if (user_uuid)␊ |
755 | ␉␉{␊ |
756 | ␉␉␉ret = getUUIDFromString(user_uuid);␊ |
757 | ␉␉}␊ |
758 | ␉}␊ |
759 | ␉␊ |
760 | ␉if (!ret) // try bios dmi info UUID extraction␉␊ |
761 | ␉␉ret = getSmbiosUUID();␊ |
762 | ␉␊ |
763 | ␉if (!ret)␊ |
764 | ␉{␊ |
765 | ␉␉// no bios dmi UUID available, get random uuid␉␉␊ |
766 | ␉␉uuid_generate_random(uuid);␊ |
767 | ␉␉ret = (EFI_CHAR8*)uuid;␉␉␊ |
768 | ␉␉verbose("Customizing SystemID with : %s\n", getStringFromUUID(ret)); // apply a nice formatting to the displayed output␊ |
769 | ␉}␊ |
770 | ␉else␉␊ |
771 | ␉{␊ |
772 | ␉␉const char *mac = getStringFromUUID(ret);␊ |
773 | ␉␉verbose("MAC address : %c%c:%c%c:%c%c:%c%c:%c%c:%c%c\n",mac[24],mac[25],mac[26],mac[27],mac[28],mac[29]␊ |
774 | ␉␉␉␉,mac[30],mac[31],mac[32],mac[33],mac[34],mac[35]);␉␉ ␊ |
775 | ␉␉␊ |
776 | ␉}␊ |
777 | ␉␊ |
778 | out:␉␊ |
779 | ␉if (ret)␊ |
780 | ␉{ ␊ |
781 | ␊ |
782 | ␉␉memcpy(sysid, ret, UUID_LEN);␊ |
783 | set_env_copy(envSysId, sysid, sizeof(sysid));␊ |
784 | ␉}␊ |
785 | ␉␊ |
786 | ␉return sysid;␊ |
787 | }␊ |
788 | ␊ |
789 | /*␊ |
790 | * Must be called AFTER setup Acpi because we need to take care of correct␊ |
791 | * facp content to reflect in ioregs␊ |
792 | */␊ |
793 | ␊ |
794 | static VOID setupSystemType(VOID)␊ |
795 | {␊ |
796 | ␉Node *node = DT__FindNode("/", false);␊ |
797 | ␉if (node == 0)␊ |
798 | {␊ |
799 | stop("Couldn't get root node");␊ |
800 | return;␊ |
801 | }␊ |
802 | ␉// we need to write this property after facp parsing␊ |
803 | ␉// Export system-type only if it has been overrriden by the SystemType option␊ |
804 | kType = get_env(envType);␊ |
805 | ␉DT__AddProperty(node, SYSTEM_TYPE_PROP, sizeof(uint8_t), &kType);␊ |
806 | }␊ |
807 | ␊ |
808 | static VOID setupEfiDeviceTree(VOID)␊ |
809 | {␉␊ |
810 | ␉Node␉␉*node;␊ |
811 | ␉␊ |
812 | ␉node = DT__FindNode("/", false);␊ |
813 | ␉␊ |
814 | ␉if (node == 0)␊ |
815 | {␊ |
816 | stop("Couldn't get root node");␊ |
817 | return;␊ |
818 | }␊ |
819 | ␊ |
820 | #ifndef NO_BOOT_IMG␊ |
821 | ␉{␊ |
822 | ␉␉long size;␊ |
823 | ␉␉{␊ |
824 | #include "appleClut8.h"␊ |
825 | ␉␉␉size = sizeof(appleClut8);␊ |
826 | ␉␉␉long clut = AllocateKernelMemory(size);␊ |
827 | ␉␉␉bcopy(&appleClut8, (void*)clut, size);␊ |
828 | ␊ |
829 | if (((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3] == '8') ␊ |
830 | {␊ |
831 | AllocateMemoryRange( "FailedCLUT", clut, size);␊ |
832 | ␊ |
833 | } else␊ |
834 | AllocateMemoryRange( "BootCLUT", clut, size);␊ |
835 | ␉␉␉␊ |
836 | ␉␉}␊ |
837 | ␉␉␊ |
838 | ␉␉{␊ |
839 | #include "failedboot.h"␉␊ |
840 | ␉␉␉size = 32 + kFailedBootWidth * kFailedBootHeight;␊ |
841 | ␉␉␉long bootPict = AllocateKernelMemory(size);␊ |
842 | if (((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3] == '8') ␊ |
843 | {␊ |
844 | AllocateMemoryRange( "FailedImage", bootPict, size); ␊ |
845 | ␊ |
846 | } else␊ |
847 | AllocateMemoryRange( "Pict-FailedBoot", bootPict, size); ␊ |
848 | ␊ |
849 | ␉␉␉((boot_progress_element *)bootPict)->width = kFailedBootWidth;␊ |
850 | ␉␉␉((boot_progress_element *)bootPict)->height = kFailedBootHeight;␊ |
851 | ␉␉␉((boot_progress_element *)bootPict)->yOffset = kFailedBootOffset;␉␊ |
852 | ␉␉␉if (((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3] == '8') ␊ |
853 | {␊ |
854 | ((boot_progress_element *)bootPict)->data_size = size - 32; ␊ |
855 | }␊ |
856 | ␉␉␉bcopy((char *)gFailedBootPict, (char *)(bootPict + 32), size - 32);␊ |
857 | ␉␉}␊ |
858 | ␉}␊ |
859 | #endif␊ |
860 | ␉//Fix an error with the Lion's (DP2+) installer␉␊ |
861 | ␉if (execute_hook("getboardproductPatched", NULL, NULL, NULL, NULL, NULL, NULL) != EFI_SUCCESS)␊ |
862 | ␉{␊ |
863 | ␉␉Setgboardproduct(getStringForKey("SMboardproduct", DEFAULT_SMBIOS_CONFIG));␊ |
864 | ␉␉␊ |
865 | ␉␉if (!Getgboardproduct()) readSMBIOS(theProducBoard);␊ |
866 | ␉␉␊ |
867 | ␉}␊ |
868 | ␉if (Getgboardproduct())␊ |
869 | ␉{␊ |
870 | ␉␉DT__AddProperty(node, "board-id", strlen(Getgboardproduct())+1, Getgboardproduct());␊ |
871 | ␉}␊ |
872 | ␉␊ |
873 | ␉{␊ |
874 | ␉␉Node *chosenNode = DT__FindNode("/chosen", true);␊ |
875 | ␉␉if (chosenNode)␊ |
876 | ␉␉{␉␉␉␊ |
877 | ␉␉␉DT__AddProperty(chosenNode, "boot-args", strlen(bootArgs->CommandLine)+1, (EFI_CHAR16*)bootArgs->CommandLine);␊ |
878 | ␉␉␉␊ |
879 | ␉␉␉// "boot-uuid" MAIN GOAL IS SYMPLY TO BOOT FROM THE UUID SET IN THE DT AND DECREASE BOOT TIME, SEE IOKitBSDInit.cpp␊ |
880 | ␉␉␉// additionally this value can be used by third-party apps or osx components (ex: pre-10.7 kextcache, ...)␊ |
881 | ␉␉␉if (bootInfo->uuidStr[0]) ␉␉␉␊ |
882 | ␉␉␉␉DT__AddProperty(chosenNode, kBootUUIDKey, strlen(bootInfo->uuidStr)+1, bootInfo->uuidStr);␊ |
883 | ␉␉␉␊ |
884 | ␉␉␉if (GetgRootDevice())␊ |
885 | ␉␉␉{␊ |
886 | ␉␉␉␉␊ |
887 | ␉␉␉␉DT__AddProperty(chosenNode, "boot-device-path", strlen(GetgRootDevice())+1, GetgRootDevice());␉␉␉␊ |
888 | ␉␉␉␉␊ |
889 | ␉␉␉}␉␉␉␊ |
890 | #ifdef rootpath␊ |
891 | ␉␉␉else␊ |
892 | ␉␉␉␉if (gRootPath[0])␊ |
893 | ␉␉␉␉{␊ |
894 | ␉␉␉␉␉␊ |
895 | ␉␉␉␉␉DT__AddProperty(chosenNode, "rootpath", strlen(gRootPath)+1, gRootPath);␉␉␉␊ |
896 | ␉␉␉␉␉␊ |
897 | ␉␉␉␉} ␊ |
898 | ␊ |
899 | #endif␊ |
900 | ␉␉␉␊ |
901 | ␉␉␉// "boot-file" is not used by kextcache if there is no "boot-device-path" or if there is a valid "rootpath" ,␊ |
902 | ␉␉␉// but i let it by default since it may be used by another service␊ |
903 | ␉␉␉DT__AddProperty(chosenNode, "boot-file", strlen(bootInfo->bootFile)+1, (EFI_CHAR16*)bootInfo->bootFile);␉␉␉␊ |
904 | ␉␉␉␊ |
905 | ␉␉␉if ((kAdler32 = (uint32_t)get_env(envAdler32))) ␊ |
906 | ␉␉␉␉DT__AddProperty(chosenNode, "boot-kernelcache-adler32", sizeof(unsigned long), &kAdler32);␊ |
907 | ␉␉␉␊ |
908 | ␉␉}␊ |
909 | ␉}␉␊ |
910 | ␉␊ |
911 | ␉// We could also just do DT__FindNode("/efi/platform", true)␊ |
912 | ␉// But I think eventually we want to fill stuff in the efi node␊ |
913 | ␉// too so we might as well create it so we have a pointer for it too.␊ |
914 | ␉Node *efiNode = DT__AddChild(node, "efi");␊ |
915 | ␉␊ |
916 | ␉{␊ |
917 | ␉␉// Set up the /efi/runtime-services table node similar to the way a child node of configuration-table␊ |
918 | ␉␉// is set up. That is, name and table properties␊ |
919 | ␉␉Node *runtimeServicesNode = DT__AddChild(efiNode, "runtime-services");␉␉␊ |
920 | ␉␉Node *kernelCompatibilityNode = 0; // ??? not sure that it should be used like that (because it's maybe the kernel capability and not the cpu capability)␊ |
921 | ␉␉␊ |
922 | ␉␉if (((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3] > '6')␊ |
923 | ␉␉{␊ |
924 | ␉␉␉kernelCompatibilityNode = DT__AddChild(efiNode, "kernel-compatibility");␉␊ |
925 | ␉␉␉DT__AddProperty(kernelCompatibilityNode, "i386", sizeof(uint32_t), (EFI_UINT32*)&DEVICE_SUPPORTED);␊ |
926 | ␉␉}␊ |
927 | ␉␉␊ |
928 | ␉␉if (get_env(envarchCpuType) == CPU_TYPE_I386)␊ |
929 | ␉␉{␊ |
930 | ␉␉␉// The value of the table property is the 32-bit physical address for the RuntimeServices table.␊ |
931 | ␉␉␉// Since the EFI system table already has a pointer to it, we simply use the address of that pointer␊ |
932 | ␉␉␉// for the pointer to the property data. Warning.. DT finalization calls free on that but we're not␊ |
933 | ␉␉␉// the only thing to use a non-malloc'd pointer for something in the DT␊ |
934 | ␉␉␉␊ |
935 | ␉␉␉DT__AddProperty(runtimeServicesNode, "table", sizeof(uint64_t), &gST32->RuntimeServices);␊ |
936 | ␉␉␉DT__AddProperty(efiNode, FIRMWARE_ABI_PROP, sizeof(FIRMWARE_ABI_32_PROP_VALUE), (char*)FIRMWARE_ABI_32_PROP_VALUE);␊ |
937 | ␉␉}␊ |
938 | ␉␉else␊ |
939 | ␉␉{␊ |
940 | ␉␉␉if (kernelCompatibilityNode) ␊ |
941 | ␉␉␉␉DT__AddProperty(kernelCompatibilityNode, "x86_64", sizeof(uint32_t), (EFI_UINT32*)&DEVICE_SUPPORTED);␊ |
942 | ␉␉␉␊ |
943 | ␉␉␉DT__AddProperty(runtimeServicesNode, "table", sizeof(uint64_t), &gST64->RuntimeServices);␊ |
944 | ␉␉␉DT__AddProperty(efiNode, FIRMWARE_ABI_PROP, sizeof(FIRMWARE_ABI_64_PROP_VALUE), (char*)FIRMWARE_ABI_64_PROP_VALUE);␊ |
945 | ␉␉}␊ |
946 | ␉}␊ |
947 | ␉␊ |
948 | ␉DT__AddProperty(efiNode, FIRMWARE_REVISION_PROP, sizeof(FIRMWARE_REVISION), (EFI_UINT32*)&FIRMWARE_REVISION);␊ |
949 | ␉DT__AddProperty(efiNode, FIRMWARE_VENDOR_PROP, sizeof(FIRMWARE_VENDOR), (EFI_CHAR16*)FIRMWARE_VENDOR);␊ |
950 | ␉DT__AddProperty(efiNode, FIRMWARE_NAME_PROP, sizeof(FIRMWARE_NAME), (EFI_CHAR16*)FIRMWARE_NAME);␊ |
951 | ␉DT__AddProperty(efiNode, FIRMWARE_DATE_PROP, strlen(I386BOOT_BUILDDATE)+1, I386BOOT_BUILDDATE);␉␊ |
952 | ␉DT__AddProperty(efiNode, FIRMWARE_DEV_PROP, strlen(FIRMWARE_MAINTENER)+1, FIRMWARE_MAINTENER);␊ |
953 | ␉DT__AddProperty(efiNode, FIRMWARE_PUBLISH_PROP, strlen(FIRMWARE_PUBLISHER)+1, FIRMWARE_PUBLISHER);␊ |
954 | ␉␊ |
955 | ␉{␊ |
956 | ␉␉// Export it for amlsgn support␊ |
957 | ␉␉char * DefaultPlatform = readDefaultPlatformName();␊ |
958 | ␉␉if (DefaultPlatform)␊ |
959 | ␉␉{␊ |
960 | ␉␉␉DT__AddProperty(efiNode, MOTHERBOARD_NAME_PROP, strlen(DefaultPlatform)+1, DefaultPlatform);␊ |
961 | ␉␉}␊ |
962 | ␉␉␊ |
963 | ␉}␊ |
964 | ␉␊ |
965 | ␉// Set up the /efi/configuration-table node which will eventually have several child nodes for␊ |
966 | ␉// all of the configuration tables needed by various kernel extensions.␊ |
967 | ␉gEfiConfigurationTableNode = DT__AddChild(efiNode, "configuration-table");␊ |
968 | ␉␊ |
969 | ␉{␊ |
970 | ␉␉EFI_CHAR16 *serial = 0, *productname = 0;␊ |
971 | int8_t␉␉␉␉*sysid = 0;␊ |
972 | ␉␉size_t␉␉ len = 0;␊ |
973 | ␉␉␊ |
974 | ␉␉// Now fill in the /efi/platform Node␊ |
975 | ␉␉Node *efiPlatformNode = DT__AddChild(efiNode, "platform");␊ |
976 | ␉␉␊ |
977 | ␉␉DT__AddProperty(efiPlatformNode, "DevicePathsSupported", sizeof(uint32_t), (EFI_UINT32*)&DEVICE_SUPPORTED);␊ |
978 | ␉␉␊ |
979 | ␉␉// NOTE WELL: If you do add FSB Frequency detection, make sure to store␊ |
980 | ␉␉// the value in the fsbFrequency global and not an malloc'd pointer␊ |
981 | ␉␉// because the DT_AddProperty function does not copy its args.␊ |
982 | ␉␉␊ |
983 | kFSBFrequency = get_env(envFSBFreq);␊ |
984 | ␉␉if (kFSBFrequency != 0)␊ |
985 | ␉␉␉DT__AddProperty(efiPlatformNode, FSB_Frequency_prop, sizeof(uint64_t), &kFSBFrequency);␉␉␊ |
986 | ␉␉␊ |
987 | #if UNUSED␊ |
988 | ␉␉// Export TSC and CPU frequencies for use by the kernel or KEXTs␊ |
989 | ␉␉Platform.CPU.TSCFrequency = get_env(envTSCFreq);␊ |
990 | if (Platform.CPU.TSCFrequency != 0)␊ |
991 | ␉␉␉DT__AddProperty(efiPlatformNode, TSC_Frequency_prop, sizeof(uint64_t), &Platform.CPU.TSCFrequency);␊ |
992 | ␉␉␊ |
993 | Platform.CPU.CPUFrequency = get_env(envCPUFreq);␊ |
994 | ␉␉if (Platform.CPU.CPUFrequency != 0)␊ |
995 | ␉␉␉DT__AddProperty(efiPlatformNode, CPU_Frequency_prop, sizeof(uint64_t), &Platform.CPU.CPUFrequency);␊ |
996 | #endif␊ |
997 | ␉␉␊ |
998 | ␉␉// Export system-id. Can be disabled with SystemId=No in com.apple.Boot.plist␉␉␊ |
999 | ␉␉if ((sysid = getSystemID()))␊ |
1000 | ␉␉␉DT__AddProperty(efiPlatformNode, SYSTEM_ID_PROP, UUID_LEN, (EFI_UINT32*) sysid);␊ |
1001 | ␉␉␊ |
1002 | ␉␉// Export SystemSerialNumber if present␊ |
1003 | ␉␉if ((serial=getSmbiosChar16("SMserial", &len)))␊ |
1004 | ␉␉␉DT__AddProperty(efiPlatformNode, SYSTEM_SERIAL_PROP, len, serial);␊ |
1005 | ␉␉␊ |
1006 | ␉␉// Export Model if present␊ |
1007 | ␉␉if ((productname=getSmbiosChar16("SMproductname", &len)))␊ |
1008 | ␉␉␉DT__AddProperty(efiPlatformNode, MODEL_PROP, len, productname);␊ |
1009 | ␉}␉␉␊ |
1010 | ␉␊ |
1011 | ␉// Fill /efi/device-properties node.␉␉␉␊ |
1012 | ␉efi_setupDeviceProperties(efiNode);␊ |
1013 | }␊ |
1014 | ␊ |
1015 | /*␊ |
1016 | * Load the smbios.plist override config file if any␊ |
1017 | */␊ |
1018 | ␊ |
1019 | void setupSmbiosConfigFile(const char *filename)␊ |
1020 | {␉␊ |
1021 | ␉static bool readSmbConfigFile = true;␊ |
1022 | ␉␊ |
1023 | ␉if (readSmbConfigFile == true)␊ |
1024 | ␉{␊ |
1025 | ␉␉char␉␉dirSpecSMBIOS[128] = "";␊ |
1026 | ␉␉const char *override_pathname = NULL;␊ |
1027 | ␉␉int␉␉␉len = 0, err = 0;␊ |
1028 | ␉␉␊ |
1029 | ␉␉// Take in account user overriding␊ |
1030 | ␉␉if (getValueForKey("SMBIOS", &override_pathname, &len, DEFAULT_BOOT_CONFIG) && len > 0)␊ |
1031 | ␉␉{␊ |
1032 | ␉␉␉// Specify a path to a file, e.g. SMBIOS=/Extra/macProXY.plist␊ |
1033 | ␉␉␉snprintf(dirSpecSMBIOS, sizeof(dirSpecSMBIOS),override_pathname);␊ |
1034 | ␉␉␉err = loadConfigFile(dirSpecSMBIOS, DEFAULT_SMBIOS_CONFIG);␊ |
1035 | ␉␉}␊ |
1036 | ␉␉else␊ |
1037 | ␉␉{␊ |
1038 | ␉␉␉// Check selected volume's Extra.␊ |
1039 | ␉␉␉snprintf(dirSpecSMBIOS, sizeof(dirSpecSMBIOS),"/Extra/%s", filename);␊ |
1040 | ␉␉␉if ((err = loadConfigFile(dirSpecSMBIOS, DEFAULT_SMBIOS_CONFIG)))␊ |
1041 | ␉␉␉{␊ |
1042 | ␉␉␉␉// Check booter volume/rdbt Extra.␊ |
1043 | ␉␉␉␉snprintf(dirSpecSMBIOS, sizeof(dirSpecSMBIOS),"bt(0,0)/Extra/%s", filename);␊ |
1044 | ␉␉␉␉err = loadConfigFile(dirSpecSMBIOS, DEFAULT_SMBIOS_CONFIG);␊ |
1045 | ␉␉␉}␊ |
1046 | ␉␉}␊ |
1047 | ␉␉␊ |
1048 | ␉␉if (err)␊ |
1049 | ␉␉{␊ |
1050 | ␉␉␉verbose("No SMBIOS config file found.\n");␊ |
1051 | ␉␉}␊ |
1052 | ␉␉readSmbConfigFile = false;␊ |
1053 | ␉}␊ |
1054 | }␊ |
1055 | ␊ |
1056 | static VOID setup_Smbios(VOID)␊ |
1057 | {␉␉␉␊ |
1058 | ␉if (execute_hook("getSmbiosPatched",NULL, NULL, NULL, NULL, NULL, NULL) != EFI_SUCCESS)␊ |
1059 | ␉{␊ |
1060 | ␉␉DBG("Using the original SMBIOS !!\n");␉␊ |
1061 | struct SMBEntryPoint *smbios_o = getSmbiosOriginal();␉␊ |
1062 | smbios_p = ((uint64_t)((uint32_t)smbios_o)); ␊ |
1063 | ␉}␉␊ |
1064 | }␊ |
1065 | ␊ |
1066 | static VOID setup_machine_signature(VOID)␊ |
1067 | {␊ |
1068 | ␉Node *chosenNode = DT__FindNode("/chosen", false);␊ |
1069 | ␉if (chosenNode)␊ |
1070 | ␉{␊ |
1071 | ␉␉if (get_env(envHardwareSignature) == 0xFFFFFFFF)␊ |
1072 | ␉␉{␉␉␉␊ |
1073 | ␉␉␉do {␊ |
1074 | ␉␉␉␉if (!local_rsd_p)␊ |
1075 | ␉␉␉␉{␉␉␉␊ |
1076 | ␉␉␉␉␉if ( EFI_FindAcpiTables() != EFI_SUCCESS)␊ |
1077 | ␉␉␉␉␉{␊ |
1078 | ␉␉␉␉␉␉printf("Failed to detect ACPI tables.\n");␊ |
1079 | ␉␉␉␉␉␉break;␊ |
1080 | ␉␉␉␉␉}␉␉␉␉␉␊ |
1081 | ␉␉␉␉}␊ |
1082 | ␉␉␉␉␊ |
1083 | ␉␉␉␉ACPI_TABLE_FACS *FacsPointer = (acpi_tables.FacsPointer64 != (void*)0ul) ? (ACPI_TABLE_FACS *)acpi_tables.FacsPointer64:(ACPI_TABLE_FACS *)acpi_tables.FacsPointer;␉␉␉␉␊ |
1084 | ␊ |
1085 | safe_set_env(envHardwareSignature , FacsPointer->HardwareSignature);␊ |
1086 | ␉␉␉␉␊ |
1087 | ␉␉␉} while (0); ␉␊ |
1088 | ␉␉␉␊ |
1089 | ␉␉␉// Verify that we have a valid hardware signature␊ |
1090 | ␉␉␉if (get_env(envHardwareSignature) == 0xFFFFFFFF) ␊ |
1091 | ␉␉␉{␊ |
1092 | ␉␉␉␉verbose("Warning: hardware_signature is invalid, defaulting to 0 \n"); ␊ |
1093 | safe_set_env(envHardwareSignature , 0);␊ |
1094 | ␉␉␉}␊ |
1095 | ␉␉}␊ |
1096 | ␉␉␊ |
1097 | kHardware_signature = get_env(envHardwareSignature); ␊ |
1098 | ␉␉DT__AddProperty(chosenNode, "machine-signature", sizeof(uint32_t), &kHardware_signature);␊ |
1099 | ␉}␊ |
1100 | ␉␊ |
1101 | }␊ |
1102 | ␊ |
1103 | /*␊ |
1104 | * Installs all the needed configuration table entries␊ |
1105 | */␊ |
1106 | ␊ |
1107 | static VOID setupEfiConfigurationTable(VOID)␊ |
1108 | {␊ |
1109 | if (smbios_p)␊ |
1110 | addConfigurationTable(&gEfiSmbiosTableGuid, &smbios_p, NULL);␊ |
1111 | #ifndef NO_SMP_SUPPORT␊ |
1112 | ␉if (get_env(envVendor) == CPUID_VENDOR_INTEL )␊ |
1113 | ␉{␊ |
1114 | ␉␉int num_cpus;␊ |
1115 | ␉␉␊ |
1116 | ␉␉void *mps_p = imps_probe(&num_cpus);␊ |
1117 | ␉␉␊ |
1118 | ␉␉if (mps_p)␊ |
1119 | ␉␉{␉␉␊ |
1120 | ␉␉␉addConfigurationTable(&gEfiMpsTableGuid, ((uint64_t*)((uint32_t)mps_p)), NULL);␊ |
1121 | ␉␉}␊ |
1122 | ␉␉␊ |
1123 | #if DEBUG_EFI␊ |
1124 | if (num_cpus != get_env(envNoCores))␊ |
1125 | {␊ |
1126 | printf("Warning: SMP nb of core (%d) mismatch with the value found in cpu.c (%d) \n",num_cpus,get_env(envNoCores)); ␊ |
1127 | } ␊ |
1128 | #endif ␊ |
1129 | ␉}␉␊ |
1130 | #endif␊ |
1131 | ␉// PM_Model␊ |
1132 | ␉if (get_env(envIsServer))␊ |
1133 | {␊ |
1134 | safe_set_env(envType , Workstation);␊ |
1135 | ␉}␊ |
1136 | ␉else if (get_env(envIsMobile))//Slice␊ |
1137 | ␉{␉␊ |
1138 | safe_set_env(envType , Mobile);␊ |
1139 | ␉} ␊ |
1140 | ␉else␊ |
1141 | ␉{␊ |
1142 | safe_set_env(envType , Desktop);␊ |
1143 | ␉}␊ |
1144 | ␉␊ |
1145 | ␉// Invalidate the platform hardware signature (this needs to be verified with acpica, but i guess that 0xFFFFFFFF is an invalid signature) ␉␊ |
1146 | safe_set_env(envHardwareSignature , 0xFFFFFFFF);␊ |
1147 | ␉␊ |
1148 | ␉// Setup ACPI (based on the mackerintel's patch)␊ |
1149 | ␉(VOID)setup_acpi();␊ |
1150 | ␉␊ |
1151 | ␉setup_machine_signature();␊ |
1152 | ␉␊ |
1153 | ␉// We now have to write the system-type in ioregs: we cannot do it before in setupDeviceTree()␊ |
1154 | ␉// because we need to take care of facp original content, if it is correct.␊ |
1155 | ␉setupSystemType();␊ |
1156 | ␉␊ |
1157 | ␉// We've obviously changed the count.. so fix up the CRC32␉␊ |
1158 | EFI_ST_FIX_CRC32();␊ |
1159 | }␊ |
1160 | ␊ |
1161 | /*␊ |
1162 | * Entrypoint from boot.c␊ |
1163 | */␊ |
1164 | ␊ |
1165 | void setupFakeEfi(void)␊ |
1166 | {␊ |
1167 | ␉// Collect PCI info &| Generate device prop string␊ |
1168 | ␉setup_root_pci_devs();␊ |
1169 | ␉␊ |
1170 | ␉// load smbios.plist file if any␊ |
1171 | ␉setupSmbiosConfigFile("SMBIOS.plist");␊ |
1172 | ␉setup_Smbios();␊ |
1173 | ␉␊ |
1174 | ␉// Initialize the base table␊ |
1175 | ␉if (get_env(envarchCpuType) == CPU_TYPE_I386)␊ |
1176 | ␉{␊ |
1177 | ␉␉setupEfiTables(32); ␊ |
1178 | ␉}␊ |
1179 | ␉else␊ |
1180 | ␉{␊ |
1181 | ␉␉setupEfiTables(64); ␊ |
1182 | ␉}␊ |
1183 | ␉␊ |
1184 | ␉// Initialize the device tree␊ |
1185 | ␉setupEfiDeviceTree();␊ |
1186 | ␉␊ |
1187 | ␉// Add configuration table entries to both the services table and the device tree␊ |
1188 | ␉setupEfiConfigurationTable();␉␉␊ |
1189 | ␉␊ |
1190 | } |