|
| 1 | +name: Build Android 13 GKI Kernels |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: # This allows this workflow to be called from another workflow |
| 5 | + inputs: |
| 6 | + lto_type: |
| 7 | + description: 'Choose LTO type (thin/full)' |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + |
| 11 | +jobs: |
| 12 | + build-kernel-a12: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Maximize build space |
| 17 | + uses: easimon/maximize-build-space@master |
| 18 | + with: |
| 19 | + root-reserve-mb: 8192 |
| 20 | + temp-reserve-mb: 2048 |
| 21 | + remove-dotnet: 'true' |
| 22 | + remove-android: 'true' |
| 23 | + remove-haskell: 'true' |
| 24 | + remove-codeql: 'true' |
| 25 | + |
| 26 | + - name: Download prebuilt toolchain |
| 27 | + run: | |
| 28 | + AOSP_MIRROR=https://android.googlesource.com |
| 29 | + BRANCH=main-kernel-build-2024 |
| 30 | + git clone $AOSP_MIRROR/platform/prebuilts/build-tools -b $BRANCH --depth 1 build-tools |
| 31 | + git clone $AOSP_MIRROR/kernel/prebuilts/build-tools -b $BRANCH --depth 1 kernel-build-tools |
| 32 | + git clone $AOSP_MIRROR/platform/system/tools/mkbootimg -b $BRANCH --depth 1 mkbootimg |
| 33 | +
|
| 34 | + export AVBTOOL=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/bin/avbtool |
| 35 | + export GZIP=$GITHUB_WORKSPACE/build-tools/path/linux-x86/gzip |
| 36 | + export LZ4=$GITHUB_WORKSPACE/build-tools/path/linux-x86/lz4 |
| 37 | + export MKBOOTIMG=$GITHUB_WORKSPACE/mkbootimg/mkbootimg.py |
| 38 | + export UNPACK_BOOTIMG=$GITHUB_WORKSPACE/mkbootimg/unpack_bootimg.py |
| 39 | +
|
| 40 | + - name: Set boot sign key |
| 41 | + env: |
| 42 | + BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }} |
| 43 | + run: | |
| 44 | + if [ ! -z "$BOOT_SIGN_KEY" ]; then |
| 45 | + echo "$BOOT_SIGN_KEY" > ./kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem |
| 46 | + fi |
| 47 | + |
| 48 | + - name: Install repo tool |
| 49 | + run: | |
| 50 | + # Install dependencies |
| 51 | + sudo apt update |
| 52 | + sudo apt install -y repo |
| 53 | +
|
| 54 | + - name: Build for all configurations |
| 55 | + run: | |
| 56 | + BUILD_CONFIGS=( |
| 57 | + #"android12-5.10-198-2024-01" |
| 58 | + #"android12-5.10-205-2024-03" |
| 59 | + #"android12-5.10-209-2024-05" |
| 60 | + "android12-5.10-218-2024-08" |
| 61 | + #"android12-5.10-X-lts" |
| 62 | + ) |
| 63 | +
|
| 64 | + for CONFIG in "${BUILD_CONFIGS[@]}"; do |
| 65 | + CONFIG_DETAILS=${CONFIG} |
| 66 | + # Create directory and proceed with your steps |
| 67 | + echo "Creating folder for configuration: $CONFIG..." |
| 68 | + mkdir -p "$CONFIG" |
| 69 | + cd "$CONFIG" |
| 70 | + IFS="-" read -r ANDROID_VERSION KERNEL_VERSION SUB_LEVEL DATE <<< "$CONFIG_DETAILS" |
| 71 | + FORMATTED_BRANCH="${ANDROID_VERSION}-${KERNEL_VERSION}-${DATE}" |
| 72 | +
|
| 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 | +
|
| 79 | + echo "Creating folder for configuration: $CONFIG..." |
| 80 | + mkdir -p "$CONFIG" |
| 81 | + cd "$CONFIG" |
| 82 | + |
| 83 | + # Initialize and sync kernel source |
| 84 | + echo "Initializing and syncing kernel source..." |
| 85 | + repo init --depth=1 --u https://android.googlesource.com/kernel/manifest -b common-${FORMATTED_BRANCH} |
| 86 | + REMOTE_BRANCH=$(git ls-remote https://android.googlesource.com/kernel/common ${FORMATTED_BRANCH}) |
| 87 | + DEFAULT_MANIFEST_PATH=.repo/manifests/default.xml |
| 88 | +
|
| 89 | + # Check if branch is deprecated |
| 90 | + if grep -q deprecated <<< $REMOTE_BRANCH; then |
| 91 | + echo "Found deprecated branch: $FORMATTED_BRANCH" |
| 92 | + sed -i "s/\"${FORMATTED_BRANCH}\"/\"deprecated\/${FORMATT_BRANCH}\"/g" $DEFAULT_MANIFEST_PATH |
| 93 | + fi |
| 94 | +
|
| 95 | + # Sync repo and apply patches |
| 96 | + repo --version |
| 97 | + repo --trace sync -c -j$(nproc --all) --no-tags --fail-fast |
| 98 | +
|
| 99 | + # Add KernelSU, SUSFS patches, and build the kernel |
| 100 | + echo "Adding KernelSU..." |
| 101 | + curl -LSs "https://raw.githubusercontent.com/rifsxd/KernelSU-Next/next/kernel/setup.sh" | bash - |
| 102 | + #cd ./KernelSU-Next/kernel |
| 103 | + #sed -i 's/ccflags-y += -DKSU_VERSION=16/ccflags-y += -DKSU_VERSION=12000/' ./Makefile |
| 104 | + #cd ../../ |
| 105 | + echo "Applying SUSFS patches..." |
| 106 | + cp ../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./KernelSU-Next/ |
| 107 | + cp ../susfs4ksu/kernel_patches/50_add_susfs_in_gki-${ANDROID_VERSION}-${KERNEL_VERSION}.patch ./common/ |
| 108 | + cp ../susfs4ksu/kernel_patches/fs/* ./common/fs/ |
| 109 | + cp ../susfs4ksu/kernel_patches/include/linux/* ./common/include/linux/ |
| 110 | +
|
| 111 | + # Apply patches |
| 112 | + cd ./KernelSU-Next |
| 113 | + patch -p1 --forward < 10_enable_susfs_for_ksu.patch || true |
| 114 | + cd ../common |
| 115 | + patch -p1 < 50_add_susfs_in_gki-${ANDROID_VERSION}-${KERNEL_VERSION}.patch || true |
| 116 | + cp ../../kernel_patches/69_hide_stuff.patch ./ |
| 117 | + patch -p1 -F 3 < 69_hide_stuff.patch |
| 118 | + cd .. |
| 119 | + |
| 120 | + cp ../kernel_patches/apk_sign.c_fix.patch ./ |
| 121 | + patch -p1 -F 3 < apk_sign.c_fix.patch |
| 122 | + |
| 123 | + cp ../kernel_patches/core_hook.c_fix.patch ./ |
| 124 | + patch -p1 --fuzz=3 < ./core_hook.c_fix.patch |
| 125 | +
|
| 126 | + cp ../kernel_patches/selinux.c_fix.patch ./ |
| 127 | + patch -p1 -F 3 < selinux.c_fix.patch |
| 128 | + |
| 129 | + # Add configuration settings for SUSFS |
| 130 | + echo "Adding configuration settings to gki_defconfig..." |
| 131 | + echo "CONFIG_KSU=y" >> ./common/arch/arm64/configs/gki_defconfig |
| 132 | + echo "CONFIG_KSU_SUSFS=y" >> ./common/arch/arm64/configs/gki_defconfig |
| 133 | + echo "CONFIG_KSU_SUSFS_HAS_MAGIC_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig |
| 134 | + echo "CONFIG_KSU_SUSFS_SUS_PATH=y" >> ./common/arch/arm64/configs/gki_defconfig |
| 135 | + echo "CONFIG_KSU_SUSFS_SUS_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig |
| 136 | + echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_KSU_DEFAULT_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig |
| 137 | + echo "CONFIG_KSU_SUSFS_AUTO_ADD_SUS_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig |
| 138 | + echo "CONFIG_KSU_SUSFS_SUS_KSTAT=y" >> ./common/arch/arm64/configs/gki_defconfig |
| 139 | + echo "CONFIG_KSU_SUSFS_SUS_OVERLAYFS=y" >> ./common/arch/arm64/configs/gki_defconfig |
| 140 | + echo "CONFIG_KSU_SUSFS_TRY_UMOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig |
| 141 | + echo "CONFIG_KSU_SUSFS_AUTO_ADD_TRY_UMOUNT_FOR_BIND_MOUNT=y" >> ./common/arch/arm64/configs/gki_defconfig |
| 142 | + echo "CONFIG_KSU_SUSFS_SPOOF_UNAME=y" >> ./common/arch/arm64/configs/gki_defconfig |
| 143 | + echo "CONFIG_KSU_SUSFS_ENABLE_LOG=y" >> ./common/arch/arm64/configs/gki_defconfig |
| 144 | + echo "CONFIG_KSU_SUSFS_HIDE_KSU_SUSFS_SYMBOLS=y" >> ./common/arch/arm64/configs/gki_defconfig |
| 145 | + echo "CONFIG_KSU_SUSFS_SPOOF_CMDLINE_OR_BOOTCONFIG=y" >> ./common/arch/arm64/configs/gki_defconfig |
| 146 | + echo "CONFIG_KSU_SUSFS_OPEN_REDIRECT=y" >> ./common/arch/arm64/configs/gki_defconfig |
| 147 | + echo "CONFIG_KSU_SUSFS_SUS_SU=y" >> ./common/arch/arm64/configs/gki_defconfig |
| 148 | +
|
| 149 | + # Run sed commands |
| 150 | + echo "Running sed commands..." |
| 151 | + sed -i '2s/check_defconfig//' ./common/build.config.gki |
| 152 | + sed -i "s/dirty/'Wild+'/g" ./common/scripts/setlocalversion |
| 153 | + |
| 154 | + # Build the kernel |
| 155 | + LTO=${{ inputs.lto_type }} BUILD_CONFIG=common/build.config.gki.aarch64 build/build.sh |
| 156 | +
|
| 157 | + # Create bootimgs folder and copy images |
| 158 | + echo "Creating bootimgs folder and copying images..." |
| 159 | + mkdir bootimgs |
| 160 | + cp ./out/${ANDROID_VERSION}-${KERNEL_VERSION}/dist/Image ./bootimgs |
| 161 | + cp ./out/${ANDROID_VERSION}-${KERNEL_VERSION}/dist/Image.lz4 ./bootimgs |
| 162 | + cp ./out/${ANDROID_VERSION}-${KERNEL_VERSION}/dist/Image ../ |
| 163 | + cp ./out/${ANDROID_VERSION}-${KERNEL_VERSION}/dist/Image.lz4 ../ |
| 164 | + gzip -n -k -f -9 ../Image >../Image.gz |
| 165 | + cd ./bootimgs |
| 166 | + |
| 167 | + echo 'Building Image.gz' |
| 168 | + gzip -n -k -f -9 Image >Image.gz |
| 169 | + |
| 170 | + echo 'Building boot.img' |
| 171 | + $MKBOOTIMG --header_version 4 --kernel Image --output boot.img |
| 172 | + $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot.img --algorithm SHA256_RSA2048 --key ./kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem |
| 173 | + cp ./boot.img ../../../${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}-boot.img |
| 174 | + |
| 175 | + echo 'Building boot-gz.img' |
| 176 | + $MKBOOTIMG --header_version 4 --kernel Image.gz --output boot-gz.img |
| 177 | + $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-gz.img --algorithm SHA256_RSA2048 --key ./kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem |
| 178 | + cp ./boot-gz.img ../../../${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}-boot-gz.img |
| 179 | +
|
| 180 | + echo 'Building boot-lz4.img' |
| 181 | + $MKBOOTIMG --header_version 4 --kernel Image.lz4 --output boot-lz4.img |
| 182 | + $AVBTOOL add_hash_footer --partition_name boot --partition_size $((64 * 1024 * 1024)) --image boot-lz4.img --algorithm SHA256_RSA2048 --key ./kernel-build-tools/linux-x86/share/avb/testkey_rsa2048.pem |
| 183 | + cp ./boot-lz4.img ../../../${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}-boot-lz4.img |
| 184 | + cd .. |
| 185 | +
|
| 186 | + # Create zip for different formats and place them in the same folder as images |
| 187 | + echo "Creating zip files for all formats..." |
| 188 | + cd ../AnyKernel3 |
| 189 | + ZIP_NAME="AnyKernel3-${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}.zip" |
| 190 | + echo "Creating zip file: $ZIP_NAME..." |
| 191 | + mv ../Image ./Image |
| 192 | + zip -r "../../$ZIP_NAME" ./* |
| 193 | + rm ./Image |
| 194 | + |
| 195 | + ZIP_NAME="AnyKernel3-lz4-${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}.zip" |
| 196 | + echo "Creating zip file: $ZIP_NAME..." |
| 197 | + mv ../Image.lz4 ./Image.lz4 |
| 198 | + zip -r "../../$ZIP_NAME" ./* |
| 199 | + rm ./Image.lz4 |
| 200 | +
|
| 201 | + ZIP_NAME="AnyKernel3-gz-${ANDROID_VERSION}-${KERNEL_VERSION}.${SUB_LEVEL}_${DATE}.zip" |
| 202 | + echo "Creating zip file: $ZIP_NAME..." |
| 203 | + mv ../Image.gz ./Image.gz |
| 204 | + zip -r "../../$ZIP_NAME" ./* |
| 205 | + rm ./Image.gz |
| 206 | + cd ../../ |
| 207 | +
|
| 208 | + # Delete the $CONFIG folder after building |
| 209 | + echo "Deleting $CONFIG folder..." |
| 210 | + rm -rf "$CONFIG" |
| 211 | + done |
| 212 | + |
| 213 | + - name: Upload build artifacts |
| 214 | + uses: actions/upload-artifact@v3 |
| 215 | + with: |
| 216 | + name: kernel-artifacts |
| 217 | + path: | |
| 218 | + *.zip |
| 219 | + *.img |
0 commit comments