build.yml 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. name: Kernel Build Process
  2. permissions:
  3. contents: write
  4. actions: write
  5. on:
  6. workflow_call:
  7. inputs:
  8. android_version:
  9. required: true
  10. type: string
  11. kernel_version:
  12. required: true
  13. type: string
  14. sub_level:
  15. required: true
  16. type: string
  17. os_patch_level:
  18. required: true
  19. type: string
  20. susfs_version:
  21. required: false
  22. type: string
  23. default: "v1.5.12"
  24. # revision input removed; A12 boot image download uses fixed r1
  25. jobs:
  26. build-gki:
  27. runs-on: ubuntu-latest
  28. strategy:
  29. fail-fast: false
  30. matrix:
  31. apply_bypass: ["normal", "bypass"]
  32. apply_bbg: ["bbg", "no-bbg"]
  33. steps:
  34. - name: Maximize Build Space
  35. uses: AdityaGarg8/remove-unwanted-software@v5
  36. with:
  37. remove-dotnet: 'true' # Frees ~2 GB
  38. remove-android: 'true' # Frees ~9 GB
  39. remove-haskell: 'true' # Frees ~5.2 GB
  40. remove-codeql: 'true' # Frees ~5.4 GB
  41. remove-docker-images: 'true' # Frees ~3.2 GB
  42. remove-large-packages: 'true' # Frees ~3.1 GB
  43. remove-swapfile: 'true' # Frees ~4 GB
  44. remove-cached-tools: 'false' # Avoid unless confirmed safe
  45. verbose: 'true' # Enable detailed logging
  46. - name: Set CONFIG Environment Variable
  47. run: |
  48. # Set CONFIG dynamically based on inputs values
  49. CONFIG="${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.sub_level }}"
  50. # Set CONFIG as an environment variable for future steps
  51. echo "CONFIG=$CONFIG" >> $GITHUB_ENV
  52. - name: Setup Build Environment
  53. run: |
  54. AOSP_MIRROR=https://android.googlesource.com
  55. BRANCH=main-kernel-2025
  56. git clone $AOSP_MIRROR/kernel/prebuilts/build-tools -b $BRANCH --depth 1 kernel-build-tools &
  57. git clone $AOSP_MIRROR/platform/system/tools/mkbootimg -b $BRANCH --depth 1 mkbootimg &
  58. wait
  59. echo "AVBTOOL=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/bin/avbtool" >> $GITHUB_ENV
  60. echo "MKBOOTIMG=$GITHUB_WORKSPACE/mkbootimg/mkbootimg.py" >> $GITHUB_ENV
  61. echo "UNPACK_BOOTIMG=$GITHUB_WORKSPACE/mkbootimg/unpack_bootimg.py" >> $GITHUB_ENV
  62. echo "BOOT_SIGN_KEY_PATH=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem" >> $GITHUB_ENV
  63. echo "PATH=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/bin:$PATH" >> $GITHUB_ENV
  64. mkdir -p ./git-repo
  65. curl https://storage.googleapis.com/git-repo-downloads/repo > ./git-repo/repo
  66. chmod a+rx ./git-repo/repo
  67. echo "REPO=$GITHUB_WORKSPACE/./git-repo/repo" >> $GITHUB_ENV
  68. - name: Set boot sign key
  69. env:
  70. BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }}
  71. run: |
  72. if [ ! -z "$BOOT_SIGN_KEY" ]; then
  73. echo "$BOOT_SIGN_KEY" > ./kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem
  74. fi
  75. - name: Clone AnyKernel3 and Other Dependencies
  76. run: |
  77. ANYKERNEL_BRANCH="gki-2.0"
  78. SUSFS_BRANCH="gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}"
  79. git clone https://github.com/WildKernels/AnyKernel3.git -b "$ANYKERNEL_BRANCH"
  80. git clone https://github.com/WildKernels/kernel_patches.git
  81. git clone https://gitlab.com/simonpunk/susfs4ksu.git -b "$SUSFS_BRANCH"
  82. # Checkout specific commits for SUSFS v1.5.9 if enabled
  83. if [ "${{ inputs.susfs_version }}" = "v1.5.9" ]; then
  84. cd susfs4ksu
  85. case "${{ inputs.android_version }}-${{ inputs.kernel_version }}" in
  86. "android15-6.6")
  87. git checkout 2598fee8963adab11c255bf28521df32912e027f
  88. ;;
  89. "android14-6.1")
  90. git checkout 646cfabce9d5dba5b806e9cbe2c198128ebd0e69
  91. ;;
  92. "android14-5.15")
  93. git checkout ab4d9570a9494a67c290002f3b28e69dd370a0f5
  94. ;;
  95. "android13-5.15")
  96. git checkout a21f265695f2869a6f3fc71a70328aa6d0f4a3ae
  97. ;;
  98. "android13-5.10")
  99. git checkout 8acbd10775a447f546b14c6bded6f476a7f4733f
  100. ;;
  101. "android12-5.10")
  102. git checkout 6f42c0e24e35a6fa0fc43051a5f1e7dfe568e8c2
  103. ;;
  104. esac
  105. cd ..
  106. fi
  107. # Checkout specific commits for SUSFS v1.5.12 if enabled
  108. if [ "${{ inputs.susfs_version }}" = "v1.5.12" ]; then
  109. cd susfs4ksu
  110. case "${{ inputs.android_version }}-${{ inputs.kernel_version }}" in
  111. "android12-5.10")
  112. git checkout ed19454a4b5905e6718c9a22fad769b906837931
  113. ;;
  114. "android13-5.10")
  115. git checkout 8919927b63d95e62d33842452b9a60546187fb7b
  116. ;;
  117. "android13-5.15")
  118. git checkout 700b9316b5a1cab174401b57f4198782a17154fb
  119. ;;
  120. "android14-5.15")
  121. git checkout e1b1bba04b3cada700b8fd5bda4cfd4c59de07a2
  122. ;;
  123. "android14-6.1")
  124. git checkout f16560ce8263fbfa9b2f259e9531f72d6fda4e3f
  125. ;;
  126. "android15-6.6")
  127. git checkout c49b1dab205bbc4ef20b120e84c5b7530355961d
  128. ;;
  129. esac
  130. cd ..
  131. fi
  132. - name: Initialize and Sync Kernel Source
  133. run: |
  134. mkdir -p "$CONFIG"
  135. cd "$CONFIG"
  136. FORMATTED_BRANCH="${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.os_patch_level }}"
  137. $REPO init --depth=1 --u https://android.googlesource.com/kernel/manifest -b common-${FORMATTED_BRANCH} --repo-rev=v2.16
  138. REMOTE_BRANCH=$(git ls-remote https://android.googlesource.com/kernel/common ${FORMATTED_BRANCH})
  139. DEFAULT_MANIFEST_PATH=.repo/manifests/default.xml
  140. if grep -q deprecated <<< $REMOTE_BRANCH; then
  141. sed -i "s/\"${FORMATTED_BRANCH}\"/\"deprecated\/${FORMATTED_BRANCH}\"/g" $DEFAULT_MANIFEST_PATH
  142. fi
  143. $REPO --trace sync -c -j$(nproc --all) --no-tags --fail-fast
  144. - name: Extract Actual Sublevel for LTS Builds
  145. if: inputs.sub_level == 'X'
  146. run: |
  147. cd "$CONFIG/common"
  148. if [ -f "Makefile" ]; then
  149. ACTUAL_SUBLEVEL=$(grep '^SUBLEVEL = ' Makefile | awk '{print $3}')
  150. if [ -n "$ACTUAL_SUBLEVEL" ]; then
  151. OLD_CONFIG="$CONFIG"
  152. NEW_CONFIG="${{ inputs.android_version }}-${{ inputs.kernel_version }}-$ACTUAL_SUBLEVEL"
  153. echo "CONFIG=$NEW_CONFIG" >> $GITHUB_ENV
  154. echo "ACTUAL_SUBLEVEL=$ACTUAL_SUBLEVEL" >> $GITHUB_ENV
  155. cd ../..
  156. if [ -d "$OLD_CONFIG" ]; then
  157. echo "Renaming directory from $OLD_CONFIG to $NEW_CONFIG"
  158. mv "$OLD_CONFIG" "$NEW_CONFIG"
  159. if [ ! -d "$NEW_CONFIG" ]; then
  160. echo "Error: Directory rename failed, $NEW_CONFIG does not exist"
  161. exit 1
  162. fi
  163. echo "Directory successfully renamed to $NEW_CONFIG"
  164. else
  165. echo "Error: Source directory $OLD_CONFIG does not exist"
  166. exit 1
  167. fi
  168. fi
  169. fi
  170. - name: Apply glibc 2.38 Compatibility Fix
  171. run: |
  172. # Use ACTUAL_SUBLEVEL for LTS builds, otherwise use the input sub_level
  173. SUBLEVEL_TO_CHECK="${ACTUAL_SUBLEVEL:-${{ inputs.sub_level }}}"
  174. if ([[ "${{ inputs.android_version }}" == "android13" ]] && [[ "${{ inputs.kernel_version }}" == "5.10" ]] && (( $SUBLEVEL_TO_CHECK <= 186 ))) ||
  175. ([[ "${{ inputs.android_version }}" == "android13" ]] && [[ "${{ inputs.kernel_version }}" == "5.15" ]] && (( $SUBLEVEL_TO_CHECK <= 119 ))) ||
  176. ([[ "${{ inputs.android_version }}" == "android14" ]] && [[ "${{ inputs.kernel_version }}" == "5.15" ]] && (( $SUBLEVEL_TO_CHECK <= 110 ))) ||
  177. ([[ "${{ inputs.android_version }}" == "android14" ]] && [[ "${{ inputs.kernel_version }}" == "6.1" ]] && (( $SUBLEVEL_TO_CHECK <= 43 ))); then
  178. GLIBC_VERSION=$(ldd --version 2>/dev/null | head -n 1 | awk '{print $NF}')
  179. if [ "$(printf '%s\n' "2.38" "$GLIBC_VERSION" | sort -V | head -n1)" = "2.38" ]; then
  180. cd $CONFIG/common/
  181. sed -i '/\$(Q)\$(MAKE) -C \$(SUBCMD_SRC) OUTPUT=\$(abspath \$(dir \$@))\/ \$(abspath \$@)/s//$(Q)$(MAKE) -C $(SUBCMD_SRC) EXTRA_CFLAGS="$(CFLAGS)" OUTPUT=$(abspath $(dir $@))\/ $(abspath $@)/' tools/bpf/resolve_btfids/Makefile 2>/dev/null || true
  182. if ([[ "${{ inputs.android_version }}" == "android13" ]] && [[ "${{ inputs.kernel_version }}" == "5.10" ]] && (( $SUBLEVEL_TO_CHECK <= 186 ))) ||
  183. ([[ "${{ inputs.android_version }}" == "android13" ]] && [[ "${{ inputs.kernel_version }}" == "5.15" ]] && (( $SUBLEVEL_TO_CHECK <= 119 ))) ||
  184. ([[ "${{ inputs.android_version }}" == "android14" ]] && [[ "${{ inputs.kernel_version }}" == "5.15" ]] && (( $SUBLEVEL_TO_CHECK <= 110 ))); then
  185. sed -i '/char \*buf = NULL;/a int i;' tools/lib/subcmd/parse-options.c 2>/dev/null || true
  186. sed -i 's/for (int i = 0; subcommands\[i\]; i++) {/for (i = 0; subcommands[i]; i++) {/' tools/lib/subcmd/parse-options.c 2>/dev/null || true
  187. sed -i '/if (subcommands) {/a int i;' tools/lib/subcmd/parse-options.c 2>/dev/null || true
  188. sed -i 's/for (int i = 0; subcommands\[i\]; i++)/for (i = 0; subcommands[i]; i++)/' tools/lib/subcmd/parse-options.c 2>/dev/null || true
  189. fi
  190. fi
  191. fi
  192. - name: Fix Less Then 6.6.50 Builds
  193. if: inputs.android_version == 'android15' && inputs.kernel_version == '6.6'
  194. run: |
  195. cd "$CONFIG/common"
  196. if ! grep -qxF '#include <trace/hooks/fs.h>' ./fs/namespace.c; then
  197. sed -i '/#include <trace\/hooks\/blk.h>/a #include <trace\/hooks\/fs.h>' ./fs/namespace.c
  198. fi
  199. - name: Apply ptrace patch for older kernels
  200. if: fromJSON(inputs.kernel_version) < 5.16
  201. run: |
  202. cd "$CONFIG/common"
  203. patch -p1 -F 3 < "../../kernel_patches/gki_ptrace.patch"
  204. - name: Add KernelSU
  205. run: |
  206. cd "$CONFIG"
  207. curl -LSs "https://raw.githubusercontent.com/WildKernels/Wild_KSU/wild/kernel/setup.sh" | bash -s wild
  208. - name: Getting KernelSU Version
  209. run: |
  210. cd "$CONFIG/Wild_KSU/kernel"
  211. BASE_VERSION=10200
  212. COMMIT_COUNT=$(/usr/bin/git rev-list --count HEAD)
  213. KSU_VERSION=$(expr $COMMIT_COUNT "+" $BASE_VERSION)
  214. echo "KSUVER=$KSU_VERSION" >> $GITHUB_ENV
  215. - name: Apply SUSFS Patches for KernelSU Variants
  216. run: |
  217. cd "$CONFIG"
  218. # Apply compatibility fixes
  219. if [ "${{ inputs.susfs_version }}" = "v1.5.9" ]; then
  220. SUSFS_VERSION="1.5.9"
  221. else
  222. SUSFS_VERSION="1.5.12"
  223. fi
  224. cp ../susfs4ksu/kernel_patches/fs/* ./common/fs/
  225. cp ../susfs4ksu/kernel_patches/include/linux/* ./common/include/linux/
  226. # Apply core SUSFS patches
  227. cp ../susfs4ksu/kernel_patches/50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch ./common/
  228. cd common
  229. patch -p1 < 50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch || true
  230. # Apply additional SUSFS patches for Android 13 5.15 compatibility
  231. if [[ "${{ inputs.android_version }}" == "android13" ]] && [[ "${{ inputs.kernel_version }}" == "5.15" ]] && (( ${{ inputs.sub_level }} <= 41 )); then
  232. cp ../../kernel_patches/wild/susfs_fix_patches/v${SUSFS_VERSION}/fix_fdinfo.c.patch ./
  233. patch -p1 < fix_fdinfo.c.patch || true
  234. cp ../../kernel_patches/wild/susfs_fix_patches/v${SUSFS_VERSION}/fix_namespace.c.patch ./
  235. patch -p1 < fix_namespace.c.patch || true
  236. cp ../../kernel_patches/wild/susfs_fix_patches/v${SUSFS_VERSION}/fix_open.c.patch ./
  237. patch -p1 < fix_open.c.patch || true
  238. sed -i 's/i_uid_into_mnt(i_user_ns(inode), inode)/i_uid_into_mnt(inode->i_sb->s_user_ns, inode)/g' fs/susfs.c
  239. fi
  240. # Apply KSU integration patches
  241. cd ../Wild_KSU
  242. cp ../../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch .
  243. patch -p1 < 10_enable_susfs_for_ksu.patch || true
  244. cp ../../kernel_patches/wild/susfs_fix_patches/v${SUSFS_VERSION}/fix_core_hook.c.patch ./
  245. patch -p1 < fix_core_hook.c.patch
  246. cp ../../kernel_patches/wild/susfs_fix_patches/v${SUSFS_VERSION}/fix_sucompat.c.patch ./
  247. patch -p1 < fix_sucompat.c.patch
  248. cp ../../kernel_patches/wild/susfs_fix_patches/v${SUSFS_VERSION}/fix_kernel_compat.c.patch ./
  249. patch -p1 < fix_kernel_compat.c.patch
  250. - name: Apply Hooks Patches
  251. run: |
  252. cd "$CONFIG/common"
  253. cp ../../kernel_patches/wild/hooks/scope_min_manual_hooks_v1.4.patch ./
  254. patch -p1 -F 3 < scope_min_manual_hooks_v1.4.patch
  255. - name: Scan and collect patch rejects
  256. if: ${{ always() }}
  257. run: |
  258. set -e
  259. CONFIG_DIR="$CONFIG"
  260. REJECTS_DIR="$GITHUB_WORKSPACE/patch-rejects"
  261. mkdir -p "$REJECTS_DIR"
  262. # Find all .rej files under the configuration directory
  263. mapfile -t REJS < <(find "$CONFIG_DIR" -type f -name '*.rej')
  264. REJ_COUNT=${#REJS[@]}
  265. echo "Found $REJ_COUNT .rej files under $CONFIG_DIR"
  266. echo "REJ_COUNT=$REJ_COUNT" >> $GITHUB_ENV
  267. if [ "$REJ_COUNT" -gt 0 ]; then
  268. for REJ in "${REJS[@]}"; do
  269. # Relative path from $CONFIG
  270. REL="${REJ#"$CONFIG_DIR"/}"
  271. DEST="$REJECTS_DIR/$REL"
  272. mkdir -p "$(dirname "$DEST")"
  273. cp "$REJ" "$DEST"
  274. # Copy the associated original file alongside the .rej
  275. ORIG="${REJ%.rej}"
  276. if [ -f "$ORIG" ]; then
  277. ORIG_DEST="$REJECTS_DIR/${REL%.rej}"
  278. mkdir -p "$(dirname "$ORIG_DEST")"
  279. cp "$ORIG" "$ORIG_DEST"
  280. fi
  281. echo "$REL" >> "$REJECTS_DIR/index.txt"
  282. done
  283. fi
  284. - name: Add BBG
  285. if: ${{ matrix.apply_bbg == 'bbg' }}
  286. run: |
  287. cd "$CONFIG"
  288. echo "Adding BBG..."
  289. wget -O- https://github.com/vc-teahouse/Baseband-guard/raw/main/setup.sh | bash
  290. echo "CONFIG_BBG=y" >> common/arch/arm64/configs/gki_defconfig
  291. # Before sed: Show the original LSM default line for comparison
  292. echo "=== Before sed ==="
  293. sed -n '/^config LSM$/,/^help$/{ /^[[:space:]]*default/ p }' common/security/Kconfig
  294. # Apply the sed command to add baseband_guard to default security configurations
  295. sed -i '/^config LSM$/,/^help$/{ /^[[:space:]]*default/ { /baseband_guard/! s/lockdown/lockdown,baseband_guard/ } }' common/security/Kconfig
  296. # After sed: Show the updated LSM default line
  297. echo "=== After sed ==="
  298. sed -n '/^config LSM$/,/^help$/{ /^[[:space:]]*default/ p }' common/security/Kconfig
  299. # Confirm baseband_guard is now present (should output the line if successful)
  300. echo "=== Confirmation: grep for baseband_guard ==="
  301. if ! grep -q "baseband_guard" common/security/Kconfig; then
  302. echo "ERROR: baseband_guard not found after sed - stopping workflow"
  303. exit 1
  304. else
  305. echo "SUCCESS: baseband_guard found in security configuration"
  306. grep "baseband_guard" common/security/Kconfig
  307. fi
  308. - name: Apply Module Check Bypass
  309. if: ${{ matrix.apply_bypass == 'bypass' }}
  310. run: |
  311. if [[ "${{ inputs.kernel_version }}" == "6.1" || "${{ inputs.kernel_version }}" == "6.6" ]]; then
  312. cd "$CONFIG/common/kernel/module"
  313. sed -i '/bad_version:/{:a;n;/return 0;/{s/return 0;/return 1;/;b};ba}' version.c
  314. else
  315. cd "$CONFIG/common/kernel"
  316. sed -i '/bad_version:/{:a;n;/return 0;/{s/return 0;/return 1;/;b};ba}' module.c
  317. fi
  318. - name: Fix WiFi and Bluetooth on Samsung 6.6 GKI devices
  319. if: ${{ ( inputs.kernel_version == '6.6' ) }}
  320. run: |
  321. SYMBOL_LIST=$CONFIG/common/android/abi_gki_aarch64_galaxy
  322. echo "kdp_set_cred_non_rcu" >> $SYMBOL_LIST
  323. echo "kdp_usecount_dec_and_test" >> $SYMBOL_LIST
  324. echo "kdp_usecount_inc" >> $SYMBOL_LIST
  325. cd $CONFIG/common
  326. PATCH="../../kernel_patches/samsung/min_kdp/add-min_kdp-symbols.patch"
  327. if patch -p1 --dry-run < $PATCH; then
  328. patch -p1 --no-backup-if-mismatch < $PATCH
  329. fi
  330. cd drivers
  331. cp "../../../kernel_patches/samsung/min_kdp/min_kdp.c" min_kdp.c
  332. echo "obj-y += min_kdp.o" >> Makefile
  333. - name: Set Kernel Configuration Variables
  334. run: |
  335. cd "$CONFIG"
  336. echo "Initializing kernel configuration..."
  337. echo "DEFCONFIG=./common/arch/arm64/configs/gki_defconfig" >> $GITHUB_ENV
  338. # Remove check_defconfig
  339. sed -i 's/check_defconfig//' ./common/build.config.gki
  340. - name: Configure KernelSU Core
  341. run: |
  342. cd "$CONFIG"
  343. # KernelSU Configuration
  344. echo "# KernelSU Configuration" >> "${{ env.DEFCONFIG }}"
  345. echo "CONFIG_KSU=y" >> "${{ env.DEFCONFIG }}"
  346. echo "CONFIG_KSU_KPROBES_HOOK=n" >> "${{ env.DEFCONFIG }}"
  347. - name: Configure Mountify Support
  348. run: |
  349. cd "$CONFIG"
  350. # Mountify Support
  351. echo "# Mountify Support" >> "${{ env.DEFCONFIG }}"
  352. echo "CONFIG_TMPFS_XATTR=y" >> "${{ env.DEFCONFIG }}"
  353. echo "CONFIG_TMPFS_POSIX_ACL=y" >> "${{ env.DEFCONFIG }}"
  354. - name: Configure Networking
  355. run: |
  356. cd "$CONFIG"
  357. # Networking Configuration
  358. echo "# Networking Configuration" >> "${{ env.DEFCONFIG }}"
  359. echo "CONFIG_IP_NF_TARGET_TTL=y" >> "${{ env.DEFCONFIG }}"
  360. echo "CONFIG_IP6_NF_TARGET_HL=y" >> "${{ env.DEFCONFIG }}"
  361. echo "CONFIG_IP6_NF_MATCH_HL=y" >> "${{ env.DEFCONFIG }}"
  362. - name: Configure TCP Congestion Control
  363. run: |
  364. cd "$CONFIG"
  365. # BBR TCP Congestion Control
  366. echo "# BBR TCP Congestion Control" >> "${{ env.DEFCONFIG }}"
  367. echo "CONFIG_TCP_CONG_ADVANCED=y" >> "${{ env.DEFCONFIG }}"
  368. echo "CONFIG_TCP_CONG_BBR=y" >> "${{ env.DEFCONFIG }}"
  369. echo "CONFIG_NET_SCH_FQ=y" >> "${{ env.DEFCONFIG }}"
  370. echo "CONFIG_TCP_CONG_BIC=n" >> "${{ env.DEFCONFIG }}"
  371. echo "CONFIG_TCP_CONG_WESTWOOD=n" >> "${{ env.DEFCONFIG }}"
  372. echo "CONFIG_TCP_CONG_HTCP=n" >> "${{ env.DEFCONFIG }}"
  373. - name: Configure IPSet Support
  374. run: |
  375. cd "$CONFIG"
  376. # IPSet support
  377. echo "# IPSet Support" >> "${{ env.DEFCONFIG }}"
  378. echo "CONFIG_IP_SET=y" >> "${{ env.DEFCONFIG }}"
  379. echo "CONFIG_IP_SET_MAX=65534" >> "${{ env.DEFCONFIG }}"
  380. echo "CONFIG_IP_SET_BITMAP_IP=y" >> "${{ env.DEFCONFIG }}"
  381. echo "CONFIG_IP_SET_BITMAP_IPMAC=y" >> "${{ env.DEFCONFIG }}"
  382. echo "CONFIG_IP_SET_BITMAP_PORT=y" >> "${{ env.DEFCONFIG }}"
  383. echo "CONFIG_IP_SET_HASH_IP=y" >> "${{ env.DEFCONFIG }}"
  384. echo "CONFIG_IP_SET_HASH_IPMARK=y" >> "${{ env.DEFCONFIG }}"
  385. echo "CONFIG_IP_SET_HASH_IPPORT=y" >> "${{ env.DEFCONFIG }}"
  386. echo "CONFIG_IP_SET_HASH_IPPORTIP=y" >> "${{ env.DEFCONFIG }}"
  387. echo "CONFIG_IP_SET_HASH_IPPORTNET=y" >> "${{ env.DEFCONFIG }}"
  388. echo "CONFIG_IP_SET_HASH_IPMAC=y" >> "${{ env.DEFCONFIG }}"
  389. echo "CONFIG_IP_SET_HASH_MAC=y" >> "${{ env.DEFCONFIG }}"
  390. echo "CONFIG_IP_SET_HASH_NETPORTNET=y" >> "${{ env.DEFCONFIG }}"
  391. echo "CONFIG_IP_SET_HASH_NET=y" >> "${{ env.DEFCONFIG }}"
  392. echo "CONFIG_IP_SET_HASH_NETNET=y" >> "${{ env.DEFCONFIG }}"
  393. echo "CONFIG_IP_SET_HASH_NETPORT=y" >> "${{ env.DEFCONFIG }}"
  394. echo "CONFIG_IP_SET_HASH_NETIFACE=y" >> "${{ env.DEFCONFIG }}"
  395. echo "CONFIG_IP_SET_LIST_SET=y" >> "${{ env.DEFCONFIG }}"
  396. - name: Configure SUSFS
  397. run: |
  398. cd "$CONFIG"
  399. # SUSFS Configuration
  400. echo "# SUSFS Configuration" >> "${{ env.DEFCONFIG }}"
  401. echo "CONFIG_KSU_SUSFS=y" >> "${{ env.DEFCONFIG }}"
  402. echo "#CONFIG_KSU_SUSFS_HAS_MAGIC_MOUNT=y" >> "${{ env.DEFCONFIG }}"
  403. echo "CONFIG_KSU_SUSFS_SUS_PATH=y" >> "${{ env.DEFCONFIG }}"
  404. echo "CONFIG_KSU_SUSFS_SUS_MOUNT=y" >> "${{ env.DEFCONFIG }}"
  405. echo "CONFIG_KSU_SUSFS_TRY_UMOUNT=y" >> "${{ env.DEFCONFIG }}"
  406. echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT=y" >> "${{ env.DEFCONFIG }}"
  407. echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT=y" >> "${{ env.DEFCONFIG }}"
  408. echo "CONFIG_KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT=y" >> "${{ env.DEFCONFIG }}"
  409. echo "CONFIG_KSU_SUSFS_SUS_KSTAT=y" >> "${{ env.DEFCONFIG }}"
  410. echo "CONFIG_KSU_SUSFS_SUS_OVERLAYFS=n" >> "${{ env.DEFCONFIG }}"
  411. echo "CONFIG_KSU_SUSFS_SPOOF_UNAME=y" >> "${{ env.DEFCONFIG }}"
  412. echo "CONFIG_KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG=y" >> "${{ env.DEFCONFIG }}"
  413. echo "CONFIG_KSU_SUSFS_OPEN_REDIRECT=y" >> "${{ env.DEFCONFIG }}"
  414. echo "CONFIG_KSU_SUSFS_ENABLE_LOG=y" >> "${{ env.DEFCONFIG }}"
  415. echo "CONFIG_KSU_SUSFS_HIDE_KSU_SUSFS_SYMBOLS=y" >> "${{ env.DEFCONFIG }}"
  416. echo "CONFIG_KSU_SUSFS_SUS_SU=n" >> "${{ env.DEFCONFIG }}"
  417. - name: Configure Sound
  418. run: |
  419. cd "$CONFIG"
  420. # Sound Configuration
  421. echo "# Sound Configuration" >> "${{ env.DEFCONFIG }}"
  422. echo "CONFIG_SND=y" >> "${{ env.DEFCONFIG }}"
  423. echo "CONFIG_SND_DRIVERS=y" >> "${{ env.DEFCONFIG }}"
  424. echo "CONFIG_SND_PCM=y" >> "${{ env.DEFCONFIG }}"
  425. echo "CONFIG_SND_TIMER=y" >> "${{ env.DEFCONFIG }}"
  426. echo "CONFIG_SND_DYNAMIC_MINORS=y" >> "${{ env.DEFCONFIG }}"
  427. echo "CONFIG_SND_PROC_FS=y" >> "${{ env.DEFCONFIG }}"
  428. echo "CONFIG_SND_ALOOP=m" >> "${{ env.DEFCONFIG }}"
  429. # Add snd-aloop.ko to modules list
  430. if [ -f "build/build.sh" ]; thena
  431. echo "sound/drivers/snd-aloop.ko" >> common/android/gki_aarch64_modules
  432. else
  433. sed -i '/_COMMON_GKI_MODULES_LIST = \[/,/]/ { /]/ i\ "sound/drivers/snd-aloop.ko", }' common/modules.bzl
  434. fi
  435. # Add symbols to abi_gki_aarch64
  436. SYMBOL_LIST=common/android/abi_gki_aarch64
  437. cat Wild_KSU/kernel/export_symbol.txt | awk '{sub("[ \t]+","");print " "$0}' >> $SYMBOL_LIST
  438. - name: Configure Build Optimization
  439. run: |
  440. cd "$CONFIG"
  441. # Build Optimization Configuration
  442. echo "# Build Optimization Configuration" >> "${{ env.DEFCONFIG }}"
  443. echo "CONFIG_LTO_CLANG_THIN=y" >> "${{ env.DEFCONFIG }}"
  444. echo "CONFIG_LTO_CLANG=y" >> "${{ env.DEFCONFIG }}"
  445. echo "CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE=y" >> "${{ env.DEFCONFIG }}"
  446. echo "CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=n" >> "${{ env.DEFCONFIG }}"
  447. echo "CONFIG_OPTIMIZE_INLINING=y" >> "${{ env.DEFCONFIG }}"
  448. - name: Change Kernel Name
  449. run: |
  450. cd "$CONFIG"
  451. #Add Wild to Kernel Version
  452. sed -i '$s|echo "\$res"|echo "\$res-Wild"|' ./common/scripts/setlocalversion
  453. #Set Kernel Timestamp
  454. perl -pi -e 's{UTS_VERSION="\$\(echo \$UTS_VERSION \$CONFIG_FLAGS \$TIMESTAMP \| cut -b -\$UTS_LEN\)"}{UTS_VERSION="#1 SMP PREEMPT Sun Apr 20 04:20:00 UTC 2025"}' ./common/scripts/mkcompile_h
  455. if [ -f "build/build.sh" ]; then
  456. #Remove Dirty Flag
  457. sed -i 's/-dirty//' ./common/scripts/setlocalversion
  458. else
  459. #Remove Dirty Flag
  460. sed -i "/stable_scmversion_cmd/s/-maybe-dirty//g" ./build/kernel/kleaf/impl/stamp.bzl
  461. #Remove Abi Exports and Error
  462. rm -rf ./common/android/abi_gki_protected_exports_*
  463. perl -pi -e 's/^\s*"protected_exports_list"\s*:\s*"android\/abi_gki_protected_exports_aarch64",\s*$//;' ./common/BUILD.bazel
  464. fi
  465. - name: Set file name
  466. run: |
  467. # Set artifact name base for consistent naming
  468. # Prepare sublevel for naming
  469. SUBLEVEL_FOR_NAME="${{ inputs.sub_level }}"
  470. if [ -n "$ACTUAL_SUBLEVEL" ]; then
  471. SUBLEVEL_FOR_NAME="$ACTUAL_SUBLEVEL"
  472. fi
  473. # Set artifact name base for consistent naming
  474. ARTIFACT_BASE="WKSU-${{ env.KSUVER }}-SUSFS_${{ inputs.susfs_version }}-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${SUBLEVEL_FOR_NAME}-${{ inputs.os_patch_level }}-${{ matrix.apply_bypass == 'bypass' && 'Bypass' || 'Normal' }}${{ matrix.apply_bbg == 'bbg' && '-BBG' || '' }}"
  475. echo "ARTIFACT_BASE=$ARTIFACT_BASE" >> $GITHUB_ENV
  476. echo "FILE_NAME=$ARTIFACT_BASE" >> $GITHUB_ENV
  477. - name: Build
  478. run : |
  479. set -e
  480. set -x
  481. cd "$CONFIG"
  482. echo "Building the kernel..."
  483. if [ -f "build/build.sh" ]; then
  484. LTO=thin BUILD_CONFIG=common/build.config.gki.aarch64 build/build.sh || exit 1
  485. else
  486. tools/bazel build --config=fast --lto=thin //common:kernel_aarch64_dist || exit 1
  487. fi
  488. - name: Prepare AnyKernel3
  489. run: |
  490. # Copy Image from normal build locations
  491. if [ -f "./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image" ]; then
  492. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image AnyKernel3/Image
  493. elif [ -f "./$CONFIG/bazel-bin/common/kernel_aarch64/Image" ]; then
  494. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image AnyKernel3/Image
  495. else
  496. echo "Error: Image file not found in any expected location"
  497. exit 1
  498. fi
  499. - name: Search for Kernel Modules
  500. run: |
  501. echo "Searching for kernel modules (.ko files)..."
  502. # Function to scan for modules (search only)
  503. scan_modules() {
  504. local search_dir="$1"
  505. local module_count=0
  506. if [ -d "$search_dir" ]; then
  507. echo "Scanning directory: $search_dir"
  508. # Find all .ko files and report their locations
  509. while IFS= read -r -d '' module_file; do
  510. if [ -f "$module_file" ]; then
  511. module_name=$(basename "$module_file")
  512. echo "Found module: $module_name in $(dirname "$module_file")"
  513. ((module_count++))
  514. fi
  515. done < <(find "$search_dir" -name "*.ko" -type f -print0 2>/dev/null)
  516. fi
  517. return $module_count
  518. }
  519. # Scan common build output directories
  520. total_modules=0
  521. # Scan bazel-bin directory
  522. if scan_modules "./$CONFIG/bazel-bin"; then
  523. total_modules=$((total_modules + $?))
  524. fi
  525. # Scan out directory
  526. if scan_modules "./$CONFIG/out"; then
  527. total_modules=$((total_modules + $?))
  528. fi
  529. # Scan dist directory specifically
  530. if scan_modules "./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist"; then
  531. total_modules=$((total_modules + $?))
  532. fi
  533. # Look for snd-aloop.ko specifically
  534. echo "Searching specifically for snd-aloop.ko..."
  535. snd_aloop_found=$(find ./$CONFIG -name "snd-aloop.ko" -type f 2>/dev/null | head -1)
  536. if [ -n "$snd_aloop_found" ]; then
  537. echo "Found snd-aloop.ko at: $snd_aloop_found"
  538. else
  539. echo "snd-aloop.ko not found"
  540. fi
  541. echo "Total kernel modules found: $total_modules"
  542. - name: Create Bootimgs Folder and Copy Images for Android 12/13
  543. if: ${{ inputs.android_version == 'android12' || inputs.android_version == 'android13' }}
  544. run: |
  545. mkdir bootimgs
  546. echo "Creating bootimgs folder and copying images..."
  547. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image ./bootimgs
  548. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image.lz4 ./bootimgs
  549. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image ./
  550. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image.lz4 ./
  551. # Create gzip of the Image file
  552. gzip -n -k -f -9 ./Image > ./Image.gz
  553. gzip -n -k -f -9 ./Image > ./bootimgs/Image.gz
  554. - name: Create Bootimgs Folder and Copy Images for Android 14/15
  555. if: ${{ inputs.android_version == 'android14' || inputs.android_version == 'android15' }}
  556. run: |
  557. mkdir bootimgs
  558. echo "Creating bootimgs folder and copying images..."
  559. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image ./bootimgs
  560. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image.lz4 ./bootimgs
  561. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image ./
  562. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image.lz4 ./
  563. # Create gzip of the Image file
  564. gzip -n -k -f -9 ./Image > ./Image.gz
  565. gzip -n -k -f -9 ./Image > ./bootimgs/Image.gz
  566. - name: Android 12 boot image build script
  567. if: ${{ inputs.android_version == 'android12' }}
  568. run: |
  569. echo "Changing to configuration directory: $CONFIG..."
  570. cd bootimgs
  571. GKI_URL=https://dl.google.com/android/gki/gki-certified-boot-android12-5.10-"${{ inputs.os_patch_level }}"_r1.zip
  572. FALLBACK_URL=https://dl.google.com/android/gki/gki-certified-boot-android12-5.10-2023-01_r1.zip
  573. # Check if the GKI URL is available
  574. echo "Checking if GKI kernel URL is reachable: $GKI_URL"
  575. status=$(curl -sL -w "%{http_code}" "$GKI_URL" -o /dev/null)
  576. if [ "$status" = "200" ]; then
  577. echo "[+] Downloading from GKI_URL"
  578. curl -Lo gki-kernel.zip "$GKI_URL"
  579. else
  580. echo "[+] $GKI_URL not found, using $FALLBACK_URL"
  581. curl -Lo gki-kernel.zip "$FALLBACK_URL"
  582. fi
  583. # Unzip the downloaded kernel and remove the zip
  584. echo "Unzipping the downloaded kernel..."
  585. unzip gki-kernel.zip && rm gki-kernel.zip
  586. echo "Unpacking boot.img..."
  587. FULL_PATH=$(pwd)/boot-5.10.img
  588. echo "Unpacking using: $FULL_PATH"
  589. echo "Running unpack_bootimg.py..."
  590. $UNPACK_BOOTIMG --boot_img="$FULL_PATH"
  591. echo "Building boot.img"
  592. $MKBOOTIMG --header_version 4 --kernel Image --output boot.img --ramdisk out/ramdisk --os_version 12.0.0 --os_patch_level "${{ inputs.os_patch_level }}"
  593. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  594. cp ./boot.img ../${{ env.FILE_NAME }}-boot.img
  595. echo "Building boot-gz.img"
  596. $MKBOOTIMG --header_version 4 --kernel Image.gz --output boot-gz.img --ramdisk out/ramdisk --os_version 12.0.0 --os_patch_level "${{ inputs.os_patch_level }}"
  597. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-gz.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  598. cp ./boot-gz.img ../${{ env.FILE_NAME }}-boot-gz.img
  599. echo "Building boot-lz4.img"
  600. $MKBOOTIMG --header_version 4 --kernel Image.lz4 --output boot-lz4.img --ramdisk out/ramdisk --os_version 12.0.0 --os_patch_level "${{ inputs.os_patch_level }}"
  601. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-lz4.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  602. cp ./boot-lz4.img ../${{ env.FILE_NAME }}-boot-lz4.img
  603. - name: Android 13/14/15 boot image build script
  604. if: ${{ inputs.android_version == 'android13' || inputs.android_version == 'android14' || inputs.android_version == 'android15' }}
  605. run: |
  606. cd bootimgs
  607. echo "Building boot.img"
  608. $MKBOOTIMG --header_version 4 --kernel Image --output boot.img
  609. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  610. cp ./boot.img ../${{ env.FILE_NAME }}-boot.img
  611. echo "Building boot-gz.img"
  612. $MKBOOTIMG --header_version 4 --kernel Image.gz --output boot-gz.img
  613. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-gz.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  614. cp ./boot-gz.img ../${{ env.FILE_NAME }}-boot-gz.img
  615. echo "Building boot-lz4.img"
  616. $MKBOOTIMG --header_version 4 --kernel Image.lz4 --output boot-lz4.img
  617. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-lz4.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  618. cp ./boot-lz4.img ../${{ env.FILE_NAME }}-boot-lz4.img
  619. - name: Upload Build Artifacts
  620. uses: actions/upload-artifact@v4
  621. with:
  622. name: ${{ env.FILE_NAME }}-AnyKernel3
  623. path: |
  624. AnyKernel3/
  625. compression-level: 9
  626. - name: Upload Build Artifacts
  627. uses: actions/upload-artifact@v4
  628. with:
  629. name: ${{ env.FILE_NAME }}-Boot
  630. path: |
  631. AnyKernel3/
  632. *-boot.img
  633. *-boot-gz.img
  634. *-boot-lz4.img
  635. compression-level: 9
  636. - name: Upload Build Diagnostics
  637. if: ${{ always() }}
  638. uses: actions/upload-artifact@v4
  639. with:
  640. name: ${{ env.FILE_NAME }}-Rejected-Patches
  641. path: patch-rejects
  642. compression-level: 9