Jump to content

[GUIDE] Patching the kernel for Haswell CPUs, XCPM early reboot


RehabMan
 Share

42 posts in this topic

Recommended Posts

Overview

 

The first version of OS X to support Haswell CPUs was Mountain Lion 10.8.5. At the same time, for certain CPUs including Haswell, Apple moved CPU power management from AppleIntelCPUPowerManagement.kext to the kernel. This technology is known as XCPM (Xnu CPU Power Management). This technology is enabled for Haswell CPUs automatically and can optionally be use with Ivy Bridge CPUs with the -xcpm kernel flag.

 

The problem is Apple's computers do not have a locked MSR 0xE2, yet most PC laptops do. When the kernel tries to write to this locked register, it causes a panic. And this panic happens so early in the process that it results in a reboot. Similar to how we must patch AppleIntelCPUPowerManagement.kext for locked CPU MSR 0xE2, the kernel must also be patched for CPUs using XCPM to avoid this reboot.

 

Background information can be found here: http://www.insanelymac.com/forum/topic/293503-haswell-early-reboot-mavericks-locked-msrs-and-hp-envy-15-j063cl-i7-4700mq

 

 

How to patch the kernel

 

After creating your USB installer, you should have the "vanilla" kernel. Here's how to patch it:

 

For Yosemite 10.10.x:

 

 

# in Terminal, assuming your USB is called Installer
cp /Volumes/Installer/System/Library/Kernels/kernel ~/Desktop/kernel_backup
cp /Volumes/Installer/System/Library/Kernels/kernel ~/Desktop/kernel
cd ~/Desktop
# now patch the kernel at ~/Desktop/kernel
perl -pi -e 's|\xe2\x00\x00\x00\x02\x00\x00\x00|\x00\x00\x00\x00\x00\x00\x00\x00|g' kernel
perl -pi -e 's|\xe2\x00\x00\x00\x4c\x00\x00\x00|\x00\x00\x00\x00\x00\x00\x00\x00|g' kernel
perl -pi -e 's|\xe2\x00\x00\x00\x90\x01\x00\x00|\x00\x00\x00\x00\x00\x00\x00\x00|g' kernel
# patched kernel is now at ~/Desktop/kernel
sudo cp kernel /Volumes/Installer/System/Library/Kernels/kernel
After you install OS X to your HDD, you will have vanilla kernel on the HDD, leading to the same instant reboot problem. So, you must re-enter the OS X installer, and go into Terminal (using Utilities -> Terminal) and replace the kernel with the patched version:

 

# in Terminal from the OS X installer, assuming your HDD volume is called "Macintosh HD"
cp /System/Library/Kernels/kernel "/Volumes/Macintosh HD/System/Library/Kernels/kernel"
After that, you can exit the installer, and boot into the installed partition to finish installation and reach the desktop.

 

 

MD5 sums for the kernel

 

Check your md5 sums with:

md5 /Volumes/Installer/System/Library/Kernels/kernel
10.10/10.10.1 kernel

vanilla: 9f1768fddec369e545d938f0f4f76350

xcpm patched: 1938ebb0bd6cdc00930543025d3df887

 

10.10.2 kernel

vanilla: 8a985412c42c153601580fd1b8bc360e

xcpm patched: cc46457172315aea68d8e1f957d2746c

 

10.10.3 kernel

vanilla: fd9b0ed2a37a393d145033a2f0ce46b4

xcpm patched: d89759c11c5f434b4434b6fbf0464d6c

 

 

A note about Clover

 

The Clover bootloader has this patch built-in with the config.plist/KernelAndKextPatches/KernelPm option.

 

Keep in mind if you're not using Clover (and KernelPm), you will have to re-patch the (new) kernel after any OS X update. With Clover, it is automatic provided the code in Clover is updated (if necessary) to patch the (new) kernel.

 

 

 

Update 2015-01-26

 

For details see the blog article: https://racerrehabman.wordpress.com/2014/10/18/yosemitehaswell-kernel-patch-for-early-reboot/

  • Like 10
Link to comment
Share on other sites

Hello

 

Good to see that has now a patch for 10.10 ;)

 

Thanks!

It has been around for quite a while, although it was in the original post in the Mavericks forum... (and on my blog, of course).

  • Like 2
Link to comment
Share on other sites

Hello

 

Can i post this information in my guide? : http://www.insanelymac.com/forum/topic/295587-power-management-for-sandy-and-ivy-bridger/

 

This guide is something very generic to several models and I just gathered a lot of information in a single guide to help users. :)

I would appreciate it linking back to the source (eg. this post).

Link to comment
Share on other sites

"A note about Clover



The Clover bootloader has this patch built-in with the config.plist/KernelAndKextPatches/KernelPm option.

