forked from ophub/amlogic-s9xxx-armbian
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrecompile
executable file
·555 lines (488 loc) · 23.4 KB
/
recompile
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
#!/bin/bash
#============================================================================================
#
# Description: Run on Ubuntu-20.04-x86_64, compile linux kernel for armbian
# Copyright (C) 2020-2021 https://github.com/unifreq
# Copyright (C) 2020-2021 https://github.com/ophub/amlogic-s9xxx-armbian
#
#============================================================================================
#
# Command to compile the kernel: [ sudo ./recompile -r unifreq -k 5.4.170_5.10.90 ]
#
# ---------- Specify the code repository of github.com through the [ -r ] parameter ---------
#
# 01. [ sudo ./recompile -r owner ]
# 01. From the [ owner ], Search the [ linux-5.x.y ] named repository, branch is default
#
# 02. [ sudo ./recompile -r owner@branch ]
# 02. From the [ owner ], Search the [ linux-5.x.y ] named repository, branch is [ branch ]
#
# 03. [ sudo ./recompile -r owner/repo ]
# 03. From the [ owner ], Search the [ repo ] named repository, branch is default
#
# 04. [ sudo ./recompile -r owner/repo@branch ]
# 04. From the [ owner ], Search the [ repo ] named repository, branch is [ branch ]
#
# ---------- Specify the code repository of kernel.org through the [ -r ] parameter ---------
#
# 01. [ sudo ./recompile -r kernel.org ]
# 01. From the [ kernel.org ], download [ linux-5.x.y.tar.xz ] kernel zip file
#
#============================================================================================
#===== Do not modify the following parameter settings, Start =====
# Set environment variables
make_path=${PWD}
compile_path="${make_path}/compile-kernel"
kernel_path="${compile_path}/kernel"
out_kernel="${compile_path}/output"
config_dir="${compile_path}/tools/config"
uInitrd_dir="${compile_path}/tools/uInitrd"
script_dir="${compile_path}/tools/script"
moredtb_path="${make_path}/build-armbian/amlogic-dtb"
arch_info=$(arch)
auto_kernel="true"
build_kernel=("5.4.170" "5.10.90")
# Kernel custom name
custom_name="-meson64-dev"
# Set the default value of the [ -r ] parameter
# When set to [ -r kernel.org ], Kernel download from kernel.org
kernel_org_repo="https://cdn.kernel.org/pub/linux/kernel/v5.x/"
# Set the default for downloading kernel sources from github.com
repo_owner="unifreq"
repo_branch="main"
# Cross compile toolchain, run on ubuntu-20.04
toolchain_dir="/usr/local/toolchain_x86_64_aarch64"
dev_repo="https://github.com/ophub/script/releases/download/dev"
# armbian
armbian_rootfs_file="armbian_22.02.0_Aml_s922x_bullseye_5.10.93.tar.xz"
armbian_dir="${compile_path}/tools/armbian"
armbian_file="${armbian_dir}/armbian.img"
chroot_dir="${out_kernel}/chroot"
chroot_file="${chroot_dir}/armbian.img"
# gcc
#gcc_repo="https://developer.arm.com/-/media/Files/downloads/gnu-a/10.3-2021.07/binrel"
gcc_file="gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu.tar.xz"
# clang
#clang_repo="https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.0"
clang_file="clang+llvm-13.0.0-x86_64-linux-gnu-ubuntu-20.04.tar.xz"
# QEMU BINARY
qemu_binary_arm="qemu-arm-static"
qemu_binary_arm64="qemu-aarch64-static"
# Set font color
blue_font_prefix="\033[94m"
purple_font_prefix="\033[95m"
green_font_prefix="\033[92m"
yellow_font_prefix="\033[93m"
red_font_prefix="\033[91m"
font_color_suffix="\033[0m"
INFO="[${blue_font_prefix}INFO${font_color_suffix}]"
STEPS="[${purple_font_prefix}STEPS${font_color_suffix}]"
SUCCESS="[${green_font_prefix}SUCCESS${font_color_suffix}]"
WARNING="[${yellow_font_prefix}WARNING${font_color_suffix}]"
ERROR="[${red_font_prefix}ERROR${font_color_suffix}]"
#===== Do not modify the following parameter settings, End =======
error_msg() {
echo -e "${ERROR} ${1}"
exit 1
}
toolchain_check() {
cd ${make_path}
echo -e "${STEPS} Check the cross-compilation environment ..."
[ -d "${toolchain_dir}" ] || mkdir -p ${toolchain_dir}
# Download gcc
if [ ! -d "${toolchain_dir}/${gcc_file//.tar.xz/}/bin" ]; then
echo -e "${INFO} Download gcc [ ${gcc_file} ] ..."
wget -c "${dev_repo}/${gcc_file}" -O "${toolchain_dir}/${gcc_file}" >/dev/null 2>&1 && sync
tar -xJf ${toolchain_dir}/${gcc_file} -C ${toolchain_dir} && sync
rm -f ${toolchain_dir}/${gcc_file} && sync
[ -d "${toolchain_dir}/${gcc_file//.tar.xz/}/bin" ] || error_msg "The gcc is not set!"
fi
# Download clang
if [ ! -d "${toolchain_dir}/${clang_file//.tar.xz/}/bin" ]; then
echo -e "${INFO} Download clang [ ${clang_file} ] ..."
wget -c "${dev_repo}/${clang_file}" -O "${toolchain_dir}/${clang_file}" >/dev/null 2>&1 && sync
tar -xJf ${toolchain_dir}/${clang_file} -C ${toolchain_dir} && sync
rm -f ${toolchain_dir}/${clang_file} && sync
[ -d "${toolchain_dir}/${clang_file//.tar.xz/}/bin" ] || error_msg "The clang is not set!"
fi
# Download armbian
if [ ! -f "${armbian_file}" ]; then
echo -e "${INFO} Download armbian [ ${armbian_rootfs_file} ] ..."
rm -rf ${armbian_dir} 2>/dev/null && mkdir -p ${armbian_dir}
wget -c "${dev_repo}/${armbian_rootfs_file}" -O "${armbian_dir}/${armbian_rootfs_file}" >/dev/null 2>&1 && sync
tar -xJf ${armbian_dir}/${armbian_rootfs_file} -C ${armbian_dir} && sync
mv -f ${armbian_dir}/*.img ${armbian_file} && sync
rm -f ${armbian_dir}/${armbian_rootfs_file} && sync
[ -f "${armbian_file}" ] || error_msg "There is no armbian file: [ ${armbian_file} ]"
fi
}
query_version() {
cd ${make_path}
# Set empty array
tmp_arr_kernels=()
# Query the latest kernel in a loop
i=1
for KERNEL_VAR in ${build_kernel[*]}; do
echo -e "${INFO} (${i}) Auto query the latest kernel version of the same series for [ ${KERNEL_VAR} ]"
MAIN_LINE_M=$(echo "${KERNEL_VAR}" | cut -d '.' -f1)
MAIN_LINE_V=$(echo "${KERNEL_VAR}" | cut -d '.' -f2)
MAIN_LINE_S=$(echo "${KERNEL_VAR}" | cut -d '.' -f3)
MAIN_LINE="${MAIN_LINE_M}.${MAIN_LINE_V}"
if [ "${code_owner}" == "kernel.org" ]; then
# latest_version="5.4.170"
latest_version=$(curl -s ${kernel_org_repo} | grep -oE linux-${MAIN_LINE}.[0-9]+.tar.xz | sort -rV | head -n 1 | grep -oE '[1-9].[0-9]{1,3}.[0-9]+')
if [[ "$?" -eq "0" && ! -z "${latest_version}" ]]; then
tmp_arr_kernels[${i}]="${latest_version}"
else
error_msg "Failed to query the kernel version in [ ${kernel_org_repo} ]"
fi
echo -e "${INFO} (${i}) [ ${tmp_arr_kernels[$i]} ] is kernel.org latest kernel. \n"
else
if [ -z "${code_repo}" ]; then linux_repo="linux-${MAIN_LINE}.y"; else linux_repo="${code_repo}"; fi
github_kernel_repo="${code_owner}/${linux_repo}/${code_branch}"
github_kernel_ver="https://raw.githubusercontent.com/${github_kernel_repo}/Makefile"
# latest_version="160"
latest_version="$(curl -s ${github_kernel_ver} | grep -oE "SUBLEVEL =.*" | head -n 1 | grep -oE '[0-9]{1,3}')"
if [[ "$?" -eq "0" && ! -z "${latest_version}" ]]; then
tmp_arr_kernels[${i}]="${MAIN_LINE}.${latest_version}"
else
error_msg "Failed to query the kernel version in [ github.com/${github_kernel_repo} ]"
fi
echo -e "${INFO} (${i}) [ ${tmp_arr_kernels[$i]} ] is github.com/${github_kernel_repo} latest kernel. \n"
fi
let i++
done
# Reset the kernel array to the latest kernel version
unset build_kernel
build_kernel=${tmp_arr_kernels[*]}
}
download_kernel() {
cd ${make_path}
# kernel_folder > kernel_.tar.xz_file > download_from_kernel.org
echo -e "${STEPS} Start query and download the kernel."
[ -d "${kernel_path}" ] || mkdir -p ${kernel_path}
if [ ! -d "${kernel_path}/${local_kernel_dirname}" ]; then
if [ "${code_owner}" == "kernel.org" ]; then
if [ -f "${kernel_path}/${local_kernel_dirname}.tar.xz" ]; then
echo -e "${INFO} Unzip local files [ ${local_kernel_dirname}.tar.xz ]"
cd ${kernel_path}
tar -xJf ${local_kernel_dirname}.tar.xz
[ "$?" -eq "0" ] || error_msg "[ ${local_kernel_dirname}.tar.xz ] file decompression failed."
else
echo -e "${INFO} [ ${kernel_version} ] Kernel loading from [ ${server_kernel_repo}${local_kernel_dirname}.tar.xz ]"
wget -q -P ${kernel_path} ${server_kernel_repo}${local_kernel_dirname}.tar.xz && sync
if [[ "$?" -eq "0" && -s "${kernel_path}/${local_kernel_dirname}.tar.xz" ]]; then
echo -e "${SUCCESS} The kernel file is downloaded successfully."
cd ${kernel_path}
tar -xJf ${local_kernel_dirname}.tar.xz && sync
[ -d "${local_kernel_dirname}" ] || error_msg "[ ${local_kernel_dirname}.tar.xz ] file decompression failed."
else
error_msg "Kernel file download failed!"
fi
fi
else
echo -e "${INFO} Start cloning from [ https://github.com/${server_kernel_repo} -b ${code_branch} ]"
git clone --depth 1 https://github.com/${server_kernel_repo} -b ${code_branch} ${kernel_path}/${local_kernel_dirname}
[ "$?" -eq "0" ] || error_msg "[ https://github.com/${server_kernel_repo} ] Clone failed."
fi
elif [ "${code_owner}" != "kernel.org" ]; then
# Get a local kernel version
local_makefile="${kernel_path}/${local_kernel_dirname}/Makefile"
local_makefile_version="$(cat ${local_makefile} | grep -oE "VERSION =.*" | head -n 1 | grep -oE '[0-9]{1,3}')"
local_makefile_patchlevel="$(cat ${local_makefile} | grep -oE "PATCHLEVEL =.*" | head -n 1 | grep -oE '[0-9]{1,3}')"
local_makefile_sublevel="$(cat ${local_makefile} | grep -oE "SUBLEVEL =.*" | head -n 1 | grep -oE '[0-9]{1,3}')"
# Local version and server version comparison
if [[ "${auto_kernel}" == "true" && "${kernel_sub}" -gt "${local_makefile_sublevel}" ]]; then
# Pull the latest source code of the server
cd ${kernel_path}/${local_kernel_dirname}
git checkout ${code_branch} && git reset --hard origin/${code_branch} && git pull && sync
unset kernel_version
kernel_version="${local_makefile_version}.${local_makefile_patchlevel}.${kernel_sub}"
echo -e "${INFO} Synchronize the upstream source code, compile the kernel version [ ${kernel_version} ]."
else
# Reset to local kernel version number
unset kernel_version
kernel_version="${local_makefile_version}.${local_makefile_patchlevel}.${local_makefile_sublevel}"
echo -e "${INFO} Use local source code, compile the kernel version [ ${kernel_version} ]."
fi
fi
sync
}
compile_env_check() {
cd ${make_path}
echo -e "${STEPS} Start checking local compilation environments."
# Check whether the kernel of the same name has been installed locally
kernel_outname="${kernel_version}${custom_name}"
local_kernel="$(ls /lib/modules -l | grep -E '^d' | awk '{print $9}' | grep -w "${kernel_outname}")"
[ -n "${local_kernel}" ] && error_msg "The current system has the same named kernel [ ${kernel_outname} ], stop compiling!"
echo -e "${INFO} Compile kernel output name [ ${kernel_outname} ]. \n"
# Get current kernel version
kernel_v=$(echo "${kernel_version}" | cut -d '.' -f1)
kernel_p=$(echo "${kernel_version}" | cut -d '.' -f2)
kernel_s=$(echo "${kernel_version}" | cut -d '.' -f3)
# Create a temp directory
rm -rf ${out_kernel}/{chroot/,boot/,dtb/,modules/,header/,${kernel_version}/} 2>/dev/null && sync
mkdir -p ${out_kernel}/{chroot/{root/boot/,},boot/,dtb/{allwinner/,amlogic/,rockchip/},modules/,header/,${kernel_version}/} && sync
}
make_kernel() {
cd ${kernel_path}/${local_kernel_dirname}
echo -e "${STEPS} Set cross compilation parameters."
# Set cross compilation parameters
path_ubuntu2004="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
path_clang="${toolchain_dir}/${clang_file//.tar.xz/}/bin:${path_ubuntu2004}"
export ARCH="arm64"
export LOCALVERSION="${custom_name}"
export PATH=${path_clang}
export CROSS_COMPILE=${toolchain_dir}/${gcc_file//.tar.xz/}/bin/aarch64-none-linux-gnu-
export CLANG_TRIPLE=${toolchain_dir}/${clang_file//.tar.xz/}/bin
export CC=${toolchain_dir}/${clang_file//.tar.xz/}/bin/clang
export LD=${toolchain_dir}/${clang_file//.tar.xz/}/bin/ld.lld
# Set $PATH variable for ~/.bashrc
sed -i '/^PATH=/d' ~/.bashrc 2>/dev/null && sync
echo "PATH=${path_clang}" >>~/.bashrc && sync
source ~/.bashrc
# Set $PATH variable for /etc/profile
sed -i '/^PATH=/d' /etc/profile 2>/dev/null && sync
echo "PATH=${path_clang}" >>/etc/profile && sync
source /etc/profile
# Show variable
echo -e "${INFO} ARCH: [ ${ARCH} ]"
echo -e "${INFO} LOCALVERSION: [ ${LOCALVERSION} ]"
echo -e "${INFO} PATH: [ ${PATH} ]"
echo -e "${INFO} CROSS_COMPILE: [ ${CROSS_COMPILE} ]"
echo -e "${INFO} CLANG_TRIPLE: [ ${CLANG_TRIPLE} ]"
echo -e "${INFO} CC: [ ${CC} ]"
echo -e "${INFO} LD: [ ${LD} ]"
# Set generic make string
MAKE_SET_STRING=" ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE} CLANG_TRIPLE=${CLANG_TRIPLE} CC=${CC} LD=${LD} LLVM=1 LLVM_IAS=1 LOCALVERSION=${LOCALVERSION} "
# Make clean/mrproper
#make ${MAKE_SET_STRING} clean
# Make menuconfig
#make ${MAKE_SET_STRING} menuconfig
# Check .config file
if [ ! -f ".config" ]; then
# Copy config file
echo -e "${INFO} Copy config file to ${local_kernel_dirname}"
config_demo=$(ls ${config_dir}/config-${kernel_verpatch}* 2>/dev/null | sort -rV | head -n 1)
config_demo_file=${config_demo##*/}
[ -z "${config_demo_file}" ] && error_msg "Missing [ config-${kernel_verpatch}* ] template!"
echo -e "${INFO} CONFIG_DEMO: [ ${config_dir}/${config_demo_file} ]"
cp -f ${config_dir}/${config_demo_file} .config && sync
else
echo -e "${INFO} Use the .config file in the current directory."
fi
#
sed -i "s|CONFIG_LOCALVERSION=.*|CONFIG_LOCALVERSION=\"\"|" .config
sync
# Enable/Disabled Linux Kernel Clang LTO
if [[ "${kernel_v}" -ge "6" ]] || [[ "${kernel_v}" -eq "5" && "${kernel_p}" -ge "12" ]]; then
scripts/config -e LTO_CLANG_THIN
else
scripts/config -d LTO_CLANG_THIN
fi
# Make kernel
echo -e "${STEPS} Start compilation kernel [ ${local_kernel_dirname} ]..."
PROCESS="$(cat /proc/cpuinfo | grep "processor" | wc -l)"
[ -z ${PROCESS} ] && PROCESS="1" && echo "PROCESS: 1"
make ${MAKE_SET_STRING} Image modules dtbs -j${PROCESS}
[ $? -eq 0 ] && echo -e "${SUCCESS} The kernel is compiled successfully."
# Install modules
echo -e "${STEPS} Install modules ..."
make ${MAKE_SET_STRING} modules_install
[ $? -eq 0 ] && echo -e "${SUCCESS} The modules is installed successfully."
# Install headers
echo -e "${STEPS} Install headers ..."
header_path="${out_kernel}/header"
make ${MAKE_SET_STRING} headers_install INSTALL_HDR_PATH=${header_path}
[ $? -eq 0 ] && echo -e "${SUCCESS} The headers is installed successfully."
}
generate_uinitrd() {
cd ${make_path}
cp -f ${armbian_file} ${chroot_file} && sync
# Mount the armbian system
tag_rootfs=${chroot_dir}/root
loop_armbian=$(losetup -P -f --show "${chroot_file}")
[ ${loop_armbian} ] || error_msg "losetup ${chroot_file} failed."
if ! mount ${loop_armbian}p2 ${tag_rootfs}; then
error_msg "mount ${loop_armbian}p2 failed!"
fi
if ! mount ${loop_armbian}p1 ${tag_rootfs}/boot; then
error_msg "mount ${loop_armbian}p1 failed!"
fi
# Copy /boot related files into armbian system
rm -f ${tag_rootfs}/boot/{config-*,initrd.img-*,System.map-*,uInitrd-*,vmlinuz-*,uInitrd,zImage} 2>/dev/null && sync
#
cp -f ${kernel_path}/${local_kernel_dirname}/System.map ${tag_rootfs}/boot/System.map-${kernel_outname}
cp -f ${kernel_path}/${local_kernel_dirname}/.config ${tag_rootfs}/boot/config-${kernel_outname}
cp -f ${kernel_path}/${local_kernel_dirname}/arch/arm64/boot/Image ${tag_rootfs}/boot/vmlinuz-${kernel_outname}
sync
#echo -e "${INFO} Kernel copy results in the [ ${tag_rootfs}/boot ] directory: \n$(ls -l ${tag_rootfs}/boot) \n"
rm -rf ${tag_rootfs}/lib/modules/* 2>/dev/null && sync
cp -rf /lib/modules/${kernel_outname} ${tag_rootfs}/lib/modules && sync
#echo -e "${INFO} Kernel copy results in the [ ${tag_rootfs}/lib/modules ] directory: \n$(ls -l ${tag_rootfs}/lib/modules) \n"
cp -f ${script_dir}/generate_uinitrd.sh ${tag_rootfs}/root 2>/dev/null && sync
chmod +x ${tag_rootfs}/root/generate_uinitrd.sh 2>/dev/null
#echo -e "${INFO} Kernel copy results in the [ ${tag_rootfs}/root ] directory: \n$(ls -l ${tag_rootfs}/root) \n"
[ -f "/usr/bin/${qemu_binary_arm}" ] && cp -f /usr/bin/${qemu_binary_arm} ${tag_rootfs}/usr/bin/ && sync
[ -f "/usr/bin/${qemu_binary_arm64}" ] && cp -f /usr/bin/${qemu_binary_arm64} ${tag_rootfs}/usr/bin/ && sync
#echo -e "${INFO} The [ ${qemu_binary_arm64} ] file copy results: \n$(ls -l ${tag_rootfs}/usr/bin/${qemu_binary_arm64}) \n"
# COMPRESS: [ gzip | bzip2 | lz4 | lzma | lzop | xz | zstd ]
compress_initrd_file="${tag_rootfs}/etc/initramfs-tools/initramfs.conf"
sed -i "/^COMPRESS=/d" ${compress_initrd_file} && sync
echo "COMPRESS=gzip" >>${compress_initrd_file} && sync
# Enter the armbian system to generate /boot/uInitrd file
chroot ${tag_rootfs} <<EOF
bash /root/generate_uinitrd.sh ${kernel_outname}
exit
EOF
cd ${make_path}
# Copy the generated uInitrd file to the current system
echo -e "${INFO} Copy the generated files from [ ${tag_rootfs}/boot/ ]"
cp -f ${tag_rootfs}/boot/*${kernel_outname} ${out_kernel}/boot/ && sync
# Unmount the armbian system
umount ${tag_rootfs}/boot 2>/dev/null
umount ${tag_rootfs} 2>/dev/null
losetup -D 2>/dev/null
}
packit_kernel() {
# Pack the kernel 6 files
echo -e "${STEPS} Packing the 6 [ ${kernel_outname} ] packages generated by the compilation of the [ ${local_kernel_dirname} ] kernel..."
cd ${out_kernel}/boot
chmod +x *
tar -czf boot-${kernel_outname}.tar.gz * && sync
cp -f *.tar.gz ${out_kernel}/${kernel_version}
echo -e "${SUCCESS} The [ boot-${kernel_outname}.tar.gz ] file is packaged."
cd ${out_kernel}/dtb/allwinner
cp -f ${kernel_path}/${local_kernel_dirname}/arch/arm64/boot/dts/allwinner/*.dtb . && chmod +x * && sync
tar -czf dtb-allwinner-${kernel_outname}.tar.gz * && sync
cp -f *.tar.gz ${out_kernel}/${kernel_version} && sync
echo -e "${SUCCESS} The [ dtb-allwinner-${kernel_outname}.tar.gz ] file is packaged."
cd ${out_kernel}/dtb/amlogic
[ -d ${moredtb_path} ] && cp -f ${moredtb_path}/*.dtb . && chmod +x * && sync
cp -f ${kernel_path}/${local_kernel_dirname}/arch/arm64/boot/dts/amlogic/*.dtb . && chmod +x * && sync
tar -czf dtb-amlogic-${kernel_outname}.tar.gz * && sync
cp -f *.tar.gz ${out_kernel}/${kernel_version} && sync
echo -e "${SUCCESS} The [ dtb-amlogic-${kernel_outname}.tar.gz ] file is packaged."
cd ${out_kernel}/dtb/rockchip
cp -f ${kernel_path}/${local_kernel_dirname}/arch/arm64/boot/dts/rockchip/*.dtb . && chmod +x * && sync
tar -czf dtb-rockchip-${kernel_outname}.tar.gz * && sync
cp -f *.tar.gz ${out_kernel}/${kernel_version} && sync
echo -e "${SUCCESS} The [ dtb-rockchip-${kernel_outname}.tar.gz ] file is packaged."
cd ${out_kernel}/modules
mv -f /lib/modules/${kernel_outname} . && sync
tar -czf modules-${kernel_outname}.tar.gz * && sync
cp -f *.tar.gz ${out_kernel}/${kernel_version}
echo -e "${SUCCESS} The [ modules-${kernel_outname}.tar.gz ] file is packaged."
cd ${out_kernel}/header
tar -czf header-${kernel_outname}.tar.gz * && sync
cp -f *.tar.gz ${out_kernel}/${kernel_version}
echo -e "${SUCCESS} The [ header-${kernel_outname}.tar.gz ] file is packaged."
cd ${out_kernel}
tar -czf ${kernel_version}.tar.gz ${kernel_version} && sync
echo -e "${INFO} Kernel series files are stored in [ ${out_kernel} ]."
}
clean_tmp() {
cd ${make_path}
echo -e "${STEPS} Clear the space and update-grub."
rm -rf ${out_kernel}/{chroot/,boot/,dtb/,modules/,header/,${kernel_version}/} 2>/dev/null && sync
update-grub 2>/dev/null
echo -e "${SUCCESS} Space cleared successfully."
sync
echo -e "${SUCCESS} All processes have been completed."
}
while [ "${1}" ]; do
case "${1}" in
-d | --default)
: ${build_kernel:="${build_kernel}"}
: ${auto_kernel:="${auto_kernel}"}
: ${custom_name:="${custom_name}"}
: ${repo_owner:="${repo_owner}"}
;;
-k | --kernel)
if [ -n "${2}" ]; then
oldIFS=$IFS
IFS=_
build_kernel=(${2})
IFS=$oldIFS
shift
else
error_msg "Invalid -k parameter [ ${2} ]!"
fi
;;
-a | --autoKernel)
if [ -n "${2}" ]; then
auto_kernel="${2}"
shift
else
error_msg "Invalid -a parameter [ ${2} ]!"
fi
;;
-n | --customName)
if [ -n "${2}" ]; then
custom_name="${2}"
shift
else
error_msg "Invalid -n parameter [ ${2} ]!"
fi
;;
-r | --repo)
if [ -n "${2}" ]; then
repo_owner="${2}"
shift
else
error_msg "Invalid -r parameter [ ${2} ]!"
fi
;;
*)
error_msg "Invalid option [ ${1} ]!"
;;
esac
shift
done
# Receive the value entered by the [ -r ] parameter
input_r_value="${repo_owner//https\:\/\/github\.com\//}"
code_owner="$(echo "${input_r_value}" | awk -F '@' '{print $1}' | awk -F '/' '{print $1}')"
code_repo="$(echo "${input_r_value}" | awk -F '@' '{print $1}' | awk -F '/' '{print $2}')"
code_branch="$(echo "${input_r_value}" | awk -F '@' '{print $2}')"
#
[ -n "${code_owner}" ] || error_msg "The [ -r ] parameter is invalid."
[ -n "${code_branch}" ] || code_branch="${repo_branch}"
toolchain_check
# Set whether to replace the kernel
[[ "${auto_kernel}" == "true" ]] && query_version
[ $(id -u) = 0 ] || error_msg "Please run this script as root: [ sudo ./$0 ]"
[[ ${arch_info} == "x86_64" ]] || error_msg "Please run this script on ubuntu-20.04"
echo -e "Welcome to compile kernel! \n"
echo -e "Server space usage before starting to compile: \n$(df -hT ${PWD}) \n"
echo -e "Kernel List: [ $(echo ${build_kernel[*]} | tr "\n" " ") ]"
echo -e "Kernel from: [ ${code_owner} ]"
echo -e "Ready, start compile kernel... \n"
k=1
for x in ${build_kernel[*]}; do
# kernel_version, such as [ 5.4.170 ]
kernel_version="${x}"
# kernel_verpatch, such as [ 5.4 ]
kernel_verpatch="$(echo ${kernel_version} | awk -F '.' '{print $1"."$2}')"
# kernel_sub, such as [ 170 ]
kernel_sub="$(echo ${kernel_version} | awk -F '.' '{print $3}')"
if [ "${code_owner}" == "kernel.org" ]; then
server_kernel_repo="${kernel_org_repo}"
local_kernel_dirname="linux-${kernel_version}"
elif [ -z "${code_repo}" ]; then
server_kernel_repo="${code_owner}/linux-${kernel_verpatch}.y"
local_kernel_dirname="linux-${kernel_verpatch}.y"
else
server_kernel_repo="${code_owner}/${code_repo}"
local_kernel_dirname="${code_repo}-${code_branch}"
fi
download_kernel
compile_env_check
make_kernel
generate_uinitrd
packit_kernel
clean_tmp
let k++
done
sync
echo -e "${INFO} Server space usage after compilation: \n$(df -hT ${PWD}) \n"
exit 0