我对编译最新版本的XNU内核的最佳方法感到困惑。我已经看到很多关于Mac OS X 10.4附带的旧内核的说明,但是较新的源代码缺少指令所包含的许多内容。只是在XNU内核源上运行make
会带来很多关于找不到ctfconvert
,ctfmerge
和ctfdump
的错误。有没有人有一个很好的“howto”来构建一个新内核?
答案 0 :(得分: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
tar ball版本现在不同了(例如DTrace是96,而不是90),但这应该可以满足依赖性。一旦你拥有它们,你就可以运行通常的make(make ARCH_CONFIGS=" X86_64" KERNEL_CONFIGS="RELEASE"
)。您可能希望添加DEBUG
,以获得默认禁用的优秀调试和跟踪消息。
这适用于XCode 4.4。现在就试试吧。
答案 1 :(得分:0)
我不认为这将适用于需要更高版本的XCode的Lion内核,但是在构建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: