build.yml 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. name: Build Script
  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. kernelsu_variant:
  21. required: true
  22. type: string
  23. kernelsu_branch:
  24. required: true
  25. type: string
  26. kernelsu_branch_other:
  27. required: false
  28. type: string
  29. revision:
  30. required: false
  31. type: string
  32. jobs:
  33. build-gki:
  34. runs-on: ubuntu-latest
  35. timeout-minutes: 120
  36. env:
  37. CCACHE_COMPILERCHECK: "%compiler% -dumpmachine; %compiler% -dumpversion"
  38. CCACHE_NOHASHDIR: "true"
  39. CCACHE_HARDLINK: "true"
  40. steps:
  41. - name: Maximize Build Space
  42. uses: AdityaGarg8/remove-unwanted-software@v5
  43. with:
  44. remove-dotnet: 'true' # Frees ~2 GB
  45. remove-android: 'true' # Frees ~9 GB
  46. remove-haskell: 'true' # Frees ~5.2 GB
  47. remove-codeql: 'true' # Frees ~5.4 GB
  48. remove-docker-images: 'true' # Frees ~3.2 GB
  49. remove-large-packages: 'true' # Frees ~3.1 GB
  50. remove-swapfile: 'true' # Frees ~4 GB
  51. remove-cached-tools: 'false' # Avoid unless confirmed safe
  52. verbose: 'true' # Enable detailed logging
  53. - name: Set CONFIG Environment Variable
  54. run: |
  55. # Set CONFIG dynamically based on inputs values
  56. CONFIG="${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.sub_level }}"
  57. # Set CONFIG as an environment variable for future steps
  58. echo "CONFIG=$CONFIG" >> $GITHUB_ENV
  59. echo "CONFIG set to: $CONFIG"
  60. - name: Install ccache
  61. run: sudo apt update && sudo apt install -y ccache
  62. - name: Set up ccache
  63. run: |
  64. mkdir -p ~/.cache/bazel
  65. ccache --version
  66. ccache --max-size=2G
  67. ccache --set-config=compression=true
  68. echo "CCACHE_DIR=$HOME/.ccache" >> $GITHUB_ENV
  69. - name: Download toolchain
  70. run: |
  71. AOSP_MIRROR=https://android.googlesource.com
  72. BRANCH=main-kernel-build-2024
  73. git clone $AOSP_MIRROR/kernel/prebuilts/build-tools -b $BRANCH --depth 1 kernel-build-tools
  74. git clone $AOSP_MIRROR/platform/system/tools/mkbootimg -b $BRANCH --depth 1 mkbootimg
  75. - name: Set environment variables
  76. run: |
  77. echo "AVBTOOL=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/bin/avbtool" >> $GITHUB_ENV
  78. echo "MKBOOTIMG=$GITHUB_WORKSPACE/mkbootimg/mkbootimg.py" >> $GITHUB_ENV
  79. echo "UNPACK_BOOTIMG=$GITHUB_WORKSPACE/mkbootimg/unpack_bootimg.py" >> $GITHUB_ENV
  80. - name: Set boot sign key
  81. env:
  82. BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }}
  83. run: |
  84. if [ ! -z "$BOOT_SIGN_KEY" ]; then
  85. echo "$BOOT_SIGN_KEY" > ./kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem
  86. echo "BOOT_SIGN_KEY_PATH=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem" >> $GITHUB_ENV
  87. else
  88. echo "BOOT_SIGN_KEY is not set. Using AOSP sign key..."
  89. echo "BOOT_SIGN_KEY_PATH=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem" >> $GITHUB_ENV
  90. fi
  91. - name: Install Repo
  92. run: |
  93. mkdir -p ./git-repo
  94. echo "Downloading repo tool..."
  95. curl https://storage.googleapis.com/git-repo-downloads/repo > ./git-repo/repo
  96. chmod a+rx ./git-repo/repo
  97. echo "REPO=$GITHUB_WORKSPACE/./git-repo/repo" >> $GITHUB_ENV
  98. - name: Clone AnyKernel3 and Other Dependencies
  99. run: |
  100. echo "Cloning AnyKernel3 and other dependencies..."
  101. ANYKERNEL_BRANCH="gki-2.0"
  102. SUSFS_BRANCH="gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}"
  103. echo "Using branch for AnyKernel3: $ANYKERNEL_BRANCH"
  104. echo "Using branch for SUSFS: $SUSFS_BRANCH"
  105. git clone https://github.com/WildPlusKernel/AnyKernel3.git -b "$ANYKERNEL_BRANCH"
  106. git clone https://gitlab.com/simonpunk/susfs4ksu.git -b "$SUSFS_BRANCH"
  107. git clone https://github.com/WildPlusKernel/kernel_patches.git
  108. - name: Initialize and Sync Kernel Source
  109. run: |
  110. echo "Creating folder for configuration: $CONFIG..."
  111. mkdir -p "$CONFIG"
  112. cd "$CONFIG"
  113. echo "Initializing and syncing kernel source..."
  114. FORMATTED_BRANCH="${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.os_patch_level }}"
  115. $REPO init --depth=1 --u https://android.googlesource.com/kernel/manifest -b common-${FORMATTED_BRANCH} --repo-rev=v2.16
  116. REMOTE_BRANCH=$(git ls-remote https://android.googlesource.com/kernel/common ${FORMATTED_BRANCH})
  117. DEFAULT_MANIFEST_PATH=.repo/manifests/default.xml
  118. if grep -q deprecated <<< $REMOTE_BRANCH; then
  119. echo "Found deprecated branch: $FORMATTED_BRANCH"
  120. sed -i "s/\"${FORMATTED_BRANCH}\"/\"deprecated\/${FORMATTED_BRANCH}\"/g" $DEFAULT_MANIFEST_PATH
  121. fi
  122. $REPO --version
  123. $REPO --trace sync -c -j$(nproc --all) --no-tags --fail-fast
  124. - name: Fix Less Then 6.6.50 Builds
  125. run: |
  126. cd "$CONFIG/common"
  127. if [ "${{ inputs.android_version }}" = "android15" ] && [ "${{ inputs.kernel_version }}" = "6.6" ]; then
  128. if ! grep -qxF '#include <trace/hooks/fs.h>' ./fs/namespace.c; then
  129. sed -i '/#include <trace\/hooks\/blk.h>/a #include <trace\/hooks\/fs.h>' ./fs/namespace.c
  130. else
  131. echo "Line already present. Skipping insert."
  132. fi
  133. fi
  134. - name: Determine the branch for KernelSU
  135. run: |
  136. case "${{ inputs.kernelsu_branch }}" in
  137. "Stable")
  138. echo "BRANCH=-" >> $GITHUB_ENV
  139. ;;
  140. "Dev")
  141. if [[ "${{ inputs.kernelsu_variant }}" =~ ^(KSU|MKSU)$ ]]; then
  142. echo "BRANCH=-s main" >> $GITHUB_ENV
  143. elif [[ "${{ inputs.kernelsu_variant }}" == "NEXT" ]]; then
  144. echo "BRANCH=-s next" >> $GITHUB_ENV
  145. elif [[ "${{ inputs.kernelsu_variant }}" == "WILD" ]]; then
  146. echo "BRANCH=-s wild" >> $GITHUB_ENV
  147. fi
  148. ;;
  149. "Other")
  150. if [[ -n "${{ inputs.kernelsu_branch_other }}" ]]; then
  151. echo "BRANCH=-s ${{ inputs.kernelsu_branch_other }}" >> $GITHUB_ENV
  152. else
  153. echo "Error: Custom branch not provided for 'Other'" >&2
  154. exit 1
  155. fi
  156. ;;
  157. esac
  158. - name: Add KernelSU
  159. run: |
  160. echo "Changing to configuration directory: $CONFIG..."
  161. cd "$CONFIG"
  162. case "${{ inputs.kernelsu_variant }}" in
  163. "WILD")
  164. echo "Adding Wild KSU..."
  165. curl -LSs "https://raw.githubusercontent.com/WildKernels/Wild_KSU/wild/kernel/setup.sh" | bash ${{ env.BRANCH }}
  166. ;;
  167. "KSU")
  168. echo "Adding KernelSU Official..."
  169. curl -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash ${{ env.BRANCH }}
  170. ;;
  171. "NEXT")
  172. echo "Adding KernelSU Next..."
  173. curl -LSs "https://raw.githubusercontent.com/KernelSU-Next/KernelSU-Next/next/kernel/setup.sh" | bash ${{ env.BRANCH }}
  174. ;;
  175. "MKSU")
  176. echo "Adding KernelSU MKSU..."
  177. curl -LSs "https://raw.githubusercontent.com/5ec1cff/KernelSU/main/kernel/setup.sh" | bash ${{ env.BRANCH }}
  178. ;;
  179. esac
  180. - name: Apply SUSFS Patches for KernelSU Variants
  181. run: |
  182. echo "Changing to configuration directory: $CONFIG..."
  183. cd "$CONFIG"
  184. echo "Applying SUSFS patches..."
  185. # Copy SUSFS patches
  186. cp ../susfs4ksu/kernel_patches/50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch ./common/
  187. cd common
  188. patch -p1 --forward < 50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch
  189. cd ..
  190. cp ../susfs4ksu/kernel_patches/fs/* ./common/fs/
  191. cp ../susfs4ksu/kernel_patches/include/linux/* ./common/include/linux/
  192. case "${{ inputs.kernelsu_variant }}" in
  193. "WILD")
  194. echo "Applying SUSFS patches for Official KernelSU..."
  195. cd ./Wild_KSU
  196. ;;
  197. "KSU")
  198. echo "Applying SUSFS patches for Official KernelSU..."
  199. cd ./KernelSU
  200. cp ../../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./
  201. patch -p1 --forward < 10_enable_susfs_for_ksu.patch
  202. ;;
  203. "NEXT")
  204. echo "Applying SUSFS patches for KernelSU Next..."
  205. cd ./KernelSU-Next
  206. cp ../../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./
  207. patch -p1 --forward < 10_enable_susfs_for_ksu.patch || true
  208. cp ../../kernel_patches/next/susfs_fix_patches/v1.5.9/fix_apk_sign.c.patch ./
  209. patch -p1 --forward < fix_apk_sign.c.patch
  210. cp ../../kernel_patches/next/susfs_fix_patches/v1.5.9/fix_core_hook.c.patch ./
  211. patch -p1 --forward --fuzz=3 < fix_core_hook.c.patch
  212. cp ../../kernel_patches/next/susfs_fix_patches/v1.5.9/fix_selinux.c.patch ./
  213. patch -p1 --forward < fix_selinux.c.patch
  214. cp ../../kernel_patches/next/susfs_fix_patches/v1.5.9/fix_ksud.c.patch ./
  215. patch -p1 --forward < fix_ksud.c.patch
  216. cp ../../kernel_patches/next/susfs_fix_patches/v1.5.9/fix_rules.c.patch ./
  217. patch -p1 --forward < fix_rules.c.patch
  218. cp ../../kernel_patches/next/susfs_fix_patches/v1.5.9/fix_sucompat.c.patch ./
  219. patch -p1 --forward < fix_sucompat.c.patch
  220. cp ../../kernel_patches/next/susfs_fix_patches/v1.5.9/fix_kernel_compat.c.patch ./
  221. patch -p1 --forward < fix_kernel_compat.c.patch
  222. ;;
  223. "MKSU")
  224. echo "Applying SUSFS patches for MKSU..."
  225. cd ./KernelS
  226. ;;
  227. esac
  228. - name: Getting KernelSU Version
  229. run: |
  230. echo "Changing to configuration directory: $CONFIG..."
  231. cd "$CONFIG"
  232. case "${{ inputs.kernelsu_variant }}" in
  233. "WILD")
  234. echo "Applying SUSFS patches for Official KernelSU..."
  235. cd ./Wild_KSU
  236. BASE_VERSION=10200
  237. ;;
  238. "KSU")
  239. echo "Applying SUSFS patches for Official KernelSU..."
  240. cd ./KernelSU
  241. BASE_VERSION=10200
  242. ;;
  243. "NEXT")
  244. cd ./KernelSU-Next
  245. BASE_VERSION=10200
  246. ;;
  247. "MKSU")
  248. ;;
  249. esac
  250. cd ./kernel
  251. KSU_VERSION=$(expr $(/usr/bin/git rev-list --count HEAD) "+" $BASE_VERSION)
  252. echo "KSUVER=$KSU_VERSION" >> $GITHUB_ENV
  253. - name: Apply Hooks Patches
  254. run: |
  255. echo "Changing to configuration directory: $CONFIG..."
  256. cd "$CONFIG/common"
  257. if [ "${{ inputs.kernelsu_variant }}" == "NEXT" ]; then
  258. echo "Applying hooks for KernelSU-Next..."
  259. cp ../../kernel_patches/next/scope_min_manual_hooks_v1.4.patch ./
  260. patch -p1 --forward -F 3 < scope_min_manual_hooks_v1.4.patch
  261. elif [ "${{ inputs.kernelsu_variant }}" == "WILD" ]; then
  262. echo "Applying hooks for Wild KSU..."
  263. cp ../../kernel_patches/wild/syscall_hooks.patch ./
  264. patch -p1 --forward -F 3 < syscall_hooks.patch
  265. fi
  266. - name: Apply Hide Stuff Patches
  267. run: |
  268. echo "Changing to configuration directory: $CONFIG..."
  269. cd "$CONFIG/common"
  270. cp ../../kernel_patches/69_hide_stuff.patch ./
  271. patch -p1 --forward -F 3 < 69_hide_stuff.patch
  272. - name: Fix WiFi and Bluetooth on Samsung 6.6 GKI devices
  273. if: ${{ ( inputs.kernel_version == '6.6' ) }}
  274. run: |
  275. echo "[+] Adding Samsung KDP exported symbols to abi_gki_aarch64_galaxy"
  276. SYMBOL_LIST=$CONFIG/common/android/abi_gki_aarch64_galaxy
  277. echo "kdp_set_cred_non_rcu" >> $SYMBOL_LIST
  278. echo "kdp_usecount_dec_and_test" >> $SYMBOL_LIST
  279. echo "kdp_usecount_inc" >> $SYMBOL_LIST
  280. echo "[+] Adding Samsung KDP exported symbols definition to abi_gki_aarch64.stg"
  281. cd $CONFIG/common
  282. PATCH="../../kernel_patches/samsung/min_kdp/add-min_kdp-symbols.patch"
  283. if patch -p1 --dry-run < $PATCH; then
  284. echo "[+] Successfully added Samsung KDP exported symbols definition to abi_gki_aarch64.stg"
  285. patch -p1 --no-backup-if-mismatch < $PATCH
  286. fi
  287. echo "[+] Adding Samsung minimal KDP driver"
  288. cd drivers
  289. cp "../../../kernel_patches/samsung/min_kdp/min_kdp.c" min_kdp.c
  290. echo "obj-y += min_kdp.o" >> Makefile
  291. - name: Add Configuration Settings
  292. run: |
  293. echo "Changing to configuration directory: $CONFIG..."
  294. cd "$CONFIG"
  295. echo "Adding configuration settings to gki_defconfig..."
  296. # Add KSU configuration settings
  297. echo "CONFIG_KSU=y" >> ./common/arch/arm64/configs/gki_defconfig
  298. if [ "${{ inputs.kernelsu_variant }}" == "NEXT" ] || [ "${{ inputs.kernelsu_variant }}" == "WILD" ]; then
  299. echo "CONFIG_KSU_KPROBES_HOOK=n" >> ./common/arch/arm64/configs/gki_defconfig
  300. fi
  301. # Add additional tmpfs config setting
  302. echo "CONFIG_TMPFS_XATTR=y" >> ./common/arch/arm64/configs/gki_defconfig
  303. echo "CONFIG_TMPFS_POSIX_ACL=y" >> ./common/arch/arm64/configs/gki_defconfig
  304. # Add additional config setting
  305. echo "CONFIG_IP_NF_TARGET_TTL=y" >> ./common/arch/arm64/configs/gki_defconfig
  306. echo "CONFIG_IP6_NF_TARGET_HL=y" >> ./common/arch/arm64/configs/gki_defconfig
  307. echo "CONFIG_IP6_NF_MATCH_HL=y" >> ./common/arch/arm64/configs/gki_defconfig
  308. # Add BBR Config
  309. echo "CONFIG_TCP_CONG_ADVANCED=y" >> ./common/arch/arm64/configs/gki_defconfig
  310. echo "CONFIG_TCP_CONG_BBR=y" >> ./common/arch/arm64/configs/gki_defconfig
  311. echo "CONFIG_NET_SCH_FQ=y" >> ./common/arch/arm64/configs/gki_defconfig
  312. echo "CONFIG_TCP_CONG_BIC=n" >> ./common/arch/arm64/configs/gki_defconfig
  313. echo "CONFIG_TCP_CONG_WESTWOOD=n" >> ./common/arch/arm64/configs/gki_defconfig
  314. echo "CONFIG_TCP_CONG_HTCP=n" >> ./common/arch/arm64/configs/gki_defconfig
  315. # Remove check_defconfig
  316. sed -i 's/check_defconfig//' ./common/build.config.gki
  317. - name: Add SUSFS Configuration Settings
  318. run: |
  319. echo "Changing to configuration directory: $CONFIG..."
  320. cd "$CONFIG"
  321. # Add SUSFS configuration settings
  322. echo "CONFIG_KSU_SUSFS=y" >> ./common/arch/arm64/configs/gki_defconfig
  323. echo "CONFIG_KSU_SUSFS_HAS_MAGIC_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  324. echo "CONFIG_KSU_SUSFS_SUS_PATH=y" >> ./common/arch/arm64/configs/gki_defconfig
  325. echo "CONFIG_KSU_SUSFS_SUS_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  326. echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  327. echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  328. echo "CONFIG_KSU_SUSFS_SUS_KSTAT=y" >> ./common/arch/arm64/configs/gki_defconfig
  329. echo "CONFIG_KSU_SUSFS_SUS_OVERLAYFS=n" >> ./common/arch/arm64/configs/gki_defconfig
  330. echo "CONFIG_KSU_SUSFS_TRY_UMOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  331. echo "CONFIG_KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  332. echo "CONFIG_KSU_SUSFS_SPOOF_UNAME=y" >> ./common/arch/arm64/configs/gki_defconfig
  333. echo "CONFIG_KSU_SUSFS_ENABLE_LOG=y" >> ./common/arch/arm64/configs/gki_defconfig
  334. echo "CONFIG_KSU_SUSFS_HIDE_KSU_SUSFS_SYMBOLS=y" >> ./common/arch/arm64/configs/gki_defconfig
  335. echo "CONFIG_KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG=y" >> ./common/arch/arm64/configs/gki_defconfig
  336. echo "CONFIG_KSU_SUSFS_OPEN_REDIRECT=y" >> ./common/arch/arm64/configs/gki_defconfig
  337. if [ "${{ inputs.kernelsu_variant }}" == "NEXT" ] || [ "${{ inputs.kernelsu_variant }}" == "WILD" ]; then
  338. echo "CONFIG_KSU_SUSFS_SUS_SU=n" >> ./common/arch/arm64/configs/gki_defconfig
  339. else
  340. echo "CONFIG_KSU_SUSFS_SUS_SU=y" >> ./common/arch/arm64/configs/gki_defconfig
  341. fi
  342. - name: Change Kernel Name
  343. run: |
  344. cd "$CONFIG"
  345. if [ -f "build/build.sh" ]; then
  346. perl -pi -e 's/-dirty//' ./common/scripts/setlocalversion
  347. perl -0777 -pi -e 's/(.*)(echo "\$res")/$1echo "\$res-Next-v\$KSUVER-SUSFS-v1.5.9-Wild"/s' ./common/scripts/setlocalversion
  348. 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
  349. else
  350. #Remove -maybe-dirty
  351. perl -pi -e 's/-maybe-dirty//g' ./build/kernel/kleaf/impl/stamp.bzl
  352. #Set Kernel Name
  353. echo "CONFIG_LOCALVERSION=\"-NEXT-v$KSUVER-SUSFS-v1.5.9-Wild\"" >> ./common/arch/arm64/configs/gki_defconfig
  354. #Set Kernel Timestamp
  355. 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
  356. #Remove Abi Exports and Error
  357. rm -rf ./common/android/abi_gki_protected_exports_*
  358. perl -pi -e 's/^\s*"protected_exports_list"\s*:\s*"android\/abi_gki_protected_exports_aarch64",\s*$//;' ./common/BUILD.bazel
  359. fi
  360. - name: Build
  361. run : |
  362. set -e
  363. set -x
  364. cd "$CONFIG"
  365. echo "Building the kernel..."
  366. if [ -f "build/build.sh" ]; then
  367. LTO=thin BUILD_CONFIG=common/build.config.gki.aarch64 build/build.sh CC="/usr/bin/ccache clang" || exit 1
  368. else
  369. tools/bazel build --disk_cache=/home/runner/.cache/bazel --config=fast --lto=thin //common:kernel_aarch64_dist || exit 1
  370. fi
  371. ccache --show-stats
  372. - name: Create Bootimgs Folder and Copy Images for Android 12/13
  373. if: ${{ inputs.android_version == 'android12' || inputs.android_version == 'android13' }}
  374. run: |
  375. mkdir bootimgs
  376. echo "Creating bootimgs folder and copying images..."
  377. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image ./bootimgs
  378. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image.lz4 ./bootimgs
  379. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image ./
  380. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image.lz4 ./
  381. # Create gzip of the Image file
  382. gzip -n -k -f -9 ./Image > ./Image.gz
  383. - name: Create Bootimgs Folder and Copy Images for Android 14/15
  384. if: ${{ inputs.android_version == 'android14' || inputs.android_version == 'android15' }}
  385. run: |
  386. mkdir bootimgs
  387. echo "Creating bootimgs folder and copying images..."
  388. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image ./bootimgs
  389. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image.lz4 ./bootimgs
  390. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image ./
  391. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image.lz4 ./
  392. # Create gzip of the Image file
  393. gzip -n -k -f -9 ./Image > ./Image.gz
  394. - name: Create ZIP Files for Different Formats
  395. run: |
  396. echo "Creating zip files for all formats..."
  397. cd ./AnyKernel3
  398. # Create and upload zip for each format
  399. ZIP_NAME="${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-AnyKernel3.zip"
  400. echo "Creating zip file: $ZIP_NAME..."
  401. mv ../Image ./Image
  402. zip -r "../$ZIP_NAME" ./*
  403. rm ./Image
  404. ZIP_NAME="${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-AnyKernel3-lz4.zip"
  405. echo "Creating zip file: $ZIP_NAME..."
  406. mv ../Image.lz4 ./Image.lz4
  407. zip -r "../$ZIP_NAME" ./*
  408. rm ./Image.lz4
  409. ZIP_NAME="${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-AnyKernel3-gz.zip"
  410. echo "Creating zip file: $ZIP_NAME..."
  411. mv ../Image.gz ./Image.gz
  412. zip -r "../$ZIP_NAME" ./*
  413. rm ./Image.gz
  414. - name: Android 12 boot image build script
  415. if: ${{ inputs.android_version == 'android12' }}
  416. run: |
  417. echo "Changing to configuration directory: $CONFIG..."
  418. cd bootimgs
  419. GKI_URL=https://dl.google.com/android/gki/gki-certified-boot-android12-5.10-"${{ inputs.os_patch_level }}"_"${{ inputs.revision }}".zip
  420. FALLBACK_URL=https://dl.google.com/android/gki/gki-certified-boot-android12-5.10-2023-01_r1.zip
  421. # Check if the GKI URL is available
  422. echo "Checking if GKI kernel URL is reachable: $GKI_URL"
  423. status=$(curl -sL -w "%{http_code}" "$GKI_URL" -o /dev/null)
  424. if [ "$status" = "200" ]; then
  425. echo "[+] Downloading from GKI_URL"
  426. curl -Lo gki-kernel.zip "$GKI_URL"
  427. else
  428. echo "[+] $GKI_URL not found, using $FALLBACK_URL"
  429. curl -Lo gki-kernel.zip "$FALLBACK_URL"
  430. fi
  431. # Unzip the downloaded kernel and remove the zip
  432. echo "Unzipping the downloaded kernel..."
  433. unzip gki-kernel.zip && rm gki-kernel.zip
  434. echo "Unpacking boot.img..."
  435. FULL_PATH=$(pwd)/boot-5.10.img
  436. echo "Unpacking using: $FULL_PATH"
  437. echo "Running unpack_bootimg.py..."
  438. $UNPACK_BOOTIMG --boot_img="$FULL_PATH"
  439. # Create gzip of the Image file
  440. gzip -n -k -f -9 ./Image > ./Image.gz
  441. echo "Building boot.img"
  442. $MKBOOTIMG --header_version 4 --kernel Image --output boot.img --ramdisk out/ramdisk --os_version 12.0.0 --os_patch_level "${{ inputs.os_patch_level }}"
  443. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  444. cp ./boot.img ../${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot.img
  445. echo "Building boot-gz.img"
  446. $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 }}"
  447. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-gz.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  448. cp ./boot-gz.img ../${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot-gz.img
  449. echo "Building boot-lz4.img"
  450. $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 }}"
  451. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-lz4.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  452. cp ./boot-lz4.img ../${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot-lz4.img
  453. - name: Android 13/14/15 boot image build script
  454. if: ${{ inputs.android_version == 'android13' || inputs.android_version == 'android14' || inputs.android_version == 'android15' }}
  455. run: |
  456. cd bootimgs
  457. # Create gzip of the Image file
  458. gzip -n -k -f -9 ./Image > ./Image.gz
  459. echo "Building boot.img"
  460. $MKBOOTIMG --header_version 4 --kernel Image --output boot.img
  461. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  462. cp ./boot.img ../${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot.img
  463. echo "Building boot-gz.img"
  464. $MKBOOTIMG --header_version 4 --kernel Image.gz --output boot-gz.img
  465. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-gz.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  466. cp ./boot-gz.img ../${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot-gz.img
  467. echo "Building boot-lz4.img"
  468. $MKBOOTIMG --header_version 4 --kernel Image.lz4 --output boot-lz4.img
  469. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-lz4.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  470. cp ./boot-lz4.img ../${{ inputs.kernelsu_variant }}-$KSUVER-${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot-lz4.img
  471. - name: Compress all img files with gzip
  472. run: |
  473. for image in *.img; do
  474. gzip -vnf9 "$image"
  475. done
  476. - name: Upload Build Artifacts
  477. uses: actions/upload-artifact@v4
  478. with:
  479. name: ${{ inputs.kernelsu_variant }}-kernel-${{ env.CONFIG }}
  480. path: |
  481. *.zip
  482. *.img.gz
  483. *Image*