-
Notifications
You must be signed in to change notification settings - Fork 1
285 lines (264 loc) · 12.5 KB
/
build-kernel.yml
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
name: Build Kernel
on:
workflow_dispatch:
jobs:
build:
name: Build Kernel by ${{ github.actor }}
runs-on: ubuntu-latest
env:
CCACHE_COMPILERCHECK: "%compiler% -dumpmachine; %compiler% -dumpversion"
CCACHE_NOHASHDIR: "true"
CCACHE_HARDLINK: "true"
steps:
- uses: actions/checkout@v4
- name: Prepare Configuration
run: |
CONFIG_ENV=$(grep -w "CONFIG_ENV" config.env | head -n 1 | cut -d "=" -f 2)
CONFIG_LIST=(
KERNEL_SOURCE
KERNEL_SOURCE_BRANCH
KERNEL_CONFIG
KERNEL_IMAGE_NAME
ARCH
ADD_LOCALVERSION_TO_FILENAME
EXTRA_CMDS
USE_CUSTOM_CLANG
CUSTOM_CLANG_SOURCE
CUSTOM_CLANG_BRANCH
CUSTOM_CMDS
ENABLE_KERNELSU
KERNELSU_TAG
ADD_KPROBES_CONFIG
DISABLE-LTO
ADD_OVERLAYFS_CONFIG
DISABLE_CC_WERROR
APPLY_KSU_PATCH
USE_CUSTOM_ANYKERNEL3
CUSTOM_ANYKERNEL3_SOURCE
CUSTOM_ANYKERNEL3_BRANCH
ENABLE_CCACHE
NEED_DTBO
BUILD_BOOT_IMG
SOURCE_BOOT_IMAGE
KSU_EXPECTED_SIZE
KSU_EXPECTED_HASH
REMOVE_UNUSED_PACKAGES
)
for CONFIG in "${CONFIG_LIST[@]}"; do
if [[ "$CONFIG" == "EXTRA_CMDS" || "$CONFIG" == "CUSTOM_CMDS" ]]; then
echo "$CONFIG=$(grep -w "$CONFIG" "$CONFIG_ENV" | head -n 1 | cut -d ":" -f 2)" >> $GITHUB_ENV
else
echo "$CONFIG=$(grep -w "$CONFIG" "$CONFIG_ENV" | head -n 1 | cut -d "=" -f 2)" >> $GITHUB_ENV
fi
done
- name: Remove unused packages
if: env.REMOVE_UNUSED_PACKAGES == 'true'
uses: jlumbroso/free-disk-space@main
with:
tool-cache: ture
android: false
dotnet: true
haskell: true
large-packages: true
docker-images: true
swap-storage: false
- name: Set swap to 10G
uses: pierotofy/set-swap-space@master
with:
swap-size-gb: 10
- name: Setup build kernel environment
run: |
echo "BUILD_TIME=$(TZ=Asia/Shanghai date "+%Y%m%d%H%M")" >> $GITHUB_ENV
echo "DEVICE=$(echo ${{ env.KERNEL_CONFIG }} | sed 's!vendor/!!;s/_defconfig//;s/_user//;s/-perf//')" >> $GITHUB_ENV
sudo apt-get update
sudo apt-get install git ccache automake flex lzop bison gperf build-essential zip curl zlib1g-dev g++-multilib libxml2-utils bzip2 libbz2-dev libbz2-1.0 libghc-bzlib-dev squashfs-tools pngcrush schedtool dpkg-dev liblz4-tool make optipng maven libssl-dev pwgen libswitch-perl policycoreutils minicom libxml-sax-base-perl libxml-simple-perl bc libc6-dev-i386 lib32ncurses5-dev libx11-dev lib32z-dev libgl1-mesa-dev xsltproc unzip device-tree-compiler python2 python3
mkdir -p $GITHUB_WORKSPACE/kernel_workspace
- name: Download Custom-Clang
if: env.USE_CUSTOM_CLANG == 'true'
run: |
cd $GITHUB_WORKSPACE/kernel_workspace
if [[ ${{ env.CUSTOM_CLANG_SOURCE }} =~ git ]]; then
if [[ ${{ env.CUSTOM_CLANG_SOURCE }} == *'.tar.gz' ]]; then
wget -O clang.tar.gz ${{ env.CUSTOM_CLANG_SOURCE }}
mkdir clang-aosp
tar -C clang-aosp/ -zxvf clang.tar.gz
else
git clone ${{ env.CUSTOM_CLANG_SOURCE }} -b ${{ env.CUSTOM_CLANG_BRANCH }} clang-aosp --depth=1
fi
else
wget -O clang.zip ${{ env.CUSTOM_CLANG_SOURCE }}
mkdir clang-aosp
unzip clang.zip -d clang-aosp/
fi
- name: Download mkbootimg tools
if: env.BUILD_BOOT_IMG == 'true'
run: |
cd $GITHUB_WORKSPACE/kernel_workspace
git clone https://android.googlesource.com/platform/system/tools/mkbootimg tools -b master-kernel-build-2022 --depth=1
- name: Download kernel source
run: |
cd $GITHUB_WORKSPACE/kernel_workspace
git clone --recursive ${{ env.KERNEL_SOURCE }} -b ${{ env.KERNEL_SOURCE_BRANCH }} android-kernel --depth=1
if [[ ${{ env.ADD_LOCALVERSION_TO_FILENAME }} == 'true' ]]; then
echo "LOCALVERSION=$(cat android-kernel/localversion)" >> $GITHUB_ENV
else
echo "LOCALVERSION=" >> $GITHUB_ENV
fi
- name: Download Boot Image
run: |
cd $GITHUB_WORKSPACE/kernel_workspace
curl -H "Authorization: token ${{ secrets.NOX88 }}" -L -o boot.img ${{ secrets.BOOT_IMAGE_URL }}
if [ -f boot.img ]; then
echo "Boot image downloaded successfully."
else
echo "Failed to download boot image."
exit 1
fi
- name: Setup KernelSU
if: env.ENABLE_KERNELSU == 'true'
run: |
cd $GITHUB_WORKSPACE/kernel_workspace/android-kernel
curl -LSs "https://raw.githubusercontent.com/tiann/KernelSU/main/kernel/setup.sh" | bash -s ${{ env.KERNELSU_TAG }}
KSU_VERSION=$(cd KernelSU && expr $(/usr/bin/git rev-list --count HEAD) + 10200)
echo "UPLOADNAME=-KernelSU_$KSU_VERSION" >> $GITHUB_ENV
- name: Setup Configuration for Kernel
run: |
cd $GITHUB_WORKSPACE/kernel_workspace/android-kernel
if [ ${{ env.APPLY_KSU_PATCH }} = true ]; then
bash $GITHUB_WORKSPACE/patches/patches.sh
if grep -q "CONFIG_KSU" arch/${{ env.ARCH }}/configs/${{ env.KERNEL_CONFIG }}; then
sed -i 's/# CONFIG_KSU is not set/CONFIG_KSU=y/g' arch/${{ env.ARCH }}/configs/${{ env.KERNEL_CONFIG }}
sed -i 's/CONFIG_KSU=n/CONFIG_KSU=y/g' arch/${{ env.ARCH }}/configs/${{ env.KERNEL_CONFIG }}
else
echo "CONFIG_KSU=y" >> arch/${{ env.ARCH }}/configs/${{ env.KERNEL_CONFIG }}
fi
fi
if [ ${{ env.ADD_KPROBES_CONFIG }} = true -a ${{ env.APPLY_KSU_PATCH }} != true ]; then
echo "CONFIG_MODULES=y" >> arch/${{ env.ARCH }}/configs/${{ env.KERNEL_CONFIG }}
echo "CONFIG_KPROBES=y" >> arch/${{ env.ARCH }}/configs/${{ env.KERNEL_CONFIG }}
echo "CONFIG_HAVE_KPROBES=y" >> arch/${{ env.ARCH }}/configs/${{ env.KERNEL_CONFIG }}
echo "CONFIG_KPROBE_EVENTS=y" >> arch/${{ env.ARCH }}/configs/${{ env.KERNEL_CONFIG }}
fi
if [ ${{ env.ADD_OVERLAYFS_CONFIG }} = true ]; then
echo "CONFIG_OVERLAY_FS=y" >> arch/${{ env.ARCH }}/configs/${{ env.KERNEL_CONFIG }}
fi
if [ ${{ env.DISABLE-LTO }} = true ]; then
sed -i 's/CONFIG_LTO=y/CONFIG_LTO=n/' arch/${{ env.ARCH }}/configs/${{ env.KERNEL_CONFIG }}
sed -i 's/CONFIG_LTO_CLANG=y/CONFIG_LTO_CLANG=n/' arch/${{ env.ARCH }}/configs/${{ env.KERNEL_CONFIG }}
sed -i 's/CONFIG_THINLTO=y/CONFIG_THINLTO=n/' arch/${{ env.ARCH }}/configs/${{ env.KERNEL_CONFIG }}
echo "CONFIG_LTO_NONE=y" >> arch/${{ env.ARCH }}/configs/${{ env.KERNEL_CONFIG }}
fi
if [ ${{ env.DISABLE_CC_WERROR }} = true ]; then
echo "CONFIG_CC_WERROR=n" >> arch/${{ env.ARCH }}/configs/${{ env.KERNEL_CONFIG }}
fi
- name: Setup ccache
if: env.ENABLE_CCACHE == 'true'
uses: hendrikmuhs/ccache-action@v1.2
with:
key: build-kernel-${{ env.DEVICE }}${{ env.LOCALVERSION }}${{ env.UPLOADNAME }}
max-size: 2G
- name: Build kernel
run: |
cd $GITHUB_WORKSPACE/kernel_workspace/android-kernel
export PATH=$GITHUB_WORKSPACE/kernel_workspace/clang-aosp/bin:$PATH
export KBUILD_BUILD_HOST=Github-Action
export KBUILD_BUILD_USER=$(echo ${{ github.actor }} | tr A-Z a-z)
if [ ! -z ${{ env.KSU_EXPECTED_SIZE }} ] && [ ! -z ${{ env.KSU_EXPECTED_HASH }} ]; then
export KSU_EXPECTED_SIZE=${{ env.KSU_EXPECTED_SIZE }}
export KSU_EXPECTED_HASH=${{ env.KSU_EXPECTED_HASH }}
fi
make -j$(nproc --all) CC=clang O=out ARCH=${{ env.ARCH }} ${{ env.CUSTOM_CMDS }} ${{ env.EXTRA_CMDS }} ${{ env.GCC_64 }} ${{ env.GCC_32 }} ${{ env.KERNEL_CONFIG }}
if [ ${{ env.ENABLE_CCACHE }} = true ]; then
make -j$(nproc --all) CC="ccache clang" O=out ARCH=${{ env.ARCH }} ${{ env.CUSTOM_CMDS }} ${{ env.EXTRA_CMDS }} ${{ env.GCC_64 }} ${{ env.GCC_32 }}
else
make -j$(nproc --all) CC=clang O=out ARCH=${{ env.ARCH }} ${{ env.CUSTOM_CMDS }} ${{ env.EXTRA_CMDS }} ${{ env.GCC_64 }} ${{ env.GCC_32 }}
fi
- name: Check a kernel output files
run: |
cd $GITHUB_WORKSPACE/kernel_workspace
if [ -f android-kernel/out/arch/${{ env.ARCH }}/boot/${{ env.KERNEL_IMAGE_NAME }} ]; then
echo "CHECK_FILE_IS_OK=true" >> $GITHUB_ENV
else
echo "Kernel output file is empty"
exit 1
fi
if [ ${{ env.NEED_DTBO }} = true ]; then
if [ -f android-kernel/out/arch/${{ env.ARCH }}/boot/dtbo.img ]; then
echo "CHECK_DTBO_IS_OK=true" >> $GITHUB_ENV
else
echo "DTBO image is empty"
exit 1
fi
fi
- name: Make Anykernel3
if: env.CHECK_FILE_IS_OK == 'true' && env.USE_CUSTOM_ANYKERNEL3 != 'true'
run: |
cd $GITHUB_WORKSPACE/kernel_workspace
git clone https://github.com/osm0sis/AnyKernel3 --depth=1 AnyKernel3
sed -i 's/do.devicecheck=1/do.devicecheck=0/g' AnyKernel3/anykernel.sh
sed -i 's!BLOCK=/dev/block/platform/omap/omap_hsmmc.0/by-name/boot;!BLOCK=auto;!g' AnyKernel3/anykernel.sh
sed -i 's/IS_SLOT_DEVICE=0;/is_slot_device=auto;/g' AnyKernel3/anykernel.sh
cp android-kernel/out/arch/${{ env.ARCH }}/boot/${{ env.KERNEL_IMAGE_NAME }} AnyKernel3/
if [ ${{ env.CHECK_DTBO_IS_OK }} = true ]; then
cp android-kernel/out/arch/${{ env.ARCH }}/boot/dtbo.img AnyKernel3/
fi
rm -rf AnyKernel3/.git* AnyKernel3/README.md
- name: Make Custom-Anykernel3
if: env.CHECK_FILE_IS_OK == 'true' && env.USE_CUSTOM_ANYKERNEL3 == 'true'
run: |
cd $GITHUB_WORKSPACE/kernel_workspace
if [[ ${{ env.CUSTOM_ANYKERNEL3_SOURCE }} =~ git ]]; then
if [[ ${{ env.CUSTOM_ANYKERNEL3_SOURCE }} == *'.tar.gz' ]]; then
wget -O AnyKernel3.tar.gz ${{ env.CUSTOM_ANYKERNEL3_SOURCE }}
mkdir AnyKernel3
tar -C AnyKernel3/ -zxvf AnyKernel3.tar.gz
else
git clone ${{ env.CUSTOM_ANYKERNEL3_SOURCE }} -b ${{ env.CUSTOM_ANYKERNEL3_BRANCH }} --depth=1 AnyKernel3
fi
else
wget -O AnyKernel3.zip ${{ env.CUSTOM_ANYKERNEL3_SOURCE }}
mkdir AnyKernel3
unzip AnyKernel3.zip -d AnyKernel3/
fi
cp android-kernel/out/arch/${{ env.ARCH }}/boot/${{ env.KERNEL_IMAGE_NAME }} AnyKernel3/
if [ ${{ env.CHECK_DTBO_IS_OK }} = true ]; then
cp android-kernel/out/arch/${{ env.ARCH }}/boot/dtbo.img AnyKernel3/
fi
rm -rf AnyKernel3/.git* AnyKernel3/README.md
- name: Make boot image
if: env.HAVE_SOURCE_BOOT_IMAGE == 'true' && env.CHECK_FILE_IS_OK == 'true'
run: |
cd $GITHUB_WORKSPACE/kernel_workspace
tools/unpack_bootimg.py --boot_img boot-source.img
cp android-kernel/out/arch/${{ env.ARCH }}/boot/${{ env.KERNEL_IMAGE_NAME }} out/kernel
tools/mkbootimg.py ${{ env.FORMAT_MKBOOTING }} -o boot.img
if [ -f boot.img ]; then
echo "MAKE_BOOT_IMAGE_IS_OK=true" >> $GITHUB_ENV
else
echo "Boot image is empty"
exit 1
fi
- name: Upload ${{ env.KERNEL_IMAGE_NAME }}
if: env.CHECK_FILE_IS_OK == 'true'
uses: actions/upload-artifact@v4
with:
name: ${{ env.KERNEL_IMAGE_NAME }}${{ env.LOCALVERSION }}${{ env.UPLOADNAME }}-${{ env.DEVICE }}-${{ env.BUILD_TIME }}
path: kernel_workspace/android-kernel/out/arch/${{ env.ARCH }}/boot/${{ env.KERNEL_IMAGE_NAME }}
- name: Upload AnyKernel3
if: env.CHECK_FILE_IS_OK == 'true'
uses: actions/upload-artifact@v4
with:
name: AnyKernel3${{ env.LOCALVERSION }}${{ env.UPLOADNAME }}-${{ env.DEVICE }}-${{ env.BUILD_TIME }}
path: kernel_workspace/AnyKernel3/*
- name: Upload DTBO image
if: env.CHECK_DTBO_IS_OK == 'true'
uses: actions/upload-artifact@v4
with:
name: dtbo-${{ env.DEVICE }}-${{ env.BUILD_TIME }}
path: kernel_workspace/android-kernel/out/arch/${{ env.ARCH }}/boot/dtbo.img
- name: Upload boot image
if: env.MAKE_BOOT_IMAGE_IS_OK == 'true'
uses: actions/upload-artifact@v4
with:
name: boot${{ env.LOCALVERSION }}${{ env.UPLOADNAME }}-${{ env.DEVICE }}-${{ env.BUILD_TIME }}
path: kernel_workspace/boot.img