build-kernel-a12-5.10.yml 15 KB

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