build.yml 28 KB

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