build-kernel-a14.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. name: Build Android 14 GKI Kernels
  2. on:
  3. workflow_call: # This allows this workflow to be called from another workflow
  4. jobs:
  5. build-kernel-a14-kernelsu-susfs:
  6. runs-on: ubuntu-22.04
  7. timeout-minutes: 2160 # Set maximum timeout
  8. steps:
  9. - name: Maximize build space
  10. uses: easimon/maximize-build-space@master
  11. with:
  12. root-reserve-mb: 8192
  13. temp-reserve-mb: 2048
  14. remove-dotnet: 'true'
  15. remove-android: 'true'
  16. remove-haskell: 'true'
  17. remove-codeql: 'true'
  18. - name: Download prebuilt toolchain
  19. run: |
  20. AOSP_MIRROR=https://android.googlesource.com
  21. BRANCH=main-kernel-build-2024
  22. git clone $AOSP_MIRROR/kernel/prebuilts/build-tools -b $BRANCH --depth 1 kernel-build-tools
  23. git clone $AOSP_MIRROR/platform/system/tools/mkbootimg -b $BRANCH --depth 1 mkbootimg
  24. echo "AVBTOOL=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/bin/avbtool" >> $GITHUB_ENV
  25. echo "MKBOOTIMG=$GITHUB_WORKSPACE/mkbootimg/mkbootimg.py" >> $GITHUB_ENV
  26. echo "UNPACK_BOOTIMG=$GITHUB_WORKSPACE/mkbootimg/unpack_bootimg.py" >> $GITHUB_ENV
  27. - name: Set boot sign key
  28. env:
  29. BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }}
  30. run: |
  31. if [ ! -z "$BOOT_SIGN_KEY" ]; then
  32. echo "$BOOT_SIGN_KEY" > ./kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem
  33. echo "BOOT_SIGN_KEY_PATH=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem" >> $GITHUB_ENV
  34. else
  35. echo "BOOT_SIGN_KEY is not set. Exiting..."
  36. exit 1
  37. fi
  38. - name: Install Dependencies
  39. run: |
  40. # Install dependencies
  41. sudo apt update
  42. sudo apt install -y lz4 gzip repo perl
  43. - name: Build for all configurations
  44. run: |
  45. BUILD_CONFIGS=(
  46. #"android14-5.15-131-2023-11"
  47. #"android14-5.15-137-2024-01"
  48. #"android14-5.15-144-2024-03"
  49. #"android14-5.15-148-2024-05"
  50. #"android14-5.15-149-2024-06"
  51. #"android14-5.15-153-2024-07"
  52. #"android14-5.15-158-2024-08"
  53. #"android14-5.15-167-2024-11"
  54. #"android14-5.15-X-lts"
  55. "android14-6.1-25-2023-10"
  56. #"android14-6.1-43-2023-11"
  57. #"android14-6.1-57-2024-01"
  58. #"android14-6.1-68-2024-03"
  59. #"android14-6.1-75-2024-05"
  60. #"android14-6.1-78-2024-06"
  61. #"android14-6.1-84-2024-07"
  62. #"android14-6.1-90-2024-08"
  63. #"android14-6.1-112-2024-11"
  64. #"android14-6.1-115-2024-12"
  65. #"android14-6.1-X-lts"
  66. )
  67. for CONFIG in "${BUILD_CONFIGS[@]}"; do
  68. CONFIG_DETAILS=${CONFIG}
  69. # Create directory and proceed with your steps
  70. echo "Creating folder for configuration: $CONFIG..."
  71. mkdir -p "$CONFIG"
  72. cd "$CONFIG"
  73. IFS="-" read -r ANDROID_VERSION KERNEL_VERSION SUB_LEVEL DATE <<< "$CONFIG_DETAILS"
  74. FORMATTED_BRANCH="${ANDROID_VERSION}-${KERNEL_VERSION}-${DATE}"
  75. # Git clone
  76. echo "Cloning AnyKernel3 and other dependencies..."
  77. git clone https://github.com/TheWildJames/AnyKernel3.git -b "${ANDROID_VERSION}-${KERNEL_VERSION}"
  78. git clone https://gitlab.com/simonpunk/susfs4ksu.git -b "gki-${ANDROID_VERSION}-${KERNEL_VERSION}"
  79. git clone https://github.com/TheWildJames/kernel_patches.git
  80. echo "Creating folder for configuration: $CONFIG..."
  81. mkdir -p "$CONFIG"
  82. cd "$CONFIG"
  83. # Initialize and sync kernel source
  84. echo "Initializing and syncing kernel source..."
  85. repo init --depth=1 --u https://android.googlesource.com/kernel/manifest -b common-${FORMATTED_BRANCH} --repo-rev=v2.16
  86. REMOTE_BRANCH=$(git ls-remote https://android.googlesource.com/kernel/common ${FORMATTED_BRANCH})
  87. DEFAULT_MANIFEST_PATH=.repo/manifests/default.xml
  88. # Check if branch is deprecated
  89. if grep -q deprecated <<< $REMOTE_BRANCH; then
  90. echo "Found deprecated branch: $FORMATTED_BRANCH"
  91. sed -i "s/\"${FORMATTED_BRANCH}\"/\"deprecated\/${FORMATTED_BRANCH}\"/g" $DEFAULT_MANIFEST_PATH
  92. fi
  93. # Sync repo and apply patches
  94. repo --version
  95. repo --trace sync -c -j$(nproc --all) --no-tags --fail-fast
  96. # Add KernelSU, SUSFS patches, and build the kernel
  97. echo "Adding KernelSU..."
  98. curl -LSs "https://raw.githubusercontent.com/rifsxd/KernelSU-Next/next/kernel/setup.sh" | bash -
  99. #cd ./KernelSU-Next/kernel
  100. #sed -i 's/ccflags-y += -DKSU_VERSION=16/ccflags-y += -DKSU_VERSION=12000/' ./Makefile
  101. #cd ../../
  102. echo "Applying SUSFS patches..."
  103. cp ../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./KernelSU-Next/
  104. cp ../susfs4ksu/kernel_patches/50_add_susfs_in_gki-${ANDROID_VERSION}-${KERNEL_VERSION}.patch ./common/
  105. cp ../susfs4ksu/kernel_patches/fs/* ./common/fs/
  106. cp ../susfs4ksu/kernel_patches/include/linux/* ./common/include/linux/
  107. # Apply patches
  108. cd ./KernelSU-Next
  109. patch -p1 --forward < 10_enable_susfs_for_ksu.patch || true
  110. cd ../common
  111. patch -p1 < 50_add_susfs_in_gki-${ANDROID_VERSION}-${KERNEL_VERSION}.patch || true
  112. cp ../../kernel_patches/69_hide_stuff.patch ./
  113. patch -p1 -F 3 < 69_hide_stuff.patch
  114. cd ..
  115. cp ../kernel_patches/apk_sign.c_fix.patch ./
  116. patch -p1 -F 3 < apk_sign.c_fix.patch
  117. cp ../kernel_patches/core_hook.c_fix.patch ./
  118. patch -p1 --fuzz=3 < ./core_hook.c_fix.patch
  119. cp ../kernel_patches/selinux.c_fix.patch ./
  120. patch -p1 -F 3 < selinux.c_fix.patch
  121. # Add configuration settings for SUSFS
  122. echo "Adding configuration settings to gki_defconfig..."
  123. echo "CONFIG_KSU=y" >> ./common/arch/arm64/configs/gki_defconfig
  124. echo "CONFIG_KSU_SUSFS=y" >> ./common/arch/arm64/configs/gki_defconfig
  125. echo "CONFIG_KSU_SUSFS_HAS_MAGIC_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  126. echo "CONFIG_KSU_SUSFS_SUS_PATH=y" >> ./common/arch/arm64/configs/gki_defconfig
  127. echo "CONFIG_KSU_SUSFS_SUS_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  128. echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  129. echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  130. echo "CONFIG_KSU_SUSFS_SUS_KSTAT=y" >> ./common/arch/arm64/configs/gki_defconfig
  131. echo "CONFIG_KSU_SUSFS_SUS_OVERLAYFS=y" >> ./common/arch/arm64/configs/gki_defconfig
  132. echo "CONFIG_KSU_SUSFS_TRY_UMOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  133. echo "CONFIG_KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  134. echo "CONFIG_KSU_SUSFS_SPOOF_UNAME=y" >> ./common/arch/arm64/configs/gki_defconfig
  135. echo "CONFIG_KSU_SUSFS_ENABLE_LOG=y" >> ./common/arch/arm64/configs/gki_defconfig
  136. echo "CONFIG_KSU_SUSFS_HIDE_KSU_SUSFS_SYMBOLS=y" >> ./common/arch/arm64/configs/gki_defconfig
  137. echo "CONFIG_KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG=y" >> ./common/arch/arm64/configs/gki_defconfig
  138. echo "CONFIG_KSU_SUSFS_OPEN_REDIRECT=y" >> ./common/arch/arm64/configs/gki_defconfig
  139. echo "CONFIG_KSU_SUSFS_SUS_SU=y" >> ./common/arch/arm64/configs/gki_defconfig
  140. echo "CONFIG_TMPFS_XATTR=y" >> ./common/arch/arm64/configs/gki_defconfig
  141. # Build the kernel using Bazel
  142. echo "Building kernel..."
  143. sed -i '$s|echo "\$res"|echo "\$res-Wild+"|' ./common/scripts/setlocalversion
  144. sed -i "/stable_scmversion_cmd/s/-maybe-dirty//g" ./build/kernel/kleaf/impl/stamp.bzl
  145. sed -i '2s/check_defconfig//' ./common/build.config.gki
  146. perl -pi -e 's{UTS_VERSION="\$\(echo \$UTS_VERSION \$CONFIG_FLAGS \$TIMESTAMP \| cut -b -\$UTS_LEN\)"}{UTS_VERSION="#1 SMP PREEMPT Sat Apr 20 04:20:00 UTC 2024"}' ./common/scripts/mkcompile_h
  147. rm -rf ./common/android/abi_gki_protected_exports_aarch64
  148. rm -rf ./common/android/abi_gki_protected_exports_x86_64
  149. tools/bazel build --config=fast --lto=thin //common:kernel_aarch64_dist
  150. # Create boot images
  151. echo "Creating boot images..."
  152. mkdir -p bootimgs
  153. cp ./bazel-bin/common/kernel_aarch64/Image ./bootimgs
  154. cp ./bazel-bin/common/kernel_aarch64/Image.lz4 ./bootimgs
  155. cp ./bazel-bin/common/kernel_aarch64/Image ../
  156. cp ./bazel-bin/common/kernel_aarch64/Image.lz4 ../
  157. gzip -n -k -f -9 ../Image >../Image.gz
  158. cd ./bootimgs
  159. echo 'Building Image.gz'
  160. gzip -n -k -f -9 Image >Image.gz
  161. $MKBOOTIMG --header_version 4 --kernel Image --output boot.img
  162. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  163. cp ./boot.img ../../../${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}-boot.img
  164. $MKBOOTIMG --header_version 4 --kernel Image.gz --output boot-gz.img
  165. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-gz.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  166. cp ./boot-gz.img ../../../${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}-boot-gz.img
  167. $MKBOOTIMG --header_version 4 --kernel Image.lz4 --output boot-lz4.img
  168. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-lz4.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  169. cp ./boot-lz4.img ../../../${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}-boot-lz4.img
  170. cd ..
  171. # Create AnyKernel3 ZIP files
  172. echo "Creating AnyKernel3 ZIP files..."
  173. cd ../AnyKernel3
  174. # Creating ZIPs for kernel images
  175. ZIP_NAME="AnyKernel3-${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}.zip"
  176. mv ../Image ./Image
  177. zip -r "../../$ZIP_NAME" ./*
  178. rm ./Image
  179. ZIP_NAME="AnyKernel3-lz4-${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}.zip"
  180. mv ../Image.lz4 ./Image.lz4
  181. zip -r "../../$ZIP_NAME" ./*
  182. rm ./Image.lz4
  183. ZIP_NAME="AnyKernel3-gz-${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}.zip"
  184. mv ../Image.gz ./Image.gz
  185. zip -r "../../$ZIP_NAME" ./*
  186. rm ./Image.gz
  187. # Go back to the original directory
  188. cd ../../
  189. # Delete the $CONFIG folder after building
  190. echo "Deleting $CONFIG folder..."
  191. rm -rf "$CONFIG"
  192. done
  193. - name: Upload build artifacts
  194. uses: actions/upload-artifact@v4
  195. with:
  196. name: kernel-artifacts-a14
  197. path: |
  198. *.zip
  199. *.img