Index: branches/meklort/i386/boot2/drivers.c =================================================================== --- branches/meklort/i386/boot2/drivers.c (revision 568) +++ branches/meklort/i386/boot2/drivers.c (revision 569) @@ -49,29 +49,29 @@ 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 ) @@ -106,7 +106,7 @@ //========================================================================== // InitDriverSupport -static long +long InitDriverSupport( void ) { gExtensionsSpec = malloc( 4096 ); @@ -125,7 +125,7 @@ // LoadDrivers long LoadDrivers( char * dirSpec ) -{ +{ char dirSpecExtra[1024]; if ( InitDriverSupport() != 0 ) @@ -255,7 +255,7 @@ //========================================================================== // FileLoadDrivers -static long +long FileLoadDrivers( char * dirSpec, long plugin ) { long ret, length, flags, time, bundleType; @@ -316,7 +316,7 @@ //========================================================================== // #ifndef OPTION_ROM -static long +long NetLoadDrivers( char * dirSpec ) { long tries; @@ -352,7 +352,7 @@ //========================================================================== // loadDriverMKext -static long +long LoadDriverMKext( char * fileSpec ) { unsigned long driversAddr, driversLength; @@ -399,7 +399,7 @@ //========================================================================== // LoadDriverPList -static long +long LoadDriverPList( char * dirSpec, char * name, long bundleType ) { long length, executablePathLength, bundlePathLength; @@ -506,8 +506,7 @@ //========================================================================== // LoadMatchedModules -static long -LoadMatchedModules( void ) +long LoadMatchedModules( void ) { TagPtr prop; ModulePtr module; @@ -597,8 +596,7 @@ //========================================================================== // MatchPersonalities -static long -MatchPersonalities( void ) +long MatchPersonalities( void ) { /* IONameMatch support not implemented */ return 0; @@ -607,8 +605,7 @@ //========================================================================== // MatchLibraries -static long -MatchLibraries( void ) +long MatchLibraries( void ) { TagPtr prop, prop2; ModulePtr module, module2; Index: branches/meklort/i386/modules/NetbookInstaller/NBI.c =================================================================== --- branches/meklort/i386/modules/NetbookInstaller/NBI.c (revision 0) +++ branches/meklort/i386/modules/NetbookInstaller/NBI.c (revision 569) @@ -0,0 +1,250 @@ +/* + * Copyright (c) 2009 Evan Lojewski. All rights reserved. + * + */ + +#include +#include +#include + +#include "libsaio.h" + +#include "sl.h" +#include "boot.h" +#include "bootstruct.h" +#include "xml.h" +#include "ramdisk.h" +#include "drivers.h" +#include "modules.h" + +int runNetbookInstaller = 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; +} + + Index: branches/meklort/i386/modules/NetbookInstaller/Makefile =================================================================== --- branches/meklort/i386/modules/NetbookInstaller/Makefile (revision 0) +++ branches/meklort/i386/modules/NetbookInstaller/Makefile (revision 569) @@ -0,0 +1,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 Index: branches/meklort/i386/modules/GUI/Makefile =================================================================== --- branches/meklort/i386/modules/GUI/Makefile (revision 568) +++ branches/meklort/i386/modules/GUI/Makefile (revision 569) @@ -29,7 +29,7 @@ -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 Index: branches/meklort/i386/modules/Makefile =================================================================== --- branches/meklort/i386/modules/Makefile (revision 568) +++ branches/meklort/i386/modules/Makefile (revision 569) @@ -27,7 +27,7 @@ # 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)