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