Keep in mind if you're not using Clover (and KernelPm), you will have to re-patch the (new) kernel after any OS X update. With Clover, it is automatic provided the code in Clover is updated (if necessary) to patch the (new) kernel."

 

 

That makes my llife a lot easyer on my X99 with 5930K! I didn't know that but that' a lifesaver!

Thanks for sharing!

 

Ed

Link to comment
Share on other sites

If you use chameleon you don't have to patch, just boot with -xcpm!

Not true. First, -xcpm is only useful with Ivy CPUs as XCPM is default for Haswell. Second, if you do use -xcpm to force XCPM on Ivy, you will still need to patch the kernel. You don't need to patch it if you're not using XCPM (pre-Haswell and not using -xcpm with Ivy), or if your motherboard BIOS does not lock CPU MSR 0xe2.

 

Clover is no good in my opinion. The difference on a hackintosh between UEFI and Legacy EFI doesn't make much of a difference, UNLESS you have a Apple SSD which at that point you might as well buy a real Mac.

Clover has significant advantages over Chameleon. Here is a list I made:

- faster UEFI boot

- simpler bootloader configuration in normal files away from "boot records"

- no boot0 problems with 4k/AF HDDs

- no issues with BIOS implementations that refuse to boot legacy to GPT drives

- no wierd issues with bootloader lockups when large drives are connected

- central location for bootloader configuration files

- automatic patching for common kernel problems (XCPM, "Local APIC")

- automatic patching for common kext problems (AppleIntelCPUPowerManagement)

- ability to provide custom patches for any kext

- ability to update to major versions by running the app from the App Store

- ability to setup the system such that little or no post-upgrade tasks need to be done

- updates are easier (and more like a real Mac) because of all of the above

- support for creating the Recovery partition during installation

- support for booting the Recovery partition

- pure GPT, so no hassles associated with hybrid GPT/MBR schemes used in dual-boot scenarios

- ability to boot UEFI installs of Windows (very common on new computers)

- active development

 

Whether you have an Apple SSD or non-Apple SSD seems rather irrelevant to bootloader choice.

  • Like 1
Link to comment
Share on other sites

I said in my opinion, I used clover in mavericks and it was very hard for a new beginner to learn unlike chameleon. I understand the update features but we all know with our rigs NOT to update due to it ruining the install {10.8.2 to 10.8.5 crashed almost everyone including me}. I was talking about Haswell and I don't have an Ivy-Bridge cause of this reason. Show me the comparison boot time between Clover and Chameleon almost exact I've tried. So bottom line it all comes down to what you want, they are both boot loaders! I edited my post to help you sleep better at night :)

 

Edit* And just to be specific I was talking about the native TRIM on Apple SSD's no matter the OS.

Link to comment
Share on other sites

I said in my opinion, I used clover in mavericks and it was very hard for a new beginner to learn unlike chameleon.

Just because it is difficult to learn does not make it "not good."

 

I understand the update features but we all know with our rigs NOT to update

A properly configured Clover setup can be updated as easily as a real Mac in most cases.

 

I was talking about Haswell and I don't have an Ivy-Bridge cause of this reason.

With Haswell, unless you have an unlocked MSR 0xE2, you must patch the kernel.

 

Show me the comparison boot time between Clover and Chameleon almost exact I've tried.

Time from BIOS to bootloader is definitely faster. This is mostly due to the direct nature of UEFI (less chainloading to code that must scan drives/partitions). This may depend on your hardware configuration and BIOS though. After that there isn't much difference, except for the fact that I don't miss the overly verbose nature of Chameleon's -v (is it really necessary to list each kext being loaded, *twice*?)

 

Edit* And just to be specific I was talking about the native TRIM on Apple SSD's no matter the OS.

I am aware of the issues with TRIM on non-Apple SSDs. It is just that it has nothing to do with the kernel or bootloaders except for with Clover, you don't have to worry about about the patch to IOACHIBlockStorage being overwritten by an update.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Thanks for your excellent patching for Haswell's CPUs.

In 10.9.x it worked perfectly for my Asus laptop G750.

However, following this in 10.10.1 it still gets early reboot by Chameleon.

Only Clover is working without this patch for me now.

But I need Chameleon booting which is working in 10.9.x to modify my DSDT and HD4600's video/audio, etc.

Can you give me more advice to prevent its reboot in Chameleon ?

  • Like 1
Link to comment
Share on other sites

Thanks for your excellent patching for Haswell's CPUs.

In 10.9.x it worked perfectly for my Asus laptop G750.

However, following this in 10.10.1 it still gets early reboot by Chameleon.

Only Clover is working without this patch for me now.

But I need Chameleon booting which is working in 10.9.x to modify my DSDT and HD4600's video/audio, etc.

