-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy patharmbian-install
executable file
·416 lines (367 loc) · 19 KB
/
armbian-install
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
#!/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 Armbian Rebuild and kernel Recompile script
# https://github.com/ophub/amlogic-s9xxx-armbian
#
# Function: Install armbian to EMMC
# Copyright (C) 2021 https://github.com/unifreq/openwrt_packit
# Copyright (C) 2021 https://github.com/ophub/amlogic-s9xxx-armbian
#
# Command: armbian-install
# Command optional parameters: armbian-install <mainline_u-boot>
# The mainline u-boot is installed by default: armbian-install
# Don't write mainline u-boot command: armbian-install no
#==========================================================================
# Receive one-key command related parameters
if [[ "${1}" == "no" ]]; then
auto_mainline_uboot="no"
else
auto_mainline_uboot="yes"
fi
error_msg() {
echo -e " [\033[1;91m Error \033[0m] ${1}"
exit 1
}
echo "Start install armbian to emmc..."
root_devname=$(df / | tail -n1 | awk '{print $1}' | awk -F '/' '{print substr($3, 1, length($3)-2)}')
if lsblk -l | grep -E "^${root_devname}boot0" >/dev/null; then
error_msg "you are running in emmc mode, please boot system with usb or tf card!"
fi
install_emmc="$(lsblk -l -o NAME | grep -oE '(mmcblk[0-9]?boot0)' | sed "s/boot0//g")"
if [[ "${install_emmc}" == "" ]]; then
error_msg "No emmc can be found to install the armbian system!"
fi
DEV_EMMC="/dev/${install_emmc}"
echo "DEV_EMMC: ${DEV_EMMC}"
# Get kernel TEXT_OFFSET, For u-boot.ext and u-boot.emmc
# With TEXT_OFFSET patch is [ 0108 ], without TEXT_OFFSET patch is [ 0000 ]
K510="1"
[[ "$(hexdump -n 15 -x "/boot/zImage" 2>/dev/null | head -n 1 | awk '{print $7}')" == "0108" ]] && K510="0"
# Generate New ROOTFS UUID
ROOTFS_UUID="$(cat /proc/sys/kernel/random/uuid)"
[ -z "${ROOTFS_UUID}" ] && ROOTFS_UUID="$(uuidgen)"
[ -z "${ROOTFS_UUID}" ] && error_msg "The new UUID is invalid, cannot continue."
# Set model list, begin ------------
AMLOGIC_MODEL_LIST="
# 1.ID 2.MODEL 3.SOC 4.FDTFILE 5.UBOOT_OVERLOAD 6.MAINLINE_UBOOT 7.ANDROID_UBOOT 8.DESCRIPTION
# Amlogic GXL Family
101:Phicomm N1:s905d:meson-gxl-s905d-phicomm-n1.dtb:u-boot-n1.bin:NA:/usr/lib/u-boot/u-boot-2015-phicomm-n1.bin:4C@1512Mhz,2GB Mem,1Gb Nic,brcm43455 wifi
102:Phicomm N1 (DMA thresh):s905d:meson-gxl-s905d-phicomm-n1-thresh.dtb:u-boot-n1.bin:NA:/usr/lib/u-boot/u-boot-2015-phicomm-n1.bin:Same as above, when ethmac flow control is off
103:hg680p & b860h:s905x:meson-gxl-s905x-p212.dtb:u-boot-p212.bin:NA:NA:4C@1512Mhz,100Mb Nic
104:X96-Mini & TX3-Mini:s905w:meson-gxl-s905w-tx3-mini.dtb:u-boot-s905x-s912.bin:NA:NA:4C@1512Mhz,100Mb Nic
105:MECOOL KI Pro:s905d:meson-gxl-s905d-mecool-ki-pro.dtb:u-boot-p201.bin:NA:NA:2G/16G,1Gb Nic
106:T95:s905x:meson-gxl-s905x-p212.dtb:u-boot-s905x-s912.bin:NA:NA:2G/16G,1Gb Nic
# Amlogic GXM Family
201:Octopus Planet:s912:meson-gxm-octopus-planet.dtb:u-boot-zyxq.bin:NA:NA:4C@1512Mhz+4C@1000Mhz,2GB Mem,1Gb Nic
202:Octopus Planet (FAKE):s912:meson-gxm-octopus-planet.dtb:u-boot-zyxq.bin:NA:/usr/lib/u-boot/bl-fake-octopus-planet.bin:4C@1512Mhz+4C@1000Mhz,2GB Mem,1Gb Nic
203:H96 Pro Plus:s912:meson-gxm-octopus-planet.dtb:u-boot-zyxq.bin:NA:NA:2G/32G,1Gb Nic
204:Tanix-TX92:s912:meson-gxm-octopus-planet.dtb:u-boot-zyxq.bin:NA:NA:3GB DDR4 32GB eMMC,1.5GHz,5G WIFI,1Gb Nic
205:VORKE-Z6-Plus:s912:meson-gxm-octopus-planet.dtb:u-boot-zyxq.bin:NA:NA:3GB DDR3 32GB eMMC5.0,1.5Ghz,TF CARD Support 1~32GB,1Gb Nic
206:MECOOL M8S Pro L:s912:meson-gxm-q201.dtb:u-boot-s905x-s912.bin:NA:NA:2G RAM,3G RAM,16G ROM,32G ROM,100Mb Nic
207:T95Z Plus:s912:meson-gxm-t95z-plus.dtb:u-boot-s905x-s912.bin:NA:NA:3G+32G,Octa-Core,2.4/5.8G Dual-Band WiFi,1Gb Nic
# Amlogic G12A Family
301:X96 Max 4GB:s905x2:meson-g12a-x96-max.dtb:u-boot-x96max.bin:/usr/lib/u-boot/x96max-u-boot.bin.sd.bin:NA:4C@1908Mhz,4GB Mem,1Gb Nic
302:X96 Max 2GB:s905x2:meson-g12a-x96-max-rmii.dtb:u-boot-x96max.bin:/usr/lib/u-boot/x96max-u-boot.bin.sd.bin:NA:4C@1908Mhz,2GB Mem,100Mb Nic
303:MECOOL KM3 4G:s905x2:meson-g12a-sei510.dtb:u-boot-x96max.bin:/usr/lib/u-boot/x96max-u-boot.bin.sd.bin:NA:4C@1908Mhz,4+64G/128G,2.4G/5G WiFi,Bluetooth 4.1,100Mb Nic
304:E900V22C-D:s905l3a:meson-g12a-s905l3a-e900v22c.dtb:u-boot-e900v22c.bin:/usr/lib/u-boot/e900v22c-u-boot.bin.sd.bin:NA:4C@1908Mhz,4+64G/128G,2.4G/5G WiFi,Bluetooth 4.1,100Mb Nic
# Amlogic G12B Family
401:Beelink GT-King:s922x:meson-g12b-gtking.dtb:u-boot-gtking.bin:/usr/lib/u-boot/gtking-u-boot.bin.sd.bin:NA:2C@1800Mhz(A53)+4C@1908Mhz(A73),4GB Mem,1Gb Nic,brcm4356 wifi
402:Beelink GT-King Pro:s922x:meson-g12b-gtking-pro.dtb:u-boot-gtkingpro.bin:/usr/lib/u-boot/gtkingpro-u-boot.bin.sd.bin:NA:2C@1800Mhz(A53)+4C@1908Mhz(A73),4GB Mem,1Gb Nic,brcm4356 wifi
403:Beelink GT-King Pro H:s922x:meson-g12b-gtking-pro-h.dtb:u-boot-gtkingpro.bin:/usr/lib/u-boot/gtkingpro-u-boot.bin.sd.bin:NA:S922X-H,2C@1800Mhz(A53)+4C@2208Mhz(A73),4GB Mem,1Gb Nic,brcm4356 wifi
404:Beelink GT-King Pro Rev_A:s922x:meson-g12b-gtking-pro.dtb:u-boot-gtkingpro-rev-a.bin:NA:NA:2C@1800Mhz(A53)+4C@1908Mhz(A73),4GB Mem,1Gb Nic,brcm4356 wifi
405:Hardkernel ODroid N2:s922x:meson-g12b-odroid-n2.dtb:u-boot-gtkingpro.bin:/usr/lib/u-boot/odroid-n2-u-boot.bin.sd.bin:NA:2C@1800Mhz(A53)+4C@1908Mhz(A73),4GB Mem,1Gb Nic
406:UGOOS AM6 Plus:s922x:meson-g12b-ugoos-am6.dtb:u-boot-gtkingpro.bin:/usr/lib/u-boot/gtkingpro-u-boot.bin.sd.bin:NA:2C@1800Mhz(A53)+4C@1908Mhz(A73),4GB Mem,1Gb Nic,brcm4398 wifi
407:Khadas VIM3:a311d:meson-g12b-a311d-khadas-vim3.dtb:u-boot-gtkingpro.bin:/usr/lib/u-boot/khadas-vim3-u-boot.sd.bin:NA:[email protected][email protected],PCIe+USB 3.0,1Gb Nic,brcm4398 wifi
# Amlogic SM1 Family
501:X96 Max+:s905x3:meson-sm1-x96-max-plus.dtb:u-boot-x96maxplus.bin:/usr/lib/u-boot/x96maxplus-u-boot.bin.sd.bin:/usr/lib/u-boot/hk1box-bootloader.img:4C@2100Mhz,4GB Mem,1Gb Nic,rtl8822cs wifi
502:X96 Max+ (OverClock):s905x3:meson-sm1-x96-max-plus-oc.dtb:u-boot-x96maxplus.bin:/usr/lib/u-boot/x96maxplus-u-boot.bin.sd.bin:/usr/lib/u-boot/hk1box-bootloader.img:4C@2208Mhz,4GB Mem,1Gb Nic,rtl8822cs wifi
503:X96 Max+ (IP1001M phy):s905x3:meson-sm1-x96-max-plus-ip1001m.dtb:u-boot-x96maxplus.bin:/usr/lib/u-boot/x96maxplus-u-boot.bin.sd.bin:/usr/lib/u-boot/hk1box-bootloader.img:4C@2208Mhz,4GB Mem,1Gb Nic (IP1001M phy),brcm4354 wifi
504:HK1 Box:s905x3:meson-sm1-hk1box-vontar-x3.dtb:u-boot-x96maxplus.bin:/usr/lib/u-boot/hk1box-u-boot.bin.sd.bin:NA:4C@2100Mhz,4GB Mem,1Gb Nic,brcm4339 wifi
505:HK1 Box (OverClock):s905x3:meson-sm1-hk1box-vontar-x3-oc.dtb:u-boot-x96maxplus.bin:/usr/lib/u-boot/hk1box-u-boot.bin.sd.bin:NA:4C@2208Mhz,4GB Mem,1Gb Nic,brcm4339 wifi
506:H96 Max X3:s905x3:meson-sm1-h96-max-x3.dtb:u-boot-x96maxplus.bin:/usr/lib/u-boot/h96maxx3-u-boot.bin.sd.bin:NA:4C@2100Mhz,4GB Mem,1Gb Nic,brcm4339 wifi
507:H96 Max X3 (OverClock):s905x3:meson-sm1-h96-max-x3-oc.dtb:u-boot-x96maxplus.bin:/usr/lib/u-boot/h96maxx3-u-boot.bin.sd.bin:NA:4C@2208Mhz,4GB Mem,1Gb Nic,brcm4339 wifi
508:Ugoos X3:s905x3:meson-sm1-ugoos-x3.dtb:u-boot-ugoos-x3.bin:NA:NA:4C@2100Mhz,2(Cube)/4(Pro,Plus)GB Mem,1Gb Nic,brcm43455/43456 wifi
509:Ugoos X3 (OverClock):s905x3:meson-sm1-ugoos-x3-oc.dtb:u-boot-ugoos-x3.bin:NA:NA:4C@2208Mhz,2(Cube)/4(Pro,Plus)GB Mem,1Gb Nic,brcm43455/43456 wifi
510:TX3 1Gb:s905x3:meson-sm1-tx3-qz.dtb:u-boot-tx3-qz.bin:/lib/u-boot/x96maxplus-u-boot.bin.sd.bin::4C@2100Mhz,4GB Mem,1Gb Nic,bcm4330 wifi
511:TX3 1Gb (OverClock):s905x3:meson-sm1-tx3-qz-oc.dtb:u-boot-tx3-qz.bin:/lib/u-boot/x96maxplus-u-boot.bin.sd.bin::4C@2100Mhz,4GB Mem,1Gb Nic,bcm4330 wifi
512:TX3 100Mb:s905x3:meson-sm1-tx3-bz.dtb:u-boot-tx3-bz.bin:/lib/u-boot/x96maxplus-u-boot.bin.sd.bin::4C@2100Mhz,4GB Mem,100Mb Nic,bcm4330 wifi
513:TX3 100Mb (OverClock):s905x3:meson-sm1-tx3-bz-oc.dtb:u-boot-tx3-bz.bin:/lib/u-boot/x96maxplus-u-boot.bin.sd.bin::4C@2100Mhz,4GB Mem,100Mb Nic,bcm4330 wifi
514:X96 Air 1Gb:s905x3:meson-sm1-x96-air-gbit.dtb:u-boot-x96maxplus.bin:NA:NA:4C@2100Mhz,2GB Mem,1Gb Nic,Wifi
515:X96 Air 100Mb:s905x3:meson-sm1-x96-air.dtb:u-boot-x96maxplus.bin:NA:NA:4C@2100Mhz,2GB Mem,100Mb Nic,Wifi
516:A95XF3 Air 1Gb:s905x3:meson-sm1-a95xf3-air-gbit.dtb:u-boot-x96maxplus.bin:NA:NA:4C@2100Mhz,2GB Mem,1Gb Nic,Wifi
517:A95XF3 Air 100Mb:s905x3:meson-sm1-a95xf3-air.dtb:u-boot-x96maxplus.bin:NA:NA:4C@2100Mhz,2GB Mem,100Mb Nic,Wifi
# Other
0:Unknown:Other:Import-custom-dtb-file:NA:NA:NA:Enter the dtb file name of your box
"
search_aml_model() {
local search_soc_id="${1}"
local ret_count=$(echo "${AMLOGIC_MODEL_LIST}" | grep -E "^${search_soc_id}:" | wc -l)
if [ "${ret_count}" -eq "1" ]; then
echo "${AMLOGIC_MODEL_LIST}" | grep -E "^${search_soc_id}:" | sed -e 's/NA//g' -e 's/NULL//g' -e 's/[ ][ ]*//g'
fi
}
# Display the model list
printf "%-s\n" "--------------------------------------------------------------------------------------"
printf "%-5s %-10s %-30s %-50s\n" ID SOC MODEL DTB
printf "%-s\n" "--------------------------------------------------------------------------------------"
printf "%-5s %-10s %-30s %-50s\n" $(echo "${AMLOGIC_MODEL_LIST}" | grep -E "^[0-9]{1,9}.*:" | sed -e 's/[ ][ ]*/-/g' | awk -F ':' '{print $1,$3,$2,$4}')
printf "%-s\n" "--------------------------------------------------------------------------------------"
read -p "Please Input ID: " boxtype
if [[ "${boxtype}" -eq "0" ]]; then
read -p "Please Input SoC Name: " AMLOGIC_SOC
AMLOGIC_SOC="${AMLOGIC_SOC}"
#
read -p "Please Input DTB Name: " FDTFILE
FDTFILE="${FDTFILE}"
#
read -p "Please Input UBOOT_OVERLOAD Name: " UBOOT_OVERLOAD
UBOOT_OVERLOAD="${UBOOT_OVERLOAD}"
#
read -p "Please Input MAINLINE_UBOOT Name: " MAINLINE_UBOOT
MAINLINE_UBOOT="${MAINLINE_UBOOT}"
#
read -p "Please Input ANDROID_UBOOT Name: " ANDROID_UBOOT
ANDROID_UBOOT="${ANDROID_UBOOT}"
else
ret=$(search_aml_model "${boxtype}")
if [ "${ret}" == "" ]; then
error_msg "Input error, exit!"
fi
AMLOGIC_SOC="$(echo "${ret}" | awk -F ':' '{print $3}')"
FDTFILE="$(echo "${ret}" | awk -F ':' '{print $4}')"
UBOOT_OVERLOAD="$(echo "${ret}" | awk -F ':' '{print $5}')"
MAINLINE_UBOOT="$(echo "${ret}" | awk -F ':' '{print $6}')"
ANDROID_UBOOT="$(echo "${ret}" | awk -F ':' '{print $7}')"
fi
# Set model list, end ------------
echo "Input Box ID: [ ${boxtype} ]"
echo "FDTFILE: [ ${FDTFILE} ]"
echo "UBOOT_OVERLOAD: [ ${UBOOT_OVERLOAD} ]"
echo "K510: [ ${K510} ]"
[[ -n "${FDTFILE}" && -f "/boot/dtb/amlogic/${FDTFILE}" ]] || error_msg "The DTB is missing, stop the install."
if [[ "${K510}" -eq "1" ]]; then
[[ -n "${UBOOT_OVERLOAD}" && -f "/boot/${UBOOT_OVERLOAD}" ]] || error_msg "The UBOOT_OVERLOAD is missing, stop the install."
fi
# Set the type of file system
cat <<EOF
--------------------------------------------
Please select the type of file system:
1. ext4
2. btrfs
--------------------------------------------
EOF
read -p "Please Input ID: " filetype
if [[ "${filetype}" -eq "2" ]]; then
file_system_type="btrfs"
uenv_mount_string="UUID=${ROOTFS_UUID} rootflags=compress=zstd:6 rootfstype=btrfs"
fstab_mount_string="defaults,noatime,compress=zstd:6"
else
file_system_type="ext4"
uenv_mount_string="UUID=${ROOTFS_UUID} rootflags=data=writeback rw rootfstype=ext4"
fstab_mount_string="defaults,noatime,errors=remount-ro"
fi
echo "Input Type ID: [ ${filetype} ]"
echo "The type of file system: [ ${file_system_type} ]"
# Disable the system's partition adjustment service
systemctl stop armbian-resize-filesystem.service
systemctl disable armbian-resize-filesystem.service
# Backup the bootloader, if necessary for system recovery
[ -d "/usr/lib/u-boot" ] || mkdir -p /usr/lib/u-boot
MYBOX_UBOOT="/usr/lib/u-boot/mybox-bootloader.img"
if [ ! -f "${MYBOX_UBOOT}" ]; then
echo "Start backup default bootloader"
dd if="${DEV_EMMC}" of=${MYBOX_UBOOT} bs=1M count=4 conv=fsync
fi
sync
# Clear emmc disk data
exists_pts=$(parted ${DEV_EMMC} print 2>/dev/null | grep 'primary' | wc -l)
if [ "${exists_pts}" -gt "0" ]; then
i=1
while [ "${i}" -le "${exists_pts}" ]; do
parted -s ${DEV_EMMC} rm ${i} 2>/dev/null
let i++
done
fi
dd if=/dev/zero of=${DEV_EMMC} bs=512 count=1 conv=fsync
sync
# Set partition size(MB)
if [[ "${AMLOGIC_SOC}" == "s912" || "${AMLOGIC_SOC}" == "s905d" ]]; then
BLANK1="68"
BOOT="512"
BLANK2="220"
elif [[ "${AMLOGIC_SOC}" == "s905x" ]]; then
BLANK1="700"
BOOT="160"
BLANK2="0"
elif [[ "${AMLOGIC_SOC}" == "s905l3a" ]]; then
BLANK1="570"
BOOT="256"
BLANK2="0"
else
BLANK1="68"
BOOT="256" # A total of [ 1120MB ] can be used in this block, and the remaining [ 864MB ] can be used.
BLANK2="1026" # Can set the rootfs partition after [ 1350MB ] of the total disk.
fi
# Format emmc disk
echo "Start create MBR and partittion"
parted -s "${DEV_EMMC}" mklabel msdos 2>/dev/null
parted -s "${DEV_EMMC}" mkpart primary fat32 $((BLANK1))MiB $((BLANK1 + BOOT - 1))MiB 2>/dev/null
parted -s "${DEV_EMMC}" mkpart primary ${file_system_type} $((BLANK1 + BOOT + BLANK2))MiB 100% 2>/dev/null
sync
# Write bootloader
if [[ -n "${MAINLINE_UBOOT}" && -f "${MAINLINE_UBOOT}" && "${auto_mainline_uboot}" == "yes" ]]; then
echo "Write Mainline bootloader: [ ${MAINLINE_UBOOT} ]"
dd if="${MAINLINE_UBOOT}" of="${DEV_EMMC}" bs=1 count=444 conv=fsync
dd if="${MAINLINE_UBOOT}" of="${DEV_EMMC}" bs=512 skip=1 seek=1 conv=fsync
elif [[ -n "${ANDROID_UBOOT}" && -f "${ANDROID_UBOOT}" ]]; then
echo "Write Android bootloader: [ ${ANDROID_UBOOT} ]"
dd if="${ANDROID_UBOOT}" of="${DEV_EMMC}" bs=1 count=444 conv=fsync
dd if="${ANDROID_UBOOT}" of="${DEV_EMMC}" bs=512 skip=1 seek=1 conv=fsync
elif [[ -n "${MYBOX_UBOOT}" && -f "${MYBOX_UBOOT}" ]]; then
echo "Restore the mybox u-boot"
dd if=${MYBOX_UBOOT} of="${DEV_EMMC}" conv=fsync bs=1 count=442
dd if=${MYBOX_UBOOT} of="${DEV_EMMC}" conv=fsync bs=512 skip=1 seek=1
fi
echo "Start copy system for eMMC."
mkdir -p /ddbr
chmod 777 /ddbr
PART_BOOT="${DEV_EMMC}p1"
PART_ROOT="${DEV_EMMC}p2"
DIR_INSTALL="/ddbr/install"
if [ -d ${DIR_INSTALL} ]; then
rm -rf ${DIR_INSTALL}
fi
mkdir -p ${DIR_INSTALL}
sync
if grep -q ${PART_BOOT} /proc/mounts; then
echo "Unmounting BOOT partiton."
umount -f ${PART_BOOT}
fi
echo "Formatting BOOTFS partition..."
mkfs.vfat -n "BOOT_EMMC" ${PART_BOOT}
mount -o rw ${PART_BOOT} ${DIR_INSTALL}
[ "$?" -ne "0" ] && error_msg "Failed to mount BOOTFS partition"
echo "Start copy BOOT_EMMC partition data..."
cp -rf /boot/* ${DIR_INSTALL} && sync
rm -rf ${DIR_INSTALL}/'System Volume Information' 2>/dev/null
echo "Generate the new uEnv.txt file."
rm -rf ${DIR_INSTALL}/uEnv.txt ${DIR_INSTALL}/extlinux 2>/dev/null && sync
cat >${DIR_INSTALL}/uEnv.txt <<EOF
LINUX=/zImage
INITRD=/uInitrd
FDT=/dtb/amlogic/${FDTFILE}
APPEND=root=${uenv_mount_string} 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
# Create a new extlinux.conf file (Temporarily tested in 5.10 kernel)
if [[ "${K510}" -eq "1" ]]; then
echo "Generate the new extlinux.conf file."
mkdir -p ${DIR_INSTALL}/extlinux
cat >${DIR_INSTALL}/extlinux/extlinux.conf <<EOF
label Armbian
kernel /zImage
initrd /uInitrd
fdt /dtb/amlogic/${FDTFILE}
append root=${uenv_mount_string} console=ttyAML0,115200n8 console=tty0 no_console_suspend consoleblank=0 fsck.fix=yes fsck.repair=yes net.ifnames=0 loglevel=1 voutmode=hdmi disablehpd=false overscan=100 sdrmode=auto
EOF
fi
rm ${DIR_INSTALL}/s9*
rm ${DIR_INSTALL}/aml*
mv -f ${DIR_INSTALL}/boot-emmc.ini ${DIR_INSTALL}/boot.ini
sed -i "s|u-boot.ext|u-boot.emmc|g" ${DIR_INSTALL}/boot.ini
mv -f ${DIR_INSTALL}/boot-emmc.scr ${DIR_INSTALL}/boot.scr
mv -f ${DIR_INSTALL}/boot-emmc.cmd ${DIR_INSTALL}/boot.cmd
# Copy u-boot.ext and u-boot.emmc
if [[ "${K510}" -eq "1" && -n "${UBOOT_OVERLOAD}" && -f "${DIR_INSTALL}/${UBOOT_OVERLOAD}" ]]; then
echo "Copy [ ${UBOOT_OVERLOAD} ] to u-boot.emmc"
if [ -f "${DIR_INSTALL}/u-boot.ext" ]; then
cp -f ${DIR_INSTALL}/u-boot.ext ${DIR_INSTALL}/u-boot.emmc
else
cp -f ${DIR_INSTALL}/${UBOOT_OVERLOAD} ${DIR_INSTALL}/u-boot.ext
cp -f ${DIR_INSTALL}/${UBOOT_OVERLOAD} ${DIR_INSTALL}/u-boot.emmc
fi
chmod +x ${DIR_INSTALL}/u-boot.ext
chmod +x ${DIR_INSTALL}/u-boot.emmc
fi
sync
sleep 3
umount ${DIR_INSTALL}
if grep -q ${PART_ROOT} /proc/mounts; then
echo "Unmounting ROOT partiton."
umount -f ${PART_ROOT}
fi
echo "Formatting ROOTFS partition..."
if [[ "${file_system_type}" == "btrfs" ]]; then
mkfs.btrfs -f -U ${ROOTFS_UUID} -L "ROOTFS_EMMC" -m single ${PART_ROOT}
sleep 3
mount -t btrfs -o compress=zstd:6 ${PART_ROOT} ${DIR_INSTALL}
else
mkfs.ext4 -F -q -U ${ROOTFS_UUID} -L "ROOTFS_EMMC" ${PART_ROOT}
sleep 3
mount -t ext4 ${PART_ROOT} ${DIR_INSTALL}
fi
[ "$?" -ne "0" ] && error_msg "Failed to mount ROOTFS partition"
echo "Start copy ROOTFS_EMMC partition data..."
cd /
# Create relevant directories
mkdir -p ${DIR_INSTALL}/{boot/,dev/,media/,mnt/,proc/,run/,sys/} && sync
# Copy the relevant directory
COPY_SRC="etc home lib64 opt root selinux srv usr var"
for src in ${COPY_SRC}; do
echo "copy [ ${src} ] ..."
tar -cf - ${src} | (
cd ${DIR_INSTALL}
tar -xf -
)
sync
done
# Create relevant symbolic link
ln -sf /usr/bin ${DIR_INSTALL}/bin
ln -sf /usr/lib ${DIR_INSTALL}/lib
ln -sf /usr/sbin ${DIR_INSTALL}/sbin
ln -sf /var/tmp ${DIR_INSTALL}/tmp
sync
echo "Copy complete."
echo "Generate the new fstab file."
rm -f ${DIR_INSTALL}/etc/fstab 2>/dev/null && sync
cat >${DIR_INSTALL}/etc/fstab <<EOF
UUID=${ROOTFS_UUID} / ${file_system_type} ${fstab_mount_string} 0 1
LABEL=BOOT_EMMC /boot vfat defaults 0 2
tmpfs /tmp tmpfs defaults,nosuid 0 0
EOF
echo "Update the relevant parameters"
ophub_release_file="${DIR_INSTALL}/etc/ophub-release"
#
sed -i '/FDTFILE/d' ${ophub_release_file} 2>/dev/null
echo "FDTFILE='${FDTFILE}'" >>${ophub_release_file} 2>/dev/null
#
sed -i '/UBOOT_OVERLOAD/d' ${ophub_release_file} 2>/dev/null
echo "UBOOT_OVERLOAD='${UBOOT_OVERLOAD}'" >>${ophub_release_file} 2>/dev/null
#
sed -i '/MAINLINE_UBOOT/d' ${ophub_release_file} 2>/dev/null
echo "MAINLINE_UBOOT='${MAINLINE_UBOOT}'" >>${ophub_release_file} 2>/dev/null
#
sed -i '/ANDROID_UBOOT/d' ${ophub_release_file} 2>/dev/null
echo "ANDROID_UBOOT='${ANDROID_UBOOT}'" >>${ophub_release_file} 2>/dev/null
#
sed -i '/MYBOX_UBOOT/d' ${ophub_release_file} 2>/dev/null
echo "MYBOX_UBOOT='${MYBOX_UBOOT}'" >>${ophub_release_file} 2>/dev/null
#
sed -i '/SOC/d' ${ophub_release_file} 2>/dev/null
echo "SOC='${AMLOGIC_SOC}'" >>${ophub_release_file} 2>/dev/null
#
sed -i '/K510/d' ${ophub_release_file} 2>/dev/null
echo "K510='${K510}'" >>${ophub_release_file} 2>/dev/null
sync
rm -f ${DIR_INSTALL}/usr/sbin/armbian-tf 2>/dev/null
sync
cd /
umount ${DIR_INSTALL}
sleep 3
echo "*************************************************************************************************"
echo "Successful installed, please unplug the USB, re-insert the power supply to start the armbian."
echo "*************************************************************************************************"
exit 0