forked from rock64-linux/build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flash_tool.sh
executable file
·95 lines (80 loc) · 1.87 KB
/
flash_tool.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
#!/bin/bash -e
LOCALPATH=$(pwd)
OUT=${LOCALPATH}/out
TOOLPATH=${LOCALPATH}/rkbin/tools
EXTLINUXPATH=${LOCALPATH}/build/extlinux
CHIP=""
DEVICE=""
IMAGE=""
DEVICE=""
SEEK=""
PATH=$PATH:$TOOLPATH
source $LOCALPATH/build/partitions.sh
usage() {
echo -e "\nUsage: emmc: build/flash_tool.sh -c rk3288 -p system -i out/system.img \n"
echo -e " sdcard: build/flash_tool.sh -c rk3288 -d /dev/sdb -p system -i out/system.img \n"
}
finish() {
echo -e "\e[31m FLASH IMAGE FAILED.\e[0m"
exit -1
}
trap finish ERR
while getopts "c:t:s:d:p:r:d:i:h" flag; do
case $flag in
c)
CHIP="$OPTARG"
;;
d)
DEVICE="$OPTARG"
;;
i)
IMAGE="$OPTARG"
if [ ! -e ${IMAGE} ]; then
echo -e "\e[31m CAN'T FIND IMAGE \e[0m"
usage
exit
fi
;;
p)
PARTITIONS="$OPTARG"
BPARTITIONS=$(echo $PARTITIONS | tr 'a-z' 'A-Z')
SEEK=${BPARTITIONS}_START
eval SEEK=\$$SEEK
if [ -n "$(echo $SEEK | sed -n "/^[0-9]\+$/p")" ]; then
echo "PARTITIONS OFFSET: $SEEK sectors."
else
echo -e "\e[31m INVAILD PARTITION.\e[0m"
exit
fi
;;
esac
done
if [ ! $IMAGE ]; then
usage
exit
fi
if [ ! -e ${EXTLINUXPATH}/${CHIP}.conf ]; then
CHIP="rk3288"
fi
flash_upgt() {
if [ "${CHIP}" == "rk3288" ]; then
sudo $TOOLPATH/rkdeveloptool db ${LOCALPATH}/rkbin/rk32/rk3288_ubootloader_*.bin
elif [ "${CHIP}" == "rk3036" ]; then
sudo $TOOLPATH/rkdeveloptool db ${LOCALPATH}/rkbin/rk30/rk3036_loader_*.bin
elif [ "${CHIP}" == "rk3399" ]; then
sudo $TOOLPATH/rkdeveloptool db ${LOCALPATH}/rkbin/rk33/rk3399_loader_*.bin
elif [ "${CHIP}" == "rk3228" ]; then
sudo $TOOLPATH/rkdeveloptool db ${LOCALPATH}/rkbin/rk33/rk3328_loader_*.bin
fi
sleep 1
sudo $TOOLPATH/rkdeveloptool wl ${SEEK} ${IMAGE}
sudo $TOOLPATH/rkdeveloptool rd
}
flash_sdcard() {
sudo dd if=${IMAGE} of=${DEVICE} seek=${SEEK} conv=notrunc
}
if [ ! $DEVICE ]; then
flash_upgt
else
flash_sdcard
fi