build-kernel-a13-5.15.yml 14 KB

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