overdue-scratch

Author Topic: kernelcache loading  (Read 3740 times)

0 Members and 1 Guest are viewing this topic.

Slice

  • VoodooLabs
  • Posts: 52
kernelcache loading
« on: January 31, 2011, 09:00:08 AM »
I think this workaround may be commited into trunc
file boot.c in boot2 folder
Code: [Select]
/*
 * Default path to kernel cache file
 */
 //Slice - first one for Leopard
#define kDefaultCachePath "/System/Library/Caches/com.apple.kernelcaches/"
#define kDefaultCachePathSnow "/System/Library/Caches/com.apple.kext.caches/Startup/"
...
       if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig) == true) {
            strlcpy(gBootKernelCacheFile, val, len+1);
        } else {
if(gMacOSVersion[3] == '6') {
sprintf(gBootKernelCacheFile, "kernelcache_%s", /*kDefaultCachePathSnow,*/ (archCpuType == CPU_TYPE_I386) ? "i386" : "x86_64");
msglog("search for kernelcache %s\n", gBootKernelCacheFile);
int lnam = sizeof(gBootKernelCacheFile) + 9; //with adler32
//Slice
/*
- but the name is longer .adler32 and more...
kernelcache_i386.E102928C.qSs0
so will opendir and scan for some files
*/
char* name;
long flagsC;
long timeC;
struct dirstuff* cacheDir = opendir(kDefaultCachePathSnow);
while(readdir(cacheDir, (const char**)&name, &flagsC, &timeC) >= 0)
{
if(strstr(name, gBootKernelCacheFile)) //?
{
if(name[lnam] == '.') continue;
sprintf(gBootKernelCacheFile, "%s%s", kDefaultCachePathSnow, name);
verbose("find kernelcache=%s\n", gBootKernelCacheFile);
break;
}
}
}
else //if(gMacOSVersion[3] == '5')
sprintf(gBootKernelCacheFile, "%skernelcache", kDefaultCachePath);
        }

        // Check for cache file.
        trycache = (((gBootMode & kBootModeSafe) == 0) &&
                    !gOverrideKernel &&
                    (gBootFileType == kBlockDeviceType) &&
                    (gMKextName[0] == '\0') &&
                    (gBootKernelCacheFile[0] != '\0'));
verbose("Try cache %s %s\n", gBootKernelCacheFile, trycache?"YES":"NO");

verbose("Loading Darwin %s\n", gMacOSVersion);

        if (trycache) do {

            // if we haven't found the kernel yet, don't use the cache
            ret = GetFileInfo(NULL, bootInfo->bootFile, &flags, &kerneltime);
            if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)) {
                trycache = 0;
                break;
            }
            ret = GetFileInfo(NULL, gBootKernelCacheFile, &flags, &cachetime);
            if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)
                || (cachetime < kerneltime)) {
                trycache = 0;
                verbose("Try cache failed\n");
                break;
            }

Any more propositions around?

EDITED.
Dunno if kernelcache is conflict with /Extra/Extensions
« Last Edit: February 01, 2011, 04:02:15 PM by Slice »

cparm

  • Observer
  • Posts: 12
Re: kernelcache loading
« Reply #1 on: February 09, 2011, 04:13:34 PM »
I think this workaround may be commited into trunc
file boot.c in boot2 folder
Code: [Select]
/*
 * Default path to kernel cache file
 */
 //Slice - first one for Leopard
#define kDefaultCachePath "/System/Library/Caches/com.apple.kernelcaches/"
#define kDefaultCachePathSnow "/System/Library/Caches/com.apple.kext.caches/Startup/"
...
       if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig) == true) {
            strlcpy(gBootKernelCacheFile, val, len+1);
        } else {
if(gMacOSVersion[3] == '6') {
sprintf(gBootKernelCacheFile, "kernelcache_%s", /*kDefaultCachePathSnow,*/ (archCpuType == CPU_TYPE_I386) ? "i386" : "x86_64");
msglog("search for kernelcache %s\n", gBootKernelCacheFile);
int lnam = sizeof(gBootKernelCacheFile) + 9; //with adler32
//Slice
/*
- but the name is longer .adler32 and more...
kernelcache_i386.E102928C.qSs0
so will opendir and scan for some files
*/
char* name;
long flagsC;
long timeC;
struct dirstuff* cacheDir = opendir(kDefaultCachePathSnow);
while(readdir(cacheDir, (const char**)&name, &flagsC, &timeC) >= 0)
{
if(strstr(name, gBootKernelCacheFile)) //?
{
if(name[lnam] == '.') continue;
sprintf(gBootKernelCacheFile, "%s%s", kDefaultCachePathSnow, name);
verbose("find kernelcache=%s\n", gBootKernelCacheFile);
break;
}
}
}
else //if(gMacOSVersion[3] == '5')
sprintf(gBootKernelCacheFile, "%skernelcache", kDefaultCachePath);
        }

        // Check for cache file.
        trycache = (((gBootMode & kBootModeSafe) == 0) &&
                    !gOverrideKernel &&
                    (gBootFileType == kBlockDeviceType) &&
                    (gMKextName[0] == '\0') &&
                    (gBootKernelCacheFile[0] != '\0'));
verbose("Try cache %s %s\n", gBootKernelCacheFile, trycache?"YES":"NO");

verbose("Loading Darwin %s\n", gMacOSVersion);

        if (trycache) do {

            // if we haven't found the kernel yet, don't use the cache
            ret = GetFileInfo(NULL, bootInfo->bootFile, &flags, &kerneltime);
            if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)) {
                trycache = 0;
                break;
            }
            ret = GetFileInfo(NULL, gBootKernelCacheFile, &flags, &cachetime);
            if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)
                || (cachetime < kerneltime)) {
                trycache = 0;
                verbose("Try cache failed\n");
                break;
            }

Any more propositions around?

EDITED.
Dunno if kernelcache is conflict with /Extra/Extensions
Dunno if kernelcache is conflict with /Extra/Extensions
hi slice,
Afaik, in some case yes,
if you use a prelinked kernel, you must add the /Extra/Ext. directory in the kextcache's option while creating the prelinked kernel, otherwise legacy kexts in /Extra/Ext. will not work (of course kextd do not take /Extra/Ext. into consideration), 'normal' kexts in Extra/Ext. seems to work fine even if they are not included in the  prelinked kernel.