Skip to content

Commit

Permalink
Add lint job + fixes to @jamlam patches
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeeq committed Feb 18, 2020
1 parent bf90311 commit 7cbba59
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 111 deletions.
53 changes: 31 additions & 22 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,37 @@ kind: pipeline
name: mbp-fedora-kernel

steps:
- name: build
image: fedora:31
pull: always
volumes:
- name: build-artifacts
path: /tmp/artifacts
commands:
- ./build.sh
- name: lint
image: alpine
pull: always
commands:
- apk add --no-cache shellcheck python3 bash
- pip3 install yamllint
- yamllint .
- shellcheck ./*.sh

- name: publish-github
image: plugins/github-release
volumes:
- name: build-artifacts
path: /tmp/artifacts
settings:
api_key:
from_secret: github_token
files: /tmp/artifacts/*
prerelease: yes
when:
event: tag
- name: build
image: fedora:31
pull: always
volumes:
- name: build-artifacts
path: /tmp/artifacts
commands:
- ./build.sh

- name: publish-github
image: plugins/github-release
volumes:
- name: build-artifacts
path: /tmp/artifacts
settings:
api_key:
from_secret: github_token
files: /tmp/artifacts/*
prerelease: true
when:
event: tag

volumes:
- name: build-artifacts
temp: {}
- name: build-artifacts
temp: {}
28 changes: 20 additions & 8 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/sh
#!/bin/bash

set -euf -o pipefail

## Update fedora docker image tag, because kernel build is using `uname -r` when defining package version variable
FEDORA_KERNEL_GIT_URL=https://src.fedoraproject.org/rpms/kernel.git
Expand All @@ -13,7 +15,7 @@ echo "FEDORA_KERNEL_COMMIT_HASH=$FEDORA_KERNEL_COMMIT_HASH"
pwd
ls
echo "CPU threads: $(nproc --all)"
cat /proc/cpuinfo | grep 'model name' | uniq
grep 'model name' /proc/cpuinfo | uniq
# git clone --depth 1 --single-branch --branch v5.1.19 git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git

### Dependencies
Expand All @@ -23,11 +25,11 @@ dnf install -y fedpkg fedora-packager rpmdevtools ncurses-devel pesign git libkc
git clone --single-branch --branch $FEDORA_KERNEL_BRANCH_NAME ${FEDORA_KERNEL_GIT_URL}
cd kernel
## Cleanup
rm -rfv *.rpm
rm -rfv ./*.rpm
rm -rf ~/rpmbuild/*
git reset --hard $FEDORA_KERNEL_BRANCH_NAME
git checkout $FEDORA_KERNEL_BRANCH_NAME
git branch -d fedora_patch_src
git branch -d fedora_patch_src &>/dev/null || true
fedpkg clean
## Change branch
git checkout $FEDORA_KERNEL_COMMIT_HASH
Expand All @@ -39,22 +41,32 @@ dnf -y builddep kernel.spec
# sed -i "s/Patch509/Patch516/g" kernel.spec

### Create patch file with custom drivers
echo >&2 "===]> Info: Creating patch file... ";
FEDORA_KERNEL_VERSION=${FEDORA_KERNEL_VERSION} ../patch_driver.sh

### Apply patches
for patch_file in $(ls ../patches)
if [ ! -f scripts/newpatch.sh ]; then
cp -rf ../fedora/newpatch.sh scripts/newpatch.sh
fi
echo >&2 "===]> Info: Applying patches... ";
[ ! -d ../patches ] && { echo 'Patches directory not found!'; exit 1; }
while IFS= read -r file
do
scripts/newpatch.sh ../patches/$patch_file
done
echo "adding $file"
scripts/newpatch.sh "$file"
done < <(find ../patches -type f -name "*.patch" | sort)

### Change buildid to mbp
echo >&2 "===]> Info: Setting kernel name... ";
sed -i 's/%define buildid.*/%define buildid .mbp/' ./kernel.spec

### Build src rpm
echo >&2 "===]> Info: Bulding src.rpm ... ";
fedpkg --release $FEDORA_KERNEL_BRANCH_NAME srpm

### Build non-debug rpms
./scripts/fast-build.sh x86_64 $(ls | grep src.rpm)
echo >&2 "===]> Info: Bulding kernel ... ";
./scripts/fast-build.sh x86_64 "$(find . -type f -name "*.src.rpm")"
rpmbuild_exitcode=$?

### Copy artifacts to shared volume
Expand Down
6 changes: 4 additions & 2 deletions build_in_docker.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/sh
#!/bin/bash

set -euf -o pipefail

