2010-11-28

Upgraded SleepEnabler.kext to 10.6.5

The SleepEnabler.kext I used with 10.6.4 caused kernel panics with 10.6.5. I learned that this kext is kernel version specific so I grabbed one that was supposed to work with 10.6.5 from kexts.com, but I still got kernel panics. I then decided to build the SleepEnabler.kext from source myself and patch whatever has to be patched.

The main motivation was simply to find out how to do stuff like this. I understand that sleep would also work with a properly patched DSDT, but I leave for some other time.

Prerequisites

Install the Mercurial client and download the xnu-sleep-enabler sources

$ sudo port install mercurial

$ hg clone https://xnu-sleep-enabler.googlecode.com/hg/ xnu-sleep-enabler

Get version specific operating system header files

$ uname -v
Darwin Kernel Version 10.5.0: Fri Nov  5 23:20:39 PDT 2010; root:xnu-1504.9.17~1/RELEASE_I386

This tells you exactly which version of the xnu kernel to download. Navigate to www.opensource.apple.com, click on Mac OS X 10.6.5 and scroll down. Near the bottom of the page you will find this link http://www.opensource.apple.com/tarballs/xnu/xnu-1504.9.17.tar.gz. Download and install next to the sleep enabler.

Patching

The sleep enabler has version specific directories called Headers_10.x.y for the different kernel versions 10.x.y. I created a new one called Headers_10.5.0. There are two files called pmCPU.h and cpu_topology.h in the existing directories:

$ ls -l Headers_10.3.0
total 40
-rw-r--r--  1 macfiets  macfiets  9615 Nov 28 15:56 cpu_topology.h
-rw-r--r--  1 macfiets  macfiets  5208 Nov 28 15:56 pmCPU.h

In the xnu kernel source, those files reside in the osfmk/i386 directory so I copied them from ../xnu-1504.9.17/osfmk/i386 to Headers_10.5.0. It turned out that pmCPU.h also needs rtclock.h so I copied this one too.

$ ls -l Headers_10.5.0
total 56
-rw-r--r-- 1 macfiets  macfiets  9747 Nov 28 15:56 cpu_topology.h
-rw-r--r-- 1 macfiets  macfiets  5634 Nov 28 15:56 pmCPU.h
-rw-r--r-- 1 macfiets  macfiets  4211 Nov 28 15:56 rtclock.h

Next, I fixed the references in pmCPU.h to the two other files.

$ diff ../xnu-1504.9.17/osfmk/i386/pmCPU.h Headers_10.5.0/pmCPU.h
32,33c32,34
< #include <i386/cpu_topology.h>
< #include <i386/rtclock.h>
---
> #include "cpu_topology.h"
> #include "rtclock.h"
>

Building

The last step before actually building this project was to create a new Xcode configuration that would tell Xcode to use the include files from Headers_10.5.0. I copied the Debug configuration to "Debug 10.6.5" and change the KERNEL_VERSION.

sleepenabler 10.6.5.jpg

Now you can build from the Xcode gui or alternatively from the command line

$ xcodebuild -configuration 'Debug 10.6.5'

Check that the resulting binaries contains code for both 32 and 64-bit:

$ file build/Debug\ 10.6.5/SleepEnabler.kext/Contents/MacOS/SleepEnabler
build/Debug 10.6.5/SleepEnabler.kext/Contents/MacOS/SleepEnabler: Mach-O universal binary with 2 architectures
build/Debug 10.6.5/SleepEnabler.kext/Contents/MacOS/SleepEnabler (for architecture x86_64):     Mach-O 64-bit kext bundle x86_64
build/Debug 10.6.5/SleepEnabler.kext/Contents/MacOS/SleepEnabler (for architecture i386):       Mach-O object i386

Done. Install the SleepEnabler.kext in /System/Library/Extensions and reboot.

My Mercurial clone on googlecode.com

I have created a Mercurial clone of the xnu-sleep-enabler project and pushed my changed. If you would like to check it out:

$ hg clone https://macfiets-10-6-5.googlecode.com/hg/ macfiets-10-6-5

- MacFiets

 

No comments:

Post a Comment