build-kernel-a13-5.10.yml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. name: Build Android 13 5.10 GKI Kernels
  2. on:
  3. workflow_call: # This allows this workflow to be called from another workflow
  4. jobs:
  5. build-kernel-a13-5-10-kernelsu-susfs:
  6. runs-on: ubuntu-22.04
  7. strategy:
  8. matrix:
  9. include:
  10. - android_version: "android13"
  11. kernel_version: "5.10"
  12. sub_level: "189"
  13. os_patch_level: "2023-11"
  14. - android_version: "android13"
  15. kernel_version: "5.10"
  16. sub_level: "198"
  17. os_patch_level: "2024-01"
  18. - android_version: "android13"
  19. kernel_version: "5.10"
  20. sub_level: "205"
  21. os_patch_level: "2024-03"
  22. - android_version: "android13"
  23. kernel_version: "5.10"
  24. sub_level: "209"
  25. os_patch_level: "2024-05"
  26. - android_version: "android13"
  27. kernel_version: "5.10"
  28. sub_level: "210"
  29. os_patch_level: "2024-06"
  30. - android_version: "android13"
  31. kernel_version: "5.10"
  32. sub_level: "214"
  33. os_patch_level: "2024-07"
  34. - android_version: "android13"
  35. kernel_version: "5.10"
  36. sub_level: "218"
  37. os_patch_level: "2024-08"
  38. - android_version: "android13"
  39. kernel_version: "5.10"
  40. sub_level: "X"
  41. os_patch_level: "lts"
  42. steps:
  43. - name: Maximize build space
  44. uses: easimon/maximize-build-space@master
  45. with:
  46. root-reserve-mb: 8192
  47. temp-reserve-mb: 2048
  48. remove-dotnet: 'true'
  49. remove-android: 'true'
  50. remove-haskell: 'true'
  51. remove-codeql: 'true'
  52. - name: Set CONFIG Environment Variable
  53. run: |
  54. # Set CONFIG dynamically based on matrix values
  55. CONFIG="${{ matrix.android_version }}-${{ matrix.kernel_version }}-${{ matrix.sub_level }}"
  56. # Set CONFIG as an environment variable for future steps
  57. echo "CONFIG=$CONFIG" >> $GITHUB_ENV
  58. echo "CONFIG set to: $CONFIG"
  59. - name: Download prebuilt toolchain
  60. run: |
  61. AOSP_MIRROR=https://android.googlesource.com
  62. BRANCH=main-kernel-build-2024
  63. git clone $AOSP_MIRROR/kernel/prebuilts/build-tools -b $BRANCH --depth 1 kernel-build-tools
  64. git clone $AOSP_MIRROR/platform/system/tools/mkbootimg -b $BRANCH --depth 1 mkbootimg
  65. echo "AVBTOOL=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/bin/avbtool" >> $GITHUB_ENV
  66. echo "MKBOOTIMG=$GITHUB_WORKSPACE/mkbootimg/mkbootimg.py" >> $GITHUB_ENV
  67. echo "UNPACK_BOOTIMG=$GITHUB_WORKSPACE/mkbootimg/unpack_bootimg.py" >> $GITHUB_ENV
  68. - name: Set boot sign key
  69. env:
  70. BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }}
  71. run: |
  72. if [ ! -z "$BOOT_SIGN_KEY" ]; then
  73. echo "$BOOT_SIGN_KEY" > ./kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem
  74. echo "BOOT_SIGN_KEY_PATH=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem" >> $GITHUB_ENV
  75. else
  76. echo "BOOT_SIGN_KEY is not set. Exiting..."
  77. exit 1
  78. fi
  79. - name: Install Repo
  80. run: |
  81. # Install dependencies
  82. mkdir -p ./git-repo
  83. curl https://storage.googleapis.com/git-repo-downloads/repo > ./git-repo/repo
  84. chmod a+rx ./git-repo/repo
  85. echo "REPO=$GITHUB_WORKSPACE/./git-repo/repo" >> $GITHUB_ENV
  86. - name: Clone AnyKernel3 and Other Dependencies
  87. run: |
  88. echo "Cloning AnyKernel3 and other dependencies..."
  89. # Define the branch names using the matrix values
  90. ANYKERNEL_BRANCH="${{ matrix.android_version }}-${{ matrix.kernel_version }}"
  91. SUSFS_BRANCH="gki-${{ matrix.android_version }}-${{ matrix.kernel_version }}"
  92. # Debug print the branches
  93. echo "Using branch for AnyKernel3: $ANYKERNEL_BRANCH"
  94. echo "Using branch for SUSFS: $SUSFS_BRANCH"
  95. # Clone repositories using the branch names
  96. git clone https://github.com/TheWildJames/AnyKernel3.git -b "$ANYKERNEL_BRANCH"
  97. git clone https://gitlab.com/simonpunk/susfs4ksu.git -b "$SUSFS_BRANCH"
  98. git clone https://github.com/TheWildJames/kernel_patches.git
  99. - name: Initialize and Sync Kernel Source
  100. run: |
  101. echo "Creating folder for configuration: $CONFIG..."
  102. mkdir -p "$CONFIG"
  103. cd "$CONFIG"
  104. # Initialize and sync kernel source
  105. echo "Initializing and syncing kernel source..."
  106. FORMATTED_BRANCH="${{ matrix.android_version }}-${{ matrix.kernel_version }}-${{ matrix.os_patch_level: }}"
  107. $REPO init --depth=1 --u https://android.googlesource.com/kernel/manifest -b common-${FORMATTED_BRANCH} --repo-rev=v2.16
  108. REMOTE_BRANCH=$(git ls-remote https://android.googlesource.com/kernel/common ${FORMATTED_BRANCH})
  109. DEFAULT_MANIFEST_PATH=.repo/manifests/default.xml
  110. # Check if branch is deprecated
  111. if grep -q deprecated <<< $REMOTE_BRANCH; then
  112. echo "Found deprecated branch: $FORMATTED_BRANCH"
  113. sed -i "s/\"${FORMATTED_BRANCH}\"/\"deprecated\/${FORMATTED_BRANCH}\"/g" $DEFAULT_MANIFEST_PATH
  114. fi
  115. # Sync repo and apply patches
  116. $REPO --version
  117. $REPO --trace sync -c -j$(nproc --all) --no-tags --fail-fast
  118. - name: Add KernelSU
  119. run: |
  120. echo "Changing to configuration directory: $CONFIG..."
  121. cd "$CONFIG"
  122. echo "Adding KernelSU..."
  123. curl -LSs "https://raw.githubusercontent.com/rifsxd/KernelSU-Next/next/kernel/setup.sh" | bash -
  124. - name: Apply SUSFS Patches
  125. run: |
  126. echo "Changing to configuration directory: $CONFIG..."
  127. cd "$CONFIG"
  128. echo "Applying SUSFS patches..."
  129. # Copy SUSFS patches
  130. cp ../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./KernelSU-Next/
  131. cp ../susfs4ksu/kernel_patches/50_add_susfs_in_gki-${{ matrix.android_version }}-${{ matrix.kernel_version }}.patch ./common/
  132. cp ../susfs4ksu/kernel_patches/fs/* ./common/fs/
  133. cp ../susfs4ksu/kernel_patches/include/linux/* ./common/include/linux/
  134. cd ./KernelSU-Next
  135. # Apply SUSFS patch for KernelSU
  136. patch -p1 --forward < 10_enable_susfs_for_ksu.patch || true
  137. # Change to common directory and apply SUSFS patch
  138. cd ../common
  139. patch -p1 < 50_add_susfs_in_gki-${{ matrix.android_version }}-${{ matrix.kernel_version }}.patch || true
  140. - name: Apply Next-SUSFS Patches
  141. run: |
  142. echo "Changing to configuration directory: $CONFIG..."
  143. cd "$CONFIG"
  144. echo "Applying next SUSFS patches..."
  145. cp ../kernel_patches/apk_sign.c_fix.patch ./
  146. patch -p1 -F 3 < apk_sign.c_fix.patch
  147. cp ../kernel_patches/core_hook.c_fix.patch ./
  148. patch -p1 --fuzz=3 < core_hook.c_fix.patch
  149. cp ../kernel_patches/selinux.c_fix.patch ./
  150. patch -p1 -F 3 < selinux.c_fix.patch
  151. - name: Apply Hide Stuff Patches
  152. run: |
  153. echo "Changing to configuration directory: $CONFIG..."
  154. cd "$CONFIG/common"
  155. # Apply additional patch
  156. cp ../../kernel_patches/69_hide_stuff.patch ./
  157. patch -p1 -F 3 < 69_hide_stuff.patch || true
  158. - name: Add SUSFS Configuration Settings
  159. run: |
  160. echo "Changing to configuration directory: $CONFIG..."
  161. cd "$CONFIG"
  162. echo "Adding configuration settings to gki_defconfig..."
  163. # Add SUSFS configuration settings
  164. echo "CONFIG_KSU=y" >> ./common/arch/arm64/configs/gki_defconfig
  165. echo "CONFIG_KSU_SUSFS=y" >> ./common/arch/arm64/configs/gki_defconfig
  166. echo "CONFIG_KSU_SUSFS_HAS_MAGIC_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  167. echo "CONFIG_KSU_SUSFS_SUS_PATH=y" >> ./common/arch/arm64/configs/gki_defconfig
  168. echo "CONFIG_KSU_SUSFS_SUS_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  169. echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  170. echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  171. echo "CONFIG_KSU_SUSFS_SUS_KSTAT=y" >> ./common/arch/arm64/configs/gki_defconfig
  172. echo "CONFIG_KSU_SUSFS_SUS_OVERLAYFS=y" >> ./common/arch/arm64/configs/gki_defconfig
  173. echo "CONFIG_KSU_SUSFS_TRY_UMOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  174. echo "CONFIG_KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  175. echo "CONFIG_KSU_SUSFS_SPOOF_UNAME=y" >> ./common/arch/arm64/configs/gki_defconfig
  176. echo "CONFIG_KSU_SUSFS_ENABLE_LOG=y" >> ./common/arch/arm64/configs/gki_defconfig
  177. echo "CONFIG_KSU_SUSFS_HIDE_KSU_SUSFS_SYMBOLS=y" >> ./common/arch/arm64/configs/gki_defconfig
  178. echo "CONFIG_KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG=y" >> ./common/arch/arm64/configs/gki_defconfig
  179. echo "CONFIG_KSU_SUSFS_OPEN_REDIRECT=y" >> ./common/arch/arm64/configs/gki_defconfig
  180. echo "CONFIG_KSU_SUSFS_SUS_SU=y" >> ./common/arch/arm64/configs/gki_defconfig
  181. # Add additional tmpfs config setting
  182. echo "CONFIG_TMPFS_XATTR=y" >> ./common/arch/arm64/configs/gki_defconfig
  183. - name: Run sed and perl Commands
  184. run: |
  185. echo "Changing to configuration directory: $CONFIG..."
  186. cd "$CONFIG"
  187. echo "Running sed commands..."
  188. # Run sed commands for modifications
  189. sed -i 's/check_defconfig//' ./common/build.config.gki
  190. sed -i 's/-dirty//' ./common/scripts/setlocalversion
  191. sed -i '$s|echo "\$res"|echo "\$res-Wild+"|' ./common/scripts/setlocalversion
  192. # Run perl command to modify UTS_VERSION
  193. 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
  194. - name: Build the Kernel
  195. run: |
  196. echo "Changing to configuration directory: $CONFIG..."
  197. cd "$CONFIG"
  198. echo "Building the kernel..."
  199. LTO=thin BUILD_CONFIG=common/build.config.gki.aarch64 build/build.sh
  200. - name: Create Bootimgs Folder and Copy Images
  201. run: |
  202. echo "Changing to configuration directory: $CONFIG..."
  203. mkdir bootimgs
  204. echo "Creating bootimgs folder and copying images..."
  205. cp ./$CONFIG/out/${{ matrix.android_version }}-${{ matrix.kernel_version }}/dist/Image ./bootimgs
  206. cp ./$CONFIG/out/${{ matrix.android_version }}-${{ matrix.kernel_version }}/dist/Image.lz4 ./bootimgs
  207. cp ./$CONFIG/out/${{ matrix.android_version }}-${{ matrix.kernel_version }}/dist/Image ./
  208. cp ./$CONFIG/out/${{ matrix.android_version }}-${{ matrix.kernel_version }}/dist/Image.lz4 ./
  209. # Create gzip of the Image file
  210. gzip -n -k -f -9 ./Image > ./Image.gz
  211. - name: Unpack boot.img and Build Kernels
  212. run: |
  213. cd bootimgs
  214. echo "Building Image.gz"
  215. gzip -n -k -f -9 ./Image > ./Image.gz
  216. echo "Building boot.img"
  217. $MKBOOTIMG --header_version 4 --kernel Image --output boot.img
  218. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  219. cp ./boot.img ../${{ matrix.android_version }}-${{ matrix.kernel_version }}.${{ matrix.sub_level }}_${{ matrix.os_patch_level }}-boot.img
  220. echo "Building boot-gz.img"
  221. $MKBOOTIMG --header_version 4 --kernel Image.gz --output boot-gz.img
  222. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-gz.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  223. cp ./boot-gz.img ../${{ matrix.android_version }}-${{ matrix.kernel_version }}.${{ matrix.sub_level }}_${{ matrix.os_patch_level }}-boot-gz.img
  224. echo "Building boot-lz4.img"
  225. $MKBOOTIMG --header_version 4 --kernel Image.lz4 --output boot-lz4.img
  226. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-lz4.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  227. cp ./boot-lz4.img ../${{ matrix.android_version }}-${{ matrix.kernel_version }}.${{ matrix.sub_level }}_${{ matrix.os_patch_level }}-boot-lz4.img
  228. - name: Create ZIP Files for Different Formats
  229. run: |
  230. echo "Creating zip files for all formats..."
  231. cd ./AnyKernel3
  232. # Create and upload zip for each format
  233. ZIP_NAME="AnyKernel3-${{ matrix.android_version }}-${{ matrix.kernel_version }}.${{ matrix.sub_level }}_${{ matrix.os_patch_level }}.zip"
  234. echo "Creating zip file: $ZIP_NAME..."
  235. mv ../Image ./Image
  236. zip -r "../$ZIP_NAME" ./*
  237. rm ./Image
  238. ZIP_NAME="AnyKernel3-lz4-${{ matrix.android_version }}-${{ matrix.kernel_version }}.${{ matrix.sub_level }}_${{ matrix.os_patch_level }}.zip"
  239. echo "Creating zip file: $ZIP_NAME..."
  240. mv ../Image.lz4 ./Image.lz4
  241. zip -r "../$ZIP_NAME" ./*
  242. rm ./Image.lz4
  243. ZIP_NAME="AnyKernel3-gz-${{ matrix.android_version }}-${{ matrix.kernel_version }}.${{ matrix.sub_level }}_${{ matrix.os_patch_level }}.zip"
  244. echo "Creating zip file: $ZIP_NAME..."
  245. mv ../Image.gz ./Image.gz
  246. zip -r "../$ZIP_NAME" ./*
  247. rm ./Image.gz
  248. - name: Upload Build Artifacts
  249. uses: actions/upload-artifact@v4
  250. with:
  251. name: kernel-${{ env.CONFIG }}
  252. path: |
  253. *.zip
  254. *.img