DOCKER_IMAGE=fedora:31
RPMBUILD_HOST_PATH=/opt/rpmbuild
Expand All @@ -9,7 +11,7 @@ docker pull ${DOCKER_IMAGE}
docker run \
-t \
--rm \
-v $(pwd):/repo \
-v "$(pwd)":/repo \
-v ${RPMBUILD_HOST_PATH}:/root/rpmbuild \
${DOCKER_IMAGE} \
/bin/bash -c 'cd /repo && ./build.sh'
42 changes: 42 additions & 0 deletions fedora/newpatch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/sh

# Facilitates the addition of a new patch to the source tree.
# -- Moves patch to tree
# -- Adds patch to kernel.spec list of patches
# -- Adds patch to git
# -- change buildid macro to the name of the patch being added

# Base directory is relative to where the script is.
BASEDIR="$(dirname "$(cd $(dirname $BASH_SOURCE[0]) && pwd)")"
pushd $BASEDIR > /dev/null
# Check for at least patch
if [ "$#" -lt 1 ]; then
echo "usage: $0 [ /path/to/patch/ ] [ description ]"
exit 1
fi
PATCHDIR=$1
DESC=$2
PATCH="$(basename "$PATCHDIR")"
# Kernel.spec file in the current tree
SPECFILE="$BASEDIR/kernel.spec"
# If adding patch from outside the source tree move it to the source tree
if [ -z "$(ls | grep $PATCH)" ]; then
cp $PATCHDIR $BASEDIR/
fi

if [ ! -z "$(grep $PATCH $SPECFILE)" ]
then
echo "$PATCH already in kernel.spec"
exit 1
fi
# ID number of the last patch in kernel.spec
LPATCH_ID=$(grep ^Patch $SPECFILE | tail -n1 | awk '{ print $1 }' | sed s/Patch// | sed s/://)
# ID of the next patch to be added to kernel.spec
NPATCH_ID=$(($LPATCH_ID + 1 ))
# Add patch with new id at the end of the list of patches
sed -i "/^Patch$LPATCH_ID:\ /a#\ $DESC\nPatch$NPATCH_ID:\ $PATCH" $SPECFILE
# Add it to git
git add $PATCH
BUILDID_PATCH="$(echo $PATCH | sed 's/\-/\_/g' )"
sed -i "s/^.*define buildid .*$/%define buildid .$BUILDID_PATCH/" $SPECFILE
popd > /dev/null
127 changes: 71 additions & 56 deletions patch_driver.sh
Original file line number Diff line number Diff line change
@@ -1,72 +1,87 @@
#!/bin/sh
#!/bin/bash

set -euf -o pipefail

### Apple T2 drivers commit hashes
BCE_DRIVER_GIT_URL=https://github.com/MCMrARM/mbp2018-bridge-drv.git
BCE_DRIVER_BRANCH_NAME=master
BCE_DRIVER_COMMIT_HASH=7330e638b9a32b4ae9ea97857f33838b5613cad3
APPLE_IB_DRIVER_GIT_URL=https://github.com/roadrunner2/macbook12-spi-driver.git
APPLE_IB_DRIVER_BRANCH_NAME=mbp15
APPLE_IB_DRIVER_COMMIT_HASH=90cea3e8e32db60147df8d39836bd1d2a5161871
# BCE_DRIVER_GIT_URL=https://github.com/MCMrARM/mbp2018-bridge-drv.git
# BCE_DRIVER_BRANCH_NAME=master
# BCE_DRIVER_COMMIT_HASH=7330e638b9a32b4ae9ea97857f33838b5613cad3
# APPLE_IB_DRIVER_GIT_URL=https://github.com/roadrunner2/macbook12-spi-driver.git
# APPLE_IB_DRIVER_BRANCH_NAME=mbp15
# APPLE_IB_DRIVER_COMMIT_HASH=90cea3e8e32db60147df8d39836bd1d2a5161871
APPLE_SMC_DRIVER_GIT_URL=https://github.com/MCMrARM/mbp2018-etc
APPLE_SMC_DRIVER_BRANCH_NAME=master
APPLE_SMC_DRIVER_COMMIT_HASH=cf42289ad637d3073e2fd348af71ad43dd31b8b4

REPO_PWD=$(pwd)
echo -e "From: fedora kernel <fedora@kernel.org>\nSubject: patch custom drivers\n" > ../patches/custom-drivers.patch

mkdir -p /root/temp
cd /root/temp
cd /root/temp || exit

### AppleSMC
git clone --single-branch --branch ${APPLE_SMC_DRIVER_BRANCH_NAME} ${APPLE_SMC_DRIVER_GIT_URL}
cp -rfv mbp2018-etc/applesmc/patches/* ${REPO_PWD}/../patches/
cd mbp2018-etc || exit
git checkout ${APPLE_SMC_DRIVER_COMMIT_HASH}
cd ..
[ ! -d mbp2018-etc/applesmc/patches ] && { echo 'AppleSMC patches directory not found!'; exit 1; }
while IFS= read -r file; do
echo "adding ${file}"
cp -rfv "${file}" "${REPO_PWD}"/../patches/"${file##*/}"
done < <(find mbp2018-etc/applesmc/patches/ -type f)

