Chameleon

Chameleon Commit Details

Date:2011-08-22 19:55:04 (8 years 9 months ago)
Author:Azimutz
Commit:1450
Parents: 1449
Message:Sync these with trunk (r1449).
Changes:
M/branches/azimutz/trunkGraphicsEnablerModules/i386/boot2/boot.c
M/branches/azimutz/Package/i386/boot2/mboot.c
M/branches/azimutz/trunkAutoResolution/i386/boot2/options.c
M/branches/azimutz/Package
M/branches/azimutz/Package/i386/boot2/boot.c
M/branches/azimutz/trunkAutoResolution/i386/boot2/mboot.c
M/branches/azimutz/trunkAutoResolution
M/branches/azimutz/trunkGraphicsEnablerModules/i386/boot2/options.c
M/branches/azimutz/trunkAutoResolution/i386/boot2/boot.c
M/branches/azimutz/Package/i386/boot2/options.c
M/branches/azimutz/trunkGraphicsEnablerModules/i386/boot2/mboot.c
M/branches/azimutz/trunkGraphicsEnablerModules

File differences

branches/azimutz/trunkAutoResolution/i386/boot2/mboot.c
310310
311311
312312
313
313
314
315
314316
315317
316318
continue_at_low_address();
// Now fix our return address.
FIX_RETURN_ADDRESS_USING_FIRST_ARG(multiboot_magic);
// JrCs: this macro should be rewritten because the code generated by XCode 4.x
// change the value of the argument passed as parameter (multiboot_magic)
// FIX_RETURN_ADDRESS_USING_FIRST_ARG(multiboot_magic);
// We can now do just about anything, including return to our caller correctly.
// However, our caller must fix his return address if he wishes to return to
branches/azimutz/trunkAutoResolution/i386/boot2/boot.c
7777
7878
7979
80
8180
8281
8382
......
253252
254253
255254
255
256256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
257387
258388
259389
......
282412
283413
284414
285
286415
287416
288417
289
290418
291419
292420
......
455583
456584
457585
458
459
586
587
460588
461589
462590
463
591
592
464593
465594
466595
......
579708
580709
581710
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647711
648712
649
650
713
714
651715
652
716
653717
654
655
656
657
718
719
720
721
722
658723
659724
660725
661
662
663
664
665
666
726
727
728
667729
668730
669
670
671
672
673
674
675
731
732
733
734
676735
677736
678
737
738
739
740
741
742
743
744
679745
746
747
680748
681
682
683
684
685
686
687
688
689
690
691
692
693
749
750
694751
695752
696
697
698753
699
700
701
702
703
704
705
706
754
755
756
757
758
759
760
761
762
763
764
765
766
767
707768
708
709
710
711
712
713
769
770
771
772
714773
715774
716
717
775
776
718777
719778
720
721
779
780
722781
723782
724783
784
785
786
787
725788
726
789
790
791
727792
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
793
794
751795
752796
753797
......
760804
761805
762806
763
764807
765808
766809
......
768811
769812
770813
814
815
771816
772817
773818
chargRootDevice[512];
chargMKextName[512];
chargMacOSVersion[8];
static chargBootKernelCacheFile[512];
intbvCount = 0, gDeviceCount = 0;
//intmenucount = 0;
longgBootMode; /* defaults to 0 == kBootModeNormal */
return 0;
}
//==========================================================================
// LoadKernelCache - Try to load Kernel Cache.
// return the length of the loaded cache file or -1 on error
long LoadKernelCache(void **binary) {
charkernelCacheFile[512];
charkernelCachePath[512];
const char*val;
int len;
longflags, time, cachetime, kerneltime, exttime, ret=-1;
unsigned long adler32;
// Determine the name of the Kernel Cache
if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig)) {
if (val[0] == '\\')
{
len--;
val++;
}
strlcpy(kernelCacheFile, val, len + 1);
}
else {
// Lion prelink kernel cache file
if (checkOSVersion("10.7")) {
sprintf(kernelCacheFile, "%skernelcache", kDefaultCachePathSnow);
}
// Snow Leopard prelink kernel cache file
else if (checkOSVersion("10.6")) {
sprintf(kernelCacheFile, "kernelcache_%s", (archCpuType == CPU_TYPE_I386)
? "i386" : "x86_64");
int lnam = strlen(kernelCacheFile) + 9; //with adler32
char* name;
long prev_time = 0;
struct dirstuff* cacheDir = opendir(kDefaultCachePathSnow);
while(readdir(cacheDir, (const char**)&name, &flags, &time) >= 0)
{
if (((flags & kFileTypeMask) != kFileTypeDirectory) && time > prev_time
&& strstr(name, kernelCacheFile) && (name[lnam] != '.'))
{
sprintf(kernelCacheFile, "%s%s", kDefaultCachePathSnow, name);
prev_time = time;
}
}
}
else {
// Reset cache name.
bzero(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64);
sprintf(gCacheNameAdler + 64, "%s,%s", gRootDevice, bootInfo->bootFile);
adler32 = Adler32((unsigned char *)gCacheNameAdler, sizeof(gCacheNameAdler));
sprintf(kernelCacheFile, "%s.%08lX", kDefaultCachePathLeo, adler32);
}
}
// kernelCacheFile must start with a /
if (kernelCacheFile[0] != '/') {
char *str = strdup(kernelCacheFile);
if (str == NULL)
return -1;
sprintf(kernelCacheFile, "/%s", str);
free(str);
}
// Check if the kernel cache file exists
ret = -1;
// If boot from a boot helper partition check the kernel cache file on it
if (gBootVolume->flags & kBVFlagBooter) {
sprintf(kernelCachePath, "com.apple.boot.P%s", kernelCacheFile);
ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);
if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))
{
sprintf(kernelCachePath, "com.apple.boot.R%s", kernelCacheFile);
ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);
if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))
{
sprintf(kernelCachePath, "com.apple.boot.S%s", kernelCacheFile);
ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);
if ((flags & kFileTypeMask) != kFileTypeFlat)
ret = -1;
}
}
}
// If not found, use the original kernel cache path.
if (ret == -1) {
strcpy(kernelCachePath, kernelCacheFile);
ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);
if ((flags & kFileTypeMask) != kFileTypeFlat)
ret = -1;
}
// Exit if kernel cache file wasn't found
if (ret == -1) {
verbose("No Kernel Cache File '%s' found\n", kernelCacheFile);
return -1;
}
// Check if the kernel cache file is more recent (mtime)
// than the kernel file or the S/L/E directory
ret = GetFileInfo(NULL, bootInfo->bootFile, &flags, &kerneltime);
// Check if the kernel file is more recent than the cache file
if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeFlat)
&& (kerneltime > cachetime)) {
verbose("Kernel file (%s) is more recent than KernelCache (%s), ignoring KernelCache\n",
bootInfo->bootFile, kernelCacheFile);
return -1;
}
ret = GetFileInfo("/System/Library/", "Extensions", &flags, &exttime);
// Check if the S/L/E directory time is more recent than the cache file
if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)
&& (exttime > cachetime)) {
verbose("/System/Library/Extensions is more recent than KernelCache (%s), ignoring KernelCache\n",
kernelCacheFile);
return -1;
}
// Since the kernel cache file exists and is the most recent try to load it
verbose("Loading kernel cache %s\n", kernelCachePath);
if (checkOSVersion("10.7")) {
ret = LoadThinFatFile(kernelCachePath, binary);
} else {
ret = LoadFile(kernelCachePath);
*binary = (void *)kLoadAddr;
}
return ret; // ret contain the length of the binary
}
//==========================================================================
// This is the entrypoint from real-mode which functions exactly as it did
// before. Multiboot does its own runtime initialization, does some of its
// own things, and then calls common_boot.
bool firstRun = true;
bool instantMenu;
bool rescanPrompt;
char *bootFile;
intstatus;
unsigned intallowBVFlags = kBVFlagSystemVolume | kBVFlagForeignBoot;
unsigned intdenyBVFlags = kBVFlagEFISystem;
unsigned longadler32;
// Set reminder to unload the PXE base code. Neglect to unload
// the base code will result in a hang or kernel panic.
booltryresume, tryresumedefault, forceresume;
booluseKernelCache = false; // by default don't use prelink kernel cache
const char*val;
intlen, trycache, ret = -1;
longflags, cachetime, kerneltime, exttime, sleeptime, time;
intlen, ret = -1;
longflags, sleeptime, time;
void*binary = (void *)kLoadAddr;
// additional variable for testing alternate kernel image locations on boot helper partitions.
charbootFileSpec[512];
char bootFile[sizeof(bootInfo->bootFile)];
charbootFilePath[512];
// Initialize globals.
sysConfigValid = false;
break;
}
// If boot from boot helper partitions and OS is Lion use prelink kernel.
// We need to find a solution to load extra mkext with a prelink kernel.
if (gBootVolume->flags & kBVFlagBooter && checkOSVersion("10.7")) {
verbose("Booting from Lion RAID volume so forcing to use KernelCache\n");
useKernelCache = true;
} else {
getBoolForKey(kUseKernelCache, &useKernelCache, &bootInfo->chameleonConfig);
}
if (useKernelCache) {
if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig)) {
if (val[0] == '\\')
{
len--;
val++;
}
strlcpy(gBootKernelCacheFile, val, len + 1);
}
else {
// Lion prelink kernel cache file
if (checkOSVersion("10.7")) {
sprintf(gBootKernelCacheFile, "%skernelcache", kDefaultCachePathSnow);
}
// Snow Leopard prelink kernel cache file
else if (checkOSVersion("10.6")) {
sprintf(gBootKernelCacheFile, "kernelcache_%s", (archCpuType == CPU_TYPE_I386)
? "i386" : "x86_64");
int lnam = sizeof(gBootKernelCacheFile) + 9; //with adler32
char* name;
long prev_time = 0;
struct dirstuff* cacheDir = opendir(kDefaultCachePathSnow);
while(readdir(cacheDir, (const char**)&name, &flags, &time) >= 0)
{
if (((flags & kFileTypeMask) != kFileTypeDirectory) && time > prev_time
&& strstr(name, gBootKernelCacheFile) && (name[lnam] != '.'))
{
sprintf(gBootKernelCacheFile, "%s%s", kDefaultCachePathSnow, name);
prev_time = time;
}
}
}
else {
// Reset cache name.
bzero(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64);
sprintf(gCacheNameAdler + 64, "%s,%s", gRootDevice, bootInfo->bootFile);
adler32 = Adler32((unsigned char *)gCacheNameAdler, sizeof(gCacheNameAdler));
sprintf(gBootKernelCacheFile, "%s.%08lX", kDefaultCachePathLeo, adler32);
}
}
}
// Check for cache file.
trycache = (useKernelCache &&
((gBootMode & kBootModeSafe) == 0) &&
!gOverrideKernel &&
(gBootFileType == kBlockDeviceType) &&
(gMKextName[0] == '\0') &&
(gBootKernelCacheFile[0] != '\0'));
verbose("Loading Darwin %s\n", gMacOSVersion);
// Check if the kernel cache file exists and is more recent (mtime) than
// the kernel file or the S/L/E directory
useKernelCache = false; // by default don't use prelink kernel cache
getBoolForKey(kUseKernelCache, &useKernelCache, &bootInfo->chameleonConfig);
if (trycache) do {
if (useKernelCache) do {
ret = GetFileInfo(NULL, gBootKernelCacheFile, &flags, &cachetime);
// Check if the kernel cache file exist
if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)) {
trycache = 0;
// If boot from boot helper partitions and OS is Lion use prelink kernel.
// We need to find a solution to load extra mkext with a prelink kernel.
if (gBootVolume->flags & kBVFlagBooter && checkOSVersion("10.7")) {
verbose("Booting from Lion RAID volume so forcing to use KernelCache\n");
useKernelCache = true;
break;
}
ret = GetFileInfo(NULL, bootInfo->bootFile, &flags, &kerneltime);
if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat))
kerneltime = -1;
// Check if the kernel file is more recent than the cache file
if (kerneltime > cachetime) {
trycache = 0;
if ((gBootMode & kBootModeSafe) == 1) {
verbose("Booting in 'Boot Safe' mode, KernelCache will not be used\n");
useKernelCache = false;
break;
}
ret = GetFileInfo("/System/Library/", "Extensions", &flags, &exttime);
if ((ret != 0) && ((flags & kFileTypeMask) != kFileTypeDirectory))
exttime = -1;
// Check if the S/L/E directory time is more recent than the cache file
if (exttime > cachetime) {
trycache = 0;
if (gOverrideKernel) {
verbose("Using a non default kernel (%s), KernelCache will not be used\n",
bootInfo->bootFile);
useKernelCache = false;
break;
}
} while (0);
if (gMKextName[0] != 0) {
verbose("Using a specific MKext Cache (%s), KernelCache will not be used\n",
gMKextName);
useKernelCache = false;
break;
}
if (gBootFileType != kBlockDeviceType)
useKernelCache = false;
} while(0);
do {
if (trycache) {
bootFile = gBootKernelCacheFile;
verbose("Loading kernel cache %s\n", bootFile);
if (checkOSVersion("10.7")) {
ret = LoadThinFatFile(bootFile, &binary);
}
else {
ret = LoadFile(bootFile);
binary = (void *)kLoadAddr;
}
if (useKernelCache) {
ret = LoadKernelCache(&binary);
if (ret >= 0)
break;
verbose("Kernel cache did not load %s\n ", bootFile);
}
if (checkOSVersion("10.7")) {
bootFile = gBootKernelCacheFile;
}
else {
sprintf(bootFile, "/%s", bootInfo->bootFile);
}
bool bootFileWithDevice = false;
// Check if bootFile start with a device ex: bt(0,0)/Extra/mach_kernel
if (strncmp(bootInfo->bootFile,"bt(",3) == 0 ||
strncmp(bootInfo->bootFile,"hd(",3) == 0 ||
strncmp(bootInfo->bootFile,"rd(",3) == 0)
bootFileWithDevice = true;
// bootFile must start with a / if it not start with a device name
if (!bootFileWithDevice && (bootInfo->bootFile)[0] != '/')
sprintf(bootFile, "/%s", bootInfo->bootFile); // append a leading /
else
strlcpy(bootFile, bootInfo->bootFile, sizeof(bootFile));
// Try to load kernel image from alternate locations on boot helper partitions.
sprintf(bootFileSpec, "com.apple.boot.P%s", bootFile);
ret = GetFileInfo(NULL, bootFileSpec, &flags, &time);
if (ret == -1)
{
sprintf(bootFileSpec, "com.apple.boot.R%s", bootFile);
ret = GetFileInfo(NULL, bootFileSpec, &flags, &time);
ret = -1;
if ((gBootVolume->flags & kBVFlagBooter) && !bootFileWithDevice) {
sprintf(bootFilePath, "com.apple.boot.P%s", bootFile);
ret = GetFileInfo(NULL, bootFilePath, &flags, &time);
if (ret == -1)
{
sprintf(bootFileSpec, "com.apple.boot.S%s", bootFile);
ret = GetFileInfo(NULL, bootFileSpec, &flags, &time);
sprintf(bootFilePath, "com.apple.boot.R%s", bootFile);
ret = GetFileInfo(NULL, bootFilePath, &flags, &time);
if (ret == -1)
{
// No alternate location found, using the original kernel image path.
strcpy(bootFileSpec, bootInfo->bootFile);
sprintf(bootFilePath, "com.apple.boot.S%s", bootFile);
ret = GetFileInfo(NULL, bootFilePath, &flags, &time);
}
}
}
if (ret == -1) {
// No alternate location found, using the original kernel image path.
strlcpy(bootFilePath, bootFile,sizeof(bootFilePath));
}
if (checkOSVersion("10.7"))
verbose("Loading kernel %s\n", bootFilePath);
ret = LoadThinFatFile(bootFilePath, &binary);
if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)
{
//Lion, dont load kernel if haz cache
if (!trycache)
{
verbose("Loading kernel %s\n", bootFileSpec);
ret = LoadThinFatFile(bootFileSpec, &binary);
if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)
{
archCpuType = CPU_TYPE_I386;
ret = LoadThinFatFile(bootFileSpec, &binary);
}
}
else ret = 1;
}
else
{
//Snow Leopard or older
verbose("Loading kernel %s\n", bootFileSpec);
ret = LoadThinFatFile(bootFileSpec, &binary);
if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)
{
archCpuType = CPU_TYPE_I386;
ret = LoadThinFatFile(bootFileSpec, &binary);
}
archCpuType = CPU_TYPE_I386;
ret = LoadThinFatFile(bootFilePath, &binary);
}
} while (0);
if (ret <= 0) {
printf("Can't find %s\n", bootFile);
sleep(1);
if (gBootFileType == kNetworkDeviceType) {
gUnloadPXEOnExit = false;
break;
}
pause();
} else {
/* Won't return if successful. */
ret = ExecKernel(binary);
branches/azimutz/trunkAutoResolution/i386/boot2/options.c
12981298
12991299
13001300
1301
1302
1301
13031302
13041303
13051304
1306
1307
1308
13091305
1310
1306
13111307
13121308
1309
1310
1311
13131312
13141313
13151314
......
14251424
14261425
14271426
1428
14291427
1430
1428
1429
14311430
14321431
14331432
gOverrideKernel = false;
if (( kernel = extractKernelName((char **)&cp) )) {
strcpy( bootInfo->bootFile, kernel );
gOverrideKernel = true;
strlcpy( bootInfo->bootFile, kernel, sizeof(bootInfo->bootFile) );
} else {
if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) ) {
strlcpy( bootInfo->bootFile, val, cnt+1 );
if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) {
gOverrideKernel = true;
}
} else {
strcpy( bootInfo->bootFile, kDefaultKernel );
strlcpy( bootInfo->bootFile, kDefaultKernel, sizeof(bootInfo->bootFile) );
}
}
if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) {
gOverrideKernel = true;
}
cntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space
argP = bootArgs->CommandLine;
}
if ( getValueForKey( kMKextCacheKey, &val, &cnt, &bootInfo->bootConfig ) )
{
strlcpy(gMKextName, val, cnt + 1);
}
else
gMKextName[0]=0;
free(configKernelFlags);
free(valueBuffer);
branches/azimutz/trunkGraphicsEnablerModules/i386/boot2/mboot.c
310310
311311
312312
313
313
314
315
314316
315317
316318
continue_at_low_address();
// Now fix our return address.
FIX_RETURN_ADDRESS_USING_FIRST_ARG(multiboot_magic);
// JrCs: this macro should be rewritten because the code generated by XCode 4.x
// change the value of the argument passed as parameter (multiboot_magic)
// FIX_RETURN_ADDRESS_USING_FIRST_ARG(multiboot_magic);
// We can now do just about anything, including return to our caller correctly.
// However, our caller must fix his return address if he wishes to return to
branches/azimutz/trunkGraphicsEnablerModules/i386/boot2/boot.c
7575
7676
7777
78
7978
8079
8180
......
222221
223222
224223
224
225225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
226356
227357
228358
......
251381
252382
253383
254
255384
256385
257386
258
259387
260388
261389
......
366494
367495
368496
369
370
497
498
371499
372500
373501
374
502
503
375504
376505
377506
......
487616
488617
489618
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555619
556620
557
558
621
622
559623
560
624
561625
562
563
564
565
626
627
628
629
630
566631
567632
568633
569
570
571
572
573
574
634
635
636
575637
576638
577
578
579
580
581
582
583
639
640
641
642
584643
585644
586
645
646
647
648
649
650
651
652
587653
654
655
588656
589
590
591
592
593
594
595
596
597
598
599
600
601
657
658
602659
603660
604
605
606661
607
608
609
610
611
612
613
614
662
663
664
665
666
667
668
669
670
671
672
673
674
675
615676
616
617
618
619
620
621
677
678
679
680
622681
623682
624
625
683
684
626685
627686
628
629
687
688
630689
631690
632691
692
693
694
695
633696
634
697
698
699
635700
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
701
702
659703
660704
661705
......
668712
669713
670714
671
672715
673716
674717
......
676719
677720
678721
722
723
679724
680725
681726
chargRootDevice[512];
chargMKextName[512];
chargMacOSVersion[8];
static chargBootKernelCacheFile[512];
intbvCount = 0, gDeviceCount = 0;
//intmenucount = 0;
longgBootMode; /* defaults to 0 == kBootModeNormal */
return 0;
}
//==========================================================================
// LoadKernelCache - Try to load Kernel Cache.
// return the length of the loaded cache file or -1 on error
long LoadKernelCache(void **binary) {
charkernelCacheFile[512];
charkernelCachePath[512];
const char*val;
int len;
longflags, time, cachetime, kerneltime, exttime, ret=-1;
unsigned long adler32;
// Determine the name of the Kernel Cache
if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig)) {
if (val[0] == '\\')
{
len--;
val++;
}
strlcpy(kernelCacheFile, val, len + 1);
}
else {
// Lion prelink kernel cache file
if (checkOSVersion("10.7")) {
sprintf(kernelCacheFile, "%skernelcache", kDefaultCachePathSnow);
}
// Snow Leopard prelink kernel cache file
else if (checkOSVersion("10.6")) {
sprintf(kernelCacheFile, "kernelcache_%s", (archCpuType == CPU_TYPE_I386)
? "i386" : "x86_64");
int lnam = strlen(kernelCacheFile) + 9; //with adler32
char* name;
long prev_time = 0;
struct dirstuff* cacheDir = opendir(kDefaultCachePathSnow);
while(readdir(cacheDir, (const char**)&name, &flags, &time) >= 0)
{
if (((flags & kFileTypeMask) != kFileTypeDirectory) && time > prev_time
&& strstr(name, kernelCacheFile) && (name[lnam] != '.'))
{
sprintf(kernelCacheFile, "%s%s", kDefaultCachePathSnow, name);
prev_time = time;
}
}
}
else {
// Reset cache name.
bzero(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64);
sprintf(gCacheNameAdler + 64, "%s,%s", gRootDevice, bootInfo->bootFile);
adler32 = Adler32((unsigned char *)gCacheNameAdler, sizeof(gCacheNameAdler));
sprintf(kernelCacheFile, "%s.%08lX", kDefaultCachePathLeo, adler32);
}
}
// kernelCacheFile must start with a /
if (kernelCacheFile[0] != '/') {
char *str = strdup(kernelCacheFile);
if (str == NULL)
return -1;
sprintf(kernelCacheFile, "/%s", str);
free(str);
}
// Check if the kernel cache file exists
ret = -1;
// If boot from a boot helper partition check the kernel cache file on it
if (gBootVolume->flags & kBVFlagBooter) {
sprintf(kernelCachePath, "com.apple.boot.P%s", kernelCacheFile);
ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);
if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))
{
sprintf(kernelCachePath, "com.apple.boot.R%s", kernelCacheFile);
ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);
if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))
{
sprintf(kernelCachePath, "com.apple.boot.S%s", kernelCacheFile);
ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);
if ((flags & kFileTypeMask) != kFileTypeFlat)
ret = -1;
}
}
}
// If not found, use the original kernel cache path.
if (ret == -1) {
strcpy(kernelCachePath, kernelCacheFile);
ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);
if ((flags & kFileTypeMask) != kFileTypeFlat)
ret = -1;
}
// Exit if kernel cache file wasn't found
if (ret == -1) {
verbose("No Kernel Cache File '%s' found\n", kernelCacheFile);
return -1;
}
// Check if the kernel cache file is more recent (mtime)
// than the kernel file or the S/L/E directory
ret = GetFileInfo(NULL, bootInfo->bootFile, &flags, &kerneltime);
// Check if the kernel file is more recent than the cache file
if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeFlat)
&& (kerneltime > cachetime)) {
verbose("Kernel file (%s) is more recent than KernelCache (%s), ignoring KernelCache\n",
bootInfo->bootFile, kernelCacheFile);
return -1;
}
ret = GetFileInfo("/System/Library/", "Extensions", &flags, &exttime);
// Check if the S/L/E directory time is more recent than the cache file
if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)
&& (exttime > cachetime)) {
verbose("/System/Library/Extensions is more recent than KernelCache (%s), ignoring KernelCache\n",
kernelCacheFile);
return -1;
}
// Since the kernel cache file exists and is the most recent try to load it
verbose("Loading kernel cache %s\n", kernelCachePath);
if (checkOSVersion("10.7")) {
ret = LoadThinFatFile(kernelCachePath, binary);
} else {
ret = LoadFile(kernelCachePath);
*binary = (void *)kLoadAddr;
}
return ret; // ret contain the length of the binary
}
//==========================================================================
// This is the entrypoint from real-mode which functions exactly as it did
// before. Multiboot does its own runtime initialization, does some of its
// own things, and then calls common_boot.
bool firstRun = true;
bool instantMenu;
bool rescanPrompt;
char *bootFile;
intstatus;
unsigned intallowBVFlags = kBVFlagSystemVolume | kBVFlagForeignBoot;
unsigned intdenyBVFlags = kBVFlagEFISystem;
unsigned longadler32;
// Set reminder to unload the PXE base code. Neglect to unload
// the base code will result in a hang or kernel panic.
booltryresume, tryresumedefault, forceresume;
booluseKernelCache = false; // by default don't use prelink kernel cache
const char*val;
intlen, trycache, ret = -1;
longflags, cachetime, kerneltime, exttime, sleeptime, time;
intlen, ret = -1;
longflags, sleeptime, time;
void*binary = (void *)kLoadAddr;
// additional variable for testing alternate kernel image locations on boot helper partitions.
charbootFileSpec[512];
char bootFile[sizeof(bootInfo->bootFile)];
charbootFilePath[512];
// Initialize globals.
sysConfigValid = false;
break;
}
// If boot from boot helper partitions and OS is Lion use prelink kernel.
// We need to find a solution to load extra mkext with a prelink kernel.
if (gBootVolume->flags & kBVFlagBooter && checkOSVersion("10.7")) {
verbose("Booting from Lion RAID volume so forcing to use KernelCache\n");
useKernelCache = true;
} else {
getBoolForKey(kUseKernelCache, &useKernelCache, &bootInfo->chameleonConfig);
}
if (useKernelCache) {
if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig)) {
if (val[0] == '\\')
{
len--;
val++;
}
strlcpy(gBootKernelCacheFile, val, len + 1);
}
else {
// Lion prelink kernel cache file
if (checkOSVersion("10.7")) {
sprintf(gBootKernelCacheFile, "%skernelcache", kDefaultCachePathSnow);
}
// Snow Leopard prelink kernel cache file
else if (checkOSVersion("10.6")) {
sprintf(gBootKernelCacheFile, "kernelcache_%s", (archCpuType == CPU_TYPE_I386)
? "i386" : "x86_64");
int lnam = sizeof(gBootKernelCacheFile) + 9; //with adler32
char* name;
long prev_time = 0;
struct dirstuff* cacheDir = opendir(kDefaultCachePathSnow);
while(readdir(cacheDir, (const char**)&name, &flags, &time) >= 0)
{
if (((flags & kFileTypeMask) != kFileTypeDirectory) && time > prev_time
&& strstr(name, gBootKernelCacheFile) && (name[lnam] != '.'))
{
sprintf(gBootKernelCacheFile, "%s%s", kDefaultCachePathSnow, name);
prev_time = time;
}
}
}
else {
// Reset cache name.
bzero(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64);
sprintf(gCacheNameAdler + 64, "%s,%s", gRootDevice, bootInfo->bootFile);
adler32 = Adler32((unsigned char *)gCacheNameAdler, sizeof(gCacheNameAdler));
sprintf(gBootKernelCacheFile, "%s.%08lX", kDefaultCachePathLeo, adler32);
}
}
}
// Check for cache file.
trycache = (useKernelCache &&
((gBootMode & kBootModeSafe) == 0) &&
!gOverrideKernel &&
(gBootFileType == kBlockDeviceType) &&
(gMKextName[0] == '\0') &&
(gBootKernelCacheFile[0] != '\0'));
verbose("Loading Darwin %s\n", gMacOSVersion);
// Check if the kernel cache file exists and is more recent (mtime) than
// the kernel file or the S/L/E directory
useKernelCache = false; // by default don't use prelink kernel cache
getBoolForKey(kUseKernelCache, &useKernelCache, &bootInfo->chameleonConfig);
if (trycache) do {
if (useKernelCache) do {
ret = GetFileInfo(NULL, gBootKernelCacheFile, &flags, &cachetime);
// Check if the kernel cache file exist
if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)) {
trycache = 0;
// If boot from boot helper partitions and OS is Lion use prelink kernel.
// We need to find a solution to load extra mkext with a prelink kernel.
if (gBootVolume->flags & kBVFlagBooter && checkOSVersion("10.7")) {
verbose("Booting from Lion RAID volume so forcing to use KernelCache\n");
useKernelCache = true;
break;
}
ret = GetFileInfo(NULL, bootInfo->bootFile, &flags, &kerneltime);
if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat))
kerneltime = -1;
// Check if the kernel file is more recent than the cache file
if (kerneltime > cachetime) {
trycache = 0;
if ((gBootMode & kBootModeSafe) == 1) {
verbose("Booting in 'Boot Safe' mode, KernelCache will not be used\n");
useKernelCache = false;
break;
}
ret = GetFileInfo("/System/Library/", "Extensions", &flags, &exttime);
if ((ret != 0) && ((flags & kFileTypeMask) != kFileTypeDirectory))
exttime = -1;
// Check if the S/L/E directory time is more recent than the cache file
if (exttime > cachetime) {
trycache = 0;
if (gOverrideKernel) {
verbose("Using a non default kernel (%s), KernelCache will not be used\n",
bootInfo->bootFile);
useKernelCache = false;
break;
}
} while (0);
if (gMKextName[0] != 0) {
verbose("Using a specific MKext Cache (%s), KernelCache will not be used\n",
gMKextName);
useKernelCache = false;
break;
}
if (gBootFileType != kBlockDeviceType)
useKernelCache = false;
} while(0);
do {
if (trycache) {
bootFile = gBootKernelCacheFile;
verbose("Loading kernel cache %s\n", bootFile);
if (checkOSVersion("10.7")) {
ret = LoadThinFatFile(bootFile, &binary);
}
else {
ret = LoadFile(bootFile);
binary = (void *)kLoadAddr;
}
if (useKernelCache) {
ret = LoadKernelCache(&binary);
if (ret >= 0)
break;
verbose("Kernel cache did not load %s\n ", bootFile);
}
if (checkOSVersion("10.7")) {
bootFile = gBootKernelCacheFile;
}
else {
sprintf(bootFile, "/%s", bootInfo->bootFile);
}
bool bootFileWithDevice = false;
// Check if bootFile start with a device ex: bt(0,0)/Extra/mach_kernel
if (strncmp(bootInfo->bootFile,"bt(",3) == 0 ||
strncmp(bootInfo->bootFile,"hd(",3) == 0 ||
strncmp(bootInfo->bootFile,"rd(",3) == 0)
bootFileWithDevice = true;
// bootFile must start with a / if it not start with a device name
if (!bootFileWithDevice && (bootInfo->bootFile)[0] != '/')
sprintf(bootFile, "/%s", bootInfo->bootFile); // append a leading /
else
strlcpy(bootFile, bootInfo->bootFile, sizeof(bootFile));
// Try to load kernel image from alternate locations on boot helper partitions.
sprintf(bootFileSpec, "com.apple.boot.P%s", bootFile);
ret = GetFileInfo(NULL, bootFileSpec, &flags, &time);
if (ret == -1)
{
sprintf(bootFileSpec, "com.apple.boot.R%s", bootFile);
ret = GetFileInfo(NULL, bootFileSpec, &flags, &time);
ret = -1;
if ((gBootVolume->flags & kBVFlagBooter) && !bootFileWithDevice) {
sprintf(bootFilePath, "com.apple.boot.P%s", bootFile);
ret = GetFileInfo(NULL, bootFilePath, &flags, &time);
if (ret == -1)
{
sprintf(bootFileSpec, "com.apple.boot.S%s", bootFile);
ret = GetFileInfo(NULL, bootFileSpec, &flags, &time);
sprintf(bootFilePath, "com.apple.boot.R%s", bootFile);
ret = GetFileInfo(NULL, bootFilePath, &flags, &time);
if (ret == -1)
{
// No alternate location found, using the original kernel image path.
strcpy(bootFileSpec, bootInfo->bootFile);
sprintf(bootFilePath, "com.apple.boot.S%s", bootFile);
ret = GetFileInfo(NULL, bootFilePath, &flags, &time);
}
}
}
if (ret == -1) {
// No alternate location found, using the original kernel image path.
strlcpy(bootFilePath, bootFile,sizeof(bootFilePath));
}
if (checkOSVersion("10.7"))
verbose("Loading kernel %s\n", bootFilePath);
ret = LoadThinFatFile(bootFilePath, &binary);
if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)
{
//Lion, dont load kernel if haz cache
if (!trycache)
{
verbose("Loading kernel %s\n", bootFileSpec);
ret = LoadThinFatFile(bootFileSpec, &binary);
if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)
{
archCpuType = CPU_TYPE_I386;
ret = LoadThinFatFile(bootFileSpec, &binary);
}
}
else ret = 1;
}
else
{
//Snow Leopard or older
verbose("Loading kernel %s\n", bootFileSpec);
ret = LoadThinFatFile(bootFileSpec, &binary);
if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)
{
archCpuType = CPU_TYPE_I386;
ret = LoadThinFatFile(bootFileSpec, &binary);
}
archCpuType = CPU_TYPE_I386;
ret = LoadThinFatFile(bootFilePath, &binary);
}
} while (0);
if (ret <= 0) {
printf("Can't find %s\n", bootFile);
sleep(1);
if (gBootFileType == kNetworkDeviceType) {
gUnloadPXEOnExit = false;
break;
}
pause();
} else {
/* Won't return if successful. */
ret = ExecKernel(binary);
branches/azimutz/trunkGraphicsEnablerModules/i386/boot2/options.c
11961196
11971197
11981198
1199
1200
1199
12011200
12021201
12031202
1204
1205
1206
12071203
1208
1204
12091205
12101206
1207
1208
1209
12111210
12121211
12131212
......
13231322
13241323
13251324
1326
13271325
1328
1326
1327
13291328
13301329
13311330
gOverrideKernel = false;
if (( kernel = extractKernelName((char **)&cp) )) {
strcpy( bootInfo->bootFile, kernel );
gOverrideKernel = true;
strlcpy( bootInfo->bootFile, kernel, sizeof(bootInfo->bootFile) );
} else {
if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) ) {
strlcpy( bootInfo->bootFile, val, cnt+1 );
if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) {
gOverrideKernel = true;
}
} else {
strcpy( bootInfo->bootFile, kDefaultKernel );
strlcpy( bootInfo->bootFile, kDefaultKernel, sizeof(bootInfo->bootFile) );
}
}
if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) {
gOverrideKernel = true;
}
cntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space
argP = bootArgs->CommandLine;
}
if ( getValueForKey( kMKextCacheKey, &val, &cnt, &bootInfo->bootConfig ) )
{
strlcpy(gMKextName, val, cnt + 1);
}
else
gMKextName[0]=0;
free(configKernelFlags);
free(valueBuffer);
branches/azimutz/Package/i386/boot2/mboot.c
310310
311311
312312
313
313
314
315
314316
315317
316318
continue_at_low_address();
// Now fix our return address.
FIX_RETURN_ADDRESS_USING_FIRST_ARG(multiboot_magic);
// JrCs: this macro should be rewritten because the code generated by XCode 4.x
// change the value of the argument passed as parameter (multiboot_magic)
// FIX_RETURN_ADDRESS_USING_FIRST_ARG(multiboot_magic);
// We can now do just about anything, including return to our caller correctly.
// However, our caller must fix his return address if he wishes to return to
branches/azimutz/Package/i386/boot2/boot.c
7575
7676
7777
78
7978
8079
8180
......
222221
223222
224223
224
225225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
226356
227357
228358
......
251381
252382
253383
254
255384
256385
257386
258
259387
260388
261389
......
366494
367495
368496
369
370
497
498
371499
372500
373501
374
502
503
375504
376505
377506
......
487616
488617
489618
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555619
556620
557
558
621
622
559623
560
624
561625
562
563
564
565
626
627
628
629
630
566631
567632
568633
569
570
571
572
573
574
634
635
636
575637
576638
577
578
579
580
581
582
583
639
640
641
642
584643
585644
586
645
646
647
648
649
650
651
652
587653
654
655
588656
589
590
591
592
593
594
595
596
597
598
599
600
601
657
658
602659
603660
604
605
606661
607
608
609
610
611
612
613
614
662
663
664
665
666
667
668
669
670
671
672
673
674
675
615676
616
617
618
619
620
621
677
678
679
680
622681
623682
624
625
683
684
626685
627686
628
629
687
688
630689
631690
632691
692
693
694
695
633696
634
697
698
699
635700
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
701
702
659703
660704
661705
......
668712
669713
670714
671
672715
673716
674717
......
676719
677720
678721
722
723
679724
680725
681726
chargRootDevice[512];
chargMKextName[512];
chargMacOSVersion[8];
static chargBootKernelCacheFile[512];
intbvCount = 0, gDeviceCount = 0;
//intmenucount = 0;
longgBootMode; /* defaults to 0 == kBootModeNormal */
return 0;
}
//==========================================================================
// LoadKernelCache - Try to load Kernel Cache.
// return the length of the loaded cache file or -1 on error
long LoadKernelCache(void **binary) {
charkernelCacheFile[512];
charkernelCachePath[512];
const char*val;
int len;
longflags, time, cachetime, kerneltime, exttime, ret=-1;
unsigned long adler32;
// Determine the name of the Kernel Cache
if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig)) {
if (val[0] == '\\')
{
len--;
val++;
}
strlcpy(kernelCacheFile, val, len + 1);
}
else {
// Lion prelink kernel cache file
if (checkOSVersion("10.7")) {
sprintf(kernelCacheFile, "%skernelcache", kDefaultCachePathSnow);
}
// Snow Leopard prelink kernel cache file
else if (checkOSVersion("10.6")) {
sprintf(kernelCacheFile, "kernelcache_%s", (archCpuType == CPU_TYPE_I386)
? "i386" : "x86_64");
int lnam = strlen(kernelCacheFile) + 9; //with adler32
char* name;
long prev_time = 0;
struct dirstuff* cacheDir = opendir(kDefaultCachePathSnow);
while(readdir(cacheDir, (const char**)&name, &flags, &time) >= 0)
{
if (((flags & kFileTypeMask) != kFileTypeDirectory) && time > prev_time
&& strstr(name, kernelCacheFile) && (name[lnam] != '.'))
{
sprintf(kernelCacheFile, "%s%s", kDefaultCachePathSnow, name);
prev_time = time;
}
}
}
else {
// Reset cache name.
bzero(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64);
sprintf(gCacheNameAdler + 64, "%s,%s", gRootDevice, bootInfo->bootFile);
adler32 = Adler32((unsigned char *)gCacheNameAdler, sizeof(gCacheNameAdler));
sprintf(kernelCacheFile, "%s.%08lX", kDefaultCachePathLeo, adler32);
}
}
// kernelCacheFile must start with a /
if (kernelCacheFile[0] != '/') {
char *str = strdup(kernelCacheFile);
if (str == NULL)
return -1;
sprintf(kernelCacheFile, "/%s", str);
free(str);
}
// Check if the kernel cache file exists
ret = -1;
// If boot from a boot helper partition check the kernel cache file on it
if (gBootVolume->flags & kBVFlagBooter) {
sprintf(kernelCachePath, "com.apple.boot.P%s", kernelCacheFile);
ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);
if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))
{
sprintf(kernelCachePath, "com.apple.boot.R%s", kernelCacheFile);
ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);
if ((ret == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))
{
sprintf(kernelCachePath, "com.apple.boot.S%s", kernelCacheFile);
ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);
if ((flags & kFileTypeMask) != kFileTypeFlat)
ret = -1;
}
}
}
// If not found, use the original kernel cache path.
if (ret == -1) {
strcpy(kernelCachePath, kernelCacheFile);
ret = GetFileInfo(NULL, kernelCachePath, &flags, &cachetime);
if ((flags & kFileTypeMask) != kFileTypeFlat)
ret = -1;
}
// Exit if kernel cache file wasn't found
if (ret == -1) {
verbose("No Kernel Cache File '%s' found\n", kernelCacheFile);
return -1;
}
// Check if the kernel cache file is more recent (mtime)
// than the kernel file or the S/L/E directory
ret = GetFileInfo(NULL, bootInfo->bootFile, &flags, &kerneltime);
// Check if the kernel file is more recent than the cache file
if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeFlat)
&& (kerneltime > cachetime)) {
verbose("Kernel file (%s) is more recent than KernelCache (%s), ignoring KernelCache\n",
bootInfo->bootFile, kernelCacheFile);
return -1;
}
ret = GetFileInfo("/System/Library/", "Extensions", &flags, &exttime);
// Check if the S/L/E directory time is more recent than the cache file
if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)
&& (exttime > cachetime)) {
verbose("/System/Library/Extensions is more recent than KernelCache (%s), ignoring KernelCache\n",
kernelCacheFile);
return -1;
}
// Since the kernel cache file exists and is the most recent try to load it
verbose("Loading kernel cache %s\n", kernelCachePath);
if (checkOSVersion("10.7")) {
ret = LoadThinFatFile(kernelCachePath, binary);
} else {
ret = LoadFile(kernelCachePath);
*binary = (void *)kLoadAddr;
}
return ret; // ret contain the length of the binary
}
//==========================================================================
// This is the entrypoint from real-mode which functions exactly as it did
// before. Multiboot does its own runtime initialization, does some of its
// own things, and then calls common_boot.
bool firstRun = true;
bool instantMenu;
bool rescanPrompt;
char *bootFile;
intstatus;
unsigned intallowBVFlags = kBVFlagSystemVolume | kBVFlagForeignBoot;
unsigned intdenyBVFlags = kBVFlagEFISystem;
unsigned longadler32;
// Set reminder to unload the PXE base code. Neglect to unload
// the base code will result in a hang or kernel panic.
booltryresume, tryresumedefault, forceresume;
booluseKernelCache = false; // by default don't use prelink kernel cache
const char*val;
intlen, trycache, ret = -1;
longflags, cachetime, kerneltime, exttime, sleeptime, time;
intlen, ret = -1;
longflags, sleeptime, time;
void*binary = (void *)kLoadAddr;
// additional variable for testing alternate kernel image locations on boot helper partitions.
charbootFileSpec[512];
char bootFile[sizeof(bootInfo->bootFile)];
charbootFilePath[512];
// Initialize globals.
sysConfigValid = false;
break;
}
// If boot from boot helper partitions and OS is Lion use prelink kernel.
// We need to find a solution to load extra mkext with a prelink kernel.
if (gBootVolume->flags & kBVFlagBooter && checkOSVersion("10.7")) {
verbose("Booting from Lion RAID volume so forcing to use KernelCache\n");
useKernelCache = true;
} else {
getBoolForKey(kUseKernelCache, &useKernelCache, &bootInfo->chameleonConfig);
}
if (useKernelCache) {
if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig)) {
if (val[0] == '\\')
{
len--;
val++;
}
strlcpy(gBootKernelCacheFile, val, len + 1);
}
else {
// Lion prelink kernel cache file
if (checkOSVersion("10.7")) {
sprintf(gBootKernelCacheFile, "%skernelcache", kDefaultCachePathSnow);
}
// Snow Leopard prelink kernel cache file
else if (checkOSVersion("10.6")) {
sprintf(gBootKernelCacheFile, "kernelcache_%s", (archCpuType == CPU_TYPE_I386)
? "i386" : "x86_64");
int lnam = sizeof(gBootKernelCacheFile) + 9; //with adler32
char* name;
long prev_time = 0;
struct dirstuff* cacheDir = opendir(kDefaultCachePathSnow);
while(readdir(cacheDir, (const char**)&name, &flags, &time) >= 0)
{
if (((flags & kFileTypeMask) != kFileTypeDirectory) && time > prev_time
&& strstr(name, gBootKernelCacheFile) && (name[lnam] != '.'))
{
sprintf(gBootKernelCacheFile, "%s%s", kDefaultCachePathSnow, name);
prev_time = time;
}
}
}
else {
// Reset cache name.
bzero(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64);
sprintf(gCacheNameAdler + 64, "%s,%s", gRootDevice, bootInfo->bootFile);
adler32 = Adler32((unsigned char *)gCacheNameAdler, sizeof(gCacheNameAdler));
sprintf(gBootKernelCacheFile, "%s.%08lX", kDefaultCachePathLeo, adler32);
}
}
}
// Check for cache file.
trycache = (useKernelCache &&
((gBootMode & kBootModeSafe) == 0) &&
!gOverrideKernel &&
(gBootFileType == kBlockDeviceType) &&
(gMKextName[0] == '\0') &&
(gBootKernelCacheFile[0] != '\0'));
verbose("Loading Darwin %s\n", gMacOSVersion);
// Check if the kernel cache file exists and is more recent (mtime) than
// the kernel file or the S/L/E directory
useKernelCache = false; // by default don't use prelink kernel cache
getBoolForKey(kUseKernelCache, &useKernelCache, &bootInfo->chameleonConfig);
if (trycache) do {
if (useKernelCache) do {
ret = GetFileInfo(NULL, gBootKernelCacheFile, &flags, &cachetime);
// Check if the kernel cache file exist
if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)) {
trycache = 0;
// If boot from boot helper partitions and OS is Lion use prelink kernel.
// We need to find a solution to load extra mkext with a prelink kernel.
if (gBootVolume->flags & kBVFlagBooter && checkOSVersion("10.7")) {
verbose("Booting from Lion RAID volume so forcing to use KernelCache\n");
useKernelCache = true;
break;
}
ret = GetFileInfo(NULL, bootInfo->bootFile, &flags, &kerneltime);
if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat))
kerneltime = -1;
// Check if the kernel file is more recent than the cache file
if (kerneltime > cachetime) {
trycache = 0;
if ((gBootMode & kBootModeSafe) == 1) {
verbose("Booting in 'Boot Safe' mode, KernelCache will not be used\n");
useKernelCache = false;
break;
}
ret = GetFileInfo("/System/Library/", "Extensions", &flags, &exttime);
if ((ret != 0) && ((flags & kFileTypeMask) != kFileTypeDirectory))
exttime = -1;
// Check if the S/L/E directory time is more recent than the cache file
if (exttime > cachetime) {
trycache = 0;
if (gOverrideKernel) {
verbose("Using a non default kernel (%s), KernelCache will not be used\n",
bootInfo->bootFile);
useKernelCache = false;
break;
}
} while (0);
if (gMKextName[0] != 0) {
verbose("Using a specific MKext Cache (%s), KernelCache will not be used\n",
gMKextName);
useKernelCache = false;
break;
}
if (gBootFileType != kBlockDeviceType)
useKernelCache = false;
} while(0);
do {
if (trycache) {
bootFile = gBootKernelCacheFile;
verbose("Loading kernel cache %s\n", bootFile);
if (checkOSVersion("10.7")) {
ret = LoadThinFatFile(bootFile, &binary);
}
else {
ret = LoadFile(bootFile);
binary = (void *)kLoadAddr;
}
if (useKernelCache) {
ret = LoadKernelCache(&binary);
if (ret >= 0)
break;
verbose("Kernel cache did not load %s\n ", bootFile);
}
if (checkOSVersion("10.7")) {
bootFile = gBootKernelCacheFile;
}
else {
sprintf(bootFile, "/%s", bootInfo->bootFile);
}
bool bootFileWithDevice = false;
// Check if bootFile start with a device ex: bt(0,0)/Extra/mach_kernel
if (strncmp(bootInfo->bootFile,"bt(",3) == 0 ||
strncmp(bootInfo->bootFile,"hd(",3) == 0 ||
strncmp(bootInfo->bootFile,"rd(",3) == 0)
bootFileWithDevice = true;
// bootFile must start with a / if it not start with a device name
if (!bootFileWithDevice && (bootInfo->bootFile)[0] != '/')
sprintf(bootFile, "/%s", bootInfo->bootFile); // append a leading /
else
strlcpy(bootFile, bootInfo->bootFile, sizeof(bootFile));
// Try to load kernel image from alternate locations on boot helper partitions.
sprintf(bootFileSpec, "com.apple.boot.P%s", bootFile);
ret = GetFileInfo(NULL, bootFileSpec, &flags, &time);
if (ret == -1)
{
sprintf(bootFileSpec, "com.apple.boot.R%s", bootFile);
ret = GetFileInfo(NULL, bootFileSpec, &flags, &time);
ret = -1;
if ((gBootVolume->flags & kBVFlagBooter) && !bootFileWithDevice) {
sprintf(bootFilePath, "com.apple.boot.P%s", bootFile);
ret = GetFileInfo(NULL, bootFilePath, &flags, &time);
if (ret == -1)
{
sprintf(bootFileSpec, "com.apple.boot.S%s", bootFile);
ret = GetFileInfo(NULL, bootFileSpec, &flags, &time);
sprintf(bootFilePath, "com.apple.boot.R%s", bootFile);
ret = GetFileInfo(NULL, bootFilePath, &flags, &time);
if (ret == -1)
{
// No alternate location found, using the original kernel image path.
strcpy(bootFileSpec, bootInfo->bootFile);
sprintf(bootFilePath, "com.apple.boot.S%s", bootFile);
ret = GetFileInfo(NULL, bootFilePath, &flags, &time);
}
}
}
if (ret == -1) {
// No alternate location found, using the original kernel image path.
strlcpy(bootFilePath, bootFile,sizeof(bootFilePath));
}
if (checkOSVersion("10.7"))
verbose("Loading kernel %s\n", bootFilePath);
ret = LoadThinFatFile(bootFilePath, &binary);
if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)
{
//Lion, dont load kernel if haz cache
if (!trycache)
{
verbose("Loading kernel %s\n", bootFileSpec);
ret = LoadThinFatFile(bootFileSpec, &binary);
if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)
{
archCpuType = CPU_TYPE_I386;
ret = LoadThinFatFile(bootFileSpec, &binary);
}
}
else ret = 1;
}
else
{
//Snow Leopard or older
verbose("Loading kernel %s\n", bootFileSpec);
ret = LoadThinFatFile(bootFileSpec, &binary);
if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)
{
archCpuType = CPU_TYPE_I386;
ret = LoadThinFatFile(bootFileSpec, &binary);
}
archCpuType = CPU_TYPE_I386;
ret = LoadThinFatFile(bootFilePath, &binary);
}
} while (0);
if (ret <= 0) {
printf("Can't find %s\n", bootFile);
sleep(1);
if (gBootFileType == kNetworkDeviceType) {
gUnloadPXEOnExit = false;
break;
}
pause();
} else {
/* Won't return if successful. */
ret = ExecKernel(binary);
branches/azimutz/Package/i386/boot2/options.c
11961196
11971197
11981198
1199
1200
1199
12011200
12021201
12031202
1204
1205
1206
12071203
1208
1204
12091205
12101206
1207
1208
1209
12111210
12121211
12131212
......
13231322
13241323
13251324
1326
13271325
1328
1326
1327
13291328
13301329
13311330
gOverrideKernel = false;
if (( kernel = extractKernelName((char **)&cp) )) {
strcpy( bootInfo->bootFile, kernel );
gOverrideKernel = true;
strlcpy( bootInfo->bootFile, kernel, sizeof(bootInfo->bootFile) );
} else {
if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) ) {
strlcpy( bootInfo->bootFile, val, cnt+1 );
if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) {
gOverrideKernel = true;
}
} else {
strcpy( bootInfo->bootFile, kDefaultKernel );
strlcpy( bootInfo->bootFile, kDefaultKernel, sizeof(bootInfo->bootFile) );
}
}
if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) {
gOverrideKernel = true;
}
cntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space
argP = bootArgs->CommandLine;
}
if ( getValueForKey( kMKextCacheKey, &val, &cnt, &bootInfo->bootConfig ) )
{
strlcpy(gMKextName, val, cnt + 1);
}
else
gMKextName[0]=0;
free(configKernelFlags);
free(valueBuffer);

Archive Download the corresponding diff file

Revision: 1450