Chameleon

Chameleon Svn Source Tree

Root/branches/cparm/i386/boot2/boot.c

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
77typedef struct platform_info {
78char platformName[PLATFORM_NAME_LEN];
79char rootPath[ROOT_PATH_LEN];
80} PlatformInfo;
81
82char *gPlatformName = NULL;
83//char gRootPath[256];
84long gBootMode; /* defaults to 0 == kBootModeNormal */
85bool gOverrideKernel;
86char gBootKernelCacheFile[512];
87char gMKextName[512];
88char gMacOSVersion[8];
89char *gRootDevice = NULL;
90bool uuidSet = false;
91#ifndef OPTION_ROM
92bool gEnableCDROMRescan;
93bool gScanSingleDrive;
94#endif
95
96int bvCount = 0;
97//intmenucount = 0;
98int gDeviceCount = 0;
99
100BVRef bvr;
101BVRef menuBVR;
102BVRef bvChain;
103
104//static void selectBiosDevice(void);
105
106static bool getOSVersion(char *str);
107static void getRootDevice();
108
109#ifdef NBP_SUPPORT
110static bool gUnloadPXEOnExit = false;
111#endif
112
113/*
114 * How long to wait (in seconds) to load the
115 * kernel after displaying the "boot:" prompt.
116 */
117#define kBootErrorTimeout 5
118
119/*
120 * Default path to kernel cache file
121 */
122#define kDefaultCachePath "/System/Library/Caches/com.apple.kext.caches/Startup/kernelcache"
123
124//==========================================================================
125// Zero the BSS.
126
127static void zeroBSS(void)
128{
129extern char _DATA__bss__begin, _DATA__bss__end;
130extern char _DATA__common__begin, _DATA__common__end;
131
132bzero(&_DATA__bss__begin, (&_DATA__bss__end - &_DATA__bss__begin));
133bzero(&_DATA__common__begin, (&_DATA__common__end - &_DATA__common__begin));
134}
135
136//==========================================================================
137// Malloc error function
138
139#ifdef SAFE_MALLOC
140static inline void malloc_error(char *addr, size_t size, const char *file, int line)
141{
142 stop("\nMemory allocation error! Addr=0x%x, Size=0x%x, File=%s, Line=%d\n", (unsigned)addr, (unsigned)size, file, line);
143}
144#else
145static inline void malloc_error(char *addr, size_t size)
146{
147 printf("\nMemory allocation error (0x%x, 0x%x)\n", (unsigned)addr, (unsigned)size);
148 asm volatile ("hlt");
149}
150#endif
151
152//==========================================================================
153//Initializes the runtime. Right now this means zeroing the BSS and initializing malloc.
154//
155void initialize_runtime(void)
156{
157zeroBSS();
158malloc_init(0, 0, 0, malloc_error);
159}
160
161//==========================================================================
162// execKernel - Load the kernel image (mach-o) and jump to its entry point.
163
164static int ExecKernel(void *binary)
165{
166 entry_t kernelEntry;
167 int ret;
168
169 bootArgs->kaddr = bootArgs->ksize = 0;
170
171if(gMacOSVersion[3] <= '6')
172{
173bootArgs->Version = kBootArgsVersion1;
174bootArgs->Revision = gMacOSVersion[3];
175}
176else
177{
178#if kBootArgsVersion > 1
179
180bootArgs->Version = kBootArgsVersion;
181bootArgs->Revision = kBootArgsRevision;
182#else
183bootArgs->Version = 2;
184 bootArgs->Revision = 0;
185#endif
186}
187
188execute_hook("ExecKernel", (void*)binary, NULL, NULL, NULL, NULL, NULL);
189
190 ret = DecodeKernel(binary,
191 &kernelEntry,
192 (char **) &bootArgs->kaddr,
193 (int *)&bootArgs->ksize );
194
195 if ( ret != 0 )
196 return ret;
197
198 // 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.)
199if(gMacOSVersion[3] == '7')
200 reserveKernBootStruct();
201
202 // Load boot drivers from the specifed root path.
203
204 if (!gHaveKernelCache) {
205LoadDrivers("/");
206 }
207
208#if TEXT_SPINNER
209clearActivityIndicator();
210#endif
211
212 if (gErrors) {
213 printf("Errors encountered while starting up the computer.\n");
214 printf("Pausing %d seconds...\n", kBootErrorTimeout);
215 sleep(kBootErrorTimeout);
216 }
217
218execute_hook("md0Ramdisk", NULL, NULL, NULL, NULL, NULL, NULL);
219
220 setupFakeEfi();
221
222 verbose("Starting Darwin %s\n",( archCpuType == CPU_TYPE_I386 ) ? "x86" : "x86_64");
223#ifdef NBP_SUPPORT
224 // Cleanup the PXE base code.
225
226 if ( (gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit ) {
227if ( (ret = nbpUnloadBaseCode()) != nbpStatusSuccess )
228 {
229 printf("nbpUnloadBaseCode error %d\n", (int) ret);
230 sleep(2);
231 }
232 }
233#endif
234 bool wait = false;
235const char *strval = 0;
236int dummysize /*= 0*/;
237
238getBoolForKey(kWaitForKeypressKey, &wait, &bootInfo->bootConfig);
239
240if (getValueForBootKey(bootArgs->CommandLine, "-wait", &strval, &dummysize))
241{
242wait = true;
243
244if (strval && strcmp(strval, "no") == 0) {
245wait = false;
246}
247}
248
249if (wait == true) {
250pause();
251}
252
253if ((execute_hook("GUI_ExecKernel", NULL, NULL, NULL, NULL, NULL, NULL) == 0))
254//if (bootArgs->Video.v_display == VGA_TEXT_MODE)
255{
256setVideoMode( GRAPHICS_MODE, 0 );
257
258#ifndef OPTION_ROM
259
260if(!gVerboseMode)
261{
262drawColorRectangle(0, 0, DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT, 0x01);
263
264uint8_t *appleBootPict;
265uint16_t bootImageWidth = kAppleBootWidth;
266uint16_t bootImageHeight = kAppleBootHeight;
267uint8_t *bootImageData = NULL;
268uint16_t x, y;
269
270unsigned long screen_params[4] = {DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT, 32, 0};// here we store the used screen resolution
271// Prepare the data for the default Apple boot image.
272appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight);
273if (appleBootPict) {
274convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData);
275if (bootImageData) {
276x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2;
277y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2;
278drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);
279free(bootImageData);
280}
281free(appleBootPict);
282}
283
284}
285#endif
286}
287
288setupBooterLog();
289
290 finalizeBootStruct();
291
292if (gMacOSVersion[3] <= '6')
293reserveKernLegacyBootStruct();
294
295
296execute_hook("Kernel Start", (void*)kernelEntry, (void*)bootArgs, NULL, NULL, NULL, NULL);// Notify modules that the kernel is about to be started
297#if UNUSED
298turnOffFloppy();
299#endif
300#if BETA
301#include "smp.h"
302#include "apic.h"
303IMPS_LAPIC_WRITE(LAPIC_LVT1, LAPIC_ICR_DM_NMI);
304#endif
305
306if (gMacOSVersion[3] <= '6') {
307
308// Jump to kernel's entry point. There's no going back now. XXX LEGACY OS XXX
309startprog( kernelEntry, bootArgsLegacy );
310}
311
312outb(0x21, 0xff); /* Maskout all interrupts Pic1 */
313outb(0xa1, 0xff); /* Maskout all interrupts Pic2 */
314
315// Jump to kernel's entry point. There's no going back now. XXX LION XXX
316 startprog( kernelEntry, bootArgs );
317
318 // Not reached
319
320 return 0;
321}
322
323//==========================================================================
324// This is the entrypoint from real-mode which functions exactly as it did
325// before. Multiboot does its own runtime initialization, does some of its
326// own things, and then calls common_boot.
327void boot(int biosdev)
328{
329initialize_runtime();
330// Enable A20 gate before accessing memory above 1Mb.
331enableA20();
332common_boot(biosdev);
333}
334
335//==========================================================================
336// The 'main' function for the booter. Called by boot0 when booting
337// from a block device, or by the network booter.
338//
339// arguments:
340// biosdev - Value passed from boot1/NBP to specify the device
341// that the booter was loaded from.
342//
343// If biosdev is kBIOSDevNetwork, then this function will return if
344// booting was unsuccessful. This allows the PXE firmware to try the
345// next boot device on its list.
346void common_boot(int biosdev)
347{
348 int status;
349 char *bootFile;
350 bool quiet;
351 bool firstRun = true;
352 bool instantMenu;
353#ifndef OPTION_ROM
354 bool rescanPrompt;
355#endif
356 unsigned int allowBVFlags = kBVFlagSystemVolume|kBVFlagForeignBoot;
357 unsigned int denyBVFlags = kBVFlagEFISystem;
358
359#ifdef NBP_SUPPORT
360 // Set reminder to unload the PXE base code. Neglect to unload
361 // the base code will result in a hang or kernel panic.
362 gUnloadPXEOnExit = true;
363#endif
364 // Record the device that the booter was loaded from.
365 gBIOSDev = biosdev & kBIOSDevMask;
366
367
368
369 // Setup VGA text mode.
370 // Not sure if it is safe to call setVideoMode() before the
371 // config table has been loaded. Call video_mode() instead.
372#if DEBUG
373 printf("before video_mode\n");
374#endif
375 video_mode( 2 ); // 80x25 mono text mode.
376#if DEBUG
377 printf("after video_mode\n");
378#endif
379#if !TEXT_SPINNER
380printf("Starting Chameleon ...\n");
381#endif
382
383initBooterLog();
384
385// Initialize boot info structure.
386 initKernBootStruct();
387
388
389 // Scan and record the system's hardware information.
390 scan_platform();
391
392 // First get info for boot volume.
393 scanBootVolumes(gBIOSDev, 0);
394 bvChain = getBVChainForBIOSDev(gBIOSDev);
395 setBootGlobals(bvChain);
396
397 // Load boot.plist config file
398 status = loadSystemConfig(&bootInfo->bootConfig);
399
400 if (getBoolForKey(kQuietBootKey, &quiet, &bootInfo->bootConfig) && quiet) {
401 gBootMode |= kBootModeQuiet;
402 }
403
404 // Override firstRun to get to the boot menu instantly by setting "Instant Menu"=y in system config
405 if (getBoolForKey(kInsantMenuKey, &instantMenu, &bootInfo->bootConfig) && instantMenu) {
406 firstRun = false;
407 }
408
409#ifndef OPTION_ROM
410// Enable touching a single BIOS device only if "Scan Single Drive"=y is set in system config.
411 if (getBoolForKey(kScanSingleDriveKey, &gScanSingleDrive, &bootInfo->bootConfig) && gScanSingleDrive) {
412 gScanSingleDrive = true;
413 }
414
415// Create a list of partitions on device(s).
416 if (gScanSingleDrive)
417{
418scanBootVolumes(gBIOSDev, &bvCount);
419 }
420else
421#endif
422{
423scanDisks(gBIOSDev, &bvCount);
424 }
425
426// Create a separated bvr chain using the specified filters.
427 bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);
428gBootVolume = selectBootVolume(bvChain);
429
430
431// Intialize module system
432if(init_module_system())
433{
434load_all_modules();
435}
436
437 // Loading preboot ramdisk if exists.
438execute_hook("loadPrebootRAMDisk", NULL, NULL, NULL, NULL, NULL, NULL);
439
440#ifndef OPTION_ROM
441
442 // Disable rescan option by default
443 gEnableCDROMRescan = false;
444
445 // Enable it with Rescan=y in system config
446 if (getBoolForKey(kRescanKey, &gEnableCDROMRescan, &bootInfo->bootConfig) && gEnableCDROMRescan) {
447 gEnableCDROMRescan = true;
448 }
449
450 // Ask the user for Rescan option by setting "Rescan Prompt"=y in system config.
451 rescanPrompt = false;
452 if (getBoolForKey(kRescanPromptKey, &rescanPrompt , &bootInfo->bootConfig) && rescanPrompt && biosDevIsCDROM(gBIOSDev)) {
453 gEnableCDROMRescan = promptForRescanOption();
454 }
455#endif
456
457
458
459
460#if DEBUG
461 printf(" Default: %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n", gBootVolume, gBootVolume->biosdev, gBootVolume->part_no, gBootVolume->flags);
462 printf(" bt(0,0): %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n", gBIOSBootVolume, gBIOSBootVolume->biosdev, gBIOSBootVolume->part_no, gBIOSBootVolume->flags);
463 getc();
464#endif
465
466
467
468 setBootGlobals(bvChain);
469
470 // Parse args, load and start kernel.
471 while (1) {
472 const char *val;
473 int len;
474 int trycache = 0;
475 long flags, cachetime, kerneltime, exttime;
476#ifdef BOOT_HELPER_SUPPORT
477long time;
478#endif
479 int ret = -1;
480 void *binary = (void *)kLoadAddr;
481
482 // additional variable for testing alternate kernel image locations on boot helper partitions.
483 char bootFileSpec[512];
484
485 // Initialize globals.
486
487 sysConfigValid = false;
488 gErrors = false;
489
490 status = getBootOptions(firstRun);
491 firstRun = false;
492 if (status == -1) continue;
493
494 status = processBootOptions();
495 // Status==1 means to chainboot
496 if ( status == 1 ) break;
497 // Status==-1 means that the config file couldn't be loaded or that gBootVolume is NULL
498 if ( status == -1 )
499 {
500// gBootVolume == NULL usually means the user hit escape.
501if(gBootVolume == NULL)
502{
503freeFilteredBVChain(bvChain);
504#ifndef OPTION_ROM
505if (gEnableCDROMRescan)
506rescanBIOSDevice(gBIOSDev);
507#endif
508
509bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount);
510setBootGlobals(bvChain);
511}
512continue;
513 }
514
515 // Other status (e.g. 0) means that we should proceed with boot.
516execute_hook("GUI_PreBoot", NULL, NULL, NULL, NULL, NULL, NULL);
517
518// Find out which version mac os we're booting.
519getOSVersion(gMacOSVersion);
520
521if (platformCPUFeature(CPU_FEATURE_EM64T)) {
522archCpuType = CPU_TYPE_X86_64;
523} else {
524archCpuType = CPU_TYPE_I386;
525}
526if (getValueForKey(karch, &val, &len, &bootInfo->bootConfig)) {
527if (strncmp(val, "i386", 4) == 0) {
528archCpuType = CPU_TYPE_I386;
529}
530}
531
532// Notify moduals that we are attempting to boot
533execute_hook("PreBoot", NULL, NULL, NULL, NULL, NULL, NULL);
534
535if (execute_hook("getProductNamePatched", NULL, NULL, NULL, NULL, NULL, NULL) == 0)
536local_readSMBIOS(1); // read smbios Platform Name
537
538getRootDevice();
539
540if (!getValueForBootKey(bootArgs->CommandLine, kIgnorePrelinkKern, &val, &len)) {
541
542if (getValueForKey(kPrelinkKernelKey, &val, &len, &bootInfo->bootConfig)) {
543strlcpy(gBootKernelCacheFile, val, len+1);
544bootInfo->adler32 = 0; //TODO: get the (unsigned long)adler32 value from kernelcache path string
545
546} else {
547if(gMacOSVersion[3] == '7'){
548sprintf(gBootKernelCacheFile, "%s", kDefaultCachePath);
549}
550else if(gMacOSVersion[3] <= '6')
551{
552
553PlatformInfo *platformInfo = malloc(sizeof(PlatformInfo));
554if (platformInfo) {
555
556bzero(platformInfo, sizeof(PlatformInfo));
557
558if (gPlatformName)
559strlcpy(platformInfo->platformName,gPlatformName, sizeof(platformInfo->platformName)+1);
560
561if (gRootDevice) {
562char *rootPath_p = platformInfo->rootPath;
563 int len = strlen(gRootDevice) + 1;
564 if (len > sizeof(platformInfo->rootPath)) {
565 len = sizeof(platformInfo->rootPath);
566 }
567memcpy(rootPath_p, gRootDevice,len);
568
569rootPath_p += len;
570
571 len = strlen(bootInfo->bootFile);
572
573 if ((rootPath_p - platformInfo->rootPath + len) >=
574 sizeof(platformInfo->rootPath)) {
575
576 len = sizeof(platformInfo->rootPath) -
577 (rootPath_p - platformInfo->rootPath);
578 }
579memcpy(rootPath_p, bootInfo->bootFile, len);
580
581}
582
583if (!platformInfo->platformName[0] || !platformInfo->rootPath[0]) {
584platformInfo->platformName[0] = platformInfo->rootPath[0] = 0;
585}
586//memcpy(gRootPath,platformInfo->rootPath, sizeof(platformInfo->rootPath));
587
588
589bootInfo->adler32 = OSSwapHostToBigInt32(local_adler32((unsigned char *)platformInfo, sizeof(*platformInfo)));
590
591free(platformInfo);
592}
593
594DBG("Adler32: %08lX\n",bootInfo->adler32);
595
596if (gMacOSVersion[3] < '6') {
597sprintf(gBootKernelCacheFile, "%s.%08lX", "/System/Library/Caches/com.apple.kernelcaches/kernelcache",bootInfo->adler32);
598ret = GetFileInfo(NULL, gBootKernelCacheFile, &flags, &cachetime);
599if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)) {
600bootInfo->adler32 = 0;
601sprintf(gBootKernelCacheFile, "%s", "/System/Library/Caches/com.apple.kernelcaches/kernelcache");
602}
603} else
604sprintf(gBootKernelCacheFile, "%s_%s.%08lX", kDefaultCachePath, (archCpuType == CPU_TYPE_I386) ? "i386" : "x86_64", bootInfo->adler32); //Snow Leopard
605
606
607}
608
609}
610
611}
612
613// Check for cache file.
614trycache = (((gBootMode & kBootModeSafe) == 0) &&
615!gOverrideKernel &&
616(gBootFileType == kBlockDeviceType) &&
617(gMKextName[0] == '\0') &&
618(gBootKernelCacheFile[0] != '\0'));
619
620verbose("Loading Darwin %s\n", gMacOSVersion);
621
622 if (trycache ) do {
623
624 // if we haven't found the kernel yet, don't use the cache
625 ret = GetFileInfo(NULL, bootInfo->bootFile, &flags, &kerneltime);
626 if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)) {
627 trycache = 0;
628bootInfo->adler32 = 0;
629 break;
630 }
631 ret = GetFileInfo(NULL, gBootKernelCacheFile, &flags, &cachetime);
632 if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)
633 || (cachetime < kerneltime)) {
634trycache = 0;
635bootInfo->adler32 = 0;
636break;
637 }
638 ret = GetFileInfo("/System/Library/", "Extensions", &flags, &exttime);
639 if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)
640 && (cachetime < exttime)) {
641 trycache = 0;
642bootInfo->adler32 = 0;
643 break;
644 }
645 if (kerneltime > exttime) {
646 exttime = kerneltime;
647 }
648 if (cachetime != (exttime + 1)) {
649 trycache = 0;
650bootInfo->adler32 = 0;
651 break;
652 }
653 } while (0);
654
655 do {
656 if (trycache) {
657 bootFile = gBootKernelCacheFile;
658 verbose("Loading kernel cache %s\n", bootFile);
659if (gMacOSVersion[3] == '7') {
660ret = LoadThinFatFile(bootFile, &binary);
661if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)
662{
663archCpuType = CPU_TYPE_I386;
664ret = LoadThinFatFile(bootFile, &binary);
665}
666} else {
667ret = LoadFile(bootFile);
668binary = (void *)kLoadAddr;
669}
670
671 if (ret >= 0) {
672 break;
673 }
674
675 }
676bootInfo->adler32 = 0;
677 bootFile = bootInfo->bootFile;
678#ifdef BOOT_HELPER_SUPPORT
679
680 // Try to load kernel image from alternate locations on boot helper partitions.
681 sprintf(bootFileSpec, "com.apple.boot.P/%s", bootFile);
682 ret = GetFileInfo(NULL, bootFileSpec, &flags, &time);
683 if (ret == -1)
684 {
685sprintf(bootFileSpec, "com.apple.boot.R/%s", bootFile);
686ret = GetFileInfo(NULL, bootFileSpec, &flags, &time);
687if (ret == -1)
688{
689sprintf(bootFileSpec, "com.apple.boot.S/%s", bootFile);
690ret = GetFileInfo(NULL, bootFileSpec, &flags, &time);
691if (ret == -1)
692{
693// Not found any alternate locations, using the original kernel image path.
694strcpy(bootFileSpec, bootFile);
695}
696}
697 }
698#else
699strcpy(bootFileSpec, bootFile);
700#endif
701
702 verbose("Loading kernel %s\n", bootFileSpec);
703 ret = LoadThinFatFile(bootFileSpec, &binary);
704 if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)
705 {
706archCpuType = CPU_TYPE_I386;
707ret = LoadThinFatFile(bootFileSpec, &binary);
708 }
709
710 } while (0);
711#if TEXT_SPINNER
712 clearActivityIndicator();
713#endif
714
715#if DEBUG
716 printf("Pausing...");
717 sleep(8);
718#endif
719
720 if (ret <= 0) {
721printf("Can't find %s\n", bootFile);
722
723sleep(1);
724#ifdef NBP_SUPPORT
725 if (gBootFileType == kNetworkDeviceType) {
726 // Return control back to PXE. Don't unload PXE base code.
727 gUnloadPXEOnExit = false;
728 break;
729 }
730#endif
731 } else {
732 /* Won't return if successful. */
733 ret = ExecKernel(binary);
734 }
735 }
736
737 // chainboot
738 if (status==1) {
739if (getVideoMode() == GRAPHICS_MODE) {// if we are already in graphics-mode,
740setVideoMode(VGA_TEXT_MODE, 0);// switch back to text mode
741}
742 }
743#ifdef NBP_SUPPORT
744 if ((gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit) {
745nbpUnloadBaseCode();
746 }
747#endif
748}
749
750
751// Maximum config table value size
752#define VALUE_SIZE 2048
753static void getRootDevice()
754{
755const char *val = 0;
756 int cnt = 0;
757
758if (getValueForKey(kBootUUIDKey, &val, &cnt, &bootInfo->bootConfig)){
759uuidSet = true;
760
761 } else {
762if (getValueForBootKey(bootArgs->CommandLine, kRootDeviceKey, &val, &cnt)) {
763if (*val == '*' && *(val + 1) != '/' && *(val + 1) != 'u') {
764val += 1; //skip the *
765uuidSet = true;
766
767} else if (*val == '*' && *(val + 1) == 'u') {
768
769if ( getValueForKey( kBootDeviceKey, &val, &cnt, &bootInfo->bootConfig))
770uuidSet = true;
771
772}
773} else {
774#ifdef BOOT_HELPER_SUPPORT
775//
776// Try an alternate method for getting the root UUID on boot helper partitions.
777//
778if (gBootVolume->flags & kBVFlagBooter)
779{
780if((loadHelperConfig(&bootInfo->helperConfig) == 0)
781 && getValueForKey(kHelperRootUUIDKey, &val, &cnt, &bootInfo->helperConfig) )
782{
783getValueForKey(kHelperRootUUIDKey, &val, &cnt, &bootInfo->helperConfig);
784uuidSet = true;
785goto out;
786}
787}
788#endif
789
790if ( getValueForKey( kBootDeviceKey, &val, &cnt, &bootInfo->bootConfig)) {
791extern int ArgCntRemaining;
792uuidSet = false;
793char * valueBuffer;
794valueBuffer = malloc(VALUE_SIZE);
795char * argP = bootArgs->CommandLine;
796valueBuffer[0] = '*';
797cnt++;
798strlcpy(valueBuffer + 1, val, cnt);
799if (!copyArgument( kRootDeviceKey, valueBuffer, cnt, &argP, &ArgCntRemaining))
800{
801free(valueBuffer);
802printf("Error: boot arguments too long, unable to set root device !!");
803getc();
804return;
805}
806free(valueBuffer);
807goto out;
808}
809
810if (gBootVolume->fs_getuuid && gBootVolume->fs_getuuid (gBootVolume, bootInfo->uuidStr) == 0) {
811verbose("Setting boot-uuid to: %s\n", bootInfo->uuidStr);
812uuidSet = true;
813gRootDevice = bootInfo->uuidStr;
814return;
815}
816
817}
818}
819
820out:
821verbose("Setting %s to: %s\n", uuidSet ? kBootUUIDKey : "root device", (char* )val);
822gRootDevice = (char* )val;
823}
824
825static bool getOSVersion(char *str)
826{
827bool valid = false;
828config_file_t systemVersion;
829const char *val;
830int len;
831
832if (!loadConfigFile("System/Library/CoreServices/SystemVersion.plist", &systemVersion))
833{
834valid = true;
835}
836else if (!loadConfigFile("System/Library/CoreServices/ServerVersion.plist", &systemVersion))
837{
838valid = true;
839}
840
841if (valid)
842{
843if (getValueForKey(kProductVersion, &val, &len, &systemVersion))
844{
845// getValueForKey uses const char for val
846// so copy it and trim
847*str = '\0';
848strncat(str, val, MIN(len, 4));
849}
850else
851valid = false;
852}
853
854return valid;
855}
856
857unsigned long
858local_adler32( unsigned char * buffer, long length )
859{
860 long cnt;
861 unsigned long result, lowHalf, highHalf;
862
863 lowHalf = 1;
864 highHalf = 0;
865
866for ( cnt = 0; cnt < length; cnt++ )
867 {
868 if ((cnt % 5000) == 0)
869 {
870 lowHalf %= 65521L;
871 highHalf %= 65521L;
872 }
873
874 lowHalf += buffer[cnt];
875 highHalf += lowHalf;
876 }
877
878lowHalf %= 65521L;
879highHalf %= 65521L;
880
881result = (highHalf << 16) | lowHalf;
882
883return result;
884}
885

Archive Download this file

Revision: 789