-
Notifications
You must be signed in to change notification settings - Fork 1
314 lines (277 loc) · 11.6 KB
/
Copy pathbuild-kernel.yml
File metadata and controls
314 lines (277 loc) · 11.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
name: Build Kernel with KernelSU (Samsung A04s)
on:
workflow_dispatch:
inputs:
kernel_source:
description: 'Kernel source URL'
required: true
default: 'https://github.com/SavedByLight/android_kernel_samsung_a04s'
kernel_branch:
description: 'Kernel branch'
required: true
default: 'main'
kernelsu_tag:
description: 'KernelSU tag or "main" for latest'
required: false
default: 'main'
create_release:
description: 'Create GitHub Release'
required: false
default: false
type: boolean
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout build repo
uses: actions/checkout@v4
- name: Set up swap space
uses: pierotofy/set-swap-space@master
with:
swap-size-gb: 12
- name: Install build dependencies
run: |
sudo apt-get update -qq
sudo apt-get install -y --no-install-recommends \
bc bison build-essential ca-certificates cpio flex \
git kmod libelf-dev libssl-dev lz4 python3 \
zip unzip wget curl sed binutils-aarch64-linux-gnu \
crossbuild-essential-arm64 gcc-aarch64-linux-gnu \
gcc-arm-linux-gnueabi clang lld llvm
- name: Clone kernel source
run: |
echo "Cloning ${{ github.event.inputs.kernel_source }} @ ${{ github.event.inputs.kernel_branch }}"
git clone --depth=1 \
-b ${{ github.event.inputs.kernel_branch }} \
${{ github.event.inputs.kernel_source }} \
android-kernel
echo "Kernel source cloned. Top-level files:"
ls android-kernel/
- name: Detect kernel version
id: kver
run: |
VER=$(grep "^VERSION =" android-kernel/Makefile | awk '{print $3}')
PATCH=$(grep "^PATCHLEVEL =" android-kernel/Makefile | awk '{print $3}')
SUB=$(grep "^SUBLEVEL =" android-kernel/Makefile | awk '{print $3}')
echo "Detected kernel version: $VER.$PATCH.$SUB"
echo "version=$VER.$PATCH.$SUB" >> $GITHUB_OUTPUT
echo "major=$VER.$PATCH" >> $GITHUB_OUTPUT
- name: Fetch latest KernelSU version
id: ksu_info
run: |
TAG="${{ github.event.inputs.kernelsu_tag }}"
if [ "$TAG" = "main" ] || [ -z "$TAG" ]; then
LATEST=$(curl -s https://api.github.com/repos/tiann/KernelSU/releases/latest \
| grep '"tag_name"' | cut -d'"' -f4)
echo "Latest KernelSU: $LATEST"
echo "ksu_version=$LATEST" >> $GITHUB_OUTPUT
else
echo "ksu_version=$TAG" >> $GITHUB_OUTPUT
fi
- name: Integrate KernelSU via setup.sh
run: |
cd android-kernel
KSU_TAG="${{ steps.ksu_info.outputs.ksu_version }}"
echo "Integrating KernelSU $KSU_TAG ..."
curl -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash -s "$KSU_TAG"
echo "--- KernelSU Makefile header ---"
head -5 KernelSU/kernel/Makefile 2>/dev/null || head -5 drivers/kernelsu/Makefile 2>/dev/null
- name: Setup Clang toolchain
run: |
mkdir -p $HOME/toolchain/clang
echo "Downloading ZyCromerZ Clang 17..."
wget -q --show-progress \
https://github.com/ZyCromerZ/Clang/releases/download/17.0.0-20230725-release/Clang-17.0.0-x86_64.tar.gz \
-O /tmp/clang.tar.gz \
&& tar -xzf /tmp/clang.tar.gz -C $HOME/toolchain/clang/ \
&& rm /tmp/clang.tar.gz \
&& echo "Clang ready" \
|| {
echo "Download failed - falling back to system clang"
mkdir -p $HOME/toolchain/clang/bin
for b in clang clang++ ld.lld llvm-ar llvm-nm llvm-objcopy llvm-objdump llvm-strip; do
[ -f "/usr/bin/$b" ] && ln -sf "/usr/bin/$b" "$HOME/toolchain/clang/bin/$b"
done
}
echo "$HOME/toolchain/clang/bin" >> $GITHUB_PATH
- name: Apply GPU driver fix (MT6765)
run: |
cd android-kernel
TARGET=$(find drivers/gpu -name "mtk_mfgsys.c" 2>/dev/null | head -n 1)
if [ -n "$TARGET" ]; then
echo "Applying MT6765 GPU fix to $TARGET"
sed -i 's/PVRSRVGetDevicePowerState(ui32RGXDevIdx,/PVRSRVGetDevicePowerState(MTKGetRGXDevNode(),/g' "$TARGET"
sed -i 's/MTKWriteBackFreqToRGX(ui32RGXDevIdx,/MTKWriteBackFreqToRGX(MTKGetRGXDevNode(),/g' "$TARGET"
sed -i 's/PVRSRVDevicePostClockSpeedChange(ui32RGXDevIdx,/PVRSRVDevicePostClockSpeedChange(MTKGetRGXDevNode(),/g' "$TARGET"
sed -i 's/PVRSRVDevicePreClockSpeedChange(ui32RGXDevIdx,/PVRSRVDevicePreClockSpeedChange(MTKGetRGXDevNode(),/g' "$TARGET"
echo "GPU fix applied."
else
echo "mtk_mfgsys.c not found - skipping GPU fix."
fi
- name: Configure kernel
run: |
cd android-kernel
export PATH=$HOME/toolchain/clang/bin:$PATH
DEFCONFIG=$(find arch/arm64/configs -name "*a04s*" -o -name "*a04*defconfig" 2>/dev/null | head -1 | xargs -r basename)
[ -z "$DEFCONFIG" ] && DEFCONFIG="a04_defconfig"
echo "Using defconfig: $DEFCONFIG"
echo "DEFCONFIG=$DEFCONFIG" >> $GITHUB_ENV
make O=out ARCH=arm64 CC=clang \
CLANG_TRIPLE=aarch64-linux-gnu- \
CROSS_COMPILE=aarch64-linux-gnu- \
"$DEFCONFIG"
sed -i 's/CONFIG_WERROR=y/CONFIG_WERROR=n/g' out/.config
scripts/config --file out/.config \
-e CONFIG_KSU \
-e CONFIG_KPROBES \
-e CONFIG_HAVE_KPROBES \
-e CONFIG_KPROBE_EVENTS \
-e CONFIG_OVERLAY_FS \
-e CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE \
-d CONFIG_KSU_DEBUG
scripts/config --file out/.config \
--set-str CONFIG_LOCALVERSION "-KSU-${{ steps.ksu_info.outputs.ksu_version }}" \
--disable CONFIG_LOCALVERSION_AUTO
scripts/config --file out/.config \
--disable CONFIG_DEBUG_INFO \
--disable CONFIG_DEBUG_INFO_SPLIT \
--disable CONFIG_DEBUG_INFO_REDUCED \
--disable CONFIG_DEBUG_INFO_DWARF4 \
--disable CONFIG_FTRACE \
--disable CONFIG_PROFILING \
--enable CONFIG_STRIP_ASM_SYMS \
--enable CONFIG_CC_OPTIMIZE_FOR_SIZE
make O=out ARCH=arm64 CC=clang \
CLANG_TRIPLE=aarch64-linux-gnu- \
CROSS_COMPILE=aarch64-linux-gnu- \
olddefconfig
echo "Configuration complete."
- name: Compile kernel
run: |
cd android-kernel
export PATH=$HOME/toolchain/clang/bin:$PATH
make -j$(nproc --all) O=out ARCH=arm64 \
CC=clang \
LD=ld.lld \
AR=llvm-ar \
NM=llvm-nm \
OBJCOPY=llvm-objcopy \
STRIP=llvm-strip \
LLVM=1 LLVM_IAS=1 \
CLANG_TRIPLE=aarch64-linux-gnu- \
CROSS_COMPILE=aarch64-linux-gnu- \
CROSS_COMPILE_ARM32=arm-linux-gnueabi- \
KCFLAGS="-w" \
Image dtbs 2>&1 | tee $GITHUB_WORKSPACE/compile.log
if [ ! -f out/arch/arm64/boot/Image ]; then
echo "::error::Build failed - kernel Image not found!"
exit 1
fi
echo "Build successful! Image size: $(du -h out/arch/arm64/boot/Image | cut -f1)"
- name: Collect DTBs
run: |
cd android-kernel
find out/arch/arm64/boot/dts -name "*.dtb" 2>/dev/null | sort | xargs cat > out/arch/arm64/boot/dtb.img 2>/dev/null || true
if [ -s out/arch/arm64/boot/dtb.img ]; then
echo "DTB collected: $(du -h out/arch/arm64/boot/dtb.img | cut -f1)"
echo "HAS_DTB=true" >> $GITHUB_ENV
else
echo "No DTBs found - skipping DTB packaging."
echo "HAS_DTB=false" >> $GITHUB_ENV
fi
- name: Write anykernel.sh
run: |
mkdir -p $GITHUB_WORKSPACE/ak3out
cat > $GITHUB_WORKSPACE/ak3out/anykernel.sh << 'AKEOF'
# AnyKernel3 Ramdisk Mod Script
# Samsung Galaxy A04s (SM-A047F) + KernelSU
properties() { '
kernel.string=Samsung A04s KernelSU Kernel
do.devicecheck=1
do.modules=0
do.systemless=1
do.cleanup=1
do.cleanuponabort=1
device.name1=a04s
device.name2=a047f
device.name3=SM-A047F
device.name4=a047fxxu
device.name5=a047x
supported.versions=12-14
supported.patchlevels=
'; }
block=auto;
is_slot_device=0;
ramdisk_compression=auto;
patch_vbmeta_flag=auto;
. tools/ak3-core.sh;
split_boot;
if [ -f "$AKHOME/dtb.img" ]; then
flash_dtb;
fi
flash_boot;
AKEOF
- name: Package with AnyKernel3
run: |
git clone --depth=1 https://github.com/osm0sis/AnyKernel3 AnyKernel3
cd AnyKernel3
rm -rf .git .github *.md
cp $GITHUB_WORKSPACE/android-kernel/out/arch/arm64/boot/Image ./
cp $GITHUB_WORKSPACE/ak3out/anykernel.sh ./anykernel.sh
if [ "${{ env.HAS_DTB }}" = "true" ]; then
cp $GITHUB_WORKSPACE/android-kernel/out/arch/arm64/boot/dtb.img ./dtb.img
echo "DTB included in zip."
fi
BUILD_DATE=$(date +%Y%m%d-%H%M)
KSU_VER="${{ steps.ksu_info.outputs.ksu_version }}"
ZIP_NAME="SamsungA04s-KernelSU-${KSU_VER}-${BUILD_DATE}.zip"
zip -r9 "$GITHUB_WORKSPACE/$ZIP_NAME" . -x '.git*'
echo "ZIP_NAME=$ZIP_NAME" >> $GITHUB_ENV
echo "Packaged: $ZIP_NAME ($(du -h $GITHUB_WORKSPACE/$ZIP_NAME | cut -f1))"
- name: Verify zip contents
run: |
ZIP_NAME="${{ env.ZIP_NAME }}"
echo "=== ZIP contents ==="
unzip -l "$GITHUB_WORKSPACE/$ZIP_NAME"
unzip -l "$GITHUB_WORKSPACE/$ZIP_NAME" | grep -q "Image" \
&& echo "Image present in zip - OK" \
|| { echo "::error::Image missing from zip!"; exit 1; }
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.ZIP_NAME }}
path: ${{ env.ZIP_NAME }}
retention-days: 14
- name: Upload compile log on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: compile-log-${{ github.run_number }}
path: compile.log
- name: Create GitHub Release
if: github.event.inputs.create_release == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: ksu-${{ steps.ksu_info.outputs.ksu_version }}-build${{ github.run_number }}
name: "KernelSU ${{ steps.ksu_info.outputs.ksu_version }} - Samsung A04s"
body: |
## Samsung A04s (SM-A047F) Kernel + KernelSU
| | |
|---|---|
| **KernelSU version** | `${{ steps.ksu_info.outputs.ksu_version }}` |
| **Kernel version** | `${{ steps.kver.outputs.version }}` |
| **Kernel source** | [SavedByLight/android_kernel_samsung_a04s](https://github.com/SavedByLight/android_kernel_samsung_a04s) |
| **Branch** | `${{ github.event.inputs.kernel_branch }}` |
| **Build number** | `#${{ github.run_number }}` |
### Flash instructions
1. Boot into TWRP / OrangeFox recovery
2. Flash the ZIP
3. Reboot to system
4. Install **KernelSU Manager APK** from the [KernelSU releases page](https://github.com/tiann/KernelSU/releases)
5. Open Manager - status should show **Working**
> Built automatically via GitHub Actions
files: ${{ env.ZIP_NAME }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}