Chameleon

Chameleon Commit Details

Date:2010-10-04 04:39:48 (8 years 5 months ago)
Author:Evan Lojewski
Commit:569
Parents: 568
Message:NBI postboot installer + recovery mode module (as usual, untested)
Changes:
A/branches/meklort/i386/modules/NetbookInstaller
A/branches/meklort/i386/modules/NetbookInstaller/NBI.c
A/branches/meklort/i386/modules/NetbookInstaller/Makefile
M/branches/meklort/i386/modules/Makefile
M/branches/meklort/i386/modules/GUI/Makefile
M/branches/meklort/i386/boot2/drivers.c

File differences

branches/meklort/i386/boot2/drivers.c
4949
5050
5151
52
52
5353
54
54
5555
56
57
58
59
60
56
57
58
59
60
6161
6262
6363
6464
6565
66
66
6767
6868
6969
70
71
72
73
74
70
71
72
73
74
7575
7676
7777
......
106106
107107
108108
109
109
110110
111111
112112
......
125125
126126
127127
128
128
129129
130130
131131
......
255255
256256
257257
258
258
259259
260260
261261
......
316316
317317
318318
319
319
320320
321321
322322
......
352352
353353
354354
355
355
356356
357357
358358
......
399399
400400
401401
402
402
403403
404404
405405
......
506506
507507
508508
509
510
509
511510
512511
513512
......
597596
598597
599598
600
601
599
602600
603601
604602
......
607605
608606
609607
610
611
608
612609
613610
614611
static unsigned long Alder32( unsigned char * buffer, long length );
static long FileLoadDrivers(char *dirSpec, long plugin);
long FileLoadDrivers(char *dirSpec, long plugin);
#ifndef OPTION_ROM
static long NetLoadDrivers(char *dirSpec);
long NetLoadDrivers(char *dirSpec);
#endif
static long LoadDriverMKext(char *fileSpec);
static long LoadDriverPList(char *dirSpec, char *name, long bundleType);
static long LoadMatchedModules(void);
static long MatchPersonalities(void);
static long MatchLibraries(void);
long LoadDriverMKext(char *fileSpec);
long LoadDriverPList(char *dirSpec, char *name, long bundleType);
long LoadMatchedModules(void);
long MatchPersonalities(void);
long MatchLibraries(void);
#ifdef NOTDEF
static ModulePtr FindModule(char *name);
static void ThinFatFile(void **loadAddrP, unsigned long *lengthP);
#endif
static long ParseXML(char *buffer, ModulePtr *module, TagPtr *personalities);
static long InitDriverSupport(void);
long InitDriverSupport(void);
static ModulePtr gModuleHead, gModuleTail;
static TagPtr gPersonalityHead, gPersonalityTail;
static char * gExtensionsSpec;
static char * gDriverSpec;
static char * gFileSpec;
static char * gTempSpec;
static char * gFileName;
char * gExtensionsSpec;
char * gDriverSpec;
char * gFileSpec;
char * gTempSpec;
char * gFileName;
static unsigned long
Alder32( unsigned char * buffer, long length )
//==========================================================================
// InitDriverSupport
static long
long
InitDriverSupport( void )
{
gExtensionsSpec = malloc( 4096 );
// LoadDrivers
long LoadDrivers( char * dirSpec )
{
{
char dirSpecExtra[1024];
if ( InitDriverSupport() != 0 )
//==========================================================================
// FileLoadDrivers
static long
long
FileLoadDrivers( char * dirSpec, long plugin )
{
long ret, length, flags, time, bundleType;
//==========================================================================
//
#ifndef OPTION_ROM
static long
long
NetLoadDrivers( char * dirSpec )
{
long tries;
//==========================================================================
// loadDriverMKext
static long
long
LoadDriverMKext( char * fileSpec )
{
unsigned long driversAddr, driversLength;
//==========================================================================
// LoadDriverPList
static long
long
LoadDriverPList( char * dirSpec, char * name, long bundleType )
{
long length, executablePathLength, bundlePathLength;
//==========================================================================
// LoadMatchedModules
static long
LoadMatchedModules( void )
long LoadMatchedModules( void )
{
TagPtr prop;
ModulePtr module;
//==========================================================================
// MatchPersonalities
static long
MatchPersonalities( void )
long MatchPersonalities( void )
{
/* IONameMatch support not implemented */
return 0;
//==========================================================================
// MatchLibraries
static long
MatchLibraries( void )
long MatchLibraries( void )
{
TagPtr prop, prop2;
ModulePtr module, module2;
branches/meklort/i386/modules/NetbookInstaller/NBI.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
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
/*
* Copyright (c) 2009 Evan Lojewski. All rights reserved.
*
*/
#include <mach-o/fat.h>
#include <libkern/OSByteOrder.h>
#include <mach/machine.h>
#include "libsaio.h"
#include "sl.h"
#include "boot.h"
#include "bootstruct.h"
#include "xml.h"
#include "ramdisk.h"
#include "drivers.h"
#include "modules.h"
intrunNetbookInstaller = 0;
long NBI_LoadDrivers( char * dirSpec );
void NBI_md0Ramdisk();
#ifndef OPTION_ROM
extern long (*LoadExtraDrivers_p)(FileLoadDrivers_t FileLoadDrivers_p);
extern long NetLoadDrivers(char *dirSpec);
extern long FileLoadDrivers(char *dirSpec, long plugin);
#endif
extern char gMacOSVersion;
extern long LoadDriverMKext(char *fileSpec);
extern long LoadDriverPList(char *dirSpec, char *name, long bundleType);
extern long MatchLibraries( void );
extern long MatchPersonalities( void );
extern long LoadMatchedModules( void );
extern long InitDriverSupport(void);
extern char * gExtensionsSpec;
extern char * gDriverSpec;
extern char * gFileSpec;
extern char * gTempSpec;
extern char * gFileName;
void NetbookInstaller_start()
{
config_file_t systemVersion;
char valid = false;
const char *val;
int len;
const char* gPrevMacOSBuildVersion;
if (!loadConfigFile("System/Library/CoreServices/SystemVersion.plist", &systemVersion))
{
valid = true;
}
else if (!loadConfigFile("System/Library/CoreServices/ServerVersion.plist", &systemVersion))
{
valid = true;
}
if (valid)
{
if (getValueForKey("ProductBuildVersion", &val, &len, &systemVersion))
{
if (!loadConfigFile("Extra/SystemVersion.LastPatched.plist", &systemVersion))
{
if(getValueForKey("ProductBuildVersion", &gPrevMacOSBuildVersion, &len, &systemVersion))
{
if(strlen(val) != strlen(gPrevMacOSBuildVersion) ||
strcmp(val, gPrevMacOSBuildVersion) != 0
)
{
runNetbookInstaller = 1;
archCpuType = CPU_TYPE_I386;
}
else
{
// Only allow restore from hibernation if the system hasn't changed, probably a bad idea though
//char* val="/private/var/vm/sleepimage";
// Do this first to be sure that root volume is mounted
//ret = GetFileInfo(0, val, &flags, &sleeptime);
//printf("System version has not changed\n");
//runNetbookInstaller = 0;
}
}
}
}
}
//else printf("Unable to locate Extra/SystemVersion.LastPatched.plist\n");
char dummyVal = 0;
if (getBoolForKey("recovery", &dummyVal, &bootInfo->bootConfig) && dummyVal)
{
if(dummyVal) runNetbookInstaller = 2;
}
if(runNetbookInstaller)
{
replace_function("_LoadDrivers", &NBI_LoadDrivers);
replace_function("_md0Ramdisk", &NBI_md0Ramdisk);
}
}
void NBI_md0Ramdisk()
{
RAMDiskParam ramdiskPtr;
char filename[512];
int fh = -1;
// TODO: embed NBI.img in this file
// If runNetbookInstaller is true, then the system has changed states, patch it
sprintf(filename, "%s", "Extra/NetbookInstaller.img");;
fh = open(filename, 0);
if (fh >= 0)
{
verbose("Enabling ramdisk %s\n", filename);
ramdiskPtr.size = file_size(fh);
ramdiskPtr.base = AllocateKernelMemory(ramdiskPtr.size);
if(ramdiskPtr.size && ramdiskPtr.base)
{
// Read new ramdisk image contents in kernel memory.
if (read(fh, (char*) ramdiskPtr.base, ramdiskPtr.size) == ramdiskPtr.size)
{
AllocateMemoryRange("RAMDisk", ramdiskPtr.base, ramdiskPtr.size, kBootDriverTypeInvalid);
Node* node = DT__FindNode("/chosen/memory-map", false);
if(node != NULL)
{
DT__AddProperty(node, "RAMDisk", sizeof(RAMDiskParam), (void*)&ramdiskPtr);
}
else
{
verbose("Unable to notify Mac OS X of the ramdisk %s.\n", filename);
}
}
else
{
verbose("Unable to read md0 image %s.\n", filename);
}
}
else
{
verbose("md0 image %s is empty.\n", filename);
}
close(fh);
}
}
long NBI_LoadDrivers( char * dirSpec )
{
char dirSpecExtra[1024];
if ( InitDriverSupport() != 0 )
return 0;
#ifndef OPTION_ROM
// Load extra drivers if a hook has been installed.
if (LoadExtraDrivers_p != NULL)
{
(*LoadExtraDrivers_p)(&FileLoadDrivers);
}
if ( gBootFileType == kNetworkDeviceType )
{
if (NetLoadDrivers(dirSpec) != 0) {
error("Could not load drivers from the network\n");
return -1;
}
}
else
#endif
if ( gBootFileType == kBlockDeviceType )
{
verbose("Loading Recovery Extensions\n");
strcpy(dirSpecExtra, "/Extra/RecoveryExtensions/");
FileLoadDrivers(dirSpecExtra, 0);
// TODO: fix this, the order does matter, and it's not correct now.
// Also try to load Extensions from boot helper partitions.
if (gBootVolume->flags & kBVFlagBooter)
{
strcpy(dirSpecExtra, "/com.apple.boot.P/System/Library/");
if (FileLoadDrivers(dirSpecExtra, 0) != 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 )
{
error("Could not load %s\n", gMKextName);
return -1;
}
}
else
{
strcpy(gExtensionsSpec, dirSpec);
strcat(gExtensionsSpec, "System/Library/");
FileLoadDrivers(gExtensionsSpec, 0);
}
}
else
{
return 0;
}
MatchPersonalities();
MatchLibraries();
LoadMatchedModules();
return 0;
}
branches/meklort/i386/modules/NetbookInstaller/Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
MODULE_NAME = NetbookInstaller
MODULE_VERSION = "1.0.0"
MODULE_COMPAT_VERSION = "1.0.0"
MODULE_START = _$(MODULE_NAME)_start
MODULE_DEPENDENCIES =
DIR = HelloWorld
include ../../MakePaths.dir
OBJROOT=../../../obj/i386/modules/$(DIR)
SYMROOT=../../../sym/i386/modules/
DSTROOT=../../../dst/i386/modules/
UTILDIR = ../../util
LIBSADIR = ../../libsa
LIBSAIODIR = ../../libsaio
BOOT2DIR = ../../boot2
INSTALLDIR = $(DSTROOT)/System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders/standalone
OPTIM = -Os -Oz
DEBUG = -DNOTHING
#DEBUG = -DDEBUG_HELLO_WORLD=1
CFLAGS= $(RC_CFLAGS) $(OPTIM) $(MORECPP) -arch i386 -g -Wmost \
-D__ARCHITECTURE__=\"i386\" -DSAIO_INTERNAL_USER \
-DRCZ_COMPRESSED_FILE_SUPPORT $(DEBUG) \
-fno-builtin $(OMIT_FRAME_POINTER_CFLAG) \
-mpreferred-stack-boundary=2 -fno-align-functions -fno-stack-protector \
-march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common -mdynamic-no-pic
DEFINES=
CONFIG = hd
INC = -I. -I.. -I$(SYMROOT) -I$(UTILDIR) -I$(LIBSADIR) -I$(LIBSAIODIR) -I$(BOOT2DIR)
ifneq "" "$(wildcard /bin/mkdirs)"
MKDIRS = /bin/mkdirs
else
MKDIRS = /bin/mkdir -p
endif
AS = as
LD = ld
# LIBS= -lc_static
LIBS=
VPATH = $(OBJROOT):$(SYMROOT)
NBI_OBJS = NBI.o
SFILES =
CFILES =
HFILES =
EXPORTED_HFILES =
INSTALLED_HFILES =
OTHERFILES = Makefile
ALLSRC = $(SFILES) $(CFILES) \
$(HFILES) $(OTHERFILES)
DIRS_NEEDED = $(OBJROOT) $(SYMROOT)
all embedtheme optionrom: ${NBI_OBJS} dylib
dylib: ${HELLO_WORLD_OBJS}
ld -flat_namespace -arch i386 \
-undefined suppress \
-alias $(MODULE_START) start \
-dylib -read_only_relocs suppress \
-S -x -Z -dead_strip_dylibs \
-no_uuid \
-current_version $(MODULE_VERSION) -compatibility_version $(MODULE_COMPAT_VERSION) \
-final_output $(MODULE_NAME) \
$(OBJROOT)/NBI.o -o $(SYMROOT)/$(MODULE_NAME).dylib
NBI.o:
$(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "NBI.c" $(INC) -o "$(OBJROOT)/NBI.o"
include ../../MakeInc.dir
# dependencies
-include $(OBJROOT)/Makedep
branches/meklort/i386/modules/GUI/Makefile
2929
3030
3131
32
32
3333
3434
3535
-DRCZ_COMPRESSED_FILE_SUPPORT $(DEBUG) \
-fno-builtin $(OMIT_FRAME_POINTER_CFLAG) \
-mpreferred-stack-boundary=2 -fno-align-functions -fno-stack-protector \
-march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common -mdynamic-no-pic
-march=pentium4 -msse2 -mfpmath=sse -msoft-float -fno-common
DEFINES=
CONFIG = hd
branches/meklort/i386/modules/Makefile
2727
2828
2929
30
30
3131
3232
3333
# The order of building is important.
# TODO: exclude Symbols from find so it isn't compiled twice
SUBDIRS = Symbols Resolution KernelPatcher KextPatcher GUI GraphicsEnabler ACPIPatcher HPET USBFix Memory Networking
SUBDIRS = Symbols Resolution KernelPatcher KextPatcher GUI GraphicsEnabler ACPIPatcher HPET USBFix Memory Networking NetbookInstaller
all embedtheme optionrom tags debug install installhdrs:
@rm -rf $(OBJROOT)

Archive Download the corresponding diff file

Revision: 569