1 | /*␊ |
2 | * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.␊ |
3 | *␊ |
4 | * @APPLE_LICENSE_HEADER_START@␊ |
5 | * ␊ |
6 | * Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights␊ |
7 | * Reserved. This file contains Original Code and/or Modifications of␊ |
8 | * Original Code as defined in and that are subject to the Apple Public␊ |
9 | * Source License Version 2.0 (the "License"). You may not use this file␊ |
10 | * except in compliance with the License. Please obtain a copy of the␊ |
11 | * License at http://www.apple.com/publicsource and read it before using␊ |
12 | * this file.␊ |
13 | * ␊ |
14 | * The Original Code and all software distributed under the License are␊ |
15 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER␊ |
16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,␊ |
17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,␊ |
18 | * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the␊ |
19 | * License for the specific language governing rights and limitations␊ |
20 | * under the License.␊ |
21 | * ␊ |
22 | * @APPLE_LICENSE_HEADER_END@␊ |
23 | */␊ |
24 | /* ␊ |
25 | * Mach Operating System␊ |
26 | * Copyright (c) 1990 Carnegie-Mellon University␊ |
27 | * Copyright (c) 1989 Carnegie-Mellon University␊ |
28 | * All rights reserved. The CMU software License Agreement specifies␊ |
29 | * the terms and conditions for use and redistribution.␊ |
30 | */␊ |
31 | ␊ |
32 | /*␊ |
33 | * INTEL CORPORATION PROPRIETARY INFORMATION␊ |
34 | *␊ |
35 | * This software is supplied under the terms of a license agreement or ␊ |
36 | * nondisclosure agreement with Intel Corporation and may not be copied ␊ |
37 | * nor disclosed except in accordance with the terms of that agreement.␊ |
38 | *␊ |
39 | * Copyright 1988, 1989 by Intel Corporation␊ |
40 | */␊ |
41 | ␊ |
42 | /*␊ |
43 | * Copyright 1993 NeXT Computer, Inc.␊ |
44 | * All rights reserved.␊ |
45 | */␊ |
46 | ␊ |
47 | /*␊ |
48 | * Completely reworked by Sam Streeper (sam_s@NeXT.com)␊ |
49 | * Reworked again by Curtis Galloway (galloway@NeXT.com)␊ |
50 | */␊ |
51 | ␊ |
52 | ␊ |
53 | #include "boot.h"␊ |
54 | #include "bootstruct.h"␊ |
55 | #include "fake_efi.h"␊ |
56 | #include "sl.h"␊ |
57 | #include "libsa.h"␊ |
58 | #include "platform.h"␊ |
59 | #include "graphics.h"␊ |
60 | #ifndef OPTION_ROM␊ |
61 | #include "appleboot.h"␊ |
62 | #endif␊ |
63 | #include "modules.h"␊ |
64 | #include "xml.h"␊ |
65 | ␊ |
66 | #ifndef DEBUG_BOOT␊ |
67 | #define DEBUG_BOOT 0␊ |
68 | #endif␊ |
69 | ␊ |
70 | #if DEBUG_BOOT␊ |
71 | #define DBG(x...)␉␉printf(x)␊ |
72 | #else␊ |
73 | #define DBG(x...)␉␉␊ |
74 | #endif␊ |
75 | ␊ |
76 | ␊ |
77 | typedef struct platform_info {␊ |
78 | ␉char platformName[PLATFORM_NAME_LEN];␊ |
79 | ␉char rootPath[ROOT_PATH_LEN];␊ |
80 | } PlatformInfo;␊ |
81 | ␊ |
82 | ␊ |
83 | char *gboardproduct = NULL;␊ |
84 | char *gPlatformName = NULL;␊ |
85 | //char gRootPath[256];␊ |
86 | long gBootMode; /* defaults to 0 == kBootModeNormal */␊ |
87 | bool gOverrideKernel;␊ |
88 | char gBootKernelCacheFile[512];␊ |
89 | char gMKextName[512];␊ |
90 | char gMacOSVersion[8];␊ |
91 | char *gRootDevice = NULL;␊ |
92 | ␊ |
93 | #ifndef OPTION_ROM␊ |
94 | bool gEnableCDROMRescan;␊ |
95 | bool gScanSingleDrive;␊ |
96 | #endif␊ |
97 | ␊ |
98 | int bvCount = 0;␊ |
99 | //int␉menucount = 0;␊ |
100 | int gDeviceCount = 0; ␊ |
101 | ␊ |
102 | BVRef bvr;␊ |
103 | BVRef menuBVR;␊ |
104 | BVRef bvChain;␊ |
105 | ␊ |
106 | static void zeroBSS(void);␊ |
107 | #ifdef SAFE_MALLOC␊ |
108 | static inline void malloc_error(char *addr, size_t size, const char *file, int line);␊ |
109 | #else␊ |
110 | static inline void malloc_error(char *addr, size_t size);␊ |
111 | #endif␊ |
112 | static int ExecKernel(void *binary);␊ |
113 | static bool getOSVersion(char *str);␊ |
114 | static void getRootDevice();␊ |
115 | #ifdef NBP_SUPPORT␊ |
116 | static bool gUnloadPXEOnExit = false;␊ |
117 | #endif␊ |
118 | static bool find_file_with_ext(const char* dir, const char *ext, const char * name_compare, size_t ext_size);␊ |
119 | static bool found_extra_kext(void);␊ |
120 | static void determineCpuArch(void);␊ |
121 | ␊ |
122 | void getKernelCachePath();␊ |
123 | ␊ |
124 | ␊ |
125 | /*␊ |
126 | * How long to wait (in seconds) to load the␊ |
127 | * kernel after displaying the "boot:" prompt.␊ |
128 | */␊ |
129 | #define kBootErrorTimeout 5␊ |
130 | ␊ |
131 | /*␊ |
132 | * Default path to kernel cache file␊ |
133 | */␊ |
134 | #define kDefaultCachePath "/System/Library/Caches/com.apple.kext.caches/Startup/kernelcache"␊ |
135 | ␊ |
136 | //==========================================================================␊ |
137 | // Zero the BSS.␊ |
138 | ␊ |
139 | static void zeroBSS(void)␊ |
140 | {␊ |
141 | ␉extern char _DATA__bss__begin, _DATA__bss__end;␊ |
142 | ␉extern char _DATA__common__begin, _DATA__common__end;␊ |
143 | ␉␊ |
144 | ␉bzero(&_DATA__bss__begin, (&_DATA__bss__end - &_DATA__bss__begin));␊ |
145 | ␉bzero(&_DATA__common__begin, (&_DATA__common__end - &_DATA__common__begin));␊ |
146 | }␊ |
147 | ␊ |
148 | //==========================================================================␊ |
149 | // Malloc error function␊ |
150 | ␊ |
151 | #ifdef SAFE_MALLOC␊ |
152 | static inline void malloc_error(char *addr, size_t size, const char *file, int line)␊ |
153 | {␊ |
154 | stop("\nMemory allocation error! Addr=0x%x, Size=0x%x, File=%s, Line=%d\n", (unsigned)addr, (unsigned)size, file, line);␊ |
155 | }␊ |
156 | #else␊ |
157 | static inline void malloc_error(char *addr, size_t size)␊ |
158 | {␊ |
159 | printf("\nMemory allocation error (0x%x, 0x%x)\n", (unsigned)addr, (unsigned)size);␊ |
160 | asm volatile ("hlt");␊ |
161 | }␊ |
162 | #endif␊ |
163 | ␊ |
164 | //==========================================================================␊ |
165 | //Initializes the runtime. Right now this means zeroing the BSS and initializing malloc.␊ |
166 | //␊ |
167 | void initialize_runtime(void)␊ |
168 | {␊ |
169 | ␉zeroBSS();␊ |
170 | ␉malloc_init(0, 0, 0, malloc_error);␊ |
171 | }␊ |
172 | ␊ |
173 | //==========================================================================␊ |
174 | // execKernel - Load the kernel image (mach-o) and jump to its entry point.␊ |
175 | ␊ |
176 | static int ExecKernel(void *binary)␊ |
177 | {␊ |
178 | entry_t kernelEntry;␊ |
179 | int ret;␊ |
180 | ␉␊ |
181 | bootArgs->kaddr = bootArgs->ksize = 0;␊ |
182 | ␉␊ |
183 | ␉if(gMacOSVersion[3] <= '6')␊ |
184 | ␉{␊ |
185 | ␉␉bootArgs->Version = kBootArgsVersion1;␉␉␊ |
186 | ␉␉bootArgs->Revision = gMacOSVersion[3];␉␊ |
187 | ␉}␊ |
188 | ␉else ␊ |
189 | ␉{␉␉␊ |
190 | #if kBootArgsVersion > 1␊ |
191 | ␉␉␊ |
192 | ␉␉bootArgs->Version = kBootArgsVersion;␉␉␊ |
193 | ␉␉bootArgs->Revision = kBootArgsRevision;␊ |
194 | #else␊ |
195 | ␉␉bootArgs->Version = 2;␊ |
196 | bootArgs->Revision = 0;␊ |
197 | #endif␊ |
198 | ␉}␊ |
199 | ␉␊ |
200 | ␉execute_hook("ExecKernel", (void*)binary, NULL, NULL, NULL, NULL, NULL);␊ |
201 | ␊ |
202 | ret = DecodeKernel(binary,␊ |
203 | &kernelEntry,␊ |
204 | (char **) &bootArgs->kaddr,␊ |
205 | (int *)&bootArgs->ksize );␊ |
206 | ␊ |
207 | if ( ret != 0 )␊ |
208 | return ret;␊ |
209 | ␉␊ |
210 | // Reserve space for boot args for 10.7 only (for 10.6 and earlier, we will convert (to legacy) the structure and reserve kernel memory for it later.)␊ |
211 | ␉if(gMacOSVersion[3] == '7')␊ |
212 | reserveKernBootStruct();␊ |
213 | ␉␊ |
214 | // Load boot drivers from the specifed root path.␊ |
215 | ␉␊ |
216 | if (!gHaveKernelCache)␊ |
217 | ␉{␊ |
218 | ␉␉LoadDrivers("/");␊ |
219 | }␊ |
220 | ␉␊ |
221 | #if TEXT_SPINNER␊ |
222 | ␉clearActivityIndicator();␊ |
223 | #endif␊ |
224 | ␉␊ |
225 | if (gErrors)␊ |
226 | ␉{␊ |
227 | printf("Errors encountered while starting up the computer.\n");␊ |
228 | #if DEBUG_BOOT␊ |
229 | printf("Pausing %d seconds...\n", kBootErrorTimeout);␊ |
230 | sleep(kBootErrorTimeout);␊ |
231 | #endif␊ |
232 | }␊ |
233 | ␉␊ |
234 | ␉execute_hook("md0Ramdisk", NULL, NULL, NULL, NULL, NULL, NULL);␊ |
235 | ␊ |
236 | setupFakeEfi();␊ |
237 | ␉␉␊ |
238 | verbose("Starting Darwin %s\n",( archCpuType == CPU_TYPE_I386 ) ? "x86" : "x86_64");␊ |
239 | #ifdef NBP_SUPPORT␊ |
240 | // Cleanup the PXE base code.␊ |
241 | ␉␊ |
242 | if ( (gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit )␊ |
243 | ␉{␊ |
244 | ␉␉if ( (ret = nbpUnloadBaseCode()) != nbpStatusSuccess )␊ |
245 | {␊ |
246 | ␉printf("nbpUnloadBaseCode error %d\n", (int) ret);␊ |
247 | sleep(2);␊ |
248 | }␊ |
249 | }␊ |
250 | #endif ␊ |
251 | ␉{␊ |
252 | ␉␉bool wait = false;␊ |
253 | ␉␉const char *strval = 0;␊ |
254 | ␉␉int dummysize /*= 0*/;␉␊ |
255 | ␉␉␊ |
256 | ␉␉getBoolForKey(kWaitForKeypressKey, &wait, &bootInfo->bootConfig);␊ |
257 | ␉␉␊ |
258 | ␉␉if (getValueForBootKey(bootArgs->CommandLine, "-wait", &strval, &dummysize))␊ |
259 | ␉␉{␊ |
260 | ␉␉␉wait = true;␊ |
261 | ␉␉␉␊ |
262 | ␉␉␉if (strval && ((strcmp(strval, "no") == 0) || (strcmp(strval, "No") == 0)))␊ |
263 | ␉␉␉{␊ |
264 | ␉␉␉␉wait = false;␊ |
265 | ␉␉␉} ␉␉␊ |
266 | ␉␉}␊ |
267 | ␉␉␊ |
268 | ␉␉if (wait == true)␊ |
269 | ␉␉{␊ |
270 | ␉␉␉pause();␊ |
271 | ␉␉}␊ |
272 | ␉} ␊ |
273 | ␉␉␉␊ |
274 | ␉if ((execute_hook("GUI_ExecKernel", NULL, NULL, NULL, NULL, NULL, NULL) != EFI_SUCCESS)) // (bootArgs->Video.v_display == VGA_TEXT_MODE)␉␊ |
275 | ␉{␊ |
276 | #if UNUSED␊ |
277 | ␉␉setVideoMode( GRAPHICS_MODE, 0 );␊ |
278 | #else␊ |
279 | ␉␉setVideoMode( GRAPHICS_MODE );␊ |
280 | #endif␊ |
281 | ␉␉␊ |
282 | #ifndef OPTION_ROM␊ |
283 | ␉␉ ␊ |
284 | ␉␉if(!gVerboseMode)␊ |
285 | ␉␉{␉␉␉␊ |
286 | ␉␉␉drawColorRectangle(0, 0, DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT, 0x01); ␊ |
287 | ␉␉␊ |
288 | ␉␉␉uint8_t *appleBootPict; ␊ |
289 | ␉␉␉uint16_t bootImageWidth = kAppleBootWidth; ␊ |
290 | ␉␉␉uint16_t bootImageHeight = kAppleBootHeight; ␊ |
291 | ␉␉␉uint8_t *bootImageData = NULL; ␉␉ ␊ |
292 | ␉␉␉uint16_t x, y;␊ |
293 | ␉␉␉␊ |
294 | ␉␉␉unsigned long screen_params[4] = {DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT, 32, 0};␉// here we store the used screen resolution␊ |
295 | ␉␉␉// Prepare the data for the default Apple boot image. ␊ |
296 | ␉␉␉appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight); ␊ |
297 | ␉␉␉if (appleBootPict)␊ |
298 | ␉␉␉{ ␊ |
299 | ␉␉␉␉convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData); ␊ |
300 | ␉␉␉␉if (bootImageData)␊ |
301 | ␉␉␉␉{␉␊ |
302 | ␉␉␉␉␉x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2; ␊ |
303 | ␉␉␉␉␉y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2; ␊ |
304 | ␉␉␉␉␉drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);␊ |
305 | ␉␉␉␉␉free(bootImageData);␊ |
306 | ␉␉␉␉}␊ |
307 | ␉␉␉␉free(appleBootPict); ␊ |
308 | ␉␉␉}␊ |
309 | ␉␉␊ |
310 | ␉␉}␊ |
311 | #endif␊ |
312 | ␉}␊ |
313 | ␊ |
314 | finalizeEFIConfigTable();␊ |
315 | ␊ |
316 | ␉setupBooterLog();␊ |
317 | ␉␊ |
318 | finalizeBootStruct(); ␊ |
319 | ␊ |
320 | ␉␊ |
321 | ␉if (gMacOSVersion[3] <= '6') ␊ |
322 | ␉␉reserveKernLegacyBootStruct(); ␉␉␊ |
323 | ␉␊ |
324 | ␉execute_hook("Kernel Start", (void*)kernelEntry, (void*)bootArgs, NULL, NULL, NULL, NULL);␉// Notify modules that the kernel is about to be started␊ |
325 | #if UNUSED␊ |
326 | ␉turnOffFloppy();␊ |
327 | #endif␊ |
328 | #if BETA␊ |
329 | #include "smp-imps.h"␊ |
330 | #include "apic.h"␊ |
331 | ␉IMPS_LAPIC_WRITE(LAPIC_LVT1, LAPIC_ICR_DM_NMI);␊ |
332 | #endif␊ |
333 | ␉␊ |
334 | ␉if (gMacOSVersion[3] <= '6')␊ |
335 | ␉{␉␉␊ |
336 | ␉␉// Jump to kernel's entry point. There's no going back now. XXX LEGACY OS XXX␊ |
337 | ␉␉startprog( kernelEntry, bootArgsLegacy );␊ |
338 | ␉}␉␊ |
339 | ␉␉␉␊ |
340 | ␉outb(0x21, 0xff); /* Maskout all interrupts Pic1 */␊ |
341 | ␉outb(0xa1, 0xff); /* Maskout all interrupts Pic2 */␊ |
342 | ␉␉␊ |
343 | ␉// Jump to kernel's entry point. There's no going back now. XXX LION XXX␊ |
344 | startprog( kernelEntry, bootArgs );␊ |
345 | ␉␊ |
346 | // Not reached␊ |
347 | ␉␊ |
348 | return 0;␊ |
349 | }␊ |
350 | ␊ |
351 | //==========================================================================␊ |
352 | // This is the entrypoint from real-mode which functions exactly as it did␊ |
353 | // before. Multiboot does its own runtime initialization, does some of its␊ |
354 | // own things, and then calls common_boot.␊ |
355 | void boot(int biosdev)␊ |
356 | {␊ |
357 | ␉initialize_runtime();␊ |
358 | ␉// Enable A20 gate before accessing memory above 1Mb.␊ |
359 | ␉enableA20();␊ |
360 | ␉common_boot(biosdev);␊ |
361 | }␊ |
362 | ␊ |
363 | //==========================================================================␊ |
364 | // The 'main' function for the booter. Called by boot0 when booting␊ |
365 | // from a block device, or by the network booter.␊ |
366 | //␊ |
367 | // arguments:␊ |
368 | // biosdev - Value passed from boot1/NBP to specify the device␊ |
369 | // that the booter was loaded from.␊ |
370 | //␊ |
371 | // If biosdev is kBIOSDevNetwork, then this function will return if␊ |
372 | // booting was unsuccessful. This allows the PXE firmware to try the␊ |
373 | // next boot device on its list.␊ |
374 | void common_boot(int biosdev)␊ |
375 | {␊ |
376 | int status; ␊ |
377 | bool firstRun = true; ␊ |
378 | ␊ |
379 | unsigned int allowBVFlags = kBVFlagSystemVolume|kBVFlagForeignBoot;␊ |
380 | unsigned int denyBVFlags = kBVFlagEFISystem;␊ |
381 | ␉␊ |
382 | #ifdef NBP_SUPPORT␊ |
383 | // Set reminder to unload the PXE base code. Neglect to unload␊ |
384 | // the base code will result in a hang or kernel panic.␊ |
385 | gUnloadPXEOnExit = true;␊ |
386 | #endif␊ |
387 | // Record the device that the booter was loaded from.␊ |
388 | gBIOSDev = biosdev & kBIOSDevMask;␊ |
389 | ␉␊ |
390 | ␉␊ |
391 | ␉␊ |
392 | // Setup VGA text mode.␊ |
393 | // Not sure if it is safe to call setVideoMode() before the␊ |
394 | // config table has been loaded. Call video_mode() instead.␊ |
395 | #if DEBUG␊ |
396 | printf("before video_mode\n");␊ |
397 | #endif␊ |
398 | video_mode( 2 ); // 80x25 mono text mode.␊ |
399 | #if DEBUG␊ |
400 | printf("after video_mode\n");␊ |
401 | #endif␊ |
402 | #if !TEXT_SPINNER␊ |
403 | ␉printf("Starting Chameleon ...\n");␊ |
404 | #endif␊ |
405 | ␉␊ |
406 | ␉initBooterLog();␊ |
407 | ␉␊ |
408 | ␉// Initialize boot info structure.␊ |
409 | initKernBootStruct();␊ |
410 | ␉␊ |
411 | ␉␊ |
412 | // Scan and record the system's hardware information.␊ |
413 | scan_platform();␊ |
414 | ␉␊ |
415 | // First get info for boot volume.␊ |
416 | scanBootVolumes(gBIOSDev, 0);␊ |
417 | bvChain = getBVChainForBIOSDev(gBIOSDev);␊ |
418 | setBootGlobals(bvChain);␊ |
419 | ␉␊ |
420 | // Load boot.plist config file␊ |
421 | status = loadSystemConfig(&bootInfo->bootConfig);␊ |
422 | ␉␊ |
423 | ␉Platform->CPU.isServer = false; ␊ |
424 | getBoolForKey(kIsServer, &Platform->CPU.isServer, &bootInfo->bootConfig); // set this as soon as possible␊ |
425 | ␉␊ |
426 | ␉{␊ |
427 | ␉␉bool quiet = false;␊ |
428 | ␉␉if (getBoolForKey(kQuietBootKey, &quiet, &bootInfo->bootConfig) && quiet)␊ |
429 | ␉␉{␊ |
430 | ␉␉␉gBootMode |= kBootModeQuiet;␊ |
431 | ␉␉}␊ |
432 | ␉}␉␊ |
433 | ␉␊ |
434 | ␉{␊ |
435 | ␉␉bool instantMenu = false;␊ |
436 | ␉␉// Override firstRun to get to the boot menu instantly by setting "Instant Menu"=y in system config␊ |
437 | ␉␉if (getBoolForKey(kInsantMenuKey, &instantMenu, &bootInfo->bootConfig) && instantMenu)␊ |
438 | ␉␉{␊ |
439 | ␉␉␉firstRun = false;␊ |
440 | ␉␉}␊ |
441 | ␉}␉␊ |
442 | ␉␊ |
443 | #ifndef OPTION_ROM␊ |
444 | ␉// Enable touching a single BIOS device only if "Scan Single Drive"=y is set in system config.␊ |
445 | if (getBoolForKey(kScanSingleDriveKey, &gScanSingleDrive, &bootInfo->bootConfig) && gScanSingleDrive)␊ |
446 | ␉{␊ |
447 | gScanSingleDrive = true;␊ |
448 | }␊ |
449 | ␉␊ |
450 | ␉// Create a list of partitions on device(s).␊ |
451 | if (gScanSingleDrive)␊ |
452 | ␉{␊ |
453 | ␉␉scanBootVolumes(gBIOSDev, &bvCount);␊ |
454 | } ␊ |
455 | ␉else ␊ |
456 | #endif␊ |
457 | ␉{␊ |
458 | #if UNUSED␊ |
459 | scanDisks(gBIOSDev, &bvCount);␊ |
460 | #else␊ |
461 | scanDisks();␊ |
462 | #endif␊ |
463 | }␊ |
464 | ␉␊ |
465 | ␉// Create a separated bvr chain using the specified filters.␊ |
466 | bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);␊ |
467 | ␉gBootVolume = selectBootVolume(bvChain);␊ |
468 | ␉␊ |
469 | ␉{␊ |
470 | ␉␉// Intialize module system␊ |
471 | ␉␉EFI_STATUS sysinit = init_module_system();␊ |
472 | ␉␉if((sysinit == EFI_SUCCESS) || (sysinit == EFI_ALREADY_STARTED) /*should never happen*/ ) ␊ |
473 | ␉␉{␊ |
474 | ␉␉␉load_all_modules();␊ |
475 | ␉␉}␊ |
476 | ␉}␉␊ |
477 | ␉␉␉␊ |
478 | // Loading preboot ramdisk if exists.␊ |
479 | ␉execute_hook("loadPrebootRAMDisk", NULL, NULL, NULL, NULL, NULL, NULL);␉␉␊ |
480 | ␊ |
481 | #ifndef OPTION_ROM␊ |
482 | ␊ |
483 | // Disable rescan option by default␊ |
484 | gEnableCDROMRescan = false;␊ |
485 | ␉␊ |
486 | // Enable it with Rescan=y in system config␊ |
487 | if (getBoolForKey(kRescanKey, &gEnableCDROMRescan, &bootInfo->bootConfig) && gEnableCDROMRescan)␊ |
488 | ␉{␊ |
489 | gEnableCDROMRescan = true;␊ |
490 | }␊ |
491 | ␉␊ |
492 | ␉{␊ |
493 | ␉␉bool rescanPrompt = false;␊ |
494 | ␉␉// Ask the user for Rescan option by setting "Rescan Prompt"=y in system config.␊ |
495 | ␉␉if (getBoolForKey(kRescanPromptKey, &rescanPrompt , &bootInfo->bootConfig) && rescanPrompt && biosDevIsCDROM(gBIOSDev))␊ |
496 | ␉␉{␊ |
497 | ␉␉␉gEnableCDROMRescan = promptForRescanOption();␊ |
498 | ␉␉}␊ |
499 | ␉}␊ |
500 | ␊ |
501 | #endif␉␊ |
502 | ␉␊ |
503 | #if DEBUG␊ |
504 | printf(" Default: %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n", gBootVolume, gBootVolume->biosdev, gBootVolume->part_no, gBootVolume->flags);␊ |
505 | printf(" bt(0,0): %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n", gBIOSBootVolume, gBIOSBootVolume->biosdev, gBIOSBootVolume->part_no, gBIOSBootVolume->flags);␊ |
506 | getc();␊ |
507 | #endif␊ |
508 | ␉␉␉␊ |
509 | setBootGlobals(bvChain);␊ |
510 | ␉␊ |
511 | ␉// Display the GUI␊ |
512 | ␉execute_hook("GUI_Display", NULL, NULL, NULL, NULL, NULL, NULL);␊ |
513 | ␊ |
514 | // Parse args, load and start kernel.␊ |
515 | while (1) {␊ |
516 | const char *val;␊ |
517 | int len;␊ |
518 | ␉␉char *bootFile;␊ |
519 | ␉␉bool trycache = true; // Always try to catch the kernelcache first␊ |
520 | ␉␉␊ |
521 | long flags;␊ |
522 | #ifdef BOOT_HELPER_SUPPORT␉␉␊ |
523 | ␉␉long time;␊ |
524 | #endif␊ |
525 | int ret = -1;␊ |
526 | void *binary = (void *)kLoadAddr;␊ |
527 | ␉␉␊ |
528 | // additional variable for testing alternate kernel image locations on boot helper partitions.␊ |
529 | char bootFileSpec[512];␊ |
530 | ␉␉␊ |
531 | // Initialize globals.␊ |
532 | ␉␉␊ |
533 | sysConfigValid = false;␊ |
534 | gErrors = false;␊ |
535 | ␉␉␊ |
536 | status = getBootOptions(firstRun);␊ |
537 | firstRun = false;␊ |
538 | if (status == -1) continue;␊ |
539 | ␉␉␊ |
540 | status = processBootOptions();␊ |
541 | // Status==1 means to chainboot␊ |
542 | if ( status == 1 ) break;␊ |
543 | // Status==-1 means that the config file couldn't be loaded or that gBootVolume is NULL␊ |
544 | if ( status == -1 )␊ |
545 | {␊ |
546 | ␉␉␉// gBootVolume == NULL usually means the user hit escape.␊ |
547 | ␉␉␉if(gBootVolume == NULL)␊ |
548 | ␉␉␉{␊ |
549 | ␉␉␉␉freeFilteredBVChain(bvChain);␊ |
550 | #ifndef OPTION_ROM␊ |
551 | ␉␉␉␉if (gEnableCDROMRescan)␊ |
552 | ␉␉␉␉␉rescanBIOSDevice(gBIOSDev);␊ |
553 | #endif␊ |
554 | ␉␉␉␉␊ |
555 | ␉␉␉␉bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);␊ |
556 | ␉␉␉␉setBootGlobals(bvChain);␊ |
557 | ␉␉␉}␊ |
558 | ␉␉␉continue;␊ |
559 | }␊ |
560 | ␉␉␉␉␉␉␊ |
561 | // Other status (e.g. 0) means that we should proceed with boot.␊ |
562 | ␉␉execute_hook("GUI_PreBoot", NULL, NULL, NULL, NULL, NULL, NULL);␊ |
563 | ␉␉␊ |
564 | ␉␉// Find out which version mac os we're booting.␊ |
565 | ␉␉getOSVersion(gMacOSVersion);␊ |
566 | ␉␉␊ |
567 | ␉␉if (getValueForKey(karch, &val, &len, &bootInfo->bootConfig) && val)␊ |
568 | ␉␉{␊ |
569 | ␉␉␉if (strncmp(val, "x86_64", 4) == 0)␊ |
570 | ␉␉␉{␊ |
571 | ␉␉␉␉archCpuType = CPU_TYPE_X86_64;␊ |
572 | ␉␉␉} ␊ |
573 | ␉␉␉else if (strncmp(val, "i386", 4) == 0)␊ |
574 | ␉␉␉{␊ |
575 | ␉␉␉␉archCpuType = CPU_TYPE_I386;␊ |
576 | ␉␉␉}␊ |
577 | ␉␉␉else ␊ |
578 | ␉␉␉{␊ |
579 | ␉␉␉␉DBG("Incorrect parameter for option 'arch =' , please use x86_64 or i386\n")␊ |
580 | ␉␉␉␉determineCpuArch();␊ |
581 | ␉␉␉}␊ |
582 | ␊ |
583 | ␉␉}␊ |
584 | ␉␉else determineCpuArch();␊ |
585 | ␊ |
586 | ␊ |
587 | ␉␉getRootDevice();␊ |
588 | ␊ |
589 | ␉␉// Notify to all modules that we are attempting to boot␊ |
590 | ␉␉execute_hook("PreBoot", NULL, NULL, NULL, NULL, NULL, NULL); ␊ |
591 | ␉␉␊ |
592 | ␉␉if (execute_hook("getProductNamePatched", NULL, NULL, NULL, NULL, NULL, NULL) != EFI_SUCCESS)␉␉␉␉␉␊ |
593 | ␉␉␉readSMBIOS(thePlatformName); // read smbios Platform Name␊ |
594 | ␉␉␊ |
595 | ␉␉␊ |
596 | ␉␉if (((gBootMode & kBootModeSafe) == 0) &&␊ |
597 | ␉␉␉!gOverrideKernel &&␊ |
598 | ␉␉␉(gBootFileType == kBlockDeviceType) &&␊ |
599 | ␉␉␉(gMKextName[0] == '\0') && ␊ |
600 | ␉␉␉!getValueForBootKey(bootArgs->CommandLine, kIgnorePrelinkKern, &val, &len))␊ |
601 | ␉␉{ ␉␉␊ |
602 | ␉␉␉getBoolForKey(kUseKernelCache, &trycache, &bootInfo->bootConfig);␊ |
603 | ␉␉␉if (trycache == true)␊ |
604 | ␉␉␉{␊ |
605 | ␉␉␉␉// try to find the cache and fill the gBootKernelCacheFile string␊ |
606 | ␉␉␉␉getKernelCachePath();␊ |
607 | ␉␉␉␉␊ |
608 | ␉␉␉␉// Check for cache file␊ |
609 | ␉␉␉␉trycache = (gBootKernelCacheFile[0] != '\0') ? true : false; // if gBootKernelCacheFile is filled et bla bla bla.... :-)␊ |
610 | ␉␉␉}␊ |
611 | ␉␉␉␊ |
612 | ␉␉}␊ |
613 | ␉␉else ␊ |
614 | ␉␉{␊ |
615 | ␉␉␉trycache = false;␊ |
616 | ␉␉}␊ |
617 | ␉␉␉␉␉␉␊ |
618 | ␉␉verbose("Loading Darwin %s\n", gMacOSVersion);␊ |
619 | ␉␉{␊ |
620 | ␉␉␉long cachetime, kerneltime, exttime;␊ |
621 | ␉␉␉if (trycache ) do {␊ |
622 | ␉␉␉␉␊ |
623 | ␉␉␉␉// if we haven't found the kernel yet, don't use the cache␊ |
624 | ␉␉␉␉ret = GetFileInfo(NULL, bootInfo->bootFile, &flags, &kerneltime);␊ |
625 | ␉␉␉␉if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
626 | ␉␉␉␉{␊ |
627 | ␉␉␉␉␉trycache = 0;␊ |
628 | ␉␉␉␉␉bootInfo->adler32 = 0;␊ |
629 | ␉␉␉␉␉DBG("No kernel found, kernelcache disabled !!!\n");␊ |
630 | ␉␉␉␉␉break;␊ |
631 | ␉␉␉␉}␊ |
632 | ␉␉␉␉ret = GetFileInfo(NULL, gBootKernelCacheFile, &flags, &cachetime);␊ |
633 | ␉␉␉␉if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
634 | ␉␉␉␉␉|| (cachetime < kerneltime))␊ |
635 | ␉␉␉␉{␊ |
636 | ␉␉␉␉␉trycache = 0;␊ |
637 | ␉␉␉␉␉bootInfo->adler32 = 0;␊ |
638 | ␉␉␉␉␉DBG("Warning: kernelcache too old, timestamp of the kernel > timestamp of the cache, kernelcache disabled !!!\n");␊ |
639 | ␊ |
640 | ␉␉␉␉␉break;␉␉␉␉ ␊ |
641 | ␉␉␉␉} ␊ |
642 | ␉␉␉␉ret = GetFileInfo("/System/Library/", "Extensions", &flags, &exttime);␊ |
643 | ␉␉␉␉if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)␊ |
644 | ␉␉␉␉␉&& (cachetime < exttime))␊ |
645 | ␉␉␉␉{␊ |
646 | ␉␉␉␉␉trycache = 0;␊ |
647 | ␉␉␉␉␉bootInfo->adler32 = 0;␊ |
648 | ␉␉␉␉␉DBG("Warning: kernelcache too old, timestamp of S/L/E > timestamp of the cache, kernelcache disabled !!! \n");␊ |
649 | ␊ |
650 | ␉␉␉␉␉break;␊ |
651 | ␉␉␉␉}␊ |
652 | ␉␉␉␉if (kerneltime > exttime)␊ |
653 | ␉␉␉␉{␊ |
654 | ␉␉␉␉␉exttime = kerneltime;␊ |
655 | ␉␉␉␉}␊ |
656 | ␉␉␉␉if (cachetime != (exttime + 1))␊ |
657 | ␉␉␉␉{␊ |
658 | ␉␉␉␉␉trycache = 0;␊ |
659 | ␉␉␉␉␉bootInfo->adler32 = 0;␊ |
660 | ␉␉␉␉␉DBG("Warning: invalid timestamp, kernelcache disabled !!!\n");␊ |
661 | ␊ |
662 | ␉␉␉␉␉break;␊ |
663 | ␉␉␉␉}␊ |
664 | ␉␉␉} while (0);␊ |
665 | ␉␉}␉␉␊ |
666 | ␊ |
667 | do {␊ |
668 | if (trycache)␊ |
669 | ␉␉␉{␊ |
670 | bootFile = gBootKernelCacheFile;␊ |
671 | verbose("Loading kernel cache %s\n", bootFile);␊ |
672 | ␉␉␉␉if (gMacOSVersion[3] == '7')␊ |
673 | ␉␉␉␉{␉␉␉␉␉␊ |
674 | ␉␉␉␉␉ret = LoadThinFatFile(bootFile, &binary);␊ |
675 | ␉␉␉␉␉if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)␊ |
676 | ␉␉␉␉␉{␊ |
677 | ␉␉␉␉␉␉archCpuType = CPU_TYPE_I386;␊ |
678 | ␉␉␉␉␉␉ret = LoadThinFatFile(bootFile, &binary);␉␉␉␉␊ |
679 | ␉␉␉␉␉}␊ |
680 | ␉␉␉␉}␊ |
681 | ␉␉␉␉else␊ |
682 | ␉␉␉␉{␊ |
683 | ␉␉␉␉␉ret = LoadFile(bootFile);␊ |
684 | ␉␉␉␉␉binary = (void *)kLoadAddr;␊ |
685 | ␉␉␉␉}␊ |
686 | ␉␉␉␉␊ |
687 | if (ret >= 0)␊ |
688 | ␉␉␉␉{␊ |
689 | break;␊ |
690 | }␊ |
691 | ␉␉␉␉␊ |
692 | }␊ |
693 | ␉␉␉bootInfo->adler32 = 0;␊ |
694 | bootFile = bootInfo->bootFile;␊ |
695 | #ifdef BOOT_HELPER_SUPPORT␊ |
696 | ␉␉␉␊ |
697 | // Try to load kernel image from alternate locations on boot helper partitions.␊ |
698 | sprintf(bootFileSpec, "com.apple.boot.P/%s", bootFile);␊ |
699 | ret = GetFileInfo(NULL, bootFileSpec, &flags, &time); ␊ |
700 | ␉ ␉ if (ret == -1)␊ |
701 | ␉ ␉ {␊ |
702 | ␉␉␉␉sprintf(bootFileSpec, "com.apple.boot.R/%s", bootFile);␊ |
703 | ␉␉␉␉ret = GetFileInfo(NULL, bootFileSpec, &flags, &time); ␊ |
704 | ␉␉␉␉if (ret == -1)␊ |
705 | ␉␉␉␉{␊ |
706 | ␉␉␉␉␉sprintf(bootFileSpec, "com.apple.boot.S/%s", bootFile);␊ |
707 | ␉␉␉␉␉ret = GetFileInfo(NULL, bootFileSpec, &flags, &time); ␊ |
708 | ␉␉␉␉␉if (ret == -1)␊ |
709 | ␉␉␉␉␉{␊ |
710 | ␉␉␉␉␉␉// Not found any alternate locations, using the original kernel image path.␊ |
711 | ␉␉␉␉␉␉strlcpy(bootFileSpec, bootFile,sizeof(bootFileSpec)+1);␊ |
712 | ␉␉␉␉␉}␊ |
713 | ␉␉␉␉}␊ |
714 | }␊ |
715 | #else␊ |
716 | ␉␉␉strlcpy(bootFileSpec, bootFile,sizeof(bootFileSpec)+1);␊ |
717 | #endif␊ |
718 | ␉␉␉␊ |
719 | verbose("Loading kernel %s\n", bootFileSpec);␊ |
720 | ret = LoadThinFatFile(bootFileSpec, &binary);␊ |
721 | if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)␊ |
722 | {␊ |
723 | ␉␉␉␉archCpuType = CPU_TYPE_I386;␊ |
724 | ␉␉␉␉ret = LoadThinFatFile(bootFileSpec, &binary);␉␉␉␉␊ |
725 | }␊ |
726 | ␉␉␉␊ |
727 | } while (0);␊ |
728 | #if TEXT_SPINNER␊ |
729 | clearActivityIndicator();␊ |
730 | #endif␊ |
731 | ␉␉␊ |
732 | #if DEBUG␊ |
733 | printf("Pausing...");␊ |
734 | sleep(8);␊ |
735 | #endif␊ |
736 | ␉␉␊ |
737 | if (ret <= 0)␊ |
738 | ␉␉{␊ |
739 | ␉␉␉printf("Can't find %s\n", bootFile);␊ |
740 | ␉␉␉␊ |
741 | ␉␉␉sleep(1);␊ |
742 | #ifdef NBP_SUPPORT␊ |
743 | if (gBootFileType == kNetworkDeviceType)␊ |
744 | ␉␉␉{␊ |
745 | // Return control back to PXE. Don't unload PXE base code.␊ |
746 | gUnloadPXEOnExit = false;␊ |
747 | break;␊ |
748 | }␊ |
749 | #endif␊ |
750 | }␊ |
751 | ␉␉else␊ |
752 | ␉␉{␊ |
753 | /* Won't return if successful. */␊ |
754 | ret = ExecKernel(binary);␊ |
755 | }␊ |
756 | }␊ |
757 | ␊ |
758 | // chainboot␊ |
759 | if (status==1)␊ |
760 | ␉{␊ |
761 | ␉␉if (getVideoMode() == GRAPHICS_MODE)␊ |
762 | ␉␉{␉// if we are already in graphics-mode,␊ |
763 | #if UNUSED␊ |
764 | ␉␉␉setVideoMode(VGA_TEXT_MODE, 0);␉// switch back to text mode␊ |
765 | #else␊ |
766 | ␉␉␉setVideoMode(VGA_TEXT_MODE);␉// switch back to text mode␊ |
767 | #endif␊ |
768 | ␉␉}␊ |
769 | }␊ |
770 | #ifdef NBP_SUPPORT␊ |
771 | if ((gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit)␊ |
772 | ␉{␊ |
773 | ␉␉nbpUnloadBaseCode();␊ |
774 | }␊ |
775 | #endif␊ |
776 | }␊ |
777 | ␊ |
778 | static void determineCpuArch(void)␊ |
779 | {␊ |
780 | ␉if (cpu_mode_is64bit())␊ |
781 | ␉{␊ |
782 | ␉␉archCpuType = CPU_TYPE_X86_64;␊ |
783 | ␉}␊ |
784 | ␉else␊ |
785 | ␉{␊ |
786 | ␉␉archCpuType = CPU_TYPE_I386;␊ |
787 | ␉}␊ |
788 | }␊ |
789 | ␊ |
790 | void getKernelCachePath()␊ |
791 | {␊ |
792 | ␉{␊ |
793 | ␉␉// If there is an extra kext/mkext, we return immediatly and we skip the kernelCache ␊ |
794 | ␉␉// since kexts/mkexts are not loaded properly when the kernelCache is used.␊ |
795 | ␉␉// Another method would be to re-build the kernelCache one the fly␊ |
796 | ␉␉if (found_extra_kext() == true) return; ␊ |
797 | ␉}␊ |
798 | ␉␊ |
799 | ␉{␊ |
800 | ␉␉const char *val;␊ |
801 | ␉␉int len;␊ |
802 | ␉␉␊ |
803 | ␉␉if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig))␊ |
804 | ␉␉{␊ |
805 | char * buffer = newString(val);␊ |
806 | ␊ |
807 | ␉␉␉if (val[0] == '\\')␊ |
808 | ␉␉␉{␊ |
809 | ␉␉␉␉// Flip the back slash's to slash's .␊ |
810 | len = 0;␊ |
811 | while (buffer[len] != '\0') {␊ |
812 | if (buffer[len] == '\\')␊ |
813 | {␊ |
814 | buffer[len] = '/'; ␊ |
815 | }␊ |
816 | len++;␊ |
817 | }␊ |
818 | ␉␉␉} ␊ |
819 | ␉␉␉strlcpy(gBootKernelCacheFile, buffer, sizeof(gBootKernelCacheFile)+1);␊ |
820 | ␉␉}␊ |
821 | ␉␉else␊ |
822 | ␉␉{␊ |
823 | ␉␉␉if(gMacOSVersion[3] == '7')␊ |
824 | ␉␉␉{␉␉␉␉␉␊ |
825 | ␉␉␉␉sprintf(gBootKernelCacheFile, "%s", kDefaultCachePath);␊ |
826 | ␉␉␉}␊ |
827 | ␉␉␉else if(gMacOSVersion[3] <= '6')␊ |
828 | ␉␉␉{␉␉␉ ␊ |
829 | ␉␉␉␉␊ |
830 | ␉␉␉␉PlatformInfo *platformInfo = malloc(sizeof(PlatformInfo));␊ |
831 | ␉␉␉␉if (platformInfo)␊ |
832 | ␉␉␉␉{␊ |
833 | ␉␉␉␉␉␊ |
834 | ␉␉␉␉␉bzero(platformInfo, sizeof(PlatformInfo));␊ |
835 | ␉␉␉␉␉␊ |
836 | ␉␉␉␉␉if (gPlatformName)␊ |
837 | ␉␉␉␉␉␉strlcpy(platformInfo->platformName,gPlatformName, sizeof(platformInfo->platformName)+1);␊ |
838 | ␉␉␉␉␉␊ |
839 | ␉␉␉␉␉if (gRootDevice)␊ |
840 | ␉␉␉␉␉{␊ |
841 | ␉␉␉␉␉␉char *rootPath_p = platformInfo->rootPath;␊ |
842 | ␉␉␉␉␉␉len = strlen(gRootDevice) + 1;␊ |
843 | ␉␉␉␉␉␉if ((unsigned)len > sizeof(platformInfo->rootPath))␊ |
844 | ␉␉␉␉␉␉{␊ |
845 | ␉␉␉␉␉␉␉len = sizeof(platformInfo->rootPath);␊ |
846 | ␉␉␉␉␉␉}␊ |
847 | ␉␉␉␉␉␉memcpy(rootPath_p, gRootDevice,len);␊ |
848 | ␉␉␉␉␉␉␊ |
849 | ␉␉␉␉␉␉rootPath_p += len;␊ |
850 | ␉␉␉␉␉␉␊ |
851 | ␉␉␉␉␉␉len = strlen(bootInfo->bootFile);␊ |
852 | ␉␉␉␉␉␉␊ |
853 | ␉␉␉␉␉␉if ((unsigned)(rootPath_p - platformInfo->rootPath + len) >=␊ |
854 | ␉␉␉␉␉␉␉sizeof(platformInfo->rootPath))␊ |
855 | ␉␉␉␉␉␉{␊ |
856 | ␉␉␉␉␉␉␉␊ |
857 | ␉␉␉␉␉␉␉len = sizeof(platformInfo->rootPath) -␊ |
858 | ␉␉␉␉␉␉␉(rootPath_p - platformInfo->rootPath);␊ |
859 | ␉␉␉␉␉␉} ␊ |
860 | ␉␉␉␉␉␉memcpy(rootPath_p, bootInfo->bootFile, len);␉␉␉␉␉␉␉␊ |
861 | ␉␉␉␉␉␉␊ |
862 | ␉␉␉␉␉}␉␊ |
863 | ␉␉␉␉␉␊ |
864 | ␉␉␉␉␉if (!platformInfo->platformName[0] || !platformInfo->rootPath[0])␊ |
865 | ␉␉␉␉␉{␊ |
866 | ␉␉␉␉␉␉platformInfo->platformName[0] = platformInfo->rootPath[0] = 0;␊ |
867 | ␉␉␉␉␉}␊ |
868 | ␉␉␉␉␉//memcpy(gRootPath,platformInfo->rootPath, sizeof(gRootPath));␊ |
869 | ␉␉␉␉␉␊ |
870 | ␉␉␉␉␉␊ |
871 | ␉␉␉␉␉bootInfo->adler32 = OSSwapHostToBigInt32(adler32((unsigned char *)platformInfo, sizeof(*platformInfo)));␊ |
872 | ␉␉␉␉␉␊ |
873 | ␉␉␉␉␉free(platformInfo);␉␊ |
874 | ␉␉␉␉}␊ |
875 | ␉␉␉␉␊ |
876 | ␉␉␉␉DBG("Adler32: %08lX\n",bootInfo->adler32);␊ |
877 | ␉␉␉␉␊ |
878 | ␉␉␉␉if (gMacOSVersion[3] < '6')␊ |
879 | ␉␉␉␉{␊ |
880 | ␉␉␉␉␉long flags, cachetime;␊ |
881 | ␉␉␉␉␉int ret = -1;␊ |
882 | ␉␉␉␉␉sprintf(gBootKernelCacheFile, "%s.%08lX", "/System/Library/Caches/com.apple.kernelcaches/kernelcache",bootInfo->adler32);␊ |
883 | ␉␉␉␉␉ret = GetFileInfo(NULL, gBootKernelCacheFile, &flags, &cachetime);␊ |
884 | ␉␉␉␉␉if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
885 | ␉␉␉␉␉{␊ |
886 | ␉␉␉␉␉␉bootInfo->adler32 = 0;␊ |
887 | ␉␉␉␉␉␉sprintf(gBootKernelCacheFile, "%s", "/System/Library/Caches/com.apple.kernelcaches/kernelcache"); ␊ |
888 | ␉␉␉␉␉}␊ |
889 | ␉␉␉␉␉␊ |
890 | ␉␉␉␉} else␊ |
891 | ␉␉␉␉␉sprintf(gBootKernelCacheFile, "%s_%s.%08lX", kDefaultCachePath, (archCpuType == CPU_TYPE_I386) ? "i386" : "x86_64", bootInfo->adler32); //Snow Leopard␊ |
892 | ␉␉␉␉␊ |
893 | ␉␉␉}␉␊ |
894 | ␉␉}␊ |
895 | ␉}␉␊ |
896 | }␊ |
897 | ␊ |
898 | ␊ |
899 | static void getRootDevice()␊ |
900 | {␊ |
901 | ␉// Maximum config table value size␊ |
902 | #define VALUE_SIZE 2048␊ |
903 | ␉bool uuidSet = false;␊ |
904 | ␉const char *val = 0;␊ |
905 | int cnt = 0;␊ |
906 | ␉␊ |
907 | ␉if (getValueForKey(kBootUUIDKey, &val, &cnt, &bootInfo->bootConfig))␊ |
908 | ␉{␊ |
909 | ␉␉uuidSet = true;␉␉␊ |
910 | ␉}␊ |
911 | ␉else␊ |
912 | ␉{␊ |
913 | ␉␉if (getValueForBootKey(bootArgs->CommandLine, kRootDeviceKey, &val, &cnt))␊ |
914 | ␉␉{␊ |
915 | ␉␉␉if (*val == '*' && *(val + 1) != '/' && *(val + 1) != 'u')␊ |
916 | ␉␉␉{ ␊ |
917 | ␉␉␉␉val += 1; //skip the *␊ |
918 | ␉␉␉␉uuidSet = true;␉␉␉␉␊ |
919 | ␉␉␉␉␊ |
920 | ␉␉␉}␊ |
921 | ␉␉␉else if (*val == '*' && *(val + 1) == 'u')␊ |
922 | ␉␉␉{␊ |
923 | ␉␉␉␉␊ |
924 | ␉␉␉␉if ( getValueForKey( kBootDeviceKey, &val, &cnt, &bootInfo->bootConfig)) ␊ |
925 | ␉␉␉␉␉uuidSet = true;␉␉␉␉␊ |
926 | ␉␉␉␉␊ |
927 | ␉␉␉} ␉␉␉␊ |
928 | ␉␉}␊ |
929 | ␉␉else␊ |
930 | ␉␉{␊ |
931 | #ifdef BOOT_HELPER_SUPPORT␊ |
932 | ␉␉␉//␊ |
933 | ␉␉␉// Try an alternate method for getting the root UUID on boot helper partitions.␊ |
934 | ␉␉␉//␊ |
935 | ␉␉␉if (gBootVolume->flags & kBVFlagBooter)␊ |
936 | ␉␉␉{␊ |
937 | ␉␉␉␉if((loadHelperConfig(&bootInfo->helperConfig) == 0)␊ |
938 | ␉␉␉␉ && getValueForKey(kHelperRootUUIDKey, &val, &cnt, &bootInfo->helperConfig) )␊ |
939 | ␉␉␉␉{␊ |
940 | ␉␉␉␉␉getValueForKey(kHelperRootUUIDKey, &val, &cnt, &bootInfo->helperConfig);␊ |
941 | ␉␉␉␉␉uuidSet = true;␊ |
942 | ␉␉␉␉␉goto out;␊ |
943 | ␉␉␉␉}␊ |
944 | ␉␉␉}␊ |
945 | #endif␉␉␉␊ |
946 | ␉␉␉if ( getValueForKey( kBootDeviceKey, &val, &cnt, &bootInfo->bootConfig))␊ |
947 | ␉␉␉{␊ |
948 | ␉␉␉␉extern int ArgCntRemaining;␊ |
949 | ␉␉␉␉uuidSet = false;␊ |
950 | ␉␉␉␉char * valueBuffer;␊ |
951 | ␉␉␉␉valueBuffer = malloc(VALUE_SIZE);␊ |
952 | ␉␉␉␉char * argP = bootArgs->CommandLine;␊ |
953 | ␉␉␉␉valueBuffer[0] = '*';␊ |
954 | ␉␉␉␉if (cnt > VALUE_SIZE)␊ |
955 | ␉␉␉␉{␊ |
956 | ␉␉␉␉␉cnt = VALUE_SIZE;␊ |
957 | ␉␉␉␉}␊ |
958 | ␉␉␉␉cnt++;␊ |
959 | ␉␉␉␉strlcpy(valueBuffer + 1, val, cnt);␉␉␉␉␊ |
960 | ␉␉␉␉if (!copyArgument( kRootDeviceKey, valueBuffer, cnt, &argP, &ArgCntRemaining))␊ |
961 | ␉␉␉␉{␊ |
962 | ␉␉␉␉␉free(valueBuffer);␊ |
963 | ␉␉␉␉␉printf("Error: boot arguments too long, unable to set root device !!");␊ |
964 | ␉␉␉␉␉getc();␊ |
965 | ␉␉␉␉␉return;␊ |
966 | ␉␉␉␉}␊ |
967 | ␉␉␉␉free(valueBuffer);␊ |
968 | ␉␉␉␉goto out;␊ |
969 | ␉␉␉}␊ |
970 | ␉␉␉␊ |
971 | ␉␉␉if (gBootVolume->fs_getuuid && gBootVolume->fs_getuuid (gBootVolume, bootInfo->uuidStr) == 0)␊ |
972 | ␉␉␉{␊ |
973 | ␉␉␉␉verbose("Setting boot-uuid to: %s\n", bootInfo->uuidStr);␊ |
974 | ␉␉␉␉uuidSet = true;␊ |
975 | ␉␉␉␉gRootDevice = bootInfo->uuidStr;␊ |
976 | ␉␉␉␉return;␊ |
977 | ␉␉␉}␊ |
978 | ␉␉␊ |
979 | ␉␉}␉␊ |
980 | ␉}␊ |
981 | ␉␉␊ |
982 | out:␉␊ |
983 | ␉verbose("Setting %s to: %s\n", uuidSet ? kBootUUIDKey : "root device", (char* )val); ␊ |
984 | ␉gRootDevice = (char* )val;␊ |
985 | }␊ |
986 | ␊ |
987 | static bool getOSVersion(char *str)␊ |
988 | {␊ |
989 | ␉bool valid = false;␉␊ |
990 | ␉config_file_t systemVersion;␊ |
991 | ␉␊ |
992 | ␉if (!loadConfigFile("System/Library/CoreServices/SystemVersion.plist", &systemVersion))␊ |
993 | ␉{␊ |
994 | ␉␉valid = true;␊ |
995 | ␉}␊ |
996 | ␉else if (!loadConfigFile("System/Library/CoreServices/ServerVersion.plist", &systemVersion))␊ |
997 | ␉{␊ |
998 | ␉␉valid = true;␊ |
999 | ␉}␊ |
1000 | ␉␊ |
1001 | ␉if (valid)␊ |
1002 | ␉{␉␉␊ |
1003 | ␉␉const char *val;␊ |
1004 | ␉␉int len;␊ |
1005 | ␉␉␊ |
1006 | ␉␉if (getValueForKey(kProductVersion, &val, &len, &systemVersion))␊ |
1007 | ␉␉{␊ |
1008 | ␉␉␉// getValueForKey uses const char for val␊ |
1009 | ␉␉␉// so copy it and trim␊ |
1010 | ␉␉␉*str = '\0';␊ |
1011 | ␉␉␉strncat(str, val, MIN(len, 4));␊ |
1012 | ␉␉}␊ |
1013 | ␉␉else␊ |
1014 | ␉␉␉valid = false;␊ |
1015 | ␉}␊ |
1016 | ␉␊ |
1017 | ␉return valid;␊ |
1018 | }␊ |
1019 | ␊ |
1020 | static bool find_file_with_ext(const char* dir, const char *ext, const char * name_compare, size_t ext_size)␊ |
1021 | {␊ |
1022 | ␉char* name;␊ |
1023 | ␉long flags;␊ |
1024 | ␉long time;␊ |
1025 | ␉struct dirstuff* moduleDir = opendir(dir);␊ |
1026 | ␉while(readdir(moduleDir, (const char**)&name, &flags, &time) >= 0)␊ |
1027 | ␉{␉␉␊ |
1028 | ␉␉int len = strlen(name);␊ |
1029 | ␉␉␊ |
1030 | ␉␉if (len >= ext_size)␊ |
1031 | ␉␉{␊ |
1032 | ␉␉␉if(strcmp(&name[len - ext_size], ext) == 0)␊ |
1033 | ␉␉␉{␉␊ |
1034 | ␉␉␉␉if (name_compare)␊ |
1035 | ␉␉␉␉{␊ |
1036 | ␉␉␉␉␉if (strcmp(name, name_compare) == 0)␊ |
1037 | ␉␉␉␉␉{␊ |
1038 | ␉␉␉␉␉␉DBG("found : %s\n", name);␉␊ |
1039 | ␉␉␉␉␉␉return true;␊ |
1040 | ␉␉␉␉␉}␊ |
1041 | ␉␉␉␉}␊ |
1042 | ␉␉␉␉else␊ |
1043 | ␉␉␉␉{␊ |
1044 | ␉␉␉␉␉DBG("found : %s\n", name);␉␊ |
1045 | ␉␉␉␉␉return true;␊ |
1046 | ␉␉␉␉}␉␉␉␊ |
1047 | ␉␉␉}␊ |
1048 | #if DEBUG_BOOT␊ |
1049 | ␉␉␉else ␊ |
1050 | ␉␉␉{␊ |
1051 | ␉␉␉␉DBG("Ignoring %s\n", name);␊ |
1052 | ␉␉␉}␊ |
1053 | #endif␊ |
1054 | ␉␉}␉␉␊ |
1055 | #if DEBUG_BOOT␊ |
1056 | ␉␉else ␊ |
1057 | ␉␉{␊ |
1058 | ␉␉␉DBG("Ignoring %s\n", name);␊ |
1059 | ␉␉}␊ |
1060 | #endif␉␉␊ |
1061 | ␉}␊ |
1062 | ␉␊ |
1063 | ␉return false;␊ |
1064 | }␊ |
1065 | ␊ |
1066 | // If a kext is found in /Extra/Extentions return true␊ |
1067 | // If a mkext is found in /Extra return true␊ |
1068 | // Otherwise return false␊ |
1069 | // Tips (if you still use extra kext(s)/mkext(s) ): With Lion it's recommended to create a system mkext (see the kextcache commandline) to decrease boot time,␊ |
1070 | // otherwise it will act like a -f each time a extra kext/kext is detected␊ |
1071 | static bool found_extra_kext(void) ␊ |
1072 | {␉␊ |
1073 | #define EXTENSIONS "Extensions"␊ |
1074 | #define MKEXT_EXT ".mkext"␉␊ |
1075 | #define MKEXT_EXT_SIZE sizeof("mkext")␊ |
1076 | #define KEXT_EXT ".kext"␉␊ |
1077 | #define KEXT_EXT_SIZE sizeof("kext")␊ |
1078 | ␉␊ |
1079 | ␉long flags;␊ |
1080 | ␉long exttime;␊ |
1081 | ␉int ret = -1;␊ |
1082 | ␉␊ |
1083 | ␉ret = GetFileInfo("rd(0,0)/Extra/", EXTENSIONS, &flags, &exttime);␊ |
1084 | ␉if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeFlat))␊ |
1085 | ␉{␉␉␉␊ |
1086 | ␉␉if (((flags & kFileTypeMask) == kFileTypeFlat))␊ |
1087 | ␉␉{␊ |
1088 | ␉␉␉if (find_file_with_ext("rd(0,0)/Extra/", MKEXT_EXT, EXTENSIONS, MKEXT_EXT_SIZE))␊ |
1089 | ␉␉␉{␊ |
1090 | ␉␉␉␉return true;␉␉␉␉␊ |
1091 | ␉␉␉}␊ |
1092 | ␉␉} ␊ |
1093 | ␉␉else if (((flags & kFileTypeMask) == kFileTypeDirectory)) ␊ |
1094 | ␉␉{␊ |
1095 | ␉␉␉if (find_file_with_ext("rd(0,0)/Extra/Extensions/", KEXT_EXT, NULL, KEXT_EXT_SIZE))␊ |
1096 | ␉␉␉{␊ |
1097 | ␉␉␉␉return true;␊ |
1098 | ␉␉␉} ␊ |
1099 | ␉␉}␊ |
1100 | ␉}␊ |
1101 | ␉ret = GetFileInfo("/Extra/", EXTENSIONS, &flags, &exttime);␊ |
1102 | ␉if (ret == 0) ␊ |
1103 | ␉{␊ |
1104 | ␉␉if (((flags & kFileTypeMask) == kFileTypeFlat))␊ |
1105 | ␉␉{␊ |
1106 | ␉␉␉if (find_file_with_ext("/Extra/", MKEXT_EXT, EXTENSIONS, MKEXT_EXT_SIZE))␊ |
1107 | ␉␉␉{␊ |
1108 | ␉␉␉␉return true;␉␉␉␉␊ |
1109 | ␉␉␉}␊ |
1110 | ␉␉} ␊ |
1111 | ␉␉else if (((flags & kFileTypeMask) == kFileTypeDirectory)) ␊ |
1112 | ␉␉{␊ |
1113 | ␉␉␉if (find_file_with_ext("/Extra/Extensions/", KEXT_EXT, NULL, KEXT_EXT_SIZE))␊ |
1114 | ␉␉␉{␊ |
1115 | ␉␉␉␉return true;␉␉␉␉␊ |
1116 | ␉␉␉} ␊ |
1117 | ␉␉}␉␉␉␊ |
1118 | ␉}␊ |
1119 | ␉ret = GetFileInfo("bt(0,0)/Extra/", EXTENSIONS, &flags, &exttime);␊ |
1120 | ␉if (ret == 0)␊ |
1121 | ␉{␊ |
1122 | ␉␉if (((flags & kFileTypeMask) == kFileTypeFlat))␊ |
1123 | ␉␉{␊ |
1124 | ␉␉␉if (find_file_with_ext("bt(0,0)/Extra/", MKEXT_EXT, EXTENSIONS, MKEXT_EXT_SIZE))␊ |
1125 | ␉␉␉{␊ |
1126 | ␉␉␉␉return true;␉␉␉␉␊ |
1127 | ␉␉␉}␊ |
1128 | ␉␉}␊ |
1129 | ␉␉else if (((flags & kFileTypeMask) == kFileTypeDirectory)) ␊ |
1130 | ␉␉{␊ |
1131 | ␉␉␉if (find_file_with_ext("bt(0,0)/Extra/Extensions/", KEXT_EXT, NULL, KEXT_EXT_SIZE))␊ |
1132 | ␉␉␉{␊ |
1133 | ␉␉␉␉return true;␊ |
1134 | ␉␉␉}␊ |
1135 | ␉␉}␊ |
1136 | ␉}␊ |
1137 | ␉DBG("NO Extra Mkext/Kext found\n");␉␉␊ |
1138 | ␉␊ |
1139 | ␉// nothing found␊ |
1140 | ␉return false;␊ |
1141 | }␊ |
1142 | ␊ |
1143 | #if 0␊ |
1144 | static char *FIXED_BOOTFILE_PATH(char * str)␊ |
1145 | {␊ |
1146 | ␉char bootfile[128];␊ |
1147 | ␉␊ |
1148 | ␉bool bootFileWithDevice = false;␊ |
1149 | ␉// Check if bootFile start with a device ex: bt(0,0)/Extra/mach_kernel␊ |
1150 | ␉if (strncmp(str,"bt(",3) == 0 ||␊ |
1151 | ␉␉strncmp(str,"hd(",3) == 0 ||␊ |
1152 | ␉␉strncmp(str,"rd(",3) == 0)␊ |
1153 | ␉{␊ |
1154 | ␉␉bootFileWithDevice = true;␊ |
1155 | ␉}␊ |
1156 | ␉␉␊ |
1157 | ␉// bootFile must start with a / if it not start with a device name␊ |
1158 | ␉if (!bootFileWithDevice && (str)[0] != '/')␊ |
1159 | ␉␉sprintf(bootFile, "/%s", str); // append a leading /␊ |
1160 | ␉else␊ |
1161 | ␉␉strlcpy(bootFile, bootInfo->bootFile, sizeof(bootInfo->bootFile)+1);␊ |
1162 | ␉␊ |
1163 | ␉return bootfile;␊ |
1164 | }␊ |
1165 | #endif␊ |
1166 | |