blob: 4f06e90750b04620573a8f61a74e5f634444bde2 [file] [log] [blame]
Vishal Mahaveer6b7b6202013-07-26 18:24:59 -05001#!/bin/bash
2
3usage ()
4{
Vishal Mahaveer05561662014-08-08 10:37:38 -05005 echo "Usage: sudo fastboot.sh <options>";
Vishal Mahaveer6b7b6202013-07-26 18:24:59 -05006 echo "options:";
Vishal Mahaveer05561662014-08-08 10:37:38 -05007 echo " --help Show this message and exit"
8 echo " --revg Flashes the dtb required for Rev-G J6 EVm which has 10inch panel";
Vishal Mahaveer6b7b6202013-07-26 18:24:59 -05009 exit 1;
10}
11
12#no args case
13if [ "$1" = "--help" ] ; then
14 usage
15fi
16
17# Pre-packaged DB
18export FASTBOOT=${FASTBOOT-"./fastboot"}
19export PRODUCT_OUT=${PRODUCT_OUT-"./"}
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
Vishal Mahaveer6b7b6202013-07-26 18:24:59 -050062## poll the board to find out its configuration
63#product=`${FASTBOOT} getvar product 2>&1 | grep product | awk '{print$2}'`
Vishal Mahaveer09e75ed2014-05-14 12:04:39 -050064cpu=`${FASTBOOT} getvar cpu 2>&1 | grep cpu | awk '{print$2}'`
Vishal Mahaveera39c17b2013-09-05 11:58:06 -050065cputype=`${FASTBOOT} getvar secure 2>&1 | grep secure | awk '{print$2}'`
Vishal Mahaveer09e75ed2014-05-14 12:04:39 -050066
67
Vishal Mahaveera39c17b2013-09-05 11:58:06 -050068# Make EMU = HS
Vishal Mahaveer4e535042014-08-25 13:24:48 -050069if [ ${cputype} = "EMU" ] || [ ${cputype} = "HS" ]; then
Vishal Mahaveera39c17b2013-09-05 11:58:06 -050070 cputype="HS"
Vishal Mahaveer4e535042014-08-25 13:24:48 -050071 xloader="${PRODUCT_OUT}${cputype}_QSPI_MLO"
Vishal Mahaveera39c17b2013-09-05 11:58:06 -050072fi
Vishal Mahaveer4e535042014-08-25 13:24:48 -050073
Vishal Mahaveera39c17b2013-09-05 11:58:06 -050074# If fastboot does not support getvar default to GP
Vishal Mahaveer18655bb2014-08-26 16:28:05 -050075if [ ${cputype} = "" ] || [ ${cputype} = "GP" ]; then
Vishal Mahaveera39c17b2013-09-05 11:58:06 -050076 cputype="GP"
Vishal Mahaveer4e535042014-08-25 13:24:48 -050077 xloader="${PRODUCT_OUT}${cputype}_MLO"
Vishal Mahaveera39c17b2013-09-05 11:58:06 -050078fi
Vishal Mahaveer6b7b6202013-07-26 18:24:59 -050079
Vishal Mahaveer09e75ed2014-05-14 12:04:39 -050080# Based on cpu, decide the dtb to flash, default fall back to J6
81if [ ${cpu} = "J6ECO" ]; then
Vishal Mahaveer03f3b8a2014-10-22 10:35:54 -050082 environment="${PRODUCT_OUT}dra72-evm-lcd10.dtb"
Vishal Mahaveer09e75ed2014-05-14 12:04:39 -050083else
Vishal Mahaveerd0b1d212014-11-14 11:46:36 -060084 environment="${PRODUCT_OUT}dra7-evm-lcd7.dtb"
Vishal Mahaveer09e75ed2014-05-14 12:04:39 -050085fi
86
Vishal Mahaveer6b7b6202013-07-26 18:24:59 -050087# Create the filename
88bootimg="${PRODUCT_OUT}boot.img"
Vishal Mahaveer6b7b6202013-07-26 18:24:59 -050089uboot="${PRODUCT_OUT}u-boot.img"
Vishal Mahaveer6b7b6202013-07-26 18:24:59 -050090systemimg="${PRODUCT_OUT}system.img"
91userdataimg="${PRODUCT_OUT}userdata.img"
92cacheimg="${PRODUCT_OUT}cache.img"
93efsimg="${PRODUCT_OUT}efs.img"
94recoveryimg="${PRODUCT_OUT}recovery.img"
95
96
97# Verify that all the files required for the fastboot flash
98# process are available
99
100if [ ! -e "${bootimg}" ] ; then
101 echo "Missing ${bootimg}"
102 exit -1;
103fi
104if [ ! -e "$xloader" ] ; then
105 echo "Missing ${xloader}"
106 exit -1;
107fi
108if [ ! -e "${uboot}" ] ; then
109 echo "Missing ${uboot}"
110 exit -1;
111fi
112if [ ! -e "${environment}" ] ; then
113 echo "Missing ${environment}"
114 exit -1;
115fi
116if [ ! -e "${systemimg}" ] ; then
117 echo "Missing ${systemimg}"
118 exit -1;
119fi
120if [ ! -e "${userdataimg}" ] ; then
121 echo "Missing ${userdataimg}"
122 exit -1;
123fi
124if [ ! -e "${cacheimg}" ] ; then
125 echo "Missing ${cacheimg}"
126# exit -1;
127fi
128if [ ! -e "${recoveryimg}" ] ; then
129 echo "Missing ${recoveryimg}"
Vishal Mahaveer4a63e632014-01-24 08:30:03 -0600130 exit -1;
Vishal Mahaveer6b7b6202013-07-26 18:24:59 -0500131fi
132
133echo "Create GPT partition table"
134${FASTBOOT} oem format
135
Shankar Rao903e4992013-08-02 14:34:04 -0500136echo "Setting target for bootloader to SPI"
137${FASTBOOT} oem spi
138
Shankar Rao7cc8dd72013-08-05 19:17:08 -0500139sleep 3
140
Vishal Mahaveer6b7b6202013-07-26 18:24:59 -0500141echo "Flashing bootloader....."
142echo " xloader: ${xloader}"
Subramaniam Chanderashekarapuramc795bdf2013-10-28 17:40:02 -0400143${FASTBOOT} flash xloader ${xloader}
Shankar Rao7cc8dd72013-08-05 19:17:08 -0500144
145sleep 3
146
Subramaniam Chanderashekarapuramc795bdf2013-10-28 17:40:02 -0400147${FASTBOOT} flash bootloader ${uboot}
Vishal Mahaveer6b7b6202013-07-26 18:24:59 -0500148
Vishal Mahaveer6b7b6202013-07-26 18:24:59 -0500149#echo "Reboot: make sure new bootloader runs..."
Vishal Mahaveera39c17b2013-09-05 11:58:06 -0500150${FASTBOOT} reboot-bootloader
151
152sleep 5
Vishal Mahaveer6b7b6202013-07-26 18:24:59 -0500153
Subramaniam Chanderashekarapuramc795bdf2013-10-28 17:40:02 -0400154echo "Re-creating GPT partition table with new bootloader"
155${FASTBOOT} oem format
156
Vishal Mahaveer6b7b6202013-07-26 18:24:59 -0500157echo "Flash android partitions"
Subramaniam Chanderashekarapuramc795bdf2013-10-28 17:40:02 -0400158${FASTBOOT} flash boot ${bootimg}
Vishal Mahaveer09e75ed2014-05-14 12:04:39 -0500159echo "Flashing device tree ${environment}"
Vishal Mahaveer6b7b6202013-07-26 18:24:59 -0500160${FASTBOOT} flash environment ${environment}
Vishal Mahaveer4a63e632014-01-24 08:30:03 -0600161${FASTBOOT} flash recovery ${recoveryimg}
Subramaniam Chanderashekarapuramc795bdf2013-10-28 17:40:02 -0400162${FASTBOOT} flash system ${systemimg}
Vishal Mahaveer6b7b6202013-07-26 18:24:59 -0500163
Vishal Mahaveer7734fca2013-10-10 09:30:29 -0500164userdataimg_orig="${userdataimg}.orig"
165if [ ! -f $userdataimg_orig ]; then
166 cp $userdataimg $userdataimg_orig
167else
168 cp $userdataimg_orig $userdataimg
169fi
170
171echo "Resizing userdata.img"
172resizefail=0
173userdatasize=`./fastboot getvar userdata_size 2>&1 | grep "userdata_size" | awk '{print$2}'`
174if [ -n "$userdatasize" ]; then
175 while [ 1 ];do
176 echo Current userdata partition size=${userdatasize} KB
177 if [ -d "./data" ]; then
178 echo "Removing data"
179 rm -rf ./data || resizefail=1
180 if [ $resizefail -eq 1 ]; then
181 echo "unable to remove data folder" && break
182 fi
183 fi
184 mkdir ./data
185 ./simg2img userdata.img userdata.img.raw
186 mount -o loop -o grpid -t ext4 ./userdata.img.raw ./data || resizefail=1
187 if [ $resizefail -eq 1 ]; then
188 echo "Mount failed" && break
189 fi
190 ./make_ext4fs -s -l ${userdatasize}K -a data userdata.img data/
191 sync
192 umount data
193 sync
194 rm -rf ./data
195 rm userdata.img.raw
196 break
197 done
198else
199 resizefail=1
200fi
201
202if [ $resizefail -eq 1 ]; then
203 echo "userdata resize failed."
204 echo "Eg: sudo ./fastboot.sh"
205 echo "For now, we are defaulting to original userdata.img"
206 cp $userdataimg_orig $userdataimg
207fi
Vishal Mahaveer6b7b6202013-07-26 18:24:59 -0500208${FASTBOOT} flash userdata ${userdataimg}
209
210if [ "$1" != "--noefs" ] ; then
211 if [ ! -f ${efsimg} ] ; then
212 echo "Creating efs.img as 16M ext4 img..."
213 test -d ./efs/ || mkdir efs
214 ./make_ext4fs -s -l 16M -a efs efs.img efs/
215 else
216 echo "Using previously created efs.img..."
217 fi
218
219 ${FASTBOOT} flash efs ${efsimg}
220else
221 echo "efs partition is untouched"
222fi
223
224#Create cache.img
225if [ ! -f ${cacheimg} ]
226then
227 echo "Creating cache.img as empty ext4 img...."
228 rm -rf /tmp/fastboot-cache
229 mkdir /tmp/fastboot-cache
Vishal Mahaveer49d9e762013-08-01 10:21:11 -0500230 ./make_ext4fs -s -l 256M -a cache ${cacheimg} /tmp/fastboot-cache/
Vishal Mahaveer6b7b6202013-07-26 18:24:59 -0500231 rm -rf /tmp/fastboot-cache
232fi
233
234#flash cache.img
Subramaniam Chanderashekarapuramc795bdf2013-10-28 17:40:02 -0400235${FASTBOOT} flash cache ${cacheimg}
Vishal Mahaveer6b7b6202013-07-26 18:24:59 -0500236
237#reboot now
238#${FASTBOOT} reboot
239
240#if [ $resizefail -eq 1 ]; then
241# echo "--------------------------------------------------"
242# echo "Attempt was made to resize the userdata partition image"
243# echo "to the size available on your SOM. But it failed either"
244# echo "because it failed to remove existing ./data folder or because"
245# echo "you are not running this script with superuser privileges"
246# echo "Don't panic! The script just loaded the original userdata.img"
247# echo "so, things should just work as expected. Just that the size"
248# echo "of /data will be smaller on target."
249# echo ""
250# echo "If you really want to resize userdata.img, remove any existing"
251# echo "./data folder and run \"sudo ./fastboot.sh\""
252# echo "For now, we are defaulting to original userdata.img"
253# echo "--------------------------------------------------"
254#fi
255