Root/
Source at commit 1166 created 13 years 10 days ago. By meklort, Fixed recent Makefile changes. Please do not use /Users/evan/SourceCode/tmp/chameleon/trunk or VPATH. the *only* time you should use /Users/evan/SourceCode/tmp/chameleon/trunk is when setting the SRCROOT variable. Also note that very soon make pkg is going to be removed. The pkg build script in trunk is very out of date. Instead please use the package maker at http://forge.voodooprojects.org/p/chameleonApplications/. Once this is ready for trunk it will be merged. | |
---|---|
1 | /*␊ |
2 | * Copyright (c) 2009 Evan Lojewski. All rights reserved.␊ |
3 | *␊ |
4 | */␊ |
5 | ␊ |
6 | #include <mach-o/fat.h>␊ |
7 | #include <libkern/OSByteOrder.h>␊ |
8 | #include <mach/machine.h>␊ |
9 | ␊ |
10 | #include "libsaio.h"␊ |
11 | ␊ |
12 | #include "sl.h"␊ |
13 | #include "boot.h"␊ |
14 | #include "bootstruct.h"␊ |
15 | #include "xml.h"␊ |
16 | #include "ramdisk.h"␊ |
17 | #include "drivers.h"␊ |
18 | #include "modules.h"␊ |
19 | ␊ |
20 | int␉␉runNetbookInstaller = 0;␊ |
21 | ␊ |
22 | long NBI_LoadDrivers( char * dirSpec );␊ |
23 | void NBI_md0Ramdisk();␊ |
24 | void NBI_PreBoot_hook(void* arg1, void* arg2, void* arg3, void* arg4);␊ |
25 | void NBI_loadBootGraphics(void);␊ |
26 | ␊ |
27 | #ifndef OPTION_ROM␊ |
28 | extern long (*LoadExtraDrivers_p)(FileLoadDrivers_t FileLoadDrivers_p);␊ |
29 | ␊ |
30 | extern long NetLoadDrivers(char *dirSpec);␊ |
31 | extern long FileLoadDrivers(char *dirSpec, long plugin);␊ |
32 | #endif␊ |
33 | ␊ |
34 | extern char gMacOSVersion;␊ |
35 | ␊ |
36 | ␊ |
37 | extern long LoadDriverMKext(char *fileSpec);␊ |
38 | extern long LoadDriverPList(char *dirSpec, char *name, long bundleType);␊ |
39 | ␊ |
40 | extern long MatchLibraries( void );␊ |
41 | extern long MatchPersonalities( void );␊ |
42 | extern long LoadMatchedModules( void );␊ |
43 | extern long InitDriverSupport(void);␊ |
44 | extern char * gExtensionsSpec;␊ |
45 | extern char * gDriverSpec;␊ |
46 | extern char * gFileSpec;␊ |
47 | extern char * gTempSpec;␊ |
48 | extern char * gFileName;␊ |
49 | ␊ |
50 | void NetbookInstaller_start()␊ |
51 | {␊ |
52 | ␉//else printf("Unable to locate Extra/SystemVersion.LastPatched.plist\n");␊ |
53 | ␉␊ |
54 | ␉register_hook_callback("PreBoot", &NBI_PreBoot_hook);␉␉␊ |
55 | ␉␊ |
56 | }␊ |
57 | ␊ |
58 | void NBI_PreBoot_hook(void* arg1, void* arg2, void* arg3, void* arg4)␊ |
59 | {␊ |
60 | ␉bool dummyVal = 0;␊ |
61 | ␉config_file_t systemVersion;␊ |
62 | ␉␊ |
63 | ␉char valid = false;␊ |
64 | ␉const char *val;␊ |
65 | ␉int len;␊ |
66 | ␉const char* gPrevMacOSBuildVersion;␊ |
67 | ␉␊ |
68 | ␉if (!loadConfigFile("System/Library/CoreServices/SystemVersion.plist", &systemVersion))␊ |
69 | ␉{␊ |
70 | ␉␉valid = true;␊ |
71 | ␉}␊ |
72 | ␉else if (!loadConfigFile("System/Library/CoreServices/ServerVersion.plist", &systemVersion))␊ |
73 | ␉{␊ |
74 | ␉␉valid = true;␊ |
75 | ␉}␊ |
76 | ␉␊ |
77 | ␉if (valid)␊ |
78 | ␉{␊ |
79 | ␉␉if (getValueForKey("ProductBuildVersion", &val, &len, &systemVersion))␊ |
80 | ␉␉{␊ |
81 | ␉␉␉␊ |
82 | ␉␉␉if (!loadConfigFile("Extra/SystemVersion.LastPatched.plist", &systemVersion))␊ |
83 | ␉␉␉{␊ |
84 | ␉␉␉␉if(getValueForKey("ProductBuildVersion", &gPrevMacOSBuildVersion, &len, &systemVersion))␊ |
85 | ␉␉␉␉{␊ |
86 | ␉␉␉␉␉if(strlen(val) != strlen(gPrevMacOSBuildVersion) ||␊ |
87 | ␉␉␉␉␉ strcmp(val, gPrevMacOSBuildVersion) != 0␊ |
88 | ␉␉␉␉␉ )␊ |
89 | ␉␉␉␉␉{␊ |
90 | ␉␉␉␉␉␉runNetbookInstaller = 1;␊ |
91 | ␉␉␉␉␉}␊ |
92 | ␉␉␉␉␉else ␊ |
93 | ␉␉␉␉␉{␊ |
94 | ␉␉␉␉␉␉// Only allow restore from hibernation if the system hasn't changed, probably a bad idea though␊ |
95 | ␉␉␉␉␉␉//char* val="/private/var/vm/sleepimage";␊ |
96 | ␉␉␉␉␉␉␊ |
97 | ␉␉␉␉␉␉// Do this first to be sure that root volume is mounted␊ |
98 | ␉␉␉␉␉␉//ret = GetFileInfo(0, val, &flags, &sleeptime);␊ |
99 | ␉␉␉␉␉␉␊ |
100 | ␉␉␉␉␉␉//printf("System version has not changed\n");␊ |
101 | ␉␉␉␉␉␉//runNetbookInstaller = 0;␊ |
102 | ␉␉␉␉␉␉␊ |
103 | ␉␉␉␉␉}␊ |
104 | ␉␉␉␉␉␊ |
105 | ␉␉␉␉}␊ |
106 | ␉␉␉}␊ |
107 | ␉␉}␊ |
108 | ␉}␊ |
109 | ␉␊ |
110 | ␉␊ |
111 | ␉␊ |
112 | ␉␊ |
113 | ␉if (!runNetbookInstaller && getBoolForKey("recovery", &dummyVal, &bootInfo->bootConfig) && dummyVal)␊ |
114 | ␉{␊ |
115 | ␉␉if(dummyVal) runNetbookInstaller = 2;␊ |
116 | ␉}␊ |
117 | ␉␊ |
118 | ␉if(runNetbookInstaller)␊ |
119 | ␉{␊ |
120 | ␉␉␊ |
121 | ␉␉replace_function("_LoadDrivers", &NBI_LoadDrivers);␊ |
122 | ␉␉if(runNetbookInstaller == 1)␊ |
123 | ␉␉{␊ |
124 | ␉␉␉replace_function("_md0Ramdisk", &NBI_md0Ramdisk);␉␉␊ |
125 | ␉␉}␊ |
126 | ␉␉␊ |
127 | ␉␉// Force arch=i386 + -v␊ |
128 | ␉␉archCpuType = CPU_TYPE_I386;␊ |
129 | ␉␉gVerboseMode = true;␊ |
130 | ␉}␊ |
131 | }␊ |
132 | ␊ |
133 | ␊ |
134 | void NBI_md0Ramdisk()␊ |
135 | {␊ |
136 | ␉RAMDiskParam ramdiskPtr;␊ |
137 | ␉char filename[512];␊ |
138 | ␉int fh = -1;␊ |
139 | ␉␊ |
140 | ␉// TODO: embed NBI.img in this file␊ |
141 | ␉// If runNetbookInstaller is true, then the system has changed states, patch it ␊ |
142 | ␉sprintf(filename, "%s", "Extra/NetbookInstaller.img");;␊ |
143 | ␉fh = open(filename, 0);␊ |
144 | ␉␊ |
145 | ␉if (fh >= 0)␊ |
146 | ␉{␊ |
147 | ␉␉verbose("Enabling ramdisk %s\n", filename);␊ |
148 | ␉␉␊ |
149 | ␉␉ramdiskPtr.size = file_size(fh);␊ |
150 | ␉␉ramdiskPtr.base = AllocateKernelMemory(ramdiskPtr.size);␊ |
151 | ␉␉␊ |
152 | ␉␉if(ramdiskPtr.size && ramdiskPtr.base)␊ |
153 | ␉␉{␊ |
154 | ␉␉␉// Read new ramdisk image contents in kernel memory.␊ |
155 | ␉␉␉if (read(fh, (char*) ramdiskPtr.base, ramdiskPtr.size) == ramdiskPtr.size)␊ |
156 | ␉␉␉{␊ |
157 | ␉␉␉␉AllocateMemoryRange("RAMDisk", ramdiskPtr.base, ramdiskPtr.size, kBootDriverTypeInvalid);␊ |
158 | ␉␉␉␉Node* node = DT__FindNode("/chosen/memory-map", false);␊ |
159 | ␉␉␉␉if(node != NULL)␊ |
160 | ␉␉␉␉{␊ |
161 | ␉␉␉␉␉DT__AddProperty(node, "RAMDisk", sizeof(RAMDiskParam), (void*)&ramdiskPtr);␉␉␊ |
162 | ␉␉␉␉}␊ |
163 | ␉␉␉␉else␊ |
164 | ␉␉␉␉{␊ |
165 | ␉␉␉␉␉verbose("Unable to notify Mac OS X of the ramdisk %s.\n", filename);␊ |
166 | ␉␉␉␉}␊ |
167 | ␉␉␉}␊ |
168 | ␉␉␉else␊ |
169 | ␉␉␉{␊ |
170 | ␉␉␉␉verbose("Unable to read md0 image %s.\n", filename);␊ |
171 | ␉␉␉}␉␉␉␊ |
172 | ␉␉}␊ |
173 | ␉␉else␊ |
174 | ␉␉{␊ |
175 | ␉␉␉verbose("md0 image %s is empty.\n", filename);␊ |
176 | ␉␉}␊ |
177 | ␉␉␊ |
178 | ␉␉close(fh);␊ |
179 | ␉␉␊ |
180 | ␉}␊ |
181 | }␊ |
182 | ␊ |
183 | ␊ |
184 | long NBI_LoadDrivers( char * dirSpec )␊ |
185 | {␊ |
186 | ␉␊ |
187 | char dirSpecExtra[1024];␊ |
188 | ␉␊ |
189 | if ( InitDriverSupport() != 0 )␊ |
190 | return 0;␊ |
191 | ␉␊ |
192 | #ifndef OPTION_ROM␊ |
193 | // Load extra drivers if a hook has been installed.␊ |
194 | if (LoadExtraDrivers_p != NULL)␊ |
195 | {␊ |
196 | (*LoadExtraDrivers_p)(&FileLoadDrivers);␊ |
197 | }␊ |
198 | ␉␊ |
199 | if ( gBootFileType == kNetworkDeviceType )␊ |
200 | {␊ |
201 | if (NetLoadDrivers(dirSpec) != 0) {␊ |
202 | error("Could not load drivers from the network\n");␊ |
203 | return -1;␊ |
204 | }␊ |
205 | }␊ |
206 | else␊ |
207 | #endif␊ |
208 | ␉␉if ( gBootFileType == kBlockDeviceType )␊ |
209 | ␉␉{␊ |
210 | ␉␉␉verbose("Loading Recovery Extensions\n");␊ |
211 | ␉␉␉strcpy(dirSpecExtra, "/Extra/RecoveryExtensions/");␊ |
212 | ␉␉␉FileLoadDrivers(dirSpecExtra, 0);␊ |
213 | ␉␉␉␊ |
214 | ␉␉␉␊ |
215 | ␉␉␉// TODO: fix this, the order does matter, and it's not correct now.␊ |
216 | ␉␉␉// Also try to load Extensions from boot helper partitions.␊ |
217 | ␉␉␉if (gBootVolume->flags & kBVFlagBooter)␊ |
218 | ␉␉␉{␊ |
219 | ␉␉␉␉strcpy(dirSpecExtra, "/com.apple.boot.P/System/Library/");␊ |
220 | ␉␉␉␉if (FileLoadDrivers(dirSpecExtra, 0) != 0)␊ |
221 | ␉␉␉␉{␊ |
222 | ␉␉␉␉␉strcpy(dirSpecExtra, "/com.apple.boot.R/System/Library/");␊ |
223 | ␉␉␉␉␉if (FileLoadDrivers(dirSpecExtra, 0) != 0)␊ |
224 | ␉␉␉␉␉{␊ |
225 | ␉␉␉␉␉␉strcpy(dirSpecExtra, "/com.apple.boot.S/System/Library/");␊ |
226 | ␉␉␉␉␉␉FileLoadDrivers(dirSpecExtra, 0);␊ |
227 | ␉␉␉␉␉}␊ |
228 | ␉␉␉␉}␊ |
229 | ␉␉␉}␊ |
230 | ␉␉␉␊ |
231 | ␉␉␉if (gMKextName[0] != '\0')␊ |
232 | ␉␉␉{␊ |
233 | ␉␉␉␉verbose("LoadDrivers: Loading from [%s]\n", gMKextName);␊ |
234 | ␉␉␉␉if ( LoadDriverMKext(gMKextName) != 0 )␊ |
235 | ␉␉␉␉{␊ |
236 | ␉␉␉␉␉error("Could not load %s\n", gMKextName);␊ |
237 | ␉␉␉␉␉return -1;␊ |
238 | ␉␉␉␉}␊ |
239 | ␉␉␉}␊ |
240 | ␉␉␉else␊ |
241 | ␉␉␉{␊ |
242 | ␉␉␉␉strcpy(gExtensionsSpec, dirSpec);␊ |
243 | ␉␉␉␉strcat(gExtensionsSpec, "System/Library/");␊ |
244 | ␉␉␉␉FileLoadDrivers(gExtensionsSpec, 0);␊ |
245 | ␉␉␉}␊ |
246 | ␉␉}␊ |
247 | ␉␉else␊ |
248 | ␉␉{␊ |
249 | ␉␉␉return 0;␊ |
250 | ␉␉}␊ |
251 | ␉␊ |
252 | MatchPersonalities();␊ |
253 | ␉␊ |
254 | MatchLibraries();␊ |
255 | ␉␊ |
256 | LoadMatchedModules();␊ |
257 | ␉␊ |
258 | return 0;␊ |
259 | }␊ |
260 |