forked from topak47/build-openwrt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make
1199 lines (1058 loc) · 48.6 KB
/
make
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
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#================================================================================================
#
# This file is licensed under the terms of the GNU General Public
# License version 2. This program is licensed "as is" without any
# warranty of any kind, whether express or implied.
#
# This file is a part of the make OpenWrt
# https://github.com/ophub/amlogic-s9xxx-openwrt
#
# Description: Automatically Packaged OpenWrt
# Copyright (C) 2020~ https://github.com/openwrt/openwrt
# Copyright (C) 2020~ https://github.com/coolsnowwolf/lede
# Copyright (C) 2020~ https://github.com/immortalwrt/immortalwrt
# Copyright (C) 2020~ https://github.com/unifreq/openwrt_packit
# Copyright (C) 2021~ https://github.com/ophub/amlogic-s9xxx-armbian/blob/main/CONTRIBUTORS.md
# Copyright (C) 2020~ https://github.com/ophub/amlogic-s9xxx-openwrt
#
# Command: sudo ./make
# Command optional parameters please refer to the source code repository
#
#======================================== Functions list ========================================
#
# error_msg : Output error message
# process_msg : Output process message
# mount_try : Mount the image file, fail again
# get_textoffset : Get kernel TEXT_OFFSET
#
# init_var : Initialize all variables
# check_data : Check the validity of the data
# find_openwrt : Find OpenWrt file (openwrt-armvirt/*rootfs.tar.gz)
# download_depends : Download the dependency files
# query_kernel : Query the latest kernel version
# check_kernel : Check kernel files integrity
# download_kernel : Download the latest kernel
#
# confirm_version : Confirm version type
# make_image : Making OpenWrt file
# extract_openwrt : Extract OpenWrt files
# replace_kernel : Replace the kernel
# refactor_bootfs : Refactor bootfs files
# refactor_rootfs : Refactor rootfs files
# clean_tmp : Clear temporary files
#
# loop_make : Loop to make OpenWrt files
#
#================================ Set make environment variables ================================
#
# Related file storage path
current_path="${PWD}"
tmp_path="${current_path}/tmp"
out_path="${current_path}/out"
openwrt_path="${current_path}/openwrt-armvirt"
openwrt_rootfs_file="*rootfs.tar.gz"
make_path="${current_path}/make-openwrt"
kernel_path="${make_path}/kernel"
uboot_path="${make_path}/u-boot"
common_files="${make_path}/openwrt-files/common-files"
platform_files="${make_path}/openwrt-files/platform-files"
different_files="${make_path}/openwrt-files/different-files"
firmware_path="${common_files}/lib/firmware"
model_conf="${common_files}/etc/model_database.conf"
model_txt="${common_files}/etc/model_database.txt"
# System operation environment
arch_info="$(uname -m)"
host_release="$(cat /etc/os-release | grep '^VERSION_CODENAME=.*' | cut -d'=' -f2)"
# Add custom OpenWrt firmware information
op_release="etc/flippy-openwrt-release"
# Dependency files download repository
depends_repo="https://github.com/ophub/amlogic-s9xxx-armbian/tree/main/build-armbian"
# Convert depends repository address to svn format
depends_repo="${depends_repo//tree\/main/trunk}"
# Firmware files download repository
firmware_repo="https://github.com/ophub/firmware/tree/main/firmware"
# Convert firmware repository address to svn format
firmware_repo="${firmware_repo//tree\/main/trunk}"
# Install/Update script files download repository
script_repo="https://github.com/ophub/luci-app-amlogic/tree/main/luci-app-amlogic"
# Convert script repository address to svn format
script_repo="${script_repo//tree\/main/trunk}"
# Set the kernel download repository from github.com
kernel_repo="https://github.com/ophub/kernel"
# Set the tags(kernel_xxx) of the default kernel that can be replaced via the [ -u ] parameter
default_tags="stable"
# Set the tags(kernel_xxx) of the specific kernel, such as 5.15.y, 6.1.y, etc.
specific_tags="${default_tags}"
# Set the list of kernels used by default
rk3588_kernel=("5.10.1")
stable_kernel=("6.1.1" "5.15.1")
flippy_kernel=(${stable_kernel[*]})
dev_kernel=(${stable_kernel[*]})
beta_kernel=(${stable_kernel[*]})
# Set to automatically use the latest kernel
auto_kernel="true"
# Initialize the build device
make_board="all"
# Set OpenWrt firmware size (Unit: MiB, boot_mb >= 256, root_mb >= 512)
boot_mb="256"
root_mb="1024"
# Set OpenWrt builder signature
builder_name=""
# Get gh_token for api.github.com
gh_token=""
# Set font color
STEPS="[\033[95m STEPS \033[0m]"
INFO="[\033[94m INFO \033[0m]"
TIPS="[\033[93m TIPS \033[0m]"
WARNING="[\033[93m WARNING \033[0m]"
SUCCESS="[\033[92m SUCCESS \033[0m]"
ERROR="[\033[91m ERROR \033[0m]"
#
#================================================================================================
error_msg() {
echo -e " [💔] ${1}"
exit 1
}
process_msg() {
echo -e " [🌿] ${1}"
}
mount_try() {
# Check mount parameters
m_type="${1}"
m_dev="${2}"
m_target="${3}"
[[ -n "${m_type}" && -n "${m_dev}" && -n "${m_target}" ]] || {
error_msg "Mount parameter is missing: [ ${m_type}, ${m_dev}, ${m_target} ]"
}
t="1"
max_try="10"
while [[ "${t}" -le "${max_try}" ]]; do
# Mount according to the image partition format
if [[ "${m_type}" == "btrfs" ]]; then
mount -t ${m_type} -o discard,compress=zstd:6 ${m_dev} ${m_target}
else
mount -t ${m_type} -o discard ${m_dev} ${m_target}
fi
# Mount failed and continue trying
if [[ "${?}" -eq "0" ]]; then
break
else
sync && sleep 3
umount -f ${m_target} 2>/dev/null
t="$((t + 1))"
fi
done
[[ "${t}" -gt "${max_try}" ]] && error_msg "[ ${t} ] attempts to mount failed."
}
get_textoffset() {
vmlinuz_name="${1}"
need_overload="yes"
# With TEXT_OFFSET patch is [ 0108 ], without TEXT_OFFSET patch is [ 0000 ]
[[ "$(hexdump -n 15 -x "${vmlinuz_name}" 2>/dev/null | head -n 1 | awk '{print $7}')" == "0108" ]] && need_overload="no"
}
init_var() {
echo -e "${STEPS} Start Initializing Variables..."
# If it is followed by [ : ], it means that the option requires a parameter value
get_all_ver="$(getopt "b:r:u:k:a:s:n:g:" "${@}")"
while [[ -n "${1}" ]]; do
case "${1}" in
-b | --Board)
if [[ -n "${2}" ]]; then
make_board="${2}"
shift
else
error_msg "Invalid -b parameter [ ${2} ]!"
fi
;;
-r | --kernelRepository)
if [[ -n "${2}" ]]; then
kernel_repo="${2}"
shift
else
error_msg "Invalid -r parameter [ ${2} ]!"
fi
;;
-u | --kernelUsage)
if [[ -n "${2}" ]]; then
kernel_usage="${2//kernel_/}"
shift
else
error_msg "Invalid -u parameter [ ${2} ]!"
fi
;;
-k | --Kernel)
if [[ -n "${2}" ]]; then
oldIFS="${IFS}"
IFS="_"
flippy_kernel=(${2})
stable_kernel=(${2})
dev_kernel=(${2})
beta_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
;;
-s | --Size)
if [[ -n "${2}" && "${2}" -ge "512" ]]; then
root_mb="${2}"
shift
else
error_msg "Invalid -s parameter [ ${2} ]!"
fi
;;
-n | --BuilderName)
if [[ -n "${2}" ]]; then
builder_name="${2// /}"
shift
else
error_msg "Invalid -n parameter [ ${2} ]!"
fi
;;
-g | --Gh_token)
if [[ -n "${2}" ]]; then
gh_token="${2}"
shift
else
error_msg "Invalid -g parameter [ ${2} ]!"
fi
;;
*)
error_msg "Invalid option [ ${1} ]!"
;;
esac
shift
done
}
check_data() {
# Columns of ${model_conf}:
# 1.ID 2.MODEL 3.SOC 4.FDTFILE 5.UBOOT_OVERLOAD 6.MAINLINE_UBOOT 7.BOOTLOADER_IMG 8.DESCRIPTION
# 9.KERNEL_TAGS 10.PLATFORM 11.FAMILY 12.BOOT_CONF 13.CONTRIBUTORS 14.BOARD 15.BUILD
[[ -f "${model_conf}" ]] || error_msg "Missing model config file: [ ${model_conf} ]"
# Convert ${model_conf} to ${model_txt} for [ openwrt-install-amlogic ], Just the first 8 columns.
cat ${model_conf} |
sed -e 's/NULL/NA/g' -e 's/[ ][ ]*//g' |
grep -E "^[^#ar].*" |
awk -F':' '{if ($6 != "NA") $6 = "/lib/u-boot/"$6; if ($7 != "NA") $7 = "/lib/u-boot/"$7; NF = 8; print}' OFS=':' \
>${model_txt}
# Get a list of build devices
if [[ "${make_board}" == "all" ]]; then
board_list=":(yes)"
make_openwrt=($(
cat ${model_conf} |
sed -e 's/NA//g' -e 's/NULL//g' -e 's/[ ][ ]*//g' |
grep -E "^[^#].*:yes$" | awk -F':' '{print $14}' |
sort -u | xargs
))
else
board_list=":($(echo ${make_board} | sed -e 's/_/\|/g')):(yes|no)"
make_openwrt=($(echo ${make_board} | sed -e 's/_/ /g'))
fi
[[ "${#make_openwrt[*]}" -eq "0" ]] && error_msg "The board is missing, stop making."
# Get a list of kernel
kernel_from=($(
cat ${model_conf} |
sed -e 's/NA//g' -e 's/NULL//g' -e 's/[ ][ ]*//g' -e 's/\.y/\.1/g' |
grep -E "^[^#].*${board_list}$" | awk -F':' '{print $9}' |
sort -u | xargs
))
[[ "${#kernel_from[*]}" -eq "0" ]] && error_msg "Missing [ KERNEL_TAGS ] settings, stop building."
# Replace custom kernel tags
[[ -n "${kernel_usage}" ]] && {
specific_tags="${kernel_usage}"
kernel_from=(${kernel_from[*]//${default_tags}/${kernel_usage}})
}
# The [ specific kernel ], Use the [ kernel version number ], such as 5.15.y, 6.1.y, etc. download from [ kernel_stable ].
specific_kernel=($(echo ${kernel_from[*]} | sed -e 's/[ ][ ]*/\n/g' | grep -E "^[0-9]+" | sort -u | xargs))
# The [ suffix ] of KERNEL_TAGS starts with a [ letter ], such as kernel_stable, kernel_rk3588, etc.
tags_list=($(echo ${kernel_from[*]} | sed -e 's/[ ][ ]*/\n/g' | grep -E "^[a-z]" | sort -u | xargs))
# Add the specific kernel to the list
[[ "${#specific_kernel[*]}" -ne "0" ]] && tags_list=(${tags_list[*]} "specific")
# Check the kernel list
[[ "${#tags_list[*]}" -eq "0" ]] && error_msg "The [ tags_list ] is missing, stop building."
# Convert kernel repository address to api format
[[ "${kernel_repo}" =~ ^https: ]] && kernel_repo="$(echo ${kernel_repo} | awk -F'/' '{print $4"/"$5}')"
kernel_api="https://api.github.com/repos/${kernel_repo}"
}
find_openwrt() {
cd ${current_path}
echo -e "${STEPS} Start searching for OpenWrt file..."
# Find whether the OpenWrt file exists
openwrt_default_file="$(ls ${openwrt_path}/${openwrt_rootfs_file} 2>/dev/null | head -n 1 | awk -F "/" '{print $NF}')"
if [[ -n "${openwrt_default_file}" ]]; then
echo -e "${INFO} OpenWrt file: [ ${openwrt_default_file} ]"
else
error_msg "There is no [ ${openwrt_rootfs_file} ] file in the [ ${openwrt_path} ] directory."
fi
# Extract the OpenWrt release information file
source_codename=""
source_release_file="etc/openwrt_release"
temp_dir="$(mktemp -d)"
(cd ${temp_dir} && tar -mxzf "${openwrt_path}/${openwrt_default_file}" "./${source_release_file}" 2>/dev/null)
# Find custom DISTRIB_SOURCECODE, such as [ official/lede ]
[[ -f "${temp_dir}/${source_release_file}" ]] && {
source_codename="$(cat ${temp_dir}/${source_release_file} 2>/dev/null | grep -oE "^DISTRIB_SOURCECODE=.*" | head -n 1 | cut -d"'" -f2)"
[[ -n "${source_codename}" ]] && {
# Record OpenWrt source codes repository
case "${source_codename}" in
official) OPENWRT_SOURCECODE="github.com/openwrt/openwrt" ;;
lede) OPENWRT_SOURCECODE="github.com/coolsnowwolf/lede" ;;
immortalwrt) OPENWRT_SOURCECODE="github.com/immortalwrt/immortalwrt" ;;
*) OPENWRT_SOURCECODE="unknown" ;;
esac
# Complete filename
[[ "${source_codename:0:1}" != "_" ]] && source_codename="_${source_codename}"
}
echo -e "${INFO} The source_codename: [ ${source_codename} ], OpenWrt source code repository: [ ${OPENWRT_SOURCECODE} ]"
}
# Remove temporary directory
rm -rf ${temp_dir}
}
download_depends() {
cd ${current_path}
echo -e "${STEPS} Start downloading dependency files..."
# Download platform files
svn co ${depends_repo}/armbian-files/platform-files ${platform_files} --force
# Remove the special files in the [ sbin ] directory of the Armbian system
rm -rf $(find ${platform_files} -type d -name "sbin")
# Download different files
svn co ${depends_repo}/armbian-files/different-files ${different_files} --force
# Download u-boot files
if [[ -d "${uboot_path}" ]]; then
svn up ${uboot_path} --force
else
svn co ${depends_repo}/u-boot ${uboot_path} --force
fi
# Download Armbian firmware files
svn co ${firmware_repo} ${firmware_path} --force
# Download balethirq related files
svn export ${depends_repo}/armbian-files/common-files/usr/sbin/balethirq.pl ${common_files}/usr/sbin --force
svn export ${depends_repo}/armbian-files/common-files/etc/balance_irq ${common_files}/etc --force
# Download install/update and other related files
svn export ${script_repo}/root/usr/sbin ${common_files}/usr/sbin --force
chmod +x ${common_files}/usr/sbin/*
svn export ${script_repo}/root/usr/share/amlogic ${common_files}/usr/share/amlogic --force
chmod +x ${common_files}/usr/share/amlogic/*
}
query_kernel() {
echo -e "${STEPS} Start querying the latest kernel version..."
# Check the version on the kernel repository
x="1"
for k in ${tags_list[*]}; do
{
# Select the kernel list
kd="${k}"
case "${k}" in
stable)
down_kernel_list=(${stable_kernel[*]})
;;
flippy)
down_kernel_list=(${flippy_kernel[*]})
;;
dev)
down_kernel_list=(${dev_kernel[*]})
;;
beta)
down_kernel_list=(${beta_kernel[*]})
;;
rk3588)
down_kernel_list=(${rk3588_kernel[*]})
;;
specific)
down_kernel_list=(${specific_kernel[*]})
kd="${specific_tags}"
;;
*) error_msg "Invalid tags." ;;
esac
# Query the name of the latest kernel version
tmp_arr_kernels=()
i=1
for kernel_var in ${down_kernel_list[*]}; do
echo -e "${INFO} (${x}.${i}) Auto query the latest kernel version for [ ${k} - ${kernel_var} ]"
# Identify the kernel <VERSION> and <PATCHLEVEL>, such as [ 6.1 ]
kernel_verpatch="$(echo ${kernel_var} | awk -F '.' '{print $1"."$2}')"
# Set the token for api.github.com
[[ -n "${gh_token}" ]] && ght="-H \"Authorization: Bearer ${gh_token}\"" || ght=""
# Query the latest kernel version
latest_version="$(
curl -s \
-H "Accept: application/vnd.github+json" \
${ght} \
${kernel_api}/releases/tags/kernel_${kd} |
jq -r '.assets[].name' |
grep -oE "${kernel_verpatch}\.[0-9]+" |
sort -rV | head -n 1
)"
if [[ "${?}" -eq "0" && -n "${latest_version}" ]]; then
tmp_arr_kernels[${i}]="${latest_version}"
else
tmp_arr_kernels[${i}]="${kernel_var}"
fi
echo -e "${INFO} (${x}.${i}) [ ${k} - ${tmp_arr_kernels[$i]} ] is latest kernel. \n"
let i++
done
# Reset the kernel array to the latest kernel version
case "${k}" in
stable)
unset stable_kernel
stable_kernel=(${tmp_arr_kernels[*]})
;;
flippy)
unset flippy_kernel
flippy_kernel=(${tmp_arr_kernels[*]})
;;
dev)
unset dev_kernel
dev_kernel=(${tmp_arr_kernels[*]})
;;
beta)
unset beta_kernel
beta_kernel=(${tmp_arr_kernels[*]})
;;
rk3588)
unset rk3588_kernel
rk3588_kernel=(${tmp_arr_kernels[*]})
;;
specific)
unset specific_kernel
specific_kernel=(${tmp_arr_kernels[*]})
;;
*) error_msg "Invalid tags." ;;
esac
let x++
}
done
}
check_kernel() {
[[ -n "${1}" ]] && check_path="${1}" || error_msg "Invalid kernel path to check."
check_files=($(cat "${check_path}/sha256sums" | awk '{print $2}'))
for cf in ${check_files[*]}; do
{
# Check if file exists
[[ -s "${check_path}/${cf}" ]] || error_msg "The [ ${cf} ] file is missing."
# Check if the file sha256sum is correct
tmp_sha256sum="$(sha256sum "${check_path}/${cf}" | awk '{print $1}')"
tmp_checkcode="$(cat ${check_path}/sha256sums | grep ${cf} | awk '{print $1}')"
[[ "${tmp_sha256sum}" == "${tmp_checkcode}" ]] || error_msg "[ ${cf} ]: sha256sum verification failed."
}
done
echo -e "${INFO} All [ ${#check_files[*]} ] kernel files are sha256sum checked to be complete.\n"
}
download_kernel() {
cd ${current_path}
echo -e "${STEPS} Start downloading the kernel files..."
x="1"
for k in ${tags_list[*]}; do
{
# Set the kernel download list
kd="${k}"
case "${k}" in
stable)
down_kernel_list=(${stable_kernel[*]})
;;
flippy)
down_kernel_list=(${flippy_kernel[*]})
;;
dev)
down_kernel_list=(${dev_kernel[*]})
;;
beta)
down_kernel_list=(${beta_kernel[*]})
;;
rk3588)
down_kernel_list=(${rk3588_kernel[*]})
;;
specific)
down_kernel_list=(${specific_kernel[*]})
kd="${specific_tags}"
;;
*) error_msg "Invalid tags." ;;
esac
# Download the kernel to the storage directory
i="1"
for kernel_var in ${down_kernel_list[*]}; do
if [[ ! -d "${kernel_path}/${kd}/${kernel_var}" ]]; then
kernel_down_from="https://github.com/${kernel_repo}/releases/download/kernel_${kd}/${kernel_var}.tar.gz"
echo -e "${INFO} (${x}.${i}) [ ${k} - ${kernel_var} ] Kernel download from [ ${kernel_down_from} ]"
mkdir -p ${kernel_path}/${kd}
wget "${kernel_down_from}" -q -P "${kernel_path}/${kd}"
[[ "${?}" -ne "0" ]] && error_msg "Failed to download the kernel files from the server."
tar -mxzf "${kernel_path}/${kd}/${kernel_var}.tar.gz" -C "${kernel_path}/${kd}"
[[ "${?}" -ne "0" ]] && error_msg "[ ${kernel_var} ] kernel decompression failed."
else
echo -e "${INFO} (${x}.${i}) [ ${k} - ${kernel_var} ] Kernel is in the local directory."
fi
# If the kernel contains the sha256sums file, check the files integrity
[[ -f "${kernel_path}/${kd}/${kernel_var}/sha256sums" ]] && check_kernel "${kernel_path}/${kd}/${kernel_var}"
let i++
done
# Delete downloaded kernel temporary files
rm -f ${kernel_path}/${kd}/*.tar.gz
sync
let x++
}
done
}
confirm_version() {
cd ${current_path}
# Columns of ${model_conf}:
# 1.ID 2.MODEL 3.SOC 4.FDTFILE 5.UBOOT_OVERLOAD 6.MAINLINE_UBOOT 7.BOOTLOADER_IMG 8.DESCRIPTION
# 9.KERNEL_TAGS 10.PLATFORM 11.FAMILY 12.BOOT_CONF 13.CONTRIBUTORS 14.BOARD 15.BUILD
# Column 5, called <UBOOT_OVERLOAD> in Amlogic, <TRUST_IMG> in Rockchip, Not used in Allwinner.
# Find [ the first ] configuration information with [ the same BOARD name ] and [ BUILD as yes ] in the ${model_conf} file.
board_conf="$(
cat ${model_conf} |
sed -e 's/NA//g' -e 's/NULL//g' -e 's/[ ][ ]*//g' |
grep -E "^[^#].*:${board}:(yes|no)$" |
head -n 1
)"
[[ -n "${board_conf}" ]] || error_msg "[ ${board} ] config is missing!"
# Get device settings options
MODEL_ID="$(echo ${board_conf} | awk -F':' '{print $1}')"
MODEL_NAME="$(echo ${board_conf} | awk -F':' '{print $2}')"
SOC="$(echo ${board_conf} | awk -F':' '{print $3}')"
FDTFILE="$(echo ${board_conf} | awk -F':' '{print $4}')"
UBOOT_OVERLOAD="$(echo ${board_conf} | awk -F':' '{print $5}')"
TRUST_IMG="${UBOOT_OVERLOAD}"
MAINLINE_UBOOT="$(echo ${board_conf} | awk -F':' '{print $6}')"
BOOTLOADER_IMG="$(echo ${board_conf} | awk -F':' '{print $7}')"
KERNEL_TAGS="$(echo ${board_conf} | awk -F':' '{print $9}')"
PLATFORM="$(echo ${board_conf} | awk -F':' '{print $10}')"
FAMILY="$(echo ${board_conf} | awk -F':' '{print $11}')"
BOOT_CONF="$(echo ${board_conf} | awk -F':' '{print $12}')"
CONTRIBUTORS="$(echo ${board_conf} | awk -F':' '{print $13}')"
# Check whether the key parameters are correct
[[ -n "${PLATFORM}" ]] || error_msg "Invalid PLATFORM parameter: [ ${PLATFORM} ]"
# Set supported platform name
support_platform=("amlogic" "rockchip" "allwinner")
[[ -n "$(echo "${support_platform[*]}" | grep -w "${PLATFORM}")" ]] || error_msg "[ ${PLATFORM} ] not supported."
# Replace custom kernel tags
[[ -n "${kernel_usage}" && "${KERNEL_TAGS}" == "${default_tags}" ]] && KERNEL_TAGS="${kernel_usage}"
}
make_image() {
process_msg "(1/6) Make OpenWrt image."
cd ${current_path}
# Set Armbian image file parameters
[[ "${PLATFORM}" == "amlogic" ]] && {
skip_mb="4"
partition_table_type="msdos"
bootfs_type="fat32"
}
[[ "${PLATFORM}" == "rockchip" ]] && {
skip_mb="16"
partition_table_type="gpt"
bootfs_type="ext4"
}
[[ "${PLATFORM}" == "allwinner" ]] && {
skip_mb="16"
partition_table_type="msdos"
bootfs_type="fat32"
}
# Set OpenWrt filename
[[ -d "${out_path}" ]] || mkdir -p ${out_path}
openwrt_filename="openwrt${source_codename}_${PLATFORM}_${board}_k${kernel}_$(date +"%Y.%m.%d").img"
build_image_file="${out_path}/${openwrt_filename}"
rm -f ${build_image_file}
IMG_SIZE="$((skip_mb + boot_mb + root_mb))"
truncate -s ${IMG_SIZE}M ${build_image_file} >/dev/null 2>&1
parted -s ${build_image_file} mklabel ${partition_table_type} 2>/dev/null
parted -s ${build_image_file} mkpart primary ${bootfs_type} $((skip_mb))MiB $((skip_mb + boot_mb - 1))MiB 2>/dev/null
parted -s ${build_image_file} mkpart primary btrfs $((skip_mb + boot_mb))MiB 100% 2>/dev/null
# Mount the OpenWrt image file
loop_new="$(losetup -P -f --show "${build_image_file}")"
[[ -n "${loop_new}" ]] || error_msg "losetup ${build_image_file} failed."
# Confirm BOOT_UUID
BOOT_UUID="$(cat /proc/sys/kernel/random/uuid)"
[[ -z "${BOOT_UUID}" ]] && BOOT_UUID="$(uuidgen)"
[[ -z "${BOOT_UUID}" ]] && error_msg "The uuidgen is invalid, cannot continue."
# Confirm ROOTFS_UUID
ROOTFS_UUID="$(cat /proc/sys/kernel/random/uuid)"
[[ -z "${ROOTFS_UUID}" ]] && ROOTFS_UUID="$(uuidgen)"
[[ -z "${ROOTFS_UUID}" ]] && error_msg "The uuidgen is invalid, cannot continue."
# Format bootfs partition
if [[ "${bootfs_type}" == "fat32" ]]; then
mkfs.vfat -F 32 -n "BOOT" ${loop_new}p1 >/dev/null 2>&1
else
mkfs.ext4 -F -q -U ${BOOT_UUID} -L "BOOT" -b 4k -m 0 ${loop_new}p1 >/dev/null 2>&1
fi
# Format rootfs partition
mkfs.btrfs -f -U ${ROOTFS_UUID} -L "ROOTFS" -m single ${loop_new}p2 >/dev/null 2>&1
# Write the specific bootloader for [ Amlogic ] boxes
[[ "${PLATFORM}" == "amlogic" ]] && {
bootloader_path="${uboot_path}/${PLATFORM}/bootloader"
if [[ -n "${MAINLINE_UBOOT}" && -f "${bootloader_path}/${MAINLINE_UBOOT}" ]]; then
dd if="${bootloader_path}/${MAINLINE_UBOOT}" of="${loop_new}" conv=fsync bs=1 count=444 2>/dev/null
dd if="${bootloader_path}/${MAINLINE_UBOOT}" of="${loop_new}" conv=fsync bs=512 skip=1 seek=1 2>/dev/null
#echo -e "${INFO} 01. For [ ${board} ] write bootloader: ${MAINLINE_UBOOT}"
elif [[ -n "${BOOTLOADER_IMG}" && -f "${bootloader_path}/${BOOTLOADER_IMG}" ]]; then
dd if="${bootloader_path}/${BOOTLOADER_IMG}" of="${loop_new}" conv=fsync bs=1 count=444 2>/dev/null
dd if="${bootloader_path}/${BOOTLOADER_IMG}" of="${loop_new}" conv=fsync bs=512 skip=1 seek=1 2>/dev/null
#echo -e "${INFO} 02. For [ ${board} ] write bootloader: ${BOOTLOADER_IMG}"
fi
}
# Write the specific bootloader for [ Rockchip ] boxes
[[ "${PLATFORM}" == "rockchip" ]] && {
bootloader_path="${uboot_path}/${PLATFORM}/${board}"
if [[ -n "${BOOTLOADER_IMG}" && -f "${bootloader_path}/${BOOTLOADER_IMG}" ]] &&
[[ -n "${MAINLINE_UBOOT}" && -f "${bootloader_path}/${MAINLINE_UBOOT}" ]] &&
[[ -n "${TRUST_IMG}" && -f "${bootloader_path}/${TRUST_IMG}" ]]; then
dd if="${bootloader_path}/${BOOTLOADER_IMG}" of="${loop_new}" conv=fsync,notrunc bs=512 seek=64 2>/dev/null
dd if="${bootloader_path}/${MAINLINE_UBOOT}" of="${loop_new}" conv=fsync,notrunc bs=512 seek=16384 2>/dev/null
dd if="${bootloader_path}/${TRUST_IMG}" of="${loop_new}" conv=fsync,notrunc bs=512 seek=24576 2>/dev/null
#echo -e "${INFO} 01. For [ ${board} ] write bootloader: ${TRUST_IMG}"
elif [[ -n "${BOOTLOADER_IMG}" && -f "${bootloader_path}/${BOOTLOADER_IMG}" ]] &&
[[ -n "${MAINLINE_UBOOT}" && -f "${bootloader_path}/${MAINLINE_UBOOT}" ]]; then
dd if="${bootloader_path}/${BOOTLOADER_IMG}" of="${loop_new}" conv=fsync,notrunc bs=512 seek=64 2>/dev/null
dd if="${bootloader_path}/${MAINLINE_UBOOT}" of="${loop_new}" conv=fsync,notrunc bs=512 seek=16384 2>/dev/null
#echo -e "${INFO} 02. For [ ${board} ] write bootloader: ${MAINLINE_UBOOT}"
elif [[ -n "${BOOTLOADER_IMG}" && -f "${bootloader_path}/${BOOTLOADER_IMG}" ]]; then
dd if="${bootloader_path}/${BOOTLOADER_IMG}" of="${loop_new}" conv=fsync,notrunc bs=512 skip=64 seek=64 2>/dev/null
#echo -e "${INFO} 03. For [ ${board} ] write bootloader: ${BOOTLOADER_IMG}"
fi
}
# Write the specific bootloader for [ Allwinner ] boxes
[[ "${PLATFORM}" == "allwinner" ]] && {
bootloader_path="${uboot_path}/${PLATFORM}/${board}"
if [[ -n "${BOOTLOADER_IMG}" && -f "${bootloader_path}/${BOOTLOADER_IMG}" ]] &&
[[ -n "${MAINLINE_UBOOT}" && -f "${bootloader_path}/${MAINLINE_UBOOT}" ]]; then
dd if="${bootloader_path}/${BOOTLOADER_IMG}" of="${loop_new}" conv=fsync,notrunc bs=8k seek=1 2>/dev/null
dd if="${bootloader_path}/${MAINLINE_UBOOT}" of="${loop_new}" conv=fsync,notrunc bs=8k seek=5 2>/dev/null
#echo -e "${INFO} 01. For [ ${board} ] write bootloader: ${MAINLINE_UBOOT}"
elif [[ -n "${BOOTLOADER_IMG}" && -f "${bootloader_path}/${BOOTLOADER_IMG}" ]]; then
dd if="${bootloader_path}/${BOOTLOADER_IMG}" of="${loop_new}" conv=fsync,notrunc bs=8k seek=1 2>/dev/null
#echo -e "${INFO} 02. For [ ${board} ] write bootloader: ${BOOTLOADER_IMG}"
fi
}
}
extract_openwrt() {
process_msg "(2/6) Extract OpenWrt files."
cd ${current_path}
# Create a dual-partition general directory
tag_bootfs="${tmp_path}/${kernel}/${board}/bootfs"
tag_rootfs="${tmp_path}/${kernel}/${board}/rootfs"
mkdir -p ${tag_bootfs} ${tag_rootfs}
chown root:root ${tag_bootfs} ${tag_rootfs}
# Mount bootfs
if [[ "${bootfs_type}" == "fat32" ]]; then
mount_try vfat ${loop_new}p1 ${tag_bootfs}
else
mount_try ext4 ${loop_new}p1 ${tag_bootfs}
fi
# Mount rootfs
mount_try btrfs ${loop_new}p2 ${tag_rootfs}
# Create snapshot directory
btrfs subvolume create ${tag_rootfs}/etc >/dev/null 2>&1
# Unzip the OpenWrt rootfs file
tar -mxzf ${openwrt_path}/${openwrt_default_file} -C ${tag_rootfs}
rm -rf ${tag_rootfs}/lib/modules/*
rm -f ${tag_rootfs}/rom/sbin/firstboot
# Copy the common files
[[ -d "${common_files}" ]] && cp -af --no-preserve=ownership ${common_files}/* ${tag_rootfs}
# Copy the platform files
platform_bootfs="${platform_files}/${PLATFORM}/bootfs"
platform_rootfs="${platform_files}/${PLATFORM}/rootfs"
[[ -d "${platform_bootfs}" ]] && cp -rf ${platform_bootfs}/* ${tag_bootfs}
[[ -d "${platform_rootfs}" ]] && cp -af --no-preserve=ownership ${platform_rootfs}/* ${tag_rootfs}
# Copy the different files
different_bootfs="${different_files}/${board}/bootfs"
different_rootfs="${different_files}/${board}/rootfs"
[[ -d "${different_bootfs}" ]] && cp -rf ${different_bootfs}/* ${tag_bootfs}
[[ -d "${different_rootfs}" ]] && cp -af --no-preserve=ownership ${different_rootfs}/* ${tag_rootfs}
# Copy the bootloader files
[[ -d "${tag_rootfs}/lib/u-boot" ]] || mkdir -p "${tag_rootfs}/lib/u-boot"
rm -rf ${tag_rootfs}/lib/u-boot/*
[[ -d "${bootloader_path}" ]] && cp -af --no-preserve=ownership ${bootloader_path}/* ${tag_rootfs}/lib/u-boot
# Copy the overload files
[[ "${PLATFORM}" == "amlogic" ]] && cp -rf ${uboot_path}/${PLATFORM}/overload/* ${tag_bootfs}
# Remove the .svn and .git directories
rm -rf $(find ${tmp_path} -type d -name '.svn' -o -name '.git')
}
replace_kernel() {
process_msg "(3/6) Replace the kernel."
cd ${current_path}
# Determine custom kernel filename
kernel_boot="$(ls ${kernel_path}/${kd}/${kernel}/boot-${kernel}*.tar.gz 2>/dev/null | head -n 1)"
kernel_name="${kernel_boot##*/}" && kernel_name="${kernel_name:5:-7}"
[[ -n "${kernel_name}" ]] || error_msg "Missing kernel files for [ ${kernel} ]"
kernel_dtb="${kernel_path}/${kd}/${kernel}/dtb-${PLATFORM}-${kernel_name}.tar.gz"
kernel_modules="${kernel_path}/${kd}/${kernel}/modules-${kernel_name}.tar.gz"
[[ -s "${kernel_boot}" && -s "${kernel_dtb}" && -s "${kernel_modules}" ]] || error_msg "The 3 kernel missing."
# 01. For /boot five files
tar -mxzf ${kernel_boot} -C ${tag_bootfs}
[[ "${PLATFORM}" == "amlogic" ]] && (cd ${tag_bootfs} && cp -f uInitrd-${kernel_name} uInitrd && cp -f vmlinuz-${kernel_name} zImage)
[[ "${PLATFORM}" == "rockchip" ]] && (cd ${tag_bootfs} && ln -sf uInitrd-${kernel_name} uInitrd && ln -sf vmlinuz-${kernel_name} Image)
[[ "${PLATFORM}" == "allwinner" ]] && (cd ${tag_bootfs} && cp -f uInitrd-${kernel_name} uInitrd && cp -f vmlinuz-${kernel_name} Image)
[[ "$(ls ${tag_bootfs}/*${kernel_name} -l 2>/dev/null | grep "^-" | wc -l)" -ge "2" ]] || error_msg "The /boot files is missing."
[[ "${PLATFORM}" == "amlogic" ]] && get_textoffset "${tag_bootfs}/zImage"
# 02. For /boot/dtb/${PLATFORM}/*
[[ -d "${tag_bootfs}/dtb/${PLATFORM}" ]] || mkdir -p ${tag_bootfs}/dtb/${PLATFORM}
tar -mxzf ${kernel_dtb} -C ${tag_bootfs}/dtb/${PLATFORM}
[[ "${PLATFORM}" == "rockchip" ]] && ln -sf dtb ${tag_bootfs}/dtb-${kernel_name}
[[ "$(ls ${tag_bootfs}/dtb/${PLATFORM} -l 2>/dev/null | grep "^-" | wc -l)" -ge "2" ]] || error_msg "/boot/dtb/${PLATFORM} files is missing."
# 03. For /lib/modules/${kernel_name}
tar -mxzf ${kernel_modules} -C ${tag_rootfs}/lib/modules
(cd ${tag_rootfs}/lib/modules/${kernel_name}/ && rm -f build source *.ko 2>/dev/null && find ./ -type f -name '*.ko' -exec ln -s {} ./ \;)
[[ "$(ls ${tag_rootfs}/lib/modules/${kernel_name} -l 2>/dev/null | grep "^d" | wc -l)" -eq "1" ]] || error_msg "/usr/lib/modules kernel folder is missing."
}
refactor_bootfs() {
process_msg "(4/6) Refactor bootfs files."
cd ${tag_bootfs}
# Process Amlogic series boot partition files
[[ "${PLATFORM}" == "amlogic" && "${need_overload}" == "yes" ]] && {
# Add u-boot.ext for Amlogic 5.10 kernel
if [[ -n "${UBOOT_OVERLOAD}" && -f "${UBOOT_OVERLOAD}" ]]; then
cp -f ${UBOOT_OVERLOAD} u-boot.ext
chmod +x u-boot.ext
elif [[ -z "${UBOOT_OVERLOAD}" || ! -f "${UBOOT_OVERLOAD}" ]]; then
error_msg "${board} Board does not support using ${kernel} kernel, missing u-boot."
fi
}
# Set uEnv.txt & extlinux.conf mount parameters
uenv_rootdev="UUID=${ROOTFS_UUID} rootflags=compress=zstd:6 rootfstype=btrfs"
# Set armbianEnv.txt mount parameters
armbianenv_rootdev="UUID=${ROOTFS_UUID}"
armbianenv_rootflags="compress=zstd:6"
# Edit the uEnv.txt
uenv_conf_file="uEnv.txt"
[[ -f "${uenv_conf_file}" ]] && {
sed -i "s|LABEL=ROOTFS|${uenv_rootdev}|g" ${uenv_conf_file}
sed -i "s|meson.*.dtb|${FDTFILE}|g" ${uenv_conf_file}
sed -i "s|sun.*.dtb|${FDTFILE}|g" ${uenv_conf_file}
sed -i "s|rk.*.dtb|${FDTFILE}|g" ${uenv_conf_file}
}
# Add an alternate file (/boot/extlinux/extlinux.conf)
boot_extlinux_file="extlinux/extlinux.conf.bak"
rename_extlinux_file="extlinux/extlinux.conf"
[[ -f "${boot_extlinux_file}" ]] && {
sed -i "s|LABEL=ROOTFS|${uenv_rootdev}|g" ${boot_extlinux_file}
sed -i "s|meson.*.dtb|${FDTFILE}|g" ${boot_extlinux_file}
sed -i "s|sun.*.dtb|${FDTFILE}|g" ${boot_extlinux_file}
sed -i "s|rk.*.dtb|${FDTFILE}|g" ${boot_extlinux_file}
# If needed, such as t95z(s905x), rename delete .bak
[[ "${BOOT_CONF}" == "extlinux.conf" ]] && mv -f ${boot_extlinux_file} ${rename_extlinux_file}
}
# Edit the armbianEnv.txt
armbianenv_conf_file="armbianEnv.txt"
[[ -f "${armbianenv_conf_file}" ]] && {
sed -i "s|^fdtfile=.*|fdtfile=${PLATFORM}/${FDTFILE}|g" ${armbianenv_conf_file}
sed -i "s|^rootdev=.*|rootdev=${armbianenv_rootdev}|g" ${armbianenv_conf_file}
sed -i "s|^rootfstype=.*|rootfstype=btrfs|g" ${armbianenv_conf_file}
sed -i "s|^rootflags=.*|rootflags=${armbianenv_rootflags}|g" ${armbianenv_conf_file}
sed -i "s|^overlay_prefix=.*|overlay_prefix=${FAMILY}|g" ${armbianenv_conf_file}
}
# Check device configuration files
[[ -f "${uenv_conf_file}" || -f "${rename_extlinux_file}" || -f "${armbianenv_conf_file}" ]] || error_msg "Missing [ /boot/*Env.txt ]"
}
refactor_rootfs() {
process_msg "(5/6) Refactor rootfs files."
cd ${tag_rootfs}
# Add directory
mkdir -p .reserved boot run
# Edit fstab
[[ -f "etc/fstab" && -f "etc/config/fstab" ]] || error_msg "The [ fstab ] files does not exist."
sed -i "s|LABEL=ROOTFS|UUID=${ROOTFS_UUID}|g" etc/fstab
sed -i "s|option label 'ROOTFS'|option uuid '${ROOTFS_UUID}'|g" etc/config/fstab
# Set the keyword for tags in Releases
[[ -n "${source_codename}" ]] && {
sed -i "s|option amlogic_firmware_tag.*|option amlogic_firmware_tag '${source_codename}'|g" etc/config/amlogic
}
# Modify the default script to [ bash ] for [ cpustat ]
[[ -x "bin/bash" ]] && {
sed -i "s/\/bin\/ash/\/bin\/bash/" etc/passwd
sed -i "s/\/bin\/ash/\/bin\/bash/" usr/libexec/login.sh
}
# Turn off hw_flow by default
[[ -f "etc/config/turboacc" ]] && {
sed -i "s|option hw_flow.*|option hw_flow '0'|g" etc/config/turboacc
sed -i "s|option sw_flow.*|option sw_flow '0'|g" etc/config/turboacc
}
# Add custom startup script
custom_startup_script="etc/custom_service/start_service.sh"
[[ -x "${custom_startup_script}" && -f "etc/rc.local" ]] && {
sed -i '/^exit 0/i\bash /etc/custom_service/start_service.sh' etc/rc.local
}
# Modify the cpu mode to schedutil
[[ -f "etc/config/cpufreq" ]] && sed -i "s/ondemand/schedutil/" etc/config/cpufreq
# Turn off speed limit by default
[[ -f "etc/config/nft-qos" ]] && sed -i "s|option limit_enable.*|option limit_enable '0'|g" etc/config/nft-qos
# Add USB and wireless network drivers
[[ -f "etc/modules.d/usb-net-rtl8150" ]] || echo "rtl8150" >etc/modules.d/usb-net-rtl8150
# USB RTL8152/8153/8156 network card Driver
[[ -f "etc/modules.d/usb-net-rtl8152" ]] || echo "r8152" >etc/modules.d/usb-net-rtl8152
# USB AX88179 network card Driver
[[ -f "etc/modules.d/usb-net-asix-ax88179" ]] || echo "ax88179_178a" >etc/modules.d/usb-net-asix-ax88179
# brcmfmac built-in wireless network card Driver
echo "brcmfmac" >etc/modules.d/brcmfmac
echo "brcmutil" >etc/modules.d/brcmutil
echo "bcmdhd" >etc/modules.d/bcmdhd
# USB Realtek RTL8188EU Wireless LAN Driver
echo "r8188eu" >etc/modules.d/rtl8188eu
# Realtek RTL8189FS Wireless LAN Driver
echo "8189fs" >etc/modules.d/8189fs
# Realtek RTL8188FU Wireless LAN Driver
echo "rtl8188fu" >etc/modules.d/rtl8188fu
# Realtek RTL8822CS Wireless LAN Driver
echo "88x2cs" >etc/modules.d/88x2cs
# USB Ralink Wireless LAN Driver
echo "rt2500usb" >etc/modules.d/rt2500-usb
echo "rt2800usb" >etc/modules.d/rt2800-usb
echo "rt2x00usb" >etc/modules.d/rt2x00-usb
# USB Mediatek Wireless LAN Driver
echo "mt7601u" >etc/modules.d/mt7601u
echo "mt7663u" >etc/modules.d/mt7663u
echo "mt76x0u" >etc/modules.d/mt76x0u
echo "mt76x2u" >etc/modules.d/mt76x2u
echo "mt76x2e" >etc/modules.d/mt76x2e
echo "mt7921e" >etc/modules.d/mt7921e
echo "mt7915e" >etc/modules.d/mt7915e
# GPU Driver
echo "panfrost" >etc/modules.d/panfrost
# PWM Driver
echo "pwm_meson" >etc/modules.d/pwm_meson
# Ath10k Driver
echo "ath10k_core" >etc/modules.d/ath10k_core
echo "ath10k_sdio" >etc/modules.d/ath10k_sdio
echo "ath10k_usb" >etc/modules.d/ath10k_usb
echo "ath10k_pci" >etc/modules.d/ath10k-pci
echo "ath10k_core frame_mode=2" >etc/modules.d/ath10k
# Enable watchdog driver
echo "meson_gxbb_wdt" >etc/modules.d/watchdog
# For rk3588
echo "bifrost_kbase" >etc/modules.d/rk_gpu
echo "rknpu" >etc/modules.d/rk_npu
# For rk3568
echo "rockchipdrm" >etc/modules.d/drm-rockchip
echo "rk_crypto2" >etc/modules.d/rk_crypto
echo -e "snd_soc_simple_card_utils\nsnd_soc_simple_card\nsnd_soc_rockchip_i2s" >etc/modules.d/snd-rk3568
echo "pwm_fan" >etc/modules.d/pwm-fan
echo "option" >etc/modules.d/usb-serial-option
# For rk3328
echo -e "snd_soc_simple_card_utils\nsnd_soc_simple_card\nsnd_soc_rockchip_i2s" >etc/modules.d/snd-rk3328
# Add blacklist
mkdir -p etc/modprobe.d
cat >etc/modprobe.d/99-local.conf <<EOF
blacklist snd_soc_meson_aiu_i2s
alias brnf br_netfilter
alias pwm pwm_meson
alias wifi brcmfmac
EOF
# Adjust startup settings
[[ -f "etc/init.d/boot" ]] && {
if ! grep -q 'ulimit -n' etc/init.d/boot; then
sed -i '/kmodloader/i \\tulimit -n 51200\n' etc/init.d/boot
fi
if ! grep -q '/tmp/update' etc/init.d/boot; then
sed -i '/mkdir -p \/tmp\/.uci/a \\tmkdir -p \/tmp\/update' etc/init.d/boot
fi
}
[[ -f "etc/inittab" ]] && {
sed -i 's/ttyAMA0/ttyAML0/' etc/inittab
sed -i 's/ttyS0/tty0/' etc/inittab
}
# Automatic expansion of the third and fourth partitions
echo "yes" >root/.todo_rootfs_resize
# Relink the kmod program
[[ -x "sbin/kmod" ]] && (
kmod_list="depmod insmod lsmod modinfo modprobe rmmod"
for ki in ${kmod_list}; do
rm -f sbin/${ki}
ln -sf kmod sbin/${ki}
done
)
# Add wireless master mode
wireless_mac80211="lib/netifd/wireless/mac80211.sh"
[[ -f "${wireless_mac80211}" ]] && {
cp -f ${wireless_mac80211} ${wireless_mac80211}.bak
sed -i "s|iw |ipconfig |g" ${wireless_mac80211}
}
# Get random macaddr
mac_hexchars="0123456789ABCDEF"
mac_end=$(for i in {1..6}; do echo -n ${mac_hexchars:$((${RANDOM} % 16)):1}; done | sed -e 's/\(..\)/:\1/g')
random_macaddr="9E:62${mac_end}"
# Optimize wifi/bluetooth module
[[ -d "lib/firmware/brcm" ]] && (