1- name : Custom build kernel and Wi-Fi module
1+ name : Custiom build kernel and Wi-Fi module
22
33on :
44 workflow_dispatch :
3131jobs :
3232 build :
3333 runs-on : ubuntu-latest
34- env :
35- CCACHE_HARDLINK : " true"
36- CCACHE_NOHASHDIR : " true"
37- CCACHE_MAXSIZE : " 3G"
38- CCACHE_COMPILERCHECK : " %compiler% -dumpmachine; %compiler% -dumpversion"
3934
4035 steps :
41- - name : Checkout repository
36+ - name : Checkout repository fresh
4237 uses : actions/checkout@v4
4338 with :
4439 fetch-depth : 0
4540
46- - name : Prepare kernel source
41+ - name : Clean workspace & clone kernel
4742 run : |
48- set -euo pipefail
43+ set -euxo pipefail
4944 rm -rf kernel modules || true
5045 git clone --depth=1 --branch "${{ github.event.inputs.kernel_branch }}" "${{ github.event.inputs.kernel_repo_url }}" kernel
5146 cd kernel
@@ -56,43 +51,85 @@ jobs:
5651 sudo apt-get update -y
5752 sudo apt-get install -y clang-18 llvm-18 lld-18 \
5853 gcc-aarch64-linux-gnu gcc-arm-linux-gnueabi binutils make python3 libssl-dev bc bison flex unzip \
59- ca-certificates xz-utils mkbootimg cpio device-tree-compiler git git-lfs zip
54+ ca-certificates xz-utils mkbootimg cpio device-tree-compiler git git-lfs zip patch
6055
61- # KSU setup (choose KernelSU or KernelSU-Next)
62- - name : Setup KernelSU or KernelSU-Next
56+ - name : KernelSU or KernelSU-Next setup (before patching)
6357 working-directory : kernel
6458 run : |
65- set -euo pipefail
59+ set -euxo pipefail
6660 export PATH=/usr/lib/llvm-18/bin:$PATH
6761 if [ "${{ github.event.inputs.use_kernelsu_next }}" = "true" ]; then
6862 curl -LSs "https://raw.githubusercontent.com/KernelSU-Next/KernelSU-Next/next/kernel/setup.sh" | bash -
6963 else
7064 curl -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash -s stable
7165 fi
7266
73- # SUSFS patch logic
7467 - name : Apply SUSFS patches if enabled
7568 if : ${{ github.event.inputs.enable_susfs == 'true' }}
7669 working-directory : kernel
7770 run : |
78- set -euo pipefail
71+ set -euxo pipefail
7972 git clone https://gitlab.com/simonpunk/susfs4ksu.git -b kernel-4.14 susfs_patches
8073 cp susfs_patches/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch KernelSU/ || true
8174 cp susfs_patches/kernel_patches/50_add_susfs_in_kernel-4.14.patch . || true
8275 cp -r susfs_patches/kernel_patches/fs/* ./fs/ || true
8376 cp -r susfs_patches/kernel_patches/include/linux/* ./include/linux/ || true
8477 if [ -f KernelSU/10_enable_susfs_for_ksu.patch ]; then
85- (cd KernelSU && patch -N -p1 -F3 < 10_enable_susfs_for_ksu.patch) || echo "KernelSU SUSFS patch already applied"
78+ (cd KernelSU && patch -N -p1 < 10_enable_susfs_for_ksu.patch)
8679 fi
8780 if [ -f 50_add_susfs_in_kernel-4.14.patch ]; then
88- patch -N -p1 -F3 < 50_add_susfs_in_kernel-4.14.patch || echo "Kernel core SUSFS patch already applied"
81+ patch -N -p1 < 50_add_susfs_in_kernel-4.14.patch
8982 fi
9083 if find . -name "*.rej" | grep -q .; then
91- echo "SUSFS patch rejects found:"; find . -name "*.rej" -print -exec sed -n '1,120p ' {} \;;
84+ echo "SUSFS patch rejects found:"; find . -name "*.rej" -print -exec sed -n '1,20p ' {} \;;
9285 exit 1;
9386 fi
9487
95- # SUSFS config values
88+ - name : Patch btrfs struct timespec64 with diff (idempotent & atomic)
89+ working-directory : kernel
90+ run : |
91+ set -euxo pipefail
92+ PATCH_FILE=btrfs_timespec64.patch
93+ cat <<EOF > $PATCH_FILE
94+ --- a/fs/btrfs/inode.c
95+ +++ b/fs/btrfs/inode.c
96+ @@ ... @@
97+ - struct timespec now = current_time(&parent_inode->vfs_inode);
98+ + struct timespec64 now = current_time(&parent_inode->vfs_inode);
99+ EOF
100+ if grep -Fq "struct timespec now = current_time(&parent_inode->vfs_inode);" fs/btrfs/inode.c; then
101+ patch -p1 < $PATCH_FILE
102+ fi
103+ grep -E "struct timespec64|struct timespec now" fs/btrfs/inode.c | cat -n
104+
105+ - name : Patch try_to_unmap argument pattern
106+ working-directory : kernel
107+ run : |
108+ set -euxo pipefail
109+ sed -i 's|try_to_unmap(page, ttu_flags);|try_to_unmap(page, ttu_flags, NULL);|g' mm/huge_memory.c
110+ grep -C2 "try_to_unmap" mm/huge_memory.c | cat -n
111+
112+ - name : Patch hugetlbpage ptep allocation (safe/atomic)
113+ working-directory : kernel
114+ run : |
115+ set -euxo pipefail
116+ file=arch/arm64/mm/hugetlbpage.c
117+ awk '/huge_pte_alloc/{f=1} f && /{/{print NR; exit}' $file | while read ln; do
118+ if ! sed -n "$((ln+1)), $((ln+15))p" $file | grep -q "pte_t *ptep"; then
119+ sed -i "$((ln+1)) i\ pte_t *ptep = NULL;" $file
120+ fi
121+ done
122+ sed -i 's/ptep = huge_pmd_share(mm, vma, addr, pud);/if (!ptep) ptep = huge_pmd_share(mm, vma, addr, pud);/' $file
123+ grep -n "pte_t *ptep" $file | cat -n
124+ grep -C4 "ptep = huge_pmd_share" $file | cat -n
125+
126+ - name : Remove mm->nr_ptes usage (safe/atomic)
127+ working-directory : kernel
128+ run : |
129+ set -euxo pipefail
130+ sed -i 's/\(.*mm->nr_ptes.*\)/\/\* REMOVED_for_ARM64 \1 \*\//' mm/khugepaged.c
131+ grep -C2 "nr_ptes" mm/khugepaged.c | cat -n || true
132+
96133 - name : Add SUSFS configs if enabled
97134 if : ${{ github.event.inputs.enable_susfs == 'true' }}
98135 working-directory : kernel
@@ -112,119 +149,62 @@ jobs:
112149 echo "CONFIG_KSU_SUSFS_SUS_SU=y"
113150 } >> "$conf"
114151
115- # Disable problematic configs
116- - name : Disable taskstats family
152+ - name : Disable problematic configs
117153 working-directory : kernel
118154 run : |
119- set -e
155+ set -euxo pipefail
120156 conf="arch/arm64/configs/${{ github.event.inputs.defconfig_file }}"
121157 for opt in CONFIG_TASKSTATS CONFIG_TASK_DELAY_ACCT CONFIG_TASK_XACCT CONFIG_TASK_IO_ACCOUNTING; do
122158 sed -i "/^$opt[= ]/d" "$conf" || true
123159 echo "${opt}=n" >> "$conf"
124160 done
161+ tail -n 10 "$conf"
125162
126- # btrfs timespec fix
127- - name : Patch btrfs struct timespec to struct timespec64
128- working-directory : kernel
129- run : |
130- set -e
131- file=fs/btrfs/inode.c
132- if grep -qE "^\s*struct timespec now = current_time\(&parent_inode->vfs_inode\);" "$file"; then
133- sed -i 's|^\(\s*\)struct timespec now = current_time(&parent_inode->vfs_inode);|\1struct timespec64 now = current_time(&parent_inode->vfs_inode);|' "$file"
134- echo "btrfs timespec patch OK"
135- fi
136-
137- # try_to_unmap argument fix
138- - name : Patch try_to_unmap arg count
139- working-directory : kernel
140- run : |
141- set -e
142- file=mm/huge_memory.c
143- if grep -q 'try_to_unmap(page, ttu_flags);' "$file"; then
144- sed -i 's|try_to_unmap(page, ttu_flags);|try_to_unmap(page, ttu_flags, NULL);|g' "$file"
145- fi
146-
147- # hugetlbpage ptep allocation fix
148- - name : Patch hugetlbpage ptep allocation
149- working-directory : kernel
150- run : |
151- set -e
152- file=arch/arm64/mm/hugetlbpage.c
153- # Add ptep declaration inside huge_pte_alloc if missing
154- awk '
155- /huge_pte_alloc/ {f=1}
156- f && /{/ {print NR; exit}
157- ' "$file" | while read ln; do
158- if ! sed -n "$((ln+1)), $((ln+20))p" "$file" | grep -q "pte_t \*ptep"; then
159- sed -i "$((ln+1)) i\ pte_t *ptep = NULL;" "$file"
160- fi
161- done
162- # Add ptep null check for huge_pmd_share calls
163- if grep -q 'ptep = huge_pmd_share(mm, vma, addr, pud);' "$file"; then
164- sed -i 's/ptep = huge_pmd_share(mm, vma, addr, pud);/if (!ptep) ptep = huge_pmd_share(mm, vma, addr, pud);/' "$file"
165- fi
166-
167- # Remove mm->nr_ptes usage
168- - name : Remove mm_struct nr_ptes usage
169- working-directory : kernel
170- run : |
171- set -e
172- file=mm/khugepaged.c
173- if grep -q 'mm->nr_ptes' "$file"; then
174- sed -i 's/\(.*mm->nr_ptes.*\)/\/\* REMOVED_for_ARM64 \1 \*\//' "$file"
175- fi
176-
177- # NR_CPUS confirmation
178163 - name : Ensure NR_CPUS config
179164 working-directory : kernel
180165 run : |
181- conf="arch/arm64/configs/${{ github.event.inputs.defconfig_file }}"
182- grep -q '^CONFIG_NR_CPUS=' "$conf" || echo 'CONFIG_NR_CPUS=8' >> "$conf"
166+ 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 }}
183167
184- # Kernel config generation
185168 - name : Prepare kernel config
186169 working-directory : kernel
187170 run : |
188- set -euo pipefail
171+ set -euxo pipefail
189172 export PATH=/usr/lib/llvm-18/bin:$PATH
173+ make mrproper
190174 LTO=thin ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make ${{ github.event.inputs.defconfig_file }}
191175 LTO=thin ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make olddefconfig
176+ grep 'CONFIG_NR_CPUS=' .config
192177
193- # Kernel build
194178 - name : Build kernel
195179 working-directory : kernel
196180 run : |
197- set -euo pipefail
181+ set -euxo pipefail
198182 export PATH=/usr/lib/llvm-18/bin:$PATH
199183 LTO=thin ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make -j$(nproc)
200184
201- # Image copy
202185 - name : Copy kernel Image.lz4 if exists
203186 if : always()
204187 run : |
205188 if [ -f kernel/out/android12-5.10/dist/Image.lz4 ]; then
206189 cp kernel/out/android12-5.10/dist/Image.lz4 kernel/AnyKernel3/Image.lz4
207190 fi
208191
209- # Package ZIP
210192 - name : Package Kernel ZIP
211193 working-directory : kernel/AnyKernel3
212194 run : |
213195 zip -r ../${{ github.event.inputs.release_name }}.zip *
214196
215- # Wi-Fi module build
216197 - name : Build Wi-Fi Module (qca_cld3)
217198 working-directory : kernel
218199 run : |
219- set -euo pipefail
200+ set -euxo pipefail
220201 export PATH=/usr/lib/llvm-18/bin:$PATH
221202 LTO=thin ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- make modules_prepare
222203 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
223204 mkdir -p ../modules/vendor/lib/modules
224205 find out/drivers/staging/qcacld-3.0 -name "*.ko" -exec cp -v {} ../modules/vendor/lib/modules/ \;
225206 sudo chown -R $(id -u):$(id -g) ../modules
226207
227- # Wi-Fi ZIP package
228208 - name : Package Wi-Fi Module ZIP
229209 run : |
230210 if [ ! -d "modules/vendor/lib/modules" ] || ! ls modules/vendor/lib/modules/*.ko >/dev/null 2>&1; then
@@ -234,7 +214,6 @@ jobs:
234214 cd modules
235215 zip -r ../${{ github.event.inputs.release_name }}-modules.zip *
236216
237- # Artifact upload (build products)
238217 - name : Upload kernel build artifacts
239218 uses : actions/upload-artifact@v4
240219 with :
0 commit comments