build-kernel-a14-5.15.yml 14 KB

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