-
Notifications
You must be signed in to change notification settings - Fork 0
/
fast
executable file
·260 lines (225 loc) · 6.72 KB
/
fast
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
#!/usr/bin/env bash
#
# Copyright 2016 Vitalii Dmitriev
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Flashes device with Android images.
set -o nounset
set -o noclobber
readonly PROGNAME=${0##*/}
# Options
readonly SHORTOPTS="h,i:,B:,U,C,S:,R:,r,M"
readonly LONGOPTS="help,images:,boot:,userdata,cache,system:,recovery:,reboot,modem"
readonly ARGS=$(getopt -s bash --options $SHORTOPTS \
--longoptions $LONGOPTS --name $PROGNAME -- "$@")
readonly ANDROID_TOOLS="/Android/Sdk/platform-tools"
readonly FASTBOOT_ANDROID="${HOME}${ANDROID_TOOLS}/fastboot"
readonly FASTBOOT="fastboot"
readonly ADB_ANDROID="${HOME}${ANDROID_TOOLS}/adb"
readonly ADB="adb"
readonly CYAN='\033[0;36m'
readonly BLU='\033[0;34m'
readonly NC='\033[0m'
# Default paths
readonly DEFAULT="IMAGES"
readonly DEFAULT_LOWER="images"
images=null
# flag reboot or not
rbt=0
boot=null
cache=null
system=null
recovery=null
userdata=null
radio=0
###################################################################
# Shows help message
# Globals:
# PROGNAME
###################################################################
usage() {
cat <<EO
Usage:
${PROGNAME} [options] <files|dirs>
Options:
EO
cat <<EO | column -s\& -t
-h, --help & Print this help.
-r, --reboot & Reboot device after flashing.
Better be the first provided parameter.
-S, --system <file.img> & Flash with a custom system image.
-B, --boot & Flash with a boot image.
-U, --userdata & Flash with a userdata image.
-R, --recovery <file.img> & Flash with a custom recovery image.
-C, --cache & Flash with a cache image.
-M, --modem & Flash with radio images.
EO
cat <<EO
Example:
${PROGNAME}
with no arguments writes system, boot,
cache and recovery from default directiry.
${PROGNAME} -rU
will also flash userdata and reboot the device.
Note that the -r parameter better be the first parameter
as if it will be combined with other parameters, which are
could be used either alone or with a file provided, it could
be interpreted as a filename by mistake.
${PROGNAME} -r -R recovery.img -S system.img
Flash all with custom recovery, custom system and reboot.
EO
}
###################################################################
# Flashes needed partition with needed image
# Arguments:
# part - partition to be flashed
# img - image to flash a partition with
# Globals:
# FASTBOOT - path to the fastboot utility
###################################################################
flash() {
part=${1}
img=${2}
echo -e "Write "$CYAN"${part}"$NC" with "$BLU"${img}"$NC"!"
sudo $FASTBOOT flash ${part} ${img}
}
###################################################################
# Checks whether there are default directories or
# not. If not, choose another one. If there are no
# default directories, use root of this script.
# Globals:
# images - variable, containing a path to built images.
# DEFAULT - default IMAGES directory.
# DEFAULT_LOWER - default images directory.
# OUT - android build directory, set by the lunch
# function from an android envsetup script.
###################################################################
check_images() {
if [[ ! -d "${images}" ]]; then
images="."
fi
if [[ -z "${images}" || ! -d "${images}" ]]; then
images="${DEFAULT}"
fi
if [[ ! -d "${images}" ]]; then
images="${DEFAULT_LOWER}"
fi
if [[ ! -d "${images}" ]]; then
images="${OUT}"
fi
}
main() {
eval set -- "$ARGS"
while true; do
case "${1}" in
-h|--help)
usage
exit 0
;;
-i|--images)
images="${2}"
shift
;;
-S|--system)
echo "Flash with custom system!"
system="${2}"
shift
;;
-B|--boot)
echo "Flash with boot image!"
boot="${2}"
shift
;;
-U|--userdata)
echo "Flash with userdata!"
if [ -n "${2}" || -f "${2}" ]; then
userdata="${2}"
else
# default userdata image
userdata=$images/userdata.img
fi
shift
;;
-R|--recovery)
echo "Flash with custom recovery!"
recovery="${2}"
shift
;;
-C|--cache)
echo "Flash with custom cache!"
if [ -n "${2}" || -f "${2}" ]; then
cache="${2}"
else
# default cache image
cache=$images/cache.img
fi
shift
;;
-M|--module)
echo "Flash with radio!"
radio=1
shift
;;
-r|--reboot)
echo "Reboot after fLASHING!"
rbt=1
shift
;;
--)
shift
break
;;
*)
shift
;;
esac
done
$ADB reboot bootloader
check_images
if [ ! -f $recovery ]; then
# default recovery image
recovery=$images/recovery.img
fi
if [ ! -f $system ]; then
system=$images/system.img
fi
if [ ! -f $boot ]; then
boot=$images/boot.img
fi
if [ $radio -eq 1 ]; then
flash modem radio/NON-HLOS.bin
flash sbl1 radio/sbl1.mbn
flash rpm radio/rpm.mbn
flash tz radio/tz.mbn
fi
if [ -f $recovery ]; then
flash recovery $recovery
fi
if [ -f $system ]; then
flash system $system
fi
if [ -f $boot ]; then
flash boot $boot
fi
if [ -f $userdata ]; then
flash userdata $userdata
fi
if [ -f $cache ]; then
flash cache $cache
fi
if [ ${rbt} -eq 1 ]; then
sudo $FASTBOOT reboot
fi
echo -e $BLU"DONE!"$NC
}
main