build.yml 26 KB

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