|
| 1 | +name: Build Kernel with KernelSU (Samsung A04) |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + kernel_source: |
| 7 | + description: 'Kernel source URL' |
| 8 | + required: true |
| 9 | + default: 'https://github.com/rsuntkOrgs/kernel_samsung_wingtech' |
| 10 | + kernel_branch: |
| 11 | + description: 'Kernel branch' |
| 12 | + required: true |
| 13 | + default: 'a045x' |
| 14 | + kernelsu_tag: |
| 15 | + description: 'KernelSU tag or "main" for latest' |
| 16 | + required: false |
| 17 | + default: 'main' |
| 18 | + create_release: |
| 19 | + description: 'Create GitHub Release' |
| 20 | + required: false |
| 21 | + default: false |
| 22 | + type: boolean |
| 23 | + push: |
| 24 | + branches: [main] |
| 25 | + paths: |
| 26 | + - '.github/workflows/build-kernel.yml' |
| 27 | + |
| 28 | +jobs: |
| 29 | + build: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + permissions: |
| 32 | + contents: write |
| 33 | + |
| 34 | + steps: |
| 35 | + - name: Checkout build repo |
| 36 | + uses: actions/checkout@v4 |
| 37 | + |
| 38 | + - name: Set up swap space |
| 39 | + uses: pierotofy/set-swap-space@master |
| 40 | + with: |
| 41 | + swap-size-gb: 12 |
| 42 | + |
| 43 | + - name: Install build dependencies |
| 44 | + run: | |
| 45 | + sudo apt-get update -qq |
| 46 | + sudo apt-get install -y --no-install-recommends \ |
| 47 | + bc bison build-essential ca-certificates cpio flex \ |
| 48 | + git kmod libelf-dev libssl-dev lz4 python3 \ |
| 49 | + zip wget curl sed binutils-aarch64-linux-gnu \ |
| 50 | + crossbuild-essential-arm64 clang lld llvm |
| 51 | +
|
| 52 | + - name: Clone kernel source |
| 53 | + run: | |
| 54 | + echo "Cloning ${{ github.event.inputs.kernel_source }} @ ${{ github.event.inputs.kernel_branch }}" |
| 55 | + git clone --depth=1 \ |
| 56 | + -b ${{ github.event.inputs.kernel_branch }} \ |
| 57 | + ${{ github.event.inputs.kernel_source }} \ |
| 58 | + android-kernel |
| 59 | +
|
| 60 | + - name: Fetch KernelSU version info |
| 61 | + id: ksu_info |
| 62 | + run: | |
| 63 | + TAG=${{ github.event.inputs.kernelsu_tag }} |
| 64 | + if [ "$TAG" = "main" ] || [ -z "$TAG" ]; then |
| 65 | + LATEST=$(curl -s https://api.github.com/repos/tiann/KernelSU/releases/latest | grep '"tag_name"' | cut -d'"' -f4) |
| 66 | + echo "KernelSU latest release: $LATEST" |
| 67 | + echo "ksu_version=$LATEST" >> $GITHUB_OUTPUT |
| 68 | + else |
| 69 | + echo "ksu_version=$TAG" >> $GITHUB_OUTPUT |
| 70 | + fi |
| 71 | +
|
| 72 | + - name: Integrate KernelSU via setup.sh |
| 73 | + run: | |
| 74 | + cd android-kernel |
| 75 | + KSU_TAG=${{ steps.ksu_info.outputs.ksu_version }} |
| 76 | + echo "Integrating KernelSU $KSU_TAG ..." |
| 77 | + curl -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash -s "$KSU_TAG" |
| 78 | + # Verify |
| 79 | + echo "KernelSU integrated:" |
| 80 | + head -5 KernelSU/kernel/Makefile || head -5 drivers/kernelsu/Makefile |
| 81 | +
|
| 82 | + - name: Setup Clang toolchain |
| 83 | + run: | |
| 84 | + mkdir -p $HOME/toolchain/clang |
| 85 | + # Use a stable Clang from ZyCromerZ (proven for MT6765 / 4.19) |
| 86 | + wget -q --show-progress \ |
| 87 | + https://github.com/ZyCromerZ/Clang/releases/download/14.0.6-20220902-full/Clang-14.0.6-x86_64.tar.gz \ |
| 88 | + -O /tmp/clang.tar.gz || { |
| 89 | + echo "ZyCromerZ Clang download failed, falling back to system clang" |
| 90 | + mkdir -p $HOME/toolchain/clang/bin |
| 91 | + ln -sf /usr/bin/clang $HOME/toolchain/clang/bin/clang |
| 92 | + ln -sf /usr/bin/ld.lld $HOME/toolchain/clang/bin/ld.lld |
| 93 | + for t in /usr/bin/llvm-*; do [ -f "$t" ] && ln -sf "$t" $HOME/toolchain/clang/bin/; done |
| 94 | + exit 0 |
| 95 | + } |
| 96 | + tar -xzf /tmp/clang.tar.gz -C $HOME/toolchain/clang/ |
| 97 | + rm /tmp/clang.tar.gz |
| 98 | + echo "$HOME/toolchain/clang/bin" >> $GITHUB_PATH |
| 99 | +
|
| 100 | + - name: Apply GPU driver fix (MT6765) |
| 101 | + run: | |
| 102 | + cd android-kernel |
| 103 | + TARGET=$(find drivers/gpu -name "mtk_mfgsys.c" 2>/dev/null | head -n 1) |
| 104 | + if [ -n "$TARGET" ]; then |
| 105 | + echo "Applying GPU fix to $TARGET" |
| 106 | + sed -i 's/PVRSRVGetDevicePowerState(ui32RGXDevIdx,/PVRSRVGetDevicePowerState(MTKGetRGXDevNode(),/g' "$TARGET" |
| 107 | + sed -i 's/MTKWriteBackFreqToRGX(ui32RGXDevIdx,/MTKWriteBackFreqToRGX(MTKGetRGXDevNode(),/g' "$TARGET" |
| 108 | + sed -i 's/PVRSRVDevicePostClockSpeedChange(ui32RGXDevIdx,/PVRSRVDevicePostClockSpeedChange(MTKGetRGXDevNode(),/g' "$TARGET" |
| 109 | + sed -i 's/PVRSRVDevicePreClockSpeedChange(ui32RGXDevIdx,/PVRSRVDevicePreClockSpeedChange(MTKGetRGXDevNode(),/g' "$TARGET" |
| 110 | + echo "GPU fix applied." |
| 111 | + else |
| 112 | + echo "mtk_mfgsys.c not found, skipping GPU fix." |
| 113 | + fi |
| 114 | +
|
| 115 | + - name: Configure kernel |
| 116 | + run: | |
| 117 | + cd android-kernel |
| 118 | + export PATH=$HOME/toolchain/clang/bin:$PATH |
| 119 | +
|
| 120 | + # Find defconfig |
| 121 | + DEFCONFIG=$(find arch/arm64/configs -name "a04*defconfig" -o -name "*a045*" 2>/dev/null | head -1 | xargs basename) |
| 122 | + if [ -z "$DEFCONFIG" ]; then |
| 123 | + DEFCONFIG="a04_defconfig" |
| 124 | + fi |
| 125 | + echo "Using defconfig: $DEFCONFIG" |
| 126 | +
|
| 127 | + make O=out ARCH=arm64 $DEFCONFIG |
| 128 | +
|
| 129 | + # Disable Werror to avoid upstream warnings killing the build |
| 130 | + sed -i 's/CONFIG_WERROR=y/CONFIG_WERROR=n/g' out/.config |
| 131 | +
|
| 132 | + # KernelSU — enable + keep KPROBES on for 4.19 non-GKI hook method |
| 133 | + scripts/config --file out/.config \ |
| 134 | + -e CONFIG_KSU \ |
| 135 | + -e CONFIG_KPROBES \ |
| 136 | + -e CONFIG_HAVE_KPROBES \ |
| 137 | + -e CONFIG_OVERLAY_FS \ |
| 138 | + -e CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE |
| 139 | +
|
| 140 | + # Build identity |
| 141 | + scripts/config --file out/.config \ |
| 142 | + --set-str CONFIG_LOCALVERSION "-KSU-${{ steps.ksu_info.outputs.ksu_version }}" \ |
| 143 | + --disable CONFIG_LOCALVERSION_AUTO |
| 144 | +
|
| 145 | + # Strip debug info to shrink image size |
| 146 | + scripts/config --file out/.config \ |
| 147 | + --disable CONFIG_DEBUG_INFO \ |
| 148 | + --disable CONFIG_DEBUG_INFO_SPLIT \ |
| 149 | + --disable CONFIG_DEBUG_INFO_REDUCED \ |
| 150 | + --disable CONFIG_DEBUG_INFO_DWARF4 \ |
| 151 | + --disable CONFIG_FTRACE \ |
| 152 | + --disable CONFIG_PROFILING \ |
| 153 | + --enable CONFIG_STRIP_ASM_SYMS \ |
| 154 | + --enable CONFIG_CC_OPTIMIZE_FOR_SIZE |
| 155 | +
|
| 156 | + echo "Configuration done." |
| 157 | +
|
| 158 | + - name: Compile kernel |
| 159 | + run: | |
| 160 | + cd android-kernel |
| 161 | + export PATH=$HOME/toolchain/clang/bin:$PATH |
| 162 | +
|
| 163 | + make -j$(nproc --all) O=out ARCH=arm64 \ |
| 164 | + CC=clang \ |
| 165 | + LD=ld.lld \ |
| 166 | + AR=llvm-ar \ |
| 167 | + NM=llvm-nm \ |
| 168 | + OBJCOPY=llvm-objcopy \ |
| 169 | + STRIP=llvm-strip \ |
| 170 | + LLVM=1 LLVM_IAS=1 \ |
| 171 | + CLANG_TRIPLE=aarch64-linux-gnu- \ |
| 172 | + CROSS_COMPILE=aarch64-linux-gnu- \ |
| 173 | + CROSS_COMPILE_ARM32=arm-linux-gnueabi- \ |
| 174 | + KCFLAGS="-w" \ |
| 175 | + Image 2>&1 | tee $GITHUB_WORKSPACE/compile.log |
| 176 | +
|
| 177 | + if [ ! -f out/arch/arm64/boot/Image ]; then |
| 178 | + echo "::error::Kernel Image not found after build!" |
| 179 | + exit 1 |
| 180 | + fi |
| 181 | +
|
| 182 | + SIZE=$(du -h out/arch/arm64/boot/Image | cut -f1) |
| 183 | + echo "Kernel Image size: $SIZE" |
| 184 | +
|
| 185 | + - name: Package with AnyKernel3 |
| 186 | + run: | |
| 187 | + git clone --depth=1 https://github.com/osm0sis/AnyKernel3 AnyKernel3 |
| 188 | + cd AnyKernel3 |
| 189 | + rm -rf .git .github *.md |
| 190 | +
|
| 191 | + cp $GITHUB_WORKSPACE/android-kernel/out/arch/arm64/boot/Image ./ |
| 192 | +
|
| 193 | + cat > anykernel.sh << 'AKEOF' |
| 194 | + properties() { |
| 195 | + kernel.string=Samsung A04 + KernelSU |
| 196 | + do.devicecheck=1 |
| 197 | + do.modules=0 |
| 198 | + do.cleanup=1 |
| 199 | + do.cleanuponabort=1 |
| 200 | + device.name1=a04 |
| 201 | + device.name2=a045f |
| 202 | + device.name3=SM-A045F |
| 203 | + device.name4=a045x |
| 204 | + supported.versions=12-14 |
| 205 | + } |
| 206 | +
|
| 207 | + block=auto |
| 208 | + is_slot_device=0 |
| 209 | +
|
| 210 | + . tools/ak3-core.sh |
| 211 | +
|
| 212 | + split_boot |
| 213 | + flash_boot |
| 214 | + AKEOF |
| 215 | +
|
| 216 | + BUILD_DATE=$(date +%Y%m%d-%H%M) |
| 217 | + KSU_VER=${{ steps.ksu_info.outputs.ksu_version }} |
| 218 | + ZIP_NAME="SamsungA04-KernelSU-${KSU_VER}-${BUILD_DATE}.zip" |
| 219 | +
|
| 220 | + zip -r9 $GITHUB_WORKSPACE/$ZIP_NAME . -x '.git*' |
| 221 | +
|
| 222 | + echo "ZIP_NAME=$ZIP_NAME" >> $GITHUB_ENV |
| 223 | + echo "Packaged: $ZIP_NAME ($(du -h $GITHUB_WORKSPACE/$ZIP_NAME | cut -f1))" |
| 224 | +
|
| 225 | + - name: Upload artifact |
| 226 | + uses: actions/upload-artifact@v4 |
| 227 | + with: |
| 228 | + name: ${{ env.ZIP_NAME }} |
| 229 | + path: ${{ env.ZIP_NAME }} |
| 230 | + retention-days: 14 |
| 231 | + |
| 232 | + - name: Upload compile log on failure |
| 233 | + if: failure() |
| 234 | + uses: actions/upload-artifact@v4 |
| 235 | + with: |
| 236 | + name: compile-log-${{ github.run_number }} |
| 237 | + path: compile.log |
| 238 | + |
| 239 | + - name: Create GitHub Release |
| 240 | + if: github.event.inputs.create_release == 'true' |
| 241 | + uses: softprops/action-gh-release@v2 |
| 242 | + with: |
| 243 | + tag_name: ksu-${{ steps.ksu_info.outputs.ksu_version }}-build${{ github.run_number }} |
| 244 | + name: "KernelSU ${{ steps.ksu_info.outputs.ksu_version }} — Samsung A04" |
| 245 | + body: | |
| 246 | + ## Samsung A04 (SM-A045F) Kernel + KernelSU |
| 247 | +
|
| 248 | + | | | |
| 249 | + |---|---| |
| 250 | + | **KernelSU version** | `${{ steps.ksu_info.outputs.ksu_version }}` | |
| 251 | + | **Kernel source** | `${{ github.event.inputs.kernel_source }}` | |
| 252 | + | **Branch** | `${{ github.event.inputs.kernel_branch }}` | |
| 253 | + | **Build number** | `#${{ github.run_number }}` | |
| 254 | +
|
| 255 | + ### Flash instructions |
| 256 | + 1. Boot into TWRP / OrangeFox recovery |
| 257 | + 2. Flash the ZIP |
| 258 | + 3. Install **KernelSU Manager APK** from the [KernelSU releases page](https://github.com/tiann/KernelSU/releases) |
| 259 | +
|
| 260 | + > Built automatically via GitHub Actions |
| 261 | + files: ${{ env.ZIP_NAME }} |
| 262 | + env: |
| 263 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments