Example #1
0
int
processBootOptions()
{
	const char *cp  = gBootArgs;
	const char *val = 0;
	const char *kernel;
	int         cnt;
	int         userCnt;
	int         cntRemaining;
	char       *argP;
	char       *configKernelFlags;
	char       *valueBuffer;

	valueBuffer = malloc(VALUE_SIZE);
    
	skipblanks( &cp );

	// Update the unit and partition number.

	if ( gBootVolume ) {
		if (!( gBootVolume->flags & kBVFlagNativeBoot )) {
			readBootSector( gBootVolume->biosdev, gBootVolume->part_boff, (void *) 0x7c00 );
			//
			// Setup edx, and signal intention to chain load the
			// foreign booter.
			//

			chainbootdev  = gBootVolume->biosdev;
			chainbootflag = 1;

			return 1;
		}

		setRootVolume(gBootVolume);

	}
	// If no boot volume fail immediately because we're just going to fail
	// trying to load the config file anyway.
	else {
		return -1;
	}

	// Find out which version mac os we're booting.
	strncpy(gMacOSVersion, gBootVolume->OSVersion, sizeof(gMacOSVersion));

	// Load config table specified by the user, or use the default.

	if (!getValueForBootKey(cp, "config", &val, &cnt)) {
		val = 0;
		cnt = 0;
	}

	// Load com.apple.Boot.plist from the selected volume
	// and use its contents to override default bootConfig.

	loadSystemConfig(&bootInfo->bootConfig);
	loadChameleonConfig(&bootInfo->chameleonConfig, NULL);

	// Use the kernel name specified by the user, or fetch the name
	// in the config table, or use the default if not specified.
	// Specifying a kernel name on the command line, or specifying
	// a non-default kernel name in the config file counts as
	// overriding the kernel, which causes the kernelcache not
	// to be used.

	gOverrideKernel = false;
	if (( kernel = extractKernelName((char **)&cp) ))
	{
		strlcpy( bootInfo->bootFile, kernel, sizeof(bootInfo->bootFile) );
	}
	else
	{
		if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) )
		{
			strlcpy( bootInfo->bootFile, val, cnt+1 );
		}
		else
		{
			if( YOSEMITE ) // is 10.10
			{

				strlcpy( bootInfo->bootFile, kOSXKernel, sizeof(bootInfo->bootFile) );
				//printf(HEADER "/System/Library/Kernels/%s\n", bootInfo->bootFile);
			}
			else
			{ // OSX is not 10.10

				strlcpy( bootInfo->bootFile, kDefaultKernel, sizeof(bootInfo->bootFile) );
				//printf(HEADER "/%s\n", bootInfo->bootFile);
			}
		}
	}

	if (!YOSEMITE) // not 10.10 so 10.9 and previus
	{
		if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0)
		{
	        	//printf(HEADER "org.chameleon.Boot.plist found path for custom '%s' found!\n", bootInfo->bootFile);
			gOverrideKernel = true;
		}
	}
	else
	{ // OSX is 10.10
		if (strcmp( bootInfo->bootFile, kOSXKernel ) != 0)
		{
        		//printf(HEADER "org.chameleon.Boot.plist found path for custom '%s' found!\n", bootInfo->bootFile);
			gOverrideKernel = true;
		}
	}

	// Ermac : Inject "kext-dev-mode=1" if OS X 10.10 is detected
	if( YOSEMITE ) // is 10.10
	{
		addBootArg("kext-dev-mode=1");
	}

	cntRemaining = BOOT_STRING_LEN - 2;  // save 1 for NULL, 1 for space
	argP = bootArgs->CommandLine;

	// Get config kernel flags, if not ignored.
	if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) ||
            !getValueForKey( kKernelFlagsKey, &val, &cnt, &bootInfo->bootConfig ))
	{
		val = "";
		cnt = 0;
	}
	configKernelFlags = malloc(cnt + 1);
	strlcpy(configKernelFlags, val, cnt + 1);

	// boot-uuid can be set either on the command-line or in the config file
	if (!processBootArgument(kBootUUIDKey, cp, configKernelFlags, bootInfo->config,
                             &argP, &cntRemaining, gBootUUIDString, sizeof(gBootUUIDString)))
	{
		//
		// Try an alternate method for getting the root UUID on boot helper partitions.
		//
		if (gBootVolume->flags & kBVFlagBooter)
		{
			// Load the configuration store in the boot helper partition
			if (loadHelperConfig(&bootInfo->helperConfig) == 0)
			{
				val = getStringForKey(kHelperRootUUIDKey, &bootInfo->helperConfig);
				if (val != NULL)
				{
					strlcpy(gBootUUIDString, val, sizeof(gBootUUIDString));
				}
			}
		}
/*
		// Try to get the volume uuid string
		if (!strlen(gBootUUIDString) && gBootVolume->fs_getuuid)
		{
			gBootVolume->fs_getuuid(gBootVolume, gBootUUIDString);
		}
*/
		// If we have the volume uuid add it to the commandline arguments
		if (strlen(gBootUUIDString))
		{
			copyArgument(kBootUUIDKey, gBootUUIDString, strlen(gBootUUIDString), &argP, &cntRemaining);
		}
		// Try to get the volume uuid string
		if (!strlen(gBootUUIDString) && gBootVolume->fs_getuuid)
		{
			gBootVolume->fs_getuuid(gBootVolume, gBootUUIDString);
			DBG("boot-uuid: %s\n", gBootUUIDString);
		}
	}

	if (!processBootArgument(kRootDeviceKey, cp, configKernelFlags, bootInfo->config,
                             &argP, &cntRemaining, gRootDevice, ROOT_DEVICE_SIZE))
	{
		cnt = 0;
		if ( getValueForKey( kBootDeviceKey, &val, &cnt, &bootInfo->chameleonConfig))
		{
			valueBuffer[0] = '*';
			cnt++;
			strlcpy(valueBuffer + 1, val, cnt);
			val = valueBuffer;
		}
		else
		{ /*
			if (strlen(gBootUUIDString))
			{
				val = "*uuid";
				cnt = 5;
			}
			else
			{ */
				// Don't set "rd=.." if there is no boot device key
				// and no UUID.
				val = "";
				cnt = 0;
			/* } */
		}

		if (cnt > 0)
		{
			copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining);
		}
		strlcpy( gRootDevice, val, (cnt + 1));
	}

	/*
	 * Removed. We don't need this anymore.
	 *
	if (!processBootArgument(kPlatformKey, cp, configKernelFlags, bootInfo->config,
							 &argP, &cntRemaining, gPlatformName, sizeof(gCacheNameAdler)))
	{
		getPlatformName(gPlatformName);
		copyArgument(kPlatformKey, gPlatformName, strlen(gPlatformName), &argP, &cntRemaining);
	}
	*/

	if (!getValueForBootKey(cp, kSafeModeFlag, &val, &cnt) &&
        !getValueForBootKey(configKernelFlags, kSafeModeFlag, &val, &cnt))
	{
		if (gBootMode & kBootModeSafe)
		{
			copyArgument(0, kSafeModeFlag, strlen(kSafeModeFlag), &argP, &cntRemaining);
		}
	}

	// Store the merged kernel flags and boot args.

	cnt = strlen(configKernelFlags);
	if (cnt)
	{
		if (cnt > cntRemaining)
		{
			error("Warning: boot arguments too long, truncating\n");
			cnt = cntRemaining;
		}
		strncpy(argP, configKernelFlags, cnt);
		argP[cnt++] = ' ';
		cntRemaining -= cnt;
	}
	userCnt = strlen(cp);
	if (userCnt > cntRemaining)
	{
		error("Warning: boot arguments too long, truncating\n");
		userCnt = cntRemaining;
	}
	strncpy(&argP[cnt], cp, userCnt);
	argP[cnt+userCnt] = '\0';

	if(!shouldboot)
	{
		gVerboseMode = getValueForKey( kVerboseModeFlag, &val, &cnt, &bootInfo->chameleonConfig ) ||
			getValueForKey( kSingleUserModeFlag, &val, &cnt, &bootInfo->chameleonConfig );
		
		gBootMode = ( getValueForKey( kSafeModeFlag, &val, &cnt, &bootInfo->chameleonConfig ) ) ?
			kBootModeSafe : kBootModeNormal;

		if ( getValueForKey( kIgnoreCachesFlag, &val, &cnt, &bootInfo->chameleonConfig ) )
		{
			gBootMode = kBootModeSafe;
		}
	}

	if ( getValueForKey( kMKextCacheKey, &val, &cnt, &bootInfo->bootConfig ) )
	{
		strlcpy(gMKextName, val, cnt + 1);
	}
	else
	{
		gMKextName[0]=0;
	}

	free(configKernelFlags);
	free(valueBuffer);

	return 0;
}
Example #2
0
int
processBootOptions()
{
    const char *     cp  = gBootArgs;
    const char *     val = 0;
    const char *     kernel;
    int              cnt;
    int		     userCnt;
    int              cntRemaining;
    char *           argP;
    char             uuidStr[64];
    bool             uuidSet = false;
    char *           configKernelFlags;
    char *           valueBuffer;

    valueBuffer = malloc(VALUE_SIZE);
    
    skipblanks( &cp );

    // Update the unit and partition number.

    if ( gBootVolume )
    {
        if (!( gBootVolume->flags & kBVFlagNativeBoot ))
        {
            readBootSector( gBootVolume->biosdev, gBootVolume->part_boff,
                            (void *) 0x7c00 );

            //
            // Setup edx, and signal intention to chain load the
            // foreign booter.
            //

            chainbootdev  = gBootVolume->biosdev;
            chainbootflag = 1;

            return 1;
        }

        setRootVolume(gBootVolume);

    }
    // If no boot volume fail immediately because we're just going to fail
    // trying to load the config file anyway.
    else
      return -1;

    // Load config table specified by the user, or use the default.

    if (!getValueForBootKey(cp, "config", &val, &cnt)) {
      val = 0;
      cnt = 0;
    }

    // Load com.apple.Boot.plist from the selected volume
    // and use its contents to override default bootConfig.
    // This is not a mandatory operation anymore.

    loadOverrideConfig(&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.
    // Specifying a kernel name on the command line, or specifying
    // a non-default kernel name in the config file counts as
    // overriding the kernel, which causes the kernelcache not
    // to be used.

    gOverrideKernel = false;
    if (( kernel = extractKernelName((char **)&cp) )) {
        strcpy( bootInfo->bootFile, kernel );
        gOverrideKernel = true;
    } else {
        if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) ) {
            strlcpy( bootInfo->bootFile, val, cnt+1 );
            if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) {
                gOverrideKernel = true;
            }
        } else {
            strcpy( bootInfo->bootFile, kDefaultKernel );
        }
    }

    cntRemaining = BOOT_STRING_LEN - 2;  // save 1 for NULL, 1 for space
    argP = bootArgs->CommandLine;

    // Get config table kernel flags, if not ignored.
    if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) ||
            !getValueForKey( kKernelFlagsKey, &val, &cnt, &bootInfo->bootConfig )) {
        val = "";
        cnt = 0;
    }
    configKernelFlags = malloc(cnt + 1);
    strlcpy(configKernelFlags, val, cnt + 1);

    if (processBootArgument(kBootUUIDKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, 0)) {
        // boot-uuid was set either on the command-line
        // or in the config file.
        uuidSet = true;
    } else {

        //
        // Try an alternate method for getting the root UUID on boot helper partitions.
        //
        if (gBootVolume->flags & kBVFlagBooter)
        {
        	if((loadHelperConfig(&bootInfo->helperConfig) == 0)
        	    && getValueForKey(kHelperRootUUIDKey, &val, &cnt, &bootInfo->helperConfig) )
        	{
          	getValueForKey(kHelperRootUUIDKey, &val, &cnt, &bootInfo->helperConfig);
            copyArgument(kBootUUIDKey, val, cnt, &argP, &cntRemaining);
            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)) {
        cnt = 0;
        if ( getValueForKey( kBootDeviceKey, &val, &cnt, &bootInfo->bootConfig)) {
            valueBuffer[0] = '*';
            cnt++;
            strlcpy(valueBuffer + 1, val, cnt);
            val = valueBuffer;
        } else {
            if (uuidSet) {
                val = "*uuid";
                cnt = 5;
            } else {
                // Don't set "rd=.." if there is no boot device key
                // and no UUID.
                val = "";
                cnt = 0;
            }
        } 
        if (cnt > 0) {
            copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining);
        }
        strlcpy( gRootDevice, val, (cnt + 1));
    }

    /*
     * Removed. We don't need this anymore.
     *
    if (!processBootArgument(kPlatformKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gPlatformName)) {
        getPlatformName(gPlatformName);
        copyArgument(kPlatformKey, gPlatformName, strlen(gPlatformName), &argP, &cntRemaining);
    }
    */

    if (!getValueForBootKey(cp, kSafeModeFlag, &val, &cnt) &&
        !getValueForBootKey(configKernelFlags, kSafeModeFlag, &val, &cnt)) {
        if (gBootMode & kBootModeSafe) {
            copyArgument(0, kSafeModeFlag, strlen(kSafeModeFlag), &argP, &cntRemaining);
        }
    }

    // Store the merged kernel flags and boot args.

    cnt = strlen(configKernelFlags);
    if (cnt) {
        if (cnt > cntRemaining) {
            error("Warning: boot arguments too long, truncating\n");
            cnt = cntRemaining;
        }
        strncpy(argP, configKernelFlags, cnt);
        argP[cnt++] = ' ';
        cntRemaining -= cnt;
    }
    userCnt = strlen(cp);
    if (userCnt > cntRemaining) {
      error("Warning: boot arguments too long, truncating\n");
      userCnt = cntRemaining;
    }
    strncpy(&argP[cnt], cp, userCnt);
    argP[cnt+userCnt] = '\0';

	if(!shouldboot)
	{
		gVerboseMode = getValueForKey( kVerboseModeFlag, &val, &cnt, &bootInfo->bootConfig ) ||
			getValueForKey( kSingleUserModeFlag, &val, &cnt, &bootInfo->bootConfig );
		
		gBootMode = ( getValueForKey( kSafeModeFlag, &val, &cnt, &bootInfo->bootConfig ) ) ?
			kBootModeSafe : kBootModeNormal;

        if ( getValueForKey( kIgnoreCachesFlag, &val, &cnt, &bootInfo->bootConfig ) ) {
            gBootMode = kBootModeSafe;
       }
	}

	if ( getValueForKey( kMKextCacheKey, &val, &cnt, &bootInfo->bootConfig ) )
	{
		strlcpy(gMKextName, val, cnt + 1);
	}

    free(configKernelFlags);
    free(valueBuffer);

    return 0;
}
Example #3
0
int
processBootOptions()
{
    const char *     cp  = gBootArgs;
    const char *     val = 0;
    const char *     kernel;
    int              cnt;
    int		     userCnt;
    int              cntRemaining;
    char *           argP;
    char             uuidStr[64];
    BOOL             uuidSet = NO;
    char *           configKernelFlags;
    char *           valueBuffer;

    valueBuffer = (char *)malloc(VALUE_SIZE);

    skipblanks( &cp );

    // Update the unit and partition number.

    if ( gBootVolume )
    {
        if ( gBootVolume->flags & kBVFlagForeignBoot )
        {
            readBootSector( gBootVolume->biosdev, gBootVolume->part_boff,
                            (void *) 0x7c00 );

            //
            // Setup edx, and signal intention to chain load the
            // foreign booter.
            //

            chainbootdev  = gBootVolume->biosdev;
            chainbootflag = 1;

            return 1;
        }

        bootInfo->kernDev &= ~((B_UNITMASK << B_UNITSHIFT ) |
                          (B_PARTITIONMASK << B_PARTITIONSHIFT));

        bootInfo->kernDev |= MAKEKERNDEV(    0,
 		         /* unit */      BIOS_DEV_UNIT(gBootVolume),
                        /* partition */ gBootVolume->part_no );
    }

    // Load config table specified by the user, or use the default.

    if (getValueForBootKey( cp, "config", &val, &cnt ) == FALSE) {
	val = 0;
	cnt = 0;
    }
    loadSystemConfig(val, cnt);
    if ( !sysConfigValid ) return -1;

    // Use the kernel name specified by the user, or fetch the name
    // in the config table, or use the default if not specified.
    // Specifying a kernel name on the command line, or specifying
    // a non-default kernel name in the config file counts as
    // overriding the kernel, which causes the kernelcache not
    // to be used.

    gOverrideKernel = NO;
    if (( kernel = extractKernelName((char **)&cp) )) {
        strcpy( bootInfo->bootFile, kernel );
        gOverrideKernel = YES;
    } else {
        if ( getValueForKey( kKernelNameKey, &val, &cnt ) ) {
            strlcpy( bootInfo->bootFile, val, cnt+1 );
            if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) {
                gOverrideKernel = YES;
            }
        } else {
            strcpy( bootInfo->bootFile, kDefaultKernel );
        }
    }

    cntRemaining = BOOT_STRING_LEN - 2;  // save 1 for NULL, 1 for space
    argP = bootArgs->CommandLine;

    // Get config table kernel flags, if not ignored.
    if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) == TRUE ||
            getValueForKey( kKernelFlagsKey, &val, &cnt ) == FALSE) {
        val = "";
        cnt = 0;
    }
    configKernelFlags = (char *)malloc(cnt + 1);
    strlcpy(configKernelFlags, val, cnt + 1);

    if (processBootArgument(kBootUUIDKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, 0)) {
        // boot-uuid was set either on the command-line
        // or in the config file.
        uuidSet = YES;
    } else {
        if (GetFSUUID(bootInfo->bootFile, uuidStr) == 0) {
            verbose("Setting boot-uuid to: %s\n", uuidStr);
            copyArgument(kBootUUIDKey, uuidStr, strlen(uuidStr), &argP, &cntRemaining);
            uuidSet = YES;
        }
    }

    if (!processBootArgument(kRootDeviceKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gRootDevice)) {
        cnt = 0;
        if ( getValueForKey( kBootDeviceKey, &val, &cnt)) {
            valueBuffer[0] = '*';
            cnt++;
            strlcpy(valueBuffer + 1, val, cnt);
            val = valueBuffer;
        } else {
            if (uuidSet) {
                val = "*uuid";
                cnt = 5;
            } else {
                // Don't set "rd=.." if there is no boot device key
                // and no UUID.
                val = "";
                cnt = 0;
            }
        } 
        if (cnt > 0) {
            copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining);
        }
        strlcpy( gRootDevice, val, (cnt + 1));
    }

    if (!processBootArgument(kPlatformKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gPlatformName)) {
        getPlatformName(gPlatformName);
        copyArgument(kPlatformKey, gPlatformName, strlen(gPlatformName), &argP, &cntRemaining);
    }

    if (!getValueForBootKey(cp, kSafeModeFlag, &val, &cnt) &&
        !getValueForBootKey(configKernelFlags, kSafeModeFlag, &val, &cnt)) {
        if (gBootMode & kBootModeSafe) {
            copyArgument(0, kSafeModeFlag, strlen(kSafeModeFlag), &argP, &cntRemaining);
        }
    }

    // Store the merged kernel flags and boot args.

    cnt = strlen(configKernelFlags);
    if (cnt) {
        if (cnt > cntRemaining) {
            error("Warning: boot arguments too long, truncating\n");
            cnt = cntRemaining;
        }
        strncpy(argP, configKernelFlags, cnt);
        argP[cnt++] = ' ';
        cntRemaining -= cnt;
    }
    userCnt = strlen(cp);
    if (userCnt > cntRemaining) {
	error("Warning: boot arguments too long, truncating\n");
	userCnt = cntRemaining;
    }
    strncpy(&argP[cnt], cp, userCnt);
    argP[cnt+userCnt] = '\0';

    gVerboseMode = getValueForKey( kVerboseModeFlag, &val, &cnt ) ||
                   getValueForKey( kSingleUserModeFlag, &val, &cnt );

    gBootMode = ( getValueForKey( kSafeModeFlag, &val, &cnt ) ) ?
                kBootModeSafe : kBootModeNormal;

    if ( getValueForKey( kOldSafeModeFlag, &val, &cnt ) ) {
        gBootMode = kBootModeSafe;
    }

    if ( getValueForKey( kMKextCacheKey, &val, &cnt ) ) {
        strlcpy(gMKextName, val, cnt + 1);
    }

    free(configKernelFlags);
    free(valueBuffer);

    return 0;
}