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