build.yml 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  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:
  21. required: false
  22. type: string
  23. jobs:
  24. build-gki:
  25. runs-on: ubuntu-latest
  26. timeout-minutes: 120
  27. steps:
  28. # # - name: Maximize Build Space
  29. # uses: AdityaGarg8/remove-unwanted-software@v5
  30. # with:
  31. # remove-dotnet: 'true' # Frees ~2 GB
  32. # remove-android: 'true' # Frees ~9 GB
  33. # remove-haskell: 'true' # Frees ~5.2 GB
  34. # remove-codeql: 'true' # Frees ~5.4 GB
  35. # remove-docker-images: 'true' # Frees ~3.2 GB
  36. # remove-large-packages: 'true' # Frees ~3.1 GB
  37. # remove-swapfile: 'true' # Frees ~4 GB
  38. # remove-cached-tools: 'false' # Avoid unless confirmed safe
  39. # verbose: 'true' # Enable detailed logging
  40. - name: Set CONFIG Environment Variable
  41. run: |
  42. # Set CONFIG dynamically based on inputs values
  43. CONFIG="${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.sub_level }}"
  44. # Set CONFIG as an environment variable for future steps
  45. echo "CONFIG=$CONFIG" >> $GITHUB_ENV
  46. - name: Setup Build Environment
  47. run: |
  48. sudo apt update && sudo apt install -y libelf-dev libssl-dev build-essential
  49. AOSP_MIRROR=https://android.googlesource.com
  50. BRANCH=main-kernel-2025
  51. git clone $AOSP_MIRROR/kernel/prebuilts/build-tools -b $BRANCH --depth 1 kernel-build-tools &
  52. git clone $AOSP_MIRROR/platform/system/tools/mkbootimg -b $BRANCH --depth 1 mkbootimg &
  53. wait
  54. echo "AVBTOOL=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/bin/avbtool" >> $GITHUB_ENV
  55. echo "MKBOOTIMG=$GITHUB_WORKSPACE/mkbootimg/mkbootimg.py" >> $GITHUB_ENV
  56. echo "UNPACK_BOOTIMG=$GITHUB_WORKSPACE/mkbootimg/unpack_bootimg.py" >> $GITHUB_ENV
  57. echo "BOOT_SIGN_KEY_PATH=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem" >> $GITHUB_ENV
  58. echo "PATH=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/bin:$PATH" >> $GITHUB_ENV
  59. mkdir -p ./git-repo
  60. curl https://storage.googleapis.com/git-repo-downloads/repo > ./git-repo/repo
  61. chmod a+rx ./git-repo/repo
  62. echo "REPO=$GITHUB_WORKSPACE/./git-repo/repo" >> $GITHUB_ENV
  63. - name: Set boot sign key
  64. env:
  65. BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }}
  66. run: |
  67. if [ ! -z "$BOOT_SIGN_KEY" ]; then
  68. echo "$BOOT_SIGN_KEY" > ./kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem
  69. fi
  70. - name: Clone AnyKernel3 and Other Dependencies
  71. run: |
  72. ANYKERNEL_BRANCH="gki-2.0"
  73. SUSFS_BRANCH="gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}"
  74. git clone https://github.com/WildKernels/AnyKernel3.git -b "$ANYKERNEL_BRANCH"
  75. git clone https://gitlab.com/simonpunk/susfs4ksu.git -b "$SUSFS_BRANCH"
  76. git clone https://github.com/WildKernels/kernel_patches.git
  77. - name: Initialize and Sync Kernel Source
  78. run: |
  79. mkdir -p "$CONFIG"
  80. cd "$CONFIG"
  81. FORMATTED_BRANCH="${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.os_patch_level }}"
  82. $REPO init --depth=1 --u https://android.googlesource.com/kernel/manifest -b common-${FORMATTED_BRANCH} --repo-rev=v2.16
  83. REMOTE_BRANCH=$(git ls-remote https://android.googlesource.com/kernel/common ${FORMATTED_BRANCH})
  84. DEFAULT_MANIFEST_PATH=.repo/manifests/default.xml
  85. if grep -q deprecated <<< $REMOTE_BRANCH; then
  86. sed -i "s/\"${FORMATTED_BRANCH}\"/\"deprecated\/${FORMATTED_BRANCH}\"/g" $DEFAULT_MANIFEST_PATH
  87. fi
  88. $REPO --trace sync -c -j$(nproc --all) --no-tags --fail-fast
  89. - name: Extract Actual Sublevel for LTS Builds
  90. if: inputs.sub_level == 'X'
  91. run: |
  92. cd "$CONFIG/common"
  93. if [ -f "Makefile" ]; then
  94. ACTUAL_SUBLEVEL=$(grep '^SUBLEVEL = ' Makefile | awk '{print $3}')
  95. if [ -n "$ACTUAL_SUBLEVEL" ]; then
  96. OLD_CONFIG="$CONFIG"
  97. NEW_CONFIG="${{ inputs.android_version }}-${{ inputs.kernel_version }}-$ACTUAL_SUBLEVEL"
  98. echo "CONFIG=$NEW_CONFIG" >> $GITHUB_ENV
  99. echo "ACTUAL_SUBLEVEL=$ACTUAL_SUBLEVEL" >> $GITHUB_ENV
  100. cd ../..
  101. if [ -d "$OLD_CONFIG" ]; then
  102. mv "$OLD_CONFIG" "$NEW_CONFIG"
  103. fi
  104. fi
  105. fi
  106. - name: Apply glibc 2.38 Compatibility Fix
  107. if: inputs.android_version == 'android14' && inputs.kernel_version == '6.1'
  108. run: |
  109. if [ ! -e build/build.sh ]; then
  110. GLIBC_VERSION=$(ldd --version 2>/dev/null | head -n 1 | awk '{print $NF}')
  111. if [ "$(printf '%s\n' "2.38" "$GLIBC_VERSION" | sort -V | head -n1)" = "2.38" ]; then
  112. cd $CONFIG/common/ && 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
  113. fi
  114. fi
  115. - name: Fix Less Then 6.6.50 Builds
  116. if: inputs.android_version == 'android15' && inputs.kernel_version == '6.6'
  117. run: |
  118. cd "$CONFIG/common"
  119. if ! grep -qxF '#include <trace/hooks/fs.h>' ./fs/namespace.c; then
  120. sed -i '/#include <trace\/hooks\/blk.h>/a #include <trace\/hooks\/fs.h>' ./fs/namespace.c
  121. fi
  122. - name: Apply ptrace patch for older kernels
  123. if: fromJSON(inputs.kernel_version) < 5.16
  124. run: |
  125. cd "$CONFIG/common"
  126. patch -p1 -F 3 < "../../kernel_patches/gki_ptrace.patch"
  127. - name: Add KernelSU
  128. run: |
  129. cd "$CONFIG"
  130. curl -LSs "https://raw.githubusercontent.com/WildKernels/Wild_KSU/wild/kernel/setup.sh" | bash -s wild
  131. - name: Apply SUSFS Patches for KernelSU Variants
  132. run: |
  133. cd "$CONFIG"
  134. # Apply core SUSFS patches
  135. cp ../susfs4ksu/kernel_patches/50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch ./common/
  136. cd common
  137. patch -p1 --forward < 50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch
  138. cd ..
  139. cp ../susfs4ksu/kernel_patches/fs/* ./common/fs/
  140. cp ../susfs4ksu/kernel_patches/include/linux/* ./common/include/linux/
  141. # Apply KSU integration patches
  142. cd ./Wild_KSU
  143. cp ../../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./
  144. patch -p1 --forward < 10_enable_susfs_for_ksu.patch || true
  145. # Apply compatibility fixes
  146. cp ../../kernel_patches/wild/susfs_fix_patches/v1.5.9/fix_core_hook.c.patch ./
  147. patch -p1 --forward --fuzz=3 < fix_core_hook.c.patch
  148. # Skip fix_rules.c.patch for Android 14 with kernel 6.1
  149. if [ "${{ inputs.android_version }}" != "android14" ] && [ "${{ inputs.kernel_version }}" != "6.1" ]; then
  150. cp ../../kernel_patches/wild/susfs_fix_patches/v1.5.9/fix_rules.c.patch ./
  151. patch -p1 --forward < fix_rules.c.patch
  152. fi
  153. cp ../../kernel_patches/wild/susfs_fix_patches/v1.5.9/fix_sucompat.c.patch ./
  154. patch -p1 --forward < fix_sucompat.c.patch
  155. cp ../../kernel_patches/wild/susfs_fix_patches/v1.5.9/fix_kernel_compat.c.patch ./
  156. patch -p1 --forward < fix_kernel_compat.c.patch
  157. - name: Getting KernelSU Version
  158. run: |
  159. cd "$CONFIG/Wild_KSU/kernel"
  160. BASE_VERSION=10200
  161. COMMIT_COUNT=$(/usr/bin/git rev-list --count HEAD)
  162. KSU_VERSION=$(expr $COMMIT_COUNT "+" $BASE_VERSION)
  163. echo "KSUVER=$KSU_VERSION" >> $GITHUB_ENV
  164. - name: Apply Hooks Patches
  165. run: |
  166. cd "$CONFIG/common"
  167. cp ../../kernel_patches/wild/hooks/scope_min_manual_hooks_v1.4.patch ./
  168. patch -p1 --forward -F 3 < scope_min_manual_hooks_v1.4.patch
  169. - name: Apply Hide Stuff Patches
  170. run: |
  171. cd "$CONFIG/common"
  172. cp ../../kernel_patches/69_hide_stuff.patch ./
  173. patch -p1 --forward -F 3 < 69_hide_stuff.patch
  174. - name: Apply Module Symbol Version Fix Patch
  175. run: |
  176. if [[ "${{ inputs.kernel_version }}" == "6.1" || "${{ inputs.kernel_version }}" == "6.6" ]]; then
  177. cd "$CONFIG/common/kernel/module"
  178. #sed -i 's/pr_warn("%s: disagrees about version of symbol %s\\n"/pr_warn("%s: disagrees about version of symbol %s, but ignore...\\n"/' version.c
  179. sed -i '/bad_version:/{:a;n;/return 0;/{s/return 0;/return 1;/;b};ba}' version.c
  180. else
  181. cd "$CONFIG/common/kernel"
  182. #sed -i 's/pr_warn("%s: disagrees about version of symbol %s\\n"/pr_warn("%s: disagrees about version of symbol %s, but ignore...\\n"/' module.c
  183. sed -i '/bad_version:/{:a;n;/return 0;/{s/return 0;/return 1;/;b};ba}' module.c
  184. fi
  185. - name: Fix WiFi and Bluetooth on Samsung 6.6 GKI devices
  186. if: ${{ ( inputs.kernel_version == '6.6' ) }}
  187. run: |
  188. SYMBOL_LIST=$CONFIG/common/android/abi_gki_aarch64_galaxy
  189. echo "kdp_set_cred_non_rcu" >> $SYMBOL_LIST
  190. echo "kdp_usecount_dec_and_test" >> $SYMBOL_LIST
  191. echo "kdp_usecount_inc" >> $SYMBOL_LIST
  192. cd $CONFIG/common
  193. PATCH="../../kernel_patches/samsung/min_kdp/add-min_kdp-symbols.patch"
  194. if patch -p1 --dry-run < $PATCH; then
  195. patch -p1 --no-backup-if-mismatch < $PATCH
  196. fi
  197. cd drivers
  198. cp "../../../kernel_patches/samsung/min_kdp/min_kdp.c" min_kdp.c
  199. echo "obj-y += min_kdp.o" >> Makefile
  200. - name: Apply Kernel Configuration
  201. run: |
  202. cd "$CONFIG"
  203. defconfig="./common/arch/arm64/configs/gki_defconfig"
  204. echo "Applying kernel configurations one by one..."
  205. # KernelSU Core Configuration
  206. echo "CONFIG_KSU=y" >> "$defconfig"
  207. echo "CONFIG_KSU_KPROBES_HOOK=n" >> "$defconfig"
  208. # Mountify Support
  209. echo "CONFIG_TMPFS_XATTR=y" >> "$defconfig"
  210. echo "CONFIG_TMPFS_POSIX_ACL=y" >> "$defconfig"
  211. # Networking Configuration
  212. echo "CONFIG_IP_NF_TARGET_TTL=y" >> "$defconfig"
  213. echo "CONFIG_IP6_NF_TARGET_HL=y" >> "$defconfig"
  214. echo "CONFIG_IP6_NF_MATCH_HL=y" >> "$defconfig"
  215. # BBR TCP Congestion Control
  216. echo "CONFIG_TCP_CONG_ADVANCED=y" >> "$defconfig"
  217. echo "CONFIG_TCP_CONG_BBR=y" >> "$defconfig"
  218. echo "CONFIG_NET_SCH_FQ=y" >> "$defconfig"
  219. echo "CONFIG_TCP_CONG_BIC=n" >> "$defconfig"
  220. echo "CONFIG_TCP_CONG_WESTWOOD=n" >> "$defconfig"
  221. echo "CONFIG_TCP_CONG_HTCP=n" >> "$defconfig"
  222. # IPSet support
  223. echo "CONFIG_IP_SET=y" >> "$defconfig"
  224. echo "CONFIG_IP_SET_MAX=256" >> "$defconfig"
  225. echo "CONFIG_IP_SET_BITMAP_IP=y" >> "$defconfig"
  226. echo "CONFIG_IP_SET_BITMAP_IPMAC=y" >> "$defconfig"
  227. echo "CONFIG_IP_SET_BITMAP_PORT=y" >> "$defconfig"
  228. echo "CONFIG_IP_SET_HASH_IP=y" >> "$defconfig"
  229. echo "CONFIG_IP_SET_HASH_IPPORT=y" >> "$defconfig"
  230. echo "CONFIG_IP_SET_HASH_IPPORTIP=y" >> "$defconfig"
  231. echo "CONFIG_IP_SET_HASH_IPPORTNET=y" >> "$defconfig"
  232. echo "CONFIG_IP_SET_HASH_NET=y" >> "$defconfig"
  233. echo "CONFIG_IP_SET_HASH_NETNET=y" >> "$defconfig"
  234. echo "CONFIG_IP_SET_HASH_NETPORT=y" >> "$defconfig"
  235. echo "CONFIG_IP_SET_HASH_NETIFACE=y" >> "$defconfig"
  236. # SUSFS Configuration
  237. echo "CONFIG_KSU_SUSFS=y" >> "$defconfig"
  238. echo "CONFIG_KSU_SUSFS_HAS_MAGIC_MOUNT=y" >> "$defconfig"
  239. echo "CONFIG_KSU_SUSFS_SUS_PATH=y" >> "$defconfig"
  240. echo "CONFIG_KSU_SUSFS_SUS_MOUNT=y" >> "$defconfig"
  241. # SUSFS Auto Mount Features
  242. echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT=y" >> "$defconfig"
  243. echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT=y" >> "$defconfig"
  244. echo "CONFIG_KSU_SUSFS_TRY_UMOUNT=y" >> "$defconfig"
  245. echo "CONFIG_KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT=y" >> "$defconfig"
  246. # SUSFS Advanced Features
  247. echo "CONFIG_KSU_SUSFS_SUS_KSTAT=y" >> "$defconfig"
  248. echo "CONFIG_KSU_SUSFS_SUS_OVERLAYFS=n" >> "$defconfig"
  249. echo "CONFIG_KSU_SUSFS_SPOOF_UNAME=y" >> "$defconfig"
  250. echo "CONFIG_KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG=y" >> "$defconfig"
  251. echo "CONFIG_KSU_SUSFS_OPEN_REDIRECT=y" >> "$defconfig"
  252. # SUSFS Debugging and Security
  253. echo "CONFIG_KSU_SUSFS_ENABLE_LOG=y" >> "$defconfig"
  254. echo "CONFIG_KSU_SUSFS_HIDE_KSU_SUSFS_SYMBOLS=y" >> "$defconfig"
  255. echo "CONFIG_KSU_SUSFS_SUS_SU=n" >> "$defconfig"
  256. # Build Optimization Configuration
  257. echo "CONFIG_LTO_CLANG_THIN=y" >> "$defconfig"
  258. echo "CONFIG_LTO_CLANG=y" >> "$defconfig"
  259. echo "CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE=y" >> "$defconfig"
  260. echo "CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3=n" >> "$defconfig"
  261. # Remove check_defconfig
  262. #sed -i 's/check_defconfig//' ./common/build.config.gki
  263. - name: Change Kernel Name
  264. run: |
  265. cd "$CONFIG"
  266. perl -pi -e 's/-dirty//' ./common/scripts/setlocalversion
  267. #Set Kernel Timestamp
  268. 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
  269. #Set Kernel Name
  270. if [ "${{ inputs.kernel_version }}" = "6.6" ]; then
  271. perl -0777 -pi -e 's/(echo "\$\{KERNELVERSION\}\$\{file_localversion\}\$\{config_localversion\}\$\{LOCALVERSION\}\$\{scm_version\}")/echo "\$\{KERNELVERSION\}\$\{file_localversion\}\$\{config_localversion\}\$\{LOCALVERSION\}\$\{scm_version\}-🟢-Wild"/s' ./common/scripts/setlocalversion
  272. else
  273. perl -0777 -pi -e 's/(echo "\$res")(?!.*echo "\$res")/echo "\$res-🟢-Wild"/s' ./common/scripts/setlocalversion
  274. fi
  275. #Set Kernel Timestamp
  276. perl -pi -e 's/build-timestamp = \$\(or \$\(KBUILD_BUILD_TIMESTAMP\), \$\(build-timestamp-auto\)\)/build-timestamp = "Sun Apr 20 04:20:00 UTC 2025"/' ./common/init/Makefile
  277. #Remove Abi Exports and Error
  278. rm -rf ./common/android/abi_gki_protected_exports_*
  279. #perl -pi -e 's/^\s*"protected_exports_list"\s*:\s*"android\/abi_gki_protected_exports_aarch64",\s*$//;' ./common/BUILD.bazel
  280. - name: Detect Clang Version from Configs
  281. run: |
  282. KERNEL_PATH="$GITHUB_WORKSPACE/$CONFIG"
  283. DEFCONFIG="$KERNEL_PATH/common/arch/arm64/configs/gki_defconfig"
  284. BUILDCONFIG="$KERNEL_PATH/common/build.config.gki"
  285. CONSTANTSCONFIG="$KERNEL_PATH/common/build.config.constants"
  286. CLANG_VERSION=""
  287. CLANG_BIN_PATH=""
  288. if grep -q '^CONFIG_CLANG_VERSION=' "$DEFCONFIG" 2>/dev/null; then
  289. CLANG_VERSION=$(grep '^CONFIG_CLANG_VERSION=' "$DEFCONFIG" 2>/dev/null | head -n1 | cut -d'=' -f2 | tr -d '"' | xargs)
  290. elif grep -q '^CLANG_VERSION=' "$BUILDCONFIG" 2>/dev/null; then
  291. CLANG_VERSION=$(grep '^CLANG_VERSION=' "$BUILDCONFIG" 2>/dev/null | head -n1 | cut -d'=' -f2 | xargs)
  292. elif grep -q '^CLANG_VERSION=' "$CONSTANTSCONFIG" 2>/dev/null; then
  293. CLANG_VERSION=$(grep '^CLANG_VERSION=' "$CONSTANTSCONFIG" 2>/dev/null | head -n1 | cut -d'=' -f2 | xargs)
  294. CLANG_VERSION="clang-$CLANG_VERSION"
  295. else
  296. echo "No clang version found in config, will auto-detect in prebuilts."
  297. fi
  298. if [ -z "$CLANG_VERSION" ]; then
  299. if [ -d "$KERNEL_PATH/prebuilts/clang/host/linux-x86" ]; then
  300. CLANG_VERSION=$(ls -d "$KERNEL_PATH"/prebuilts/clang/host/linux-x86/clang-r*/ | tail -n 1 | xargs basename)
  301. CLANG_BIN_PATH="$KERNEL_PATH/prebuilts/clang/host/linux-x86/$CLANG_VERSION/bin"
  302. elif [ -d "$KERNEL_PATH/prebuilts-master/clang/host/linux-x86" ]; then
  303. CLANG_VERSION=$(ls -d "$KERNEL_PATH"/prebuilts-master/clang/host/linux-x86/clang-r*/ | tail -n 1 | xargs basename)
  304. CLANG_BIN_PATH="$KERNEL_PATH/prebuilts-master/clang/host/linux-x86/$CLANG_VERSION/bin"
  305. else
  306. CLANG_VERSION="clang"
  307. CLANG_BIN_PATH="$KERNEL_PATH/prebuilts/clang/host/linux-x86/$CLANG_VERSION/bin" # dummy
  308. fi
  309. else
  310. if [ -d "$KERNEL_PATH/prebuilts/clang/host/linux-x86" ]; then
  311. CLANG_BIN_PATH="$KERNEL_PATH/prebuilts/clang/host/linux-x86/$CLANG_VERSION/bin"
  312. else
  313. CLANG_BIN_PATH="$KERNEL_PATH/prebuilts-master/clang/host/linux-x86/$CLANG_VERSION/bin"
  314. fi
  315. fi
  316. echo "CLANG_VERSION=$CLANG_VERSION" >> $GITHUB_ENV
  317. echo "CLANG_BIN_PATH=$CLANG_BIN_PATH" >> $GITHUB_ENV
  318. - name: Build Kernel
  319. run: |
  320. KERNEL_PATH="$GITHUB_WORKSPACE/$CONFIG"
  321. CLANG_BIN_PATH="${{ env.CLANG_BIN_PATH }}"
  322. CLANG_VERSION="${{ env.CLANG_VERSION }}"
  323. if [ -d "$CLANG_BIN_PATH" ] && [ -x "$CLANG_BIN_PATH/clang" ]; then
  324. export PATH="$CLANG_BIN_PATH:$PATH"
  325. SELECTED_CLANG="$CLANG_BIN_PATH/clang"
  326. elif command -v clang >/dev/null 2>&1; then
  327. SELECTED_CLANG="$(command -v clang)"
  328. exit 1
  329. else
  330. exit 1
  331. fi
  332. LLVM_TOOLS="clang ld.lld llvm-ar llvm-objcopy llvm-objdump llvm-nm"
  333. MISSING_TOOLS=""
  334. for tool in $LLVM_TOOLS; do
  335. if ! command -v $tool >/dev/null 2>&1; then
  336. MISSING_TOOLS="$MISSING_TOOLS $tool"
  337. fi
  338. done
  339. if [ -n "$MISSING_TOOLS" ]; then
  340. sudo apt-get update
  341. sudo apt-get install -yq --no-install-recommends llvm
  342. for tool in $MISSING_TOOLS; do
  343. if ! command -v $tool >/dev/null 2>&1; then
  344. exit 1
  345. fi
  346. done
  347. fi
  348. KERNEL_VERSION="${{ inputs.kernel_version }}"
  349. if [[ "$KERNEL_VERSION" == "5.10" ]]; then
  350. USE_LLVM_IAS=true
  351. fi
  352. cd "$KERNEL_PATH/common" || exit 1
  353. MAKE_ARGS="LLVM=1 ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- \
  354. RUSTC=$KERNEL_PATH/prebuilts/rust/linux-x86/1.73.0b/bin/rustc \
  355. PAHOLE=$KERNEL_PATH/prebuilts/kernel-build-tools/linux-x86/bin/pahole \
  356. LD=ld.lld HOSTLD=ld.lld"
  357. if [[ -v USE_LLVM_IAS ]]; then
  358. MAKE_ARGS="LLVM_IAS=1 $MAKE_ARGS"
  359. fi
  360. make -j$(nproc --all) O=out $MAKE_ARGS KCFLAGS+="-Wno-error -O2 -flto=thin -fno-stack-protector" gki_defconfig Image Image.gz Image.lz4 || exit 1
  361. make -j$(nproc --all) O=out $MAKE_ARGS KCFLAGS+="-Wno-error -O2 -flto=thin -fno-stack-protector" || exit 1
  362. - name: Create Kernel ZIP
  363. run: |
  364. cp $CONFIG/common/out/arch/arm64/boot/Image AnyKernel3/Image
  365. cd AnyKernel3
  366. # Use actual sublevel for LTS builds if available
  367. SUBLEVEL_FOR_NAME="${{ inputs.sub_level }}"
  368. if [ -n "$ACTUAL_SUBLEVEL" ]; then
  369. SUBLEVEL_FOR_NAME="$ACTUAL_SUBLEVEL"
  370. fi
  371. ZIP_NAME="WKSU-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.$SUBLEVEL_FOR_NAME-${{ inputs.os_patch_level }}-AnyKernel3.zip"
  372. zip -r "../$ZIP_NAME" ./*
  373. - name: Create Bootimgs Folder and Copy Images
  374. run: |
  375. mkdir bootimgs
  376. echo "Creating bootimgs folder and copying images..."
  377. cp $CONFIG/common/out/arch/arm64/boot/Image ./bootimgs
  378. cp $CONFIG/common/out/arch/arm64/boot/Image.gz ./bootimgs
  379. cp $CONFIG/common/out/arch/arm64/boot/Image.lz4 ./bootimgs
  380. - name: Android 12 boot image build script
  381. if: ${{ inputs.android_version == 'android12' }}
  382. run: |
  383. echo "Changing to configuration directory: $CONFIG..."
  384. cd bootimgs
  385. # Prepare sublevel for naming
  386. SUBLEVEL_FOR_NAME="${{ inputs.sub_level }}"
  387. if [ -n "$ACTUAL_SUBLEVEL" ]; then
  388. SUBLEVEL_FOR_NAME="$ACTUAL_SUBLEVEL"
  389. fi
  390. GKI_URL=https://dl.google.com/android/gki/gki-certified-boot-android12-5.10-"${{ inputs.os_patch_level }}"_"${{ inputs.revision }}".zip
  391. FALLBACK_URL=https://dl.google.com/android/gki/gki-certified-boot-android12-5.10-2023-01_r1.zip
  392. # Check if the GKI URL is available
  393. echo "Checking if GKI kernel URL is reachable: $GKI_URL"
  394. status=$(curl -sL -w "%{http_code}" "$GKI_URL" -o /dev/null)
  395. if [ "$status" = "200" ]; then
  396. echo "[+] Downloading from GKI_URL"
  397. curl -Lo gki-kernel.zip "$GKI_URL"
  398. else
  399. echo "[+] $GKI_URL not found, using $FALLBACK_URL"
  400. curl -Lo gki-kernel.zip "$FALLBACK_URL"
  401. fi
  402. # Unzip the downloaded kernel and remove the zip
  403. echo "Unzipping the downloaded kernel..."
  404. unzip gki-kernel.zip && rm gki-kernel.zip
  405. echo "Unpacking boot.img..."
  406. FULL_PATH=$(pwd)/boot-5.10.img
  407. echo "Unpacking using: $FULL_PATH"
  408. echo "Running unpack_bootimg.py..."
  409. $UNPACK_BOOTIMG --boot_img="$FULL_PATH"
  410. echo "Building boot.img"
  411. $MKBOOTIMG --header_version 4 --kernel Image --output boot.img --ramdisk out/ramdisk --os_version 12.0.0 --os_patch_level "${{ inputs.os_patch_level }}"
  412. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  413. cp ./boot.img ../WKSU-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.$SUBLEVEL_FOR_NAME-${{ inputs.os_patch_level }}-boot.img
  414. echo "Building boot-gz.img"
  415. $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 }}"
  416. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-gz.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  417. cp ./boot-gz.img ../WKSU-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.$SUBLEVEL_FOR_NAME-${{ inputs.os_patch_level }}-boot-gz.img
  418. echo "Building boot-lz4.img"
  419. $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 }}"
  420. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-lz4.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  421. cp ./boot-lz4.img ../WKSU-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.$SUBLEVEL_FOR_NAME-${{ inputs.os_patch_level }}-boot-lz4.img
  422. - name: Android 13/14/15 boot image build script
  423. if: ${{ inputs.android_version == 'android13' || inputs.android_version == 'android14' || inputs.android_version == 'android15' }}
  424. run: |
  425. cd bootimgs
  426. # Prepare sublevel for naming
  427. SUBLEVEL_FOR_NAME="${{ inputs.sub_level }}"
  428. if [ -n "$ACTUAL_SUBLEVEL" ]; then
  429. SUBLEVEL_FOR_NAME="$ACTUAL_SUBLEVEL"
  430. fi
  431. echo "Building boot.img"
  432. $MKBOOTIMG --header_version 4 --kernel Image --output boot.img
  433. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  434. cp ./boot.img ../WKSU-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.$SUBLEVEL_FOR_NAME-${{ inputs.os_patch_level }}-boot.img
  435. echo "Building boot-gz.img"
  436. $MKBOOTIMG --header_version 4 --kernel Image.gz --output boot-gz.img
  437. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-gz.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  438. cp ./boot-gz.img ../WKSU-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.$SUBLEVEL_FOR_NAME-${{ inputs.os_patch_level }}-boot-gz.img
  439. echo "Building boot-lz4.img"
  440. $MKBOOTIMG --header_version 4 --kernel Image.lz4 --output boot-lz4.img
  441. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-lz4.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  442. cp ./boot-lz4.img ../WKSU-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.$SUBLEVEL_FOR_NAME-${{ inputs.os_patch_level }}-boot-lz4.img
  443. - name: Upload Build Artifacts
  444. run: |
  445. # Prepare sublevel for naming
  446. SUBLEVEL_FOR_NAME="${{ inputs.sub_level }}"
  447. if [ -n "$ACTUAL_SUBLEVEL" ]; then
  448. SUBLEVEL_FOR_NAME="$ACTUAL_SUBLEVEL"
  449. fi
  450. - name: Upload Build Artifacts
  451. uses: actions/upload-artifact@v4
  452. with:
  453. name: WKSU-${{ env.KSUVER }}-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ env.ACTUAL_SUBLEVEL || inputs.sub_level }}-${{ inputs.os_patch_level }}
  454. path: |
  455. *.zip
  456. *.img