forked from unifreq/openwrt_packit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mk_s922x_gtking.sh
executable file
·673 lines (577 loc) · 19.1 KB
/
mk_s922x_gtking.sh
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
#!/bin/bash
echo "========================= begin $0 ==========================="
WORK_DIR="${PWD}/tmp"
if [ ! -d ${WORK_DIR} ];then
mkdir -p ${WORK_DIR}
fi
# 源镜像文件
##########################################################################
source make.env
# 盒子型号识别参数
SOC=s922x
BOARD=gtking
SUBVER=$1
MODULES_TGZ=${KERNEL_PKG_HOME}/modules-${KERNEL_VERSION}.tar.gz
BOOT_TGZ=${KERNEL_PKG_HOME}/boot-${KERNEL_VERSION}.tar.gz
DTBS_TGZ=${KERNEL_PKG_HOME}/dtb-amlogic-${KERNEL_VERSION}.tar.gz
if [ ! -f ${MODULES_TGZ} ];then
echo "${MODULES_TGZ} not exists!"
exit 1
fi
if [ ! -f ${BOOT_TGZ} ];then
echo "${BOOT_TGZ} not exists!"
exit 1
fi
if [ ! -f ${DTBS_TGZ} ];then
echo "${DTBS_TGZ} not exists!"
exit 1
fi
###########################################################################
# Openwrt root 源文件
OP_ROOT_TGZ="openwrt-armvirt-64-default-rootfs.tar.gz"
OPWRT_ROOTFS_GZ="${PWD}/${OP_ROOT_TGZ}"
echo "Use $OPWRT_ROOTFS_GZ as openwrt rootfs!"
# 目标镜像文件
TGT_IMG="${WORK_DIR}/openwrt_${SOC}_${BOARD}_${OPENWRT_VER}_k${KERNEL_VERSION}${SUBVER}.img"
# 判断内核版本是否 >= 5.10
K_VER=$(echo "$KERNEL_VERSION" | cut -d '.' -f1)
K_MAJ=$(echo "$KERNEL_VERSION" | cut -d '.' -f2)
if [ $K_VER -eq 5 ];then
if [ $K_MAJ -ge 10 ];then
K510=1
else
K510=0
fi
elif [ $K_VER -gt 5 ];then
K510=1
else
K510=0
fi
# 补丁和脚本
###########################################################################
REGULATORY_DB="${PWD}/files/regulatory.db.tar.gz"
KMOD="${PWD}/files/kmod"
KMOD_BLACKLIST="${PWD}/files/kmod_blacklist"
MAC_SCRIPT1="${PWD}/files/fix_wifi_macaddr.sh"
MAC_SCRIPT2="${PWD}/files/find_macaddr.pl"
MAC_SCRIPT3="${PWD}/files/inc_macaddr.pl"
CPUSTAT_SCRIPT="${PWD}/files/cpustat"
CPUSTAT_SCRIPT_PY="${PWD}/files/cpustat.py"
CPUSTAT_PATCH="${PWD}/files/luci-admin-status-index-html.patch"
CPUSTAT_PATCH_02="${PWD}/files/luci-admin-status-index-html-02.patch"
GETCPU_SCRIPT="${PWD}/files/getcpu"
TTYD="${PWD}/files/ttyd"
FLIPPY="${PWD}/files/flippy"
BANNER="${PWD}/files/banner"
# 20200314 add
FMW_HOME="${PWD}/files/firmware"
SMB4_PATCH="${PWD}/files/smb4.11_enable_smb1.patch"
SYSCTL_CUSTOM_CONF="${PWD}/files/99-custom.conf"
# 20200709 add
COREMARK="${PWD}/files/coremark.sh"
# 20200930 add
INST_SCRIPT="${PWD}/files/s922x/install-to-emmc.sh"
UPDATE_SCRIPT="${PWD}/files/s922x/update-to-emmc.sh"
SND_MOD="${PWD}/files/s922x/snd-meson-g12"
DAEMON_JSON="${PWD}/files/s922x/daemon.json"
# 20201006 add
FORCE_REBOOT="${PWD}/files/s922x/reboot"
# 20201017 add
BAL_ETH_IRQ="${PWD}/files/balethirq.pl"
# 20201026 add
FIX_CPU_FREQ="${PWD}/files/fixcpufreq.pl"
SYSFIXTIME_PATCH="${PWD}/files/sysfixtime.patch"
# 20201128 add
SSL_CNF_PATCH="${PWD}/files/openssl_engine.patch"
# 20201212 add
BAL_CONFIG="${PWD}/files/s922x/balance_irq"
CPUFREQ_INIT="${PWD}/files/s922x/cpufreq"
# 20210302 modify
FIP_HOME="${PWD}/files/meson_btld/with_fip/s922x"
UBOOT_WITH_FIP="${FIP_HOME}/gtkingpro-u-boot.bin.sd.bin"
UBOOT_WITHOUT_FIP_HOME="${PWD}/files/meson_btld/without_fip"
UBOOT_WITHOUT_FIP="u-boot-gtkingpro.bin"
# 20210208 add
WIRELESS_CONFIG="${PWD}/files/s922x/wireless"
# 20210307 add
SS_LIB="${PWD}/files/ss-glibc/lib-glibc.tar.xz"
SS_BIN="${PWD}/files/ss-glibc/ss-bin-glibc.tar.xz"
JQ="${PWD}/files/jq"
# 20210330 add
DOCKERD_PATCH="${PWD}/files/dockerd.patch"
# 20200416 add
FIRMWARE_TXZ="${PWD}/files/firmware_armbian.tar.xz"
BOOTFILES_HOME="${PWD}/files/bootfiles/amlogic"
GET_RANDOM_MAC="${PWD}/files/get_random_mac.sh"
# 20210618 add
DOCKER_README="${PWD}/files/DockerReadme.pdf"
# 20210704 add
SYSINFO_SCRIPT="${PWD}/files/30-sysinfo.sh"
###########################################################################
# 检查环境
if [ $(id -u) -ne 0 ];then
echo "这个脚本需要用root用户来执行,你好象不是root吧?"
exit 1
fi
if [ ! -f "$OPWRT_ROOTFS_GZ" ];then
echo "Openwrt镜像: ${OPWRT_ROOTFS_GZ} 不存在, 请检查!"
exit 1
fi
if mkfs.btrfs -V >/dev/null;then
echo "check mkfs.btrfs ok"
else
echo "mkfs.btrfs 程序不存在,请安装 btrfsprogs"
exit 1
fi
if mkfs.vfat --help 1>/dev/nul 2>&1;then
echo "check mkfs.vfat ok"
else
echo "mkfs.vfat 程序不存在,请安装 dosfstools"
exit 1
fi
if uuidgen>/dev/null;then
echo "check uuidgen ok"
else
echo "uuidgen 程序不存在,请安装 uuid-runtime"
exit 1
fi
if losetup -V >/dev/null;then
echo "check losetup ok"
else
echo "losetup 程序不存在,请安装 mount"
exit 1
fi
if lsblk --version >/dev/null 2>&1;then
echo "check lsblk ok"
else
echo "lsblk 程序不存在,请安装 util-linux"
exit 1
fi
if parted --version >/dev/null 2>&1;then
echo "check parted ok"
else
echo "parted 程序不存在,请安装 parted"
exit 1
fi
# work dir
cd $WORK_DIR
TEMP_DIR=$(mktemp -p $WORK_DIR)
rm -rf $TEMP_DIR
mkdir -p $TEMP_DIR
echo $TEMP_DIR
# temp dir
cd $TEMP_DIR
losetup -D
# 创建空白镜像文件
echo "创建空白的目标镜像文件 ..."
SKIP_MB=4
BOOT_MB=256
ROOTFS_MB=640
SIZE=$((SKIP_MB + BOOT_MB + ROOTFS_MB))
echo $SIZE
dd if=/dev/zero of=$TGT_IMG bs=1M count=$SIZE
losetup -f -P $TGT_IMG
TGT_DEV=$(losetup | grep "$TGT_IMG" | gawk '{print $1}')
echo "创建磁盘分区和文件系统 ..."
parted -s $TGT_DEV mklabel msdos 2>/dev/null
BEGIN=$((SKIP_MB * 1024 * 1024))
END=$(( BOOT_MB * 1024 * 1024 + BEGIN -1))
parted -s $TGT_DEV mkpart primary fat32 ${BEGIN}b ${END}b 2>/dev/null
if [ $? -ne 0 ];then
echo "创建 boot 分区失败!"
losetup -D
exit 1
fi
BEGIN=$((END + 1))
END=$((ROOTFS_MB * 1024 * 1024 + BEGIN -1))
parted -s $TGT_DEV mkpart primary btrfs ${BEGIN}b 100% 2>/dev/null
if [ $? -ne 0 ];then
echo "创建 rootfs 分区失败!"
losetup -D
exit 1
fi
parted -s $TGT_DEV print 2>/dev/null
# 格式化文件系统
mkfs.vfat -n BOOT ${TGT_DEV}p1
ROOTFS_UUID=$(uuidgen)
echo "ROOTFS_UUID = $ROOTFS_UUID"
mkfs.btrfs -U ${ROOTFS_UUID} -L ROOTFS -m single ${TGT_DEV}p2
echo "挂载目标设备 ..."
TGT_BOOT=${TEMP_DIR}/tgt_boot
TGT_ROOT=${TEMP_DIR}/tgt_root
mkdir $TGT_BOOT $TGT_ROOT
mount -t vfat ${TGT_DEV}p1 $TGT_BOOT
mount -t btrfs -o compress=zstd ${TGT_DEV}p2 $TGT_ROOT
echo "创建 /etc 子卷 ..."
btrfs subvolume create $TGT_ROOT/etc
# extract root
echo "openwrt 根文件系统解包 ... "
(
cd $TGT_ROOT && \
tar --exclude="./lib/firmware/*" --exclude="./lib/modules/*" -xzf $OPWRT_ROOTFS_GZ && \
rm -rf ./lib/firmware/* ./lib/modules/* && \
mkdir -p .reserved boot rom proc sys run
)
echo "Armbian firmware 解包 ... "
(
cd ${TGT_ROOT} && \
tar xJf $FIRMWARE_TXZ
)
echo "内核模块解包 ... "
(
cd ${TGT_ROOT} && \
mkdir -p lib/modules && \
cd lib/modules && \
tar xzf ${MODULES_TGZ}
)
echo "boot 文件解包 ... "
(
cd ${TGT_BOOT} && \
cp -v "${BOOTFILES_HOME}"/* . && \
tar xzf "${BOOT_TGZ}" && \
rm -f initrd.img-${KERNEL_VERSION} && \
cp -v vmlinuz-${KERNEL_VERSION} zImage && \
cp -v uInitrd-${KERNEL_VERSION} uInitrd && \
cp -v ${UBOOT_WITHOUT_FIP_HOME}/* . && \
mkdir -p dtb/amlogic && \
cd dtb/amlogic && \
tar xzf "${DTBS_TGZ}" && \
sync
)
while :;do
lsblk -l -o NAME,PATH,UUID
BOOT_UUID=$(lsblk -l -o NAME,PATH,UUID | grep "${TGT_DEV}p1" | awk '{print $3}')
#ROOTFS_UUID=$(lsblk -l -o NAME,PATH,UUID | grep "${TGT_DEV}p2" | awk '{print $3}')
echo "BOOT_UUID is $BOOT_UUID"
echo "ROOTFS_UUID is $ROOTFS_UUID"
if [ "$ROOTFS_UUID" != "" ];then
break
fi
sleep 1
done
echo "修改引导分区相关配置 ... "
# modify boot
cd $TGT_BOOT
rm -f uEnv.ini
cat > uEnv.txt <<EOF
LINUX=/zImage
INITRD=/uInitrd
# 下列 dtb,用到哪个就把哪个的#删除,其它的则加上 # 在行首
# 用于 Belink GT-King
#FDT=/dtb/amlogic/meson-g12b-gtking.dtb
# 用于 Belink GT-King Pro
FDT=/dtb/amlogic/meson-g12b-gtking-pro.dtb
APPEND=root=UUID=${ROOTFS_UUID} rootfstype=btrfs rootflags=compress=zstd console=ttyAML0,115200n8 console=tty0 no_console_suspend consoleblank=0 fsck.fix=yes fsck.repair=yes net.ifnames=0 cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory swapaccount=1
EOF
# 替换dtb文件
[ "$REPLACE_DTB" == "y" ] && [ -f "$DTB_FILE" ] && cp "$DTB_FILE" ./dtb/amlogic/
echo "uEnv.txt --->"
cat uEnv.txt
# 5.10以后的内核,需要增加u-boot重载
if [ $K510 -eq 1 ];then
cp -fv ${UBOOT_WITHOUT_FIP} u-boot.ext
rm -f u-boot.sd u-boot.usb
else
rm -f u-boot*.bin
fi
echo "修改根文件系统相关配置 ... "
# modify root
cd $TGT_ROOT
( [ -f "$SS_LIB" ] && cd lib && tar xJf "$SS_LIB" )
if [ -f "$SS_BIN" ];then
(
cd usr/bin
mkdir -p ss-bin-musl && mv -f ss-server ss-redir ss-local ss-tunnel ss-bin-musl/ 2>/dev/null
tar xJf "$SS_BIN"
)
fi
if [ -f "$JQ" ] && [ ! -f "./usr/bin/jq" ];then
cp -v ${JQ} ./usr/bin
fi
if [ -d "${FIP_HOME}" ];then
mkdir -p lib/u-boot
cp -v "${FIP_HOME}"/../*.sh lib/u-boot/
cp -v "${FIP_HOME}"/*.sd.bin lib/u-boot/
fi
[ -f $INST_SCRIPT ] && cp $INST_SCRIPT root/
# [ -f $UPDATE_SCRIPT ] && cp $UPDATE_SCRIPT root/
[ -f $MAC_SCRIPT1 ] && cp $MAC_SCRIPT1 usr/bin/
[ -f $MAC_SCRIPT2 ] && cp $MAC_SCRIPT2 usr/bin/
[ -f $MAC_SCRIPT3 ] && cp $MAC_SCRIPT3 usr/bin/
[ -f $DAEMON_JSON ] && mkdir -p "etc/docker" && cp $DAEMON_JSON "etc/docker/daemon.json"
[ -f $FORCE_REBOOT ] && cp $FORCE_REBOOT usr/sbin/
[ -f $COREMARK ] && [ -f "etc/coremark.sh" ] && cp -f $COREMARK "etc/coremark.sh" && chmod 755 "etc/coremark.sh"
if [ -x usr/bin/perl ];then
[ -f $CPUSTAT_SCRIPT ] && cp $CPUSTAT_SCRIPT usr/bin/cpustat && chmod 755 usr/bin/cpustat
[ -f $GETCPU_SCRIPT ] && cp $GETCPU_SCRIPT bin/
else
[ -f $CPUSTAT_SCRIPT_PY ] && cp $CPUSTAT_SCRIPT_PY usr/bin/cpustat && chmod 755 usr/bin/cpustat
fi
#[ -f $TTYD ] && cp $TTYD etc/init.d/
[ -f $FLIPPY ] && cp $FLIPPY usr/sbin/
if [ -f $BANNER ];then
cp -f $BANNER etc/banner
echo " Base on OpenWrt ${OPENWRT_VER} by lean & lienol" >> etc/banner
echo " Kernel ${KERNEL_VERSION}" >> etc/banner
TODAY=$(date +%Y-%m-%d)
echo " Packaged by ${WHOAMI} on ${TODAY}" >> etc/banner
echo " SOC: ${SOC} BOARD: ${BOARD}" >> etc/banner
echo >> etc/banner
fi
if [ -f $BAL_ETH_IRQ ];then
cp -v $BAL_ETH_IRQ usr/sbin
chmod 755 usr/sbin/balethirq.pl
sed -e "/exit/i\/usr/sbin/balethirq.pl" -i etc/rc.local
[ -f ${BAL_CONFIG} ] && cp -v ${BAL_CONFIG} etc/config/
fi
[ -f $CPUFREQ_INIT ] && cp -v $CPUFREQ_INIT etc/init.d/ && chmod 755 etc/init.d/cpufreq
[ -f $WIRELESS_CONFIG ] && cp -v $WIRELESS_CONFIG etc/config/
if [ -f $FIX_CPU_FREQ ];then
cp -v $FIX_CPU_FREQ usr/sbin
chmod 755 usr/sbin/fixcpufreq.pl
fi
if [ -f etc/config/cpufreq ];then
sed -e "s/ondemand/schedutil/" -i etc/config/cpufreq
fi
if [ -f $SYSFIXTIME_PATCH ];then
patch -p1 < $SYSFIXTIME_PATCH
fi
if [ -f $SSL_CNF_PATCH ];then
patch -p1 < $SSL_CNF_PATCH
fi
if [ -f etc/init.d/dockerd ] && [ -f $DOCKERD_PATCH ];then
patch -p1 < $DOCKERD_PATCH
fi
if [ -f usr/bin/xray-plugin ] && [ -f usr/bin/v2ray-plugin ];then
( cd usr/bin && rm -f v2ray-plugin && ln -s xray-plugin v2ray-plugin )
fi
[ -d ${FMW_HOME} ] && cp -a ${FMW_HOME}/* lib/firmware/
[ -f ${SYSCTL_CUSTOM_CONF} ] && cp ${SYSCTL_CUSTOM_CONF} etc/sysctl.d/
[ -f ${GET_RANDOM_MAC} ] && cp ${GET_RANDOM_MAC} usr/bin/
[ -d boot ] || mkdir -p boot
[ -d overlay ] || mkdir -p overlay
[ -d rom ] || mkdir -p rom
[ -d sys ] || mkdir -p sys
[ -d proc ] || mkdir -p proc
[ -d run ] || mkdir -p run
sed -e 's/ttyAMA0/ttyAML0/' -i ./etc/inittab
sed -e 's/ttyS0/tty0/' -i ./etc/inittab
sed -e 's/\/opt/\/etc/' -i ./etc/config/qbittorrent
sed -e "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/" -i ./etc/ssh/sshd_config 2>/dev/null
sss=$(date +%s)
ddd=$((sss/86400))
[ -x ./bin/bash ] && [ -f "${SYSINFO_SCRIPT}" ] && cp -v "${SYSINFO_SCRIPT}" ./etc/profile.d/ && sed -e "s/\/bin\/ash/\/bin\/bash/" -i ./etc/passwd && \
sed -e "s/\/bin\/ash/\/bin\/bash/" -i ./usr/libexec/login.sh
sed -e "s/:0:0:99999:7:::/:${ddd}:0:99999:7:::/" -i ./etc/shadow
sed -e 's/root::/root:$1$NA6OM0Li$99nh752vw4oe7A.gkm2xk1:/' -i ./etc/shadow
# for collectd
#[ -f ./etc/ppp/options-opkg ] && mv ./etc/ppp/options-opkg ./etc/ppp/options
# for cifsd
[ -f ./etc/init.d/cifsd ] && rm -f ./etc/rc.d/S98samba4
# for smbd
[ -f ./etc/init.d/smbd ] && rm -f ./etc/rc.d/S98samba4
# for ksmbd
[ -f ./etc/init.d/ksmbd ] && rm -f ./etc/rc.d/S98samba4 && sed -e 's/modprobe ksmbd/sleep 1 \&\& modprobe ksmbd/' -i ./etc/init.d/ksmbd
# for samba4 enable smbv1 protocol
[ -f ./etc/config/samba4 ] && \
sed -e 's/services/nas/g' -i ./usr/lib/lua/luci/controller/samba4.lua && \
[ -f ${SMB4_PATCH} ] && \
patch -p1 < ${SMB4_PATCH}
# for nfs server
if [ -f ./etc/init.d/nfsd ];then
cat > ./etc/exports <<EOF
# /etc/exports: the access control list for filesystems which may be exported
# to NFS clients. See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)
#
/mnt *(ro,fsid=0,sync,nohide,no_subtree_check,insecure,no_root_squash)
/mnt/mmcblk2p4 *(rw,fsid=1,sync,no_subtree_check,no_root_squash)
EOF
cat > ./etc/config/nfs <<EOF
config share
option clients '*'
option enabled '1'
option path '/mnt'
option options 'ro,fsid=0,sync,nohide,no_subtree_check,insecure,no_root_squash'
config share
option enabled '1'
option path '/mnt/mmcblk2p4'
option clients '*'
option options 'rw,fsid=1,sync,no_subtree_check,no_root_squash'
EOF
fi
# for openclash
if [ -d ./etc/openclash/core ];then
(
mkdir -p ./usr/share/openclash/core && \
cd ./etc/openclash && \
mv core ../../usr/share/openclash/ && \
ln -s ../../usr/share/openclash/core .
)
fi
chmod 755 ./etc/init.d/*
sed -e "s/option wan_mode 'false'/option wan_mode 'true'/" -i ./etc/config/dockerman 2>/dev/null
mv -f ./etc/rc.d/S??dockerd ./etc/rc.d/S99dockerd 2>/dev/null
rm -f ./etc/rc.d/S80nginx 2>/dev/null
cat > ./etc/fstab <<EOF
UUID=${ROOTFS_UUID} / btrfs compress=zstd 0 1
LABEL=BOOT /boot vfat defaults 0 2
#tmpfs /tmp tmpfs defaults,nosuid 0 0
EOF
echo "/etc/fstab --->"
cat ./etc/fstab
cat > ./etc/config/fstab <<EOF
config global
option anon_swap '0'
option auto_swap '0'
option anon_mount '1'
option auto_mount '1'
option delay_root '5'
option check_fs '0'
config mount
option target '/overlay'
option uuid '${ROOTFS_UUID}'
option enabled '1'
option enabled_fsck '1'
option options 'compress=zstd'
option fstype 'btrfs'
config mount
option target '/boot'
option label 'BOOT'
option enabled '1'
option enabled_fsck '1'
option fstype 'vfat'
EOF
echo "/etc/config/fstab --->"
cat ./etc/config/fstab
[ -f ./etc/docker-init ] && rm -f ./etc/docker-init
[ -f ./sbin/firstboot ] && rm -f ./sbin/firstboot
[ -f ./sbin/jffs2reset ] && rm -f ./sbin/jffs2reset ./sbin/jffs2mark
[ -f ./www/DockerReadme.pdf ] && [ -f ${DOCKER_README} ] && cp -fv ${DOCKER_README} ./www/DockerReadme.pdf
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
sed -e "s/option sw_flow '1'/option sw_flow '${SW_FLOWOFFLOAD}'/" -i ./etc/config/turboacc
sed -e "s/option hw_flow '1'/option hw_flow '${HW_FLOWOFFLOAD}'/" -i ./etc/config/turboacc
echo pwm_meson > ./etc/modules.d/pwm_meson
echo panfrost > ./etc/modules.d/panfrost
echo meson_gxbb_wdt > ./etc/modules.d/watchdog
mkdir ./etc/modules.d.remove
mod_blacklist=$(cat ${KMOD_BLACKLIST})
for mod in $mod_blacklist ;do
mv -f ./etc/modules.d/${mod} ./etc/modules.d.remove/ 2>/dev/null
done
if [ $K510 -eq 1 ];then
# 高版本内核下,如果ENABLE_WIFI_K510 = 0 则禁用wifi
if [ $ENABLE_WIFI_K510 -eq 0 ];then
mv -f ./etc/modules.d/brcm* ./etc/modules.d.remove/ 2>/dev/null
fi
else
# 低版本内核下,如果ENABLE_WIFI_K504 = 0 则禁用wifi
if [ $ENABLE_WIFI_K504 -eq 0 ];then
mv -f ./etc/modules.d/brcm* ./etc/modules.d.remove/ 2>/dev/null
fi
fi
# 默认禁用sfe
[ -f ./etc/config/sfe ] && sed -e 's/option enabled '1'/option enabled '0'/' -i ./etc/config/sfe
[ -f ./etc/modules.d/usb-net-asix-ax88179 ] || echo "ax88179_178a" > ./etc/modules.d/usb-net-asix-ax88179
# +版内核,优先启用v2驱动, +o内核则启用v1驱动
if echo $KERNEL_VERSION | grep -E '*\+$' ;then
echo "r8152" > ./etc/modules.d/usb-net-rtl8152
else
echo "r8152" > ./etc/modules.d/usb-net-rtl8152
fi
[ -f ./etc/config/shairport-sync ] && [ -f ${SND_MOD} ] && cp ${SND_MOD} ./etc/modules.d/
echo "r8188eu" > ./etc/modules.d/rtl8188eu
rm -f ./etc/rc.d/S*dockerd
# 写入版本信息
cat > ./etc/flippy-openwrt-release <<EOF
SOC=${SOC}
BOARD=${BOARD}
KERNEL_VERSION=${KERNEL_VERSION}
K510=${K510}
SFE_FLAG=${SFE_FLAG}
FLOWOFFLOAD_FLAG=${FLOWOFFLOAD_FLAG}
EOF
if [ $K510 -eq 1 ];then
cat >> ./etc/flippy-openwrt-release <<EOF
UBOOT_OVERLOAD=${UBOOT_WITHOUT_FIP}
EOF
fi
cd $TGT_ROOT/lib/modules/${KERNEL_VERSION}/
rm -f build source
find . -name '*.ko' -exec ln -sf {} . \;
rm -f ntfs.ko
cd $TGT_ROOT/sbin
if [ ! -x kmod ];then
cp $KMOD .
fi
ln -sf kmod depmod
ln -sf kmod insmod
ln -sf kmod lsmod
ln -sf kmod modinfo
ln -sf kmod modprobe
ln -sf kmod rmmod
if [ -f mount.ntfs3 ];then
ln -sf mount.ntfs3 mount.ntfs
elif [ -f ../usr/bin/ntfs-3g ];then
ln -sf /usr/bin/ntfs-3g mount.ntfs
fi
cd $TGT_ROOT/lib/firmware
mv *.hcd brcm/ 2>/dev/null
if [ -f "$REGULATORY_DB" ];then
tar xzf "$REGULATORY_DB"
fi
cd brcm
source ${GET_RANDOM_MAC}
# gtking/gtking pro 采用 bcm4356 wifi/bluetooth 模块
get_random_mac
# wifi5 module AP6356S
sed -e "s/macaddr=00:90:4c:1a:10:01/macaddr=${MACADDR}/" "brcmfmac4356-sdio.txt" > "brcmfmac4356-sdio.azw,gtking.txt"
get_random_mac
# wifi6 module AP6275S
sed -e "s/macaddr=00:90:4c:12:d0:01/macaddr=${MACADDR}/" "brcmfmac4375-sdio.txt" > "brcmfmac4375-sdio.azw,gtking.txt"
# Phicomm N1 采用 bcm43455 wifi/bluetooth 模块
get_random_mac
sed -e "s/macaddr=b8:27:eb:74:f2:6c/macaddr=${MACADDR}/" "brcmfmac43455-sdio.txt" > "brcmfmac43455-sdio.phicomm,n1.txt"
# HK1 Box 和 H96 Max X3 采用 bcm54339 wifi/bluetooth 模块
get_random_mac
sed -e "s/macaddr=00:90:4c:c5:12:38/macaddr=${MACADDR}/" "brcmfmac4339-sdio.ZP.txt" > "brcmfmac4339-sdio.amlogic,sm1.txt"
rm -f ${TGT_ROOT}/etc/bench.log
cat >> ${TGT_ROOT}/etc/crontabs/root << EOF
37 5 * * * /etc/coremark.sh
EOF
[ -f $CPUSTAT_PATCH ] && cd $TGT_ROOT && patch -p1 < ${CPUSTAT_PATCH}
[ -x "${TGT_ROOT}/usr/bin/perl" ] && [ -f "${CPUSTAT_PATCH_02}" ] && cd ${TGT_ROOT} && patch -p1 < ${CPUSTAT_PATCH_02}
# 创建 /etc 初始快照
echo "创建初始快照: /etc -> /.snapshots/etc-000"
cd $TGT_ROOT && \
mkdir -p .snapshots && \
btrfs subvolume snapshot -r etc .snapshots/etc-000
# 2021.04.01添加
# 强制锁定fstab,防止用户擅自修改挂载点
# 开启了快照功能之后,不再需要锁定fstab
#chattr +ia ./etc/config/fstab
# clean temp_dir
cd $TEMP_DIR
umount -f $TGT_BOOT $TGT_ROOT
if [ -f ${UBOOT_WITH_FIP} ];then
dd if=${UBOOT_WITH_FIP} of=${TGT_DEV} conv=fsync,notrunc bs=512 skip=1 seek=1
dd if=${UBOOT_WITH_FIP} of=${TGT_DEV} conv=fsync,notrunc bs=1 count=444
fi
( losetup -D && cd $WORK_DIR && rm -rf $TEMP_DIR && losetup -D)
sync
echo
echo "镜像打包已完成,再见!"
echo "========================== end $0 ================================"
echo