build-kernel-a14-6.1.yml 16 KB

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