2012-08-06 136 views
4

我對編譯最新版本的XNU內核的最佳方式感到困惑。我已經看到許多關於Mac OS X 10.4附帶的較舊內核的說明,但較新的源代碼缺少很多說明中包含的內容。在XNU內核源代碼上運行make會帶來很多關於找不到ctfconvert,ctfmergectfdump的錯誤。有沒有人有一個很好的「如何」來構建一個新的內核?編譯XNU內核2050

+0

有指導例如[雪豹](http://osx86.boeaja.info/2009/10/building-xnu-kernel-on-snow-leopard/)。鑑於他們至少回答了有關'ctf *'工具的問題,您應該儘可能地遵循這些問題。 – 2012-08-06 17:07:58

回答

0

我不認爲這將適用於Lion內核,它需要更高版本的XCode,但是我在構建10.6.8內核時遇到ctf *錯誤的方式是使用XCode 3.2。*

ctf *二進制文件是在「dtrace」編譯過程中創建的。

只需從一個目錄中運行這個腳本而沒有任何空格(例如〜/ xnu是完美的)。最終結果應該是一個工作的10.6.8內核。後來的(甚至更早的)內核都比10.6.8簡單。

#!/usr/bin/env bash 

# Builds 10.6.8 kernel - most other builds are easier, this one needs a little patching. 
# Script assembled by sfinktah 

# Invaluable source: slice - http://www.projectosx.com/forum/lofiversion/index.php/t1922.html 

# Note, two (got this down to one) patches necessary to build 10.6.8 - source: http://www.insanelymac.com/forum/index.php?showtopic=261736 
# This is automatically applied, but I will detail here: 
# 
# You will have to do this: (Automated now, but just in case) 
# Define CPUFAMILY_INTEL_SANDYBRIDGE in ~/xnu-1504.15.3/osfmk/mach/machine.h 
#  #define CPUFAMILY_INTEL_SANDYBRIDGE  0x5490b78c 
# 
# Skipped this step, seemed not to be needed (eventually). Leaving notes in, just in case. 
# Add line 1 in ~/xnu-1504.15.3/makedefs/MakeInc.def: 
#  export BUILD_STABS = 1 
# 

# You should probaby use a local proxy, since this script makes no effort not to redownload 
# existing items. Uncomment this line accordingly. 

# export http_proxy=192.168.1.6:3128 

export PATH="/usr/local/bin:$PATH" 

CURL="curl -O " 
echo "Download the build tools source(s)" 

KEXT=kext_tools-180.2.1 
BOOTSTRAP=bootstrap_cmds-79 
DTRACE=dtrace-90 
CXXFILT=cxxfilt-9 
KERNEL=xnu-1504.15.3 
CCTOOLS=cctools-806 
# DYLD=dyld-132.13 
# LD64=ld64-95.2.12 

$CURL http://www.opensource.apple.com/tarballs/cxxfilt/$CXXFILT.tar.gz \ 
&& $CURL http://www.opensource.apple.com/tarballs/dtrace/$DTRACE.tar.gz \ 
&& $CURL http://www.opensource.apple.com/tarballs/kext_tools/$KEXT.tar.gz \ 
&& $CURL http://www.opensource.apple.com/tarballs/bootstrap_cmds/$BOOTSTRAP.tar.gz \ 
&& $CURL http://www.opensource.apple.com/tarballs/cctools/$CCTOOLS.tar.gz && 
# && # $CURL http://www.opensource.apple.com/tarballs/dyld/$DYLD.tar.gz 
# && # $CURL http://www.opensource.apple.com/tarballs/ld64/$LD64.tar.gz 

echo "Unpack the tools" \ 
&& 
tar zxf $CXXFILT.tar.gz \ 
&& tar zxf $DTRACE.tar.gz \ 
&& tar zxf $KEXT.tar.gz \ 
&& tar zxf $BOOTSTRAP.tar.gz \ 
&& tar zxf $CCTOOLS.tar.gz && 
# && # tar zxf $LD64.tar.gz 
# && # tar zxf $DYLD.tar.gz 


# Copy folder cctools-8xx/include/mach-o/ to /usr/include/mach-o/ 
sudo cp -a $CCTOOLS/include/mach-o /usr/include/ \ 
&& 
echo "Build cxxfilt" \ 
&& 
cd $CXXFILT \ 
&& mkdir -p obj sym dst \ 
&& make install RC_ARCHS="i386 x86_64" RC_CFLAGS="-arch i386 -arch x86_64 -pipe" RC_OS=macos RC_RELEASE=SnowLeopard SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst \ 
&& sudo ditto $PWD/dst/usr/local /usr/local \ 
&& cd .. \ 
&& 
echo "Build dtrace" \ 
&& 
cd $DTRACE \ 
&& mkdir -p obj sym dst \ 
&& xcodebuild install -target ctfconvert -target ctfdump -target ctfmerge ARCHS="i386 x86_64" SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst \ 
&& sudo ditto $PWD/dst/usr/local /usr/local \ 
&& cd .. \ 
&& 
echo "Build kext_tools" \ 
&& 
cd $KEXT \ 
&& mkdir -p obj sym dst \ 
&& xcodebuild install -target kextsymboltool -target setsegname ARCHS="i386 x86_64" SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst \ 
&& sudo ditto $PWD/dst/usr/local /usr/local \ 
&& cd .. \ 
&& 
echo "Build bootstrap_cmds" \ 
&& 
cd $BOOTSTRAP \ 
&& mkdir -p obj sym dst \ 
&& make install RC_ARCHS="i386" RC_CFLAGS="-arch i386 -pipe" RC_OS=macos RC_RELEASE=SnowLeopard SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst \ 
&& sudo ditto $PWD/dst/usr/local /usr/local \ 
&& cd .. \ 
&& 
echo "Download the xnu source" \ 
&& 
$CURL http://www.opensource.apple.com/tarballs/xnu/$KERNEL.tar.gz \ 
&& 
echo "Unpack xnu" \ 
&& 
tar zxf $KERNEL.tar.gz \ 
&& 
echo "Build xnu" \ 
&& 
cd $KERNEL \ 
&& sed -i -e '1s/.*/#define CPUFAMILY_INTEL_SANDYBRIDGE 0x5490b78c \/*/' osfmk/mach/machine.h \ 
&& make ARCH_CONFIGS="I386 X86_64" KERNEL_CONFIGS="RELEASE" \ 
&& file BUILD/obj/RELEASE_*/mach_kernel && 
# && # Removing AppleProfileFamily.kext - http://lists.apple.com/archives/darwin-kernel/2009/Dec/msg00000.html 
echo "Complete. Remember to remove /System/Library/Extensions/AppleProfileFamily.kext from target." \ 
|| echo "Failed" 

# vim: set ts=180 sts=0 sw=3 noet: 
6

一本新書by Wiley詳細介紹了一套完整的操作方法在第9章

試試這個:

# 
# Getting C++ filter 
# 
$ curl http://opensource.apple.com/tarballs/cxxfilt/cxxfilt-9.tar.gz > cxx.tar.gz 
$ tar xvf cxx.tar.gz 
$ cd cxxfilt-9 
$ mkdir -p build obj sym 
$ make install RC_ARCHS="i386 x86_64" RC_CFLAGS="-arch i386 -arch x86_64 -pipe" \ 
RC_OS=macos RC_RELEASE=Lion SRCROOT=$PWD OBJROOT=$PWD/obj \ SYMROOT=$PWD/sym DSTROOT=$PWD/build 
# 
# Getting DTrace – This is required for ctfconvert, a kernel build tool 
# 
$ curl http://opensource.apple.com/tarballs/dtrace/dtrace-90.tar.gz > dt.tar.gz 
$ tar zxvf dt.tar.gz 
$ cd dtrace-90 
$ mkdir -p obj sym dst 
$ xcodebuild install -target ctfconvert -target ctfdump -target ctfmerge \ ARCHS="i386 x86_64" SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym \ DSTROOT=$PWD/dst 
# 
# Getting Kext Tools 
# 
$ wget http://opensource.apple.com/tarballs/Kext_tools/Kext_tools-180.2.1.tar.gz \ > kt.tar.gz 
$ tar xvf kt.tar.gz 
$ cd Kext_tools-180.2.1 
$ mkdir -p obj sym dst 
$ xcodebuild install -target Kextsymboltool -target setsegname \ ARCHS="i386 x86_64" SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym \ 
DSTROOT=$PWD/dst 
# 
# Getting Bootstrap commands – newer versions are available, but would # force xcodebuild 
# 
$ curl http://opensource.apple.com/tarballs/bootstrap_cmds/bootstrap_cmds-72.tar.gz \ > bc.tar.gz 
$ tar zxvf bc.tar.gz 
$ cd bootstrap_cmds-84 
$ mkdir -p obj sym dst 
$ make install RC_ARCHS="i386" RC_CFLAGS="-arch i386 -pipe" RC_OS=macos \ 
RC_RELEASE=Lion SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst 

焦油球版本現在是不同的(如DTrace是96,不是90),但這應該可以滿足依賴關係。一旦你有他們,你只是運行通常的做法(使ARCH_CONFIGS=" X86_64" KERNEL_CONFIGS="RELEASE")。您可能需要添加DEBUG,以獲取默認禁用的優秀調試和跟蹤消息。

這適用於XCode 4.4。實際上,現在就試過了。

+0

愛新書喬納森! – trojanfoe 2012-11-14 18:52:42