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 | /*␊ |
26 | * Mach Operating System␊ |
27 | * Copyright (c) 1990 Carnegie-Mellon University␊ |
28 | * Copyright (c) 1989 Carnegie-Mellon University␊ |
29 | * All rights reserved.␉ The CMU software License Agreement specifies␊ |
30 | * the terms and conditions for use and redistribution.␊ |
31 | *␊ |
32 | * INTEL CORPORATION PROPRIETARY INFORMATION␊ |
33 | *␊ |
34 | * This software is supplied under the terms of a license agreement or␊ |
35 | * nondisclosure agreement with Intel Corporation and may not be copied␊ |
36 | * nor disclosed except in accordance with the terms of that agreement.␊ |
37 | *␊ |
38 | *␉Copyright 1988, 1989 by Intel Corporation␊ |
39 | *␊ |
40 | *␊ |
41 | * Copyright 1993 NeXT Computer, Inc.␊ |
42 | * All rights reserved.␊ |
43 | *␊ |
44 | * Completely reworked by Sam Streeper (sam_s@NeXT.com)␊ |
45 | * Reworked again by Curtis Galloway (galloway@NeXT.com)␊ |
46 | */␊ |
47 | ␊ |
48 | #include "config.h"␊ |
49 | #include "boot.h"␊ |
50 | #include "bootstruct.h"␊ |
51 | #include "fake_efi.h"␊ |
52 | #include "sl.h"␊ |
53 | #include "libsa.h"␊ |
54 | #include "ramdisk.h"␊ |
55 | #include "gui.h"␊ |
56 | #include "platform.h"␊ |
57 | #include "modules.h"␊ |
58 | #include "device_tree.h"␊ |
59 | #include "xml.h" ␊ |
60 | ␊ |
61 | #if DEBUG_BOOT2␊ |
62 | ␉#define DBG(x...)␉printf(x)␊ |
63 | #else␊ |
64 | ␉#define DBG(x...)␉msglog(x)␊ |
65 | #endif␊ |
66 | ␊ |
67 | /*␊ |
68 | * How long to wait (in seconds) to load the␊ |
69 | * kernel after displaying the "boot:" prompt.␊ |
70 | */␊ |
71 | #define kBootErrorTimeout 5␊ |
72 | ␊ |
73 | bool␉␉gOverrideKernel;␊ |
74 | bool␉␉gEnableCDROMRescan;␊ |
75 | bool␉␉gScanSingleDrive;␊ |
76 | bool␉␉useGUI;␊ |
77 | ␊ |
78 | /* recovery or installer ? */␊ |
79 | bool isInstaller;␊ |
80 | bool isRecoveryHD;␊ |
81 | bool isMacOSXUpgrade;␊ |
82 | bool isOSXUpgrade;␊ |
83 | ␊ |
84 | #if DEBUG_INTERRUPTS␊ |
85 | ␉static int␉interruptsAvailable = 0;␊ |
86 | #endif␊ |
87 | ␊ |
88 | static bool␉gUnloadPXEOnExit = false;␊ |
89 | ␊ |
90 | static char␉gCacheNameAdler[64 + 256];␊ |
91 | char␉␉*gPlatformName = gCacheNameAdler;␊ |
92 | ␊ |
93 | char␉␉gRootDevice[ROOT_DEVICE_SIZE];␊ |
94 | char␉␉gMKextName[512];␊ |
95 | int␉␉bvCount = 0;␊ |
96 | int␉␉gDeviceCount = 0;␊ |
97 | //int␉␉menucount = 0;␊ |
98 | long␉␉gBootMode; /* defaults to 0 == kBootModeNormal */␊ |
99 | ␊ |
100 | BVRef␉␉bvr;␊ |
101 | BVRef␉␉menuBVR;␊ |
102 | BVRef␉␉bvChain;␊ |
103 | ␊ |
104 | static unsigned long␉Adler32(unsigned char *buffer, long length);␊ |
105 | //static void␉␉␉selectBiosDevice(void);␊ |
106 | ␊ |
107 | /** options.c **/␊ |
108 | extern char *msgbuf;␊ |
109 | void showTextBuffer(char *buf, int size);␊ |
110 | ␊ |
111 | //==========================================================================␊ |
112 | // Zero the BSS.␊ |
113 | ␊ |
114 | static void zeroBSS(void)␊ |
115 | {␊ |
116 | ␉extern char bss_start __asm("section$start$__DATA$__bss");␊ |
117 | ␉extern char bss_end __asm("section$end$__DATA$__bss");␊ |
118 | ␉extern char common_start __asm("section$start$__DATA$__common");␊ |
119 | ␉extern char common_end __asm("section$end$__DATA$__common");␊ |
120 | ␊ |
121 | ␉bzero(&bss_start, (&bss_end - &bss_start));␊ |
122 | ␉bzero(&common_start, (&common_end - &common_start));␊ |
123 | }␊ |
124 | ␊ |
125 | //==========================================================================␊ |
126 | // Malloc error function␊ |
127 | ␊ |
128 | static void malloc_error(char *addr, size_t size, const char *file, int line)␊ |
129 | {␊ |
130 | ␉stop("\nMemory allocation error! Addr: 0x%x, Size: 0x%x, File: %s, Line: %d\n",␊ |
131 | ␉␉␉␉␉␉␉␉␉ (unsigned)addr, (unsigned)size, file, line);␊ |
132 | }␊ |
133 | ␊ |
134 | //==========================================================================␊ |
135 | //Initializes the runtime. Right now this means zeroing the BSS and initializing malloc.␊ |
136 | //␊ |
137 | void initialize_runtime(void)␊ |
138 | {␊ |
139 | ␉zeroBSS();␊ |
140 | ␉malloc_init(0, 0, 0, malloc_error);␊ |
141 | }␊ |
142 | ␊ |
143 | // =========================================================================␊ |
144 | // Load the Kernel.plist override config file if any␊ |
145 | static void setupKernelConfigFile(const char *filename)␊ |
146 | {␊ |
147 | ␉char␉␉dirSpec[128];␊ |
148 | ␉const char␉*override_pathname = NULL;␊ |
149 | ␉int␉␉len = 0, err = 0;␊ |
150 | ␊ |
151 | ␉// Take in account user overriding␊ |
152 | ␉if (getValueForKey(kKERNELKey, &override_pathname, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
153 | ␉{␊ |
154 | ␉␉// Specify a path to a file, e.g. KERNELPlist=/Extra/Kernel2.plist␊ |
155 | ␉␉strcpy(dirSpec, override_pathname);␊ |
156 | ␉␉err = loadConfigFile(dirSpec, &bootInfo->kernelConfig);␊ |
157 | ␉}␊ |
158 | ␉else␊ |
159 | ␉{␊ |
160 | ␉␉// Check selected volume's Extra.␊ |
161 | ␉␉sprintf(dirSpec, "/Extra/%s", filename);␊ |
162 | ␉␉err = loadConfigFile(dirSpec, &bootInfo->kernelConfig);␊ |
163 | ␉}␊ |
164 | ␊ |
165 | ␉if (!err)␊ |
166 | ␉{␊ |
167 | ␉␉getBoolForKey(kKernelBooter_kexts, &KernelBooter_kexts, KERNELPlist);␊ |
168 | ␉␉getBoolForKey(kKernelPm, &KernelPm, KERNELPlist);␊ |
169 | ␉␉getBoolForKey(kKernelLapicError, &KernelLapicError, KERNELPlist);␊ |
170 | ␉␉getBoolForKey(kKernelLapicVersion, &KernelLapicVersion, KERNELPlist);␊ |
171 | ␉␉getBoolForKey(kKernelHaswell, &KernelHaswell, KERNELPlist);␊ |
172 | ␉␉getBoolForKey(kKernelcpuFamily, &KernelcpuFamily, KERNELPlist);␊ |
173 | ␉␉getBoolForKey(kKernelSSE3, &KernelSSE3, KERNELPlist);␊ |
174 | ␉}␊ |
175 | ␉else␊ |
176 | ␉{␊ |
177 | ␉␉verbose("No %s replacement found.\n", filename);␊ |
178 | ␉}␊ |
179 | }␊ |
180 | ␊ |
181 | #if KEXTPATCH_SUPPORT␊ |
182 | // =========================================================================␊ |
183 | // Load the Kexts.plist override config file if any␊ |
184 | static void setupKextConfigFile(const char *filename)␊ |
185 | {␊ |
186 | ␉char␉␉dirSpec[128];␊ |
187 | ␉const char␉*override_pathname = NULL;␊ |
188 | ␉int␉␉len = 0, err = 0;␊ |
189 | ␊ |
190 | ␉AppleRTCPatch = false;␊ |
191 | ␉AICPMPatch = false;␊ |
192 | ␉OrangeIconFixSata = false;␊ |
193 | ␉NVIDIAWebDrv = false;␊ |
194 | ␉TrimEnablerSata = false;␊ |
195 | ␊ |
196 | ␉// Take in account user overriding␊ |
197 | ␉if (getValueForKey(kKEXTKey, &override_pathname, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
198 | ␉{␊ |
199 | ␉␉// Specify a path to a file, e.g. KEXTPlist=/Extra/Kext2.plist␊ |
200 | ␉␉strcpy(dirSpec, override_pathname);␊ |
201 | ␉␉err = loadConfigFile(dirSpec, &bootInfo->kextConfig);␊ |
202 | ␉} else {␊ |
203 | ␉␉// Check selected volume's Extra.␊ |
204 | ␉␉sprintf(dirSpec, "/Extra/%s", filename);␊ |
205 | ␉␉err = loadConfigFile(dirSpec, &bootInfo->kextConfig);␊ |
206 | ␉}␊ |
207 | ␊ |
208 | ␉if (!err)␊ |
209 | ␉{␊ |
210 | ␉␉getBoolForKey(kAppleRTCPatch, &AppleRTCPatch, KEXTPlist);␊ |
211 | ␉␉getBoolForKey(kAICPMPatch, &AICPMPatch, KEXTPlist);␊ |
212 | ␉␉getBoolForKey(kNVIDIAWebDrv, &NVIDIAWebDrv, KEXTPlist);␊ |
213 | ␉␉getBoolForKey(kOrangeIconFixSata, &OrangeIconFixSata, KEXTPlist);␊ |
214 | ␉␉getBoolForKey(kTrimEnablerSata, &TrimEnablerSata, KEXTPlist);␊ |
215 | ␉} else {␊ |
216 | ␉␉verbose("No %s replacement found.\n", filename);␊ |
217 | ␉}␊ |
218 | }␊ |
219 | #endif␊ |
220 | ␊ |
221 | //==========================================================================␊ |
222 | // ExecKernel - Load the kernel image (mach-o) and jump to its entry point.␊ |
223 | ␊ |
224 | static int ExecKernel(void *binary)␊ |
225 | {␊ |
226 | ␉int␉␉␉ret;␊ |
227 | ␉entry_t␉␉kernelEntry;␊ |
228 | ␊ |
229 | ␉bootArgs->kaddr = bootArgs->ksize = 0;␊ |
230 | ␊ |
231 | // ===============================================================================␊ |
232 | ␊ |
233 | ␉gMacOSVersion[0] = 0;␊ |
234 | ␉verbose("Booting on %s %s (%s)\n", (MacOSVerCurrent < MacOSVer2Int("10.8")) ? "Mac OS X" : (MacOSVerCurrent < MacOSVer2Int("10.12")) ? "OS X" : "macOS", gBootVolume->OSFullVer, gBootVolume->OSBuildVer );␊ |
235 | ␊ |
236 | ␉setupBooterArgs();␊ |
237 | ␊ |
238 | // ===============================================================================␊ |
239 | ␊ |
240 | ␉execute_hook("ExecKernel", (void *)binary, NULL, NULL, NULL);␊ |
241 | ␊ |
242 | ␉ret = DecodeKernel(binary,␊ |
243 | ␉␉␉␉␉ &kernelEntry,␊ |
244 | ␉␉␉␉␉ (char **) &bootArgs->kaddr,␊ |
245 | ␉␉␉␉␉ (int *)&bootArgs->ksize);␊ |
246 | ␊ |
247 | ␉if ( ret != 0 )␊ |
248 | ␉{␊ |
249 | ␉␉printf("Decoding kernel failed.\n");␊ |
250 | ␉␉pause();␊ |
251 | ␉␉return ret;␊ |
252 | ␉}␊ |
253 | ␊ |
254 | ␉// Reserve space for boot args␊ |
255 | ␉reserveKernBootStruct();␊ |
256 | ␊ |
257 | ␉// Notify modules that the kernel has been decoded␊ |
258 | ␉execute_hook("DecodedKernel", (void *)binary, (void *)bootArgs->kaddr, (void *)bootArgs->ksize, NULL);␊ |
259 | ␊ |
260 | ␉setupFakeEfi();␊ |
261 | ␊ |
262 | ␉// Load boot drivers from the specifed root path.␊ |
263 | ␉//if (!gHaveKernelCache)␊ |
264 | ␉{␊ |
265 | ␉␉LoadDrivers("/");␊ |
266 | ␉}␊ |
267 | ␊ |
268 | ␉execute_hook("DriversLoaded", (void *)binary, NULL, NULL, NULL);␊ |
269 | ␊ |
270 | ␉clearActivityIndicator();␊ |
271 | ␊ |
272 | ␉if (gErrors)␊ |
273 | ␉{␊ |
274 | ␉␉printf("Errors encountered while starting up the computer.\n");␊ |
275 | ␉␉printf("Pausing %d seconds...\n", kBootErrorTimeout);␊ |
276 | ␉␉sleep(kBootErrorTimeout);␊ |
277 | ␉}␊ |
278 | ␊ |
279 | ␉md0Ramdisk();␊ |
280 | ␊ |
281 | ␉// Cleanup the PXE base code.␊ |
282 | ␊ |
283 | ␉if ( (gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit )␊ |
284 | ␉{␊ |
285 | ␉␉if ( (ret = nbpUnloadBaseCode()) != nbpStatusSuccess )␊ |
286 | ␉␉{␊ |
287 | ␉␉␉printf("nbpUnloadBaseCode error %d\n", (int)ret);␊ |
288 | ␉␉␉sleep(2);␊ |
289 | ␉␉}␊ |
290 | ␉}␊ |
291 | ␊ |
292 | ␉bool dummyVal;␊ |
293 | ␉if (getBoolForKey(kWaitForKeypressKey, &dummyVal, &bootInfo->chameleonConfig) && dummyVal)␊ |
294 | ␉{␊ |
295 | ␉␉showTextBuffer(msgbuf, strlen(msgbuf));␊ |
296 | ␉}␊ |
297 | ␊ |
298 | ␉usb_loop();␊ |
299 | ␊ |
300 | #if DEBUG␊ |
301 | ␉if (interruptsAvailable) ShowInterruptCounters();␊ |
302 | #endif␊ |
303 | ␊ |
304 | ␉// If we were in text mode, switch to graphics mode.␊ |
305 | ␉// This will draw the boot graphics unless we are in␊ |
306 | ␉// verbose mode.␊ |
307 | ␉if (gVerboseMode)␊ |
308 | ␉{␊ |
309 | ␉␉setVideoMode( GRAPHICS_MODE );␊ |
310 | ␉}␊ |
311 | ␉else␊ |
312 | ␉{␊ |
313 | ␉␉drawBootGraphics();␊ |
314 | ␉}␊ |
315 | ␊ |
316 | ␉DBG("Starting Darwin/%s [%s]\n",( archCpuType == CPU_TYPE_I386 ) ? "x86" : "x86_64", gDarwinBuildVerStr);␊ |
317 | ␉DBG("Boot Args: %s\n", bootArgs->CommandLine);␊ |
318 | ␊ |
319 | ␉setupBooterLog();␊ |
320 | ␊ |
321 | ␉finalizeBootStruct();␊ |
322 | ␊ |
323 | ␉// Jump to kernel's entry point. There's no going back now.␊ |
324 | ␉if ( MacOSVerCurrent < MacOSVer2Int("10.7") )␊ |
325 | ␉{␊ |
326 | ␉␉// Notify modules that the kernel is about to be started␊ |
327 | ␉␉execute_hook("Kernel Start", (void *)kernelEntry, (void *)bootArgsLegacy, NULL, NULL);␊ |
328 | ␊ |
329 | ␉␉startprog( kernelEntry, bootArgsLegacy );␊ |
330 | ␉}␊ |
331 | ␉else␊ |
332 | ␉{␊ |
333 | ␉␉// Notify modules that the kernel is about to be started␊ |
334 | ␉␉execute_hook("Kernel Start", (void *)kernelEntry, (void *)bootArgs, NULL, NULL);␊ |
335 | ␊ |
336 | ␉␉startprog( kernelEntry, bootArgs );␊ |
337 | ␉}␊ |
338 | ␊ |
339 | ␉// Not reached␊ |
340 | ␉__builtin_unreachable();␊ |
341 | }␊ |
342 | ␊ |
343 | //==========================================================================␊ |
344 | // LoadKernelCache - Try to load Kernel Cache.␊ |
345 | // return the length of the loaded cache file or -1 on error␊ |
346 | long LoadKernelCache(const char *cacheFile, void **binary)␊ |
347 | {␊ |
348 | ␉char␉␉kernelCacheFile[512];␊ |
349 | ␉char␉␉kernelCachePath[512];␊ |
350 | ␉long␉␉flags, ret=-1;␊ |
351 | ␉unsigned long␉adler32 = 0;␊ |
352 | ␉u_int32_t time, cachetime, kerneltime, exttime;␊ |
353 | ␊ |
354 | ␉if((gBootMode & kBootModeSafe) != 0)␊ |
355 | ␉{␊ |
356 | ␉␉DBG("Kernel Cache ignored.\n");␊ |
357 | ␉␉return -1;␊ |
358 | ␉}␊ |
359 | ␊ |
360 | ␉// Use specify kernel cache file if not empty␊ |
361 | ␉if (cacheFile[0] != 0)␊ |
362 | ␉{␊ |
363 | ␉␉strlcpy(kernelCacheFile, cacheFile, sizeof(kernelCacheFile));␊ |
364 | ␉␉verbose("Specified kernel cache file path: %s\n", cacheFile);␊ |
365 | ␉}␊ |
366 | ␉else␊ |
367 | ␉{␊ |
368 | ␉␉// Leopard prelink kernel cache file␊ |
369 | ␉␉if ( MacOSVerCurrent >= MacOSVer2Int("10.4") && MacOSVerCurrent <= MacOSVer2Int("10.5") ) // OSX is 10.4 or 10.5␊ |
370 | ␉␉{␊ |
371 | ␉␉␉// Reset cache name.␊ |
372 | ␉␉␉bzero(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64);␊ |
373 | ␉␉␉snprintf(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64, "%s,%s", gRootDevice, bootInfo->bootFile);␊ |
374 | ␉␉␉adler32 = Adler32((unsigned char *)gCacheNameAdler, sizeof(gCacheNameAdler));␊ |
375 | ␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%s.%08lX", kDefaultCachePathLeo, adler32);␊ |
376 | ␉␉␉verbose("Reseted kernel cache file path: %s\n", kernelCacheFile);␊ |
377 | ␊ |
378 | ␉␉}␊ |
379 | ␉␉// Snow Leopard prelink kernel cache file␊ |
380 | ␉␉else if ( MacOSVerCurrent >= MacOSVer2Int("10.6") && MacOSVerCurrent < MacOSVer2Int("10.7") )␊ |
381 | ␉␉{␊ |
382 | ␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "kernelcache_%s",␊ |
383 | ␉␉␉␉(archCpuType == CPU_TYPE_I386) ? "i386" : "x86_64");␊ |
384 | ␊ |
385 | ␉␉␉int␉␉lnam = strlen(kernelCacheFile) + 9; //with adler32␊ |
386 | ␉␉␉char␉␉*name;␊ |
387 | ␉␉␉u_int32_t␉prev_time = 0;␊ |
388 | ␊ |
389 | ␉␉␉struct dirstuff *cacheDir = opendir(kDefaultCachePathSnow);␊ |
390 | ␊ |
391 | ␉␉␉/* TODO: handle error? */␊ |
392 | ␉␉␉if (cacheDir)␊ |
393 | ␉␉␉{␊ |
394 | ␉␉␉␉while(readdir(cacheDir, (const char**)&name, &flags, &time) >= 0)␊ |
395 | ␉␉␉␉{␊ |
396 | ␉␉␉␉␉if (((flags & kFileTypeMask) != kFileTypeDirectory) && time > prev_time␊ |
397 | ␉␉␉␉␉␉&& strstr(name, kernelCacheFile) && (name[lnam] != '.'))␊ |
398 | ␉␉␉␉␉{␊ |
399 | ␉␉␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%s%s", kDefaultCachePathSnow, name);␊ |
400 | ␉␉␉␉␉␉prev_time = time;␊ |
401 | ␉␉␉␉␉}␊ |
402 | ␉␉␉␉}␊ |
403 | ␉␉␉␉verbose("Kernel Cache file path (Mac OS X 10.6): %s\n", kernelCacheFile);␊ |
404 | ␉␉␉}␊ |
405 | ␉␉␉closedir(cacheDir);␊ |
406 | ␉␉}␊ |
407 | ␉␉else if ( MacOSVerCurrent >= MacOSVer2Int("10.7") && MacOSVerCurrent < MacOSVer2Int("10.9") )␊ |
408 | ␉␉{␊ |
409 | ␉␉␉// Lion, Mountain Lion␊ |
410 | ␉␉␉// for 10.7 10.8␊ |
411 | ␉␉␉if (isMacOSXUpgrade)␊ |
412 | ␉␉␉{␊ |
413 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", "/Mac OS X Install Data/");␊ |
414 | ␉␉␉}␊ |
415 | ␉␉␉else if (isInstaller)␊ |
416 | ␉␉␉{␊ |
417 | ␉␉␉␉if (MacOSVerCurrent >= MacOSVer2Int("10.7") && MacOSVerCurrent < MacOSVer2Int("10.8") )␊ |
418 | ␉␉␉␉{␊ |
419 | ␉␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kLionInstallerDataFolder);␊ |
420 | ␉␉␉␉}␊ |
421 | ␉␉␉␉else if ( MacOSVerCurrent >= MacOSVer2Int("10.8") && MacOSVerCurrent < MacOSVer2Int("10.9") )␊ |
422 | ␉␉␉␉{␊ |
423 | ␉␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kMLionInstallerDataFolder);␊ |
424 | ␉␉␉␉}␊ |
425 | ␊ |
426 | ␉␉␉}␊ |
427 | ␉␉␉else if (isRecoveryHD)␊ |
428 | ␉␉␉{␊ |
429 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCacheRecoveryHD);␊ |
430 | ␉␉␉}␊ |
431 | ␉␉␉else␊ |
432 | ␉␉␉{␊ |
433 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCachePathSnow);␊ |
434 | ␉␉␉}␊ |
435 | ␊ |
436 | ␉␉␉verbose("Kernel Cache file path (Mac OS X 10.7 and newer): %s\n", kernelCacheFile);␊ |
437 | ␊ |
438 | ␉␉}␊ |
439 | ␉␉else if ( MacOSVerCurrent >= MacOSVer2Int("10.9") && MacOSVerCurrent < MacOSVer2Int("10.10") )␊ |
440 | ␉␉{␊ |
441 | ␉␉␉// Mavericks prelinked cache file␊ |
442 | ␉␉␉// for 10.9␊ |
443 | ␉␉␉if (isOSXUpgrade)␊ |
444 | ␉␉␉{␊ |
445 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", "/OS X Install Data/");␊ |
446 | ␉␉␉}␊ |
447 | ␉␉␉else if (isInstaller)␊ |
448 | ␉␉␉{␊ |
449 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCacheInstallerNew);␊ |
450 | ␉␉␉}␊ |
451 | ␉␉␉else if (isRecoveryHD)␊ |
452 | ␉␉␉{␊ |
453 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCacheRecoveryHD);␊ |
454 | ␉␉␉}␊ |
455 | ␉␉␉else␊ |
456 | ␉␉␉{␊ |
457 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCachePathSnow);␊ |
458 | ␉␉␉}␊ |
459 | ␊ |
460 | ␉␉␉verbose("Kernel Cache file path (OS X 10.9): %s\n", kernelCacheFile);␊ |
461 | ␊ |
462 | ␉␉}␊ |
463 | ␉␉else if ( MacOSVerCurrent >= MacOSVer2Int("10.10") && MacOSVerCurrent < MacOSVer2Int("10.11") )␊ |
464 | ␉␉{␊ |
465 | ␉␉␉// Yosemite prelink kernel cache file␊ |
466 | ␉␉␉// for 10.10 and 10.11␊ |
467 | ␉␉␉if (isOSXUpgrade)␊ |
468 | ␉␉␉{␊ |
469 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", "/OS X Install Data/");␊ |
470 | ␉␉␉}␊ |
471 | ␉␉␉else if (isInstaller)␊ |
472 | ␉␉␉{␊ |
473 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCacheInstallerNew);␊ |
474 | ␉␉␉}␊ |
475 | ␉␉␉else if (isRecoveryHD)␊ |
476 | ␉␉␉{␊ |
477 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCacheRecoveryHD);␊ |
478 | ␉␉␉}␊ |
479 | ␉␉␉else␊ |
480 | ␉␉␉{␊ |
481 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%sprelinkedkernel", kDefaultCachePathYosemite);␊ |
482 | ␉␉␉}␊ |
483 | ␊ |
484 | ␉␉␉verbose("Kernel Cache file path (OS X 10.10): %s\n", kernelCacheFile);␊ |
485 | ␉␉}␊ |
486 | ␉␉else if ( MacOSVerCurrent >= MacOSVer2Int("10.11") )␊ |
487 | ␉␉{␊ |
488 | ␉␉␉// El Capitan on prelinked kernel cache file␊ |
489 | ␉␉␉// for 10.10 and 10.11␊ |
490 | ␉␉␉if (isOSXUpgrade)␊ |
491 | ␉␉␉{␊ |
492 | ␉␉␉␉if ( MacOSVerCurrent >= MacOSVer2Int("10.13") )␊ |
493 | ␉␉␉␉{␊ |
494 | ␉␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile),␊ |
495 | ␉␉␉␉␉␉"%sprelinkedkernel",␊ |
496 | ␉␉␉␉␉␉"/macOS Install Data/Locked Files/Boot Files/");␊ |
497 | ␉␉␉␉}␊ |
498 | ␉␉␉␉else␊ |
499 | ␉␉␉␉{␊ |
500 | ␉␉␉␉␉snprintf(kernelCacheFile,␊ |
501 | ␉␉␉␉␉␉sizeof(kernelCacheFile),␊ |
502 | ␉␉␉␉␉␉"%sprelinkedkernel",␊ |
503 | ␉␉␉␉␉␉"/OS X Install Data/");␊ |
504 | ␉␉␉␉}␊ |
505 | ␊ |
506 | ␉␉␉}␊ |
507 | ␉␉␉else if (isInstaller)␊ |
508 | ␉␉␉{␊ |
509 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%sprelinkedkernel", kDefaultCacheInstallerNew);␊ |
510 | ␉␉␉}␊ |
511 | ␉␉␉else if (isRecoveryHD)␊ |
512 | ␉␉␉{␊ |
513 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%sprelinkedkernel", kDefaultCacheRecoveryHD);␊ |
514 | ␉␉␉}␊ |
515 | ␉␉␉else␊ |
516 | ␉␉␉{␊ |
517 | ␉␉␉␉snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%sprelinkedkernel", kDefaultCachePathYosemite);␊ |
518 | ␉␉␉}␊ |
519 | ␊ |
520 | ␉␉␉verbose("Kernel Cache file path (OS X 10.11 and newer): %s\n", kernelCacheFile);␊ |
521 | ␉␉}␊ |
522 | ␉}␊ |
523 | ␊ |
524 | ␉// Check if the kernel cache file exists␊ |
525 | ␉ret = -1;␊ |
526 | ␊ |
527 | ␉if (gBootVolume->flags & kBVFlagBooter)␊ |
528 | ␉{␊ |
529 | ␉␉if (isRecoveryHD)␊ |
530 | ␉␉{␊ |
531 | ␉␉␉strncpy(kernelCachePath, "/com.apple.recovery.boot/prelinkedkernel", sizeof(kernelCachePath) );␊ |
532 | ␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
533 | ␊ |
534 | ␉␉␉if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
535 | ␉␉␉{␊ |
536 | ␉␉␉␉strncpy(kernelCachePath, "/com.apple.recovery.boot/kernelcache", sizeof(kernelCachePath) );␊ |
537 | ␉␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
538 | ␊ |
539 | ␉␉␉␉if ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
540 | ␉␉␉␉{␊ |
541 | ␉␉␉␉␉ret = -1;␊ |
542 | ␉␉␉␉}␊ |
543 | ␉␉␉}␊ |
544 | ␉␉}␊ |
545 | ␉␉else if (isInstaller)␊ |
546 | ␉␉{␊ |
547 | ␉␉␉strncpy(kernelCachePath, "/.IABootFiles/prelinkedkernel", sizeof(kernelCachePath) );␊ |
548 | ␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
549 | ␊ |
550 | ␉␉␉if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
551 | ␉␉␉{␊ |
552 | ␉␉␉␉strncpy(kernelCachePath, "/.IABootFiles/kernelcache", sizeof(kernelCachePath) );␊ |
553 | ␉␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
554 | ␊ |
555 | ␉␉␉␉if ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
556 | ␉␉␉␉{␊ |
557 | ␉␉␉␉␉ret = -1;␊ |
558 | ␉␉␉␉}␊ |
559 | ␉␉␉}␊ |
560 | ␉␉}␊ |
561 | ␉␉else if (isMacOSXUpgrade)␊ |
562 | ␉␉{␊ |
563 | ␉␉␉strncpy(kernelCachePath, "/Mac OS X Install Data/kernelcache", sizeof(kernelCachePath) );␊ |
564 | ␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
565 | ␊ |
566 | ␉␉␉if ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
567 | ␉␉␉{␊ |
568 | ␉␉␉␉ret = -1;␊ |
569 | ␉␉␉}␊ |
570 | ␉␉}␊ |
571 | ␉␉else if (isOSXUpgrade)␊ |
572 | ␉␉{␊ |
573 | ␉␉␉strncpy(kernelCachePath,␊ |
574 | ␉␉␉␉"/macOS Install Data/Locked Files/Boot Files/prelinkedkernel",␊ |
575 | ␉␉␉␉sizeof(kernelCachePath) );␊ |
576 | ␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
577 | ␊ |
578 | ␉␉␉if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
579 | ␉␉␉{␊ |
580 | ␉␉␉␉strncpy(kernelCachePath, "/OS X Install Data/prelinkedkernel", sizeof(kernelCachePath) );␊ |
581 | ␉␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
582 | ␊ |
583 | ␉␉␉␉if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
584 | ␉␉␉␉{␊ |
585 | ␉␉␉␉␉strncpy(kernelCachePath, "/OS X Install Data/kernelcache", sizeof(kernelCachePath) );␊ |
586 | ␉␉␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
587 | ␊ |
588 | ␉␉␉␉␉if ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
589 | ␉␉␉␉␉{␊ |
590 | ␉␉␉␉␉␉ret = -1;␊ |
591 | ␉␉␉␉␉}␊ |
592 | ␉␉␉␉}␊ |
593 | ␉␉␉}␊ |
594 | ␉␉}␊ |
595 | ␉␉else␊ |
596 | ␉␉{␊ |
597 | ␉␉␉snprintf(kernelCachePath, sizeof(kernelCachePath), "/com.apple.boot.P/%s", kernelCacheFile);␊ |
598 | ␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
599 | ␉␉␉if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
600 | ␉␉␉{␊ |
601 | ␉␉␉␉snprintf(kernelCachePath, sizeof(kernelCachePath), "/com.apple.boot.R/%s", kernelCacheFile);␊ |
602 | ␉␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
603 | ␊ |
604 | ␉␉␉␉if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
605 | ␉␉␉␉{␊ |
606 | ␉␉␉␉␉snprintf(kernelCachePath, sizeof(kernelCachePath), "/com.apple.boot.S/%s", kernelCacheFile);␊ |
607 | ␉␉␉␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
608 | ␊ |
609 | ␉␉␉␉␉if ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
610 | ␉␉␉␉␉{␊ |
611 | ␉␉␉␉␉␉ret = -1;␊ |
612 | ␉␉␉␉␉}␊ |
613 | ␉␉␉␉}␊ |
614 | ␉␉␉}␊ |
615 | ␉␉}␊ |
616 | ␉}␊ |
617 | ␊ |
618 | ␉// If not found, use the original kernel cache path.␊ |
619 | ␉if (ret == -1)␊ |
620 | ␉{␊ |
621 | ␉␉strlcpy(kernelCachePath, kernelCacheFile, sizeof(kernelCachePath));␊ |
622 | ␉␉ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);␊ |
623 | ␊ |
624 | ␉␉if ((flags & kFileTypeMask) != kFileTypeFlat)␊ |
625 | ␉␉{␊ |
626 | ␉␉␉ret = -1;␊ |
627 | ␉␉}␊ |
628 | ␉}␊ |
629 | ␊ |
630 | ␉// Exit if kernel cache file wasn't found␊ |
631 | ␉if (ret == -1)␊ |
632 | ␉{␊ |
633 | ␉␉DBG("No Kernel Cache File '%s' found\n", kernelCacheFile);␊ |
634 | ␉␉return -1;␊ |
635 | ␉}␊ |
636 | ␊ |
637 | ␉if ( !isInstaller && !isRecoveryHD && !isMacOSXUpgrade && !isOSXUpgrade )␊ |
638 | ␉{␊ |
639 | ␉␉// Check if the kernel cache file is more recent (mtime)␊ |
640 | ␉␉// than the kernel file or the S/L/E directory␊ |
641 | ␉␉ret = GetFileInfo(NULL, bootInfo->bootFile, &flags, &kerneltime);␊ |
642 | ␊ |
643 | ␉␉// Check if the kernel file is more recent than the cache file␊ |
644 | ␉␉if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeFlat) && (kerneltime > cachetime))␊ |
645 | ␉␉{␊ |
646 | ␉␉␉DBG("Kernel file '%s' is more recent than Kernel Cache '%s'! Ignoring Kernel Cache.\n", bootInfo->bootFile, kernelCacheFile);␊ |
647 | ␉␉␉return -1;␊ |
648 | ␉␉}␊ |
649 | ␊ |
650 | ␉␉ret = GetFileInfo("/System/Library/", "Extensions", &flags, &exttime);␊ |
651 | ␊ |
652 | ␉␉// Check if the S/L/E directory time is more recent than the cache file␊ |
653 | ␉␉if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory) && (exttime > cachetime))␊ |
654 | ␉␉{␊ |
655 | ␉␉␉DBG("Folder '/System/Library/Extensions' is more recent than Kernel Cache file '%s'! Ignoring Kernel Cache.\n", kernelCacheFile);␊ |
656 | ␉␉␉return -1;␊ |
657 | ␉␉}␊ |
658 | ␉}␊ |
659 | ␊ |
660 | ␉// Since the kernel cache file exists and is the most recent try to load it␊ |
661 | ␉DBG("Loading Kernel Cache from: '%s%s' (%s)\n", gBootVolume->label, gBootVolume->altlabel, gBootVolume->type_name);␊ |
662 | ␊ |
663 | ␉ret = LoadThinFatFile(kernelCachePath, binary);␊ |
664 | ␉return ret; // ret contain the length of the binary␊ |
665 | }␊ |
666 | ␊ |
667 | //==========================================================================␊ |
668 | // This is the entrypoint from real-mode which functions exactly as it did␊ |
669 | // before. Multiboot does its own runtime initialization, does some of its␊ |
670 | // own things, and then calls common_boot.␊ |
671 | void boot(int biosdev)␊ |
672 | {␊ |
673 | ␉// Enable A20 gate before accessing memory above 1Mb.␊ |
674 | ␉// Note: malloc_init(), called via initialize_runtime() writes␊ |
675 | ␉// memory >= 1Mb, so A20 must be enabled before calling it. - zenith432␊ |
676 | ␉zeroBSS();␊ |
677 | ␉enableA20();␊ |
678 | ␉malloc_init(0, 0, 0, malloc_error);␊ |
679 | ␉common_boot(biosdev);␊ |
680 | }␊ |
681 | ␊ |
682 | //==========================================================================␊ |
683 | // The 'main' function for the booter. Called by boot0 when booting␊ |
684 | // from a block device, or by the network booter.␊ |
685 | //␊ |
686 | // arguments:␊ |
687 | //␉ biosdev - Value passed from boot1/NBP to specify the device␊ |
688 | //␉␉␉ that the booter was loaded from.␊ |
689 | //␊ |
690 | // If biosdev is kBIOSDevNetwork, then this function will return if␊ |
691 | // booting was unsuccessful. This allows the PXE firmware to try the␊ |
692 | // next boot device on its list.␊ |
693 | void common_boot(int biosdev)␊ |
694 | {␊ |
695 | ␉bool␉ ␉␉quiet;␊ |
696 | ␉bool␉ ␉␉firstRun = true;␊ |
697 | ␉bool␉ ␉␉instantMenu;␊ |
698 | ␉bool␉ ␉␉rescanPrompt;␊ |
699 | ␉int␉␉␉status;␊ |
700 | ␉unsigned int␉␉allowBVFlags = kBVFlagSystemVolume | kBVFlagForeignBoot;␊ |
701 | ␉unsigned int␉␉denyBVFlags = kBVFlagEFISystem;␊ |
702 | ␊ |
703 | ␉// Set reminder to unload the PXE base code. Neglect to unload␊ |
704 | ␉// the base code will result in a hang or kernel panic.␊ |
705 | ␉gUnloadPXEOnExit = true;␊ |
706 | ␊ |
707 | ␉// Record the device that the booter was loaded from.␊ |
708 | ␉gBIOSDev = biosdev & kBIOSDevMask;␊ |
709 | ␊ |
710 | ␉// Initialize boot-log␊ |
711 | ␉initBooterLog();␊ |
712 | ␊ |
713 | #if DEBUG_INTERRUPTS␊ |
714 | ␉// Enable interrupts␊ |
715 | ␉interruptsAvailable = SetupInterrupts();␊ |
716 | ␉if (interruptsAvailable)␊ |
717 | ␉{␊ |
718 | ␉␉EnableInterrupts();␊ |
719 | ␉}␊ |
720 | #endif␊ |
721 | ␊ |
722 | ␉// Initialize boot info structure.␊ |
723 | ␉initKernBootStruct();␊ |
724 | ␊ |
725 | ␉// Setup VGA text mode.␊ |
726 | ␉// Not sure if it is safe to call setVideoMode() before the␊ |
727 | ␉// config table has been loaded. Call video_mode() instead.␊ |
728 | #if DEBUG␊ |
729 | ␉printf("before video_mode\n");␊ |
730 | #endif␊ |
731 | ␉video_mode( 2 ); // 80x25 mono text mode.␊ |
732 | #if DEBUG␊ |
733 | ␉printf("after video_mode\n");␊ |
734 | #endif␊ |
735 | ␊ |
736 | ␉// Scan and record the system's hardware information.␊ |
737 | ␉scan_platform();␊ |
738 | ␊ |
739 | ␉// First get info for boot volume.␊ |
740 | ␉scanBootVolumes(gBIOSDev, 0);␊ |
741 | ␉bvChain = getBVChainForBIOSDev(gBIOSDev);␊ |
742 | ␉setBootGlobals(bvChain);␊ |
743 | ␊ |
744 | ␉// Load boot.plist config file␊ |
745 | ␉status = loadChameleonConfig(&bootInfo->chameleonConfig, bvChain);␊ |
746 | ␊ |
747 | ␉if (getBoolForKey(kQuietBootKey, &quiet, &bootInfo->chameleonConfig) && quiet)␊ |
748 | ␉{␊ |
749 | ␉␉gBootMode |= kBootModeQuiet;␊ |
750 | ␉}␊ |
751 | ␊ |
752 | ␉// Override firstRun to get to the boot menu instantly by setting "Instant Menu"=y in system config␊ |
753 | ␉if (getBoolForKey(kInstantMenuKey, &instantMenu, &bootInfo->chameleonConfig) && instantMenu)␊ |
754 | ␉{␊ |
755 | ␉␉firstRun = false;␊ |
756 | ␉}␊ |
757 | ␊ |
758 | ␉// Loading preboot ramdisk if exists.␊ |
759 | ␉loadPrebootRAMDisk();␊ |
760 | ␊ |
761 | ␉// Disable rescan option by default␊ |
762 | ␉gEnableCDROMRescan = false;␊ |
763 | ␊ |
764 | ␉// Enable it with Rescan=y in system config␊ |
765 | ␉if (getBoolForKey(kRescanKey, &gEnableCDROMRescan, &bootInfo->chameleonConfig)␉&& gEnableCDROMRescan)␊ |
766 | ␉{␊ |
767 | ␉␉gEnableCDROMRescan = true;␊ |
768 | ␉}␊ |
769 | ␊ |
770 | ␉// Disable rescanPrompt option by default␊ |
771 | ␉rescanPrompt = false;␊ |
772 | ␊ |
773 | ␉// Ask the user for Rescan option by setting "Rescan Prompt"=y in system config.␊ |
774 | ␉if (getBoolForKey(kRescanPromptKey, &rescanPrompt , &bootInfo->chameleonConfig) && rescanPrompt && biosDevIsCDROM(gBIOSDev))␊ |
775 | ␉{␊ |
776 | ␉␉gEnableCDROMRescan = promptForRescanOption();␊ |
777 | ␉}␊ |
778 | ␊ |
779 | ␉// Enable touching a single BIOS device only if "Scan Single Drive"=y is set in system config.␊ |
780 | ␉if (getBoolForKey(kScanSingleDriveKey, &gScanSingleDrive, &bootInfo->chameleonConfig) && gScanSingleDrive)␊ |
781 | ␉{␊ |
782 | ␉␉gScanSingleDrive = true;␊ |
783 | ␉}␊ |
784 | ␊ |
785 | ␉// Create a list of partitions on device(s).␊ |
786 | ␉if (gScanSingleDrive)␊ |
787 | ␉{␊ |
788 | ␉␉scanBootVolumes(gBIOSDev, &bvCount);␊ |
789 | ␉}␊ |
790 | ␉else␊ |
791 | ␉{␊ |
792 | ␉␉scanDisks(gBIOSDev, &bvCount);␊ |
793 | ␉}␊ |
794 | ␊ |
795 | ␉// Create a separated bvr chain using the specified filters.␊ |
796 | ␉bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);␊ |
797 | ␊ |
798 | ␉gBootVolume = selectBootVolume(bvChain);␊ |
799 | ␊ |
800 | ␉// Intialize module system␊ |
801 | ␉init_module_system();␊ |
802 | ␊ |
803 | #if DEBUG␊ |
804 | ␉printf("Default: %d, ->biosdev: %d, ->part_no: %d ->flags: 0x%08X\n",␊ |
805 | ␉␉gBootVolume, gBootVolume->biosdev, gBootVolume->part_no, gBootVolume->flags);␊ |
806 | ␉printf("bt(0,0): %d, ->biosdev: %d, ->part_no: %d ->flags: 0x%08X\n",␊ |
807 | ␉␉gBIOSBootVolume, gBIOSBootVolume->biosdev, gBIOSBootVolume->part_no, gBIOSBootVolume->flags);␊ |
808 | ␉getchar();␊ |
809 | #endif␊ |
810 | ␊ |
811 | ␉useGUI = true;␊ |
812 | ␉// Override useGUI default␊ |
813 | ␉getBoolForKey(kGUIKey, &useGUI, &bootInfo->chameleonConfig);␊ |
814 | ␉if (useGUI && initGUI())␊ |
815 | ␉{␊ |
816 | ␉␉// initGUI() returned with an error, disabling GUI.␊ |
817 | ␉␉useGUI = false;␊ |
818 | ␉}␊ |
819 | ␊ |
820 | ␉setBootGlobals(bvChain);␊ |
821 | ␊ |
822 | ␉// Parse args, load and start kernel.␊ |
823 | ␉while (1)␊ |
824 | ␉{␊ |
825 | ␉␉bool␉␉tryresume, tryresumedefault, forceresume;␊ |
826 | ␉␉bool␉␉useKernelCache = true; // by default try to use the prelinked kernel␊ |
827 | ␉␉const char␉*val;␊ |
828 | ␉␉int␉␉␉len, ret = -1;␊ |
829 | ␉␉long␉␉flags;␊ |
830 | ␉␉u_int32_t␉sleeptime, time;␊ |
831 | ␉␉void␉␉*binary = (void *)kLoadAddr;␊ |
832 | ␊ |
833 | ␉␉char␉␉bootFile[sizeof(bootInfo->bootFile)];␊ |
834 | ␉␉char␉␉bootFilePath[512];␊ |
835 | ␉␉char␉␉kernelCacheFile[512];␊ |
836 | ␊ |
837 | ␉␉// Initialize globals.␊ |
838 | ␉␉sysConfigValid = false;␊ |
839 | ␉␉gErrors␉␉ = false;␊ |
840 | ␊ |
841 | ␉␉status = getBootOptions(firstRun);␊ |
842 | ␉␉firstRun = false;␊ |
843 | ␉␉if (status == -1) continue;␊ |
844 | ␊ |
845 | ␉␉status = processBootOptions();␊ |
846 | ␉␉// Status == 1 means to chainboot␊ |
847 | ␉␉if ( status ==␉1 ) break;␊ |
848 | ␉␉// Status == -1 means that the config file couldn't be loaded or that gBootVolume is NULL␊ |
849 | ␉␉if ( status == -1 )␊ |
850 | ␉␉{␊ |
851 | ␉␉␉// gBootVolume == NULL usually means the user hit escape.␊ |
852 | ␉␉␉if (gBootVolume == NULL)␊ |
853 | ␉␉␉{␊ |
854 | ␉␉␉␉freeFilteredBVChain(bvChain);␊ |
855 | ␊ |
856 | ␉␉␉␉if (gEnableCDROMRescan)␊ |
857 | ␉␉␉␉{␊ |
858 | ␉␉␉␉␉rescanBIOSDevice(gBIOSDev);␊ |
859 | ␉␉␉␉}␊ |
860 | ␊ |
861 | ␉␉␉␉bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);␊ |
862 | ␉␉␉␉setBootGlobals(bvChain);␊ |
863 | ␉␉␉␉setupDeviceList(&bootInfo->themeConfig);␊ |
864 | ␉␉␉}␊ |
865 | ␉␉␉continue;␊ |
866 | ␉␉}␊ |
867 | ␊ |
868 | ␉␉// Other status (e.g. 0) means that we should proceed with boot.␊ |
869 | ␊ |
870 | ␉␉// Turn off any GUI elements␊ |
871 | ␉␉if ( bootArgs->Video.v_display == GRAPHICS_MODE )␊ |
872 | ␉␉{␊ |
873 | ␉␉␉gui.devicelist.draw = false;␊ |
874 | ␉␉␉gui.bootprompt.draw = false;␊ |
875 | ␉␉␉gui.menu.draw = false;␊ |
876 | ␉␉␉gui.infobox.draw = false;␊ |
877 | ␉␉␉gui.logo.draw = false;␊ |
878 | ␉␉␉drawBackground();␊ |
879 | ␉␉␉updateVRAM();␊ |
880 | ␉␉}␊ |
881 | ␊ |
882 | ␉␉if (platformCPUFeature(CPU_FEATURE_EM64T))␊ |
883 | ␉␉{␊ |
884 | ␉␉␉archCpuType = CPU_TYPE_X86_64;␊ |
885 | ␉␉}␊ |
886 | ␉␉else␊ |
887 | ␉␉{␊ |
888 | ␉␉␉archCpuType = CPU_TYPE_I386;␊ |
889 | ␉␉}␊ |
890 | ␊ |
891 | ␉␉if (getValueForKey(karch, &val, &len, &bootInfo->chameleonConfig))␊ |
892 | ␉␉{␊ |
893 | ␉␉␉if (strncmp(val, "x86_64", sizeof("x86_64") ) == 0)␊ |
894 | ␉␉␉{␊ |
895 | ␉␉␉␉archCpuType = CPU_TYPE_X86_64;␊ |
896 | ␉␉␉}␊ |
897 | ␉␉␉else if (strncmp(val, "i386", sizeof("i386") ) == 0)␊ |
898 | ␉␉␉{␊ |
899 | ␉␉␉␉archCpuType = CPU_TYPE_I386;␊ |
900 | ␉␉␉}␊ |
901 | ␉␉␉else␊ |
902 | ␉␉␉{␊ |
903 | ␉␉␉␉DBG("Incorrect parameter for option 'arch =' , please use x86_64 or i386\n");␊ |
904 | ␉␉␉}␊ |
905 | ␉␉}␊ |
906 | ␊ |
907 | ␉␉if (getValueForKey(kKernelArchKey, &val, &len, &bootInfo->chameleonConfig))␊ |
908 | ␉␉{␊ |
909 | ␉␉␉if (strncmp(val, "i386", sizeof("i386") ) == 0)␊ |
910 | ␉␉␉{␊ |
911 | ␉␉␉␉archCpuType = CPU_TYPE_I386;␊ |
912 | ␉␉␉}␊ |
913 | ␉␉}␊ |
914 | ␊ |
915 | ␉␉// Notify modules that we are attempting to boot␊ |
916 | ␉␉execute_hook("PreBoot", NULL, NULL, NULL, NULL);␊ |
917 | ␊ |
918 | ␉␉//--------------------------------------␊ |
919 | ␉␉getBoolForKey(kSkipKernelPatcher, &skipKernelPatcher, &bootInfo->chameleonConfig);␊ |
920 | ␊ |
921 | ␉␉// kernel patcher␊ |
922 | ␉␉if (!skipKernelPatcher)␊ |
923 | ␉␉{␊ |
924 | ␉␉␉const char␉*key = NULL;␊ |
925 | ␉␉␉int len = 0;␊ |
926 | ␉␉␉setupKernelConfigFile("kernel.plist");␊ |
927 | ␊ |
928 | ␉␉␉// looking at command line for kernel patcher setting and override where needed␊ |
929 | ␉␉␉if (getValueForKey(kKernelBooter_kexts, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
930 | ␉␉␉{␊ |
931 | ␉␉␉␉getBoolForKey(kKernelBooter_kexts, &KernelBooter_kexts, &bootInfo->chameleonConfig);␊ |
932 | ␉␉␉}␊ |
933 | ␉␉␉key = NULL; len = 0;␊ |
934 | ␊ |
935 | ␉␉␉if (getValueForKey(kKernelPm, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
936 | ␉␉␉{␊ |
937 | ␉␉␉␉getBoolForKey(kKernelPm, &KernelPm, &bootInfo->chameleonConfig);␊ |
938 | ␉␉␉}␊ |
939 | ␉␉␉key = NULL; len = 0;␊ |
940 | ␊ |
941 | ␉␉␉if (getValueForKey(kKernelLapicError, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
942 | ␉␉␉{␊ |
943 | ␉␉␉␉getBoolForKey(kKernelLapicError, &KernelLapicError, &bootInfo->chameleonConfig);␊ |
944 | ␉␉␉}␊ |
945 | ␉␉␉key = NULL; len = 0;␊ |
946 | ␊ |
947 | ␉␉␉if (getValueForKey(kKernelLapicVersion, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
948 | ␉␉␉{␊ |
949 | ␉␉␉␉getBoolForKey(kKernelLapicVersion, &KernelLapicVersion, &bootInfo->chameleonConfig);␊ |
950 | ␉␉␉}␊ |
951 | ␉␉␉key = NULL; len = 0;␊ |
952 | ␊ |
953 | ␉␉␉if (getValueForKey(kKernelHaswell, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
954 | ␉␉␉{␊ |
955 | ␉␉␉␉getBoolForKey(kKernelHaswell, &KernelHaswell, &bootInfo->chameleonConfig);␊ |
956 | ␉␉␉}␊ |
957 | ␉␉␉key = NULL; len = 0;␊ |
958 | ␊ |
959 | ␉␉␉if (getValueForKey(kKernelcpuFamily, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
960 | ␉␉␉{␊ |
961 | ␉␉␉␉getBoolForKey(kKernelcpuFamily, &KernelcpuFamily, &bootInfo->chameleonConfig);␊ |
962 | ␉␉␉}␊ |
963 | ␉␉␉key = NULL; len = 0;␊ |
964 | ␊ |
965 | ␉␉␉if (getValueForKey(kKernelSSE3, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
966 | ␉␉␉{␊ |
967 | ␉␉␉␉getBoolForKey(kKernelSSE3, &KernelSSE3, &bootInfo->chameleonConfig);␊ |
968 | ␉␉␉}␊ |
969 | ␉␉}␊ |
970 | ␊ |
971 | #if KEXTPATCH_SUPPORT␊ |
972 | ␉␉//-------------------------------------- kext patcher␊ |
973 | ␉␉getBoolForKey(kSkipKextsPatcher, &skipKextsPatcher, &bootInfo->chameleonConfig);␊ |
974 | ␊ |
975 | ␉␉// kext patcher␊ |
976 | ␉␉if (!skipKextsPatcher)␊ |
977 | ␉␉{␊ |
978 | ␉␉␉const char␉*key = NULL;␊ |
979 | ␉␉␉int␉␉len = 0;␊ |
980 | ␉␉␉setupKextConfigFile("kexts.plist");␊ |
981 | ␊ |
982 | ␉␉␉// looking at command line for kext patcher setting and override where needed␊ |
983 | ␉␉␉if (getValueForKey(kAICPMPatch, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
984 | ␉␉␉{␊ |
985 | ␉␉␉␉getBoolForKey(kAICPMPatch, &AICPMPatch, &bootInfo->chameleonConfig);␊ |
986 | ␉␉␉}␊ |
987 | ␊ |
988 | ␉␉␉key = NULL;␊ |
989 | ␉␉␉len = 0;␊ |
990 | ␉␉␉if (getValueForKey(kNVIDIAWebDrv, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
991 | ␉␉␉{␊ |
992 | ␉␉␉␉getBoolForKey(kNVIDIAWebDrv, &NVIDIAWebDrv, &bootInfo->chameleonConfig);␊ |
993 | ␉␉␉}␊ |
994 | ␊ |
995 | ␉␉␉key = NULL;␊ |
996 | ␉␉␉len = 0;␊ |
997 | ␉␉␉if (getValueForKey(kOrangeIconFixSata, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
998 | ␉␉␉{␊ |
999 | ␉␉␉␉getBoolForKey(kOrangeIconFixSata, &OrangeIconFixSata, &bootInfo->chameleonConfig);␊ |
1000 | ␉␉␉}␊ |
1001 | ␊ |
1002 | ␉␉␉key = NULL;␊ |
1003 | ␉␉␉len = 0;␊ |
1004 | ␉␉␉if (getValueForKey(kTrimEnablerSata, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
1005 | ␉␉␉{␊ |
1006 | ␉␉␉␉getBoolForKey(kTrimEnablerSata, &TrimEnablerSata, &bootInfo->chameleonConfig);␊ |
1007 | ␉␉␉}␊ |
1008 | ␊ |
1009 | ␉␉␉key = NULL;␊ |
1010 | ␉␉␉len = 0;␊ |
1011 | ␉␉␉if (getValueForKey(kAppleRTCPatch, &key, &len, &bootInfo->chameleonConfig) && len > 0)␊ |
1012 | ␉␉␉{␊ |
1013 | ␉␉␉␉getBoolForKey(kAppleRTCPatch, &AppleRTCPatch, &bootInfo->chameleonConfig);␊ |
1014 | ␉␉␉}␊ |
1015 | ␉␉}␊ |
1016 | ␊ |
1017 | ␉␉// -------------------------------------- kext patcher␊ |
1018 | #endif␊ |
1019 | ␊ |
1020 | ␉␉if (gBootVolume->OSisInstaller)␊ |
1021 | ␉␉{␊ |
1022 | ␉␉␉isInstaller = true;␊ |
1023 | ␉␉}␊ |
1024 | ␊ |
1025 | ␉␉if (gBootVolume->OSisMacOSXUpgrade)␊ |
1026 | ␉␉{␊ |
1027 | ␉␉␉isMacOSXUpgrade = true;␊ |
1028 | ␉␉}␊ |
1029 | ␊ |
1030 | ␉␉if (gBootVolume->OSisOSXUpgrade)␊ |
1031 | ␉␉{␊ |
1032 | ␉␉␉isOSXUpgrade = true;␊ |
1033 | ␉␉}␊ |
1034 | ␊ |
1035 | ␉␉if (gBootVolume->OSisRecovery)␊ |
1036 | ␉␉{␊ |
1037 | ␉␉␉isRecoveryHD = true;␊ |
1038 | ␉␉}␊ |
1039 | ␊ |
1040 | ␉␉if ( !isRecoveryHD && !isInstaller && !isMacOSXUpgrade && !isOSXUpgrade )␊ |
1041 | ␉␉{␊ |
1042 | ␉␉␉if (!getBoolForKey (kWake, &tryresume, &bootInfo->chameleonConfig))␊ |
1043 | ␉␉␉{␊ |
1044 | ␉␉␉␉tryresume = true;␊ |
1045 | ␉␉␉␉tryresumedefault = true;␊ |
1046 | ␉␉␉}␊ |
1047 | ␉␉␉else␊ |
1048 | ␉␉␉{␊ |
1049 | ␉␉␉␉tryresumedefault = false;␊ |
1050 | ␉␉␉}␊ |
1051 | ␊ |
1052 | ␉␉␉if (!getBoolForKey (kForceWake, &forceresume, &bootInfo->chameleonConfig))␊ |
1053 | ␉␉␉{␊ |
1054 | ␉␉␉␉forceresume = false;␊ |
1055 | ␉␉␉}␊ |
1056 | ␊ |
1057 | ␉␉␉if (forceresume)␊ |
1058 | ␉␉␉{␊ |
1059 | ␉␉␉␉tryresume = true;␊ |
1060 | ␉␉␉␉tryresumedefault = false;␊ |
1061 | ␉␉␉}␊ |
1062 | ␊ |
1063 | ␉␉␉while (tryresume)␊ |
1064 | ␉␉␉{␊ |
1065 | ␉␉␉␉const char *tmp;␊ |
1066 | ␉␉␉␉BVRef bvr;␊ |
1067 | ␉␉␉␉if (!getValueForKey(kWakeImage, &val, &len, &bootInfo->chameleonConfig))␊ |
1068 | ␉␉␉␉␉val = "/private/var/vm/sleepimage";␊ |
1069 | ␊ |
1070 | ␉␉␉␉// Do this first to be sure that root volume is mounted␊ |
1071 | ␉␉␉␉ret = GetFileInfo(0, val, &flags, &sleeptime);␊ |
1072 | ␊ |
1073 | ␉␉␉␉if ((bvr = getBootVolumeRef(val, &tmp)) == NULL)␊ |
1074 | ␉␉␉␉␉break;␊ |
1075 | ␊ |
1076 | ␉␉␉␉// Can't check if it was hibernation Wake=y is required␊ |
1077 | ␉␉␉␉if (bvr->modTime == 0 && tryresumedefault)␊ |
1078 | ␉␉␉␉␉break;␊ |
1079 | ␊ |
1080 | ␉␉␉␉if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat))␊ |
1081 | ␉␉␉␉␉break;␊ |
1082 | ␊ |
1083 | ␉␉␉␉if (!forceresume && ((sleeptime+3)<bvr->modTime))␊ |
1084 | ␉␉␉␉{␊ |
1085 | #if DEBUG␊ |
1086 | ␉␉␉␉␉printf ("Hibernate image is too old by %d seconds. Use ForceWake=y to override\n",␊ |
1087 | ␉␉␉␉␉␉␉bvr->modTime-sleeptime);␊ |
1088 | #endif␊ |
1089 | ␉␉␉␉␉break;␊ |
1090 | ␉␉␉␉}␊ |
1091 | ␊ |
1092 | ␉␉␉␉HibernateBoot((char *)val);␊ |
1093 | ␉␉␉␉break;␊ |
1094 | ␉␉␉}␊ |
1095 | ␉␉}␊ |
1096 | ␊ |
1097 | ␉␉if (!isRecoveryHD && !isInstaller && !isMacOSXUpgrade && !isOSXUpgrade )␊ |
1098 | ␉␉{␊ |
1099 | ␉␉␉getBoolForKey(kUseKernelCache, &useKernelCache, &bootInfo->chameleonConfig);␊ |
1100 | ␉␉}␊ |
1101 | ␊ |
1102 | ␉␉if (useKernelCache)␊ |
1103 | ␉␉{␊ |
1104 | ␉␉␉do␊ |
1105 | ␉␉␉{␊ |
1106 | ␉␉␉␉// Determine the name of the Kernel Cache␊ |
1107 | ␉␉␉␉if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig))␊ |
1108 | ␉␉␉␉{␊ |
1109 | ␉␉␉␉␉if (val[0] == '\\')␊ |
1110 | ␉␉␉␉␉{␊ |
1111 | ␉␉␉␉␉␉len--;␊ |
1112 | ␉␉␉␉␉␉val++;␊ |
1113 | ␉␉␉␉␉}␊ |
1114 | ␉␉␉␉␉/* FIXME: check len vs sizeof(kernelCacheFile) */␊ |
1115 | ␉␉␉␉␉strlcpy(kernelCacheFile, val, len + 1);␊ |
1116 | ␉␉␉␉}␊ |
1117 | ␉␉␉␉else␊ |
1118 | ␉␉␉␉{␊ |
1119 | ␉␉␉␉␉kernelCacheFile[0] = 0; // Use default kernel cache file␊ |
1120 | ␉␉␉␉}␊ |
1121 | ␊ |
1122 | ␉␉␉␉if (gOverrideKernel && kernelCacheFile[0] == 0)␊ |
1123 | ␉␉␉␉{␊ |
1124 | ␉␉␉␉␉DBG("Using a non default kernel (%s) without specifying 'Kernel Cache' path, KernelCache will not be used\n", bootInfo->bootFile);␊ |
1125 | ␉␉␉␉␉useKernelCache = false;␊ |
1126 | ␉␉␉␉␉break;␊ |
1127 | ␉␉␉␉}␊ |
1128 | ␊ |
1129 | ␉␉␉␉if (gMKextName[0] != 0)␊ |
1130 | ␉␉␉␉{␊ |
1131 | ␉␉␉␉␉DBG("Using a specific MKext Cache (%s), KernelCache will not be used\n", gMKextName);␊ |
1132 | ␉␉␉␉␉useKernelCache = false;␊ |
1133 | ␉␉␉␉␉break;␊ |
1134 | ␉␉␉␉}␊ |
1135 | ␊ |
1136 | ␉␉␉␉if (gBootFileType != kBlockDeviceType)␊ |
1137 | ␉␉␉␉{␊ |
1138 | ␉␉␉␉␉useKernelCache = false;␊ |
1139 | ␉␉␉␉}␊ |
1140 | ␊ |
1141 | ␉␉␉} while(0);␊ |
1142 | ␉␉}␊ |
1143 | ␉␉else␊ |
1144 | ␉␉{␊ |
1145 | ␉␉␉DBG("Kernel Cache using disabled by user.\n");␊ |
1146 | ␉␉}␊ |
1147 | ␊ |
1148 | ␉␉do␊ |
1149 | ␉␉{␊ |
1150 | ␉␉␉if (useKernelCache)␊ |
1151 | ␉␉␉{␊ |
1152 | ␉␉␉␉ret = LoadKernelCache(kernelCacheFile, &binary);␊ |
1153 | ␉␉␉␉if (ret >= 0)␊ |
1154 | ␉␉␉␉{␊ |
1155 | ␉␉␉␉␉break;␊ |
1156 | ␉␉␉␉}␊ |
1157 | ␉␉␉}␊ |
1158 | ␊ |
1159 | ␉␉␉bool bootFileWithDevice = false;␊ |
1160 | ␉␉␉// Check if bootFile start with a device ex: bt(0,0)/Extra/mach_kernel␊ |
1161 | ␉␉␉if (strncmp(bootInfo->bootFile, "bt(", sizeof("bt(") ) == 0 ||␊ |
1162 | ␉␉␉␉strncmp(bootInfo->bootFile, "hd(", sizeof("hd(") ) == 0 ||␊ |
1163 | ␉␉␉␉strncmp(bootInfo->bootFile, "rd(", sizeof("rd(") ) == 0)␊ |
1164 | ␉␉␉{␊ |
1165 | ␉␉␉␉bootFileWithDevice = true;␊ |
1166 | ␉␉␉}␊ |
1167 | ␊ |
1168 | ␉␉␉// bootFile must start with a / if it not start with a device name␊ |
1169 | ␉␉␉if (!bootFileWithDevice && (bootInfo->bootFile)[0] != '/')␊ |
1170 | ␉␉␉{␊ |
1171 | ␉␉␉␉if ( MacOSVerCurrent < MacOSVer2Int("10.10") ) // Mavericks and older␊ |
1172 | ␉␉␉␉{␊ |
1173 | ␉␉␉␉␉snprintf(bootFile, sizeof(bootFile), "/%s", bootInfo->bootFile); // append a leading /␊ |
1174 | ␉␉␉␉}␊ |
1175 | ␉␉␉␉else␊ |
1176 | ␉␉␉␉{␊ |
1177 | ␉␉␉␉␉// Yosemite and newer␊ |
1178 | ␉␉␉␉␉snprintf(bootFile, sizeof(bootFile), kDefaultKernelPathForYos"%s", bootInfo->bootFile); // Yosemite or El Capitan␊ |
1179 | ␉␉␉␉}␊ |
1180 | ␉␉␉}␊ |
1181 | ␉␉␉else␊ |
1182 | ␉␉␉{␊ |
1183 | ␉␉␉␉strlcpy(bootFile, bootInfo->bootFile, sizeof(bootFile));␊ |
1184 | ␉␉␉}␊ |
1185 | ␊ |
1186 | ␉␉␉// Try to load kernel image from alternate locations on boot helper partitions.␊ |
1187 | ␉␉␉ret = -1;␊ |
1188 | ␉␉␉if ((gBootVolume->flags & kBVFlagBooter) && !bootFileWithDevice)␊ |
1189 | ␉␉␉{␊ |
1190 | ␉␉␉␉snprintf(bootFilePath, sizeof(bootFilePath), "com.apple.boot.P%s", bootFile);␊ |
1191 | ␉␉␉␉ret = GetFileInfo(NULL, bootFilePath, &flags, &time);␊ |
1192 | ␉␉␉␉if (ret == -1)␊ |
1193 | ␉␉␉␉{␊ |
1194 | ␉␉␉␉␉snprintf(bootFilePath, sizeof(bootFilePath), "com.apple.boot.R%s", bootFile);␊ |
1195 | ␉␉␉␉␉ret = GetFileInfo(NULL, bootFilePath, &flags, &time);␊ |
1196 | ␉␉␉␉␉if (ret == -1)␊ |
1197 | ␉␉␉␉␉{␊ |
1198 | ␉␉␉␉␉␉snprintf(bootFilePath, sizeof(bootFilePath), "com.apple.boot.S%s", bootFile);␊ |
1199 | ␉␉␉␉␉␉ret = GetFileInfo(NULL, bootFilePath, &flags, &time);␊ |
1200 | ␉␉␉␉␉}␊ |
1201 | ␉␉␉␉}␊ |
1202 | ␉␉␉}␊ |
1203 | ␉␉␉if (ret == -1)␊ |
1204 | ␉␉␉{␊ |
1205 | ␉␉␉␉// No alternate location found, using the original kernel image path.␊ |
1206 | ␉␉␉␉strlcpy(bootFilePath, bootFile, sizeof(bootFilePath));␊ |
1207 | ␉␉␉}␊ |
1208 | ␊ |
1209 | ␉␉␉DBG("Loading kernel from: '%s' (%s)\n", gBootVolume->label, gBootVolume->type_name);␊ |
1210 | ␉␉␉ret = LoadThinFatFile(bootFilePath, &binary);␊ |
1211 | ␉␉␉if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)␊ |
1212 | ␉␉␉{␊ |
1213 | ␉␉␉␉archCpuType = CPU_TYPE_I386;␊ |
1214 | ␉␉␉␉ret = LoadThinFatFile(bootFilePath, &binary);␊ |
1215 | ␉␉␉}␊ |
1216 | ␉␉} while (0);␊ |
1217 | ␊ |
1218 | ␉␉clearActivityIndicator();␊ |
1219 | ␊ |
1220 | #if DEBUG␊ |
1221 | ␉␉printf("Pausing...");␊ |
1222 | ␉␉sleep(8);␊ |
1223 | #endif␊ |
1224 | ␊ |
1225 | ␉␉if (ret <= 0)␊ |
1226 | ␉␉{␊ |
1227 | ␉␉␉printf("Can't find boot file: '%s'\n", bootFile);␊ |
1228 | ␉␉␉sleep(1);␊ |
1229 | ␊ |
1230 | ␉␉␉if (gBootFileType == kNetworkDeviceType)␊ |
1231 | ␉␉␉{␊ |
1232 | ␉␉␉␉// Return control back to PXE. Don't unload PXE base code.␊ |
1233 | ␉␉␉␉gUnloadPXEOnExit = false;␊ |
1234 | ␉␉␉␉break;␊ |
1235 | ␉␉␉}␊ |
1236 | ␉␉␉pause();␊ |
1237 | ␊ |
1238 | ␉␉}␊ |
1239 | ␉␉else␊ |
1240 | ␉␉{␊ |
1241 | ␉␉␉/* Won't return if successful. */␊ |
1242 | ␉␉␉ret = ExecKernel(binary);␊ |
1243 | ␉␉}␊ |
1244 | ␉}␊ |
1245 | ␊ |
1246 | ␉// chainboot␊ |
1247 | ␉if (status == 1)␊ |
1248 | ␉{␊ |
1249 | ␉␉// if we are already in graphics-mode,␊ |
1250 | ␉␉if (getVideoMode() == GRAPHICS_MODE)␊ |
1251 | ␉␉{␊ |
1252 | ␉␉␉setVideoMode( VGA_TEXT_MODE ); // switch back to text mode.␊ |
1253 | ␉␉}␊ |
1254 | ␉}␊ |
1255 | ␊ |
1256 | ␉if ((gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit)␊ |
1257 | ␉{␊ |
1258 | ␉␉nbpUnloadBaseCode();␊ |
1259 | ␉}␊ |
1260 | ␊ |
1261 | #if DEBUG_INTERRUPTS␊ |
1262 | ␉if (interruptsAvailable)␊ |
1263 | ␉{␊ |
1264 | ␉␉DisableInterrupts();␊ |
1265 | ␉}␊ |
1266 | #endif␊ |
1267 | ␊ |
1268 | }␊ |
1269 | ␊ |
1270 | // =========================================================================␊ |
1271 | //␊ |
1272 | void setupBooterArgs()␊ |
1273 | {␊ |
1274 | ␉bool KPRebootOption␉= false; // I don't want this by default ( It makes me angry because I do not see the reason for the panic)+␊ |
1275 | //␉bool HiDPIOption␉= false; // (Disabled by default) 10.8+␊ |
1276 | //␉bool FlagBlackOption␉= false; // (Disabled by default) 10.10+␊ |
1277 | ␊ |
1278 | ␉// OS X Lion 10.7␊ |
1279 | ␉if ( MacOSVerCurrent >= MacOSVer2Int("10.7") ) // Lion and Up!␊ |
1280 | ␉{␊ |
1281 | ␉␉// Pike R. Alpha: Adding a 16 KB log space.␊ |
1282 | ␉␉bootArgs->performanceDataSize␉␉= 0;␊ |
1283 | ␉␉bootArgs->performanceDataStart␉␉= 0;␊ |
1284 | ␊ |
1285 | ␉␉// Pike R. Alpha: AppleKeyStore.kext␊ |
1286 | ␉␉bootArgs->keyStoreDataSize␉␉= 0;␊ |
1287 | ␉␉bootArgs->keyStoreDataStart␉␉= 0;␊ |
1288 | ␊ |
1289 | ␉␉bootArgs->bootMemSize␉␉␉= 0;␊ |
1290 | ␉␉bootArgs->bootMemStart␉␉␉= 0;␊ |
1291 | ␉}␊ |
1292 | ␊ |
1293 | ␉// OS X Mountain Lion 10.8␊ |
1294 | ␉if ( MacOSVerCurrent >= MacOSVer2Int("10.8") ) // Mountain Lion and Up!␊ |
1295 | ␉{␊ |
1296 | ␉␉// cparm␊ |
1297 | ␉␉getBoolForKey(kRebootOnPanic, &KPRebootOption, &bootInfo->chameleonConfig);␊ |
1298 | ␉␉if ( KPRebootOption )␊ |
1299 | ␉␉{␊ |
1300 | ␉␉␉bootArgs->flags |= kBootArgsFlagRebootOnPanic;␊ |
1301 | ␉␉}␊ |
1302 | ␊ |
1303 | ␉␉// cparm␊ |
1304 | ␉␉getBoolForKey(kEnableHiDPI, &HiDPIOption, &bootInfo->chameleonConfig);␊ |
1305 | ␊ |
1306 | ␉␉if ( HiDPIOption )␊ |
1307 | ␉␉{␊ |
1308 | ␉␉␉bootArgs->flags |= kBootArgsFlagHiDPI;␊ |
1309 | ␉␉}␊ |
1310 | ␉}␊ |
1311 | ␊ |
1312 | ␉// OS X Yosemite 10.10␊ |
1313 | ␉if ( MacOSVerCurrent >= MacOSVer2Int("10.10") ) // Yosemite and Up!␊ |
1314 | ␉{␊ |
1315 | ␉␉// Pike R. Alpha␊ |
1316 | ␉␉getBoolForKey(kBlackMode, &FlagBlackOption, &bootInfo->chameleonConfig);␊ |
1317 | ␉␉if ( FlagBlackOption )␊ |
1318 | ␉␉{␊ |
1319 | ␉␉␉// bootArgs->flags |= kBootArgsFlagBlack;␊ |
1320 | ␉␉␉bootArgs->flags |= kBootArgsFlagBlackBg; // Micky1979␊ |
1321 | ␉␉}␊ |
1322 | ␉}␊ |
1323 | ␊ |
1324 | ␉// OS X El Capitan 10.11␊ |
1325 | ␉if ( MacOSVerCurrent >= MacOSVer2Int("10.11") ) // El Capitan, Sierra and High Sierra!␊ |
1326 | ␉{␊ |
1327 | ␉␉// ErmaC␊ |
1328 | ␉␉verbose("\n");␊ |
1329 | ␉␉int␉csrValue;␊ |
1330 | ␊ |
1331 | ␉␉/*␊ |
1332 | ␉␉ * A special BootArgs flag "kBootArgsFlagCSRBoot"␊ |
1333 | ␉␉ * is set in the Recovery or Installation environment.␊ |
1334 | ␉␉ * This flag is kind of overkill by turning off all the protections␊ |
1335 | ␉␉ */␊ |
1336 | ␊ |
1337 | ␉␉if (isRecoveryHD || isInstaller || isOSXUpgrade || isMacOSXUpgrade)␊ |
1338 | ␉␉{␊ |
1339 | ␉␉␉// SIP can be controlled with or without FileNVRAM.kext (Pike R. Alpha)␊ |
1340 | ␉␉␉bootArgs->flags␉|=␉(kBootArgsFlagCSRActiveConfig + kBootArgsFlagCSRConfigMode + kBootArgsFlagCSRBoot + kBootArgsFlagInstallUI);␊ |
1341 | ␉␉}␊ |
1342 | ␉␉else␊ |
1343 | ␉␉{␊ |
1344 | ␉␉␉bootArgs->flags␉|= kBootArgsFlagCSRActiveConfig;␊ |
1345 | ␉␉}␊ |
1346 | ␊ |
1347 | ␉␉// Set limit to 8bit␊ |
1348 | ␉␉if ( getIntForKey(kCsrActiveConfig, &csrValue, &bootInfo->chameleonConfig) && (csrValue >= 0 && csrValue <= 255) )␊ |
1349 | ␉␉{␊ |
1350 | ␉␉␉bootArgs->csrActiveConfig␉= csrValue;␊ |
1351 | ␉␉␉csrInfo(csrValue, 1);␊ |
1352 | ␉␉}␊ |
1353 | ␉␉else␊ |
1354 | ␉␉{␊ |
1355 | ␉␉␉// zenith432␊ |
1356 | ␉␉␉bootArgs->csrActiveConfig␉= 0x67;␊ |
1357 | ␉␉␉csrInfo(0x67, 0);␊ |
1358 | ␊ |
1359 | ␉␉}␊ |
1360 | ␊ |
1361 | ␊ |
1362 | // ===============================================================================␊ |
1363 | ␊ |
1364 | ␉␉bootArgs->csrCapabilities␉␉= CSR_VALID_FLAGS;␊ |
1365 | ␉␉bootArgs->boot_SMC_plimit␉␉= 0;␊ |
1366 | ␉}␊ |
1367 | }␊ |
1368 | ␊ |
1369 | // =========================================================================␊ |
1370 | // ErmaC␊ |
1371 | void csrInfo(int csrValue, bool custom)␊ |
1372 | {␊ |
1373 | #define CSR_BITS 0x080␊ |
1374 | ␊ |
1375 | ␉int mask = CSR_BITS;␊ |
1376 | ␉verbose("System Integrity Protection status: %s ", (csrValue == 0) ? "enabled":"disabled");␊ |
1377 | ␉verbose("(%s Configuration).\nCsrActiveConfig = 0x%02X (", custom ? "Custom":"Default", csrValue);␊ |
1378 | ␊ |
1379 | ␉// Display integer number into binary using bitwise operator␊ |
1380 | ␉((csrValue & 0x020) == 0) ? verbose("0"): verbose("1");␊ |
1381 | ␉while (mask != 0)␊ |
1382 | ␉{␊ |
1383 | ␉␉( ((csrValue & mask) == 0) ? verbose("0"): verbose("1") );␊ |
1384 | ␉␉mask = mask >> 1; // Right Shift␊ |
1385 | ␉}␊ |
1386 | ␉verbose(")\n");␊ |
1387 | ␉if (csrValue != 0)␊ |
1388 | ␉{␊ |
1389 | ␉␉verbose("\nConfiguration:\n");␊ |
1390 | ␉␉verbose("Kext Signing: %s\n", ((csrValue & 0x001) == 0) ? "enabled":"disabled"); /* (1 << 0) Allow untrusted kexts */␊ |
1391 | ␉␉verbose("Filesystem Protections: %s\n", ((csrValue & 0x002) == 0) ? "enabled":"disabled"); /* (1 << 1) Allow unrestricted file system. */␊ |
1392 | ␉␉verbose("Task for PID: %s\n", ((csrValue & 0x004) == 0) ? "enabled":"disabled"); /* (1 << 2) */␊ |
1393 | ␉␉verbose("Debugging Restrictions: %s\n", ((csrValue & 0x008) == 0) ? "enabled":"disabled"); /* (1 << 3) */␊ |
1394 | ␉␉verbose("Apple Internal: %s\n", ((csrValue & 0x010) == 0) ? "enabled":"disabled"); /* (1 << 4) */␊ |
1395 | ␉␉verbose("DTrace Restrictions: %s\n", ((csrValue & 0x020) == 0) ? "enabled":"disabled"); /* (1 << 5) Allow unrestricted dtrace */␊ |
1396 | ␉␉verbose("NVRAM Protections: %s\n", ((csrValue & 0x040) == 0) ? "enabled":"disabled"); /* (1 << 6) Allow unrestricted NVRAM */␊ |
1397 | ␉␉verbose("Device configuration: %s\n", ((csrValue & 0x080) == 0) ? "enabled":"disabled"); /* (1 << 7) Allow device configuration */␊ |
1398 | ␉␉verbose("BaseSystem Verification: %s\n", ((csrValue & 0x100) == 0) ? "enabled":"disabled"); /* (1 << 8) Allow any Recovery OS */␊ |
1399 | ␉}␊ |
1400 | ␉verbose("\n");␊ |
1401 | }␊ |
1402 | ␊ |
1403 | // =========================================================================␊ |
1404 | ␊ |
1405 | /*!␊ |
1406 | ␉Selects a new BIOS device, taking care to update the global state appropriately.␊ |
1407 | */␊ |
1408 | /*␊ |
1409 | static void selectBiosDevice(void)␊ |
1410 | {␊ |
1411 | ␉struct DiskBVMap *oldMap = diskResetBootVolumes(gBIOSDev);␊ |
1412 | ␉CacheReset();␊ |
1413 | ␉diskFreeMap(oldMap);␊ |
1414 | ␉oldMap = NULL;␊ |
1415 | ␊ |
1416 | ␉int dev = selectAlternateBootDevice(gBIOSDev);␊ |
1417 | ␊ |
1418 | ␉BVRef bvchain = scanBootVolumes(dev, 0);␊ |
1419 | ␉BVRef bootVol = selectBootVolume(bvchain);␊ |
1420 | ␉gBootVolume = bootVol;␊ |
1421 | ␉setRootVolume(bootVol);␊ |
1422 | ␉gBIOSDev = dev;␊ |
1423 | }␊ |
1424 | */␊ |
1425 | ␊ |
1426 | // =========================================================================␊ |
1427 | bool checkOSVersion(const char *version)␊ |
1428 | {␊ |
1429 | ␉if ( '\0' != version[4] )␊ |
1430 | ␉{␊ |
1431 | ␉␉return !memcmp(&gMacOSVersion[0], &version[0], 5);␊ |
1432 | ␉}␊ |
1433 | ␉else␊ |
1434 | ␉{␊ |
1435 | ␉␉return !memcmp(&gMacOSVersion[0], &version[0], 4);␊ |
1436 | ␉}␊ |
1437 | }␊ |
1438 | ␊ |
1439 | uint32_t getMacOSVerCurrent()␊ |
1440 | {␊ |
1441 | ␉MacOSVerCurrent = MacOSVer2Int(gBootVolume->OSVersion);␊ |
1442 | ␉return MacOSVerCurrent;␊ |
1443 | }␊ |
1444 | ␊ |
1445 | // =========================================================================␊ |
1446 | unsigned long Adler32(unsigned char *buf, long len)␊ |
1447 | {␊ |
1448 | #define BASE 65521L /* largest prime smaller than 65536 */␊ |
1449 | #define NMAX 5000␊ |
1450 | // NMAX (was 5521) the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1␊ |
1451 | ␊ |
1452 | #define DO1(buf, i)␉{s1 += buf[i]; s2 += s1;}␊ |
1453 | #define DO2(buf, i)␉DO1(buf, i); DO1(buf, i + 1);␊ |
1454 | #define DO4(buf, i)␉DO2(buf, i); DO2(buf, i + 2);␊ |
1455 | #define DO8(buf, i)␉DO4(buf, i); DO4(buf, i + 4);␊ |
1456 | #define DO16(buf)␉DO8(buf, 0); DO8(buf, 8);␊ |
1457 | ␊ |
1458 | ␉int k;␊ |
1459 | ␊ |
1460 | ␉unsigned long s1 = 1; // adler & 0xffff;␊ |
1461 | ␉unsigned long s2 = 0; // (adler >> 16) & 0xffff;␊ |
1462 | ␉unsigned long result;␊ |
1463 | ␊ |
1464 | ␉while (len > 0)␊ |
1465 | ␉{␊ |
1466 | ␉␉k = len < NMAX ? len : NMAX;␊ |
1467 | ␉␉len -= k;␊ |
1468 | ␉␉while (k >= 16)␊ |
1469 | ␉␉{␊ |
1470 | ␉␉␉DO16(buf);␊ |
1471 | ␉␉␉buf += 16;␊ |
1472 | ␉␉␉k -= 16;␊ |
1473 | ␉␉}␊ |
1474 | ␊ |
1475 | ␉␉if (k != 0)␊ |
1476 | ␉␉{␊ |
1477 | ␉␉␉do␊ |
1478 | ␉␉␉{␊ |
1479 | ␉␉␉␉s1 += *buf++;␊ |
1480 | ␉␉␉␉s2 += s1;␊ |
1481 | ␉␉␉} while (--k);␊ |
1482 | ␉␉}␊ |
1483 | ␊ |
1484 | ␉␉s1 %= BASE;␊ |
1485 | ␉␉s2 %= BASE;␊ |
1486 | ␉}␊ |
1487 | ␊ |
1488 | ␉result = (s2 << 16) | s1;␊ |
1489 | ␊ |
1490 | ␉return OSSwapHostToBigInt32(result);␊ |
1491 | }␊ |
1492 | |