Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge to master #24

Merged
merged 41 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
c0793b5
Fedora Linux v5.4.14
mikeeq Jan 24, 2020
274bd48
Add @aunali1 wifi patches for dynamic rambase address changing
mikeeq Jan 24, 2020
8b2b842
Fedora Linux v5.4.17
mikeeq Feb 6, 2020
c5ca53f
Fedora Linux v5.4.19
mikeeq Feb 17, 2020
bf90311
MBP16 devices Addition - merging @jamlam fork (#5)
mikeeq Feb 17, 2020
7cbba59
Add lint job + fixes to @jamlam patches
mikeeq Feb 18, 2020
6094cdd
CI Pipeline fixes
mikeeq Feb 18, 2020
3e380dd
Added script for updating kernel on already installed mbp-fedora
mikeeq Feb 19, 2020
6ff811d
Refresh discord invite and add wifi firmware link to README
mikeeq Feb 19, 2020
eaf661d
Add installation of module compilation dependency to update_kernel_mb…
mikeeq Feb 20, 2020
7acba9c
Fedora Linux v5.5.5 (#6)
mikeeq Feb 20, 2020
a88797d
Add @aunali1 BT (ACPI) fix
mikeeq Feb 20, 2020
7173ce3
Fedora Linux v5.5.6
mikeeq Feb 26, 2020
aef59b1
New BT patch from @aunali1
mikeeq Feb 26, 2020
52d148e
Fedora Linux v5.5.7
mikeeq Mar 2, 2020
ca77ecb
[fix] update_kernel_mbp.sh - proper skipping macos boot option creati…
mikeeq Mar 3, 2020
d782364
Add more information about WiFi issues
mikeeq Mar 3, 2020
dceda3e
Feature/5.6.5 (#9)
mikeeq Apr 18, 2020
f7e53f5
Change default branch for update script
mikeeq Apr 18, 2020
b91416f
Fedora Linux v5.6.6
mikeeq Apr 21, 2020
9782b82
Fix devm_led_classdev_register call (#10)
marcosfad Apr 21, 2020
249c11b
Revert "Fix devm_led_classdev_register call (#10)" (#11)
mikeeq Apr 21, 2020
d6233c8
Fedora Linux v5.6.7
mikeeq Apr 28, 2020
dc7d238
Fedora Linux v5.6.8
mikeeq Apr 30, 2020
55861a6
Fedora Linux v5.6.8 f32
mikeeq Apr 30, 2020
8ea2a7a
Fedora Linux v5.6.11
mikeeq May 8, 2020
faadffa
Fedora Linux v5.6.13 + @aunali1 DP patch
mikeeq May 16, 2020
5e2d4be
Fedora Linux v5.6.15
mikeeq Jun 1, 2020
7c4ad52
[drone-CI] Fix linting job
mikeeq Jun 1, 2020
c683fa3
Fedora Linux v5.6.19
mikeeq Jun 23, 2020
37ec5f8
Fedora Linux v5.6.19 v2
mikeeq Jun 23, 2020
21524e9
update_kernel_mbp.sh - dracut warning fix
mikeeq Jun 23, 2020
d975bb2
update_kernel_mbp.sh - dracut warning fix v2
mikeeq Jun 23, 2020
2ff3e01
Fedora Linux v5.7 init (#15)
mikeeq Jun 30, 2020
a399f29
Switch default branch for update_kernel_mbp sh
mikeeq Jun 30, 2020
373d009
update_kernel_mbp.sh linting fix
mikeeq Jul 1, 2020
af366f7
Fedora Linux v5.7.7
mikeeq Jul 7, 2020
30cda0d
Fedora Linux v5.7.8
mikeeq Jul 13, 2020
f7cb974
Fedora Linux v5.7.12
mikeeq Aug 3, 2020
4357e2f
README: Replace wifi instructions with link to t2linux wiki (#20)
networkException May 11, 2021
bd7d434
Feature/v5.12 f34 (#23)
mikeeq Jun 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 36 additions & 22 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,43 @@
kind: pipeline
name: mbp-fedora-kernel

trigger:
event:
exclude:
- pull_request

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

- name: build
image: fedora:33
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: yes
when:
event: tag
- 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: {}
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM fedora:33

ARG RPMBUILD_PATH=/root/rpmbuild
ARG FEDORA_KERNEL_VERSION=5.11.20-300.fc34 # https://bodhi.fedoraproject.org/updates/?search=&packages=kernel&releases=F34

RUN dnf install -y fedpkg fedora-packager rpmdevtools ncurses-devel pesign git libkcapi libkcapi-devel libkcapi-static libkcapi-tools zip curl dwarves libbpf \
&& rpmdev-setuptree \
&& cd ${RPMBUILD_PATH}/SOURCES \
&& koji download-build --arch=src kernel-${FEDORA_KERNEL_VERSION} \
&& rpm -Uvh kernel-${FEDORA_KERNEL_VERSION}.src.rpm \
&& cd ${RPMBUILD_PATH}/SPECS \
&& dnf -y builddep kernel.spec
65 changes: 33 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,25 @@ Fedora kernel with Apple T2 patches built-in (Macbooks produced >= 2018).

Fedora ISO (with mbp-fedora-kernel builtin) - <https://github.com/mikeeq/mbp-fedora>

There are multiple version of the kernel maintained on seperate branches (all compiled versions could be found in releases section):
Drivers:

- 5.4-f31 - <https://github.com/mikeeq/mbp-fedora-kernel/tree/v5.4-f31>
- 5.3-f31 - <https://github.com/mikeeq/mbp-fedora-kernel/tree/v5.3-f31>
- 5.3-f30 - <https://github.com/mikeeq/mbp-fedora-kernel/tree/v5.3-f30>
- 5.1-f30 - <https://github.com/mikeeq/mbp-fedora-kernel/tree/v5.1>
- Apple T2 (audio, keyboard, touchpad) - <https://github.com/MCMrARM/mbp2018-bridge-drv>
- Apple SMC - <https://github.com/MCMrARM/mbp2018-etc>
- Touchbar - <https://github.com/roadrunner2/macbook12-spi-driver/tree/mbp15>

## How to update kernel-mbp

```
### First run
sudo -i
curl -L https://raw.githubusercontent.com/mikeeq/mbp-fedora-kernel/v5.6-f32/update_kernel_mbp.sh -o /usr/bin/update_kernel_mbp
chmod +x /usr/bin/update_kernel_mbp
update_kernel_mbp

### Next ones
sudo -i
update_kernel_mbp
```

## CI status

Expand All @@ -21,30 +34,22 @@ Travis kernel publish status - <http://fedora-mbp-repo.herokuapp.com/> :

## TODO

- integrate `roadrunner2/macbook12-spi-driver` and `MCMrARM/mbp2018-bridge-drv` drivers
- integrate `roadrunner2/macbook12-spi-driver` and `MCMrARM/mbp2018-bridge-drv` drivers into kernel
- add `kernel-headers` rpm generation

> Tested on: Macbook Pro 15,2 13" 2019 i5 TouchBar Z0WQ000AR MV972ZE/A/R1

```
Boot ROM Version: 220.270.99.0.0 (iBridge: 16.16.6571.0.0,0)
MacOS Mojave: 10.14.6 (18G103)
macOS Mojave: 10.14.6 (18G103)
```

### Known issues

- 5.2<= kernel random kernel panics - just disable thunderbolt driver

```
➜ cat /etc/modprobe.d/blacklist.conf
blacklist thunderbolt
```

- it's working on 5.1, because 5.1 is failing to load thunderbolt firmware
- Dynamic audio input/output change (on connecting/disconnecting headphones jack)
- TouchID - (@MCMrARM is working on it - https://github.com/Dunedan/mbp-2016-linux/issues/71#issuecomment-528545490)
- Thunderbolt (is disabled, because driver was causing kernel panics (not tested with 5.5 kernel))
- Microphone (it's recognised with new apple t2 sound driver, but there is a low mic volume amp)
- Dynamic audio outputs change (on connecting/disconnecting headphones jack)
- Suspend/Resume (sleep mode)
- Thunderbolt

#### Working with upstream stable kernel 5.1

Expand All @@ -60,19 +65,7 @@ MacOS Mojave: 10.14.6 (18G103)
- Camera
- keyboard
- touchpad (scroll, right click)
- wifi
- you need to manually extract firmware from MacOS
- <https://github.com/Dunedan/mbp-2016-linux/issues/71#issuecomment-517444300>
- <https://github.com/Dunedan/mbp-2016-linux/issues/71#issuecomment-515401480>

> The firmware files to use can be found by running `ioreg -l | grep C-4364` or `ioreg -l | grep RequestedFiles`, copy from `/usr/share/firmware/wifi` when being on MacOS

```
Put the firmware in the right place!
The .trx file for your model goes to /lib/firmware/brcm/brcmfmac4364-pcie.bin,
the .clmb goes to /lib/firmware/brcm/brcmfmac4364-pcie.clm_blob
and the .txt to something like /lib/firmware/brcm/brcmfmac4364-pcie.Apple Inc.-MacBookPro15,2.txt
```
- wifi (see <https://wiki.t2linux.org/guides/wifi/>)

#### Working with external drivers

Expand All @@ -86,10 +79,17 @@ and the .txt to something like /lib/firmware/brcm/brcmfmac4364-pcie.Apple Inc.-M
#### Not tested

- eGPU
- Thunderbolt

## Docs

- Discord: <https://discord.gg/39Rmjh>
- Discord: <https://discord.gg/Uw56rqW>
- WiFi firmware: <https://packages.aunali1.com/apple/wifi-fw/18G2022>
- blog `Installing Fedora 31 on a 2018 Mac mini`: <https://linuxwit.ch/blog/2020/01/installing-fedora-on-mac-mini/>
- iwd:
- <https://iwd.wiki.kernel.org/networkconfigurationsettings>
- <https://wiki.archlinux.org/index.php/Iwd>
- <https://www.vocal.com/secure-communication/eap-types/>

### Fedora

Expand All @@ -106,6 +106,7 @@ and the .txt to something like /lib/firmware/brcm/brcmfmac4364-pcie.Apple Inc.-M
- TouchBar driver: <https://github.com/roadrunner2/macbook12-spi-driver/tree/mbp15>
- Kernel patches (all are mentioned in github issue above): <https://github.com/aunali1/linux-mbp-arch>
- ArchLinux kernel patches: <https://github.com/ppaulweber/linux-mba>
- hid-apple-patched module for changing mappings of ctrl, fn, option keys: <https://github.com/free5lot/hid-apple-patched>

## Credits

Expand Down
82 changes: 39 additions & 43 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,72 +1,68 @@
#!/bin/sh
#!/bin/bash

set -eu -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
FEDORA_KERNEL_VERSION=5.4.10
FEDORA_KERNEL_BRANCH_NAME=f31
FEDORA_KERNEL_COMMIT_HASH=34597fed7b4308339dbdd1761da4608444b4320e # https://src.fedoraproject.org/rpms/kernel/commits/f31
RPMBUILD_PATH=/root/rpmbuild
FEDORA_KERNEL_VERSION=5.12.11-300.fc34 # https://bodhi.fedoraproject.org/updates/?search=&packages=kernel&releases=F34
REPO_PWD=$(pwd)

### Debug commands
echo "FEDORA_KERNEL_VERSION=$FEDORA_KERNEL_VERSION"
echo "FEDORA_KERNEL_BRANCH_NAME=$FEDORA_KERNEL_BRANCH_NAME"
echo "FEDORA_KERNEL_COMMIT_HASH=$FEDORA_KERNEL_COMMIT_HASH"

pwd
ls
echo "CPU threads: $(nproc --all)"
cat /proc/cpuinfo | grep 'model name' | uniq
# git clone --depth 1 --single-branch --branch v5.1.19 git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
grep 'model name' /proc/cpuinfo | uniq

### Dependencies
dnf install -y fedpkg fedora-packager rpmdevtools ncurses-devel pesign git libkcapi libkcapi-devel libkcapi-static libkcapi-tools zip curl
dnf install -y fedpkg fedora-packager rpmdevtools ncurses-devel pesign git libkcapi libkcapi-devel libkcapi-static libkcapi-tools zip curl dwarves libbpf

### Clone Fedora Kernel git repo
git clone --single-branch --branch $FEDORA_KERNEL_BRANCH_NAME ${FEDORA_KERNEL_GIT_URL}
cd kernel
## Cleanup
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
fedpkg clean
## Change branch
git checkout $FEDORA_KERNEL_COMMIT_HASH
git reset --hard $FEDORA_KERNEL_COMMIT_HASH
git checkout -b fedora_patch_src
dnf -y builddep kernel.spec
## Set home build directory
rpmdev-setuptree

### Fixes for kernel.spec
# sed -i "s/Patch509/Patch516/g" kernel.spec
## Install the kernel source and finish installing dependencies
cd ${RPMBUILD_PATH}/SOURCES
koji download-build --arch=src kernel-${FEDORA_KERNEL_VERSION}
rpm -Uvh kernel-${FEDORA_KERNEL_VERSION}.src.rpm

cd ${RPMBUILD_PATH}/SPECS
dnf -y builddep kernel.spec

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

### Apply patches
for patch_file in $(ls ../patches)
echo >&2 "===]> Info: Applying patches... ";
mkdir -p "${REPO_PWD}"/patches
while IFS= read -r file
do
scripts/newpatch.sh ../patches/$patch_file
done
echo "adding $file"
"${REPO_PWD}"/patch_kernel.sh "$file"
done < <(find "${REPO_PWD}"/patches -type f -name "*.patch" | sort)

### Change buildid to mbp
sed -i 's/%define buildid.*/%define buildid .mbp/' ./kernel.spec

### Build src rpm
fedpkg --release $FEDORA_KERNEL_BRANCH_NAME srpm
echo >&2 "===]> Info: Setting kernel name... ";
sed -i 's/# define buildid.*/%define buildid .mbp/' "${RPMBUILD_PATH}"/SPECS/kernel.spec

### Build non-debug rpms
./scripts/fast-build.sh x86_64 $(ls | grep src.rpm)
echo >&2 "===]> Info: Bulding kernel ... ";
# cd ${RPMBUILD_PATH}/SOURCES
# rpmbuild --target x86_64 --without debug --without debuginfo --without perf --without tools --rebuild kernel-${FEDORA_KERNEL_VERSION}.src.rpm
cd "${RPMBUILD_PATH}"/SPECS
# rpmbuild -bb --without debug --target=x86_64 kernel.spec
rpmbuild -bb --without debug --without debuginfo --without perf --without tools --target=x86_64 kernel.spec
rpmbuild_exitcode=$?

### Copy artifacts to shared volume
find ~/rpmbuild/ | grep '\.rpm'
cp -rfv ~/rpmbuild/RPMS/x86_64/*.rpm /tmp/artifacts/

### Calculate sha256 sums of built RPMs
sha256sum ~/rpmbuild/RPMS/x86_64/*.rpm > /tmp/artifacts/sha256
echo >&2 "===]> Info: Copying rpms and calculating SHA256 ... ";
cp -rfv ${RPMBUILD_PATH}/RPMS/x86_64/*.rpm /tmp/artifacts/
sha256sum ${RPMBUILD_PATH}/RPMS/x86_64/*.rpm > /tmp/artifacts/sha256

### Add patches to artifacts
cd ..
cd "${REPO_PWD}" | exit
zip -r patches.zip patches/
cp -rfv patches.zip /tmp/artifacts/
du -h /tmp/artifacts/

exit $rpmbuild_exitcode
13 changes: 8 additions & 5 deletions build_in_docker.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#!/bin/sh
#!/bin/bash

DOCKER_IMAGE=fedora:31
RPMBUILD_HOST_PATH=/opt/rpmbuild
set -eu -o pipefail

# DOCKER_IMAGE=fedora:33
DOCKER_IMAGE=fedora_build:33
RPMBUILD_HOST_PATH=~/rpmbuild

mkdir -p ${RPMBUILD_HOST_PATH}

docker pull ${DOCKER_IMAGE}
# 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'
Loading