forked from ExtremeXT/M62-backport
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·443 lines (392 loc) · 13.1 KB
/
build.sh
File metadata and controls
executable file
·443 lines (392 loc) · 13.1 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
#!/bin/bash
abort()
{
cd -
echo "-----------------------------------------------"
echo "Kernel compilation failed! Exiting..."
echo "-----------------------------------------------"
exit -1
}
unset_flags()
{
cat << EOF
Usage: $(basename "$0") [options]
Options:
-m, --model [value] Specify the model code of the phone
-k, --ksu [Y/n] Include KernelSU
-r, --recovery [y/N] Compile kernel for an Android Recovery
-g, --gpu-max [value] Set GPU max MHz (ex: 806) using forOC tables (default: 702)
EOF
}
apply_gpu_tables()
{
local max_khz="$1"
local src_dtsi="$PWD/forOC/exynos9820-mali_tables.dtsi"
local dst_dtsi="$PWD/arch/arm64/boot/dts/exynos/exynos9820-mali_tables.dtsi"
local src_cal="$PWD/forOC/g3d_dvfs_table.h"
local dst_cal="$PWD/drivers/soc/samsung/cal-if/g3d_dvfs_table.h"
if [ ! -f "$src_dtsi" ] || [ ! -f "$src_cal" ]; then
echo "GPU table sources not found under forOC; skipping GPU table update."
return 1
fi
if ! command -v python3 >/dev/null 2>&1; then
echo "python3 not found; cannot update GPU tables."
return 1
fi
python3 - "$max_khz" "$src_dtsi" "$dst_dtsi" "$src_cal" "$dst_cal" << 'PY'
import re
import sys
from pathlib import Path
max_khz = int(sys.argv[1])
src_dtsi = Path(sys.argv[2])
dst_dtsi = Path(sys.argv[3])
src_cal = Path(sys.argv[4])
dst_cal = Path(sys.argv[5])
def parse_table(lines, key):
start = next(i for i, l in enumerate(lines) if key in l)
end = next(i for i in range(start + 1, len(lines)) if ">;" in lines[i])
entries = []
indent = None
for line in lines[start + 1:end + 1]:
stripped = line.strip()
if not stripped or stripped.startswith("/*"):
continue
cleaned = re.sub(r">;\s*$", "", stripped)
cleaned = re.sub(r">\s*$", "", cleaned)
parts = cleaned.split()
if not parts or not parts[0].isdigit():
continue
freq = int(parts[0])
if indent is None:
indent = line[:len(line) - len(line.lstrip())]
entries.append((freq, cleaned))
if indent is None:
indent = "\t"
return start, end, entries, indent
def update_size_line(line, row, cols):
return re.sub(r"<\s*\d+\s+%d\s*>" % cols, f"<{row} {cols}>", line)
def update_clock_line(line, value):
return re.sub(r"<\s*\d+\s*>", f"<{value}>", line)
def write_dtsi():
lines = src_dtsi.read_text().splitlines(True)
start, end, entries, indent = parse_table(lines, "gpu_dvfs_table = <")
filtered = [e for e in entries if e[0] <= max_khz]
if not any(e[0] == max_khz for e in filtered):
raise SystemExit(f"GPU max {max_khz} not found in DVFS table")
dvfs_block = []
for idx, (_, cleaned) in enumerate(filtered):
suffix = " >;\n" if idx == len(filtered) - 1 else "\n"
dvfs_block.append(f"{indent}{cleaned}{suffix}")
lines[start + 1:end + 1] = dvfs_block
start, end, entries, indent = parse_table(lines, "gpu_cl_pmqos_table = <")
filtered_cl = [e for e in entries if e[0] <= max_khz]
if not any(e[0] == max_khz for e in filtered_cl):
raise SystemExit(f"GPU max {max_khz} not found in PMQoS table")
cl_block = []
for idx, (_, cleaned) in enumerate(filtered_cl):
suffix = " >;\n" if idx == len(filtered_cl) - 1 else "\n"
cl_block.append(f"{indent}{cleaned}{suffix}")
lines[start + 1:end + 1] = cl_block
for i, line in enumerate(lines):
if line.strip().startswith("gpu_dvfs_table_size"):
lines[i] = update_size_line(line, len(filtered), 8)
elif line.strip().startswith("gpu_cl_pmqos_table_size"):
lines[i] = update_size_line(line, len(filtered_cl), 5)
elif line.strip().startswith("gpu_max_clock_limit"):
lines[i] = update_clock_line(line, max_khz)
elif line.strip().startswith("gpu_max_clock"):
lines[i] = update_clock_line(line, max_khz)
dst_dtsi.write_text("".join(lines))
def write_cal():
lines = src_cal.read_text().splitlines(True)
start = next(i for i, l in enumerate(lines)
if "G3D_DVFS_TABLE_ENTRY_LIST" in l)
i = start + 1
entries = []
indent = None
while i < len(lines):
line = lines[i]
if line.strip().startswith("#endif") or not line.strip():
break
m = re.search(r"\bX\((\d+),", line)
if m:
if indent is None:
indent = line[:len(line) - len(line.lstrip())]
entries.append((int(m.group(1)), line))
i += 1
if indent is None:
indent = "\t"
filtered = [(f, l) for (f, l) in entries if f <= max_khz]
if not any(f == max_khz for f, _ in filtered):
raise SystemExit(f"GPU max {max_khz} not found in CAL table")
new_list = []
for idx, (_, line) in enumerate(filtered):
core = line.rstrip().rstrip("\\").rstrip()
suffix = "\n" if idx == len(filtered) - 1 else " \\\n"
new_list.append(f"{indent}{core}{suffix}")
lines[start + 1:i] = new_list
dst_cal.write_text("".join(lines))
write_dtsi()
write_cal()
PY
}
DEFAULT_GPU_MAX_BEYOND=702
DEFAULT_GPU_MAX_D=754
while [[ $# -gt 0 ]]; do
case "$1" in
--model|-m)
MODEL="$2"
shift 2
;;
--gpu-max|-g)
GPU_MAX="$2"
shift 2
;;
--ksu|-k)
KSU_OPTION="$2"
shift 2
;;
--recovery|-r)
RECOVERY_OPTION="$2"
shift 2
;;
*)
unset_flags
exit 1
;;
esac
done
echo "Preparing the build environment..."
pushd $(dirname "$0") > /dev/null
CORES=`cat /proc/cpuinfo | grep -c processor`
# Define toolchain variables
CLANG_DIR=$PWD/toolchain/neutron_18
PATH=$CLANG_DIR/bin:$PATH
# Check if toolchain exists
if [ ! -f "$CLANG_DIR/bin/clang-18" ]; then
echo "-----------------------------------------------"
echo "Toolchain not found! Downloading..."
echo "-----------------------------------------------"
rm -rf $CLANG_DIR
mkdir -p $CLANG_DIR
pushd toolchain/neutron_18 > /dev/null
bash <(curl -s "https://raw.githubusercontent.com/Neutron-Toolchains/antman/main/antman") -S=05012024
echo "-----------------------------------------------"
echo "Patching toolchain..."
echo "-----------------------------------------------"
bash <(curl -s "https://raw.githubusercontent.com/Neutron-Toolchains/antman/main/antman") --patch=glibc
echo "-----------------------------------------------"
echo "Cleaning up..."
popd > /dev/null
fi
MAKE_ARGS=(
LLVM=1
LLVM_IAS=1
ARCH=arm64
O=out
)
# Prefer content-addressed compiler cache so rebuilds in fresh checkouts are fast
if command -v ccache >/dev/null 2>&1; then
echo "ccache detected, enabling compiler cache..."
export CCACHE_DIR="${CCACHE_DIR:-$PWD/.ccache}"
export CCACHE_BASEDIR="${CCACHE_BASEDIR:-$PWD}"
export CCACHE_COMPILERCHECK="${CCACHE_COMPILERCHECK:-content}"
export CCACHE_NOHASHDIR="${CCACHE_NOHASHDIR:-1}"
export CCACHE_SLOPPINESS="${CCACHE_SLOPPINESS:-file_macro,locale,time_macros}"
MAKE_ARGS+=(CC="ccache clang" HOSTCC="ccache clang" HOSTCXX="ccache clang++")
else
echo "ccache not found, building without compiler cache."
fi
# Define specific variables
case $MODEL in
beyond0lte)
BOARD=SRPRI28A016KU
SOC=exynos9820
;;
beyond0lteks)
BOARD=SRPRI28C007KU
SOC=exynos9820
;;
beyond1lte)
BOARD=SRPRI28B016KU
SOC=exynos9820
;;
beyond1lteks)
BOARD=SRPRI28D007KU
SOC=exynos9820
;;
beyond2lte)
BOARD=SRPRI17C016KU
SOC=exynos9820
;;
beyond2lteks)
BOARD=SRPRI28E007KU
SOC=exynos9820
;;
beyondx)
BOARD=SRPSC04B014KU
SOC=exynos9820
;;
beyondxks)
BOARD=SRPRK21D006KU
SOC=exynos9820
;;
d1)
BOARD=SRPSD26B009KU
SOC=exynos9825
;;
d1xks)
BOARD=SRPSD23A002KU
SOC=exynos9825
;;
d2s)
BOARD=SRPSC14B009KU
SOC=exynos9825
;;
d2x)
BOARD=SRPSC14C009KU
SOC=exynos9825
;;
d2xks)
BOARD=SRPSD23C002KU
SOC=exynos9825
;;
*)
unset_flags
exit
esac
if [[ "$RECOVERY_OPTION" == "y" ]]; then
RECOVERY=recovery.config
KSU_OPTION=n
fi
if [ -z $KSU_OPTION ]; then
read -p "Include KernelSU (y/N): " KSU_OPTION
fi
if [[ "$KSU_OPTION" == "y" ]]; then
KSU=ksu.config
fi
if [ -z "$GPU_MAX" ]; then
if [[ "$MODEL" == d* ]]; then
GPU_MAX=$DEFAULT_GPU_MAX_D
else
GPU_MAX=$DEFAULT_GPU_MAX_BEYOND
fi
fi
if [ -n "$GPU_MAX" ]; then
if ! [[ "$GPU_MAX" =~ ^[0-9]+$ ]]; then
echo "Invalid GPU max value: $GPU_MAX"
exit 1
fi
if [ "$GPU_MAX" -lt 10000 ]; then
GPU_MAX_KHZ=$((GPU_MAX * 1000))
else
GPU_MAX_KHZ=$GPU_MAX
fi
echo "Applying GPU max: ${GPU_MAX_KHZ} kHz (from forOC tables)"
apply_gpu_tables "$GPU_MAX_KHZ" || abort
fi
rm -rf build/out/$MODEL
mkdir -p build/out/$MODEL/zip/files
mkdir -p build/out/$MODEL/zip/META-INF/com/google/android
# Build kernel image
echo "-----------------------------------------------"
echo "Defconfig: "$KERNEL_DEFCONFIG""
if [ -z "$KSU" ]; then
echo "KSU: No"
else
echo "KSU: Yes"
fi
if [ -z "$RECOVERY" ]; then
echo "Recovery: N"
else
echo "Recovery: Y"
fi
echo "-----------------------------------------------"
echo "Building kernel using "$KERNEL_DEFCONFIG""
echo "Generating configuration file..."
echo "-----------------------------------------------"
make "${MAKE_ARGS[@]}" -j$CORES exynos9820_defconfig $MODEL.config $KSU $RECOVERY || abort
echo "Building kernel..."
echo "-----------------------------------------------"
make "${MAKE_ARGS[@]}" -j$CORES || abort
# Define constant variables
KERNEL_PATH=build/out/$MODEL/Image
KERNEL_OFFSET=0x00008000
RAMDISK_OFFSET=0xF0000000
SECOND_OFFSET=0xF0000000
TAGS_OFFSET=0x00000100
BASE=0x10000000
CMDLINE='loop.max_part=7'
HASHTYPE=sha1
HEADER_VERSION=1
OS_PATCH_LEVEL=2025-08
OS_VERSION=15.0.0
PAGESIZE=2048
RAMDISK=build/out/$MODEL/ramdisk.cpio.gz
OUTPUT_FILE=build/out/$MODEL/boot.img
## Build auxiliary boot.img files
# Copy kernel to build
cp out/arch/arm64/boot/Image build/out/$MODEL
echo "-----------------------------------------------"
# Build dtb
if [[ "$SOC" == "exynos9820" ]]; then
echo "Building common exynos9820 Device Tree Blob Image..."
echo "-----------------------------------------------"
./toolchain/mkdtimg cfg_create build/out/$MODEL/dtb.img build/dtconfigs/exynos9820.cfg -d out/arch/arm64/boot/dts/exynos
fi
if [[ "$SOC" == "exynos9825" ]]; then
echo "Building common exynos9825 Device Tree Blob Image..."
echo "-----------------------------------------------"
./toolchain/mkdtimg cfg_create build/out/$MODEL/dtb.img build/dtconfigs/exynos9825.cfg -d out/arch/arm64/boot/dts/exynos
fi
echo "-----------------------------------------------"
# Build dtbo
echo "Building Device Tree Blob Output Image for "$MODEL"..."
echo "-----------------------------------------------"
./toolchain/mkdtimg cfg_create build/out/$MODEL/dtbo.img build/dtconfigs/$MODEL.cfg -d out/arch/arm64/boot/dts/samsung
echo "-----------------------------------------------"
if [ -z "$RECOVERY" ]; then
# Build ramdisk
echo "Building RAMDisk..."
echo "-----------------------------------------------"
pushd build/ramdisk > /dev/null
find . ! -name . | LC_ALL=C sort | cpio -o -H newc -R root:root | gzip > ../out/$MODEL/ramdisk.cpio.gz || abort
popd > /dev/null
echo "-----------------------------------------------"
# Create boot image
echo "Creating boot image..."
echo "-----------------------------------------------"
./toolchain/mkbootimg --base $BASE --board $BOARD --cmdline "$CMDLINE" --hashtype $HASHTYPE \
--header_version $HEADER_VERSION --kernel $KERNEL_PATH --kernel_offset $KERNEL_OFFSET \
--os_patch_level $OS_PATCH_LEVEL --os_version $OS_VERSION --pagesize $PAGESIZE \
--ramdisk $RAMDISK --ramdisk_offset $RAMDISK_OFFSET --second_offset $SECOND_OFFSET \
--tags_offset $TAGS_OFFSET -o $OUTPUT_FILE || abort
# Build zip
echo "Building zip..."
echo "-----------------------------------------------"
cp build/out/$MODEL/boot.img build/out/$MODEL/zip/files/boot.img
cp build/out/$MODEL/dtb.img build/out/$MODEL/zip/files/dtb.img
cp build/out/$MODEL/dtbo.img build/out/$MODEL/zip/files/dtbo.img
cp build/update-binary build/out/$MODEL/zip/META-INF/com/google/android/update-binary
cp build/updater-script build/out/$MODEL/zip/META-INF/com/google/android/updater-script
version=$(grep -o 'CONFIG_LOCALVERSION="[^"]*"' arch/arm64/configs/exynos9820_defconfig | cut -d '"' -f 2)
version=${version:1}
if [ "$SOC" == "exynos9825" ]; then
version="${version}-N10"
else
version="${version}-S10"
fi
pushd build/out/$MODEL/zip > /dev/null
DATE=`date +"%d-%m-%Y_%H-%M-%S"`
if [[ "$KSU_OPTION" == "y" ]]; then
NAME="$version"_"$MODEL"_OFFICIAL_KSU_"$DATE".zip
else
NAME="$version"_"$MODEL"_OFFICIAL_"$DATE".zip
fi
# Store the generated archive inside the zip directory so CI artifact
# uploads can glob the file reliably.
zip -r "$NAME" .
popd > /dev/null
fi
popd > /dev/null
echo "Build finished successfully!"