|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Written by: Rolando Zappacosta |
| 4 | +# rolando_dot_zappacosta_at_nokia_dot_com |
| 5 | + |
| 6 | +KERNEL_VERSION=5.8.18 |
| 7 | +KERNEL_URL=https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-$KERNEL_VERSION.tar.xz |
| 8 | +# |
| 9 | +DRIVER_BCE_URL=https://github.com/t2linux/apple-bce-drv/archive/aur.zip |
| 10 | +DRIVER_IBRIDGE_URL=https://github.com/roadrunner2/macbook12-spi-driver/archive/mbp15.zip |
| 11 | +# |
| 12 | +ZAPPACOR_PATCHES_KERNEL=./zappacor-patches-kernel-$KERNEL_VERSION |
| 13 | +ZAPPACOR_PATCHES_BCE=./zappacor-patches-apple_bce-0.1.patch |
| 14 | +ZAPPACOR_DEFCONF=./zappacor-config-5.8.18 |
| 15 | +ZAPPACOR_DOWNLOADS=./zappacor-downloads |
| 16 | +ZAPPACOR_WORKDIR=./zappacor-work-dir |
| 17 | + |
| 18 | + |
| 19 | +##################################################### |
| 20 | +################## DOWNLOAD KERNEL ################## |
| 21 | +##################################################### |
| 22 | +mkdir -p $ZAPPACOR_DOWNLOADS |
| 23 | +wget -c -P $ZAPPACOR_DOWNLOADS $KERNEL_URL |
| 24 | +mkdir -p $ZAPPACOR_WORKDIR |
| 25 | +tar xf $ZAPPACOR_DOWNLOADS/linux-$KERNEL_VERSION.tar.xz -C $ZAPPACOR_WORKDIR |
| 26 | + |
| 27 | +################################################################## |
| 28 | +################## APPLY UBUNTU AND SMC PATCHES ################## |
| 29 | +################################################################## |
| 30 | +# Ubuntu patches |
| 31 | +# From: |
| 32 | +# https://github.com/marcosfad/mbp-ubuntu-kernel/tree/master/patches |
| 33 | +# Excluded patches: |
| 34 | +# 0004-debian-changelog.patch (from Marcos) |
| 35 | +# Not creating: |
| 36 | +# custom-drivers.patch |
| 37 | +############################################################ |
| 38 | +# SMC patches |
| 39 | +# From: |
| 40 | +# https://github.com/aunali1/linux-mbp-archaunali1/linux-mbp-arch |
| 41 | +# Excluded patches: |
| 42 | +# wifi.patch (not needed) |
| 43 | +# 000[0-9]* (excluded by Marcos, blindly doing the same): |
| 44 | +# 0001-ZEN-Add-sysctl-and-CONFIG-to-disallow-unprivileged-C.patch |
| 45 | +# 0002-virt-vbox-Add-support-for-the-new-VBG_IOCTL_ACQUIRE_.patch |
| 46 | +# |
| 47 | +(ZAPPACOR_PATCHES_KERNEL=`readlink -f $ZAPPACOR_PATCHES_KERNEL` |
| 48 | + cd $ZAPPACOR_WORKDIR/linux-$KERNEL_VERSION |
| 49 | + # This patch is on $ZAPPACOR_PATCHES_KERNEL but it's filtered out by the grep command on the |
| 50 | + # following line (just in case since some folks told Marcos it breaks their systems): |
| 51 | + # 2001-drm-amd-display-Force-link_rate-as-LINK_RATE_RBR2-fo.patch |
| 52 | + for PATCH_FILE in `ls -1 $ZAPPACOR_PATCHES_KERNEL| grep -vE '[2]00[0-9]'`; do |
| 53 | + echo "### Applying patch: `basename $PATCH_FILE`" |
| 54 | + patch -p1 <$ZAPPACOR_PATCHES_KERNEL/$PATCH_FILE |
| 55 | + done |
| 56 | +) |
| 57 | + |
| 58 | +#################################################### |
| 59 | +################## ADD BCE DRIVER ################## |
| 60 | +#################################################### |
| 61 | +# From: https://github.com/aunali1/mbp2018-bridge-drv.git (redirects to https://github.com/t2linux/apple-bce-drv) |
| 62 | +# Will show up as: |
| 63 | +# -> Device Drivers │ |
| 64 | +# -> Macintosh device drivers |
| 65 | +# -> Apple BCE driver (VHCI and Audio support) |
| 66 | +# Download and decompress it |
| 67 | +wget -c -O $ZAPPACOR_DOWNLOADS/apple-bce.zip $DRIVER_BCE_URL |
| 68 | +unzip -d $ZAPPACOR_WORKDIR/linux-$KERNEL_VERSION/drivers/macintosh/ $ZAPPACOR_DOWNLOADS/apple-bce.zip -x '*/.gitignore' |
| 69 | +mv $ZAPPACOR_WORKDIR/linux-$KERNEL_VERSION/drivers/macintosh/apple-bce-drv-aur $ZAPPACOR_WORKDIR/linux-$KERNEL_VERSION/drivers/macintosh/apple-bce |
| 70 | +# Apply this patch to add a modalias to the driver so it can get automatically loaded on boot on a Mac with the T2 chip |
| 71 | +(ZAPPACOR_PATCHES_BCE=`readlink -f $ZAPPACOR_PATCHES_BCE` |
| 72 | + cd $ZAPPACOR_WORKDIR/linux-$KERNEL_VERSION |
| 73 | + patch -p1 <$ZAPPACOR_PATCHES_BCE |
| 74 | +) |
| 75 | +# Create its Kconfig |
| 76 | +printf 'config APPLE_BCE |
| 77 | +\ttristate "Apple BCE driver (VHCI and Audio support)" |
| 78 | +\tdefault m |
| 79 | +\tdepends on X86 |
| 80 | +\tselect SOUND |
| 81 | +\tselect SND |
| 82 | +\tselect SND_PCM |
| 83 | +\tselect SND_JACK |
| 84 | +\thelp |
| 85 | +\t VHCI and audio support on Apple MacBook models 2018 and later. |
| 86 | +
|
| 87 | +\t The project that implements this driver is divided in three components: |
| 88 | +\t - BCE (Buffer Copy Engine): which establishes a basic communication |
| 89 | +\t channel with the T2 chip. This component is required by the other two: |
| 90 | +\t - VHCI (Virtual Host Controller Interface): Access to keyboard, mouse |
| 91 | +\t and other system devices depend on this virtual USB host controller |
| 92 | +\t - Audio: a driver for the T2 audio interface (currently only audio |
| 93 | +\t output is supported). |
| 94 | +\t |
| 95 | +\t Please note that system suspend and resume are currently *not* supported. |
| 96 | +\t |
| 97 | +\t If "M" is selected, the module will be called apple-bce.' >$ZAPPACOR_WORKDIR/linux-$KERNEL_VERSION/drivers/macintosh/apple-bce/Kconfig |
| 98 | +# Edit its Makefile |
| 99 | +sed -i 's/obj-m/obj-$(CONFIG_APPLE_BCE)/g' $ZAPPACOR_WORKDIR/linux-$KERNEL_VERSION/drivers/macintosh/apple-bce/Makefile |
| 100 | +# Edit the kernel drivers Kconfig |
| 101 | +sed -i "\$i source \"drivers/macintosh/apple-bce/Kconfig\"\n" $ZAPPACOR_WORKDIR/linux-$KERNEL_VERSION/drivers/macintosh/Kconfig |
| 102 | +# Edit the kernel drivers Makefile |
| 103 | +echo 'obj-$(CONFIG_APPLE_BCE) += apple-bce/' >>$ZAPPACOR_WORKDIR/linux-$KERNEL_VERSION/drivers/macintosh/Makefile |
| 104 | + |
| 105 | +######################################################### |
| 106 | +################## ADD IBRIDGE DRIVERS ################## |
| 107 | +######################################################### |
| 108 | +# From: https://github.com/roadrunner2/macbook12-spi-driver |
| 109 | +# Will show up as: |
| 110 | +# -> Device Drivers │ |
| 111 | +# -> Macintosh device drivers |
| 112 | +# -> Apple iBridge driver (Touchbar and ALS support) |
| 113 | +# Download and decompress it |
| 114 | +wget -c -O $ZAPPACOR_DOWNLOADS/apple-ibridge.zip $DRIVER_IBRIDGE_URL |
| 115 | +unzip -d $ZAPPACOR_WORKDIR/linux-$KERNEL_VERSION/drivers/macintosh/ $ZAPPACOR_DOWNLOADS/apple-ibridge.zip -x '*/.gitignore' |
| 116 | +mv $ZAPPACOR_WORKDIR/linux-$KERNEL_VERSION/drivers/macintosh/macbook12-spi-driver-mbp15 $ZAPPACOR_WORKDIR/linux-$KERNEL_VERSION/drivers/macintosh/apple-ibridge |
| 117 | +# Create its Kconfig |
| 118 | +printf 'config APPLE_IBRIDGE |
| 119 | +\ttristate "Apple iBridge driver (Touchbar and ALS support)" |
| 120 | +\tdefault m |
| 121 | +\tdepends on X86 |
| 122 | +\tselect HID |
| 123 | +\tselect IIO |
| 124 | +\tselect IIO_TRIGGERED_BUFFER |
| 125 | +\tselect IIO_BUFFER |
| 126 | +\tselect ACPI_ALS |
| 127 | +\thelp |
| 128 | +\t Work in progress driver for the Touchbar and ALS (Ambient |
| 129 | +\t Light Sensor) on 2019 and later Apple MacBook Pro computers. |
| 130 | +\t |
| 131 | +\t If "M" is selected, the modules will be called apple-ibridge, |
| 132 | +\t apple-ib-tb and apple-ib-als.' >$ZAPPACOR_WORKDIR/linux-$KERNEL_VERSION/drivers/macintosh/apple-ibridge/Kconfig |
| 133 | +# Edit its Makefile file |
| 134 | +sed -i 's/obj-m/obj-$(CONFIG_APPLE_IBRIDGE)/g' $ZAPPACOR_WORKDIR/linux-$KERNEL_VERSION/drivers/macintosh/apple-ibridge/Makefile |
| 135 | +# Edit the kernel drivers Kconfig file |
| 136 | +sed -i "\$i source \"drivers/macintosh/apple-ibridge/Kconfig\"\n" $ZAPPACOR_WORKDIR/linux-$KERNEL_VERSION/drivers/macintosh/Kconfig |
| 137 | +# Edit the kernel drivers Makefile file |
| 138 | +echo 'obj-$(CONFIG_APPLE_IBRIDGE) += apple-ibridge/' >>$ZAPPACOR_WORKDIR/linux-$KERNEL_VERSION/drivers/macintosh/Makefile |
| 139 | + |
| 140 | +################################################################# |
| 141 | +################## CONFIG AND BUILD THE KERNEL ################## |
| 142 | +################################################################# |
| 143 | +ZAPPACOR_DEFCONF=`readlink -f $ZAPPACOR_DEFCONF` |
| 144 | +cd $ZAPPACOR_WORKDIR/linux-$KERNEL_VERSION |
| 145 | +make clean |
| 146 | +# Create a default kernel config |
| 147 | +cp $ZAPPACOR_DEFCONF .config |
| 148 | +# Build it |
| 149 | +make -j8 all |
| 150 | +cd - |
| 151 | + |
| 152 | +###################################################################### |
| 153 | +################## LOCAL COMPUTER TEST/INSTALLATION ################## |
| 154 | +###################################################################### |
| 155 | +cd $ZAPPACOR_WORKDIR/linux-$KERNEL_VERSION |
| 156 | +# Should check if the headers are really needed or not (guess they're not) |
| 157 | + make headers ; make headers_install |
| 158 | +make modules_install |
| 159 | +make install |
| 160 | +cd - |
| 161 | +# Need this for the Broadcom WiFi on my *HP laptop* to work (these following steps are *not* related to any Mac at all) |
| 162 | +wget -c -P $ZAPPACOR_DOWNLOADS https://launchpad.net/ubuntu/+source/bcmwl/6.30.223.271+bdcom-0ubuntu7/+build/20102161/+files/bcmwl-kernel-source_6.30.223.271+bdcom-0ubuntu7_amd64.deb |
| 163 | +apt install $ZAPPACOR_DOWNLOADS/bcmwl-kernel-source_6.30.223.271+bdcom-0ubuntu7_amd64.deb |
| 164 | + |
0 commit comments