git clone --depth 1 --single-branch --branch v${FEDORA_KERNEL_VERSION} git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
cd ./linux-stable/drivers
### Add custom drivers to kernel
# echo -e "From: fedora kernel <fedora@kernel.org>\nSubject: patch custom drivers\n" > "${REPO_PWD}"/../patches/custom-drivers.patch

### bce
git clone --depth 1 --single-branch --branch ${BCE_DRIVER_BRANCH_NAME} ${BCE_DRIVER_GIT_URL} ./bce
cd bce
git checkout ${BCE_DRIVER_COMMIT_HASH}
# git clone --depth 1 --single-branch --branch v"${FEDORA_KERNEL_VERSION}" git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
# cd ./linux-stable/drivers || exit

rm -rf .git
cd ..
cp -rfv ${REPO_PWD}/../templates/Kconfig bce/Kconfig
sed -i "s/TEST_DRIVER/BCE_DRIVER/g" bce/Kconfig
sed -i 's/obj-m/obj-$(CONFIG_BCE)/g' bce/Makefile

### apple-ib
git clone --single-branch --branch ${APPLE_IB_DRIVER_BRANCH_NAME} ${APPLE_IB_DRIVER_GIT_URL} touchbar
cd touchbar
git checkout ${APPLE_IB_DRIVER_COMMIT_HASH}
rm -rf .git
cd ..
cp -rfv ${REPO_PWD}/../templates/Kconfig touchbar/Kconfig
sed -i "s/TEST_DRIVER/TOUCHBAR_DRIVER/g" touchbar/Kconfig
sed -i 's/obj-m/obj-$(CONFIG_TOUCHBAR)/g' touchbar/Makefile

echo 'obj-$(CONFIG_BCE) += bce/' >> ./Makefile
echo 'obj-$(CONFIG_TOUCHBAR) += touchbar/' >> ./Makefile
sed -i "\$i source \"drivers/bce/Kconfig\"\n" Kconfig
sed -i "\$i source \"drivers/touchbar/Kconfig\"\n" Kconfig

### Prepare patch
git add .
git diff HEAD >> ${REPO_PWD}/../patches/custom-drivers.patch

### back to fedora kernel repo
cd $REPO_PWD
for config_file in $(ls | grep kernel | grep '.config')
do
echo 'CONFIG_BCE_DRIVER=m' >> $config_file
echo 'CONFIG_TOUCHBAR_DRIVER=m' >> $config_file
done

echo 'CONFIG_BCE_DRIVER=m' > configs/fedora/generic/CONFIG_BCE_DRIVER
echo 'CONFIG_TOUCHBAR_DRIVER=m' >> configs/fedora/generic/CONFIG_TOUCHBAR_DRIVER

echo -e "bce.ko\napple-ib-als.ko\napple-ib-tb.ko\napple-ibridge.ko" >> mod-extra.list
echo 'inputdrvs="gameport tablet touchscreen bce touchbar"' >> filter-x86_64.sh

### Remove thunderbolt driver
# ### bce
# git clone --depth 1 --single-branch --branch ${BCE_DRIVER_BRANCH_NAME} ${BCE_DRIVER_GIT_URL} ./bce
# cd bce || exit
# git checkout ${BCE_DRIVER_COMMIT_HASH}

# rm -rf .git
# cd ..
# cp -rfv "${REPO_PWD}"/../templates/Kconfig bce/Kconfig
# sed -i "s/TEST_DRIVER/BCE_DRIVER/g" bce/Kconfig
# # shellcheck disable=SC2016
# sed -i 's/obj-m/obj-$(CONFIG_BCE)/g' bce/Makefile

# ### apple-ib
# git clone --single-branch --branch ${APPLE_IB_DRIVER_BRANCH_NAME} ${APPLE_IB_DRIVER_GIT_URL} touchbar
# cd touchbar || exit
# git checkout ${APPLE_IB_DRIVER_COMMIT_HASH}
# rm -rf .git
# cd ..
# cp -rfv "${REPO_PWD}"/../templates/Kconfig touchbar/Kconfig
# sed -i "s/TEST_DRIVER/TOUCHBAR_DRIVER/g" touchbar/Kconfig
# # shellcheck disable=SC2016
# sed -i 's/obj-m/obj-$(CONFIG_TOUCHBAR)/g' touchbar/Makefile

# # shellcheck disable=SC2016
# echo 'obj-$(CONFIG_BCE) += bce/' >> ./Makefile
# # shellcheck disable=SC2016
# echo 'obj-$(CONFIG_TOUCHBAR) += touchbar/' >> ./Makefile
# sed -i "\$i source \"drivers/bce/Kconfig\"\n" Kconfig
# sed -i "\$i source \"drivers/touchbar/Kconfig\"\n" Kconfig

