build-kernel-a13.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. name: Build Android 13 GKI Kernels
  2. on:
  3. workflow_call: # This allows this workflow to be called from another workflow
  4. jobs:
  5. build-kernel-a13-kernelsu-susfs:
  6. runs-on: ubuntu-latest
  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. #"android13-5.10-189-2023-11"
  47. #"android13-5.10-198-2024-01"
  48. #"android13-5.10-205-2024-03"
  49. #"android13-5.10-209-2024-05"
  50. #"android13-5.10-210-2024-06"
  51. #"android13-5.10-214-2024-07"
  52. #"android13-5.10-218-2024-08"
  53. #"android13-5.10-223-2024-11"
  54. #"android13-5.10-X-lts"
  55. "android13-5.15-94-2023-05"
  56. #"android13-5.15-123-2023-11"
  57. #"android13-5.15-137-2024-01"
  58. #"android13-5.15-144-2024-03"
  59. #"android13-5.15-148-2024-05"
  60. #"android13-5.15-149-2024-07"
  61. #"android13-5.15-151-2024-08"
  62. #"android13-5.15-167-2024-11"
  63. #"android13-5.15-X-lts"
  64. )
  65. for CONFIG in "${BUILD_CONFIGS[@]}"; do
  66. CONFIG_DETAILS=${CONFIG}
  67. # Create directory and proceed with your steps
  68. echo "Creating folder for configuration: $CONFIG..."
  69. mkdir -p "$CONFIG"
  70. cd "$CONFIG"
  71. IFS="-" read -r ANDROID_VERSION KERNEL_VERSION SUB_LEVEL DATE <<< "$CONFIG_DETAILS"
  72. FORMATTED_BRANCH="${ANDROID_VERSION}-${KERNEL_VERSION}-${DATE}"
  73. # Git clone
  74. echo "Cloning AnyKernel3 and other dependencies..."
  75. git clone https://github.com/TheWildJames/AnyKernel3.git -b "${ANDROID_VERSION}-${KERNEL_VERSION}"
  76. git clone https://gitlab.com/simonpunk/susfs4ksu.git -b "gki-${ANDROID_VERSION}-${KERNEL_VERSION}"
  77. git clone https://github.com/TheWildJames/kernel_patches.git
  78. echo "Creating folder for configuration: $CONFIG..."
  79. mkdir -p "$CONFIG"
  80. cd "$CONFIG"
  81. # Initialize and sync kernel source
  82. echo "Initializing and syncing kernel source..."
  83. repo init --depth=1 --u https://android.googlesource.com/kernel/manifest -b common-${FORMATTED_BRANCH} --repo-rev=v2.16
  84. REMOTE_BRANCH=$(git ls-remote https://android.googlesource.com/kernel/common ${FORMATTED_BRANCH})
  85. DEFAULT_MANIFEST_PATH=.repo/manifests/default.xml
  86. # Check if branch is deprecated
  87. if grep -q deprecated <<< $REMOTE_BRANCH; then
  88. echo "Found deprecated branch: $FORMATTED_BRANCH"
  89. sed -i "s/\"${FORMATTED_BRANCH}\"/\"deprecated\/${FORMATTED_BRANCH}\"/g" $DEFAULT_MANIFEST_PATH
  90. fi
  91. # Sync repo and apply patches
  92. repo --version
  93. repo --trace sync -c -j$(nproc --all) --no-tags --fail-fast
  94. # Add KernelSU, SUSFS patches, and build the kernel
  95. echo "Adding KernelSU..."
  96. curl -LSs "https://raw.githubusercontent.com/rifsxd/KernelSU-Next/next/kernel/setup.sh" | bash -
  97. #cd ./KernelSU-Next/kernel
  98. #sed -i 's/ccflags-y += -DKSU_VERSION=16/ccflags-y += -DKSU_VERSION=12000/' ./Makefile
  99. #cd ../../
  100. echo "Applying SUSFS patches..."
  101. cp ../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./KernelSU-Next/
  102. cp ../susfs4ksu/kernel_patches/50_add_susfs_in_gki-${ANDROID_VERSION}-${KERNEL_VERSION}.patch ./common/
  103. cp ../susfs4ksu/kernel_patches/fs/* ./common/fs/
  104. cp ../susfs4ksu/kernel_patches/include/linux/* ./common/include/linux/
  105. # Apply patches
  106. cd ./KernelSU-Next
  107. patch -p1 --forward < 10_enable_susfs_for_ksu.patch || true
  108. cd ../common
  109. patch -p1 < 50_add_susfs_in_gki-${ANDROID_VERSION}-${KERNEL_VERSION}.patch || true
  110. cp ../../kernel_patches/69_hide_stuff.patch ./
  111. patch -p1 -F 3 < 69_hide_stuff.patch
  112. cd ..
  113. cp ../kernel_patches/apk_sign.c_fix.patch ./
  114. patch -p1 -F 3 < apk_sign.c_fix.patch
  115. cp ../kernel_patches/core_hook.c_fix.patch ./
  116. patch -p1 --fuzz=3 < ./core_hook.c_fix.patch
  117. cp ../kernel_patches/selinux.c_fix.patch ./
  118. patch -p1 -F 3 < selinux.c_fix.patch
  119. # Add configuration settings for SUSFS
  120. echo "Adding configuration settings to gki_defconfig..."
  121. echo "CONFIG_KSU=y" >> ./common/arch/arm64/configs/gki_defconfig
  122. echo "CONFIG_KSU_SUSFS=y" >> ./common/arch/arm64/configs/gki_defconfig
  123. echo "CONFIG_KSU_SUSFS_HAS_MAGIC_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  124. echo "CONFIG_KSU_SUSFS_SUS_PATH=y" >> ./common/arch/arm64/configs/gki_defconfig
  125. echo "CONFIG_KSU_SUSFS_SUS_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  126. echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  127. echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  128. echo "CONFIG_KSU_SUSFS_SUS_KSTAT=y" >> ./common/arch/arm64/configs/gki_defconfig
  129. echo "CONFIG_KSU_SUSFS_SUS_OVERLAYFS=y" >> ./common/arch/arm64/configs/gki_defconfig
  130. echo "CONFIG_KSU_SUSFS_TRY_UMOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  131. echo "CONFIG_KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  132. echo "CONFIG_KSU_SUSFS_SPOOF_UNAME=y" >> ./common/arch/arm64/configs/gki_defconfig
  133. echo "CONFIG_KSU_SUSFS_ENABLE_LOG=y" >> ./common/arch/arm64/configs/gki_defconfig
  134. echo "CONFIG_KSU_SUSFS_HIDE_KSU_SUSFS_SYMBOLS=y" >> ./common/arch/arm64/configs/gki_defconfig
  135. echo "CONFIG_KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG=y" >> ./common/arch/arm64/configs/gki_defconfig
  136. echo "CONFIG_KSU_SUSFS_OPEN_REDIRECT=y" >> ./common/arch/arm64/configs/gki_defconfig
  137. echo "CONFIG_KSU_SUSFS_SUS_SU=y" >> ./common/arch/arm64/configs/gki_defconfig
  138. echo "CONFIG_TMPFS_XATTR=y" >> ./common/arch/arm64/configs/gki_defconfig
  139. if [ ! -e build/build.sh ]; then
  140. GLIBC_VERSION=$(ldd --version 2>/dev/null | head -n 1 | awk '{print $NF}')
  141. echo "GLIBC_VERSION: $GLIBC_VERSION"
  142. if [ "$(printf '%s\n' "2.38" "$GLIBC_VERSION" | sort -V | head -n1)" = "2.38" ]; then
  143. echo "Patching resolve_btfids/Makefile"
  144. sed -i '/\$(Q)\$(MAKE) -C \$(SUBCMD_SRC) OUTPUT=\$(abspath \$(dir \$@))\/ \$(abspath \$@)/s//$(Q)$(MAKE) -C $(SUBCMD_SRC) EXTRA_CFLAGS="$(CFLAGS)" OUTPUT=$(abspath $(dir $@))\/ $(abspath $@)/' \
  145. $GKI_ROOT/common/tools/bpf/resolve_btfids/Makefile || echo "No patch needed."
  146. fi
  147. fi
  148. # Run sed commands
  149. echo "Running sed commands..."
  150. sed -i 's/check_defconfig//' ./common/build.config.gki
  151. sed -i 's/dirty//' ./common/scripts/setlocalversion
  152. sed -i '$s|echo "\$res"|echo "\$res-Wild+"|' ./common/scripts/setlocalversion
  153. 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
  154. # Build the kernel
  155. LTO=thin BUILD_CONFIG=common/build.config.gki.aarch64 build/build.sh
  156. # Create bootimgs folder and copy images
  157. echo "Creating bootimgs folder and copying images..."
  158. mkdir bootimgs
  159. cp ./out/${ANDROID_VERSION}-${KERNEL_VERSION}/dist/Image ./bootimgs
  160. cp ./out/${ANDROID_VERSION}-${KERNEL_VERSION}/dist/Image.lz4 ./bootimgs
  161. cp ./out/${ANDROID_VERSION}-${KERNEL_VERSION}/dist/Image ../
  162. cp ./out/${ANDROID_VERSION}-${KERNEL_VERSION}/dist/Image.lz4 ../
  163. gzip -n -k -f -9 ../Image >../Image.gz
  164. cd ./bootimgs
  165. echo 'Building Image.gz'
  166. gzip -n -k -f -9 Image >Image.gz
  167. echo 'Building boot.img'
  168. $MKBOOTIMG --header_version 4 --kernel Image --output boot.img
  169. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  170. cp ./boot.img ../../../${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}-boot.img
  171. echo 'Building boot-gz.img'
  172. $MKBOOTIMG --header_version 4 --kernel Image.gz --output boot-gz.img
  173. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-gz.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  174. cp ./boot-gz.img ../../../${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}-boot-gz.img
  175. echo 'Building boot-lz4.img'
  176. $MKBOOTIMG --header_version 4 --kernel Image.lz4 --output boot-lz4.img
  177. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-lz4.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  178. cp ./boot-lz4.img ../../../${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}-boot-lz4.img
  179. cd ..
  180. # Create zip for different formats and place them in the same folder as images
  181. echo "Creating zip files for all formats..."
  182. cd ../AnyKernel3
  183. ZIP_NAME="AnyKernel3-${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}.zip"
  184. echo "Creating zip file: $ZIP_NAME..."
  185. mv ../Image ./Image
  186. zip -r "../../$ZIP_NAME" ./*
  187. rm ./Image
  188. ZIP_NAME="AnyKernel3-lz4-${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}.zip"
  189. echo "Creating zip file: $ZIP_NAME..."
  190. mv ../Image.lz4 ./Image.lz4
  191. zip -r "../../$ZIP_NAME" ./*
  192. rm ./Image.lz4
  193. ZIP_NAME="AnyKernel3-gz-${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}.zip"
  194. echo "Creating zip file: $ZIP_NAME..."
  195. mv ../Image.gz ./Image.gz
  196. zip -r "../../$ZIP_NAME" ./*
  197. rm ./Image.gz
  198. cd ../../
  199. # Delete the $CONFIG folder after building
  200. echo "Deleting $CONFIG folder..."
  201. rm -rf "$CONFIG"
  202. done
  203. - name: Upload build artifacts
  204. uses: actions/upload-artifact@v4
  205. with:
  206. name: kernel-artifacts-a13
  207. path: |
  208. *.zip
  209. *.img