gki-kernel.yml 23 KB

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