# ### Prepare patch
# git add .
# git diff HEAD >> "${REPO_PWD}"/../patches/custom-drivers.patch

# ### back to fedora kernel repo
# cd "$REPO_PWD" || exit
# find . -type f -name "*.config" -exec sh -c '
# echo "CONFIG_BCE_DRIVER=m" >> $1
# echo "CONFIG_TOUCHBAR_DRIVER=m" >> $1
# ' sh {} \;

# echo 'CONFIG_BCE_DRIVER=m' > configs/fedora/generic/CONFIG_BCE_DRIVER
# echo 'CONFIG_TOUCHBAR_DRIVER=m' >> configs/fedora/generic/CONFIG_TOUCHBAR_DRIVER

# echo -e "bce.ko\napple-ib-als.ko\napple-ib-tb.ko\napple-ibridge.ko" >> mod-extra.list
# echo 'inputdrvs="gameport tablet touchscreen bce touchbar"' >> filter-x86_64.sh

# ### Remove thunderbolt driver
# sed -i "s/CONFIG_THUNDERBOLT=m/CONFIG_THUNDERBOLT=n/g" kernel-x86_64*
# sed -i "s/CONFIG_THUNDERBOLT=m/CONFIG_THUNDERBOLT=n/g" configs/fedora/generic/x86/x86_64/CONFIG_THUNDERBOLT
20 changes: 11 additions & 9 deletions patch_kernel_manually.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/sh
#!/bin/bash

set -euf -o pipefail

### Apple T2 drivers commit hashes
KERNEL_VERSION=5.4.19-200.mbp.fc31.x86_64
Expand All @@ -11,29 +13,29 @@ BCE_DRIVER_COMMIT_HASH=b43fcc069da73e051072fde24af4014c9c487286
APPLE_IB_DRIVER_GIT_URL=https://github.com/roadrunner2/macbook12-spi-driver.git
APPLE_IB_DRIVER_BRANCH_NAME=mbp15
APPLE_IB_DRIVER_COMMIT_HASH=90cea3e8e32db60147df8d39836bd1d2a5161871
APPLE_SMC_DRIVER_GIT_URL=https://github.com/MCMrARM/mbp2018-etc
APPLE_SMC_DRIVER_BRANCH_NAME=master
APPLE_SMC_DRIVER_COMMIT_HASH=cf42289ad637d3073e2fd348af71ad43dd31b8b4
# APPLE_SMC_DRIVER_GIT_URL=https://github.com/MCMrARM/mbp2018-etc
# APPLE_SMC_DRIVER_BRANCH_NAME=master
# APPLE_SMC_DRIVER_COMMIT_HASH=cf42289ad637d3073e2fd348af71ad43dd31b8b4

rpm -i ./*.rpm

mkdir -p ${KERNEL_PATCH_PATH}
cd ${KERNEL_PATCH_PATH}
cd ${KERNEL_PATCH_PATH} || exit

### bce
git clone --depth 1 --single-branch --branch ${BCE_DRIVER_BRANCH_NAME} ${BCE_DRIVER_GIT_URL} ./bce
cd bce
cd bce || exit
git checkout ${BCE_DRIVER_COMMIT_HASH}

make -C /lib/modules/${KERNEL_VERSION}/build/ M=$(pwd) modules
make -C /lib/modules/${KERNEL_VERSION}/build/ M="$(pwd)" modules
cp -rfv ./bce.ko /lib/modules/${KERNEL_VERSION}/extra
cd ..

git clone --single-branch --branch ${APPLE_IB_DRIVER_BRANCH_NAME} ${APPLE_IB_DRIVER_GIT_URL} ./touchbar
cd touchbar
cd touchbar || exit
git checkout ${APPLE_IB_DRIVER_COMMIT_HASH}

make -C /lib/modules/${KERNEL_VERSION}/build/ M=$(pwd) modules
make -C /lib/modules/${KERNEL_VERSION}/build/ M="$(pwd)" modules
cp -rfv ./*.ko /lib/modules/${KERNEL_VERSION}/extra

depmod -a ${KERNEL_VERSION}
Expand Down
2 changes: 1 addition & 1 deletion patches/hid-apple-mod.patch
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ index 1cb4199..3f30d04 100644
static const struct hid_device_id apple_devices[] = {
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE),
.driver_data = APPLE_MIGHTYMOUSE | APPLE_INVERT_HWHEEL },
@@ -561,6 +724,14 @@
@@ -561,6 +724,16 @@
.driver_data = APPLE_HAS_FN },
{ HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING9_JIS),
.driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
Expand Down
Loading

1 comment on commit 7cbba59

@jamlam
Copy link
Contributor

@jamlam jamlam commented on 7cbba59 Feb 18, 2020 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.