build-kernel-a13-5.10.yml 15 KB

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