build-kernel-a12.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. name: Build Android 12 GKI Kernels
  2. on:
  3. workflow_call: # This allows this workflow to be called from another workflow
  4. jobs:
  5. build-kernel-a12-kernelsu-susfs:
  6. runs-on: ubuntu-22.04
  7. timeout-minutes: 2160 # Set maximum timeout
  8. steps:
  9. - name: Maximize build space
  10. uses: easimon/maximize-build-space@master
  11. with:
  12. root-reserve-mb: 8192
  13. temp-reserve-mb: 2048
  14. remove-dotnet: 'true'
  15. remove-android: 'true'
  16. remove-haskell: 'true'
  17. remove-codeql: 'true'
  18. - name: Download prebuilt toolchain
  19. run: |
  20. AOSP_MIRROR=https://android.googlesource.com
  21. BRANCH=main-kernel-build-2024
  22. git clone $AOSP_MIRROR/kernel/prebuilts/build-tools -b $BRANCH --depth 1 kernel-build-tools
  23. git clone $AOSP_MIRROR/platform/system/tools/mkbootimg -b $BRANCH --depth 1 mkbootimg
  24. echo "AVBTOOL=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/bin/avbtool" >> $GITHUB_ENV
  25. echo "MKBOOTIMG=$GITHUB_WORKSPACE/mkbootimg/mkbootimg.py" >> $GITHUB_ENV
  26. echo "UNPACK_BOOTIMG=$GITHUB_WORKSPACE/mkbootimg/unpack_bootimg.py" >> $GITHUB_ENV
  27. - name: Set boot sign key
  28. env:
  29. BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }}
  30. run: |
  31. if [ ! -z "$BOOT_SIGN_KEY" ]; then
  32. echo "$BOOT_SIGN_KEY" > ./kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem
  33. echo "BOOT_SIGN_KEY_PATH=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem" >> $GITHUB_ENV
  34. else
  35. echo "BOOT_SIGN_KEY is not set. Exiting..."
  36. exit 1
  37. fi
  38. - name: Install Dependencies
  39. run: |
  40. # Install dependencies
  41. sudo apt update
  42. sudo apt install -y lz4 gzip repo perl
  43. - name: Build for all configurations
  44. run: |
  45. BUILD_CONFIGS=(
  46. "android12-5.10-198-2024-01"
  47. "android12-5.10-205-2024-03"
  48. "android12-5.10-209-2024-05"
  49. "android12-5.10-218-2024-08"
  50. "android12-5.10-226-2024-11"
  51. "android12-5.10-X-lts"
  52. )
  53. for CONFIG in "${BUILD_CONFIGS[@]}"; do
  54. CONFIG_DETAILS=${CONFIG}
  55. # Create directory and proceed with your steps
  56. echo "Creating folder for configuration: $CONFIG..."
  57. mkdir -p "$CONFIG"
  58. cd "$CONFIG"
  59. IFS="-" read -r ANDROID_VERSION KERNEL_VERSION SUB_LEVEL DATE <<< "$CONFIG_DETAILS"
  60. FORMATTED_BRANCH="${ANDROID_VERSION}-${KERNEL_VERSION}-${DATE}"
  61. # Git clone
  62. echo "Cloning AnyKernel3 and other dependencies..."
  63. git clone https://github.com/TheWildJames/AnyKernel3.git -b "${ANDROID_VERSION}-${KERNEL_VERSION}"
  64. git clone https://gitlab.com/simonpunk/susfs4ksu.git -b "gki-${ANDROID_VERSION}-${KERNEL_VERSION}"
  65. git clone https://github.com/TheWildJames/kernel_patches.git
  66. echo "Creating folder for configuration: $CONFIG..."
  67. mkdir -p "$CONFIG"
  68. cd "$CONFIG"
  69. # Initialize and sync kernel source
  70. echo "Initializing and syncing kernel source..."
  71. repo init --depth=1 --u https://android.googlesource.com/kernel/manifest -b common-${FORMATTED_BRANCH} --repo-rev=v2.16
  72. REMOTE_BRANCH=$(git ls-remote https://android.googlesource.com/kernel/common ${FORMATTED_BRANCH})
  73. DEFAULT_MANIFEST_PATH=.repo/manifests/default.xml
  74. # Check if branch is deprecated
  75. if grep -q deprecated <<< $REMOTE_BRANCH; then
  76. echo "Found deprecated branch: $FORMATTED_BRANCH"
  77. sed -i "s/\"${FORMATTED_BRANCH}\"/\"deprecated\/${FORMATTED_BRANCH}\"/g" $DEFAULT_MANIFEST_PATH
  78. fi
  79. # Sync repo and apply patches
  80. repo --version
  81. repo --trace sync -c -j$(nproc --all) --no-tags --fail-fast
  82. # Add KernelSU, SUSFS patches, and build the kernel
  83. echo "Adding KernelSU..."
  84. curl -LSs "https://raw.githubusercontent.com/rifsxd/KernelSU-Next/next/kernel/setup.sh" | bash -
  85. #cd ./KernelSU-Next/kernel
  86. #sed -i 's/ccflags-y += -DKSU_VERSION=16/ccflags-y += -DKSU_VERSION=12000/' ./Makefile
  87. #cd ../../
  88. echo "Applying SUSFS patches..."
  89. cp ../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./KernelSU-Next/
  90. cp ../susfs4ksu/kernel_patches/50_add_susfs_in_gki-${ANDROID_VERSION}-${KERNEL_VERSION}.patch ./common/
  91. cp ../susfs4ksu/kernel_patches/fs/* ./common/fs/
  92. cp ../susfs4ksu/kernel_patches/include/linux/* ./common/include/linux/
  93. # Apply patches
  94. cd ./KernelSU-Next
  95. patch -p1 --forward < 10_enable_susfs_for_ksu.patch || true
  96. cd ../common
  97. patch -p1 < 50_add_susfs_in_gki-${ANDROID_VERSION}-${KERNEL_VERSION}.patch || true
  98. cp ../../kernel_patches/69_hide_stuff.patch ./
  99. patch -p1 -F 3 < 69_hide_stuff.patch
  100. cd ..
  101. cp ../kernel_patches/apk_sign.c_fix.patch ./
  102. patch -p1 -F 3 < apk_sign.c_fix.patch
  103. cp ../kernel_patches/core_hook.c_fix.patch ./
  104. patch -p1 --fuzz=3 < ./core_hook.c_fix.patch
  105. cp ../kernel_patches/selinux.c_fix.patch ./
  106. patch -p1 -F 3 < selinux.c_fix.patch
  107. # Add configuration settings for SUSFS
  108. echo "Adding configuration settings to gki_defconfig..."
  109. echo "CONFIG_KSU=y" >> ./common/arch/arm64/configs/gki_defconfig
  110. echo "CONFIG_KSU_SUSFS=y" >> ./common/arch/arm64/configs/gki_defconfig
  111. echo "CONFIG_KSU_SUSFS_HAS_MAGIC_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  112. echo "CONFIG_KSU_SUSFS_SUS_PATH=y" >> ./common/arch/arm64/configs/gki_defconfig
  113. echo "CONFIG_KSU_SUSFS_SUS_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  114. echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  115. echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  116. echo "CONFIG_KSU_SUSFS_SUS_KSTAT=y" >> ./common/arch/arm64/configs/gki_defconfig
  117. echo "CONFIG_KSU_SUSFS_SUS_OVERLAYFS=y" >> ./common/arch/arm64/configs/gki_defconfig
  118. echo "CONFIG_KSU_SUSFS_TRY_UMOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  119. echo "CONFIG_KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  120. echo "CONFIG_KSU_SUSFS_SPOOF_UNAME=y" >> ./common/arch/arm64/configs/gki_defconfig
  121. echo "CONFIG_KSU_SUSFS_ENABLE_LOG=y" >> ./common/arch/arm64/configs/gki_defconfig
  122. echo "CONFIG_KSU_SUSFS_HIDE_KSU_SUSFS_SYMBOLS=y" >> ./common/arch/arm64/configs/gki_defconfig
  123. echo "CONFIG_KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG=y" >> ./common/arch/arm64/configs/gki_defconfig
  124. echo "CONFIG_KSU_SUSFS_OPEN_REDIRECT=y" >> ./common/arch/arm64/configs/gki_defconfig
  125. echo "CONFIG_KSU_SUSFS_SUS_SU=y" >> ./common/arch/arm64/configs/gki_defconfig
  126. echo "CONFIG_TMPFS_XATTR=y" >> ./common/arch/arm64/configs/gki_defconfig
  127. # Run sed commands
  128. echo "Running sed commands..."
  129. sed -i 's/check_defconfig//' ./common/build.config.gki
  130. sed -i 's/dirty//' ./common/scripts/setlocalversion
  131. sed -i '$s|echo "\$res"|echo "\$res-Wild+"|' ./common/scripts/setlocalversion
  132. 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
  133. # Build the kernel
  134. LTO=thin BUILD_CONFIG=common/build.config.gki.aarch64 build/build.sh
  135. # Create bootimgs folder and copy images
  136. echo "Creating bootimgs folder and copying images..."
  137. mkdir bootimgs
  138. cp ./out/${ANDROID_VERSION}-${KERNEL_VERSION}/dist/Image ./bootimgs
  139. cp ./out/${ANDROID_VERSION}-${KERNEL_VERSION}/dist/Image.lz4 ./bootimgs
  140. cp ./out/${ANDROID_VERSION}-${KERNEL_VERSION}/dist/Image ../
  141. cp ./out/${ANDROID_VERSION}-${KERNEL_VERSION}/dist/Image.lz4 ../
  142. gzip -n -k -f -9 ../Image >../Image.gz
  143. cd ./bootimgs
  144. # Set the GKI URLs
  145. GKI_URL=https://dl.google.com/android/gki/gki-certified-boot-android12-5.10-"${DATE}"_r1.zip
  146. FALLBACK_URL=https://dl.google.com/android/gki/gki-certified-boot-android12-5.10-2023-01_r1.zip
  147. # Check if the GKI URL is available
  148. echo "Checking if GKI kernel URL is reachable: $GKI_URL"
  149. status=$(curl -sL -w "%{http_code}" "$GKI_URL" -o /dev/null)
  150. if [ "$status" = "200" ]; then
  151. echo "[+] Downloading from GKI_URL"
  152. curl -Lo gki-kernel.zip "$GKI_URL"
  153. else
  154. echo "[+] $GKI_URL not found, using $FALLBACK_URL"
  155. curl -Lo gki-kernel.zip "$FALLBACK_URL"
  156. fi
  157. # Unzip the downloaded kernel and remove the zip
  158. echo "Unzipping the downloaded kernel..."
  159. unzip gki-kernel.zip && rm gki-kernel.zip
  160. # Unpack the boot.img using the absolute path
  161. echo "Unpacking boot.img..."
  162. FULL_PATH=$(pwd)/boot-5.10.img
  163. echo "Unpacking using: $FULL_PATH"
  164. # Run the unpacking tool
  165. echo "Running unpack_bootimg.py..."
  166. $UNPACK_BOOTIMG --boot_img="$FULL_PATH"
  167. echo 'Building Image.gz'
  168. gzip -n -k -f -9 Image >Image.gz
  169. echo 'Building boot.img'
  170. $MKBOOTIMG --header_version 4 --kernel Image --output boot.img --ramdisk out/ramdisk --os_version 12.0.0 --os_patch_level "${DATE}"
  171. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  172. cp ./boot.img ../../../${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}-boot.img
  173. echo 'Building boot-gz.img'
  174. $MKBOOTIMG --header_version 4 --kernel Image.gz --output boot-gz.img --ramdisk out/ramdisk --os_version 12.0.0 --os_patch_level "${DATE}"
  175. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-gz.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  176. cp ./boot-gz.img ../../../${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}-boot-gz.img
  177. echo 'Building boot-lz4.img'
  178. $MKBOOTIMG --header_version 4 --kernel Image.lz4 --output boot-lz4.img --ramdisk out/ramdisk --os_version 12.0.0 --os_patch_level "${DATE}"
  179. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-lz4.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  180. cp ./boot-lz4.img ../../../${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}-boot-lz4.img
  181. cd ..
  182. # Create zip for different formats and place them in the same folder as images
  183. echo "Creating zip files for all formats..."
  184. cd ../AnyKernel3
  185. ZIP_NAME="AnyKernel3-${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}.zip"
  186. echo "Creating zip file: $ZIP_NAME..."
  187. mv ../Image ./Image
  188. zip -r "../../$ZIP_NAME" ./*
  189. rm ./Image
  190. ZIP_NAME="AnyKernel3-lz4-${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}.zip"
  191. echo "Creating zip file: $ZIP_NAME..."
  192. mv ../Image.lz4 ./Image.lz4
  193. zip -r "../../$ZIP_NAME" ./*
  194. rm ./Image.lz4
  195. ZIP_NAME="AnyKernel3-gz-${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}.zip"
  196. echo "Creating zip file: $ZIP_NAME..."
  197. mv ../Image.gz ./Image.gz
  198. zip -r "../../$ZIP_NAME" ./*
  199. rm ./Image.gz
  200. cd ../../
  201. # Delete the $CONFIG folder after building
  202. echo "Deleting $CONFIG folder..."
  203. rm -rf "$CONFIG"
  204. done
  205. - name: Upload build artifacts
  206. uses: actions/upload-artifact@v4
  207. with:
  208. name: kernel-artifacts-a12
  209. path: |
  210. *.zip
  211. *.img