Skip to content

Custom Build kernel and Wi-Fi module #16

Custom Build kernel and Wi-Fi module

Custom Build kernel and Wi-Fi module #16

Workflow file for this run

name: Custom Build kernel and Wi-Fi module
on:
workflow_dispatch:
inputs:
kernel_repo_url:
description: 'Kernel repository URL'
required: true
default: 'https://github.com/LineageOS/android_kernel_oneplus_sm8150'
kernel_branch:
description: 'Kernel branch'
required: true
default: 'lineage-22.1'
defconfig_file:
description: 'Kernel defconfig filename'
required: true
default: 'lineage_sm8150_defconfig'
use_kernelsu_next:
description: 'Use KernelSU-Next instead of KernelSU'
required: true
default: 'false'
enable_susfs:
description: 'Enable SUSFS patches'
required: true
default: 'false'
release_name:
description: 'Release name for ZIPs'
required: true
default: 'OP7_KSN_wifi'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository fresh
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Clean workspace & clone kernel
run: |
set -euxo pipefail
rm -rf kernel modules || true
git clone --depth=1 --branch "${{ github.event.inputs.kernel_branch }}" "${{ github.event.inputs.kernel_repo_url }}" kernel
cd kernel
git submodule update --init --recursive
- name: Setup dependencies
run: |
sudo apt-get update -y
sudo apt-get install -y clang-18 llvm-18 lld-18 \
gcc-aarch64-linux-gnu gcc-arm-linux-gnueabi binutils make python3 libssl-dev bc bison flex unzip \
ca-certificates xz-utils mkbootimg cpio device-tree-compiler git git-lfs zip patch
- name: KernelSU or KernelSU-Next setup (before patching)
working-directory: kernel
run: |
set -euxo pipefail
export PATH=/usr/lib/llvm-18/bin:$PATH
if [ "${{ github.event.inputs.use_kernelsu_next }}" = "true" ]; then
curl -LSs "https://raw.githubusercontent.com/KernelSU-Next/KernelSU-Next/next/kernel/setup.sh" | bash -
else
curl -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash -s stable
fi
- name: Apply SUSFS patches if enabled
if: ${{ github.event.inputs.enable_susfs == 'true' }}
working-directory: kernel
run: |
set -euxo pipefail
git clone https://gitlab.com/simonpunk/susfs4ksu.git -b kernel-4.14 susfs_patches
cp susfs_patches/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch KernelSU/ || true
cp susfs_patches/kernel_patches/50_add_susfs_in_kernel-4.14.patch . || true
cp -r susfs_patches/kernel_patches/fs/* ./fs/ || true
cp -r susfs_patches/kernel_patches/include/linux/* ./include/linux/ || true
if [ -f KernelSU/10_enable_susfs_for_ksu.patch ]; then
(cd KernelSU && patch -N -p1 < 10_enable_susfs_for_ksu.patch)
fi
if [ -f 50_add_susfs_in_kernel-4.14.patch ]; then
patch -N -p1 < 50_add_susfs_in_kernel-4.14.patch
fi
if find . -name "*.rej" | grep -q .; then
echo "SUSFS patch rejects found:"; find . -name "*.rej" -print -exec sed -n '1,20p' {} \;;
exit 1;
fi
- name: Patch btrfs struct timespec64 (idempotent sed)
working-directory: kernel
run: |
set -euxo pipefail
file=fs/btrfs/inode.c
orig='struct timespec now = current_time(&parent_inode->vfs_inode);'
repl='struct timespec64 now = current_time(&parent_inode->vfs_inode);'
grep -qF "$orig" "$file" && sed -i "s|$orig|$repl|" "$file"
grep -E "struct timespec64|struct timespec now" "$file" | cat -n
- name: Patch try_to_unmap argument pattern
working-directory: kernel
run: |
set -euxo pipefail
sed -i 's|try_to_unmap(page, ttu_flags);|try_to_unmap(page, ttu_flags, NULL);|g' mm/huge_memory.c
grep -C2 "try_to_unmap" mm/huge_memory.c | cat -n
- name: Patch hugetlbpage ptep allocation (safe/atomic)
working-directory: kernel
run: |
set -euxo pipefail
file=arch/arm64/mm/hugetlbpage.c
awk '/huge_pte_alloc/{f=1} f && /{/{print NR; exit}' $file | while read ln; do
if ! sed -n "$((ln+1)), $((ln+15))p" $file | grep -q "pte_t *ptep"; then
sed -i "$((ln+1)) i\ pte_t *ptep = NULL;" $file
fi
done
sed -i 's/ptep = huge_pmd_share(mm, vma, addr, pud);/if (!ptep) ptep = huge_pmd_share(mm, vma, addr, pud);/' $file
grep -n "pte_t *ptep" $file | cat -n
grep -C4 "ptep = huge_pmd_share" $file | cat -n
- name: Remove mm->nr_ptes usage (safe/atomic)
working-directory: kernel
run: |
set -euxo pipefail
sed -i 's/\(.*mm->nr_ptes.*\)/\/\* REMOVED_for_ARM64 \1 \*\//' mm/khugepaged.c
grep -C2 "nr_ptes" mm/khugepaged.c | cat -n || true
- name: Add SUSFS configs if enabled
if: ${{ github.event.inputs.enable_susfs == 'true' }}
working-directory: kernel
run: |
conf="arch/arm64/configs/${{ github.event.inputs.defconfig_file }}"
{
echo "CONFIG_KSU=y"
echo "CONFIG_KSU_SUSFS=y"
echo "CONFIG_KSU_SUSFS_SUS_PATH=y"
echo "CONFIG_KSU_SUSFS_SUS_MOUNT=y"
echo "CONFIG_KSU_SUSFS_SUS_KSTAT=y"
echo "CONFIG_KSU_SUSFS_SUS_OVERLAYFS=y"
echo "CONFIG_KSU_SUSFS_TRY_UMOUNT=y"
echo "CONFIG_KSU_SUSFS_SPOOF_UNAME=y"
echo "CONFIG_KSU_SUSFS_ENABLE_LOG=y"
echo "CONFIG_KSU_SUSFS_OPEN_REDIRECT=y"
echo "CONFIG_KSU_SUSFS_SUS_SU=y"
} >> "$conf"
- name: Disable problematic configs
working-directory: kernel
run: |
set -euxo pipefail
conf="arch/arm64/configs/${{ github.event.inputs.defconfig_file }}"
for opt in CONFIG_TASKSTATS CONFIG_TASK_DELAY_ACCT CONFIG_TASK_XACCT CONFIG_TASK_IO_ACCOUNTING; do
sed -i "/^$opt[= ]/d" "$conf" || true
echo "${opt}=n" >> "$conf"
done
tail -n 10 "$conf"
- name: Ensure NR_CPUS config
working-directory: kernel
run: |
grep -q '^CONFIG_NR_CPUS=' arch/arm64/configs/${{ github.event.inputs.defconfig_file }} || echo 'CONFIG_NR_CPUS=8' >> arch/arm64/configs/${{ github.event.inputs.defconfig_file }}
- name: Prepare kernel config
working-directory: kernel
run: |
set -euxo pipefail
export PATH=/usr/lib/llvm-18/bin:$PATH
make mrproper
LTO=thin ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make ${{ github.event.inputs.defconfig_file }}
LTO=thin ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make olddefconfig
grep 'CONFIG_NR_CPUS=' .config
- name: Build kernel
working-directory: kernel
run: |
set -euxo pipefail
export PATH=/usr/lib/llvm-18/bin:$PATH
LTO=thin ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make -j$(nproc)
- name: Copy kernel Image.lz4 if exists
if: always()
run: |
if [ -f kernel/out/android12-5.10/dist/Image.lz4 ]; then
cp kernel/out/android12-5.10/dist/Image.lz4 kernel/AnyKernel3/Image.lz4
fi
- name: Package Kernel ZIP
working-directory: kernel/AnyKernel3
run: |
zip -r ../${{ github.event.inputs.release_name }}.zip *
- name: Build Wi-Fi Module (qca_cld3)
working-directory: kernel
run: |
set -euxo pipefail
export PATH=/usr/lib/llvm-18/bin:$PATH
LTO=thin ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make modules_prepare
LTO=thin ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make -j$(nproc) -C drivers/staging/qcacld-3.0 M=$(pwd)/drivers/staging/qcacld-3.0 modules
mkdir -p ../modules/vendor/lib/modules
find out/drivers/staging/qcacld-3.0 -name "*.ko" -exec cp -v {} ../modules/vendor/lib/modules/ \;
sudo chown -R $(id -u):$(id -g) ../modules
- name: Package Wi-Fi Module ZIP
run: |
if [ ! -d "modules/vendor/lib/modules" ] || ! ls modules/vendor/lib/modules/*.ko >/dev/null 2>&1; then
echo "No Wi-Fi modules to package, exiting."
exit 1
fi
cd modules
zip -r ../${{ github.event.inputs.release_name }}-modules.zip *
- name: Upload kernel build artifacts
uses: actions/upload-artifact@v4
with:
name: kernel-output
path: kernel/out
- name: Upload zips
uses: actions/upload-artifact@v4
with:
name: build-zips
path: |
kernel/${{ github.event.inputs.release_name }}.zip
${{ github.event.inputs.release_name }}-modules.zip