Skip to content

Commit

Permalink
New HelperPath detection
Browse files Browse the repository at this point in the history
- check for root UUID added.
  • Loading branch information
Piker-Alpha committed Dec 23, 2014
1 parent 4ac8db0 commit baa1f5c
Showing 1 changed file with 57 additions and 31 deletions.
88 changes: 57 additions & 31 deletions i386/boot2/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,14 @@ void boot(int biosdev)
#endif
}
}
// Check for Root UUID (required for Fusion Drives).
if (rootUUID[0] == '\0' && (getValueForKey(kHelperRootUUIDKey, &val, &length, &bootInfo->bootConfig) && length == 36))
{
_BOOT_DEBUG_DUMP("Target boot-uuid=<%s>\n", val);

// Yes. Copy its value into rootUUID.
strlcpy(rootUUID, val, 37);
}

/* Enable touching of a single BIOS device by setting 'Scan Single Drive' to yes.
if (getBoolForKey(kScanSingleDriveKey, &gScanSingleDrive, &bootInfo->bootConfig) && gScanSingleDrive)
Expand Down Expand Up @@ -554,53 +562,71 @@ void boot(int biosdev)
* Starting with Lion, we can take a shortcut by simply pointing
* the 'bootFile' to the kernel cache and we are done.
*/

sprintf(bootFile, "%s", gPlatform.KernelCachePath);
}
else // Try to find a prelinked-kernel/kernelcache
{
char * preLinkedKernelPath = malloc(128);

/*
* We might have been fired up from a USB thumbdrive (kickstart boot) and
* thus we have to check the kernel cache path first (might not be there).
*/
if (gPlatform.HelperPath) // com.apple.boot.[RPS]
{
sprintf(preLinkedKernelPath, "%s%s", gPlatform.HelperPath, gPlatform.KernelCachePath);
}
else
{
sprintf(preLinkedKernelPath, "%s", gPlatform.KernelCachePath);
}

else if (GetFileInfo(NULL, gPlatform.KernelCachePath, &flags, &cachetime) == 0)
{
static char preLinkedKernelPath[128];
static char adler32Key[PLATFORM_NAME_LEN + ROOT_PATH_LEN];
// Check kernelcache directory
if (GetFileInfo(NULL, preLinkedKernelPath, &flags, &cachetime) == 0)
{
static char adler32Key[PLATFORM_NAME_LEN + ROOT_PATH_LEN];

// unsigned long adler32 = 0;
_BOOT_DEBUG_DUMP("Checking for pre-linked kernel...\n");

preLinkedKernelPath[0] = '\0';
// Zero out platform info (name and kernel root path).
bzero(adler32Key, sizeof(adler32Key));

_BOOT_DEBUG_DUMP("Checking for pre-linked kernel...\n");
// Construct key for the pre-linked kernel checksum (generated by adler32).
sprintf(adler32Key, gPlatform.ModelID);
sprintf(adler32Key + PLATFORM_NAME_LEN, "%s", BOOT_DEVICE_PATH);
sprintf(adler32Key + (PLATFORM_NAME_LEN + 38), "%s", bootInfo->bootFile);

// Zero out platform info (name and kernel root path).
bzero(adler32Key, sizeof(adler32Key));
adler32 = Adler32((unsigned char *)adler32Key, sizeof(adler32Key));

// Construct key for the pre-linked kernel checksum (generated by adler32).
sprintf(adler32Key, gPlatform.ModelID);
sprintf(adler32Key + PLATFORM_NAME_LEN, "%s", BOOT_DEVICE_PATH);
sprintf(adler32Key + (PLATFORM_NAME_LEN + 38), "%s", bootInfo->bootFile);

adler32 = Adler32((unsigned char *)adler32Key, sizeof(adler32Key));

_BOOT_DEBUG_DUMP("adler32: %08X\n", adler32);
_BOOT_DEBUG_DUMP("adler32: %08X\n", adler32);

#if ((MAKE_TARGET_OS & LION) == LION) // Yosemite, Mavericks and Mountain Lion also have bit 1 set (like Lion).

_BOOT_DEBUG_DUMP("Checking for kernelcache...\n");
_BOOT_DEBUG_DUMP("Checking for kernelcache...\n");

if (GetFileInfo(gPlatform.KernelCachePath, (char *)kKernelCache, &flags, &cachetime) == 0)
{
sprintf(bootFile, "%s/%s", gPlatform.KernelCachePath, kKernelCache);
// if (GetFileInfo(gPlatform.KernelCachePath, (char *)kKernelCache, &flags, &cachetime) == 0)
if (GetFileInfo(preLinkedKernelPath, (char *)kKernelCache, &flags, &cachetime) == 0)
{
sprintf(bootFile, "%s/%s", preLinkedKernelPath, kKernelCache);

_BOOT_DEBUG_DUMP("Kernelcache located.\n");
_BOOT_DEBUG_DUMP("Kernelcache located.\n");
}
else
{
mayUseKernelCache = false;
_BOOT_DEBUG_DUMP("Failed to locate the kernelcache!\n");
}
}
else
{
mayUseKernelCache = false;
_BOOT_DEBUG_DUMP("Failed to locate the kernelcache directory!\n");
}

if (mayUseKernelCache == false)
{
sprintf(bootFile, "/System/Library/Kernels/%s", bootInfo->bootFile);
_BOOT_DEBUG_DUMP("No kernelcache found, will load: %s!\n", bootInfo->bootFile);
}

_BOOT_DEBUG_ELSE_DUMP("Failed to locate the kernelcache. Will load: %s!\n", bootInfo->bootFile);
free(preLinkedKernelPath);
}

_BOOT_DEBUG_ELSE_DUMP("Failed to locate the kernelcache (directory)!\n");
}
#else // Not for Mavericks/Mountain Lion/Lion, go easy with the Snow Leopard.

Expand Down Expand Up @@ -746,7 +772,7 @@ void boot(int biosdev)

// _BOOT_DEBUG_SLEEP(6);

// Switch to graphics mode and show the Apple logo on a gray-ish background.
// Switch to graphics mode and show the (white) Apple logo on a black/gray background.
showBootLogo(bootRecoveryHD);
}

Expand Down

0 comments on commit baa1f5c

Please sign in to comment.