build-kernel-a13-5.15.yml 15 KB

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