Jump to content
RehabMan

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

41 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/

Share this post


Link to post
Share on other sites
Advertisement

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).

Share this post


Link to post
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).

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

If you use chameleon you don't have to patch, just boot with -xcpm! Clover is no good in my opinion. The difference on a hackintosh between UEFI and Legacy EFI doesn't make much of a difference.

 

Just saying.... but great patching guide.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

I switched over to clover and never looked back. I love the ability to patch vbios for proper VESA modes without having to risk flashing and bricking the card.

Share this post


Link to post
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 ?

Share this post


Link to post
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.

Share this post


Link to post
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 ?

Share this post


Link to post
Share on other sites

...

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

Yes. Or workaround with cpus=1.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Yes. Or workaround with cpus=1.

Unfortunately both methods still get early reboot.

Any advice besides Clover booting ?

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

Announcements

  • Similar Content

    • By k.panic
      Ciao ragazzi,
       
      ho provato ad eseguire l'installer di Yosemite su un
      Asrock H110 BTC+
      Intel G3900 (con FakeCPUID 0x0306A0 e flag -xcpm)
      GeForce 710
       
      ma dopo aver raggiunto lo step di "bluetooth transport" mi dà il simbolo del divieto d'accesso.. Cosa sbaglio?
    • By zazman
      Bonjour,
       
      Je rencontre un souci depuis la dernière maj supplémentaire catalina 10.15.4, même chose pour la 10.15.5 aujourd'hui : après le début de l'update, lorsque le pc redémarre, je ne vois pas le volume d'installation dans les volumes de l'écran de boot clover (v5118). j'ai juste Preboot dans les volumes cachés au démarrage, et j'ai essayé de les afficher, le préboot de l'install apparait bien mais le boot n'aboutit jamais par ce biais. du coup, je suis bloqué en 10.15.4. Auriez-vous une idée du problème ?
    • By netseeder1008
      I tried to patch my DSDT.dsl. for Catalina 10.15.4
      i am searching alink where all the error have solution(if know then please share)
      Solved few errors but stuck in those---

      3107, Reserved method must return a value (Integer/String/Buffer/Package/Reference required for _DSM)
      3124, Switch expression is not a static Integer/Buffer/String data type, defaulting to Integer
      3130, Result is not used, possible operator timeout will be missed

      Can anyone tell me how to resolve this problem and any help should be apritiatable.


      Here is my working DSDT
      DSDT.aml
      DSDT.dsl
    • By Cimmerian_Iter
      Hello everyone i have a sony vaio svd1321Z9E intel i7-4500U/4400HD and 8G of ram and using opencore 5.6
      I made a battery patch following rehabman tutorials and i think the patch looks good, but when i try to load it with the kext my pc won't boot to the home menu.

      Like i it does the verbose boot then show me a grey glitchy screen with scattered apple logo.

      Normally it should give this screen then immediately turn into a black apple loading screen (still glitchy) and then return back to normal once it boot into the desktop menu of mac os. (my gpu problem that i never managed to fix but doesn't bother me)

      I would like to know how i could debug and solve this problem. Any help is appreciated.
      Here are my DSDT, config and my battery patch

       
      config.plist
      DSDT.dsl
      SSDT-BATT-3.aml
    • By haoyouandme
      Hello:
      I install hackintosh Catalina 10.15.4, I need some help: 
      If I shut down my Hackintosh, it will reboot.
      If I sleep my Hackintosh, it never wakes up until I force to reboot it or shutdown it.
      Can you help me to solve this problem?
       
      CPU: I9-9900ES (QQZ5)
      Motherboard: Asrock Z390 Pro4
      GPU: Sapphiretech AMD 5700xt
      Memory: Samsung DDR4 16GB
      SSD: Intel 545s 128G SATA
      Power: Cooler master MWE Bronze 650
      EFI.zip
×