summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'fastboot.sh')
-rwxr-xr-xfastboot.sh256
1 files changed, 256 insertions, 0 deletions
diff --git a/fastboot.sh b/fastboot.sh
new file mode 100755
index 0000000..77449dd
--- /dev/null
+++ b/fastboot.sh
@@ -0,0 +1,256 @@
1#!/bin/bash
2
3usage ()
4{
5 echo "Usage: sudo fastboot.sh <options>";
6 echo "options:";
7 echo " --help Show this message and exit"
8 exit 1;
9}
10
11#no args case
12if [ "$1" = "--help" ] ; then
13 usage
14fi
15
16# Pre-packaged DB
17export FASTBOOT=${FASTBOOT-"./fastboot"}
18export PRODUCT_OUT=${PRODUCT_OUT-"./"}
19export LD_LIBRARY_PATH=./
20
21echo "Fastboot: $FASTBOOT"
22echo "Image location: $PRODUCT_OUT"
23
24
25# =============================================================================
26# pre-run
27# =============================================================================
28
29# Verify fastboot program is available
30# Verify user permission to run fastboot
31# Verify fastboot detects a device, otherwise exit
32if [ -f ${FASTBOOT} ]; then
33 fastboot_status=`${FASTBOOT} devices 2>&1`
34 if [ `echo $fastboot_status | grep -wc "no permissions"` -gt 0 ]; then
35 cat <<-EOF >&2
36 -------------------------------------------
37 Fastboot requires administrator permissions
38 Please run the script as root or create a
39 fastboot udev rule, e.g:
40
41 % cat /etc/udev/rules.d/99_android.rules
42 SUBSYSTEM=="usb",
43 SYSFS{idVendor}=="0451"
44 OWNER="<username>"
45 GROUP="adm"
46 -------------------------------------------
47 EOF
48 exit 1
49 elif [ "X$fastboot_status" = "X" ]; then
50 echo "No device detected. Please ensure that" \
51 "fastboot is running on the target device"
52 exit -1;
53 else
54 device=`echo $fastboot_status | awk '{print$1}'`
55 echo -e "\nFastboot - device detected: $device\n"
56 fi
57else
58 echo "Error: fastboot is not available at ${FASTBOOT}"
59 exit -1;
60fi
61
62## poll the board to find out its configuration
63#product=`${FASTBOOT} getvar product 2>&1 | grep product | awk '{print$2}'`
64cpu=`${FASTBOOT} getvar cpu 2>&1 | grep cpu | awk '{print$2}'`
65cputype=`${FASTBOOT} getvar secure 2>&1 | grep secure | awk '{print$2}'`
66boardrev=`${FASTBOOT} getvar board_rev 2>&1 | grep board_rev | awk '{print$2}'`
67
68
69# Make EMU = HS
70if [ ${cputype} = "EMU" ] || [ ${cputype} = "HS" ]; then
71 cputype="HS"
72 xloader="${PRODUCT_OUT}${cputype}_QSPI_MLO"
73 uboot="${PRODUCT_OUT}${cputype}_u-boot.img"
74# If fastboot does not support getvar default to GP
75elif [ ${cputype} = "" ] || [ ${cputype} = "GP" ]; then
76 cputype="GP"
77 xloader="${PRODUCT_OUT}${cputype}_MLO"
78 uboot="${PRODUCT_OUT}u-boot.img"
79fi
80
81# Based on cpu, decide the dtb to flash, default fall back to J6 and LCD 10
82if [ ${cpu} = "J6ECO" ]; then
83 if [ ${boardrev} = "C" ]; then
84 environment="${PRODUCT_OUT}dra72-evm-lcd-osd.dtb"
85 else
86 environment="${PRODUCT_OUT}dra72-evm-lcd10.dtb"
87 fi
88else
89 if [ ${boardrev} = "H" ]; then
90 environment="${PRODUCT_OUT}dra7-evm-lcd-osd.dtb"
91 else
92 environment="${PRODUCT_OUT}dra7-evm-lcd10.dtb"
93 fi
94fi
95
96# Create the filename
97bootimg="${PRODUCT_OUT}boot.img"
98systemimg="${PRODUCT_OUT}system.img"
99userdataimg="${PRODUCT_OUT}userdata.img"
100cacheimg="${PRODUCT_OUT}cache.img"
101efsimg="${PRODUCT_OUT}efs.img"
102recoveryimg="${PRODUCT_OUT}recovery.img"
103
104
105# Verify that all the files required for the fastboot flash
106# process are available
107
108if [ ! -e "${bootimg}" ] ; then
109 echo "Missing ${bootimg}"
110 exit -1;
111fi
112if [ ! -e "$xloader" ] ; then
113 echo "Missing ${xloader}"
114 exit -1;
115fi
116if [ ! -e "${uboot}" ] ; then
117 echo "Missing ${uboot}"
118 exit -1;
119fi
120if [ ! -e "${environment}" ] ; then
121 echo "Missing ${environment}"
122 exit -1;
123else
124 echo "DTB = ${environment}"
125fi
126if [ ! -e "${systemimg}" ] ; then
127 echo "Missing ${systemimg}"
128 exit -1;
129fi
130if [ ! -e "${userdataimg}" ] ; then
131 echo "Missing ${userdataimg}"
132 exit -1;
133fi
134if [ ! -e "${cacheimg}" ] ; then
135 echo "Missing ${cacheimg}"
136 exit -1;
137fi
138if [ ! -e "${recoveryimg}" ] ; then
139 echo "Missing ${recoveryimg}"
140 exit -1;
141fi
142
143echo "Create GPT partition table"
144${FASTBOOT} oem format
145
146echo "Setting target for bootloader to SPI"
147${FASTBOOT} oem spi
148
149sleep 3
150
151echo "Flashing bootloader....."
152echo " xloader: ${xloader}"
153${FASTBOOT} flash xloader ${xloader}
154
155sleep 3
156echo " bootloader: ${uboot}"
157${FASTBOOT} flash bootloader ${uboot}
158
159#echo "Reboot: make sure new bootloader runs..."
160${FASTBOOT} reboot-bootloader
161
162sleep 5
163
164echo "Re-creating GPT partition table with new bootloader"
165${FASTBOOT} oem format
166
167echo "Flash android partitions"
168${FASTBOOT} flash boot ${bootimg}
169echo "Flashing environemnt....."
170echo " environment: ${environment}"
171${FASTBOOT} flash environment ${environment}
172${FASTBOOT} flash recovery ${recoveryimg}
173${FASTBOOT} flash system ${systemimg}
174
175userdataimg_orig="${userdataimg}.orig"
176if [ ! -f $userdataimg_orig ]; then
177 cp $userdataimg $userdataimg_orig
178else
179 cp $userdataimg_orig $userdataimg
180fi
181
182echo "Resizing userdata.img"
183resizefail=0
184userdatasize=`./fastboot getvar userdata_size 2>&1 | grep "userdata_size" | awk '{print$2}'`
185if [ -n "$userdatasize" ]; then
186 while [ 1 ];do
187 echo Current userdata partition size=${userdatasize} KB
188 if [ -d "./data" ]; then
189 echo "Removing data"
190 rm -rf ./data || resizefail=1
191 if [ $resizefail -eq 1 ]; then
192 echo "unable to remove data folder" && break
193 fi
194 fi
195 mkdir ./data
196 ./simg2img userdata.img userdata.img.raw
197 mount -o loop -o grpid -t ext4 ./userdata.img.raw ./data || resizefail=1
198 if [ $resizefail -eq 1 ]; then
199 echo "Mount failed" && break
200 fi
201 ./make_ext4fs -s -l ${userdatasize}K -a data userdata.img data/
202 sync
203 umount data
204 sync
205 rm -rf ./data
206 rm userdata.img.raw
207 break
208 done
209else
210 resizefail=1
211fi
212
213if [ $resizefail -eq 1 ]; then
214 echo "userdata resize failed."
215 echo "Eg: sudo ./fastboot.sh"
216 echo "For now, we are defaulting to original userdata.img"
217 cp $userdataimg_orig $userdataimg
218fi
219${FASTBOOT} flash userdata ${userdataimg}
220
221if [ "$1" != "--noefs" ] ; then
222 if [ ! -f ${efsimg} ] ; then
223 echo "Creating efs.img as 16M ext4 img..."
224 test -d ./efs/ || mkdir efs
225 ./make_ext4fs -s -l 16M -a efs efs.img efs/
226 else
227 echo "Using previously created efs.img..."
228 fi
229
230 ${FASTBOOT} flash efs ${efsimg}
231else
232 echo "efs partition is untouched"
233fi
234
235#flash cache.img
236${FASTBOOT} flash cache ${cacheimg}
237
238#reboot now
239#${FASTBOOT} reboot
240
241#if [ $resizefail -eq 1 ]; then
242# echo "--------------------------------------------------"
243# echo "Attempt was made to resize the userdata partition image"
244# echo "to the size available on your SOM. But it failed either"
245# echo "because it failed to remove existing ./data folder or because"
246# echo "you are not running this script with superuser privileges"
247# echo "Don't panic! The script just loaded the original userdata.img"
248# echo "so, things should just work as expected. Just that the size"
249# echo "of /data will be smaller on target."
250# echo ""
251# echo "If you really want to resize userdata.img, remove any existing"
252# echo "./data folder and run \"sudo ./fastboot.sh\""
253# echo "For now, we are defaulting to original userdata.img"
254# echo "--------------------------------------------------"
255#fi
256