Chameleon

Chameleon Commit Details

Date:2011-07-04 19:22:29 (12 years 9 months ago)
Author:Evan Lojewski
Commit:1103
Parents: 1102
Message:com.apple.Boot.plist is now loaded in a more sane way. Modified kernelcache support.
Changes:
M/trunk/i386/boot2/drivers.c
M/trunk/i386/boot2/boot.c
M/trunk/i386/boot2/boot.h
M/trunk/i386/boot2/modules.c
M/trunk/i386/libsaio/saio_internal.h
M/trunk/i386/boot2/options.c
M/trunk/i386/libsaio/stringTable.c
M/trunk/i386/libsaio/sys.c

File differences

trunk/i386/libsaio/sys.c
335335
336336
337337
338
338339
339340
340341
for (idx = len; idx && (name[idx] != '/' && name[idx] != '\\'); idx--) {}
if (idx == 0) {
if(name[idx] == '/' || name[idx] == '\\') ++name; // todo: ensure other functions handel \ properly
gMakeDirSpec[0] = '/';
gMakeDirSpec[1] = '\0';
} else {
trunk/i386/libsaio/stringTable.c
2828
2929
3030
31
3132
3233
3334
......
607608
608609
609610
610
611
612611
613
614
615
616612
617613
618614
......
639635
640636
641637
642
638
643639
644640
645641
646642
647
643
648644
649645
650646
651647
652
653
654
655
656648
657649
658650
#include "bootstruct.h"
#include "libsaio.h"
#include "boot.h"
#include "xml.h"
extern char *Language;
int loadSystemConfig(config_file_t *config)
{
char *dirspec[] = {
"/Extra/com.apple.Boot.plist",
"bt(0,0)/Extra/com.apple.Boot.plist",
"/Library/Preferences/SystemConfiguration/com.apple.Boot.plist",
"/com.apple.boot.P/Library/Preferences/SystemConfiguration/com.apple.Boot.plist",
"/com.apple.boot.R/Library/Preferences/SystemConfiguration/com.apple.Boot.plist",
"/com.apple.boot.S/Library/Preferences/SystemConfiguration/com.apple.Boot.plist"
};
int i, fd, count, ret=-1;
return ret;
}
/* loadOverrideConfig
/* loadChameleonConfig
*
* Returns 0 - successful.
* -1 - unsuccesful.
*/
int loadOverrideConfig(config_file_t *config)
int loadChameleonConfig(config_file_t *config)
{
char *dirspec[] = {
"rd(0,0)/Extra/com.apple.Boot.plist",
"/Extra/com.apple.Boot.plist",
"/Library/Preferences/SystemConfiguration/com.apple.Boot.plist",
"/com.apple.boot.P/Library/Preferences/SystemConfiguration/com.apple.Boot.plist",
"/com.apple.boot.R/Library/Preferences/SystemConfiguration/com.apple.Boot.plist",
"/com.apple.boot.S/Library/Preferences/SystemConfiguration/com.apple.Boot.plist"
};
int i, fd, count, ret=-1;
trunk/i386/libsaio/saio_internal.h
162162
163163
164164
165
165
166166
167167
168168
extern int loadConfigFile(const char *configFile, config_file_t *configBuff);
extern int loadSystemConfig(config_file_t *configBuff);
extern int loadHelperConfig(config_file_t *configBuff);
extern int loadOverrideConfig(config_file_t *configBuff);
extern int loadChameleonConfig(config_file_t *configBuff);
extern char * newString(const char *oldString);
extern char * getNextArg(char ** ptr, char * val);
extern int ParseXMLFile( char * buffer, TagPtr * dict );
trunk/i386/boot2/drivers.c
209209
210210
211211
212
213
214
212
215213
216
217
214
215
216
217
218
219
220
218221
219
222
220223
221224
222
223
225
226
227
228
229
230
224231
225232
226
227
228
229
230
231
233
234
232235
233
234
236
237
238
239
240
241
235242
243
244
245
246
247
248
249
236250
237
238
239
240
241
242
243251
244252
245253
}
}
}
// Also try to load Extensions from boot helper partitions.
if (gBootVolume->flags & kBVFlagBooter)
if(!gHaveKernelCache)
{
strcpy(dirSpecExtra, "/com.apple.boot.P/System/Library/");
if (FileLoadDrivers(dirSpecExtra, 0) != 0)
// Don't load main driver (from /System/Library/Extentions) if gHaveKernelCache is set.
// since these drivers will already be in the kernel cache.
// NOTE: when gHaveKernelCache, xnu cannot (by default) load *any* extra kexts from the bootloader.
// The /Extra code is not disabled in this case due to a kernel patch that allows for this to happen.
// Also try to load Extensions from boot helper partitions.
if (gBootVolume->flags & kBVFlagBooter)
{
strcpy(dirSpecExtra, "/com.apple.boot.R/System/Library/");
strcpy(dirSpecExtra, "/com.apple.boot.P/System/Library/");
if (FileLoadDrivers(dirSpecExtra, 0) != 0)
{
strcpy(dirSpecExtra, "/com.apple.boot.S/System/Library/");
FileLoadDrivers(dirSpecExtra, 0);
strcpy(dirSpecExtra, "/com.apple.boot.R/System/Library/");
if (FileLoadDrivers(dirSpecExtra, 0) != 0)
{
strcpy(dirSpecExtra, "/com.apple.boot.S/System/Library/");
FileLoadDrivers(dirSpecExtra, 0);
}
}
}
}
if (gMKextName[0] != '\0')
{
verbose("LoadDrivers: Loading from [%s]\n", gMKextName);
if ( LoadDriverMKext(gMKextName) != 0 )
if (gMKextName[0] != '\0')
{
error("Could not load %s\n", gMKextName);
return -1;
verbose("LoadDrivers: Loading from [%s]\n", gMKextName);
if ( LoadDriverMKext(gMKextName) != 0 )
{
error("Could not load %s\n", gMKextName);
return -1;
}
}
else
{
strcpy(gExtensionsSpec, dirSpec);
strcat(gExtensionsSpec, "System/Library/");
FileLoadDrivers(gExtensionsSpec, 0);
}
}
else
{
strcpy(gExtensionsSpec, dirSpec);
strcat(gExtensionsSpec, "System/Library/");
FileLoadDrivers(gExtensionsSpec, 0);
}
}
else
{
trunk/i386/boot2/boot.c
9393
9494
9595
96
97
98
99
100
101
10296
10397
10498
......
155149
156150
157151
158
159
152
153
160154
161155
162156
......
265259
266260
267261
268
262
269263
270264
271265
......
300294
301295
302296
303
297
304298
305299
306300
......
438432
439433
440434
441
435
436
442437
443438
444439
......
489484
490485
491486
492
493
494
487
488
489
490
491
492
495493
496494
497495
......
550548
551549
552550
553
554
555551
556
552
553
557554
558555
559556
557
560558
561559
562560
......
595593
596594
597595
598
596
599597
600598
601599
*/
#define kBootErrorTimeout 5
/*
* Default path to kernel cache file
*/
//Slice - first one for Leopard
#define kDefaultCachePathLeo "/System/Library/Caches/com.apple.kernelcaches/"
#define kDefaultCachePathSnow "/System/Library/Caches/com.apple.kext.caches/Startup/"
//==========================================================================
// Zero the BSS.
execute_hook("DecodedKernel", (void*)binary, NULL, NULL, NULL);
// Load boot drivers from the specifed root path.
if (!gHaveKernelCache)
LoadDrivers("/");
//if (!gHaveKernelCache)
LoadDrivers("/");
clearActivityIndicator();
bool firstRun = true;
bool instantMenu;
bool rescanPrompt;
unsigned int allowBVFlags = kBVFlagSystemVolume|kBVFlagForeignBoot;
unsigned int allowBVFlags = kBVFlagSystemVolume | kBVFlagForeignBoot;
unsigned int denyBVFlags = kBVFlagEFISystem;
// Set reminder to unload the PXE base code. Neglect to unload
setBootGlobals(bvChain);
// Load boot.plist config file
status = loadSystemConfig(&bootInfo->bootConfig);
status = loadChameleonConfig(&bootInfo->overrideConfig);
if (getBoolForKey(kQuietBootKey, &quiet, &bootInfo->bootConfig) && quiet) {
gBootMode |= kBootModeQuiet;
archCpuType = CPU_TYPE_I386;
}
}
//archCpuType = CPU_TYPE_I386;
// Notify moduals that we are attempting to boot
execute_hook("PreBoot", NULL, NULL, NULL, NULL);
getBoolForKey(kUseKernelCache, &usecache, &bootInfo->bootConfig);
if(usecache) {
if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig)) {
//ugly hack. FIX THIS
if(strcmp(val, "\\kernelcache") == 0) strlcpy(gBootKernelCacheFile, "kernelcache", sizeof("kernelcache"));
else strlcpy(gBootKernelCacheFile, val, len+1);
if(val[0] == '\\')
{
len--;
val++;
}
strlcpy(gBootKernelCacheFile, val, len+1);
}
else {
//Lion
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)) {
if(ret != 0) kerneltime = 0;
else if ((flags & kFileTypeMask) != kFileTypeFlat) {
trycache = 0;
break;
}
ret = GetFileInfo(NULL, gBootKernelCacheFile, &flags, &cachetime);
if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)
|| (cachetime < kerneltime)) {
if (ret >= 0)
break;
verbose("Kernel cache did not loaded %s\n ", bootFile);
verbose("Kernel cache did not load %s\n ", bootFile);
}
bootFile = bootInfo->bootFile;
trunk/i386/boot2/boot.h
3030
3131
3232
33
34
35
3336
37
38
39
40
41
42
43
44
3445
3546
3647
#define __BOOT2_BOOT_H
#include "libsaio.h"
/*
* Paths used by chameleon
*/
//kernel cache
#define kDefaultCachePathLeo "/System/Library/Caches/com.apple.kernelcaches/"
#define kDefaultCachePathSnow "/System/Library/Caches/com.apple.kext.caches/Startup/"
// Lion installer
#define kLionInstallerDataFolder "/Mac OS X Install Data/"
#define kLionInstallerPlist kLionInstallerDataFolder "com.apple.Boot.plist"
/*
* Keys used in system Boot.plist
*/
trunk/i386/boot2/modules.c
177177
178178
179179
180
180
181181
182182
183183
......
455455
456456
457457
458
458459
459460
460461
......
475476
476477
477478
478
479
479480
480481
481482
if(module_start && module_start != (void*)0xFFFFFFFF)
{
// Notify the system that it was laoded
module_loaded(module, NULL, NULL, 0, 0 /*moduleName, moduleVersion, moduleCompat*/);
module_loaded(module, NULL, NULL, 0, 0 /*moduleName, NULL, moduleVersion, moduleCompat*/);
(*module_start)();// Start the module
DBG("Module %s Loaded.\n", module); DBGPAUSE();
}
case LC_LOAD_DYLIB:
case LC_LOAD_WEAK_DYLIB ^ LC_REQ_DYLD:
// Required modules
dylibCommand = binary + binaryIndex;
char* module = binary + binaryIndex + ((UInt32)*((UInt32*)&dylibCommand->dylib.name));
// Possible enhancments: verify version
break;
case LC_ID_DYLIB:
dylibCommand = binary + binaryIndex;
//dylibCommand = binary + binaryIndex;
/*moduleName =binary + binaryIndex + ((UInt32)*((UInt32*)&dylibCommand->dylib.name));
moduleVersion =dylibCommand->dylib.current_version;
moduleCompat =dylibCommand->dylib.compatibility_version;
trunk/i386/boot2/options.c
11831183
11841184
11851185
1186
11871186
1188
1187
11891188
11901189
11911190
......
12401239
12411240
12421241
1243
1242
12441243
12451244
12461245
12471246
12481247
1248
12491249
12501250
12511251
// Load com.apple.Boot.plist from the selected volume
// and use its contents to override default bootConfig.
// This is not a mandatory opeartion anymore.
loadOverrideConfig(&bootInfo->overrideConfig);
loadSystemConfig(&bootInfo->overrideConfig);
// Use the kernel name specified by the user, or fetch the name
// in the config table, or use the default if not specified.
uuidSet = true;
}
}
if (!uuidSet && gBootVolume->fs_getuuid && gBootVolume->fs_getuuid (gBootVolume, uuidStr) == 0) {
verbose("Setting boot-uuid to: %s\n", uuidStr);
copyArgument(kBootUUIDKey, uuidStr, strlen(uuidStr), &argP, &cntRemaining);
uuidSet = true;
}
}
if (!processBootArgument(kRootDeviceKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gRootDevice)) {

Archive Download the corresponding diff file

Revision: 1103