blob: 967901dfcf14683a23c4927d963d1ebdc047f0f8 (
plain) (
blame)
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
|
#!/bin/bash
usage ()
{
echo "Usage: sudo fastboot.sh <options>";
echo "options:";
echo " --help Show this message and exit"
echo " --revg Flashes the dtb required for Rev-G J6 EVm which has 10inch panel";
exit 1;
}
#no args case
if [ "$1" = "--help" ] ; then
usage
fi
# Pre-packaged DB
export FASTBOOT=${FASTBOOT-"./fastboot"}
export PRODUCT_OUT=${PRODUCT_OUT-"./"}
echo "Fastboot: $FASTBOOT"
echo "Image location: $PRODUCT_OUT"
# =============================================================================
# pre-run
# =============================================================================
# Verify fastboot program is available
# Verify user permission to run fastboot
# Verify fastboot detects a device, otherwise exit
if [ -f ${FASTBOOT} ]; then
fastboot_status=`${FASTBOOT} devices 2>&1`
if [ `echo $fastboot_status | grep -wc "no permissions"` -gt 0 ]; then
cat <<-EOF >&2
-------------------------------------------
Fastboot requires administrator permissions
Please run the script as root or create a
fastboot udev rule, e.g:
% cat /etc/udev/rules.d/99_android.rules
SUBSYSTEM=="usb",
SYSFS{idVendor}=="0451"
OWNER="<username>"
GROUP="adm"
-------------------------------------------
EOF
exit 1
elif [ "X$fastboot_status" = "X" ]; then
echo "No device detected. Please ensure that" \
"fastboot is running on the target device"
exit -1;
else
device=`echo $fastboot_status | awk '{print$1}'`
echo -e "\nFastboot - device detected: $device\n"
fi
else
echo "Error: fastboot is not available at ${FASTBOOT}"
exit -1;
fi
## poll the board to find out its configuration
#product=`${FASTBOOT} getvar product 2>&1 | grep product | awk '{print$2}'`
cpu=`${FASTBOOT} getvar cpu 2>&1 | grep cpu | awk '{print$2}'`
cputype=`${FASTBOOT} getvar secure 2>&1 | grep secure | awk '{print$2}'`
# Make EMU = HS
if [ ${cputype} = "EMU" ] || [ ${cputype} = "HS" ]; then
cputype="HS"
xloader="${PRODUCT_OUT}${cputype}_QSPI_MLO"
fi
# If fastboot does not support getvar default to GP
if [ ${cputype} = "" ] || [ ${cputype} = "GP" ]; then
cputype="GP"
xloader="${PRODUCT_OUT}${cputype}_MLO"
fi
# Based on cpu, decide the dtb to flash, default fall back to J6
if [ ${cpu} = "J6ECO" ]; then
environment="${PRODUCT_OUT}dra72-evm-lcd10.dtb"
else
environment="${PRODUCT_OUT}dra7-evm-lcd10.dtb"
fi
# Create the filename
bootimg="${PRODUCT_OUT}boot.img"
uboot="${PRODUCT_OUT}u-boot.img"
systemimg="${PRODUCT_OUT}system.img"
userdataimg="${PRODUCT_OUT}userdata.img"
cacheimg="${PRODUCT_OUT}cache.img"
efsimg="${PRODUCT_OUT}efs.img"
recoveryimg="${PRODUCT_OUT}recovery.img"
# Verify that all the files required for the fastboot flash
# process are available
if [ ! -e "${bootimg}" ] ; then
echo "Missing ${bootimg}"
exit -1;
fi
if [ ! -e "$xloader" ] ; then
echo "Missing ${xloader}"
exit -1;
fi
if [ ! -e "${uboot}" ] ; then
echo "Missing ${uboot}"
exit -1;
fi
if [ ! -e "${environment}" ] ; then
echo "Missing ${environment}"
exit -1;
fi
if [ ! -e "${systemimg}" ] ; then
echo "Missing ${systemimg}"
exit -1;
fi
if [ ! -e "${userdataimg}" ] ; then
echo "Missing ${userdataimg}"
exit -1;
fi
if [ ! -e "${cacheimg}" ] ; then
echo "Missing ${cacheimg}"
# exit -1;
fi
if [ ! -e "${recoveryimg}" ] ; then
echo "Missing ${recoveryimg}"
exit -1;
fi
echo "Create GPT partition table"
${FASTBOOT} oem format
echo "Setting target for bootloader to SPI"
${FASTBOOT} oem spi
sleep 3
echo "Flashing bootloader....."
echo " xloader: ${xloader}"
${FASTBOOT} flash xloader ${xloader}
sleep 3
${FASTBOOT} flash bootloader ${uboot}
#echo "Reboot: make sure new bootloader runs..."
${FASTBOOT} reboot-bootloader
sleep 5
echo "Re-creating GPT partition table with new bootloader"
${FASTBOOT} oem format
echo "Flash android partitions"
${FASTBOOT} flash boot ${bootimg}
echo "Flashing device tree ${environment}"
${FASTBOOT} flash environment ${environment}
${FASTBOOT} flash recovery ${recoveryimg}
${FASTBOOT} flash system ${systemimg}
userdataimg_orig="${userdataimg}.orig"
if [ ! -f $userdataimg_orig ]; then
cp $userdataimg $userdataimg_orig
else
cp $userdataimg_orig $userdataimg
fi
echo "Resizing userdata.img"
resizefail=0
userdatasize=`./fastboot getvar userdata_size 2>&1 | grep "userdata_size" | awk '{print$2}'`
if [ -n "$userdatasize" ]; then
while [ 1 ];do
echo Current userdata partition size=${userdatasize} KB
if [ -d "./data" ]; then
echo "Removing data"
rm -rf ./data || resizefail=1
if [ $resizefail -eq 1 ]; then
echo "unable to remove data folder" && break
fi
fi
mkdir ./data
./simg2img userdata.img userdata.img.raw
mount -o loop -o grpid -t ext4 ./userdata.img.raw ./data || resizefail=1
if [ $resizefail -eq 1 ]; then
echo "Mount failed" && break
fi
./make_ext4fs -s -l ${userdatasize}K -a data userdata.img data/
sync
umount data
sync
rm -rf ./data
rm userdata.img.raw
break
done
else
resizefail=1
fi
if [ $resizefail -eq 1 ]; then
echo "userdata resize failed."
echo "Eg: sudo ./fastboot.sh"
echo "For now, we are defaulting to original userdata.img"
cp $userdataimg_orig $userdataimg
fi
${FASTBOOT} flash userdata ${userdataimg}
if [ "$1" != "--noefs" ] ; then
if [ ! -f ${efsimg} ] ; then
echo "Creating efs.img as 16M ext4 img..."
test -d ./efs/ || mkdir efs
./make_ext4fs -s -l 16M -a efs efs.img efs/
else
echo "Using previously created efs.img..."
fi
${FASTBOOT} flash efs ${efsimg}
else
echo "efs partition is untouched"
fi
#Create cache.img
if [ ! -f ${cacheimg} ]
then
echo "Creating cache.img as empty ext4 img...."
rm -rf /tmp/fastboot-cache
mkdir /tmp/fastboot-cache
./make_ext4fs -s -l 256M -a cache ${cacheimg} /tmp/fastboot-cache/
rm -rf /tmp/fastboot-cache
fi
#flash cache.img
${FASTBOOT} flash cache ${cacheimg}
#reboot now
#${FASTBOOT} reboot
#if [ $resizefail -eq 1 ]; then
# echo "--------------------------------------------------"
# echo "Attempt was made to resize the userdata partition image"
# echo "to the size available on your SOM. But it failed either"
# echo "because it failed to remove existing ./data folder or because"
# echo "you are not running this script with superuser privileges"
# echo "Don't panic! The script just loaded the original userdata.img"
# echo "so, things should just work as expected. Just that the size"
# echo "of /data will be smaller on target."
# echo ""
# echo "If you really want to resize userdata.img, remove any existing"
# echo "./data folder and run \"sudo ./fastboot.sh\""
# echo "For now, we are defaulting to original userdata.img"
# echo "--------------------------------------------------"
#fi
|