forked from ShirkNeko/GKI_KernelSU_SUSFS
-
Notifications
You must be signed in to change notification settings - Fork 0
767 lines (662 loc) · 36.2 KB
/
gki-kernel.yml
File metadata and controls
767 lines (662 loc) · 36.2 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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
name: GKI Kernel Build
permissions:
contents: write # Allow writing to repository contents (for pushing tags)
actions: write # Allows triggering actions
on:
workflow_call: # This allows this workflow to be called from another workflow
inputs:
make_release:
required: true
type: boolean
default: true
android_version:
required: true
type: string
kernel_version:
required: true
type: string
sub_level:
required: true
type: string
os_patch_level:
required: true
type: string
kernelsu_variant:
required: true
type: string
kernelsu_branch:
required: true
type: string
# kernelsu_branch_other:
# required: false
# type: string
revision:
required: false
type: string
version:
required: false
type: string
use_zram:
required: true
type: boolean
default: true
use_kpm:
required: true
type: boolean
default: true
supp_op:
required: true
type: boolean
default: false
BBG:
required: true
type: boolean
default: false
jobs:
build-kernel-kernelsu-susfs:
runs-on: ubuntu-latest
env:
CCACHE_COMPILERCHECK: "%compiler% -dumpmachine; %compiler% -dumpversion"
CCACHE_NOHASHDIR: "true"
CCACHE_HARDLINK: "true"
steps:
- name: Maximize Build Space
uses: AdityaGarg8/remove-unwanted-software@v5
with:
remove-dotnet: 'true' # Frees ~2 GB
remove-android: 'true' # Frees ~9 GB
remove-haskell: 'true' # Frees ~5.2 GB
remove-codeql: 'true' # Frees ~5.4 GB
remove-docker-images: 'true' # Frees ~3.2 GB
remove-large-packages: 'true' # Frees ~3.1 GB
remove-swapfile: 'true' # Frees ~4 GB
remove-cached-tools: 'false' # Avoid unless confirmed safe
verbose: 'true' # Enable detailed logging
- name: 设定 CONFIG 环境变量
run: |
# Set CONFIG dynamically based on inputs values
CONFIG="${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.sub_level }}"
# Set CONFIG as an environment variable for future steps
echo "CONFIG=$CONFIG" >> $GITHUB_ENV
echo "CONFIG set to: $CONFIG"
# Install ccache
- name: 安装 ccache
run: sudo apt update && sudo apt upgrade -y && sudo apt install -y ccache python3 git curl
- name: 配置 ccache
run: |
mkdir -p ~/.cache/bazel
ccache --version
ccache --max-size=2G
ccache --set-config=compression=true
echo "CCACHE_DIR=$HOME/.ccache" >> $GITHUB_ENV
- name: 从缓存中还原ccache
uses: actions/cache@v4
with:
path: ~/.ccache
key: ${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.sub_level }}-ccache-${{ github.sha }}
restore-keys: |
${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.sub_level }}-ccache-
- name: 缓存工具链
id: cache-toolchain
uses: actions/cache@v4
with:
path: |
kernel-build-tools
mkbootimg
key: toolchain-${{ runner.os }}-v1
# Step 2: Download toolchain if cache was not found
- name: 下载工具链(如果未找到缓存)
if: steps.cache-toolchain.outputs.cache-hit != 'true'
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
- name: 设置环境变量
run: |
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: 密钥设置——已经过mkppk修改
env:
BOOT_SIGN_KEY: ${{ secrets.BOOT_SIGN_KEY }}
run: |
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 > ./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
- name: 安装仓库
run: |
# Install dependencies
mkdir -p ./git-repo
curl https://storage.googleapis.com/git-repo-downloads/repo > ./git-repo/repo
chmod a+rx ./git-repo/repo
echo "REPO=$GITHUB_WORKSPACE/./git-repo/repo" >> $GITHUB_ENV
- name: 克隆 AnyKernel3 和其他依赖项
run: |
echo "Cloning AnyKernel3 and other dependencies..."
ANYKERNEL_BRANCH="gki-2.0"
SUSFS_BRANCH="gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}"
# Debug print the branches
echo "Using branch for SUSFS: $SUSFS_BRANCH"
# Clone repositories using the branch names
git clone https://github.com/WildPlusKernel/AnyKernel3.git -b "$ANYKERNEL_BRANCH"
git clone https://github.com/ShirkNeko/susfs4ksu.git -b "$SUSFS_BRANCH"
git clone https://github.com/Tools-cx-app/kernel_patches.git
# Sukisu的补丁仓库
git clone https://github.com/ShirkNeko/SukiSU_patch.git
- name: 设置 CONFIG 环境变量
run: |
# Set CONFIG dynamically based on inputs values
CONFIG="${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.sub_level }}"
# Set CONFIG as an environment variable for future steps
echo "CONFIG=$CONFIG" >> $GITHUB_ENV
echo "CONFIG set to: $CONFIG"
- name: 初始化和同步内核源代码
run: |
echo "Creating folder for configuration: $CONFIG..."
mkdir -p "$CONFIG"
cd "$CONFIG"
# Initialize and sync kernel source
echo "Initializing and syncing kernel source..."
FORMATTED_BRANCH="${{ inputs.android_version }}-${{ inputs.kernel_version }}-${{ inputs.os_patch_level }}"
$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
echo "REMOTE_BRANCH=$REMOTE_BRANCH" >> $GITHUB_ENV
FORMATTED_BRANCH="${{ inputs.android_version }}-${{ inputs.kernel_version }}"
if grep -q deprecated <<< "$REMOTE_BRANCH" && \
{ [ "$FORMATTED_BRANCH" == "android13-5.15" ] && \
[ ${{ inputs.sub_level }} -lt 123 ]; }; then
echo '修复5.15仅支持旧版C库的BUG'
cd ./common
curl -LSs https://github.com/zzh20188/GKI_KernelSU_SUSFS/raw/refs/heads/legacy/fix_5.15.legacy -o fix_5.15.legacy.patch
patch -p1 < fix_5.15.legacy.patch
fi
- name: 使GKI在一加8E平台正常使用
if: ${{ inputs.supp_op }}
run: |
echo '切换到驱动目录'
cd "$CONFIG/common/drivers/"
echo '当前目录$(pwd),下载支持补丁'
curl -LSs "https://github.com/zzh20188/GKI_KernelSU_SUSFS/raw/refs/heads/dev/hmbird_patch.c" -o hmbird_patch.c
if [ ! -f hmbird_patch.c ]; then
echo "hmbird_patch.c 下载失败"
fi
echo '补丁加入构建'
echo "obj-y += hmbird_patch.o" >> Makefile
tail -n 3 Makefile
- name: 确定 KernelSU 的分支
run: |
branch_input="${{ inputs.kernelsu_branch }}"
variant_input="${{ inputs.kernelsu_variant }}"
case "$branch_input" in
"Stable(标准)")
echo "BRANCH=-s susfs-main" >> $GITHUB_ENV
;;
"Dev(开发)")
case "$variant_input" in
"Official" | "MKSU") echo "BRANCH=-s main" >> $GITHUB_ENV ;;
"Next") echo "BRANCH=-s next-susfs-dev" >> $GITHUB_ENV ;;
"SukiSU") echo "BRANCH=-s susfs-test" >> $GITHUB_ENV ;;
*)
echo "错误:未定义开发分支的变体 '$variant_input'" >&2
exit 1
;;
esac
;;
*)
echo "错误:需要自定义分支时未提供参数" >&2
exit 1
;;
esac
- name: 添加 KernelSU
run: |
echo "更改为配置目录: $CONFIG..."
cd "$CONFIG"
if [ "${{ inputs.kernelsu_variant }}" == "Official" ]; then
echo "Adding KernelSU Official..."
curl -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash $BRANCH
elif [ "${{ inputs.kernelsu_variant }}" == "Next" ]; then
echo "Adding KernelSU Next..."
curl -LSs "https://raw.githubusercontent.com/rifsxd/KernelSU-Next/next-susfs/kernel/setup.sh" | bash $BRANCH
elif [ "${{ inputs.kernelsu_variant }}" == "MKSU" ]; then
echo "Adding KernelSU MKSU..."
curl -LSs "https://raw.githubusercontent.com/5ec1cff/KernelSU/main/kernel/setup.sh" | bash $BRANCH
elif [ "${{ inputs.kernelsu_variant }}" == "SukiSU" ]; then
echo "Adding KernelSU SukiSU..."
curl -LSs "https://raw.githubusercontent.com/SukiSU-Ultra/SukiSU-Ultra/main/kernel/setup.sh" | bash $BRANCH
fi
- name: 添加 Baseband-guard 支持
if: ${{ github.event.inputs.BBG == 'true' }}
run: |
echo "更改为配置目录: $CONFIG..."
cd "$CONFIG/common"
echo "下载并运行 Baseband-guard setup 脚本..."
wget -O- https://github.com/vc-teahouse/Baseband-guard/raw/main/setup.sh | bash
echo "启用 Baseband-guard 内核配置..."
CONFIG_FILE="arch/arm64/configs/gki_defconfig"
echo "CONFIG_BBG=y" >> "$CONFIG_FILE"
# 对于 GitHub Actions 云编译,修改 LSM Kconfig
echo "修改 security/Kconfig 以包含 baseband_guard..."
sed -i '/^config LSM$/,/^help$/{ /^[[:space:]]*default/ { /baseband_guard/! s/lockdown/lockdown,baseband_guard/ } }' ./security/Kconfig
echo "Baseband-guard 配置完成"
- name: 为 KernelSU 变体安装 SUSFS 补丁
run: |
echo "更改为配置目录: $CONFIG..."
cd "$CONFIG"
echo "Applying SUSFS patches..."
# Copy SUSFS patches
cp ../susfs4ksu/kernel_patches/50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch ./common/
cp ../susfs4ksu/kernel_patches/fs/* ./common/fs/
cp ../susfs4ksu/kernel_patches/include/linux/* ./common/include/linux/
if [ "${{ inputs.kernelsu_variant }}" == "Official" ]; then
echo "Applying SUSFS patches for Official KernelSU..."
cd ./KernelSU
cp ../../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./
patch -p1 --forward --fuzz=3 < 10_enable_susfs_for_ksu.patch
elif [ "${{ inputs.kernelsu_variant }}" == "Next" ]; then
# echo "Applying SUSFS patches for KernelSU-Next..."
cd ./KernelSU-Next
# curl -LSs https://github.com/zzh20188/GKI_KernelSU_SUSFS/raw/refs/heads/dev/0001-kernel-patch-susfs-v1.5.7-to-KernelSU-Next-v1.0.7.patch -o susfs.patch
# patch -p1 --forward < susfs.patch
# # cp ../../kernel_patches/next/kernel-patch-susfs-v1.5.7-to-KernelSU-Next.patch ./
# # patch -p1 --forward --fuzz=3 < kernel-patch-susfs-v1.5.7-to-KernelSU-Next.patch || true
# # # 临时补丁
# # curl -LSs "https://github.com/zzh20188/GKI_KernelSU_SUSFS/raw/refs/heads/dev/fix_ksun_susfs.patch" -o fix_ksun_susfs.patch
# # echo '应用KSUN临时修复补丁'
# # patch -p1 --forward < fix_ksun_susfs.patch
# sed -i '/bool ksu_devpts_hook = false;/d' ./kernel/sucompat.c
elif [ "${{ inputs.kernelsu_variant }}" == "MKSU" ]; then
echo "Applying SUSFS patches for MKSU..."
cd ./KernelSU
cp ../../susfs4ksu/kernel_patches/KernelSU/10_enable_susfs_for_ksu.patch ./
patch -p1 --forward --fuzz=3 < 10_enable_susfs_for_ksu.patch || true
echo "Applying MKSU specific SUSFS patch..."
cp ../../kernel_patches/mksu/mksu_susfs.patch ./
patch -p1 < mksu_susfs.patch || true
cp ../../kernel_patches/mksu/fix.patch ./
patch -p1 < fix.patch || true
elif [ "${{ inputs.kernelsu_variant }}" == "SukiSU" ]; then
echo "Applying SUSFS patches for SukiSU..."
cd ./KernelSU
echo "Applying SukiSU specific SUSFS patch..."
else
echo "Invalid KernelSU variant selected!"
exit 1
fi
cd ../common
FORMATTED_BRANCH="${{ inputs.android_version }}-${{ inputs.kernel_version }}"
if grep -q deprecated <<< "$REMOTE_BRANCH" && \
{ [ "$FORMATTED_BRANCH" == "android12-5.10" ] && \
[ ${{ inputs.sub_level }} -lt 136 ]; }; then
patch -p1 < 50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch || true
curl -LSs https://github.com/zzh20188/GKI_KernelSU_SUSFS/raw/refs/heads/legacy/fdinfo.c.patch -o fdinfo.c.patch
patch -p1 < fdinfo.c.patch
else
patch -p1 --fuzz=3 < 50_add_susfs_in_gki-${{ inputs.android_version }}-${{ inputs.kernel_version }}.patch || true
fi
- name: 一些修复补丁
run: |
cd "$CONFIG/common"
FORMATTED_BRANCH="${{ inputs.android_version }}-${{ inputs.kernel_version }}"
# Fake Patch to fix failures
fake_patched=0
if [ "$FORMATTED_BRANCH" = "android15-6.6" ]; then
if ! grep -qxF $'\tunsigned int nr_subpages = __PAGE_SIZE / PAGE_SIZE;' ./fs/proc/task_mmu.c; then
echo "未找到 nr_subpages,正在进行补丁修复"
sed -i -e '/int ret = 0, copied = 0;/a \\tunsigned int nr_subpages \= __PAGE_SIZE \/ PAGE_SIZE;' -e '/int ret = 0, copied = 0;/a \\tpagemap_entry_t \*res = NULL;' ./fs/proc/task_mmu.c
fake_patched=1
fi
fi
if [ "$FORMATTED_BRANCH" = "android12-5.10" ] || [ "$FORMATTED_BRANCH" = "android13-5.10" ] || [ "$FORMATTED_BRANCH" = "android13-5.15" ]; then
if ! grep -qxF $'\tif (!vma_pages(vma))' ./fs/proc/task_mmu.c; then
echo "未找到 vma_pages,正在进行补丁修复"
fake_patched=1
fi
fi
if [ "$fake_patched" = 1 ]; then
if [ "$FORMATTED_BRANCH" = "android15-6.6" ]; then
if grep -qxF $'\tunsigned int nr_subpages = __PAGE_SIZE / PAGE_SIZE;' ./fs/proc/task_mmu.c; then
sed -i -e '/unsigned int nr_subpages \= __PAGE_SIZE \/ PAGE_SIZE;/d' -e '/pagemap_entry_t \*res = NULL;/d' ./fs/proc/task_mmu.c
fi
fi
if [ "$FORMATTED_BRANCH" = "android12-5.10" ] || [ "$FORMATTED_BRANCH" = "android13-5.10" ] || [ "$FORMATTED_BRANCH" = "android13-5.15" ]; then
if grep -qxF $'\t\tgoto show_pad;' ./fs/proc/task_mmu.c; then
sed -i -e 's/goto show_pad;/return 0;/' ./fs/proc/task_mmu.c
fi
fi
fi
- name: 应用新的HOOKS补丁
run: |
echo "更改为配置目录: $CONFIG..."
cd "$CONFIG/common"
if [ "${{ inputs.kernelsu_variant }}" == "Next" ]; then
echo "Applying hooks for KernelSU-Next..."
cp ../../kernel_patches/next/scope_min_manual_hooks_v1.4.patch ./
patch -p1 -F 3 < scope_min_manual_hooks_v1.4.patch
elif [ "${{ inputs.kernelsu_variant }}" == "SukiSU" ]; then
echo "Applying hooks for SukiSU..."
fi
- name: 复制源文件 & 应用LZ4KD & ZSTDN补丁
if: ${{ inputs.use_zram }}
run: |
echo "更改为配置目录: $CONFIG..."
cd "$CONFIG/common"
cp -r ../../SukiSU_patch/other/zram/lz4k/include/linux/* ./include/linux/
cp -r ../../SukiSU_patch/other/zram/lz4k/lib/* ./lib/
cp -r ../../SukiSU_patch/other/zram/lz4k/crypto/* ./crypto/
cp -r ../../SukiSU_patch/other/zram/lz4k_oplus ./lib/
cp ../../SukiSU_patch/other/zram/zram_patch/${{ inputs.kernel_version }}/lz4kd.patch ./
echo "正在打lz4kd补丁"
patch -p1 -F 3 < lz4kd.patch || true
echo '完成LZ4KD补丁'
cp ../../SukiSU_patch/other/zram/zram_patch/${{ inputs.kernel_version }}/lz4k_oplus.patch ./
echo "正在打lz4k_oplus补丁"
patch -p1 -F 3 < lz4k_oplus.patch || true
echo '完成lz4k_oplus补丁'
- name: 应用隐藏某特征的补丁
run: |
echo "更改为配置目录: $CONFIG..."
cd "$CONFIG/common"
# Apply additional patch
if [ "${{ inputs.kernelsu_variant }}" == "SukiSU" ]; then
cp ../../SukiSU_patch/69_hide_stuff.patch ./
patch -p1 -F 3 < 69_hide_stuff.patch
else
cp ../../kernel_patches/69_hide_stuff.patch ./
patch -p1 -F 3 < 69_hide_stuff.patch
fi
- name: LZ4KD & Lz4k_oplus配置
if: ${{ inputs.use_zram }}
run: |
set -x
set -e
echo "写入LZ4KD&ZSTDN config依赖"
CONFIG_FILE="$CONFIG/common/arch/arm64/configs/gki_defconfig"
if [ "${{ inputs.kernel_version }}" = "5.10" ]; then
echo "CONFIG_ZSMALLOC=y" >> "$CONFIG_FILE"
echo "CONFIG_ZRAM=y" >> "$CONFIG_FILE"
echo "CONFIG_MODULE_SIG=n" >> "$CONFIG_FILE"
echo "CONFIG_CRYPTO_LZO=y" >> "$CONFIG_FILE"
echo "CONFIG_ZRAM_DEF_COMP_LZ4KD=y" >> "$CONFIG_FILE"
fi
if [ "${{ inputs.kernel_version }}" != "6.6" ] && [ "${{ inputs.kernel_version }}" != "5.10" ]; then
# sed -i 's/CONFIG_MODULE_SIG=y/CONFIG_MODULE_SIG=n/g' "$CONFIG_FILE"
if grep -q "CONFIG_ZSMALLOC" -- "$CONFIG_FILE"; then
echo "提示:文件 $CONFIG_FILE 包含字符串 CONFIG_ZSMALLOC。"
sed -i 's/CONFIG_ZSMALLOC=m/CONFIG_ZSMALLOC=y/g' "$CONFIG_FILE"
else
echo "警告:文件 $CONFIG_FILE 不包含字符串 CONFIG_ZSMALLOC。"
echo "CONFIG_ZSMALLOC=y" >> "$CONFIG_FILE"
fi
sed -i 's/CONFIG_ZRAM=m/CONFIG_ZRAM=y/g' "$CONFIG_FILE"
fi
if [ "${{ inputs.kernel_version }}" = "6.6" ]; then
echo "CONFIG_ZSMALLOC=y" >> "$CONFIG_FILE"
sed -i 's/CONFIG_ZRAM=m/CONFIG_ZRAM=y/g' "$CONFIG_FILE"
fi
if [ "${{ inputs.android_version }}" = "android14" ] || [ "${{ inputs.android_version }}" = "android15" ]; then
sed -i 's/"drivers\/block\/zram\/zram\.ko",//g; s/"mm\/zsmalloc\.ko",//g' "$CONFIG/common/modules.bzl"
echo "CONFIG_MODULE_SIG_FORCE=n" >> "$CONFIG_FILE"
echo 'Android14_Bazel:已修复zram&zsmalloc'
fi
if grep -q "CONFIG_ZSMALLOC=y" "$CONFIG_FILE" && grep -q "CONFIG_ZRAM=y" "$CONFIG_FILE"; then
echo "CONFIG_CRYPTO_LZ4HC=y" >> "$CONFIG_FILE"
echo "CONFIG_CRYPTO_LZ4K=y" >> "$CONFIG_FILE"
echo "CONFIG_CRYPTO_LZ4KD=y" >> "$CONFIG_FILE"
echo "CONFIG_CRYPTO_842=y" >> "$CONFIG_FILE"
echo "CONFIG_CRYPTO_LZ4K_OPLUS=y" >> "$CONFIG_FILE"
echo "CONFIG_ZRAM_WRITEBACK=y" >> "$CONFIG_FILE"
fi
- name: 设置BBR为默认拥塞算法
if: ${{ inputs.set_defbbr }}
run: |
CONFIG_FILE="$CONFIG/common/arch/arm64/configs/gki_defconfig"
echo "Changing to configuration directory: $CONFIG_FILE..."
echo "CONFIG_DEFAULT_BBR=y" >> "$CONFIG_FILE"
- name: 添加SUSFS配置设置
run: |
echo "更改为配置目录: $CONFIG..."
cd "$CONFIG"
echo "Adding configuration settings to gki_defconfig..."
# Add KSU configuration settings
echo "CONFIG_KSU=y" >> ./common/arch/arm64/configs/gki_defconfig
if [ "${{ inputs.kernelsu_variant }}" == "Next" ]; then
echo "CONFIG_KSU_KPROBES_HOOK=n" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_KSU_SUSFS_SUS_SU=n" >> ./common/arch/arm64/configs/gki_defconfig
elif [ "${{ inputs.kernelsu_variant }}" == "SukiSU" ]; then
echo "CONFIG_KPM=y" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_KSU_SUSFS_SUS_SU=n" >> ./common/arch/arm64/configs/gki_defconfig
elif [ "${{ inputs.kernelsu_variant }}" == "MKSU" ]; then
echo "CONFIG_KSU_SUSFS_SUS_SU=n" >> ./common/arch/arm64/configs/gki_defconfig
fi
# Add additional tmpfs config setting
echo "CONFIG_TMPFS_XATTR=y" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_TMPFS_POSIX_ACL=y" >> ./common/arch/arm64/configs/gki_defconfig
# Add additional config setting
echo "CONFIG_IP_NF_TARGET_TTL=y" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_IP6_NF_TARGET_HL=y" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_IP6_NF_MATCH_HL=y" >> ./common/arch/arm64/configs/gki_defconfig
# Add BBR Config
echo "CONFIG_TCP_CONG_ADVANCED=y" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_TCP_CONG_BBR=y" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_NET_SCH_FQ=y" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_TCP_CONG_BIC=n" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_TCP_CONG_WESTWOOD=n" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_TCP_CONG_HTCP=n" >> ./common/arch/arm64/configs/gki_defconfig
# Add SUSFS configuration settings
echo "CONFIG_KSU_SUSFS=y" >> ./common/arch/arm64/configs/gki_defconfig
echo "CONFIG_KSU_SUSFS_SUS_MAP=y" >> ./common/arch/arm64/configs/gki_defconfig
if [ "${{ inputs.kernel_version }}" != "6.6" ]; then
echo "CONFIG_KSU_SUSFS_SUS_PATH=y" >> ./common/arch/arm64/configs/gki_defconfig
else
echo "CONFIG_KSU_SUSFS_SUS_PATH=n" >> ./common/arch/arm64/configs/gki_defconfig
fi
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_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
# Remove check_defconfig
sed -i 's/check_defconfig//' ./common/build.config.gki
- name: 配置内核名称
run: |
echo "更改为配置目录: $CONFIG..."
cd "$CONFIG"
if [ ! -z ${{ inputs.version }} ]; then
echo "版本号不为空"
sed -i '$s|echo "\$res"|echo "${{ inputs.version }}"|' ./common/scripts/setlocalversion
else
echo "版本号为空,使用默认值"
sed -i '$s|echo "\$res"|echo "\$res-zakozakoooooo-1145141919"|' ./common/scripts/setlocalversion
fi
# 如果你需要改构建时间,请把以下变量 CURRENT_TIME 修改为如下例子字符串,如:CURRENT_TIME="Sat Jun 07 06:29:29 UTC 2025"
# 该字符串表示 UTC时间: 2025年6月7日 06:29:29,"Sat" 是星期六的缩写,而 "Jun" 是六月的缩写
# 如果你想使用北京时间应为:CURRENT_TIME="Sat Jun 07 14:29:29 CST 2025"
CURRENT_TIME=$(date -u +"%a %b %d %H:%M:%S UTC %Y")
echo "CURRENT_TIME=$CURRENT_TIME"
perl -pi -e "s{UTS_VERSION=\"\\\$\(echo \\\$UTS_VERSION \\\$CONFIG_FLAGS \\\$TIMESTAMP \\| cut -b -\\\$UTS_LEN\)\"}{UTS_VERSION=\"#1 SMP PREEMPT $CURRENT_TIME\"}" ./common/scripts/mkcompile_h
# Apply specific Makefile modification for kernel versions 6.1 and 6.6 only
if [ "${{ inputs.kernel_version }}" = "6.1" ] || [ "${{ inputs.kernel_version }}" = "6.6" ]; then
sed -i -e "s|\$(preempt-flag-y) \"\$(build-timestamp)\"|\$(preempt-flag-y) \"$CURRENT_TIME\"|" ./common/init/Makefile
fi
if [ -f "build/build.sh" ]; then
sed -i 's/-dirty//' ./common/scripts/setlocalversion
else
sed -i '/^[[:space:]]*"protected_exports_list"[[:space:]]*:[[:space:]]*"android\/abi_gki_protected_exports_aarch64",$/d' ./common/BUILD.bazel
rm -rf ./common/android/abi_gki_protected_exports_*
sed -i "/stable_scmversion_cmd/s/-maybe-dirty//g" ./build/kernel/kleaf/impl/stamp.bzl
# sed -E -i '/^CONFIG_LOCALVERSION=/ s/(.*)"$/\1"/' ./common/arch/arm64/configs/gki_defconfig
if [ ! -z ${{ inputs.version }} ]; then
sed -i '/^CONFIG_LOCALVERSION=/ s/="\([^"]*\)"/="${{ inputs.version }}"/' ./common/arch/arm64/configs/gki_defconfig
fi
fi
- name: Build with retry
uses: nick-fields/retry@v3
with:
timeout_minutes: 30
max_attempts: 3
retry_on: timeout
command: |
set -e
set -x
cd "$CONFIG"
# 替换 BUILD_SYSTEM_DLKM=1 为 BUILD_SYSTEM_DLKM=0
sed -i 's/BUILD_SYSTEM_DLKM=1/BUILD_SYSTEM_DLKM=0/' common/build.config.gki.aarch64
# 删除 MODULES_ORDER=android/gki_aarch64_modules 行
sed -i '/MODULES_ORDER=android\/gki_aarch64_modules/d' common/build.config.gki.aarch64
sed -i '/KMI_SYMBOL_LIST_STRICT_MODE/d' common/build.config.gki.aarch64
echo "Building the kernel..."
if [ -f "build/build.sh" ]; then
LTO=thin BUILD_CONFIG=common/build.config.gki.aarch64 build/build.sh CC="/usr/bin/ccache clang" || exit 1
else
tools/bazel build --disk_cache=/home/runner/.cache/bazel --config=fast --lto=thin //common:kernel_aarch64_dist || exit 1
fi
ccache --show-stats
- name: 修补 Image 文件 安卓12和安卓13(仅限sukisu)
if: ${{ inputs.use_kpm && inputs.kernelsu_variant == 'SukiSU' && (inputs.android_version == 'android12' || inputs.android_version == 'android13') }}
run: |
if [ "${{ inputs.kernel_version }}" != "6.6" ]; then
echo "Patching Image file..."
cd "$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist"
curl -LSs "https://raw.githubusercontent.com/ShirkNeko/SukiSU_patch/refs/heads/main/kpm/patch_linux" -o patch
chmod 777 patch
./patch
rm -rf Image
mv oImage Image
cd ../../../..
fi
- name: 修补 Image 文件 安卓14和安卓15(仅限sukisu)
if: ${{ inputs.use_kpm && inputs.kernelsu_variant == 'SukiSU' && (inputs.android_version == 'android14' || inputs.android_version == 'android15') }}
run: |
if [ "${{ inputs.kernel_version }}" != "6.6" ]; then
echo "Patching Image file..."
cd "$CONFIG/bazel-bin/common/kernel_aarch64/"
curl -LSs "https://raw.githubusercontent.com/ShirkNeko/SukiSU_patch/refs/heads/main/kpm/patch_linux" -o patch
chmod 777 patch
./patch
rm -rf Image
mv oImage Image
cd ../../..
fi
- name: 创建Bootimgs文件夹并复制镜像
if: ${{ inputs.android_version == 'android12' || inputs.android_version == 'android13' }}
run: |
echo "更改为配置目录: $CONFIG..."
mkdir bootimgs
echo "Creating bootimgs folder and copying images..."
cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image ./bootimgs
cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image.lz4 ./bootimgs
cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image ./
cp ./$CONFIG/out/${{ inputs.android_version }}-${{ inputs.kernel_version }}/dist/Image.lz4 ./
# Create gzip of the Image file
gzip -n -k -f -9 ./Image > ./Image.gz
- name: 创建Bootimgs文件夹并复制镜像
if: ${{ inputs.android_version == 'android14' || inputs.android_version == 'android15' }}
run: |
echo "更改为配置目录: $CONFIG..."
mkdir bootimgs
echo "Creating bootimgs folder and copying images..."
cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image ./bootimgs
cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image.lz4 ./bootimgs
cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image ./
cp ./$CONFIG/bazel-bin/common/kernel_aarch64/Image.lz4 ./
# Create gzip of the Image file
gzip -n -k -f -9 ./Image > ./Image.gz
- name: 创建不同格式的ZIP文件
run: |
echo "Creating zip files for all formats..."
cd ./AnyKernel3
# Create and upload zip for each format
ZIP_NAME="${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-AnyKernel3.zip"
echo "Creating zip file: $ZIP_NAME..."
mv ../Image ./Image
zip -r "../$ZIP_NAME" ./*
rm ./Image
ZIP_NAME="${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-AnyKernel3-lz4.zip"
echo "Creating zip file: $ZIP_NAME..."
mv ../Image.lz4 ./Image.lz4
zip -r "../$ZIP_NAME" ./*
rm ./Image.lz4
ZIP_NAME="${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-AnyKernel3-gz.zip"
echo "Creating zip file: $ZIP_NAME..."
mv ../Image.gz ./Image.gz
zip -r "../$ZIP_NAME" ./*
rm ./Image.gz
- name: 运行boot镜像 ${{ inputs.android_version }} 编译脚本
if: ${{ inputs.android_version == 'android12' }}
run: |
echo "更改为配置目录: $CONFIG..."
cd bootimgs
GKI_URL=https://dl.google.com/android/gki/gki-certified-boot-android12-5.10-"${{ inputs.os_patch_level }}"_"${{ inputs.revision }}".zip
FALLBACK_URL=https://dl.google.com/android/gki/gki-certified-boot-android12-5.10-2023-01_r1.zip
# Check if the GKI URL is available
echo "Checking if GKI kernel URL is reachable: $GKI_URL"
status=$(curl -sL -w "%{http_code}" "$GKI_URL" -o /dev/null)
if [ "$status" = "200" ]; then
echo "[+] Downloading from GKI_URL"
curl -Lo gki-kernel.zip "$GKI_URL"
else
echo "[+] $GKI_URL not found, using $FALLBACK_URL"
curl -Lo gki-kernel.zip "$FALLBACK_URL"
fi
# Unzip the downloaded kernel and remove the zip
echo "Unzipping the downloaded kernel..."
unzip gki-kernel.zip && rm gki-kernel.zip
echo "Unpacking boot.img..."
FULL_PATH=$(pwd)/boot-5.10.img
echo "Unpacking using: $FULL_PATH"
echo "Running unpack_bootimg.py..."
$UNPACK_BOOTIMG --boot_img="$FULL_PATH"
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 --ramdisk out/ramdisk --os_version 12.0.0 --os_patch_level "${{ inputs.os_patch_level }}"
$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 ../${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot.img
echo "Building boot-gz.img"
$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 }}"
$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 ../${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot-gz.img
echo "Building boot-lz4.img"
$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 }}"
$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 ../${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot-lz4.img
- name: 运行boot镜像 ${{ inputs.android_version }} 编译脚本
if: ${{ inputs.android_version == 'android13' || inputs.android_version == 'android14' || inputs.android_version == 'android15' }}
run: |
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 ../${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-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 ../${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-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 ../${{ inputs.android_version }}-${{ inputs.kernel_version }}.${{ inputs.sub_level }}-${{ inputs.os_patch_level }}-boot-lz4.img
- name: 上传编译资产
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.kernelsu_variant }}_kernel-${{ env.CONFIG }}
path: |
*AnyKernel3.zip
*.img