name: Build Android 13 GKI Kernels on: workflow_call: # This allows this workflow to be called from another workflow jobs: build-kernel-a13-kernelsu-susfs: runs-on: ubuntu-22.04 timeout-minutes: 2160 # Set maximum timeout steps: - name: Maximize build space uses: easimon/maximize-build-space@master with: root-reserve-mb: 8192 temp-reserve-mb: 2048 remove-dotnet: 'true' remove-android: 'true' remove-haskell: 'true' remove-codeql: 'true' - name: Download prebuilt toolchain run: | AOSP_MIRROR=https://android.googlesource.com BRANCH=main-kernel-build-2024 git clone $AOSP_MIRROR/kernel/prebuilts/build-tools -b $BRANCH --depth 1 kernel-build-tools git clone $AOSP_MIRROR/platform/system/tools/mkbootimg -b $BRANCH --depth 1 mkbootimg echo "AVBTOOL=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/bin/avbtool" >> $GITHUB_ENV echo "MKBOOTIMG=$GITHUB_WORKSPACE/mkbootimg/mkbootimg.py" >> $GITHUB_ENV echo "UNPACK_BOOTIMG=$GITHUB_WORKSPACE/mkbootimg/unpack_bootimg.py" >> $GITHUB_ENV - name: Set boot sign key env: BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }} run: | if [ ! -z "$BOOT_SIGN_KEY" ]; then echo "$BOOT_SIGN_KEY" > ./kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem echo "BOOT_SIGN_KEY_PATH=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem" >> $GITHUB_ENV else echo "BOOT_SIGN_KEY is not set. Exiting..." exit 1 fi - name: Install Dependencies run: | # Install dependencies sudo apt update sudo apt install -y lz4 gzip repo perl - name: Build for all configurations run: | BUILD_CONFIGS=( "android13-5.10-189-2023-11" "android13-5.10-198-2024-01" "android13-5.10-205-2024-03" "android13-5.10-209-2024-05" "android13-5.10-210-2024-06" "android13-5.10-214-2024-07" "android13-5.10-218-2024-08" "android13-5.10-223-2024-11" "android13-5.10-X-lts" "android13-5.15-94-2023-05" "android13-5.15-123-2023-11" "android13-5.15-137-2024-01" "android13-5.15-144-2024-03" "android13-5.15-148-2024-05" "android13-5.15-149-2024-07" "android13-5.15-151-2024-08" "android13-5.15-167-2024-11" "android13-5.15-X-lts" ) for CONFIG in "${BUILD_CONFIGS[@]}"; do CONFIG_DETAILS=${CONFIG} # Create directory and proceed with your steps echo "Creating folder for configuration: $CONFIG..." mkdir -p "$CONFIG" cd "$CONFIG" IFS="-" read -r ANDROID_VERSION KERNEL_VERSION SUB_LEVEL DATE <<< "$CONFIG_DETAILS" FORMATTED_BRANCH="${ANDROID_VERSION}-${KERNEL_VERSION}-${DATE}" # Git clone echo "Cloning AnyKernel3 and other dependencies..." git clone https://github.com/TheWildJames/AnyKernel3.git -b "${ANDROID_VERSION}-${KERNEL_VERSION}" git clone https://gitlab.com/simonpunk/susfs4ksu.git -b "gki-${ANDROID_VERSION}-${KERNEL_VERSION}" git clone https://github.com/TheWildJames/kernel_patches.git echo "Creating folder for configuration: $CONFIG..." mkdir -p "$CONFIG" cd "$CONFIG" # Initialize and sync kernel source echo "Initializing and syncing kernel source..." repo init --depth=1 --u https://android.googlesource.com/kernel/manifest -b common-${FORMATTED_BRANCH} --repo-rev=v2.16 REMOTE_BRANCH=$(git ls-remote https://android.googlesource.com/kernel/common ${FORMATTED_BRANCH}) DEFAULT_MANIFEST_PATH=.repo/manifests/default.xml # Check if branch is deprecated if grep -q deprecated <<< $REMOTE_BRANCH; then echo "Found deprecated branch: $FORMATTED_BRANCH" sed -i "s/\"${FORMATTED_BRANCH}\"/\"deprecated\/${FORMATTED_BRANCH}\"/g" $DEFAULT_MANIFEST_PATH fi # Sync repo and apply patches repo --version repo --trace sync -c -j$(nproc --all) --no-tags --fail-fast # Add KernelSU, SUSFS patches, and build the kernel echo "Adding KernelSU..." curl -LSs "https://raw.githubusercontent.com/rifsxd/KernelSU-Next/next/kernel/setup.sh" | bash - #cd ./KernelSU-Next/kernel #sed -i 's/ccflags-y += -DKSU_VERSION=16/ccflags-y += -DKSU_VERSION=12000/' ./Makefile #cd ../../ echo "Applying SUSFS patches..." cp ../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./KernelSU-Next/ cp ../susfs4ksu/kernel_patches/50_add_susfs_in_gki-${ANDROID_VERSION}-${KERNEL_VERSION}.patch ./common/ cp ../susfs4ksu/kernel_patches/fs/* ./common/fs/ cp ../susfs4ksu/kernel_patches/include/linux/* ./common/include/linux/ # Apply patches cd ./KernelSU-Next patch -p1 --forward < 10_enable_susfs_for_ksu.patch || true cd ../common patch -p1 < 50_add_susfs_in_gki-${ANDROID_VERSION}-${KERNEL_VERSION}.patch || true cp ../../kernel_patches/69_hide_stuff.patch ./ patch -p1 -F 3 < 69_hide_stuff.patch cd .. cp ../kernel_patches/apk_sign.c_fix.patch ./ patch -p1 -F 3 < apk_sign.c_fix.patch cp ../kernel_patches/core_hook.c_fix.patch ./ patch -p1 --fuzz=3 < ./core_hook.c_fix.patch cp ../kernel_patches/selinux.c_fix.patch ./ patch -p1 -F 3 < selinux.c_fix.patch # Add configuration settings for SUSFS echo "Adding configuration settings to gki_defconfig..." echo "CONFIG_KSU=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_HAS_MAGIC_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_SUS_PATH=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_SUS_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_SUS_KSTAT=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_SUS_OVERLAYFS=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_TRY_UMOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_SPOOF_UNAME=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_ENABLE_LOG=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_HIDE_KSU_SUSFS_SYMBOLS=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_OPEN_REDIRECT=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_KSU_SUSFS_SUS_SU=y" >> ./common/arch/arm64/configs/gki_defconfig echo "CONFIG_TMPFS_XATTR=y" >> ./common/arch/arm64/configs/gki_defconfig # Run sed commands echo "Running sed commands..." sed -i 's/check_defconfig//' ./common/build.config.gki sed -i 's/dirty//' ./common/scripts/setlocalversion sed -i '$s|echo "\$res"|echo "\$res-Wild+"|' ./common/scripts/setlocalversion 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 # Build the kernel LTO=thin BUILD_CONFIG=common/build.config.gki.aarch64 build/build.sh # Create bootimgs folder and copy images echo "Creating bootimgs folder and copying images..." mkdir bootimgs cp ./out/${ANDROID_VERSION}-${KERNEL_VERSION}/dist/Image ./bootimgs cp ./out/${ANDROID_VERSION}-${KERNEL_VERSION}/dist/Image.lz4 ./bootimgs cp ./out/${ANDROID_VERSION}-${KERNEL_VERSION}/dist/Image ../ cp ./out/${ANDROID_VERSION}-${KERNEL_VERSION}/dist/Image.lz4 ../ gzip -n -k -f -9 ../Image >../Image.gz cd ./bootimgs echo 'Building Image.gz' gzip -n -k -f -9 Image >Image.gz echo 'Building boot.img' $MKBOOTIMG --header_version 4 --kernel Image --output boot.img $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH cp ./boot.img ../../../${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}-boot.img echo 'Building boot-gz.img' $MKBOOTIMG --header_version 4 --kernel Image.gz --output boot-gz.img $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-gz.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH cp ./boot-gz.img ../../../${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}-boot-gz.img echo 'Building boot-lz4.img' $MKBOOTIMG --header_version 4 --kernel Image.lz4 --output boot-lz4.img $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-lz4.img --algorithm SHA256_RSA2048 --key $BOOT_SIGN_KEY_PATH cp ./boot-lz4.img ../../../${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}-boot-lz4.img cd .. # Create zip for different formats and place them in the same folder as images echo "Creating zip files for all formats..." cd ../AnyKernel3 ZIP_NAME="AnyKernel3-${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}.zip" echo "Creating zip file: $ZIP_NAME..." mv ../Image ./Image zip -r "../../$ZIP_NAME" ./* rm ./Image ZIP_NAME="AnyKernel3-lz4-${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}.zip" echo "Creating zip file: $ZIP_NAME..." mv ../Image.lz4 ./Image.lz4 zip -r "../../$ZIP_NAME" ./* rm ./Image.lz4 ZIP_NAME="AnyKernel3-gz-${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}.zip" echo "Creating zip file: $ZIP_NAME..." mv ../Image.gz ./Image.gz zip -r "../../$ZIP_NAME" ./* rm ./Image.gz cd ../../ # Delete the $CONFIG folder after building echo "Deleting $CONFIG folder..." rm -rf "$CONFIG" done - name: Upload build artifacts uses: actions/upload-artifact@v4 with: name: kernel-artifacts-a13 path: | *.zip *.img