Can you give me more advice to prevent its reboot in Chameleon ?

Check that you patched correctly (check md5 sum of the kernel).

 

And... you may have early reboot due to "Local APIC" panic. Use the KernelPatcher module in that case.

Link to comment
Share on other sites

Check that you patched correctly (check md5 sum of the kernel).

 

And... you may have early reboot due to "Local APIC" panic. Use the KernelPatcher module in that case.

The MD5 of the xcpm patched kernel is correct.

Do you mean to apply Chameleon Wizard's KernelPatcher module for Chameleon booting ?

Link to comment
Share on other sites

Can you tell me what is the different between this:

Here is a quick and dirty patch for the mach_kernel to let it run Haswell code on Haswell-E

1.

Patch the vanilla kernel using a Haswell code:

sudo perl -pi -e 's|\x74\x11\x83\xF8\x3C|\x74\x11\x83\xF8\x3F|g' /System/Library/Kernels/kernel

 

found here;http://www.insanelymac.com/forum/topic/301585-haswell-e-mach-kernel-patch-5960x-5830k-and-5820k-yosemite/

 

And this patch?

 

I'm just curious because I have tried the clover "config.plist/KernelAndKextPatches/KernelPm option." bootflag and updated to 10.10.1

But I got the reboot again.

 

Like to know. Thanks again.

Link to comment
Share on other sites

Unfortunately both methods still get early reboot.

Any advice besides Clover booting ?

Can you even boot from USB? If so than there the patch is working fine.

Reboot from USB and copy in terminal the patched kernel to your HD.

And reboot.

Link to comment
Share on other sites

Unfortunately both methods still get early reboot.

Any advice besides Clover booting ?

Either you haven't done it correctly or you have a different problem. There are other things that can cause early reboot:

- problems with ACPI (DSDT/SSDT issues)

- DEP not enabled in BIOS

- graphics chip issues

Link to comment
Share on other sites

Can you even boot from USB? If so than there the patch is working fine.

Reboot from USB and copy in terminal the patched kernel to your HD.

And reboot.

No, I can not boot from USB with this patched kernel either.

Thanks.

The only way to boot is via Clover now.

Either you haven't done it correctly or you have a different problem. There are other things that can cause early reboot:

- problems with ACPI (DSDT/SSDT issues)

- DEP not enabled in BIOS

- graphics chip issues

Thanks and I'll try to figure it out why with the same BIOS, DSDT/SSDT, and Intel HD4600 Graphics working in Mavericks and not working in Yosemite via Chameleon bootloader.

Link to comment
Share on other sites

  • 4 weeks later...

Hi Rehabman.  I was so happy to see your post about the kernel fix for the boot loop.  Your patch got me past the boot loop but when I select USB at the Chimera screen of ##### the screen blanks out for a few seconds, then a white background grey Apple logo appears with a progress bar underneath (what you see on a real Mac as Yosemite launches).  The progress bar reaches about 10% complete and then I get text overwritting the screen that appears to be a Panic attack.  The first line of text reads: "panic (CPU 0 caller 0xffffff8000379458): a freed zone element has been modified in zone kalloc64:...."

 

I have an Intel NUC D54250WYKH with 8 GB Crucial RAM and Mushkin Direct Atlas Deluxe 120GB mSTAT SSD.  I setup the ##### 5.0.2 installer following  the most recent directions from tonymacx86.  My Yosemite installer is version 1.6.7 downloaded 12/19/14. 

 

Any idea why I can't get past the boot screen?

 

Suggestions would be greatlly appreciated.

 

Gene

 
Link to comment
Share on other sites

  • 4 weeks later...

Hi Rehabman.  I was so happy to see your post about the kernel fix for the boot loop.  Your patch got me past the boot loop but when I select USB at the Chimera screen of ##### the screen blanks out for a few seconds, then a white background grey Apple logo appears with a progress bar underneath (what you see on a real Mac as Yosemite launches).  The progress bar reaches about 10% complete and then I get text overwritting the screen that appears to be a Panic attack.  The first line of text reads: "panic (CPU 0 caller 0xffffff8000379458): a freed zone element has been modified in zone kalloc64:...."

 

I have an Intel NUC D54250WYKH with 8 GB Crucial RAM and Mushkin Direct Atlas Deluxe 120GB mSTAT SSD.  I setup the ##### 5.0.2 installer following  the most recent directions from tonymacx86.  My Yosemite installer is version 1.6.7 downloaded 12/19/14. 

 

Any idea why I can't get past the boot screen?

 

Suggestions would be greatlly appreciated.

 

Gene

Your panic is likely caused from using a rollback AppleACPIPlatform.kext.

  • Like 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...