Custom Build kernel and Wi-Fi module #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: 'Base name of the zip release files' | |
| required: true | |
| default: 'OP7_KSN_wifi' | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| env: | |
| CCACHE_HARDLINK: "true" | |
| CCACHE_NOHASHDIR: "true" | |
| CCACHE_MAXSIZE: "3G" | |
| CCACHE_COMPILERCHECK: "%compiler% -dumpmachine; %compiler% -dumpversion" | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Prepare kernel source | |
| run: | | |
| set -euo pipefail | |
| rm -rf kernel builds || true | |
| mkdir -p builds | |
| 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 | |
| - name: Setup KernelSU or KernelSU-Next | |
| working-directory: kernel | |
| run: | | |
| set -euo 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 -euo 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/ | |
| cp susfs_patches/kernel_patches/50_add_susfs_in_kernel-4.14.patch . | |
| cp susfs_patches/kernel_patches/fs/* ./fs/ | |
| cp susfs_patches/kernel_patches/include/linux/* ./include/linux/ | |
| cd KernelSU | |
| patch -N -p1 -F 3 < 10_enable_susfs_for_ksu.patch || echo "Patch already applied or failed" | |
| cd .. | |
| patch -N -p1 -F 3 < 50_add_susfs_in_kernel-4.14.patch || echo "Patch already applied or failed" | |
| find . -name "*.rej" -exec echo "Patch reject: {}" \; -exec cat {} \; | |
| if find . -name "*.rej" | grep -q .; then | |
| echo "FAIL: Some SUSFS hunks failed. Check your kernel version/patches above for why."; | |
| exit 1; | |
| fi | |
| - name: Add SUSFS configs if enabled | |
| if: ${{ github.event.inputs.enable_susfs == 'true' }} | |
| working-directory: kernel | |
| run: | | |
| echo "CONFIG_KSU=y" >> arch/arm64/configs/${{ github.event.inputs.defconfig_file }} | |
| echo "CONFIG_KSU_SUSFS=y" >> arch/arm64/configs/${{ github.event.inputs.defconfig_file }} | |
| echo "CONFIG_KSU_SUSFS_SUS_PATH=y" >> arch/arm64/configs/${{ github.event.inputs.defconfig_file }} | |
| echo "CONFIG_KSU_SUSFS_SUS_MOUNT=y" >> arch/arm64/configs/${{ github.event.inputs.defconfig_file }} | |
| echo "CONFIG_KSU_SUSFS_SUS_KSTAT=y" >> arch/arm64/configs/${{ github.event.inputs.defconfig_file }} | |
| echo "CONFIG_KSU_SUSFS_SUS_OVERLAYFS=y" >> arch/arm64/configs/${{ github.event.inputs.defconfig_file }} | |
| echo "CONFIG_KSU_SUSFS_TRY_UMOUNT=y" >> arch/arm64/configs/${{ github.event.inputs.defconfig_file }} | |
| echo "CONFIG_KSU_SUSFS_SPOOF_UNAME=y" >> arch/arm64/configs/${{ github.event.inputs.defconfig_file }} | |
| echo "CONFIG_KSU_SUSFS_ENABLE_LOG=y" >> arch/arm64/configs/${{ github.event.inputs.defconfig_file }} | |
| echo "CONFIG_KSU_SUSFS_OPEN_REDIRECT=y" >> arch/arm64/configs/${{ github.event.inputs.defconfig_file }} | |
| echo "CONFIG_KSU_SUSFS_SUS_SU=y" >> arch/arm64/configs/${{ github.event.inputs.defconfig_file }} | |
| - name: Remove CONFIG_TASKSTATS and related (CI robust) | |
| working-directory: kernel | |
| run: | | |
| set -euo 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" | |
| echo "$opt=n" >> "$conf" | |
| done | |
| - name: Fix btrfs timespec/timespec64 incompatibility (idempotent) | |
| working-directory: kernel | |
| run: | | |
| set -e | |
| FILE=fs/btrfs/inode.c | |
| # Only change line if the unpatched line exists | |
| if grep -qE "^\s*struct timespec now = current_time\(&parent_inode->vfs_inode\);" "$FILE"; then | |
| sed -i 's|^\(\s*\)struct timespec now = current_time(&parent_inode->vfs_inode);|\1struct timespec64 now = current_time(&parent_inode->vfs_inode);|' "$FILE" | |
| echo "✓ Patched btrfs timespec to timespec64" | |
| else | |
| echo "✓ btrfs already patched or not present" | |
| fi | |
| # Show result for debugging | |
| echo "--- btrfs/inode.c context after patch ---" | |
| grep -A2 -B1 "timespec" "$FILE" || true | |
| - name: Fix try_to_unmap argument count in huge_memory.c (idempotent) | |
| working-directory: kernel | |
| run: | | |
| set -e | |
| FILE=mm/huge_memory.c | |
| if grep -q 'try_to_unmap(page, ttu_flags);' "$FILE"; then | |
| sed -i 's|try_to_unmap(page, ttu_flags);|try_to_unmap(page, ttu_flags, NULL);|g' "$FILE" | |
| echo "✓ Patched try_to_unmap with NULL argument" | |
| else | |
| echo "✓ try_to_unmap already patched or not present" | |
| fi | |
| echo "--- huge_memory.c context after patch ---" | |
| grep -A1 -B1 "try_to_unmap" "$FILE" || true | |
| - name: Fix hugetlbpage ptep allocation bug (idempotent) | |
| working-directory: kernel | |
| run: | | |
| set -e | |
| FILE=arch/arm64/mm/hugetlbpage.c | |
| if grep -q 'pte_t \*pte = NULL;' "$FILE" && ! grep -q 'pte_t \*ptep' "$FILE"; then | |
| sed -i '/pte_t \*pte = NULL;/a\ pte_t *ptep = NULL;' "$FILE" | |
| echo "✓ Added ptep declaration" | |
| else | |
| echo "✓ ptep already declared or not needed" | |
| fi | |
| if grep -q 'ptep = huge_pmd_share(mm, vma, addr, pud);' "$FILE"; then | |
| sed -i 's/ptep = huge_pmd_share(mm, vma, addr, pud);/if (!ptep) ptep = huge_pmd_share(mm, vma, addr, pud);/' "$FILE" | |
| echo "✓ Added ptep null check" | |
| else | |
| echo "✓ ptep null check already present" | |
| fi | |
| - name: Remove mm_struct nr_ptes usage (idempotent) | |
| working-directory: kernel | |
| run: | | |
| set -e | |
| FILE=mm/khugepaged.c | |
| if grep -q 'mm->nr_ptes' "$FILE"; then | |
| # Comment out lines instead of deleting to avoid syntax breaks | |
| sed -i 's/\(.*mm->nr_ptes.*\)/\/\* REMOVED_for_ARM64 \1 \*\//' "$FILE" | |
| echo "✓ Commented out nr_ptes references" | |
| else | |
| echo "✓ nr_ptes already removed or not present" | |
| fi | |
| echo "--- khugepaged.c nr_ptes context after patch ---" | |
| grep -n "nr_ptes\|REMOVED_for_ARM64" "$FILE" || true | |
| - name: Set NR_CPUS if not present | |
| working-directory: kernel | |
| run: | | |
| set -euo pipefail | |
| conf=arch/arm64/configs/${{ github.event.inputs.defconfig_file }} | |
| if ! grep -q '^CONFIG_NR_CPUS=' "$conf"; then | |
| echo 'CONFIG_NR_CPUS=8' >> "$conf" | |
| fi | |
| - name: Prepare kernel config (non-interactive) | |
| working-directory: kernel | |
| run: | | |
| set -euo pipefail | |
| export PATH=/usr/lib/llvm-18/bin:$PATH | |
| 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 | |
| - name: Build kernel | |
| working-directory: kernel | |
| run: | | |
| set -euo 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 | |
| else | |
| echo "Image.lz4 not found, skipping copy." | |
| 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 -euo 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 |