-
Notifications
You must be signed in to change notification settings - Fork 0
/
phy-fix.sh
executable file
·103 lines (84 loc) · 1.87 KB
/
phy-fix.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
#!/bin/bash
# tary, 2018-05-23
# set -x
BASE_URL=https://github.com/turmary/bbg-phy-fix/raw/master
MLO_BK=/opt/backup/uboot/MLO
SOC=/boot/SOC.sh
VERSION=
FILES="MLO u-boot.img"
TMP=/tmp
uboot_ver_get() {
local ver uboot_ver YEAR
ver=201603
if [ ! -f $MLO_BK ]; then
echo $ver
return 0
fi
uboot_ver=$(strings $MLO_BK | egrep "U-Boot SPL")
YEAR=( $( echo $uboot_ver | sed -re 's/U-Boot SPL ([0-9]+)\.([0-9]+).*/\1 \2/g') )
if [ "${YEAR[0]}" -ge "2017" ]; then
ver=201803
fi
echo $ver
return 0
}
boot_device_get() {
local fields line
while read line; do
fields=( $line )
if [ "${fields[2]}" == "/" ]; then
break
fi
done < <(mount)
echo ${fields[0]} | sed -re 's/p[0-9]+$//g'
return 0;
}
file_download() {
local url
url=$BASE_URL/$VERSION/$1
wget -O $TMP/$1 $url
if [ "$?" -ne 0 ]; then
echo Download file $url error >&2
return 1
fi
return 0;
}
burn_MLO() {
dd if=$TMP/MLO of=$BOOT_DEV bs=$dd_spl_uboot_bs seek=$dd_spl_uboot_seek count=$dd_spl_uboot_count conv=$dd_spl_uboot_conf
}
burn_UBOOT() {
dd if=$TMP/u-boot.img of=$BOOT_DEV bs=$dd_uboot_bs seek=$dd_uboot_seek count=$dd_uboot_count conv=$dd_uboot_conf
}
VERSION=$(uboot_ver_get)
BOOT_DEV=$(boot_device_get)
echo U-BOOT Version $VERSION
echo BOOT Device $BOOT_DEV
if ! source $SOC; then
dd_spl_uboot_count=1
dd_spl_uboot_seek=1
dd_spl_uboot_conf=notrunc
dd_spl_uboot_bs=128k
dd_uboot_count=2
dd_uboot_seek=1
dd_uboot_conf=notrunc
dd_uboot_bs=384k
fi
for f in $FILES; do
if ! file_download $f; then
exit 1
fi
if [ "$f" == "MLO" ]; then
burn_MLO
elif [ "$f" == "u-boot.img" ]; then
burn_UBOOT
fi
done
sync
sleep 1
sync
cat <<-EOF
================================================================================
Update U-boot with $VERSION phy fixed successful"
Please reboot your device!"
================================================================================
EOF