build.yml 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. name: Build Script
  2. permissions:
  3. contents: write
  4. actions: write
  5. on:
  6. workflow_call:
  7. inputs:
  8. android_version:
  9. required: true
  10. type: string
  11. kernel_version:
  12. required: true
  13. type: string
  14. sub_level:
  15. required: true
  16. type: string
  17. os_patch_level:
  18. required: true
  19. type: string
  20. kernelsu_variant:
  21. required: true
  22. type: string
  23. kernelsu_branch:
  24. required: true
  25. type: string
  26. kernelsu_branch_other:
  27. required: false
  28. type: string
  29. revision:
  30. required: false
  31. type: string
  32. jobs:
  33. build-gki:
  34. runs-on: ubuntu-latest
  35. timeout-minutes: 120
  36. env:
  37. CCACHE_COMPILERCHECK: "%compiler% -dumpmachine; %compiler% -dumpversion"
  38. CCACHE_NOHASHDIR: "true"
  39. CCACHE_HARDLINK: "true"
  40. steps:
  41. - name: Maximize build space
  42. uses: easimon/maximize-build-space@master
  43. with:
  44. root-reserve-mb: 8192
  45. temp-reserve-mb: 2048
  46. swap-size-mb: 8192
  47. remove-dotnet: "true"
  48. remove-android: "true"
  49. remove-haskell: "true"
  50. remove-codeql: "true"
  51. - name: Set CONFIG Environment Variable
  52. run: |
  53. # Set CONFIG dynamically based on inputs values
  54. CONFIG="${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.sub_level }}"
  55. # Set CONFIG as an environment variable for future steps
  56. echo "CONFIG=$CONFIG" >> $GITHUB_ENV
  57. echo "CONFIG set to: $CONFIG"
  58. - name: Install ccache
  59. run: sudo apt update && sudo apt install -y ccache
  60. - name: Set up ccache
  61. run: |
  62. mkdir -p ~/.cache/bazel
  63. ccache --version
  64. ccache --max-size=2G
  65. ccache --set-config=compression=true
  66. echo "CCACHE_DIR=$HOME/.ccache" >> $GITHUB_ENV
  67. - name: Restore ccache from cache
  68. uses: actions/cache@v4
  69. with:
  70. path: ~/.ccache
  71. key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.sub_level }}-ccache-${{ github.sha }}
  72. restore-keys: |
  73. ${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.sub_level }}-ccache-
  74. - name: Cache toolchain
  75. id: cache-toolchain
  76. uses: actions/cache@v4
  77. with:
  78. path: |
  79. kernel-build-tools
  80. mkbootimg
  81. key: toolchain-${{ runner.os }}-v1
  82. - name: Download toolchain (if cache not found)
  83. if: steps.cache-toolchain.outputs.cache-hit != 'true'
  84. run: |
  85. AOSP_MIRROR=https://android.googlesource.com
  86. BRANCH=main-kernel-build-2024
  87. git clone $AOSP_MIRROR/kernel/prebuilts/build-tools -b $BRANCH --depth 1 kernel-build-tools
  88. git clone $AOSP_MIRROR/platform/system/tools/mkbootimg -b $BRANCH --depth 1 mkbootimg
  89. - name: Set environment variables
  90. run: |
  91. echo "AVBTOOL=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/bin/avbtool" >> $GITHUB_ENV
  92. echo "MKBOOTIMG=$GITHUB_WORKSPACE/mkbootimg/mkbootimg.py" >> $GITHUB_ENV
  93. echo "UNPACK_BOOTIMG=$GITHUB_WORKSPACE/mkbootimg/unpack_bootimg.py" >> $GITHUB_ENV
  94. - name: Set boot sign key
  95. env:
  96. BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }}
  97. run: |
  98. if [ ! -z "$BOOT_SIGN_KEY" ]; then
  99. echo "$BOOT_SIGN_KEY" > ./kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem
  100. echo "BOOT_SIGN_KEY_PATH=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem" >> $GITHUB_ENV
  101. else
  102. echo "BOOT_SIGN_KEY is not set. Exiting..."
  103. exit 1
  104. fi
  105. - name: Install Repo
  106. run: |
  107. mkdir -p ./git-repo
  108. echo "Downloading repo tool..."
  109. curl https://storage.googleapis.com/git-repo-downloads/repo > ./git-repo/repo
  110. chmod a+rx ./git-repo/repo
  111. echo "REPO=$GITHUB_WORKSPACE/./git-repo/repo" >> $GITHUB_ENV
  112. - name: Clone AnyKernel3 and Other Dependencies
  113. run: |
  114. echo "Cloning AnyKernel3 and other dependencies..."
  115. ANYKERNEL_BRANCH="gki-2.0"
  116. SUSFS_BRANCH="gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}"
  117. echo "Using branch for AnyKernel3: $ANYKERNEL_BRANCH"
  118. echo "Using branch for SUSFS: $SUSFS_BRANCH"
  119. git clone https://github.com/WildPlusKernel/AnyKernel3.git -b "$ANYKERNEL_BRANCH"
  120. git clone https://gitlab.com/simonpunk/susfs4ksu.git -b "$SUSFS_BRANCH"
  121. git clone https://github.com/WildPlusKernel/kernel_patches.git
  122. - name: Check Disk Space Before Sync
  123. run: |
  124. echo "Disk space before kernel source sync:"
  125. df -h
  126. - name: Initialize and Sync Kernel Source
  127. run: |
  128. echo "Creating folder for configuration: $CONFIG..."
  129. mkdir -p "$CONFIG"
  130. cd "$CONFIG"
  131. echo "Initializing and syncing kernel source..."
  132. FORMATTED_BRANCH="${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.os_patch_level }}"
  133. $REPO init --depth=1 --u https://android.googlesource.com/kernel/manifest -b common-${FORMATTED_BRANCH} --repo-rev=v2.16
  134. REMOTE_BRANCH=$(git ls-remote https://android.googlesource.com/kernel/common ${FORMATTED_BRANCH})
  135. DEFAULT_MANIFEST_PATH=.repo/manifests/default.xml
  136. if grep -q deprecated <<< $REMOTE_BRANCH; then
  137. echo "Found deprecated branch: $FORMATTED_BRANCH"
  138. sed -i "s/\"${FORMATTED_BRANCH}\"/\"deprecated\/${FORMATTED_BRANCH}\"/g" $DEFAULT_MANIFEST_PATH
  139. fi
  140. $REPO --version
  141. $REPO --trace sync -c -j$(nproc --all) --no-tags --fail-fast
  142. - name: Determine the branch for KernelSU
  143. run: |
  144. case "${{ inputs.kernelsu_branch }}" in
  145. "Stable")
  146. echo "BRANCH=-" >> $GITHUB_ENV
  147. ;;
  148. "Dev")
  149. if [[ "${{ inputs.kernelsu_variant }}" =~ ^(KSU|MKSU)$ ]]; then
  150. echo "BRANCH=-s main" >> $GITHUB_ENV
  151. elif [[ "${{ inputs.kernelsu_variant }}" == "KSU_NEXT" ]]; then
  152. echo "BRANCH=-s next" >> $GITHUB_ENV
  153. fi
  154. ;;
  155. "Other")
  156. if [[ -n "${{ inputs.kernelsu_branch_other }}" ]]; then
  157. echo "BRANCH=-s ${{ inputs.kernelsu_branch_other }}" >> $GITHUB_ENV
  158. else
  159. echo "Error: Custom branch not provided for 'Other'" >&2
  160. exit 1
  161. fi
  162. ;;
  163. esac
  164. - name: Add KernelSU
  165. run: |
  166. echo "Changing to configuration directory: $CONFIG..."
  167. cd "$CONFIG"
  168. case "${{ inputs.kernelsu_variant }}" in
  169. "KSU")
  170. echo "Adding KernelSU Official..."
  171. curl -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash ${{ env.BRANCH }}
  172. ;;
  173. "KSU_NEXT")
  174. echo "Adding KernelSU Next..."
  175. curl -LSs "https://raw.githubusercontent.com/KernelSU-Next/KernelSU-Next/next/kernel/setup.sh" | bash ${{ env.BRANCH }}
  176. ;;
  177. "MKSU")
  178. echo "Adding KernelSU MKSU..."
  179. curl -LSs "https://raw.githubusercontent.com/5ec1cff/KernelSU/main/kernel/setup.sh" | bash ${{ env.BRANCH }}
  180. ;;
  181. esac
  182. - name: Apply SUSFS Patches for KernelSU Variants
  183. run: |
  184. echo "Changing to configuration directory: $CONFIG..."
  185. cd "$CONFIG"
  186. echo "Applying SUSFS patches..."
  187. # Copy SUSFS patches
  188. cp ../susfs4ksu/kernel_patches/50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch ./common/
  189. cp ../susfs4ksu/kernel_patches/fs/* ./common/fs/
  190. cp ../susfs4ksu/kernel_patches/include/linux/* ./common/include/linux/
  191. case "${{ inputs.kernelsu_variant }}" in
  192. "KSU")
  193. echo "Applying SUSFS patches for Official KernelSU..."
  194. cd ./KernelSU
  195. cp ../../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./
  196. patch -p1 --forward --fuzz=3 < 10_enable_susfs_for_ksu.patch
  197. ;;
  198. "KSU_NEXT")
  199. echo "Applying SUSFS patches for KernelSU Next..."
  200. cd ./KernelSU-Next
  201. cp ../../kernel_patches/next/kernel-patch-susfs-v1.5.7-to-KernelSU-Next.patch ./
  202. patch -p1 --forward --fuzz=3 < kernel-patch-susfs-v1.5.7-to-KernelSU-Next.patch
  203. ;;
  204. "MKSU")
  205. echo "Applying SUSFS patches for MKSU..."
  206. cd ./KernelSU
  207. cp ../../kernel_patches/next/kernel-patch-susfs-v1.5.7-to-KernelSU-Next.patch ./
  208. patch -p1 --forward --fuzz=3 < kernel-patch-susfs-v1.5.7-to-KernelSU-Next.patch
  209. ;;
  210. esac
  211. cd ../common
  212. patch -p1 --fuzz=3 < 50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch || true
  213. - name: Apply Hooks Patches
  214. run: |
  215. echo "Changing to configuration directory: $CONFIG..."
  216. cd "$CONFIG/common"
  217. if [ "${{ inputs.kernelsu_variant }}" == "KSU_NEXT" ]; then
  218. echo "Applying hooks for KernelSU-Next..."
  219. cp ../../kernel_patches/next/syscall_hooks.patch ./
  220. patch -p1 -F 3 < syscall_hooks.patch
  221. #elif [ "${{ inputs.kernelsu_variant }}" == "MKSU" ]; then
  222. # echo "Applying hooks for MKSU..."
  223. # cp ../../kernel_patches/hooks/ksu_hooks.patch ./
  224. # patch -p1 -F 3 < ksu_hooks.patch
  225. fi
  226. - name: Apply Hide Stuff Patches
  227. run: |
  228. echo "Changing to configuration directory: $CONFIG..."
  229. cd "$CONFIG/common"
  230. cp ../../kernel_patches/69_hide_stuff.patch ./
  231. patch -p1 -F 3 < 69_hide_stuff.patch
  232. - name: Add All Managers
  233. if: ${{ inputs.kernelsu_variant == 'ALL' }}
  234. run: |
  235. cd "$CONFIG"
  236. case "${{ inputs.kernelsu_variant }}" in
  237. "KSU")
  238. echo "Applying Manager patch for Official KernelSU..."
  239. #cp ../kernel_patches/ksu/manager.patch ./
  240. ;;
  241. "KSU_NEXT")
  242. echo "Applying Manager patch for KernelSU Next..."
  243. cp ../kernel_patches/next/manager.patch ./
  244. ;;
  245. "MKSU")
  246. echo "Applying Manager patch for MKSU..."
  247. #cp ../kernel_patches/mksu/manager.patch .//
  248. ;;
  249. esac
  250. patch -p1 --fuzz=3 < manager.patch
  251. if [ "${{ inputs.include_susfs }}" = "true" ]; then
  252. cp ../kernel_patches/next/apk_sign.c_fix.patch ./
  253. patch -p1 --fuzz=3 < apk_sign.c_fix.patch
  254. else
  255. cp ../kernel_patches/no-susfs_apk_sign.c_fix.patch ./
  256. patch -p1 --fuzz=3 < no-susfs_apk_sign.c_fix.patch
  257. fi
  258. - name: Add Configuration Settings
  259. run: |
  260. echo "Changing to configuration directory: $CONFIG..."
  261. cd "$CONFIG"
  262. echo "Adding configuration settings to gki_defconfig..."
  263. # Add KSU configuration settings
  264. echo "CONFIG_KSU=y" >> ./common/arch/arm64/configs/gki_defconfig
  265. if [ "${{ inputs.kernelsu_variant }}" == "KSU_NEXT" ]; then
  266. echo "CONFIG_KSU_WITH_KPROBES=n" >> ./common/arch/arm64/configs/gki_defconfig
  267. fi
  268. # Add additional tmpfs config setting
  269. echo "CONFIG_TMPFS_XATTR=y" >> ./common/arch/arm64/configs/gki_defconfig
  270. echo "CONFIG_TMPFS_POSIX_ACL=y" >> ./common/arch/arm64/configs/gki_defconfig
  271. # Add additional config setting
  272. echo "CONFIG_IP_NF_TARGET_TTL=y" >> ./common/arch/arm64/configs/gki_defconfig
  273. echo "CONFIG_IP6_NF_TARGET_HL=y" >> ./common/arch/arm64/configs/gki_defconfig
  274. echo "CONFIG_IP6_NF_MATCH_HL=y" >> ./common/arch/arm64/configs/gki_defconfig
  275. # Add BBR Config
  276. echo "CONFIG_TCP_CONG_ADVANCED=y" >> ./common/arch/arm64/configs/gki_defconfig
  277. echo "CONFIG_TCP_CONG_BBR=y" >> ./common/arch/arm64/configs/gki_defconfig
  278. echo "CONFIG_NET_SCH_FQ=y" >> ./common/arch/arm64/configs/gki_defconfig
  279. echo "CONFIG_TCP_CONG_BIC=n" >> ./common/arch/arm64/configs/gki_defconfig
  280. echo "CONFIG_TCP_CONG_WESTWOOD=n" >> ./common/arch/arm64/configs/gki_defconfig
  281. echo "CONFIG_TCP_CONG_HTCP=n" >> ./common/arch/arm64/configs/gki_defconfig
  282. # Remove check_defconfig
  283. sed -i 's/check_defconfig//' ./common/build.config.gki
  284. - name: Add SUSFS Configuration Settings
  285. run: |
  286. echo "Changing to configuration directory: $CONFIG..."
  287. cd "$CONFIG"
  288. # Add SUSFS configuration settings
  289. echo "CONFIG_KSU_SUSFS=y" >> ./common/arch/arm64/configs/gki_defconfig
  290. echo "CONFIG_KSU_SUSFS_HAS_MAGIC_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  291. echo "CONFIG_KSU_SUSFS_SUS_PATH=y" >> ./common/arch/arm64/configs/gki_defconfig
  292. echo "CONFIG_KSU_SUSFS_SUS_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  293. echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  294. echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  295. echo "CONFIG_KSU_SUSFS_SUS_KSTAT=y" >> ./common/arch/arm64/configs/gki_defconfig
  296. echo "CONFIG_KSU_SUSFS_SUS_OVERLAYFS=n" >> ./common/arch/arm64/configs/gki_defconfig
  297. echo "CONFIG_KSU_SUSFS_TRY_UMOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  298. echo "CONFIG_KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig
  299. echo "CONFIG_KSU_SUSFS_SPOOF_UNAME=y" >> ./common/arch/arm64/configs/gki_defconfig
  300. echo "CONFIG_KSU_SUSFS_ENABLE_LOG=y" >> ./common/arch/arm64/configs/gki_defconfig
  301. echo "CONFIG_KSU_SUSFS_HIDE_KSU_SUSFS_SYMBOLS=y" >> ./common/arch/arm64/configs/gki_defconfig
  302. echo "CONFIG_KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG=y" >> ./common/arch/arm64/configs/gki_defconfig
  303. echo "CONFIG_KSU_SUSFS_OPEN_REDIRECT=y" >> ./common/arch/arm64/configs/gki_defconfig
  304. if [ "${{ inputs.kernelsu_variant }}" == "KSU_NEXT" ]; then
  305. echo "CONFIG_KSU_SUSFS_SUS_SU=n" >> ./common/arch/arm64/configs/gki_defconfig
  306. else
  307. echo "CONFIG_KSU_SUSFS_SUS_SU=y" >> ./common/arch/arm64/configs/gki_defconfig
  308. fi
  309. - name: Change Kernel Name
  310. run: |
  311. cd "$CONFIG"
  312. # modify UTS_VERSION
  313. 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
  314. sed -i '$s|echo "\$res"|echo "\$res-Wild"|' ./common/scripts/setlocalversion
  315. if [ -f "build/build.sh" ]; then
  316. sed -i 's/-dirty//' ./common/scripts/setlocalversion
  317. else
  318. sed -i '/^[[:space:]]*"protected_exports_list"[[:space:]]*:[[:space:]]*"android\/abi_gki_protected_exports_aarch64",$/d' ./common/BUILD.bazel
  319. rm -rf ./common/android/abi_gki_protected_exports_*
  320. sed -i "/stable_scmversion_cmd/s/-maybe-dirty//g" ./build/kernel/kleaf/impl/stamp.bzl
  321. sed -E -i '/^CONFIG_LOCALVERSION=/ s/(.*)"$/\1-Wild"/' ./common/arch/arm64/configs/gki_defconfig
  322. fi
  323. - name: Build
  324. run : |
  325. set -e
  326. set -x
  327. cd "$CONFIG"
  328. echo "Building the kernel..."
  329. if [ -f "build/build.sh" ]; then
  330. LTO=thin BUILD_CONFIG=common/build.config.gki.aarch64 build/build.sh CC="/usr/bin/ccache clang" || exit 1
  331. else
  332. tools/bazel build --disk_cache=/home/runner/.cache/bazel --config=fast --lto=thin //common:kernel_aarch64_dist || exit 1
  333. fi
  334. ccache --show-stats
  335. - name: Create Bootimgs Folder and Copy Images for Android 12/13
  336. if: ${{ inputs.android_version == 'android12' || inputs.android_version == 'android13' }}
  337. run: |
  338. mkdir bootimgs
  339. echo "Creating bootimgs folder and copying images..."
  340. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image ./bootimgs
  341. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image.lz4 ./bootimgs
  342. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image ./
  343. cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image.lz4 ./
  344. # Create gzip of the Image file
  345. gzip -n -k -f -9 ./Image > ./Image.gz
  346. - name: Create Bootimgs Folder and Copy Images for Android 14/15
  347. if: ${{ inputs.android_version == 'android14' || inputs.android_version == 'android15' }}
  348. run: |
  349. mkdir bootimgs
  350. echo "Creating bootimgs folder and copying images..."
  351. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image ./bootimgs
  352. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image.lz4 ./bootimgs
  353. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image ./
  354. cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image.lz4 ./
  355. # Create gzip of the Image file
  356. gzip -n -k -f -9 ./Image > ./Image.gz
  357. - name: Create ZIP Files for Different Formats
  358. run: |
  359. echo "Creating zip files for all formats..."
  360. cd ./AnyKernel3
  361. # Create and upload zip for each format
  362. ZIP_NAME="${{ inputs.kernelsu_variant }}_${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-AnyKernel3.zip"
  363. echo "Creating zip file: $ZIP_NAME..."
  364. mv ../Image ./Image
  365. zip -r "../$ZIP_NAME" ./*
  366. rm ./Image
  367. ZIP_NAME="${{ inputs.kernelsu_variant }}_${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-AnyKernel3-lz4.zip"
  368. echo "Creating zip file: $ZIP_NAME..."
  369. mv ../Image.lz4 ./Image.lz4
  370. zip -r "../$ZIP_NAME" ./*
  371. rm ./Image.lz4
  372. ZIP_NAME="${{ inputs.kernelsu_variant }}_${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-AnyKernel3-gz.zip"
  373. echo "Creating zip file: $ZIP_NAME..."
  374. mv ../Image.gz ./Image.gz
  375. zip -r "../$ZIP_NAME" ./*
  376. rm ./Image.gz
  377. - name: Android 12 boot image build script
  378. if: ${{ inputs.android_version == 'android12' }}
  379. run: |
  380. echo "Changing to configuration directory: $CONFIG..."
  381. cd bootimgs
  382. GKI_URL=https://dl.google.com/android/gki/gki-certified-boot-android12-5.10-"${{ inputs.os_patch_level }}"_"${{ inputs.revision }}".zip
  383. FALLBACK_URL=https://dl.google.com/android/gki/gki-certified-boot-android12-5.10-2023-01_r1.zip
  384. # Check if the GKI URL is available
  385. echo "Checking if GKI kernel URL is reachable: $GKI_URL"
  386. status=$(curl -sL -w "%{http_code}" "$GKI_URL" -o /dev/null)
  387. if [ "$status" = "200" ]; then
  388. echo "[+] Downloading from GKI_URL"
  389. curl -Lo gki-kernel.zip "$GKI_URL"
  390. else
  391. echo "[+] $GKI_URL not found, using $FALLBACK_URL"
  392. curl -Lo gki-kernel.zip "$FALLBACK_URL"
  393. fi
  394. # Unzip the downloaded kernel and remove the zip
  395. echo "Unzipping the downloaded kernel..."
  396. unzip gki-kernel.zip && rm gki-kernel.zip
  397. echo "Unpacking boot.img..."
  398. FULL_PATH=$(pwd)/boot-5.10.img
  399. echo "Unpacking using: $FULL_PATH"
  400. echo "Running unpack_bootimg.py..."
  401. $UNPACK_BOOTIMG --boot_img="$FULL_PATH"
  402. # Create gzip of the Image file
  403. gzip -n -k -f -9 ./Image > ./Image.gz
  404. echo "Building boot.img"
  405. $MKBOOTIMG --header_version 4 --kernel Image --output boot.img --ramdisk out/ramdisk --os_version 12.0.0 --os_patch_level "${{ inputs.os_patch_level }}"
  406. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  407. cp ./boot.img ../${{ inputs.kernelsu_variant }}_${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot.img
  408. echo "Building boot-gz.img"
  409. $MKBOOTIMG --header_version 4 --kernel Image.gz --output boot-gz.img --ramdisk out/ramdisk --os_version 12.0.0 --os_patch_level "${{ inputs.os_patch_level }}"
  410. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-gz.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  411. cp ./boot-gz.img ../${{ inputs.kernelsu_variant }}_${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot-gz.img
  412. echo "Building boot-lz4.img"
  413. $MKBOOTIMG --header_version 4 --kernel Image.lz4 --output boot-lz4.img --ramdisk out/ramdisk --os_version 12.0.0 --os_patch_level "${{ inputs.os_patch_level }}"
  414. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-lz4.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  415. cp ./boot-lz4.img ../${{ inputs.kernelsu_variant }}_${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot-lz4.img
  416. - name: Android 13/14/15 boot image build script
  417. if: ${{ inputs.android_version == 'android13' || inputs.android_version == 'android14' || inputs.android_version == 'android15' }}
  418. run: |
  419. cd bootimgs
  420. # Create gzip of the Image file
  421. gzip -n -k -f -9 ./Image > ./Image.gz
  422. echo "Building boot.img"
  423. $MKBOOTIMG --header_version 4 --kernel Image --output boot.img
  424. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  425. cp ./boot.img ../${{ inputs.kernelsu_variant }}_${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot.img
  426. echo "Building boot-gz.img"
  427. $MKBOOTIMG --header_version 4 --kernel Image.gz --output boot-gz.img
  428. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-gz.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  429. cp ./boot-gz.img ../${{ inputs.kernelsu_variant }}_${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot-gz.img
  430. echo "Building boot-lz4.img"
  431. $MKBOOTIMG --header_version 4 --kernel Image.lz4 --output boot-lz4.img
  432. $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-lz4.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH
  433. cp ./boot-lz4.img ../${{ inputs.kernelsu_variant }}_${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot-lz4.img
  434. echo "Transfering kernel files"
  435. cp ./Image ../${{ inputs.kernelsu_variant }}_${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-Image
  436. cp ./Image.gz ../${{ inputs.kernelsu_variant }}_${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-Image.gz
  437. cp ./Image.lz4 ../${{ inputs.kernelsu_variant }}_${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-Image.lz4
  438. - name: Compress all img files with gzip
  439. run: |
  440. for image in *.img; do
  441. gzip -vnf9 "$image"
  442. done
  443. - name: Upload Build Artifacts
  444. uses: actions/upload-artifact@v4
  445. with:
  446. name: ${{ inputs.kernelsu_variant }}_kernel-${{ env.CONFIG }}
  447. path: |
  448. *.zip
  449. *.img.gz
  450. *Image*