Skip to content

Instantly share code, notes, and snippets.

@Kyle-Ye
Last active November 26, 2022 01:02
Show Gist options
  • Save Kyle-Ye/c5aa91e9ec6cd6dc1247beb1866ed663 to your computer and use it in GitHub Desktop.
Save Kyle-Ye/c5aa91e9ec6cd6dc1247beb1866ed663 to your computer and use it in GitHub Desktop.
XNU build script
download() {
gh repo clone apple-oss-distributions/distribution-macOS
cd distribution-macOS
# checkout to macos-123 since Xcode 13.4 is bundled with macOS 12.3 SDK
git checkout tags/macos-123
export TOOLCHAIN_PATH=$(cd `xcrun -sdk macosx -show-sdk-platform-path`/../../Toolchains/XcodeDefault.xctoolchain && pwd)
export SDKPATH=$(xcrun -sdk macosx -show-sdk-path)
export XCODEPATH=$(xcrun -sdk macosx -show-sdk-path | sed 's,\(.*/Xcode[^/]*\.app\)/.*,\1,')
rm -rf dtrace
git submodule update --init dtrace
cd dtrace
xcodebuild install -sdk macosx -target ctfconvert \
-target ctfdump -target ctfmerge \
ARCHS='x86_64 arm64' VALID_ARCHS='x86_64 arm64' DSTROOT="$PWD/dst"
sudo ditto "$PWD/dst/$TOOLCHAIN_PATH" "$TOOLCHAIN_PATH"
cd ..
rm -rf AvailabilityVersions
git submodule update --init AvailabilityVersions
cd AvailabilityVersions
make install
sudo ditto "$PWD/dst/usr/local/libexec" "$SDKPATH/usr/local/libexec"
cd ..
rm -rf xnu
git submodule update --init xnu
cd xnu
make SDKROOT=macosx ARCH_CONFIGS="X86_64 ARM64" installhdrs
sudo ditto "$PWD/BUILD/dst" "$SDKPATH"
cd ..
rm -rf libdispatch
git submodule update --init libdispatch
cd libdispatch
xcodebuild install -sdk macosx ARCHS='x86_64 arm64e' \
VALID_ARCHS='x86_64 arm64e' -target libfirehose_kernel \
PRODUCT_NAME=firehose_kernel DSTROOT=$PWD/dst
sudo ditto "$PWD/dst/usr/local" "$SDKPATH/usr/local"
cd ..
}
build() {
# makedefs/MakeInc.def USE_WERROR := 0
# iokit/Kernel/IOBufferMemoryDescriptor.cpp Null → false
cd xnu
# Build for arm64
export KDK=/Library/Developer/KDKs/KDK_12.3_21E230.kdk
make SDKROOT=macosx KDKROOT=$KDK TARGET_CONFIGS="RELEASE ARM64 T8101"
# Build for x86_64
# make SDKROOT=macosx ARCH_CONFIGS=x86_64 KERNEL_CONFIGS=RELEASE
cd ..
}
install() {
cd xnu
kmutil create -a arm64e -z -V development -n boot \
-B BUILD/OpenSource.kc \
-k BUILD/obj/kernel.development.t8101 \
-r /System/Library/Extensions \
-r /System/Library/DriverExtensions \
-x \
$(kmutil inspect -V release --no-header | grep -v "SEPHiber" | awk '{print " -b "$1; }')
# kmutil create -a arm64e -z -V release -n boot \
# -B BUILD/OpenSource.kc \
# -k BUILD/obj/kernel.release.t8101 \
# -r /System/Library/Extensions \
# -r /System/Library/DriverExtensions \
# -x \
# $(kmutil inspect -V release --no-header | grep -v "SEPHiber" | awk '{print " -b "$1; }')
cd ..
}
download
build
install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment