gki-kernel.yml 23 KB

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